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

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