ActivityNewsModel.php 3.8 KB
<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/12/31
 * Time: 13:47
 */

namespace api\index\model;


use think\Model;

class ActivityNewsModel extends Model
{
    /**
     * thumbnail 自动转化
     * @param $value
     * @return array
     */
    public function getThumbnailAttr($value)
    {
        return cmf_get_image_url($value);
    }
    /**
     * time 自动转化
     * @param $value
     * @return array
     */
    public function getTimeAttr($value)
    {
        return date('Y-m-d',$value);
    }
    /**
     * content 自动转化
     * @param $value
     * @return array
     */
    public function getContentAttr($value)
    {
        return cmf_replace_content_file_url(htmlspecialchars_decode($value));
    }

    public function selectData($page,$pageNum){
        $order = "create_time desc";
        $where['a.delete_time'] = ['eq',0];
        $where['is_up'] = ['eq',1];
        $data = $this->alias('a')
            ->field('a.*,p.province_name,act.type_name')
            ->join('activity_type act','act.id=a.activity_type','LEFT')
            ->join('position_province p','p.id=a.position_id','LEFT')
            ->where($where)
            ->limit(($page * $pageNum),$pageNum)
            ->order($order)
            ->select()
            ->toArray();
        return $data;
    }
    public function selectCityData($city_id){
        $order = "create_time desc";
        $where['a.delete_time'] = ['eq',0];
        if (!empty($city_id)){
            $where['a.position_id'] = $city_id;
        }
        $data = $this->alias('a')
            ->field('a.*,p.province_name,act.type_name')
            ->join('activity_type act','act.id=a.activity_type','LEFT')
            ->join('position_province p','p.id=a.position_id','LEFT')
            ->where($where)
            ->order($order)
            ->select()
            ->toArray();
        return $data;
    }
 public function selectTypeData($type_id){
        $order = "create_time desc";
        $where['a.delete_time'] = ['eq',0];
        if (!empty($type_id)){
            $where['a.activity_type'] = $type_id;
        }
        $data = $this->alias('a')
            ->field('a.*,p.province_name,act.type_name')
            ->join('activity_type act','act.id=a.activity_type','LEFT')
            ->join('position_province p','p.id=a.position_id','LEFT')
            ->where($where)
            ->order($order)
            ->select()
            ->toArray();
        return $data;
    }

    public function findData($where){
        $data = $this->where($where)->find();
        return $data;
    }

    /**
     * 即将开始的活动
     * @param $page
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function beginAtOnce($page,$pageNum){
        $now=time();
        $map['a.create_time']=['<',$now];
        $map['a.delete_time'] = ['eq',0];
        if ($page<=0){
            $data=$this->alias('a')
                ->field('a.*,p.province_name,act.type_name')
                ->join('activity_type act','act.id=a.activity_type','LEFT')
                ->join('position_province p','p.id=a.position_id','LEFT')
                ->where($map)
                ->order("create_time desc")
                ->limit('2')
                ->select()->toArray();
        }else{
            $data=$this->alias('a')
                ->field('a.*,p.province_name,act.type_name')
                ->join('activity_type act','act.id=a.activity_type','LEFT')
                ->join('position_province p','p.id=a.position_id','LEFT')
                ->where($map)
                ->order("create_time desc")
                ->limit(($page * $pageNum),$pageNum)
                ->select()->toArray();
        }
        return $data;
    }

}