<?php
/**
 * App会员中心控制器
 * @Copyright (C) 2016 汉潮 All rights reserved.
 * @License http://www.hanchao9999.com
 * @Author xiaoli <xiaoli@1094186793.com>
 */

namespace Pad\Controller;
use Common\Controller\HanchaoController;
class UCenterController extends BaseController {
    public function _initialize(){
        parent::_initialize ();
        $param=I('param.');
        if($param['is_root']==1){$this->checkrootauth();}
        else{$this->checkshopauth();}
    }

	/**
	 * 我的首页
	 */
	public function index(){
        $param=I('get.');$return=array();$return['status']=1;
        $shops_info=D('App/ShopLogin')->get_shops_info($param);
        if($shops_info['status']==1) {
            $return['data']['name'] = $shops_info['data']['name'];
            $return['data']['thumb'] = $shops_info['data']['thumb'];
        }else{
            $return['data']['name'] = $shops_info['msg'];
        }
        if($param['is_root']==1){
            $account_info=$this->checkrootauth();
            $return['data']['account_name']=$account_info['username'];
        } else{
            $account_info=$this->checkshopauth();
            $return['data']['account_name']=$account_info['login_name'];
        }
        //经营类目
        if(intval($param['appid'])>0) {
            $return['data']['category'] = idtoname($param['appid'], 'SiteInfo', 'type_name', 'site_id', false);
        }
        $params=array(
            'action'=>'get_member_extension',
            'signtype'=>'sha1',
            'appid'=>C('appid'),//站点ID
            'timestamp'=>NOW_TIME,//时间戳
            'uid'=>$param['mid'],//密码
        );
        ksort($params);$key=C('SAAS_APPSECRET');
        $params['sign']= sha1(format_array2http($params).$key);
        $return['data']['sign']=$params['sign'];
        $return['data']['timestamp']=NOW_TIME;
        $return['data']['key']=$params;
        $this->ajaxReturn($return);
	}

    /**
     * 修改密码 主站账号/子站账号
     */
    public function set_password(){
        $return = array('status'=>3,'msg'=>'参数错误');
        $param=I('post.');
        $is_root=$param['is_root'];
        if($is_root==1){$return=D('App/ShopLogin')->resetpwd($param);}
        else{//子站
            $return=D('App/ShopLogin')->set_pwd($param);//管理员
        }
        $this->ajaxReturn($return);
    }
}