|
|
|
@ -21,7 +21,6 @@ use Dcat\Admin\Grid; |
|
|
|
use Dcat\Admin\Show; |
|
|
|
use Dcat\Admin\Http\Controllers\AdminController; |
|
|
|
use Dcat\Admin\Widgets\Alert; |
|
|
|
use Dcat\Admin\Widgets\Table; |
|
|
|
|
|
|
|
class AgentProductController extends AdminController |
|
|
|
{ |
|
|
|
@ -37,9 +36,22 @@ class AgentProductController extends AdminController |
|
|
|
$grid->model()->where('agent_id', $agent_id); |
|
|
|
|
|
|
|
$grid->column('id')->sortable(); |
|
|
|
$grid->column('product.picture', '产品图片')->image('', 60, 60); |
|
|
|
$grid->column('product.title', '产品名称')->limit(15); |
|
|
|
$grid->column('product_ids', '产品详情') |
|
|
|
$grid->column('picture', '产品图片')->image('', 60, 60); |
|
|
|
$grid->column('title', '产品名称')->limit(15); |
|
|
|
$grid->column('price'); |
|
|
|
$grid->column('original_price'); |
|
|
|
$grid->column('sale'); |
|
|
|
$grid->column('stock'); |
|
|
|
|
|
|
|
$channels = Channel::where('agent_id', $agent_id)->pluck('name', 'id')->toArray(); |
|
|
|
$grid->column('channel_id', '频道') |
|
|
|
->display(function ($modal) use ($channels) { |
|
|
|
$data = array_flip(explode(',', $this->channel_id)); |
|
|
|
return join(',',array_intersect_key($channels, $data)); |
|
|
|
}) |
|
|
|
->limit(10); |
|
|
|
$grid->column('category.name', '分类'); |
|
|
|
/*$grid->column('product_ids', '产品详情') |
|
|
|
->display('查看') |
|
|
|
->modal(function ($modal) { |
|
|
|
$titles = ['供应商', '产品标题', '产品图片', '原价', '现价', '销量', '库存']; |
|
|
|
@ -56,20 +68,8 @@ class AgentProductController extends AdminController |
|
|
|
$this->product->stock ?? '', |
|
|
|
]]; |
|
|
|
return Table::make($titles, $data); |
|
|
|
}); |
|
|
|
$grid->column('price'); |
|
|
|
$grid->column('original_price'); |
|
|
|
$grid->column('sale'); |
|
|
|
$grid->column('stock'); |
|
|
|
});*/ |
|
|
|
|
|
|
|
$channels = Channel::where('agent_id', $agent_id)->pluck('name', 'id')->toArray(); |
|
|
|
$grid->column('channel_id', '频道') |
|
|
|
->display(function ($modal) use ($channels) { |
|
|
|
$data = array_flip(explode(',', $this->channel_id)); |
|
|
|
return join(',',array_intersect_key($channels, $data)); |
|
|
|
}) |
|
|
|
->limit(10); |
|
|
|
$grid->column('category.name', '分类'); |
|
|
|
$grid->column('status') |
|
|
|
->using(ProductStatus::array()) |
|
|
|
->dot([ |
|
|
|
@ -78,7 +78,7 @@ class AgentProductController extends AdminController |
|
|
|
ProductStatus::REFUSE => 'danger', |
|
|
|
ProductStatus::SOLD_OUT => 'warning', |
|
|
|
], 'primary'); |
|
|
|
$grid->column('created_at'); |
|
|
|
$grid->column('is_rec')->switch()->help('推荐后将在“我的”页面下方显示'); |
|
|
|
$grid->column('updated_at'); |
|
|
|
|
|
|
|
$grid->filter(function (Grid\Filter $filter) { |
|
|
|
@ -125,6 +125,11 @@ class AgentProductController extends AdminController |
|
|
|
if (Admin::user()->type == AgentType::CLUSTER) { |
|
|
|
$show->field('guide.name', '地接'); |
|
|
|
} |
|
|
|
$show->field('is_rec')->using(['未推荐', '已推荐']); |
|
|
|
$show->field('title'); |
|
|
|
$show->field('pictures')->image('', 80, 80); |
|
|
|
$show->field('know')->unescape(); |
|
|
|
$show->field('content')->unescape(); |
|
|
|
$show->field('created_at'); |
|
|
|
$show->field('updated_at'); |
|
|
|
|
|
|
|
@ -150,7 +155,7 @@ class AgentProductController extends AdminController |
|
|
|
*/ |
|
|
|
protected function form() |
|
|
|
{ |
|
|
|
return Form::make(new AgentProduct(['product:id,title']), function (Form $form) { |
|
|
|
return Form::make(new AgentProduct(), function (Form $form) { |
|
|
|
$agent_id = Admin::user()->id; |
|
|
|
|
|
|
|
//不允许查看非自己的数据
|
|
|
|
@ -159,25 +164,36 @@ class AgentProductController extends AdminController |
|
|
|
} |
|
|
|
|
|
|
|
$form->display('id'); |
|
|
|
$form->hidden('product_id'); |
|
|
|
$form->selectTable('product_id', '封面产品') |
|
|
|
->help('产品列表显示的是该产品的标题和图片') |
|
|
|
->title('选择产品') |
|
|
|
->dialogWidth('80%;min-width:825px;') |
|
|
|
->from(SelectProduct::make()) |
|
|
|
->model(Product::class) |
|
|
|
->required(); |
|
|
|
$form->multipleSelectTable('product_ids', '选择产品') |
|
|
|
->help('可单选或多选组合销售') |
|
|
|
->title('选择产品') |
|
|
|
->dialogWidth('80%;min-width:825px;') |
|
|
|
->from(SelectProduct::make()) |
|
|
|
->model(Product::class) |
|
|
|
->required(); |
|
|
|
$form->radio('type') |
|
|
|
->options(['单品销售', '组合销售']) |
|
|
|
->default(0) |
|
|
|
->when(0, function (Form $form) { |
|
|
|
/** 单品销售 **/ |
|
|
|
$form->selectTable('product_id', '选择产品') |
|
|
|
->help('产品列表显示的是该产品的标题和图片') |
|
|
|
->title('选择产品') |
|
|
|
->dialogWidth('80%;min-width:825px;') |
|
|
|
->from(SelectProduct::make()) |
|
|
|
->model(Product::class); |
|
|
|
})->when(1, function (Form $form) { |
|
|
|
/** 组合销售 **/ |
|
|
|
$form->multipleSelectTable('product_ids', '选择产品') |
|
|
|
->help('可单选或多选组合销售') |
|
|
|
->title('选择产品') |
|
|
|
->dialogWidth('80%;min-width:825px;') |
|
|
|
->from(SelectProduct::make()) |
|
|
|
->model(Product::class); |
|
|
|
|
|
|
|
/** 自定义内容 **/ |
|
|
|
$form->text('title'); |
|
|
|
$form->multipleImage('pictures'); |
|
|
|
$form->editor('know'); |
|
|
|
$form->editor('content'); |
|
|
|
}); |
|
|
|
$form->text('price')->required(); |
|
|
|
$form->text('original_price')->required(); |
|
|
|
$form->text('sale')->default(0); |
|
|
|
$form->text('stock')->default(9999); |
|
|
|
$form->text('stock')->default(8888); |
|
|
|
|
|
|
|
$options = Channel::selectOptions(fn($query) => $query->where('agent_id', $agent_id)); |
|
|
|
$form->multipleSelect('channel_id')->options(array_slice($options, 1)); |
|
|
|
@ -194,6 +210,7 @@ class AgentProductController extends AdminController |
|
|
|
ProductStatus::SOLD_OUT => '下架', |
|
|
|
]) |
|
|
|
->required(); |
|
|
|
$form->switch('is_rec')->help('推荐后将在“我的”页面下方显示'); |
|
|
|
$form->selectTable('verifier') |
|
|
|
->title('选择核销人员') |
|
|
|
->dialogWidth('50%;min-width:600px;') //不起作用
|
|
|
|
@ -216,26 +233,69 @@ class AgentProductController extends AdminController |
|
|
|
return $form->response()->error('数据不存在'); |
|
|
|
} |
|
|
|
|
|
|
|
$agent_id = Admin::user()->id; |
|
|
|
//推荐按钮开关
|
|
|
|
if ($form->product_id === null && $form->product_ids === null && $form->is_rec !== null) { |
|
|
|
$form->model()->is_rec = $form->is_rec ? 1 : 0; |
|
|
|
$form->model()->save(); |
|
|
|
return $form->response()->success('更新成功'); |
|
|
|
} |
|
|
|
|
|
|
|
$product_ids = explode(',', $form->product_ids); |
|
|
|
if (empty($product_ids)) { |
|
|
|
return $form->response()->error('请选择产品'); |
|
|
|
//单品销售
|
|
|
|
if ($form->type == 0) { |
|
|
|
$form->product_id = (int)$form->product_id; |
|
|
|
if (!$form->product_id) { |
|
|
|
return $form->response()->error('请选择产品'); |
|
|
|
} |
|
|
|
$form->product_ids = $form->product_id; |
|
|
|
|
|
|
|
//将供应商产品写入title,pictures,know,content
|
|
|
|
$product = Product::find($form->product_id); |
|
|
|
if ($product->status != ProductStatus::ON_SALE) { |
|
|
|
return $form->response()->error('产品ID '. $form->product_id .' 已下架'); |
|
|
|
} else if ($product->stock < $form->stock) { |
|
|
|
return $form->response()->error('库存不足,你设置的库存应小于等于' . $form->stock); |
|
|
|
} |
|
|
|
$form->title = $product->title; |
|
|
|
$form->pictures = $product->pictures; |
|
|
|
$form->know = $product->know; |
|
|
|
$form->content = $product->content; |
|
|
|
} |
|
|
|
//组合销售
|
|
|
|
else if ($form->type == 1) { |
|
|
|
if (!$form->product_ids) { |
|
|
|
return $form->response()->error('请选择产品'); |
|
|
|
} |
|
|
|
$product_ids = explode(',', $form->product_ids); |
|
|
|
|
|
|
|
//判断供应商产品是否存在或下架
|
|
|
|
$not_in_id = Product::query() |
|
|
|
->whereIn('id', $product_ids) |
|
|
|
->where(function ($query) use ($form) { |
|
|
|
$query->where('status', '<>', ProductStatus::ON_SALE) |
|
|
|
->orWhere('stock', '<', $form->stock); |
|
|
|
}) |
|
|
|
->pluck('id') |
|
|
|
->toArray(); |
|
|
|
if ($not_in_id) { |
|
|
|
return $form->response()->error('产品ID '. join(',', $not_in_id) .' 库存小于你设置的库存' . $form->stock . ',或不存在、已下架'); |
|
|
|
if (count($product_ids) < 2) { |
|
|
|
return $form->response()->error('组合销售必须选择两个以上产品,否则请选择单品销售'); |
|
|
|
} |
|
|
|
$form->product_id = $product_ids[0]; |
|
|
|
|
|
|
|
$required_fields = ['title', 'pictures', 'know', 'content']; |
|
|
|
foreach ($required_fields as $field) { |
|
|
|
if (!$form->$field) { |
|
|
|
return $form->response()->error('内容输入不完整,标题、产品图片、旅游须知、产品详情必填'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//判断供应商产品是否存在或下架
|
|
|
|
$not_in_id = Product::query() |
|
|
|
->whereIn('id', $product_ids) |
|
|
|
->where(function ($query) use ($form) { |
|
|
|
$query->where('status', '<>', ProductStatus::ON_SALE) |
|
|
|
->orWhere('stock', '<', $form->stock); |
|
|
|
}) |
|
|
|
->pluck('id') |
|
|
|
->toArray(); |
|
|
|
if ($not_in_id) { |
|
|
|
return $form->response()->error('产品ID ' . join(',', $not_in_id) . ' 库存小于你设置的库存' . $form->stock . ',或不存在、已下架'); |
|
|
|
} |
|
|
|
} else { |
|
|
|
return $form->response()->error('不存在此销售方式'); |
|
|
|
} |
|
|
|
|
|
|
|
$agent_id = Admin::user()->id; |
|
|
|
//处理特殊字段
|
|
|
|
$form->hidden(['agent_id', 'status']); //表单没有的字段,必须加这句才能够重写
|
|
|
|
$form->agent_id = $agent_id; |
|
|
|
|