添加后台代理代码

This commit is contained in:
2026-03-15 01:27:05 +08:00
parent 11f9ac4dc1
commit ea08c9366a
5254 changed files with 721042 additions and 0 deletions

View File

@@ -0,0 +1,608 @@
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2017/11/14
* Time: 11:30
*/
namespace models;
class Agent extends \core\Model
{
/**
* 添加新代理商
* @param $params
*/
public function addAgent(&$params)
{
$sql = 'insert into ct_agent_list (agent_id, nickname, max_sales_id, default_sales_power) VALUES (?,?,?,?)';
$this->execute($sql, [$params['agentid'], $params['name'], 10000000, $params['power']]);
}
/**
* 添加新渠道,并添加相应的产品
* @param $p
*/
public function addChannel(&$p)
{
$sql = 'insert into ct_channel_list (
agent_id, channel_id, nickname, logo, qq,
is_show_recharge_star, recharge_roomcard_to_sales,
wechat, app_id, devkey, market_id, app_id_pay,
devkey_pay, market_id_pay, is_open, parent_agent_id, become_sales_mode,
invitation_model, buy_card_mode, is_check_phone)
VALUES (
?,?,?,?,?,
?,?,
?,?,?,?,?,
?,?,?,?,?,
?,?,0
)';
$this->execute($sql, [
$p['agentid'], $p['channelid'], $p['name'], $p['logo'], $p['qq'],
$p['is_show_recharge_star'], $p['recharge_roomcard_to_sales'],
$p['wechat'], '14966338932488', '14966329712475', 'ylhdyx', '14966338932488',
'14966329712475', 'ylhdyx', $p['is_open'], $p['parentid'], $p['become_sales_mode'],
$p['invitation_model'], $p['buy_card_mode']
]);
// 添加产品
$agent_id = $p['agentid'];
$sql = <<<EOL
# 玩家购房卡
INSERT INTO `sales_product` (`sapr_agentid`, `sapr_productid`, `sapr_type`, `sapr_name`, `sapr_amount`, `sapr_money`, `sapr_memo`, `sapr_state`, `product_type`) VALUES ('{$agent_id}', MD5(unix_timestamp(now())+1), '0', '5张F卡', '5', '15.00', '', '0', '0');
INSERT INTO `sales_product` (`sapr_agentid`, `sapr_productid`, `sapr_type`, `sapr_name`, `sapr_amount`, `sapr_money`, `sapr_memo`, `sapr_state`, `product_type`) VALUES ('{$agent_id}', MD5(unix_timestamp(now())+2), '0', '10张F卡', '10', '30.00', '', '0', '0');
INSERT INTO `sales_product` (`sapr_agentid`, `sapr_productid`, `sapr_type`, `sapr_name`, `sapr_amount`, `sapr_money`, `sapr_memo`, `sapr_state`, `product_type`) VALUES ('{$agent_id}', MD5(unix_timestamp(now())+3), '0', '80张F卡', '80', '208.00', '', '0', '0');
# 代理购房卡
INSERT INTO `sales_product` (`sapr_agentid`, `sapr_productid`, `sapr_type`, `sapr_name`, `sapr_amount`, `sapr_money`, `sapr_memo`, `sapr_state`, `product_type`) VALUES ('{$agent_id}', MD5(unix_timestamp(now())+4), '1', '1张F卡', '1', '10.00', '', '0', '0');
INSERT INTO `sales_product` (`sapr_agentid`, `sapr_productid`, `sapr_type`, `sapr_name`, `sapr_amount`, `sapr_money`, `sapr_memo`, `sapr_state`, `product_type`) VALUES ('{$agent_id}', MD5(unix_timestamp(now())+5), '1', '1张F卡', '1', '10.00', '', '0', '0');
INSERT INTO `sales_product` (`sapr_agentid`, `sapr_productid`, `sapr_type`, `sapr_name`, `sapr_amount`, `sapr_money`, `sapr_memo`, `sapr_state`, `product_type`) VALUES ('{$agent_id}', MD5(unix_timestamp(now())+6), '1', '1张F卡', '1', '10.00', '', '0', '0');
# 玩家购星星
INSERT INTO `sales_product` (`sapr_agentid`, `sapr_productid`, `sapr_type`, `sapr_name`, `sapr_amount`, `sapr_money`, `sapr_memo`, `sapr_state`, `product_type`) VALUES ('{$agent_id}', MD5(unix_timestamp(now())+7), '0', '一万个星星', '10000', '105.00', '', '1', '1');
INSERT INTO `sales_product` (`sapr_agentid`, `sapr_productid`, `sapr_type`, `sapr_name`, `sapr_amount`, `sapr_money`, `sapr_memo`, `sapr_state`, `product_type`) VALUES ('{$agent_id}', MD5(unix_timestamp(now())+8), '0', '五万个星星', '50000', '525.00', '', '1', '1');
INSERT INTO `sales_product` (`sapr_agentid`, `sapr_productid`, `sapr_type`, `sapr_name`, `sapr_amount`, `sapr_money`, `sapr_memo`, `sapr_state`, `product_type`) VALUES ('{$agent_id}', MD5(unix_timestamp(now())+9), '0', '十万个星星', '100000', '1050.00', '', '1', '1');
# 代理购星星
INSERT INTO `sales_product` (`sapr_agentid`, `sapr_productid`, `sapr_type`, `sapr_name`, `sapr_amount`, `sapr_money`, `sapr_memo`, `sapr_state`, `product_type`) VALUES ('{$agent_id}', MD5(unix_timestamp(now())+10), '1', '一万个星星', '10000', '105.00', '', '1', '1');
INSERT INTO `sales_product` (`sapr_agentid`, `sapr_productid`, `sapr_type`, `sapr_name`, `sapr_amount`, `sapr_money`, `sapr_memo`, `sapr_state`, `product_type`) VALUES ('{$agent_id}', MD5(unix_timestamp(now())+11), '1', '五万个星星', '50000', '525.00', '', '1', '1');
INSERT INTO `sales_product` (`sapr_agentid`, `sapr_productid`, `sapr_type`, `sapr_name`, `sapr_amount`, `sapr_money`, `sapr_memo`, `sapr_state`, `product_type`) VALUES ('{$agent_id}', MD5(unix_timestamp(now())+12), '1', '十万个星星', '100000', '1050.00', '', '1', '1');
EOL;
$this->execute($sql);
}
/**
* 添加游戏
* @param $p
*/
public function addGame(&$p)
{
$sql = 'insert into ct_game_list (
channel_id, game_id, game_name, logo, description,
ios_download_url, ios_market_type, ios_app_size, android_download_url, android_app_size,
is_open
) VALUES (
?,?,?,?,?,
?,?,?,?,?,
?
);';
$this->execute($sql, [
$p['channelid'], $p['gameid'], $p['gamename'], $p['logo'], $p['description'],
$p['ios_download_url'], $p['ios_market_type'], $p['ios_app_size'], $p['android_download_url'], $p['android_app_size'],
$p['is_open']
]);
}
/**
* 修改代理商信息
* @param $p
*/
public function setAgentInfo(&$p)
{
$sql = 'update ct_agent_list set
agent_id=?, nickname=?, default_sales_power=? where id=?;
';
$this->execute($sql, [
$p['agentid'], $p['name'], $p['power'], $p['id']
]);
}
/**
* 修改渠道信息
* @param $p
*/
public function setChannelInfo(&$p)
{
$sql = 'update ct_channel_list set
agent_id=?, channel_id=?, nickname=?, logo=?, qq=?,
is_show_recharge_star=?, recharge_roomcard_to_sales=?,
wechat=?, is_open=?, parent_agent_id=?, become_sales_mode=?, invitation_model=?,
buy_card_mode=?, share_title=?, share_desc=?, share_img=?, share_text=?, pay_desc=?, announcement=? where id=?;
';
$this->execute($sql, [
$p['agentid'], $p['channelid'], $p['name'], $p['logo'], $p['qq'],
$p['is_show_recharge_star'], $p['recharge_roomcard_to_sales'],
$p['wechat'], $p['is_open'], $p['parentid'], $p['become_sales_mode'], $p['invitation_model'],
$p['buy_card_mode'], $p['share_title'], $p['share_desc'], $p['share_img'], $p['share_text'], $p['pay_desc'],
$p['announcement'], $p['id']
]);
}
/**
* 修改渠道信息
* @param $p
*/
public function setGameInfo(&$p)
{
$sql = 'update ct_game_list set
channel_id=?, game_id=?, game_name=?, logo=?,
description=?, ios_download_url=?, ios_market_type=?, ios_app_size=?, android_download_url=?,
android_app_size=?, is_open=? where id=?;
';
$this->execute($sql, [
$p['channelid'], $p['gameid'], $p['gamename'], $p['logo'],
$p['description'], $p['ios_download_url'], $p['ios_market_type'], $p['ios_app_size'], $p['android_download_url'],
$p['android_app_size'], $p['is_open'], $p['id']
]);
}
/**
* 获取相关联的渠道列表
* @param $params
* @return array
*/
public function getChannelList(&$params)
{
// 获取所有开放的渠道
if($params['agentid'] === 'all') {
$sql = /** @lang text */
'SELECT id, agent_id AS agentid, channel_id AS channelid, nickname AS name
FROM ct_channel_list WHERE is_open = 1;';
} else {
$sql = /** @lang text */
'SELECT id, agent_id AS agentid, channel_id AS channelid, nickname AS name
FROM ct_channel_list WHERE parent_agent_id = ? AND is_open = 1;';
}
$result = $this->queryAll($sql, [$params['agentid']]);
return $result;
}
/**
* 获取所有渠道
* @return array
*/
public function getAllAgentList()
{
$sql = /** @lang text */'select id, agent_id as agentid, nickname as name, max_sales_id, default_sales_power
from ct_agent_list;';
$result = $this->queryAll($sql);
return $result;
}
/**
* 获取所有渠道
* @return array
*/
public function getAllChannelList()
{
$sql = 'select id, agent_id as agentid, channel_id as channelid, nickname as name, parent_agent_id
from ct_channel_list where is_open=1;';
$result = $this->queryAll($sql);
return $result;
}
/**
* 获取所有游戏
* @return array
*/
public function getAllGameList()
{
$sql = 'select id, channel_id as channelid, game_id as gameid, game_name as name
from ct_game_list where is_open=1 order by channelid, id;';
$result = $this->queryAll($sql);
return $result;
}
/**
* 获取渠道配置信息,公共版
* @param $params
* @return mixed
*/
public function getChannelConfig(&$params)
{
$sql = 'SELECT
id,
agent_id,
channel_id,
nickname AS agentname,
logo AS agentlogo,
qq,
wechat AS channelwechat,
become_sales_mode AS html_applysales,
invitation_model AS agentmode,
buy_card_mode AS html_buyroomcard,
recharge_roomcard_to_sales,
request_star,
is_check_phone,
create_withdrawals_order_type,
create_withdrawals_order_qcode,
is_show_topsales_menu,
is_show_recharge_star,
share_title,
share_desc,
share_img,
share_text,
pay_desc,
app_id AS youle_appid,
devkey AS youle_devkey,
market_id AS youle_busiid,
app_id_pay AS youle_appid_pay,
devkey_pay AS youle_devkey_pay,
market_id_pay AS youle_busiid_pay
FROM ct_channel_list WHERE agent_id = ? AND channel_id = ? AND is_open = 1;';
$result = $this->query($sql, [$params['agentid'], $params['channelid']]);
return $result;
}
/**
* 获取渠道配置信息,公共版
* @param $id
* @return mixed
*/
public function getChannelConfigById($id)
{
$sql = 'SELECT
id,
agent_id,
channel_id,
nickname AS agentname,
logo AS agentlogo,
qq,
wechat AS channelwechat,
become_sales_mode AS html_applysales,
invitation_model AS agentmode,
buy_card_mode AS html_buyroomcard,
recharge_roomcard_to_sales,
request_star,
share_title,
share_desc,
share_img,
share_text,
pay_desc,
app_id AS youle_appid,
devkey AS youle_devkey,
market_id AS youle_busiid,
app_id_pay AS youle_appid_pay,
devkey_pay AS youle_devkey_pay,
market_id_pay AS youle_busiid_pay
FROM ct_channel_list WHERE id=? AND is_open = 1;';
$result = $this->query($sql, [$id]);
return $result;
}
/**
* 获取代理商配置信息,管理员版
* @param $p
* @return mixed
*/
public function getAgentInfo(&$p)
{
$sql = 'SELECT
agent_id as agentid,
nickname as name,
default_sales_power as power
FROM ct_agent_list WHERE id=?;';
$result = $this->query($sql, [$p['id']]);
return $result;
}
/**
* 获取渠道配置信息,管理员版
* @param $p
* @return mixed
*/
public function getChannelInfo(&$p)
{
$sql = 'SELECT
agent_id as agentid,
channel_id as channelid,
parent_agent_id as parentid,
nickname AS name,
logo,
qq,
wechat,
is_show_recharge_star,
recharge_roomcard_to_sales,
become_sales_mode,
invitation_model,
buy_card_mode,
request_star,
share_title,
share_desc,
share_img,
share_text,
pay_desc,
announcement,
is_open
FROM ct_channel_list WHERE id=?;';
$result = $this->query($sql, [$p['id']]);
return $result;
}
/**
* 获取游戏配置信息,管理员版
* @param $p
* @return mixed
*/
public function getGameInfo(&$p)
{
$sql = 'SELECT
channel_id as channelid,
game_id as gameid,
game_name as gamename,
logo,
description,
ios_download_url,
ios_market_type,
ios_app_size,
android_download_url,
android_app_size,
is_open
FROM ct_game_list WHERE id=?;';
$result = $this->query($sql, [$p['id']]);
return $result;
}
/**
* 获取游戏下载列表
* @param $params
* @return array
*/
public function getGameList(&$params)
{
$sql = 'SELECT
game_id,
game_name AS name,
logo AS image,
description AS memo,
ios_download_url AS ios_down,
ios_download_url_2 AS ios_down_2,
ios_market_type AS ios_marketid,
ios_app_size AS ios_size,
android_download_url AS android_down,
android_download_url_2 AS android_down_2,
android_app_size AS android_size
FROM ct_game_list WHERE channel_id = ? AND is_open = 1;';
$result = $this->queryAll($sql, [$params['channelid']]);
return $result;
}
/**
* 产品列表
* @param $params
* @return array
*/
public function getProductList(&$params)
{
/**
* sales_product 表
* sapr_type => 0-针对个人玩家的产品 1-针对个人代理的产品
* product_type => 0-房卡1-星星2-钻石
* sapr_state => 0-启用 1-禁用
* sort 排序(数值大的在前面)
*/
$sql = 'SELECT
idx as productid, sapr_name as name, sapr_amount as amount, sapr_money as money,
sapr_memo as memo, product_type, sapr_type as type, make_vip
FROM
sales_product
WHERE
sapr_agentid = ? and sapr_type = ? and product_type = ? and sapr_state = 0 and parent_id is null
ORDER BY sort desc, idx;';
$result = $this->queryAll($sql, [$params['agentid'], $params['type'], $params['ptype']]);
return $result;
}
/**
* 获取指定渠道所有商品
* @param $agent_id
* @return array
* @throws \Exception
*/
public function getAllProductList($agent_id)
{
$sql = 'select * from sales_product where sapr_agentid=? order by product_type, sort desc';
return $this->queryAll($sql, [$agent_id]);
}
/**
* 获取单个商品信息
* @param $id
* @return mixed
* @throws \Exception
*/
public function getProductInfo($id)
{
$sql = 'select * from sales_product where idx=?';
return $this->query($sql, $id);
}
/**
* 修改商品信息
* @param $p
* @throws \Exception
*/
public function setProductInfo($p)
{
if(empty($p['parent_id']))
$parent_id = null;
else
$parent_id = $p['parent_id'];
$sql = 'update sales_product set sapr_agentid=?, sapr_type=?, sapr_name=?, sapr_amount=?, sapr_money=?, sapr_memo=?,
sapr_state=?, product_type=?, parent_id=?, sort=?, make_vip=? where idx=?';
$this->execute($sql, [
$p['sapr_agentid'], $p['sapr_type'],$p['sapr_name'],$p['sapr_amount'],$p['sapr_money'], $p['sapr_memo'],
$p['sapr_state'],$p['product_type'],$parent_id,$p['sort'], $p['make_vip'],$p['idx']
]);
}
/**
* 添加商品
* @param $p
* @throws \Exception
*/
public function addProductInfo($p)
{
if(empty($p['parent_id']))
$parent_id = null;
else
$parent_id = $p['parent_id'];
$sql = 'insert into sales_product (
sapr_agentid, sapr_type, sapr_name, sapr_amount, sapr_money,
sapr_memo, sapr_state, product_type, parent_id, sort,
make_vip
) values (
?,?,?,?,?,
?,?,?,?,?,
?)';
$this->execute($sql, [
$p['sapr_agentid'], $p['sapr_type'],$p['sapr_name'],$p['sapr_amount'],$p['sapr_money'], $p['sapr_memo'],
$p['sapr_state'],$p['product_type'],$parent_id,$p['sort'], $p['make_vip']
]);
}
/**
* 使用钻石兑换的商品
* @param $params
* @return array
* @throws \Exception
*/
public function getTransformProductList(&$params)
{
$sql = /** @lang text */<<<EOL
select
id, name, amount, diamond, type, remark
from
(
select
id, name, amount, diamond, type, remark, sort
from
ct_transform_product_info
where
agent_id = ? and channel_id = ? and enabled = 1 and is_preferential = 0
union all
select
id, name, amount, diamond, type, remark, sort
from
ct_transform_product_info
where
agent_id = ? and channel_id = ? and enabled = 1 and is_preferential = 1 and
date_format(now(), '%H:%i:%s') between preferential_start_time and preferential_end_time
) t
order by
sort desc, id
EOL;
// $sql = 'select
// id, name, amount, diamond, type, remark
// from
// ct_transform_product_info
// where
// agent_id=? and channel_id=? and enabled=1
// order by sort desc, id';
//
// $result = $this->queryAll($sql, [$params['agentid'], $params['channelid']]);
$result = $this->queryAll($sql, [$params['agentid'], $params['channelid'], $params['agentid'], $params['channelid']]);
return $result;
}
/**
* 公告
* type => 0-代理后台的公告 1-代理抽成的公告
* @param $p
* @return array
*/
public function getNotice(&$p)
{
$sql = 'SELECT
notice_info
FROM
ct_agent_notice
WHERE
(channel_id=1 or channel_id=?) and type=? and status=1;';
$result = $this->queryAll($sql, [$p['channelid'], $p['type']]);
return isset($result[0]) ? $result[0] : ['notice_info' => ''];
}
/**
* 获取茶水费配置
* @param $p
* @return array
*/
public function getAgentServiceConfig(&$p)
{
$sql = 'select * from ct_agent_service where agent_id=? and channel_id=?;';
$result = $this->queryAll($sql, [$p['agentid'], $p['channelid']]);
return $result;
}
/**
* 单个茶水费配置
* @param $id
* @return array
*/
public function getAgentServiceConfigSingle($id)
{
$sql = 'select * from ct_agent_service where id=?;';
$result = $this->query($sql, [$id]);
return $result;
}
/**
* 单个茶水费配置
* @param $p
* @return array
*/
public function getAgentServiceConfigSave(&$p)
{
$sql = 'update ct_agent_service set min_value=?, max_value=?, `type`=?, `value`=? where id=?;';
$this->execute($sql, [$p['min_value'], $p['max_value'], $p['type'], $p['value'], $p['id']]);
}
}

