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

228 lines
7.1 KiB

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');
  137. $form->textarea('comment');
  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. }else{
  155. $form->select('bidding_user_type', '竞标用户类型')
  156. ->options([
  157. 1 => '供应商',
  158. ])
  159. ->default(1);
  160. }
  161. $form->decimal('price');
  162. $form->number('stock');
  163. $form->hidden('publisher_type');
  164. $form->hidden('publisher_id');
  165. $form->saving(function (Form $form) {
  166. // 判断是否是新增操作
  167. if ($form->isCreating()) {
  168. if ($form->bidding_user_type != 2) {
  169. $form->demand_product_id = 0;
  170. }
  171. $form->bidding_user_type = DemandTraits::$col[$form->bidding_user_type];
  172. //处理流拍时间
  173. $form->deadline = now()->addDays(5);
  174. //发布人身份
  175. $form->publisher_type = DemandTraits::$col[0];
  176. $form->publisher_id = Admin::user()->id;
  177. }
  178. });
  179. });
  180. }
  181. //public function binding()
  182. //{
  183. // $demandBiddingId = request('demand_bidding_id',0);
  184. // $demandBidding = DemandBidding::find($demandBiddingId);
  185. // if (empty($demandBidding)) {
  186. // return false;
  187. // }
  188. //
  189. // $demand = \App\Models\Demand::find($demandBidding->demand_id);
  190. //
  191. // if (empty($demand)) {
  192. // return false;
  193. // }
  194. //
  195. // DB::beginTransaction();
  196. // try {
  197. // $demandBidding->state = 1;
  198. // $demandBidding->save();
  199. // //改变订单状态
  200. // $demand->bidding_id = $demandBidding->id;
  201. // $demand->bidding_user_id = $demandBidding->bidding_user_id;
  202. // $demand->state = DemandTraits::$stateKey[1];
  203. // $demand->save();
  204. // //如果是地接类型 绑定地接到订单
  205. // if ($demand->bidding_user_type == DemandTraits::$col[2]){
  206. // $agentProduct = AgentProduct::find($demand->agent_product_id);
  207. // $agentProduct->guide_id = $demandBidding->bidding_user_id;
  208. // $agentProduct->save();
  209. // }
  210. // DB::commit();
  211. // } catch (\Exception $e) {
  212. // Log::error('选中竞标失败::'.$e->getTraceAsString());
  213. // DB::rollBack();
  214. // return $this->jsonFail(1001,'选中竞标失败,稍后重试或联系管理员!'.$e->getMessage());
  215. // }
  216. // return back();
  217. //}
  218. }