diff --git a/app/AdminAgent/Actions/Grid/DemandConfirm.php b/app/AdminAgent/Actions/Grid/DemandConfirm.php new file mode 100644 index 0000000..972e991 --- /dev/null +++ b/app/AdminAgent/Actions/Grid/DemandConfirm.php @@ -0,0 +1,87 @@ +model = $model; + } + + /** + * 标题 + * + * @return string + */ + public function title() + { + return 'Copy'; + } + + /** + * 设置确认弹窗信息,如果返回空值,则不会弹出弹窗 + * + * 允许返回字符串或数组类型 + * + * @return array|string|void + */ + public function confirm() + { + return [ + // 确认弹窗 title + "您确定要复制这行数据吗?", + // 确认弹窗 content + $this->row->username, + ]; + } + + /** + * 处理请求 + * + * @param Request $request + * + * @return \Dcat\Admin\Actions\Response + */ + public function handle(Request $request) + { + // 获取当前行ID + $id = $this->getKey(); + + // 获取 parameters 方法传递的参数 + $username = $request->get('username'); + $model = $request->get('model'); + + // 复制数据 + $model::find($id)->replicate()->save(); + + // 返回响应结果并刷新页面 + return $this->response()->success("复制成功: [{$username}]")->refresh(); + } + + /** + * 设置要POST到接口的数据 + * + * @return array + */ + public function parameters() + { + return [ + // 发送当前行 username 字段数据到接口 + 'username' => $this->row->username, + // 把模型类名传递到接口 + 'model' => $this->model, + ]; + } + +} diff --git a/app/AdminAgent/Controllers/AgentProductController.php b/app/AdminAgent/Controllers/AgentProductController.php index ee27d4f..9a75141 100644 --- a/app/AdminAgent/Controllers/AgentProductController.php +++ b/app/AdminAgent/Controllers/AgentProductController.php @@ -157,7 +157,6 @@ class AgentProductController extends AdminController { return Form::make(new AgentProduct(), function (Form $form) { $agent_id = Admin::user()->id; - //不允许查看非自己的数据 if ($form->isEditing() && $form->model()->agent_id != Admin::user()->id) { return $form->response()->error('数据不存在'); @@ -190,7 +189,9 @@ class AgentProductController extends AdminController $form->editor('know'); $form->editor('content'); }); - $form->text('price')->required(); + $form->text('title', '产品名称'); + + $form->text('price')->required(); $form->text('original_price')->required(); $form->text('sale')->default(0); $form->text('stock')->default(8888); diff --git a/app/AdminAgent/Controllers/DemandBiddingController.php b/app/AdminAgent/Controllers/DemandBiddingController.php index c05d223..1796d1a 100755 --- a/app/AdminAgent/Controllers/DemandBiddingController.php +++ b/app/AdminAgent/Controllers/DemandBiddingController.php @@ -26,6 +26,13 @@ class DemandBiddingController extends AdminController $grid->column('id')->sortable(); $grid->column('price'); $grid->column('comment'); + $grid->column('state','状态')->using(DemandTraits::$biddingState)->dot( + [ + 'yellow', + 'success', + 'danger', + ] + ); $grid->column('created_at'); $grid->column('updated_at')->sortable(); $grid->disableDeleteButton(); @@ -67,9 +74,12 @@ class DemandBiddingController extends AdminController protected function form() { return Form::make(new DemandBidding(), function (Form $form) { - $form->display('id'); + $form->disableEditingCheck(); + $form->disableCreatingCheck(); + $form->disableViewCheck(); + $form->display('id'); $form->text('price'); - $form->text('comment'); + $form->textarea('comment'); $form->hidden('demand_id')->value(request('demand_id',0)); $form->hidden('bidding_user_type'); $form->hidden('bidding_user_id'); @@ -77,9 +87,10 @@ class DemandBiddingController extends AdminController // 判断是否是新增操作 if ($form->isCreating()) { //发布人身份 - $form->bidding_user_type = 'App\models\Agent'; + $form->bidding_user_type = DemandTraits::$col[0]; $form->bidding_user_id = Admin::user()->id; } + $form->response()->success('操作成功')->redirect('demand_bidding'); }); }); } diff --git a/app/AdminAgent/Controllers/DemandController.php b/app/AdminAgent/Controllers/DemandController.php index c5a42d3..16dc732 100755 --- a/app/AdminAgent/Controllers/DemandController.php +++ b/app/AdminAgent/Controllers/DemandController.php @@ -2,6 +2,8 @@ namespace App\AdminAgent\Controllers; +use App\AdminAgent\Actions\Grid\DemandConfirm; +use App\AdminAgent\Lazys\DemandBiddingLazys; use App\Models\AgentProduct; use App\Models\Product; use App\Traits\ResponseHelper; @@ -32,6 +34,9 @@ class DemandController extends AdminController protected function grid() { return Grid::make(new Demand(['publisher','biddingUser']), function (Grid $grid) { + if (\request('self',0)) { + $grid->model()->where(['publisher_id' => Admin::user()->id,'publisher_type' => DemandTraits::$col[0]]); + } $grid->column('id')->sortable(); $grid->column('title'); $grid->column('detail','内容')->display('查看')->modal('详情',function ($modal) { @@ -55,20 +60,37 @@ class DemandController extends AdminController 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 == Arr::first(DemandTraits::$col); + }) + ->then(function (Grid\Column $column) { + $column->append('发起竞标'); + }); + } - $grid->column('bidding','竞标') - ->if(function (){ - return $this->state == 1 && $this->bidding_user_type == Arr::first(DemandTraits::$col); - }) - ->then(function (Grid\Column $column) { - $column->append('发起竞标'); - }); $grid->column('created_at')->sortable(); $grid->disableDeleteButton(); $grid->disableEditButton(); $grid->disableQuickEditButton(); $grid->disableViewButton(); - $grid->disableActions(); + //$grid->disableActions(); $grid->filter(function (Grid\Filter $filter) { $filter->equal('id'); $filter->equal('bidding_user_type','竞标用户类型')->select(DemandTraits::$polymorphic); @@ -127,7 +149,7 @@ class DemandController extends AdminController $form->hidden('deadline'); $form->select('bidding_user_type','竞标用户类型') ->when([2],function (Form $form){ - $form->select('product_id','产品')->options(function (){ + $form->select('demand_product_id','产品')->options(function (){ return Product::query()->whereIn('agent_id',[0,Admin::user()->id])->pluck('title','id'); }); }) @@ -144,7 +166,7 @@ class DemandController extends AdminController // 判断是否是新增操作 if ($form->isCreating()) { if ($form->bidding_user_type != 2) { - $form->product_id = 0; + $form->demand_product_id = 0; } $form->bidding_user_type = DemandTraits::$col[$form->bidding_user_type]; //处理流拍时间 @@ -173,25 +195,8 @@ class DemandController extends AdminController DB::beginTransaction(); try { - //新建供应商订单 - $product = new Product(); - $product->agent_id = $demand->publisher_id; - $product->title = $demand->title; - $product->pictures = $demand->images; - $product->price = $demand->price; - $product->original_price = $demand->price; - $product->stock = $demand->stock; - $product->state = 0; - $product->save(); - //处理代理商订单 - $agentProduct = new AgentProduct(); - $agentProduct->agent_id = $demand->publisher_id; - $agentProduct->product_id = $product->id; - $agentProduct->stock = $demand->stock; - $agentProduct->price = $demand->price; - $agentProduct->original_price = $demand->price; - $agentProduct->state = 0; - $agentProduct->save(); + $demandBidding->state = 1; + $demandBidding->save(); //改变订单状态 $demand->bidding_id = $demandBidding->id; $demand->bidding_user_id = $demandBidding->bidding_user_id; diff --git a/app/AdminAgent/Controllers/MyDemandController.php b/app/AdminAgent/Controllers/MyDemandController.php deleted file mode 100755 index 42242da..0000000 --- a/app/AdminAgent/Controllers/MyDemandController.php +++ /dev/null @@ -1,132 +0,0 @@ -model()->where(['publisher_id' => Admin::user()->id,'publisher_type' => Arr::first(DemandTraits::$col)]); - $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('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->column('bidding','竞标明细') - ->display(function (){ - return '竞标数 : '. DemandBidding::query()->where('demand_id',$this->id)->count(); - }) - ->modal('竞标明细',function () { - return DemandBiddingLazys::make(['demand_id' => $this->id]); - }); - - $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('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->display('id'); - $form->text('title'); - $form->text('comment'); - $form->multipleImage('images','图片'); - $form->hidden('deadline'); - $form->select('bidding_user_type','竞标用户类型')->options([ - 'App\models\Supplier' => '供应商', - 'App\models\Guides' => '地接' - ]); - $form->decimal('price'); - $form->number('stock'); - $form->hidden('publisher_type'); - $form->hidden('publisher_id'); - $form->saving(function (Form $form) { - // 判断是否是新增操作 - if ($form->isCreating()) { - //处理流拍时间 - $form->deadline = now()->addDays(5); - //发布人身份 - $form->publisher_type = 'App\models\Agent'; - $form->publisher_id = Admin::user()->id; - } - }); - }); - } -} diff --git a/app/AdminAgent/Renderable/SelectProduct.php b/app/AdminAgent/Renderable/SelectProduct.php index f162add..e8194bb 100644 --- a/app/AdminAgent/Renderable/SelectProduct.php +++ b/app/AdminAgent/Renderable/SelectProduct.php @@ -28,7 +28,7 @@ class SelectProduct extends LazyRenderable $grid->quickSearch(['title', 'supplier.name'])->placeholder('搜索产品名称、供应商'); $grid->column('id'); - $grid->column('supplier.name', '供应商'); + //$grid->column('supplier.name', '供应商'); $grid->column('title'); $grid->column('picture')->image('',60, 60); $grid->column('sale'); diff --git a/app/AdminAgent/routes.php b/app/AdminAgent/routes.php index ae3b1ee..e099027 100644 --- a/app/AdminAgent/routes.php +++ b/app/AdminAgent/routes.php @@ -26,7 +26,6 @@ Route::group([ $router->resource('demand', 'DemandController'); $router->resource('demand_bidding', 'DemandBiddingController'); - $router->resource('my_demand', 'MyDemandController'); diff --git a/app/AdminSupplier/Controllers/DemandBiddingController.php b/app/AdminSupplier/Controllers/DemandBiddingController.php new file mode 100755 index 0000000..327315d --- /dev/null +++ b/app/AdminSupplier/Controllers/DemandBiddingController.php @@ -0,0 +1,171 @@ +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; + $demand->save(); + + $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(); + DB::commit(); + } catch (\Exception $e) { + Log::error('分配订单失败::' . $e->getTraceAsString()); + DB::rollBack(); + return $form->response()->error('分配订单失败,稍后重试或联系管理员!' . $e->getMessage()); + } + } + } + $form->response()->success('操作成功')->redirect('demand_bidding'); + }); + }); + } +} diff --git a/app/AdminSupplier/Controllers/DemandController.php b/app/AdminSupplier/Controllers/DemandController.php new file mode 100755 index 0000000..ba49ef3 --- /dev/null +++ b/app/AdminSupplier/Controllers/DemandController.php @@ -0,0 +1,224 @@ +model()->where(['publisher_id' => Admin::user()->id,'publisher_type' => DemandTraits::$col[1]]); + } + $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', + ] + ); + + 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[1]; + }) + ->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([0],function (Form $form){ + $form->select('demand_product_id','产品')->options(function (){ + return DemandProduct::query()->where('supplier_id',Admin::user()->id)->where('agent_id',0)->pluck('title','id'); + }); + }) + ->options([ + '代理商' + ]) + ->default(0); + $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[1]; + $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(); + //将产品绑给代理商 + $demandProduct = DemandProduct::find($demand->demand_product_id); + $product = new Product(); + + $product->supplier_id = $demandProduct->supplier_id; + $product->category_id = $demandProduct->category_id; + $product->title = $demandProduct->title; + $product->price = $demandBidding->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 = $demandBidding->bidding_user_id; + $product->pictures = $demandProduct->pictures; + $product->save(); + DB::commit(); + } catch (\Exception $e) { + Log::error('选中竞标失败::'.$e->getTraceAsString()); + DB::rollBack(); + return $this->jsonFail(1001,'选中竞标失败,稍后重试或联系管理员!'.$e->getMessage()); + } + return back(); + } +} diff --git a/app/AdminSupplier/Controllers/DemandProductController.php b/app/AdminSupplier/Controllers/DemandProductController.php new file mode 100755 index 0000000..19598f2 --- /dev/null +++ b/app/AdminSupplier/Controllers/DemandProductController.php @@ -0,0 +1,139 @@ +model()->where('supplier_id', Admin::user()->id); + + $grid->column('id')->sortable(); + $grid->column('category.name', '产品分类'); + $grid->column('title'); + $grid->column('picture')->image('', 60, 60); + $grid->column('price'); + $grid->column('original_price'); + $grid->column('stock'); + $grid->column('sale'); + $grid->column('status')->using(ProductStatus::array()); + $grid->column('created_at'); + $grid->column('updated_at'); + + $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 DemandProduct(), function (Show $show) { + $show->field('id'); + $show->field('supplier_id'); + $show->field('category_id'); + $show->field('title'); + $show->field('price'); + $show->field('original_price'); + $show->field('pictures')->image('', 80, 80); + $show->field('stock'); + $show->field('sale'); + $show->field('status'); + $show->field('know')->unescape()->as(fn($v) => preg_replace('/.*?<\/script>/is', '', $v)); + $show->field('content')->unescape()->as(fn($v) => preg_replace('/.*?<\/script>/is', '', $v)); + $show->field('created_at'); + $show->field('updated_at'); + }); + } + + /** + * Make a form builder. + * + * @return Form + */ + protected function form() + { + return Form::make(new DemandProduct(), function (Form $form) { + //不允许编辑非自己数据 + if ($form->isEditing() && $form->model()->supplier_id != Admin::user()->id) { + return $form->response()->error('数据不存在'); + } + + $form->display('id'); + + $options = Category::selectOptions(fn($query) => $query->where('agent_id', 0)); + $form->select('category_id')->options(array_slice($options, 1, null, true))->required(); + $form->text('title')->required(); + $form->text('price')->required(); + $form->text('original_price')->required(); + $form->multipleImage('pictures')->required()->removable(false)->retainable()->uniqueName(); + $form->text('stock')->default(9999)->required(); + $form->editor('know'); + $form->editor('content')->required(); + + if ($form->isEditing()) { + $form->confirm('提示', '编辑产品需要重新审核,同时下架所有关联的代理商产品,是否继续?'); + } + })->saving(function (Form $form) { + //不允许编辑非自己数据 + if ($form->isEditing() && $form->model()->supplier_id != Admin::user()->id) { + return $form->response()->error('数据不存在'); + } + + //不允许编辑的字段 TODO 忽略字段不起作用 + $form->ignore(['id', 'supplier_id', 'sale', 'status', 'created_at', 'updated_at', 'deleted_at']); + + //null字段转为'' + foreach ($form->input() as $k => $v) { + if (is_null($v)) { + $form->$k = ''; + } + } + + //特殊字段处理 + $form->hidden(['status', 'supplier_id']); //表单没有的字段,必须加上这句才能重置值 + $form->status = ProductStatus::UNAUDITED; + $form->supplier_id = Admin::user()->id; + })->saved(function (Form $form, $result) { + //下架代理商产品 + if ($result) { + $id = $form->getKey(); + AgentProduct::where('product_id', $id) + ->orWhere(DB::raw('FIND_IN_SET(' . $id . ', product_ids)')) //TODO product_ids字段可能会去掉 + ->update(['status' => ProductStatus::SOLD_OUT]); + } + })->deleting(function (Form $form) { + //不允许删除非自己的数据 + if (array_filter($form->model()->toArray(), fn($v) => $v['supplier_id'] != Admin::user()->id)) { + return $form->response()->error('数据不存在'); + } + }); + } +} diff --git a/app/AdminSupplier/Renderable/SelectProduct.php b/app/AdminSupplier/Renderable/SelectProduct.php new file mode 100644 index 0000000..efceef3 --- /dev/null +++ b/app/AdminSupplier/Renderable/SelectProduct.php @@ -0,0 +1,48 @@ +id; + Admin::translation('product'); + return Grid::make(new DemandProduct(['supplier:id,name']), function (Grid $grid) { + $grid->disableActions(); + $grid->disableBatchDelete(); + $grid->disableBatchActions(); + + //$grid->model()->where('status', ProductStatus::ON_SALE); + $grid->model()->where('supplier_id',Admin::user()->id)->where('agent_id',0); + $grid->quickSearch(['title', 'supplier.name'])->placeholder('搜索产品名称、供应商'); + + $grid->column('id'); + $grid->column('supplier.name', '供应商'); + $grid->column('title'); + $grid->column('picture')->image('',60, 60); + $grid->column('sale'); + $grid->column('stock'); + $grid->column('updated_at'); + + $grid->paginate(15); + + $grid->filter(function (Grid\Filter $filter) { + $filter->like('title')->width(4); + $filter->like('supplier.name', '供应商名称')->width(4); + }); + }); + } +} diff --git a/app/AdminSupplier/Repositories/Demand.php b/app/AdminSupplier/Repositories/Demand.php new file mode 100755 index 0000000..08390df --- /dev/null +++ b/app/AdminSupplier/Repositories/Demand.php @@ -0,0 +1,16 @@ +resource('order/list', 'OrderController'); $router->resource('agent/list', 'AgentController'); $router->resource('supplier_info', 'SupplierInfoController'); + + $router->resource('demand', 'DemandController'); + $router->resource('demand_bidding', 'DemandBiddingController'); + $router->resource('demand_product', 'DemandProductController'); + + //api + $router->any('/api/demand/binding', 'DemandController@binding'); }); diff --git a/app/Models/DemandBidding.php b/app/Models/DemandBidding.php index fe75024..726fe24 100755 --- a/app/Models/DemandBidding.php +++ b/app/Models/DemandBidding.php @@ -16,4 +16,9 @@ class DemandBidding extends BaseModel { return $this->morphTo(); } + + public function demand() + { + return $this->belongsTo(Demand::class,'demand_id','id'); + } } diff --git a/app/Models/DemandProduct.php b/app/Models/DemandProduct.php new file mode 100755 index 0000000..b6720e1 --- /dev/null +++ b/app/Models/DemandProduct.php @@ -0,0 +1,52 @@ +append('picture'); + return $value ?? []; + } + + // 获取第一张产品图片 + public function getPictureAttribute($value): string + { + return $this->pictures[0] ?? ''; + } + + public function setPicturesAttribute($value) + { + if (is_array($value)) { + $this->attributes['pictures'] = json_encode(array_filter($value)); + } + } + + public function supplier() + { + return $this->belongsTo(Supplier::class); + } + + public function category() + { + return $this->belongsTo(Category::class); + } +} diff --git a/app/Traits/DemandTraits.php b/app/Traits/DemandTraits.php index a0c8ae2..6d44104 100644 --- a/app/Traits/DemandTraits.php +++ b/app/Traits/DemandTraits.php @@ -28,4 +28,10 @@ trait DemandTraits 2 => '已竞标' , 3 => '流拍' ]; + + public static $biddingState = [ + '待竞标' , + '已中标' , + '未中标' + ]; } diff --git a/resources/lang/zh_CN/demand-product.php b/resources/lang/zh_CN/demand-product.php new file mode 100755 index 0000000..45487b2 --- /dev/null +++ b/resources/lang/zh_CN/demand-product.php @@ -0,0 +1,23 @@ + [ + 'DemandProduct' => 'DemandProduct', + 'demand-product' => 'DemandProduct', + ], + 'fields' => [ + 'agent_id' => '代理商id 竞标特供', + 'category_id' => '产品分类ID', + 'content' => '产品详情', + 'know' => '旅客须知', + 'original_price' => '原价', + 'pictures' => '产品图片,可能有多张,JSON格式', + 'price' => '价格', + 'sale' => '销量', + 'status' => '0:下架,1:在售', + 'stock' => '库存量', + 'supplier_id' => '供应商ID', + 'title' => '标题', + ], + 'options' => [ + ], +];