正在显示
4 个修改的文件
包含
113 行增加
和
10 行删除
| @@ -53,4 +53,21 @@ class ExtendController extends BaseController | @@ -53,4 +53,21 @@ class ExtendController extends BaseController | ||
| 53 | $extendLogic->extendSave(); | 53 | $extendLogic->extendSave(); |
| 54 | $this->response('success'); | 54 | $this->response('success'); |
| 55 | } | 55 | } |
| 56 | + | ||
| 57 | + /** | ||
| 58 | + * @remark :删除扩展字段 | ||
| 59 | + * @name :del | ||
| 60 | + * @author :lyh | ||
| 61 | + * @method :post | ||
| 62 | + * @time :2023/11/9 16:00 | ||
| 63 | + */ | ||
| 64 | + public function del(ExtendLogic $extendLogic){ | ||
| 65 | + $this->request->validate([ | ||
| 66 | + 'id'=>'required', | ||
| 67 | + ],[ | ||
| 68 | + 'id.required' => '主键不能为空', | ||
| 69 | + ]); | ||
| 70 | + $extendLogic->extendDel(); | ||
| 71 | + $this->response('success'); | ||
| 72 | + } | ||
| 56 | } | 73 | } |
| @@ -12,6 +12,7 @@ namespace App\Http\Logic\Bside\Product; | @@ -12,6 +12,7 @@ namespace App\Http\Logic\Bside\Product; | ||
| 12 | use App\Helper\Translate; | 12 | use App\Helper\Translate; |
| 13 | use App\Http\Logic\Bside\BaseLogic; | 13 | use App\Http\Logic\Bside\BaseLogic; |
| 14 | use App\Models\Product\Extend; | 14 | use App\Models\Product\Extend; |
| 15 | +use App\Models\Product\ExtendInfo; | ||
| 15 | 16 | ||
| 16 | class ExtendLogic extends BaseLogic | 17 | class ExtendLogic extends BaseLogic |
| 17 | { | 18 | { |
| @@ -30,12 +31,54 @@ class ExtendLogic extends BaseLogic | @@ -30,12 +31,54 @@ class ExtendLogic extends BaseLogic | ||
| 30 | * @time :2023/11/9 14:29 | 31 | * @time :2023/11/9 14:29 |
| 31 | */ | 32 | */ |
| 32 | public function extendSave(){ | 33 | public function extendSave(){ |
| 33 | - $this->param['key'] = Translate::tran($this->param['title'], 'en'); | 34 | + $info = $this->model->read(['title'=>$this->param['title']]); |
| 35 | + if($info === false){ | ||
| 36 | + $this->fail('当前扩展名称已存在'); | ||
| 37 | + } | ||
| 34 | if(isset($this->param['id']) && !empty($this->param['id'])){ | 38 | if(isset($this->param['id']) && !empty($this->param['id'])){ |
| 35 | - | 39 | + $rs = $this->model->edit($this->param,['id'=>$this->param['id']]); |
| 36 | }else{ | 40 | }else{ |
| 41 | + $this->getKey(Translate::tran($this->param['title'], 'en')); | ||
| 42 | + $rs = $this->model->add($this->param); | ||
| 43 | + } | ||
| 44 | + if($rs === false){ | ||
| 45 | + $this->fail('error'); | ||
| 46 | + } | ||
| 47 | + return $this->success(); | ||
| 48 | + } | ||
| 37 | 49 | ||
| 50 | + /** | ||
| 51 | + * @remark :获取唯一key | ||
| 52 | + * @name :getKey | ||
| 53 | + * @author :lyh | ||
| 54 | + * @method :post | ||
| 55 | + * @time :2023/11/9 15:55 | ||
| 56 | + */ | ||
| 57 | + public function getKey($key){ | ||
| 58 | + $info = $this->model->read(['key'=>$key]); | ||
| 59 | + if($info === false){ | ||
| 60 | + $key .= '_1'; | ||
| 61 | + return $this->getKey($key); | ||
| 62 | + } | ||
| 63 | + return $key; | ||
| 38 | } | 64 | } |
| 39 | 65 | ||
| 66 | + /** | ||
| 67 | + * @remark :删除自定义字段 | ||
| 68 | + * @name :extendDel | ||
| 69 | + * @author :lyh | ||
| 70 | + * @method :post | ||
| 71 | + * @time :2023/11/9 16:07 | ||
| 72 | + */ | ||
| 73 | + public function extendDel(){ | ||
| 74 | + $info = $this->model->read(['id'=>$this->param['id']]); | ||
| 75 | + //查看当前扩展字段是否设置了值 | ||
| 76 | + $extendInfoModel = new ExtendInfo(); | ||
| 77 | + $extendInfo = $extendInfoModel->read(['key'=>$info['key']]); | ||
| 78 | + if($extendInfo !== false){ | ||
| 79 | + $this->fail('当前扩展字段已有产品在使用,不允许删除'); | ||
| 80 | + } | ||
| 81 | + $this->model->del(['id'=>$this->param['id']]); | ||
| 82 | + return $this->success(); | ||
| 40 | } | 83 | } |
| 41 | } | 84 | } |
| @@ -105,7 +105,7 @@ class KeywordLogic extends BaseLogic | @@ -105,7 +105,7 @@ class KeywordLogic extends BaseLogic | ||
| 105 | * @time :2023/8/28 14:03 | 105 | * @time :2023/8/28 14:03 |
| 106 | */ | 106 | */ |
| 107 | public function batchAdd(){ | 107 | public function batchAdd(){ |
| 108 | -// try { | 108 | + try { |
| 109 | $idArr = []; | 109 | $idArr = []; |
| 110 | foreach ($this->param['title'] as $v){ | 110 | foreach ($this->param['title'] as $v){ |
| 111 | $this->model = new Keyword(); | 111 | $this->model = new Keyword(); |
| @@ -125,9 +125,9 @@ class KeywordLogic extends BaseLogic | @@ -125,9 +125,9 @@ class KeywordLogic extends BaseLogic | ||
| 125 | $route = RouteMap::setRoute($v['title'], RouteMap::SOURCE_PRODUCT_KEYWORD, $v['id'], $this->user['project_id']); | 125 | $route = RouteMap::setRoute($v['title'], RouteMap::SOURCE_PRODUCT_KEYWORD, $v['id'], $this->user['project_id']); |
| 126 | $this->model->edit(['route'=>$route],['id'=>$v['id']]); | 126 | $this->model->edit(['route'=>$route],['id'=>$v['id']]); |
| 127 | } | 127 | } |
| 128 | -// }catch (\Exception $e){ | ||
| 129 | -// $this->fail('error'); | ||
| 130 | -// } | 128 | + }catch (\Exception $e){ |
| 129 | + $this->fail('error'); | ||
| 130 | + } | ||
| 131 | return $this->success(); | 131 | return $this->success(); |
| 132 | } | 132 | } |
| 133 | 133 |
| @@ -7,6 +7,7 @@ use App\Helper\Common; | @@ -7,6 +7,7 @@ use App\Helper\Common; | ||
| 7 | use App\Http\Logic\Bside\BaseLogic; | 7 | use App\Http\Logic\Bside\BaseLogic; |
| 8 | use App\Models\Product\Category; | 8 | use App\Models\Product\Category; |
| 9 | use App\Models\Product\CategoryRelated; | 9 | use App\Models\Product\CategoryRelated; |
| 10 | +use App\Models\Product\ExtendInfo; | ||
| 10 | use App\Models\Product\Keyword; | 11 | use App\Models\Product\Keyword; |
| 11 | use App\Models\Product\Product; | 12 | use App\Models\Product\Product; |
| 12 | use App\Models\RouteMap\RouteMap; | 13 | use App\Models\RouteMap\RouteMap; |
| @@ -37,6 +38,12 @@ class ProductLogic extends BaseLogic | @@ -37,6 +38,12 @@ class ProductLogic extends BaseLogic | ||
| 37 | * @time :2023/8/21 18:35 | 38 | * @time :2023/8/21 18:35 |
| 38 | */ | 39 | */ |
| 39 | public function productSave(){ | 40 | public function productSave(){ |
| 41 | + //扩展字段 | ||
| 42 | + $extend = []; | ||
| 43 | + if(!empty($this->param['extend'])){ | ||
| 44 | + $extend = $this->param['extend']; | ||
| 45 | + unset($this->param['extend']); | ||
| 46 | + } | ||
| 40 | $this->param = $this->handleSaveParam($this->param); | 47 | $this->param = $this->handleSaveParam($this->param); |
| 41 | //单独处理分类 | 48 | //单独处理分类 |
| 42 | $category_ids = []; | 49 | $category_ids = []; |
| @@ -52,16 +59,15 @@ class ProductLogic extends BaseLogic | @@ -52,16 +59,15 @@ class ProductLogic extends BaseLogic | ||
| 52 | $this->param['route'] = $this->editProductRoute($this->param['route']); | 59 | $this->param['route'] = $this->editProductRoute($this->param['route']); |
| 53 | $this->model->edit($this->param,['id'=>$this->param['id']]); | 60 | $this->model->edit($this->param,['id'=>$this->param['id']]); |
| 54 | }else{ | 61 | }else{ |
| 55 | - $this->param['project_id'] = $this->user['project_id']; | ||
| 56 | - $this->param['created_at'] = date('Y-m-d H:i:s'); | ||
| 57 | - $this->param['updated_at'] = $this->param['created_at']; | ||
| 58 | - $this->param['route'] = $this->param['route'].'-'.RouteMap::SOURCE_PRODUCT; | 62 | + $this->param = $this->addHandleParam($this->param); |
| 59 | $id = $this->model->addReturnId($this->param); | 63 | $id = $this->model->addReturnId($this->param); |
| 60 | } | 64 | } |
| 61 | $route = RouteMap::setRoute($this->param['route'], RouteMap::SOURCE_PRODUCT, $id, $this->user['project_id']); | 65 | $route = RouteMap::setRoute($this->param['route'], RouteMap::SOURCE_PRODUCT, $id, $this->user['project_id']); |
| 62 | $this->model->edit(['route'=>$route],['id'=>$id]); | 66 | $this->model->edit(['route'=>$route],['id'=>$id]); |
| 63 | //产品分类关联 | 67 | //产品分类关联 |
| 64 | CategoryRelated::saveRelated($id, $category_ids); | 68 | CategoryRelated::saveRelated($id, $category_ids); |
| 69 | + //保存扩展字段 | ||
| 70 | + $this->saveExtendInfo($id,$extend); | ||
| 65 | DB::connection('custom_mysql')->commit(); | 71 | DB::connection('custom_mysql')->commit(); |
| 66 | }catch (\Exception $e){ | 72 | }catch (\Exception $e){ |
| 67 | DB::connection('custom_mysql')->rollBack(); | 73 | DB::connection('custom_mysql')->rollBack(); |
| @@ -73,6 +79,43 @@ class ProductLogic extends BaseLogic | @@ -73,6 +79,43 @@ class ProductLogic extends BaseLogic | ||
| 73 | } | 79 | } |
| 74 | 80 | ||
| 75 | /** | 81 | /** |
| 82 | + * @remark :新增时处理字段 | ||
| 83 | + * @name :addHandleParam | ||
| 84 | + * @author :lyh | ||
| 85 | + * @method :post | ||
| 86 | + * @time :2023/11/9 14:48 | ||
| 87 | + */ | ||
| 88 | + public function addHandleParam($param){ | ||
| 89 | + $param['project_id'] = $this->user['project_id']; | ||
| 90 | + $param['created_at'] = date('Y-m-d H:i:s'); | ||
| 91 | + $param['updated_at'] = $param['created_at']; | ||
| 92 | + $this->param['route'] = $this->param['route'].'-'.RouteMap::SOURCE_PRODUCT; | ||
| 93 | + return $param; | ||
| 94 | + } | ||
| 95 | + | ||
| 96 | + /** | ||
| 97 | + * @remark :保存扩展字段 | ||
| 98 | + * @name :saveExtend | ||
| 99 | + * @author :lyh | ||
| 100 | + * @method :post | ||
| 101 | + * @time :2023/11/9 15:02 | ||
| 102 | + */ | ||
| 103 | + public function saveExtendInfo($id,$extend){ | ||
| 104 | + //先删除以前的数据 | ||
| 105 | + $extendInfoModel = new ExtendInfo(); | ||
| 106 | + $extendInfoModel->del(['project_id'=>$id]); | ||
| 107 | + if(!empty($extend)){ | ||
| 108 | + foreach ($extend as $v){ | ||
| 109 | + $v['project_id'] = $this->user['project_id']; | ||
| 110 | + $v['product_id'] = $id; | ||
| 111 | + $extendInfoModel->add($v); | ||
| 112 | + } | ||
| 113 | + } | ||
| 114 | + return $this->success(); | ||
| 115 | + } | ||
| 116 | + | ||
| 117 | + | ||
| 118 | + /** | ||
| 76 | * @remark :编辑列表数据 | 119 | * @remark :编辑列表数据 |
| 77 | * @name :editList | 120 | * @name :editList |
| 78 | * @author :lyh | 121 | * @author :lyh |
-
请 注册 或 登录 后发表评论