View File

@@ -0,0 +1,106 @@
<?php
/**
* 控制器基类(父类)
*/
class Base
{
/**
* 记录日志
* @param $data
* @param string $tmp
*/
public function log($data, $tmp = '')
{
$str = date('H:m:s').' => '. $tmp .': ';
if(is_array($data))
$str .= json_encode($data);
else
$str .= $data;
file_put_contents('debug/'.date('Y-m-d').'.txt', $str . PHP_EOL, FILE_APPEND);
}
/**
* 用于调试
* @param $tmp
*/
public function debug($tmp)
{
echo '<pre>';
var_dump($tmp);
die;
}
/**
* 校验数据
* R => 必要的数据(不能为空)
* r => 必要的数据(可以为空)
* 数字类型 => 没有传递参数默认赋值
* 字符串 => 没有传递参数默认赋值
* @param $params
* @param $rule
* @return mixed
* @throws Exception
*/
public function checkParams(&$params, $rule)
{
$biz = $params->biz_content;
$tmp = [];
$res = [];
foreach ($rule as $v) {
$tmp = explode('/', $v);
switch ($tmp[1])
{
// 不能为空
case 'R':
if(!empty($biz[$tmp[0]])) {
$res[$tmp[0]] = $biz[$tmp[0]];
continue;
}
throw new Exception("请上传必要的数据({$tmp[0]}", 1001);
break;
// 必须上传
case 'r':
if(isset($biz[$tmp[0]])) {
$res[$tmp[0]] = $biz[$tmp[0]];
continue;
}
throw new Exception("请上传必要的数据({$tmp[0]}", 1002);
break;
// 数字
case 'd':
$res[$tmp[0]] = (isset($biz[$tmp[0]]) && is_numeric($biz[$tmp[0]])) ? intval($biz[$tmp[0]]) : intval($tmp[1]);
break;
// 字符串
case 's':
$res[$tmp[0]] = isset($biz[$tmp[0]]) ? strval($biz[$tmp[0]]) : strval($tmp[1]);
break;
// 手机号
case 'phone':
if(!preg_match('/^1[3456789]{1}\d{9}$/', $biz[$tmp[0]])) {
throw new Exception('请输入正确的手机号', 1003);
}
$res[$tmp[0]] = $biz[$tmp[0]];
break;
default:
throw new Exception('未定义的格式', 1009);
}
}
return $res;
}
}

