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

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