KeywordPrefixLogic.php 1.8 KB
<?php
/**
 * @remark :
 * @name   :KeywordPrefixLogic.php
 * @author :lyh
 * @method :post
 * @time   :2023/9/6 14:40
 */

namespace App\Http\Logic\Aside\Project;

use App\Http\Logic\Aside\BaseLogic;
use App\Models\Project\KeywordPrefix;

class KeywordPrefixLogic extends BaseLogic
{
    public function __construct()
    {
        parent::__construct();
        $this->param = $this->requestAll;
        $this->model = new KeywordPrefix();
    }

    /**
     * @remark :保存关键字
     * @name   :prefixSave
     * @author :lyh
     * @method :post
     * @time   :2023/9/6 14:42
     */
    public function prefixSave(){
        $keyword_arr = explode(',',$this->param['keyword']);
        foreach ($keyword_arr as $v){
            $data = [
                'project_id'=>$this->param['project_id'] ?? 0,
                'keyword'=>$v,
                'type'=>$this->param['type'],
            ];
            $prefixInfo = $this->model->read($data);
            if($prefixInfo == false){
                $data['remark'] = $this->param['remark'] ?? '';
                $this->model->add($data);
            }
        }
        return $this->success();
    }

    /**
     * @remark :删除关键字
     * @name   :prefixDel
     * @author :lyh
     * @method :post
     * @time   :2023/12/16 13:48
     */
    public function prefixDel(){
        $ids = $this->param['id'];
        try {
            foreach ($ids as $id){
                $info = $this->model->read(['id'=>$id]);
                if($info !== false){
                    if($info['project_id'] != 0){
                        $this->model->del(['id'=>$id]);
                    }
                }
            }
        }catch (\Exception $e){
            $this->fail('删除失败,请联系管理员');
        }
        return $this->success();
    }
}