<?php
/**
 * 店铺申请
 * @Copyright (C) 2016 汉潮 All rights reserved.
 * @License http://www.hanchao9999.com
 * @Author zhaoh <zhao@qq.com>
 */

namespace Shop\Controller;
use Think\Controller;
class RegisterController extends BaseController {
	public function _initialize(){
		parent :: _initialize();
		$map['pid']=0;
		$map['status']=1;
		$this->cate_id=M('goods_category')->where($map)->field('id,name')->select();
		$this->assign('cate_id',$this->cate_id);
		$this->is_login=session('shops_info');
	}
	public function beforeindex(){
		$map=array();
		$map['catid']=2;
		$map['status']=1;
		$map['is_tuijian']=1;
		$list=M('Article')->where($map)->limit(4)->select();
		if($list){
			foreach ($list as $key => $value) {
				$content_format=strip_tags(htmlspecialchars($value['content']));
				$list[$key]['content']=h(substr_replace($content_format,'...',20));
				$list[$key]['bid']=$key+1;
			}
		}
		$this->assign('list',$list);
		$this->display();
	}
	/**
     * 店铺申请页面
     */
    public function index(){
    	$param=I('param.');
		if($this->is_login)$this->redirect('Index/index');//已登录
		$member_info=session('member_info');
		$u_map['uid']=$member_info['id'];
		$u_map['status']=1;
		// $is_shop=M('Shops')->where($u_map)->count();
		// if($is_shop){$this->error('您已是店铺，请登录',U('Register/shop_login'));}
		$register_config=json_decode(C('SHOP_REGISTER_CONFIG'),true);
		$this->assign('register_config',$register_config);
		if($member_info){//已提交未审核
			$map['uid']=$member_info['id'];
			// $map['publish_wait']=0;
			$shops_info=M('ShopsSubmit')->where($map)->find();
			$is_cate=explode(',',$shops_info['cate_ids']);
			$cate_ids=$this->cate_id;
			if($is_cate && $cate_ids){
				foreach($cate_ids as $k=>$v){
					$cate_ids[$k]['on']=in_array($v['id'],$is_cate);
				}
				$this->assign('cate_id',$cate_ids);
			}
			$this->assign('memberinfo',$member_info);
			$this->assign($shops_info);
		}
		$this->assign($param);
        $this->assign('tplseo_title','店铺申请_'.C('WEB_SITE_TITLE'));
        $this->display();
    }
	/**
     * 店铺申请
     */
	public function add_shop(){
		$postdata=I('param.');
		$result=D('Common/ShopLogin')->register($postdata);
		// if($result['status'])$result['url']=U('Member/index/index');
		$this->ajaxReturn($result);
	}
	public function content(){
		if($this->is_login)$this->redirect('Index/index');//已登录
		$art_id=I('art_id');if(empty($art_id))$this->error('参数错误');
		$info=M('Article')->where('id='.$art_id)->field(true)->find();
		$this->assign($info);
		$this->assign('art_id',$art_id);
		$this->assign('tplseo_title','入驻申请_'.C('WEB_SITE_TITLE'));
        $this->display();
    }
	/**
     * 店铺登录页面
     */
	public function shop_login(){
		if($this->is_login){
            $this->redirect('Index/index');
        }else{
            $this->redirect('Cashier/login');
        }//已登录

        $this->assign('tplseo_title','门店登录_'.C('WEB_SITE_TITLE'));
		$this->display();
	}
	/**
     * 店铺登录
     */
	public function dologin(){
		$data=I('post.');
        $return=D("Common/ShopLogin")->check_login($data);
        $this->ajaxReturn($return);
	}
	/**
     * 退出登录
     */
	public function log_out(){
        $return=D("Common/ShopLogin")->logout();
        if($return['status']==1){
            $this->success($return['info'],$return['url']);
        }else{
            $this->error($return['info'],$return['url']);
        }
	}
	/**
     * 修改密码
     */
	public function modify_paw(){
        $data=I('post.');
		if($data){
			$return=D("Common/ShopLogin")->resetpwd($data);
			if($return['status']==1){$return['url']=U('Shop/Register/shop_login');}
		}
        $this->ajaxReturn($return);
	}
	/**
     * 找回密码页面
     */
	public function getpassword(){
        if($this->is_login)$this->redirect('Index/index');//已登录
        $this->assign('tplseo_title','找回密码_'.C('WEB_SITE_TITLE'));
		$this->display();
	}
	/**
     * 找回密码获取店铺信息
     */
	public function get_shop(){
		$data=I('post.');
        $return=D("Common/ShopLogin")->get_shop($data);
        $this->ajaxReturn($return);
	}
	/**
     * 找回密码
     */
	public function getpwd(){
		$data=I('post.');
        $return=D("Common/ShopLogin")->getpwd($data);
		if($return['status']==1){$return['url']=U('Shop/Register/shop_login');}
        $this->ajaxReturn($return);
	}
}
?>