<?php
/**
*宜配会员中心
*/
class userAction extends baseAction
{
	/**
	  * @method 会员登录
	  * @http  POST
	  * @param  token              string [必填] 调用接口凭证 (post|get)
	  * @param  type               string [必填] 登录类型password | token | weixin | worker商城职员 | mobile手机验证码 | unitag
	  * @param  data               array  [必填] password['name'=>'', 'password'=>'123456', 'ip'=>'', 'from'=>'']
											     token['token'=>'c291bDEyQDZmNDczMDA4MzQyYTI2NDZlYjcwODRhMGZhMzFjYTlkQDE0OTMzNTE1OTY', 'ip'=>'', 'from'=>'']
											     weixin['unionid'=>'ok4PpvzZiYdMfaJzC_cMdsrVman4', 'openid'=>'', 'ip'=>'', 'from'=>''] 可以先只提供openid，当登录失败时使用unionid(最好同时提供openid，方便下次使用openid登录)
											     qq['unionid'=>'ok4PpvzZiYdMfaJzC_cMdsrVman4', 'openid'=>'', 'ip'=>'', 'from'=>''] 可以先只提供openid，当登录失败时使用unionid(最好同时提供openid，方便下次使用openid登录)
												 mobile['mobile'=>'1355', 'code'=>32154, 'from'=>'必填']
												 worker['name'=>'', 'password'=>'123456', 'ip'=>'', 'from'=>'']
												 unitag['unitag'=>'ok4PpvzZiYdMfaJzC_cMdsrVman4']
												 apple['unionid'=>'apple userid', 'ip'=>'', 'from'=>'']

												from来源值：YP(宜配网)|YPAPP|YPGZG|YPIM|YPYPC|PJD(跑街的)|PJDAPP|PJDGZH|PJDSGZH(商城店铺公众号)|PJL(跑街令)|CRM|BMTSR|CLIENT(客户网)
	  * @param  lang               string [必填] 语言版本 cn en
	  * @author soul
	  * @copyright 2017/4/13
	  * @return 
			{"status":true,"data":{"u_id":"149894","u_name":"soul12","u_pay_password":null,"u_nickname":"soul12","u_real_name":"欧昌宇","u_yiparts":"N","u_b2c_worker":"N","u_b2c_shopid":"149894","u_type":"2","u_ul_id":"4","u_email":"472211059@qq.com","u_emil_check":"1","u_mobile":"13434580358","u_mobile_check":"Y","u_weixin_unionid":"ok4Ppv4IBlRwm5pzM45YU6TamVNA","u_weixin_info":{"openid":"obxtFwBqEAQFD8xyJ1QroR7mqk0I","nickname":"蓝宇战车","sex":0,"language":"zh_CN","city":"","province":"","country":"","headimgurl":"http:\/\/thirdwx.qlogo.cn\/mmopen\/vi_32\/I3mx3eDkoPhsaib0dM62bLRhcHOibGS2LQEbxOJ7E6FN3HgySf3pu8gbIIoicIexn8LaNOmb2bOxslkssYsia5ltqA\/132","privilege":[],"unionid":"ok4Ppv4IBlRwm5pzM45YU6TamVNA"},"u_weixin_bd":"Y","u_gzh_bd":"Y","u_integral":"37781","u_register_time":"1392825600","u_login_count":"3155","u_logo":"Logo\/1009\/100\/ccad6358aba98691.jpg","u_growth":"1160","u_from":null,"ui_period":"2022-04-22 23:59:59","utag":"c291bDEyQDFjNzU3ZjIyODMxYjk4ZmM1M2QzY2E1N2FmNWNjYzZj", "unitag": "用户标识，30天有效期"},"code":""}
			{"status":false,"data":"错误代码","code":"code_error"}
			错误代码 
			error:账户名与密码不匹配
			no_email_check:邮箱未验证，请先验证
			token_error: token失效或者不存在
			weixin_no:微信未绑定
	  */
	function login()
	{
		$YpwUser = new YpwUser();
		$Res = $YpwUser->Login($_POST['type'], $_POST['data'], $_POST['lang']);
		echo json_encode($Res);
	}



