BlogLabelLogic.php 3.0 KB
<?php

namespace App\Http\Logic\Bside\Blog;

use App\Enums\Common\Code;
use App\Http\Logic\Bside\BaseLogic;
use App\Models\Blog\Blog as BlogModel;
use App\Models\Blog\BlogLabel as BlogLabelModel;

class BlogLabelLogic extends BaseLogic
{
    public function __construct()
    {
        parent::__construct();

        $this->model = new BlogLabelModel();
        $this->param = $this->requestAll;
    }
    /**
     * @param $v
     * @name :获取分类名称
     * @return void
     * @author :liyuhang
     * @method
     */
    public function get_label_name($v){
        //获取用户已读还是未读
        $label_info = $this->model->list(['id'=>['in',explode(',',trim($v['label_id'],','))]],'id',['name']);
        $str = '';
        foreach ($label_info as $v1){
            $str .= $v1['name'].',';
        }
        $v['label_name'] = trim($str,',');
        return $this->success($v);
    }
    /**
     * @name :新增标签
     * @return void
     * @author :liyuhang
     * @method
     */
    public function add_blog_label(){
        $condition = [
            'name'=>$this->param['name']
        ];
        //查看当前分类名称是否存在
        $info = $this->model->read($condition);
        if($info !== false){
            $this->fail('当前标签名称已存在');
        }
        $this->param['create_id'] = $this->user['id'];
        $this->param['Operator_id'] = $this->user['id'];
        $this->param['project_id'] = $this->user['project_id'];
        $rs = $this->model->add($this->param);
        if($rs ===  false){
            $this->fail('error');
        }
        return $this->success();
    }

    /**
     * @name :编辑标签
     * @return void
     * @author :liyuhang
     * @method
     */
    public function edit_blog_label(){
        $condition = [
            'id'=>['!=',$this->param['id']],
            'name'=>$this->param['name']
        ];
        //查看当前分类名称是否存在
        $info = $this->model->read($condition);
        if($info !== false){
            $this->fail('当前标签名称已存在');
        }
        $this->param['operator_id'] = $this->user['id'];
        $rs = $this->model->edit($this->param,['id'=>$this->param['id']]);
        //TODO::路由映射
        if($rs ===  false){
            $this->fail('error');
        }
        return $this->success();
    }

    /**
     * @name :删除标签
     * @return array
     * @author :liyuhang
     * @method
     */
    public function del_blog_label(){
        foreach ($this->param['id'] as $v){
            //查看当前分内下是否有博客
            $blogModel = new BlogModel();
            $rs = $blogModel->read(['label_id'=>$v],['id']);
            if($rs !== false){
                $this->response('当前标签拥有博客,不允许删除');
            }
        }
        $this->param['id'] = ['in',$this->param['id']];
        $rs = $this->model->del($this->param);
        if($rs === false){
            $this->fail('error');
        }
        return $this->success();
    }
}