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

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