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

namespace App\Controller;
use Think\Controller;
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('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);
        }
        $this->ajaxReturn($return);
	}

    /**
     * 获取账号
     */
    public function get_account(){
        $param=I('get.');$return=array();$return['status']=1;
        if($param['is_root']==1){
            $account_info=$this->checkrootauth();
            $return['data']['account_name']=$account_info['username'];
            $return['data']['mobile']=$account_info['mobile'];
        } else{
            $account_info=$this->checkshopauth();
            $return['data']['account_name']=$account_info['login_name'];
            $return['data']['mobile']=$account_info['mobile'];
        }
        $this->ajaxReturn($return);
    }

    /**
     * 修改账号 主站账号/子站账号
     */
    public function set_account(){
        $return = array('status'=>3,'msg'=>'参数错误');
        $param=I('post.');
        $is_root=$param['is_root'];
        if($is_root==1){$return=D('ShopLogin')->resetacc($param);}
        else{//子站
            $return=D('ShopLogin')->set_acc($param);
        }
        $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('ShopLogin')->resetpwd($param);}
        else{//子站
            $return=D('ShopLogin')->set_pwd($param);//管理员
        }
        $this->ajaxReturn($return);
    }

    /**
     * 获取门店某些字段
     */
    public function get_shops_info(){
        $param=I('get.');
        $return=D('ShopLogin')->get_shops_info($param);
        $this->ajaxReturn($return);
    }

    /**
     * 修改门店某个字段
     */
    public function set_shops_item(){
        $param=I('post.');
        $return=D('ShopLogin')->set_shops_item($param);
        $this->ajaxReturn($return);
    }

    /**
     * 获取台卡收款提示设置
     */
    public function get_cashier_info(){
        $param=I('get.');
        $return=D('ShopLogin')->get_shops_info($param);
        $cashier_tone=C('CASHIER_TONE');
        if(!empty($cashier_tone)){
            $cashier_tone=explode(',',$cashier_tone);
            $tone_config=array();
            foreach($cashier_tone as $val){
                $toneconfig=explode(':',$val);
                $tone_config[$toneconfig[0]]=$toneconfig[1];
            }
            $return['data']['tone_config']=$tone_config;
        }
        $this->ajaxReturn($return);
    }
}