|
...
|
...
|
@@ -7,6 +7,7 @@ use App\Helper\Common; |
|
|
|
use App\Http\Logic\Bside\BaseLogic;
|
|
|
|
use App\Models\Product\Category;
|
|
|
|
use App\Models\Product\CategoryRelated;
|
|
|
|
use App\Models\Product\ExtendInfo;
|
|
|
|
use App\Models\Product\Keyword;
|
|
|
|
use App\Models\Product\Product;
|
|
|
|
use App\Models\RouteMap\RouteMap;
|
|
...
|
...
|
@@ -37,6 +38,12 @@ class ProductLogic extends BaseLogic |
|
|
|
* @time :2023/8/21 18:35
|
|
|
|
*/
|
|
|
|
public function productSave(){
|
|
|
|
//扩展字段
|
|
|
|
$extend = [];
|
|
|
|
if(!empty($this->param['extend'])){
|
|
|
|
$extend = $this->param['extend'];
|
|
|
|
unset($this->param['extend']);
|
|
|
|
}
|
|
|
|
$this->param = $this->handleSaveParam($this->param);
|
|
|
|
//单独处理分类
|
|
|
|
$category_ids = [];
|
|
...
|
...
|
@@ -52,26 +59,67 @@ class ProductLogic extends BaseLogic |
|
|
|
$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;
|
|
|
|
$this->param = $this->addHandleParam($this->param);
|
|
|
|
$id = $this->model->addReturnId($this->param);
|
|
|
|
$this->param['route'] = RouteMap::setRoute($this->param['route'], RouteMap::SOURCE_PRODUCT, $id, $this->user['project_id']);
|
|
|
|
}
|
|
|
|
$route = RouteMap::setRoute($this->param['route'], RouteMap::SOURCE_PRODUCT, $id, $this->user['project_id']);
|
|
|
|
$this->model->edit(['route'=>$route],['id'=>$id]);
|
|
|
|
$this->model->edit(['route'=> $this->param['route']],['id'=>$id]);
|
|
|
|
//产品分类关联
|
|
|
|
CategoryRelated::saveRelated($id, $category_ids);
|
|
|
|
//保存扩展字段
|
|
|
|
$this->saveExtendInfo($id,$extend);
|
|
|
|
DB::connection('custom_mysql')->commit();
|
|
|
|
}catch (\Exception $e){
|
|
|
|
DB::connection('custom_mysql')->rollBack();
|
|
|
|
$this->fail('系统错误请联系管理员');
|
|
|
|
}
|
|
|
|
//通知更新
|
|
|
|
$this->updateNotify(['project_id'=>$this->user['project_id'], 'type'=>RouteMap::SOURCE_PRODUCT, 'route'=>$route]);
|
|
|
|
$this->updateNotify(['project_id'=>$this->user['project_id'], 'type'=>RouteMap::SOURCE_PRODUCT, 'route'=>$this->param['route']]);
|
|
|
|
return $this->success();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :新增时处理字段
|
|
|
|
* @name :addHandleParam
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2023/11/9 14:48
|
|
|
|
*/
|
|
|
|
public function addHandleParam($param){
|
|
|
|
$param['project_id'] = $this->user['project_id'];
|
|
|
|
$param['created_at'] = date('Y-m-d H:i:s');
|
|
|
|
$param['updated_at'] = $param['created_at'];
|
|
|
|
return $param;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :保存扩展字段
|
|
|
|
* @name :saveExtend
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2023/11/9 15:02
|
|
|
|
*/
|
|
|
|
public function saveExtendInfo($id,$extend){
|
|
|
|
//先删除以前的数据
|
|
|
|
$extendInfoModel = new ExtendInfo();
|
|
|
|
$extendInfoModel->del(['project_id'=>$id]);
|
|
|
|
if(!empty($extend)){
|
|
|
|
foreach ($extend as $v){
|
|
|
|
unset($v['title']);
|
|
|
|
if(!empty($v['values'])){
|
|
|
|
if($v['type'] == 3 || $v['type'] || 4){
|
|
|
|
$v['values'] = str_replace_url($v['values']);
|
|
|
|
}
|
|
|
|
$v['project_id'] = $this->user['project_id'];
|
|
|
|
$v['product_id'] = $id;
|
|
|
|
$extendInfoModel->add($v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $this->success();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :编辑列表数据
|
|
|
|
* @name :editList
|
|
...
|
...
|
@@ -135,15 +183,15 @@ class ProductLogic extends BaseLogic |
|
|
|
$v['url'] = str_replace_url($v['url']);
|
|
|
|
$param['gallery'][$k] = $v;
|
|
|
|
}
|
|
|
|
$param['thumb'] = Arr::a2s($param['gallery'][0] ?? '');
|
|
|
|
$param['gallery'] = Arr::a2s($param['gallery'] ?? '');
|
|
|
|
$param['thumb'] = Arr::a2s($param['gallery'][0] ?? []);
|
|
|
|
$param['gallery'] = Arr::a2s($param['gallery'] ?? []);
|
|
|
|
}
|
|
|
|
$param['attrs'] = Arr::a2s($param['attrs'] ?? '');
|
|
|
|
$param['attrs'] = Arr::a2s($param['attrs'] ?? []);
|
|
|
|
$param['attr_id'] = Arr::arrToSet($param['attr_id'] ?? '');
|
|
|
|
if(isset($param['keyword_id']) && !empty($param['keyword_id'])){
|
|
|
|
$param['keyword_id'] = ','.Arr::arrToSet($param['keyword_id']).',';
|
|
|
|
}
|
|
|
|
$param['describe'] = Arr::a2s($param['describe'] ?? '');
|
|
|
|
$param['describe'] = Arr::a2s($param['describe'] ?? []);
|
|
|
|
$param['describe_id'] = Arr::arrToSet($param['describe_id'] ?? '');
|
|
|
|
$param['seo_mate'] = Arr::a2s($param['seo_mate'] ?? '');
|
|
|
|
$param['related_product_id'] = Arr::arrToSet($param['related_product_id'] ?? '');
|
|
...
|
...
|
@@ -151,7 +199,7 @@ class ProductLogic extends BaseLogic |
|
|
|
foreach ($param['icon'] as $k1 => $v1){
|
|
|
|
$param['icon'][$k1] = str_replace_url($v1);
|
|
|
|
}
|
|
|
|
$param['icon'] = Arr::a2s($param['icon'] ?? '');
|
|
|
|
$param['icon'] = Arr::a2s($param['icon'] ?? []);
|
|
|
|
}
|
|
|
|
$param['created_uid'] = $this->user['id'];
|
|
|
|
return $param;
|
...
|
...
|
|