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

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