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

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