	/**
	  * @method 会员注册
	  * @http  POST
	  * @param  token              string [必填] 调用接口凭证 (post|get)
	  * @param  data               array  [必填] ['u_name', u_password, u_email, u_mobile, mobile_code, u_from]
												  字段u_real_name, u_nickname, ui_company, ui_country选填，其它为必填
												  //中文版手机必填(用户名可为空)，其它语言版本邮箱必填
												  u_password提供明文密码
	  * @param  lang               string [必填] 语言版本 cn en
	  * @author soul
	  * @copyright 2017/4/13
	  * @return 
	  {"status":true,"data": ID,"code":""}
	  {"status":false,"data":"失败原因","code":"错误代码"}
			错误代码:
			name_error:用户名格式不正确
			pass_error:密码长度不正确
			email_error:邮箱格式不正确
			mobile_error:手机不正确
			name_exists:用户名已被注册
			email_exists:email已被注册
	  */
	function register()
	{
		$YpwUser = new YpwUser();
		$Res = $YpwUser->Register($_POST['data'], $_POST['lang']);
		echo json_encode($Res);
	}

	/**
	  * @method 用户数据唯一性，用户名、邮箱、昵称、手机号码....
	  * @http  GET
	  * @param  token              string [必填] 调用接口凭证 (post|get)
	  * @param  uid                int    [选填] 用户ID
	  * @param  filed              string [必填] username email  mobile nickname
	  * @param  val                string [必填] 
	  * @author soul
	  * @copyright 2017/4/13
	  * @return 
	  {"status":true,"data": true|false,"code":""}
	  {"status":false,"data":'失败原因',"code":'error'}
	  */
	function checkUnique()
	{
		$pass = false;
		$val = trim($_GET['val']);
		$uid = (int) $_GET['uid'];
		if($val != '')
		{
			$where = '';
			switch($_GET['filed'])
			{
				case 'username': 
					$where = sprintf(" and u_name='%s'", LibFc::Escape($val));
				break;
				case 'email': 
					$where = sprintf(" and u_emil_check=1 and u_email='%s'", LibFc::Escape($val));
				break;
				case 'mobile': 
					$where = sprintf(" and u_mobile_check='Y' and u_mobile='%s'", LibFc::Escape($val));
				break;
				case 'nickname': 
					$where = sprintf(" and u_nickname='%s'", $Uid, LibFc::Escape($val));
				break;
			}
			if($where != ''){
				$where .= $uid > 0? ' and u_id!='.$uid: '';
				$YpwUser = new YpwUser();
				$res = $YpwUser->GetUser(['u_id'], $where, true);
				if(empty($res['data'])){
					$pass = true;
				}
			}
		}
		echo json_encode(['status'=>true, 'data'=>$pass]);
	}


	/**
	  * @method 修改会员信息
	  * @http  POST
	  * @param  token              string [必填] 调用接口凭证 (post|get)
	  * @param  uid                int    [必填]   用户ID
	  * @param  data               array  [必填] ['u_logo'=>.....]
	  * @author soul
	  * @copyright 2017/4/13
	  * @return 
	  {"status":true,"data": ID,"code":""}
	  {"status":false,"data":'失败原因',"code":'error'}
	  *错误代码 name_error:用户名格式不正确
	            pass_error:密码长度不正确
	            email_error:邮箱格式不正确
	            mobile_error:手机不正确
				name_exists:用户名已被注册
				email_exists:email已被注册
	  */
	function setUser()
	{
		$YpwUser = new YpwUser();
		$Res = $YpwUser->setUser($_POST['uid'], $_POST['data']);
		echo json_encode($Res);
	}


	/**
	  * @method 商城职员添加
	  * @http   POST
	  * @param  token              string [必填] 调用接口凭证 (post|get)
	  * @param  data               array  [必填] [u_name, u_password 提供明文密码, u_b2c_shopid店铺ID]
	  * @author soul
	  * @copyright 2017/4/13
	  * @return 
	  {"status":true,"data": ID,"code":""}
	  {"status":false,"data":'失败原因',"code":'error'}
	  *错误代码 name_error:用户名格式不正确
	            pass_error:密码长度不正确
				name_exists:用户名已被注册
	  */
	function addWorker()
	{
		$YpwUser = new YpwUser();
		$Res = $YpwUser->addWorker($_POST['data']);
		echo json_encode($Res);
	}


	/**
	  * @method 检测支付密码是否正确
	  * @http	post
	  * @param  $uid  用户ID [必填]
	  * @param  $password 密码 [必填]
	  * @author soul
	  * @copyright 2018/8/25
	  * @return 
			成功：['status'=>true, 'data'=>true|false]
			失败：['status'=>false, 'data'=>'错误原因']
	  */
	function checkPayPassword()
	{
		$YpwUser = new YpwUser();
		$res = $YpwUser->checkPayPassword($_POST['uid'], $_POST['password']);
		LibFc::EchoJson($res);
	}


