WxUserWithdrawalController.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <?php
  2. namespace App\Admin\Controllers\User;
  3. use App\Admin\Actions\Extensions\userWithdrawalButton;
  4. use App\Admin\Actions\Grid\User\UserWithdrawalProcessAction;
  5. use App\Admin\Repositories\User\WxUserWithdrawal;
  6. use App\Jobs\User\UserWithdrawalProcessJob;
  7. use App\Jobs\User\UserWithdrawalQueryJob;
  8. use App\Wen\Utils\Settings;
  9. use App\Wen\Utils\Utils;
  10. use Dcat\Admin\Form;
  11. use Dcat\Admin\Grid;
  12. use Dcat\Admin\Show;
  13. use Dcat\Admin\Http\Controllers\AdminController;
  14. use Dcat\Admin\Widgets\Metrics\Card;
  15. use Illuminate\Support\Arr;
  16. class WxUserWithdrawalController extends AdminController
  17. {
  18. /**
  19. * Make a grid builder.
  20. *
  21. * @return Grid
  22. */
  23. protected function grid()
  24. {
  25. $mch_transfer_to_weChat = Settings::get('mch_transfer_to_weChat', 0) == 1;
  26. return Grid::make(new WxUserWithdrawal('user'), function (Grid $grid) use (&$mch_transfer_to_weChat) {
  27. $grid->simplePaginate();
  28. $grid->quickSearch(['id', 'withdrawal_id', 'user_id', 'user.user_name', 'wx_batch_id', 'ali_batch_id', 'bank_card', 'wechat_phone', 'alipay_phone'])->placeholder('搜索提现单号,用户id,用户名...')->width(35);
  29. $grid->model()->orderBy('id', 'desc');
  30. $grid->column('id')->sortable();
  31. $grid->column('withdrawal_id')->sortable()->display(function ($v){
  32. if(_empty_($v)){
  33. \App\Models\User\WxUserWithdrawal::where('id', $this->id)->update([
  34. 'withdrawal_id' => Utils::getSn(14)
  35. ]);
  36. }
  37. return $v;
  38. });
  39. $grid->column('owers', '头像')->display(function ($v) {
  40. return '<img src="' . ($this->ower['user_avatar'] ?? Settings::get('img_default', 'https://img.mini.minisns.cn/icons/dafault.png')) . '" style="border-radius:50px;width:30px;" />';
  41. })->width('50px');
  42. $grid->column('ower', '用户名称')->display(function ($v) {
  43. if($v && $v['user_name']){
  44. return '<a target="_blank" href="'.admin_url('users?id='.$v['id']).'">'.$v['user_name'].'</a>' ?? '用户已删除';
  45. }
  46. return '用户已删除';
  47. })->width('100px');
  48. $grid->column('price');
  49. $grid->column('pay_amount');
  50. // 微信
  51. $grid->column('real_name');
  52. $grid->column('wechat_phone');
  53. $grid->column('alipay_phone');
  54. $grid->column('account_way')->display(function ($v){
  55. return _array_key(['wxpay'=>'微信零钱', 'alipay'=>'支付宝余额'], $v, '');
  56. });
  57. $grid->column('account_at');
  58. $grid->column('other','其他')->display('查看') // 设置按钮名称
  59. ->expand(function ($v) {
  60. $input['银行名字'] = $this->bank_name;
  61. $input['银行账号'] = $this->bank_card;
  62. $input['微信打款批次号'] = $this->wx_batch_id;
  63. $input['支付宝打款批次号'] = $this->ali_batch_id;
  64. $input['到账方式'] = _array_key(['wxpay'=>'微信零钱', 'alipay'=>'支付宝余额'], $this->account_way, '');
  65. $input['到账时间'] = $this->account_at;
  66. $str__ = '';
  67. foreach ($input as $key => $item){
  68. if(!_empty_($str__)){
  69. $str__ .= "\n";
  70. }
  71. $str__ .= $key . ':'. $item;
  72. }
  73. $input = $str__;
  74. // 只填充内容,不需要标题
  75. $card = Card::make(view('admin/system/log', compact('input')));
  76. return $card;
  77. });
  78. $grid->column('state')->using([0 => '待处理', 1 => '已处理', 2 => '异常', 3=>'微信打款中', 4=>'支付宝打款中', 5=>'尝试重新微信打款'])->label([
  79. 0 => 'success',
  80. 1 => 'pink',
  81. 2 => 'primary',
  82. 3 => '#29ad6a',
  83. 4 => '#1578ff',
  84. 5 => 'primary'
  85. ])->sortable();
  86. $grid->column('refuse_tip')->display(function ($v) use ($mch_transfer_to_weChat){
  87. if(_empty_($v)){
  88. $v = '';
  89. }
  90. if($mch_transfer_to_weChat){
  91. if($this->state === 0 && _empty_($this->wx_batch_id)){
  92. UserWithdrawalProcessJob::dispatch($this->id);
  93. }else if(!_empty_($this->wx_batch_id) && $this->state == 3){
  94. UserWithdrawalQueryJob::dispatch($this->id);
  95. }else if($this->state == 5 && _empty_($this->wx_batch_id)){
  96. UserWithdrawalProcessJob::dispatch($this->id);
  97. }
  98. }
  99. return $this->is_lock == 1 ? '🔒'.$v : $v;
  100. })->limit(20);
  101. // $grid->column('account_at');
  102. $grid->column('created_at')->sortable();
  103. $grid->filter(function (Grid\Filter $filter) {
  104. $filter->equal('id');
  105. $filter->equal('state')->multipleSelect([0 => '待处理', 1 => '已处理', 2 => '异常', 3=>'微信打款中', 4=>'支付宝打款中', 5=>'尝试重新微信打款']);
  106. });
  107. // 禁用新增按钮
  108. $grid->disableCreateButton();
  109. // 禁用编辑按钮
  110. $grid->disableEditButton();
  111. // 禁用详情按钮
  112. // $grid->disableViewButton();
  113. $grid->disableDeleteButton();
  114. $grid->disableBatchDelete();
  115. $grid->actions(function (Grid\Displayers\Actions $actions) {
  116. $actions->append((new UserWithdrawalProcessAction())->setKey($this->id));
  117. });
  118. $grid->tools([
  119. // new userWithdrawalButton(),
  120. ]);
  121. });
  122. }
  123. /**
  124. * Make a show builder.
  125. *
  126. * @param mixed $id
  127. *
  128. * @return Show
  129. */
  130. protected function detail($id)
  131. {
  132. return Show::make($id, new WxUserWithdrawal(), function (Show $show) {
  133. $show->field('id');
  134. $show->field('withdrawal_id');
  135. $show->field('user_id');
  136. $show->field('price');
  137. $show->field('real_name');
  138. $show->field('id_card');
  139. $show->field('wechat_phone');
  140. $show->field('alipay_phone');
  141. $show->field('bank_name');
  142. $show->field('bank_card');
  143. $show->field('state');
  144. $show->field('refuse_tip');
  145. $show->field('account_at');
  146. $show->field('account_way');
  147. $show->field('account_way');
  148. $show->field('wx_batch_id');
  149. $show->field('ali_batch_id');
  150. $show->field('created_at');
  151. $show->field('updated_at');
  152. $show->field('is_lock');
  153. $show->disableEditButton();
  154. $show->disableDeleteButton();
  155. });
  156. }
  157. /**
  158. * Make a form builder.
  159. *
  160. * @return Form
  161. */
  162. protected function form()
  163. {
  164. return Form::make(new WxUserWithdrawal(), function (Form $form) {
  165. $form->display('id');
  166. $form->text('user_id');
  167. $form->text('price');
  168. $form->text('state');
  169. $form->text('account_at');
  170. $form->deleting(function (Form $form){
  171. global $__MINI_GLOBAL_TENANT_ID__;
  172. if($__MINI_GLOBAL_TENANT_ID__ > 0){
  173. return $form->response()->error('权限不足,不可以删除其他分站对象');
  174. }
  175. });
  176. });
  177. }
  178. }