View File

@@ -0,0 +1,104 @@
<?php
class Db
{
/**
* 数据查询实例
* @var null
*/
public static $Db = null;
private static function _init()
{
if(!self::$Db)
self::$Db = new BaseMethod();
}
/**
* 查询方法,返回单条数据
* @param $sql
* @param array $arr
* @return mixed
* @throws \Exception
*/
public static function query($sql, $arr = [])
{
self::_init();
$result = self::$Db->PDO_Request($sql, $arr);
if(!self::$Db->PDO_IsDone())
throw new Exception(self::$Db->GetErrorInfo(), 101);
if(isset($result[0]))
return $result[0];
return false;
}
/**
* 查询方法,返回多条数据
* @param $sql
* @param $arr
* @return array
* @throws \Exception
*/
public static function queryAll($sql, $arr = [])
{
self::_init();
$result = self::$Db->PDO_Request($sql, $arr);
if(!self::$Db->PDO_IsDone())
throw new Exception(self::$Db->GetErrorInfo(), 102);
return $result;
}
/**
* 只执行sql语句不反回结果
* @param $sql
* @param array $arr
* @return bool
* @throws \Exception
*/
public static function execute($sql, $arr = [])
{
self::_init();
$ret = self::$Db->PDO_Execute($sql, $arr);
if(!$ret || !self::$Db->PDO_IsDone())
throw new \Exception(self::$Db->GetErrorInfo(), 103);
return true;
}
/**
* 开启事务
*/
public static function beginTransaction()
{
self::_init();
self::$Db->PDO_BeginTransaction();
}
/**
* 提交一个事务
*/
public static function commit()
{
self::$Db->PDO_Commit();
}
/**
* 回滚一个事务
*/
public static function rollBack()
{
self::$Db->PDO_Rollback();
}
}

