作者 lyh

gx

... ... @@ -213,16 +213,7 @@ class ProductController extends BaseController
* @time :2023/8/17 9:15
*/
public function handleParam($v){
$v['category_id_text'] = '';
$v['keyword_id_text'] = '';
if(!empty($v['category_id'])){
$categoryModel = new Category();
$category_data = $categoryModel->list(['id'=>['in',$v['category_id']]],'id',['title']);
foreach ($category_data as $v1){
$v['category_id_text'] .= $v1['title'].',';
}
$v['category_id_text'] = trim($v['category_id_text'],',');
}
if(!empty($v['keyword_id'])){
$keywordModel = new Keyword();
$keyword_data = $keywordModel->list(['id'=>['in',$v['keyword_id']]]);
... ...
... ... @@ -102,12 +102,12 @@ class BlogLogic extends BaseLogic
if($info === false){
$this->fail('error');
}
$category = explode(',',trim($info['category_id'],','));
$str = [];
foreach ($category as $v){
$this->getAllFather($v,$str);
}
$info['category_id'] = array_values(array_unique($str));
$info['category_id'] = explode(',',trim($info['category_id'],','));
// $str = [];
// foreach ($category as $v){
// $this->getAllFather($v,$str);
// }
// $info['category_id'] = array_values(array_unique($str));
//获取标签名称
$blogLabelLogic = new BlogLabelLogic();
$info['label_name'] = $blogLabelLogic->getLabelName($info['label_id']);
... ... @@ -115,21 +115,21 @@ class BlogLogic extends BaseLogic
return $this->success($info);
}
/**
* @remark :获取分类的所有上级
* @name :getAllFather
* @author :lyh
* @method :post
* @time :2023/10/20 9:08
*/
public function getAllFather($id,&$str = []){
$cateModel = new BlogCategoryModel();
$info = $cateModel->read(['id'=>$id],['id','pid']);
if($info !== false){
$str[] = (int)$id;
$this->getAllFather($info['pid'],$str);
}
}
// /**
// * @remark :获取分类的所有上级
// * @name :getAllFather
// * @author :lyh
// * @method :post
// * @time :2023/10/20 9:08
// */
// public function getAllFather($id,&$str = []){
// $cateModel = new BlogCategoryModel();
// $info = $cateModel->read(['id'=>$id],['id','pid']);
// if($info !== false){
// $str[] = (int)$id;
// $this->getAllFather($info['pid'],$str);
// }
// }
/**
* @name :修改状态
... ...
... ... @@ -152,12 +152,12 @@ class NewsLogic extends BaseLogic
if($info === false){
$this->fail('error');
}
$category = explode(',',trim($info['category_id'],','));
$str = [];
foreach ($category as $v){
$this->getAllFather($v,$str);
}
$info['category_id'] = array_values(array_unique($str));
$info['category_id'] = explode(',',trim($info['category_id'],','));
// $str = [];
// foreach ($category as $v){
// $this->getAllFather($v,$str);
// }
// $info['category_id'] = array_values(array_unique($str));
$info['image_link'] = getImageUrl($info['image']);
return $this->success($info);
}
... ...
... ... @@ -4,6 +4,7 @@ namespace App\Http\Logic\Bside\Product;
use App\Helper\Arr;
use App\Http\Logic\Bside\BaseLogic;
use App\Models\Product\Category;
use App\Models\Product\CategoryRelated;
use App\Models\Product\Product;
use App\Models\RouteMap\RouteMap;
... ... @@ -26,9 +27,6 @@ class ProductLogic extends BaseLogic
$this->model = new Product();
}
/**
* @remark :保存产品
* @name :productSave
... ... @@ -37,7 +35,7 @@ class ProductLogic extends BaseLogic
* @time :2023/8/21 18:35
*/
public function productSave(){
$category_ids = $this->param['category_id'] ?? [];
// $category_ids = $this->param['category_id'] ?? [];
//参数处理
$this->param = $this->handleSaveParam($this->param);
DB::connection('custom_mysql')->beginTransaction();
... ... @@ -56,8 +54,7 @@ class ProductLogic extends BaseLogic
$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();
... ... @@ -88,7 +85,7 @@ 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'] = ','.Arr::arrToSet($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']).',';
... ... @@ -108,6 +105,25 @@ class ProductLogic extends BaseLogic
}
/**
* @remark :获取最后一级分类id
* @name :getLastCategory
* @author :lyh
* @method :post
* @time :2023/10/20 9:02
*/
public function getLastCategory($category){
$str = '';
$cateModel = new Category();
foreach ($category as $v){
$info = $cateModel->read(['pid'=>$v]);
if($info === false){
$str .= $v.',';
}
}
return ','.$str;
}
/**
* @remark :编辑产品
* @name :editProduct
* @author :lyh
... ...