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

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