diff --git a/app/AdminAgent/Controllers/AgentProductController.php b/app/AdminAgent/Controllers/AgentProductController.php index 9d600ef..82fd956 100644 --- a/app/AdminAgent/Controllers/AgentProductController.php +++ b/app/AdminAgent/Controllers/AgentProductController.php @@ -29,6 +29,16 @@ class AgentProductController extends AdminController */ protected function grid() { + //下架供应商产品状态不是上架或库存不足的产品 + \App\Models\AgentProduct::where('agent_id', Admin::user()->id) + ->whereHas('agentProductItem', function ($query) { + return $query->whereHas('product', function ($query) { + return $query->where('stock', '<=', 0)->orWhere('status', '<>', ProductStatus::ON_SALE); + }); + }) + ->orWhere('stock', '<=', 0) + ->update(['status' => ProductStatus::SOLD_OUT]); + return Grid::make(new AgentProduct(['product.supplier:id,name', 'category:id,name']), function (Grid $grid) { $agent_id = Admin::user()->id; $grid->model()->where('agent_id', $agent_id); @@ -287,7 +297,7 @@ class AgentProductController extends AdminController return $form->response()->error('数据不存在'); } - if ($form->isEditing() && $form->product_id === null && $form->product_ids === null) { + if ($form->isEditing() && $form->type === null) { //推荐按钮开关 if ($form->is_rec !== null) { $form->model()->is_rec = $form->is_rec ? 1 : 0; @@ -324,6 +334,11 @@ class AgentProductController extends AdminController } } + //库存不足,上架失败 + if ($form->model()->stock <= 0 && $form->status == 1) { + return $form->response()->error('库存不足,上架失败!')->refresh(); + } + $form->model()->status = $form->status == 1 ? ProductStatus::ON_SALE : ProductStatus::SOLD_OUT; $form->model()->save(); return $form->response()->success('更新成功!'); @@ -454,7 +469,7 @@ class AgentProductController extends AdminController } else if ($form->isEditing() && in_array($form->model()->status, [ProductStatus::UNAUDITED, ProductStatus::REFUSE])) { $form->deleteInput('status'); //待审核和拒绝的状态不允许修改 } - } else { + } else if ($form->type == 0 || $form->type == 2) { $form->status = $form->status == ProductStatus::ON_SALE ? ProductStatus::ON_SALE : ProductStatus::SOLD_OUT; } @@ -475,10 +490,11 @@ class AgentProductController extends AdminController } //不允许编辑的字段 - $form->ignore(['id', 'agent_id', 'status', 'created_at', 'updated_at', 'deleted_at']); + $form->ignore(['id', 'agent_id', 'created_at', 'updated_at', 'deleted_at']); //判断是否重复发布产品 $where = [ + ['type', '=', $form->type], ['agent_id', '=', $agent_id], ['product_id', '=', $form->product_id], ['product_ids', '=', $form->product_ids], @@ -504,7 +520,7 @@ class AgentProductController extends AdminController }, $product); //组合产品编辑关键字段需要审核 - if ($form->isEditing() && $form->model()->wasChanged(['title', 'pictures', 'know', 'content'])) { + if ($form->isEditing() && $form->type == 1 && $form->model()->wasChanged(['title', 'pictures', 'know', 'content'])) { $form->model()->update(['status' => ProductStatus::UNAUDITED]); } diff --git a/app/AdminSupplier/Controllers/ProductController.php b/app/AdminSupplier/Controllers/ProductController.php index 8126d08..83c5631 100644 --- a/app/AdminSupplier/Controllers/ProductController.php +++ b/app/AdminSupplier/Controllers/ProductController.php @@ -138,7 +138,8 @@ class ProductController extends AdminController $table->text('name', '项目名称'); $table->text('num', '数量'); $table->text('price', '费用'); - }); + })->help('第一行数据默认是表头,如:项目名称、数量、额外费用'); + $form->dateRange('extends.field_0.date.start', 'extends.field_0.date.end', '行程时间'); })->when(1, function (Form $form) { //酒店 $default = [ @@ -149,31 +150,36 @@ class ProductController extends AdminController ]; $form->table('extends.field_1.tags', '酒店设施', function (NestedForm $table) { $table->text('tag', '包含项目')->placeholder('如:24小时热水、干洗服务等'); - })->value($default); + })->value($default)->help('首次创建时,系统会默认填充基本服务,请根据本酒店情况进行删减或新增'); + $form->map('extends.field_1.latitude', 'extends.field_1.longitude', '位置'); })->when(2, function (Form $form) { //景区 $form->table('extends.field_2.open_time', '开放时间', function (NestedForm $table) { $table->text('node', '节点')->placeholder('如:周一至周五'); $table->text('summer', '夏季')->placeholder('如:08:00~19:00'); $table->text('winter', '冬季')->placeholder('如:08:00~18:00'); - }); + })->help('第一行数据默认是表头,如:项目名称、数量、额外费用'); + $form->table('extends.field_2.project', '包含项目', function (NestedForm $table) { $table->text('name', '项目名称'); $table->text('num', '数量'); $table->text('price', '费用'); - }); + })->help('第一行数据默认是表头,如:项目名称、数量、额外费用'); + $form->map('extends.field_2.latitude', 'extends.field_2.longitude', '位置'); })->when(3, function (Form $form) { //餐厅 $form->table('extends.field_3.open_time', '开放时间', function (NestedForm $table) { $table->text('week', '星期')->placeholder('如:周一至周五'); $table->text('section', '时段')->placeholder('如:上午/下午'); $table->text('time', '时间')->placeholder('如:08:00~18:00'); - }); + })->help('第一行数据默认是表头,如:项目名称、数量、额外费用'); + $form->table('extends.field_3.package', '包含套餐', function (NestedForm $table) { $table->text('name', '名称')->placeholder('如:清蒸鱿鱼'); $table->text('num', '数量')->placeholder('如:1条'); $table->text('price', '价格')->placeholder('如:99元'); - }); + })->help('第一行数据默认是表头,如:项目名称、数量、额外费用'); + $form->map('extends.field_3.latitude', 'extends.field_3.longitude', '位置'); });