链街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.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
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. } else {
  57. $grid->disableCreateButton();
  58. }
  59. });
  60. }
  61. /**
  62. * Make a show builder.
  63. *
  64. * @param mixed $id
  65. *
  66. * @return Show
  67. */
  68. protected function detail($id)
  69. {
  70. return Show::make($id, new LanzuMpWithdraw(['mpInfo']), function (Show $show) {
  71. $show->id;
  72. $show->mp_id;
  73. $show->column('服务商名称', 'mpInfo.name');
  74. $show->money;
  75. $show->status;
  76. $show->created_at->as(function ($time) {
  77. if ($time) {
  78. return date('Y-m-d H:i', $time);
  79. } else {
  80. return '-';
  81. }
  82. });
  83. $show->updated_at->as(function ($time) {
  84. if ($time) {
  85. return date('Y-m-d H:i', $time);
  86. } else {
  87. return '-';
  88. }
  89. });
  90. });
  91. }
  92. /**
  93. * Make a form builder.
  94. *
  95. * @return Form
  96. */
  97. protected function lanzu_bis_form()
  98. {
  99. //管理员或者lanzu_bis操作
  100. return Form::make(new LanzuMpWithdraw(['mpInfo']), function (Form $form) {
  101. $form->footer(function ($footer) {
  102. // 去掉`查看`checkbox
  103. $footer->disableViewCheck();
  104. // 去掉`继续编辑`checkbox
  105. $footer->disableEditingCheck();
  106. // 去掉`继续创建`checkbox
  107. $footer->disableCreatingCheck();
  108. });
  109. $form->tools(function (Form\Tools $tools) {
  110. // 去掉跳转详情页按钮
  111. $tools->disableView();
  112. // 去掉删除按钮
  113. $tools->disableDelete();
  114. $tools->disableList();
  115. });
  116. $mpName = $form->model()->mp_info['name'];
  117. $form->display('id');
  118. $form->text('mp_id', '服务商ID')->disable();
  119. $form->display('', '服务商名')->value($mpName);
  120. $form->text('money', '提现金额')->disable()->required();
  121. $form->hidden('is_operated');
  122. $form->saving(function (Form $form) {
  123. $form->is_operated = 1;
  124. });
  125. if ($form->model()->is_operated) {
  126. $status = '';
  127. if ($form->model()->status == 1) {
  128. $status = '审核通过';
  129. }
  130. if ($form->model()->status == -1) {
  131. $status = '拒绝';
  132. }
  133. $form->display('', '审核状态')->value($status);
  134. $form->disableSubmitButton();
  135. $form->disableResetButton();
  136. } else {
  137. if ($form->isCreating()) {
  138. $form->radio('status')->options([1 => '通过审核', -1 => '拒绝'])->default(-1)->disable();
  139. } else {
  140. $form->model()->status = 1;
  141. $form->radio('status')->options([1 => '通过审核', -1 => '拒绝']);
  142. }
  143. }
  144. $form->saved(function (Form $form, $result) {
  145. $adminUserId = $form->model()->mp_info['admin_user_id'];
  146. $money = $form->model()->money;
  147. if ($form->isEditing()) {
  148. if ($form->status == -1) {
  149. //如果服务商提现审核被拒绝,退回服务商的提现金额
  150. MpBalance::returnBalance($adminUserId, Type::BALANCE_USER_TYPE_MP, $money);
  151. } elseif ($form->status == 1) {
  152. //如果审核通过,则记录流水
  153. FinancialRecord::addFinancialRecord($adminUserId, Type::BALANCE_USER_TYPE_MP, $money, Type::MONEY_TYPE_MP, '服务商提现', '服务商提现');
  154. }
  155. }
  156. });
  157. });
  158. }
  159. protected function form()
  160. {
  161. $current_user = Admin::user();
  162. if (!$current_user->isRole('lanzu_mp')) {
  163. return $this->lanzu_bis_form();
  164. }
  165. //如果是服务商角色,获取服务商信息
  166. $mp = LanzuMpInfo::where('admin_user_id', $current_user->id)->first();
  167. //获取服务商可提现金额
  168. $mpb = MpBalance::where('source_id', $mp->admin_user_id)
  169. ->where('user_type', Type::BALANCE_USER_TYPE_MP)->first();
  170. $balance = 0;
  171. if ($mpb) {
  172. $balance = $mpb->balance;
  173. }
  174. return Form::make(new LanzuMpWithdraw(), function (Form $form) use ($current_user, $balance, $mpb, $mp) {
  175. $form->footer(function ($footer) {
  176. // 去掉`查看`checkbox
  177. $footer->disableViewCheck();
  178. // 去掉`继续编辑`checkbox
  179. $footer->disableEditingCheck();
  180. // 去掉`继续创建`checkbox
  181. $footer->disableCreatingCheck();
  182. });
  183. $form->display('id');
  184. $form->hidden('mp_id')->value($mp->id);
  185. $form->text('balance', '当前可提现余额')->value($balance)->disable()->help('当前可提现金额');
  186. $form->number('money', '提现金额')->required()->min(0);
  187. $form->ignore(['balance']);
  188. $form->saving(function (Form $form)use ($current_user){
  189. if ($form->money < env('MP_MIN_MONEY')) {
  190. return $form->error('提现金额不得小于 ' . env('MP_MIN_MONEY') . ' 元');
  191. } elseif ($form->money > env('MP_MAX_MONEY')) {
  192. return $form->error('提现金额不得大于 ' . env('MP_MAX_MONEY') . ' 元');
  193. }
  194. $res = LanzuUserBalance::checkBalance($current_user->id, $form->money);
  195. if (!$res) {
  196. return $form->error('您可提现金额不足!');
  197. }
  198. });
  199. //添加成功之后,扣减掉可提现金额
  200. $form->saved(function (Form $form, $id) use ($mpb, $mp) {
  201. if ($form->isCreating()) {
  202. if ($id) {
  203. $mpb->balance = $mpb->balance - $form->money;
  204. $mpb->save();
  205. //发送短信通知
  206. if (env('SMS_MP_NOTICE')){
  207. $phone = env('SMS_MP_TEL');
  208. $template = env('SMS_MP_TEMPLATE');
  209. $templateParams = ['name' => "({$mp->name})", 'money' => $form->money . '元'];
  210. $signName = env('SMS_MP_SIGN_NAME');
  211. $result = Sms::rpcSent($phone, $template, $templateParams, $signName);
  212. $result = json_decode($result);
  213. if ($result->result->Code != 'OK') {
  214. $msg = $result->result->Message;
  215. Log::error('发送短信失败', [
  216. 'Message'=>$msg,
  217. 'name'=>$mp->name,
  218. 'money'=>$form->money,
  219. 'id'=>$id
  220. ]);
  221. }
  222. }
  223. }
  224. }
  225. });
  226. });
  227. }
  228. }