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

220 lines
7.0 KiB

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