<?php

namespace wechat\controllers;

use wechat\base\CommonController;
use Yii;
use wechat\base\Help;
use common\models\NewsRenovation;
use common\models\NewsRenovationcontent;
use yii\data\Pagination;

class PjController extends CommonController
{
        public function actionHome()
        {
            return $this->render('home');
        }

        public function actionHomeform()
        {
            $model = new NewsRenovation();
            $rows = $model->MgetList(Yii::$app->request->get());
            if(!empty($rows))
            {
                    foreach ($rows as &$val)
                    {
                        $val['img'] = Yii::$app->params['httpImg']['host'].Yii::$app->params['httpImg']['pj'].$val['img'];
                        isset(Yii::$app->params['DecorationStyle'][$val['type']]) ? $val['type'] = Yii::$app->params['DecorationStyle'][$val['type']] : '';
                    }
                    return Help::JsonCode(Help::SUCCESS,'成功',$rows);
            }
                    return Help::JsonCode(Help::ERROR,'失败');
        }

        public function actionDetails()
        {
            $model = new NewsRenovation();
            //品鉴相关信息
            $f = new NewsRenovationcontent();
            $f->nid = Yii::$app->request->get('pid');
            $col = $f->MLabel();
            //记录查看次数
            $iprecord = new \common\models\AllclickRecord();
            $arr['id'] = Yii::$app->request->get('pid');
            $arr['ip'] = Yii::$app->request->userIP;;
            $arr['type'] = 1;
            $re = $iprecord->RecordQuery($arr);
            if(empty($re)){
                if($iprecord->addRecord($arr))
                {
                    $model->Clickadd($model->id);
                }
            }
            return $this->render('details',['model'=>$col]);
        }


}