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

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