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

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