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

235 lines
7.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
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. ->if(function () {
  74. $isBidding = DemandBidding::query()
  75. ->where('demand_id',$this->id)
  76. ->where([
  77. 'bidding_user_type' => DemandTraits::$col[2],
  78. 'bidding_user_id' => Admin::user()->id
  79. ])
  80. ->exists();
  81. return $this->state == 1 && $this->bidding_user_type == DemandTraits::$col[2] && $isBidding;
  82. })
  83. ->then(function (Grid\Column $column) {
  84. $column->display('已竞标');
  85. })
  86. ->if(function (){
  87. $isNotBidding = DemandBidding::query()
  88. ->where('demand_id',$this->id)
  89. ->where([
  90. 'bidding_user_type' => DemandTraits::$col[2],
  91. 'bidding_user_id' => Admin::user()->id
  92. ])
  93. ->doesntExist();
  94. return $this->state == 1 && $this->bidding_user_type == DemandTraits::$col[2] && $isNotBidding;
  95. })
  96. ->then(function (Grid\Column $column) {
  97. $column->append('<a class="btn btn-sm btn-primary" href="'.admin_url('/demand_bidding/create?demand_id='.$this->id).'">参与竞标</a>');
  98. });
  99. }
  100. $grid->column('created_at')->sortable();
  101. $grid->disableDeleteButton();
  102. $grid->disableEditButton();
  103. $grid->disableCreateButton();
  104. $grid->disableQuickEditButton();
  105. $grid->disableViewButton();
  106. $grid->disableRowSelector();
  107. //$grid->disableActions();
  108. $grid->filter(function (Grid\Filter $filter) {
  109. $filter->equal('id');
  110. $filter->equal('bidding_user_type','竞标用户类型')->select(DemandTraits::$polymorphic);
  111. });
  112. });
  113. }
  114. ///**
  115. // * Make a show builder.
  116. // *
  117. // * @param mixed $id
  118. // *
  119. // * @return Show
  120. // */
  121. //protected function detail($id)
  122. //{
  123. // return Show::make($id, new Demand(['publisher','biddingUser']), function (Show $show) {
  124. // $show->field('id');
  125. // $show->field('title');
  126. // $show->field('comment');
  127. // $show->field('images')->image();
  128. // $show->field('deadline');
  129. // $show->field('bidding_user_type','竞标用户类型')->using(DemandTraits::$polymorphic);
  130. // $show->field('price');
  131. // $show->field('stock');
  132. // $show->field('publisher_type')->using(DemandTraits::$polymorphic);
  133. // $show->field('publisher.name','发布人');
  134. // $show->field('state')->using(DemandTraits::$state)->dot(
  135. // [
  136. // 1 => 'yellow',
  137. // 2 => 'danger',
  138. // 3 => 'success',
  139. // ]
  140. // );;
  141. // $show->field('created_at');
  142. // });
  143. //}
  144. //
  145. ///**
  146. // * Make a form builder.
  147. // *
  148. // * @return Form
  149. // */
  150. //protected function form()
  151. //{
  152. // return Form::make(new Demand(), function (Form $form) {
  153. // $form->disableEditingCheck();
  154. // $form->disableCreatingCheck();
  155. // $form->disableViewCheck();
  156. // $form->display('id');
  157. // $form->text('title')->required();
  158. // $form->textarea('comment')->required();
  159. // $form->multipleImage('images','图片')->limit(5)->saving(function ($path) {
  160. // return json_encode($path);
  161. // });
  162. // $form->hidden('deadline')->required();
  163. // $form->select('bidding_user_type','竞标用户类型')
  164. // ->when([2],function (Form $form){
  165. // $form->select('demand_product_id','产品')->options(function (){
  166. // return Product::query()->whereIn('agent_id',[0,Admin::user()->id])->pluck('title','id');
  167. // });
  168. // })
  169. // ->options([
  170. // 1 => '供应商',
  171. // 2 => '地接'
  172. // ])
  173. // ->default(1)
  174. // ->required();
  175. // $form->decimal('price')->required();
  176. // $form->number('stock')->required();
  177. // $form->hidden('publisher_type')->required();
  178. // $form->hidden('publisher_id')->required();
  179. // $form->saving(function (Form $form) {
  180. // // 判断是否是新增操作
  181. // if ($form->isCreating()) {
  182. // if ($form->bidding_user_type != 2) {
  183. // $form->demand_product_id = 0;
  184. // }
  185. // $form->bidding_user_type = DemandTraits::$col[$form->bidding_user_type];
  186. // //处理流拍时间
  187. // $form->deadline = now()->addDays(5);
  188. // //发布人身份
  189. // $form->publisher_type = DemandTraits::$col[2];
  190. // $form->publisher_id = Admin::user()->id;
  191. // }
  192. // });
  193. // });
  194. //}
  195. //public function binding()
  196. //{
  197. // $demandBiddingId = request('demand_bidding_id',0);
  198. // $demandBidding = DemandBidding::find($demandBiddingId);
  199. // if (empty($demandBidding)) {
  200. // return false;
  201. // }
  202. //
  203. // $demand = \App\Models\Demand::find($demandBidding->demand_id);
  204. //
  205. // if (empty($demand)) {
  206. // return false;
  207. // }
  208. //
  209. // DB::beginTransaction();
  210. // try {
  211. // $demandBidding->state = 1;
  212. // $demandBidding->save();
  213. // //改变订单状态
  214. // $demand->bidding_id = $demandBidding->id;
  215. // $demand->bidding_user_id = $demandBidding->bidding_user_id;
  216. // $demand->state = DemandTraits::$stateKey[1];
  217. // $demand->save();
  218. // DB::commit();
  219. // } catch (\Exception $e) {
  220. // Log::error('选中竞标失败::'.$e->getTraceAsString());
  221. // DB::rollBack();
  222. // return $this->jsonFail(1001,'选中竞标失败,稍后重试或联系管理员!'.$e->getMessage());
  223. // }
  224. // return back();
  225. //}
  226. }