	/**
	  * @method 修改支付密码 
	  * @http	post
	  * @param  $uid  用户ID [必填]
	  * @param  $new_password 新密码 [必填]
	  * @param  $old_password 旧密码 [可选]      未设置过密码不需要提供，修改支付密码：$old_password、$mobile_code二选一 
	  * @param  $mobile_code  手机验证码 [可选]  未设置过密码不需要提供，修改支付密码：$old_password、$mobile_code二选一 
	  * @param  $from 来源 [必填]
	  * @author soul
	  * @copyright 2018/8/25
	  * @return 
			成功：['status'=>true, 'data'=>true]
			失败：['status'=>false, 'data'=>'错误原因']
	  */
	function setPayPassword()
	{
		$YpwUser = new YpwUser();
		$filed = ['new_password', 'old_password', 'mobile_code', 'from'];
		$dataArr = [];
		foreach($filed as $v)
		{
			if(isset($_POST[$v])) $dataArr[$v] = $_POST[$v];
		}
		$Res = $YpwUser->setPayPassword($_POST['uid'], $dataArr);
		echo json_encode($Res);
	}
	
	/**
	  * @method 微信登录绑定
	  * @http  POST
	  * @param  udata  微信信息
	  * @param  name  用户名
	  * @param  password 密码
	  * @param  from
	  * @author soul
	  * @copyright 2017/4/13
	  * @return 
	  {"status":true,"data": true,"code":""}
	  {"status":false,"data":'失败原因',"code":'error'}
	  */
	function bindLoginWx()
	{
		$WXUserArr = json_decode(base64_decode($_POST['udata']), true);
		if(empty($WXUserArr['unionid']) || empty($WXUserArr['nickname']) || empty($WXUserArr['openid'])){
			LibFc::ReturnJson(false, '获取数据失败，请稍后重试！');exit;
		}
		$YpwUser = new YpwUser();
		$dataArr = [
			'name'=>$_POST['name'],
			'password'=>$_POST['password'],
			'from'=>$_POST['from']
		];
		$res = $YpwUser->Login('password', $dataArr, 'cn');
		if(!empty($res['data']['u_id']))
		{
			$userData = $res['data'];
			$bindArr = [
				'weixin'=>['bind'=>'Y', 'u_weixin_unionid'=>$WXUserArr['unionid'], 'u_weixin_info'=>json_encode($WXUserArr)] 
			];
			$YpwUser->BindAccount($userData['u_id'], $bindArr);
		}
		echo json_encode($res);
	}


	/**
	  * @method 手机、微信、QQ的绑定与解绑 公众号关注或者取消关注
	  * @http  POST
	  * @param  token              string [必填] 调用接口凭证 (post|get)
	  * @param  uid                int    [必填] 用户ID
	  * @param  data               array  [必填] 'weixin','qq','shouji','gzh' 可选择里面的任意key组合
												 [
													'qq'=>['bind'=>'Y|N', 'u_qq_unionid'=>'', 'u_qq_info'=>''] bind必填
													'weixin'=>['bind'=>'Y|N', 'u_weixin_unionid'=>'', 'u_weixin_info'=>'json'] bind必填
													'gzh'=>['bind'=>'Y|N', 'u_weixin_bd'=>'', 'u_weixin_unionid'=>''] bind必填
													'shouji'=>['bind'=>'Y|N', 'u_mobile'=>''] bind必填
													'apple'=>['bind'=>'Y|N', 'u_apple_unionid'=>'', 'u_apple_info'=>'json'] bind必填
												 ]						
	  * @author soul
	  * @copyright 2017/4/13
	  * @return 
	  {"status":true,"data": {"unitag":"用户唯一编码"},"code":""}
	  {"status":false,"data":'失败原因',"code":'error'}
	  */
	function bind_account()
	{
		$YpwUser = new YpwUser();
		$Res = $YpwUser->BindAccount($_POST['uid'], $_POST['data']);
		echo json_encode($Res);
	}

	
	/**
	  * @method 通过关键字搜索用户
	  * @http  POST
	  * @param  token              string [必填] 调用接口凭证 (post|get)
	  * @param  word  '用户名，昵称，公司名，手机，邮箱'
	  * @param  per  20 每页多少数据
	  * @param  page  1 第几页	
	  * @author soul
	  * @copyright 2017/4/13
	  * @return 
	  {"status":true,"data": [[用户基本信息]],"code":""}
	  {"status":false,"data":'失败原因',"code":'error'}
	  */
	function searchUser()
	{
		$word = isset($_POST['word'])? LibFc::Escape($_POST['word']): '';
		if($word != '')
		{
			$nowPage = isset($_POST['page']) ? (int) $_POST['page'] : 1;
			$perPage = isset($_POST['per']) ? (int) $_POST['per'] : 20;
			$where = sprintf(" AND (u_name LIKE '%s%%' OR u_nickname LIKE '%%%s%%' OR u_email LIKE '%s%%' OR u_mobile LIKE '%s%%' OR ui_company LIKE '%%%s%%') limit %d, %d",
				$word, $word, $word, $word, $word, ($nowPage-1)*$perPage, $perPage);
			$YpwUser = new YpwUser();
			$res = $YpwUser->GetUser(['u_id, u_name, u_nickname, u_logo, u_real_name, u_email, u_mobile, u_weixin_info, ui_sign, ui_sex, ui_company, ui_province, ui_city, ui_address'], $where);
			$res['data'] = $this->initUserLogo($res['data'], $oneRow);
			echo json_encode($res);
		}
		else
		{
			LibFc::ReturnJson(false, 'word参数必填');
		}
	}


