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

169 lines
5.3 KiB

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