BlogController.php 5.0 KB
<?php

namespace App\Http\Controllers\Bside\Blog;

use App\Enums\Common\Code;
use App\Http\Controllers\Bside\BaseController;
use App\Http\Logic\Bside\Blog\BlogCategoryLogic;
use App\Http\Logic\Bside\Blog\BlogLabelLogic;
use App\Http\Logic\Bside\Blog\BlogLogic;
use App\Http\Requests\Bside\Blog\BlogRequest;
use App\Models\Blog\Blog as BlogModel;
use App\Models\RouteMap;

class BlogController extends BaseController
{
    //通知别名
    public $updateModelView = 'blog';

    /**
     * @name :博客列表
     * @author :liyuhang
     * @method
     */
    public function lists(BlogModel $blogModel,BlogCategoryLogic $blogCategoryLogic,BlogLabelLogic $blogLabelLogic){
        //搜索条件
        $this->map['project_id'] = $this->user['project_id'];
        $lists = $blogModel->lists($this->map,$this->page,$this->row,$this->order,
            ['id','category_id','operator_id','status','created_at','label_id','image','updated_at','name','sort','url']);
        if(!empty($lists['list'])){
            foreach ($lists['list'] as $k => $v){
                //获取分类名称
                $v = $blogCategoryLogic->get_category_name($v);
                //获取标签名称
                $v = $blogLabelLogic->get_label_name($v);
                $v['route'] = RouteMap::getRoute(RouteMap::SOURCE_BLOG, $v['id'], $this->user['project_id']);
                $v['url'] = $this->getProjectDomain() . $v['route'];
                $lists['list'][$k] = $v;
            }
        }
        $this->response('success',Code::SUCCESS,$lists);
    }

    /**
     * @remark :根据状态数量
     * @name   :getStatusNumber
     * @author :lyh
     * @method :post
     * @time   :2023/6/19 9:39
     */
    public function getStatusNumber(BlogLogic $blogLogic){
        $data = $blogLogic->getStatusNumber();
        $this->response('success',Code::SUCCESS,$data);
    }

    /**
     * @name :获取分页列表
     * @throws \App\Exceptions\BsideGlobalException
     * @author :liyuhang
     * @method
     */
    public function get_category_list(BlogLogic $blogLogic){
        $list = $blogLogic->blog_get_category_list();
        $this->response('success',Code::SUCCESS,$list);
    }

    /**
     * @name :获取当前博客详情
     * @author :liyuhang
     * @method
     */
    public function info(BlogLogic $blogLogic){
        $this->request->validate([
            'id'=>['required']
        ],[
            'id.required' => 'ID不能为空'
        ]);
        $info = $blogLogic->blog_info();
        $info['route'] = RouteMap::getRoute(RouteMap::SOURCE_BLOG, $info['id'], $this->user['project_id']);
        $info['url'] = $this->getProjectDomain() . $info['route'];
        $this->response('success',Code::SUCCESS,$info);
    }

    /**
     * @name :添加博客
     * @author :liyuhang
     * @method
     */
    public function add(BlogRequest $request,BlogLogic $blogLogic){
        $request->validated();
        $blogLogic->blog_add();
        //TODO::通知网站更新
        $this->projectUrlNotify($this->updateModelView);
        $this->response('success');
    }

    /**
     * @name :编辑博客
     * @author :liyuhang
     * @method
     */
    public function edit(BlogRequest $request,BlogLogic $blogLogic){
        $request->validate([
            'id'=>['required']
        ],[
            'id.required' => 'ID不能为空'
        ]);
        $blogLogic->blog_edit();
        //TODO::通知网站更新
        $this->projectUrlNotify($this->updateModelView);
        $this->response('success');
    }

    /**
     * @name :编辑新闻seo
     * @author :liyuhang
     * @method
     */
    public function edit_seo(BlogLogic $blogLogic){
        $this->request->validate([
            'id'=>['required'],
            'seo_title'=>['required'],
            'seo_description'=>['required'],
            'seo_keywords'=>['required'],
        ],[
            'id.required' => 'ID不能为空',
            'seo_title.required' => 'seo_title不能为空',
            'seo_description.required' => 'seo_description不能为空',
            'seo_keywords.required' => 'seo_description不能为空',
        ]);
        $blogLogic->edit_seo();
        $this->response('success');
    }

    /**
     * @name :编辑博客状态/排序
     * @author :liyuhang
     * @method
     */
    public function status(BlogLogic $blogLogic){
        $this->request->validate([
            'id'=>['required','array'],
        ],[
            'id.required' => 'ID不能为空',
            'id.array' => 'ID为数组',
        ]);
        $blogLogic->blog_status();
        //TODO::写入日志
        $this->response('success');
    }

    /**
     * @name :删除博客(批量逻辑删除)
     * @author :liyuhang
     * @method
     */
    public function del(BlogLogic $blogLogic){
        $this->request->validate([
            'id'=>['required','array'],
        ],[
            'id.required' => 'ID不能为空',
            'id.array' => 'ID为数组',
        ]);
        $blogLogic->blog_del();
        $this->response('success');
    }

}