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

124 lines
3.5 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
  1. <?php
  2. namespace App\AdminAgent\Controllers;
  3. use App\AdminAgent\Repositories\DemandBidding;
  4. use App\Models\Demand;
  5. use App\Traits\DemandTraits;
  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 http\Env\Request;
  12. use Illuminate\Support\Arr;
  13. class DemandBiddingController extends AdminController
  14. {
  15. /**
  16. * Make a grid builder.
  17. *
  18. * @return Grid
  19. */
  20. protected function grid()
  21. {
  22. return Grid::make(new DemandBidding(['demand']), function (Grid $grid) {
  23. $grid->model()->where(['bidding_user_id' => Admin::user()->id,'bidding_user_type' => Arr::first(DemandTraits::$col)]);
  24. $grid->column('id')->sortable();
  25. $grid->column('price');
  26. $grid->column('comment');
  27. $grid->column('demand.title','竞拍标题');
  28. $grid->column('demand.comment','竞拍内容')
  29. ->display('查看')
  30. ->modal('详情',function ($modal) {
  31. $modal->xl();
  32. return $this->demand->comment;
  33. });
  34. $grid->column('state','状态')->using(DemandTraits::$biddingState)->dot(
  35. [
  36. 'yellow',
  37. 'success',
  38. 'danger',
  39. ]
  40. );
  41. $grid->column('created_at');
  42. $grid->column('updated_at')->sortable();
  43. $grid->disableDeleteButton();
  44. $grid->disableEditButton();
  45. $grid->disableQuickEditButton();
  46. $grid->disableViewButton();
  47. $grid->disableCreateButton();
  48. $grid->disableActions();
  49. $grid->disableRowSelector();
  50. $grid->filter(function (Grid\Filter $filter) {
  51. $filter->equal('id');
  52. });
  53. });
  54. }
  55. /**
  56. * Make a show builder.
  57. *
  58. * @param mixed $id
  59. *
  60. * @return Show
  61. */
  62. protected function detail($id)
  63. {
  64. return Show::make($id, new DemandBidding(), function (Show $show) {
  65. $show->field('id');
  66. $show->field('price');
  67. $show->field('comment');
  68. $show->field('created_at');
  69. $show->field('updated_at');
  70. });
  71. }
  72. /**
  73. * Make a form builder.
  74. *
  75. * @return Form
  76. */
  77. protected function form()
  78. {
  79. return Form::make(new DemandBidding(), function (Form $form) {
  80. $demand_id = request('demand_id');
  81. $isBidding = \App\Models\DemandBidding::query()
  82. ->where('demand_id',$demand_id)
  83. ->where([
  84. 'bidding_user_type' => DemandTraits::$col[0],
  85. 'bidding_user_id' => Admin::user()->id
  86. ])
  87. ->exists();
  88. if ($demand_id && $isBidding) {
  89. Admin::exit('你已经竞标过了,无需重复参加');
  90. }
  91. $form->disableEditingCheck();
  92. $form->disableCreatingCheck();
  93. $form->disableViewCheck();
  94. $form->display('id');
  95. $form->text('price')->required();
  96. $form->textarea('comment')->required();
  97. $form->hidden('demand_id')->value(request('demand_id',0));
  98. $form->hidden('bidding_user_type');
  99. $form->hidden('bidding_user_id');
  100. $form->saving(function (Form $form) {
  101. $provinceId = Demand::query()->where('id',$this->demand_id)->value('province_id');
  102. if ($provinceId != Admin::user()->province_id) {
  103. $form->response()->error('竞标失败,只能竞标跟自己相同省份的的需求');
  104. }
  105. // 判断是否是新增操作
  106. if ($form->isCreating()) {
  107. //发布人身份
  108. $form->bidding_user_type = DemandTraits::$col[0];
  109. $form->bidding_user_id = Admin::user()->id;
  110. }
  111. $form->response()->success('操作成功')->redirect('demand_bidding');
  112. });
  113. });
  114. }
  115. }