GeoArticleLogic.php 2.9 KB
<?php
/**
 * @remark :
 * @name   :GeoArticleLogic.php
 * @author :lyh
 * @method :post
 * @time   :2025/7/14 16:21
 */

namespace App\Http\Logic\Aside\Geo;

use App\Http\Logic\Aside\BaseLogic;
use App\Models\Geo\GeoArticle;

/**
 * @remark :GEO文章列表
 * @name   :GeoArticleLogic
 * @author :lyh
 * @method :post
 * @time   :2025/7/14 16:22
 */
class GeoArticleLogic extends BaseLogic
{
    public function __construct()
    {
        parent::__construct();
        $this->param = $this->requestAll;
        $this->model = new GeoArticle();
    }

    /**
     * @remark :列表数据
     * @name   :getArticleList
     * @author :lyh
     * @method :post
     * @time   :2025/7/14 16:24
     */
    public function getArticleList($map = [],$page = 1,$row = 20,$order = 'id'){
        if(isset($map['filename']) && !empty($map['filename'])){
            $map['filename'] = ['like','%'.$map['filename'].'%'];
        }
        $filed = ['*'];
        $lists = $this->model->lists($map,$page,$row,$order,$filed);
        if(!empty($lists) && !empty($lists['list'])){
            foreach ($lists['list'] as $key => $item){
                $item['download_url'] = url('a/download_files?path='.$item['url']);
                $item['url'] = getFileUrl($item['url']);
                $lists['list'][$key] = $item;
            }
        }
        return $this->success($lists);
    }

    /**
     * @remark :获取数据详情
     * @name   :getArticleInfo
     * @author :lyh
     * @method :post
     * @time   :2025/7/14 16:26
     */
    public function getArticleInfo(){
        $info = $this->model->read($this->param);
        if($info === false){
            $this->fail('当前数据不存在或者已被删除');
        }
        $info['url'] = getFileUrl($info['url']);
        return $this->success($info);
    }

    /**
     * @remark :保存数据
     * @name   :saveArticle
     * @author :lyh
     * @method :post
     * @time   :2025/7/14 16:26
     */
    public function saveArticle(){
        try {
            if(!empty($this->param['data'])){
                $data = [];
                foreach ($this->param['data'] as $item){
                   $data[] = [
                       'filename' => $item['filename'],
                       'url'=> $item['url'],
                       'project_id'=>$this->param['project_id']
                   ];
                }
                $this->model->insertAll($data);
            }
        }catch (\Exception $e){
            $this->fail('保存失败,请联系管理员');
        }
        return $this->success();
    }

    /**
     * @remark :删除数据
     * @name   :delArticle
     * @author :lyh
     * @method :post
     * @time   :2025/7/14 16:28
     */
    public function delArticle(){
        try {
            $this->model->del($this->param);
        }catch (\Exception $e){
            $this->fail('删除失败,请联系管理员.');
        }
        return $this->success();
    }
}