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

5882 lines
165 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 dirname(dirname(dirname(__DIR__))) . '/config/game_config.inc.php';
//require_once dirname(dirname(dirname(__DIR__))) . '/outData/outData.php';
/**
* Created by PhpStorm.
* User: win7
* Date: 2017-07-05
* Time: 9:39
*/
class agent extends BaseMethod
{
private function getGamePlayerInfo($agentID, $playerID, $urlLink)
{
//请求玩家
$playerData = array(
'app' => 'youle',
'route' => 'agent',
'rpc' => 'query_player2',
'data' => array(
'agentid' => $agentID,
'playerid' => $playerID,
),
);
$json_data = json_encode($playerData);
$dd_ret = file_get_contents($urlLink . '?' . $json_data);
//请求数据出错
if (!$dd_ret)
return null;
$playerInfo = json_decode($dd_ret, true);
if(!is_array($playerInfo))
return null;
return $playerInfo;
}
/**
* 获取代理商的服务器地址
* 被请求方法示例参数固定为RequestParameter和ReturnParameter对象返回值固定为true(成功)和false(失败)
* @param RequestParameter $inParam
* @param ReturnParameter $outParam
* @return bool
*/
public function serverAddress($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($channelID))
{
$outParam->SetErrors(ERRORCODE_CHANNELIDERROR, ERRORINFO_CHANNELIDERROR);
return false;
}
$channelData = $this->PDO_Request(/** @lang text */
'
SELECT
a.agen_agentid, a.agen_name, a.agen_server,
b.agch_channelid, b.agch_channelname, b.agch_service_tel, b.agch_service_wechat,
b.agch_youle_appid, b.agch_youle_devkey, b.agch_youle_busiid, b.agch_pay_appid, b.agch_pay_devkey,
b.agch_pay_marketid
FROM
agent a
LEFT JOIN agent_channel b ON a.agen_agentid=b.agch_agentid
WHERE
a.agen_agentid=? AND b.agch_channelid=?
', $agentID, $channelID);
if (!is_array($channelData))
{
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
return false;
}
if (count($channelData) < 1)
{
$outParam->SetErrors(ERRORCODE_NODATAERROR, ERRORINFO_NODATAERROR);
return false;
}
$db_agent_info = $this->PDO_Request(/** @lang text */
'
SELECT
html_buyroomcard, logo, html_applysales
FROM
config_agent
WHERE
agent_id=?', $agentID);
if (!is_array($db_agent_info))
{
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
return false;
}
if (count($db_agent_info) < 1)
{
$outParam->SetErrors(ERRORCODE_AGENTNOTEXISTERROR, ERRORINFO_AGENTNOTEXISTERROR);
return false;
}
$outParam->biz_content = array(
'state' => 0,
'error' => '',
'agentid' => $channelData[0]['agen_agentid'],
'agentname' => $channelData[0]['agen_name'],
'agentlogo' => $db_agent_info[0]['logo'],
'urlserver' => $channelData[0]['agen_server'],
'channelid' => $channelData[0]['agch_channelid'],
'channeltel' => $channelData[0]['agch_service_tel'],
'channelwechat' => $channelData[0]['agch_service_wechat'],
'html_buyroomcard' => $db_agent_info[0]['html_buyroomcard'],
'youle_appid' => $channelData[0]['agch_youle_appid'],
'youle_devkey' => $channelData[0]['agch_youle_devkey'],
'youle_busiid' => $channelData[0]['agch_youle_busiid'],
'youle_appid_pay' => $channelData[0]['agch_pay_appid'],
'youle_devkey_pay' => $channelData[0]['agch_pay_devkey'],
'youle_busiid_pay' => $channelData[0]['agch_pay_marketid'],
'html_applysales' => $db_agent_info[0]['html_applysales'],
);
return true;
}
/**
* 查询推荐人
* 被请求方法示例参数固定为RequestParameter和ReturnParameter对象返回值固定为true(成功)和false(失败)
* @param RequestParameter $inParam
* @param ReturnParameter $outParam
* @return bool
*/
public function recommend($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;
}
$salesID = isset($request_data['salesid']) ? $request_data['salesid'] : '';
if (empty($salesID))
{
$outParam->SetErrors(ERRORCODE_SALESIDERROR, ERRORINFO_SALESIDERROR);
return false;
}
$db_data = $this->PDO_Request(/** @lang text */
'
SELECT
saus_nickname, saus_avatar
FROM
sales_user
WHERE
saus_agentid = ? and saus_salesid = ?;', $agentID, $salesID);
if (!is_array($db_data))
{
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
return false;
}
if (count($db_data) < 1)
{
$outParam->biz_content = array(
'state' => 1,
'error' => '未查到推荐人',
);
return true;
}
$outParam->biz_content = array(
'state' => 0,
'salesid' => $salesID,
'name' => $db_data[0]['saus_nickname'],
'avatar' => $db_data[0]['saus_avatar'],
);
return true;
}
/**
* 绑定推荐人 代理绑定代理
* 被请求方法示例参数固定为RequestParameter和ReturnParameter对象返回值固定为true(成功)和false(失败)
* @param RequestParameter $inParam
* @param ReturnParameter $outParam
* @return bool
*/
public function bindRecommend($inParam, $outParam)
{
$request_data = isset($inParam->biz_content) ? $inParam->biz_content : '';
if (!is_array($request_data))
{
/// 参数格式错误
$outParam->SetErrors(ERRORCODE_INPARAMERROR, ERRORINFO_INPARAMERROR);
return false;
}
$agent_id = @$request_data['agentid'];
$channel_id = @$request_data['channelid'];
$open_id = @$request_data['openid'];
$union_id = @$request_data['unionid'];
$sales_id = @$request_data['salesid'];
if (empty($agent_id))
{
$outParam->SetErrors(ERRORCODE_AGENTIDERROR, ERRORINFO_AGENTIDERROR);
return false;
}
if (empty($open_id) && empty($union_id))
{
$outParam->SetErrors(ERRORCODE_OPENIDERROR, ERRORINFO_OPENIDERROR);
return false;
}
if (empty($sales_id))
{
$outParam->SetErrors(ERRORCODE_SALESIDERROR, ERRORINFO_SALESIDERROR);
return false;
}
$cmd = $this->NewMasterCommand();
$channel_info = $cmd
->select('agent_id', 'channel_id', 'sync_invitecode')
->from('ct_channel_list')
->where(['agent_id' => $agent_id, 'channel_id' => $channel_id])
->request();
if (!$this->pdo_isdone())
{
$outParam->seterrors($this->geterrorcode(), $this->geterrorinfo());
return false;
}
elseif (empty($channel_info))
{
$outParam->SetErrors(ERRORCODE_AGENTNOTEXISTERROR, ERRORINFO_AGENTNOTEXISTERROR);
return false;
}
else
$sync_invitecode = intval($channel_info[0]['sync_invitecode']);
$this->pdo_begintransaction();
try
{
$target = $cmd
->select('saus_salesid', 'saus_nickname', 'saus_avatar', 'saus_wechat', 'saus_tel', 'saus_parentid')
->from('sales_user')
->where([
'saus_agentid' => $agent_id,
'saus_salesid' => $sales_id,
])
->request();
if (!$this->pdo_isdone())
throw new Exception($this->geterrorinfo(), $this->geterrorcode());
elseif (empty($target))
throw new Exception(ERRORINFO_SALESNOTEXISTERROR, ERRORCODE_SALESNOTEXISTERROR);
if (!empty($union_id))
{
$source = $cmd
->select('saus_salesid', 'saus_parentid', 'player_id')
->from('sales_user')
->where([
'saus_agentid' => $agent_id,
'saus_unionid' => $union_id,
'saus_salesman' => 1,
])
->request();
}
elseif(!empty($open_id))
{
$source = $cmd
->select('saus_salesid', 'saus_parentid', 'player_id')
->from('sales_user')
->where([
'saus_agentid' => $agent_id,
'saus_openid' => $open_id,
'saus_salesman' => 1,
])
->request();
}
else
throw new Exception(ERRORINFO_INVALIDPARAMETER, ERRORCODE_INVALIDPARAMETER);
if (!$this->pdo_isdone())
throw new Exception($this->geterrorinfo(), $this->geterrorcode());
elseif (empty($source))
throw new Exception(ERRORINFO_SALESNOTEXISTERROR, ERRORCODE_SALESNOTEXISTERROR);
elseif ($target[0]['saus_parentid'] == $source[0]['saus_salesid'])
throw new Exception(ERRORINFO_CANNOTBINDCHILD, ERRORCODE_CANNOTBINDCHILD);
/// 修改代理表的上级代理和邀请码
$ret = $cmd
->update('sales_user')
->fields('saus_invitecode', 'saus_parentid')
->values($sales_id, $sales_id)
->where([
'saus_agentid' => $agent_id,
'saus_salesid' => $source[0]['saus_salesid'],
])
->execute();
if (!$ret)
throw new Exception($this->geterrorinfo(), $this->geterrorcode());
if (0 != $sync_invitecode) /// 要同步邀请码
{
/// 修改玩家表的邀请码
$ret = $cmd
->update('player')
->fields('play_invitecode')
->values($sales_id)
->where([
'play_agentid' => $agent_id,
'play_playerid' => $source[0]['player_id'],
])
->execute();
if (!$ret)
throw new Exception($this->geterrorinfo(), $this->geterrorcode());
/// 记录绑定日志
$ret = $cmd
->insert('ct_user_process_log')
->fields('from_agent', 'from_channel', 'from_user', 'to_agent', 'to_channel',
'to_user', 'oper_type', 'oper_data', 'remark', 'oper_time', 'is_process')
->values($agent_id, $channel_id, $sales_id, $agent_id, $channel_id, $open_id,
101, $union_id, '来源用户为要绑定的代理目标用户为要绑定的玩家。其中目标用户的userid为用户的openidoper_data为用户unionid。', time(), 0)
->execute();
if (!$ret)
throw new Exception($this->GetErrorInfo(), $this->GetErrorCode());
}
$outParam->biz_content = array(
'state' => 0,
'salesid' => $target[0]['saus_salesid'],
'wechat' => $target[0]['saus_wechat'],
'tel' => $target[0]['saus_tel'],
'nickname' => $target[0]['saus_nickname'],
'avatar' => $target[0]['saus_avatar'],
);
$this->PDO_Commit();
}
catch(Exception $e)
{
$this->PDO_Rollback();
$outParam->SetErrors($e->getCode(), $e->getMessage());
return false;
}
return true;
}
/**
* 我的人推荐
* 被请求方法示例参数固定为RequestParameter和ReturnParameter对象返回值固定为true(成功)和false(失败)
* @param RequestParameter $inParam
* @param ReturnParameter $outParam
* @return bool
*/
public function myRecommend($inParam, $outParam)
{
$request_data = isset($inParam->biz_content) ? $inParam->biz_content : '';
if (!is_array($request_data))
{
/// 参数格式错误
$outParam->SetErrors(ERRORCODE_INPARAMERROR, ERRORINFO_INPARAMERROR);
return false;
}
$agent_id = @$request_data['agentid']; /// 代理
$channel_id = @$request_data['channelid']; /// 渠道
$sales_id = @$request_data['salesid']; /// 代理号
//$player_id = @$request_data['playerid']; /// 玩家号
$open_id = @$request_data['openid']; /// openid
$union_id = @$request_data['unionid']; /// unionid
$type = intval(@$request_data['type']); /// 类型0代理1玩家
if (empty($agent_id))
{
$outParam->SetErrors(ERRORCODE_AGENTIDERROR, ERRORINFO_AGENTIDERROR);
return false;
}
if (empty($channel_id))
{
$outParam->SetErrors(ERRORCODE_CHANNELIDERROR, ERRORINFO_CHANNELIDERROR);
return false;
}
$db_data = array();
$cmd = $this->NewMasterCommand();
if (0 == $type) /// 查代理信息上级信息
{
$db_data = $cmd->Request(/** @lang text */
'
select
p.saus_salesid, p.saus_nickname, p.saus_avatar
from
sales_user i inner join sales_user p on i.saus_agentid = p.saus_agentid and i.saus_channelid = p.saus_channelid and p.saus_salesid = i.saus_parentid and p.saus_salesid is not null
where
i.saus_agentid = ? and i.saus_channelid = ? and i.saus_salesid = ?',
$agent_id, $channel_id, $sales_id
);
}
else
{
/// 先判断player表中是否绑定了邀请码
if (!empty($union_id))
$bindSalesInfo = $cmd->Request(/** @lang text */
'
select
idx, play_playerid, play_invitecode
from
player
where
play_agentid = ? and play_channelid = ? and play_unionid = ?',
$agent_id, $channel_id, $union_id
);
else
$bindSalesInfo = $cmd->Request(/** @lang text */
'
select
idx, play_playerid, play_invitecode
from
player
where
play_agentid = ? and play_channelid = ? and play_openid = ?',
$agent_id, $channel_id, $open_id
);
if (!$this->PDO_IsDone())
{
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
return false;
}
if (empty($bindSalesInfo) || count($bindSalesInfo) < 1)
{
$outParam->SetErrors(ERRORCODE_PLAYERNOTEXISTERROR, ERRORINFO_PLAYERNOTEXISTERROR);
return false;
}
$sales_id = $bindSalesInfo[0]['play_invitecode'];
if (!empty($sales_id))
$db_data = $cmd->Request(/** @lang text */
'
select
idx, saus_salesid, saus_nickname, saus_avatar
from
sales_user
where
saus_agentid = ? and saus_channelid = ? and saus_salesid = ?',
$agent_id, $channel_id, $sales_id
);
}
if (!$this->PDO_IsDone())
{
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
return false;
}
if (count($db_data) > 0)
$outParam->biz_content = array(
'parentid' => $db_data[0]['saus_salesid'],
'name' => $db_data[0]['saus_nickname'],
'avatar' => $db_data[0]['saus_avatar'],
);
else
$outParam->biz_content = array(
'parentid' => '',
'name' => '',
'avatar' => '',
);
return true;
}
/**
* 我的子代理
* 被请求方法示例参数固定为RequestParameter和ReturnParameter对象返回值固定为true(成功)和false(失败)
* @param RequestParameter $inParam
* @param ReturnParameter $outParam
* @return bool
*/
public function myAgent($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;
}
$openID = isset($request_data['openid']) ? $request_data['openid'] : '';
if (empty($openID))
{
$outParam->SetErrors(ERRORCODE_OPENIDERROR, ERRORINFO_OPENIDERROR);
return false;
}
$db_data = $this->PDO_Request(
'call cp_sales_get_child(?,?);',
$agentID,
$openID
);
if (!is_array($db_data))
{
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
return false;
}
$outParam->biz_content = array('childs' => $db_data);
return true;
}
/**
* 我的奖励
* 被请求方法示例参数固定为RequestParameter和ReturnParameter对象返回值固定为true(成功)和false(失败)
* @param RequestParameter $inParam
* @param ReturnParameter $outParam
* @return bool
*/
public function myAward($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;
}
$openID = isset($request_data['openid']) ? $request_data['openid'] : '';
if (empty($openID))
{
$outParam->SetErrors(ERRORCODE_OPENIDERROR, ERRORINFO_OPENIDERROR);
return false;
}
$db_data = $this->PDO_Request(
'call cp_sales_get_award(?,?);',
$agentID,
$openID
);
if (!is_array($db_data))
{
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
return false;
}
$outParam->biz_content = array('awards' => $db_data);
return true;
}
/**
* 领取奖励
* 被请求方法示例参数固定为RequestParameter和ReturnParameter对象返回值固定为true(成功)和false(失败)
* @param RequestParameter $inParam
* @param ReturnParameter $outParam
* @return bool
*/
public function getAward($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;
}
$openID = isset($request_data['openid']) ? $request_data['openid'] : '';
if (empty($openID))
{
$outParam->SetErrors(ERRORCODE_OPENIDERROR, ERRORINFO_OPENIDERROR);
return false;
}
$awardID = isset($request_data['awardid']) ? $request_data['awardid'] : '';
if (empty($awardID))
{
$outParam->SetErrors(ERRORCODE_AWARDIDERROR, ERRORINFO_AWARDIDERROR);
return false;
}
$db_data = $this->PDO_Request(
'call cp_sales_accept_award(?,?,?);',
$agentID,
$openID,
$awardID
);
if (!is_array($db_data) || count($db_data) < 1)
{
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
return false;
}
if (!isset($db_data[0]['result']) || intval($db_data[0]['result']) != 0)
{
$outParam->SetErrors($db_data[0]['result'], $db_data[0]['error']);
return false;
}
$outParam->biz_content = array(
'state' => 0,
'roomcard' => isset($db_data[0]['myroomcard']) ? intval($db_data[0]['myroomcard']) : 0,
'awardstate' => isset($db_data[0]['mystate']) ? intval($db_data[0]['mystate']) : 0,
);
return true;
}
/**
* 查询个人代理
* 被请求方法示例参数固定为RequestParameter和ReturnParameter对象返回值固定为true(成功)和false(失败)
* @param RequestParameter $inParam
* @param ReturnParameter $outParam
* @return bool
*/
public function queryAgent($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;
}
$openID = isset($request_data['openid']) ? $request_data['openid'] : '';
if (empty($openID))
{
$outParam->SetErrors(ERRORCODE_OPENIDERROR, ERRORINFO_OPENIDERROR);
return false;
}
$salesID = isset($request_data['salesid']) ? $request_data['salesid'] : '';
if (empty($salesID))
{
$outParam->SetErrors(ERRORCODE_SALESIDERROR, ERRORINFO_SALESIDERROR);
return false;
}
$db_data = $this->PDO_Request(
'call cp_sales_query_salesman(?,?,?);',
$agentID,
$openID,
$salesID
);
if (!is_array($db_data) || count($db_data) < 1)
{
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
return false;
}
if (!isset($db_data[0]['result']))
{
return false;
}
if (intval($db_data[0]['result']) != 0)
{
$outParam->biz_content = array(
'state' => $db_data[0]['result'],
'error' => $db_data[0]['error'],
);
return true;
}
$dbSaleInfo = $this->PDO_Request(/** @lang text */
'
select
saus_status, saus_bean
from
sales_user
where
saus_agentid=? and saus_salesid=?', $agentID, $salesID);
if (!is_array($dbSaleInfo) || count($dbSaleInfo) < 1)
{
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
return false;
}
$outParam->biz_content = array(
'state' => 0,
'salesid' => $db_data[0]['salesid'],
'salesname' => $db_data[0]['salesname'],
'roomcard' => $db_data[0]['salesroomcard'],
'salesstatus' => $dbSaleInfo[0]['saus_status'],
'bean' => $dbSaleInfo[0]['saus_bean'],
);
return true;
}
/**
* 获取绑定了我的邀请码的玩家列表
* 被请求方法示例参数固定为RequestParameter和ReturnParameter对象返回值固定为true(成功)和false(失败)
* @param RequestParameter $inParam
* @param ReturnParameter $outParam
* @return bool
*/
public function myPlayer($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;
}
$openID = isset($request_data['openid']) ? $request_data['openid'] : '';
if (empty($openID))
{
$outParam->SetErrors(ERRORCODE_OPENIDERROR, ERRORINFO_OPENIDERROR);
return false;
}
$db_data = $this->PDO_Request(
'call cp_sales_get_myplayer(?,?);',
$agentID,
$openID
);
if (!is_array($db_data))
{
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
return false;
}
$outParam->biz_content = array('list' => $db_data);
return true;
}
/**
* 下级玩家列表
* @param $inParam
* @param $outParam
* @return bool
*/
public function lowerPlayerList($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($channelID))
{
$outParam->SetErrors(ERRORCODE_CHANNELIDERROR, ERRORINFO_CHANNELIDERROR);
return false;
}
$salesID = isset($request_data['salesid']) ? $request_data['salesid'] : '';
if (empty($salesID))
{
$outParam->SetErrors(ERRORCODE_SALESIDERROR, ERRORINFO_SALESIDERROR);
return false;
}
// $sql = 'select play_playerid as playerid, play_nickname as nickname, play_avatar as avatar from player where play_invitecode=? and play_agentid=? and play_channelid=?';
$sql = 'select player_id as playerid, saus_nickname as nickname, saus_avatar as avatar, saus_salesid as salesid from sales_user where saus_invitecode=? and saus_agentid=? and saus_channelid=?';
$playerList = $this->PDO_Request($sql, $salesID, $agentID, $channelID);
if (!is_array($playerList))
{
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
return false;
}
$outParam->biz_content = array('list' => $playerList);
return true;
}
/**
* 获取我的下级代理列表
* 被请求方法示例参数固定为RequestParameter和ReturnParameter对象返回值固定为true(成功)和false(失败)
* @param RequestParameter $inParam
* @param ReturnParameter $outParam
* @return bool
*/
public function mySales($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;
}
$openID = isset($request_data['openid']) ? $request_data['openid'] : '';
if (empty($openID))
{
$outParam->SetErrors(ERRORCODE_OPENIDERROR, ERRORINFO_OPENIDERROR);
return false;
}
$db_data = $this->PDO_Request(
'call cp_sales_get_mysalesman(?,?);',
$agentID,
$openID
);
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 bindSales($inParam, $outParam)
{
$param = $inParam->biz_content;
$agentid = isset($param['agentid']) ? $param['agentid'] : '';
$channelid = isset($param['channelid']) ? $param['channelid'] : '';
$openid = isset($param['openid']) ? $param['openid'] : '';
$unionid = isset($param['unionid']) ? $param['unionid'] : '';
$salesid = isset($param['salesid']) ? $param['salesid'] : '';
if (empty($agentid))
{
$outParam->SetErrors(ERRORCODE_AGENTIDERROR, ERRORINFO_AGENTIDERROR);
return false;
}
if (empty($channelid))
{
$outParam->SetErrors(ERRORCODE_CHANNELIDERROR, ERRORINFO_CHANNELIDERROR);
return false;
}
if (empty($openid))
{
$outParam->SetErrors(ERRORCODE_OPENIDERROR, ERRORINFO_OPENIDERROR);
return false;
}
if (empty($salesid))
{
$outParam->SetErrors(ERRORCODE_SALESIDERROR, ERRORINFO_SALESIDERROR);
return false;
}
$cmd = $this->NewMasterCommand();
$channel_info = $cmd
->select('agent_id', 'channel_id', 'sync_invitecode')
->from('ct_channel_list')
->where(['agent_id' => $agentid, 'channel_id' => $channelid])
->request();
if (!$this->pdo_isdone())
{
$outParam->seterrors($this->geterrorcode(), $this->geterrorinfo());
return false;
}
elseif (empty($channel_info))
{
$outParam->SetErrors(ERRORCODE_AGENTNOTEXISTERROR, ERRORINFO_AGENTNOTEXISTERROR);
return false;
}
else
$sync_invitecode = intval($channel_info[0]['sync_invitecode']);
$player_info = $cmd
->select('play_playerid', 'play_invitecode')
->from('player')
->where(array(
'play_agentid' => $agentid,
'play_channelid' => $channelid,
'play_unionid' => $unionid,
))
->request();
if (!$this->pdo_isdone())
{
$outParam->seterrors($this->geterrorcode(), $this->geterrorinfo());
return false;
}
elseif (empty($player_info))
{
$outParam->biz_content = array(
'state' => 1,
'error' => '未查询到你的玩家信息,如果你是新注册的玩家,请稍等几分钟!',
);
return false;
}
if (!empty($player_info[0]['play_invitecode']))
{
$outParam->biz_content = array(
'state' => 2,
'error' => '你已在游戏中绑定过代理!邀请码为:' . $player_info[0]['play_invitecode'],
);
return false;
}
$player_id = $player_info[0]['play_playerid'];
/// 查询代理信息
$sales_user = $cmd
->select('saus_salesid', 'saus_nickname', 'saus_avatar', 'saus_wechat', 'saus_tel')
->from('sales_user')
->where([
'saus_agentid' => $agentid,
'saus_channelid' => $channelid,
'saus_salesid' => $salesid,
'saus_salesman' => 1,
])
->request();
if (!empty($sales_user))
{
$saus_salesid = $sales_user[0]['saus_salesid'];
$nickname = $sales_user[0]['saus_nickname'];
$avatar = $sales_user[0]['saus_avatar'];
$wechat = $sales_user[0]['saus_wechat'];
$tel = $sales_user[0]['saus_tel'];
}
else
{
$saus_salesid = 0;
$nickname = '';
$avatar = '';
$wechat = '';
$tel = '';
}
/// 查询不到对应的代理信息
if (empty($saus_salesid))
{
$outParam->SetErrors(ERRORCODE_SALESIDERROR, ERRORINFO_SALESIDERROR);
return false;
}
$sales_user = $cmd
->select('saus_invitecode')
->from('sales_user')
->where(array(
'saus_agentid' => $agentid,
'saus_channelid' => $channelid,
//'saus_unionid' => $unionid,
'player_id' => $player_id,
))
->request();
if (!empty($sales_user))
$myinvitecode = $sales_user[0]['saus_invitecode'];
else
$myinvitecode = null;
if (empty($myinvitecode))
{
$this->pdo_begintransaction();
try
{
if (0 == $sync_invitecode) /// 不同步邀请码
{
/// 修改代理表的代理号
$ret = $cmd
->update('sales_user')
->fields('saus_invitecode')
->values($salesid)
->where([
'saus_agentid' => $agentid,
'saus_channelid' => $channelid,
//'saus_unionid' => $unionid,
'player_id' => $player_id,
])
->execute();
}
else /// 同步邀请码
{
/// 修改代理表的代理号
$ret = $cmd
->update('sales_user')
->fields('saus_invitecode', 'saus_parentid')
->values($salesid, $salesid)
->where([
'saus_agentid' => $agentid,
'saus_channelid' => $channelid,
//'saus_unionid' => $unionid,
'player_id' => $player_id,
])
->execute();
}
if (!$ret)
throw new Exception($this->GetErrorInfo(), $this->GetErrorCode());
/// 修改玩家表的代理号
$ret = $cmd
->update('player')
->fields('play_invitecode')
->values($salesid)
->where([
'play_agentid' => $agentid,
'play_channelid' => $channelid,
//'play_unionid' => $unionid,
'play_playerid' => $player_id,
])
->execute();
if (!$ret)
throw new Exception($this->GetErrorInfo(), $this->GetErrorCode());
$outParam->biz_content = [
'salesid' => $saus_salesid,
'nickname' => $nickname,
'avatar' => $avatar,
'wechat' => $wechat,
'tel' => $tel,
];
/// 记录绑定日志
$ret = $cmd
->insert('ct_user_process_log')
->fields('from_agent', 'from_channel', 'from_user', 'to_agent', 'to_channel', 'to_user',
'oper_type', 'oper_data', 'remark', 'oper_time', 'is_process')
->values($agentid, $channelid, $salesid, $agentid, $channelid, $openid,
101, $unionid, '来源用户为要绑定的代理目标用户为要绑定的玩家。其中目标用户的userid为用户的openidoper_data为用户unionid。', time(), 0)
->execute();
if (!$ret)
throw new Exception($this->GetErrorInfo(), $this->GetErrorCode());
$this->pdo_commit();
return true;
}
catch (Exception $e)
{
$this->pdo_rollback();
$outParam->seterrors($e->getcode(), $e->getmessage());
return false;
}
}
else
{
$sales_user = $cmd
->select('saus_salesid', 'saus_nickname', 'saus_avatar', 'saus_wechat', 'saus_tel')
->from('sales_user')
->where([
'saus_agentid' => $agentid,
'saus_salesid' => $myinvitecode,
'saus_salesman' => 1,
])
->request();
if (!empty($sales_user))
{
$saus_salesid = $sales_user[0]['saus_salesid'];
$nickname = $sales_user[0]['saus_nickname'];
$avatar = $sales_user[0]['saus_avatar'];
$wechat = $sales_user[0]['saus_wechat'];
$tel = $sales_user[0]['saus_tel'];
}
else
{
$saus_salesid = 0;
$nickname = '';
$avatar = '';
$wechat = '';
$tel = '';
}
$outParam->biz_content = array(
'salesid' => $saus_salesid,
'nickname' => $nickname,
'avatar' => $avatar,
'wechat' => $wechat,
'tel' => $tel,
);
$outParam->SetErrors(ERRORCODE_INVITECODEEXISTS, '你已绑定代理(有疑问请联系代理)');
return false;
}
}
/**
* 申请为个人代理
* 被请求方法示例参数固定为RequestParameter和ReturnParameter对象返回值固定为true(成功)和false(失败)
* @param RequestParameter $inParam
* @param ReturnParameter $outParam
* @return bool
* @throws Exception
*/
public function applySales($inParam, $outParam)
{
$request_data = isset($inParam->biz_content) ? $inParam->biz_content : '';
if (!is_array($request_data))
{
//参数格式错误
$outParam->SetErrors(ERRORCODE_INPARAMERROR, ERRORINFO_INPARAMERROR);
return false;
}
$agent_id = @$request_data['agentid']; /// 代理
$channel_id = @$request_data['channelid']; /// 渠道
$sales_id = @$request_data['salesid']; /// 代理号
$open_id = @$request_data['openid']; /// openid
$union_id = @$request_data['unionid']; /// unionid
$wechat = @$request_data['wechat']; /// 微信号
$tel = isset($request_data['tel']) ? $request_data['tel'] : ''; /// 电话
$inivtecode = isset($request_data['inivtecode']) ? $request_data['inivtecode'] : ''; /// 邀请码
//$type = isset($request_data['type']) ? $request_data['type'] : ''; /// 成为代理的类型,微信还是手机
if (empty($agent_id))
{
$outParam->SetErrors(ERRORCODE_AGENTIDERROR, ERRORINFO_AGENTIDERROR);
return false;
}
if (empty($channel_id))
{
$outParam->SetErrors(ERRORCODE_CHANNELIDERROR, ERRORINFO_CHANNELIDERROR);
return false;
}
$password = isset($request_data['password']) ? $request_data['password'] : '';
$password2 = isset($request_data['password2']) ? $request_data['password2'] : '';
if ( !$password)
throw new Exception('请输入密码', 200);
if ( !$password2)
throw new Exception('请再次输入密码', 200);
if ($password !== $password2)
throw new Exception('两次输入的密码不相同', 200);
/** @var ISQLCommand $cmd */
$cmd = $this->NewMasterCommand();
/// 业务开始
$this->PDO_BeginTransaction();
try
{
/// 检验agentid
/*$agent = $cmd->request(
'select 1 from agent where agen_agentid = ?', $agent_id);*/
$agent = $cmd->request(/** @lang text */'select 1 from ct_agent_list where agent_id = ?', $agent_id);
if (empty($agent))
throw new Exception(ERRORINFO_AGENTIDERROR, ERRORCODE_AGENTIDERROR);
/// 检验代理号
if (!empty($sales_id))
{
/// 检验微信公众号用户
$sales_user = $cmd->request(/** @lang text */
'select saus_salesman from sales_user where saus_agentid = ? and saus_channelid = ? and saus_salesid = ?', $agent_id, $channel_id, $sales_id);
if (empty($sales_user))
throw new Exception(ERRORINFO_OPENIDERROR, ERRORCODE_OPENIDERROR);
elseif (1 == $sales_user[0]['saus_salesman'])
throw new Exception(ERRORINFO_INVITECODEEXISTS, ERRORCODE_INVITECODEEXISTS);
/// 取上级代理号
$parentid = null;
if (!empty($inivtecode))
{
$sales_user = $cmd->request(/** @lang text */
'select saus_salesid from sales_user where saus_agentid = ? and saus_channelid = ? and saus_salesid = ?', $agent_id, $channel_id, $inivtecode);
if (empty($sales_user))
throw new Exception(ERRORINFO_OPENIDERROR, ERRORCODE_OPENIDERROR);
$parentid = $sales_user[0]['saus_salesid'];
}
/// 更新代理信息
$sql = /** @lang text */<<<EOL
update
sales_user
set
saus_salesman = 1,
saus_saletime = now(),
saus_salestype = 1,
saus_wechat = ?,
saus_tel = ?,
saus_parentid = ?,
password=?
where
saus_agentid = ? and saus_salesid = ?
EOL;
$ret = $cmd->execute($sql, $wechat, $tel, $parentid, $password, $agent_id, $sales_id);
if (!$ret)
throw new Exception($this->GetErrorInfo(), $this->GetErrorCode());
}
elseif (!empty($union_id) || !empty($open_id)) /// 为了兼顾老数据,这里处理没有代理号的用户成为代理的情况。
{
/// 检验微信公众号用户
if ( !empty($union_id)) {
$sales_user = $cmd->request(/** @lang text */
'select saus_salesman from sales_user where saus_agentid = ? and saus_channelid = ? and saus_unionid = ?',
$agent_id, $channel_id, $union_id);
} else {
$sales_user = $cmd->request(/** @lang text */
'select saus_salesman from sales_user where saus_agentid = ? and saus_channelid = ? and saus_openid = ?',
$agent_id, $channel_id, $open_id);
}
//if (empty($sales_user))
//throw new Exception(ERRORINFO_OPENIDERROR, ERRORCODE_OPENIDERROR);
if (!empty($sales_user) && 1 == $sales_user[0]['saus_salesman'])
throw new Exception(ERRORINFO_INVITECODEEXISTS, ERRORCODE_INVITECODEEXISTS);
/// 如果没有代理编号,则需要生成一个代理号
/// 新个人代理
/*$ret = $cmd->execute(
'update agent set agen_maxsalesid = agen_maxsalesid + floor(rand() * (12-6) + 6) where agen_agentid = ?', $agent_id);*/
$ret = $cmd->execute(/** @lang text */
'update ct_agent_list set max_sales_id = max_sales_id + floor(rand() * (12-6) + 6) where agent_id = ?', $agent_id);
if (!$ret)
throw new Exception($this->GetErrorInfo(), $this->GetErrorCode());
/*$agent = $cmd->request(
'select agen_maxsalesid, agen_salespower from agent where agen_agentid = ?', $agent_id);*/
$agent = $cmd->request(/** @lang text */'
select max_sales_id as agen_maxsalesid, default_sales_power as agen_salespower from ct_agent_list where agent_id = ?', $agent_id);
if (empty($agent))
throw new Exception(ERRORINFO_AGENTIDERROR, ERRORCODE_AGENTIDERROR);
$sales_id = $agent[0]['agen_maxsalesid'];
$sales_power = $agent[0]['agen_salespower'];
/// 取上级代理号
$parentid = null;
if (!empty($inivtecode))
{
$sales_user = $cmd->request(/** @lang text */
'select saus_salesid from sales_user where saus_agentid = ? and saus_channelid = ? and saus_salesid = ?', $agent_id, $channel_id, $inivtecode);
if (empty($sales_user))
throw new Exception(ERRORINFO_OPENIDERROR, ERRORCODE_OPENIDERROR);
$parentid = $sales_user[0]['saus_salesid'];
}
/// 更新代理信息
if (!empty($union_id))
{
$sql = /** @lang text */<<<EOL
update
sales_user
set
saus_salesman = 1,
saus_saletime = now(),
saus_salestype = 1,
saus_wechat = ?,
saus_tel = ?,
saus_parentid = ?,
saus_salesid = ?,
saus_power = ?,
password = ?
where
saus_agentid = ? and saus_channelid = ? and saus_unionid = ?
EOL;
$ret = $cmd->execute($sql, $wechat, $tel, $parentid, $sales_id, $sales_power, $password, $agent_id, $channel_id, $union_id);
}
else
{
$sql = /** @lang text */<<<EOL
update
sales_user
set
saus_salesman = 1,
saus_saletime = now(),
saus_salestype = 1,
saus_wechat = ?,
saus_tel = ?,
saus_parentid = ?,
saus_salesid = ?,
saus_power = ?,
password=?
where
saus_agentid = ? and saus_channelid = ? and saus_openid = ?
EOL;
$ret = $cmd->execute($sql, $wechat, $tel, $parentid, $sales_id, $sales_power, $password, $agent_id, $channel_id, $open_id);
}
if (!$ret)
throw new Exception($this->GetErrorInfo(), $this->GetErrorCode());
}
else
throw new Exception(ERRORINFO_SALESIDERROR, ERRORCODE_SALESIDERROR);
/// 按日期统计新增个人代理人数
$ret = $cmd->CallStoredProcedure('cp_report_agent_day')->Values($agent_id, 1, 1);
if (!$ret)
throw new Exception($this->GetErrorInfo(), $this->GetErrorCode());
$sql = /** @lang text */<<<EOL
select
idx id,
saus_agentid agentid,
saus_channelid channelid,
saus_openid openid,
saus_unionid unionid,
saus_nickname nickname,
saus_avatar avatar,
saus_sex sex,
saus_province province,
saus_city city,
saus_firsttime firsttime,
saus_lasttime lasttime,
saus_salesman salesman,
saus_salesid salesid,
saus_level level,
saus_parentid parentid,
saus_salestype salestype,
saus_roomcard roomcard,
saus_bean bean,
saus_saletime saletime,
saus_tel tel,
saus_wechat wechat,
saus_invitecode invitecode,
saus_power power,
saus_pushrate1 pushrate1,
saus_pushrate2 pushrate2,
saus_pushmoney1 pushmoney1,
saus_pushmoney2 pushmoney2
from
sales_user
where
saus_agentid = ? and saus_channelid = ? and saus_salesid = ?
EOL;
$sales_user = $cmd->request($sql, $agent_id, $channel_id, $sales_id);
if (is_array($sales_user) && count($sales_user) > 0)
{
$sales_user[0]['nickname'] = usefull::getInstance()->check_name($sales_user[0]['nickname']);
/// 记录注册日志
$ret = $cmd->execute(/** @lang text */
'insert into ct_user_process_log(
to_agent, to_channel, to_user,
oper_type, oper_data, remark, oper_time, is_process)
values(?, ?, ?, 21, ?, ?, ?, 0)',
$agent_id, $channel_id, $sales_user[0]['salesid'],
JsonObjectToJsonString($sales_user[0]), '目标用户为注册的代理信息。oper_data为用户unionid。', time());
if (!$ret)
throw new Exception($this->GetErrorInfo(), $this->GetErrorCode());
}
if (!empty($sales_user[0]['tel']))
{
/// 处理已送的记录
$sql = /** @lang text */<<<EOL
update
sales_bonus_list a,
sales_user b
set
b.saus_power = a.power,
a.send_time = sysdate(),
a.sales_id = b.saus_salesid
where
a.agent_id = b.saus_agentid and a.channel_id = b.saus_channelid and a.phone = b.saus_tel and a.is_send = 1 and
a.agent_id = ? and a.channel_id = ? and a.phone = ?
EOL;
$ret = $this->pdo_execute($sql, $agent_id, $channel_id, $sales_user[0]['tel']);
if (!$ret)
throw new Exception($this->GetErrorInfo(), $this->GetErrorCode());
/// 加入流水信息
$sql = /** @lang text */<<<EOL
insert into
sales_transferbill
(
satr_agentid, channel_id, from_sales, satr_openid, satr_salesid, satr_amount, satr_transfertime
)
select
a.agent_id, a.channel_id, 0, 'system', b.saus_salesid, a.send_card, sysdate()
from
sales_bonus_list a, sales_user b
where
a.agent_id = b.saus_agentid and a.channel_id = b.saus_channelid and a.phone = b.saus_tel and a.is_send = 0 and
a.agent_id = ? and a.channel_id = ? and a.phone = ?
EOL;
$ret = $this->pdo_execute($sql, $agent_id, $channel_id, $sales_user[0]['tel']);
if (!$ret)
throw new Exception($this->GetErrorInfo(), $this->GetErrorCode());
/// 处理未送的记录
$sql = /** @lang text */<<<EOL
update
sales_bonus_list a,
sales_user b
set
b.saus_roomcard = b.saus_roomcard + a.send_card,
b.saus_power = a.power,
a.is_send = 1,
a.send_time = sysdate(),
a.sales_id = b.saus_salesid
where
a.agent_id = b.saus_agentid and a.channel_id = b.saus_channelid and a.phone = b.saus_tel and a.is_send = 0 and
a.agent_id = ? and a.channel_id = ? and a.phone = ?
EOL;
$ret = $this->pdo_execute($sql, $agent_id, $channel_id, $sales_user[0]['tel']);
if (!$ret)
throw new Exception($this->GetErrorInfo(), $this->GetErrorCode());
}
$this->PDO_Commit();
}
catch (Exception $Exception)
{
$this->PDO_Rollback();
$outParam->SetErrors($Exception->getCode(), $Exception->getMessage());
return false;
}
$outParam->biz_content = array('inivtecode' => $parentid);
return true;
}
/**
* 让游戏生成代理信息,以解决玩家在游戏中绑定不了代理的问题
*/
public function gameRegisterSales($inParam, $outParam)
{
$request_data = isset($inParam->biz_content) ? $inParam->biz_content : '';
if (!is_array($request_data)) {
$outParam->SetErrors(ERRORCODE_INPARAMERROR, ERRORINFO_INPARAMERROR);
return false;
}
$agent_id = @$request_data['agentid']; /// 代理
$channel_id = @$request_data['channelid']; /// 渠道
$sales_id = @$request_data['salesid']; /// 代理号
if (empty($agent_id)) {
$outParam->SetErrors(ERRORCODE_AGENTIDERROR, ERRORINFO_AGENTIDERROR);
return false;
}
if (empty($channel_id)) {
$outParam->SetErrors(ERRORCODE_CHANNELIDERROR, ERRORINFO_CHANNELIDERROR);
return false;
}
$cmd = $this->NewMasterCommand();
$sql = /** @lang text */<<<EOL
select
idx id,
saus_agentid agentid,
saus_channelid channelid,
saus_openid openid,
saus_unionid unionid,
saus_nickname nickname,
saus_avatar avatar,
saus_sex sex,
saus_province province,
saus_city city,
saus_firsttime firsttime,
saus_lasttime lasttime,
saus_salesman salesman,
saus_salesid salesid,
saus_level level,
saus_parentid parentid,
saus_salestype salestype,
saus_roomcard roomcard,
saus_bean bean,
saus_saletime saletime,
saus_tel tel,
saus_wechat wechat,
saus_invitecode invitecode,
saus_power power,
saus_pushrate1 pushrate1,
saus_pushrate2 pushrate2,
saus_pushmoney1 pushmoney1,
saus_pushmoney2 pushmoney2
from
sales_user
where
saus_agentid = ? and saus_channelid = ? and saus_salesid = ?
EOL;
$sales_user = $cmd->request($sql, $agent_id, $channel_id, $sales_id);
if (is_array($sales_user) && count($sales_user) > 0)
{
/// 记录注册日志
$ret = $cmd->execute(/** @lang text */
'insert into ct_user_process_log(
to_agent, to_channel, to_user,
oper_type, oper_data, remark, oper_time, is_process)
values(?, ?, ?, 21, ?, ?, ?, 0)',
$agent_id, $channel_id, $sales_id,
JsonObjectToJsonString($sales_user[0]), '目标用户为注册的代理信息。oper_data为用户unionid。', time());
if (!$ret) {
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
return false;
}
$outParam->biz_content = array('msg' => 'ok');
return true;
} else {
$outParam->SetErrors(ERRORCODE_OPENIDERROR, '该代理不存在');
return false;
}
}
/**
* 修改个人代理的联系方式
* 被请求方法示例参数固定为RequestParameter和ReturnParameter对象返回值固定为true(成功)和false(失败)
* @param RequestParameter $inParam
* @param ReturnParameter $outParam
* @return bool
*/
public function updateInfo($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;
}
$openID = isset($request_data['openid']) ? $request_data['openid'] : '';
if (empty($openID))
{
$outParam->SetErrors(ERRORCODE_OPENIDERROR, ERRORINFO_OPENIDERROR);
return false;
}
$unionID = isset($request_data['unionid']) ? $request_data['unionid'] : '';
if (empty($unionID))
{
$outParam->SetErrors(ERRORCODE_CHANNELIDERROR, ERRORINFO_CHANNELIDERROR);
return false;
}
$wechat = isset($request_data['wechat']) ? $request_data['wechat'] : '';
if (empty($wechat))
{
$outParam->SetErrors(ERRORCODE_WECHATERROR, ERRORINFO_WECHATERROR);
return false;
}
$tel = isset($request_data['tel']) ? $request_data['tel'] : '';
$dbSaleInfo = $this->PDO_Request(/** @lang text */
'
SELECT
idx
FROM
sales_user
WHERE saus_agentid = ? and saus_unionid = ?;', $agentID, $unionID);
if (!is_array($dbSaleInfo))
{
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
return false;
}
if (count($dbSaleInfo) < 1)
{
$outParam->SetErrors(ERRORCODE_SALESNOTEXISTERROR, ERRORINFO_SALESNOTEXISTERROR);
return false;
}
$strSql = '';
$arrayParam = array($wechat);
if (!empty($tel))
{
$strSql .= ' ,saus_tel=? ';
$arrayParam[] = $tel;
}
$arrayParam[] = $agentID;
$arrayParam[] = $unionID;
$this->PDO_Execute(/** @lang text */
"
UPDATE sales_user
SET saus_wechat = ? {$strSql}
WHERE saus_agentid = ? and saus_unionid = ?;", $arrayParam);
if (!$this->PDO_IsDone())
{
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
return false;
}
$outParam->biz_content = array(
'state' => 0,
'error' => '',
);
return true;
}
/**
* 客服联系方式
* 被请求方法示例参数固定为RequestParameter和ReturnParameter对象返回值固定为true(成功)和false(失败)
* @param RequestParameter $inParam
* @param ReturnParameter $outParam
* @return bool
*/
public function contactWay($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
sale_qq, sale_wechat, sale_tel
FROM
config_agent
WHERE
agent_id=?', $agentID);*/
$db_data = $this->PDO_Request(/** @lang text */'select qq as sale_qq, wechat as sale_wechat from ct_channel_list where agent_id=?', $agentID);
if (!is_array($db_data))
{
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
return false;
}
if (count($db_data) < 1)
{
$outParam->biz_content = array();
return true;
}
$outParam->biz_content = array(
'qq' => $db_data[0]['sale_qq'],
'wechat' => $db_data[0]['sale_wechat'],
'tel' => '',
);
return true;
}
/**
* 代理城市列表
* 被请求方法示例参数固定为RequestParameter和ReturnParameter对象返回值固定为true(成功)和false(失败)
* @param RequestParameter $inParam
* @param ReturnParameter $outParam
* @return bool
*/
public function cityList($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($channelID))
// {
// $outParam->SetErrors(ERRORCODE_CHANNELIDERROR, ERRORINFO_CHANNELIDERROR);
// return false;
// }
$db_data = $this->PDO_Request(/** @lang text */
"
SELECT
agent_id as agentid, agent_name as name, channel_id as channelid
FROM
config_agent
WHERE
agent_id=? OR rel_agent_id=? ", $agentID, $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 closeSale($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($channelID))
{
$outParam->SetErrors(ERRORCODE_CHANNELIDERROR, ERRORINFO_CHANNELIDERROR);
return false;
}
$salesID = isset($request_data['salesid']) ? $request_data['salesid'] : '';
if (empty($salesID))
{
$outParam->SetErrors(ERRORCODE_SALESIDERROR, ERRORINFO_SALESIDERROR);
return false;
}
//1、封玩家 2、解封
$type = isset($request_data['type']) ? intval($request_data['type']) : 0;
if ($type != 1 && $type != 2)
{
return false;
}
$dbSaleInfo = $this->PDO_Request(/** @lang text */
'
SELECT
idx, saus_salesman, saus_status
FROM
sales_user
WHERE
saus_agentid = ? AND saus_channelid=? AND saus_salesid=?', $agentID, $channelID, $salesID);
if (!is_array($dbSaleInfo) || count($dbSaleInfo) < 1)
{
$outParam->SetErrors(ERRORCODE_SALESIDERROR, ERRORINFO_SALESIDERROR);
return false;
}
if (intval($dbSaleInfo[0]['saus_salesman']) != 1)
{
$outParam->SetErrors(ERRORCODE_SALESNOTEXISTERROR, ERRORINFO_SALESNOTEXISTERROR);
return false;
}
$status = 0;
$operate_type = 32;
if ($type == 1)
{
$operate_type = 31;
$status = 1;
}
if ($operate_type == 31 && $dbSaleInfo[0]['saus_status'] == 1)
{
return true;
}
if ($operate_type == 32 && $dbSaleInfo[0]['saus_status'] == 0)
{
return true;
}
$ret = $this->PDO_Execute(/** @lang text */
'UPDATE sales_user SET saus_status = ? WHERE idx=?', $status, $dbSaleInfo[0]['idx']);
if (!$ret)
{
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
return false;
}
$log_res = $this->PDO_Execute(/** @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 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', '', '', '', $agentID, $channelID, $salesID, $operate_type, '', '', time(), 0);
if (!$log_res)
{
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
return false;
}
return true;
}
/**
* 解绑绑定我的玩家或代理
* 被请求方法示例参数固定为RequestParameter和ReturnParameter对象返回值固定为true(成功)和false(失败)
* @param RequestParameter $inParam
* @param ReturnParameter $outParam
* @return bool
*/
public function unbind($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($channelID))
{
$outParam->SetErrors(ERRORCODE_CHANNELIDERROR, ERRORINFO_CHANNELIDERROR);
return false;
}
$salesID = isset($request_data['salesid']) ? $request_data['salesid'] : '';
if (empty($salesID))
{
$outParam->SetErrors(ERRORCODE_SALESIDERROR, ERRORINFO_SALESIDERROR);
return false;
}
//判断自己是否是代理身份
$dbData = $this->PDO_Request(/** @lang text */
'
SELECT
idx, saus_salesman
FROM
sales_user
WHERE
saus_agentid=? AND saus_channelid=? AND saus_salesid=?', $agentID, $channelID, $salesID);
if (!is_array($dbData))
{
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
return false;
}
if (count($dbData) < 1 || intval($dbData[0]['saus_salesman']) != 1)
{
$outParam->SetErrors(ERRORCODE_SALESNOTEXISTERROR, ERRORINFO_SALESNOTEXISTERROR);
return false;
}
//解除绑定了我的代理
$dbSaleInfo = $this->PDO_Request(/** @lang text */
'
SELECT
idx, saus_salesid
FROM
sales_user
WHERE
saus_salesman=1 AND saus_agentid=? AND saus_channelid=? AND saus_parentid=?', $agentID, $channelID, $salesID);
if (!is_array($dbSaleInfo))
{
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
return false;
}
$this->PDO_BeginTransaction();
$this->PDO_Execute(/** @lang text */
'
UPDATE sales_user
SET saus_parentid=null
WHERE saus_salesman=1 AND saus_agentid=? AND saus_channelid=? AND saus_parentid=?', $agentID, $channelID, $salesID);
if (!$this->PDO_IsDone())
{
$this->PDO_Rollback();
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
return false;
}
$arrayUnbind = array(
'player' => array(),
'sales' => array(
'par' => array(),
'inv' => array(),
),
);
foreach ($dbSaleInfo as $item)
{
if (empty($item['saus_salesid']))
{
continue;
}
$arrayUnbind['sales']['par'][] = $item['saus_salesid'];
}
//解除绑定了我的玩家
$dbPlayerInfo = $this->PDO_Request(/** @lang text */
'
SELECT
idx, play_playerid
FROM
player
WHERE
play_agentid = ? AND play_channelid=? AND play_invitecode=?', $agentID, $channelID, $salesID);
$this->PDO_Execute(/** @lang text */
'
UPDATE player
SET play_invitecode=null
WHERE play_agentid = ? AND play_channelid=? AND play_invitecode=?', $agentID, $channelID, $salesID);
if (!$this->PDO_IsDone())
{
$this->PDO_Rollback();
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
return false;
}
foreach ($dbPlayerInfo as $item)
{
if (empty($item['play_playerid']))
{
continue;
}
$arrayUnbind['player'][] = $item['play_playerid'];
}
$dbSaleInfoTwo = $this->PDO_Request(/** @lang text */
'
SELECT
idx, saus_salesid
FROM
sales_user
WHERE
saus_agentid=? AND saus_channelid=? AND saus_invitecode=?', $agentID, $channelID, $salesID);
if (!is_array($dbSaleInfoTwo))
{
$this->PDO_Rollback();
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
return false;
}
foreach ($dbSaleInfoTwo as $item)
{
if (empty($item['saus_salesid']))
{
continue;
}
$arrayUnbind['sales']['inv'][] = $item['saus_salesid'];
}
$this->PDO_Execute(/** @lang text */
'
UPDATE sales_user
SET saus_invitecode=null
WHERE saus_agentid=? AND saus_channelid=? AND saus_invitecode=?', $agentID, $channelID, $salesID);
if (!$this->PDO_IsDone())
{
$this->PDO_Rollback();
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
return false;
}
if (count($arrayUnbind['player']) > 0 || count($arrayUnbind['sales']['inv']) > 0 || count($arrayUnbind['sales']['par']) > 0)
{
//记录日志
$log_res = $this->PDO_Execute(/** @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 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', $agentID, $channelID, $salesID, $agentID, $channelID, '', 41, json_encode($arrayUnbind), '', time(), 0);
if (!$log_res)
{
$this->PDO_Rollback();
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
return false;
}
//记录本地日志
$log_res = $this->PDO_Execute(/** @lang text */
'
INSERT INTO
sales_operate_log(agent_id, channel_id, sales_id, operate_type, operate_data, create_time)
VALUES (?, ?, ?, ?, ?, ?)', $agentID, $channelID, $salesID, 0, json_encode($arrayUnbind), date('Y-m-d H:i:s', time()));
if (!$log_res)
{
$this->PDO_Rollback();
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
return false;
}
}
$this->PDO_Commit();
return true;
}
/**
* 封禁或解封玩家
* 被请求方法示例参数固定为RequestParameter和ReturnParameter对象返回值固定为true(成功)和false(失败)
* @param RequestParameter $inParam
* @param ReturnParameter $outParam
* @return bool
*/
public function closePlayer($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($channelID))
{
$outParam->SetErrors(ERRORCODE_CHANNELIDERROR, ERRORINFO_CHANNELIDERROR);
return false;
}
$playerID = isset($request_data['playerid']) ? $request_data['playerid'] : '';
if (empty($playerID))
{
$outParam->SetErrors(ERRORCODE_PLAYERIDERROR, ERRORINFO_PLAYERIDERROR);
return false;
}
//1、封玩家 2、解封
$type = isset($request_data['type']) ? intval($request_data['type']) : 0;
if ($type != 1 && $type != 2)
{
return false;
}
$dbPlayerInfo = $this->PDO_Request(/** @lang text */
'
SELECT
play_status
FROM
player
WHERE
play_agentid=? AND play_channelid=? AND play_playerid=?', $agentID, $channelID, $playerID);
if (!is_array($dbPlayerInfo))
{
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
return false;
}
if (count($dbPlayerInfo) < 1)
{
$outParam->SetErrors(ERRORCODE_PLAYERNOTEXISTERROR, ERRORINFO_PLAYERNOTEXISTERROR);
return false;
}
$status = 0;
$operate_type = 34;
if ($type == 1)
{
$status = 1;
$operate_type = 33;
}
if ($operate_type == 33 && $dbPlayerInfo[0]['play_status'] == 1)
{
return true;
}
if ($operate_type == 34 && $dbPlayerInfo[0]['play_status'] == 0)
{
return true;
}
$log_res = $this->PDO_Execute(/** @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 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', '', '', '', $agentID, $channelID, $playerID, $operate_type, '', '', time(), 0);
if (!$log_res)
{
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
return false;
}
$ret = $this->PDO_Execute(/** @lang text */
'
UPDATE player
SET play_status=?, status_change_time=?
WHERE play_agentid=? AND play_channelid=? AND play_playerid=?', $status, date('Y-m-d H:i:s', time()),
$agentID, $channelID, $playerID);
if (!$ret)
{
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
return false;
}
return true;
}
/**
* 新查询代理信息
* 被请求方法示例参数固定为RequestParameter和ReturnParameter对象返回值固定为true(成功)和false(失败)
* @param RequestParameter $inParam
* @param ReturnParameter $outParam
* @return bool
*/
public function findAgent($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($channelID))
{
$outParam->SetErrors(ERRORCODE_CHANNELIDERROR, ERRORINFO_CHANNELIDERROR);
return false;
}
$salesID = isset($request_data['salesid']) ? $request_data['salesid'] : '';
if (empty($salesID))
{
$outParam->SetErrors(ERRORCODE_SALESIDERROR, ERRORINFO_SALESIDERROR);
return false;
}
// 操作人id
$operateID = isset($request_data['operateid']) ? $request_data['operateid'] : '';
// 兼容如果有操作人的id就判断他是否有权限
if(!empty($operateID)) {
$command = /** @lang text */
<<<EOL
select
saus_power salespower
from
sales_user
where
saus_agentid = ? and saus_channelid = ? and saus_salesid = ?
EOL;
$dbSalesInfo = $this->PDO_Request($command, $agentID, $channelID, $operateID);
if ( !is_array($dbSalesInfo) || count($dbSalesInfo) < 1) {
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
return false;
}
$salePower = $dbSalesInfo[0]['salespower'];
if (empty($salePower))
{
$dbAgentInfo = $this->PDO_Request(/** @lang text */'select default_sales_power as agen_salespower from ct_agent_list where agent_id = ?;', $agentID);
if (!is_array($dbAgentInfo) || count($dbAgentInfo) < 1) {
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
return false;
}
$salePower = $dbAgentInfo[0]['agen_salespower'];
}
switch (intval(substr($salePower, 0, 1)))
{
case 0: /// 无权限
$outParam->SetErrors(ERRORCODE_NOPOWERERROR, ERRORINFO_NOPOWERERROR);
return false;
break;
case 1: /// 需要判断是否绑定自己
$to_sales = $this->pdo_request(/** @lang text */
'select saus_parentid from sales_user where saus_agentid = ? and saus_channelid = ? and saus_salesid = ?',
$agentID, $channelID, $salesID);
if (!$this->pdo_isdone()) {
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
return false;
}
if (empty($to_sales)) {
$outParam->SetErrors(ERRORCODE_INVITECODE_NOT_EXISTS, ERRORINFO_INVITECODE_NOT_EXISTS);
return false;
}
if ($to_sales[0]['saus_parentid'] != $operateID) {
$outParam->SetErrors(ERRORCODE_ONLYBINDSELFERROR, ERRORINFO_ONLYBINDSELFERROR);
return false;
}
break;
case 2: /// 可以给所有代理转卡
break;
default:
$outParam->SetErrors(ERRORINFO_NOPOWERERROR, ERRORCODE_NOPOWERERROR);
return false;
break;
}
}
$dbSaleInfo = $this->PDO_Request(/** @lang text */
'
SELECT
saus_nickname, saus_salesid, saus_roomcard, saus_bean, saus_status, saus_parentid
FROM
sales_user
WHERE
saus_salesman=1 AND saus_agentid=? AND saus_channelid=? AND saus_salesid=?', $agentID, $channelID, $salesID);
if (!is_array($dbSaleInfo))
{
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
return false;
}
if (count($dbSaleInfo) < 1)
{
$outParam->SetErrors(ERRORCODE_SALESNOTEXISTERROR, ERRORINFO_SALESNOTEXISTERROR);
return false;
}
$outParam->biz_content = array(
'state' => 0,
'salesid' => $dbSaleInfo[0]['saus_salesid'],
'salesname' => $dbSaleInfo[0]['saus_nickname'],
'roomcard' => $dbSaleInfo[0]['saus_roomcard'],
'been' => $dbSaleInfo[0]['saus_bean'],
'salesstatus' => $dbSaleInfo[0]['saus_status'],
'parentid' => $dbSaleInfo[0]['saus_parentid'],
);
return true;
}
/**
* 总代理扣除 玩家 的房卡或星星
* 被请求方法示例参数固定为RequestParameter和ReturnParameter对象返回值固定为true(成功)和false(失败)
* @param RequestParameter $inParam
* @param ReturnParameter $outParam
* @return bool
*/
public function deductPlayer($inParam, $outParam)
{
//参数格式错误
//$outParam->SetErrors(400, '该功能已关闭');
//return false;
$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($channelID))
{
$outParam->SetErrors(ERRORCODE_CHANNELIDERROR, ERRORINFO_CHANNELIDERROR);
return false;
}
//操作人id
$salesID = isset($request_data['salesid']) ? $request_data['salesid'] : '';
if (empty($salesID))
{
$outParam->SetErrors(ERRORCODE_SALESIDERROR, ERRORINFO_SALESIDERROR);
return false;
}
//被扣id
$deductID = isset($request_data['deductid']) ? $request_data['deductid'] : '';
if (empty($deductID))
{
$outParam->SetErrors(ERRORCODE_SALESIDERROR, ERRORINFO_SALESIDERROR);
return false;
}
//扣除数量
$amount = isset($request_data['amount']) ? intval($request_data['amount']) : 0;
if ($amount <= 0)
{
$outParam->SetErrors(ERRORCODE_AMOUNTERROR, ERRORINFO_AMOUNTERROR);
return false;
}
//操作类型 0、扣除房卡1、扣除星星
$type = isset($request_data['type']) ? intval($request_data['type']) : 0;
//只有总代理才有权限
$dbSalesInfo = $this->PDO_Request(/** @lang text */
'select idx, user_id, 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;
}
if ($type == 0)
{
//扣玩家房卡,判断玩家是否存在
$dbPlayerInfo = $this->PDO_Request(/** @lang text */
'select idx, play_roomcard from player where play_agentid=? and play_channelid=? and play_playerid=?',
$agentID, $channelID, $deductID);
if (!is_array($dbPlayerInfo))
{
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
return false;
}
if (count($dbPlayerInfo) < 1)
{
$outParam->SetErrors(ERRORCODE_PLAYERNOTEXISTERROR, ERRORINFO_PLAYERNOTEXISTERROR);
return false;
}
//判断玩家房卡数是否够
//获取游戏中,玩家房卡数量
/*$gamePlayerInfo = $this->getGamePlayerInfo($agentID, $deductID, REQUEST_USER_INFO);
if (!is_array($gamePlayerInfo))
{
$outParam->SetErrors(ERRORCODE_PLAYERNOTEXISTERROR, ERRORINFO_PLAYERNOTEXISTERROR);
return false;
}
if (!isset($gamePlayerInfo['data']['roomcard']))
{
$outParam->SetErrors(ERRORCODE_PLAYERNOTEXISTERROR, ERRORINFO_PLAYERNOTEXISTERROR);
return false;
}
$gamePlayerCard = intval($gamePlayerInfo['data']['roomcard']);
//判断房卡数是否够
if ($gamePlayerCard < $amount)
{
$outParam->SetErrors(ERRORCODE_ROOMCARDENOUGHERROR, ERRORINFO_ROOMCARDENOUGHERROR);
return false;
}
$leftCard = $gamePlayerCard - $amount;
if ($leftCard < 0)
$leftCard = 0;*/
if ($dbPlayerInfo[0]['play_roomcard'] < $amount)
{
$outParam->SetErrors(ERRORCODE_ROOMCARDENOUGHERROR, ERRORINFO_ROOMCARDENOUGHERROR);
return false;
}
//事务开始
//扣除玩家房卡
$this->PDO_BeginTransaction();
try
{
//扣除玩家房卡
$ret = $this->PDO_Execute(/** @lang */
'
UPDATE player
SET play_roomcard=play_roomcard - ?
WHERE idx=?;', $amount, $dbPlayerInfo[0]['idx']);
if (!$ret || !$this->PDO_IsDone())
throw new Exception($this->GetErrorInfo(), $this->GetErrorCode());
//把房卡加入到总代理里面
// $ret = $this->PDO_Execute(/** @lang */
// 'update sales_user set saus_roomcard=saus_roomcard+? where idx=?;',
// $amount, $dbSalesInfo[0]['idx']);
// if (!$ret || !$this->PDO_IsDone())
// throw new Exception($this->GetErrorInfo(), $this->GetErrorCode());
// if (!empty($dbSalesInfo[0]['user_id']))
// {
// $ret = $this->pdo_execute(/** @lang text */
// 'update ct_user_account set card = card + ? where agent_id = ? and channel_id = ? and user_id = ?',
// $amount, $agentID, $channelID, $dbSalesInfo[0]['user_id']);
// if (!$ret)
// throw new Exception($this->GetErrorInfo(), $this->GetErrorCode());
// }
//记录日志
$log_res = $this->PDO_Execute(/** @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 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', $agentID, $channelID, $salesID, $agentID, $channelID, $deductID, 2, -$amount, '总代理扣除玩家房卡', time(), 0);
if (!$log_res)
throw new Exception($this->GetErrorInfo(), $this->GetErrorCode());
//记录本地日志
$ret = $this->PDO_Execute(/** @lang */
'
insert into sales_operate_log
(agent_id, channel_id, player_id, to_agent_id, to_channel_id, to_player_id, operate_type, operate_data, create_time)
values
(?, ?, ?, ?, ?, ?, ?, ?, ?)',
$agentID, $channelID, $salesID, $agentID, $channelID, $deductID, 21,
json_encode(array(
'before' => $dbPlayerInfo[0]['play_roomcard'],
'deduct' => $amount,
'after' => ($dbPlayerInfo[0]['play_roomcard'] - $amount),
)),
date('Y-m-d H:i:s', time()));
if (!$ret || !$this->PDO_IsDone())
throw new Exception($this->GetErrorInfo(), $this->GetErrorCode());
$sql = /** @lang */'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,
?,?,?,2,now(),?,
?);';
$ret = $this->PDO_Execute($sql, $agentID, $channelID, $salesID, $deductID, $amount, $dbPlayerInfo[0]['play_roomcard'], ($dbPlayerInfo[0]['play_roomcard'] - $amount), $salesID, '总代扣卡');
if (!$ret || !$this->PDO_IsDone())
throw new Exception($this->GetErrorInfo(), $this->GetErrorCode());
$this->PDO_Commit();
return true;
}
catch (Exception $e)
{
$this->PDO_Rollback();
$outParam->SetErrors($e->getCode(), $e->getMessage());
return false;
}
//事务结束
}
else if ($type == 1)
{
//扣玩家星星,判断玩家是否存在
$dbPlayerInfo = $this->PDO_Request(/** @lang */
'
SELECT idx, play_bean
FROM player
WHERE play_agentid=? AND play_channelid=? AND play_playerid=?', $agentID, $channelID, $deductID);
if (!is_array($dbPlayerInfo))
{
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
return false;
}
if (count($dbPlayerInfo) < 1)
{
$outParam->SetErrors(ERRORCODE_PLAYERNOTEXISTERROR, ERRORINFO_PLAYERNOTEXISTERROR);
return false;
}
//判断玩家房卡数是否够
//获取游戏中,玩家房卡数量
/*$gamePlayerInfo = $this->getGamePlayerInfo($agentID, $deductID, REQUEST_USER_INFO);
if (!is_array($gamePlayerInfo))
{
$outParam->SetErrors(ERRORCODE_PLAYERNOTEXISTERROR, ERRORINFO_PLAYERNOTEXISTERROR);
return false;
}
if (!isset($gamePlayerInfo['data']['bean']))
{
$outParam->SetErrors(ERRORCODE_PLAYERNOTEXISTERROR, ERRORINFO_PLAYERNOTEXISTERROR);
return false;
}
$gamePlayerBean = intval($gamePlayerInfo['data']['bean']);
//判断房卡数是否够
if ($gamePlayerBean < $amount)
{
$outParam->SetErrors(ERRORCODE_STARNOENOUGHERROR, ERRORINFO_STARNOENOUGHERROR);
return false;
}
$leftBean = $gamePlayerBean - $amount;
if ($leftBean < 0)
$leftBean = 0;*/
if ($dbPlayerInfo[0]['play_bean'] < $amount)
{
$outParam->SetErrors(ERRORCODE_STARNOENOUGHERROR, ERRORINFO_STARNOENOUGHERROR);
return false;
}
$leftBean = $dbPlayerInfo[0]['play_bean'] - $amount;
//事务开始
//扣除玩家星星
$this->PDO_BeginTransaction();
try
{
$ret = $this->PDO_Execute(/** @lang */
'update player set play_bean=? where idx=?;', $leftBean, $dbPlayerInfo[0]['idx']);
if (!$ret || !$this->PDO_IsDone())
throw new Exception($this->GetErrorInfo(), $this->GetErrorCode());
//把星星加入到总代理里面
// $ret = $this->PDO_Execute(/** @lang */
// 'update sales_user set saus_bean=saus_bean+? where idx=?;', $amount, $dbSalesInfo[0]['idx']);
// if (!$ret || !$this->PDO_IsDone())
// throw new Exception($this->GetErrorInfo(), $this->GetErrorCode());
//
// if (!empty($dbSalesInfo[0]['user_id']))
// {
// $ret = $this->pdo_execute(/** @lang text */
// 'update ct_user_account set currency = currency + ? where agent_id = ? and channel_id = ? and user_id = ?',
// $amount, $agentID, $channelID, $dbSalesInfo[0]['user_id']);
// if (!$ret)
// throw new Exception($this->GetErrorInfo(), $this->GetErrorCode());
// }
//记录日志
$log_res = $this->PDO_Execute(/** @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 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', $agentID, $channelID, $salesID, $agentID, $channelID, $deductID, 12, -$amount, '总代理扣除玩家星星', time(), 0);
if (!$log_res)
throw new Exception($this->GetErrorInfo(), $this->GetErrorCode());
//记录本地日志
//记录本地日志
$ret = $this->PDO_Execute(/** @lang */
'
insert into sales_operate_log
(agent_id, channel_id, player_id, to_agent_id, to_channel_id, to_player_id, operate_type, operate_data, create_time)
values
(?, ?, ?, ?, ?, ?, ?, ?, ?)',
$agentID, $channelID, $salesID, $agentID, $channelID, $deductID, 23,
json_encode(array(
'before' => $dbPlayerInfo[0]['play_bean'],
'deduct' => $amount,
'after' => $leftBean,
)),
date('Y-m-d H:i:s', time()));
if (!$ret || !$this->PDO_IsDone())
throw new Exception($this->GetErrorInfo(), $this->GetErrorCode());
$sql = /** @lang */'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,2,
?,?,?,2,now(),?,
?);';
$ret = $this->PDO_Execute($sql, $agentID, $channelID, $salesID, $deductID, $amount, $dbPlayerInfo[0]['play_bean'], $leftBean, $salesID, '总代扣星星');
if (!$ret || !$this->PDO_IsDone())
throw new Exception($this->GetErrorInfo(), $this->GetErrorCode());
$this->PDO_Commit();
return true;
}
catch (Exception $e)
{
$this->PDO_Rollback();
$outParam->SetErrors($e->getCode(), $e->getMessage());
return false;
}
//事务结束
}
else
return false;
}
/**
* 总代理扣除 代理 的房卡或星星
* 被请求方法示例参数固定为RequestParameter和ReturnParameter对象返回值固定为true(成功)和false(失败)
* @param RequestParameter $inParam
* @param ReturnParameter $outParam
* @return bool
*/
public function deductSales($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($channelID))
{
$outParam->SetErrors(ERRORCODE_CHANNELIDERROR, ERRORINFO_CHANNELIDERROR);
return false;
}
//操作人id
$salesID = isset($request_data['salesid']) ? $request_data['salesid'] : '';
if (empty($salesID))
{
$outParam->SetErrors(ERRORCODE_SALESIDERROR, ERRORINFO_SALESIDERROR);
return false;
}
//被扣id
$deductID = isset($request_data['deductid']) ? $request_data['deductid'] : '';
if (empty($deductID))
{
$outParam->SetErrors(ERRORCODE_SALESIDERROR, ERRORINFO_SALESIDERROR);
return false;
}
// 不能自己扣自己
if($salesID == $deductID) {
$outParam->SetErrors(200, '不能扣除自己');
return false;
}
//扣除数量
$amount = isset($request_data['amount']) ? intval($request_data['amount']) : 0;
if ($amount <= 0)
{
$outParam->SetErrors(ERRORCODE_AMOUNTERROR, ERRORINFO_AMOUNTERROR);
return false;
}
//操作类型 0、扣除代理房卡1、扣除代理星星
$type = isset($request_data['type']) ? intval($request_data['type']) : 0;
//只有总代理才有权限
$dbSalesInfo = $this->PDO_Request(/** @lang text */
'select idx, user_id, 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;
}
$sales_user = $dbSalesInfo[0]['user_id']; /// 代理的用户号
//扣代理房卡/星星, 获取代理信息
$dbDeductInfo = $this->PDO_Request(/** @lang text */
'select idx, user_id, saus_roomcard, saus_bean, global_power from sales_user where saus_agentid=? and saus_channelid=? and saus_salesid=?',
$agentID, $channelID, $deductID);
if (!is_array($dbDeductInfo))
{
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
return false;
}
if (count($dbDeductInfo) < 1)
{
$outParam->SetErrors(ERRORCODE_SALESNOTEXISTERROR, ERRORINFO_SALESNOTEXISTERROR);
return false;
}
if ($dbDeductInfo[0]['global_power'] == 1)
{
$outParam->SetErrors(200, '不能扣除总代理');
return false;
}
if ($type == 0)
{
/// 被扣代理的用户号
if (empty($deduct_user = $dbDeductInfo[0]['user_id']))
$salesCard = intval($dbDeductInfo[0]['saus_roomcard']);
else
{
$ret = $this->pdo_request(/** @lang text */
'select card from ct_user_account where agent_id = ? and channel_id = ? and user_id = ?',
$agentID, $channelID, $deduct_user);
if (!$this->pdo_isdone())
{
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
return false;
}
$salesCard = $ret[0]['card'];
}
if ($salesCard < $amount)
{
$outParam->SetErrors(ERRORCODE_ROOMCARDENOUGHERROR, ERRORINFO_ROOMCARDENOUGHERROR);
return false;
}
$leftCard = $salesCard - $amount;
if ($leftCard < 0)
$leftCard = 0;
//事务开始
$this->PDO_BeginTransaction();
try
{
if ($amount <= intval($dbDeductInfo[0]['saus_roomcard'])) /// 如果当前账户足够本次扣减,则直接扣除
{
$ret = $this->pdo_execute(/** @lang text */
'update sales_user set saus_roomcard = saus_roomcard - ? where idx = ?',
$amount, $dbDeductInfo[0]['idx']);
if (!$ret)
throw new Exception($this->GetErrorInfo(), $this->GetErrorCode());
}
else
{
/// 如果当前账户不够本次扣减,则先清空当前账户,再扣除绑定的其他账户
$ret = $this->pdo_execute(/** @lang text */
'update sales_user set saus_roomcard = 0 where idx = ?',
$dbDeductInfo[0]['idx']);
if (!$ret)
throw new Exception($this->GetErrorInfo(), $this->GetErrorCode());
/// 扣除绑定的其他账户
$need_amount = $amount - intval($dbDeductInfo[0]['saus_roomcard']);
$command = /** @lang text */<<<EOL
update
sales_user a,
(
select
_u.idx,
_u.saus_salesid,
_u.saus_roomcard,
if(@c + _u.saus_roomcard < {$need_amount}, @n := _u.saus_roomcard, @n := {$need_amount} - @c) n,
if(@c + _u.saus_roomcard < {$need_amount}, @c := @c + _u.saus_roomcard, @c := {$need_amount}) c
from
sales_user _u,
(select @n := 0) _n,
(select @c := 0) _c
where
_u.saus_agentid = ? and _u.saus_channelid = ? and _u.user_id = ? and
@c < {$need_amount}
order by
_u.idx
) b
set
a.saus_roomcard = a.saus_roomcard - b.n
where
a.idx = b.idx
EOL;
if (!$this->pdo_execute($command, $agentID, $channelID, $deduct_user))
throw new Exception($this->GetErrorInfo(), $this->GetErrorCode());
}
/// 把代理扣除房卡,加入到总代里面
// $ret = $this->PDO_Execute(/** @lang */
// 'update sales_user set saus_roomcard=saus_roomcard+? where idx=?;',
// $amount, $dbSalesInfo[0]['idx']);
// if (!$ret)
// throw new Exception($this->GetErrorInfo(), $this->GetErrorCode());
/// 如果有绑定主账户,则需要更新主账户信息
if (!empty($sales_user))
{
$ret = $this->pdo_execute(/** @lang text */
'update ct_user_account set card = card + ? where agent_id = ? and channel_id = ? and user_id = ?',
$amount, $agentID, $channelID, $sales_user);
if (!$ret)
throw new Exception($this->GetErrorInfo(), $this->GetErrorCode());
}
/// 记录本地日志
$ret = $this->PDO_Execute(/** @lang */
'insert into sales_operate_log(agent_id, channel_id, player_id, to_agent_id, to_channel_id, to_player_id, operate_type, operate_data, create_time)values(?, ?, ?, ?, ?, ?, ?, ?, ?)',
$agentID, $channelID, $salesID, $agentID, $channelID, $deductID, 22,
json_encode(array(
'before' => $salesCard,
'deduct' => $amount,
'after' => $leftCard,
)),
date('Y-m-d H:i:s', time()));
if (!$ret || !$this->PDO_IsDone())
throw new Exception($this->GetErrorInfo(), $this->GetErrorCode());
$sql = /** @lang */'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 (
?,?,?,?,2,1,
?,?,?,2,now(),?,
?);';
$ret = $this->PDO_Execute($sql, $agentID, $channelID, $salesID, $deductID, $amount, $salesCard, $leftCard, $salesID, '总代扣卡');
if (!$ret || !$this->PDO_IsDone())
throw new Exception($this->GetErrorInfo(), $this->GetErrorCode());
$this->PDO_Commit();
return true;
}
catch (Exception $e)
{
$this->PDO_Rollback();
$outParam->SetErrors($e->getCode(), $e->getMessage());
return false;
}
//事务结束
}
else if ($type == 1)
{
/// 被扣代理的用户号
if (empty($deduct_user = $dbDeductInfo[0]['user_id']))
$saleBean = intval($dbDeductInfo[0]['saus_bean']);
else
{
$ret = $this->pdo_request(/** @lang text */
'select currency from ct_user_account where agent_id = ? and channel_id = ? and user_id = ?',
$agentID, $channelID, $deduct_user);
if (!$this->pdo_isdone())
{
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
return false;
}
$saleBean = $ret[0]['currency'];
}
if ($saleBean < $amount)
{
$outParam->SetErrors(ERRORCODE_STARNOENOUGHERROR, ERRORINFO_STARNOENOUGHERROR);
return false;
}
$leftBean = $saleBean - $amount;
if ($leftBean < 0)
$leftBean = 0;
/// 事务开始
$this->PDO_BeginTransaction();
try
{
if ($amount <= intval($dbDeductInfo[0]['saus_bean'])) /// 如果当前账户足够本次扣减,则直接扣除
{
$ret = $this->pdo_execute(/** @lang text */
'update sales_user set saus_bean = saus_bean - ? where idx = ?',
$amount, $dbDeductInfo[0]['idx']);
if (!$ret)
throw new Exception($this->GetErrorInfo(), $this->GetErrorCode());
}
else
{
/// 如果当前账户不够本次扣减,则先清空当前账户,再扣除绑定的其他账户
$ret = $this->pdo_execute(/** @lang text */
'update sales_user set saus_bean = 0 where idx = ?',
$dbDeductInfo[0]['idx']);
if (!$ret)
throw new Exception($this->GetErrorInfo(), $this->GetErrorCode());
/// 扣除绑定的其他账户
$need_amount = $amount - intval($dbDeductInfo[0]['saus_bean']);
$command = /** @lang text */<<<EOL
update
sales_user a,
(
select
_u.idx,
_u.saus_salesid,
_u.saus_bean,
if(@c + _u.saus_bean < {$need_amount}, @n := _u.saus_bean, @n := {$need_amount} - @c) n,
if(@c + _u.saus_bean < {$need_amount}, @c := @c + _u.saus_bean, @c := {$need_amount}) c
from
sales_user _u,
(select @n := 0) _n,
(select @c := 0) _c
where
_u.saus_agentid = ? and _u.saus_channelid = ? and _u.user_id = ? and
@c < {$need_amount}
order by
_u.idx
) b
set
a.saus_bean = a.saus_bean - b.n
where
a.idx = b.idx
EOL;
if (!$this->pdo_execute($command, $agentID, $channelID, $deduct_user))
throw new Exception($this->GetErrorInfo(), $this->GetErrorCode());
}
/// 把代理扣除的星星,加入到总代里面
// $ret = $this->PDO_Execute(/** @lang */
// 'update sales_user set saus_bean = saus_bean + ? where idx=?;',
// $amount, $dbSalesInfo[0]['idx']);
// if (!$ret)
// throw new Exception($this->GetErrorInfo(), $this->GetErrorCode());
/// 如果有绑定主账户,则需要更新主账户信息
if (!empty($sales_user))
{
$ret = $this->pdo_execute(/** @lang text */
'update ct_user_account set currency = currency + ? where agent_id = ? and channel_id = ? and user_id = ?',
$amount, $agentID, $channelID, $sales_user);
if (!$ret)
throw new Exception($this->GetErrorInfo(), $this->GetErrorCode());
}
//记录本地日志
$ret = $this->PDO_Execute(/** @lang */
'insert into sales_operate_log (agent_id, channel_id, player_id, to_agent_id, to_channel_id, to_player_id, operate_type, operate_data, create_time) values (?, ?, ?, ?, ?, ?, ?, ?, ?)',
$agentID, $channelID, $salesID, $agentID, $channelID, $deductID, 24,
json_encode(array(
'before' => $saleBean,
'deduct' => $amount,
'after' => $leftBean,
)),
date('Y-m-d H:i:s', time()));
if (!$ret || !$this->PDO_IsDone())
throw new Exception($this->GetErrorInfo(), $this->GetErrorCode());
$sql = /** @lang */'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 (
?,?,?,?,2,2,
?,?,?,2,now(),?,
?);';
$ret = $this->PDO_Execute($sql, $agentID, $channelID, $salesID, $deductID, $amount, $saleBean, $leftBean, $salesID, '总代扣星星');
if (!$ret || !$this->PDO_IsDone())
throw new Exception($this->GetErrorInfo(), $this->GetErrorCode());
$this->PDO_Commit();
return true;
}
catch (Exception $e)
{
$this->PDO_Rollback();
$outParam->SetErrors($e->getCode(), $e->getMessage());
return false;
}
//事务结束
}
else
return false;
}
/**
* 总代理查询代理下面的所有子代理或者玩家
* 被请求方法示例参数固定为RequestParameter和ReturnParameter对象返回值固定为true(成功)和false(失败)
* @param RequestParameter $inParam
* @param ReturnParameter $outParam
* @return bool
*/
public function salesChilds($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($channelID))
{
$outParam->SetErrors(ERRORCODE_CHANNELIDERROR, ERRORINFO_CHANNELIDERROR);
return false;
}
//操作人id
$salesID = isset($request_data['salesid']) ? $request_data['salesid'] : '';
if (empty($salesID))
{
$outParam->SetErrors(ERRORCODE_SALESIDERROR, ERRORINFO_SALESIDERROR);
return false;
}
//查询的代理id
$queryID = isset($request_data['queryid']) ? $request_data['queryid'] : '';
if (empty($queryID))
{
$outParam->SetErrors(ERRORCODE_SALESIDERROR, ERRORINFO_SALESIDERROR);
return false;
}
//操作类型 0、查询子代理1、查询绑定的玩家
$type = isset($request_data['type']) ? intval($request_data['type']) : 0;
$page_index = empty($request_data['page_index']) ? 1 : intval($request_data['page_index']);
$page_size = empty($request_data['page_size']) ? 10 : intval($request_data['page_size']);
$start = ($page_index - 1) * $page_size;
$strPage = '';
if (!empty($request_data['page_index']))
{
$strPage .= " LIMIT {$start},{$page_size} ";
}
//只有总代理才有权限
$dbSalesInfo = $this->PDO_Request(/** @lang */
'
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;
}
$dbQueryInfo = $this->PDO_Request(/** @lang */
'
SELECT idx, saus_bean
FROM sales_user
WHERE saus_agentid=? AND saus_channelid=? AND saus_salesid=?', $agentID, $channelID, $queryID);
if (!is_array($dbQueryInfo))
{
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
return false;
}
if (count($dbQueryInfo) < 1)
{
$outParam->SetErrors(ERRORCODE_SALESNOTEXISTERROR, ERRORINFO_SALESNOTEXISTERROR);
return false;
}
if ($type == 0)
{
//查询代理下面的所有子代理
$childs = $this->PDO_Request(/** @lang */
"
SELECT saus_nickname as nickname, saus_avatar as avatar, saus_sex, saus_salesid as id, saus_level, saus_roomcard as roomcard, saus_bean as star, saus_power,
saus_status, global_power, saus_tel as tel, saus_wechat as wechat
FROM sales_user
WHERE saus_agentid=? AND saus_channelid=? AND saus_parentid=?
ORDER BY idx desc {$strPage};", $agentID, $channelID, $queryID);
if (!is_array($childs))
{
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
return false;
}
$page_count = 1;
if (!empty($request_data['page_index']))
{
$dbData = $this->PDO_Request(/** @lang text */
"
SELECT count(1) num
FROM sales_user
WHERE saus_agentid=? AND saus_channelid=? AND saus_parentid=?;", $agentID, $channelID, $queryID);
if (!is_array($dbData) || count($dbData) < 1)
{
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
return false;
}
$page_count = intval($dbData[0]['num']) / $page_size + 1;
}
$outParam->biz_content = array(
'detail' => $childs,
'page_index' => $page_index,
'page_size' => $page_size,
'page_count' => $page_count,
);
return true;
}
else if ($type == 1)
{
//查询代理下面的所有玩家
$childs = $this->PDO_Request(/** @lang */
"
SELECT play_playerid as id, play_nickname as nickname, play_avatar as avatar, play_sex, play_roomcard as roomcard, play_bean as star, play_status
FROM player
WHERE play_agentid=? AND play_channelid=? AND play_invitecode=?
ORDER BY idx DESC {$strPage};", $agentID, $channelID, $queryID);
if (!is_array($childs))
{
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
return false;
}
$page_count = 1;
if (!empty($request_data['page_index']))
{
$dbData = $this->PDO_Request(/** @lang text */
"
SELECT count(1) num
FROM player
WHERE play_agentid=? AND play_channelid=? AND play_invitecode=?;", $agentID, $channelID, $queryID);
if (!is_array($dbData) || count($dbData) < 1)
{
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
return false;
}
$page_count = intval($dbData[0]['num']) / $page_size + 1;
}
$outParam->biz_content = array(
'detail' => $childs,
'page_index' => $page_index,
'page_size' => $page_size,
'page_count' => $page_count,
);
return true;
}
else
return false;
}
/**
* 总代理查询玩家房卡或星星流水记录
* 被请求方法示例参数固定为RequestParameter和ReturnParameter对象返回值固定为true(成功)和false(失败)
* @param RequestParameter $inParam
* @param ReturnParameter $outParam
* @return bool
*/
public function playerCardStarRecord($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($channelID))
{
$outParam->SetErrors(ERRORCODE_CHANNELIDERROR, ERRORINFO_CHANNELIDERROR);
return false;
}
//操作人id
$salesID = isset($request_data['salesid']) ? $request_data['salesid'] : '';
if (empty($salesID))
{
$outParam->SetErrors(ERRORCODE_SALESIDERROR, ERRORINFO_SALESIDERROR);
return false;
}
$playerID = isset($request_data['playerid']) ? $request_data['playerid'] : '';
if (empty($playerID))
{
$outParam->SetErrors(ERRORCODE_PLAYERIDERROR, ERRORINFO_PLAYERIDERROR);
return false;
}
$str_time = '';
$array_param = array(
$agentID,
$playerID,
);
$beginTime = isset($request_data['begintime']) ? $request_data['begintime'] : '';
$endTime = isset($request_data['endtime']) ? $request_data['endtime'] : '';
$page_index = empty($request_data['page_index']) ? 1 : intval($request_data['page_index']);
$page_size = empty($request_data['page_size']) ? 10 : intval($request_data['page_size']);
$start = ($page_index - 1) * $page_size;
$strPage = '';
if (!empty($request_data['page_index']))
{
$strPage .= " LIMIT {$start},{$page_size} ";
}
/// 操作类型 0、查询房卡1、查询星星
$type = isset($request_data['type']) ? intval($request_data['type']) : 0;
/// 只有总代理才有权限
$dbSalesInfo = $this->PDO_Request(/** @lang */'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;
}
/// 判断玩家是否存在
$dbPlayerInfo = $this->PDO_Request(/** @lang */'select idx, play_openid from player where play_agentid=? and play_playerid=?;', $agentID, $playerID);
if (!is_array($dbPlayerInfo))
{
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
return false;
}
if (count($dbPlayerInfo) < 1)
{
$outParam->SetErrors(ERRORCODE_PLAYERNOTEXISTERROR, ERRORINFO_PLAYERNOTEXISTERROR);
return false;
}
$page_count = 1;
//0、房卡记录1、星星记录
if ($type == 0)
{
if (!empty($beginTime))
{
$str_time .= ' and a.sase_selltime >= ? ';
$array_param[] = $beginTime;
}
if (!empty($endTime))
{
$str_time .= ' and a.sase_selltime <= ? ';
$array_param[] = $endTime;
}
if (!empty($beginTime) && !empty($endTime) && $beginTime > $endTime)
{
$outParam->SetErrors(ERRORCODE_TIMEERROR, ERRORINFO_TIMEERROR);
return false;
}
$command = /** @lang text */<<<EOL
select
a.idx,
a.sase_amount amount,
a.sase_selltime time,
b.saus_salesid salesid,
b.saus_nickname nickname,
b.saus_avatar avatar
from
sales_sellbill a
inner join
sales_user b
on
a.sase_agentid = b.saus_agentid and
a.channel_id = b.saus_channelid and
a.from_sales = b.saus_salesid
left join
sales_user c
on
a.sase_agentid = c.saus_agentid and
a.channel_id = c.saus_channelid and
a.sase_playerid = c.player_id
#left join
# player d
#on
# a.sase_agentid = d.play_agentid and
# a.channel_id = d.play_channelid and
# a.sase_playerid = d.play_playerid
where
ifnull(b.statistic_type, 0) = 0 and
ifnull(c.statistic_type, 0) = 0 and
a.sase_agentid = ? and
a.sase_playerid = ? {$str_time}
order by
a.idx DESC
{$strPage}
EOL;
$dbRecord = $this->PDO_Request($command, $array_param);
if (!$this->PDO_IsDone() || !is_array($dbRecord))
{
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
return false;
}
if (!empty($request_data['page_index']))
{
$command = /** @lang text */<<<EOL
select
count(0) num
from
sales_sellbill a
inner join
sales_user b
on
a.sase_agentid = b.saus_agentid and
a.channel_id = b.saus_channelid and
a.from_sales = b.saus_salesid
left join
sales_user c
on
a.sase_agentid = c.saus_agentid and
a.channel_id = c.saus_channelid and
a.sase_playerid = c.player_id
#left join
# player d
#on
# a.sase_agentid = d.play_agentid and
# a.channel_id = d.play_channelid and
# a.sase_playerid = d.play_playerid
where
ifnull(b.statistic_type, 0) = 0 and
ifnull(c.statistic_type, 0) = 0 and
a.sase_agentid = ? and
a.sase_playerid = ? {$str_time}
EOL;
$dbCount = $this->PDO_Request($command, $array_param);
if (!is_array($dbCount) || count($dbCount) < 1)
{
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
return false;
}
$page_count = intval($dbCount[0]['num']) / $page_size + 1;
}
}
elseif ($type == 1)
{
if (!empty($beginTime))
{
$str_time .= ' and a.ssbe_selltime >= ? ';
$array_param[] = $beginTime;
}
if (!empty($endTime))
{
$str_time .= ' and a.ssbe_selltime <= ? ';
$array_param[] = $endTime;
}
if (!empty($beginTime) && !empty($endTime) && $beginTime > $endTime)
{
$outParam->SetErrors(ERRORCODE_TIMEERROR, ERRORINFO_TIMEERROR);
return false;
}
$command = /** @lang text */<<<EOL
select
a.idx,
a.ssbe_amount amount,
a.ssbe_selltime time,
b.saus_salesid salesid,
b.saus_nickname nickname,
b.saus_avatar avatar
from
sales_sellbill_bean a
inner join
sales_user b
on
a.ssbe_agentid = b.saus_agentid and
a.channel_id = b.saus_channelid and
a.from_sales = b.saus_salesid
left join
sales_user c
on
a.ssbe_agentid = c.saus_agentid and
a.channel_id = c.saus_channelid and
a.ssbe_playerid = c.player_id
#left join
# player d
#on
# a.ssbe_agentid = d.play_agentid and
# a.channel_id = d.play_channelid and
# a.ssbe_playerid = d.play_playerid
where
ifnull(b.statistic_type, 0) = 0 and
ifnull(c.statistic_type, 0) = 0 and
a.ssbe_agentid = ? and
a.ssbe_playerid = ? {$str_time}
order by
a.idx desc
{$strPage}
EOL;
$dbRecord = $this->PDO_Request($command, $array_param);
if (!$this->PDO_IsDone() || !is_array($dbRecord))
{
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
return false;
}
if (!empty($request_data['page_index']))
{
$command = /** @lang text */<<<EOL
select
count(0) num
from
sales_sellbill_bean a
inner join
sales_user b
on
a.ssbe_agentid = b.saus_agentid and
a.channel_id = b.saus_channelid and
a.from_sales = b.saus_salesid
left join
sales_user c
on
a.ssbe_agentid = c.saus_agentid and
a.channel_id = c.saus_channelid and
a.ssbe_playerid = c.player_id
#left join
# player d
#on
# a.ssbe_agentid = d.play_agentid and
# a.channel_id = d.play_channelid and
# a.ssbe_playerid = d.play_playerid
where
ifnull(b.statistic_type, 0) = 0 and
ifnull(c.statistic_type, 0) = 0 and
a.ssbe_agentid = ? and
a.ssbe_playerid = ? {$str_time}
EOL;
$dbCount = $this->PDO_Request($command, $array_param);
if (!is_array($dbCount) || count($dbCount) < 1)
{
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
return false;
}
$page_count = intval($dbCount[0]['num']) / $page_size + 1;
}
}
else
{
return false;
}
$outParam->biz_content = array(
'record' => $dbRecord,
'page_index' => $page_index,
'page_size' => $page_size,
'page_count' => intval($page_count),
);
return true;
}
/**
* 总代理查询代理房卡或星星 获得 记录
* 被请求方法示例参数固定为RequestParameter和ReturnParameter对象返回值固定为true(成功)和false(失败)
* @param RequestParameter $inParam
* @param ReturnParameter $outParam
* @return bool
*/
public function salesCardStarRecord($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($channelID))
{
$outParam->SetErrors(ERRORCODE_CHANNELIDERROR, ERRORINFO_CHANNELIDERROR);
return false;
}
//操作人id
$salesID = isset($request_data['salesid']) ? $request_data['salesid'] : '';
if (empty($salesID))
{
$outParam->SetErrors(ERRORCODE_SALESIDERROR, ERRORINFO_SALESIDERROR);
return false;
}
//查询的id
$queryID = isset($request_data['queryid']) ? $request_data['queryid'] : '';
if (empty($queryID))
{
$outParam->SetErrors(ERRORCODE_SALESIDERROR, ERRORINFO_SALESIDERROR);
return false;
}
$str_time = '';
//$array_param = array($agentID, $queryID, $channelID);
$beginTime = isset($request_data['begintime']) ? $request_data['begintime'] : '';
$endTime = isset($request_data['endtime']) ? $request_data['endtime'] : '';
$page_index = empty($request_data['page_index']) ? 1 : intval($request_data['page_index']);
$page_size = empty($request_data['page_size']) ? 10 : intval($request_data['page_size']);
$start = ($page_index - 1) * $page_size;
$strPage = '';
if (!empty($request_data['page_index']))
{
$strPage .= " LIMIT {$start},{$page_size} ";
}
//操作类型 0、查询房卡1、查询星星
$type = isset($request_data['type']) ? intval($request_data['type']) : 0;
/// 只有总代理才有权限
$dbSalesInfo = $this->PDO_Request(/** @lang */'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() . __FILE__ . '(' . __LINE__ . ')');
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;
}
//要查询的代理信息
$dbQueryInfo = $this->PDO_Request(/** @lang */'select idx, saus_openid, saus_unionid from sales_user where saus_agentid=? and saus_salesid=?;', $agentID, $queryID);
if (!is_array($dbQueryInfo))
{
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo() . __FILE__ . '(' . __LINE__ . ')');
return false;
}
if (count($dbQueryInfo) < 1)
{
$outParam->SetErrors(ERRORCODE_SALESNOTEXISTERROR, ERRORINFO_SALESNOTEXISTERROR);
return false;
}
$page_count = 1;
if ($type == 0)
{
$array_param = array(
$agentID,
$queryID,
);
if (!empty($beginTime))
{
$str_time .= ' and a.satr_transfertime >= ? ';
$array_param[] = $beginTime;
}
if (!empty($endTime))
{
$str_time .= ' and a.satr_transfertime <= ? ';
$array_param[] = $endTime;
}
if (!empty($beginTime) && !empty($endTime) && $beginTime > $endTime)
{
$outParam->SetErrors(ERRORCODE_TIMEERROR, ERRORINFO_TIMEERROR);
return false;
}
$command = /** @lang text */<<<EOL
select
a.idx,
a.satr_amount amount,
a.satr_transfertime time,
b.saus_salesid salesid,
b.saus_nickname nickname,
b.saus_avatar avatar
from
sales_transferbill a
inner join
sales_user b
on
a.satr_agentid = b.saus_agentid and
a.channel_id = b.saus_channelid and
a.from_sales = b.saus_salesid
left join
sales_user c
on
a.satr_agentid = c.saus_agentid and
a.channel_id = c.saus_channelid and
a.satr_salesid = c.saus_salesid
where
ifnull(b.statistic_type, 0) = 0 and
ifnull(c.statistic_type, 0) = 0 and
a.satr_agentid = ? and
a.satr_salesid = ? {$str_time}
order by
a.idx desc
{$strPage}
EOL;
$dbRecord = $this->PDO_Request($command, $array_param);
if (!is_array($dbRecord))
{
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo() . __FILE__ . '(' . __LINE__ . ')');
return false;
}
if (!empty($request_data['page_index']))
{
$command = /** @lang text */<<<EOL
select
count(0) num
from
sales_transferbill a
inner join
sales_user b
on
a.satr_agentid = b.saus_agentid and
a.channel_id = b.saus_channelid and
a.from_sales = b.saus_salesid
left join
sales_user c
on
a.satr_agentid = c.saus_agentid and
a.channel_id = c.saus_channelid and
a.satr_salesid = c.saus_salesid
where
ifnull(b.statistic_type, 0) = 0 and
ifnull(c.statistic_type, 0) = 0 and
a.satr_agentid = ? and
a.satr_salesid = ? {$str_time}
EOL;
$dbCount = $this->PDO_Request($command, $array_param);
if (!is_array($dbCount) || count($dbCount) < 1)
{
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo() . __FILE__ . '(' . __LINE__ . ')');
return false;
}
$page_count = intval($dbCount[0]['num']) / $page_size + 1;
}
}
elseif ($type == 1)
{
$array_param = array(
$agentID,
$queryID,
$channelID,
);
if (!empty($beginTime))
{
$str_time .= ' and a.op_time >= ? ';
$array_param[] = $beginTime;
}
if (!empty($endTime))
{
$str_time .= ' and a.op_time <= ? ';
$array_param[] = $endTime;
}
if (!empty($beginTime) && !empty($endTime) && $beginTime > $endTime)
{
$outParam->SetErrors(ERRORCODE_TIMEERROR, ERRORINFO_TIMEERROR);
return false;
}
$command = /** @lang text */<<<EOL
select
a.id idx,
a.amount,
a.op_time time,
b.saus_salesid salesid,
b.saus_nickname nickname,
b.saus_avatar avatar
from
trans_star_record a
inner join
sales_user b
on
a.agent_id = b.saus_agentid and
a.channel_id = b.saus_channelid and
a.send_id = b.saus_salesid
left join
sales_user c
on
a.agent_id = c.saus_agentid and
a.channel_id = c.saus_channelid and
a.get_id = c.saus_salesid
where
ifnull(b.statistic_type, 0) = 0 and
ifnull(c.statistic_type, 0) = 0 and
a.agent_id = ? and
a.get_id = ? and
a.channel_id = ? {$str_time}
order by
a.id desc
{$strPage}
EOL;
$dbRecord = $this->PDO_Request($command, $array_param);
if (!is_array($dbRecord))
{
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo() . __FILE__ . '(' . __LINE__ . ')');
return false;
}
if (!empty($request_data['page_index']))
{
$command = /** @lang text */<<<EOL
select
count(0) num
from
trans_star_record a
inner join
sales_user b
on
a.agent_id = b.saus_agentid and
a.channel_id = b.saus_channelid and
a.send_id = b.saus_salesid
left join
sales_user c
on
a.agent_id = c.saus_agentid and
a.channel_id = c.saus_channelid and
a.get_id = c.saus_salesid
where
ifnull(b.statistic_type, 0) = 0 and
ifnull(c.statistic_type, 0) = 0 and
a.agent_id = ? and
a.get_id = ? and
a.channel_id = ? {$str_time}
EOL;
$dbCount = $this->PDO_Request($command, $array_param);
if (!is_array($dbCount) || count($dbCount) < 1)
{
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo() . __FILE__ . '(' . __LINE__ . ')');
return false;
}
$page_count = intval($dbCount[0]['num']) / $page_size + 1;
}
}
else
{
return false;
}
$outParam->biz_content = array(
'record' => $dbRecord,
'page_index' => $page_index,
'page_size' => $page_size,
'page_count' => intval($page_count),
);
return true;
}
/**
* 总代理查询代理房卡或星星 消耗 记录
* 被请求方法示例参数固定为RequestParameter和ReturnParameter对象返回值固定为true(成功)和false(失败)
* @param RequestParameter $inParam
* @param ReturnParameter $outParam
* @return bool
*/
public function salesCardStarDeduct($inParam, $outParam)
{
$request_data = isset($inParam->biz_content) ? $inParam->biz_content : '';
if (!is_array($request_data))
{
//参数格式错误
$outParam->SetErrors(ERRORCODE_INPARAMERROR, ERRORINFO_INPARAMERROR);
return false;
}
$agent_id = @$request_data['agentid'];
$channel_id = @$request_data['channelid'];
$sales_id = @$request_data['salesid'];
$query_id = @$request_data['queryid'];
$beginTime = isset($request_data['begintime']) ? $request_data['begintime'] : '';
$endTime = isset($request_data['endtime']) ? $request_data['endtime'] : '';
$page_index = empty($request_data['page_index']) ? 1 : intval($request_data['page_index']);
$page_size = empty($request_data['page_size']) ? 10 : intval($request_data['page_size']);
/// 操作类型 0、查询房卡1、查询星星
$type = isset($request_data['type']) ? intval($request_data['type']) : 0;
if (empty($agent_id))
{
$outParam->SetErrors(ERRORCODE_AGENTIDERROR, ERRORINFO_AGENTIDERROR);
return false;
}
if (empty($channel_id))
{
$outParam->SetErrors(ERRORCODE_CHANNELIDERROR, ERRORINFO_CHANNELIDERROR);
return false;
}
if (empty($sales_id))
{
$outParam->SetErrors(ERRORCODE_SALESIDERROR, ERRORINFO_SALESIDERROR);
return false;
}
//查询的id
if (empty($query_id))
{
$outParam->SetErrors(ERRORCODE_SALESIDERROR, ERRORINFO_SALESIDERROR);
return false;
}
$str_time = '';
$start = ($page_index - 1) * $page_size;
$strPage = '';
if (!empty($request_data['page_index']))
{
$strPage .= " limit {$start},{$page_size} ";
}
//只有总代理才有权限
$dbSalesInfo = $this->PDO_Request(/** @lang */' select idx, global_power from sales_user where saus_agentid=? and saus_channelid=? and saus_salesid=?', $agent_id, $channel_id, $sales_id);
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;
}
// //要查询的代理信息
// $dbQueryInfo = $this->PDO_Request(/** @lang */
// '
// SELECT idx, saus_openid, saus_unionid
// FROM sales_user
// WHERE saus_agentid=? AND saus_salesid=?;', $agentID, $queryID);
//
// if (!is_array($dbQueryInfo))
// {
// $outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
// return false;
// }
//
// if (count($dbQueryInfo) < 1)
// {
// $outParam->SetErrors(ERRORCODE_SALESNOTEXISTERROR, ERRORINFO_SALESNOTEXISTERROR);
// return false;
// }
$page_count = 1;
if ($type == 0) /// 查询房卡
{
$array_param = array($agent_id, $query_id,);
if (!empty($beginTime))
{
$str_time .= ' and a.satr_transfertime >= ? ';
$array_param[] = $beginTime;
}
if (!empty($endTime))
{
$str_time .= ' and a.satr_transfertime <= ? ';
$array_param[] = $endTime;
}
if (!empty($beginTime) && !empty($endTime) && $beginTime > $endTime)
{
$outParam->SetErrors(ERRORCODE_TIMEERROR, ERRORINFO_TIMEERROR);
return false;
}
$command = /** @lang text */<<<EOL
select
a.idx,
a.satr_amount amount,
a.satr_transfertime time,
b.saus_salesid salesid,
b.saus_nickname nickname,
b.saus_avatar avatar
from
sales_transferbill a
inner join
sales_user b
on
a.satr_agentid = b.saus_agentid and
a.channel_id = b.saus_channelid and
a.from_sales = b.saus_salesid
left join
sales_user c
on
a.satr_agentid = c.saus_agentid and
a.channel_id = c.saus_channelid and
a.satr_salesid = c.saus_salesid
where
ifnull(b.statistic_type, 0) = 0 and
ifnull(c.statistic_type, 0) = 0 and
a.satr_agentid = ? and
a.from_sales = ? {$str_time}
order by
a.idx desc
{$strPage}
EOL;
$dbRecord = $this->PDO_Request($command, $array_param);
if (!is_array($dbRecord))
{
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
return false;
}
if (!empty($request_data['page_index']))
{
$command = /** @lang text */<<<EOL
select
count(0) num
from
sales_transferbill a
inner join
sales_user b
on
a.satr_agentid = b.saus_agentid and
a.channel_id = b.saus_channelid and
a.from_sales = b.saus_salesid
left join
sales_user c
on
a.satr_agentid = c.saus_agentid and
a.channel_id = c.saus_channelid and
a.satr_salesid = c.saus_salesid
where
ifnull(b.statistic_type, 0) = 0 and
ifnull(c.statistic_type, 0) = 0 and
a.satr_agentid = ? and
a.from_sales = ? {$str_time}
EOL;
$dbCount = $this->PDO_Request($command, $array_param);
if (!is_array($dbCount) || count($dbCount) < 1)
{
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
return false;
}
$page_count = intval($dbCount[0]['num']) / $page_size + 1;
}
}
elseif ($type == 1)
{
$array_param = array($agent_id, $query_id, $channel_id,);
if (!empty($beginTime))
{
$str_time .= ' and a.op_time >= ? ';
$array_param[] = $beginTime;
}
if (!empty($endTime))
{
$str_time .= ' and a.op_time <= ? ';
$array_param[] = $endTime;
}
if (!empty($beginTime) && !empty($endTime) && $beginTime > $endTime)
{
$outParam->SetErrors(ERRORCODE_TIMEERROR, ERRORINFO_TIMEERROR);
return false;
}
$command = /** @lang text */<<<EOL
select
a.id idx,
a.amount,
a.op_time time,
b.saus_salesid salesid,
b.saus_nickname nickname,
b.saus_avatar avatar
from
trans_star_record a
inner join
sales_user b
on
a.agent_id = b.saus_agentid and
a.channel_id = b.saus_channelid and
a.send_id = b.saus_salesid
left join
sales_user c
on
a.agent_id = c.saus_agentid and
a.channel_id = c.saus_channelid and
a.get_id = c.saus_salesid
where
ifnull(b.statistic_type, 0) = 0 and
ifnull(c.statistic_type, 0) = 0 and
a.agent_id = ? and
a.send_id = ? and
a.channel_id = ? {$str_time}
order by
a.id desc
{$strPage}
EOL;
$dbRecord = $this->PDO_Request($command, $array_param);
if (!is_array($dbRecord))
{
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
return false;
}
if (!empty($request_data['page_index']))
{
$command = /** @lang text */<<<EOL
select
count(0) num
from
trans_star_record a
inner join
sales_user b
on
a.agent_id = b.saus_agentid and
a.channel_id = b.saus_channelid and
a.send_id = b.saus_salesid
left join
sales_user c
on
a.agent_id = c.saus_agentid and
a.channel_id = c.saus_channelid and
a.get_id = c.saus_salesid
where
ifnull(b.statistic_type, 0) = 0 and
ifnull(c.statistic_type, 0) = 0 and
a.agent_id = ? and
a.send_id = ? and
a.channel_id = ? {$str_time}
EOL;
$dbCount = $this->PDO_Request($command, $array_param);
if (!is_array($dbCount) || count($dbCount) < 1)
{
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
return false;
}
$page_count = intval($dbCount[0]['num']) / $page_size + 1;
}
}
else
return false;
$outParam->biz_content = array(
'record' => $dbRecord,
'page_index' => $page_index,
'page_size' => $page_size,
'page_count' => intval($page_count),
);
return true;
}
/**
* 总代理查询代理权限
* 被请求方法示例参数固定为RequestParameter和ReturnParameter对象返回值固定为true(成功)和false(失败)
* @param RequestParameter $inParam
* @param ReturnParameter $outParam
* @return bool
*/
public function getPower($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($channelID))
{
$outParam->SetErrors(ERRORCODE_CHANNELIDERROR, ERRORINFO_CHANNELIDERROR);
return false;
}
//操作人id
$salesID = isset($request_data['salesid']) ? $request_data['salesid'] : '';
if (empty($salesID))
{
$outParam->SetErrors(ERRORCODE_SALESIDERROR, ERRORINFO_SALESIDERROR);
return false;
}
//查询的id
$queryID = isset($request_data['queryid']) ? $request_data['queryid'] : '';
if (empty($queryID))
{
$outParam->SetErrors(ERRORCODE_SALESIDERROR, ERRORINFO_SALESIDERROR);
return false;
}
//判断操作人是否是总代身份
//只有总代理才有权限
$dbSalesInfo = $this->PDO_Request(/** @lang */
'
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;
}
//要查询的代理信息
$dbQueryInfo = $this->PDO_Request(/** @lang */
'
SELECT idx, saus_openid, saus_unionid, saus_power, saus_nickname, saus_salesid, saus_avatar, is_vip
FROM sales_user
WHERE saus_agentid=? AND saus_salesid=?;', $agentID, $queryID);
if (!is_array($dbQueryInfo))
{
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
return false;
}
if (count($dbQueryInfo) < 1)
{
$outParam->SetErrors(ERRORCODE_SALESNOTEXISTERROR, ERRORINFO_SALESNOTEXISTERROR);
return false;
}
$outParam->biz_content = $dbQueryInfo[0];
return true;
}
/**
* 总代理设置代理权限
* 被请求方法示例参数固定为RequestParameter和ReturnParameter对象返回值固定为true(成功)和false(失败)
* @param RequestParameter $inParam
* @param ReturnParameter $outParam
* @return bool
*/
public function setPower($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($channelID))
{
$outParam->SetErrors(ERRORCODE_CHANNELIDERROR, ERRORINFO_CHANNELIDERROR);
return false;
}
//操作人id
$salesID = isset($request_data['salesid']) ? $request_data['salesid'] : '';
if (empty($salesID))
{
$outParam->SetErrors(ERRORCODE_SALESIDERROR, ERRORINFO_SALESIDERROR);
return false;
}
//设置的id
$queryID = isset($request_data['queryid']) ? $request_data['queryid'] : '';
if (empty($queryID))
{
$outParam->SetErrors(ERRORCODE_SALESIDERROR, ERRORINFO_SALESIDERROR);
return false;
}
//设置的权限
if (!isset($request_data['power']))
{
$outParam->SetErrors(ERRORCODE_POWERERROR, ERRORINFO_POWERERROR);
return false;
}
$power = $request_data['power'];
//vip
if (!isset($request_data['is_vip']))
{
$outParam->SetErrors(ERRORCODE_POWERERROR, '未设置vip');
return false;
}
$isVip = intval($request_data['is_vip']);
//判断操作人是否是总代身份
//只有总代理才有权限
$dbSalesInfo = $this->PDO_Request(/** @lang */
'
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;
}
//要设置的代理信息
$dbQueryInfo = $this->PDO_Request(/** @lang */
'
SELECT idx, saus_openid, saus_unionid, saus_power
FROM sales_user
WHERE saus_agentid=? AND saus_salesid=?;', $agentID, $queryID);
if (!is_array($dbQueryInfo))
{
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
return false;
}
if (count($dbQueryInfo) < 1)
{
$outParam->SetErrors(ERRORCODE_SALESNOTEXISTERROR, ERRORINFO_SALESNOTEXISTERROR);
return false;
}
$ret = $this->PDO_Execute(/** @lang */
'
UPDATE sales_user
SET saus_power=?, is_vip=?
WHERE idx=?;', $power, $isVip, $dbQueryInfo[0]['idx']);
if (!$ret)
{
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
return false;
}
$outParam->biz_content = array(
'salesid' => $salesID,
'power' => $power,
'isvip' => $isVip,
);
return true;
}
/**
* 总代理设置玩家短号
* 被请求方法示例参数固定为RequestParameter和ReturnParameter对象返回值固定为true(成功)和false(失败)
* @param RequestParameter $inParam
* @param ReturnParameter $outParam
* @return bool
* method=agent.agent.shortNum&format=json&charset=utf-8&timestamp=1&version=1.0&biz_content={"agentid":"00bA05haB0d9ZC0fwGD09Q2OA30insbQ","channelid":"frdt0C1GG0t91P0McFo0rbA1he5yurbS","salesid":"202734","playerid":"100006","roomnum":2,"desone":"哈哈哈","destwo":"哈哈哈2","shortnum":124}
*/
public function shortNum($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'] : '';
$channelID = isset($request_data['channelid']) ? $request_data['channelid'] : '';
//操作人id
$salesID = isset($request_data['salesid']) ? $request_data['salesid'] : '';
$shortNum = isset($request_data['shortnum']) ? $request_data['shortnum'] : '';
//设置的玩家id
$playerID = isset($request_data['playerid']) ? $request_data['playerid'] : '';
/// 新增短号描述1和短号描述2
$desOne = isset($request_data['desone']) ? $request_data['desone'] : '';
$desTwo = isset($request_data['destwo']) ? $request_data['destwo'] : '';
$lower_limit = !empty($request_data['lower_limit']) ? $request_data['lower_limit'] : -9999999;
$announcement = isset($request_data['announcement']) ? $request_data['announcement'] : '';
/// 收款码
$collection_code = isset($request_data['collectioncode']) ? $request_data['collectioncode'] : '';
/// 最大房间数
$roomNum = intval($request_data['roomnum']);
if (empty($agentID))
{
$outParam->SetErrors(ERRORCODE_AGENTIDERROR, ERRORINFO_AGENTIDERROR);
return false;
}
if (empty($channelID))
{
$outParam->SetErrors(ERRORCODE_CHANNELIDERROR, ERRORINFO_CHANNELIDERROR);
return false;
}
if (empty($playerID))
{
$outParam->SetErrors(ERRORCODE_PLAYERIDERROR, ERRORINFO_PLAYERIDERROR);
return false;
}
//玩家最大开房间数
if (!isset($request_data['roomnum']))
{
$outParam->SetErrors(ERRORCODE_ROOMNUMNULLERROR, ERRORINFO_ROOMNUMNULLERROR);
return false;
}
if ($roomNum < 0)
{
$outParam->SetErrors(ERRORCODE_ROOMNUMERROR, ERRORINFO_ROOMNUMERROR);
return false;
}
if (strlen($desOne) > 500 || strlen($desTwo) > 500)
{
$outParam->SetErrors(ERRORCODE_SHORTDESERROR, ERRORINFO_SHORTDESERROR);
return false;
}
$playerInfo = $this->PDO_Request(/** @lang */"select idx, play_openid, play_unionid from player where play_agentid=? and play_channelid=? and play_playerid=?;", $agentID, $channelID, $playerID);
if (!is_array($playerInfo))
{
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
return false;
}
if (count($playerInfo) < 1)
{
$outParam->SetErrors(ERRORCODE_PLAYERNOTEXISTERROR, ERRORINFO_PLAYERNOTEXISTERROR);
return false;
}
// //设置的短号
// if (!isset($request_data['shortnum']))
// {
// $outParam->SetErrors(ERRORCODE_SHORTNUMNULLERROR, ERRORINFO_SHORTNUMNULLERROR);
// return false;
// }
// $shortNum = intval($request_data['shortnum']);
//
// if ($shortNum <= 0 || $shortNum > 99999)
// {
// $outParam->SetErrors(ERRORCODE_SHORTNUMERROR, ERRORINFO_SHORTNUMERROR);
// return false;
// }
// //判断短号是否被占用
// $shortInfo = $this->PDO_Request(/** @lang */
// "
// SELECT id, player_id
// FROM player_short_num
// WHERE agent_id=? AND channel_id=? AND short_str=?;", $agentID, $channelID, $shortNum);
//
// if (!is_array($shortInfo))
// {
// $outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
// return false;
// }
//
// if (count($shortInfo) > 0 && $shortInfo[0]['player_id'] != $playerID)
// {
// $outParam->SetErrors(ERRORCODE_SHORTNUMUSEDERROR, ERRORINFO_SHORTNUMUSEDERROR);
// return false;
// }
/// 获取玩家是否设置过短号
$playerShortInfo = $this->PDO_Request(/** @lang */"select id, des_one, des_two, short_str from player_short_num where agent_id=? and channel_id=? and player_id=?;", $agentID, $channelID, $playerID);
if (!is_array($playerShortInfo))
{
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
return false;
}
$this->PDO_BeginTransaction();
try
{
// 新建短号
if (count($playerShortInfo) < 1)
{
if(empty($shortNum)) {
/// 随机生成短号码
do {
$shortNum = rand(1, 99999);
$cmd = /** @lang text */
'select 1 from player_short_num where agent_id = ? and channel_id = ? and short_str = ?';
$ret = $this->pdo_request($cmd, $agentID, $channelID, $shortNum);
if ( !$this->pdo_isdone())
throw new Exception($this->geterrorinfo(), $this->geterrorcode());
} while ( !empty($ret));
} else {
// 指定短号
$cmd = /** @lang text */
'select 1 from player_short_num where agent_id = ? and channel_id = ? and short_str = ?';
$ret = $this->pdo_request($cmd, $agentID, $channelID, $shortNum);
if ( !$this->pdo_isdone())
throw new Exception($this->geterrorinfo(), $this->geterrorcode());
if(!empty($ret)) {
throw new Exception('该短号已被使用', 200);
}
}
$cmd = /** @lang text */<<<EOL
insert into player_short_num(
agent_id, channel_id, sales_id, player_id, open_id,
union_id, short_str, max_room, create_time, des_one,
des_two, lower_limit, collection_code, announcement)
values
(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
EOL;
$ret = $this->PDO_Execute($cmd, $agentID, $channelID, $salesID, $playerID, $playerInfo[0]['play_openid'],
$playerInfo[0]['play_unionid'], $shortNum, $roomNum, date('Y-m-d H:i:s', time()), $desOne, $desTwo, $lower_limit, $collection_code, $announcement);
if (!$ret)
{
throw new Exception($this->GetErrorInfo(), $this->GetErrorCode());
}
$strMark = '设置玩家短号和最大房间数';
}
else
{
$shortNum = empty($shortNum) ? $playerShortInfo[0]['short_str'] : $shortNum;
//$shortNum = $playerShortInfo[0]['short_str'];
$arrayParam = array(
$roomNum,
date('Y-m-d H:i:s', time()),
);
$shortDes = '';
if (isset($shortNum))
{
$shortDes .= " , short_str=? ";
$arrayParam[] = $shortNum;
}
if (isset($desOne))
{
$shortDes .= " , des_one=? ";
$arrayParam[] = $desOne;
}
if (isset($desTwo))
{
$shortDes .= " , des_two=? ";
$arrayParam[] = $desTwo;
}
if (isset($lower_limit))
{
$shortDes .= " , lower_limit=? ";
$arrayParam[] = $lower_limit;
}
if (isset($collection_code))
{
$shortDes .= " , collection_code=? ";
$arrayParam[] = $collection_code;
}
if (isset($announcement))
{
$shortDes .= " , announcement=? ";
$arrayParam[] = $announcement;
}
$arrayParam[] = $playerShortInfo[0]['id'];
$ret = $this->PDO_Execute(/** @lang */"
update player_short_num
set max_room=?, change_time=? {$shortDes}
where id=?;", $arrayParam);
if (!$ret)
throw new Exception($this->GetErrorInfo(), $this->GetErrorCode());
$strMark = '修改玩家短号和最大房间数';
}
$operData = array(
'shortnum' => $shortNum,
'maxroomnum' => $roomNum,
'desone' => $desOne,
'destwo' => $desTwo,
'lower_limit' => $lower_limit,
'collectioncode' => $collection_code,
'announcement' => $announcement,
);
//写入日志
$log_res = $this->PDO_Execute(/** @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 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', $agentID, $channelID, $salesID, $agentID, $channelID, $playerID, 110, json_encode($operData, JSON_UNESCAPED_UNICODE), $strMark, time(), 0);
if (!$log_res)
{
throw new Exception($this->GetErrorInfo(), $this->GetErrorCode());
}
$this->PDO_Commit();
}
catch (Exception $e)
{
$this->PDO_Rollback();
$outParam->SetErrors($e->getCode(), $e->getMessage());
return false;
}
return true;
}
/**
* 查询玩家短号
* 被请求方法示例参数固定为RequestParameter和ReturnParameter对象返回值固定为true(成功)和false(失败)
* @param RequestParameter $inParam
* @param ReturnParameter $outParam
* @return bool
* method=agent.agent.getShortNum&format=json&charset=utf-8&timestamp=1&version=1.0&biz_content={"agentid":"00bA05haB0d9ZC0fwGD09Q2OA30insbQ","channelid":"frdt0C1GG0t91P0McFo0rbA1he5yurbS","playerid":"100001"}
*/
public function getShortNum($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($channelID))
{
$outParam->SetErrors(ERRORCODE_CHANNELIDERROR, ERRORINFO_CHANNELIDERROR);
return false;
}
//操作人id
//$salesID = isset($request_data['salesid']) ? $request_data['salesid'] : '';
//玩家id
$playerID = isset($request_data['playerid']) ? $request_data['playerid'] : '';
if (empty($playerID))
{
$outParam->SetErrors(ERRORCODE_PLAYERIDERROR, ERRORINFO_PLAYERIDERROR);
return false;
}
// 是否需要大赢家的信息 0-否 1-是
$is_winner = isset($request_data['is_winner']) ? intval($request_data['is_winner']) : 0;
$start_time = isset($request_data['starttime']) ? $request_data['starttime'] : '';
$end_time = isset($request_data['endtime']) ? $request_data['endtime'] : '';
$playerShortInfo = $this->PDO_Request(/** @lang */
"
select id, open_id, union_id, short_str, max_room, des_one, des_two, collection_code, lower_limit, announcement
from player_short_num
where agent_id=? and channel_id=? and player_id=?;", $agentID, $channelID, $playerID);
if (!is_array($playerShortInfo))
{
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
return false;
}
if (count($playerShortInfo) < 1)
{
$outParam->biz_content = array();
return true;
}
$outParam->biz_content = $playerShortInfo[0];
if($is_winner) {
// 获取昨日房间内玩家赢得大赢家的次数
if(empty($start_time) || empty($end_time)) {
$tmp_time = strtotime("-1 day");
$year_month = date("Ym", $tmp_time);
$start_day = date("Y-m-d", $tmp_time);
$end_day = date("Y-m-d", $tmp_time);
} else {
$year_month = substr($start_time,0, 7);
$year_month = str_replace('-', '', $year_month);
$start_day = $start_time;
$end_day = $end_time;
}
$sql = /** @lang */<<<EOL
select
a.player_id,
b.play_nickname nickname,
count(0) war_count,
sum(a.score) winner_score,
sum(
case a.is_winner
when 1 then 1
else 0
end
) winner_count,
max(
case a.is_winner
when 1 then a.score
else 0
end
) max_score
from
ct_grade_{$year_month} a
inner join
player b
on
a.agent_id = b.play_agentid and
a.player_id = b.play_playerid
where
a.agent_id = ? and
a.short_number = ? and
date_format(a.over_time, '%Y-%m-%d') between '{$start_day}' and '{$end_day}'
group by
a.player_id,
b.play_nickname
EOL;
$winner_info = $this->PDO_Request($sql, $agentID, $playerShortInfo[0]['short_str']);
if(isset($winner_info[0]))
$outParam->biz_content['winner_info'] = $winner_info;
}
return true;
}
/**
* 总代查询指定时间注册代理信息
* 被请求方法示例参数固定为RequestParameter和ReturnParameter对象返回值固定为true(成功)和false(失败)
* @param RequestParameter $inParam
* @param ReturnParameter $outParam
* @return bool
* method=agent.agent.getShortNum&format=json&charset=utf-8&timestamp=1&version=1.0&biz_content={"agentid":"00bA05haB0d9ZC0fwGD09Q2OA30insbQ","channelid":"frdt0C1GG0t91P0McFo0rbA1he5yurbS","playerid":"100001"}
*/
public function timeReg($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($channelID))
{
$outParam->SetErrors(ERRORCODE_CHANNELIDERROR, ERRORINFO_CHANNELIDERROR);
return false;
}
//操作人id
$salesID = isset($request_data['salesid']) ? $request_data['salesid'] : '';
if (empty($salesID))
{
$outParam->SetErrors(ERRORCODE_SALESIDERROR, ERRORINFO_SALESIDERROR);
return false;
}
//判断操作人是否是总代身份
//只有总代理才有权限
$dbSalesInfo = $this->PDO_Request(/** @lang */
'
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;
}
$page_count = 1;
$str_time = '';
//$array_param = array($agentID, $queryID, $channelID);
$beginTime = isset($request_data['begintime']) ? $request_data['begintime'] : '';
$endTime = isset($request_data['endtime']) ? $request_data['endtime'] : '';
if (empty($beginTime) || empty($endTime))
{
$outParam->SetErrors(ERRORCODE_TIMEERROR, ERRORINFO_TIMEERROR);
return false;
}
$page_index = empty($request_data['page_index']) ? 1 : intval($request_data['page_index']);
$page_size = empty($request_data['page_size']) ? 10 : intval($request_data['page_size']);
$start = ($page_index - 1) * $page_size;
$strPage = '';
if (!empty($request_data['page_index']))
{
$strPage .= " LIMIT {$start},{$page_size} ";
}
$array_param = array(
$agentID,
$channelID,
);
if (!empty($beginTime) && !empty($endTime))
{
$str_time .= ' and date_format(saus_saletime, \'%Y-%m-%d\') between ? and ?';
$array_param[] = $beginTime;
$array_param[] = $endTime;
}
if (!empty($beginTime) && !empty($endTime) && $beginTime > $endTime)
{
$outParam->SetErrors(ERRORCODE_TIMEERROR, ERRORINFO_TIMEERROR);
return false;
}
$timeRegSales = $this->PDO_Request(/** @lang */
"
select
idx, saus_nickname, saus_avatar, saus_sex, saus_salesid, saus_roomcard, saus_bean, saus_saletime,
saus_tel, saus_wechat, saus_parentid, saus_invitecode, saus_power, saus_status
from
sales_user
where
saus_agentid=? and saus_channelid=? {$str_time}
order by idx desc {$strPage}", $array_param);
if (!is_array($timeRegSales))
{
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
return false;
}
if (!empty($request_data['page_index']))
{
$dbCount = $this->PDO_Request(/** @lang */
"
select
count(1) num
from
sales_user
where
saus_agentid=? and saus_channelid=? {$str_time}", $array_param);
if (!is_array($dbCount) || count($dbCount) < 1)
{
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
return false;
}
$page_count = intval($dbCount[0]['num']) / $page_size + 1;
}
$outParam->biz_content = array(
'record' => $timeRegSales,
'page_index' => $page_index,
'page_size' => $page_size,
'page_count' => intval($page_count),
);
return true;
}
/**
* 总代查询指定时间所有代理的下的玩家购买房卡、星星金额和数量
* 被请求方法示例参数固定为RequestParameter和ReturnParameter对象返回值固定为true(成功)和false(失败)
* @param RequestParameter $inParam
* @param ReturnParameter $outParam
* @return bool
* method=agent.agent.allSalesReport&format=json&charset=utf-8&timestamp=1&version=1.0&biz_content={"agentid":"00bA05haB0d9ZC0fwGD09Q2OA30insbQ","channelid":"frdt0C1GG0t91P0McFo0rbA1he5yurbS","salesid":"200001","type":0,"begintime":"2017-08-01","endtime":"2017-10-01","page_index":1}
*/
public function allSalesReport($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($channelID))
{
$outParam->SetErrors(ERRORCODE_CHANNELIDERROR, ERRORINFO_CHANNELIDERROR);
return false;
}
//操作人id
$salesID = isset($request_data['salesid']) ? $request_data['salesid'] : '';
if (empty($salesID))
{
$outParam->SetErrors(ERRORCODE_SALESIDERROR, ERRORINFO_SALESIDERROR);
return false;
}
//查询人id
$queryID = isset($request_data['queryid']) ? $request_data['queryid'] : '';
//操作类型 type 0、购买房卡数1、购买房卡金额2、购买星星数3、购买星星金额
$type = isset($request_data['type']) ? intval($request_data['type']) : 0;
switch ($type)
{
case 0:
//
$selType = 107;
break;
case 1:
$selType = 108;
break;
case 2:
$selType = 109;
break;
case 3:
$selType = 110;
break;
default:
$selType = 107;
break;
}
//判断操作人是否是总代身份
//只有总代理才有权限
$dbSalesInfo = $this->PDO_Request(/** @lang text */'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;
}
$page_count = 1;
$str_time = '';
//$array_param = array($agentID, $queryID, $channelID);
$beginTime = isset($request_data['begintime']) ? $request_data['begintime'] : '';
$endTime = isset($request_data['endtime']) ? $request_data['endtime'] : '';
$page_index = empty($request_data['page_index']) ? 1 : intval($request_data['page_index']);
$page_size = empty($request_data['page_size']) ? 10 : intval($request_data['page_size']);
$start = ($page_index - 1) * $page_size;
$strPage = '';
if (!empty($request_data['page_index']))
{
$strPage .= " LIMIT {$start},{$page_size} ";
}
$array_param = array(
$agentID,
$channelID,
$selType,
);
if (!empty($beginTime))
{
$str_time .= ' and a.report_date >= ? ';
$array_param[] = $beginTime;
}
if (!empty($endTime))
{
$str_time .= ' and a.report_date <= ? ';
$array_param[] = $endTime;
}
if ($queryID !== '')
{
$str_time .= ' and a.sales_id = ? ';
$array_param[] = $queryID;
}
if (!empty($beginTime) && !empty($endTime) && $beginTime > $endTime)
{
$outParam->SetErrors(ERRORCODE_TIMEERROR, ERRORINFO_TIMEERROR);
return false;
}
$dbData = $this->PDO_Request(/** @lang */
"
SELECT
a.id, a.sales_id, a.report_id, SUM(report_data) num, report_date,
b.saus_nickname, b.saus_avatar
FROM
ct_report_info a
LEFT JOIN sales_user b ON a.agent_id=b.saus_agentid AND a.channel_id=b.saus_channelid AND a.sales_id=b.saus_salesid
WHERE
a.agent_id=? AND a.channel_id=? AND a.report_id=? {$str_time}
GROUP BY a.sales_id
ORDER BY a.id {$strPage};", $array_param);
if (!is_array($dbData))
{
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
return false;
}
if (!empty($request_data['page_index']))
{
$dbCount = $this->PDO_Request(/** @lang */
"
SELECT
count(DISTINCT a.sales_id) num
FROM
ct_report_info a
WHERE
a.agent_id=? AND a.channel_id=? AND a.report_id=? {$str_time}", $array_param);
if (!is_array($dbCount) || count($dbCount) < 1)
{
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
return false;
}
$page_count = intval($dbCount[0]['num']) / $page_size + 1;
}
$outParam->biz_content = array(
'record' => $dbData,
'page_index' => $page_index,
'page_size' => $page_size,
'page_count' => intval($page_count),
);
return true;
}
/**
* 获取公告信息
* 被请求方法示例参数固定为RequestParameter和ReturnParameter对象返回值固定为true(成功)和false(失败)
* @param RequestParameter $inParam
* @param ReturnParameter $outParam
* @return bool
*
*/
public function getNotice($inParam, $outParam)
{
$request_data = isset($inParam->biz_content) ? $inParam->biz_content : '';
if (!is_array($request_data))
{
//参数格式错误
$outParam->SetErrors(ERRORCODE_INPARAMERROR, ERRORINFO_INPARAMERROR);
return false;
}
if (!isset($request_data['type']))
{
$outParam->SetErrors(ERRORCODE_TYPEERROR, ERRORINFO_TYPEERROR);
return false;
}
//0、渠道下的公告1、全服公告, 2,本渠道和全服公告
$type = isset($request_data['type']) ? intval($request_data['type']) : 0;
$strSql = '';
$arraySql = array();
if ($type == 0)
{
$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($channelID))
{
$outParam->SetErrors(ERRORCODE_CHANNELIDERROR, ERRORINFO_CHANNELIDERROR);
return false;
}
$strSql .= ' AND agent_id=? AND channel_id=? ';
$arraySql[] = $agentID;
$arraySql[] = $channelID;
$noticeList = $this->PDO_Request(/** @lang */
"
SELECT
id, notice_info, create_time
FROM
ct_agent_notice
WHERE
status=1 AND global_notice=0 {$strSql}", $arraySql);
if (!is_array($noticeList))
{
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
return false;
}
$outParam->biz_content = array('list' => $noticeList);
}
else if ($type == 1)
{
$noticeList = $this->PDO_Request(/** @lang */
"
SELECT
id, notice_info, create_time
FROM
ct_agent_notice
WHERE
status=1 AND global_notice=1;");
if (!is_array($noticeList))
{
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
return false;
}
$outParam->biz_content = array('list' => $noticeList);
}
else
{
$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($channelID))
{
$outParam->SetErrors(ERRORCODE_CHANNELIDERROR, ERRORINFO_CHANNELIDERROR);
return false;
}
$globalNotice = $this->PDO_Request(/** @lang */
"
SELECT
notice_info
FROM
ct_agent_notice
WHERE
status=1 AND global_notice=1 and type=0;");
if (!is_array($globalNotice))
{
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
return false;
}
if (!empty($globalNotice))
{
$outParam->biz_content = $globalNotice[0];
return true;
}
$strSql .= ' AND agent_id=? AND channel_id=? ';
$arraySql[] = $agentID;
$arraySql[] = $channelID;
$notice = $this->PDO_Request(/** @lang */
"
SELECT
notice_info
FROM
ct_agent_notice
WHERE
status=1 AND global_notice=0 and type=0 {$strSql};", $arraySql);
if (!is_array($notice))
{
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
return false;
}
$outParam->biz_content = (isset($notice[0]) ? $notice[0] : array('notice_info' => ''));
}
return true;
}
/******************************************************************************************
* ================== summer 2017/11/6 Handel 代理分成部分业务 ====================== *
*****************************************************************************************/
##------------ 订单操作[curd]
##------------[表ct_withdraw_record] ------------------------->
/**
* [增]新增绑定玩家
* author summer
* @param RequestParameter $inParam
* @param ReturnParameter $outParam
* @return bool
*/
public function addAgentPlayer($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,
),
# 新增玩家id
'playerid' => array(
'name' => 'playerid',
'errcode' => ERRORCODE_INPARAMERROR,
'errinfo' => ERRORINFO_INPARAMERROR,
),
);
// 2、数据处理后的结果集 异常标志errtrue false
$param = $this->inParamHandel($inParam, $outParam, $config);
if (!$param)
{
return false;
}
$res = $this->PDO_Execute(/** @lang text */'insert into ct_sales_player(agent_id, channel_id, saus_salesid, play_playerid, create_time) values (?, ?, ?, ?, ?)',
$param['agentID'], $param['channelID'], $param['salesID'], $param['playerid'], date('Y-m-d H:i:s', time()));
if (!$res)
{
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
return false;
}
// 5、数据返回部分
$outParam->biz_content = array(
'code' => 1,
'msg' => '提交成功',
);
return true;
}
/**
* [查]查询绑定玩家
* author summer
* @param RequestParameter $inParam
* @param ReturnParameter $outParam
* @return bool
*/
public function getAgentPlayer($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;
}
$items = $this->PDO_Request(/** @lang text */'
select
a.`id`, a.`saus_salesid`, a.`play_playerid`, b.play_nickname
from
`ct_sales_player` as a
left join
`player` as b
on
a.`play_playerid` = b.`play_playerid` and a.`agent_id` = b.`play_agentid` and a.`channel_id` = b.`play_channelid`
where
a.`agent_id` = ?
and a.`channel_id` = ?
and a.`saus_salesid` = ?;', $param['agentID'], $param['channelID'], $param['salesID']);
if (!is_array($items))
{
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
return false;
}
// 5、数据返回部分
$outParam->biz_content = $items;
return true;
}
/**
* [查]删除绑定玩家
* author summer
* @param RequestParameter $inParam
* @param ReturnParameter $outParam
* @return bool
*/
public function delAgentPlayer($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
'id' => array(
'name' => 'id',
'errcode' => ERRORCODE_SALESIDERROR,
'errinfo' => ERRORINFO_SALESIDERROR,
),
);
// 2、数据处理后的结果集 异常标志errtrue false
$param = $this->inParamHandel($inParam, $outParam, $config);
if (!$param)
{
return false;
}
$items = $this->PDO_Request(/** @lang text */'delete from ct_sales_player where id= ?;', $param['id']);
if (!is_array($items))
{
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
return false;
}
// 5、数据返回部分
$outParam->biz_content = '删除成功';
return true;
}
##------------ 用户账户操作[curd] 总代权限
##------------[表sales_user] --------------------------------->
/**
* [查]查询用户账户
* author summer
* @param RequestParameter $inParam
* @param ReturnParameter $outParam
* @return bool
*/
public function getSalesUser($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、权限验证
$auth = $this->checkAgentAuth($inParam, $outParam, $param['agentID'], $param['channelID'], $param['salesID']);
if (!$auth)
{
return false;
}
//3.1 可选参数获取
$type = empty($param['_params']['type']) ? 1 : 0; // 查询类型1、代理 0、玩家
$objuserid = empty($param['_params']['objuserid']) ? false : $param['_params']['objuserid']; // 指定查询代理/玩家id
$beginTime = empty($param['_params']['begintime']) ? false : $param['_params']['begintime']; // 查询开始时间
$endTime = empty($param['_params']['endtime']) ? false : $param['_params']['endtime']; // 查询结束时间
# 分页信息
$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 saus_saletime >= "'.$beginTime.'"';
}else{
$where_begin = '';
}
if ($endTime) {
$where_end = ' AND saus_saletime <= "'.$endTime.'"';
}else{
$where_end = '';
}
// 预留
// if ($objuserid) {
// $where_objuserid = ' AND sales_id = '.$objuserid;
// }
$items = $this->PDO_Request(/** @lang text */"
select
saus_salesid, saus_avatar, saus_nickname, saus_firsttime, currency_withdraw, saus_status, currency_freeze, idx
from
sales_user
where
saus_agentid = ? and saus_channelid = ? and saus_salesman = ?{$where_begin}{$where_end}
order by
saus_saletime desc {$strPage}", $param['agentID'], $param['channelID'], 1);
if (!is_array($items))
{
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
return false;
}
# 分页计算
$page_count = 1;
if (!empty($request_data['page_index']))
{
$dbData = $this->PDO_Request(/** @lang text */"
select
count(1) num
from
sales_user
where
saus_agentid = ? and saus_channelid = ? and saus_salesman = ?{$where_begin}{$where_end}
order by
saus_saletime desc {$strPage};", $param['agentID'], $param['channelID'], 1);
if (!is_array($dbData) || count($dbData) < 1)
{
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
return false;
}
$page_count = intval($dbData[0]['num']) / $page_size + 1; // 总页数
}
// 5、数据返回部分
$outParam->biz_content = array(
'data' => $items,
'page_index' => $page_index,
'page_size' => $page_size,
'page_count' => intval($page_count),
);
return true;
}
/**
* [改]修改用户账户
* author summer
* @param RequestParameter $inParam
* @param ReturnParameter $outParam
* @return bool
*/
public function editSalesUser($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(/** @lang text */'select * from sales_user where idx = ?; ', $param['id']);
if (!$item)
{
$outParam->SetErrors(ERRORCODE_COMMISSIONNOTEXISTERROR, ERRORINFO_COMMISSIONNOTEXISTERROR);
return false;
}
#b.传了几个改几个,没有传用默认
// $saus_nickname = isset($param['_params']['saus_nickname']) ? $param['_params']['saus_nickname'] : $item[0]['saus_nickname']; // 昵称
// $saus_wechat = isset($param['_params']['saus_wechat']) ? $param['_params']['saus_wechat'] : $item[0]['saus_wechat']; // 微信
// $saus_tel = isset($param['_params']['saus_tel']) ? $param['_params']['saus_tel'] : $item[0]['saus_tel']; // 电话
$currency_freeze = isset($param['_params']['currency_freeze']) ? $param['_params']['currency_freeze'] : $item[0]['currency_freeze']; // 冻结金额
$this->PDO_Execute(/** @lang text */'update sales_user set currency_freeze = ? where idx = ?', $currency_freeze, $param['id']);
if (!$this->PDO_IsDone())
{
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
return false;
}
return true;
}
##------------ 工具方法[curd]
##------------[summer 2017/11/6 Handel] ----------------------->
/**
* 输入参数标准化处理
* @param RequestParameter $inParam
* @param ReturnParameter $outParam
* @param array $config 待处理变量配置文件
* @return array
*
* authorsummer 2017/11/6
*/
public function inParamHandel($inParam, $outParam, $config)
{
$data = [];
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 $inParam
* @param ReturnParameter $outParam
* @param string $agentID 代理商id
* @param string $channelID 渠道商id
* @param int $salesID 代理人id
*
* @return array
*
* authorsummer 2017/11/6
*/
public function checkAgentAuth($inParam, $outParam, $agentID, $channelID, $salesID)
{
//只有总代理才有权限
$dbSalesInfo = $this->PDO_Request(/** @lang text */'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;
}
}