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

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