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

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