<?php


namespace wechat\server;

use Yii;
use common\models\News;
use common\models\CategoryNews;
use common\models\PushmNews;
use common\models\House;

class NewsServer
{

        /*
         * 新闻资讯首页-推送部分
         * */
        public function Pushinfo($type)
        {
            $pushModel = new PushmNews();
            $pushModel->type = $type;
            switch ($type)
            {
                case 1:
                    $limit = 3;  //
                    break;
                case 2:
                    $limit = 3;
                    break;
                case 3:
                    $limit = 2;
                    break;
                default:
                    return false;
                    break;
            }
            $arr = $pushModel->Homegetlist($limit);
            return   $arr;
        }

        /*
         * 资讯首页- 资讯栏目 and 资讯栏目所属资讯
         * */
        public function ColumnInfo()
        {
            $model = new CategoryNews();
            return $model->getList([],['news_name','id','img']);
        }

//        public func

        /*
         * 点击量 -- 热文
         * */
        public function clickList($num)
        {
                $model = new News();
                return  $model->Clicks($num);
        }


        /*
         * 资讯详情
         * */
        public function NewsDetails($input)
        {
            $model = new News();
            if(is_numeric($input['nid']))
            {
               $info = $model->FindById($input['nid']);
               if(!empty($info))
               {
                   //$ip = new IpServer();
                   //$ipaddress = $ip->add($input['nid']);
                   //if($ipaddress === true)
                   //{
                       $info->clicks =  ++$info->clicks;
                       $info->true_click =  ++$info->true_click;
                       $info->save(false);
                    //}
                   return $info;
               }
            }
        }

        /*
         * 相关资讯
         * */
        public function Relevant($category)
        {
            $model = new News();
            $model->category = $category;
            return $model->Clicks(4);
        }

        /*
         * 根据区域,随机推荐楼盘
         * */
        public function NewsCityHouse($city)
        {
            $model = new House();
            $model->city = $city;
			$model->is_push=2;
            return $model->ispush(3);
        }


}