View File

@@ -0,0 +1,24 @@
<?php
class SalesModel
{
/**
* 手机号是否注册过
* 已注册返回 true否则 false
*/
public function isRegisterPhone($agent_id, $channel_id, $phone)
{
$sql = 'select * from sales_user where saus_agentid = ? AND saus_channelid = ? AND saus_tel = ?';
$result = Db::query($sql, [$agent_id, $channel_id, $phone]);
if($result)
return true;
return false;
}
public function sendPhoneCode()
{
}
}

View File

@@ -0,0 +1,277 @@
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2017/11/14
* Time: 11:30
*/
namespace models;
class SalesUser extends \core\Model
{
/**
* 查询代理信息,管理员版
* @param $params
* @return mixed
*/
public function querySalesInfo(&$params)
{
$sql = /** @lang text */'select
saus_nickname as nickname,
saus_parentid as parentid,
saus_roomcard as roomcard,
saus_bean as star,
password,
statistic_type,
global_power,
is_vip,
announcement
from sales_user where saus_salesid = ? and saus_agentid = ? and saus_channelid = ?;';
$result = $this->query($sql, [$params['salesid'], $params['agentid'], $params['channelid']]);
return $result;
}
/**
* 设置代理信息,管理员版
* @param $p
*/
public function setSalesInfo(&$p)
{
// 兼容
if(empty($p['parentid'])) $p['parentid'] = null;
$sql = /** @lang text */'update sales_user set saus_parentid = ?, global_power = ?, statistic_type = ?, is_vip=?, announcement=?
where saus_salesid = ? and saus_agentid = ? and saus_channelid = ? LIMIT 1;';
$this->execute($sql, [$p['parentid'], $p['global_power'], $p['statistic_type'], $p['is_vip'], $p['announcement'], $p['salesid'], $p['agentid'], $p['channelid']]);
}
/**
* 管理员给玩家充值房卡或星星
*/
public function playerRecharge(&$p)
{
/*$sql = 'select play_roomcard as card, play_bean as star from player WHERE play_agentid = ? and play_channelid = ? and play_playerid = ? LIMIT 1;';
$user_info = $this->query($sql, [$p['agentid'], $p['channelid'], $p['userid']]);*/
// 通过游戏的接口获取实时的玩家信息
$player_data = array(
'app' => 'youle',
'route' => 'agent',
'rpc' => 'query_player2',
'data' => array(
'agentid' => $p['agentid'],
'playerid' => $p['userid'],
),
);
$player_info = file_get_contents(REQUEST_USER_INFO . '?' . json_encode($player_data));
if(!$player_info) throw new \Exception('获取玩家信息错误', 1103);
$player_info = json_decode($player_info, true);
$user_info = $player_info['data'];
if(!isset($user_info['roomcard']) || !isset($user_info['bean']))
throw new \Exception('获取玩家信息错误', 1100);
// 判断是房卡还是星星
if($p['p_type'] === 1) {
$before = $user_info['roomcard'];
$sql = /** @lang text */'insert into ct_user_process_log(
from_agent, from_channel, from_user, to_agent, to_channel,
to_user, oper_type, oper_data, remark, oper_time,
is_process)
values (
?, ?, ?, ?, ?,
?, 2, ?, ?, ?,
?);';
} elseif($p['p_type'] === 2) {
$before = $user_info['bean'];
$sql = /** @lang text */'insert into ct_user_process_log(
from_agent, from_channel, from_user, to_agent, to_channel,
to_user, oper_type, oper_data, remark, oper_time,
is_process)
values (
?, ?, ?, ?, ?,
?, 12, ?, ?, ?,
?);';
} else {
throw new \Exception('充值类型错误', 1101);
}
$this->beginTransaction();
try {
// 插入日志
$this->query($sql, [
$p['agentid'], $p['channelid'], $p['adminid'], $p['agentid'], $p['channelid'],
$p['userid'], $p['amount'], '管理员充值', time(), 0
]);
$sql = /** @lang text */'insert into ct_manager_production_info (
agent_id, channel_id, from_user, to_user, user_type, production_type,
amount, before_update, after_update, oper_type, create_time, source_from,
remark)
values (
?,?,1,?,?,?,
?,?,?,1,now(),?,
?);';
$this->query($sql, [$p['agentid'], $p['channelid'], $p['userid'], $p['u_type'], $p['p_type'],
$p['amount'], $before, ($before + $p['amount']), $p['adminid'], '管理员充值']);
$this->commit();
} catch (\Exception $e) {
$this->rollBack();
throw $e;
}
}
/**
* 管理员给代理充值房卡或星星
* @param $p
* @throws \Exception
*/
public function salesRecharge(&$p)
{
$sql = /** @lang text */'select user_id, saus_roomcard card, saus_bean bean, diamond from sales_user where saus_agentid = ? and saus_channelid = ? and saus_salesid = ?';
$user_info = $this->query($sql, [$p['agentid'], $p['channelid'], $p['userid']]);
if(empty($user_info))
throw new \Exception('获取代理的信息错误', 1100);
$this->beginTransaction();
try {
/// 判断是房卡还是星星
switch ($p['p_type']) {
case 1:
$before = $user_info['card'];
// 校验数量
if(($before + $p['amount']) < 0) throw new \Exception('数量不足', 1102);
$sql = /** @lang text */'update sales_user set saus_roomcard = saus_roomcard + ? where saus_agentid = ? and saus_channelid = ? and saus_salesid = ? limit 1;';
$ret = self::$Db->pdo_execute($sql, $p['amount'], $p['agentid'], $p['channelid'], $p['userid']);
if (!$ret)
throw new \Exception(self::$Db->geterrorinfo(), self::$Db->geterrorcode());
if (!empty($user_info['user_id'])) {
$sql = /** @lang text */'update ct_user_account set card = card + ? where user_id = ?';
$ret = self::$Db->pdo_execute($sql, $p['amount'], $user_info['user_id']);
if (!$ret)
throw new \Exception(self::$Db->geterrorinfo(), self::$Db->geterrorcode());
}
break;
case 2:
$before = $user_info['bean'];
// 校验数量
if(($before + $p['amount']) < 0) throw new \Exception('数量不足', 1102);
$sql = /** @lang text */'update sales_user set saus_bean = saus_bean + ? where saus_agentid = ? and saus_channelid = ? and saus_salesid = ? limit 1;';
$ret = self::$Db->pdo_execute($sql, $p['amount'], $p['agentid'], $p['channelid'], $p['userid']);
if (!$ret)
throw new \Exception(self::$Db->geterrorinfo(), self::$Db->geterrorcode());
if (!empty($user_info['user_id'])) {
$sql = /** @lang text */'update ct_user_account set currency = currency + ? where user_id = ?';
$ret = self::$Db->pdo_execute($sql, $p['amount'], $user_info['user_id']);
if (!$ret)
throw new \Exception(self::$Db->geterrorinfo(), self::$Db->geterrorcode());
}
break;
default:
throw new \Exception('充值类型错误', 1101);
break;
}
$sql = /** @lang text */<<<EOL
insert into ct_manager_production_info (
agent_id, channel_id, from_user, to_user, user_type, production_type,
amount, before_update, after_update, oper_type, create_time, source_from,
remark)
values (
?,?,1,?,?,?,
?,?,?,1,now(),?,
?)
EOL;
$this->query($sql, [$p['agentid'], $p['channelid'], $p['userid'], $p['u_type'], $p['p_type'],
$p['amount'], $before, ($before + $p['amount']), $p['adminid'], '管理员充值']);
$this->commit();
} catch (\Exception $e) {
$this->rollBack();
throw $e;
}
}
/**
* 获取代理银行账户信息
* @param $params
* @return mixed
*/
public function getSalesBankInfo(&$params)
{
$sql =/** @lang text */ 'select
saus_realname,
saus_wechat,
saus_alipay,
saus_kaihu_name,
saus_kaihu_bank,
saus_kaihu_zhihang,
saus_kaihu_count
from sales_user WHERE saus_salesid = ? and saus_agentid = ? and saus_channelid = ?;';
$result = $this->query($sql, [$params['salesid'], $params['agentid'], $params['channelid']]);
return $result;
}
/**
* 获取玩家的上级
* @param $p
* @return array
*/
public function getPlayerParentInfo(&$p)
{
$sql = 'select play_playerid, play_nickname, play_invitecode from player where play_agentid=? and play_channelid=? and play_playerid=?';
$player = $this->query($sql, [$p['agentid'], $p['channelid'], $p['playerid']]);
$sql = 'select saus_salesid, saus_nickname, saus_invitecode, saus_parentid, player_id from sales_user where saus_agentid=? and saus_channelid=? and player_id=?';
$sales = $this->query($sql, [$p['agentid'], $p['channelid'], $p['playerid']]);
return ['playerinfo' => $player, 'salesinfo' => $sales];
}
public function setPlayerParent(&$p)
{
if(empty($p['parentid']))
$p['parentid'] = null;
$this->beginTransaction();
try {
$sql = 'select idx from player where play_agentid=? and play_channelid=? and play_playerid=? limit 1';
$res = $this->query($sql, [$p['agentid'], $p['channelid'], $p['playerid']]);
if(!$res)
throw new \Exception('玩家表信息不存在', 1000);
$sql = 'select idx from sales_user where saus_agentid=? and saus_channelid=? and player_id=? limit 1';
$res = $this->query($sql, [$p['agentid'], $p['channelid'], $p['playerid']]);
if(!$res)
throw new \Exception('推广员表信息不存在', 1000);
$sql = 'update player set play_invitecode=? where play_agentid=? and play_channelid=? and play_playerid=? limit 1';
$this->execute($sql, [$p['parentid'], $p['agentid'], $p['channelid'], $p['playerid']]);
$sql = 'update sales_user set saus_invitecode=? where saus_agentid=? and saus_channelid=? and player_id=? limit 1';
$this->execute($sql, [$p['parentid'], $p['agentid'], $p['channelid'], $p['playerid']]);
$this->commit();
return true;
} catch (\Exception $e) {
$this->rollBack();
throw $e;
}
}
}

View File

@@ -0,0 +1,31 @@
<?php
require_once APP_PATH.'/sms.php';
class Tools
{
/**
* 发送手机验证码
* @param $phone
* @param int $captcha
* @param bool $is_debug
* @return int
* @throws Exception
*/
public function sendCaptcha($phone, $captcha = 0, $is_debug = false)
{
$rand_code = !empty($captcha) ? $captcha : rand(100000, 999999);
// 是否是测试状态
if(!$is_debug) {
$sms = new sms();
$result = $sms->_SendSms(7, array('code' => $rand_code, 'product' => '代理'), $phone);
if ( !is_null($result)) {
throw new Exception('短信发送太频繁,请稍候再试', ERRORCODE_SMSSENDERROR);
}
}
return $rand_code;
}
}