You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
422 lines
14 KiB
PHP
422 lines
14 KiB
PHP
<?php
|
|
namespace Mobile\Controller;
|
|
use User\Api\MemberApi;
|
|
|
|
class SsgController extends BaseController {
|
|
const USER_NOT_ILLEGAL = -1; //用户名不合法
|
|
const USER_HAVE_SENSITIVE_STR = -2; //包含敏感字符
|
|
const USER_HAS_REGISTERED = -3; //用户已存在
|
|
const USER_PROMOTE_NATURAL = 0;//自然注册
|
|
const EMPTY_DATA = -100; //数据为空
|
|
const SIGN_ERROR = -99; //验签失败
|
|
const USER_NOT_EXIST = -1000; //用户不存在
|
|
const USER_FORBIDDEN = -1001; //被禁用
|
|
const USER_PWD_ERROR = -10021; //密码错误
|
|
const UNKNOWN_ERROR = -1100; //未知错误
|
|
const CODE_TIMEOUT = -98; //验证码超时
|
|
const CODE_ERROR = -97; //验证码错误
|
|
const RETURN_SUCCESS = 1;
|
|
const RETURN_FALSE = 2;
|
|
|
|
|
|
public function login()
|
|
{
|
|
$promoteId = I("promote_id", 0);
|
|
$user = session("user_auth");
|
|
if ($user) {
|
|
redirect(U("ssg/index", array('promete_id' => $promoteId)));
|
|
}
|
|
|
|
// /*if (!$promoteId) {
|
|
// echo "链接失效,请重新向推广员索取链接。";
|
|
// exit();
|
|
// $this->error("参数非法");
|
|
// }*/
|
|
if ($promoteId) {
|
|
$exists = M("promote", "tab_")->where(array('id' => $promoteId))->find();
|
|
if (!$exists) {
|
|
$this->error("链接失效,请重新向推广员索取链接.");
|
|
}
|
|
}
|
|
//获取客服qq
|
|
$appqq = M("config", "sys_")->field('value')->where("name='APP_QQ'")->find()['value'];
|
|
$this->assign("app_qq", $appqq);
|
|
|
|
$this->assign("promote_id", $promoteId);
|
|
$this->display();
|
|
}
|
|
|
|
public function home(){
|
|
//获取客服qq
|
|
$appqq = M("config", "sys_")->field('value')->where("name='APP_QQ'")->find()['value'];
|
|
|
|
$this->assign("app_qq", $appqq);
|
|
$this->assign("rand", rand());
|
|
$this->display();
|
|
}
|
|
|
|
//用户登录
|
|
public function do_login()
|
|
{
|
|
$account = I("Account");
|
|
$password = I("Password");
|
|
$promoteId = I("promote_id", 0);
|
|
/*if (!$promoteId) {
|
|
$this->ajaxReturn(array("ErrorCode" => -97, "ResultMsg" => "参数非法"));
|
|
}*/
|
|
$promote = array();
|
|
if ($promoteId) {
|
|
$promote = M("promote", "tab_")->where(array('id' => $promoteId))->find();
|
|
if (!$promote) {
|
|
$this->ajaxReturn(array("ErrorCode" => -97, "ResultMsg" => "参数非法."));
|
|
}
|
|
}
|
|
|
|
//var_dump($password);
|
|
$verify = new \Think\Verify();
|
|
if (!$verify->check(I("VerifyCode"))) {
|
|
$this->ajaxReturn(array("ErrorCode" => -97, "ResultMsg" => "验证码错误"));
|
|
}
|
|
$userApi = new MemberApi();
|
|
$user_id = $userApi->login($account, $password,1);//调用登录
|
|
$res_code = 0;
|
|
$res_msg = "登录成功";
|
|
if ($user_id < 0) {
|
|
switch ($user_id) {
|
|
case -1000 :
|
|
$res_code = self::USER_NOT_EXIST;
|
|
$res_msg = "用户不存在";
|
|
break;
|
|
case -10021 :
|
|
$res_code = self::USER_PWD_ERROR;
|
|
$res_msg = "登录密码错误";
|
|
break;
|
|
default :
|
|
$res_code = self::UNKNOWN_ERROR;
|
|
$res_msg = "未知错误";
|
|
}
|
|
}
|
|
if($user_id>0){
|
|
$_SESSION['user_id'] = $user_id;
|
|
|
|
$user = M('user', 'tab_')->where(array(
|
|
'id' => $user_id
|
|
))->find();
|
|
if (!$user['promote_id'] && $promote) {
|
|
M('user', 'tab_')->where(array(
|
|
'id' => $user_id
|
|
))->save(array(
|
|
'promote_id' => $promoteId,
|
|
'promote_account' => $promote['account']
|
|
));
|
|
}
|
|
}
|
|
$this->ajaxReturn(array("ErrorCode"=>$res_code,"ResultMsg"=>$res_msg),'JSON');
|
|
}
|
|
|
|
//验证码
|
|
public function verify($vid = '')
|
|
{
|
|
$config = array(
|
|
'seKey' => 'ThinkPHP.CN', //验证码加密密钥
|
|
'fontSize' => 16, // 验证码字体大小(px)
|
|
'imageH' => 42, // 验证码图片高度
|
|
'imageW' => 107, // 验证码图片宽度
|
|
'length' => 4, // 验证码位数
|
|
'fontttf' => '4.ttf', // 验证码字体,不设置随机获取
|
|
'useCurve' => false,
|
|
);
|
|
|
|
ob_clean();
|
|
$verify = new \Think\Verify($config);
|
|
$verify->codeSet = '0123456789';
|
|
$verify->entry($vid);
|
|
|
|
}
|
|
|
|
//注册
|
|
public function phoneRegister()
|
|
{
|
|
//添加用户
|
|
C(api('Config/lists'));
|
|
|
|
$user = $_POST;
|
|
$promoteId =( $user['promote_id'] ? $user['promote_id'] : 0);
|
|
#判断数据是否为空
|
|
if (empty($user)) {
|
|
$this -> set_message(1001, "fail", "注册数据不能为空");
|
|
}
|
|
#验证短信验证码
|
|
$this -> sms_verify($user['account'], $user['code']);
|
|
|
|
$res = $this -> doRegister($user['account'],$user['password'],$user['account'],$promoteId,4,2);
|
|
if(empty($res)){
|
|
$this -> set_message(1017, "fail", "添加失败");
|
|
}
|
|
//添加自动登录
|
|
$userApi = new MemberApi();
|
|
$user_id = $userApi->login($account, $password,1);
|
|
|
|
$this -> set_message(1, "success", "添加成功");
|
|
|
|
}
|
|
//普通注册
|
|
public function userRegister()
|
|
{
|
|
$account = I("account");
|
|
$password = I("password");
|
|
$promoteId = I("promote_id", 0);
|
|
$res = $this -> doRegister($account,$password,'',$promoteId,4,1);
|
|
if(empty($res)){
|
|
$this -> set_message(1017, "fail", "添加失败");
|
|
}
|
|
|
|
|
|
//添加自动登录
|
|
$userApi = new MemberApi();
|
|
$user_id = $userApi->login($account, $password,1);
|
|
|
|
$this -> set_message(1, "success", "添加成功");
|
|
# code...
|
|
}
|
|
//消息返回
|
|
public function set_message($status=0,$return_code="fail",$return_msg="操作失败"){
|
|
$msg = array(
|
|
"status" => $status,
|
|
"return_code" => $return_code,
|
|
"return_msg" => $return_msg
|
|
);
|
|
$this->ajaxReturn($msg,'JSON');
|
|
exit();
|
|
}
|
|
//真正注册代码
|
|
public function doRegister($account,$password,$phone,$promote_id,$register_way,$register_type)
|
|
{
|
|
//验证账号
|
|
$is_user_info = M('user', 'tab_') -> where(['account' => $account]) -> find();
|
|
if (!empty($is_user_info)) {
|
|
$this -> set_message(1017, "fail", "用户名已存在");
|
|
}
|
|
//2.验证其他平台是否存在账号
|
|
$domain = C('UC_OTHER_WEB_URL');
|
|
if (!empty($domain)) {
|
|
$url = "http://{$domain}/Api/user/checkUserName?account={$account}";
|
|
$check_res = json_decode(file_get_contents($url), true);
|
|
if ($check_res['status'] == 0) {
|
|
$this -> set_message(1017, "fail", "用户名已存在");
|
|
}
|
|
}
|
|
|
|
$data = array(
|
|
'account' => $account,
|
|
'password' => think_ucenter_md5($password, UC_AUTH_KEY),
|
|
'phone' => $phone,
|
|
'head_img' =>'',
|
|
'promote_id' => $promote_id,
|
|
'promote_account' =>get_promote_account($promote_id),
|
|
'register_way' => $register_way,
|
|
'register_type' => $register_type,
|
|
'register_ip' => get_client_ip(),
|
|
'parent_id'=>get_fu_id($promote_id),
|
|
'parent_name'=>get_parent_name($promote_id),
|
|
'register_time'=>time(),
|
|
'check_time' => time(),
|
|
|
|
);
|
|
/* 添加用户 */
|
|
$res = M('user', 'tab_') ->add($data);
|
|
return $res;
|
|
# code...
|
|
}
|
|
|
|
//首页
|
|
public function index(){
|
|
$user = session("user_auth");
|
|
if (!$user) {
|
|
redirect(U("ssg/login"));
|
|
//$this->error("请登入", U('ssg/login'));
|
|
}
|
|
|
|
$appqq = M("config", "sys_")->field('value')->where("name='APP_QQ'")->find()['value'];
|
|
$this->assign("app_qq", $appqq);
|
|
$this->display();
|
|
}
|
|
public function getGamaList()
|
|
{
|
|
|
|
$user = session("user_auth");
|
|
$game_name = I("game_name", false);
|
|
$type = I("type",false);
|
|
$map = [];
|
|
if($game_name){
|
|
$map["game_name"] = array("like","%{$game_name}%");
|
|
}
|
|
$map["sdk_version"]=2;
|
|
$map["game_status"]=1;
|
|
$game_list = M("game", "tab_")->field("*, id as game_id")->where($map)->select();
|
|
for ($i=0; $i < count($game_list); $i++) {
|
|
$game_list[$i]["game_icon"] = get_cover($game_list[$i]["icon"], 'path');
|
|
}
|
|
$res = array("list"=>$game_list);
|
|
if($type == 1){
|
|
$map['user_id']= $user['user_id'];
|
|
$map['pay_status'] = 1;
|
|
$userpay = M("game_supersign","tab_")->field("game_id")->where($map)->select();
|
|
if(empty($userpay)){
|
|
$userpay = [];
|
|
}else{
|
|
$tmparr = [];
|
|
for ($i=0; $i < count($userpay); $i++) {
|
|
# code...
|
|
$tmparr[] = $userpay[$i]["game_id"];
|
|
}
|
|
$userpay = $tmparr;
|
|
}
|
|
$res["pay_game_id"] = $userpay;
|
|
}
|
|
$this->ajaxReturn($res,'JSON');
|
|
# code...
|
|
}
|
|
|
|
public function order(){
|
|
//.echo md5(sha1('123456') . 'UmtW6-Z(S^8xvwDn;B:J{X7FG9z2+Np.|C#~QRY"');exit();
|
|
$user = session("user_auth");
|
|
if (!$user) {
|
|
redirect(U("ssg/login"));
|
|
//$this->error("请登入", U('ssg/login'));
|
|
}
|
|
|
|
$order_list = M("game_supersign a","tab_")->field("a.order_id, b.game_name, b.icon, b.id as game_id, a.pay_status, a.user_id, a.create_time")->join("left join tab_game b on a.game_id=b.id")->where(array(
|
|
'a.user_id' => $user['user_id'],
|
|
))->order("a.id")->select();
|
|
// pp($order_list);
|
|
|
|
foreach ($order_list as $key => $value){
|
|
$deff = $this->timediffs(time(),$value['create_time']);
|
|
//计算分钟数
|
|
if(($deff['day']+ $deff['hour'])>=1 || $deff['min']>30){
|
|
$order_list[$key]['invalid']=1;
|
|
}else{
|
|
$order_list[$key]['invalid']=0;
|
|
}
|
|
}
|
|
$this->assign("data_list", $order_list);
|
|
$this->assign("nowtime", time());
|
|
$this->display();
|
|
}
|
|
|
|
//流程
|
|
public function process(){
|
|
$this->display();
|
|
}
|
|
|
|
//教程
|
|
public function tutorial(){
|
|
$this->display();
|
|
}
|
|
|
|
//帮助
|
|
public function help(){
|
|
$this->display();
|
|
}
|
|
|
|
//规则
|
|
public function rule(){
|
|
$this->display();
|
|
}
|
|
|
|
public function clear(){
|
|
\Think\Log::record('缓存清理业务触发');
|
|
session(null);
|
|
}
|
|
//退出
|
|
public function logout() {
|
|
session("user_auth",null);
|
|
redirect(U("ssg/login"));
|
|
}
|
|
//发送验证码
|
|
public function sendPhoneCode()
|
|
{
|
|
$phone = I("phone");
|
|
$result = R('Common/Sms/send_sms_code', array($phone, 10, false));
|
|
|
|
if ($result['code'] == 200) {
|
|
$data['status'] = 1;
|
|
$data['data'] = $result['data'];
|
|
} else {
|
|
$data['status'] = 0;
|
|
}
|
|
|
|
$data['msg'] = $result['msg'];
|
|
|
|
echo json_encode($data);
|
|
exit;
|
|
}
|
|
public function timediffs($begin_time, $end_time) {
|
|
if ($begin_time < $end_time) {
|
|
$starttime = $begin_time;
|
|
$endtime = $end_time;
|
|
} else {
|
|
$starttime = $end_time;
|
|
$endtime = $begin_time;
|
|
}
|
|
|
|
//计算天数
|
|
$timediff = $endtime - $starttime;
|
|
$days = intval($timediff / 86400);
|
|
//计算小时数
|
|
$remain = $timediff % 86400;
|
|
$hours = intval($remain / 3600);
|
|
//计算分钟数
|
|
$remain = $remain % 3600;
|
|
$mins = intval($remain / 60);
|
|
//计算秒数
|
|
$secs = $remain % 60;
|
|
$res = array("day" => $days, "hour" => $hours, "min" => $mins, "sec" => $secs);
|
|
return $res;
|
|
}
|
|
public function sms_verify($phone="" ,$code="",$type=2){
|
|
|
|
$result = R('Common/Sms/verify_sms_code',array($phone,$code,false));
|
|
|
|
if($result['code']==200) {
|
|
if($type==1){
|
|
$this->set_message(200,"success","正确");
|
|
}else{
|
|
return true;
|
|
}
|
|
} else {
|
|
switch ($result['code']) {
|
|
case 1021:{
|
|
$this->set_message(1010,"fail","验证码已失效,请重新获取");
|
|
};break;
|
|
case 1022:{
|
|
$this->set_message(1022,"fail","验证码不正确,请重新输入");
|
|
};break;
|
|
default:
|
|
$this->set_message($result['code'],"fail",$result['msg']);
|
|
}
|
|
}
|
|
|
|
}
|
|
/**
|
|
* 领取激活码
|
|
* @param $token
|
|
* @param $gift_id
|
|
* author: xmy 280564871@qq.com
|
|
*/
|
|
public function get_novice($user_id,$gift_id){
|
|
|
|
$model = D("Giftbag");
|
|
$exist = $model->checkAccountGiftExist($logininfo['user_id'],$gift_id);
|
|
if($exist){
|
|
$this->error("您已经领取过该礼包!");
|
|
}
|
|
$novice = $model->getNovice($logininfo['user_id'],$logininfo['account'],$gift_id);
|
|
if(empty($novice)){
|
|
$this->error("暂无激活码");
|
|
}
|
|
$this->success("领取成功",$novice);
|
|
}
|
|
}
|