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

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