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

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