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

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