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

163 lines
5.3 KiB

4 years ago
4 years ago
4 years ago
  1. <?php
  2. namespace App\AdminSupplier\Controllers;
  3. use App\AdminSupplier\Extensions\Grid\IndustryOrderAudit;
  4. use App\AdminSupplier\Extensions\Grid\IndustryOrderStatus;
  5. use App\AdminSupplier\Repositories\IndustryOrder;
  6. use App\Common\OrderStatus;
  7. use App\Common\PayType;
  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 IndustryOrderController extends AdminController
  15. {
  16. /**
  17. * Make a grid builder.
  18. *
  19. * @return Grid
  20. */
  21. protected function grid()
  22. {
  23. return Grid::make(new IndustryOrder(['agent:id,company_name', 'spec']), function (Grid $grid) {
  24. $grid->disableCreateButton();
  25. $grid->disableRowSelector();
  26. $grid->disableActions();
  27. $grid->model()->where('supplier_id', Admin::user()->id);
  28. $grid->column('id')->sortable();
  29. $grid->column('agent.company_name', '代理商名称')->limit(10);
  30. $grid->column('order_no')->limit(10);
  31. $grid->column('num');
  32. $grid->column('price');
  33. $grid->column('name');
  34. $grid->column('mobile');
  35. $grid->column('info', '信息收集')
  36. ->display('查看')
  37. ->modal('信息收集', function ($modal) {
  38. $modal->xl();
  39. $info = $this->info ?? [];
  40. $info = array_map(function($v) {
  41. if (isset($v['value'], $v['type'])) {
  42. if ($v['type'] == 'image') {
  43. if (is_array($v['value'])) {
  44. 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;');
  45. } else {
  46. return '<img data-action="preview-img" src="' . $v['value'] . '" style="max-width:120px;max-height:200px;cursor:pointer" class="img img-thumbnail">';
  47. }
  48. } else {
  49. return is_string($v['value']) ? $v['value'] : join(',', $v['value']);
  50. }
  51. }
  52. return is_string($v) ? $v : json_encode($v);
  53. }, $info);
  54. return Table::make([], $info);
  55. });
  56. $grid->column('规格信息')
  57. ->display('查看')
  58. ->modal('规格信息', function ($model) {
  59. $info = [
  60. ['规格名称', $this->spec->name ?? ''],
  61. ['规格日期', $this->spec->date ?? ''],
  62. ];
  63. return Table::make([], $info);
  64. });
  65. $grid->column('industry_product_id', '产品ID');
  66. $grid->column('title')->limit(15);
  67. $grid->column('pay_type')->using(PayType::array());
  68. $grid->column('status')
  69. ->using(OrderStatus::array())
  70. //审核拒绝
  71. ->if(fn() => $this->audit_status == -1)
  72. ->then(function ($column) {
  73. $column->display('已拒绝')->label();
  74. })
  75. //审核通过
  76. ->if(fn() => $this->audit_status == 1)
  77. ->then(function ($column) {
  78. if ($this->status == OrderStatus::OFFLINE_UNPAID) {
  79. $column->action(new IndustryOrderStatus);
  80. } else {
  81. $column->display(OrderStatus::array()[$this->status]);
  82. }
  83. });
  84. $grid->column('操作')
  85. //待审核
  86. ->if(fn() => $this->audit_status == 0)
  87. ->then(function ($column) {
  88. $column->append((new IndustryOrderAudit(null, 1))->setKey($this->id))->append('&nbsp;');
  89. $column->append((new IndustryOrderAudit(null, 2))->setKey($this->id));
  90. })
  91. ->if(fn() => !empty($this->show_qrcode))
  92. ->then(function ($column) {
  93. $verify_code = $this->id . '-' . $this->verify_code;
  94. $column->append(admin_url('industry_order/qrcode', $verify_code))->image('', 60, 60);
  95. $column->append('<br>' . $verify_code . '<br>');
  96. });
  97. $grid->column('paid_at')->width(100);
  98. $grid->column('created_at')->width(100);
  99. $grid->filter(function (Grid\Filter $filter) {
  100. $filter->equal('id')->width(2);
  101. $filter->equal('order_no')->width(3);
  102. });
  103. });
  104. }
  105. public function qrcode()
  106. {
  107. return (new \App\AdminAgent\Controllers\IndustryOrderController)->qrcode();
  108. }
  109. /**
  110. * Make a show builder.
  111. *
  112. * @param mixed $id
  113. *
  114. * @return Show
  115. */
  116. protected function detail($id)
  117. {
  118. /*return Show::make($id, new IndustryOrder(), function (Show $show) {
  119. $show->field('id');
  120. $show->field('agent_id');
  121. $show->field('supplier_id');
  122. $show->field('order_no');
  123. $show->field('industry_product_id');
  124. $show->field('num');
  125. $show->field('price');
  126. $show->field('name');
  127. $show->field('mobile');
  128. $show->field('title');
  129. $show->field('picture');
  130. $show->field('status');
  131. $show->field('paid_at');
  132. $show->field('verify_code');
  133. $show->field('timeout');
  134. $show->field('created_at');
  135. $show->field('updated_at');
  136. });*/
  137. }
  138. /**
  139. * Make a form builder.
  140. *
  141. * @return Form
  142. */
  143. protected function form()
  144. {
  145. return Form::make(new IndustryOrder(), function (Form $form) {
  146. $form->display('id');
  147. // $form->select('status')->options([OrderStatus::OFFLINE_PAID => '已付款']);
  148. })->saving(function(Form $form) {
  149. return $form->response()->error('操作禁止');
  150. })->deleting(function(Form $form) {
  151. return $form->response()->error('操作禁止');
  152. });
  153. }
  154. }