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

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