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.
|
|
<?php
namespace App\AdminSupplier\Controllers;
use App\AdminSupplier\Renderable\SelectProduct;use App\AdminSupplier\Repositories\DemandBidding;use App\Models\AgentProduct;use App\Models\AgentProductItem;use App\Models\Demand;use App\Models\DemandProduct;use App\Models\Product;use App\Traits\DemandTraits;use Dcat\Admin\Admin;use Dcat\Admin\Form;use Dcat\Admin\Grid;use Dcat\Admin\Show;use Dcat\Admin\Http\Controllers\AdminController;use Illuminate\Database\Eloquent\Model;use Illuminate\Support\Arr;use Illuminate\Support\Facades\DB;use Illuminate\Support\Facades\Log;
class DemandBiddingController extends AdminController{ /** * Make a grid builder. * * @return Grid */ protected function grid() { return Grid::make(new DemandBidding(['demand']), function (Grid $grid) { $grid->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','竞拍内容') ->display('查看') ->modal('详情',function ($modal) { $modal->xl(); return $this->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('<a class="btn btn-sm btn-success" href="'.admin_url('/demand_bidding/'.$this->id.'/edit?is_bidding=true').'">添加中标产品</a>'); }) ->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('<a class="btn btn-sm btn-primary" href="'.admin_url('/demand_product/'.$this->demand->demand_product_id).'">查看产品</a>'); }); $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();
$demand_id = request('demand_id'); if ($demand_id && \App\Models\DemandBidding::find($demand_id)) { Admin::exit('你已经竞标过了,无需重复参加'); }
$form->display('id')->disable(); if(request('is_bidding',0)) { $form->textarea('comment')->disable()->required(); $form->selectTable('demand_product_id', '产品') ->title('选择产品') ->dialogWidth('50%;min-width:600px;') //不起作用
->from(SelectProduct::make()) ->model(DemandProduct::class) ->required(); }else{ $form->text('price')->required(); $form->textarea('comment')->required(); } $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) { $provinceId = Demand::query()->where('id',$this->demand_id)->value('province_id');
if ($provinceId != Admin::user()->province_id) { $form->response()->error('竞标失败,指能竞标跟自己相同省份的的需求'); } 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 = $form->model()->price; $product->pictures = $demandProduct->pictures; $product->stock = $demand->stock; $product->know = $demandProduct->know; $product->content = $demandProduct->content; $product->agent_id = $form->model()->bidding_user_id; $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'); }); }); }}
|