2193 lines
61 KiB
PHP
2193 lines
61 KiB
PHP
<?php
|
||
|
||
/**
|
||
* Created by PhpStorm.
|
||
* User: win7
|
||
* Date: 2017-07-12
|
||
* Time: 14:26
|
||
*/
|
||
class demand extends BaseMethod
|
||
{
|
||
/**
|
||
* 索要房卡-玩家获取个人代理信息
|
||
* 被请求方法示例:参数固定为RequestParameter和ReturnParameter对象,返回值固定为true(成功)和false(失败)
|
||
* @param RequestParameter $inParam
|
||
* @param ReturnParameter $outParam
|
||
* @return bool
|
||
*/
|
||
public function salesInfo($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;
|
||
}
|
||
|
||
$playerID = isset($request_data['playerid']) ? $request_data['playerid'] : '';
|
||
if (empty($playerID))
|
||
{
|
||
$outParam->SetErrors(ERRORCODE_PLAYERIDERROR, ERRORINFO_PLAYERIDERROR);
|
||
return false;
|
||
}
|
||
|
||
$gameID = isset($request_data['gameid']) ? $request_data['gameid'] : '';
|
||
// if(empty($gameID))
|
||
// {
|
||
// $outParam->SetErrors(ERRORCODE_GAMEIDERROR, ERRORINFO_GAMEIDERROR);
|
||
// return false;
|
||
// }
|
||
|
||
$channelID = isset($request_data['channelid']) ? $request_data['channelid'] : '';
|
||
if (empty($channelID))
|
||
{
|
||
$outParam->SetErrors(ERRORCODE_CHANNELIDERROR, ERRORINFO_CHANNELIDERROR);
|
||
return false;
|
||
}
|
||
|
||
$dbPlayerInfo = $this->PDO_Request(/** @lang text */
|
||
'
|
||
SELECT play_invitecode FROM player where play_agentid=? AND play_channelid=? AND play_playerid=?;', $agentID,
|
||
$channelID, $playerID);
|
||
|
||
if (!is_array($dbPlayerInfo) || count($dbPlayerInfo) < 1)
|
||
{
|
||
$outParam->biz_content = array(
|
||
'state' => 1,
|
||
'error' => '你还未绑定邀请码',
|
||
);
|
||
return true;
|
||
}
|
||
|
||
$db_data = $this->PDO_Request(/** @lang text */
|
||
'
|
||
select
|
||
saus_nickname, saus_salesid, saus_wechat, saus_tel, saus_avatar
|
||
from
|
||
sales_user
|
||
where
|
||
saus_agentid = ? and saus_channelid=? and saus_salesman=1 and saus_salesid = ?;', $agentID, $channelID,
|
||
$dbPlayerInfo[0]['play_invitecode']);
|
||
|
||
if (!is_array($db_data))
|
||
{
|
||
$outParam->biz_content = array(
|
||
'state' => 1,
|
||
'error' => '查询代理信息出错',
|
||
);
|
||
return true;
|
||
}
|
||
|
||
if (count($db_data) < 1)
|
||
{
|
||
$outParam->biz_content = array(
|
||
'state' => 1,
|
||
'error' => '未绑定邀请码',
|
||
);
|
||
return true;
|
||
}
|
||
|
||
/*
|
||
$db_data = $this->PDO_Request(
|
||
'call cp_sales_ask_player_getsalesman(?,?);',
|
||
$agentID,
|
||
$playerID
|
||
);
|
||
|
||
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' => isset($db_data[0]['saus_salesid']) ? $db_data[0]['saus_salesid'] : '',
|
||
'wechat' => isset($db_data[0]['saus_wechat']) ? $db_data[0]['saus_wechat'] : '',
|
||
'tel' => isset($db_data[0]['saus_tel']) ? $db_data[0]['saus_tel'] : '',
|
||
'nickname' => isset($db_data[0]['saus_nickname']) ? $db_data[0]['saus_nickname'] : '',
|
||
'avatar' => isset($db_data[0]['saus_avatar']) ? $db_data[0]['saus_avatar'] : '',
|
||
);
|
||
|
||
return true;
|
||
}
|
||
|
||
/**
|
||
* 索要房卡-个人代理获取上级代理信息
|
||
* 被请求方法示例:参数固定为RequestParameter和ReturnParameter对象,返回值固定为true(成功)和false(失败)
|
||
* @param RequestParameter $inParam
|
||
* @param ReturnParameter $outParam
|
||
* @return bool
|
||
*/
|
||
public function parentInfo($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(
|
||
'call cp_sales_ask_sales_getparentman(?,?);',
|
||
$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' => isset($db_data[0]['sales_id']) ? $db_data[0]['sales_id'] : '',
|
||
'wechat' => isset($db_data[0]['sales_wechat']) ? $db_data[0]['sales_wechat'] : '',
|
||
'tel' => isset($db_data[0]['sales_tel']) ? $db_data[0]['sales_tel'] : '',
|
||
'nickname' => isset($db_data[0]['sales_nickname']) ? $db_data[0]['sales_nickname'] : '',
|
||
'avatar' => isset($db_data[0]['sales_avatar']) ? $db_data[0]['sales_avatar'] : '',
|
||
);
|
||
|
||
return true;
|
||
}
|
||
|
||
|
||
/**
|
||
* 索要房卡-新增订单
|
||
* 被请求方法示例:参数固定为RequestParameter和ReturnParameter对象,返回值固定为true(成功)和false(失败)
|
||
* @param RequestParameter $request
|
||
* @param ReturnParameter $return
|
||
* @return bool
|
||
*/
|
||
public function newOrder($request, &$return)
|
||
{
|
||
$param = $request->biz_content;
|
||
|
||
$agentid = isset($param['agentid']) ? $param['agentid'] : '';
|
||
// 0-玩家索取房卡 1-个人代理索取房卡 2-玩家索取星星 3-个人代理索取星星
|
||
$billtype = isset($param['billtype']) ? $param['billtype'] : '';
|
||
$askid = isset($param['askid']) ? $param['askid'] : '';
|
||
$amount = isset($param['amount']) ? $param['amount'] : '';
|
||
|
||
if (empty($agentid))
|
||
{
|
||
$return->SetErrors(ERRORCODE_AGENTIDERROR, ERRORINFO_AGENTIDERROR);
|
||
return false;
|
||
}
|
||
|
||
if ('' === $billtype)
|
||
{
|
||
$return->SetErrors(ERRORCODE_ORDERTYPEERROR, ERRORINFO_ORDERTYPEERROR);
|
||
return false;
|
||
}
|
||
$billtype = intval($billtype);
|
||
|
||
if ('' === $askid)
|
||
{
|
||
$return->SetErrors(ERRORCODE_ASKIDERROR, ERRORINFO_ASKIDERROR);
|
||
return false;
|
||
}
|
||
|
||
if ('' === $amount)
|
||
{
|
||
$return->SetErrors(ERRORCODE_ASKIDERROR, ERRORINFO_ASKIDERROR);
|
||
return false;
|
||
}
|
||
|
||
$channelID = isset($param['channelid']) ? $param['channelid'] : '';
|
||
if (empty($channelID))
|
||
{
|
||
$return->SetErrors(ERRORCODE_CHANNELIDERROR, ERRORINFO_CHANNELIDERROR);
|
||
return false;
|
||
}
|
||
|
||
$ask_nick_name = '';
|
||
$ask_avatar = '';
|
||
$invite_code = '';
|
||
|
||
/// 业务开始
|
||
$this->PDO_BeginTransaction();
|
||
try
|
||
{
|
||
$cmd = $this->NewMasterCommand();
|
||
if (0 === $billtype || 2 === $billtype)
|
||
{ /// 玩家索取
|
||
$player = $cmd
|
||
->select('play_nickname', 'play_avatar', 'play_invitecode')
|
||
->from('player')
|
||
->where(array(
|
||
'play_agentid' => $agentid,
|
||
'play_playerid' => $askid,
|
||
))
|
||
->request();
|
||
|
||
/// 如果无个人信息,则记录下playerid
|
||
if (!empty($player))
|
||
{
|
||
$ask_nick_name = $player[0]['play_nickname'];
|
||
$ask_avatar = $player[0]['play_avatar'];
|
||
$invite_code = $player[0]['play_invitecode'];
|
||
}
|
||
else
|
||
{
|
||
// $ask_nick_name = $askid;
|
||
// $ask_avatar = '';
|
||
// $invite_code = $askid;
|
||
$return->SetErrors(ERRORCODE_PLAYERIDERROR, ERRORINFO_PLAYERIDERROR);
|
||
return false;
|
||
}
|
||
}
|
||
elseif (1 === $billtype || 3 === $billtype)
|
||
{ /// 个人代理索取
|
||
$sales_user = $cmd
|
||
->select('saus_nickname', 'saus_avatar', 'saus_parentid')
|
||
->from('sales_user')
|
||
->where(array(
|
||
'saus_agentid' => $agentid,
|
||
'saus_salesman' => 1,
|
||
'saus_salesid' => $askid,
|
||
))
|
||
->Request();
|
||
|
||
if (!empty($sales_user))
|
||
{
|
||
$ask_nick_name = $sales_user[0]['saus_nickname'];
|
||
$ask_avatar = $sales_user[0]['saus_avatar'];
|
||
$invite_code = $sales_user[0]['saus_parentid'];
|
||
}
|
||
}
|
||
else
|
||
return false;
|
||
|
||
/// 无邀请码
|
||
if (empty($invite_code))
|
||
{
|
||
$return->SetErrors(ERRORCODE_INVALIDPARAMETER, sprintf(ERRORINFO_INVALIDPARAMETER, 'invitecode'));
|
||
$this->PDO_Rollback();
|
||
return false;
|
||
}
|
||
|
||
//判断索要的人是否被封
|
||
$dbSaleInfo = $this->PDO_Request(/** @lang text */
|
||
'select saus_status from sales_user where saus_agentid=? and saus_salesid=?', $agentid, $invite_code);
|
||
|
||
if (!is_array($dbSaleInfo) || count($dbSaleInfo) < 1)
|
||
{
|
||
$return->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
|
||
return false;
|
||
}
|
||
|
||
if (intval($dbSaleInfo[0]['saus_status']) == 1)
|
||
{
|
||
$return->biz_content = array(
|
||
'state' => 1,
|
||
'errorinfo' => '代理被查封',
|
||
);
|
||
return true;
|
||
}
|
||
|
||
/// 新增数据
|
||
$ret = $cmd
|
||
->insert('sales_ask_bill')
|
||
->Fields('saab_agentid', 'saab_type', 'saab_askid', 'saab_asknickname', 'saab_askavatar',
|
||
'saab_salesid', 'saab_amount', 'saab_state', 'saab_asktime', 'channel_id')
|
||
->values($agentid, $billtype, $askid, $ask_nick_name, $ask_avatar, $invite_code, $amount, 0, $cmd->GetSystemTime(), $channelID)
|
||
->Execute();
|
||
if (!$ret)
|
||
{
|
||
$this->PDO_Rollback();
|
||
$return->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
|
||
return false;
|
||
}
|
||
|
||
$this->PDO_Commit();
|
||
}
|
||
catch (Exception $e)
|
||
{
|
||
$this->PDO_Rollback();
|
||
$return->SetErrors($e->getCode(), $e->getMessage());
|
||
return false;
|
||
}
|
||
|
||
$return->biz_content = array('state' => 0);
|
||
return true;
|
||
}
|
||
|
||
|
||
/**
|
||
* 索要房卡-获取我发起的索要房卡订单列表
|
||
* 被请求方法示例:参数固定为RequestParameter和ReturnParameter对象,返回值固定为true(成功)和false(失败)
|
||
* @param RequestParameter $inParam
|
||
* @param ReturnParameter $outParam
|
||
* @return bool
|
||
*/
|
||
public function orderList($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;
|
||
}
|
||
|
||
$orderType = isset($request_data['billtype']) ? intval($request_data['billtype']) : '';
|
||
if ($orderType === '')
|
||
{
|
||
$outParam->SetErrors(ERRORCODE_ORDERTYPEERROR, ERRORINFO_ORDERTYPEERROR);
|
||
return false;
|
||
}
|
||
|
||
$askID = isset($request_data['askid']) ? intval($request_data['askid']) : '';
|
||
if ($askID === '')
|
||
{
|
||
$outParam->SetErrors(ERRORCODE_ASKIDERROR, ERRORINFO_ASKIDERROR);
|
||
return false;
|
||
}
|
||
|
||
$db_data = $this->PDO_Request(
|
||
'call cp_sales_ask_getmyaskbill(?,?,?);',
|
||
$agentID,
|
||
$orderType,
|
||
$askID
|
||
);
|
||
|
||
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 askCardList($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 = isset($request_data['agentid']) ? $request_data['agentid'] : '';
|
||
$order_type = isset($request_data['billtype']) ? intval($request_data['billtype']) : '';
|
||
$sales_id = isset($request_data['salesid']) ? intval($request_data['salesid']) : '';
|
||
$user_id = @$request_data['userid']; /// 用户编号(新用户表,绑定手机后自动生成。)
|
||
|
||
if (empty($agent_id))
|
||
{
|
||
$outParam->SetErrors(ERRORCODE_AGENTIDERROR, ERRORINFO_AGENTIDERROR);
|
||
return false;
|
||
}
|
||
if ($order_type === '')
|
||
{
|
||
$outParam->SetErrors(ERRORCODE_ORDERTYPEERROR, ERRORINFO_ORDERTYPEERROR);
|
||
return false;
|
||
}
|
||
if ($sales_id === '')
|
||
{
|
||
$outParam->SetErrors(ERRORCODE_SALESIDERROR, ERRORINFO_SALESIDERROR);
|
||
return false;
|
||
}
|
||
|
||
if (empty($user_id))
|
||
{
|
||
$command = /** @lang text */
|
||
<<<EOL
|
||
select
|
||
a.idx,
|
||
a.saab_asktime asktime,
|
||
a.saab_amount amount,
|
||
a.saab_state state,
|
||
case a.saab_state
|
||
when 0 then 0
|
||
when 2 then 2
|
||
when 3 then 3
|
||
else 1
|
||
end stateidx,
|
||
a.saab_askid askid,
|
||
a.saab_asknickname nickname,
|
||
a.saab_askavatar avatar,
|
||
a.saab_dealtime
|
||
from
|
||
sales_ask_bill a
|
||
where
|
||
a.saab_agentid = ? and a.saab_type = ? and a.saab_salesid = ?
|
||
order by
|
||
stateidx, asktime desc
|
||
limit 100
|
||
|
||
EOL;
|
||
$db_data = $this->PDO_Request($command, $agent_id, $order_type, $sales_id);
|
||
}
|
||
else
|
||
{
|
||
$command = /** @lang text */
|
||
<<<EOL
|
||
select
|
||
a.idx,
|
||
a.saab_asktime asktime,
|
||
a.saab_amount amount,
|
||
a.saab_state state,
|
||
case a.saab_state
|
||
when 0 then 0
|
||
when 2 then 2
|
||
when 3 then 3
|
||
else 1
|
||
end stateidx,
|
||
a.saab_askid askid,
|
||
a.saab_asknickname nickname,
|
||
a.saab_askavatar avatar,
|
||
a.saab_dealtime
|
||
from
|
||
sales_ask_bill a inner join sales_user b on a.saab_agentid = b.saus_agentid and a.channel_id = b.saus_channelid and a.saab_salesid = b.saus_salesid
|
||
where
|
||
a.saab_agentid = ? and a.saab_type = ? and b.user_id = ?
|
||
order by
|
||
stateidx, asktime desc
|
||
limit 100
|
||
|
||
EOL;
|
||
$db_data = $this->PDO_Request($command, $agent_id, $order_type, $user_id);
|
||
}
|
||
|
||
if (!$this->pdo_isdone())
|
||
{
|
||
$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 dealOrder($inParam, $outParam)
|
||
{
|
||
$param = $inParam->biz_content;
|
||
|
||
//$channelid = isset($param['channelid']) ? $param['channelid'] : null;
|
||
$idx = isset($param['idx']) ? intval($param['idx']) : null; /// 订单表主键
|
||
$dealid = isset($param['dealid']) ? intval($param['dealid']) : null; /// 发放人的代理号
|
||
$dealstate = isset($param['dealstate']) ? intval($param['dealstate']) : null; /// 是否发放,1:确认发放;3:拒绝
|
||
|
||
if (empty($idx))
|
||
{
|
||
$outParam->SetErrors(ERRORCODE_ORDERIDERROR, ERRORINFO_ORDERIDERROR);
|
||
return false;
|
||
}
|
||
if ($dealid === '')
|
||
{
|
||
$outParam->SetErrors(ERRORCODE_DEALIDERROR, ERRORINFO_DEALIDERROR);
|
||
return false;
|
||
}
|
||
if ($dealstate === '')
|
||
{
|
||
$outParam->SetErrors(ERRORCODE_DEALSTATESERROR, ERRORINFO_DEALSTATESERROR);
|
||
return false;
|
||
}
|
||
|
||
$cmd = $this->NewMasterCommand();
|
||
$sales_ask_bill = $cmd
|
||
->select('a.saab_agentid', 'a.channel_id', 'a.saab_type', 'a.saab_askid', 'a.saab_salesid', 'a.saab_amount', 'b.user_id', 'b.saus_roomcard', 'b.saus_bean')
|
||
->from(array('a' => 'sales_ask_bill',))
|
||
->innerjoin(array('b' => 'sales_user', ))
|
||
->on('a.saab_agentid = b.saus_agentid and a.channel_id = b.saus_channelid and a.saab_salesid = b.saus_salesid')
|
||
->where(array('a.idx' => $idx))
|
||
->request();
|
||
|
||
if (!empty($sales_ask_bill))
|
||
{
|
||
$agentid = $sales_ask_bill[0]['saab_agentid'];
|
||
$channelid = $sales_ask_bill[0]['channel_id'];
|
||
$billtype = intval($sales_ask_bill[0]['saab_type']);
|
||
$askid = $sales_ask_bill[0]['saab_askid'];
|
||
$salesid = $sales_ask_bill[0]['saab_salesid'];
|
||
$amount = $sales_ask_bill[0]['saab_amount'];
|
||
$user_id = $sales_ask_bill[0]['user_id'];
|
||
$room_card = $sales_ask_bill[0]['saus_roomcard'];
|
||
$bean = $sales_ask_bill[0]['saus_bean'];
|
||
}
|
||
else
|
||
{
|
||
$agentid = '';
|
||
$channelid = '';
|
||
$billtype = '';
|
||
$askid = '';
|
||
$salesid = '';
|
||
$amount = '';
|
||
$user_id = '';
|
||
$room_card = 0;
|
||
$bean = 0;
|
||
}
|
||
|
||
if (empty($agentid))
|
||
{
|
||
$outParam->SetErrors(ERRORCODE_ORDERIDERROR, ERRORINFO_ORDERIDERROR);
|
||
return false;
|
||
}
|
||
|
||
if (1 == $dealstate) /// 确认发放
|
||
{
|
||
if ($amount <= 0)
|
||
{
|
||
$outParam->SetErrors(ERRORCODE_AMOUNTERROR, ERRORINFO_AMOUNTERROR);
|
||
return false;
|
||
}
|
||
|
||
$sales_user = $cmd
|
||
->select('saus_roomcard', 'saus_bean')
|
||
->from('sales_user')
|
||
->where(array(
|
||
'saus_agentid' => $agentid,
|
||
'saus_salesman' => 1,
|
||
'saus_salesid' => $salesid,
|
||
))
|
||
->request();
|
||
if (!empty($sales_user))
|
||
{
|
||
$saus_roomcard = $sales_user[0]['saus_roomcard'];
|
||
$saus_star = $sales_user[0]['saus_bean'];
|
||
}
|
||
else
|
||
{
|
||
$saus_roomcard = 0;
|
||
$saus_star = 0;
|
||
}
|
||
|
||
/// 0: 玩家索要房卡
|
||
/// 1: 代理索要房卡
|
||
/// 2: 玩家索要金币
|
||
/// 3: 代理索要金币
|
||
|
||
if (($billtype === 1 || $billtype === 0) && $saus_roomcard < $amount)
|
||
{
|
||
//$outParam->SetErrors(ERRORCODE_AMOUNTERROR, ERRORINFO_AMOUNTERROR);
|
||
$outParam->biz_content = array(
|
||
'state' => 1,
|
||
'error' => '房卡数量不足',
|
||
);
|
||
return true;
|
||
}
|
||
elseif (($billtype === 2 || $billtype === 3) && $saus_star < $amount)
|
||
{
|
||
//$outParam->SetErrors(ERRORCODE_AMOUNTERROR, ERRORINFO_AMOUNTERROR);
|
||
$outParam->biz_content = array(
|
||
'state' => 1,
|
||
'error' => '数量不足',
|
||
);
|
||
return true;
|
||
}
|
||
}
|
||
|
||
if (1 == $dealstate || 3 == $dealstate)
|
||
{
|
||
if ($dealid != $salesid) /// 无权限
|
||
{
|
||
$outParam->SetErrors(ERRORCODE_NOPERMISSION_USER, ERRORINFO_NOPERMISSION_USER);
|
||
return false;
|
||
}
|
||
}
|
||
else if (2 == $dealstate)
|
||
{
|
||
if ($dealid != $askid) /// 无权限
|
||
{
|
||
$outParam->SetErrors(ERRORCODE_NOPERMISSION_USER, ERRORINFO_NOPERMISSION_USER);
|
||
return false;
|
||
}
|
||
}
|
||
|
||
$this->PDO_BeginTransaction();
|
||
try
|
||
{
|
||
$command = /** @lang text */'update sales_ask_bill set saab_state = ?, saab_dealtime = now() where idx = ?';
|
||
if (!$cmd->execute($command, $dealstate, $idx))
|
||
throw new Exception( $this->GetErrorInfo(), $this->GetErrorCode());
|
||
|
||
$asker_roomcard = 0;
|
||
$asker_star = 0;
|
||
$sales_roomcard = 0;
|
||
$sales_star = 0;
|
||
if (1 == $dealstate) /// 确认发放
|
||
{
|
||
|
||
switch ($billtype)
|
||
{
|
||
case 0: /// 玩家、个人 索要房卡
|
||
{
|
||
/// 记录操作流水
|
||
$ret = $cmd->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(?, ?, ?, ?, ?, ?, 3, ?, ?, ?, 0)',
|
||
$agentid, $channelid, $salesid, $agentid, $channelid, $askid, $amount,
|
||
'来源用户为要转卡的代理,目标用户为要接收的玩家。data为要转卡的数量。', time());
|
||
|
||
if (!$ret)
|
||
throw new Exception( $this->GetErrorInfo(), $this->GetErrorCode());
|
||
|
||
$asker_roomcard = $amount;
|
||
|
||
break;
|
||
}
|
||
|
||
case 1: /// 代理索卡
|
||
{
|
||
/// 修改代理的房卡余额
|
||
$command = /** @lang text */'update sales_user set saus_roomcard = saus_roomcard + ? where saus_agentid = ? and saus_salesid = ?';
|
||
if (!$cmd->execute($command, $amount, $agentid, $askid))
|
||
throw new Exception( $this->GetErrorInfo(), $this->GetErrorCode());
|
||
|
||
/// 修改账户的房卡余额
|
||
$command = /** @lang text */'update ct_user_account set card = card + ? where user_id in (select user_id from sales_user where saus_agentid = ? and saus_salesid = ?)';
|
||
if (!$cmd->execute($command, $amount, $agentid, $askid))
|
||
throw new Exception( $this->GetErrorInfo(), $this->GetErrorCode());
|
||
|
||
$sales_user = $cmd
|
||
->select('saus_roomcard')
|
||
->from('sales_user')
|
||
->where(array(
|
||
'saus_agentid' => $agentid,
|
||
'saus_salesid' => $askid,
|
||
))
|
||
->request();
|
||
if (!empty($sales_user))
|
||
$asker_roomcard = $sales_user[0]['saus_roomcard'];
|
||
else
|
||
$asker_roomcard = $amount;
|
||
|
||
break;
|
||
}
|
||
|
||
|
||
case 2: /// 玩家索取星星
|
||
{
|
||
$ret = $cmd->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(?, ?, ?, ?, ?, ?, 13, ?, ?, ?, 0)',
|
||
$agentid, $channelid, $salesid, $agentid, $channelid, $askid, $amount,
|
||
'来源用户为要转星星的代理,目标用户为要接收的玩家。data为要转星星的数量。', time());
|
||
|
||
if (!$ret)
|
||
throw new Exception( $this->GetErrorInfo(), $this->GetErrorCode());
|
||
|
||
$asker_star = $amount;
|
||
|
||
break;
|
||
}
|
||
|
||
case 3: /// 个人代理索取星星
|
||
{
|
||
/// 修改代理的金币余额
|
||
$command = /** @lang text */'update sales_user set saus_bean = saus_bean + ? where saus_agentid = ? and saus_salesid = ?';
|
||
if (!$cmd->execute($command, $amount, $agentid, $askid))
|
||
throw new Exception( $this->GetErrorInfo(), $this->GetErrorCode());
|
||
|
||
/// 修改账户的房卡余额
|
||
$command = /** @lang text */'update ct_user_account set currency = currency + ? where user_id in (select user_id from sales_user where saus_agentid = ? and saus_salesid = ?)';
|
||
if (!$cmd->execute($command, $amount, $agentid, $askid))
|
||
throw new Exception( $this->GetErrorInfo(), $this->GetErrorCode());
|
||
|
||
$sales_user = $cmd
|
||
->select('saus_bean')
|
||
->from('sales_user')
|
||
->where(array(
|
||
'saus_agentid' => $agentid,
|
||
'saus_salesid' => $askid,
|
||
))
|
||
->request();
|
||
if (!empty($sales_user))
|
||
$asker_star = $sales_user[0]['saus_bean'];
|
||
else
|
||
$asker_star = $amount;
|
||
|
||
break;
|
||
}
|
||
}
|
||
|
||
if ($billtype === 0 || $billtype === 1) /// 修改房卡余额
|
||
{
|
||
/// 有绑定账号信息,则需要修改绑定的账户信息
|
||
if (!empty($user_id))
|
||
{
|
||
/// 修改绑定的账户信息
|
||
$command = /** @lang text */'update ct_user_account set card = card - ? where agent_id = ? and channel_id = ? and user_id = ?';
|
||
if (!$cmd->execute($command, $amount, $agentid, $channelid, $user_id))
|
||
throw new Exception($this->GetErrorInfo(), $this->GetErrorCode());
|
||
|
||
/// 修改代理子账户信息
|
||
if ($room_card < $amount)
|
||
{
|
||
/// 如果当前子账户余额不足,则先清空当前子账户
|
||
$command = /** @lang text */'update sales_user set saus_roomcard = 0 where saus_agentid = ? and saus_salesid = ?';
|
||
if (!$cmd->execute($command, $agentid, $salesid))
|
||
throw new Exception( $this->GetErrorInfo(), $this->GetErrorCode());
|
||
|
||
/// 再修改绑定的其他账户
|
||
$need_amount = $amount - $room_card;
|
||
$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, $salesid, $user_id))
|
||
throw new Exception($this->GetErrorInfo(), $this->GetErrorCode());
|
||
}
|
||
else
|
||
{
|
||
$command = /** @lang text */'update sales_user set saus_roomcard = saus_roomcard - ? where saus_agentid = ? and saus_salesid = ?';
|
||
if (!$cmd->execute($command, $amount, $agentid, $salesid))
|
||
throw new Exception( $this->GetErrorInfo(), $this->GetErrorCode());
|
||
}
|
||
}
|
||
else
|
||
{
|
||
$command = /** @lang text */'update sales_user set saus_roomcard = saus_roomcard - ? where saus_agentid = ? and saus_salesid = ?';
|
||
if (!$cmd->execute($command, $amount, $agentid, $salesid))
|
||
throw new Exception( $this->GetErrorInfo(), $this->GetErrorCode());
|
||
}
|
||
}
|
||
elseif ($billtype === 2 || $billtype === 3) /// 修改金币余额
|
||
{
|
||
/// 有绑定账号信息,则需要修改绑定的账户信息
|
||
if (!empty($user_id))
|
||
{
|
||
/// 修改绑定的账户信息
|
||
$command = /** @lang text */'update ct_user_account set currency = currency - ? where agent_id = ? and channel_id = ? and user_id = ?';
|
||
if (!$cmd->execute($command, $amount, $agentid, $channelid, $user_id))
|
||
throw new Exception($this->GetErrorInfo(), $this->GetErrorCode());
|
||
|
||
/// 修改代理子账户信息
|
||
if ($bean < $amount)
|
||
{
|
||
/// 如果当前子账户余额不足,则先清空当前子账户
|
||
$command = /** @lang text */'update sales_user set saus_bean = 0 where saus_agentid = ? and saus_salesid = ?';
|
||
if (!$cmd->execute($command, $agentid, $salesid))
|
||
throw new Exception( $this->GetErrorInfo(), $this->GetErrorCode());
|
||
|
||
/// 再修改绑定的其他账户
|
||
$need_amount = $amount - $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, $salesid, $user_id))
|
||
throw new Exception($this->GetErrorInfo(), $this->GetErrorCode());
|
||
}
|
||
else
|
||
{
|
||
$command = /** @lang text */'update sales_user set saus_bean = saus_bean - ? where saus_agentid = ? and saus_salesid = ?';
|
||
if (!$cmd->execute($command, $amount, $agentid, $salesid))
|
||
throw new Exception( $this->GetErrorInfo(), $this->GetErrorCode());
|
||
}
|
||
}
|
||
else
|
||
{
|
||
$command = /** @lang text */'update sales_user set saus_bean = saus_bean - ? where saus_agentid = ? and saus_salesid = ?';
|
||
if (!$cmd->execute($command, $amount, $agentid, $salesid))
|
||
throw new Exception( $this->GetErrorInfo(), $this->GetErrorCode());
|
||
}
|
||
}
|
||
else
|
||
return false;
|
||
|
||
$sales_user = $cmd
|
||
->select('saus_roomcard')
|
||
->from('sales_user')
|
||
->where(array(
|
||
'saus_agentid' => $agentid,
|
||
'saus_salesid' => $salesid,
|
||
))
|
||
->request();
|
||
if (!empty($sales_user))
|
||
$sales_roomcard = $sales_user[0]['saus_roomcard'];
|
||
else
|
||
$sales_roomcard = 0;
|
||
}
|
||
|
||
$this->PDO_Commit();
|
||
}
|
||
catch (Exception $e)
|
||
{
|
||
$this->PDO_Rollback();
|
||
$outParam->SetErrors($e->getCode(), $e->getMessage());
|
||
return false;
|
||
}
|
||
|
||
$outParam->biz_content = array(
|
||
'state' => 0,
|
||
'agentid' => $agentid,
|
||
'askid' => $askid,
|
||
'amount' => $amount,
|
||
'askerroomcard' => $asker_roomcard,
|
||
'salesroomcard' => $sales_roomcard,
|
||
'askerstar' => $asker_star,
|
||
'salesstar' => $sales_star,
|
||
);
|
||
|
||
return true;
|
||
}
|
||
|
||
/**
|
||
* 查询玩家星星数
|
||
* @param RequestParameter $inParam
|
||
* @param ReturnParameter $outParam
|
||
* @return bool
|
||
*/
|
||
public function queryPlayerStar($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;
|
||
}
|
||
|
||
$playerID = isset($request_data['playerid']) ? $request_data['playerid'] : '';
|
||
if (empty($playerID))
|
||
{
|
||
$outParam->SetErrors(ERRORCODE_PLAYERIDERROR, ERRORINFO_PLAYERIDERROR);
|
||
return false;
|
||
}
|
||
|
||
$userInfo = $this->PDO_Request(
|
||
'call cp_sales_query_player_bean(?,?,?);',
|
||
$agentID,
|
||
$openID,
|
||
$playerID
|
||
);
|
||
|
||
if (!is_array($userInfo) || count($userInfo) < 1)
|
||
{
|
||
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
|
||
return false;
|
||
}
|
||
|
||
if (!isset($userInfo[0]['result']) || intval($userInfo[0]['result']) != 0)
|
||
{
|
||
$outParam->biz_content = array(
|
||
'state' => $userInfo[0]['result'],
|
||
'error' => $userInfo[0]['error'],
|
||
);
|
||
return true;
|
||
}
|
||
|
||
$outParam->biz_content = array(
|
||
'state' => 0,
|
||
'playerid' => isset($userInfo[0]['playerid']) ? $userInfo[0]['playerid'] : '',
|
||
'playername' => isset($userInfo[0]['playername']) ? $userInfo[0]['playername'] : '',
|
||
'playerbean' => isset($userInfo[0]['playerbean']) ? $userInfo[0]['playerbean'] : '',
|
||
);
|
||
return true;
|
||
}
|
||
|
||
|
||
/**
|
||
* 给玩家充星星
|
||
* @param RequestParameter $inParam
|
||
* @param ReturnParameter $outParam
|
||
* @return bool
|
||
*/
|
||
public function addStar($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 = isset($request_data['agentid']) ? $request_data['agentid'] : '';
|
||
$open_id = isset($request_data['openid']) ? $request_data['openid'] : '';
|
||
$player_id = isset($request_data['playerid']) ? $request_data['playerid'] : '';
|
||
$amount = isset($request_data['amount']) ? intval($request_data['amount']) : 0;
|
||
$channel_id = isset($request_data['channelid']) ? $request_data['channelid'] : '';
|
||
|
||
$from_sales = @$request_data['fromsales']; /// 来源代理号
|
||
|
||
if (empty($agent_id))
|
||
{
|
||
$outParam->SetErrors(ERRORCODE_AGENTIDERROR, ERRORINFO_AGENTIDERROR);
|
||
return false;
|
||
}
|
||
if (empty($open_id))
|
||
{
|
||
$outParam->SetErrors(ERRORCODE_OPENIDERROR, ERRORINFO_OPENIDERROR);
|
||
return false;
|
||
}
|
||
if (empty($player_id))
|
||
{
|
||
$outParam->SetErrors(ERRORCODE_PLAYERIDERROR, ERRORINFO_PLAYERIDERROR);
|
||
return false;
|
||
}
|
||
if ($amount <= 0)
|
||
{
|
||
$outParam->SetErrors(ERRORCODE_AMOUNTERROR, ERRORINFO_AMOUNTERROR);
|
||
return false;
|
||
}
|
||
if (empty($channel_id))
|
||
{
|
||
$outParam->SetErrors(ERRORCODE_CHANNELIDERROR, ERRORINFO_CHANNELIDERROR);
|
||
return false;
|
||
}
|
||
if (empty($from_sales))
|
||
{
|
||
$outParam->SetErrors(ERRORCODE_SALESIDERROR, ERRORINFO_SALESIDERROR);
|
||
return false;
|
||
}
|
||
|
||
$this->PDO_BeginTransaction();
|
||
try
|
||
{
|
||
$dbAgentInfo = $this->PDO_Request(/** @lang text */
|
||
'select default_sales_power as agentsalespower from ct_agent_list where agent_id = ?;', $agent_id);
|
||
if (!is_array($dbAgentInfo) || count($dbAgentInfo) < 1)
|
||
throw new Exception($this->GetErrorInfo(), $this->GetErrorCode());
|
||
|
||
$command = /** @lang text */
|
||
<<<EOL
|
||
select
|
||
idx,
|
||
saus_salesid salesid,
|
||
saus_power salespower,
|
||
saus_bean salesbean,
|
||
saus_status,
|
||
saus_salesman,
|
||
user_id
|
||
from
|
||
sales_user
|
||
where
|
||
saus_agentid = ? and saus_channelid = ? and saus_salesid = ?
|
||
EOL;
|
||
|
||
$dbSalesInfo = $this->PDO_Request($command, $agent_id, $channel_id, $from_sales);
|
||
if (!is_array($dbSalesInfo) || count($dbSalesInfo) < 1)
|
||
throw new Exception($this->GetErrorInfo(), $this->GetErrorCode());
|
||
|
||
if (intval($dbSalesInfo[0]['saus_status']) == 1)
|
||
throw new Exception(ERRORINFO_SALESCLOSEERROR, ERRORCODE_SALESCLOSEERROR);
|
||
|
||
if (intval($dbSalesInfo[0]['saus_salesman']) == 0)
|
||
throw new Exception(ERRORINFO_NOTSALESERROR, ERRORCODE_NOTSALESERROR);
|
||
|
||
$user_id = $dbSalesInfo[0]['user_id'];
|
||
if (empty($user_id))
|
||
{
|
||
if (intval($dbSalesInfo[0]['salesbean']) < $amount)
|
||
throw new Exception(ERRORINFO_AMOUNTERROR, ERRORCODE_AMOUNTERROR);
|
||
}
|
||
else
|
||
{
|
||
$user_info = $this->pdo_request(/** @lang text */
|
||
'select currency, enabled from ct_user_account where agent_id = ? and channel_id = ? and user_id = ?',
|
||
$agent_id, $channel_id, $user_id);
|
||
if (empty($user_info))
|
||
throw new Exception(ERRORINFO_SALESNOTEXISTERROR, ERRORCODE_SALESNOTEXISTERROR);
|
||
|
||
if (0 == $user_info[0]['enabled']) /// 判断状态
|
||
throw new Exception(ERRORINFO_SALESCLOSEERROR, ERRORCODE_SALESCLOSEERROR);
|
||
|
||
if ($user_info[0]['currency'] < $amount) /// 游戏币存量
|
||
throw new Exception(ERRORINFO_AMOUNTERROR, ERRORCODE_AMOUNTERROR);
|
||
}
|
||
|
||
$salesPower = $dbSalesInfo[0]['salespower'];
|
||
if (empty($salesPower))
|
||
$salesPower = $dbAgentInfo[0]['agentsalespower'];
|
||
switch (intval(substr($salesPower, 2, 1)))
|
||
{
|
||
case 0: /// 无权限
|
||
throw new Exception(ERRORINFO_NOPOWERERROR, ERRORCODE_NOPOWERERROR);
|
||
break;
|
||
|
||
case 1: /// 需要判断是否绑定自己
|
||
break;
|
||
|
||
case 2: /// 可以给所有玩家转卡
|
||
break;
|
||
|
||
default:
|
||
throw new Exception(ERRORINFO_NOPOWERERROR, ERRORCODE_NOPOWERERROR);
|
||
break;
|
||
}
|
||
|
||
/// 加入订单记录
|
||
$ret = $this->PDO_Execute(/** @lang text */
|
||
'insert into sales_sellbill_bean(ssbe_agentid, ssbe_openid, ssbe_playerid, ssbe_amount, ssbe_selltime, channel_id, from_sales) values(?, ?, ?, ?, ?, ?, ?)',
|
||
$agent_id, $open_id, $player_id, $amount, date('Y-m-d H:i:s', time()), $channel_id, $from_sales);
|
||
if (!$ret)
|
||
throw new Exception($this->GetErrorInfo(), $this->GetErrorCode());
|
||
|
||
/// 当传入了用户id的时候,则需要更新用户账户表中的数据
|
||
if (!empty($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, $agent_id, $channel_id, $user_id);
|
||
if (!$ret)
|
||
throw new Exception($this->GetErrorInfo(), $this->GetErrorCode());
|
||
|
||
/// 如果当前代理子账户余额不足,则扣除绑定的其他子账户中的金币
|
||
if (intval($dbSalesInfo[0]['salesbean']) < $amount)
|
||
{
|
||
/// 更新代理信息表
|
||
$ret = $this->PDO_Execute(/** @lang text */
|
||
'update sales_user set saus_bean = 0 where saus_agentid = ? and saus_channelid = ? and saus_salesid = ?;',
|
||
$agent_id, $channel_id, $from_sales);
|
||
|
||
if (!$ret)
|
||
throw new Exception($this->GetErrorInfo(), $this->GetErrorCode());
|
||
|
||
/// 扣除掉其他绑定了同一个账号的子代理账号
|
||
$need_amount = $amount - $dbSalesInfo[0]['salesbean'];
|
||
$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, $agent_id, $channel_id, $user_id))
|
||
throw new Exception($this->GetErrorInfo(), $this->GetErrorCode());
|
||
}
|
||
else
|
||
{
|
||
/// 更新代理记录
|
||
$res = $this->PDO_Execute(/** @lang text */
|
||
'update sales_user set saus_bean = saus_bean - ? where saus_agentid = ? and saus_channelid = ? and saus_salesid = ?;',
|
||
$amount, $agent_id, $channel_id, $from_sales);
|
||
if (!$res)
|
||
throw new Exception($this->GetErrorInfo(), $this->GetErrorCode());
|
||
}
|
||
}
|
||
else
|
||
{
|
||
/// 更新代理记录
|
||
$res = $this->PDO_Execute(/** @lang text */
|
||
'update sales_user set saus_bean = saus_bean - ? where saus_agentid = ? and saus_channelid = ? and saus_salesid = ?;',
|
||
$amount, $agent_id, $channel_id, $from_sales);
|
||
if (!$res)
|
||
throw new Exception($this->GetErrorInfo(), $this->GetErrorCode());
|
||
}
|
||
|
||
/// 更新玩家记录
|
||
$res = $this->PDO_Execute(/** @lang text */
|
||
'update player set play_bean = play_bean + ? where play_agentid = ? and play_playerid = ?;',
|
||
$amount, $agent_id, $player_id);
|
||
if (!$res)
|
||
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 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
|
||
$agent_id, $channel_id, $from_sales, $agent_id, $channel_id, $player_id, 12, $amount, '', 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;
|
||
}
|
||
|
||
$outParam->biz_content = array(
|
||
'state' => 0,
|
||
'salesbean' => (intval($dbSalesInfo[0]['salesbean']) - $amount),
|
||
'amount' => $amount,
|
||
'playerid' => $player_id,
|
||
'playername' => '',
|
||
'playerbean' => 0,
|
||
);
|
||
return true;
|
||
|
||
}
|
||
|
||
/**
|
||
* 给玩家充星星的记录
|
||
* @param RequestParameter $inParam
|
||
* @param ReturnParameter $outParam
|
||
* @return bool
|
||
*/
|
||
public function addStarRecord($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 = isset($request_data['agentid']) ? $request_data['agentid'] : '';
|
||
$channel_id = isset($request_data['channelid']) ? $request_data['channelid'] : '';
|
||
//$open_id = isset($request_data['openid']) ? $request_data['openid'] : '';
|
||
$begin_time = isset($request_data['begintime']) ? $request_data['begintime'] : '';
|
||
$end_time = 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']);
|
||
|
||
$sales_id = @$request_data['salesid']; /// 代理号
|
||
$user_id = @$request_data['userid']; /// 用户编号(新用户表,绑定手机后自动生成。)
|
||
|
||
if (empty($agent_id))
|
||
{
|
||
$outParam->SetErrors(ERRORCODE_AGENTIDERROR, ERRORINFO_AGENTIDERROR);
|
||
return false;
|
||
}
|
||
if ($begin_time > $end_time)
|
||
{
|
||
$outParam->SetErrors(ERRORCODE_TIMEERROR, ERRORINFO_TIMEERROR);
|
||
return false;
|
||
}
|
||
|
||
if (empty($user_id)) /// 如果没有userid,则按原方式获取记录
|
||
{
|
||
$str_time = '';
|
||
$array_param = array(
|
||
$agent_id,
|
||
$channel_id,
|
||
$sales_id,
|
||
);
|
||
|
||
if (!empty($begin_time))
|
||
{
|
||
$str_time .= ' and date_format(a.ssbe_selltime, \'%Y-%m-%d\') >= ? ';
|
||
$array_param[] = $begin_time;
|
||
}
|
||
|
||
if (!empty($end_time))
|
||
{
|
||
$str_time .= ' and date_format(a.ssbe_selltime, \'%Y-%m-%d\') <= ? ';
|
||
$array_param[] = $end_time;
|
||
}
|
||
|
||
$start = ($page_index - 1) * $page_size;
|
||
|
||
$strPage = '';
|
||
if (!empty($request_data['page_index']))
|
||
$strPage .= " LIMIT {$start},{$page_size} ";
|
||
|
||
$command = /** @lang text */<<<EOL
|
||
select
|
||
date_format(a.ssbe_selltime, '%Y-%m-%d %H:%i') time,
|
||
a.ssbe_playerid playerid,
|
||
d.play_nickname name,
|
||
d.play_avatar avatar,
|
||
a.ssbe_amount amount
|
||
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.channel_id = ? and
|
||
a.from_sales = ? {$str_time}
|
||
order by
|
||
a.ssbe_selltime desc
|
||
{$strPage}
|
||
EOL;
|
||
$record = $this->PDO_Request($command, $array_param);
|
||
|
||
$page_count = 1;
|
||
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.channel_id = ? 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;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
$str_time = '';
|
||
$array_param = array(
|
||
$agent_id,
|
||
$channel_id,
|
||
$user_id,
|
||
);
|
||
|
||
if (!empty($begin_time))
|
||
{
|
||
$str_time .= ' and date_format(a.ssbe_selltime, \'%Y-%m-%d\') >= ? ';
|
||
$array_param[] = $begin_time;
|
||
}
|
||
|
||
if (!empty($end_time))
|
||
{
|
||
$str_time .= ' and date_format(a.ssbe_selltime, \'%Y-%m-%d\') <= ? ';
|
||
$array_param[] = $end_time;
|
||
}
|
||
|
||
$start = ($page_index - 1) * $page_size;
|
||
|
||
$strPage = '';
|
||
if (!empty($request_data['page_index']))
|
||
$strPage .= " LIMIT {$start},{$page_size} ";
|
||
|
||
$command = /** @lang text */<<<EOL
|
||
select
|
||
date_format(a.ssbe_selltime, '%Y-%m-%d %H:%i') time,
|
||
a.ssbe_playerid playerid,
|
||
d.play_nickname name,
|
||
d.play_avatar avatar,
|
||
a.ssbe_amount amount
|
||
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.channel_id = ? and
|
||
b.user_id = ? {$str_time}
|
||
order by
|
||
a.ssbe_selltime desc
|
||
{$strPage}
|
||
EOL;
|
||
$record = $this->PDO_Request($command, $array_param);
|
||
|
||
$page_count = 1;
|
||
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.channel_id = ? and
|
||
b.user_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;
|
||
}
|
||
}
|
||
|
||
|
||
if (!is_array($record))
|
||
{
|
||
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
|
||
return false;
|
||
}
|
||
|
||
$outParam->biz_content = array(
|
||
'list' => $record,
|
||
'page_index' => $page_index,
|
||
'page_size' => $page_size,
|
||
'page_count' => $page_count,
|
||
);
|
||
return true;
|
||
}
|
||
|
||
|
||
/**
|
||
* 代理给代理充星星
|
||
* 被请求方法示例:参数固定为RequestParameter和ReturnParameter对象,返回值固定为true(成功)和false(失败)
|
||
* @param RequestParameter $inParam
|
||
* @param ReturnParameter $outParam
|
||
* @return bool
|
||
* http://localhost/project/daili/api/Index.php?method=agent.demand.transStar&format=json&charset=utf-8×tamp=1&version=1.0&biz_content={%22agentid%22:%2200bA05haB0d9ZC0fwGD09Q2OA30insbQ%22,%22unionid%22:%22oLVKiswayfK7UiKtrXLt_PSTdb8g%22,%22salesid%22:%22200017%22,%22amount%22:%225%22}&user_auth_token=xxxxxxxx
|
||
*/
|
||
public function transStar($inParam, $outParam)
|
||
{
|
||
$param = isset($inParam->biz_content) ? $inParam->biz_content : '';
|
||
if (!is_array($param))
|
||
{
|
||
/// 参数格式错误
|
||
$outParam->SetErrors(ERRORCODE_INPARAMERROR, ERRORINFO_INPARAMERROR);
|
||
return false;
|
||
}
|
||
|
||
$agent_id = @$param['agentid']; /// 代理
|
||
$channel_id = @$param['channelid']; /// 渠道
|
||
$from_sales = @$param['fromsales']; /// 来源(发送人的salesid)
|
||
$to_sales = @$param['tosales']; /// 目标(接收人的salesid)
|
||
$amount = isset($param['amount']) ? intval($param['amount']) : 0;
|
||
|
||
if ($amount == 0)
|
||
{
|
||
$outParam->SetErrors(ERRORCODE_AMOUNTERROR, ERRORINFO_AMOUNTERROR);
|
||
return false;
|
||
}
|
||
|
||
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($from_sales))
|
||
{
|
||
$outParam->SetErrors(ERRORCODE_FROMUSERERROR, ERRORINFO_FROMUSERERROR);
|
||
return false;
|
||
}
|
||
if (empty($to_sales))
|
||
{
|
||
$outParam->SetErrors(ERRORCODE_TOUSERERROR, ERRORINFO_TOUSERERROR);
|
||
return false;
|
||
}
|
||
if ($amount <= 0)
|
||
{
|
||
$outParam->SetErrors(ERRORCODE_AMOUNTERROR, ERRORINFO_AMOUNTERROR);
|
||
return false;
|
||
}
|
||
|
||
$command = /** @lang text */
|
||
<<<EOL
|
||
select
|
||
idx, saus_salesman, saus_salesid, saus_level, saus_roomcard, saus_bean, saus_status, saus_unionid, saus_openid, user_id
|
||
from
|
||
sales_user
|
||
where
|
||
saus_agentid = ? and saus_channelid = ? and saus_salesid = ?
|
||
EOL;
|
||
|
||
/// 获取来源账户信息
|
||
$from = $this->PDO_Request($command, $agent_id, $channel_id, $from_sales);
|
||
if (!$this->PDO_IsDone())
|
||
{
|
||
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
|
||
return false;
|
||
}
|
||
if (count($from) < 1)
|
||
{
|
||
$outParam->SetErrors(ERRORCODE_SALESNOTEXISTERROR, ERRORINFO_SALESNOTEXISTERROR);
|
||
return false;
|
||
}
|
||
|
||
/// 获取目标账户信息
|
||
$to = $this->PDO_Request($command, $agent_id, $channel_id, $to_sales);
|
||
if (!$this->PDO_IsDone())
|
||
{
|
||
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
|
||
return false;
|
||
}
|
||
if (count($to) < 1)
|
||
{
|
||
$outParam->SetErrors(ERRORCODE_SALESNOTEXISTERROR, ERRORINFO_SALESNOTEXISTERROR);
|
||
return false;
|
||
}
|
||
|
||
//开始事务
|
||
$this->PDO_BeginTransaction();
|
||
try
|
||
{
|
||
/// 判断代理是否被封
|
||
if (intval($from[0]['saus_status']) == 1)
|
||
throw new Exception(ERRORINFO_SALESCLOSEERROR, ERRORCODE_SALESCLOSEERROR);
|
||
|
||
if (!empty($from_user = $from[0]['user_id']))
|
||
{
|
||
$user_info = $this->pdo_request(/** @lang text */
|
||
'select currency, enabled from ct_user_account where agent_id = ? and channel_id = ? and user_id = ?',
|
||
$agent_id, $channel_id, $from_user);
|
||
if (empty($user_info))
|
||
throw new Exception(ERRORINFO_SALESNOTEXISTERROR, ERRORCODE_SALESNOTEXISTERROR);
|
||
|
||
if (0 == $user_info[0]['enabled']) /// 判断状态
|
||
throw new Exception(ERRORINFO_SALESCLOSEERROR, ERRORCODE_SALESCLOSEERROR);
|
||
|
||
if ($user_info[0]['currency'] < $amount) /// 金币存量
|
||
throw new Exception(ERRORINFO_ROOMCARDENOUGHERROR, ERRORCODE_ROOMCARDENOUGHERROR);
|
||
}
|
||
else
|
||
{
|
||
/// 判断转星星的代理星星是否足够
|
||
if ($from[0]['saus_bean'] < $amount)
|
||
throw new Exception(ERRORINFO_STARNOENOUGHERROR, ERRORCODE_STARNOENOUGHERROR);
|
||
}
|
||
|
||
/// 判断代理是否被封
|
||
if (intval($to[0]['saus_status']) == 1)
|
||
throw new Exception(ERRORINFO_SALESCLOSEERROR, ERRORCODE_SALESCLOSEERROR);
|
||
|
||
if (!empty($to_user = $to[0]['user_id']))
|
||
{
|
||
$user_info = $this->pdo_request(/** @lang text */
|
||
'select currency, enabled from ct_user_account where agent_id = ? and channel_id = ? and user_id = ?',
|
||
$agent_id, $channel_id, $to_user);
|
||
if (empty($user_info))
|
||
throw new Exception(ERRORINFO_SALESNOTEXISTERROR, ERRORCODE_SALESNOTEXISTERROR);
|
||
|
||
if (0 == $user_info[0]['enabled']) /// 判断状态
|
||
throw new Exception(ERRORINFO_SALESCLOSEERROR, ERRORCODE_SALESCLOSEERROR);
|
||
}
|
||
|
||
/// 减少转让者星星
|
||
if (empty($from_user))
|
||
{
|
||
$command = /** @lang text */
|
||
<<<EOL
|
||
update sales_user set saus_bean = saus_bean - ? where idx = ?
|
||
EOL;
|
||
$ret = $this->PDO_Execute($command, $amount, $from[0]['idx']);
|
||
}
|
||
else
|
||
{
|
||
$ret = $this->PDO_Execute(/** @lang text */
|
||
'update ct_user_account set currency = currency - ? where agent_id = ? and channel_id = ? and user_id = ?',
|
||
$amount, $agent_id, $channel_id, $from_user);
|
||
if (!$ret)
|
||
throw new Exception($this->GetErrorInfo(), $this->GetErrorCode());
|
||
|
||
/// 如果当前代理子账户余额不足,则扣除绑定的其他子账户中的金币
|
||
if (intval($from[0]['saus_bean']) < $amount)
|
||
{
|
||
/// 更新代理信息表
|
||
$ret = $this->PDO_Execute(/** @lang text */
|
||
'update sales_user set saus_bean = 0 where saus_agentid = ? and saus_channelid = ? and saus_salesid = ?;',
|
||
$agent_id, $channel_id, $from_sales);
|
||
|
||
if (!$ret)
|
||
throw new Exception($this->GetErrorInfo(), $this->GetErrorCode());
|
||
|
||
/// 扣除掉其他绑定了同一个账号的子代理账号
|
||
$need_amount = $amount - $from[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, $agent_id, $channel_id, $from_user))
|
||
throw new Exception($this->GetErrorInfo(), $this->GetErrorCode());
|
||
}
|
||
else
|
||
{
|
||
/// 更新代理记录
|
||
$res = $this->PDO_Execute(/** @lang text */
|
||
'update sales_user set saus_bean = saus_bean - ? where saus_agentid = ? and saus_channelid = ? and saus_salesid = ?;',
|
||
$amount, $agent_id, $channel_id, $from_sales);
|
||
if (!$res)
|
||
throw new Exception($this->GetErrorInfo(), $this->GetErrorCode());
|
||
}
|
||
}
|
||
if (!$this->PDO_IsDone() || !$ret)
|
||
throw new Exception($this->GetErrorInfo(), $this->GetErrorCode());
|
||
|
||
/// 接受人增加星星
|
||
if (empty($to_user))
|
||
{
|
||
$command = /** @lang text */
|
||
'update sales_user set saus_bean = saus_bean + ? where idx = ?';
|
||
$ret = $this->PDO_Execute($command, $amount, $to[0]['idx']);
|
||
}
|
||
else
|
||
{
|
||
$command = /** @lang text */
|
||
<<<EOL
|
||
update
|
||
sales_user a,
|
||
ct_user_account b
|
||
set
|
||
a.saus_bean = a.saus_bean + ?,
|
||
b.currency = b.currency + ?
|
||
where
|
||
a.saus_agentid = b.agent_id and a.saus_channelid = b.channel_id and a.user_id = b.user_id and
|
||
a.idx = ?
|
||
|
||
EOL;
|
||
$ret = $this->PDO_Execute($command, $amount, $amount, $to[0]['idx']);
|
||
}
|
||
if (!$this->PDO_IsDone() || !$ret)
|
||
throw new Exception($this->GetErrorInfo(), $this->GetErrorCode());
|
||
|
||
/// 记入日志
|
||
$ret = $this->PDO_Execute(/** @lang text */
|
||
'
|
||
insert into trans_star_record(agent_id, channel_id, union_id, open_id, send_id, get_id, type, amount, op_time)
|
||
values(?, ?, ?, ?, ?, ?, ?, ?, ?);', $agent_id, $channel_id, $from[0]['saus_unionid'], $from[0]['saus_openid'], $from[0]['saus_salesid'],
|
||
$to[0]['saus_salesid'], 0, $amount, date('Y-m-d H:i:s', time()));
|
||
|
||
if (!$this->PDO_IsDone() || !$ret)
|
||
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
|
||
*/
|
||
public function transStarRecord($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']; /// 代理号
|
||
$begin_time = @$request_data['begintime']; /// 起始时间
|
||
$end_time = @$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']); /// 页大小
|
||
|
||
$user_id = @$request_data['user_id']; /// 用户编号(新用户表,绑定手机后自动生成。)
|
||
|
||
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;
|
||
}
|
||
|
||
if (true /*empty($user_id)*/)
|
||
{
|
||
if (!empty($begin_time) && !empty($end_time))
|
||
{
|
||
if ($begin_time > $end_time)
|
||
{
|
||
$outParam->SetErrors(ERRORCODE_TIMEERROR, ERRORINFO_TIMEERROR);
|
||
return false;
|
||
}
|
||
|
||
$time_filter = ' and date_format(op_time, \'%Y-%m-%d\') between ? and ?';
|
||
$param = array(
|
||
$agent_id,
|
||
$channel_id,
|
||
$sales_id,
|
||
$begin_time,
|
||
$end_time,
|
||
);
|
||
}
|
||
else
|
||
{
|
||
$time_filter = '';
|
||
$param = array(
|
||
$agent_id,
|
||
$channel_id,
|
||
$sales_id,
|
||
);
|
||
}
|
||
|
||
$start = ($page_index - 1) * $page_size;
|
||
$limit = '';
|
||
if (!empty($request_data['page_index']))
|
||
$limit .= " limit {$start}, {$page_size} ";
|
||
|
||
$command = /** @lang text */
|
||
<<<EOL
|
||
select
|
||
date_format(a.op_time, '%Y-%m-%d %h:%i') as time,
|
||
a.union_id,
|
||
a.send_id,
|
||
a.get_id,
|
||
a.amount,
|
||
b.saus_nickname,
|
||
b.saus_avatar
|
||
from
|
||
trans_star_record a left join
|
||
sales_user b on b.saus_agentid = a.agent_id and a.channel_id = b.saus_channelid and b.saus_salesid = a.get_id
|
||
where
|
||
a.agent_id = ? and a.channel_id = ? and a.send_id = ? {$time_filter}
|
||
order by
|
||
op_time desc
|
||
{$limit}
|
||
|
||
EOL;
|
||
|
||
$db_data = $this->PDO_Request($command, $param);
|
||
|
||
if (!$this->PDO_IsDone())
|
||
{
|
||
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
|
||
return false;
|
||
}
|
||
|
||
$page_count = 1;
|
||
if (!empty($request_data['page_index']))
|
||
{
|
||
$command = /** @lang text */
|
||
<<<EOL
|
||
select
|
||
count(0) num
|
||
from
|
||
trans_star_record a left join
|
||
sales_user b on b.saus_agentid = a.agent_id and a.channel_id = b.saus_channelid and b.saus_salesid = a.get_id
|
||
where
|
||
a.agent_id = ? and a.channel_id = ? and a.send_id = ? {$time_filter}
|
||
|
||
EOL;
|
||
|
||
$dbCount = $this->PDO_Request($command, $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
|
||
{
|
||
if (!empty($begin_time) && !empty($end_time))
|
||
{
|
||
if ($begin_time > $end_time)
|
||
{
|
||
$outParam->SetErrors(ERRORCODE_TIMEERROR, ERRORINFO_TIMEERROR);
|
||
return false;
|
||
}
|
||
|
||
$time_filter = ' and date_format(op_time, \'%Y-%m-%d\') between ? and ?';
|
||
$param = array(
|
||
$agent_id,
|
||
$channel_id,
|
||
$user_id,
|
||
$begin_time,
|
||
$end_time,
|
||
);
|
||
}
|
||
else
|
||
{
|
||
$time_filter = '';
|
||
$param = array(
|
||
$agent_id,
|
||
$channel_id,
|
||
$user_id,
|
||
);
|
||
}
|
||
|
||
$start = ($page_index - 1) * $page_size;
|
||
$limit = '';
|
||
if (!empty($request_data['page_index']))
|
||
$limit .= " limit {$start}, {$page_size} ";
|
||
|
||
$command = /** @lang text */
|
||
<<<EOL
|
||
select
|
||
date_format(a.op_time, '%Y-%m-%d %h:%i') as time,
|
||
a.union_id,
|
||
a.send_id,
|
||
a.get_id,
|
||
a.amount,
|
||
b.saus_nickname,
|
||
b.saus_avatar
|
||
from
|
||
trans_star_record a left join
|
||
sales_user b on b.saus_agentid = a.agent_id and a.channel_id = b.saus_channelid and b.saus_salesid = a.send_id
|
||
where
|
||
a.agent_id = ? and a.channel_id = ? and b.user_id = ? {$time_filter}
|
||
order by
|
||
op_time desc
|
||
{$limit}
|
||
|
||
EOL;
|
||
|
||
$db_data = $this->PDO_Request($command, $param);
|
||
|
||
if (!$this->PDO_IsDone())
|
||
{
|
||
$outParam->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
|
||
return false;
|
||
}
|
||
|
||
$page_count = 1;
|
||
if (!empty($request_data['page_index']))
|
||
{
|
||
$command = /** @lang text */
|
||
<<<EOL
|
||
select
|
||
count(0) num
|
||
from
|
||
trans_star_record a left join
|
||
sales_user b on b.saus_agentid = a.agent_id and a.channel_id = b.saus_channelid and b.saus_salesid = a.send_id
|
||
where
|
||
a.agent_id = ? and a.channel_id = ? and b.user_id = ? {$time_filter}
|
||
|
||
EOL;
|
||
|
||
$dbCount = $this->PDO_Request($command, $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(
|
||
'detail' => $db_data,
|
||
'page_index' => $page_index,
|
||
'page_size' => $page_size,
|
||
'page_count' => $page_count,
|
||
);
|
||
return true;
|
||
}
|
||
|
||
|
||
/**
|
||
* 扣除玩家星星
|
||
* @param RequestParameter $inParam
|
||
* @param ReturnParameter $outParam
|
||
* @return bool
|
||
* method=agent.demand.deductStar&format=json&charset=utf-8×tamp=1&version=1.0&biz_content={"agentid":"00bA05haB0d9ZC0fwGD09Q2OA30insbQ","channelid":"frdt0C1GG0t91P0McFo0rbA1he5yurbS","gameid":"123","playerid":"100002","amount":10}
|
||
*/
|
||
public function deductStar($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;
|
||
}
|
||
|
||
$gameID = isset($request_data['gameid']) ? $request_data['gameid'] : '';
|
||
|
||
$playerID = isset($request_data['playerid']) ? $request_data['playerid'] : '';
|
||
if (empty($playerID))
|
||
{
|
||
$outParam->SetErrors(ERRORCODE_PLAYERIDERROR, ERRORINFO_PLAYERIDERROR);
|
||
return false;
|
||
}
|
||
|
||
$amount = isset($request_data['amount']) ? intval($request_data['amount']) : 0;
|
||
if ($amount <= 0)
|
||
{
|
||
$outParam->SetErrors(ERRORCODE_AMOUNTERROR, ERRORINFO_AMOUNTERROR);
|
||
return false;
|
||
}
|
||
|
||
//查询玩家当前星星数
|
||
$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(REQUEST_USER_INFO . '?' . $json_data);
|
||
|
||
//请求数据出错
|
||
if (!$dd_ret)
|
||
{
|
||
$outParam->SetErrors(ERRORCODE_NODATAERROR, ERRORINFO_NODATAERROR);
|
||
return false;
|
||
}
|
||
$playerInfo = json_decode($dd_ret, true);
|
||
|
||
if (!$playerInfo)
|
||
{
|
||
$outParam->SetErrors(ERRORCODE_NODATAERROR, ERRORINFO_NODATAERROR);
|
||
return false;
|
||
}
|
||
|
||
$playerBeans = intval($playerInfo['data']['bean']);
|
||
if ($amount > $playerBeans)
|
||
{
|
||
$outParam->SetErrors(ERRORCODE_STARNOENOUGHERROR, ERRORINFO_STARNOENOUGHERROR);
|
||
return false;
|
||
}
|
||
|
||
|
||
$this->PDO_BeginTransaction();
|
||
try
|
||
{
|
||
//扣除代理后台玩家星星数
|
||
$res = $this->PDO_Execute(/** @lang */
|
||
'
|
||
update player set play_bean = play_bean - ?
|
||
where play_agentid = ? and play_playerid = ?;', $amount, $agentID, $playerID);
|
||
if (!$res || !$this->PDO_IsDone())
|
||
{
|
||
throw new Exception($this->GetErrorInfo(), $this->GetErrorCode());
|
||
}
|
||
|
||
//为游戏记录日志
|
||
$log_res = $this->PDO_Execute(/** @lang */
|
||
'
|
||
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, '', $agentID, $channelID, $playerID, 12, -$amount, '玩家报名比赛,扣除星星', time(), 0);
|
||
|
||
if (!$log_res || !$this->PDO_IsDone())
|
||
{
|
||
throw new Exception(ERRORINFO_ORDERNULLERROR, ERRORCODE_ORDERNULLERROR);
|
||
}
|
||
|
||
//记录代理后台日志
|
||
$res = $this->PDO_Execute(/** @lang */
|
||
'
|
||
INSERT INTO
|
||
player_bean_use_record(agent_id, channel_id, player_id, game_id, use_type, amount, create_time)
|
||
VALUES(?, ?, ?, ?, ?, ?, ?);', $agentID, $channelID, $playerID, $gameID, 0, $amount, date('Y-m-d H:i:s', time()));
|
||
if (!$res || !$this->PDO_IsDone())
|
||
{
|
||
throw new Exception($this->GetErrorInfo(), $this->GetErrorCode());
|
||
}
|
||
|
||
$this->PDO_Commit();
|
||
}
|
||
catch (Exception $e)
|
||
{
|
||
$this->PDO_Rollback();
|
||
$outParam->SetErrors($e->getCode(), $e->getMessage());
|
||
return false;
|
||
}
|
||
|
||
|
||
$outParam->biz_content = array(
|
||
'state' => 0,
|
||
'amount' => $amount,
|
||
'playerid' => $playerID,
|
||
'playername' => '',
|
||
'playerbean' => 0,
|
||
);
|
||
return true;
|
||
|
||
}
|
||
|
||
|
||
} |