	/**
	  * @method 通过用户名、昵称、手机号码、邮箱精准查找用户
	  * @http  get
	  * @param  token              string [必填] 调用接口凭证 (post|get)
	  * @param  account  用户名、昵称、手机号码、邮箱
	  * @author soul
	  * @copyright 2022/4/2
	  * @return 
	  {"status":true,"data":[{"u_id":"166055","u_name":"soul123","u_nickname":"soul123","u_logo":"http:\/\/192.168.1.42\/file_center\/center\/read.php?site=yp&c=yp_logo&f=Logo\/1041\/120\/6429bfccf32006a9.jpg&i=42","u_real_name":"ssss","u_email":"soul123@126.com","u_mobile":"18620087058","u_weixin_info":""}],"code":0}{"status":true,"data":[],"code":0,"runtime":51}
	  */
	function getUserByAccount()
	{
		$Params = mvc::$URL_PARAMS;
		$arr = [];
		if(!empty($Params['account']))
		{
			$word = LibFc::Escape($Params['account']);
			$where = sprintf(" AND (u_name='%s' OR u_nickname='%s' OR (u_email ='%s' and u_emil_check = 1) OR (u_mobile ='%s' AND u_mobile_check='Y'))",
				$word, $word, $word, $word);
			$YpwUser = new YpwUser();
			$res = $YpwUser->GetUser(['u_id, u_name, u_nickname, u_logo, u_real_name, u_email, u_mobile, u_weixin_info'], $where);
			$res['data'] = $this->initUserLogo($res['data'], $oneRow);
			$arr = $res['data'];
		}
		LibFc::ReturnJson(true, $arr);
	}

	/**
	  * @method 通过ID查询用户信息
	  * @http  POST
	  * @param  token              string [必填] 调用接口凭证 (post|get)
	  * @param  uids  '1,2,3,4'				
	  * @author soul
	  * @copyright 2017/4/13
	  * @return 
	  {"status":true,"data": [[用户基本信息]],"code":""}
	  {"status":false,"data":'失败原因',"code":'error'}
	  */
	function getUserByIds()
	{
		$uidArr = [];
		foreach(explode(',', $_POST['uids']) as $v)
		{
			$v = (int) $v;
			$uidArr[$v] = $v;
		}
		if(count($uidArr) > 0)
		{
			$where = sprintf(" AND u_id IN (%s)", implode(',', $uidArr));
			$YpwUser = new YpwUser();
			$res = $YpwUser->GetUser(['u_id, u_name, u_nickname, u_logo, u_real_name, u_email, u_mobile, u_weixin_info, ui_sign, ui_sex, ui_company, ui_province, ui_city, ui_address'], $where);
			$res['data'] = $this->initUserLogo($res['data']);
			echo json_encode($res);
		}
		else
		{
			LibFc::ReturnJson(false, 'uids参数必填');
		}
	}

	/**
	  * @method 通过ID查询用户信息
	  * @http	get
	  * @param  token              string [必填] 调用接口凭证 (post|get)
	  * @param  uid                int    [必填] 				
	  * @param  type               string [选填] 	base | all					
	  * @author soul
	  * @copyright 2017/4/13
	  * @return 
	  {"status":true,"data": [[用户基本信息]],"code":""}
	  {"status":false,"data":'失败原因',"code":'error'}
	  */
	function getUserById()
	{
		if(!empty($_GET['uid']))
		{
			$YpwUser = new YpwUser();
			$filed = empty($_GET['type']) || $_GET['type'] != 'all'? ['u.*']: ['*'];
			$res = $YpwUser->GetUser($filed, sprintf(" AND u_id =%d", $_GET['uid']), true);
			$res['data'] = $this->initUserLogo($res['data'], true);
			echo json_encode($res);
		}
		else
		{
			LibFc::ReturnJson(false, 'uid参数必填');
		}
	}

