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

183 lines
5.8 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\Repositories\LanzuMpWithdraw;
  4. use App\Models\LanzuMpInfo;
  5. use Dcat\Admin\Form;
  6. use Dcat\Admin\Grid;
  7. use Dcat\Admin\Show;
  8. use Dcat\Admin\Admin;
  9. use Dcat\Admin\Controllers\AdminController;
  10. use App\Models\MpBalance;
  11. class LanzuMpWithdrawController extends AdminController
  12. {
  13. /**
  14. * Make a grid builder.
  15. *
  16. * @return Grid
  17. */
  18. protected function grid()
  19. {
  20. return Grid::make(new LanzuMpWithdraw(['mpInfo']), function (Grid $grid) {
  21. $grid->id->sortable();
  22. $grid->column('mpInfo.name','服务商名字');
  23. $grid->money;
  24. $grid->status('提现状态')->using([-1=>'拒绝',0=>'审核中',1=>'通过'])
  25. ->label([-1=>'danger',0=>'default',1=>'success']);
  26. $grid->created_at;
  27. $grid->filter(function (Grid\Filter $filter) {
  28. $filter->equal('id');
  29. });
  30. $grid->actions(function (Grid\Displayers\Actions $actions) {
  31. $actions->disableDelete();
  32. // $actions->disableEdit();
  33. $actions->disableQuickEdit();
  34. $actions->disableView();
  35. });
  36. });
  37. }
  38. /**
  39. * Make a show builder.
  40. *
  41. * @param mixed $id
  42. *
  43. * @return Show
  44. */
  45. protected function detail($id)
  46. {
  47. return Show::make($id, new LanzuMpWithdraw(['mpInfo']), function (Show $show) {
  48. $show->id;
  49. $show->mp_id;
  50. $show->column('服务商名称','mpInfo.name');
  51. $show->money;
  52. $show->status;
  53. $show->created_at;
  54. $show->updated_at;
  55. });
  56. }
  57. /**
  58. * Make a form builder.
  59. *
  60. * @return Form
  61. */
  62. protected function lanzu_bis_form(){
  63. //管理员或者lanzu_bis操作
  64. return Form::make(new LanzuMpWithdraw(['mpInfo']), function (Form $form) {
  65. $form->footer(function ($footer) {
  66. // 去掉`查看`checkbox
  67. $footer->disableViewCheck();
  68. // 去掉`继续编辑`checkbox
  69. $footer->disableEditingCheck();
  70. // 去掉`继续创建`checkbox
  71. $footer->disableCreatingCheck();
  72. });
  73. $form->tools(function (Form\Tools $tools) {
  74. // 去掉跳转详情页按钮
  75. $tools->disableView();
  76. // 去掉删除按钮
  77. $tools->disableDelete();
  78. $tools->disableList();
  79. });
  80. // dd($form->model()->mp_info['name']);
  81. $mpName = $form->model()->mp_info['name'];
  82. //dd( $mpName);
  83. $form->display('id');
  84. $form->text('mp_id','服务商ID')->disable();
  85. $form->display('','服务商名')->value($mpName);
  86. $form->text('money','提现金额')->disable()->required();
  87. $form->hidden('is_operated');
  88. $form->saving(function (Form $form) {
  89. $form->is_operated = 1;
  90. });
  91. if($form->model()->is_operated){
  92. $status = '';
  93. if($form->model()->status==1){
  94. $status = '审核通过';
  95. }
  96. if($form->model()->status==-1){
  97. $status = '拒绝';
  98. }
  99. $form->display('','审核状态')->value($status);
  100. $form->disableSubmitButton();
  101. $form->disableResetButton();
  102. }else{
  103. $form->radio('status')->options([1 => '通过审核', -1=> '拒绝'])->default(-1);
  104. }
  105. $form->saved(function (Form $form,$result){
  106. if ($form->isEditing()){
  107. if ($form->model()->status==-1){
  108. //如果服务商提现审核被拒绝,退回服务商的提现金额
  109. MpBalance::returnBalance($form->model()->mp_id,1,$form->model()->money);
  110. }
  111. }
  112. });
  113. });
  114. }
  115. protected function form()
  116. {
  117. $current_user = Admin::user();
  118. if(!$current_user->isRole('lanzu_mp')){
  119. return $this->lanzu_bis_form();
  120. }
  121. //如果是服务商角色,获取服务商信息
  122. $mp = LanzuMpInfo::where('admin_user_id',$current_user->id)->first();
  123. //获取服务商可提现金额
  124. $mpb = MpBalance::where('user_id',$mp->id)
  125. ->where('user_type',1)->first();
  126. $balance = 0;
  127. if($mpb){
  128. $balance = $mpb->balance;
  129. }
  130. return Form::make(new LanzuMpWithdraw(), function (Form $form) use($current_user,$balance,$mpb) {
  131. $form->footer(function ($footer) {
  132. // 去掉`查看`checkbox
  133. $footer->disableViewCheck();
  134. // 去掉`继续编辑`checkbox
  135. $footer->disableEditingCheck();
  136. // 去掉`继续创建`checkbox
  137. $footer->disableCreatingCheck();
  138. });
  139. $form->tools(function (Form\Tools $tools) {
  140. // 去掉跳转列表按钮
  141. $tools->disableList();
  142. });
  143. $form->display('id');
  144. $form->hidden('mp_id')->value($mpb->id);
  145. $form->text('balance','当前可提现余额')->value($balance)->disable()->help('当前可提现金额');
  146. $form->number('money','提现金额')->required();
  147. $form->ignore(['balance']);
  148. //添加成功之后,扣减掉可提现金额
  149. $form->saved(function (Form $form,$result)use ($mpb){
  150. if ($form->isCreating()){
  151. if ($result){
  152. $mpb->balance = $mpb->balance-$form->money;
  153. $mpb->save();
  154. }
  155. }
  156. });
  157. });
  158. }
  159. }