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

233 lines
7.3 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
  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. ->if(function (){
  78. return $this->state == 1 && $this->bidding_user_type == Arr::first(DemandTraits::$col);
  79. })
  80. ->then(function (Grid\Column $column) {
  81. $column->append('<a class="btn btn-sm btn-primary" href="'.admin_url('/demand_bidding/create?demand_id='.$this->id).'">发起竞标</a>');
  82. });
  83. }
  84. $grid->column('created_at')->sortable();
  85. $grid->disableDeleteButton();
  86. $grid->disableEditButton();
  87. $grid->disableQuickEditButton();
  88. $grid->disableViewButton();
  89. //$grid->disableActions();
  90. $grid->filter(function (Grid\Filter $filter) {
  91. $filter->equal('id');
  92. $filter->equal('bidding_user_type','竞标用户类型')->select(DemandTraits::$polymorphic);
  93. });
  94. });
  95. }
  96. /**
  97. * Make a show builder.
  98. *
  99. * @param mixed $id
  100. *
  101. * @return Show
  102. */
  103. protected function detail($id)
  104. {
  105. return Show::make($id, new Demand(['publisher','biddingUser']), function (Show $show) {
  106. $show->field('id');
  107. $show->field('title');
  108. $show->field('comment');
  109. $show->field('images')->image();
  110. $show->field('deadline');
  111. $show->field('bidding_user_type','竞标用户类型')->using(DemandTraits::$polymorphic);
  112. $show->field('price');
  113. $show->field('stock');
  114. $show->field('publisher_type')->using(DemandTraits::$polymorphic);
  115. $show->field('publisher.name','发布人');
  116. $show->field('state')->using(DemandTraits::$state)->dot(
  117. [
  118. 1 => 'yellow',
  119. 2 => 'danger',
  120. 3 => 'success',
  121. ]
  122. );;
  123. $show->field('created_at');
  124. });
  125. }
  126. /**
  127. * Make a form builder.
  128. *
  129. * @return Form
  130. */
  131. protected function form()
  132. {
  133. return Form::make(new Demand(), function (Form $form) {
  134. $form->disableEditingCheck();
  135. $form->disableCreatingCheck();
  136. $form->disableViewCheck();
  137. $form->display('id');
  138. $form->text('title')->required();
  139. $form->textarea('comment')->required();
  140. $form->distpicker(['province_id', 'city_id', 'area_id'], '请选择区域')->required();
  141. $form->multipleImage('images','图片')->limit(5)->saving(function ($path) {
  142. return json_encode($path);
  143. });
  144. $form->hidden('deadline');
  145. if (Admin::user()->type == AgentType::CLUSTER) {
  146. $form->select('bidding_user_type', '竞标用户类型')
  147. ->when([2], function (Form $form) {
  148. $form->select('agent_product_id', '产品')->options(function () {
  149. return AgentProduct::query()->where('agent_id', Admin::user()->id)->where('status', 1)->pluck('title', 'id');
  150. });
  151. })
  152. ->options([
  153. 1 => '供应商',
  154. 2 => '地接'
  155. ])
  156. ->default(1)
  157. ->required();
  158. }else{
  159. $form->select('bidding_user_type', '竞标用户类型')
  160. ->options([
  161. 1 => '供应商',
  162. ])
  163. ->default(1)
  164. ->required();
  165. }
  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[0];
  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. // $demandBidding->state = 1;
  203. // $demandBidding->save();
  204. // //改变订单状态
  205. // $demand->bidding_id = $demandBidding->id;
  206. // $demand->bidding_user_id = $demandBidding->bidding_user_id;
  207. // $demand->state = DemandTraits::$stateKey[1];
  208. // $demand->save();
  209. // //如果是地接类型 绑定地接到订单
  210. // if ($demand->bidding_user_type == DemandTraits::$col[2]){
  211. // $agentProduct = AgentProduct::find($demand->agent_product_id);
  212. // $agentProduct->guide_id = $demandBidding->bidding_user_id;
  213. // $agentProduct->save();
  214. // }
  215. // DB::commit();
  216. // } catch (\Exception $e) {
  217. // Log::error('选中竞标失败::'.$e->getTraceAsString());
  218. // DB::rollBack();
  219. // return $this->jsonFail(1001,'选中竞标失败,稍后重试或联系管理员!'.$e->getMessage());
  220. // }
  221. // return back();
  222. //}
  223. }