	/**
	  * @method 查询用户信息
	  * @http  POST
	  * @param  token              string [必填] 调用接口凭证 (post|get)
	  * @param  filed   ['u_id', ....]
	  * @param  where  'and u_id=111'
	  * @param  oneRow   true|false							
	  * @author soul
	  * @copyright 2017/4/13
	  * @return 
	  {"status":true,"data": [[用户基本信息]],"code":""}
	  {"status":false,"data":'失败原因',"code":'error'}
	  */
	function getUser()
	{
		if(is_array($_POST['filed']) && !empty($_POST['where']))
		{
			$oneRow = isset($_POST['oneRow'])? $_POST['oneRow']: false;
			$YpwUser = new YpwUser();
			$res = $YpwUser->GetUser($_POST['filed'], $_POST['where'], $oneRow);
			$res['data'] = $this->initUserLogo($res['data'], $oneRow);
			echo json_encode($res);
		}
		else
		{
			LibFc::ReturnJson(false, '参数错误');
		}
	}


	/**
	  * @method 查询用户在宜配的服务项目情况
	  * @http  get
	  * @param  uid   int    [必填]   用户ID
	  * @author soul
	  * @copyright 2017/4/13
	  * @return {"status":true,"data":{"web":1,"webetime":1899302399},"code":0,"runtime":35}
	  web: 1网站VIP  0非网站VIP
	  webetime:到期时间
	  */
	function getUserService()
	{
		$Params = mvc::$URL_PARAMS;
		$arr = ['web'=>0, 'webetime'=>0];
		if(!empty($Params['uid']))
		{
			$YpwBase = new YpwBase();
			$res = $YpwBase->Get('yp_user_ext', ['ui_period'],sprintf(" and ui_uid = %d limit 1", $Params['uid']), true);
			if(!empty($res['data']))
			{
				$uArr = $res['data'];
				$arr['webetime'] = strtotime($uArr['ui_period']);
				if($arr['webetime'] > time()) $arr['web'] = 1;
			}
		}
		LibFc::ReturnJson(true, $arr);
	}
	

	/**
	  * @method 查询用户积分记录
	  * @http  POST
	  * @param  token              string [必填] 调用接口凭证 (post|get)
	  * @param  filed   ['u_id', ....]
	  * @param  where  'and u_id=111'
	  * @param  oneRow   true|false							
	  * @author soul
	  * @copyright 2017/4/13
	  * @return 
	  {"status":true,"data": [[用户基本信息]],"code":""}
	  {"status":false,"data":'失败原因',"code":'error'}
	  */
	function getIntegral()
	{
		if(is_array($_POST['filed']) && !empty($_POST['where']))
		{
			$oneRow = isset($_POST['oneRow'])? $_POST['oneRow']: false;
			$YpwBase = new YpwBase();
			$res = $YpwBase->Get('yp_user_integral_list', $_POST['filed'], $_POST['where'], $oneRow);
			echo json_encode($res);
		}
		else
		{
			LibFc::ReturnJson(false, '参数错误');
		}
	}

	/**
	  * @method 获取积分充值优惠信息
	  * @http  POST
	  * @param  token              string [必填] 调用接口凭证 (post|get)		
	  * @author soul
	  * @copyright 2017/4/13
	  * @return 
	  {"status":true,"data": [
			'rate'=>100,//兑换比例 1元钱=100积分
			'index'=>[
				['money'=>10, 'total'=>1000, 'free'=>0]
			]
		],"code":""}
	  {"status":false,"data":'失败原因',"code":'error'}
	  */
	function getPayIntegral()
	{
		LibFc::ReturnJson(true, mvc::$cfg['INTEGRAL']);
	}


	/**
	  * @method 查询用户积分充值记录
	  * @http  POST
	  * @param  token              string [必填] 调用接口凭证 (post|get)
	  * @param  filed   ['u_id', ....]
	  * @param  where  'and u_id=111'
	  * @param  oneRow   true|false				
	  * @author soul
	  * @copyright 2017/4/13
	  * @return 
	  {"status":true,"data": [],"code":""}
	  {"status":false,"data":'失败原因',"code":'error'}
	  */
	function getIntegralPay()
	{
		if(is_array($_POST['filed']) && !empty($_POST['where']))
		{
			$oneRow = isset($_POST['oneRow'])? $_POST['oneRow']: false;
			$YpwBase = new YpwBase();
			$res = $YpwBase->Get('yp_user_pay', $_POST['filed'], $_POST['where'], $oneRow);
			echo json_encode($res);
		}
		else
		{
			LibFc::ReturnJson(false, '参数错误');
		}
	}

