WxOrderController.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <?php
  2. namespace App\Admin\Controllers;
  3. use App\Admin\Actions\Grid\OrderSupplyAction;
  4. use App\Admin\Repositories\WxOrder;
  5. use App\Jobs\Order\OrderDeliverInfoManage;
  6. use App\Wen\Utils\FieldUtils;
  7. use App\Wen\Utils\Settings;
  8. use Dcat\Admin\Actions\Action;
  9. use Dcat\Admin\Form;
  10. use Dcat\Admin\Grid;
  11. use Dcat\Admin\Show;
  12. use Dcat\Admin\Http\Controllers\AdminController;
  13. class WxOrderController extends AdminController
  14. {
  15. protected $status_arr = [0 => '未付款', 1 => '已付款', 2 => '已退款', 3=>'待小程序发货', 4=>'小程序发货中', 5=>'待小程序确定收货', 6=>'小程序确定收货中'];
  16. /**
  17. * Make a grid builder.
  18. *
  19. * @return Grid
  20. */
  21. protected function grid()
  22. {
  23. return Grid::make(new WxOrder('user'), function (Grid $grid) {
  24. $grid->simplePaginate();
  25. $grid->model()->orderBy('id','desc');
  26. $grid->quickSearch(['id','user_id','user.user_name', 'order_number', 'order_serial_number'])->placeholder('搜索ID,用户ID,用户名字,商户流水号,微信支付流水号...')->width(50);
  27. $grid->column('id')->sortable();
  28. $grid->column('users', '头像')->display(function ($v) {
  29. return '<img src="' . ($this->user['user_avatar'] ?? Settings::get('img_default', 'https://img.mini.minisns.cn/icons/dafault.png')) . '" style="border-radius:50px;width:30px;" />';
  30. })->width('50px');
  31. $grid->column('user')->display(function ($v) {
  32. if($v && $v['user_name']){
  33. return '<a target="_blank" href="'.admin_url('users?id='.$v['id']).'">'.$v['user_name'].'</a>' ?? '用户已删除';
  34. }
  35. return '';
  36. })->width('100px');
  37. $grid->column('order_type')->using(FieldUtils::getOrderTypes())->label([
  38. 0 => 'success',
  39. 1 => 'pink',
  40. 2 => 'primary',
  41. 3 => 'green',
  42. 4 => 'pink',
  43. 5 => 'pink',
  44. 6 => 'pink',
  45. 7 => 'pink',
  46. 8 => 'green',
  47. 9 => 'black'
  48. ]);
  49. $grid->column('order_information')->limit(8);
  50. $grid->column('order_price');
  51. $grid->column('order_pay_price')->label('success');
  52. $grid->column('order_number')->limit(8);
  53. $grid->column('order_serial_number')->limit(8);
  54. $grid->column('order_state')->display(function ($v){
  55. if($v == 3 && !_empty_($this->order_serial_number)){
  56. OrderDeliverInfoManage::dispatch('upload', $this->id);
  57. }else if($v == 5 && !_empty_($this->order_serial_number)){
  58. OrderDeliverInfoManage::dispatch('query', $this->id);
  59. }
  60. return $v;
  61. })->using($this->status_arr)->label([
  62. 0 => 'red',
  63. 1 => 'success',
  64. 2 => 'primary',
  65. ]);
  66. $grid->column('updated_at')->sortable();
  67. $grid->filter(function (Grid\Filter $filter) {
  68. $filter->equal('id');
  69. $filter->equal('order_type')->select(FieldUtils::getOrderTypes());
  70. $filter->equal('order_number');
  71. $filter->equal('order_state')->select($this->status_arr);
  72. });
  73. $grid->disableCreateButton();
  74. // $grid->disableActions();
  75. // 禁用编辑按钮
  76. $grid->disableEditButton();
  77. // 禁用详情按钮
  78. $grid->disableViewButton();
  79. $grid->disableBatchDelete();
  80. $grid->batchActions(function ($batch) {
  81. $batch->add(new OrderSupplyAction());
  82. });
  83. });
  84. }
  85. /**
  86. * Make a show builder.
  87. *
  88. * @param mixed $id
  89. *
  90. * @return Show
  91. */
  92. protected function detail($id)
  93. {
  94. return Show::make($id, new WxOrder(), function (Show $show) {
  95. $show->field('id');
  96. $show->field('user_id');
  97. $show->field('order_type');
  98. $show->field('order_information');
  99. $show->field('order_price');
  100. $show->field('order_pay_price');
  101. $show->field('order_number');
  102. $show->field('order_serial_number');
  103. $show->field('order_state');
  104. $show->field('created_at');
  105. $show->field('updated_at');
  106. });
  107. }
  108. /**
  109. * Make a form builder.
  110. *
  111. * @return Form
  112. */
  113. protected function form()
  114. {
  115. return Form::make(new WxOrder(), function (Form $form) {
  116. $form->display('id');
  117. $form->text('user_id');
  118. $form->text('order_type');
  119. $form->text('order_information');
  120. $form->text('order_price');
  121. $form->text('order_pay_price');
  122. $form->text('order_number');
  123. $form->text('order_serial_number');
  124. $form->text('order_state');
  125. $form->deleting(function (Form $form){
  126. global $__MINI_GLOBAL_TENANT_ID__;
  127. if($__MINI_GLOBAL_TENANT_ID__ > 0){
  128. return $form->response()->error('权限不足,不可以删除其他分站对象');
  129. }
  130. });
  131. });
  132. }
  133. }