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

216 lines
6.9 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\AdminGuide\Controllers;
  3. use App\AdminAgent\Actions\Grid\DemandConfirm;
  4. use App\AdminAgent\Lazys\DemandBiddingLazys;
  5. use App\Models\AgentProduct;
  6. use App\Models\Product;
  7. use App\Traits\ResponseHelper;
  8. use App\AdminAgent\Repositories\Demand;
  9. use App\Models\DemandBidding;
  10. use Dcat\Admin\Admin;
  11. use Dcat\Admin\Form;
  12. use Dcat\Admin\Grid;
  13. use Dcat\Admin\Show;
  14. use Dcat\Admin\Http\Controllers\AdminController;
  15. use App\Traits\DemandTraits;
  16. use Illuminate\Database\Eloquent\Model;
  17. use Illuminate\Http\Request;
  18. use Illuminate\Support\Arr;
  19. use Illuminate\Support\Facades\DB;
  20. use Illuminate\Support\Facades\Log;
  21. use Illuminate\Support\Facades\URL;
  22. class DemandController extends AdminController
  23. {
  24. use ResponseHelper;
  25. /**
  26. * Make a grid builder.
  27. *
  28. * @return Grid
  29. */
  30. protected function grid()
  31. {
  32. return Grid::make(new Demand(['publisher','biddingUser']), function (Grid $grid) {
  33. if (\request('self',0)) {
  34. $grid->model()->where(['publisher_id' => Admin::user()->id,'publisher_type' => DemandTraits::$col[2]]);
  35. } else {
  36. $grid->model()->where(['province_id' => Admin::user()->province_id]);
  37. }
  38. $grid->column('id')->sortable();
  39. $grid->column('title');
  40. $grid->column('detail','内容')->display('查看')->modal('详情',function ($modal) {
  41. $modal->xl();
  42. return $this->comment;
  43. });
  44. $grid->column('images','图片')->display(function ($image) {
  45. return json_decode($image,true);
  46. })->image('', 60, 60);
  47. $grid->column('deadline');
  48. $grid->column('publisher.name','发布人');
  49. $grid->column('publisher_type')->using(DemandTraits::$polymorphic);
  50. $grid->column('biddingUser.name','中标人');
  51. $grid->column('bidding_user_type','竞标用户类型')->using(DemandTraits::$polymorphic);
  52. $grid->column('price');
  53. $grid->column('stock');
  54. $grid->column('state')->using(DemandTraits::$state)->dot(
  55. [
  56. 1 => 'yellow',
  57. 2 => 'success',
  58. 3 => 'danger',
  59. ]
  60. );
  61. //$grid->setActionClass(Grid\Displayers\Actions::class);
  62. //
  63. //$grid->actions(function (Grid\Displayers\Actions $actions) {
  64. // $actions->append(new DemandConfirm(1));
  65. //});
  66. if (\request('self',0)) {
  67. $grid->column('bidding','竞标明细')
  68. ->display(function (){
  69. return '竞标数 : '. DemandBidding::query()->where('demand_id',$this->id)->count();
  70. })
  71. ->modal('竞标明细',function () {
  72. return DemandBiddingLazys::make(['demand_id' => $this->id]);
  73. });
  74. }else{
  75. $grid->column('bidding','竞标')
  76. ->if(function (){
  77. return $this->state == 1 && $this->bidding_user_type == DemandTraits::$col[2];
  78. })
  79. ->then(function (Grid\Column $column) {
  80. $column->append('<a class="btn btn-sm btn-primary" href="'.admin_url('/demand_bidding/create?demand_id='.$this->id).'">发起竞标</a>');
  81. });
  82. }
  83. $grid->column('created_at')->sortable();
  84. $grid->disableDeleteButton();
  85. $grid->disableEditButton();
  86. $grid->disableQuickEditButton();
  87. $grid->disableViewButton();
  88. //$grid->disableActions();
  89. $grid->filter(function (Grid\Filter $filter) {
  90. $filter->equal('id');
  91. $filter->equal('bidding_user_type','竞标用户类型')->select(DemandTraits::$polymorphic);
  92. });
  93. });
  94. }
  95. ///**
  96. // * Make a show builder.
  97. // *
  98. // * @param mixed $id
  99. // *
  100. // * @return Show
  101. // */
  102. //protected function detail($id)
  103. //{
  104. // return Show::make($id, new Demand(['publisher','biddingUser']), function (Show $show) {
  105. // $show->field('id');
  106. // $show->field('title');
  107. // $show->field('comment');
  108. // $show->field('images')->image();
  109. // $show->field('deadline');
  110. // $show->field('bidding_user_type','竞标用户类型')->using(DemandTraits::$polymorphic);
  111. // $show->field('price');
  112. // $show->field('stock');
  113. // $show->field('publisher_type')->using(DemandTraits::$polymorphic);
  114. // $show->field('publisher.name','发布人');
  115. // $show->field('state')->using(DemandTraits::$state)->dot(
  116. // [
  117. // 1 => 'yellow',
  118. // 2 => 'danger',
  119. // 3 => 'success',
  120. // ]
  121. // );;
  122. // $show->field('created_at');
  123. // });
  124. //}
  125. //
  126. ///**
  127. // * Make a form builder.
  128. // *
  129. // * @return Form
  130. // */
  131. //protected function form()
  132. //{
  133. // return Form::make(new Demand(), function (Form $form) {
  134. // $form->disableEditingCheck();
  135. // $form->disableCreatingCheck();
  136. // $form->disableViewCheck();
  137. // $form->display('id');
  138. // $form->text('title')->required();
  139. // $form->textarea('comment')->required();
  140. // $form->multipleImage('images','图片')->limit(5)->saving(function ($path) {
  141. // return json_encode($path);
  142. // });
  143. // $form->hidden('deadline')->required();
  144. // $form->select('bidding_user_type','竞标用户类型')
  145. // ->when([2],function (Form $form){
  146. // $form->select('demand_product_id','产品')->options(function (){
  147. // return Product::query()->whereIn('agent_id',[0,Admin::user()->id])->pluck('title','id');
  148. // });
  149. // })
  150. // ->options([
  151. // 1 => '供应商',
  152. // 2 => '地接'
  153. // ])
  154. // ->default(1)
  155. // ->required();
  156. // $form->decimal('price')->required();
  157. // $form->number('stock')->required();
  158. // $form->hidden('publisher_type')->required();
  159. // $form->hidden('publisher_id')->required();
  160. // $form->saving(function (Form $form) {
  161. // // 判断是否是新增操作
  162. // if ($form->isCreating()) {
  163. // if ($form->bidding_user_type != 2) {
  164. // $form->demand_product_id = 0;
  165. // }
  166. // $form->bidding_user_type = DemandTraits::$col[$form->bidding_user_type];
  167. // //处理流拍时间
  168. // $form->deadline = now()->addDays(5);
  169. // //发布人身份
  170. // $form->publisher_type = DemandTraits::$col[2];
  171. // $form->publisher_id = Admin::user()->id;
  172. // }
  173. // });
  174. // });
  175. //}
  176. //public function binding()
  177. //{
  178. // $demandBiddingId = request('demand_bidding_id',0);
  179. // $demandBidding = DemandBidding::find($demandBiddingId);
  180. // if (empty($demandBidding)) {
  181. // return false;
  182. // }
  183. //
  184. // $demand = \App\Models\Demand::find($demandBidding->demand_id);
  185. //
  186. // if (empty($demand)) {
  187. // return false;
  188. // }
  189. //
  190. // DB::beginTransaction();
  191. // try {
  192. // $demandBidding->state = 1;
  193. // $demandBidding->save();
  194. // //改变订单状态
  195. // $demand->bidding_id = $demandBidding->id;
  196. // $demand->bidding_user_id = $demandBidding->bidding_user_id;
  197. // $demand->state = DemandTraits::$stateKey[1];
  198. // $demand->save();
  199. // DB::commit();
  200. // } catch (\Exception $e) {
  201. // Log::error('选中竞标失败::'.$e->getTraceAsString());
  202. // DB::rollBack();
  203. // return $this->jsonFail(1001,'选中竞标失败,稍后重试或联系管理员!'.$e->getMessage());
  204. // }
  205. // return back();
  206. //}
  207. }