	/**
	  * @method 积分充值订单提交
	  * @http  POST
	  * @param data [
			'up_u_id'=>1,
			'up_money'=>支付金额, 
			'up_integral'=>兑换积分数
			'up_pay_by'=>alipay||weixin,
			'up_pay_type'=>pc:扫码 app:APP wap:手机网 gzh:公众号,
			'up_from'=>来源
			]
	  * @author soul
	  * @copyright 2016/3/30
	  * @return 
			成功：['status'=>true, 'data'=>[up_id, 支付信息]]
			失败：['status'=>false, 'data'=>'错误原因']
	  */
	public function rechargeIntegral()
	{
		$YpwUser = new YpwUser();
		$res = $YpwUser->rechargeIntegral($_POST['data']);
		echo json_encode($res);
	}


	/**
	  * @method 积分充值支付信息
	  * @http  GET
	  * @param  upId 订单ID
	  * @param  payBy alipay||weixin[可选，需要变更时提供]
	  * @param  payType pc:扫码 app:APP wap:手机网 gzh:公众号[可选，需要变更时提供]
	  * @author soul
	  * @copyright 2016/3/30
	  * @return 
			成功：['status'=>true, 'data'=>[支付信息]]
			失败：['status'=>false, 'data'=>'错误原因']
	  */
	public function getRechargeIntegralPay()
	{
		$YpwUser = new YpwUser();
		$res = $YpwUser->getRechargeIntegralPay($_GET['upId'], $_GET['payBy'], $_GET['payType']);
		echo json_encode($res);
	}



	/**
	  * @method 检查积分充值是否完成
	  * @http  GET
	  * @param  upId 订单ID
	  * @author soul
	  * @copyright 2016/3/30
	  * @return 
			成功：['status'=>true, 'data'=>-1已关闭 0 待支付 2支付并且已兑换积分]
			失败：['status'=>false, 'data'=>'错误原因']
	  */
	public function checkRechargeIntegral()
	{
		$YpwUser = new YpwUser();
		$res = $YpwUser->checkRechargeIntegral($_GET['upId']);
		echo json_encode($res);
	}


	/**
	  * @method 关闭积分充值
	  * @http  GET
	  * @param  upId 订单ID
	  * @author soul
	  * @copyright 2016/3/30
	  * @return 
			成功：['status'=>true, 'data'=>true]
			失败：['status'=>false, 'data'=>'错误原因']
	  */
	public function closeRechargeIntegral()
	{
		$YpwUser = new YpwUser();
		$res = $YpwUser->closeRechargeIntegral($_GET['upId']);
		echo json_encode($res);
	}


	/**
	  * @method 查询余额提现账号
	  * @http  POST
	  * @param  token             string [必填] 调用接口凭证 (post|get)
	  * @param  uid               array  [必填]  [
													'filed'=>['u_id', ....]
													'where'=>'and u_id=111'
													'oneRow'=>true|false
												 ]						
	  * @author soul
	  * @copyright 2017/4/13
	  * @return 
	  {"status":true,"data": [],"code":""}
	  {"status":false,"data":'失败原因',"code":'error'}
	  */
	function getMoneyAccount()
	{
		if(is_array($_POST['filed']) && !empty($_POST['where']))
		{
			$oneRow = isset($_POST['oneRow'])? $_POST['oneRow']: false;
			$YpwBase = new YpwBase();
			$res = $YpwBase->Get('yp_user_account', $_POST['filed'], $_POST['where'], $oneRow);
			echo json_encode($res);
		}
		else
		{
			LibFc::ReturnJson(false, '参数错误');
		}
	}


