增加docke部署

This commit is contained in:
2026-04-10 16:44:13 +08:00
parent e2f8054794
commit cd4ddb606d
5076 changed files with 701092 additions and 0 deletions

View File

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