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

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