	/**
	  * @method 添加余额提现账号
	  * @http  POST
	  * @param  token             string [必填] 调用接口凭证 (post|get)
	  * @param  $dataArr [
			'uac_u_id'=>1,
			'uac_type'=>0微信 1支付宝, 2银行卡 
			'uac_name'=>'收款姓名',
			'mobile_code'=>'手机验证码',  style:baccount
			'uac_alipay'=>'邮箱或者手机号码', 支付宝
			'uac_weixin'=>'{openid:   unionid:.... }'  微信
			'uac_from'=>来源,
			
			'uac_bank_card'=>卡号,
			'uac_bank_name'=>银行名称,
			'uac_bank_open'=>开户行,
		]
	  * @author soul
	  * @copyright 2017/4/13
	  * @return 
	  {"status":true,"data": [],"code":"uac_id"}
	  {"status":false,"data":'失败原因',"code":'error'}
	  */
	function bindMoneyAccount()
	{
		$YpwUser = new YpwUser();
		$arr = [];
		foreach($_POST as $k=>$v)
		{
			if(stripos($k, 'uac_') === 0 || $k == 'mobile_code')
			$arr[$k] = $v;
		}
		$Res = $YpwUser->bindMoneyAccount($arr);
		echo json_encode($Res);
	}


	/**
	  * @method 删除余额提现账号
	  * @http  POST
	  * @param  token             string [必填] 调用接口凭证 (post|get)
	  * @param  $dataArr [
			'uac_id'=>1,
			'mobile_code'=>'手机验证码',  style:ubaccount
			'uac_from'=>来源
		]
	  * @author soul
	  * @copyright 2017/4/13
	  * @return 
	  {"status":true,"data": [],"code":"uac_id"}
	  {"status":false,"data":'失败原因',"code":'error'}
	  */
	function unbindMoneyAccount()
	{
		$YpwUser = new YpwUser();
		$arr = [];
		foreach($_POST as $k=>$v)
		{
			if(stripos($k, 'uac_') === 0 || $k == 'mobile_code')
			$arr[$k] = $v;
		}
		$Res = $YpwUser->unbindMoneyAccount($arr);
		echo json_encode($Res);
	}




	/**
	  * @method 登录是否启用验证码
	  * @http  get
	  * @param  token              string [必填] 调用接口凭证 (post|get)
	  * @param  name               string [必填]  				
	  * @author soul
	  * @copyright 2017/4/13
	  * @return 
	  {"status":true,"data": [],"code":""}
	  {"status":false,"data":'失败原因',"code":'error'}
	  */
	function nameCheckcode()
	{
		$must = 0;
		if(!empty($_GET['name']))
		{
			$YpwUser = new YpwUser();
			$name = LibFc::Escape($_GET['name']);
			$Res = $YpwUser->GetUser(['count(*) as count'], sprintf(" AND u_error_count > 0 AND (u_name='%s' OR (u_email='%s' AND u_emil_check=1) OR (u_mobile='%s' AND u_mobile_check='Y'))", $name, $name, $name), true);
			$must = empty($Res['data']['count'])?  0: 1;
		}
		LibFc::ReturnJson(true, $must);
	}


	/**
	  * @method 根据用户ID获取token
	  * @http  get
	  * @param  token              string [必填] 调用接口凭证 (post|get)
	  * @param  uid                int  [必填] 用户ID
	  * @author soul
	  * @copyright 2017/8/16
	  * @return 
		{"status":true,"data":'token',"code":0}
		{"status":false,"data":'失败原因',"code":0}
	  */
	function getToken()
	{
		$YpwUser = new YpwUser();
		$dataArr = [
			'uid'=>$_GET['uid'],
			'uname'=>$_GET['uname']
		];
		$Res = $YpwUser->getToken($dataArr);
		echo json_encode($Res);
	}


	/**
	  * @method 获取token的原始信息
	  * @http  get
	  * @param  token              string [必填] 调用接口凭证 (post|get)
	  * @param  utoken             string [必填] 用户登录token
	  * @author soul
	  * @copyright 2017/8/16
	  * @return 
		{"status":true,"data":'token',"code":0}
		{"status":false,"data":'失败原因',"code":0}
	  */
	function getDataByToken($token)
	{
		$YpwUser = new YpwUser();
		$Res = $YpwUser->getDataByToken($_GET['utoken']);
		echo json_encode($Res);
	}
	

	private function initUserLogo($dataArr, $oneRow = false)
	{
		$YpwUser = new YpwUser();
		$Res = $YpwUser->initUserLogo($dataArr, $oneRow);
		return $Res['data'];
	}

	/**
	  * @method 根据IP地址获取省市
	  * @http  get
	  * @param  token           string [必填] 调用接口凭证 (post|get)
	  * @param  ip              string [必填] IP地址
	  * @author soul
	  * @copyright 2017/8/16
	  * @return 
		{"status":true,"data":{"country":"中国","pcts":["广东省","广州市"],"pctids":["19","1901"],"lng_lat":"113.273239,23.157921"},"code":0,"runtime":73}
		{"status":false,"data":'失败原因',"code":0}
	  */
	public function getIpPCT()
	{
		$OthPct = new OthPct();
		$res=$OthPct->getIpPCT($_GET['ip']);
		LibFc::EchoJson($res);
	}


