作者 lyh

gx

@@ -30,14 +30,30 @@ class KeywordPrefixLogic extends BaseLogic @@ -30,14 +30,30 @@ class KeywordPrefixLogic extends BaseLogic
30 * @time :2023/9/6 14:42 30 * @time :2023/9/6 14:42
31 */ 31 */
32 public function prefixSave(){ 32 public function prefixSave(){
33 - try {  
34 - if(isset($this->param['id']) && !empty($this->param['id'])){  
35 - $this->model->edit($this->param,['id'=>$this->param['id']]);  
36 - }else{  
37 - $this->model->add($this->param); 33 + if(isset($this->param['id']) && !empty($this->param['id'])){
  34 + $condition = [
  35 + 'keyword'=>$this->param['keyword'],
  36 + 'id'=>['!=',$this->param['id']]
  37 + ];
  38 + $prefixInfo = $this->model->read($condition);
  39 + if($prefixInfo !== false){
  40 + $this->fail('当前关键字已存在');
38 } 41 }
39 - }catch (\Exception $e){  
40 - $this->fail('error'); 42 + $data = [
  43 + 'keyword'=>$this->param['keyword']
  44 + ];
  45 + $this->model->edit($data,['id'=>$this->param['id']]);
  46 + }else{
  47 + $data = [
  48 + 'project_id'=>$this->param['project_id'] ?? 0,
  49 + 'keyword'=>$this->param['keyword'],
  50 + 'type'=>$this->param['type']
  51 + ];
  52 + $prefixInfo = $this->model->read($data);
  53 + if($prefixInfo !== false){
  54 + $this->fail('当前关键字已存在');
  55 + }
  56 + $this->model->add($data);
41 } 57 }
42 return $this->success(); 58 return $this->success();
43 } 59 }