链街Dcat后台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

168 lines
5.4 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. <?php
  2. namespace App\Admin\Controllers;
  3. use App\Admin\Common\Auth;
  4. use App\Admin\Extensions\CheckRow;
  5. use App\Admin\Metrics\Examples\TotalUsers;
  6. use App\Admin\Repositories\LanzuMpInfo;
  7. use App\Models\LanzuMmInfo;
  8. use App\Models\LanzuMmInfo as mmInfo;
  9. use App\Models\LanzuMpWithdraw;
  10. use App\Models\MpBalance;
  11. use Dcat\Admin\Actions\Action;
  12. use Dcat\Admin\Admin;
  13. use Dcat\Admin\Form;
  14. use Dcat\Admin\Grid;
  15. use Dcat\Admin\Layout\Column;
  16. use Dcat\Admin\Layout\Content;
  17. use Dcat\Admin\Layout\Row;
  18. use Dcat\Admin\Show;
  19. use Dcat\Admin\Controllers\AdminController;
  20. use Dcat\Admin\Widgets\Metrics\Card;
  21. use EasyWeChat\Factory;
  22. use Encore\Admin\Grid\Displayers\Actions;
  23. use Illuminate\Support\Facades\DB;
  24. use Illuminate\Support\Facades\Hash;
  25. use \App\Models\LanzuMpInfo as mpInfo;
  26. use \App\Models\AdminUsers;
  27. use \App\Models\AdminRoles;
  28. use \App\Models\AdminRoleUsers;
  29. class LanzuMpInfoController extends AdminController
  30. {
  31. /**
  32. * Make a grid builder.
  33. *
  34. * @return Grid
  35. */
  36. protected function grid()
  37. {
  38. return Grid::make(new LanzuMpInfo(), function (Grid $grid) {
  39. $grid->name;
  40. $grid->phone;
  41. $grid->actions(function (Grid\Displayers\Actions $actions) {
  42. $actions->row->id;
  43. });
  44. $grid->column('可提现金额')->display(function () {
  45. return MpBalance::getBalance($this->admin_user_id, Type::BALANCE_USER_TYPE_MP);
  46. });
  47. $grid->id_frond->image('', 50, 50);
  48. $grid->id_back->image('', 50, 50);
  49. $grid->id_number;
  50. $grid->column('status', '状态')->display(function ($status) {
  51. if ($status == 1) {
  52. return '正常';
  53. } elseif ($status == 0) {
  54. return '禁用';
  55. }
  56. });
  57. $grid->created_at->display(function ($time) {
  58. return date("Y-m-d H:i", $time);
  59. });
  60. $grid->filter(function (Grid\Filter $filter) {
  61. $filter->like('name')->placeholder('输入服务商名称');
  62. $filter->equal('phone')->placeholder('输入电话号码');
  63. });
  64. });
  65. }
  66. /**
  67. * Make a show builder.
  68. *
  69. * @param mixed $id
  70. *
  71. * @return Show
  72. */
  73. protected function detail($id)
  74. {
  75. return Show::make($id, new LanzuMpInfo(), function (Show $show) {
  76. $show->name;
  77. $show->phone;
  78. $show->bank_name;
  79. $show->bank_card;
  80. $show->bank_addr;
  81. $show->id_frond()->image();
  82. $show->id_back()->image();
  83. $show->id_number;
  84. $show->status()->using([1 => '正常', 0 => '禁用']);
  85. $show->created_at()->as(function ($time) {
  86. return date('Y-m-d H:i', $time);
  87. });
  88. $show->updated_at()->as(function ($time) {
  89. return date('Y-m-d H:i', $time);
  90. });
  91. });
  92. }
  93. /**
  94. * Make a form builder.
  95. *
  96. * @return Form
  97. */
  98. protected function form()
  99. {
  100. return Form::make(new LanzuMpInfo(), function (Form $form) {
  101. $form->display('id')->hideInDialog();
  102. $form->text('user_id','懒ID')->placeholder('对应懒族小程序个人中心的懒ID')->required();
  103. $form->text('name', '姓名')->required();
  104. $form->mobile('phone')->required();
  105. $form->text('bank_name')->required();
  106. $form->text('bank_card')->required();
  107. $form->text('bank_addr')->required();
  108. $form->image('id_frond')->uniqueName()->required();
  109. $form->image('id_back')->uniqueName()->required();
  110. $form->text('id_number')->required();
  111. $form->radio('status', '状态')->options(['禁用', '启用'])->default(1);
  112. $form->saved(function (Form $form, $mpid) {
  113. $model = new mpInfo();
  114. if ($form->isCreating()) {
  115. $res = Auth::addAdminUser($form, $model, $mpid, 'lanzu_mp',Type::BALANCE_USER_TYPE_MP);
  116. if ($res == -1) {
  117. return $form->error('该手机号作为登陆帐号已存在!');
  118. } elseif ($res == -2) {
  119. return $form->error('添加失败!');
  120. }
  121. } else {
  122. //>>4.编辑时同步登陆帐号状态
  123. $adu = new AdminUsers();
  124. $id = $form->getKey();
  125. $mp = mpInfo::find($id);
  126. $ad = $adu->find($mp->admin_user_id);
  127. $ad->status = $form->status;
  128. $ad->save();
  129. }
  130. });
  131. $form->deleted(function (Form $form, $result) {
  132. $aduids = array_column($form->model()->toArray(), 'admin_user_id');
  133. $mids = array_column($form->model()->toArray(), 'id');
  134. //删除对应的登陆帐号
  135. AdminUsers::whereIn('id', $aduids)->delete();
  136. //删除提现记录
  137. LanzuMpWithdraw::whereIn('mp_id',$mids)->update(['deleted_at'=>time()]);
  138. });
  139. });
  140. }
  141. public function showData(Content $content)
  142. {
  143. return $content->header('控制面板')
  144. ->description('欢迎回到懒族后台')
  145. ->body(function (Row $row) {
  146. $row->column(4, new \App\Admin\Metrics\Examples\MmInfo());
  147. });
  148. }
  149. }