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

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