From dde7cb0e92151fb9ba4a9877648f225c4c453596 Mon Sep 17 00:00:00 2001
From: lemon <15040771@qq.com>
Date: Sat, 28 Aug 2021 17:20:43 +0800
Subject: [PATCH 01/26] =?UTF-8?q?=E4=BB=A3=E7=90=86=E5=95=86=E4=BE=9B?=
=?UTF-8?q?=E5=BA=94=E5=95=86?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/AdminAgent/Actions/Grid/DemandConfirm.php | 87 +++++++
.../Controllers/AgentProductController.php | 5 +-
.../Controllers/DemandBiddingController.php | 17 +-
.../Controllers/DemandController.php | 63 ++---
.../Controllers/MyDemandController.php | 132 -----------
app/AdminAgent/Renderable/SelectProduct.php | 2 +-
app/AdminAgent/routes.php | 1 -
.../Controllers/DemandBiddingController.php | 171 +++++++++++++
.../Controllers/DemandController.php | 224 ++++++++++++++++++
.../Controllers/DemandProductController.php | 139 +++++++++++
.../Renderable/SelectProduct.php | 48 ++++
app/AdminSupplier/Repositories/Demand.php | 16 ++
.../Repositories/DemandBidding.php | 16 ++
.../Repositories/DemandProduct.php | 16 ++
app/AdminSupplier/routes.php | 7 +
app/Models/DemandBidding.php | 5 +
app/Models/DemandProduct.php | 52 ++++
app/Traits/DemandTraits.php | 6 +
resources/lang/zh_CN/demand-product.php | 23 ++
19 files changed, 862 insertions(+), 168 deletions(-)
create mode 100644 app/AdminAgent/Actions/Grid/DemandConfirm.php
delete mode 100755 app/AdminAgent/Controllers/MyDemandController.php
create mode 100755 app/AdminSupplier/Controllers/DemandBiddingController.php
create mode 100755 app/AdminSupplier/Controllers/DemandController.php
create mode 100755 app/AdminSupplier/Controllers/DemandProductController.php
create mode 100644 app/AdminSupplier/Renderable/SelectProduct.php
create mode 100755 app/AdminSupplier/Repositories/Demand.php
create mode 100755 app/AdminSupplier/Repositories/DemandBidding.php
create mode 100755 app/AdminSupplier/Repositories/DemandProduct.php
create mode 100755 app/Models/DemandProduct.php
create mode 100755 resources/lang/zh_CN/demand-product.php
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' => [
+ ],
+];
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 02/26] =?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');
});
From 8d720312834d4b0b584724ce699b10cb7a0290b5 Mon Sep 17 00:00:00 2001
From: lemon <15040771@qq.com>
Date: Sun, 29 Aug 2021 17:04:14 +0800
Subject: [PATCH 03/26] =?UTF-8?q?=E7=BB=91=E5=AE=9A=E8=AE=A2=E5=8D=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/AdminAgent/routes.php | 1 +
app/AdminSupplier/Controllers/DemandBiddingController.php | 5 ++++-
app/AdminSupplier/Controllers/DemandController.php | 5 +++--
3 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/app/AdminAgent/routes.php b/app/AdminAgent/routes.php
index 99389c4..423bb12 100644
--- a/app/AdminAgent/routes.php
+++ b/app/AdminAgent/routes.php
@@ -26,6 +26,7 @@ Route::group([
$router->resource('demand', 'DemandController');
$router->resource('demand_bidding', 'DemandBiddingController');
+ $router->resource('my_demand_product', 'ProductController');
$router->resource('message/list', 'MessageController');
$router->resource('notice/list', 'NoticeController');
diff --git a/app/AdminSupplier/Controllers/DemandBiddingController.php b/app/AdminSupplier/Controllers/DemandBiddingController.php
index 327315d..8c477c6 100755
--- a/app/AdminSupplier/Controllers/DemandBiddingController.php
+++ b/app/AdminSupplier/Controllers/DemandBiddingController.php
@@ -134,7 +134,7 @@ class DemandBiddingController extends AdminController
//将产品绑给代理商
$demand = Demand::find($form->model()->demand_id);
$demand->demand_product_id = $productId;
- $demand->save();
+
$demandProduct = DemandProduct::find($productId);
$product = new Product();
@@ -156,6 +156,9 @@ class DemandBiddingController extends AdminController
$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());
diff --git a/app/AdminSupplier/Controllers/DemandController.php b/app/AdminSupplier/Controllers/DemandController.php
index ba49ef3..bc6339b 100755
--- a/app/AdminSupplier/Controllers/DemandController.php
+++ b/app/AdminSupplier/Controllers/DemandController.php
@@ -209,10 +209,11 @@ class DemandController extends AdminController
$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();
+
+ $demand->product_id = $product->id;
+ $demand->save();
DB::commit();
} catch (\Exception $e) {
Log::error('选中竞标失败::'.$e->getTraceAsString());
From 68d8fe206f0c31d85699ec35949ba247a986553a Mon Sep 17 00:00:00 2001
From: lemon <15040771@qq.com>
Date: Sun, 29 Aug 2021 20:22:09 +0800
Subject: [PATCH 04/26] =?UTF-8?q?=E7=AB=9E=E6=A0=87=E4=BA=A7=E5=93=81?=
=?UTF-8?q?=E5=BA=93?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../Controllers/DemandController.php | 4 +-
.../Controllers/MyDemandProductController.php | 71 +++++++++++++++++
app/AdminAgent/routes.php | 2 +-
.../Controllers/MyDemandProductController.php | 79 +++++++++++++++++++
app/AdminGuide/routes.php | 1 +
.../Controllers/MyDemandProductController.php | 71 +++++++++++++++++
app/AdminSupplier/routes.php | 2 +-
app/Models/Demand.php | 16 +++-
resources/lang/zh_CN/my-demand-product.php | 21 +++++
9 files changed, 260 insertions(+), 7 deletions(-)
create mode 100755 app/AdminAgent/Controllers/MyDemandProductController.php
create mode 100755 app/AdminGuide/Controllers/MyDemandProductController.php
create mode 100755 app/AdminSupplier/Controllers/MyDemandProductController.php
create mode 100755 resources/lang/zh_CN/my-demand-product.php
diff --git a/app/AdminAgent/Controllers/DemandController.php b/app/AdminAgent/Controllers/DemandController.php
index 6baba5a..6154df2 100755
--- a/app/AdminAgent/Controllers/DemandController.php
+++ b/app/AdminAgent/Controllers/DemandController.php
@@ -149,7 +149,7 @@ class DemandController extends AdminController
$form->hidden('deadline');
$form->select('bidding_user_type','竞标用户类型')
->when([2],function (Form $form){
- $form->select('demand_product_id','产品')->options(function (){
+ $form->select('agent_product_id','产品')->options(function (){
return AgentProduct::query()->where('agent_id',Admin::user()->id)->pluck('title','id');
});
})
@@ -204,7 +204,7 @@ class DemandController extends AdminController
$demand->save();
//如果是地接类型 绑定地接到订单
if ($demand->bidding_user_type == DemandTraits::$col[2]){
- $agentProduct = AgentProduct::find($demand->demand_product_id);
+ $agentProduct = AgentProduct::find($demand->agent_product_id);
$agentProduct->guide_id = $demandBidding->bidding_user_id;
$agentProduct->save();
}
diff --git a/app/AdminAgent/Controllers/MyDemandProductController.php b/app/AdminAgent/Controllers/MyDemandProductController.php
new file mode 100755
index 0000000..eba3fd6
--- /dev/null
+++ b/app/AdminAgent/Controllers/MyDemandProductController.php
@@ -0,0 +1,71 @@
+model()
+ ->where(['publisher_id' => Admin::user()->id,'publisher_type' => DemandTraits::$col[0]])
+ ->where('product_id','>',0);
+
+ $grid->column('id')->sortable();
+ //$grid->column('title');
+ //$grid->column('detail','内容')->display('查看')->modal('详情',function ($modal) {
+ // $modal->xl();
+ // return $this->comment;
+ //});
+ $grid->column('biddingUser.name','中标人');
+ $grid->column('price','发标价格');
+ $grid->column('product.category.name', '产品分类');
+ $grid->column('product.title','产品标题');
+ $grid->column('product.picture','产品图片')->image('', 60, 60);
+ $grid->column('product.price','产品售价');
+ $grid->column('product.original_price','产品原价');
+ $grid->column('product.stock','产品库存');
+ $grid->column('product.sale','产品销量');
+ $grid->column('product.status','产品状态')->using(ProductStatus::array());
+ $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);
+ });
+ });
+ }
+
+}
diff --git a/app/AdminAgent/routes.php b/app/AdminAgent/routes.php
index 423bb12..a76dbd2 100644
--- a/app/AdminAgent/routes.php
+++ b/app/AdminAgent/routes.php
@@ -26,7 +26,7 @@ Route::group([
$router->resource('demand', 'DemandController');
$router->resource('demand_bidding', 'DemandBiddingController');
- $router->resource('my_demand_product', 'ProductController');
+ $router->resource('my_demand_product', 'MyDemandProductController');
$router->resource('message/list', 'MessageController');
$router->resource('notice/list', 'NoticeController');
diff --git a/app/AdminGuide/Controllers/MyDemandProductController.php b/app/AdminGuide/Controllers/MyDemandProductController.php
new file mode 100755
index 0000000..1835570
--- /dev/null
+++ b/app/AdminGuide/Controllers/MyDemandProductController.php
@@ -0,0 +1,79 @@
+model()
+ ->where(['bidding_user_id' => Admin::user()->id,'bidding_user_type' => DemandTraits::$col[2]])
+ ->where('agent_product_id','>',0);
+
+ $grid->column('id')->sortable();
+ //$grid->column('title');
+ //$grid->column('detail','内容')->display('查看')->modal('详情',function ($modal) {
+ // $modal->xl();
+ // return $this->comment;
+ //});
+ $grid->column('agentProduct.picture', '产品图片')->image('', 60, 60);
+ $grid->column('agentProduct.title', '产品名称')->limit(15);
+ $grid->column('agentProduct.price','产品价格');
+ $grid->column('agentProduct.original_price','产品原价');
+ $grid->column('agentProduct.sale','产品销量');
+ $grid->column('agentProduct.stock','产品库存');
+
+ $grid->column('channel_id', '频道')
+ ->display(function ($modal) {
+
+ $channels = Channel::where('agent_id', $this->publisher_id)->pluck('name', 'id')->toArray();
+
+ $data = array_flip(explode(',', $this->channel_id));
+ return join(',',array_intersect_key($channels, $data));
+ })
+ ->limit(10);
+ $grid->column('agentProduct.category.name', '分类');
+ $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);
+ });
+ });
+ }
+
+}
diff --git a/app/AdminGuide/routes.php b/app/AdminGuide/routes.php
index 0eb6530..5eb9d79 100644
--- a/app/AdminGuide/routes.php
+++ b/app/AdminGuide/routes.php
@@ -18,4 +18,5 @@ Route::group([
$router->resource('order/list', 'OrderController');
$router->resource('demand', 'DemandController');
$router->resource('demand_bidding', 'DemandBiddingController');
+ $router->resource('my_demand_product', 'MyDemandProductController');
});
diff --git a/app/AdminSupplier/Controllers/MyDemandProductController.php b/app/AdminSupplier/Controllers/MyDemandProductController.php
new file mode 100755
index 0000000..a9ce7d2
--- /dev/null
+++ b/app/AdminSupplier/Controllers/MyDemandProductController.php
@@ -0,0 +1,71 @@
+model()
+ ->where(['bidding_user_id' => Admin::user()->id,'bidding_user_type' => DemandTraits::$col[1]])
+ ->where('product_id','>',0);
+
+ $grid->column('id')->sortable();
+ //$grid->column('title');
+ //$grid->column('detail','内容')->display('查看')->modal('详情',function ($modal) {
+ // $modal->xl();
+ // return $this->comment;
+ //});
+ $grid->column('biddingUser.name','中标人');
+ $grid->column('price','发标价格');
+ $grid->column('product.category.name', '产品分类');
+ $grid->column('product.title','产品标题');
+ $grid->column('product.picture','产品图片')->image('', 60, 60);
+ $grid->column('product.price','产品售价');
+ $grid->column('product.original_price','产品原价');
+ $grid->column('product.stock','产品库存');
+ $grid->column('product.sale','产品销量');
+ $grid->column('product.status','产品状态')->using(ProductStatus::array());
+ $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);
+ });
+ });
+ }
+
+}
diff --git a/app/AdminSupplier/routes.php b/app/AdminSupplier/routes.php
index 9c9957d..d32c73a 100644
--- a/app/AdminSupplier/routes.php
+++ b/app/AdminSupplier/routes.php
@@ -23,7 +23,7 @@ Route::group([
$router->resource('demand', 'DemandController');
$router->resource('demand_bidding', 'DemandBiddingController');
$router->resource('demand_product', 'DemandProductController');
-
+ $router->resource('my_demand_product', 'MyDemandProductController');
//api
$router->any('/api/demand/binding', 'DemandController@binding');
});
diff --git a/app/Models/Demand.php b/app/Models/Demand.php
index 48930b0..b53bdc3 100755
--- a/app/Models/Demand.php
+++ b/app/Models/Demand.php
@@ -9,11 +9,11 @@ use Illuminate\Database\Eloquent\Model;
class Demand extends BaseModel
{
use HasDateTimeFormatter;
- use SoftDeletes;
+ use SoftDeletes;
- protected $table = 'demand';
+ protected $table = 'demand';
- public function publisher()
+ public function publisher()
{
return $this->morphTo();
}
@@ -22,4 +22,14 @@ class Demand extends BaseModel
{
return $this->morphTo();
}
+
+ public function product()
+ {
+ return $this->hasOne(Product::class, 'id', 'product_id');
+ }
+
+ public function agentproduct()
+ {
+ return $this->hasOne(AgentProduct::class, 'id', 'agent_product_id');
+ }
}
diff --git a/resources/lang/zh_CN/my-demand-product.php b/resources/lang/zh_CN/my-demand-product.php
new file mode 100755
index 0000000..afbb895
--- /dev/null
+++ b/resources/lang/zh_CN/my-demand-product.php
@@ -0,0 +1,21 @@
+ [
+ 'MyDemandProduct' => '我的竞标产品库',
+ 'my_demand_product' => '我的竞标产品库',
+ ],
+ 'fields' => [
+ 'title' => '标题',
+ 'comment' => '内容',
+ 'deadline' => '流拍时间',
+ 'type' => '类型',
+ 'price' => '价格',
+ 'stock' => '库存',
+ 'publisher_type' => '发布人身份',
+ 'publisher_id' => '发布人',
+ 'state' => '状态',
+ 'bidding_id' => '竞拍成功id 关联竞标表',
+ ],
+ 'options' => [
+ ],
+];
From 8fb1bce067e4bc981a14a5cff90657723eaf5bb3 Mon Sep 17 00:00:00 2001
From: liapples
Date: Mon, 30 Aug 2021 10:24:10 +0800
Subject: [PATCH 05/26] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=B8=B8=E9=87=8F?=
=?UTF-8?q?=E5=90=8D?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/Common/PayType.php | 8 ++++----
app/Http/Controllers/Api/OrderController.php | 2 +-
app/Http/Controllers/Api/WxpayController.php | 2 +-
3 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/app/Common/PayType.php b/app/Common/PayType.php
index 132ee54..b9b7c7b 100644
--- a/app/Common/PayType.php
+++ b/app/Common/PayType.php
@@ -16,10 +16,10 @@ class PayType
const OFFLINE = 1;
/** @var int 订金支付 */
- const SUBSCRIPTION = 2;
+ const DEPOSIT_PAY = 2;
/** @var int 定金支付 */
- const DEPOSIT = 3;
+ const EARNEST_PAY = 3;
/** @var int 尾款/多加支付 */
const DOWN_PAYMENT = 4;
@@ -32,8 +32,8 @@ class PayType
return [
self::ONLINE => '在线支付',
self::OFFLINE => '线下支付',
- self::SUBSCRIPTION => '订金支付',
- self::DEPOSIT => '定金支付',
+ self::DEPOSIT_PAY => '订金支付',
+ self::EARNEST_PAY => '定金支付',
self::DOWN_PAYMENT => '首款支付',
self::BALANCE_PAY => '尾款/多加支付',
];
diff --git a/app/Http/Controllers/Api/OrderController.php b/app/Http/Controllers/Api/OrderController.php
index fd84711..0c8adfb 100644
--- a/app/Http/Controllers/Api/OrderController.php
+++ b/app/Http/Controllers/Api/OrderController.php
@@ -379,7 +379,7 @@ class OrderController extends Controller
private function calc($price, $coupon, $num, $pay_type)
{
//根据支付方式计算价格
- if (in_array($pay_type, [PayType::SUBSCRIPTION, PayType::DEPOSIT, PayType::DOWN_PAYMENT])) {
+ if (in_array($pay_type, [PayType::DEPOSIT_PAY, PayType::EARNEST_PAY, PayType::DOWN_PAYMENT])) {
return $this->earnest;
}
//TODO 还要计算尾款支付金额
diff --git a/app/Http/Controllers/Api/WxpayController.php b/app/Http/Controllers/Api/WxpayController.php
index 766da12..938c0a2 100644
--- a/app/Http/Controllers/Api/WxpayController.php
+++ b/app/Http/Controllers/Api/WxpayController.php
@@ -66,7 +66,7 @@ class WxpayController
$pay_type = $order->pay_type;
$money = $message['total_fee'] / 100;
//定金支付和首付款支付
- if (in_array($pay_type, [PayType::SUBSCRIPTION, PayType::DEPOSIT, PayType::DOWN_PAYMENT])) {
+ if (in_array($pay_type, [PayType::DEPOSIT_PAY, PayType::EARNEST_PAY, PayType::DOWN_PAYMENT])) {
if ($status == OrderStatus::UNPAID) {
$order->status = OrderStatus::PAY_EARNEST;
} else if ($status == OrderStatus::PAY_EARNEST) {
From 192e9c1408408353d0ca7d707948a0d38ff0ddf3 Mon Sep 17 00:00:00 2001
From: liapples
Date: Mon, 30 Aug 2021 10:45:23 +0800
Subject: [PATCH 06/26] =?UTF-8?q?=E8=AE=A2=E9=87=91=E5=92=8C=E5=AE=9A?=
=?UTF-8?q?=E9=87=91=E6=A0=B9=E6=8D=AE=E4=BA=A7=E5=93=81=E6=9D=A5=E8=AE=BE?=
=?UTF-8?q?=E5=AE=9A?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
MySQL_change.sql | 7 +++++
.../Controllers/AgentProductController.php | 21 +++++++++++--
app/Http/Controllers/Api/OrderController.php | 31 +++++++++++--------
resources/lang/zh_CN/agent-product.php | 4 +++
4 files changed, 48 insertions(+), 15 deletions(-)
diff --git a/MySQL_change.sql b/MySQL_change.sql
index 32611e9..771a575 100644
--- a/MySQL_change.sql
+++ b/MySQL_change.sql
@@ -210,3 +210,10 @@ ALTER TABLE `notices`
ADD COLUMN `author` VARCHAR(20) NOT NULL DEFAULT '' COMMENT '作者' COLLATE 'utf8_general_ci' AFTER `sort`;
ALTER TABLE `articles`
ADD COLUMN `agent_product_ids` TEXT NULL DEFAULT NULL COMMENT '绑定产品' AFTER `sort`;
+
+# 9:28 2021/8/30
+ALTER TABLE `agent_products`
+ ADD COLUMN `earnest` DECIMAL(20,2) NOT NULL DEFAULT '0' COMMENT '定金' AFTER `content`,
+ ADD COLUMN `earnest_timeout` INT NOT NULL DEFAULT 0 COMMENT '定金支付超时时间,单位:分钟' AFTER `earnest`,
+ ADD COLUMN `deposit` DECIMAL(20,2) NOT NULL DEFAULT 0 COMMENT '订金' AFTER `earnest_timeout`,
+ ADD COLUMN `deposit_timeout` INT NOT NULL DEFAULT 0 COMMENT '订金支付超时时间,单位:分钟' AFTER `deposit`;
diff --git a/app/AdminAgent/Controllers/AgentProductController.php b/app/AdminAgent/Controllers/AgentProductController.php
index c0e0727..2f1b258 100644
--- a/app/AdminAgent/Controllers/AgentProductController.php
+++ b/app/AdminAgent/Controllers/AgentProductController.php
@@ -125,6 +125,10 @@ class AgentProductController extends AdminController
$show->field('pictures')->image('', 80, 80);
$show->field('know')->unescape();
$show->field('content')->unescape();
+ $show->field('earnest');
+ $show->field('earnest_timeout');
+ $show->field('deposit');
+ $show->field('deposit_timeout');
$show->field('created_at');
$show->field('updated_at');
@@ -223,6 +227,11 @@ class AgentProductController extends AdminController
->from(SelectGuide::make())
->model(Guide::class, 'id', 'name');
}
+
+ $form->text('earnest')->default(0)->help('单位:元。不输入或输入 0 则不支持定金支付,必须和定金超时时间同时设置才会生效');
+ $form->text('earnest_timeout')->default(0)->help('单位:分钟。超过这个时间未支付,订单将自动关闭');
+ $form->text('deposit')->default(0)->help('单位:元。不输入或输入 0 则不支持订金支付,必须和订金超时时间同时设置才会生效');
+ $form->text('deposit_timeout')->default(0)->help('单位:分钟。超过这个时间未支付,订单将自动关闭');
})->saving(function (Form $form) {
//不允许修改非自己的数据
if ($form->isEditing() && $form->model()->agent_id != Admin::user()->id) {
@@ -303,12 +312,20 @@ class AgentProductController extends AdminController
//处理特殊字段
$form->hidden(['agent_id', 'status']); //表单没有的字段,必须加这句才能够重写
$form->agent_id = $agent_id;
- if (array_key_exists($form->status, $form->input())) {
+ if (array_key_exists('status', $form->input())) {
$form->status = $form->status == ProductStatus::ON_SALE ? ProductStatus::ON_SALE : ProductStatus::SOLD_OUT;
}
- if (array_key_exists($form->guide_id, $form->input())) {
+ if (array_key_exists('guide_id', $form->input())) {
$form->guide_id = $form->guide_id ?? 0;
}
+ if ($form->earnest <= 0 || $form->earnest_timeout <= 0) {
+ $form->earnest = 0;
+ $form->earnest_timeout = 0;
+ }
+ if ($form->deposit <= 0 || $form->deposit_timeout <= 0) {
+ $form->deposit = 0;
+ $form->deposit_timeout = 0;
+ }
//不允许编辑的字段
$form->ignore(['id', 'agent_id', 'status', 'created_at', 'updated_at', 'deleted_at']);
diff --git a/app/Http/Controllers/Api/OrderController.php b/app/Http/Controllers/Api/OrderController.php
index 0c8adfb..acc7fbd 100644
--- a/app/Http/Controllers/Api/OrderController.php
+++ b/app/Http/Controllers/Api/OrderController.php
@@ -14,6 +14,7 @@ use EasyWeChat\Factory;
use EasyWeChat\Kernel\Exceptions\InvalidArgumentException;
use EasyWeChat\Kernel\Exceptions\InvalidConfigException;
use GuzzleHttp\Exception\GuzzleException;
+use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use App\Common\OrderStatus as Status;
@@ -144,7 +145,7 @@ class OrderController extends Controller
DB::beginTransaction();
try {
- $price = $this->calc($ap->price, $ap->coupon, $formData['num'], $formData['pay_type']);
+ $price = $this->calc($ap->price, $formData['num'], $formData['pay_type'], $ap);
$title = $ap->title; //产品标题
//供应商产品表减库存
@@ -252,7 +253,7 @@ class OrderController extends Controller
$ap = AgentProduct::query()
->has('product')
->with('coupon:agent_product_id,type,detail,agent_id,tag,start_at,end_at')
- ->find($formData['id'], ['id', 'price', 'original_price', 'product_id', 'title', 'pictures']);
+ ->find($formData['id'], ['id', 'price', 'original_price', 'product_id', 'title', 'pictures', 'earnest', 'earnest_timeout', 'deposit', 'deposit_timeout']);
if (!$ap) {
return $this->error('产品信息不存在');
@@ -266,7 +267,7 @@ class OrderController extends Controller
$formData['pay_type'] = PayType::ONLINE;
}
- $ap->final_price = $this->calc($ap->price, $ap->coupon, $formData['num'], $formData['pay_type']);
+ $ap->final_price = $this->calc($ap->price, $formData['num'], $formData['pay_type'], $ap);
$ap->num = $formData['num'];
return $this->success($ap);
}
@@ -286,13 +287,13 @@ class OrderController extends Controller
return $this->error('订单不存在或已支付');
}
- $coupon = Coupon::whereIn('id', $order['coupon_id'])->get();
+ $ap = AgentProduct::with('coupon')->find($order->agent_product_id);
//如果已经付定金或首付款,则仅支付尾款
if ($order->status == Status::PAY_EARNEST) {
$price = $order->price - $order->paid_money;
} else {
- $price = $this->calc($order->price, $coupon, $order->num, $order->pay_type);
+ $price = $this->calc($order->price, $order->num, $order->pay_type, $ap);
}
$config = $this->payConfig($order, $price);
@@ -371,21 +372,25 @@ class OrderController extends Controller
* 计算最终价格(扣除优惠券之后的价格)
* $price:原价;$coupon:优惠券;$num:产品数量;$pay_type:支付方式
* @param float $price
- * @param Coupon $coupon
* @param int $num
* @param int $pay_type
+ * @param Model $agent_product
* @return float
*/
- private function calc($price, $coupon, $num, $pay_type)
+ private function calc($price, $num, $pay_type, $agent_product)
{
//根据支付方式计算价格
if (in_array($pay_type, [PayType::DEPOSIT_PAY, PayType::EARNEST_PAY, PayType::DOWN_PAYMENT])) {
- return $this->earnest;
+ if ($pay_type == PayType::DEPOSIT_PAY && $agent_product->deposit && $agent_product->deposit_timeout) {
+ return $agent_product->deposit;
+ }
+ if ($pay_type == PayType::EARNEST_PAY && $agent_product->earnest && $agent_product->earnest_timeout) {
+ return $agent_product->earnest;
+ }
}
- //TODO 还要计算尾款支付金额
$total_price = $price * $num;
- //没有任何优惠券时直接返回最终价
+ /*//没有任何优惠券时直接返回最终价
if ($coupon && $coupon->isEmpty()) {
return $total_price;
}
@@ -393,14 +398,14 @@ class OrderController extends Controller
$coupon = $coupon->toArray();
foreach ($coupon as $v) {
// TODO 未判断优惠券有效期
- /*if ($v['type'] == 1 && !empty($v['detail']['full']) && !empty($v['detail']['reduction'])) { //满减
+ if ($v['type'] == 1 && !empty($v['detail']['full']) && !empty($v['detail']['reduction'])) { //满减
if ($total_price >= $v['detail']['full']) {
$total_price -= $v['detail']['reduction'];
}
} else if ($v['type'] == 2 && !empty($v['detail']['discount'])) { //打折
$total_price *= $v['detail']['discount'];
- }*/
- }
+ }
+ }*/
return round($total_price, 2);
}
diff --git a/resources/lang/zh_CN/agent-product.php b/resources/lang/zh_CN/agent-product.php
index 2d914c6..28ab890 100644
--- a/resources/lang/zh_CN/agent-product.php
+++ b/resources/lang/zh_CN/agent-product.php
@@ -21,6 +21,10 @@ return [
'know' => '旅游须知',
'pictures' => '产品图片',
'picture' => '产品图片',
+ 'earnest' => '定金',
+ 'earnest_timeout' => '定金超时时间',
+ 'deposit' => '订金',
+ 'deposit_timeout' => '订金超时时间',
'product' => trans('product.fields'),
],
'options' => [
From 8ff344e84298db9c39401ce193c83c7456bad1af Mon Sep 17 00:00:00 2001
From: lemon <15040771@qq.com>
Date: Mon, 30 Aug 2021 10:47:15 +0800
Subject: [PATCH 07/26] =?UTF-8?q?=E5=AE=A1=E6=A0=B8?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../Controllers/DemandProductController.php | 73 +++++++++++++++++++
.../Extensions/Grid/AuditDemandProduct.php | 57 +++++++++++++++
app/Admin/routes.php | 1 +
resources/lang/zh_CN/demand-product.php | 12 +--
4 files changed, 138 insertions(+), 5 deletions(-)
create mode 100644 app/Admin/Controllers/DemandProductController.php
create mode 100644 app/Admin/Extensions/Grid/AuditDemandProduct.php
diff --git a/app/Admin/Controllers/DemandProductController.php b/app/Admin/Controllers/DemandProductController.php
new file mode 100644
index 0000000..da95a56
--- /dev/null
+++ b/app/Admin/Controllers/DemandProductController.php
@@ -0,0 +1,73 @@
+disableCreateButton();
+ //如果是审核页面,多加where条件判断
+ if (strpos(Route::current()->uri, 'audit')) {
+ $grid->model()->where('status', ProductStatus::UNAUDITED);
+ }
+
+ $grid->column('id')->sortable();
+ $grid->column('category.name', '分类');
+ $grid->column('picture')->image('', 60, 60);
+ $grid->column('title');
+ $grid->column('original_price');
+ $grid->column('price');
+ $grid->column('sale');
+ $grid->column('stock');
+ $grid->column('supplier.name', '供应商');
+ $grid->column('status')
+ ->if(fn() => $this->status == ProductStatus::UNAUDITED)
+ ->display('')
+ ->then(function ($column) {
+ $column->append((new AuditDemandProduct(null, 1))->setKey($this->id))->append(' ');
+ $column->append((new AuditDemandProduct(null, 2))->setKey($this->id));
+ })
+ ->else()
+ ->using(ProductStatus::array())
+ ->dot([
+ ProductStatus::ON_SALE => 'success',
+ ProductStatus::UNAUDITED => '',
+ ProductStatus::REFUSE => 'danger',
+ ProductStatus::SOLD_OUT => 'warning',
+ ], 'primary');
+ $grid->column('created_at');
+ $grid->column('updated_at');
+ $grid->disableDeleteButton();
+ $grid->disableEditButton();
+ $grid->disableQuickEditButton();
+ $grid->disableViewButton();
+ $grid->filter(function (Grid\Filter $filter) {
+ $filter->panel();
+
+ $filter->equal('id')->width(2);
+ $filter->like('title')->width(3);
+ $filter->equal('status')->select(ProductStatus::array())->width(2);
+ });
+ });
+ }
+}
diff --git a/app/Admin/Extensions/Grid/AuditDemandProduct.php b/app/Admin/Extensions/Grid/AuditDemandProduct.php
new file mode 100644
index 0000000..cdbfa3f
--- /dev/null
+++ b/app/Admin/Extensions/Grid/AuditDemandProduct.php
@@ -0,0 +1,57 @@
+action = $action; //$action:1=通过;2=拒绝
+ $this->title = $action == 1 ? '通过' : '拒绝';
+ }
+
+ protected function html()
+ {
+ $class = $this->action == 1 ? 'btn btn-sm btn-success' : 'btn btn-sm btn-danger';
+ $this->appendHtmlAttribute('class', $class);
+ $this->defaultHtmlAttribute('href', 'javascript:;');
+
+ return "formatHtmlAttributes()}>{$this->title}";
+ }
+
+ public function handle(Request $request)
+ {
+ try {
+ $product = DemandProduct::find($this->getKey());
+ $product->status = $request->action == 1 ? ProductStatus::ON_SALE : ProductStatus::REFUSE;
+ $product->save();
+
+ return $this->response()->success("审核成功")->refresh();
+ } catch (\Exception $e) {
+ return $this->response()->error($e->getMessage());
+ }
+ }
+
+ public function confirm()
+ {
+ return ['确定要'.$this->title.'该产品吗?', ''];
+ }
+
+ public function parameters()
+ {
+ return ['action' => $this->action];
+ }
+}
diff --git a/app/Admin/routes.php b/app/Admin/routes.php
index 1330535..2895ebd 100644
--- a/app/Admin/routes.php
+++ b/app/Admin/routes.php
@@ -26,4 +26,5 @@ Route::group([
$router->resource('category/list', 'CategoryController');
$router->resource('product/list', 'ProductController');
$router->resource('product/audit', 'ProductController');
+ $router->resource('demand/product', 'DemandProductController');
});
diff --git a/resources/lang/zh_CN/demand-product.php b/resources/lang/zh_CN/demand-product.php
index 45487b2..ac923a0 100755
--- a/resources/lang/zh_CN/demand-product.php
+++ b/resources/lang/zh_CN/demand-product.php
@@ -1,8 +1,10 @@
- [
- 'DemandProduct' => 'DemandProduct',
- 'demand-product' => 'DemandProduct',
+ 'DemandProduct' => '需求市场产品',
+ 'demand-product' => '需求市场产品',
+ 'demand' => '需求市场',
+ 'product' => '产品',
],
'fields' => [
'agent_id' => '代理商id 竞标特供',
@@ -10,10 +12,10 @@ return [
'content' => '产品详情',
'know' => '旅客须知',
'original_price' => '原价',
- 'pictures' => '产品图片,可能有多张,JSON格式',
+ 'picture' => '产品图片',
'price' => '价格',
'sale' => '销量',
- 'status' => '0:下架,1:在售',
+ 'status' => '状态',
'stock' => '库存量',
'supplier_id' => '供应商ID',
'title' => '标题',
From b35c9cff48e19241c352979f89a692b9a46bc417 Mon Sep 17 00:00:00 2001
From: liapples
Date: Mon, 30 Aug 2021 10:52:07 +0800
Subject: [PATCH 08/26] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=A1=BA=E5=BA=8F?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
MySQL_change.sql | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/MySQL_change.sql b/MySQL_change.sql
index 771a575..da88840 100644
--- a/MySQL_change.sql
+++ b/MySQL_change.sql
@@ -213,7 +213,7 @@ ALTER TABLE `articles`
# 9:28 2021/8/30
ALTER TABLE `agent_products`
- ADD COLUMN `earnest` DECIMAL(20,2) NOT NULL DEFAULT '0' COMMENT '定金' AFTER `content`,
- ADD COLUMN `earnest_timeout` INT NOT NULL DEFAULT 0 COMMENT '定金支付超时时间,单位:分钟' AFTER `earnest`,
- ADD COLUMN `deposit` DECIMAL(20,2) NOT NULL DEFAULT 0 COMMENT '订金' AFTER `earnest_timeout`,
- ADD COLUMN `deposit_timeout` INT NOT NULL DEFAULT 0 COMMENT '订金支付超时时间,单位:分钟' AFTER `deposit`;
+ ADD COLUMN `deposit` DECIMAL(20,2) NOT NULL DEFAULT 0 COMMENT '订金' AFTER `content`,
+ ADD COLUMN `deposit_timeout` INT NOT NULL DEFAULT 0 COMMENT '订金支付超时时间,单位:分钟' AFTER `deposit`,
+ ADD COLUMN `earnest` DECIMAL(20,2) NOT NULL DEFAULT '0' COMMENT '定金' AFTER `deposit_timeout`,
+ ADD COLUMN `earnest_timeout` INT NOT NULL DEFAULT 0 COMMENT '定金支付超时时间,单位:分钟' AFTER `earnest`;
From 750d7d058d8b013fc39a11e727a692f92b3ee750 Mon Sep 17 00:00:00 2001
From: lemon <15040771@qq.com>
Date: Mon, 30 Aug 2021 10:53:48 +0800
Subject: [PATCH 09/26] =?UTF-8?q?=E7=8A=B6=E6=80=81?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/Admin/Controllers/DemandProductController.php | 1 +
app/AdminAgent/Controllers/DemandController.php | 2 +-
app/AdminSupplier/Controllers/DemandController.php | 2 +-
3 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/app/Admin/Controllers/DemandProductController.php b/app/Admin/Controllers/DemandProductController.php
index da95a56..88af1a9 100644
--- a/app/Admin/Controllers/DemandProductController.php
+++ b/app/Admin/Controllers/DemandProductController.php
@@ -61,6 +61,7 @@ class DemandProductController extends AdminController
$grid->disableEditButton();
$grid->disableQuickEditButton();
$grid->disableViewButton();
+ $grid->disableActions();
$grid->filter(function (Grid\Filter $filter) {
$filter->panel();
diff --git a/app/AdminAgent/Controllers/DemandController.php b/app/AdminAgent/Controllers/DemandController.php
index 6154df2..e062f21 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('agent_product_id','产品')->options(function (){
- return AgentProduct::query()->where('agent_id',Admin::user()->id)->pluck('title','id');
+ return AgentProduct::query()->where('agent_id',Admin::user()->id)->where('status',1)->pluck('title','id');
});
})
->options([
diff --git a/app/AdminSupplier/Controllers/DemandController.php b/app/AdminSupplier/Controllers/DemandController.php
index bc6339b..87f9861 100755
--- a/app/AdminSupplier/Controllers/DemandController.php
+++ b/app/AdminSupplier/Controllers/DemandController.php
@@ -144,7 +144,7 @@ class DemandController extends AdminController
$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');
+ return DemandProduct::query()->where('supplier_id',Admin::user()->id)->where('status',1)->pluck('title','id');
});
})
->options([
From 461a4041a97422ce848f55c6f6e6934011d147d7 Mon Sep 17 00:00:00 2001
From: liapples
Date: Mon, 30 Aug 2021 11:36:40 +0800
Subject: [PATCH 10/26] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=80=80=E6=AC=BE?=
=?UTF-8?q?=E8=AF=A6=E6=83=85=E7=82=B9=E5=87=BB=E6=97=A0=E5=93=8D=E5=BA=94?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/AdminAgent/Controllers/OrderController.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/app/AdminAgent/Controllers/OrderController.php b/app/AdminAgent/Controllers/OrderController.php
index b51a8d6..37e452f 100644
--- a/app/AdminAgent/Controllers/OrderController.php
+++ b/app/AdminAgent/Controllers/OrderController.php
@@ -52,6 +52,7 @@ class OrderController extends AdminController
$grid->column('status')
->using(OrderStatus::array())
->if(fn() => in_array($this->status, [OrderStatus::REFUNDING, OrderStatus::REFUNDED, OrderStatus::REFUSED_REFUND]))
+ ->display('退款详情 ')
->modal('查看退款详情', function (Grid\Displayers\Modal $modal) {
$modal->icon('');
if (!$this->refund_info) {
@@ -74,7 +75,6 @@ class OrderController extends AdminController
];
return Table::make($refund_info);
})
- ->display('退款详情 ') //放在modal下面可以去掉空格
->then(function (Grid\Column $column) {
if ($this->status == OrderStatus::REFUNDING) {
$column->append((new AuditRefund(null, 1))->setKey($this->id))->append(' ');
From 941a8821fc413897b949a65246abe31bc2dd4bf2 Mon Sep 17 00:00:00 2001
From: liapples
Date: Mon, 30 Aug 2021 11:37:08 +0800
Subject: [PATCH 11/26] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=88=9B=E5=BB=BA?=
=?UTF-8?q?=E6=97=B6=E6=8F=90=E7=A4=BA500?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/AdminAgent/Controllers/CategoryController.php | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/app/AdminAgent/Controllers/CategoryController.php b/app/AdminAgent/Controllers/CategoryController.php
index 1870ed6..ef56279 100644
--- a/app/AdminAgent/Controllers/CategoryController.php
+++ b/app/AdminAgent/Controllers/CategoryController.php
@@ -100,8 +100,11 @@ class CategoryController extends AdminController
//不允许编辑的字段
$form->ignore(['id', 'deleted_at']);
+ $form->hidden(['agent_id']);
$form->agent_id = Admin::user()->id;
- $form->sort = $form->sort ?? 255;
+ if (array_key_exists('sort', $form->input())) {
+ $form->sort = $form->sort ?? 255;
+ }
})->deleting(function (Form $form) {
//不允许修改非自己的数据
if (array_filter($form->model()->toArray(), fn($v) => $v['agent_id'] != Admin::user()->id)) {
From 99780a229439e7a454f34dc0421d04602c86b5b5 Mon Sep 17 00:00:00 2001
From: liapples
Date: Mon, 30 Aug 2021 14:47:37 +0800
Subject: [PATCH 12/26] =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E8=AE=BE=E7=BD=AE?=
=?UTF-8?q?=E4=BF=AE=E6=94=B9?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/AdminAgent/Forms/Setting.php | 10 ++++++----
app/Http/Controllers/Api/TestController.php | 2 +-
app/Models/AgentSetting.php | 5 +++--
resources/lang/zh_CN/setting.php | 4 ++--
4 files changed, 12 insertions(+), 9 deletions(-)
diff --git a/app/AdminAgent/Forms/Setting.php b/app/AdminAgent/Forms/Setting.php
index 3a4ff26..bba4d94 100644
--- a/app/AdminAgent/Forms/Setting.php
+++ b/app/AdminAgent/Forms/Setting.php
@@ -21,7 +21,7 @@ class Setting extends Form
AgentSetting::updateOrCreate(
['agent_id' => Admin::user()->id],
- ['setting' => json_encode($input), 'agent_id' => Admin::user()->id],
+ ['setting' => $input, 'agent_id' => Admin::user()->id],
);
return $this->response()->success('保存成功')->refresh();
@@ -32,8 +32,10 @@ class Setting extends Form
*/
public function form()
{
- $this->text('earnest')->required()->help('用户支付订金、定金、首付款的金额');
- $this->text('earnest_timeout')->required()->help('单位:分钟。当通过订金、定金、首付款支付时,用户超过该时间未支付将关闭订单,且定金不退');
+ $this->text('order_timeout')->required()->default(1440)
+ ->help('订单超时时间,单位:分钟。(订金、定金支付的超时时间将根据产品设定的超时时间)');
+ $this->radio('auto_shelves')->options(['否', '是'])->required()->default(1)
+ ->help('是否自动上架合作供应商的产品,如果选是,当合作供应商发布新产品之后,将自动上架供应商的产品');
}
/**
@@ -44,6 +46,6 @@ class Setting extends Form
public function default()
{
$setting = AgentSetting::where('agent_id', Admin::user()->id)->value('setting');
- return is_string($setting) ? json_decode($setting, true) : [];
+ return $setting ?? [];
}
}
diff --git a/app/Http/Controllers/Api/TestController.php b/app/Http/Controllers/Api/TestController.php
index 9626a91..337df8d 100644
--- a/app/Http/Controllers/Api/TestController.php
+++ b/app/Http/Controllers/Api/TestController.php
@@ -16,6 +16,6 @@ class TestController
public function index()
{
//test
- return AgentSetting::val(1, 'earnest') ?? 198.88;
+ return AgentSetting::val(11, 'order_timeout') ?? 188;
}
}
diff --git a/app/Models/AgentSetting.php b/app/Models/AgentSetting.php
index 83cded3..1a9fffc 100644
--- a/app/Models/AgentSetting.php
+++ b/app/Models/AgentSetting.php
@@ -9,6 +9,7 @@ class AgentSetting extends BaseModel
use HasFactory;
protected $fillable = ['agent_id', 'setting'];
+ protected $casts = ['setting' => 'json'];
public function __construct(array $attributes = [])
{
@@ -16,9 +17,9 @@ class AgentSetting extends BaseModel
$this->timestamps = false;
}
- public function scopeVal($query, $agent_id, $key)
+ public static function val($agent_id, $key)
{
- $setting = json_decode($query->where('agent_id', $agent_id)->value('setting'), true);
+ $setting = static::query()->where('agent_id', $agent_id)->value('setting');
return $setting[$key] ?? null;
}
}
diff --git a/resources/lang/zh_CN/setting.php b/resources/lang/zh_CN/setting.php
index 19a7f60..3c2ab7f 100644
--- a/resources/lang/zh_CN/setting.php
+++ b/resources/lang/zh_CN/setting.php
@@ -5,8 +5,8 @@ return [
'setting' => '系统设置',
],
'fields' => [
- 'earnest' => '定金金额',
- 'earnest_timeout' => '定金支付超时时间',
+ 'order_timeout' => '订单超时时间',
+ 'auto_shelves' => '自动上架',
],
'options' => [
],
From 71120f0701b30e67f75a09e394229294a50a8bb4 Mon Sep 17 00:00:00 2001
From: liapples
Date: Mon, 30 Aug 2021 14:48:28 +0800
Subject: [PATCH 13/26] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=AE=A2=E5=8D=95?=
=?UTF-8?q?=E8=B6=85=E6=97=B6=E5=AD=97=E6=AE=B5?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
MySQL_change.sql | 4 ++++
app/Http/Controllers/Api/OrderController.php | 18 ++++++++++++++----
2 files changed, 18 insertions(+), 4 deletions(-)
diff --git a/MySQL_change.sql b/MySQL_change.sql
index da88840..887a3de 100644
--- a/MySQL_change.sql
+++ b/MySQL_change.sql
@@ -217,3 +217,7 @@ ALTER TABLE `agent_products`
ADD COLUMN `deposit_timeout` INT NOT NULL DEFAULT 0 COMMENT '订金支付超时时间,单位:分钟' AFTER `deposit`,
ADD COLUMN `earnest` DECIMAL(20,2) NOT NULL DEFAULT '0' COMMENT '定金' AFTER `deposit_timeout`,
ADD COLUMN `earnest_timeout` INT NOT NULL DEFAULT 0 COMMENT '定金支付超时时间,单位:分钟' AFTER `earnest`;
+
+# 10:58 2021/8/30
+ALTER TABLE `orders`
+ ADD COLUMN `timeout` TIMESTAMP NULL DEFAULT NULL COMMENT '订单超时时间,超过这个时间,订单将变为“已取消”' AFTER `verify_code`;
diff --git a/app/Http/Controllers/Api/OrderController.php b/app/Http/Controllers/Api/OrderController.php
index acc7fbd..6488299 100644
--- a/app/Http/Controllers/Api/OrderController.php
+++ b/app/Http/Controllers/Api/OrderController.php
@@ -6,8 +6,8 @@ use App\Common\PayType;
use App\Http\Controllers\Controller;
use App\Models\Agent;
use App\Models\AgentProduct;
+use App\Models\AgentSetting;
use App\Models\Coupon;
-use App\Models\Product;
use App\Models\User;
use App\Models\Order;
use EasyWeChat\Factory;
@@ -74,8 +74,8 @@ class OrderController extends Controller
}, $v['pictures']);
}
- //10分钟内未付款订单提示付款
- if ($v['status'] == Status::UNPAID) {
+ //10分钟内未付款订单提示付款 TODO 此部分由定时
+ /*if ($v['status'] == Status::UNPAID) {
$minute = $time - strtotime($v['created_at']);
//订单创建后10分钟内未付款则提示,否则取消订单
if ($minute < 600) {
@@ -87,7 +87,7 @@ class OrderController extends Controller
//TODO 加回库存,未考虑到几天/几个月后再打开订单列表页的情况,需要定时任务处理
Product::query()->find($v['product_id'])->increment('stock', $v['num']);
}
- }
+ }*/
}
//超时订单设置为已取消 TODO 测试阶段暂时注释
@@ -154,6 +154,15 @@ class OrderController extends Controller
//代理商产品表减库存
$ap->decrement('stock', $formData['num']);
+ if ($formData['pay_type'] == PayType::DEPOSIT_PAY && $ap->deposit_timeout > 0) {
+ $timeout = date('Y-m-d H:i:s', time() + $ap->deposit_timeout * 60);
+ } else if ($formData['pay_type'] == PayType::EARNEST_PAY && $ap->earnest_timeout > 0) {
+ $timeout = date('Y-m-d H:i:s', time() + $ap->earnest_timeout * 60);
+ } else {
+ $order_timeout = AgentSetting::val($this->agent_id, 'order_timeout') ?? 1440;
+ $timeout = date('Y-m-d H:i:s', time() + $ap->earnest_timeout * $order_timeout);
+ }
+
// 存入订单表
$order = Order::query()->create([
'user_id' => $this->user_id,
@@ -172,6 +181,7 @@ class OrderController extends Controller
'pay_type' => $formData['pay_type'],
'coupon_id' => join(',', $coupon_ids),
'guide_id' => $ap->guide_id,
+ 'timeout' => $timeout,
]);
DB::commit();
From 803de4c5e9e287aab63cd2caaa84c74e172a376b Mon Sep 17 00:00:00 2001
From: lemon <15040771@qq.com>
Date: Mon, 30 Aug 2021 16:54:54 +0800
Subject: [PATCH 14/26] =?UTF-8?q?=E7=9F=AD=E4=BF=A1?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../DemandBiddingServiceProvider.php | 38 +++++
app/Service/SmsService.php | 115 +++++++++++++
composer.json | 3 +-
composer.lock | 154 ++++++++----------
config/sms.php | 16 ++
5 files changed, 242 insertions(+), 84 deletions(-)
create mode 100644 app/Providers/DemandBiddingServiceProvider.php
create mode 100644 app/Service/SmsService.php
create mode 100644 config/sms.php
diff --git a/app/Providers/DemandBiddingServiceProvider.php b/app/Providers/DemandBiddingServiceProvider.php
new file mode 100644
index 0000000..580d37c
--- /dev/null
+++ b/app/Providers/DemandBiddingServiceProvider.php
@@ -0,0 +1,38 @@
+with('publisher')->where('id',$order->demand_id)->first();
+ if(!empty($demand->publisher->contact_phone)) {
+ $smsConfig = config('sms.tencent');
+ $sms = new SmsService();
+ $sms->send($smsConfig['templates']['bidding'],['','$demand->id'],$demand->publisher->contact_phone);
+ }
+ });
+ }
+}
diff --git a/app/Service/SmsService.php b/app/Service/SmsService.php
new file mode 100644
index 0000000..d41555c
--- /dev/null
+++ b/app/Service/SmsService.php
@@ -0,0 +1,115 @@
+cfg = config('sms.tencent');
+ $cred = new Credential($this->cfg['secret_id'], $this->cfg['secret_key']);
+ // $cred = new Credential(getenv("TENCENTCLOUD_SECRET_ID"), getenv("TENCENTCLOUD_SECRET_KEY"));
+ // 实例化一个http选项,可选的,没有特殊需求可以跳过
+ $httpProfile = new HttpProfile();
+ // 配置代理
+ // $httpProfile->setProxy("https://ip:port");
+ $httpProfile->setReqMethod("GET"); // post请求(默认为post请求)
+ $httpProfile->setReqTimeout(30); // 请求超时时间,单位为秒(默认60秒)
+ $httpProfile->setEndpoint("sms.tencentcloudapi.com"); // 指定接入地域域名(默认就近接入)
+ // 实例化一个client选项,可选的,没有特殊需求可以跳过
+ $clientProfile = new ClientProfile();
+ $clientProfile->setSignMethod("TC3-HMAC-SHA256"); // 指定签名算法(默认为HmacSHA256)
+ $clientProfile->setHttpProfile($httpProfile);
+ // 实例化要请求产品(以sms为例)的client对象,clientProfile是可选的
+ // 第二个参数是地域信息,可以直接填写字符串 ap-guangzhou,或者引用预设的常量
+ $this->client = new SmsClient($cred, 'ap-guangzhou', $clientProfile);
+ }
+
+ public function send($templateId, $templateParamSet, $phoneNumberSet, $signName = '领峰远扬')
+ {
+ //if (!config('sms.debug') || config('sms.debug') == 'yes') {
+ // Log::debug([$templateId, $templateParamSet, $phoneNumberSet, $signName]);
+ // return true;
+ //}
+ foreach ($phoneNumberSet as $key => $phone) {
+ if (!$phoneNumberSet[$key]) {
+ unset($phoneNumberSet[$key]);
+ } else {
+ $phoneNumberSet[$key] = '+86' . $phoneNumberSet[$key];
+ }
+ }
+ if (count($phoneNumberSet) == 0) {
+ return true;
+ }
+ if (!$signName) {
+ $signName = $this->cfg['sign_name'];
+ }
+ try {
+ // 实例化一个 sms 发送短信请求对象,每个接口都会对应一个request对象。
+ $req = new SendSmsRequest();
+ /* 填充请求参数,这里request对象的成员变量即对应接口的入参
+ * 你可以通过官网接口文档或跳转到request对象的定义处查看请求参数的定义
+ * 基本类型的设置:
+ * 帮助链接:
+ * 短信控制台: https://console.cloud.tencent.com/smsv2
+ * sms helper: https://cloud.tencent.com/document/product/382/3773
+ */
+ /*
+ * 短信应用ID: 短信SdkAppId在 [短信控制台] 添加应用后生成的实际SdkAppId,示例如1400006666
+ */
+ $req->SmsSdkAppId = $this->cfg['sms_sdk_app_id'];
+ /* 短信签名内容: 使用 UTF-8 编码,必须填写已审核通过的签名,签名信息可登录 [短信控制台] 查看 */
+ $req->SignName = $signName;
+ /* 短信码号扩展号: 默认未开通,如需开通请联系 [sms helper] */
+ $req->ExtendCode = "";
+ /*
+ 下发手机号码,采用 E.164 标准,+[国家或地区码][手机号]
+ * 示例如:+8613711112222, 其中前面有一个+号 ,86为国家码,13711112222为手机号,最多不要超过200个手机号
+ */
+ $req->PhoneNumberSet = $phoneNumberSet;
+ /* 国际/港澳台短信 SenderId: 国内短信填空,默认未开通,如需开通请联系 [sms helper] */
+ $req->SenderId = "";
+ /* 用户的 session 内容: 可以携带用户侧 ID 等上下文信息,server 会原样返回 */
+ $req->SessionContext = "xxx";
+ /* 模板 ID: 必须填写已审核通过的模板 ID。模板ID可登录 [短信控制台] 查看 */
+ $req->TemplateId = $this->cfg['templates'][$templateId];
+ /* 模板参数: 若无模板参数,则设置为空*/
+ $req->TemplateParamSet = $templateParamSet;
+ // 通过client对象调用SendSms方法发起请求。注意请求方法名与请求对象是对应的
+ // 返回的resp是一个SendSmsResponse类的实例,与请求对象对应
+ $resp = $this->client->SendSms($req);
+ // 输出json格式的字符串回包
+ $res = json_decode($resp->toJsonString());
+ foreach ($res->SendStatusSet as $item) {
+ if ($item->Code != 'Ok') {
+ $tpl = $this->cfg['templates'][$templateId];
+ $param = json_encode($templateParamSet);
+ Log::error("SMS ERROR $item->Code[$tpl:$item->PhoneNumber:$param]$item->Message");
+ }
+ }
+ return True;
+ } catch (TencentCloudSDKException $e) {
+ Log::error($e);
+ }
+ return 0;
+ }
+}
diff --git a/composer.json b/composer.json
index 4a1348c..2d0673c 100644
--- a/composer.json
+++ b/composer.json
@@ -12,7 +12,8 @@
"guzzlehttp/guzzle": "^7.0.1",
"laravel/framework": "^8.40",
"laravel/tinker": "^2.5",
- "overtrue/wechat": "~5.0"
+ "overtrue/wechat": "~5.0",
+ "tencentcloud/tencentcloud-sdk-php": "^3.0"
},
"require-dev": {
"facade/ignition": "^2.5",
diff --git a/composer.lock b/composer.lock
index 10daf56..6d893f6 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
- "content-hash": "7a150183291d25e55b752a22e9bd8d62",
+ "content-hash": "5dd2556c6bb5b2e049435c53c47893ff",
"packages": [
{
"name": "asm89/stack-cors",
@@ -1426,16 +1426,16 @@
},
{
"name": "guzzlehttp/psr7",
- "version": "2.0.0",
+ "version": "1.8.2",
"source": {
"type": "git",
"url": "https://github.com/guzzle/psr7.git",
- "reference": "1dc8d9cba3897165e16d12bb13d813afb1eb3fe7"
+ "reference": "dc960a912984efb74d0a90222870c72c87f10c91"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/guzzle/psr7/zipball/1dc8d9cba3897165e16d12bb13d813afb1eb3fe7",
- "reference": "1dc8d9cba3897165e16d12bb13d813afb1eb3fe7",
+ "url": "https://api.github.com/repos/guzzle/psr7/zipball/dc960a912984efb74d0a90222870c72c87f10c91",
+ "reference": "dc960a912984efb74d0a90222870c72c87f10c91",
"shasum": "",
"mirrors": [
{
@@ -1445,19 +1445,16 @@
]
},
"require": {
- "php": "^7.2.5 || ^8.0",
- "psr/http-factory": "^1.0",
- "psr/http-message": "^1.0",
- "ralouphie/getallheaders": "^3.0"
+ "php": ">=5.4.0",
+ "psr/http-message": "~1.0",
+ "ralouphie/getallheaders": "^2.0.5 || ^3.0.0"
},
"provide": {
- "psr/http-factory-implementation": "1.0",
"psr/http-message-implementation": "1.0"
},
"require-dev": {
- "bamarni/composer-bin-plugin": "^1.4.1",
- "http-interop/http-factory-tests": "^0.9",
- "phpunit/phpunit": "^8.5.8 || ^9.3.10"
+ "ext-zlib": "*",
+ "phpunit/phpunit": "~4.8.36 || ^5.7.27 || ^6.5.14 || ^7.5.20 || ^8.5.8 || ^9.3.10"
},
"suggest": {
"laminas/laminas-httphandlerrunner": "Emit PSR-7 responses"
@@ -1465,13 +1462,16 @@
"type": "library",
"extra": {
"branch-alias": {
- "dev-master": "2.0-dev"
+ "dev-master": "1.7-dev"
}
},
"autoload": {
"psr-4": {
"GuzzleHttp\\Psr7\\": "src/"
- }
+ },
+ "files": [
+ "src/functions_include.php"
+ ]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
@@ -1486,11 +1486,6 @@
{
"name": "Tobias Schultze",
"homepage": "https://github.com/Tobion"
- },
- {
- "name": "Márk Sági-Kazár",
- "email": "mark.sagikazar@gmail.com",
- "homepage": "https://sagikazarmark.hu"
}
],
"description": "PSR-7 message implementation that also provides common utility methods",
@@ -1506,9 +1501,9 @@
],
"support": {
"issues": "https://github.com/guzzle/psr7/issues",
- "source": "https://github.com/guzzle/psr7/tree/2.0.0"
+ "source": "https://github.com/guzzle/psr7/tree/1.8.2"
},
- "time": "2021-06-30T20:03:07+00:00"
+ "time": "2021-04-26T09:17:50+00:00"
},
{
"name": "hamcrest/hamcrest-php",
@@ -3030,67 +3025,6 @@
},
"time": "2020-06-29T06:28:15+00:00"
},
- {
- "name": "psr/http-factory",
- "version": "1.0.1",
- "source": {
- "type": "git",
- "url": "https://github.com/php-fig/http-factory.git",
- "reference": "12ac7fcd07e5b077433f5f2bee95b3a771bf61be"
- },
- "dist": {
- "type": "zip",
- "url": "https://api.github.com/repos/php-fig/http-factory/zipball/12ac7fcd07e5b077433f5f2bee95b3a771bf61be",
- "reference": "12ac7fcd07e5b077433f5f2bee95b3a771bf61be",
- "shasum": "",
- "mirrors": [
- {
- "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
- "preferred": true
- }
- ]
- },
- "require": {
- "php": ">=7.0.0",
- "psr/http-message": "^1.0"
- },
- "type": "library",
- "extra": {
- "branch-alias": {
- "dev-master": "1.0.x-dev"
- }
- },
- "autoload": {
- "psr-4": {
- "Psr\\Http\\Message\\": "src/"
- }
- },
- "notification-url": "https://packagist.org/downloads/",
- "license": [
- "MIT"
- ],
- "authors": [
- {
- "name": "PHP-FIG",
- "homepage": "http://www.php-fig.org/"
- }
- ],
- "description": "Common interfaces for PSR-7 HTTP message factories",
- "keywords": [
- "factory",
- "http",
- "message",
- "psr",
- "psr-17",
- "psr-7",
- "request",
- "response"
- ],
- "support": {
- "source": "https://github.com/php-fig/http-factory/tree/master"
- },
- "time": "2019-04-30T12:38:16+00:00"
- },
{
"name": "psr/http-message",
"version": "1.0.1",
@@ -6497,6 +6431,60 @@
],
"time": "2021-06-27T09:16:08+00:00"
},
+ {
+ "name": "tencentcloud/tencentcloud-sdk-php",
+ "version": "3.0.467",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/TencentCloud/tencentcloud-sdk-php.git",
+ "reference": "11f0a41777f97cdc4226a9d1b0dea78eead42a24"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/TencentCloud/tencentcloud-sdk-php/zipball/11f0a41777f97cdc4226a9d1b0dea78eead42a24",
+ "reference": "11f0a41777f97cdc4226a9d1b0dea78eead42a24",
+ "shasum": "",
+ "mirrors": [
+ {
+ "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
+ "preferred": true
+ }
+ ]
+ },
+ "require": {
+ "guzzlehttp/guzzle": "^6.3 || ^7.0",
+ "guzzlehttp/psr7": "^1.8",
+ "php": ">=5.6.0"
+ },
+ "type": "library",
+ "autoload": {
+ "classmap": [
+ "src/QcloudApi/QcloudApi.php"
+ ],
+ "psr-4": {
+ "TencentCloud\\": "./src/TencentCloud"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "Apache-2.0"
+ ],
+ "authors": [
+ {
+ "name": "coolli",
+ "email": "tencentcloudapi@tencent.com",
+ "homepage": "https://cloud.tencent.com/document/sdk/PHP",
+ "role": "Developer"
+ }
+ ],
+ "description": "TencentCloudApi php sdk",
+ "homepage": "https://github.com/TencentCloud/tencentcloud-sdk-php",
+ "support": {
+ "issues": "https://github.com/TencentCloud/tencentcloud-sdk-php/issues",
+ "source": "https://github.com/TencentCloud/tencentcloud-sdk-php/tree/3.0.467"
+ },
+ "time": "2021-08-30T01:17:41+00:00"
+ },
{
"name": "tijsverkoyen/css-to-inline-styles",
"version": "2.2.3",
diff --git a/config/sms.php b/config/sms.php
new file mode 100644
index 0000000..cfa0a03
--- /dev/null
+++ b/config/sms.php
@@ -0,0 +1,16 @@
+ \App\Libraries\Sms\Tencent::class,
+ 'type' => 'tencent',
+ //'debug' => env('SMS_DEBUG'),
+ 'tencent' => [
+ 'sms_sdk_app_id'=> env('SMS_SDK_APP_ID'),
+ 'secret_id' => env('SECRET_ID'),
+ 'secret_key' => env('SECRET_KEY'),
+ 'sign_name' => '领峰远扬',
+ 'templates' => [
+ 'bidding' => '1100494' //{1}参与了您发起的竞标{2},详情请登录{3}查看。
+ ]
+ ]
+];
From 0d3410ff2f54fc8c20914ab7ea85494d4875021f Mon Sep 17 00:00:00 2001
From: lemon <15040771@qq.com>
Date: Mon, 30 Aug 2021 17:40:26 +0800
Subject: [PATCH 15/26] =?UTF-8?q?=E6=A8=A1=E5=9E=8B?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/Models/Agent.php | 2 ++
1 file changed, 2 insertions(+)
diff --git a/app/Models/Agent.php b/app/Models/Agent.php
index 5ab58ad..1cdb5a0 100644
--- a/app/Models/Agent.php
+++ b/app/Models/Agent.php
@@ -9,6 +9,8 @@ class Agent extends BaseModel
{
use HasFactory, SoftDeletes;
+ protected $table = 'agents';
+
public function agentInfo()
{
return $this->hasOne(AgentInfo::class);
From 373a4822dddced4b9bf433a16c704872add9d3d7 Mon Sep 17 00:00:00 2001
From: liapples
Date: Mon, 30 Aug 2021 17:41:33 +0800
Subject: [PATCH 16/26] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=8F=92=E5=85=A5?=
=?UTF-8?q?=E6=9D=83=E9=99=90=E8=A1=A8=E9=80=BB=E8=BE=91?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/Admin/Controllers/SupplierController.php | 8 ++++++++
app/Admin/Extensions/Grid/AuditAgent.php | 2 +-
app/Admin/Extensions/Grid/AuditGuide.php | 2 +-
app/Admin/Extensions/Grid/AuditSupplier.php | 2 +-
4 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/app/Admin/Controllers/SupplierController.php b/app/Admin/Controllers/SupplierController.php
index 1f097c2..342710d 100644
--- a/app/Admin/Controllers/SupplierController.php
+++ b/app/Admin/Controllers/SupplierController.php
@@ -7,10 +7,12 @@ use App\Admin\Repositories\Supplier;
use App\Common\ProductStatus;
use App\Common\UserStatus;
use App\Models\Product;
+use Dcat\Admin\Admin;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;
+use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Route;
class SupplierController extends AdminController
@@ -150,6 +152,12 @@ class SupplierController extends AdminController
if ($form->status == UserStatus::DISABLED) {
Product::where('supplier_id', $form->getKey())->update(['status' => ProductStatus::SOLD_OUT]);
}
+
+ //插入权限表
+ if ($form->status == UserStatus::NORMAL) {
+ DB::table(config('admin-supplier.database.role_users_table'))
+ ->insertOrIgnore(['role_id' => 1, 'user_id' => $form->id]);
+ }
});
}
}
diff --git a/app/Admin/Extensions/Grid/AuditAgent.php b/app/Admin/Extensions/Grid/AuditAgent.php
index aaf66b9..f76cc42 100644
--- a/app/Admin/Extensions/Grid/AuditAgent.php
+++ b/app/Admin/Extensions/Grid/AuditAgent.php
@@ -111,7 +111,7 @@ class AuditAgent extends RowAction
//插入权限表
if ($user->status == UserStatus::NORMAL) {
DB::table(config('admin-agent.database.role_users_table'))
- ->insertOrIgnore(['role_id' => 1, 'user_id' => Admin::user()->id]);
+ ->insertOrIgnore(['role_id' => 1, 'user_id' => $user->id]);
}
//TODO 还需要插入 演示产品、公告、专题等
diff --git a/app/Admin/Extensions/Grid/AuditGuide.php b/app/Admin/Extensions/Grid/AuditGuide.php
index abc610c..d6e6231 100644
--- a/app/Admin/Extensions/Grid/AuditGuide.php
+++ b/app/Admin/Extensions/Grid/AuditGuide.php
@@ -43,7 +43,7 @@ class AuditGuide extends RowAction
//插入权限表
if ($user->status == UserStatus::NORMAL) {
DB::table(config('admin-guide.database.role_users_table'))
- ->insertOrIgnore(['role_id' => 1, 'user_id' => Admin::user()->id]);
+ ->insertOrIgnore(['role_id' => 1, 'user_id' => $user->id]);
}
return $this->response()->success("审核成功")->refresh();
diff --git a/app/Admin/Extensions/Grid/AuditSupplier.php b/app/Admin/Extensions/Grid/AuditSupplier.php
index 86c5642..190be80 100644
--- a/app/Admin/Extensions/Grid/AuditSupplier.php
+++ b/app/Admin/Extensions/Grid/AuditSupplier.php
@@ -43,7 +43,7 @@ class AuditSupplier extends RowAction
//插入权限表
if ($user->status == UserStatus::NORMAL) {
DB::table(config('admin-supplier.database.role_users_table'))
- ->insertOrIgnore(['role_id' => 1, 'user_id' => Admin::user()->id]);
+ ->insertOrIgnore(['role_id' => 1, 'user_id' => $user->id]);
}
return $this->response()->success("审核成功")->refresh();
From 0e9073bf77ae9a9e850adc4896d01393809bc8b1 Mon Sep 17 00:00:00 2001
From: lemon <15040771@qq.com>
Date: Mon, 30 Aug 2021 17:48:52 +0800
Subject: [PATCH 17/26] =?UTF-8?q?=E5=B8=B8=E9=87=8F?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/Traits/DemandTraits.php | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/app/Traits/DemandTraits.php b/app/Traits/DemandTraits.php
index 6d44104..b74b6de 100644
--- a/app/Traits/DemandTraits.php
+++ b/app/Traits/DemandTraits.php
@@ -6,15 +6,15 @@ trait DemandTraits
{
public static $col = [
- 'App\models\Agent',
- 'App\models\Supplier',
- 'App\models\Guide',
+ 'App\Models\Agent',
+ 'App\Models\Supplier',
+ 'App\Models\Guide',
];
public static $polymorphic = [
- 'App\models\Agent' => '代理商',
- 'App\models\Supplier' => '供应商',
- 'App\models\Guide' => '地接',
+ 'App\Models\Agent' => '代理商',
+ 'App\Models\Supplier' => '供应商',
+ 'App\Models\Guide' => '地接',
];
public static $stateKey = [
From 342d5169563fa4d75224d51ed8a68e361068a43e Mon Sep 17 00:00:00 2001
From: liapples
Date: Mon, 30 Aug 2021 17:50:59 +0800
Subject: [PATCH 18/26] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=8F=92=E5=85=A5?=
=?UTF-8?q?=E6=9D=83=E9=99=90=E8=A1=A8=E9=80=BB=E8=BE=91?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/Admin/Controllers/GuideController.php | 7 +++++++
app/Admin/Controllers/SupplierController.php | 2 +-
app/Admin/Extensions/Grid/AuditAgent.php | 2 +-
app/Admin/Extensions/Grid/AuditGuide.php | 2 +-
app/Admin/Extensions/Grid/AuditSupplier.php | 2 +-
5 files changed, 11 insertions(+), 4 deletions(-)
diff --git a/app/Admin/Controllers/GuideController.php b/app/Admin/Controllers/GuideController.php
index 3236a3a..119e872 100644
--- a/app/Admin/Controllers/GuideController.php
+++ b/app/Admin/Controllers/GuideController.php
@@ -9,6 +9,7 @@ use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;
+use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Route;
class GuideController extends AdminController
@@ -131,6 +132,12 @@ class GuideController extends AdminController
$form->$k = '';
}
}
+ })->saved(function (Form $form) {
+ //插入权限表
+ if ($form->status == UserStatus::NORMAL) {
+ DB::table(config('admin-guide.database.role_users_table'))
+ ->insertOrIgnore(['role_id' => 1, 'user_id' => $form->getKey()]);
+ }
});
}
}
diff --git a/app/Admin/Controllers/SupplierController.php b/app/Admin/Controllers/SupplierController.php
index 342710d..0c2c2bc 100644
--- a/app/Admin/Controllers/SupplierController.php
+++ b/app/Admin/Controllers/SupplierController.php
@@ -156,7 +156,7 @@ class SupplierController extends AdminController
//插入权限表
if ($form->status == UserStatus::NORMAL) {
DB::table(config('admin-supplier.database.role_users_table'))
- ->insertOrIgnore(['role_id' => 1, 'user_id' => $form->id]);
+ ->insertOrIgnore(['role_id' => 1, 'user_id' => $form->getKey()]);
}
});
}
diff --git a/app/Admin/Extensions/Grid/AuditAgent.php b/app/Admin/Extensions/Grid/AuditAgent.php
index f76cc42..b7b331c 100644
--- a/app/Admin/Extensions/Grid/AuditAgent.php
+++ b/app/Admin/Extensions/Grid/AuditAgent.php
@@ -111,7 +111,7 @@ class AuditAgent extends RowAction
//插入权限表
if ($user->status == UserStatus::NORMAL) {
DB::table(config('admin-agent.database.role_users_table'))
- ->insertOrIgnore(['role_id' => 1, 'user_id' => $user->id]);
+ ->insertOrIgnore(['role_id' => 1, 'user_id' => $this->getKey()]);
}
//TODO 还需要插入 演示产品、公告、专题等
diff --git a/app/Admin/Extensions/Grid/AuditGuide.php b/app/Admin/Extensions/Grid/AuditGuide.php
index d6e6231..86f9b3e 100644
--- a/app/Admin/Extensions/Grid/AuditGuide.php
+++ b/app/Admin/Extensions/Grid/AuditGuide.php
@@ -43,7 +43,7 @@ class AuditGuide extends RowAction
//插入权限表
if ($user->status == UserStatus::NORMAL) {
DB::table(config('admin-guide.database.role_users_table'))
- ->insertOrIgnore(['role_id' => 1, 'user_id' => $user->id]);
+ ->insertOrIgnore(['role_id' => 1, 'user_id' => $this->getKey()]);
}
return $this->response()->success("审核成功")->refresh();
diff --git a/app/Admin/Extensions/Grid/AuditSupplier.php b/app/Admin/Extensions/Grid/AuditSupplier.php
index 190be80..c5bd6c9 100644
--- a/app/Admin/Extensions/Grid/AuditSupplier.php
+++ b/app/Admin/Extensions/Grid/AuditSupplier.php
@@ -43,7 +43,7 @@ class AuditSupplier extends RowAction
//插入权限表
if ($user->status == UserStatus::NORMAL) {
DB::table(config('admin-supplier.database.role_users_table'))
- ->insertOrIgnore(['role_id' => 1, 'user_id' => $user->id]);
+ ->insertOrIgnore(['role_id' => 1, 'user_id' => $this->getKey()]);
}
return $this->response()->success("审核成功")->refresh();
From 587944abbd6efb6b45a328d880a2db10fccc4ebb Mon Sep 17 00:00:00 2001
From: lemon <15040771@qq.com>
Date: Mon, 30 Aug 2021 18:17:27 +0800
Subject: [PATCH 19/26] =?UTF-8?q?=E4=BE=9B=E5=BA=94=E5=95=86?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../Controllers/DemandProductController.php | 3 ---
.../Controllers/DemandProductController.php | 18 +++++++++---------
2 files changed, 9 insertions(+), 12 deletions(-)
diff --git a/app/Admin/Controllers/DemandProductController.php b/app/Admin/Controllers/DemandProductController.php
index 88af1a9..381d311 100644
--- a/app/Admin/Controllers/DemandProductController.php
+++ b/app/Admin/Controllers/DemandProductController.php
@@ -35,10 +35,7 @@ class DemandProductController extends AdminController
$grid->column('category.name', '分类');
$grid->column('picture')->image('', 60, 60);
$grid->column('title');
- $grid->column('original_price');
- $grid->column('price');
$grid->column('sale');
- $grid->column('stock');
$grid->column('supplier.name', '供应商');
$grid->column('status')
->if(fn() => $this->status == ProductStatus::UNAUDITED)
diff --git a/app/AdminSupplier/Controllers/DemandProductController.php b/app/AdminSupplier/Controllers/DemandProductController.php
index 19598f2..e31d49b 100755
--- a/app/AdminSupplier/Controllers/DemandProductController.php
+++ b/app/AdminSupplier/Controllers/DemandProductController.php
@@ -31,9 +31,9 @@ class DemandProductController extends AdminController
$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('price');
+ //$grid->column('original_price');
+ //$grid->column('stock');
$grid->column('sale');
$grid->column('status')->using(ProductStatus::array());
$grid->column('created_at');
@@ -60,10 +60,10 @@ class DemandProductController extends AdminController
$show->field('supplier_id');
$show->field('category_id');
$show->field('title');
- $show->field('price');
- $show->field('original_price');
+ //$show->field('price');
+ //$show->field('original_price');
$show->field('pictures')->image('', 80, 80);
- $show->field('stock');
+ //$show->field('stock');
$show->field('sale');
$show->field('status');
$show->field('know')->unescape()->as(fn($v) => preg_replace('/.*?<\/script>/is', '', $v));
@@ -91,10 +91,10 @@ class DemandProductController extends AdminController
$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->text('price')->required();
+ //$form->text('original_price')->required();
$form->multipleImage('pictures')->required()->removable(false)->retainable()->uniqueName();
- $form->text('stock')->default(9999)->required();
+ //$form->text('stock')->default(9999)->required();
$form->editor('know');
$form->editor('content')->required();
From abb6c4bc4446175357e1e2f1617cbcaa9c9c8c95 Mon Sep 17 00:00:00 2001
From: lemon <15040771@qq.com>
Date: Mon, 30 Aug 2021 18:20:03 +0800
Subject: [PATCH 20/26] 1
---
app/AdminSupplier/Controllers/DemandController.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/app/AdminSupplier/Controllers/DemandController.php b/app/AdminSupplier/Controllers/DemandController.php
index 87f9861..0e42df9 100755
--- a/app/AdminSupplier/Controllers/DemandController.php
+++ b/app/AdminSupplier/Controllers/DemandController.php
@@ -204,7 +204,7 @@ class DemandController extends AdminController
$product->category_id = $demandProduct->category_id;
$product->title = $demandProduct->title;
$product->price = $demandBidding->price;
- $product->original_price = $demandProduct->original_price;
+ $product->original_price = $demandBidding->price;
$product->pictures = $demandProduct->pictures;
$product->stock = $demand->stock;
$product->know = $demandProduct->know;
From 76f0830872a207be554e88b2b36dc5ba68c0ba17 Mon Sep 17 00:00:00 2001
From: lemon <15040771@qq.com>
Date: Mon, 30 Aug 2021 18:22:36 +0800
Subject: [PATCH 21/26] 1
---
app/AdminSupplier/Renderable/SelectProduct.php | 1 -
1 file changed, 1 deletion(-)
diff --git a/app/AdminSupplier/Renderable/SelectProduct.php b/app/AdminSupplier/Renderable/SelectProduct.php
index efceef3..5f35abc 100644
--- a/app/AdminSupplier/Renderable/SelectProduct.php
+++ b/app/AdminSupplier/Renderable/SelectProduct.php
@@ -34,7 +34,6 @@ class SelectProduct extends LazyRenderable
$grid->column('title');
$grid->column('picture')->image('',60, 60);
$grid->column('sale');
- $grid->column('stock');
$grid->column('updated_at');
$grid->paginate(15);
From 333b8d0f0f369c43f6f26a63fd546fa6b26087d6 Mon Sep 17 00:00:00 2001
From: lemon <15040771@qq.com>
Date: Mon, 30 Aug 2021 18:24:27 +0800
Subject: [PATCH 22/26] 1
---
app/AdminSupplier/Renderable/SelectProduct.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/app/AdminSupplier/Renderable/SelectProduct.php b/app/AdminSupplier/Renderable/SelectProduct.php
index 5f35abc..dfa6f82 100644
--- a/app/AdminSupplier/Renderable/SelectProduct.php
+++ b/app/AdminSupplier/Renderable/SelectProduct.php
@@ -26,7 +26,7 @@ class SelectProduct extends LazyRenderable
$grid->disableBatchActions();
//$grid->model()->where('status', ProductStatus::ON_SALE);
- $grid->model()->where('supplier_id',Admin::user()->id)->where('agent_id',0);
+ $grid->model()->where('supplier_id',Admin::user()->id);
$grid->quickSearch(['title', 'supplier.name'])->placeholder('搜索产品名称、供应商');
$grid->column('id');
From 2c5dcdc3f2e4c84445adf1cd4d743edfad3f7e55 Mon Sep 17 00:00:00 2001
From: lemon <15040771@qq.com>
Date: Mon, 30 Aug 2021 18:29:36 +0800
Subject: [PATCH 23/26] 1
---
app/AdminSupplier/Controllers/DemandBiddingController.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/app/AdminSupplier/Controllers/DemandBiddingController.php b/app/AdminSupplier/Controllers/DemandBiddingController.php
index 8c477c6..78083df 100755
--- a/app/AdminSupplier/Controllers/DemandBiddingController.php
+++ b/app/AdminSupplier/Controllers/DemandBiddingController.php
@@ -143,7 +143,7 @@ class DemandBiddingController extends AdminController
$product->category_id = $demandProduct->category_id;
$product->title = $demandProduct->title;
$product->price = $form->model()->price;
- $product->original_price = $demandProduct->original_price;
+ $product->original_price = $form->model()->price;
$product->pictures = $demandProduct->pictures;
$product->stock = $demand->stock;
$product->know = $demandProduct->know;
From c1a42d655684b6a3c8467cdd5a0a6f9a44dfa29a Mon Sep 17 00:00:00 2001
From: lemon <15040771@qq.com>
Date: Mon, 30 Aug 2021 18:30:30 +0800
Subject: [PATCH 24/26] 1
---
app/AdminSupplier/Controllers/DemandBiddingController.php | 2 --
1 file changed, 2 deletions(-)
diff --git a/app/AdminSupplier/Controllers/DemandBiddingController.php b/app/AdminSupplier/Controllers/DemandBiddingController.php
index 78083df..19e6e41 100755
--- a/app/AdminSupplier/Controllers/DemandBiddingController.php
+++ b/app/AdminSupplier/Controllers/DemandBiddingController.php
@@ -148,9 +148,7 @@ class DemandBiddingController extends AdminController
$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);
From cff71b2487080db4af141f8dcab847b486a07034 Mon Sep 17 00:00:00 2001
From: lemon <15040771@qq.com>
Date: Mon, 30 Aug 2021 19:08:12 +0800
Subject: [PATCH 25/26] =?UTF-8?q?=E7=9B=91=E5=90=AC=E5=99=A8?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../DemandBiddingServiceProvider.php | 22 ++++++++++++++-----
config/app.php | 2 +-
2 files changed, 18 insertions(+), 6 deletions(-)
diff --git a/app/Providers/DemandBiddingServiceProvider.php b/app/Providers/DemandBiddingServiceProvider.php
index 580d37c..7634ed3 100644
--- a/app/Providers/DemandBiddingServiceProvider.php
+++ b/app/Providers/DemandBiddingServiceProvider.php
@@ -3,8 +3,10 @@
namespace App\Providers;
use App\Models\Demand;
-use App\Models\DemandProduct;
+use App\Models\DemandBidding;
use App\Service\SmsService;
+use App\Traits\DemandTraits;
+use Illuminate\Support\Facades\Log;
use Illuminate\Support\ServiceProvider;
class DemandBiddingServiceProvider extends ServiceProvider
@@ -26,12 +28,22 @@ class DemandBiddingServiceProvider extends ServiceProvider
*/
public function boot()
{
- DemandProduct::created(function ($order) {
- $demand = Demand::query()->with('publisher')->where('id',$order->demand_id)->first();
+ DemandBidding::created(function ($order) {
+ $demand = Demand::query()->with(['publisher'])->where('id',$order->demand_id)->first();
if(!empty($demand->publisher->contact_phone)) {
- $smsConfig = config('sms.tencent');
$sms = new SmsService();
- $sms->send($smsConfig['templates']['bidding'],['','$demand->id'],$demand->publisher->contact_phone);
+ $sms->send('bidding',[$order->biddingUser->name,$demand->id,DemandTraits::$polymorphic[$demand->publisher_type]],[$demand->publisher->contact_phone]);
+ }
+ });
+
+
+ Demand::updated(function ($demand) {
+ //如果状态改变了
+ if($demand->isDirty('bidding_id')) {
+ if(!empty($demand->publisher->contact_phone)) {
+ $sms = new SmsService();
+ $sms->send('bidding',[$demand->publisher->name,$demand->id,DemandTraits::$polymorphic[$demand->bidding_user_type]],[$demand->biddingUser->contact_phone]);
+ }
}
});
}
diff --git a/config/app.php b/config/app.php
index 85d4629..09aecc1 100644
--- a/config/app.php
+++ b/config/app.php
@@ -174,7 +174,7 @@ return [
// App\Providers\BroadcastServiceProvider::class,
App\Providers\EventServiceProvider::class,
App\Providers\RouteServiceProvider::class,
-
+ App\Providers\DemandBiddingServiceProvider::class,
],
/*
From 78ee6169de4a4cb199963011fc678495ccfe7ce1 Mon Sep 17 00:00:00 2001
From: lemon <15040771@qq.com>
Date: Mon, 30 Aug 2021 19:08:59 +0800
Subject: [PATCH 26/26] =?UTF-8?q?=E6=9A=82=E6=97=B6=E6=B3=A8=E9=87=8A?=
=?UTF-8?q?=E7=9F=AD=E4=BF=A1=E7=B3=BB=E7=BB=9F=20=E6=B5=8B=E8=AF=95?=
=?UTF-8?q?=E7=9A=84=E6=97=B6=E5=80=99=E5=86=8D=E6=89=93=E5=BC=80?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../DemandBiddingServiceProvider.php | 36 +++++++++----------
1 file changed, 18 insertions(+), 18 deletions(-)
diff --git a/app/Providers/DemandBiddingServiceProvider.php b/app/Providers/DemandBiddingServiceProvider.php
index 7634ed3..e34011a 100644
--- a/app/Providers/DemandBiddingServiceProvider.php
+++ b/app/Providers/DemandBiddingServiceProvider.php
@@ -28,23 +28,23 @@ class DemandBiddingServiceProvider extends ServiceProvider
*/
public function boot()
{
- DemandBidding::created(function ($order) {
- $demand = Demand::query()->with(['publisher'])->where('id',$order->demand_id)->first();
- if(!empty($demand->publisher->contact_phone)) {
- $sms = new SmsService();
- $sms->send('bidding',[$order->biddingUser->name,$demand->id,DemandTraits::$polymorphic[$demand->publisher_type]],[$demand->publisher->contact_phone]);
- }
- });
-
-
- Demand::updated(function ($demand) {
- //如果状态改变了
- if($demand->isDirty('bidding_id')) {
- if(!empty($demand->publisher->contact_phone)) {
- $sms = new SmsService();
- $sms->send('bidding',[$demand->publisher->name,$demand->id,DemandTraits::$polymorphic[$demand->bidding_user_type]],[$demand->biddingUser->contact_phone]);
- }
- }
- });
+ //DemandBidding::created(function ($order) {
+ // $demand = Demand::query()->with(['publisher'])->where('id',$order->demand_id)->first();
+ // if(!empty($demand->publisher->contact_phone)) {
+ // $sms = new SmsService();
+ // $sms->send('bidding',[$order->biddingUser->name,$demand->id,DemandTraits::$polymorphic[$demand->publisher_type]],[$demand->publisher->contact_phone]);
+ // }
+ //});
+ //
+ //
+ //Demand::updated(function ($demand) {
+ // //如果状态改变了
+ // if($demand->isDirty('bidding_id')) {
+ // if(!empty($demand->publisher->contact_phone)) {
+ // $sms = new SmsService();
+ // $sms->send('bidding',[$demand->publisher->name,$demand->id,DemandTraits::$polymorphic[$demand->bidding_user_type]],[$demand->biddingUser->contact_phone]);
+ // }
+ // }
+ //});
}
}