<?php
/**
 * 商铺动态管理
 * @Copyright (C) 2016 汉潮 All rights reserved.
 * @License http://www.hanchao9999.com
 * @Author xiaogg <xiaogg@sina.cn>
 */

namespace Admin\Controller;
class ShopsArticleController extends BaseController
{
    public function _initialize()
    {
        parent::_initialize();
    }

    public function index()
    {
        $name = CONTROLLER_NAME;
        $map = array();
        $keyword = I('keyword');
        $shopsid = I('get.shopsid');
        if (!empty($shopsid)) {
            $map['shop_id'] = $shopsid;
            $this->assign('id',$shopsid);
        }
        $order='updatetime desc,id desc,sort desc';
        if (!empty($keyword)) $map['title'] = array('like', "%" . $keyword . "%");
        $list = $this->lists($name, $map,$order);
        $this->assign('list', $list);
        $this->display();
    }
    public function update(){
        $data=I('post.');
        $savedata['updatetime']=$data['updatetime'];
        $savedata['shop_id']=$data['shop_id'];
        $savedata['title']=$data['title'];
        $savedata['content']=$data['content'];
        $savedata['status']=$data['status'];
        $where['id']=$data['id'];
        $res=M('ShopsArticle')->where($where)->save($savedata);
        if($res){
            $this->success('操作成功',U('ShopsArticle/index',array('shopsid'=>$data['shop_id'])));
        }else{
            $this->error('操作失败',U('ShopsArticle/index',array('shopsid'=>$data['shop_id'])));
        }
    }
}