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

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