ShowModel.php 2.0 KB
<?php
/**
 * Author : xiaojie
 * DateTime: 2018/11/29 10:06
 */
namespace app\portal\model;

use think\Model;
use traits\model\SoftDelete;

class ShowModel extends Model
{
    protected $autoWriteTimestamp = true;

    protected $type = [
        'files' => 'array',
    ];

    /**
     * content 自动转化
     * @param $value
     * @return string
     */
    public function getContentAttr($value){

        return cmf_replace_content_file_url(htmlspecialchars_decode($value));
    }

    /**
     * 获取列表信息
     *  ->paginate(10,false,['query'=>$page_arr])
     * @param $cate_id 分类id
     * @param string $keyword 关键词查询
     * @param string $order 排序
     * @return \think\Paginator
     */
    public function getList($cate_id,$keyword='' ,$page_num = '4',$order = 'id DESC')
    {
        if($keyword){
            $map['title'] = ['like',"%$keyword%"];
        }

        if(is_array($cate_id)){
            $map['cate_id'] = ['in',$cate_id];
        }else{
            $map['cate_id'] = $cate_id;
        }

        $list = $this
            ->where($map)
            ->order($order)
            ->paginate($page_num);
        return $list;
    }

    /**
     * 获取移动端的列表数据
     * @param $cate_id
     * @param string $page_num
     * @param string $order
     * @return \think\Paginator
     */
    public function getMobileList($cate_id,$page,$page_num = '10',$order = 'id DESC')
    {
        if(is_array($cate_id)){
            $map['cate_id'] = ['in',$cate_id];
        }else{
            $map['cate_id'] = $cate_id;
        }

        $list = $this
            ->where($map)
            ->order($order)
            ->limit($page_num)
            ->page($page)
            ->select();
        return $list;
    }

    /**
     * 获取详情
     * @param $id
     * @return array|false|\PDOStatement|string|Model
     */
    public function getDetail($id)
    {
        $info = $this->where('id',$id)->find();
        return $info;
    }
}