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

213 lines
6.5 KiB

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