model()->where(['bidding_user_id' => Admin::user()->id,'bidding_user_type' => DemandTraits::$col[1]]); $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('bidding','操作') ->if(function (){ return $this->state == 1 && $this->bidding_user_type == DemandTraits::$col[1] && empty($this->demand->demand_product_id); }) ->then(function (Grid\Column $column) { $column->append('绑定产品'); }) ->if(function (){ return $this->state == 1 && $this->bidding_user_type == DemandTraits::$col[1] && !empty($this->demand->demand_product_id); }) ->then(function (Grid\Column $column) { $column->append('查看产品'); }); $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->disableDeleteButton(); $form->disableViewButton(); $form->disableViewCheck(); $form->display('id')->disable(); if(request('is_bidding',0)) { $form->textarea('comment')->disable(); $form->selectTable('demand_product_id', '产品') ->title('选择产品') ->dialogWidth('50%;min-width:600px;') //不起作用 ->from(SelectProduct::make()) ->model(DemandProduct::class, 'id', 'title'); }else{ $form->text('price'); $form->textarea('comment'); } $form->hidden('demand_id')->value(request('demand_id',0)); $form->hidden('bidding_user_type')->disable(); $form->hidden('bidding_user_id')->disable(); $form->saving(function (Form $form) { $form->deleteInput('demand_product_id'); //发布人身份 $form->bidding_user_type = DemandTraits::$col[1]; $form->bidding_user_id = Admin::user()->id; }); $form->saved(function (Form $form) { if($form->isEditing()) { $productId = request('demand_product_id', 0); if (!empty($productId)) { DB::beginTransaction(); try { //处理订单 //将产品绑给代理商 $demand = Demand::find($form->model()->demand_id); $demand->demand_product_id = $productId; $demandProduct = DemandProduct::find($productId); $product = new Product(); $product->supplier_id = $demandProduct->supplier_id; $product->category_id = $demandProduct->category_id; $product->title = $demandProduct->title; $product->price = $form->model()->price; $product->original_price = $demandProduct->original_price; $product->pictures = $demandProduct->pictures; $product->stock = $demand->stock; $product->know = $demandProduct->know; $product->content = $demandProduct->content; $product->pictures = $demandProduct->pictures; $product->agent_id = $form->model()->bidding_user_id; $product->pictures = $demandProduct->pictures; $product->save(); //处理需求 $demand = Demand::find($form->model()->demand_id); $demand->demand_product_id = $productId; $demand->save(); $demand->product_id = $product->id; $demand->save(); DB::commit(); } catch (\Exception $e) { Log::error('分配订单失败::' . $e->getTraceAsString()); DB::rollBack(); return $form->response()->error('分配订单失败,稍后重试或联系管理员!' . $e->getMessage()); } } } $form->response()->success('操作成功')->redirect('demand_bidding'); }); }); } }