=$adult) {
return true;
} else {
return false;
}
}
/* 支付验证 当前只有未成年
* return: array code 1成功 0失败 msg :错误消息
*/
function pay_check($user_id) {
$ret = array(
'code' => 1,
'msg' => '',
);
$idcard = M("user", "tab_")->where(array('id' => $user_id))->getField("idcard");
if (!$idcard) {
$ret['code'] = 0;
$ret['msg'] = '
未实名认证不可充值!
请到“悬浮球->我的”进行实名认证';
return $ret;
}
if (is_adult($idcard, 18)) {
$ret['code'] = 1;
$ret['msg'] = '';
return $ret;
} else {
$ret['code'] = 0;
$ret['msg'] = '未成年禁止支付哟!';
return $ret;
}
}
// 支付限额 wx alipay
function pay_limit($type='wx') {
C(BaseController::get_tool());
$configType = $type;
if ($configType== 'wx') {
$configType = 'wei_xin';
}
$date = date('Ymd');
if ($configType== 'wei_xin') {
$dwhere = "pay_date={$date} and (pay_way=2 or pay_way=3)";
} else if ($configType== 'alipay') {
$dwhere = "pay_date={$date} and pay_way=1";
} else { // 找不到的不限额
return false;
}
if (C($configType.".day_pay_limit") > 0) {
$todayTotal = M("pay_today_total", "tab_")->where($dwhere)->getField("price_cnt");
if ($todayTotal >= C($configType.".day_pay_limit")) { // 日限额
return true;
}
}
$start = date('Ym01');
$end = date('Ymd');
if ($configType== 'wei_xin') {
$mwhere = "(pay_way=2 or pay_way=3) and pay_date>={$start} and pay_date<={$end}";
} else if ($configType== 'alipay') {
$mwhere = "pay_way=1 and pay_date>={$start} and pay_date<={$end}";
} else { // 找不到的不限额
return false;
}
if (C($configType.".month_pay_limit") > 0) {
$todayTotal = M("pay_today_total", "tab_")->where($mwhere)->sum("price_cnt");
if ($todayTotal >= C($configType.".month_pay_limit")) { // 月限额
return true;
}
}
return false;
}
/* //获取支付方式 */
function get_pay_way($id=null)
{
if(!isset($id)){
return false;
}
switch ($id) {
case -1:
return "绑币";
break;
case 0:
return "平台币";
break;
case 1:
return "支付宝";
break;
case 2:
case 3:
case 4:
return "微信";
break;
// case 3:
// return "微信APP";
// break;
// case 4:
// return "威富通";
// break;
case 5:
return "聚宝云";
break;
case 6:
return "竣付通";
break;
case 7:
return "苹果支付";
break;
case 8:
return "金猪支付";
break;
case 9:
return "金猪支付-微信";
break;
}
}
/*
* 获取添加好友请求总数
* @param integer $userid 我的账户编号
* @author 鹿文学
*/
function get_buddies_unagree_count($userid) {
$count = 0;
if(is_numeric($userid) && $userid>0) {
$map['_string'] = "(inviter_id = {$userid} and inviter_status in(2,3) and invitee_status=1 )";
$map['_complex'] = array('invitee_id'=>$userid,'invitee_status'=>array('in','2,3'),'inviter_status'=>1);
$map['_logic'] = 'or';
$count = M('buddies','tab_')->where($map)->count();
}
return $count;
}
/*
*获取游戏设置信息
*/
function get_game_set_info($game_id = 0){
$game = M('GameSet','tab_');
$map['game_id'] = $game_id;
$data = $game->where($map)->find();
return $data;
}
/**
* 对数据进行编码转换
* @param array/string $data 数组
* @param string $output 转换后的编码
*/
function array_iconv($data, $output = 'utf-8') {
$encode_arr = array('UTF-8','ASCII','GBK','GB2312','BIG5','JIS','eucjp-win','sjis-win','EUC-JP');
$encoded = mb_detect_encoding($data, $encode_arr);
if (!is_array($data)) {
return mb_convert_encoding($data, $output, $encoded);
}
else {
foreach ($data as $key=>$val) {
$key = array_iconv($key, $output);
if(is_array($val)) {
$data[$key] = array_iconv($val, $output);
} else {
$data[$key] = mb_convert_encoding($data, $output, $encoded);
}
}
return $data;
}
}
/**
* 获取游戏appstor上线状态
* @param $game_id 游戏id
* @return mixed appstatus 上线状态
* @author zhaochao
*/
function get_game_appstatus($game_id){
$map['id']=$game_id;
$game=M('game','tab_')->where($map)->find();
if($game['sdk_version']==2&&$game['appstatus']==1){
return true;
}elseif($game['sdk_version']==2&&$game['appstatus']==0){
return false;
}elseif($game['sdk_version']==1){
return true;
}
}
/**
* 邮件发送函数
*/
function sendMail($to,$rand) {
Vendor('phpmailer.PHPMailerAutoload');
$mail = new \PHPMailer(); //实例化
$mail->IsSMTP(); // 启用SMTP
$mail->Host=C('email_set.smtp'); //smtp服务器的名称(这里以126邮箱为例:smtp.126.com)
$mail->SMTPAuth = TRUE;//C('MAIL_SMTPAUTH'); //启用smtp认证
$mail->SMTPSecure = 'ssl'; //设置使用ssl加密方式登录鉴权
$mail->Port = C('email_set.smtp_port'); //设置ssl连接smtp服务器的远程服务器端口号
$mail->CharSet = 'UTF-8';
$mail->Username = C('email_set.smtp_account'); //你的邮箱名
$mail->Password = C('email_set.smtp_password') ; //邮箱密码
$mail->From = C('email_set.smtp_account'); //发件人地址(也就是你的邮箱地址)
$mail->FromName = C('email_set.smtp_name'); //发件人姓名
$mail->AddAddress($to,"尊敬的客户");
$mail->WordWrap = 50; //设置每行字符长度
$mail->IsHTML(TRUE); // 是否HTML格式邮件
$mail->CharSet='utf-8'; //设置邮件编码
$mail->Subject =C('email_set.title'); //邮件主题
$content=M("tool",'tab_')->where(array('name'=>'email_set'))->getField('template');
$reg="/#code#/";
$content=preg_replace($reg,$rand,$content);
$mail->Body = $content; //邮件内容
$c = strip_tags($content);
$mail->AltBody = $c; //邮件正文不支持HTML的备用显示
return($mail->Send());
}
/**
* 获取微信app登录参数
* @return [type] [description]
*/
function get_game_param($game_id,$field="",$type=''){
$map['game_id']=0; empty($type) || $map['type'] = $type;
$find=M('param','tab_')->field($field)->where($map)->find();
if(null==$find){
$map['game_id']=$game_id;
$find=M('param','tab_')->field($field)->where($map)->find();
}
return $find;
}
/**
* 生成随机汉字字符串
* @param $num 数量
* @return [type] [description]
*/
function getChinaChar($num)
{
$char = file_get_contents(APP_PATH.'Sdk/SecretKey/Data/chinaChar.txt');
$str = '';
$length = strlen($char);
$len = mb_strlen($char);
for($i = 0;$i < $num;$i++)
{
$rand = rand(0,$len);
$str .= substr($char,$rand*3,3);
}
return $str;
}
/**
* 公共返回方法
* @param number $code 200成功 非200失败
* @param string $msg 错误提示
* @param unknown $data 业务数据
*/
function re_msg($code=200,$msg='',$data=[])
{
$ret['code'] = $code;
$ret['msg'] = $msg;
$ret['data'] = $data;
echo base64_encode(json_encode($ret));
exit();
}
function jsonOutput($status=0, $msg='', $data=[]) {
$ret['status'] = $status;
$ret['msg'] = $msg;
$ret['data'] = $data;
echo json_encode($ret);
exit();
}
/**
* 使用淘宝接口 判断ip,,,确定是否属于该地区
* @param $ip
* @return bool
*/
function ip_is_country($ip, $country_id=['US'], $country=['美国'])
{
$url = "http://sp0.baidu.com/8aQDcjqpAAV3otqbppnN2DJv/api.php?query={$ip}&co=&resource_id=6006";
$url2 = "http://ip.taobao.com/service/getIpInfo.php?ip=".$ip;
$res = file_get_contents($url);
if (!$res) { // 走淘宝
$res = file_get_contents($url2);
Log::write("taobao:".serialize($res));
if (!empty($res)) {
$ipData = json_decode($res,true);
if ($ipData['code']==0 && in_array($ipData['data']['country_id'],$country_id)) {
return true;
}
if ($ipData['code']==0 && in_array($ipData['data']['country'],$country)) {
return true;
}
}
} else {
$res= iconv('GB2312', 'UTF-8', $res);
$ipData = json_decode($res, true);
Log::write("sina:".serialize($res));
if ($ipData['status']==0 && substr($ipData['data'][0]['location'], 0, strlen($country[0])) == $country[0]) {
return true;
}
}
return false;
}
/*
* 记录行为日志
* @param [type] $log [description]
* @return [type] [description]
*/
function log_action($log) {
if(!empty($log['uid'])) {
$log['account'] = M('user', 'tab_')->where(['id' => $log['uid']])->getField('account');
}
if(!empty($log['game_id'])) {
$log['game_name'] = M('game', 'tab_')->where(['id' => $log['game_id']])->getField('game_name');
}
$log['ip'] = get_client_ip();
$log['create_time'] = time();
M('user_action_log', 'tab_')->data($log)->add();
}
/**
* 是否开启苹果内购通知
* @return bool
*/
function getAppleInteriorBuyStatus() {
$appleInteriorBuyStatus = M('tool','tab_')->where(['name'=>'apple_interior_buy'])->getField('status');
return $appleInteriorBuyStatus?true:false;
}
/**
* 记录行为日志
* @param $user_id
* @return bool
*/
function getIpForbitWhiteList($user_id) {
$is_white_list = M('forbit_ip', 'tab_')->where(['user_id'=>$user_id,'status'=>1])->find();
return $is_white_list?true:false;
}
/**
* 聚合数据短信接口
* @param $phone 电话号码
* @param $tpl_id 模板id
* @param $key 模板密钥
* @param $code 验证码
* @return array
*/
function juheSmsCode($phone,$tpl_id,$key,$code) {
$post['mobile'] = $phone;
$post['tpl_id'] = $tpl_id;
$tpl_value=urlencode("#code#={$code}m#=10");
$post['tpl_value'] = $tpl_value;
$post['key'] = $key;
$return = json_decode(curl_post(C("JUHE_SMSURL"),$post),true);
return $return;
}
/**
* 获取用户折扣
* @param $game_id 游戏ID
* @param $promote_id 渠道ID
* @param $user_id 用户ID
* @return mixed
*/
function get_discount($gameId, $userId)
{
//获取折扣
$res = [
'discount' => 10,
'discount_type' => 0,
];
$baseGame = M('base_game', 'tab_')->where([
'android_game_id|ios_game_id' => $gameId
])->find();
if (!$baseGame) {
return $res;
}
$time = time();
$discount = M('game_discount','tab_')->where([
'base_game_id' => $baseGame['id'],
'start_time' => ['elt', $time],
'end_time' => ['gt', $time],
'status' => 1,
])->find();
if (!$discount) {
return $res;
}
$exists = M('spend','tab_')->where([
'user_id' => $userId,
'pay_status' => 1
])->where("(game_id={$baseGame['android_game_id']} or game_id={$baseGame['ios_game_id']})")->find();
if ($exists) {
$res = [
'discount' => $discount['second_rate'],
'discount_type' => 1,
];
} else {
$res = [
'discount' => $discount['first_rate'],
'discount_type' => 0,
];
}
return $res;
}
// 未成年强制下线处理
function forceOffline($userId) {
$user = M('user', 'tab_')->where(['id' => $userId])->find();
if ($user['age_status'] == 3) {
echo base64_encode (json_encode(array(
"code" => 9999,
"msg" => "您已下线,请重新登入",
"data" => ""
)));
exit ();
}
}