|
|
@ -2,6 +2,7 @@ |
|
|
|
|
|
|
|
|
namespace App\AdminAgent\Controllers; |
|
|
namespace App\AdminAgent\Controllers; |
|
|
|
|
|
|
|
|
|
|
|
use App\AdminAgent\Renderable\SelectAgentCloudProduct; |
|
|
use App\AdminAgent\Renderable\SelectGuide; |
|
|
use App\AdminAgent\Renderable\SelectGuide; |
|
|
use App\AdminAgent\Renderable\SelectProduct; |
|
|
use App\AdminAgent\Renderable\SelectProduct; |
|
|
use App\AdminAgent\Repositories\AgentProduct; |
|
|
use App\AdminAgent\Repositories\AgentProduct; |
|
|
@ -163,13 +164,19 @@ class AgentProductController extends AdminController |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
$form->display('id'); |
|
|
$form->display('id'); |
|
|
|
|
|
|
|
|
|
|
|
//组团版旅行社不允许选择组团云产品
|
|
|
|
|
|
$options = Admin::user()->type == AgentType::CLUSTER ? [1 => '组合销售'] : ['单品销售', '组合销售', '组团云产品']; |
|
|
$form->radio('type') |
|
|
$form->radio('type') |
|
|
->options(['单品销售', '组合销售']) |
|
|
|
|
|
->default(0)->required() |
|
|
|
|
|
|
|
|
->options($options) |
|
|
|
|
|
->default(Admin::user()->type == AgentType::CLUSTER ? 1 : 0)->required() |
|
|
->help('单品销售无需审核,组合销售需要审核才能上架') |
|
|
->help('单品销售无需审核,组合销售需要审核才能上架') |
|
|
->when(0, function (Form $form) { |
|
|
->when(0, function (Form $form) { |
|
|
|
|
|
//组团版没有单品选择功能
|
|
|
|
|
|
if (Admin::user()->type == AgentType::CLUSTER) return; |
|
|
|
|
|
|
|
|
/** 单品销售 **/ |
|
|
/** 单品销售 **/ |
|
|
$form->selectTable('product_id', '选择产品') |
|
|
|
|
|
|
|
|
$form->selectTable('product_id', '供应商产品') |
|
|
->help('产品列表显示的是该产品的标题和图片') |
|
|
->help('产品列表显示的是该产品的标题和图片') |
|
|
->title('选择产品') |
|
|
->title('选择产品') |
|
|
->dialogWidth('80%;min-width:825px;') |
|
|
->dialogWidth('80%;min-width:825px;') |
|
|
@ -177,7 +184,7 @@ class AgentProductController extends AdminController |
|
|
->model(Product::class); |
|
|
->model(Product::class); |
|
|
})->when(1, function (Form $form) { |
|
|
})->when(1, function (Form $form) { |
|
|
/** 组合销售 **/ |
|
|
/** 组合销售 **/ |
|
|
$form->multipleSelectTable('product_ids', '选择产品') |
|
|
|
|
|
|
|
|
$form->multipleSelectTable('product_ids', '供应商产品') |
|
|
->help('可单选或多选组合销售') |
|
|
->help('可单选或多选组合销售') |
|
|
->title('选择产品') |
|
|
->title('选择产品') |
|
|
->dialogWidth('80%;min-width:825px;') |
|
|
->dialogWidth('80%;min-width:825px;') |
|
|
@ -189,6 +196,17 @@ class AgentProductController extends AdminController |
|
|
$form->multipleImage('pictures')->removable(false)->uniqueName(); |
|
|
$form->multipleImage('pictures')->removable(false)->uniqueName(); |
|
|
$form->editor('know'); |
|
|
$form->editor('know'); |
|
|
$form->editor('content'); |
|
|
$form->editor('content'); |
|
|
|
|
|
})->when(2, function (Form $form) { |
|
|
|
|
|
//组团版旅行社不允许选择组团云产品
|
|
|
|
|
|
if (Admin::user()->type == AgentType::CLUSTER) return; |
|
|
|
|
|
|
|
|
|
|
|
/** 组团云产品 **/ |
|
|
|
|
|
$form->selectTable('agent_cloud_pid', '组团云产品') |
|
|
|
|
|
->help('产品列表显示的是该产品的标题和图片') |
|
|
|
|
|
->title('选择产品') |
|
|
|
|
|
->dialogWidth('80%;min-width:825px;') |
|
|
|
|
|
->from(SelectAgentCloudProduct::make()) |
|
|
|
|
|
->model(Product::class); |
|
|
}); |
|
|
}); |
|
|
$form->text('price')->required(); |
|
|
$form->text('price')->required(); |
|
|
$form->text('original_price')->required(); |
|
|
$form->text('original_price')->required(); |
|
|
@ -214,7 +232,7 @@ class AgentProductController extends AdminController |
|
|
]) |
|
|
]) |
|
|
->required(); |
|
|
->required(); |
|
|
} |
|
|
} |
|
|
$form->switch('is_rec')->help('推荐后将在“我的”页面下方显示'); |
|
|
|
|
|
|
|
|
$form->switch('is_rec')->help('推荐后将在小程序“我的”页面下方显示'); |
|
|
//$form->selectTable('verifier')
|
|
|
//$form->selectTable('verifier')
|
|
|
// ->title('选择核销人员')
|
|
|
// ->title('选择核销人员')
|
|
|
// ->dialogWidth('50%;min-width:600px;') //不起作用
|
|
|
// ->dialogWidth('50%;min-width:600px;') //不起作用
|
|
|
@ -232,10 +250,14 @@ class AgentProductController extends AdminController |
|
|
->model(Guide::class, 'id', 'name'); |
|
|
->model(Guide::class, 'id', 'name'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
$form->number('earnest')->width(2)->default(0)->help('单位:元。不输入或输入 0 则不支持定金支付,必须和定金超时时间同时设置才会生效'); |
|
|
|
|
|
$form->number('earnest_timeout')->width(2)->default(0)->help('单位:分钟。超过这个时间未支付,订单将自动关闭'); |
|
|
|
|
|
$form->number('deposit')->default(0)->help('单位:元。不输入或输入 0 则不支持订金支付,必须和订金超时时间同时设置才会生效'); |
|
|
|
|
|
$form->number('deposit_timeout')->default(0)->help('单位:分钟。超过这个时间未支付,订单将自动关闭'); |
|
|
|
|
|
|
|
|
$form->number('earnest')->min(0) |
|
|
|
|
|
->default(0)->help('单位:元。不输入或输入 0 则不支持定金支付,必须和定金超时时间同时设置才会生效'); |
|
|
|
|
|
$form->number('earnest_timeout')->min(0) |
|
|
|
|
|
->default(0)->help('单位:分钟。超过这个时间未支付,订单将自动关闭'); |
|
|
|
|
|
$form->number('deposit')->min(0) |
|
|
|
|
|
->default(0)->help('单位:元。不输入或输入 0 则不支持订金支付,必须和订金超时时间同时设置才会生效'); |
|
|
|
|
|
$form->number('deposit_timeout')->min(0) |
|
|
|
|
|
->default(0)->help('单位:分钟。超过这个时间未支付,订单将自动关闭'); |
|
|
})->saving(function (Form $form) { |
|
|
})->saving(function (Form $form) { |
|
|
//不允许修改非自己的数据
|
|
|
//不允许修改非自己的数据
|
|
|
if ($form->isEditing() && $form->model()->agent_id != Admin::user()->id) { |
|
|
if ($form->isEditing() && $form->model()->agent_id != Admin::user()->id) { |
|
|
@ -331,6 +353,43 @@ class AgentProductController extends AdminController |
|
|
if ($not_in_id) { |
|
|
if ($not_in_id) { |
|
|
return $form->response()->error('产品ID ' . join(',', $not_in_id) . ' 库存小于你设置的库存' . $form->stock . ',或不存在、已下架等'); |
|
|
return $form->response()->error('产品ID ' . join(',', $not_in_id) . ' 库存小于你设置的库存' . $form->stock . ',或不存在、已下架等'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//如果是组团版旅行社,标记为是云产品
|
|
|
|
|
|
if (Admin::user()->type == AgentType::CLUSTER) { |
|
|
|
|
|
$form->hidden('is_cloud'); |
|
|
|
|
|
$form->is_cloud = 1; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
//组团云产品
|
|
|
|
|
|
else if ($form->type == 2) { |
|
|
|
|
|
$form->agent_cloud_pid = (int)$form->agent_cloud_pid; |
|
|
|
|
|
if (!$form->agent_cloud_pid) { |
|
|
|
|
|
return $form->response()->error('请选择产品'); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//产品信息预判断
|
|
|
|
|
|
$cloud_product = \App\Models\AgentProduct::where([ |
|
|
|
|
|
['stock', '>', 0], |
|
|
|
|
|
['status', '=', ProductStatus::ON_SALE], |
|
|
|
|
|
['is_cloud', '=', 1], |
|
|
|
|
|
['type', '=', 1], |
|
|
|
|
|
['agent_id', '<>', Admin::user()->id], |
|
|
|
|
|
])->find($form->agent_cloud_pid); |
|
|
|
|
|
|
|
|
|
|
|
if (!$cloud_product) { |
|
|
|
|
|
return $form->response()->error('你选择的组团云产品库存不足或已下架,请重新选择'); |
|
|
|
|
|
} else if ($cloud_product->stock < $form->stock) { |
|
|
|
|
|
return $form->response()->error("组团云产品当前库存为{$cloud_product->stock},你设置的库存不能超过该数值"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//同步关键字段信息
|
|
|
|
|
|
$form->product_id = $cloud_product->product_id; |
|
|
|
|
|
$form->product_ids = $cloud_product->product_ids; |
|
|
|
|
|
$form->guide_id = $cloud_product->guide_id; |
|
|
|
|
|
$form->title = $cloud_product->title; |
|
|
|
|
|
$form->pictures = $cloud_product->pictures; |
|
|
|
|
|
$form->know = $cloud_product->know; |
|
|
|
|
|
$form->content = $cloud_product->content; |
|
|
} else { |
|
|
} else { |
|
|
return $form->response()->error('不存在此销售方式'); |
|
|
return $form->response()->error('不存在此销售方式'); |
|
|
} |
|
|
} |
|
|
@ -339,6 +398,7 @@ class AgentProductController extends AdminController |
|
|
//处理特殊字段
|
|
|
//处理特殊字段
|
|
|
$form->hidden(['agent_id', 'status']); //表单没有的字段,必须加这句才能够重写
|
|
|
$form->hidden(['agent_id', 'status']); //表单没有的字段,必须加这句才能够重写
|
|
|
$form->agent_id = $agent_id; |
|
|
$form->agent_id = $agent_id; |
|
|
|
|
|
$form->agent_cloud_pid = $form->type ==2 ? ($form->agent_cloud_pid ?? 0) : 0; |
|
|
if (array_key_exists('guide_id', $form->input())) { |
|
|
if (array_key_exists('guide_id', $form->input())) { |
|
|
$form->guide_id = $form->guide_id ?? 0; |
|
|
$form->guide_id = $form->guide_id ?? 0; |
|
|
} |
|
|
} |
|
|
@ -381,8 +441,8 @@ class AgentProductController extends AdminController |
|
|
if ($form->isEditing()) { |
|
|
if ($form->isEditing()) { |
|
|
$where[] = ['id', '<>', $form->getKey()]; |
|
|
$where[] = ['id', '<>', $form->getKey()]; |
|
|
} |
|
|
} |
|
|
if ($form->repository()->model()->where($where)->exists()) { |
|
|
|
|
|
return $form->response()->error('该产品已经存在,请勿重复发布'); |
|
|
|
|
|
|
|
|
if ($id = $form->repository()->model()->where($where)->value('id')) { |
|
|
|
|
|
return $form->response()->error("你发布的产品ID {$id} 与本产品重复,请检查"); |
|
|
} |
|
|
} |
|
|
})->saved(function (Form $form) { |
|
|
})->saved(function (Form $form) { |
|
|
/** 保存到组合产品明细,先查询出之前明细,再跟新的比较,若没有则删除,新的产品原来明细表没有的,则插入 **/ |
|
|
/** 保存到组合产品明细,先查询出之前明细,再跟新的比较,若没有则删除,新的产品原来明细表没有的,则插入 **/ |
|
|
@ -419,6 +479,21 @@ class AgentProductController extends AdminController |
|
|
); |
|
|
); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//如果是组团云产品,同步信息到其它产品
|
|
|
|
|
|
if ($form->is_cloud) { |
|
|
|
|
|
\App\Models\AgentProduct::query() |
|
|
|
|
|
->where(['agent_cloud_pid' => $form->getKey(), 'type' => 2]) |
|
|
|
|
|
->update([ |
|
|
|
|
|
'product_id' => $form->product_id, |
|
|
|
|
|
'product_ids' => $form->product_ids, |
|
|
|
|
|
'guide_id' => $form->guide_id, |
|
|
|
|
|
'title' => $form->title, |
|
|
|
|
|
'pictures' => explode(',', $form->pictures), |
|
|
|
|
|
'know' => $form->know, |
|
|
|
|
|
'content' => $form->content, |
|
|
|
|
|
]); |
|
|
|
|
|
} |
|
|
})->deleting(function (Form $form) { |
|
|
})->deleting(function (Form $form) { |
|
|
//不允许删除非自己的数据
|
|
|
//不允许删除非自己的数据
|
|
|
if (array_filter($form->model()->toArray(), fn($v) => $v['agent_id'] != Admin::user()->id)) { |
|
|
if (array_filter($form->model()->toArray(), fn($v) => $v['agent_id'] != Admin::user()->id)) { |
|
|
|