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

196 lines
6.4 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
  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->is_pay('是否到账')->using([0=>'否',1=>'是']);
  36. $grid->created_at;
  37. $grid->filter(function (Grid\Filter $filter) {
  38. $filter->equal('id');
  39. });
  40. $grid->actions(function (Grid\Displayers\Actions $actions) {
  41. $actions->disableDelete();
  42. // $actions->disableEdit();
  43. $actions->disableQuickEdit();
  44. $actions->disableView();
  45. });
  46. if ($current_user->isRole('lanzu_mp')){
  47. $grid->disableEditButton();
  48. }
  49. });
  50. }
  51. /**
  52. * Make a show builder.
  53. *
  54. * @param mixed $id
  55. *
  56. * @return Show
  57. */
  58. protected function detail($id)
  59. {
  60. return Show::make($id, new LanzuMpWithdraw(['mpInfo']), function (Show $show) {
  61. $show->id;
  62. $show->mp_id;
  63. $show->column('服务商名称','mpInfo.name');
  64. $show->money;
  65. $show->status;
  66. $show->created_at;
  67. $show->updated_at;
  68. });
  69. }
  70. /**
  71. * Make a form builder.
  72. *
  73. * @return Form
  74. */
  75. protected function lanzu_bis_form(){
  76. //管理员或者lanzu_bis操作
  77. return Form::make(new LanzuMpWithdraw(['mpInfo']), function (Form $form) {
  78. $form->footer(function ($footer) {
  79. // 去掉`查看`checkbox
  80. $footer->disableViewCheck();
  81. // 去掉`继续编辑`checkbox
  82. $footer->disableEditingCheck();
  83. // 去掉`继续创建`checkbox
  84. $footer->disableCreatingCheck();
  85. });
  86. $form->tools(function (Form\Tools $tools) {
  87. // 去掉跳转详情页按钮
  88. $tools->disableView();
  89. // 去掉删除按钮
  90. $tools->disableDelete();
  91. $tools->disableList();
  92. });
  93. // dd($form->model()->mp_info['name']);
  94. $mpName = $form->model()->mp_info['name'];
  95. //dd( $mpName);
  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. }