Files
youlegames/codes/agent/game/dlweb/api/lib/1.0/sales.php
2026-03-15 01:27:05 +08:00

267 lines
11 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
require_once __DIR__ . '/header.php';
require_once __DIR__ . '/models/SalesModel.php';
class sales extends Base
{
/**
* 代理注册
* 用户通过手机号注册成为代理
* @post agent_id
* @post channel_id
* @post phone 手机号
* @post captcha 验证码
*/
public function register($request, &$return)
{
$params = $this->checkParams($request, [
'agentid/R', 'channelid/R', 'phone/R', 'captcha/0'
]);
$agent_id = $params['agentid'];
$channel_id = $params['channelid'];
$phone = $params['phone'];
$captcha = $params['captcha'];
// 判断手机号码是否正确
if ( !preg_match('/^1[3456789]{1}\d{9}$/', $phone)) {
throw new Exception('手机号不符合规则', 200);
}
if ( !isset($_SESSION['rand_code'])) {
throw new Exception('请先获取验证码', 200);
}
if ($_SESSION['rand_code'] !== $captcha) {
throw new Exception('验证码不正确', 200);
}
$SalesModel = new SalesModel();
$flag = $SalesModel->isRegisterPhone($agent_id, $channel_id, $phone);
if ($flag) {
throw new Exception('该手机号已注册', 200);
}
// 更新当前最大的代理id
$sql = 'update ct_agent_list set max_sales_id = max_sales_id + floor(rand() * (12-6) + 6) where agent_id = ?';
Db::execute($sql, [$agent_id]);
// 获取当前最大的代理id默认权限
$sql = 'select max_sales_id, default_sales_power from ct_agent_list where agent_id = ? LIMIT 1';
$result = Db::query($sql, [$agent_id]);
$max_sales_id = $result['max_sales_id'];
$power = $result['default_sales_power'];
// 插入记录
$sql = 'INSERT INTO sales_user (
saus_agentid, saus_channelid, saus_openid, saus_unionid, saus_firsttime,
saus_salesid, saus_tel, saus_power, password, saus_salesman,
saus_avatar, saus_nickname
) VALUES (
?,?,?,?,?,
?,?,?,?,1,
?,?
);';
$now = date("Y-m-d H:i:s", time());
$password = $max_sales_id . rand(1000, 9999);
$result = Db::execute($sql, [
$agent_id, $channel_id, $phone, $phone, $now,
$max_sales_id, $phone, $power, $password, '', '']);
// 清楚短信验证码
unset($_SESSION['rand_code']);
$return->biz_content = '注册成功';
return true;
}
/**
* 代理登入
*/
public function login($request, $return)
{
$params = $this->checkParams($request, [
'agentid/R', 'channelid/R', 'account/R', 'password/R'
]);
$agent_id = $params['agentid'];
$channel_id = $params['channelid'];
$account = $params['account'];
$password = $params['password'];
$sql = 'select saus_salesid, saus_nickname, saus_avatar,saus_roomcard, saus_bean from sales_user where saus_agentid = ? and saus_channelid and (saus_salesid = ? or saus_tel=?) and password=?;';
$sales_info = Db::query($sql, [$agent_id, $channel_id, $account, $account, $password]);
}
/**
* 手机号动态验证码登录
* @param $request
* @param $return
* @return bool
* @throws Exception
*/
public function loginByPhone($request, &$return)
{
$params = $this->checkParams($request, [
'agentid/R', 'channelid/R', 'phone/phone', 'captcha/R'
]);
$agent_id = $params['agentid'];
$channel_id = $params['channelid'];
$phone = $params['phone'];
$captcha = $params['captcha'];
$ret = Db::query('select id from sales_sms_code where agent_id = ? and channnel_id = ? and phone = ? and code = ?', [$agent_id, $channel_id, $phone, $captcha]);
if ( !$ret) {
$return->setErrors(200, '未查询到验证码');
return false;
}
// 通过session中的idx获取用户信息
$command = <<<EOL
select
idx, saus_agentid, saus_channelid, saus_openid, saus_unionid, saus_salesman, saus_salesid, saus_level,
saus_salestype, saus_roomcard, saus_bean, saus_power, saus_invitecode, saus_pushmoney1, saus_pushmoney2,
saus_status, password, saus_nickname, saus_avatar, saus_sex, saus_province, saus_city, global_power,
saus_tel, saus_wechat, is_send_star, user_id, player_id
from
sales_user
where
saus_agentid = ? and saus_channelid = ? and saus_tel = ?
EOL;
$dbSaleInfo = Db::query($command, [$agent_id, $channel_id, $phone]);
if ( !$dbSaleInfo) {
$return->setErrors(200, '未获取到用户信息');
return false;
}
if ($dbSaleInfo['saus_status'] != 0) {
$return->setErrors(200, '对不起,你的账号已被账号冻结');
return false;
}
// 记录登录日志 登录类型 0-微信登录 1-账号登录 2-手机号动态验证码登录
$sql = 'insert into ct_sales_login_log (agent_id, channel_id, sales_id, login_type, login_time) values (?,?,?,?,now());';
Db::execute($sql, [$agent_id, $channel_id, $dbSaleInfo['saus_salesid'], 2]);
// 更新最后一次的登录的时间
$sql = 'update sales_user set saus_lasttime=now() where idx=?';
Db::execute($sql, [$dbSaleInfo['idx']]);
$return->biz_content = array(
'idx' => $dbSaleInfo['idx'], /// 代理
'agentid' => $dbSaleInfo['saus_agentid'], /// 代理
'channelid' => $dbSaleInfo['saus_channelid'], /// 渠道
'openid' => isset($dbSaleInfo['saus_openid']) ? $dbSaleInfo['saus_openid'] : '', /// openid
'unionid' => isset($dbSaleInfo['saus_unionid']) ? $dbSaleInfo['saus_unionid'] : '', /// unionid
'nickname' => isset($dbSaleInfo['saus_nickname']) ? $dbSaleInfo['saus_nickname'] : '', /// 昵称
'headimgurl' => isset($dbSaleInfo['saus_avatar']) ? $dbSaleInfo['saus_avatar'] : '', /// 头像
'sex' => isset($dbSaleInfo['saus_sex']) ? $dbSaleInfo['saus_sex'] : '', /// 性别
'province' => isset($dbSaleInfo['saus_province']) ? $dbSaleInfo['saus_province'] : '', /// 省
'city' => isset($dbSaleInfo['saus_city']) ? $dbSaleInfo['saus_city'] : '', /// 市
'salesman' => empty($dbSaleInfo['saus_salesman']) ? 0 : intval($dbSaleInfo['saus_salesman']), /// 是否代理
'salesid' => isset($dbSaleInfo['saus_salesid']) ? $dbSaleInfo['saus_salesid'] : '', /// 代理编号
'level' => isset($dbSaleInfo['saus_level']) ? $dbSaleInfo['saus_level'] : '', /// 代理等级
'salestype' => isset($dbSaleInfo['saus_salestype']) ? $dbSaleInfo['saus_salestype'] : '', /// 代理类型
'roomcard' => isset($dbSaleInfo['saus_roomcard']) ? $dbSaleInfo['saus_roomcard'] : '', /// 账户房卡数
'bean' => isset($dbSaleInfo['saus_bean']) ? $dbSaleInfo['saus_bean'] : '', /// 账户金币数
'salespower' => isset($dbSaleInfo['saus_power']) ? $dbSaleInfo['saus_power'] : '', /// 代理权限
'agentmode' => 0, /// 分享模式
//'pushmoney' => intval($dbSaleInfo['saus_pushmoney1']) + intval($dbSaleInfo['saus_pushmoney2']), /// 提成金额
'sausstatus' => isset($dbSaleInfo['saus_status']) ? $dbSaleInfo['saus_status'] : '', /// 当前状态
'html_applysales' => isset($db_agent_info['html_applysales']) ? $db_agent_info['html_applysales'] : '', /// 成为代理的方式
'global_power' => isset($dbSaleInfo['global_power']) ? intval($dbSaleInfo['global_power']) : 0, /// 是否总代
'tel' => isset($dbSaleInfo['saus_tel']) ? $dbSaleInfo['saus_tel'] : '', /// 电话号码
'wechat' => isset($dbSaleInfo['saus_wechat']) ? $dbSaleInfo['saus_wechat'] : '', /// 微信号码
'ppp' => isset($dbSaleInfo['password']) ? $dbSaleInfo['password'] : '', /// 密码
'user_id' => empty(@$dbSaleInfo['user_id']) ? '' : $dbSaleInfo['user_id'], /// 统一账户编号
'is_bind' => empty($dbSaleInfo['saus_tel']) ? 0 : (0 == $dbSaleInfo['is_send_star'] ? 0 : 1), /// 是否绑定
'logintype' => 2,
'player_id' => isset($dbSaleInfo['player_id']) ? $dbSaleInfo['player_id'] : ''
);
return true;
}
/**
* 发送手机验证码,动态登录
*/
public function captchaLogin($request, &$return)
{
$params = $this->checkParams($request, [
'agentid/R', 'channelid/R', 'phone/phone'
]);
$agent_id = $params['agentid'];
$channel_id = $params['channelid'];
$phone = $params['phone'];
// 判断手机号是否绑定过账号
$sql = 'select idx from sales_user where saus_agentid=? and saus_channelid=? and saus_tel=? and is_send_star=1;';
$result = Db::query($sql, [$agent_id, $channel_id, $phone]);
if ( !$result) {
$return->setErrors(200, '该功能只支持已绑定手机的用户');
return false;
}
// 发送验证码
require_once '/models/Tools.php';
$Tools = new Tools();
$rand_code = $Tools->sendCaptcha($phone, 0, false);
$command = 'select id from sales_sms_code where agent_id = ? and channnel_id = ? and phone = ? and status = 0';
$ret = Db::query($command, [$agent_id, $channel_id, $phone]);
if (empty($ret)) {
$command = 'insert into sales_sms_code(agent_id, channnel_id, phone, code, status, is_bind, create_time) values(?, ?, ?, ?, 0, 1, now());';
Db::execute($command, [$agent_id, $channel_id, $phone, $rand_code]);
} else {
$command = 'update sales_sms_code set code = ? where id = ?';
Db::execute($command, [$rand_code, $ret['id']]);
}
// 验证码保存到session中
//$_SESSION['rand_code'] = $rand_code;
//$_SESSION['idx'] = $result['idx'];
$return->biz_content = $rand_code;
return true;
}
/**
* 测试方法
* @param $request
* @param $return
* @return bool
* @throws Exception
*/
public function test($request, $return)
{
$params = $this->checkParams($request, [
'agentid/R', 'channelid/R'
]);
$data = DB::query('select * from sales_user LIMIT 1;');
$params['test'] = 'tangjian';
$params['sales_info'] = $data;
$return->biz_content = $params;
return true;
}
}