|
...
|
...
|
@@ -334,22 +334,6 @@ class ProductLogic extends BaseLogic |
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :编辑产品
|
|
|
|
* @name :editProduct
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2023/9/7 10:02
|
|
|
|
*/
|
|
|
|
public function editProductRoute($id,$route){
|
|
|
|
$info = $this->model->read(['id'=>$id]);
|
|
|
|
if($info['route'] != $route){
|
|
|
|
$this->addUpdateNotify(RouteMap::SOURCE_PRODUCT,$route);
|
|
|
|
}
|
|
|
|
$this->curlDelRoute(['route'=>$info['route'],'new_route'=>$route]);
|
|
|
|
return $route;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :删除数据
|
|
|
|
* @name :delete
|
|
|
|
* @author :lyh
|
|
...
|
...
|
@@ -409,10 +393,32 @@ class ProductLogic extends BaseLogic |
|
|
|
//三种状态 0:草稿 1:发布 2:回收站
|
|
|
|
$data = ['dra'=>0,'pub'=>1,'del'=>2,'tal'=>3];
|
|
|
|
foreach ($data as $k => $v){
|
|
|
|
$map = [];
|
|
|
|
$cateModel = new Category();
|
|
|
|
$status = [];
|
|
|
|
if($v != 3){
|
|
|
|
$status = ['status'=>$v];
|
|
|
|
}
|
|
|
|
$cateList = $cateModel->list($status,'id',['id','pid']);
|
|
|
|
$this->param['featured_status'] = $this->param['featured_status'] ?? 0;
|
|
|
|
if(!empty($cateList) && ($this->param['featured_status'] != $cateModel::STATUS_ACTIVE)){
|
|
|
|
$featured_ids = $cateModel->where('title', 'like', 'Featured%')->pluck('id')->toArray();
|
|
|
|
//获取当前的子集
|
|
|
|
$featured_arr = [];
|
|
|
|
foreach ($featured_ids as $id){
|
|
|
|
$featured_arr = array_merge($featured_arr,array_unique(_get_all_sub($id,$cateList)));
|
|
|
|
}
|
|
|
|
if(!empty($featured_arr)){
|
|
|
|
$cateRelated = new CategoryRelated();
|
|
|
|
$product_ids = $cateRelated->whereIn('cate_id',$featured_arr)->pluck('product_id')->unique()->toArray();
|
|
|
|
$map['id'] = ['not in',$product_ids];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if($v == 3){
|
|
|
|
$data[$k] = $this->model->where(['project_id'=>$this->user['project_id']])->count();
|
|
|
|
$data[$k] = $this->model->formatQuery($map)->count();
|
|
|
|
}else{
|
|
|
|
$data[$k] = $this->model->where(['status'=>$v,'project_id'=>$this->user['project_id']])->count();
|
|
|
|
$map['status'] = $v;
|
|
|
|
$data[$k] = $this->model->formatQuery($map)->count();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $this->success($data);
|
|
...
|
...
|
@@ -428,16 +434,51 @@ class ProductLogic extends BaseLogic |
|
|
|
public function setCopyProduct(){
|
|
|
|
$info = $this->model->read(['id'=>$this->param['id']]);
|
|
|
|
$param = $this->setProductParams($info);
|
|
|
|
$save_id = $this->model->insertGetId($param);
|
|
|
|
$route = preg_replace('/-product.*/', '', $param['route']);
|
|
|
|
$route = RouteMap::setRoute($route, RouteMap::SOURCE_PRODUCT, $save_id, $this->user['project_id']);
|
|
|
|
$this->model->edit(['route'=>$route],['id'=>$save_id]);
|
|
|
|
//同步可视化装修数据
|
|
|
|
$this->copyTemplate($this->param['id'],$info['project_id'],$save_id);
|
|
|
|
DB::beginTransaction();
|
|
|
|
try {
|
|
|
|
$save_id = $this->model->insertGetId($param);
|
|
|
|
CategoryRelated::saveRelated($save_id, $info['category_id']);
|
|
|
|
$route = preg_replace('/-product.*/', '', $param['route']);
|
|
|
|
//同步分类关联表
|
|
|
|
$route = RouteMap::setRoute($route, RouteMap::SOURCE_PRODUCT, $save_id, $this->user['project_id']);
|
|
|
|
$this->model->edit(['route'=>$route],['id'=>$save_id]);
|
|
|
|
//同步可视化装修数据
|
|
|
|
$this->copyTemplate($this->param['id'],$info['project_id'],$save_id);
|
|
|
|
//同步扩展字段
|
|
|
|
$this->copyExtendInfo($info['id'],$save_id);
|
|
|
|
DB::commit();
|
|
|
|
}catch (\Exception $e){
|
|
|
|
DB::rollBack();
|
|
|
|
$this->fail('复制失败,请联系管理员');
|
|
|
|
}
|
|
|
|
return $this->success(['id'=>$save_id]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :复制项目扩展字段
|
|
|
|
* @name :copyExtendInfo
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2024/7/12 9:23
|
|
|
|
*/
|
|
|
|
public function copyExtendInfo($old_id,$new_id){
|
|
|
|
$extendInfoModel = new ExtendInfo();
|
|
|
|
$extendList = $extendInfoModel->list(['product_id'=>$old_id],'created_at');
|
|
|
|
if(!empty($extendList)){
|
|
|
|
$data = [];
|
|
|
|
foreach ($extendList as $k => $v){
|
|
|
|
unset($v['id']);
|
|
|
|
$v['product_id'] = $new_id;
|
|
|
|
$v['created_at'] = date('Y-m-d H:i:s');
|
|
|
|
$v['updated_at'] = date('Y-m-d H:i:s');
|
|
|
|
$data[] = $v;
|
|
|
|
}
|
|
|
|
return $extendList->insert($data);
|
|
|
|
}
|
|
|
|
return $this->success();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :同步模版数据
|
|
|
|
* @name :copyTemplate
|
|
|
|
* @author :lyh
|
|
...
|
...
|
@@ -847,4 +888,35 @@ class ProductLogic extends BaseLogic |
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :产品列表搜索参数时分类列表
|
|
|
|
* @param :
|
|
|
|
* @name :getSearchCategoryList
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2024/7/9 14:56
|
|
|
|
*/
|
|
|
|
public function getSearchCategoryList()
|
|
|
|
{
|
|
|
|
$data = [];
|
|
|
|
$categoryModel = new Category();
|
|
|
|
$this->param['deleted_at'] = null;
|
|
|
|
$this->param['featured_status'] = $this->param['featured_status'] ?? 0;
|
|
|
|
if(($this->param['featured_status'] != Category::STATUS_ACTIVE)) {
|
|
|
|
$this->param['title'] = ['not like','Featured%'];
|
|
|
|
}
|
|
|
|
unset($this->param['featured_status']);
|
|
|
|
$list = $categoryModel->list($this->param, ['sort', 'id'], ['id', 'pid', 'title']);
|
|
|
|
if (!empty($list)) {
|
|
|
|
foreach ($list as $v) {
|
|
|
|
$v = (array)$v;
|
|
|
|
if ($v['pid'] == 0) {
|
|
|
|
$v['sub'] = _get_child($v['id'], $list);
|
|
|
|
$data[] = $v;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $this->success($data);
|
|
|
|
}
|
|
|
|
} |
...
|
...
|
|