链街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.

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