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

157 lines
4.6 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
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,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.name', '代理商');
  39. $grid->column('order_no', '订单号')->limit(10);
  40. $grid->column('title')->limit(20);
  41. $grid->column('picture')->image('', 60, 60);
  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('paid_money');
  63. $grid->column('price');
  64. // $grid->column('refund_info');
  65. $grid->column('pay_type')->using(PayType::array());
  66. $grid->column('status', '订单状态')->using(OrderStatus::array());
  67. $grid->column('paid_at');
  68. $grid->column('created_at');
  69. $grid->filter(function (Grid\Filter $filter) {
  70. $filter->panel();
  71. $filter->equal('id')->width(2);
  72. $filter->equal('mobile')->width(2);
  73. $filter->equal('order_no')->width(3);
  74. $filter->equal('status')->select(OrderStatus::array())->width(2);
  75. $option = Agent::query()->pluck('name', 'id');
  76. $filter->equal('agent_id', '代理商')->select($option)->width(3);
  77. $option = Supplier::query()->pluck('name', 'id');
  78. $filter->equal('product.supplier_id', '供应商')->select($option)->width(3);
  79. $filter->between('created_at')->datetime()->width(4);
  80. });
  81. });
  82. }
  83. /**
  84. * Make a show builder.
  85. *
  86. * @param mixed $id
  87. *
  88. * @return Show
  89. */
  90. protected function detail($id)
  91. {
  92. return Show::make($id, new Order(['agent:id,name', 'orderProductItem']), function (Show $show) {
  93. $show->disableDeleteButton();
  94. $show->disableQuickEdit();
  95. $show->disableEditButton();
  96. //不允许查看非自己的数据
  97. $show->model()->whereHas('orderProductItem', function ($query) {
  98. return $query->where('supplier_id', Admin::user()->id);
  99. });
  100. $show->field('id');
  101. $show->field('agent.name');
  102. $show->field('mobile');
  103. $show->field('name');
  104. $show->field('num');
  105. $show->field('order_no');
  106. $show->field('paid_at');
  107. $show->field('paid_money');
  108. $show->field('pay_type')->using(PayType::array());
  109. $show->field('title');
  110. $show->field('picture')->image('', 80, 80);
  111. $show->field('price');
  112. $show->field('product_id');
  113. $show->field('status')->using(OrderStatus::array());
  114. $show->field('title');
  115. $show->field('user_id');
  116. $show->field('timeout');
  117. $show->field('created_at');
  118. $show->field('updated_at');
  119. });
  120. }
  121. /**
  122. * Make a form builder.
  123. *
  124. * @return Form
  125. */
  126. protected function form()
  127. {
  128. return Form::make(new Order('orderProductItem'), function (Form $form) {
  129. $form->disableDeleteButton();
  130. $form->disableFooter();
  131. $form->disableHeader();
  132. $form->display('id')->width(2);
  133. //订单不允许新增或编辑
  134. return $form->response()->error('操作禁止');
  135. })->saving(function (Form $form) {
  136. return $form->response()->error('操作禁止');
  137. })->deleting(function (Form $form) {
  138. return $form->response()->error('操作禁止');
  139. });
  140. }
  141. }