|
...
|
...
|
@@ -7,6 +7,8 @@ use App\Helper\Common; |
|
|
|
use App\Http\Logic\Bside\BaseLogic;
|
|
|
|
use App\Models\Product\Category;
|
|
|
|
use App\Models\Product\CategoryRelated;
|
|
|
|
use App\Models\Product\Column;
|
|
|
|
use App\Models\Product\Detail;
|
|
|
|
use App\Models\Product\ExtendInfo;
|
|
|
|
use App\Models\Product\Keyword;
|
|
|
|
use App\Models\Product\KeywordRelated;
|
|
...
|
...
|
@@ -39,113 +41,176 @@ class ProductLogic extends BaseLogic |
|
|
|
* @time :2023/8/21 18:35
|
|
|
|
*/
|
|
|
|
public function productSave(){
|
|
|
|
//处理扩展字段
|
|
|
|
$extend = $this->handleExtent();
|
|
|
|
//单独处理分类
|
|
|
|
$category_ids = $this->handleCategory();
|
|
|
|
$keyword_arr = $this->param['keyword_id'] ?? [];
|
|
|
|
//处理其他字段
|
|
|
|
$this->param = $this->handleSaveParam($this->param);
|
|
|
|
try {
|
|
|
|
if(isset($this->param['id']) && !empty($this->param['id'])){
|
|
|
|
$is_upgrade = $this->param['is_upgrade'] ?? 0;//1:5.0数据 0:6.0
|
|
|
|
$six_read = $this->param['six_read'] ?? 0;//是否按6.0显示
|
|
|
|
if($is_upgrade == 0 || $six_read == 0){
|
|
|
|
$this->param['route'] = RouteMap::setRoute($this->param['route'], RouteMap::SOURCE_PRODUCT, $this->param['id'], $this->user['project_id']);
|
|
|
|
}
|
|
|
|
$route = $this->param['route'];
|
|
|
|
$this->model->edit($this->param,['id'=>$this->param['id']]);
|
|
|
|
$id = $this->param['id'];
|
|
|
|
$data = $this->editProduct();
|
|
|
|
}else{
|
|
|
|
$this->param = $this->addHandleParam($this->param);
|
|
|
|
$data = $this->addProduct();
|
|
|
|
}
|
|
|
|
CategoryRelated::saveRelated($data['id'], $this->param['category_id'] ?? []);//分类关联
|
|
|
|
KeywordRelated::saveRelated($data['id'],$this->param['keyword_id'] ?? []);//关键字关联
|
|
|
|
$this->saveExtendInfo($data['id'],$this->param['extend'] ?? []);//扩展字段
|
|
|
|
$this->saveDetail($data['id'],$this->param['detail'] ?? []);
|
|
|
|
}catch (\Exception $e){
|
|
|
|
Log::info('错误信息---'.$e->getMessage());
|
|
|
|
$this->fail('系统错误,请联系管理员');
|
|
|
|
}
|
|
|
|
$this->addUpdateNotify(RouteMap::SOURCE_PRODUCT,$data['route'] ?? '');
|
|
|
|
$this->curlDelRoute(['new_route'=>$data['route'] ?? '']);
|
|
|
|
return $this->success(['id'=>$data['id']]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :新增产品
|
|
|
|
* @name :saveProduct
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2024/12/18 9:48
|
|
|
|
*/
|
|
|
|
public function addProduct(){
|
|
|
|
//处理字段
|
|
|
|
$param = $this->handleSaveParam($this->param);
|
|
|
|
//新增时所需默认参数
|
|
|
|
$param['project_id'] = $this->user['project_id'];
|
|
|
|
if($this->user['project_id'] != 2059){//2059项目不处理排序
|
|
|
|
$this->param['sort'] = $this->setProductSort();
|
|
|
|
$param['sort'] = $this->setProductSort();
|
|
|
|
}
|
|
|
|
$id = $this->model->addReturnId($this->param);
|
|
|
|
try {
|
|
|
|
$id = $this->model->addReturnId($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);
|
|
|
|
KeywordRelated::saveRelated($id,$keyword_arr);
|
|
|
|
//更新产品新描述
|
|
|
|
$detailLogic = new DetailLogic();
|
|
|
|
$detailLogic->saveDetail($id,$this->param['data'] ?? []);
|
|
|
|
//保存扩展字段
|
|
|
|
$this->saveExtendInfo($id,$extend);
|
|
|
|
//保存新描述
|
|
|
|
}catch (\Exception $e){
|
|
|
|
Log::info('错误信息---'.$e->getMessage());
|
|
|
|
$this->fail('系统错误,请联系管理员');
|
|
|
|
$this->fail('操作失败,请联系管理员:'.$e->getMessage());
|
|
|
|
}
|
|
|
|
$this->addUpdateNotify(RouteMap::SOURCE_PRODUCT,$route);
|
|
|
|
$this->curlDelRoute(['new_route'=>$route]);
|
|
|
|
return $this->success(['id'=>$id]);
|
|
|
|
return $this->success(['id'=>$id,'route'=>$route]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :设置最新产品的sort排序
|
|
|
|
* @name :setNewsSort
|
|
|
|
* @remark :编辑产品
|
|
|
|
* @name :editProduct
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2023/12/25 9:27
|
|
|
|
* @time :2024/12/18 10:09
|
|
|
|
*/
|
|
|
|
public function setProductSort(){
|
|
|
|
$info = $this->model->orderBy('sort','desc')->first();
|
|
|
|
if(empty($info)){
|
|
|
|
return 1;
|
|
|
|
public function editProduct(){
|
|
|
|
//处理字段
|
|
|
|
$param = $this->handleSaveParam($this->param);
|
|
|
|
$route = $param['route'];
|
|
|
|
$is_upgrade = $param['is_upgrade'] ?? 0;//1:5.0数据 0:6.0
|
|
|
|
$six_read = $param['six_read'] ?? 0;//是否按6.0显示
|
|
|
|
try {
|
|
|
|
if($six_read == 0 && $is_upgrade == 1){
|
|
|
|
unset($param['route']);
|
|
|
|
}else{
|
|
|
|
$param['route'] = RouteMap::setRoute($param['route'], RouteMap::SOURCE_PRODUCT, $this->param['id'], $this->user['project_id']);
|
|
|
|
}
|
|
|
|
$sort = $info['sort']+1;
|
|
|
|
return $sort;
|
|
|
|
$this->model->edit($param,['id'=>$this->param['id']]);
|
|
|
|
//保存新描述
|
|
|
|
}catch (\Exception $e){
|
|
|
|
$this->fail('操作失败,请联系管理员:'.$e->getMessage());
|
|
|
|
}
|
|
|
|
return $this->success(['id'=>$this->param['id'],'route'=>$route]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :处理扩展字段
|
|
|
|
* @name :handleExtent
|
|
|
|
* @remark :保存产品描述切换栏
|
|
|
|
* @name :saveDetail
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2023/12/6 15:06
|
|
|
|
* @time :2024/12/18 10:25
|
|
|
|
*/
|
|
|
|
public function handleExtent(){
|
|
|
|
//扩展字段
|
|
|
|
$extend = [];
|
|
|
|
if(!empty($this->param['extend'])){
|
|
|
|
$extend = $this->param['extend'];
|
|
|
|
unset($this->param['extend']);
|
|
|
|
public function saveDetail($product_id,$detail){
|
|
|
|
$this->delProductDetail($product_id);
|
|
|
|
if(!empty($detail)){
|
|
|
|
try {
|
|
|
|
foreach ($detail as $val){
|
|
|
|
foreach ($val as $v){
|
|
|
|
if(empty($v['column_name'])){
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
//查看当前栏目是否存在
|
|
|
|
$columnId = $this->getColumnId($product_id,$v['column_name']);
|
|
|
|
$save_data = $this->handleDetailParam($columnId['column_id'],$product_id,$v);
|
|
|
|
$this->model->add($save_data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}catch (\Exception $e){
|
|
|
|
$this->fail('保存失败,请联系管理员.错误:'.$e->getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $extend;
|
|
|
|
return $this->success(['product_id'=>$product_id]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :处理分类数据
|
|
|
|
* @name :handleCategory
|
|
|
|
* @remark :删除当前产品的所有detail
|
|
|
|
* @name :delProductDetail
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2023/12/6 15:01
|
|
|
|
* @time :2024/12/18 10:50
|
|
|
|
*/
|
|
|
|
public function handleCategory(){
|
|
|
|
$category_ids = [];
|
|
|
|
if(isset($this->param['category_id']) && !empty($this->param['category_id'])) {
|
|
|
|
$category_ids = $this->param['category_id'];
|
|
|
|
$this->param['category_id'] = ','.implode(',',$category_ids).',';
|
|
|
|
public function delProductDetail($product_id){
|
|
|
|
$columnModel = new Column();
|
|
|
|
$columnModel->del(['product_id'=>$product_id]);
|
|
|
|
$detailModel= new Detail();
|
|
|
|
$detailModel->del(['product_id'=>$product_id]);
|
|
|
|
return $this->success();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :获取当前栏目id
|
|
|
|
* @name :getColumnId
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2024/12/18 10:42
|
|
|
|
*/
|
|
|
|
public function getColumnId($product_id,$column_name){
|
|
|
|
$columnModel = new Column();
|
|
|
|
$columnInfo = $columnModel->read(['column_name'=>strtolower($column_name),'product_id'=>$product_id]);
|
|
|
|
if($columnInfo['id'] != 1){
|
|
|
|
$column_id = $columnModel->addReturnId(['column_name'=>$column_name,'product_id'=>$product_id]);
|
|
|
|
}else{
|
|
|
|
$this->param['category_id'] = '';
|
|
|
|
$column_id = 1;
|
|
|
|
}
|
|
|
|
return $category_ids;
|
|
|
|
return $this->success(['column_id'=>$column_id]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :新增时处理字段
|
|
|
|
* @name :addHandleParam
|
|
|
|
* @remark :保存时处理描述数据
|
|
|
|
* @name :handleDetailParam
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2023/11/9 14:48
|
|
|
|
* @time :2024/12/18 10:47
|
|
|
|
*/
|
|
|
|
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;
|
|
|
|
public function handleDetailParam($column_id,$product_id,$info){
|
|
|
|
$save_data = [
|
|
|
|
'sort'=>$info['sort'],
|
|
|
|
'column_id'=>$column_id,
|
|
|
|
'product_id'=>$product_id,
|
|
|
|
'text_type'=>$info['text_type'],
|
|
|
|
'title'=>$info['title'] ?? '',
|
|
|
|
'content'=>json_encode($info['content'] ?? [],JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES),
|
|
|
|
'css'=>json_encode($info['css'] ?? [],JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES),
|
|
|
|
];
|
|
|
|
return $this->success(['data'=>$save_data]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :设置最新产品的sort排序
|
|
|
|
* @name :setNewsSort
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2023/12/25 9:27
|
|
|
|
*/
|
|
|
|
public function setProductSort(){
|
|
|
|
$info = $this->model->orderBy('sort','desc')->first();
|
|
|
|
if(empty($info)){
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
$sort = $info['sort']+1;
|
|
|
|
return $sort;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :保存扩展字段
|
|
...
|
...
|
@@ -282,6 +347,12 @@ class ProductLogic extends BaseLogic |
|
|
|
* @time :2023/8/21 17:03
|
|
|
|
*/
|
|
|
|
public function handleSaveParam(&$param){
|
|
|
|
if(isset($this->param['category_id']) && !empty($this->param['category_id'])) {
|
|
|
|
$category_ids = $this->param['category_id'];
|
|
|
|
$param['category_id'] = ','.implode(',',$category_ids).',';
|
|
|
|
}else{
|
|
|
|
$param['category_id'] = '';
|
|
|
|
}
|
|
|
|
//产品图
|
|
|
|
if(isset($param['gallery']) && !empty($param['gallery'])){
|
|
|
|
foreach ($param['gallery'] as $k => $v){
|
...
|
...
|
|