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

225 lines
7.1 KiB

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