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

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