From 50c158cc1e8454adf83508d214e48ed550d057eb Mon Sep 17 00:00:00 2001 From: lemon <15040771@qq.com> Date: Sun, 29 Aug 2021 11:33:36 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9C=B0=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/DemandBiddingController.php | 4 +- .../Controllers/DemandController.php | 8 +- .../Controllers/DemandBiddingController.php | 99 ++++++++ .../Controllers/DemandController.php | 213 ++++++++++++++++++ app/AdminGuide/Repositories/Demand.php | 16 ++ app/AdminGuide/Repositories/DemandBidding.php | 16 ++ app/AdminGuide/routes.php | 2 + 7 files changed, 356 insertions(+), 2 deletions(-) create mode 100755 app/AdminGuide/Controllers/DemandBiddingController.php create mode 100755 app/AdminGuide/Controllers/DemandController.php create mode 100755 app/AdminGuide/Repositories/Demand.php create mode 100755 app/AdminGuide/Repositories/DemandBidding.php diff --git a/app/AdminAgent/Controllers/DemandBiddingController.php b/app/AdminAgent/Controllers/DemandBiddingController.php index 1796d1a..d59d320 100755 --- a/app/AdminAgent/Controllers/DemandBiddingController.php +++ b/app/AdminAgent/Controllers/DemandBiddingController.php @@ -21,11 +21,13 @@ class DemandBiddingController extends AdminController */ protected function grid() { - return Grid::make(new DemandBidding(), function (Grid $grid) { + return Grid::make(new DemandBidding(['demand']), function (Grid $grid) { $grid->model()->where(['bidding_user_id' => Admin::user()->id,'bidding_user_type' => Arr::first(DemandTraits::$col)]); $grid->column('id')->sortable(); $grid->column('price'); $grid->column('comment'); + $grid->column('demand.title','竞拍标题'); + $grid->column('demand.comment','竞拍内容'); $grid->column('state','状态')->using(DemandTraits::$biddingState)->dot( [ 'yellow', diff --git a/app/AdminAgent/Controllers/DemandController.php b/app/AdminAgent/Controllers/DemandController.php index 16dc732..6baba5a 100755 --- a/app/AdminAgent/Controllers/DemandController.php +++ b/app/AdminAgent/Controllers/DemandController.php @@ -150,7 +150,7 @@ class DemandController extends AdminController $form->select('bidding_user_type','竞标用户类型') ->when([2],function (Form $form){ $form->select('demand_product_id','产品')->options(function (){ - return Product::query()->whereIn('agent_id',[0,Admin::user()->id])->pluck('title','id'); + return AgentProduct::query()->where('agent_id',Admin::user()->id)->pluck('title','id'); }); }) ->options([ @@ -202,6 +202,12 @@ class DemandController extends AdminController $demand->bidding_user_id = $demandBidding->bidding_user_id; $demand->state = DemandTraits::$stateKey[1]; $demand->save(); + //如果是地接类型 绑定地接到订单 + if ($demand->bidding_user_type == DemandTraits::$col[2]){ + $agentProduct = AgentProduct::find($demand->demand_product_id); + $agentProduct->guide_id = $demandBidding->bidding_user_id; + $agentProduct->save(); + } DB::commit(); } catch (\Exception $e) { Log::error('选中竞标失败::'.$e->getTraceAsString()); diff --git a/app/AdminGuide/Controllers/DemandBiddingController.php b/app/AdminGuide/Controllers/DemandBiddingController.php new file mode 100755 index 0000000..f11bd42 --- /dev/null +++ b/app/AdminGuide/Controllers/DemandBiddingController.php @@ -0,0 +1,99 @@ +model()->where(['bidding_user_id' => Admin::user()->id,'bidding_user_type' => DemandTraits::$col[2]]); + $grid->column('id')->sortable(); + $grid->column('price'); + $grid->column('comment'); + $grid->column('demand.title','竞拍标题'); + $grid->column('demand.comment','竞拍内容'); + $grid->column('state','状态')->using(DemandTraits::$biddingState)->dot( + [ + 'yellow', + 'success', + 'danger', + ] + ); + $grid->column('created_at'); + $grid->column('updated_at')->sortable(); + $grid->disableDeleteButton(); + $grid->disableEditButton(); + $grid->disableQuickEditButton(); + $grid->disableViewButton(); + $grid->disableCreateButton(); + $grid->disableActions(); + $grid->filter(function (Grid\Filter $filter) { + $filter->equal('id'); + + }); + }); + } + + /** + * Make a show builder. + * + * @param mixed $id + * + * @return Show + */ + protected function detail($id) + { + return Show::make($id, new DemandBidding(), function (Show $show) { + $show->field('id'); + $show->field('price'); + $show->field('comment'); + $show->field('created_at'); + $show->field('updated_at'); + }); + } + + /** + * Make a form builder. + * + * @return Form + */ + protected function form() + { + return Form::make(new DemandBidding(), function (Form $form) { + $form->disableEditingCheck(); + $form->disableCreatingCheck(); + $form->disableViewCheck(); + $form->display('id'); + $form->text('price'); + $form->textarea('comment'); + $form->hidden('demand_id')->value(request('demand_id',0)); + $form->hidden('bidding_user_type'); + $form->hidden('bidding_user_id'); + $form->saving(function (Form $form) { + // 判断是否是新增操作 + if ($form->isCreating()) { + //发布人身份 + $form->bidding_user_type = DemandTraits::$col[2]; + $form->bidding_user_id = Admin::user()->id; + } + $form->response()->success('操作成功')->redirect('demand_bidding'); + }); + }); + } +} diff --git a/app/AdminGuide/Controllers/DemandController.php b/app/AdminGuide/Controllers/DemandController.php new file mode 100755 index 0000000..90e8e49 --- /dev/null +++ b/app/AdminGuide/Controllers/DemandController.php @@ -0,0 +1,213 @@ +model()->where(['publisher_id' => Admin::user()->id,'publisher_type' => DemandTraits::$col[2]]); + } + $grid->column('id')->sortable(); + $grid->column('title'); + $grid->column('detail','内容')->display('查看')->modal('详情',function ($modal) { + $modal->xl(); + return $this->comment; + }); + $grid->column('images','图片')->display(function ($image) { + return json_decode($image,true); + })->image(); + $grid->column('deadline'); + $grid->column('publisher.name','发布人'); + $grid->column('publisher_type')->using(DemandTraits::$polymorphic); + $grid->column('biddingUser.name','中标人'); + $grid->column('bidding_user_type','竞标用户类型')->using(DemandTraits::$polymorphic); + $grid->column('price'); + $grid->column('stock'); + $grid->column('state')->using(DemandTraits::$state)->dot( + [ + 1 => 'yellow', + 2 => 'success', + 3 => 'danger', + ] + ); + //$grid->setActionClass(Grid\Displayers\Actions::class); + // + //$grid->actions(function (Grid\Displayers\Actions $actions) { + // $actions->append(new DemandConfirm(1)); + //}); + + + if (\request('self',0)) { + $grid->column('bidding','竞标明细') + ->display(function (){ + return '竞标数 : '. DemandBidding::query()->where('demand_id',$this->id)->count(); + }) + ->modal('竞标明细',function () { + return DemandBiddingLazys::make(['demand_id' => $this->id]); + }); + }else{ + $grid->column('bidding','竞标') + ->if(function (){ + return $this->state == 1 && $this->bidding_user_type == DemandTraits::$col[2]; + }) + ->then(function (Grid\Column $column) { + $column->append('发起竞标'); + }); + } + + $grid->column('created_at')->sortable(); + $grid->disableDeleteButton(); + $grid->disableEditButton(); + $grid->disableQuickEditButton(); + $grid->disableViewButton(); + //$grid->disableActions(); + $grid->filter(function (Grid\Filter $filter) { + $filter->equal('id'); + $filter->equal('bidding_user_type','竞标用户类型')->select(DemandTraits::$polymorphic); + }); + }); + } + + /** + * Make a show builder. + * + * @param mixed $id + * + * @return Show + */ + protected function detail($id) + { + return Show::make($id, new Demand(['publisher','biddingUser']), function (Show $show) { + $show->field('id'); + $show->field('title'); + $show->field('comment'); + $show->field('images')->image(); + $show->field('deadline'); + $show->field('bidding_user_type','竞标用户类型')->using(DemandTraits::$polymorphic); + $show->field('price'); + $show->field('stock'); + $show->field('publisher_type')->using(DemandTraits::$polymorphic); + $show->field('publisher.name','发布人'); + $show->field('state')->using(DemandTraits::$state)->dot( + [ + 1 => 'yellow', + 2 => 'danger', + 3 => 'success', + ] + );; + $show->field('created_at'); + }); + } + + /** + * Make a form builder. + * + * @return Form + */ + protected function form() + { + return Form::make(new Demand(), function (Form $form) { + $form->disableEditingCheck(); + $form->disableCreatingCheck(); + $form->disableViewCheck(); + $form->display('id'); + $form->text('title'); + $form->text('comment'); + $form->multipleImage('images','图片')->limit(5)->saving(function ($path) { + return json_encode($path); + }); + $form->hidden('deadline'); + $form->select('bidding_user_type','竞标用户类型') + ->when([2],function (Form $form){ + $form->select('demand_product_id','产品')->options(function (){ + return Product::query()->whereIn('agent_id',[0,Admin::user()->id])->pluck('title','id'); + }); + }) + ->options([ + 1 => '供应商', + 2 => '地接' + ]) + ->default(1); + $form->decimal('price'); + $form->number('stock'); + $form->hidden('publisher_type'); + $form->hidden('publisher_id'); + $form->saving(function (Form $form) { + // 判断是否是新增操作 + if ($form->isCreating()) { + if ($form->bidding_user_type != 2) { + $form->demand_product_id = 0; + } + $form->bidding_user_type = DemandTraits::$col[$form->bidding_user_type]; + //处理流拍时间 + $form->deadline = now()->addDays(5); + //发布人身份 + $form->publisher_type = DemandTraits::$col[2]; + $form->publisher_id = Admin::user()->id; + } + }); + }); + } + + public function binding() + { + $demandBiddingId = request('demand_bidding_id',0); + $demandBidding = DemandBidding::find($demandBiddingId); + if (empty($demandBidding)) { + return false; + } + + $demand = \App\Models\Demand::find($demandBidding->demand_id); + + if (empty($demand)) { + return false; + } + + DB::beginTransaction(); + try { + $demandBidding->state = 1; + $demandBidding->save(); + //改变订单状态 + $demand->bidding_id = $demandBidding->id; + $demand->bidding_user_id = $demandBidding->bidding_user_id; + $demand->state = DemandTraits::$stateKey[1]; + $demand->save(); + DB::commit(); + } catch (\Exception $e) { + Log::error('选中竞标失败::'.$e->getTraceAsString()); + DB::rollBack(); + return $this->jsonFail(1001,'选中竞标失败,稍后重试或联系管理员!'.$e->getMessage()); + } + return back(); + } +} diff --git a/app/AdminGuide/Repositories/Demand.php b/app/AdminGuide/Repositories/Demand.php new file mode 100755 index 0000000..89c941a --- /dev/null +++ b/app/AdminGuide/Repositories/Demand.php @@ -0,0 +1,16 @@ +post('auth/login', 'AuthController@postLogin'); $router->resource('order/list', 'OrderController'); + $router->resource('demand', 'DemandController'); + $router->resource('demand_bidding', 'DemandBiddingController'); });