News.php 3.19 KB
<?php
/**
 * tpshop
 * ============================================================================
 * 版权所有 2015-2027 深圳搜豹网络科技有限公司,并保留所有权利。
 * 网站地址: http://www.tp-shop.cn
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
 * 不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * Author: 当燃      
 * Date: 2015-09-09
 */
namespace app\admin\controller;

use think\Page;
use app\admin\logic\ArticleCatLogic;
use think\Db;
use qcloudcos\Conf;
use qcloudcos\Myqcloudcos;
class News extends Base {


    public function _initialize()
    {
        parent::_initialize();

    }


    public function newslist(){
        $Article =  M('news');
        $pagenum=20;//每页显示多少条

        $list = array();
        $p = input('p/d', 1);

        $size = input('size/d', $pagenum);
        $where = array();
        /*--添加门店ID--*/

        $keywords = trim(urldecode(urldecode(I('keywords'))));
        $keywords && $where['title'] = array('like', '%' . $keywords . '%');

        $res = $Article->where($where)->order('add_time desc')->page("$p,$size")->select();
        $count = $Article->where($where)->count();// 查询满足要求的总记录数
        $pager = new Page($count,$size);// 实例化分页类 传入总记录数和每页显示的记录数
        $page = $pager->show();//分页显示输出


        $this->assign('keywords',$keywords);
        $this->assign('list',$res);// 赋值数据集
        $this->assign('page',$page);// 赋值分页输出
        $this->assign('pager',$pager);
        $this->assign('store_id',getAdmStoId());

        $this->assign('pagenum',$pagenum);
        $this->assign('oldurl',urlencode(curPageURL()));
//        upload_ylp_log('文章列表');
        return $this->fetch('',getAdmStoId());
    }
    
    public function newsdetail(){


        $newsid = I('newsid/d');

        if($newsid){
           $info = D('news')->where('article_id', $newsid)->find();
           if ($info)
           {
               M('news')->where('article_id',$newsid)->setInc('click',1);
               $readnews=M('news_readlist')->where(array('store_id'=>getAdmStoId(),'admin_id'=>getAdminId(),'news_id'=>$info['article_id']))->find();
               if (empty($readnews)) {
                   $data['store_id']=getAdmStoId();
                   $data['admin_id']=getAdminId();
                   $data['news_id']=$info['article_id'];
                   $data['add_time']=time();
                   M('news_readlist')->save($data);
               }

           }

        }

        $this->assign('info',$info);

        return $this->fetch('',getAdmStoId());
    }

    public function readnews(){
        $newsid = I('newsid/d');
        if($newsid)
        {
            $data['store_id']=getAdmStoId();
            $data['admin_id']=getAdminId();
            $data['news_id']=$newsid;
            $data['add_time']=time();
            M('news_readlist')->save($data);
            return "1";
        }
    }


}