作者 lyh

gx

... ... @@ -53,4 +53,21 @@ class ExtendController extends BaseController
$extendLogic->extendSave();
$this->response('success');
}
/**
* @remark :删除扩展字段
* @name :del
* @author :lyh
* @method :post
* @time :2023/11/9 16:00
*/
public function del(ExtendLogic $extendLogic){
$this->request->validate([
'id'=>'required',
],[
'id.required' => '主键不能为空',
]);
$extendLogic->extendDel();
$this->response('success');
}
}
... ...
... ... @@ -12,6 +12,7 @@ namespace App\Http\Logic\Bside\Product;
use App\Helper\Translate;
use App\Http\Logic\Bside\BaseLogic;
use App\Models\Product\Extend;
use App\Models\Product\ExtendInfo;
class ExtendLogic extends BaseLogic
{
... ... @@ -30,12 +31,54 @@ class ExtendLogic extends BaseLogic
* @time :2023/11/9 14:29
*/
public function extendSave(){
$this->param['key'] = Translate::tran($this->param['title'], 'en');
$info = $this->model->read(['title'=>$this->param['title']]);
if($info === false){
$this->fail('当前扩展名称已存在');
}
if(isset($this->param['id']) && !empty($this->param['id'])){
$rs = $this->model->edit($this->param,['id'=>$this->param['id']]);
}else{
$this->getKey(Translate::tran($this->param['title'], 'en'));
$rs = $this->model->add($this->param);
}
if($rs === false){
$this->fail('error');
}
return $this->success();
}
/**
* @remark :获取唯一key
* @name :getKey
* @author :lyh
* @method :post
* @time :2023/11/9 15:55
*/
public function getKey($key){
$info = $this->model->read(['key'=>$key]);
if($info === false){
$key .= '_1';
return $this->getKey($key);
}
return $key;
}
/**
* @remark :删除自定义字段
* @name :extendDel
* @author :lyh
* @method :post
* @time :2023/11/9 16:07
*/
public function extendDel(){
$info = $this->model->read(['id'=>$this->param['id']]);
//查看当前扩展字段是否设置了值
$extendInfoModel = new ExtendInfo();
$extendInfo = $extendInfoModel->read(['key'=>$info['key']]);
if($extendInfo !== false){
$this->fail('当前扩展字段已有产品在使用,不允许删除');
}
$this->model->del(['id'=>$this->param['id']]);
return $this->success();
}
}
... ...
... ... @@ -105,7 +105,7 @@ class KeywordLogic extends BaseLogic
* @time :2023/8/28 14:03
*/
public function batchAdd(){
// try {
try {
$idArr = [];
foreach ($this->param['title'] as $v){
$this->model = new Keyword();
... ... @@ -125,9 +125,9 @@ class KeywordLogic extends BaseLogic
$route = RouteMap::setRoute($v['title'], RouteMap::SOURCE_PRODUCT_KEYWORD, $v['id'], $this->user['project_id']);
$this->model->edit(['route'=>$route],['id'=>$v['id']]);
}
// }catch (\Exception $e){
// $this->fail('error');
// }
}catch (\Exception $e){
$this->fail('error');
}
return $this->success();
}
... ...
... ... @@ -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,16 +59,15 @@ 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);
}
$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);
//保存扩展字段
$this->saveExtendInfo($id,$extend);
DB::connection('custom_mysql')->commit();
}catch (\Exception $e){
DB::connection('custom_mysql')->rollBack();
... ... @@ -73,6 +79,43 @@ class ProductLogic extends BaseLogic
}
/**
* @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'];
$this->param['route'] = $this->param['route'].'-'.RouteMap::SOURCE_PRODUCT;
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){
$v['project_id'] = $this->user['project_id'];
$v['product_id'] = $id;
$extendInfoModel->add($v);
}
}
return $this->success();
}
/**
* @remark :编辑列表数据
* @name :editList
* @author :lyh
... ...