添加后台代理代码

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

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,285 @@
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2017/7/3
* Time: 21:36
*/
class game extends BaseMethod
{
/**
* 获取产品列表
* 被请求方法示例参数固定为RequestParameter和ReturnParameter对象返回值固定为true(成功)和false(失败)
* @param RequestParameter $inParam
* @param ReturnParameter $outParam
* @return bool
*
*/
public function productList($inParam, $outParam)
{
$request_data = isset($inParam->biz_content) ? $inParam->biz_content : '';
if (!is_array($request_data)) {
//参数格式错误
$outParam->SetErrors(ERRORCODE_INPARAMERROR, ERRORINFO_INPARAMERROR);
return false;
}
$agentID = isset($request_data['agentid']) ? $request_data['agentid'] : '';
if(empty($agentID))
{
$outParam->SetErrors(ERRORCODE_AGENTIDERROR, ERRORINFO_AGENTIDERROR);
return false;
}
$type = isset($request_data['type']) ? intval($request_data['type']) : '';
if($type === '')
{
$outParam->SetErrors(ERRORCODE_TYPEERROR, ERRORINFO_TYPEERROR);
return false;
}
$productType = isset($request_data['ptype']) ? intval($request_data['ptype']) : 0;
$pro_list = $this->PDO_Request('
SELECT
sapr_productid as productid, sapr_name as name, sapr_amount as amount, sapr_money as money,
sapr_memo as memo
FROM
sales_product
WHERE
sapr_agentid = ? and sapr_type = ? and sapr_state = 0 and product_type = ?
ORDER BY idx;', $agentID, $type, $productType);
if(!is_array($pro_list))
{
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
return false;
}
$outParam->biz_content = array('state' => 0, 'products' => $pro_list);
return true;
}
/**
* 获公告列表
* 被请求方法示例参数固定为RequestParameter和ReturnParameter对象返回值固定为true(成功)和false(失败)
* @param RequestParameter $inParam
* @param ReturnParameter $outParam
* @return bool
*
*/
public function noticeList($inParam, $outParam)
{
$request_data = isset($inParam->biz_content) ? $inParam->biz_content : '';
if (!is_array($request_data)) {
//参数格式错误
$outParam->SetErrors(ERRORCODE_INPARAMERROR, ERRORINFO_INPARAMERROR);
return false;
}
$agentID = isset($request_data['agentid']) ? $request_data['agentid'] : '';
if(empty($agentID))
{
$outParam->SetErrors(ERRORCODE_AGENTIDERROR, ERRORINFO_AGENTIDERROR);
return false;
}
$db_data = $this->PDO_Request("
SELECT
sano_noticeid as noticeid, sano_title as title, sano_time as time
FROM
sales_notice
WHERE
sano_agentid = ? and (sano_begintime is null or now() >= sano_begintime)
and (sano_endtime is null or now() <= sano_endtime);", $agentID);
if(!is_array($db_data))
{
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
return false;
}
$outParam->biz_content = array('list' => $db_data);
return true;
}
/**
* 获公告详情
* 被请求方法示例参数固定为RequestParameter和ReturnParameter对象返回值固定为true(成功)和false(失败)
* @param RequestParameter $inParam
* @param ReturnParameter $outParam
* @return bool
*
*/
public function noticeDetail($inParam, $outParam)
{
$request_data = isset($inParam->biz_content) ? $inParam->biz_content : '';
if (!is_array($request_data)) {
//参数格式错误
$outParam->SetErrors(ERRORCODE_INPARAMERROR, ERRORINFO_INPARAMERROR);
return false;
}
$agentID = isset($request_data['agentid']) ? $request_data['agentid'] : '';
if(empty($agentID))
{
$outParam->SetErrors(ERRORCODE_AGENTIDERROR, ERRORINFO_AGENTIDERROR);
return false;
}
$noticeID = isset($request_data['noticeid']) ? $request_data['noticeid'] : '';
if(empty($noticeID))
{
$outParam->SetErrors(ERRORCODE_NOTICEIDERROR, ERRORINFO_NOTICEIDERROR);
return false;
}
$db_data = $this->PDO_Request("
SELECT
sano_title as title, sano_time as time, sano_content as content
FROM
sales_notice
WHERE
sano_agentid = ? and sano_noticeid = ? ;", $agentID, $noticeID);
if(!is_array($db_data))
{
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
return false;
}
if(count($db_data) < 1)
{
return false;
}
$outParam->biz_content = array(
'title' => isset($db_data[0]['title']) ? $db_data[0]['title'] : '',
'time' => isset($db_data[0]['time']) ? $db_data[0]['time'] : '',
'content' => isset($db_data[0]['content']) ? $db_data[0]['content'] : '',
);
return true;
}
/**
* 游戏下载列表
* 被请求方法示例参数固定为RequestParameter和ReturnParameter对象返回值固定为true(成功)和false(失败)
* @param RequestParameter $inParam
* @param ReturnParameter $outParam
* @return bool
*
*/
public function downList($inParam, $outParam)
{
$request_data = isset($inParam->biz_content) ? $inParam->biz_content : '';
if (!is_array($request_data)) {
//参数格式错误
$outParam->SetErrors(ERRORCODE_INPARAMERROR, ERRORINFO_INPARAMERROR);
return false;
}
$agentID = isset($request_data['agentid']) ? $request_data['agentid'] : '';
if(empty($agentID))
{
$outParam->SetErrors(ERRORCODE_AGENTIDERROR, ERRORINFO_AGENTIDERROR);
return false;
}
$channelID = isset($request_data['channelid']) ? $request_data['channelid'] : '';
if(empty($agentID))
{
$outParam->SetErrors(ERRORCODE_CHANNELIDERROR, ERRORINFO_CHANNELIDERROR);
return false;
}
/*$agent_data = $this->PDO_Request('
SELECT
html_buyroomcard
FROM
config_agent
WHERE
agent_id=?', $agentID);
if(!is_array($agent_data))
{
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
return false;
}
if(count($agent_data) < 1)
{
$outParam->SetErrors(ERRORCODE_AGENTNOTEXISTERROR, ERRORINFO_AGENTNOTEXISTERROR);
return false;
}*/
/*$maket_data = $this->PDO_Request('
SELECT
a.game_id, a.game_name, a.game_down_image, a.game_down_state, a.game_down_memo,
b.ios_download, b.and_download,
c.market_id, c.market_name, c.app_download, c.app_size
FROM
config_game a
LEFT JOIN config_channel b ON a.game_id=b.game_id
LEFT JOIN config_market c ON b.channel_id=c.channel_id
WHERE
a.agent_id=? AND b.channel_id=? ', $agentID, $channelID);*/
$maket_data = $this->PDO_Request('
SELECT
a.game_id, a.game_name as name, a.game_down_image as image, a.game_down_state as state, a.game_down_memo as memo,
b.ios_download as ios_down, b.and_download as android_down, b.ios_market_id as ios_marketid, b.ios_app_size as ios_size, b.and_app_size as android_size
FROM
config_game a
LEFT JOIN config_channel b ON a.game_id=b.game_id
WHERE
a.agent_id=? AND b.channel_id=? and b.and_download != ""', $agentID, $channelID);
if(!is_array($maket_data))
{
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
return false;
}
if(count($maket_data) < 1)
{
$outParam->SetErrors(ERRORCODE_AGENTNOTEXISTERROR, ERRORINFO_AGENTNOTEXISTERROR);
return false;
}
/*
$data = array();
$data['name'] = $maket_data[0]['game_name'];
$data['image'] = $maket_data[0]['game_down_image'];
$data['state'] = $maket_data[0]['game_down_state'];
$data['memo'] = $maket_data[0]['game_down_memo'];
foreach($maket_data as $item)
{
if($item['ios_download'] == $item['market_id'])
{
$data['ios_down'] = $item['app_download'];
$data['ios_size'] = $item['app_size'];
$data['ios_marketid'] = $item['market_id'];
}
if($item['and_download'] == $item['market_id'])
{
$data['android_down'] = $item['app_download'];
$data['android_size'] = $item['app_size'];
}
}
*/
$outParam->biz_content = array(
//'html_buyroomcard' => isset($agent_data[0]['html_buyroomcard']) ? $agent_data[0]['html_buyroomcard'] : '',
'list' => $maket_data
);
return true;
}
}

View File

@@ -0,0 +1,666 @@
<?php
/**
* Created by PhpStorm.
* User: bahamut
* Date: 2018/6/6
* Time: 9:11
*/
class gift extends BaseMethod
{
/**
* 被请求方法示例参数固定为RequestParameter和ReturnParameter对象返回值固定为true(成功)和false(失败)
* @note 创建礼包
* @param RequestParameter $request
* @param ReturnParameter $return
* @return bool
*/
public function newgift($request, $return)
{
$param = (array)@$request->biz_content;
$agent_id = @$param['agentid']; /// 代理编号
$channel_id = @$param['channelid']; /// 渠道编号
$sales_id = @$param['salesid']; /// 代理编号
$type = @$param['type']; /// 类型1房卡2星星
$amount = @$param['amount']; /// 数量
if (empty($agent_id))
{
$return->seterrors(ERRORCODE_AGENTIDERROR, ERRORINFO_AGENTIDERROR);
return false;
}
if (empty($channel_id))
{
$return->seterrors(ERRORCODE_CHANNELIDERROR, ERRORINFO_CHANNELIDERROR);
return false;
}
if (empty($sales_id))
{
$return->seterrors(ERRORCODE_SALESIDERROR, ERRORINFO_SALESIDERROR);
return false;
}
$this->pdo_begintransaction();
try
{
/// 查询代理信息
$command = /** @lang text */'select user_id, saus_roomcard, saus_bean from sales_user where saus_agentid = ? and saus_channelid = ? and saus_salesid = ?';
$sales_info = $this->pdo_request($command, $agent_id, $channel_id, $sales_id);
if (!$this->pdo_isdone())
throw new Exception($this->geterrorinfo(), $this->geterrorcode());
elseif (empty($sales_info))
throw new Exception(ERRORINFO_SALESNOTEXISTERROR, ERRORCODE_SALESNOTEXISTERROR);
else
$sales_info = $sales_info[0];
/// 判断数量
switch (intval($type))
{
case 1; /// 房卡
$amount = intval($amount);
if ($amount > $sales_info['saus_roomcard'])
throw new Exception(ERRORINFO_ROOMCARDENOUGHERROR, ERRORCODE_ROOMCARDENOUGHERROR);
/// 修改账户
$command = /** @lang text */'update sales_user set saus_roomcard = saus_roomcard - ? where saus_agentid = ? and saus_channelid = ? and saus_salesid = ?';
/// 修改账户余额
$ret = $this->pdo_execute($command, $amount, $agent_id, $channel_id, $sales_id);
if (!$ret)
throw new Exception($this->geterrorinfo(), $this->geterrorcode());
/// 如果有统一账户,则需要修改统一账户余额
if (!empty($sales_info['user_id']))
{
$command = /** @lang text */'update ct_user_account set card = card - ? where user_id = ?';
$ret = $this->pdo_execute($command, $amount, $sales_info['user_id']);
if (!$ret)
throw new Exception($this->geterrorinfo(), $this->geterrorcode());
}
break;
case 2: /// 星星
$amount = floatval($amount);
if ($amount > $sales_info['saus_bean'])
throw new Exception(ERRORINFO_ROOMCARDENOUGHERROR, ERRORCODE_ROOMCARDENOUGHERROR);
/// 修改账户
$command = /** @lang text */'update sales_user set saus_bean = saus_bean - ? where saus_agentid = ? and saus_channelid = ? and saus_salesid = ?';
/// 修改账户余额
$ret = $this->pdo_execute($command, $amount, $agent_id, $channel_id, $sales_id);
if (!$ret)
throw new Exception($this->geterrorinfo(), $this->geterrorcode());
/// 如果有统一账户,则需要修改统一账户余额
if (!empty($sales_info['user_id']))
{
$command = /** @lang text */'update ct_user_account set currency = currency - ? where user_id = ?';
$ret = $this->pdo_execute($command, $amount, $sales_info['user_id']);
if (!$ret)
throw new Exception($this->geterrorinfo(), $this->geterrorcode());
}
break;
default:
throw new Exception(ERRORINFO_TYPEERROR, ERRORINFO_TYPEERROR);
}
/// 加入流水记录
$command = /** @lang text */<<<EOL
insert into ct_gift_info
(agent_id, channel_id, sales_id, type, amount, status, create_time)
values
(?, ?, ?, ?, ?, 0, unix_timestamp())
EOL;
$ret = $this->pdo_execute($command, $agent_id, $channel_id, $sales_id, $type, $amount);
if (!$ret)
throw new Exception($this->geterrorinfo(), $this->geterrorcode());
$return->biz_content = [
'giftid' => $this->pdo_lastinsertid(),
];
$this->pdo_commit();
return true;
}
catch(Exception $Exception)
{
$this->pdo_rollback();
$return->seterrors($Exception->getcode(), $Exception->getmessage());
return false;
}
}
/**
* 被请求方法示例参数固定为RequestParameter和ReturnParameter对象返回值固定为true(成功)和false(失败)
* @note 领取礼包
* @param RequestParameter $request
* @param ReturnParameter $return
* @return bool
*/
public function receivegift($request, $return)
{
$param = (array)$request->biz_content;
$gift_id = @$param['giftid']; /// 礼包编号
$player_id = @$param['playerid']; /// 玩家编号
if (empty($gift_id))
{
$return->seterrors(ERRORCODE_GIFTIDERROR, ERRORINFO_GIFTIDERROR);
return false;
}
if (empty($player_id))
{
$return->seterrors(ERRORCODE_PLAYERIDERROR, ERRORINFO_PLAYERIDERROR);
return false;
}
$this->pdo_begintransaction();
try
{
/// 查询礼包是否存在
$command = /** @lang text */<<<EOL
select
id, agent_id, channel_id, sales_id, player_id,
type, amount, status, create_time, receive_time, order_id
from
ct_gift_info
where
id = ?
for update
EOL;
$gift_info = $this->pdo_request($command, $gift_id);
if (!$this->pdo_isdone())
throw new Exception($this->geterrorinfo(), $this->geterrorcode());
elseif (empty($gift_info))
throw new Exception(ERRORINFO_GIFTNOTEXISTS, ERRORCODE_GIFTNOTEXISTS);
else
$gift_info = $gift_info[0];
/// 状态不正确
if ($gift_info['status'] != 0)
throw new Exception(ERRORINFO_GIFTNOTEXISTS, ERRORCODE_GIFTNOTEXISTS);
/// 查询代理信息,分开查询是因为做关联查询反而比分成两次查询慢
$command = /** @lang text */'select saus_agentid, saus_channelid, saus_openid, saus_unionid, saus_power from sales_user where saus_agentid = ? and saus_channelid = ? and saus_salesid = ? and saus_status = 0';
$sales_info = $this->pdo_request($command, $gift_info['agent_id'], $gift_info['channel_id'], $gift_info['sales_id']);
if (!$this->pdo_isdone())
throw new Exception($this->geterrorinfo(), $this->geterrorcode());
elseif (empty($sales_info))
throw new Exception(ERRORINFO_SALESNOTEXISTERROR, ERRORCODE_SALESNOTEXISTERROR);
else
$sales_info = $sales_info[0];
/// 查询玩家信息
$command = /** @lang text */'select play_invitecode from player where play_agentid = ? and play_channelid = ? and play_playerid = ? and play_status = 0';
$player_info = $this->pdo_request($command, $gift_info['agent_id'], $gift_info['channel_id'], $player_id);
if (!$this->pdo_isdone())
throw new Exception($this->geterrorinfo(), $this->geterrorcode());
elseif (empty($player_info))
throw new Exception(ERRORINFO_PLAYERNOTEXISTERROR, ERRORCODE_PLAYERNOTEXISTERROR);
else
$player_info = $player_info[0];
/// 判断权限
switch (intval($sales_info['saus_power'][1]))
{
case 0: /// 无权限
throw new Exception(ERRORINFO_NOPOWERERROR, ERRORCODE_NOPOWERERROR);
break;
case 1: /// 需要判断是否绑定自己
if ($player_info['play_invitecode'] != $gift_info['sales_id'])
throw new Exception(ERRORINFO_ONLYBINDSELFERROR, ERRORCODE_ONLYBINDSELFERROR);
break;
case 2: /// 可以给所有代理转卡
break;
default:
throw new Exception(ERRORINFO_NOPOWERERROR, ERRORCODE_NOPOWERERROR);
break;
}
/// 判断类型
switch ($gift_info['type'])
{
case 1; /// 房卡
$amount = intval($gift_info['amount']);
/// 新增订单
$command = /** @lang text */<<<EOL
insert into sales_sellbill
(sase_agentid, channel_id, sase_openid, from_sales, sase_playerid, sase_amount, sase_selltime)
values
(?, ?, ?, ?, ?, ?, now())
EOL;
$ret = $this->pdo_execute($command, $sales_info['saus_agentid'], $sales_info['saus_channelid'], $sales_info['saus_openid'], $gift_info['sales_id'], $player_id, $amount);
if (!$ret)
throw new Exception($this->geterrorinfo(), $this->geterrorcode());
else
$order_id = $this->pdo_lastinsertid();
/// 记录同步流水
$command = /** @lang text */<<<EOL
insert into ct_user_process_log
(to_agent, to_channel, to_user, oper_type, oper_data, oper_time, is_process)
values
(?, ?, ?, 1, ?, unix_timestamp(), 0)
EOL;
$ret = $this->pdo_execute($command, $gift_info['agent_id'], $gift_info['channel_id'], $player_id, $amount);
if (!$ret)
throw new Exception($this->geterrorinfo(), $this->geterrorcode());
break;
case 2: /// 星星
$amount = floatval($gift_info['amount']);
/// 新增订单
$command = /** @lang text */<<<EOL
insert into sales_sellbill_bean
(ssbe_agentid, channel_id, ssbe_openid, from_sales, ssbe_playerid, ssbe_amount, ssbe_selltime)
values
(?, ?, ?, ?, ?, ?, now())
EOL;
$ret = $this->pdo_execute($command, $sales_info['saus_agentid'], $sales_info['saus_channelid'], $sales_info['saus_openid'], $gift_info['sales_id'], $player_id, $amount);
if (!$ret)
throw new Exception($this->geterrorinfo(), $this->geterrorcode());
else
$order_id = $this->pdo_lastinsertid();
/// 记录同步流水
$command = /** @lang text */<<<EOL
insert into ct_user_process_log
(to_agent, to_channel, to_user, oper_type, oper_data, oper_time, is_process)
values
(?, ?, ?, 11, ?, unix_timestamp(), 0)
EOL;
$ret = $this->pdo_execute($command, $gift_info['agent_id'], $gift_info['channel_id'], $player_id, $amount);
if (!$ret)
throw new Exception($this->geterrorinfo(), $this->geterrorcode());
break;
default:
throw new Exception(ERRORINFO_TYPEERROR, ERRORINFO_TYPEERROR);
}
/// 修改礼包状态
$command = /** @lang text */'update ct_gift_info set player_id = ?, status = 1, receive_time = unix_timestamp(), order_id = ? where id = ?';
$ret = $this->pdo_execute($command, $player_id, $order_id, $gift_id);
if (!$ret)
throw new Exception($this->geterrorinfo(), $this->geterrorcode());
$this->pdo_commit();
$return->biz_content = [
'amount' => $amount,
'product_type' => $gift_info['type'],
];
return true;
}
catch(Exception $Exception)
{
$this->pdo_rollback();
$return->seterrors($Exception->getcode(), $Exception->getmessage());
return false;
}
}
/**
* 被请求方法示例参数固定为RequestParameter和ReturnParameter对象返回值固定为true(成功)和false(失败)
* @note 领取礼包
* @param RequestParameter $request
* @param ReturnParameter $return
* @return bool
*/
public function querygift($request, $return)
{
/// method=agent.gift.querygift&format=json&charset=utf-8&timestamp=1&version=1.0&biz_content={"agentid":"a","channelid":"b","salesid":1,}&user_auth_token=xxxxxxxx&tag=tag&random_string=xxxxxx
$param = (array)$request->biz_content;
$agent_id = @$param['agentid']; /// 代理编号
$channel_id = @$param['channelid']; /// 渠道编号
$sales_id = @$param['salesid']; /// 代理编号
$page_index = @$param['pageindex']; /// 页序号0开始
$page_size = @$param['pagesize']; /// 页大小
if (empty($agent_id))
{
$return->seterrors(ERRORCODE_AGENTIDERROR, ERRORINFO_AGENTIDERROR);
return false;
}
if (empty($channel_id))
{
$return->seterrors(ERRORCODE_CHANNELIDERROR, ERRORINFO_CHANNELIDERROR);
return false;
}
if (empty($sales_id))
{
$return->seterrors(ERRORCODE_SALESIDERROR, ERRORINFO_SALESIDERROR);
return false;
}
if (empty($page_index))
$page_index = 0;
if (empty($page_size))
$page_size = 10;
$cmd = $this->NewMasterCommand();
$ret = $cmd
->select('id', 'agent_id', 'channel_id', 'sales_id', 'player_id', 'type', 'amount', 'status', 'create_time', 'receive_time', 'order_id')
->from('ct_gift_info')
->where('agent_id = ? and channel_id = ? and sales_id = ? and status = 0 and type in (1, 2)')
->bindparameters($agent_id, $channel_id, $sales_id)
->withpage($page_index, $page_size)
->request();
if (!$cmd->getconnection()->isdone())
{
$return->seterrors($cmd->getconnection()->geterrorcode(), $cmd->getconnection()->geterrorinfo());
return false;
}
$return->biz_content = [
'list' => $ret,
'pageindex' => $page_index,
'pagesize' => $page_size,
'recordcount' => 0,
];
if (empty($ret))
return true;
$ret = $cmd->request(/** @lang text */
'select count(0) c from ct_gift_info where agent_id = ? and channel_id = ? and sales_id = ? and status = 0 and type in (1, 2)',
$agent_id, $channel_id, $sales_id);
if (!$cmd->getconnection()->isdone())
{
$return->seterrors($cmd->getconnection()->geterrorcode(), $cmd->getconnection()->geterrorinfo());
return false;
}
$return->biz_content['recordcount'] = $ret[0]['c'];
return true;
}
/**
* 被请求方法示例参数固定为RequestParameter和ReturnParameter对象返回值固定为true(成功)和false(失败)
* @note 创建充值卡
* @param RequestParameter $request
* @param ReturnParameter $return
* @return bool
*/
public function newrechargecard($request, $return)
{
$param = (array)@$request->biz_content;
$agent_id = @$param['agentid']; /// 代理编号
$channel_id = @$param['channelid']; /// 渠道编号
$type = @$param['type']; /// 类型1房卡2星星
$amount = @$param['amount']; /// 数量
if (empty($agent_id))
{
$return->seterrors(ERRORCODE_AGENTIDERROR, ERRORINFO_AGENTIDERROR);
return false;
}
if (empty($channel_id))
{
$return->seterrors(ERRORCODE_CHANNELIDERROR, ERRORINFO_CHANNELIDERROR);
return false;
}
$this->pdo_begintransaction();
try
{
/// 判断数量
switch (intval($type))
{
case 1; /// 房卡
$type = 3; /// 房卡-充值卡密
do {
$card_number = sprintf('%s%06d', date('YmdHis'), rand(1, 999999));
$card_password = sprintf('%06d', rand(1, 999999));
$ret = $this->pdo_request(/** @lang text */'select 1 from ct_gift_info where card_number = ?', $card_number);
if (!$this->pdo_isdone())
throw new Exception($this->geterrorinfo(), $this->geterrorcode());
} while (!empty($ret));
break;
case 2: /// 星星
$type = 4; /// 星星-充值卡密
do {
$card_number = sprintf('%s%06d', date('YmdHis'), rand(1, 999999));
$card_password = sprintf('%06d', rand(1, 999999));
$ret = $this->pdo_request(/** @lang text */'select 1 from ct_gift_info where card_number = ?', $card_number);
if (!$this->pdo_isdone())
throw new Exception($this->geterrorinfo(), $this->geterrorcode());
} while (!empty($ret));
break;
default:
throw new Exception(ERRORINFO_TYPEERROR, ERRORINFO_TYPEERROR);
}
/// 加入流水记录
$command = /** @lang text */<<<EOL
insert into ct_gift_info
(agent_id, channel_id, sales_id, type, amount, status, create_time, card_number, card_password)
values
(?, ?, null, ?, ?, 0, unix_timestamp(), ?, ?)
EOL;
$ret = $this->pdo_execute($command, $agent_id, $channel_id, $type, $amount, $card_number, $card_password);
if (!$ret)
throw new Exception($this->geterrorinfo(), $this->geterrorcode());
$return->biz_content = [
'card_number' => $card_number,
'card_password' => $card_password,
'card_type' => $type,
'product_amount' => $amount,
];
$this->pdo_commit();
return true;
}
catch(Exception $Exception)
{
$this->pdo_rollback();
$return->seterrors($Exception->getcode(), $Exception->getmessage());
return false;
}
}
/**
* 被请求方法示例参数固定为RequestParameter和ReturnParameter对象返回值固定为true(成功)和false(失败)
* @note 使用充值卡密
* @param RequestParameter $request
* @param ReturnParameter $return
* @return bool
*/
public function userechargecard($request, $return)
{
$param = (array)@$request->biz_content;
$card_number = @$param['cardnumber']; /// 卡号
$card_password = @$param['cardpassword']; /// 密码
$sales_id = @$param['salesid']; /// 代理编号
//$player_id = @$param['playerid']; /// 玩家编号
if (empty($card_number))
{
$return->seterrors(ERRORCODE_CARDNUMBERERROR, ERRORINFO_CARDNUMBERERROR);
return false;
}
$cmd = /** @lang text */'select id from ct_gift_info where card_number = ? and card_password = ?';
$ret = $this->pdo_request($cmd, $card_number, $card_password);
if (!$this->pdo_isdone())
{
$return->seterrors($this->geterrorcode(), $this->geterrorinfo());
return false;
}
elseif (empty($ret))
{
//$return->seterrors(ERRORCODE_CARDNUMBERNOTEXISTS, ERRORINFO_CARDNUMBERNOTEXISTS);
$return->seterrors(ERRORCODE_CARDNUMBERERROR, ERRORINFO_CARDNUMBERERROR);
return false;
}
$id = $ret[0]['id'];
$this->pdo_begintransaction();
try
{
/// 查询礼包是否存在
$cmd = /** @lang text */<<<EOL
select
id, agent_id, channel_id, sales_id, player_id,
type, amount, status, create_time, receive_time, order_id
from
ct_gift_info
where
id = ?
for update
EOL;
$gift_info = $this->pdo_request($cmd, $id);
if (!$this->pdo_isdone())
throw new Exception($this->geterrorinfo(), $this->geterrorcode());
elseif (empty($gift_info))
throw new Exception(ERRORINFO_GIFTNOTEXISTS, ERRORCODE_GIFTNOTEXISTS);
else
$gift_info = $gift_info[0];
/// 状态不正确
if ($gift_info['status'] != 0)
throw new Exception(ERRORINFO_GIFTNOTEXISTS, ERRORCODE_GIFTNOTEXISTS);
/// 查询代理信息,分开查询是因为做关联查询反而比分成两次查询慢
$command = /** @lang text */'select user_id, saus_agentid, saus_channelid, saus_openid, saus_unionid, saus_power from sales_user where saus_agentid = ? and saus_channelid = ? and saus_salesid = ? and saus_status = 0';
$sales_info = $this->pdo_request($command, $gift_info['agent_id'], $gift_info['channel_id'], $sales_id);
if (!$this->pdo_isdone())
throw new Exception($this->geterrorinfo(), $this->geterrorcode());
elseif (empty($sales_info))
throw new Exception(ERRORINFO_SALESNOTEXISTERROR, ERRORCODE_SALESNOTEXISTERROR);
else
$sales_info = $sales_info[0];
/// 判断类型
switch ($gift_info['type'])
{
case 3; /// 房卡-充值卡密
$amount = intval($gift_info['amount']);
/// 新增订单
$command = /** @lang text */<<<EOL
insert into sales_transferbill
(satr_agentid, channel_id, satr_openid, from_sales, satr_salesid, satr_amount, satr_transfertime)
values
(?, ?, ?, ?, ?, ?, now())
EOL;
$ret = $this->pdo_execute($command, $sales_info['saus_agentid'], $sales_info['saus_channelid'], 'system', 0, $sales_id, $amount);
if (!$ret)
throw new Exception($this->geterrorinfo(), $this->geterrorcode());
else
$order_id = $this->pdo_lastinsertid();
/// 修改账户余额
$command = /** @lang text */'update sales_user set saus_roomcard = saus_roomcard + ? where saus_agentid = ? and saus_channelid = ? and saus_salesid = ?';
/// 修改账户余额
$ret = $this->pdo_execute($command, $amount, $sales_info['saus_agentid'], $sales_info['saus_channelid'], $sales_id);
if (!$ret)
throw new Exception($this->geterrorinfo(), $this->geterrorcode());
/// 如果有统一账户,则需要修改统一账户余额
if (!empty($sales_info['user_id']))
{
$command = /** @lang text */'update ct_user_account set card = card + ? where user_id = ?';
$ret = $this->pdo_execute($command, $amount, $sales_info['user_id']);
if (!$ret)
throw new Exception($this->geterrorinfo(), $this->geterrorcode());
}
break;
case 4: /// 星星-充值卡密
$amount = floatval($gift_info['amount']);
/// 新增订单
$command = /** @lang text */<<<EOL
insert into trans_star_record
(agent_id, channel_id, union_id, open_id, send_id, get_id, type, amount, op_time)
values
(?, ?, ?, ?, 0, ?, 0, ?, now())
EOL;
$ret = $this->pdo_execute($command, $sales_info['saus_agentid'], $sales_info['saus_channelid'], 'system', 'system', $sales_id, $amount);
if (!$ret)
throw new Exception($this->geterrorinfo(), $this->geterrorcode());
else
$order_id = $this->pdo_lastinsertid();
/// 修改账户
$command = /** @lang text */'update sales_user set saus_bean = saus_bean + ? where saus_agentid = ? and saus_channelid = ? and saus_salesid = ?';
/// 修改账户余额
$ret = $this->pdo_execute($command, $amount, $sales_info['saus_agentid'], $sales_info['saus_channelid'], $sales_id);
if (!$ret)
throw new Exception($this->geterrorinfo(), $this->geterrorcode());
/// 如果有统一账户,则需要修改统一账户余额
if (!empty($sales_info['user_id']))
{
$command = /** @lang text */'update ct_user_account set currency = currency + ? where user_id = ?';
$ret = $this->pdo_execute($command, $amount, $sales_info['user_id']);
if (!$ret)
throw new Exception($this->geterrorinfo(), $this->geterrorcode());
}
break;
default:
throw new Exception(ERRORINFO_TYPEERROR, ERRORINFO_TYPEERROR);
}
/// 修改礼包状态
$command = /** @lang text */'update ct_gift_info set sales_id = ?, status = 1, receive_time = unix_timestamp(), order_id = ? where id = ?';
$ret = $this->pdo_execute($command, $sales_id, $order_id, $id);
if (!$ret)
throw new Exception($this->geterrorinfo(), $this->geterrorcode());
$this->pdo_commit();
$return->biz_content = [
'amount' => $amount,
'product_type' => $gift_info['type'],
];
return true;
}
catch(Exception $Exception)
{
$this->pdo_rollback();
$return->seterrors($Exception->getcode(), $Exception->getmessage());
return false;
}
}
}

View File

@@ -0,0 +1,390 @@
<?php
/******************************************************************************************
* ================ summer 2017/11/6 Handel 管理部分业务 ====================== *
*****************************************************************************************/
class manage extends BaseMethod
{
##------------ 公告管理[curd]
##------------[ct_agent_notice] ------------------------->
/**
* 发布公告
* @param RequestParameter $inParam
* @param ReturnParameter $outParam
* @return bool
*/
public function addAgentNotice($inParam, $outParam)
{
// 1、系统非空数据配置初始化
$config = array(
# 代理商id
'agentID' => array(
'name' => 'agentid',
'errcode' => ERRORCODE_AGENTIDERROR,
'errinfo' => ERRORINFO_AGENTIDERROR,
),
# 渠道商id
'channelID' => array(
'name' => 'channelid',
'errcode' => ERRORCODE_CHANNELIDERROR,
'errinfo' => ERRORINFO_CHANNELIDERROR,
),
# 个人代理id
'salesID' => array(
'name' => 'salesid',
'errcode' => ERRORCODE_SALESIDERROR,
'errinfo' => ERRORINFO_SALESIDERROR,
),
# 公告内容
'noticeInfo' => array(
'name' => 'content',
'errcode' => 'H00001',
'errinfo' => '公告内容不能为空',
),
);
// 2、数据处理后的结果集 异常标志errtrue false
$param = $this->inParamHandel($inParam, $outParam, $config);
if (!$param)
{
return false;
}
// 验证总代权限
$auth = $this->checkAgentAuth($inParam, $outParam, $param['agentID'], $param['channelID'], $param['salesID']);
if (!$auth)
{
return false;
}
// 通知入库
$res = $this->PDO_Execute(
'
INSERT INTO
ct_agent_notice(agent_id, channel_id, notice_info, create_time, status)
VALUES (?, ?, ?, ?, ?)',
$param['agentID'], $param['channelID'], $param['noticeInfo'], date('Y-m-d H:i:s', time()), 1
);
if (!$res)
{
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
return false;
}
return true;
}
/**
* [改]修改公告内容 公告状态
* author summer
*/
public function editAgentNotice($inParam, $outParam)
{
$config = array(
# 代理商id
'agentID' => array(
'name' => 'agentid',
'errcode' => ERRORCODE_AGENTIDERROR,
'errinfo' => ERRORINFO_AGENTIDERROR,
),
# 渠道商id
'channelID' => array(
'name' => 'channelid',
'errcode' => ERRORCODE_CHANNELIDERROR,
'errinfo' => ERRORINFO_CHANNELIDERROR,
),
# 个人代理id
'salesID' => array(
'name' => 'salesid',
'errcode' => ERRORCODE_SALESIDERROR,
'errinfo' => ERRORINFO_SALESIDERROR,
),
# 操作记录id
'id' => array(
'name' => 'id',
'errcode' => 'H00001',
'errinfo' => 'id不能为空',
)
);
// 2、数据处理后的结果集 异常标志errtrue false
$param = $this->inParamHandel($inParam, $outParam, $config);
if (!$param)
{
return false;
}
// 3、权限验证
$auth = $this->checkAgentAuth($inParam, $outParam, $param['agentID'], $param['channelID'], $param['salesID']);
if (!$auth)
{
return false;
}
// 4、业务逻辑部分
#a.查看公告是否存在
$item = $this->PDO_Request(
'
select
*
from
ct_agent_notice
where
id = ?; ', $param['id']
);
if (!$item)
{
$outParam->SetErrors(ERRORCODE_COMMISSIONNOTEXISTERROR, ERRORINFO_COMMISSIONNOTEXISTERROR);
return false;
}
// 传了几个改几个
$status = isset($param['_params']['status']) ? $param['_params']['status'] : $item[0]['status']; // 修改状态
$content = isset($param['_params']['content']) ? $param['_params']['content'] : $item[0]['notice_info']; // 内容
// 更新公告
$this->PDO_Execute(
'
update
ct_agent_notice
set
notice_info = ?, status = ?
where
id = ?; ', $content, $status, $param['id']
);
if (!$this->PDO_IsDone())
{
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
return false;
}
return true;
}
/**
* [查]查询公告 pc后台
* author summer
*/
public function getAgentNotice($inParam, $outParam)
{
// 1、系统非空数据配置初始化
$config = array(
# 代理商id
'agentID' => array(
'name' => 'agentid',
'errcode' => ERRORCODE_AGENTIDERROR,
'errinfo' => ERRORINFO_AGENTIDERROR,
),
# 渠道商id
'channelID' => array(
'name' => 'channelid',
'errcode' => ERRORCODE_CHANNELIDERROR,
'errinfo' => ERRORINFO_CHANNELIDERROR,
),
# 个人代理id
'salesID' => array(
'name' => 'salesid',
'errcode' => ERRORCODE_SALESIDERROR,
'errinfo' => ERRORINFO_SALESIDERROR,
),
);
// 2、数据处理后的结果集 异常标志errtrue false
$param = $this->inParamHandel($inParam, $outParam, $config);
if (!$param)
{
return false;
}
//3.1 可选参数获取
$beginTime = empty($param['_params']['begintime']) ? false : $param['_params']['begintime']; // 查询开始时间
$endTime = empty($param['_params']['endtime']) ? false : $param['_params']['endtime']; // 查询结束时间
$status = empty($param['_params']['status']) ? 5 : $param['_params']['status']; // 查询状态
switch ($status)
{
// 当前状态(0: 关闭;1: 开启)
case '0':
$where_status = ' AND status = 0';
break;
case '1':
$where_status = ' AND status = 1';
break;
default:
$where_status = '';
break;
}
$keyword = empty($param['_params']['keyword']) ? false : $param['_params']['keyword']; // 查询关键字
if ($keyword)
{
$where_keyword = ' AND notice_info like "%' . trim($keyword) . '%"';
}
else
{
$where_keyword = '';
}
# 分页信息
$page_index = empty($param['_params']['page_index']) ? 1 : intval($param['_params']['page_index']); // 当前页
$page_size = empty($param['_params']['page_size']) ? 10 : intval($param['_params']['page_size']); // 单页容量
$start = ($page_index - 1) * $page_size;
$strPage = '';
if (!empty($page_index))
{
$strPage .= " LIMIT {$start},{$page_size} ";
}
if ($beginTime)
{
$where_begin = ' AND create_time >= "' . $beginTime . ' 00:00:00"';
}
else
{
$where_begin = '';
}
if ($endTime)
{
$where_end = ' AND create_time <= "' . $endTime . ' 23:59:59"';
}
else
{
$where_end = '';
}
$items = $this->PDO_Request(
'
SELECT
*
FROM
ct_agent_notice
WHERE
agent_id = ? AND channel_id = ? AND status != -1' . $where_begin . $where_end . $where_keyword . $where_status . '
ORDER BY
create_time desc ' . $strPage . ';', $param['agentID'], $param['channelID']
);
if (!is_array($items))
{
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
return false;
}
# 分页计算
$dbData = $this->PDO_Request(
'
SELECT
count(1) num
FROM
ct_agent_notice
WHERE
agent_id = ? AND channel_id = ? AND status != -1' . $where_begin . $where_end . $where_keyword . $where_status . ';',
$param['agentID'], $param['channelID']
);
if (!is_array($dbData) || count($dbData) < 1)
{
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
return false;
}
$data_count = intval($dbData[0]['num']);
$page_count = $data_count / $page_size + 1; // 总页数
// 5、数据返回部分
$outParam->biz_content = array(
'data' => $items,
'page_index' => $page_index,
'page_size' => $page_size,
'page_count' => intval($page_count),
'data_count' => $data_count,
);
return true;
}
##------------ 工具方法[curd]
##------------[summer 2017/11/6 Handel] ----------------------->
/**
* 输入参数标准化处理
* @param RequestParameter $inParam
* @param ReturnParameter $outParam
* @param array $config 待处理变量配置文件
*
* @return array data
*
* authorsummer 2017/11/6
*/
public function inParamHandel($inParam, $outParam, $config)
{
foreach ($config as $k => $v)
{
// 1、全局校验
$data['_params'] = $request_data = isset($inParam->biz_content) ? $inParam->biz_content : '';
if (!is_array($request_data))
{
$outParam->SetErrors(ERRORCODE_INPARAMERROR, ERRORINFO_INPARAMERROR);
return false;
}
// 2、单元校验
$data[$k] = isset($request_data[$v['name']]) ? $request_data[$v['name']] : '';
if (empty($data[$k]))
{
$outParam->SetErrors($v['errcode'], $v['errinfo']);
return false;
}
}
// 3、返回处理后的数据
return $data;
}
/**
* 代理权限认证
* @param RequestParameter $agentid 代理商id
* @param RequestParameter $channelid 渠道商id
* @param RequestParameter $salesid 代理人id
*
* @return array data
*
* authorsummer 2017/11/6
*/
public function checkAgentAuth($inParam, $outParam, $agentID, $channelID, $salesID)
{
//只有总代理才有权限
$dbSalesInfo = $this->PDO_Request(
'
SELECT idx, global_power
FROM sales_user
WHERE saus_agentid=? AND saus_channelid=? AND saus_salesid=?', $agentID, $channelID, $salesID
);
if (!is_array($dbSalesInfo))
{
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
return false;
}
// 代理不存在
if (count($dbSalesInfo) < 1)
{
$outParam->SetErrors(ERRORCODE_SALESNOTEXISTERROR, ERRORINFO_SALESNOTEXISTERROR);
return false;
}
// 不是总代理,没有权限
if (intval($dbSalesInfo[0]['global_power']) != 1)
{
$outParam->SetErrors(ERRORCODE_NOPOWERERROR, ERRORINFO_NOPOWERERROR);
return false;
}
return true;
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,712 @@
<?php
/**
* Created by PhpStorm.
* User: abcdefg
* Date: 2017/11/27
* Time: 15:38
*/
require_once dirname(dirname(dirname(__DIR__))) . '/config/game_config.inc.php';
require_once dirname(dirname(dirname(__DIR__))) . '/public/usefull.php';
class auth_item extends ToolBase
{
/** @var string $name */
public $name = '';
/// 允许使用的账户类型(1: 三方购买房卡; 2: 三方购买金币; 101: 三方转账房卡; 102: 三方转账金币;)
/** @var array $account_type */
public $account_type = [];
/// 允许使用的登录类型(1: 玩家; 2: 代理;)
/** @var array $login_type */
public $login_type = [];
public function verify_account_type($account_type)
{
return in_array($account_type, $this->account_type);
}
public function verify_login_type($login_type)
{
return in_array($login_type, $this->login_type);
}
}
class auth_list
{
/** @var array $items */
public $items;
public function __construct($list)
{
$this->items = array();
if (is_object($list))
$list = (array)$list;
if (is_array($list)) {
foreach ($list as $item) {
array_push($this->items, new auth_item($item));
}
}
}
public function search($name)
{
/** @var auth_item $item */
foreach($this->items as $item) {
if (0 == strcasecmp($item->name, $name))
return $item;
}
return null;
}
}
class game_item extends ToolBase
{
public $game_id;
public $scheme = 'http';
public $address;
public $port;
public function get_address($param = null, $needencode = true)
{
if (empty($this->scheme)) {
$is_https =
(isset($_SERVER['REQUEST_SCHEME']) && strcasecmp($_SERVER['REQUEST_SCHEME'], 'https') == 0) ||
(isset($_SERVER['HTTPS']) && (strcasecmp($_SERVER['HTTPS'], 'on') == 0 || strcasecmp($_SERVER['HTTPS'], '1') == 0));
$this->scheme = $is_https ? 'https' : 'http';
}
if (empty($this->port)) {
if (0 == strcasecmp('https', $this->scheme))
$this->port = 443;
else
$this->port = 80;
}
if (0 == strcasecmp('https', $this->scheme))
$result = 'https://' . $this->address . (443 == $this->port ? '' : ':' . $this->port) . '/index.html';
else
$result = 'http://' . $this->address . (80 == $this->port ? '' : ':' . $this->port) . '/index.html';
if (empty($param))
return $result;
if (is_object($param))
$param = (array)$param;
if ($needencode) {
if (is_array($param)) {
$data = array();
foreach ($param as $key => $value) {
array_push($data, rawurlencode($key) . '=' . rawurlencode($value));
}
$result .= '?' . implode('&', $data);
} else {
$result .= '?' . rawurlencode($param);
}
} else {
if (is_array($param)) {
$data = array();
foreach ($param as $key => $value) {
array_push($data, $key . '=' . $value);
}
$result .= '?' . implode('&', $data);
} else {
$result .= '?' . $param;
}
}
return $result;
}
}
class game_list
{
/** @var array of game_item */
public $items;
public function __construct($list)
{
$this->items = array();
if (is_object($list))
$list = (array)$list;
if (is_array($list)) {
foreach ($list as $item) {
array_push($this->items, new game_item($item));
}
}
}
public function search($game_id)
{
/** @var game_item $item */
foreach($this->items as $item) {
if (0 == strcasecmp($item->game_id, $game_id))
return $item;
}
return null;
}
}
class player extends BaseMethod
{
const SCHEME_HTTP = 'http';
const SCHEME_HTTPS = 'https';
const GAME_ID_TEST = 'test'; /// 测试环境下的游戏id不用更改。
/// 有效的来源标志
const AUTH_SIGN = [
/// 游戏跳转的标志
[
'name' => 'WHITELOGIN', /// 标志标识
'account_type' => [], /// 允许使用的账户类型
'login_type' => [2], /// 允许使用的登录类型
],
/// 黄超的标志
[
'name' => 'GAMEPAY', /// 标志标识
'account_type' => [1, 2, ], /// 允许使用的账户类型
'login_type' => [1], /// 允许使用的登录类型
],
/// 第一个三方游戏来源
[
'name' => 'TG9000000001', /// 标志标识
'account_type' => [101, 102, ], /// 允许使用的账户类型
'login_type' => [1], /// 允许使用的登录类型
],
];
/** @var auth_list $auth_list */
private $auth_list;
/** @var game_list $game_list */
private $game_list;
public function __construct()
{
parent::__construct();
$this->auth_list = new auth_list(self::AUTH_SIGN);
if (file_exists(dirname(__DIR__) . '/config/game.config.json')) {
$str = file_get_contents(dirname(__DIR__) . '/config/game.config.json');
$obj = JsonStringToJsonObject($str);
if (is_null($obj)) {
$obj = include dirname(__DIR__) . '/config/game.config.php';
}
$this->game_list = new game_list($obj);
} else {
$this->game_list = new game_list(include dirname(__DIR__) . '/config/game.config.php');
}
}
/**
* 用户登录
* 被请求方法示例参数固定为RequestParameter和ReturnParameter对象返回值固定为true(成功)和false(失败)
* @param RequestParameter $request
* @param ReturnParameter $return
* @return bool
* { "agentid": "a", "channelid": "b", "openid": "c", "unionid": "d", "nickname": "eee", "avatar": "dd", "sex": 0, "province": "jx", "city": "nc" }
*/
public function login($request, $return)
{
$param = (array)@$request->biz_content;
if (!is_array($param))
{
//参数格式错误
$return->seterrors(ERRORCODE_INPARAMERROR, ERRORINFO_INPARAMERROR);
return false;
}
$agent_id = empty(@$param['agentid']) ? '' : $param['agentid']; /// 代理
$channel_id = empty(@$param['channelid']) ? '' : $param['channelid']; /// 渠道
//$game_id = empty(@$param['gameid']) ? '' : $param['gameid']; /// 游戏id
$player_id = empty(@$param['playerid']) ? '' : $param['playerid']; /// 用户id
$open_id = empty(@$param['openid']) ? '' : $param['openid']; /// openid
$union_id = empty(@$param['unionid']) ? '' : $param['unionid']; /// unionid
//$nick_name = empty(@$param['nickname']) ? '' : $param['nickname']; /// 昵称
//$avatar = empty(@$param['avatar']) ? '' : $param['avatar']; /// 头像
$from_sign = mb_strtoupper(empty(@$param['fromsign']) ? '' : $param['fromsign'], USEDCHARSET); /// 来源标志
if (empty($agent_id))
{
$return->seterrors(ERRORCODE_AGENTIDERROR, ERRORINFO_AGENTIDERROR);
return false;
}
if (empty($channel_id))
{
$return->seterrors(ERRORCODE_CHANNELIDERROR, ERRORINFO_CHANNELIDERROR);
return false;
}
if (empty($player_id))
{
$return->seterrors(ERRORCODE_PLAYERIDERROR, ERRORINFO_PLAYERIDERROR);
return false;
}
/// 判断来源
$auth = $this->auth_list->search($from_sign);
if (!$auth)
{
$return->seterrors(ERRORCODE_INVALIDPARAMETER, sprintf(ERRORINFO_INVALIDPARAMETER, 'source sign'));
return false;
}
if (!$cmd = $this->NewServantCommand())
$cmd = $this->NewMasterCommand();
if ($auth->verify_login_type(1)) /// 允许获取玩家信息
{
if (!empty($union_id))
{
$ret = $cmd
->select('idx', 'play_playerid', 'play_nickname', 'play_avatar', 'play_sex', 'play_roomcard', 'play_bean', 'play_invitecode', 'play_openid', 'play_unionid')
->from('player')
->where([
'play_agentid' => $agent_id,
'play_channelid' => $channel_id,
'play_unionid' => $union_id,
'play_playerid' => $player_id,
])
->request();
}
elseif (!empty($open_id))
{
$ret = $cmd
->select('idx', 'play_playerid', 'play_nickname', 'play_avatar', 'play_sex', 'play_roomcard', 'play_bean', 'play_invitecode', 'play_openid', 'play_unionid')
->from('player')
->where([
'play_agentid' => $agent_id,
'play_channelid' => $channel_id,
'play_openid' => $open_id,
'play_playerid' => $player_id,
])
->request();
}
else
{
$return->seterrors(ERRORCODE_INVALIDPARAMETER, sprintf(ERRORINFO_INVALIDPARAMETER, 'player information'));
return false;
}
if (!$this->pdo_isdone())
{
$return->seterrors($this->geterrorcode(), $this->geterrorinfo());
return false;
}
elseif (empty($ret))
{
$return->seterrors(ERRORCODE_PLAYERNOTEXISTERROR, ERRORINFO_PLAYERNOTEXISTERROR);
return false;
}
$player = $ret[0];
/// 请求玩家
$playerData = array(
'app' => 'youle',
'route' => 'agent',
'rpc' => 'query_player2',
'data' => array(
'agentid' => $agent_id,
'playerid' => $player_id,
),
);
$json_data = json_encode($playerData);
$dd_ret = file_get_contents(REQUEST_USER_INFO . '?' . $json_data);
/// 请求数据出错
if (!$dd_ret)
{
$return->SetErrors(ERRORCODE_NODATAERROR, ERRORINFO_NODATAERROR);
return false;
}
$playerInfo = json_decode($dd_ret, true);
$player['play_nickname'] = usefull::getInstance()->check_name($playerInfo['data']['nickname']);
$player['play_avatar'] = isset($playerInfo['data']['avatar']) ? $playerInfo['data']['avatar'] : '';
$player['play_roomcard'] = isset($playerInfo['data']['roomcard']) ? $playerInfo['data']['roomcard'] : '';
$player['play_bean'] = isset($playerInfo['data']['bean']) ? $playerInfo['data']['bean'] : '';
$ret = $this->pdo_execute(/** @lang text */'update player set play_nickname=?, play_avatar=?, play_sex=?, play_roomcard=?, play_bean=? where idx=?',
$player['play_nickname'], $player['play_avatar'], isset($playerInfo['data']['sex']) ? $playerInfo['data']['sex'] : '',
$player['play_roomcard'], $player['play_bean'], $player['idx']);
if (!$ret)
{
$return->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
return false;
}
/// 记录登录流水
$ret = $this->pdo_execute(/** @lang text */ 'insert into ct_player_login_info(agent_id,channel_id,player_id,login_time,from_sign) values(?,?,?,now(),?)',
$agent_id, $channel_id, $player_id, $from_sign);
if (!$ret)
{
$return->seterrors($this->geterrorcode(), $this->geterrorinfo());
return false;
}
// if (strcmp($ret['play_playerid'], $player_id)) /// id不匹配
// {
// $return->seterrors(ERRORCODE_PLAYERIDERROR, ERRORINFO_PLAYERIDERROR);
// return false;
// }
//
// /// 更新昵称和头像
// $ret = $cmd
// ->update('player')
// ->fields('play_nickname', 'play_avatar')
// ->values($nick_name, $avatar)
// ->where(array('idx' => $player['idx']))
// ->execute();
// if (!$ret)
// {
// $return->seterrors($this->geterrorcode(), $this->geterrorinfo());
// return false;
// }
$player_info = array(
'playerid' => $player_id, /// id
'openid' => $player['play_openid'], /// openid
'unionid' => $player['play_unionid'], /// unionid
'nickname' => $player['play_nickname'], /// 昵称
'avatar' => $player['play_avatar'], /// 头像
'sex' => $player['play_sex'], /// 性别
'card' => empty($player['play_roomcard']) ? 0 : $player['play_roomcard'], /// 房卡数
'gold' => empty($player['play_bean']) ? 0 : $player['play_bean'], /// 金币数
'invitecode' => empty($player['play_invitecode']) ? '' : $player['play_invitecode'], /// 邀请码
);
}
else
$player_info = [];
if ($auth->verify_login_type(2)) /// 允许获取代理信息
{
$fields = [
'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', 'global_power', 'saus_tel', 'saus_wechat', 'is_send_star', 'saus_nickname', 'saus_avatar', 'saus_sex',
'saus_province', 'saus_city', 'user_id', 'player_id', 'is_vip'
];
if (!empty($union_id))
{
$ret = $cmd
->select($fields)
->from('sales_user')
->where(['saus_agentid' => $agent_id, 'saus_channelid' => $channel_id, 'saus_unionid' => $union_id, 'player_id' => $player_id, ])
->request();
}
elseif (!empty($open_id))
{
$ret = $cmd
->select($fields)
->from('sales_user')
->where(['saus_agentid' => $agent_id, 'saus_channelid' => $channel_id, 'saus_openid' => $open_id, 'player_id' => $player_id, ])
->request();
}
else
{
$return->seterrors(ERRORCODE_INVALIDPARAMETER, sprintf(ERRORINFO_INVALIDPARAMETER, 'player information'));
return false;
}
if (!$this->pdo_isdone())
{
$return->seterrors($this->geterrorcode(), $this->geterrorinfo());
return false;
}
elseif (empty($ret))
{
$return->seterrors(ERRORCODE_PLAYERNOTEXISTERROR, ERRORINFO_PLAYERNOTEXISTERROR);
return false;
}
$sales = $ret[0];
if (isset($_SERVER['HTTP_CLIENT_IP']))
$address = $_SERVER['HTTP_CLIENT_IP'];
elseif (isset($_SERVER['HTTP_X_FORWARDED_FOR']))
$address = $_SERVER['HTTP_X_FORWARDED_FOR'];
elseif (isset($_SERVER['REMOTE_ADDR']))
$address = $_SERVER['REMOTE_ADDR'];
else
$address = null;
/// 记录登录流水
$ret = $cmd
->insert('ct_sales_login_log')
->fields('agent_id', 'channel_id', 'sales_id', 'login_type', 'login_time', 'login_addr', 'login_status')
->values($agent_id, $channel_id, $sales['saus_salesid'], 2, date('Y-m-d H:i:s'), $address, 0)
->execute();
if (!$ret)
{
$return->seterrors($this->geterrorcode(), $this->geterrorinfo());
return false;
}
/// 返回用户信息
$sales_info = array(
'idx' => isset($sales['idx']) ? $sales['idx'] : '', /// 代理
'agentid' => isset($sales['saus_agentid']) ? $sales['saus_agentid'] : '', /// 代理
'channelid' => isset($sales['saus_channelid']) ? $sales['saus_channelid'] : '', /// 渠道
'openid' => isset($sales['saus_openid']) ? $sales['saus_openid'] : '', /// openid
'unionid' => isset($sales['saus_unionid']) ? $sales['saus_unionid'] : '', /// unionid
'nickname' => isset($sales['saus_nickname']) ? $sales['saus_nickname'] : '', /// 昵称
'headimgurl' => isset($sales['saus_avatar']) ? $sales['saus_avatar'] : '', /// 头像
'sex' => isset($sales['saus_sex']) ? $sales['saus_sex'] : '', /// 性别
'province' => isset($sales['saus_province']) ? $sales['saus_province'] : '', /// 省
'city' => isset($sales['saus_city']) ? $sales['saus_city'] : '', /// 市
'salesman' => empty($sales['saus_salesman']) ? 0 : intval($sales['saus_salesman']), /// 是否代理
'salesid' => isset($sales['saus_salesid']) ? $sales['saus_salesid'] : '', /// 代理编号
'level' => isset($sales['saus_level']) ? $sales['saus_level'] : '', /// 代理等级
'salestype' => isset($sales['saus_salestype']) ? $sales['saus_salestype'] : '', /// 代理类型
'roomcard' => isset($sales['saus_roomcard']) ? $sales['saus_roomcard'] : '', /// 账户房卡数
'bean' => isset($sales['saus_bean']) ? $sales['saus_bean'] : '', /// 账户金币数
'salespower' => isset($sales['saus_power']) ? $sales['saus_power'] : '', /// 代理权限
'agentmode' => '', /// 分享模式
//'pushmoney' => intval($sales['saus_pushmoney1']) + intval($sales['saus_pushmoney2']), /// 提成金额
'sausstatus' => isset($sales['saus_status']) ? $sales['saus_status'] : '', /// 当前状态
'html_applysales' => '', /// 成为代理的方式
'global_power' => isset($sales['global_power']) ? intval($sales['global_power']) : 0, /// 是否总代
'tel' => isset($sales['saus_tel']) ? $sales['saus_tel'] : '', /// 电话号码
'wechat' => isset($sales['saus_wechat']) ? $sales['saus_wechat'] : '', /// 微信号码
'user_id' => empty(@$sales['user_id']) ? '' : $sales['user_id'], /// 统一账户编号
'is_bind' => empty($sales['saus_tel']) ? 0 : (0 == $sales['is_send_star'] ? 0 : 1), /// 是否绑定
'logintype' => 11, /// 自动登录
'player_id' => isset($sales['player_id']) ? $sales['player_id'] : '',
'is_vip' => $sales['is_vip'],
);
}
else
$sales_info = [];
$return->biz_content = [];
foreach ($player_info as $k => $v) {
$return->biz_content[$k] = $v;
}
foreach ($sales_info as $k => $v) {
$return->biz_content[$k] = $v;
}
return true;
}
/**
* 用户登录
* 被请求方法示例参数固定为RequestParameter和ReturnParameter对象返回值固定为true(成功)和false(失败)
* @param RequestParameter $request
* @param ReturnParameter $return
* @return bool
* { "agentid": "a", "channelid": "b", "openid": "c", "unionid": "d", "nickname": "eee", "avatar": "dd", "sex": 0, "province": "jx", "city": "nc" }
*/
public function change_account($request, $return)
{
$param = (array)@$request->biz_content;
if (!is_array($param))
{
/// 参数格式错误
$return->seterrors(ERRORCODE_INPARAMERROR, ERRORINFO_INPARAMERROR);
return false;
}
$agent_id = empty(@$param['agentid']) ? '' : $param['agentid']; /// 代理
$channel_id = empty(@$param['channelid']) ? '' : $param['channelid']; /// 渠道
$game_id = empty(@$param['gameid']) ? '' : $param['gameid']; /// 游戏id
$player_id = empty(@$param['playerid']) ? '' : $param['playerid']; /// 用户id
$change_type = intval(empty(@$param['changetype']) ? 0 : $param['changetype']); /// 类型1购买房卡2购买金币101三方转账房卡102三方转账金币
$change_amount = floatval(empty(@$param['changeamount']) ? 0 : $param['changeamount']); /// 变更数量
$transaction_id = @$param['transactionid']; /// 订单号
$pay_fee = intval(empty(@$param['payfee']) ? 0 : $param['payfee']); /// 支付金额(分)
$from_sign = mb_strtoupper(empty(@$param['fromsign']) ? '' : $param['fromsign'], USEDCHARSET); /// 来源标志
$remark = @$param['remark']; /// 备注
if (empty($agent_id))
{
$return->seterrors(ERRORCODE_AGENTIDERROR, ERRORINFO_AGENTIDERROR);
return false;
}
if (empty($channel_id))
{
$return->seterrors(ERRORCODE_CHANNELIDERROR, ERRORINFO_CHANNELIDERROR);
return false;
}
if (empty($player_id))
{
$return->seterrors(ERRORCODE_PLAYERIDERROR, ERRORINFO_PLAYERIDERROR);
return false;
}
if (empty($change_type))
{
$return->seterrors(ERRORCODE_TYPEERROR, ERRORINFO_TYPEERROR);
return false;
}
/// 判断来源
$auth = $this->auth_list->search($from_sign);
if (!$auth)
{
$return->seterrors(ERRORCODE_INVALIDPARAMETER, sprintf(ERRORINFO_INVALIDPARAMETER, 'source sign'));
return false;
}
/// 判断类型
if (!$auth->verify_account_type($change_type))
{
$return->seterrors(ERRORCODE_TYPEERROR, ERRORINFO_TYPEERROR);
return false;
}
if (in_array($change_type, [1, 2])) /// 三方购买房卡、金币
{
if (empty($pay_fee))
{
$return->seterrors(ERRORCODE_ORDERMONEYERROR, ERRORINFO_ORDERMONEYERROR);
return false;
}
if (empty($transaction_id))
{
$return->seterrors(ERRORCODE_ORDERIDERROR, ERRORINFO_ORDERIDERROR);
return false;
}
}
$this->pdo_begintransaction();
try {
/// 校验账户
$cmd = /** @lang text */'select play_roomcard, play_bean from player a where play_agentid = ? and play_channelid = ? and play_playerid = ?';
$ret = $this->pdo_request($cmd, $agent_id, $channel_id, $player_id);
if (!$this->pdo_isdone())
throw new Exception($this->geterrorinfo() . '(' . __LINE__ . ')', $this->geterrorcode());
elseif (empty($ret))
throw new Exception(ERRORINFO_PLAYER_NOT_EXISTS, ERRORCODE_PLAYER_NOT_EXISTS);
switch ($change_type) {
case 1: /// 三方购买房卡
$account = $ret[0]['play_roomcard'] + $change_amount;
if ($ret[0]['play_roomcard'] + $change_amount < 0)
throw new Exception(ERRORINFO_AMOUNTERROR, ERRORCODE_AMOUNTERROR);
$oper_type = 1;
break;
case 2: /// 三方购买金币
$account = $ret[0]['play_bean'] + $change_amount;
if ($ret[0]['play_bean'] + $change_amount < 0)
throw new Exception(ERRORINFO_AMOUNTERROR, ERRORCODE_AMOUNTERROR);
$oper_type = 11;
break;
case 101: /// 三方转账房卡
throw new Exception(ERRORINFO_TYPEERROR, ERRORCODE_TYPEERROR);
$account = $ret[0]['play_roomcard'] + $change_amount;
if ($ret[0]['play_roomcard'] + $change_amount < 0)
throw new Exception(ERRORINFO_AMOUNTERROR, ERRORCODE_AMOUNTERROR);
$oper_type = 1;
break;
case 102: /// 三方转账星星
$account = $ret[0]['play_bean'] + $change_amount;
if ($ret[0]['play_bean'] + $change_amount < 0)
throw new Exception(ERRORINFO_AMOUNTERROR, ERRORCODE_AMOUNTERROR);
$oper_type = 11;
break;
default: /// 其他
throw new Exception(ERRORINFO_TYPEERROR, ERRORCODE_TYPEERROR);
break;
}
if (!empty($game_id) && 102 == $change_type) {
if (DEBUG_MODE) {
$game_info = $this->game_list->search(self::GAME_ID_TEST);
} else {
$game_info = $this->game_list->search($game_id);
}
} else
$game_info = null;
/// 没有传入游戏id则写入日志表
if (empty($game_info)) {
/// 记录同步流水
$cmd = /** @lang text */<<<EOL
insert into ct_user_process_log
(to_agent, to_channel, to_user, oper_type, oper_data, oper_time, is_process)
values
(?, ?, ?, ?, ?, ?, 0)
EOL;
$ret = $this->pdo_execute($cmd, $agent_id, $channel_id, $player_id, $oper_type, $change_amount, time());
if (!$ret)
throw new Exception($this->geterrorinfo() . '(' . __LINE__ . ')', $this->geterrorcode());
$log_id = $this->pdo_lastinsertid();
} else {
$data = array(
'app' => 'youle',
'route' => 'agent',
'rpc' => 0 > $change_amount ? 'coin_sub' : 'coin_add', /// 减少、增加
'data' => array(
'agentid' => $agent_id,
'playerid' => $player_id,
'change' => abs($change_amount),
),
);
$result = file_get_contents($game_info->get_address(JsonObjectToJsonString($data), false));
$result = JsonStringToJsonObject(rawurldecode($result));
if (0 == $result->data->result) /// 成功
$account = $result->data->bean;
else /// 失败
throw new Exception($result->data->error, ERRORCODE_UNKNOWN);
$log_id = 0;
}
/// 记录购买流水
$cmd = /** @lang text */<<<EOL
insert into ct_pay_for_third
(agent_id, channel_id, player_id, transaction_id, fee, type, amount, create_time, from_sign, log_id, remark)
values
(?, ?, ?, ?, ?, ?, ?, now(), ?, ?, ?)
EOL;
$ret = $this->pdo_execute($cmd, $agent_id, $channel_id, $player_id, $transaction_id, $pay_fee, $change_type, $change_amount, $from_sign, $log_id, $remark);
if (!$ret)
throw new Exception($this->geterrorinfo() . '(' . __LINE__ . ')', $this->geterrorcode());
$this->pdo_commit();
$return->biz_content = array(
'agentid' => $agent_id,
'channelid' => $channel_id,
'playerid' => $player_id,
'account' => $account,
);
return true;
}
catch(Exception $Exception)
{
$this->pdo_rollback();
$return->seterrors($Exception->getcode(), $Exception->getmessage());
return false;
}
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff