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

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