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

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