	public function initWxUserLogoNickName()
	{
		$YpwBase = new YpwBase();
		$YpwUser = new YpwUser();
		while(1)
		{
			$Res = $YpwUser->GetUser(['u_id', 'u_weixin_info','u_nickname'], " AND u_weixin_bd='Y' AND u_logo = '' order by rand() LIMIT 20");
			if(empty($Res['data'])) break;
			foreach($Res['data'] as $V)
			{
				//头像 昵称
				$setArr = [];
				$infoArr = json_decode($V['u_weixin_info'], true);
				if(!empty($infoArr['headimgurl']))
				{
					$LibHttp = new LibHttp();
					$html = $LibHttp->fetch($infoArr['headimgurl']);
					if(strlen($html) < 1000 || md5($html) == 'fee9458c29cdccf10af7ec01155dc7f0') continue;
					$data_arr = [
						'token'=>mvc::$cfg['FILE_CENTER']['yp']['token'],
						'file'=>[
							'name'=>'a.jpg',
							'data'=>$html
						],
						'cate'=>'yp_logo'
					];
					$res  = $LibHttp->upload(mvc::$cfg['FILE_CENTER']['yp']['url_put'], $data_arr);
					$setArr['u_logo'] = $res['data']['path'].$res['data']['small'].'/'.$res['data']['name'].'.'.$res['data']['ext'];
				}

				if(empty($V['u_nickname']) && !empty($infoArr['nickname']))
				{
					$infoArr['nickname'] = preg_replace_callback( '/./u', function (array $match) {return strlen($match[0]) >= 4 ? '' : $match[0];}, $infoArr['nickname']);
					$res = $YpwBase->Get('yp_user', ['u_id'], sprintf(" AND u_nickname='%s' and u_id != %d", LibFc::Escape($infoArr['nickname']), $V['u_id']), true);
					if(empty($res['data']))
					{
						$setArr['u_nickname'] = $infoArr['nickname'];
					}
				}
				if(!empty($setArr))
					$YpwBase->Set('yp_user', $setArr, sprintf(" AND u_id = %d", $V['u_id']));
			}
		}
		LibFc::ReturnJson(true, 'ok');
	}


	/**
	  * @method 格式化地址，匹配出省市区、经纬度
	  * @http  get
	  * @param  addr    string [必填] 广东省深圳市龙华新村鹊山路口太阳能硅谷1003
	  * @param  pctIds    string [选填] 已有的省市区ID 19,1901,14363
	  * @param  lngFlag    int [选填] 默认1 是否需要返回经纬度 1|0
	  * @author soul
	  * @copyright 2017/8/16
	  * @return {"status":true,"data":{"pctids":["19","1901","14423"],"pcts":["广东省","广州市","白云区"],"new":"石槎路363号长盛网红直播基地A栋806","full":"广东省广州市白云区石槎路363号长盛网红直播基地A栋806","lng":0,"lat":0},"code":0,"runtime":60}
	  */
	public function formatAddrInfo()
	{
		$params = mvc::$URL_PARAMS;
		$OthPct = new OthPct();
		$res = $OthPct->formatAddrInfo($params['addr'], $params['pctIds'], $params['lngFlag']);
		LibFc::EchoJson($res);
	}

	/**
	 * @method 注销当前账号
	 * @http  get
	 * @param  uid    int [必填] 账号ID
	 * @param mobile_code   string [必填] 手机验证码
	 * @param from   string [必填] 手机验证码的来源
	 * @author soul 2022/7/19
	 * @return {"status":true,"data": ['iscancel'=>1|0, 'msg'=>'iscancel=0时无法注销的原因'],"code":0}
	 */
	public function cancelAccount()
	{
		$params = mvc::$URL_PARAMS;
		$YpwUser = new YpwUser();
		$res = $YpwUser->cancelAccount($params['uid'], $params['mobile_code'], $params['from']);
		LibFc::EchoJson($res);
	}


	/**
	 * @method 获取unitag的信息
	 * @http  get
	 * @param unitag     string [必填]       用户唯一标码（登录成功会返回），有效期30天，可以通过此唯一标码进行登录、获取api token
	 * @author soul 2024/1/20
	 * @return
	 */
	public function getUnitagInfo()
	{
		$params = mvc::$URL_PARAMS;
		$YpwUser = new YpwUser();
		$res = $YpwUser->decodeUnitag($params['unitag']);
		LibFc::EchoJson($res);
	}
}