作者 lyh

gx

... ... @@ -298,24 +298,7 @@ class ProductController extends BaseController
$v['values'] = '';
}
}else{
if($v['type'] == 3){
$arr = json_decode($info['values']);
foreach ($arr as $k1=>$v1){
$v1 = (array)$v1;
$v1['url'] = getImageUrl($v1['url']);
$arr[$k1] = $v1;
}
$v['values'] = $arr;
}elseif($v['type'] == 4){
$arr1 = json_decode($info['values']);
foreach ($arr1 as $k1=>$v1){
$v1 = getFileUrl($v1);
$arr1[$k1] = $v1;
}
$v['values'] = $arr1;
}else{
$v['values'] = $info['values'];
}
$v = $this->setTypValues($v,$info);
}
$list[$k] = $v;
}
... ... @@ -323,6 +306,35 @@ class ProductController extends BaseController
}
/**
* @remark :扩展字段根据type返回类型
* @name :setTypValues
* @author :lyh
* @method :post
* @time :2023/12/6 14:43
*/
public function setTypValues($v,$info){
if($v['type'] == 3){
$arr = json_decode($info['values']);
foreach ($arr as $k1=>$v1){
$v1 = (array)$v1;
$v1['url'] = getImageUrl($v1['url']);
$arr[$k1] = $v1;
}
$v['values'] = $arr;
}elseif($v['type'] == 4){
$arr1 = json_decode($info['values']);
foreach ($arr1 as $k1=>$v1){
$v1 = getFileUrl($v1);
$arr1[$k1] = $v1;
}
$v['values'] = $arr1;
}else{
$v['values'] = $info['values'];
}
return $this->success($v);
}
/**
* @remark :保存产品数据
* @name :save
* @author :lyh
... ...
... ... @@ -38,21 +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);
//处理扩展字段
$extend = $this->handleExtent();
//单独处理分类
$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).',';
}else{
$this->param['category_id'] = '';
}
$category_ids = $this->handleCategory();
//处理其他字段
$this->param = $this->handleSaveParam($this->param);
DB::connection('custom_mysql')->beginTransaction();
try {
if(isset($this->param['id']) && !empty($this->param['id'])){
... ... @@ -81,6 +72,40 @@ class ProductLogic extends BaseLogic
}
/**
* @remark :处理扩展字段
* @name :handleExtent
* @author :lyh
* @method :post
* @time :2023/12/6 15:06
*/
public function handleExtent(){
//扩展字段
$extend = [];
if(!empty($this->param['extend'])){
$extend = $this->param['extend'];
unset($this->param['extend']);
}
return $extend;
}
/**
* @remark :处理分类数据
* @name :handleCategory
* @author :lyh
* @method :post
* @time :2023/12/6 15:01
*/
public function handleCategory(){
$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).',';
}else{
$this->param['category_id'] = '';
}
return $category_ids;
}
/**
* @remark :新增时处理字段
* @name :addHandleParam
* @author :lyh
... ... @@ -112,27 +137,38 @@ class ProductLogic extends BaseLogic
if(empty($v['values'])){
continue;
}
unset($v['title']);
if($v['type'] == 3){
foreach ($v['values'] as $k1=>$v1){
$v1['url'] = str_replace_url($v1['url']);
$v['values'][$k1] = $v1;
}
$v['values'] = json_encode($v['values']);
}elseif ($v['type'] == 4){
foreach ($v['values'] as $k1=>$v1){
$v1 = str_replace_url($v1);
$v['values'][$k1] = $v1;
}
$v['values'] = json_encode($v['values']);
}
$v['project_id'] = $this->user['project_id'];
$v['product_id'] = $product_id;
$v = $this->saveHandleExtend($v,$product_id);
$extendInfoModel->add($v);
}
return $this->success();
}
/**
* @remark :保存扩展字段时处理数据
* @name :saveHandleExtend
* @author :lyh
* @method :post
* @time :2023/12/6 15:11
*/
public function saveHandleExtend(&$v,$product_id){
unset($v['title']);
if($v['type'] == 3){
foreach ($v['values'] as $k1=>$v1){
$v1['url'] = str_replace_url($v1['url']);
$v['values'][$k1] = $v1;
}
$v['values'] = json_encode($v['values']);
}elseif ($v['type'] == 4){
foreach ($v['values'] as $k1=>$v1){
$v1 = str_replace_url($v1);
$v['values'][$k1] = $v1;
}
$v['values'] = json_encode($v['values']);
}
$v['project_id'] = $this->user['project_id'];
$v['product_id'] = $product_id;
return $this->success($v);
}
/**
* @remark :编辑列表数据
... ...
... ... @@ -38,7 +38,9 @@ class CategoryRelated extends Base
foreach ($cate_ids as $cate_id){
$data[] = [
'product_id' => $product_id,
'cate_id' => $cate_id
'cate_id' => $cate_id,
'created_at'=>date('Y-m-d H:i:s'),
'updated_at'=>date('Y-m-d H:i:s')
];
}
self::insert($data);
... ...