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

132 lines
3.9 KiB

  1. <?php
  2. namespace App\AdminAgent\Controllers;
  3. use App\AdminAgent\Lazys\DemandBiddingLazys;
  4. use App\AdminAgent\Repositories\Demand;
  5. use App\Models\DemandBidding;
  6. use Dcat\Admin\Admin;
  7. use Dcat\Admin\Form;
  8. use Dcat\Admin\Grid;
  9. use Dcat\Admin\Show;
  10. use Dcat\Admin\Http\Controllers\AdminController;
  11. use App\Traits\DemandTraits;
  12. use Illuminate\Support\Arr;
  13. class MyDemandController extends AdminController
  14. {
  15. /**
  16. * Make a grid builder.
  17. *
  18. * @return Grid
  19. */
  20. protected function grid()
  21. {
  22. return Grid::make(new Demand(['publisher','biddingUser']), function (Grid $grid) {
  23. $grid->model()->where(['publisher_id' => Admin::user()->id,'publisher_type' => Arr::first(DemandTraits::$col)]);
  24. $grid->column('id')->sortable();
  25. $grid->column('title');
  26. $grid->column('detail','内容')->display('查看')->modal('详情',function ($modal) {
  27. $modal->xl();
  28. return $this->comment;
  29. });
  30. $grid->column('images','图片')->display(function ($image) {
  31. return json_decode($image,true);
  32. })->image();
  33. $grid->column('deadline');
  34. $grid->column('biddingUser.name','中标人');
  35. $grid->column('bidding_user_type','竞标用户类型')->using(DemandTraits::$polymorphic);
  36. $grid->column('price');
  37. $grid->column('stock');
  38. $grid->column('state')->using(DemandTraits::$state)->dot(
  39. [
  40. 1 => 'yellow',
  41. 2 => 'success',
  42. 3 => 'danger',
  43. ]
  44. );
  45. $grid->column('bidding','竞标明细')
  46. ->display(function (){
  47. return '竞标数 : '. DemandBidding::query()->where('demand_id',$this->id)->count();
  48. })
  49. ->modal('竞标明细',function () {
  50. return DemandBiddingLazys::make(['demand_id' => $this->id]);
  51. });
  52. $grid->column('created_at')->sortable();
  53. $grid->disableDeleteButton();
  54. $grid->disableEditButton();
  55. $grid->disableQuickEditButton();
  56. $grid->disableViewButton();
  57. $grid->disableActions();
  58. $grid->filter(function (Grid\Filter $filter) {
  59. $filter->equal('id');
  60. $filter->equal('bidding_user_type','竞标用户类型')->select(DemandTraits::$polymorphic);
  61. });
  62. });
  63. }
  64. /**
  65. * Make a show builder.
  66. *
  67. * @param mixed $id
  68. *
  69. * @return Show
  70. */
  71. protected function detail($id)
  72. {
  73. return Show::make($id, new Demand(['publisher','biddingUser']), function (Show $show) {
  74. $show->field('id');
  75. $show->field('title');
  76. $show->field('comment');
  77. $show->field('images')->image();
  78. $show->field('deadline');
  79. $show->field('bidding_user_type','竞标用户类型')->using(DemandTraits::$polymorphic);
  80. $show->field('price');
  81. $show->field('stock');
  82. $show->field('state')->using(DemandTraits::$state)->dot(
  83. [
  84. 1 => 'yellow',
  85. 2 => 'danger',
  86. 3 => 'success',
  87. ]
  88. );;
  89. $show->field('created_at');
  90. });
  91. }
  92. /**
  93. * Make a form builder.
  94. *
  95. * @return Form
  96. */
  97. protected function form()
  98. {
  99. return Form::make(new Demand(), function (Form $form) {
  100. $form->display('id');
  101. $form->text('title');
  102. $form->text('comment');
  103. $form->multipleImage('images','图片');
  104. $form->hidden('deadline');
  105. $form->select('bidding_user_type','竞标用户类型')->options([
  106. 'App\models\Supplier' => '供应商',
  107. 'App\models\Guides' => '地接'
  108. ]);
  109. $form->decimal('price');
  110. $form->number('stock');
  111. $form->hidden('publisher_type');
  112. $form->hidden('publisher_id');
  113. $form->saving(function (Form $form) {
  114. // 判断是否是新增操作
  115. if ($form->isCreating()) {
  116. //处理流拍时间
  117. $form->deadline = now()->addDays(5);
  118. //发布人身份
  119. $form->publisher_type = 'App\models\Agent';
  120. $form->publisher_id = Admin::user()->id;
  121. }
  122. });
  123. });
  124. }
  125. }