diff --git a/app/AdminAgent/Controllers/DemandBiddingController.php b/app/AdminAgent/Controllers/DemandBiddingController.php new file mode 100755 index 0000000..c05d223 --- /dev/null +++ b/app/AdminAgent/Controllers/DemandBiddingController.php @@ -0,0 +1,86 @@ +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('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->display('id'); + $form->text('price'); + $form->text('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 = 'App\models\Agent'; + $form->bidding_user_id = Admin::user()->id; + } + }); + }); + } +} diff --git a/app/AdminAgent/Controllers/DemandController.php b/app/AdminAgent/Controllers/DemandController.php new file mode 100755 index 0000000..c5a42d3 --- /dev/null +++ b/app/AdminAgent/Controllers/DemandController.php @@ -0,0 +1,208 @@ +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->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->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('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->product_id = 0; + } + $form->bidding_user_type = DemandTraits::$col[$form->bidding_user_type]; + //处理流拍时间 + $form->deadline = now()->addDays(5); + //发布人身份 + $form->publisher_type = DemandTraits::$col[0]; + $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 { + //新建供应商订单 + $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(); + //改变订单状态 + $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/AdminAgent/Controllers/MyDemandController.php b/app/AdminAgent/Controllers/MyDemandController.php new file mode 100755 index 0000000..42242da --- /dev/null +++ b/app/AdminAgent/Controllers/MyDemandController.php @@ -0,0 +1,132 @@ +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/Lazys/DemandBiddingLazys.php b/app/AdminAgent/Lazys/DemandBiddingLazys.php new file mode 100644 index 0000000..6ace0f9 --- /dev/null +++ b/app/AdminAgent/Lazys/DemandBiddingLazys.php @@ -0,0 +1,47 @@ +model()->where('demand_id',$demandId); + $grid->column('id'); + $grid->column('price','出价'); + $grid->column('comment','内容'); + $grid->column('biddingUser.name','竞拍人'); + $grid->column('bidding','竞标') + ->if(function () use ($demand){ + return $demand->state == 1; + }) + ->then(function (Grid\Column $column) { + $column->append('选中竞标'); + }) + ->if(function () use ($demand){ + return $demand->state == 2; + }) + ->then(function (Grid\Column $column) use ($demand){ + if ($demand->bidding_id == $this->id) { + $column->append('已中标'); + } else { + $column->append('未中标'); + } + }); + $grid->column('created_at'); + $grid->disableActions(); + $grid->disableRowSelector(); + }); + } +} diff --git a/app/AdminAgent/Repositories/Demand.php b/app/AdminAgent/Repositories/Demand.php new file mode 100755 index 0000000..4cb5fb1 --- /dev/null +++ b/app/AdminAgent/Repositories/Demand.php @@ -0,0 +1,16 @@ +resource('advertising/list', 'AdvertisingController'); $router->resource('special/list', 'SpecialController'); $router->resource('waterfall_ad/list', 'WaterfallAdController'); + + $router->resource('demand', 'DemandController'); + $router->resource('demand_bidding', 'DemandBiddingController'); + $router->resource('my_demand', 'MyDemandController'); + + + $router->resource('message/list', 'MessageController'); $router->resource('notice/list', 'NoticeController'); $router->resource('agent_info', 'AgentInfoController'); $router->resource('supplier/list', 'SupplierController'); $router->resource('article/list', 'ArticleController'); $router->resource('setting', 'SettingController'); + + //api + $router->any('/api/demand/binding', 'DemandController@binding'); }); diff --git a/app/Models/Agent.php b/app/Models/Agent.php index 87e1555..5ab58ad 100644 --- a/app/Models/Agent.php +++ b/app/Models/Agent.php @@ -26,4 +26,19 @@ class Agent extends BaseModel { return $this->hasMany(AgentProduct::class); } + + public function demand() + { + return $this->morphOne('App\Models\Demand', 'publisher'); + } + + public function demandUser() + { + return $this->morphOne('App\Models\Demand', 'biddingUser'); + } + + public function demandBidding() + { + return $this->morphOne('App\Models\DemandBidding', 'biddingUser'); + } } diff --git a/app/Models/Demand.php b/app/Models/Demand.php new file mode 100755 index 0000000..48930b0 --- /dev/null +++ b/app/Models/Demand.php @@ -0,0 +1,25 @@ +morphTo(); + } + + public function biddingUser() + { + return $this->morphTo(); + } +} diff --git a/app/Models/DemandBidding.php b/app/Models/DemandBidding.php new file mode 100755 index 0000000..fe75024 --- /dev/null +++ b/app/Models/DemandBidding.php @@ -0,0 +1,19 @@ +morphTo(); + } +} diff --git a/app/Models/Guide.php b/app/Models/Guide.php index 0489b4d..310ea5d 100644 --- a/app/Models/Guide.php +++ b/app/Models/Guide.php @@ -16,4 +16,19 @@ class Guide extends BaseModel $this->attributes['password'] = password_hash($value, PASSWORD_BCRYPT); } } + + public function demand() + { + return $this->morphOne('App\Models\Demand', 'publisher'); + } + + public function demandUser() + { + return $this->morphOne('App\Models\Demand', 'biddingUser'); + } + + public function demandBidding() + { + return $this->morphOne('App\Models\DemandBidding', 'biddingUser'); + } } diff --git a/app/Models/Supplier.php b/app/Models/Supplier.php index 863b4c5..9110b1a 100644 --- a/app/Models/Supplier.php +++ b/app/Models/Supplier.php @@ -17,6 +17,22 @@ class Supplier extends BaseModel } } + + public function demand() + { + return $this->morphOne('App\Models\Demand', 'publisher'); + } + + public function demandUser() + { + return $this->morphOne('App\Models\Demand', 'biddingUser'); + } + + public function demandBidding() + { + return $this->morphOne('App\Models\DemandBidding', 'biddingUser'); + } + public function agentProductItem() { return $this->hasMany(AgentProductItem::class); diff --git a/app/Traits/DemandTraits.php b/app/Traits/DemandTraits.php new file mode 100644 index 0000000..a0c8ae2 --- /dev/null +++ b/app/Traits/DemandTraits.php @@ -0,0 +1,31 @@ + '代理商', + 'App\models\Supplier' => '供应商', + 'App\models\Guide' => '地接', + ]; + + public static $stateKey = [ + 1, + 2, + 3, + ]; + + public static $state = [ + 1 => '待竞标' , + 2 => '已竞标' , + 3 => '流拍' + ]; +} diff --git a/app/Traits/ResponseHelper.php b/app/Traits/ResponseHelper.php new file mode 100644 index 0000000..b77986e --- /dev/null +++ b/app/Traits/ResponseHelper.php @@ -0,0 +1,50 @@ + $code, + 'msg' => $msg, + 'data' => $data, + 'metal_data' => $metalData, + ]); + } + + public function jsonFail($code = 0, $msg = 'fail', $data = [], $metalData = []) + { + return Response::json([ + 'code' => $code, + 'msg' => $msg, + 'data' => $data, + 'metal_data' => $metalData, + ]); + } + + public function jsonFailValidated($msg = 'validate fail', $code = 5000, $data = [], $metalData = []) + { + return Response::json([ + 'code' => $code, + 'msg' => $msg, + 'data' => $data, + 'metal_data' => $metalData, + ]); + } + + public function jsonException(Throwable $e, $statusCode = 200) + { + return Response::json([ + 'code' => $e->getCode() ?: $statusCode, + 'msg' => $e->getMessage(), + 'data' => [], + 'metal_data' => [], + ], 500); + } +} diff --git a/database/migrations/2021_08_24_164921_create_demand_table.php b/database/migrations/2021_08_24_164921_create_demand_table.php new file mode 100644 index 0000000..a99e372 --- /dev/null +++ b/database/migrations/2021_08_24_164921_create_demand_table.php @@ -0,0 +1,45 @@ +id(); + $table->string('title')->comment('标题')->default(''); + $table->string('comment')->comment('内容')->default(''); + $table->dateTime('deadline')->comment('流拍时间')->nullable(); + $table->decimal('price')->comment('起拍价格')->default(0); + $table->integer('stock')->comment('库存')->default(0); + $table->string('publisher_type')->comment('发布人身份 类型 关联模型')->default(''); + $table->bigInteger('publisher_id')->index()->comment('发布人身份id 根据类型查不同的表')->default(1); + $table->tinyInteger('state')->comment('状态 1 待竞标 2 已竞标 3 流拍')->default(1); + $table->string('bidding_user_type')->comment('竞拍人 关联模型')->default(1); + $table->bigInteger('bidding_user_id')->index()->comment('竞拍成功人用户id 关联竞标表')->default(0); + $table->bigInteger('bidding_id')->index()->comment('竞拍成功id 关联竞标表')->default(0); + $table->string('images')->index()->comment('图片')->default(''); + $table->dateTime('created_at')->nullable(); + $table->dateTime('updated_at')->nullable(); + $table->dateTime('deleted_at')->nullable(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('demand'); + } +} diff --git a/database/migrations/2021_08_24_165029_create_demand_bidding_table.php b/database/migrations/2021_08_24_165029_create_demand_bidding_table.php new file mode 100644 index 0000000..03740c1 --- /dev/null +++ b/database/migrations/2021_08_24_165029_create_demand_bidding_table.php @@ -0,0 +1,36 @@ +id(); + $table->decimal('price')->comment('报价')->default(0); + $table->string('comment')->comment('内容 解决方案')->default(''); + $table->bigInteger('demand_id')->index()->comment('市场需求表id 关联需求表表')->default(0); + $table->dateTime('created_at')->nullable(); + $table->dateTime('updated_at')->nullable(); + $table->dateTime('deleted_at')->nullable(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('demand_bidding'); + } +} diff --git a/resources/lang/zh_CN/demand-bidding.php b/resources/lang/zh_CN/demand-bidding.php new file mode 100755 index 0000000..22e5e19 --- /dev/null +++ b/resources/lang/zh_CN/demand-bidding.php @@ -0,0 +1,13 @@ + [ + 'DemandBidding' => '我的竞标', + 'demand-bidding' => '我的竞标', + ], + 'fields' => [ + 'price' => '价格', + 'comment' => '内容', + ], + 'options' => [ + ], +]; diff --git a/resources/lang/zh_CN/demand.php b/resources/lang/zh_CN/demand.php new file mode 100755 index 0000000..5fb3854 --- /dev/null +++ b/resources/lang/zh_CN/demand.php @@ -0,0 +1,21 @@ + [ + 'Demand' => '市场需求', + 'demand' => '市场需求', + ], + 'fields' => [ + 'title' => '标题', + 'comment' => '内容', + 'deadline' => '流拍时间', + 'type' => '类型', + 'price' => '价格', + 'stock' => '库存', + 'publisher_type' => '发布人身份', + 'publisher_id' => '发布人', + 'state' => '状态', + 'bidding_id' => '竞拍成功id 关联竞标表', + ], + 'options' => [ + ], +]; diff --git a/resources/lang/zh_CN/my-demand.php b/resources/lang/zh_CN/my-demand.php new file mode 100755 index 0000000..03a4e7b --- /dev/null +++ b/resources/lang/zh_CN/my-demand.php @@ -0,0 +1,21 @@ + [ + 'MyDemand' => '我的需求', + 'my_demand' => '我的需求', + ], + 'fields' => [ + 'title' => '标题', + 'comment' => '内容', + 'deadline' => '流拍时间', + 'type' => '类型', + 'price' => '价格', + 'stock' => '库存', + 'publisher_type' => '发布人身份', + 'publisher_id' => '发布人', + 'state' => '状态', + 'bidding_id' => '竞拍成功id 关联竞标表', + ], + 'options' => [ + ], +];