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

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