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

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