|
...
|
...
|
@@ -37,26 +37,31 @@ class ProductLogic extends BaseLogic |
|
|
|
* @time :2023/8/21 18:35
|
|
|
|
*/
|
|
|
|
public function productSave(){
|
|
|
|
//参数处理
|
|
|
|
$this->param = $this->handleSaveParam($this->param);
|
|
|
|
//单独处理分类
|
|
|
|
$category_ids = [];
|
|
|
|
if(isset($this->param['category_id']) && !empty($this->param['category_id'])) {
|
|
|
|
$category_ids = $this->getLastCategoryArr($this->param['category_id']);
|
|
|
|
$this->param['category_id'] = ','.implode(',',$category_ids).',';
|
|
|
|
}
|
|
|
|
DB::connection('custom_mysql')->beginTransaction();
|
|
|
|
try {
|
|
|
|
if(isset($this->param['id']) && !empty($this->param['id'])){
|
|
|
|
$id = $this->param['id'];
|
|
|
|
//查看路由是否更新
|
|
|
|
$id = $this->editProductRoute($this->param['id'],$this->param['route']);
|
|
|
|
$this->param['route'] = $this->editProductRoute($this->param['route']);
|
|
|
|
$this->model->edit($this->param,['id'=>$this->param['id']]);
|
|
|
|
}else{
|
|
|
|
$this->param['project_id'] = $this->user['project_id'];
|
|
|
|
$this->param['created_at'] = date('Y-m-d H:i:s');
|
|
|
|
$this->param['updated_at'] = $this->param['created_at'];
|
|
|
|
//路由映射
|
|
|
|
$this->param['route'] = $this->param['route'].'-'.RouteMap::SOURCE_PRODUCT;
|
|
|
|
$id = $this->model->addReturnId($this->param);
|
|
|
|
}
|
|
|
|
$route = RouteMap::setRoute($this->param['route'], RouteMap::SOURCE_PRODUCT, $id, $this->user['project_id']);
|
|
|
|
$this->model->edit(['route'=>$route],['id'=>$id]);
|
|
|
|
//产品分类关联
|
|
|
|
// CategoryRelated::saveRelated($id, $category_ids);
|
|
|
|
CategoryRelated::saveRelated($id, $category_ids);
|
|
|
|
DB::connection('custom_mysql')->commit();
|
|
|
|
}catch (\Exception $e){
|
|
|
|
DB::connection('custom_mysql')->rollBack();
|
|
...
|
...
|
@@ -135,9 +140,6 @@ class ProductLogic extends BaseLogic |
|
|
|
}
|
|
|
|
$param['attrs'] = Arr::a2s($param['attrs'] ?? '');
|
|
|
|
$param['attr_id'] = Arr::arrToSet($param['attr_id'] ?? '');
|
|
|
|
if(isset($param['category_id']) && !empty($param['category_id'])) {
|
|
|
|
$param['category_id'] = $this->getLastCategory($param['category_id']);
|
|
|
|
}
|
|
|
|
if(isset($param['keyword_id']) && !empty($param['keyword_id'])){
|
|
|
|
$param['keyword_id'] = ','.Arr::arrToSet($param['keyword_id']).',';
|
|
|
|
}
|
|
...
|
...
|
@@ -156,7 +158,7 @@ class ProductLogic extends BaseLogic |
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :获取最后一级分类id
|
|
|
|
* @remark :获取最后一级分类id(字符串)
|
|
|
|
* @name :getLastCategory
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
...
|
...
|
@@ -177,13 +179,34 @@ class ProductLogic extends BaseLogic |
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :获取最后一级分类id(数组)
|
|
|
|
* @name :getLastCategory
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2023/10/20 9:02
|
|
|
|
*/
|
|
|
|
public function getLastCategoryArr($category){
|
|
|
|
$arr = [];
|
|
|
|
if(isset($category) && !empty($category)){
|
|
|
|
$cateModel = new Category();
|
|
|
|
foreach ($category as $v){
|
|
|
|
$info = $cateModel->read(['pid'=>$v]);
|
|
|
|
if($info === false){
|
|
|
|
$arr[] = $v;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $arr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :编辑产品
|
|
|
|
* @name :editProduct
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2023/9/7 10:02
|
|
|
|
*/
|
|
|
|
public function editProductRoute($id,$route){
|
|
|
|
public function editProductRoute($route){
|
|
|
|
$info = $this->model->read(['id'=>$this->param['id']]);
|
|
|
|
if($info['route'] != $route){
|
|
|
|
//生成一条删除路由记录
|
|
...
|
...
|
@@ -192,8 +215,12 @@ class ProductLogic extends BaseLogic |
|
|
|
'route'=>$route,
|
|
|
|
];
|
|
|
|
$this->setRouteDeleteSave($data);
|
|
|
|
//"字符串以\"-product\"结尾"
|
|
|
|
if (!endsWith($route, "-product")) {
|
|
|
|
$route = $route."-product";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $id;
|
|
|
|
return $route;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
...
|
...
|
@@ -410,23 +437,27 @@ class ProductLogic extends BaseLogic |
|
|
|
* @time :2023/8/15 17:53
|
|
|
|
*/
|
|
|
|
public function batchSetCategory(){
|
|
|
|
DB::connection('custom_mysql')->beginTransaction();
|
|
|
|
try {
|
|
|
|
//批量
|
|
|
|
$param = [
|
|
|
|
'category_id'=>','.Arr::arrToSet($this->param['category_id']).',',
|
|
|
|
'status'=>$this->param['status']
|
|
|
|
];
|
|
|
|
$this->model->edit($param,['id'=>['in',$this->param['id']]]);
|
|
|
|
//分类关联
|
|
|
|
foreach ($this->param['id'] as $id){
|
|
|
|
CategoryRelated::saveRelated($id, $this->param['category_id']);
|
|
|
|
}
|
|
|
|
DB::connection('custom_mysql')->commit();
|
|
|
|
//对应添加关联表
|
|
|
|
}catch (\Exception $e){
|
|
|
|
DB::connection('custom_mysql')->rollBack();
|
|
|
|
$this->fail('系统错误,请联系管理员');
|
|
|
|
if(isset($this->param['category_id']) && !empty($this->param['category_id'])) {
|
|
|
|
DB::connection('custom_mysql')->beginTransaction();
|
|
|
|
$category_ids = $this->getLastCategoryArr($this->param['category_id']);
|
|
|
|
$this->param['category_id'] = ','.implode(',',$category_ids).',';
|
|
|
|
try {
|
|
|
|
//批量
|
|
|
|
$param = [
|
|
|
|
'category_id'=>$this->param['category_id'],
|
|
|
|
'status'=>$this->param['status']
|
|
|
|
];
|
|
|
|
$this->model->edit($param,['id'=>['in',$this->param['id']]]);
|
|
|
|
//分类关联
|
|
|
|
foreach ($this->param['id'] as $id){
|
|
|
|
CategoryRelated::saveRelated($id, $category_ids);
|
|
|
|
}
|
|
|
|
DB::connection('custom_mysql')->commit();
|
|
|
|
//对应添加关联表
|
|
|
|
}catch (\Exception $e){
|
|
|
|
DB::connection('custom_mysql')->rollBack();
|
|
|
|
$this->fail('系统错误,请联系管理员');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $this->success();
|
|
|
|
}
|
...
|
...
|
|