<?php
/**
 * 消息中心
 * @Copyright (C) 2016 汉潮 All rights reserved.
 * @License http://www.hanchao9999.com
 * @Author lss <lss@qq.com>
 */

namespace Shop\Controller;
use Think\Controller;
class MessageController extends BaseController {
	public function _initialize()
    {
        parent::_initialize();
        $shops_info=session('shops_info');
        if(empty($shops_info['id']))$this->error('身份过期，请重新登录',U('Shop/Register/shop_login'));
		$this->mendian();
    }
    //客服设置
    public function index(){
        $where['id']=MID;
        $shopinfo=M('Shops')->where($where)->field('name,qq')->find();
        if(IS_POST){
            $postdata=I('post.');
            if(empty($postdata['qq'])){
                $this->error('请输入客服QQ');
            }
            if(empty($postdata['type']) || $postdata['type']==0){
                $this->error('请选择客服工具');
            }
            if(!preg_match('/^\d{5,10}$/',$postdata['qq'])){
                $this->error('请输入正确的QQ号');
            }
            $savedata['qq']=$postdata['qq'];
            $savedata['updatetime']=NOW_TIME;
            $result=M('Shops')->where($where)->save($savedata);
            if($result){
                $this->success('设置成功');
            }else{
                $this->error('设置失败');
            }
        }else{
            $tabid=I('param.tabid');
            if(!empty($tabid)){
                $this->display($tabid);
            }else{
                $this->assign('shopinfo',$shopinfo);
                $this->display();
            }   
        }
    }
    //系统消息
    public function system_message(){
	$tabid=I('param.tabid');
        $this->assign('title_ass','消息');
             $shopinfo=session('shops_info');
	$map['touid']=$shopinfo['id'];
        	$map['type']=2;
        	$info=page_list('Message',$map,'status asc,addtime desc',true);
        	$this->assign($info);
	if(!empty($tabid)) $this->display($tabid);
	else $this->display();
    }
    //平台消息管理
    public function min_view(){
    	$id=I('id');
    	if($id){
    		$where['id']=$id;
    		$info=M('Message')->where($where)->field('title,content')->find();
    		$this->assign($info);
    	}
	$this->display();
    }
}
?>