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

139 lines
4.1 KiB

  1. <?php
  2. namespace App\Admin\Controllers;
  3. use App\Admin\Repositories\Order;
  4. use App\Models\Agent;
  5. use App\Models\Supplier;
  6. use App\Common\OrderStatus;
  7. use Dcat\Admin\Form;
  8. use Dcat\Admin\Grid;
  9. use Dcat\Admin\Show;
  10. use Dcat\Admin\Http\Controllers\AdminController;
  11. use Dcat\Admin\Widgets\Table;
  12. class OrderController extends AdminController
  13. {
  14. /**
  15. * Make a grid builder.
  16. *
  17. * @return Grid
  18. */
  19. protected function grid()
  20. {
  21. return Grid::make(new Order([
  22. 'agent:id,agent_name',
  23. 'agentProduct.product:id,title,price,pictures',
  24. 'product.supplier:id,supplier_name'
  25. ]), function (Grid $grid) {
  26. $grid->disableCreateButton();
  27. $grid->disableDeleteButton();
  28. $grid->column('id')->sortable();
  29. $grid->column('order_no');
  30. $grid->column('agent.agent_name');
  31. $grid->column('mobile');
  32. $grid->column('name');
  33. $grid->column('product', '产品信息')
  34. ->display('查看')
  35. ->modal('购买产品信息', function ($modal) {
  36. return Table::make([
  37. '产品名称',
  38. '产品图片',
  39. '购买数量',
  40. '所属代理商',
  41. '所属供应商',
  42. ], [[
  43. $this->title,
  44. '<img data-action="preview-img" src="'.$this->picture.'" style="max-width:120px;max-height:200px;cursor:pointer" class="img img-thumbnail">',
  45. $this->num,
  46. $this->agent->agent_name,
  47. $this->product->supplier->supplier_name,
  48. ]]);
  49. })->xl();
  50. $grid->column('paid_money');
  51. $grid->column('price');
  52. // $grid->column('refund_info');
  53. $grid->column('pay_type')
  54. ->using([0 => '在线支付', 1 => '定金支付', 2 => '首款支付', 3 => '线下支付']);
  55. $grid->column('status', '订单状态')
  56. ->select(OrderStatus::array());
  57. $grid->column('paid_at')->display(fn($v) => date('Y-m-d H:i:s', $v));
  58. $grid->column('created_at')->display(fn($v) => $v);
  59. $grid->column('updated_at')->display(fn($v) => $v);
  60. $grid->filter(function (Grid\Filter $filter) {
  61. $filter->panel();
  62. $filter->equal('id')->width(2);
  63. $filter->equal('mobile')->width(2);
  64. $filter->equal('order_no')->width(3);
  65. $filter->equal('status')->select(OrderStatus::array())->width(2);
  66. $option = Agent::query()->pluck('agent_name', 'id');
  67. $filter->equal('agent_id', '代理商')->select($option)->width(3);
  68. $option = Supplier::query()->pluck('supplier_name', 'id');
  69. $filter->equal('product.supplier_id', '供应商')->select($option)->width(3);
  70. $filter->between('created_at')->width(4);
  71. });
  72. });
  73. }
  74. /**
  75. * Make a show builder.
  76. *
  77. * @param mixed $id
  78. *
  79. * @return Show
  80. */
  81. protected function detail($id)
  82. {
  83. return Show::make($id, new Order(), function (Show $show) {
  84. $show->disableDeleteButton();
  85. $show->disableQuickEdit();
  86. $show->field('id');
  87. $show->field('agent.agent_name');
  88. $show->field('mobile');
  89. $show->field('name');
  90. $show->field('num');
  91. $show->field('order_no');
  92. $show->field('paid_at')->as(fn ($v) => date('Y-m-d H:i:s', $v));
  93. $show->field('paid_money');
  94. $show->field('pay_type');
  95. $show->field('title');
  96. $show->field('picture')->image();
  97. $show->field('price');
  98. $show->field('product_id');
  99. $show->field('status')->using(OrderStatus::array());
  100. $show->field('title');
  101. $show->field('user_id');
  102. $show->field('created_at')->as(fn ($v) => date('Y-m-d H:i:s', $v));
  103. $show->field('updated_at')->as(fn ($v) => date('Y-m-d H:i:s', $v));
  104. });
  105. }
  106. /**
  107. * Make a form builder.
  108. *
  109. * @return Form
  110. */
  111. protected function form()
  112. {
  113. return Form::make(new Order(), function (Form $form) {
  114. $form->disableDeleteButton();
  115. $form->display('id')->width(2);
  116. $form->mobile('mobile');
  117. $form->text('name')->width(2);
  118. $form->select('status')->options(OrderStatus::array())->width(2);
  119. });
  120. }
  121. public function destroy($id)
  122. {
  123. return false;
  124. }
  125. }