海南旅游SAAS
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.

167 lines
5.0 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. <?php
  2. namespace App\AdminSupplier\Controllers;
  3. use App\AdminSupplier\Extensions\Grid\VerificationOrder;
  4. use App\AdminSupplier\Repositories\Order;
  5. use App\Common\OrderStatus;
  6. use App\Common\PayType;
  7. use App\Models\Agent;
  8. use App\Models\Supplier;
  9. use Dcat\Admin\Admin;
  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\Table;
  15. class OrderController extends AdminController
  16. {
  17. /**
  18. * Make a grid builder.
  19. *
  20. * @return Grid
  21. */
  22. protected function grid()
  23. {
  24. return Grid::make(new Order([
  25. 'agent:id,company_name',
  26. 'agentProduct.product:id,title,price,pictures',
  27. 'product'
  28. ]), function (Grid $grid) {
  29. $grid->disableCreateButton();
  30. $grid->disableDeleteButton();
  31. $grid->disableEditButton();
  32. $grid->disableRowSelector();
  33. $grid->model()->where(function ($query) {
  34. return $query->whereHas('orderProductItem', function($query) {
  35. return $query->where('supplier_id', Admin::user()->id);
  36. });
  37. });
  38. $grid->column('id')->sortable();
  39. $grid->column('agent.company_name', '代理商');
  40. $grid->column('order_no', '订单号')->limit(10);
  41. $grid->column('title')->limit(20);
  42. $grid->column('info')
  43. ->display('查看')
  44. ->modal('信息收集表单', function ($modal) {
  45. $info = $this->info ?? [];
  46. $info = array_map(function($v) {
  47. if (isset($v['value'], $v['type'])) {
  48. if ($v['type'] == 'image') {
  49. if (is_array($v['value'])) {
  50. return array_reduce($v['value'], fn($v2, $v3) => $v2 . '<img data-action="preview-img" src="' . $v3 . '" style="max-width:120px;max-height:200px;cursor:pointer" class="img img-thumbnail"> &nbsp;');
  51. } else {
  52. return '<img data-action="preview-img" src="' . $v['value'] . '" style="max-width:120px;max-height:200px;cursor:pointer" class="img img-thumbnail">';
  53. }
  54. } else {
  55. return is_string($v['value']) ? $v['value'] : join(',', $v['value']);
  56. }
  57. }
  58. return is_string($v) ? $v : json_encode($v);
  59. }, $info);
  60. return Table::make([], $info);
  61. })->xl();
  62. $grid->column('status', '订单状态')
  63. ->if(fn() => in_array($this->status, [OrderStatus::PAID, OrderStatus::PAID_RETAINAGE, OrderStatus::OFFLINE_PAID, OrderStatus::REFUSED_REFUND]))
  64. ->action(new VerificationOrder())
  65. ->else()
  66. ->using(OrderStatus::array());
  67. $grid->column('pay_type')->using(PayType::array());
  68. $grid->column('price');
  69. $grid->column('paid_money');
  70. $grid->column('收益')
  71. ->display(function () {
  72. if ($this->status == OrderStatus::SUCCESS && !empty($this->orderProductItem)) {
  73. $item = $this->orderProductItem->toArray();
  74. return bcadd(0, array_sum(array_column($item, 'price')), 2);
  75. }
  76. });
  77. $grid->column('paid_at');
  78. $grid->column('created_at');
  79. $grid->filter(function (Grid\Filter $filter) {
  80. $filter->panel();
  81. $filter->equal('id')->width(2);
  82. $filter->equal('mobile')->width(2);
  83. $filter->equal('order_no')->width(3);
  84. $filter->equal('status')->select(OrderStatus::array())->width(2);
  85. $option = Agent::query()->pluck('company_name', 'id');
  86. $filter->equal('agent_id', '代理商')->select($option)->width(3);
  87. $option = Supplier::query()->pluck('company_name', 'id');
  88. $filter->equal('product.supplier_id', '供应商')->select($option)->width(3);
  89. $filter->between('created_at')->datetime()->width(4);
  90. });
  91. });
  92. }
  93. /**
  94. * Make a show builder.
  95. *
  96. * @param mixed $id
  97. *
  98. * @return Show
  99. */
  100. protected function detail($id)
  101. {
  102. return Show::make($id, new Order(['agent:id,company_name', 'orderProductItem']), function (Show $show) {
  103. $show->disableDeleteButton();
  104. $show->disableQuickEdit();
  105. $show->disableEditButton();
  106. //不允许查看非自己的数据
  107. $show->model()->whereHas('orderProductItem', function ($query) {
  108. return $query->where('supplier_id', Admin::user()->id);
  109. });
  110. $show->field('id');
  111. $show->field('agent.company_name', '代理商');
  112. $show->field('mobile');
  113. $show->field('name');
  114. $show->field('num');
  115. $show->field('order_no');
  116. $show->field('paid_at');
  117. $show->field('paid_money');
  118. $show->field('pay_type')->using(PayType::array());
  119. $show->field('title');
  120. $show->field('picture')->image('', 80, 80);
  121. $show->field('price');
  122. $show->field('product_id');
  123. $show->field('status')->using(OrderStatus::array());
  124. $show->field('title');
  125. $show->field('user_id');
  126. $show->field('timeout');
  127. $show->field('created_at');
  128. $show->field('updated_at');
  129. });
  130. }
  131. /**
  132. * Make a form builder.
  133. *
  134. * @return Form
  135. */
  136. protected function form()
  137. {
  138. return Form::make(new Order('orderProductItem'), function (Form $form) {
  139. $form->disableDeleteButton();
  140. $form->disableFooter();
  141. $form->disableHeader();
  142. $form->display('id')->width(2);
  143. //订单不允许新增或编辑
  144. return $form->response()->error('操作禁止');
  145. })->saving(function (Form $form) {
  146. return $form->response()->error('操作禁止');
  147. })->deleting(function (Form $form) {
  148. return $form->response()->error('操作禁止');
  149. });
  150. }
  151. }