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

210 lines
6.9 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
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
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
5 years ago
5 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->as(function ($time) {
  69. if ($time) {
  70. return date('Y-m-d H:i', $time);
  71. } else {
  72. return '-';
  73. }
  74. });
  75. $show->updated_at->as(function ($time) {
  76. if ($time) {
  77. return date('Y-m-d H:i', $time);
  78. } else {
  79. return '-';
  80. }
  81. });
  82. });
  83. }
  84. /**
  85. * Make a form builder.
  86. *
  87. * @return Form
  88. */
  89. protected function lanzu_bis_form()
  90. {
  91. //管理员或者lanzu_bis操作
  92. return Form::make(new LanzuMpWithdraw(['mpInfo']), function (Form $form) {
  93. $form->footer(function ($footer) {
  94. // 去掉`查看`checkbox
  95. $footer->disableViewCheck();
  96. // 去掉`继续编辑`checkbox
  97. $footer->disableEditingCheck();
  98. // 去掉`继续创建`checkbox
  99. $footer->disableCreatingCheck();
  100. });
  101. $form->tools(function (Form\Tools $tools) {
  102. // 去掉跳转详情页按钮
  103. $tools->disableView();
  104. // 去掉删除按钮
  105. $tools->disableDelete();
  106. $tools->disableList();
  107. });
  108. $mpName = $form->model()->mp_info['name'];
  109. $form->display('id');
  110. $form->text('mp_id', '服务商ID')->disable();
  111. $form->display('', '服务商名')->value($mpName);
  112. $form->text('money', '提现金额')->disable()->required();
  113. $form->hidden('is_operated');
  114. $form->saving(function (Form $form) {
  115. $form->is_operated = 1;
  116. });
  117. if ($form->model()->is_operated) {
  118. $status = '';
  119. if ($form->model()->status == 1) {
  120. $status = '审核通过';
  121. }
  122. if ($form->model()->status == -1) {
  123. $status = '拒绝';
  124. }
  125. $form->display('', '审核状态')->value($status);
  126. $form->disableSubmitButton();
  127. $form->disableResetButton();
  128. } else {
  129. if ($form->isCreating()) {
  130. $form->radio('status')->options([1 => '通过审核', -1 => '拒绝'])->default(-1)->disable();
  131. } else {
  132. $form->radio('status')->options([1 => '通过审核', -1 => '拒绝'])->default(-1);
  133. }
  134. }
  135. $form->saved(function (Form $form, $result) {
  136. if ($form->isEditing()) {
  137. if ($form->model()->status == -1) {
  138. //如果服务商提现审核被拒绝,退回服务商的提现金额
  139. MpBalance::returnBalance($form->model()->mp_id, 1, $form->model()->money);
  140. }
  141. }
  142. });
  143. });
  144. }
  145. protected function form()
  146. {
  147. $current_user = Admin::user();
  148. if (!$current_user->isRole('lanzu_mp')) {
  149. return $this->lanzu_bis_form();
  150. }
  151. //如果是服务商角色,获取服务商信息
  152. $mp = LanzuMpInfo::where('admin_user_id', $current_user->id)->first();
  153. //获取服务商可提现金额
  154. $mpb = MpBalance::where('user_id', $mp->id)
  155. ->where('user_type', 1)->first();
  156. $balance = 0;
  157. if ($mpb) {
  158. $balance = $mpb->balance;
  159. }
  160. return Form::make(new LanzuMpWithdraw(), function (Form $form) use ($current_user, $balance, $mpb, $mp) {
  161. $form->footer(function ($footer) {
  162. // 去掉`查看`checkbox
  163. $footer->disableViewCheck();
  164. // 去掉`继续编辑`checkbox
  165. $footer->disableEditingCheck();
  166. // 去掉`继续创建`checkbox
  167. $footer->disableCreatingCheck();
  168. });
  169. $form->display('id');
  170. $form->hidden('mp_id')->value($mp->id);
  171. $form->text('balance', '当前可提现余额')->value($balance)->disable()->help('当前可提现金额');
  172. $form->number('money', '提现金额')->required()->min(0);
  173. $form->ignore(['balance']);
  174. //添加成功之后,扣减掉可提现金额
  175. $form->saved(function (Form $form, $result) use ($mpb) {
  176. if ($form->isCreating()) {
  177. if ($result) {
  178. $mpb->balance = $mpb->balance - $form->money;
  179. $mpb->save();
  180. }
  181. }
  182. });
  183. });
  184. }
  185. }