2120 lines
77 KiB
PHP
2120 lines
77 KiB
PHP
<?php
|
||
/**
|
||
* Created by PhpStorm.
|
||
* User: bahamut
|
||
* Date: 2018/3/14
|
||
* Time: 9:28
|
||
*/
|
||
|
||
|
||
require_once dirname(dirname(__DIR__)) . '/common/ErrorType.php';
|
||
require_once dirname(dirname(__DIR__)) . '/common/common.inc.php';
|
||
require_once dirname(dirname(__DIR__)) . '/common/BaseMethodHelper.php';
|
||
require_once dirname(dirname(__DIR__)) . '/public/usefull.php';
|
||
|
||
|
||
class finance extends BaseMethod
|
||
{
|
||
//truncate table ct_channel_account_period_pay_log;
|
||
//truncate table ct_channel_pay_log;
|
||
//update ct_channel_account_period set receivable = total, realincome = 0;
|
||
//update ct_channel_list set account = 0;
|
||
|
||
/* 清除账期数据
|
||
truncate table ct_channel_pay_log;
|
||
truncate table ct_channel_account_period_log;
|
||
truncate table ct_channel_account_period;
|
||
truncate table ct_channel_account_period_online;
|
||
truncate table ct_channel_account_period_pay_log;
|
||
truncate table ct_channel_account_period_online_pay_log;
|
||
update ct_channel_list set account = 0, account_online = 0;
|
||
*/
|
||
|
||
/**
|
||
* @note 生成账期数据
|
||
* 被请求方法示例:参数固定为RequestParameter和ReturnParameter对象,返回值固定为true(成功)和false(失败)
|
||
* @param RequestParameter $request
|
||
* @param ReturnParameter $return
|
||
* @return bool
|
||
*/
|
||
public function account_period_new($request, $return)
|
||
{
|
||
// http://localhost/game_proxy/trunk/api/index.php?method=finance.finance.account_period_new&format=json&charset=utf-8×tamp=1&version=1.0&biz_content={"agentid":"i33v0llvp0euhd1n9qo1fM2RV8vtog4y","channelid":"7N0e0z2u2098pf1M2fj0kyB1D4n4ylkA","accountperiod":"201801","freecard":"0","freegold":"0","pricecard":"1","pricegold":"1","loginid":"test"}&user_auth_token=xxxxxxxx&tag=tag&random_string=xxxxxx
|
||
$param = (array)$request->biz_content;
|
||
if (!is_array($param))
|
||
{
|
||
/// 参数格式错误
|
||
$return->SetErrors(ERRORCODE_INPARAMERROR, ERRORINFO_INPARAMERROR);
|
||
return false;
|
||
}
|
||
|
||
//{"agentid":"i33v0llvp0euhd1n9qo1fM2RV8vtog4y","channelid":"7N0e0z2u2098pf1M2fj0kyB1D4n4ylkA","accountperiod":"201801","freecard":"0","freegold":"0","pricecard":"1","pricegold":"1","loginid":"test"}
|
||
$agent_id = @$param['agentid']; /// 代理id
|
||
$channel_id = @$param['channelid']; /// 渠道id
|
||
$account_period = @$param['accountperiod']; /// 账期(yyyymm)
|
||
$account_period = str_replace('-', '',$account_period);
|
||
$free_card = floatval(@$param['freecard']); /// 免费、赠送房卡数
|
||
$free_gold = floatval(@$param['freegold']); /// 免费、赠送金币数
|
||
$price_card = floatval(@$param['pricecard']); /// 房卡单价
|
||
$price_gold = floatval(@$param['pricegold']); /// 金币单价
|
||
$login_id = @$param['loginid']; /// 登录账号
|
||
|
||
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($account_period))
|
||
{
|
||
$return->seterrors(ERRORCODE_ACCOUNTPERIODERROR, ERRORINFO_ACCOUNTPERIODERROR);
|
||
return false;
|
||
}
|
||
|
||
/// 判断所属账期是否已支付过
|
||
$cmd = /** @lang text */ <<<EOL
|
||
select
|
||
group_concat(b.order_id) order_list
|
||
from
|
||
ct_channel_account_period_pay_log a inner join ct_channel_pay_log b on a.pay_log_id = b.id
|
||
where
|
||
a.is_enable != 0 and b.is_enable != 0 and
|
||
a.agent_id = ? and a.channel_id = ? and a.account_period = ?
|
||
EOL;
|
||
$ret = $this->pdo_request($cmd, $agent_id, $channel_id, $account_period);
|
||
if (!$this->pdo_isdone())
|
||
{
|
||
$return->seterrors($this->geterrorcode(), $this->geterrorinfo() . '(' . __LINE__ . ')');
|
||
return false;
|
||
}
|
||
|
||
if (!empty($ret) && !empty($ret[0]['order_list']))
|
||
{
|
||
$return->seterrors(ERRORCODE_ACCOUNTPERIODEXISTS, sprintf(ERRORINFO_ACCOUNTPERIODEXISTS, $ret[0]['order_list']));
|
||
return false;
|
||
}
|
||
|
||
$this->pdo_begintransaction();
|
||
try
|
||
{
|
||
/// 尝试删除已存在的账期数据
|
||
$cmd = /** @lang text */'delete from ct_channel_account_period where agent_id = ? and channel_id = ? and account_period = ?';
|
||
$ret = $this->pdo_execute($cmd, $agent_id, $channel_id, $account_period);
|
||
if (!$ret)
|
||
throw new Exception($this->geterrorinfo() . '(' . __LINE__ . ')', $this->geterrorcode());
|
||
$cmd = /** @lang text */'delete from ct_channel_account_period_online where agent_id = ? and channel_id = ? and account_period = ?';
|
||
$ret = $this->pdo_execute($cmd, $agent_id, $channel_id, $account_period);
|
||
if (!$ret)
|
||
throw new Exception($this->geterrorinfo() . '(' . __LINE__ . ')', $this->geterrorcode());
|
||
|
||
$card = 0; /// 房卡数
|
||
$gold = 0; /// 金币数
|
||
|
||
/// 计算总计转出到代理的房卡数
|
||
$cmd = /** @lang text */<<<EOL
|
||
select
|
||
sum(a.satr_amount) amount
|
||
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) = 1 and
|
||
ifnull(c.statistic_type, 0) = 0 and
|
||
ifnull(b.saus_status, 1) = 0 and
|
||
a.satr_agentid = ? and
|
||
a.channel_id = ? and
|
||
date_format(a.satr_transfertime, '%Y%m') = ?
|
||
EOL;
|
||
$ret = $this->pdo_request($cmd, $agent_id, $channel_id, $account_period);
|
||
if (!$this->pdo_isdone())
|
||
throw new Exception($this->geterrorinfo() . '(' . __LINE__ . ')', $this->geterrorcode());
|
||
$card += floatval(@$ret[0]['amount']);
|
||
|
||
/// 计算总计转出到玩家的房卡数
|
||
$cmd = /** @lang text */<<<EOL
|
||
select
|
||
sum(a.sase_amount) amount
|
||
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
|
||
where
|
||
ifnull(b.statistic_type, 0) = 1 and
|
||
ifnull(c.statistic_type, 0) = 0 and
|
||
ifnull(b.saus_status, 1) = 0 and
|
||
a.sase_agentid = ? and
|
||
a.channel_id = ? and
|
||
date_format(a.sase_selltime, '%Y%m') = ?
|
||
EOL;
|
||
$ret = $this->pdo_request($cmd, $agent_id, $channel_id, $account_period);
|
||
if (!$this->pdo_isdone())
|
||
throw new Exception($this->geterrorinfo() . '(' . __LINE__ . ')', $this->geterrorcode());
|
||
$card += floatval(@$ret[0]['amount']);
|
||
|
||
/// 计算总计转出到代理的金币数
|
||
$cmd = /** @lang text */<<<EOL
|
||
select
|
||
sum(a.amount) amount
|
||
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) = 1 and
|
||
ifnull(c.statistic_type, 0) = 0 and
|
||
ifnull(b.saus_status, 1) = 0 and
|
||
a.agent_id = ? and
|
||
a.channel_id = ? and
|
||
date_format(a.op_time, '%Y%m') = ?
|
||
EOL;
|
||
$ret = $this->pdo_request($cmd, $agent_id, $channel_id, $account_period);
|
||
if (!$this->pdo_isdone())
|
||
throw new Exception($this->geterrorinfo() . '(' . __LINE__ . ')', $this->geterrorcode());
|
||
$gold += floatval(@$ret[0]['amount']);
|
||
|
||
/// 计算总计转出到玩家的金币数
|
||
$cmd = /** @lang text */<<<EOL
|
||
select
|
||
sum(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
|
||
where
|
||
ifnull(b.statistic_type, 0) = 1 and
|
||
ifnull(c.statistic_type, 0) = 0 and
|
||
ifnull(b.saus_status, 1) = 0 and
|
||
a.ssbe_agentid = ? and
|
||
a.channel_id = ? and
|
||
date_format(a.ssbe_selltime, '%Y%m') = ?
|
||
EOL;
|
||
$ret = $this->pdo_request($cmd, $agent_id, $channel_id, $account_period);
|
||
if (!$this->pdo_isdone())
|
||
throw new Exception($this->geterrorinfo() . '(' . __LINE__ . ')', $this->geterrorcode());
|
||
$gold += floatval(@$ret[0]['amount']);
|
||
|
||
/// 计算索要订单
|
||
$cmd = /** @lang text */<<<EOL
|
||
select
|
||
ifnull(sum(case when a.saab_type in (0, 1) then a.saab_amount else 0 end), 0) card,
|
||
ifnull(sum(case when a.saab_type in (2, 3) then a.saab_amount else 0 end), 0) gold
|
||
#sum(saus_roomcard) card,
|
||
#sum(saus_bean) gold
|
||
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
|
||
left join
|
||
sales_user c
|
||
on
|
||
a.saab_agentid = c.saus_agentid and a.channel_id = c.saus_channelid and (a.saab_type in (0, 2) and a.saab_askid = c.player_id or a.saab_type in (1, 3) and a.saab_askid = c.saus_salesid)
|
||
where
|
||
ifnull(b.statistic_type, 0) = 1 and
|
||
ifnull(c.statistic_type, 0) = 0 and
|
||
ifnull(b.saus_status, 1) = 0 and
|
||
a.saab_agentid = ? and
|
||
a.channel_id = ? and
|
||
date_format(a.saab_asktime, '%Y%m') = ?
|
||
EOL;
|
||
$ret = $this->pdo_request($cmd, $agent_id, $channel_id, $account_period);
|
||
if (!$this->pdo_isdone())
|
||
throw new Exception($this->geterrorinfo() . '(' . __LINE__ . ')', $this->geterrorcode());
|
||
$card += floatval($ret[0]['card']);
|
||
$gold += floatval($ret[0]['gold']);
|
||
|
||
if ($free_card > $card)
|
||
throw new Exception(sprintf(ERRORINFO_INVALIDCARDAMOUNT, $card, $free_card), ERRORCODE_INVALIDCARDAMOUNT);
|
||
|
||
if ($free_gold > $gold)
|
||
throw new Exception(sprintf(ERRORINFO_INVALIDGOLDAMOUNT, $gold, $free_gold), ERRORCODE_INVALIDGOLDAMOUNT);
|
||
|
||
/// 获取渠道分成数据
|
||
$cmd = /** @lang text */'select (1 - proportions) proportions from ct_channel_list where agent_id = ? and channel_id = ?';
|
||
$ret = $this->pdo_request($cmd, $agent_id, $channel_id);
|
||
if (!$this->pdo_isdone())
|
||
throw new Exception($this->geterrorinfo() . '(' . __LINE__ . ')', $this->geterrorcode());
|
||
elseif (empty($ret))
|
||
throw new Exception(ERRORINFO_AGENTNOTEXISTERROR, ERRORCODE_AGENTNOTEXISTERROR);
|
||
|
||
$proportions = $ret[0]['proportions']; /// 分成百分比
|
||
$total = (($card - $free_card) * $price_card) + (($gold - $free_gold) * $price_gold); /// 总数
|
||
|
||
/// 新增账期数据
|
||
$cmd = /** @lang text */<<<EOL
|
||
insert into
|
||
ct_channel_account_period(
|
||
agent_id, channel_id, account_period,
|
||
account_period_start_time, account_period_end_time,
|
||
total_card, total_gold, free_card, free_gold, price_card,
|
||
price_gold, total, realtotal, receivable, realincome,
|
||
last_pay_time, is_enable)
|
||
values(
|
||
?, ?, ?,
|
||
str_to_date(concat(?, '01000000'), '%Y%m%d%H%i%s'),
|
||
date_add(date_add(str_to_date(concat(?, '01235959'), '%Y%m%d%H%i%s'), interval 1 month), interval -1 day),
|
||
?, ?, ?, ?, ?,
|
||
?, ?, ?, ?, 0,
|
||
null, 1)
|
||
EOL;
|
||
$ret = $this->pdo_execute($cmd,
|
||
$agent_id, $channel_id, $account_period, $account_period, $account_period,
|
||
$card, $gold, $free_card, $free_gold, $price_card, $price_gold,
|
||
$total, $total * $proportions, $total * $proportions);
|
||
if (!$ret)
|
||
throw new Exception($this->geterrorinfo() . '(' . __LINE__ . ')', $this->geterrorcode());
|
||
|
||
$card = 0;
|
||
$gold = 0;
|
||
$total = 0;
|
||
|
||
// /// 在线购买的房卡
|
||
// $cmd = /** @lang text */<<<EOL
|
||
//select
|
||
// sum(sabu_amount) card_amount,
|
||
// sum(sabu_paymoney) card_money
|
||
//from
|
||
// sales_buybill
|
||
//where
|
||
// sabu_paystate = 1 and
|
||
// sabu_agentid = ? and
|
||
// sabu_channelid = ? and
|
||
// date_format(sabu_paytime, '%Y%m') = ?
|
||
//EOL;
|
||
// $ret = $this->pdo_request($cmd, $agent_id, $channel_id, $account_period);
|
||
// if (!$this->pdo_isdone())
|
||
// throw new Exception($this->geterrorinfo() . '(' . __LINE__ . ')', $this->geterrorcode());
|
||
// $card += $ret[0]['card_amount'];
|
||
// $total += $ret[0]['card_money'];
|
||
//
|
||
// /// 在线购买的金币
|
||
// $cmd = /** @lang text */<<<EOL
|
||
//select
|
||
// sum(star_amount) gold_amount,
|
||
// sum(pay_money) gold_money
|
||
//from
|
||
// order_star
|
||
//where
|
||
// `status` = 1 and
|
||
// agent_id = ? and
|
||
// channel_id = ? and
|
||
// date_format(pay_time, '%Y%m') = ?
|
||
//EOL;
|
||
// $ret = $this->pdo_request($cmd, $agent_id, $channel_id, $account_period);
|
||
// if (!$this->pdo_isdone())
|
||
// throw new Exception($this->geterrorinfo() . '(' . __LINE__ . ')', $this->geterrorcode());
|
||
// $gold += $ret[0]['gold_amount'];
|
||
// $total += $ret[0]['gold_money'];
|
||
|
||
/// 购买的房卡和金币数
|
||
$cmd = /** @lang text */<<<EOL
|
||
select
|
||
sum(case product_type when 0 then product_amount else 0 end) card_amount, -- 总售房卡数
|
||
sum(case product_type when 0 then pay_money else 0 end) card_money, -- 总售房卡金额
|
||
sum(case product_type when 1 then product_amount else 0 end) gold_amount, -- 总售金币数
|
||
sum(case product_type when 1 then pay_money else 0 end) gold_money, -- 总售金币金额
|
||
sum(case product_type when 2 then product_amount else 0 end) diamond_amount, -- 总售钻石数
|
||
sum(case product_type when 2 then pay_money else 0 end) diamond_money -- 总售钻石金额
|
||
from
|
||
ct_order_info
|
||
where
|
||
pay_status = 1 and
|
||
agent_id = ? and
|
||
channel_id = ? and
|
||
date_format(from_unixtime(pay_time), '%Y%m') = ?
|
||
EOL;
|
||
$ret = $this->pdo_request($cmd, $agent_id, $channel_id, $account_period);
|
||
if (!$this->pdo_isdone())
|
||
throw new Exception($this->geterrorinfo() . '(' . __LINE__ . ')', $this->geterrorcode());
|
||
$card += $ret[0]['card_amount'];
|
||
$total += $ret[0]['card_money'];
|
||
$gold += $ret[0]['gold_amount'];
|
||
$total += $ret[0]['gold_money'];
|
||
|
||
/// 第三方代付的房卡和金币
|
||
$cmd = /** @lang text */<<<EOL
|
||
select
|
||
sum(case type when 1 then amount else 0 end) card_amount,
|
||
sum(case type when 2 then amount else 0 end) gold_amount,
|
||
sum(case type when 1 then fee else 0 end) card_money,
|
||
sum(case type when 2 then fee else 0 end) gold_money
|
||
from
|
||
ct_pay_for_third
|
||
where
|
||
agent_id = ? and channel_id = ? and date_format(create_time, '%Y%m') = ?
|
||
EOL;
|
||
$ret = $this->pdo_request($cmd, $agent_id, $channel_id, $account_period);
|
||
if (!$this->pdo_isdone())
|
||
throw new Exception($this->geterrorinfo() . '(' . __LINE__ . ')', $this->geterrorcode());
|
||
$card += $ret[0]['card_amount'];
|
||
$total += $ret[0]['card_money'];
|
||
$gold += $ret[0]['gold_amount'];
|
||
$total += $ret[0]['gold_money'];
|
||
|
||
/// 新增账期数据(在线支付)
|
||
$cmd = /** @lang text */<<<EOL
|
||
insert into
|
||
ct_channel_account_period_online(
|
||
agent_id, channel_id, account_period,
|
||
account_period_start_time, account_period_end_time,
|
||
total_card, total_gold,
|
||
total, realtotal, receivable, realincome,
|
||
last_pay_time, is_enable)
|
||
values(
|
||
?, ?, ?,
|
||
str_to_date(concat(?, '01000000'), '%Y%m%d%H%i%s'),
|
||
date_add(date_add(str_to_date(concat(?, '01235959'), '%Y%m%d%H%i%s'), interval 1 month), interval -1 day),
|
||
?, ?,
|
||
?, ?, ?, 0,
|
||
null, 1)
|
||
EOL;
|
||
$ret = $this->pdo_execute($cmd,
|
||
$agent_id, $channel_id, $account_period, $account_period, $account_period,
|
||
$card, $gold,
|
||
$total, $total * $proportions, $total * $proportions);
|
||
if (!$ret)
|
||
throw new Exception($this->geterrorinfo() . '(' . __LINE__ . ')', $this->geterrorcode());
|
||
|
||
/// 保存操作流水
|
||
$cmd = /** @lang text */<<<EOL
|
||
insert into
|
||
ct_channel_account_period_log(agent_id, channel_id, account_period, free_card, free_gold, price_card, price_gold, user_id, create_time)
|
||
values
|
||
(?, ?, ?, ?, ?, ?, ?, ?, now())
|
||
EOL;
|
||
$ret = $this->pdo_execute($cmd, $agent_id, $channel_id, $account_period, $free_card, $free_gold, $price_card, $price_gold, $login_id);
|
||
if (!$ret)
|
||
throw new Exception($this->geterrorinfo() . '(' . __LINE__ . ')', $this->geterrorcode());
|
||
|
||
$this->pdo_commit();
|
||
}
|
||
catch (Exception $Exception)
|
||
{
|
||
$this->pdo_rollback();
|
||
$return->seterrors($Exception->getcode(), $Exception->getmessage());
|
||
return false;
|
||
}
|
||
|
||
return true;
|
||
}
|
||
|
||
|
||
/**
|
||
* @note 渠道付款
|
||
* 被请求方法示例:参数固定为RequestParameter和ReturnParameter对象,返回值固定为true(成功)和false(失败)
|
||
* @param RequestParameter $request
|
||
* @param ReturnParameter $return
|
||
* @return bool
|
||
*/
|
||
public function account_period_pay($request, $return)
|
||
{
|
||
// http://localhost/game_proxy/trunk/api/index.php?method=finance.finance.account_period_pay&format=json&charset=utf-8×tamp=1&version=1.0&biz_content={"agentid":"i33v0llvp0euhd1n9qo1fM2RV8vtog4y","channelid":"7N0e0z2u2098pf1M2fj0kyB1D4n4ylkA","fee":"100","fee_online":"10","loginid":"test","accountperiod":"201803"}&user_auth_token=xxxxxxxx&tag=tag&random_string=xxxxxx
|
||
$param = (array)$request->biz_content;
|
||
if (!is_array($param))
|
||
{
|
||
/// 参数格式错误
|
||
$return->SetErrors(ERRORCODE_INPARAMERROR, ERRORINFO_INPARAMERROR);
|
||
return false;
|
||
}
|
||
|
||
$agent_id = @$param['agentid']; /// 代理id
|
||
$channel_id = @$param['channelid']; /// 渠道id
|
||
$fee = floatval(@$param['fee']); /// 金额(渠道转款)
|
||
$fee_online = floatval(@$param['fee_online']); /// 支付金额(线上支付,公众号等)
|
||
$login_id = @$param['loginid']; /// 登录账号
|
||
$account_period = @$param['accountperiod']; /// 账期(yyyymm)
|
||
|
||
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 ($fee < 0 || $fee_online < 0)
|
||
{
|
||
$return->seterrors(ERRORCODE_MONEYERROR, ERRORINFO_MONEYERROR);
|
||
return false;
|
||
}
|
||
|
||
if (empty($account_period))
|
||
$account_period = date('Ym');
|
||
else
|
||
$account_period = str_replace('-', '', $account_period);
|
||
|
||
$this->pdo_begintransaction();
|
||
try
|
||
{
|
||
/// 获取当前账户余额
|
||
$cmd = /** @lang text */'select account, account_online from ct_channel_list where agent_id = ? and channel_id = ?';
|
||
$ret = $this->pdo_request($cmd, $agent_id, $channel_id);
|
||
if (!$this->pdo_isdone())
|
||
throw new Exception($this->geterrorinfo() . '(' . __LINE__ . ')', $this->geterrorcode());
|
||
elseif (empty($ret))
|
||
throw new Exception(ERRORINFO_AGENTNOTEXISTERROR, ERRORCODE_AGENTNOTEXISTERROR);
|
||
|
||
$account = floatval($ret[0]['account']);
|
||
$account_online = floatval($ret[0]['account_online']);
|
||
|
||
$total = $account + $fee; /// 转账的总金额
|
||
$total_online = $account_online + $fee_online; /// 在线支付的总金额
|
||
|
||
/// 创建支付订单号
|
||
do {
|
||
$order_id = date('YmdHis') . rand(100000, 999999);
|
||
$cmd = /** @lang text */'select 1 from ct_channel_pay_log where order_id = ?';
|
||
$ret = $this->pdo_request($cmd, $order_id);
|
||
if (!$this->pdo_isdone())
|
||
throw new Exception($this->geterrorinfo() . '(' . __LINE__ . ')', $this->geterrorcode());
|
||
elseif (empty($ret))
|
||
break;
|
||
} while (1);
|
||
|
||
/// 新增支付流水记录
|
||
$cmd = /** @lang text */<<<EOL
|
||
insert into
|
||
ct_channel_pay_log
|
||
(
|
||
order_id, agent_id, channel_id, account_period, pay_time,
|
||
pay_fee, pay_fee_online, pay_user, account_before, account_after,
|
||
account_online_before, account_online_after, cancel_time, remark, is_enable
|
||
)
|
||
values
|
||
(
|
||
?, ?, ?, ?, now(),
|
||
?, ?, ?, ?, ?,
|
||
?, ?, null, null, 1)
|
||
EOL;
|
||
$ret = $this->pdo_execute($cmd, $order_id, $agent_id, $channel_id, $account_period, $fee, $fee_online, $login_id, $account, $total, $account_online, $total_online);
|
||
if (!$ret)
|
||
throw new Exception($this->geterrorinfo() . '(' . __LINE__ . ')', $this->geterrorcode());
|
||
|
||
$pay_log_id = $this->pdo_lastinsertid(); /// 支付流水id
|
||
|
||
/// ========================================================================================================
|
||
|
||
/// 转房卡、金币的支付情况
|
||
$base = /** @lang text */<<<EOL
|
||
select
|
||
a.id, -- id
|
||
a.agent_id, -- 代理id
|
||
a.channel_id, -- 渠道id
|
||
a.account_period, -- 账期
|
||
a.receivable, -- 账期应付
|
||
if(@line > 0, @realpay := 0.0000, @realpay := {$fee} * 1.0000) realpay, -- 本期实际付款
|
||
if(@line > 0, @carryover := 0.0000, @carryover := {$account} * 1.0000) carryover, -- 上期结转余额
|
||
@total_fee - @pay_count total_fee, -- 累计付款额(本期实付 + 上期结转)
|
||
if (a.receivable + @pay_count < @total_fee, @pay_fee := a.receivable, @pay_fee := @total_fee - @pay_count) pay_fee, -- 本期实际冲抵额
|
||
if (a.receivable + @pay_count < @total_fee, @pay_count := @pay_count + a.receivable, @pay_count := @total_fee) pay_count, -- 累计冲抵额
|
||
a.receivable - @pay_fee pay_receivable, -- 还应支付余额
|
||
@total_fee - @pay_count pay_surplus, -- 支付后剩余的可用金额
|
||
@line := @line + 1 rownum -- 行号
|
||
from
|
||
(select id, agent_id, channel_id, account_period, receivable from ct_channel_account_period where receivable > 0 order by account_period) a,
|
||
(select @pay_fee := 0.0000) b,
|
||
(select @pay_count := 0.0000) c,
|
||
(select @total_fee := {$total} * 1.0000) d,
|
||
(select @line := 0.0000) e
|
||
where
|
||
a.agent_id = ? and a.channel_id = ?
|
||
EOL;
|
||
|
||
/// 判断是否存在需要冲抵的账目
|
||
$cmd = $base;
|
||
$ret = $this->pdo_request($cmd, $agent_id, $channel_id);
|
||
if (!$this->pdo_isdone())
|
||
throw new Exception($this->geterrorinfo() . '(' . __LINE__ . ')', $this->geterrorcode());
|
||
elseif (!empty($ret)) /// 存在需要冲抵的账目
|
||
{
|
||
/// 最后的账户余额
|
||
$last_account = $ret[count($ret) - 1]['pay_surplus'];
|
||
|
||
/// 新增渠道帐期支付流水
|
||
$cmd = /** @lang text */<<<EOL
|
||
insert into
|
||
ct_channel_account_period_pay_log(pay_log_id, agent_id, channel_id, account_period, receivable, realincome, realpay, carryover, total, surplus, pay_time, is_enable)
|
||
select
|
||
{$pay_log_id}, agent_id, channel_id, account_period, receivable, pay_fee, realpay, carryover, total_fee, pay_surplus, now(), 1
|
||
from
|
||
(
|
||
{$base}
|
||
) t
|
||
where
|
||
pay_fee > 0
|
||
EOL;
|
||
$ret = $this->pdo_execute($cmd, $agent_id, $channel_id);
|
||
if (!$ret)
|
||
throw new Exception($this->geterrorinfo() . '(' . __LINE__ . ')', $this->geterrorcode());
|
||
|
||
/// 修改账期数据
|
||
$cmd = /** @lang text */<<<EOL
|
||
update
|
||
ct_channel_account_period a,
|
||
(
|
||
{$base}
|
||
) b
|
||
set
|
||
a.receivable = b.pay_receivable,
|
||
a.realincome = a.realincome + pay_fee,
|
||
a.last_pay_time = now()
|
||
where
|
||
a.id = b.id
|
||
EOL;
|
||
$ret = $this->pdo_execute($cmd, $agent_id, $channel_id);
|
||
if (!$ret)
|
||
throw new Exception($this->geterrorinfo() . '(' . __LINE__ . ')', $this->geterrorcode());
|
||
|
||
/// 更新账户余额
|
||
$cmd = /** @lang text */'update ct_channel_list set account = ? where agent_id = ? and channel_id = ?';
|
||
$ret = $this->pdo_execute($cmd, $last_account, $agent_id, $channel_id);
|
||
if (!$ret)
|
||
throw new Exception($this->geterrorinfo() . '(' . __LINE__ . ')', $this->geterrorcode());
|
||
|
||
/// 更新支付流水信息里的支付后账户余额
|
||
$cmd = /** @lang text */'update ct_channel_pay_log set account_after = ? where id = ?';
|
||
$ret = $this->pdo_execute($cmd, $last_account, $pay_log_id);
|
||
if (!$ret)
|
||
throw new Exception($this->geterrorinfo() . '(' . __LINE__ . ')', $this->geterrorcode());
|
||
}
|
||
else /// 不存在需要冲抵的账目
|
||
{
|
||
/// 最后的账户余额
|
||
$last_account = $total;
|
||
|
||
/// 更新账户余额
|
||
$cmd = /** @lang text */'update ct_channel_list set account = ? where agent_id = ? and channel_id = ?';
|
||
$ret = $this->pdo_execute($cmd, $last_account, $agent_id, $channel_id);
|
||
if (!$ret)
|
||
throw new Exception($this->geterrorinfo() . '(' . __LINE__ . ')', $this->geterrorcode());
|
||
}
|
||
|
||
/// ========================================================================================================
|
||
|
||
/// 购买房卡、金币的支付情况
|
||
$base = /** @lang text */<<<EOL
|
||
select
|
||
a.id, -- id
|
||
a.agent_id, -- 代理id
|
||
a.channel_id, -- 渠道id
|
||
a.account_period, -- 账期
|
||
a.receivable, -- 账期应付
|
||
if(@line > 0, @realpay := 0.0000, @realpay := {$fee_online} * 1.0000) realpay, -- 本期实际付款
|
||
if(@line > 0, @carryover := 0.0000, @carryover := {$account_online} * 1.0000) carryover, -- 上期结转余额
|
||
@total_fee - @pay_count total_fee, -- 累计付款额(本期实付 + 上期结转)
|
||
if (a.receivable + @pay_count < @total_fee, @pay_fee := a.receivable, @pay_fee := @total_fee - @pay_count) pay_fee, -- 本期实际冲抵额
|
||
if (a.receivable + @pay_count < @total_fee, @pay_count := @pay_count + a.receivable, @pay_count := @total_fee) pay_count, -- 累计冲抵额
|
||
a.receivable - @pay_fee pay_receivable, -- 还应支付余额
|
||
@total_fee - @pay_count pay_surplus, -- 支付后剩余的可用金额
|
||
@line := @line + 1 rownum -- 行号
|
||
from
|
||
(select id, agent_id, channel_id, account_period, receivable from ct_channel_account_period_online where receivable > 0 order by account_period) a,
|
||
(select @pay_fee := 0.0000) b,
|
||
(select @pay_count := 0.0000) c,
|
||
(select @total_fee := {$total_online} * 1.0000) d,
|
||
(select @line := 0.0000) e
|
||
where
|
||
a.agent_id = ? and a.channel_id = ?
|
||
EOL;
|
||
|
||
/// 判断是否存在需要冲抵的账目
|
||
$cmd = $base;
|
||
$ret = $this->pdo_request($cmd, $agent_id, $channel_id);
|
||
if (!$this->pdo_isdone())
|
||
throw new Exception($this->geterrorinfo() . '(' . __LINE__ . ')', $this->geterrorcode());
|
||
elseif (!empty($ret)) /// 存在需要冲抵的账目
|
||
{
|
||
/// 最后的账户余额
|
||
$last_account = $ret[count($ret) - 1]['pay_surplus'];
|
||
|
||
/// 新增渠道帐期支付流水
|
||
$cmd = /** @lang text */<<<EOL
|
||
insert into
|
||
ct_channel_account_period_online_pay_log(pay_log_id, agent_id, channel_id, account_period, receivable, realincome, realpay, carryover, total, surplus, pay_time, is_enable)
|
||
select
|
||
{$pay_log_id}, agent_id, channel_id, account_period, receivable, pay_fee, realpay, carryover, total_fee, pay_surplus, now(), 1
|
||
from
|
||
(
|
||
{$base}
|
||
) t
|
||
where
|
||
pay_fee > 0
|
||
EOL;
|
||
$ret = $this->pdo_execute($cmd, $agent_id, $channel_id);
|
||
if (!$ret)
|
||
throw new Exception($this->geterrorinfo() . '(' . __LINE__ . ')', $this->geterrorcode());
|
||
|
||
/// 修改账期数据
|
||
$cmd = /** @lang text */<<<EOL
|
||
update
|
||
ct_channel_account_period_online a,
|
||
(
|
||
{$base}
|
||
) b
|
||
set
|
||
a.receivable = b.pay_receivable,
|
||
a.realincome = a.realincome + pay_fee,
|
||
a.last_pay_time = now()
|
||
where
|
||
a.id = b.id
|
||
EOL;
|
||
$ret = $this->pdo_execute($cmd, $agent_id, $channel_id);
|
||
if (!$ret)
|
||
throw new Exception($this->geterrorinfo() . '(' . __LINE__ . ')', $this->geterrorcode());
|
||
|
||
/// 更新账户余额
|
||
$cmd = /** @lang text */'update ct_channel_list set account_online = ? where agent_id = ? and channel_id = ?';
|
||
$ret = $this->pdo_execute($cmd, $last_account, $agent_id, $channel_id);
|
||
if (!$ret)
|
||
throw new Exception($this->geterrorinfo() . '(' . __LINE__ . ')', $this->geterrorcode());
|
||
|
||
/// 更新支付流水信息里的支付后账户余额
|
||
$cmd = /** @lang text */'update ct_channel_pay_log set account_online_after = ? where id = ?';
|
||
$ret = $this->pdo_execute($cmd, $last_account, $pay_log_id);
|
||
if (!$ret)
|
||
throw new Exception($this->geterrorinfo() . '(' . __LINE__ . ')', $this->geterrorcode());
|
||
}
|
||
else /// 不存在需要冲抵的账目
|
||
{
|
||
/// 最后的账户余额
|
||
$last_account = $total;
|
||
|
||
/// 更新账户余额
|
||
$cmd = /** @lang text */'update ct_channel_list set account_online = ? where agent_id = ? and channel_id = ?';
|
||
$ret = $this->pdo_execute($cmd, $last_account, $agent_id, $channel_id);
|
||
if (!$ret)
|
||
throw new Exception($this->geterrorinfo() . '(' . __LINE__ . ')', $this->geterrorcode());
|
||
}
|
||
|
||
$this->pdo_commit();
|
||
}
|
||
catch (Exception $Exception)
|
||
{
|
||
$this->pdo_rollback();
|
||
$return->seterrors($Exception->getcode(), $Exception->getmessage());
|
||
return false;
|
||
}
|
||
|
||
$return->biz_content = array('orderid' => $order_id);
|
||
return true;
|
||
}
|
||
|
||
/**
|
||
* @note 渠道付款记录
|
||
* 被请求方法示例:参数固定为RequestParameter和ReturnParameter对象,返回值固定为true(成功)和false(失败)
|
||
* @param RequestParameter $request
|
||
* @param ReturnParameter $return
|
||
* @return bool
|
||
*/
|
||
public function account_period_pay_record($request, $return)
|
||
{
|
||
$params = $request->biz_content;
|
||
// 查看那一页
|
||
$page = isset($params['page']) ? intval($params['page']) : 1;
|
||
// 分页多少条
|
||
$limit = isset($params['limit']) ? intval($params['limit']) : 10;
|
||
$limit_index = ($page - 1) * $limit;
|
||
|
||
$sql = <<<EOL
|
||
select
|
||
a.id 编号,
|
||
b.nickname 渠道,
|
||
a.pay_fee 金额,
|
||
a.pay_fee_online 支付金额,
|
||
a.account_before 支付前帐户余额,
|
||
a.account_after 支付后帐户余额,
|
||
a.account_period 账期,
|
||
a.pay_time 添加时间
|
||
from
|
||
ct_channel_pay_log a
|
||
left join
|
||
ct_channel_list b
|
||
on
|
||
a.agent_id = b.agent_id and a.channel_id = b.channel_id
|
||
where
|
||
a.is_enable = 1
|
||
order by
|
||
a.id desc
|
||
limit ?, ?
|
||
EOL;
|
||
|
||
$items = $this->pdo_request($sql, $limit_index, $limit);
|
||
if (!$this->pdo_isdone()) {
|
||
$return->seterrors($this->geterrorcode(), $this->geterrorinfo() . '(' . __LINE__ . ')');
|
||
return false;
|
||
}
|
||
|
||
$data = [];
|
||
if(is_array($items) && isset($items[0])) {
|
||
$data['title'] = array_keys($items[0]);
|
||
foreach ($items as $k => $v) {
|
||
foreach ($v as $q) {
|
||
$data['data'][$k][] = $q;
|
||
}
|
||
}
|
||
}
|
||
|
||
// 5、数据返回部分
|
||
$return->biz_content = $data;
|
||
|
||
return true;
|
||
}
|
||
|
||
/**
|
||
* @note 撤销渠道付款
|
||
* 被请求方法示例:参数固定为RequestParameter和ReturnParameter对象,返回值固定为true(成功)和false(失败)
|
||
* @param RequestParameter $request
|
||
* @param ReturnParameter $return
|
||
* @return bool
|
||
*/
|
||
public function account_period_cancel($request, $return)
|
||
{
|
||
// http://localhost/game_proxy/trunk/api/index.php?method=finance.finance.account_period_cancel&format=json&charset=utf-8×tamp=1&version=1.0&biz_content={"agentid":"i33v0llvp0euhd1n9qo1fM2RV8vtog4y","channelid":"7N0e0z2u2098pf1M2fj0kyB1D4n4ylkA","orderid":"20180330113523646817","loginid":"test"}&user_auth_token=xxxxxxxx&tag=tag&random_string=xxxxxx
|
||
$param = (array)$request->biz_content;
|
||
if (!is_array($param))
|
||
{
|
||
/// 参数格式错误
|
||
$return->SetErrors(ERRORCODE_INPARAMERROR, ERRORINFO_INPARAMERROR);
|
||
return false;
|
||
}
|
||
|
||
$agent_id = @$param['agentid']; /// 代理id
|
||
$channel_id = @$param['channelid']; /// 渠道id
|
||
$order_id = @$param['orderid']; /// 支付订单号
|
||
$remark = @$param['remark']; /// 备注
|
||
$login_id = @$param['loginid']; /// 登录账号
|
||
|
||
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($order_id))
|
||
{
|
||
$return->seterrors(ERRORCODE_ORDERIDERROR, ERRORINFO_ORDERIDERROR);
|
||
return false;
|
||
}
|
||
|
||
$this->pdo_begintransaction();
|
||
try
|
||
{
|
||
/// 校验订单信息
|
||
$cmd = /** @lang text */'select id from ct_channel_pay_log where agent_id = ? and channel_id = ? and order_id = ? and is_enable != 0';
|
||
$ret = $this->pdo_request($cmd, $agent_id, $channel_id, $order_id);
|
||
if (!$this->pdo_isdone())
|
||
throw new Exception($this->geterrorinfo() . '(' . __LINE__ . ')', $this->geterrorcode());
|
||
elseif (empty($ret))
|
||
throw new Exception(ERRORINFO_INVALIDFINANCEORDER, ERRORCODE_INVALIDFINANCEORDER);
|
||
|
||
/// 判断必须是最后一个有效订单
|
||
$pay_log_id = $ret[0]['id'];
|
||
$cmd = /** @lang text */'select group_concat(order_id) order_id from ct_channel_pay_log where is_enable != 0 and id > ?';
|
||
$ret = $this->pdo_request($cmd, $pay_log_id);
|
||
if (!$this->pdo_isdone())
|
||
throw new Exception($this->geterrorinfo() . '(' . __LINE__ . ')', $this->geterrorcode());
|
||
elseif (!empty($ret) && !empty($ret[0]['order_id']))
|
||
throw new Exception(sprintf(ERRORINFO_FINANCEORDERISNOTLAST, $ret[0]['order_id']), ERRORCODE_FINANCEORDERISNOTLAST);
|
||
|
||
/// 还原账期数据
|
||
$cmd = /** @lang text */<<<EOL
|
||
update
|
||
ct_channel_account_period a,
|
||
ct_channel_account_period_pay_log b
|
||
set
|
||
a.receivable = b.receivable,
|
||
a.realincome = a.realincome - b.realincome
|
||
where
|
||
a.agent_id = b.agent_id and
|
||
a.channel_id = b.channel_id and
|
||
a.account_period = b.account_period and
|
||
b.pay_log_id = ?
|
||
EOL;
|
||
$ret = $this->pdo_execute($cmd, $pay_log_id);
|
||
if (!$ret)
|
||
throw new Exception($this->geterrorinfo() . '(' . __LINE__ . ')', $this->geterrorcode());
|
||
|
||
$cmd = /** @lang text */<<<EOL
|
||
update
|
||
ct_channel_account_period_online a,
|
||
ct_channel_account_period_online_pay_log b
|
||
set
|
||
a.receivable = b.receivable,
|
||
a.realincome = a.realincome - b.realincome
|
||
where
|
||
a.agent_id = b.agent_id and
|
||
a.channel_id = b.channel_id and
|
||
a.account_period = b.account_period and
|
||
b.pay_log_id = ?
|
||
EOL;
|
||
$ret = $this->pdo_execute($cmd, $pay_log_id);
|
||
if (!$ret)
|
||
throw new Exception($this->geterrorinfo() . '(' . __LINE__ . ')', $this->geterrorcode());
|
||
|
||
/// 还原账户数据
|
||
$cmd = /** @lang text */<<<EOL
|
||
update
|
||
ct_channel_list a,
|
||
ct_channel_pay_log b
|
||
set
|
||
a.account = b.account_before,
|
||
a.account_online = b.account_online_before
|
||
where
|
||
a.agent_id = b.agent_id and
|
||
a.channel_id = b.channel_id and
|
||
b.id = ?
|
||
EOL;
|
||
$ret = $this->pdo_execute($cmd, $pay_log_id);
|
||
if (!$ret)
|
||
throw new Exception($this->geterrorinfo() . '(' . __LINE__ . ')', $this->geterrorcode());
|
||
|
||
/// 修改支付流水
|
||
$cmd = /** @lang text */'update ct_channel_pay_log set remark = ?, cancel_time = now(), cancel_user = ?, is_enable = 0 where id = ?';
|
||
$ret = $this->pdo_execute($cmd, $remark, $login_id, $pay_log_id);
|
||
if (!$ret)
|
||
throw new Exception($this->geterrorinfo() . '(' . __LINE__ . ')', $this->geterrorcode());
|
||
|
||
$cmd = /** @lang text */'update ct_channel_account_period_pay_log set is_enable = 0 where pay_log_id = ?';
|
||
$ret = $this->pdo_execute($cmd, $pay_log_id);
|
||
if (!$ret)
|
||
throw new Exception($this->geterrorinfo() . '(' . __LINE__ . ')', $this->geterrorcode());
|
||
|
||
$cmd = /** @lang text */'update ct_channel_account_period_online_pay_log set is_enable = 0 where pay_log_id = ?';
|
||
$ret = $this->pdo_execute($cmd, $pay_log_id);
|
||
if (!$ret)
|
||
throw new Exception($this->geterrorinfo() . '(' . __LINE__ . ')', $this->geterrorcode());
|
||
|
||
$this->pdo_commit();
|
||
}
|
||
catch (Exception $Exception)
|
||
{
|
||
$this->pdo_rollback();
|
||
$return->seterrors($Exception->getcode(), $Exception->getmessage());
|
||
return false;
|
||
}
|
||
|
||
$return->biz_content = array('orderid' => $order_id);
|
||
return true;
|
||
}
|
||
|
||
|
||
/**
|
||
* @note 获取渠道应收账款报表
|
||
* 被请求方法示例:参数固定为RequestParameter和ReturnParameter对象,返回值固定为true(成功)和false(失败)
|
||
* @param RequestParameter $request
|
||
* @param ReturnParameter $return
|
||
* @return bool
|
||
*/
|
||
public function query_channel_receivables_report($request, $return)
|
||
{
|
||
// http://localhost/game_proxy/trunk/api/index.php?method=finance.finance.query_channel_receivables_report&format=json&charset=utf-8×tamp=1&version=1.0&biz_content={"agentid":"i33v0llvp0euhd1n9qo1fM2RV8vtog4y","channelid":"7N0e0z2u2098pf1M2fj0kyB1D4n4ylkA","year":"2018"}&user_auth_token=xxxxxxxx&tag=tag&random_string=xxxxxx
|
||
$param = (array)$request->biz_content;
|
||
if (!is_array($param))
|
||
{
|
||
/// 参数格式错误
|
||
$return->SetErrors(ERRORCODE_INPARAMERROR, ERRORINFO_INPARAMERROR);
|
||
return false;
|
||
}
|
||
|
||
$agent_id = @$param['agentid']; /// 代理id
|
||
$channel_id = @$param['channelid']; /// 渠道id
|
||
$year = intval(@$param['year']); /// 获取账期年份
|
||
$type = intval(@$param['type']); /// 类型(1:转账记录;2:支付记录)
|
||
|
||
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($year))
|
||
{
|
||
$return->seterrors(ERRORCODE_FINANCEYEARERROR, ERRORINFO_FINANCEYEARERROR);
|
||
return false;
|
||
}
|
||
|
||
if (1 == $type)
|
||
$cmd = /** @lang text */<<<EOL
|
||
select
|
||
#a.agent_id,
|
||
#a.channel_id,
|
||
a.nickname `渠道`,
|
||
a.account_period `账期`,
|
||
cast(ifnull(b.realpay, 0) as decimal(18, 2)) `本期实付金额`,
|
||
cast(ifnull(b.carryover, 0) as decimal(18, 2)) `上期结转余额`,
|
||
cast(ifnull(b.realincome, 0) as decimal(18, 2)) `实际抵扣`,
|
||
cast(ifnull(b.realpay, 0) + ifnull(b.carryover, 0) - ifnull(b.realincome, 0) as decimal(18, 2)) `余额`,
|
||
cast(if(a.account_period < '{$year}01', 0, a.`{$year}01` - ifnull(b.`{$year}01`, 0)) as decimal(18, 2)) `{$year}01`,
|
||
cast(if(a.account_period < '{$year}02', 0, a.`{$year}02` - ifnull(b.`{$year}02`, 0)) as decimal(18, 2)) `{$year}02`,
|
||
cast(if(a.account_period < '{$year}03', 0, a.`{$year}03` - ifnull(b.`{$year}03`, 0)) as decimal(18, 2)) `{$year}03`,
|
||
cast(if(a.account_period < '{$year}04', 0, a.`{$year}04` - ifnull(b.`{$year}04`, 0)) as decimal(18, 2)) `{$year}04`,
|
||
cast(if(a.account_period < '{$year}05', 0, a.`{$year}05` - ifnull(b.`{$year}05`, 0)) as decimal(18, 2)) `{$year}05`,
|
||
cast(if(a.account_period < '{$year}06', 0, a.`{$year}06` - ifnull(b.`{$year}06`, 0)) as decimal(18, 2)) `{$year}06`,
|
||
cast(if(a.account_period < '{$year}07', 0, a.`{$year}07` - ifnull(b.`{$year}07`, 0)) as decimal(18, 2)) `{$year}07`,
|
||
cast(if(a.account_period < '{$year}08', 0, a.`{$year}08` - ifnull(b.`{$year}08`, 0)) as decimal(18, 2)) `{$year}08`,
|
||
cast(if(a.account_period < '{$year}09', 0, a.`{$year}09` - ifnull(b.`{$year}09`, 0)) as decimal(18, 2)) `{$year}09`,
|
||
cast(if(a.account_period < '{$year}10', 0, a.`{$year}10` - ifnull(b.`{$year}10`, 0)) as decimal(18, 2)) `{$year}10`,
|
||
cast(if(a.account_period < '{$year}11', 0, a.`{$year}11` - ifnull(b.`{$year}11`, 0)) as decimal(18, 2)) `{$year}11`,
|
||
cast(if(a.account_period < '{$year}12', 0, a.`{$year}12` - ifnull(b.`{$year}12`, 0)) as decimal(18, 2)) `{$year}12`
|
||
from
|
||
(
|
||
select
|
||
b.agent_id,
|
||
b.channel_id,
|
||
b.nickname,
|
||
a.account_period,
|
||
b.`{$year}01`,
|
||
b.`{$year}02`,
|
||
b.`{$year}03`,
|
||
b.`{$year}04`,
|
||
b.`{$year}05`,
|
||
b.`{$year}06`,
|
||
b.`{$year}07`,
|
||
b.`{$year}08`,
|
||
b.`{$year}09`,
|
||
b.`{$year}10`,
|
||
b.`{$year}11`,
|
||
b.`{$year}12`
|
||
from
|
||
(
|
||
select distinct account_period from ct_channel_account_period where substr(account_period, 1, 4) = {$year}
|
||
) a,
|
||
(
|
||
select
|
||
a.agent_id,
|
||
a.channel_id,
|
||
b.nickname,
|
||
sum(case a.account_period when '{$year}01' then a.realtotal else 0 end) `{$year}01`,
|
||
sum(case a.account_period when '{$year}02' then a.realtotal else 0 end) `{$year}02`,
|
||
sum(case a.account_period when '{$year}03' then a.realtotal else 0 end) `{$year}03`,
|
||
sum(case a.account_period when '{$year}04' then a.realtotal else 0 end) `{$year}04`,
|
||
sum(case a.account_period when '{$year}05' then a.realtotal else 0 end) `{$year}05`,
|
||
sum(case a.account_period when '{$year}06' then a.realtotal else 0 end) `{$year}06`,
|
||
sum(case a.account_period when '{$year}07' then a.realtotal else 0 end) `{$year}07`,
|
||
sum(case a.account_period when '{$year}08' then a.realtotal else 0 end) `{$year}08`,
|
||
sum(case a.account_period when '{$year}09' then a.realtotal else 0 end) `{$year}09`,
|
||
sum(case a.account_period when '{$year}10' then a.realtotal else 0 end) `{$year}10`,
|
||
sum(case a.account_period when '{$year}11' then a.realtotal else 0 end) `{$year}11`,
|
||
sum(case a.account_period when '{$year}12' then a.realtotal else 0 end) `{$year}12`
|
||
from
|
||
ct_channel_account_period a inner join
|
||
ct_channel_list b on a.agent_id = b.agent_id and a.channel_id = b.channel_id
|
||
where
|
||
a.is_enable != 0 and substr(a.account_period, 1, 4) = {$year}
|
||
group by
|
||
a.agent_id, a.channel_id, b.nickname
|
||
) b
|
||
) a
|
||
left join
|
||
(
|
||
select
|
||
a.agent_id,
|
||
a.channel_id,
|
||
b.nickname,
|
||
-- date_format(c.pay_time, '%Y%m') account_period,
|
||
c.account_period,
|
||
sum(a.realpay) realpay,
|
||
sum(a.carryover) carryover,
|
||
sum(a.realincome) realincome,
|
||
sum(case a.account_period when '{$year}01' then a.realincome else 0 end) `{$year}01`,
|
||
sum(case a.account_period when '{$year}02' then a.realincome else 0 end) `{$year}02`,
|
||
sum(case a.account_period when '{$year}03' then a.realincome else 0 end) `{$year}03`,
|
||
sum(case a.account_period when '{$year}04' then a.realincome else 0 end) `{$year}04`,
|
||
sum(case a.account_period when '{$year}05' then a.realincome else 0 end) `{$year}05`,
|
||
sum(case a.account_period when '{$year}06' then a.realincome else 0 end) `{$year}06`,
|
||
sum(case a.account_period when '{$year}07' then a.realincome else 0 end) `{$year}07`,
|
||
sum(case a.account_period when '{$year}08' then a.realincome else 0 end) `{$year}08`,
|
||
sum(case a.account_period when '{$year}09' then a.realincome else 0 end) `{$year}09`,
|
||
sum(case a.account_period when '{$year}10' then a.realincome else 0 end) `{$year}10`,
|
||
sum(case a.account_period when '{$year}11' then a.realincome else 0 end) `{$year}11`,
|
||
sum(case a.account_period when '{$year}12' then a.realincome else 0 end) `{$year}12`
|
||
from
|
||
ct_channel_account_period_pay_log a inner join
|
||
ct_channel_list b on a.agent_id = b.agent_id and a.channel_id = b.channel_id inner join
|
||
ct_channel_pay_log c on a.pay_log_id = c.id
|
||
where
|
||
a.is_enable != 0 and c.is_enable != 0 and year(c.pay_time) = {$year}
|
||
group by
|
||
a.agent_id, a.channel_id, b.nickname, date_format(c.pay_time, '%Y%m')
|
||
) b on a.agent_id = b.agent_id and a.channel_id = b.channel_id and a.account_period = b.account_period
|
||
where
|
||
a.agent_id = ? and a.channel_id = ?
|
||
order by
|
||
a.account_period
|
||
EOL;
|
||
elseif (2 == $type)
|
||
$cmd = /** @lang text */<<<EOL
|
||
select
|
||
#a.agent_id,
|
||
#a.channel_id,
|
||
a.nickname `渠道`,
|
||
a.account_period `账期`,
|
||
cast(ifnull(b.realpay, 0) as decimal(18, 2)) `本期实付金额`,
|
||
cast(ifnull(b.carryover, 0) as decimal(18, 2)) `上期结转余额`,
|
||
cast(ifnull(b.realincome, 0) as decimal(18, 2)) `实际抵扣`,
|
||
cast(ifnull(b.realpay, 0) + ifnull(b.carryover, 0) - ifnull(b.realincome, 0) as decimal(18, 2)) `余额`,
|
||
cast(if(a.account_period < '{$year}01', 0, a.`{$year}01` - ifnull(b.`{$year}01`, 0)) as decimal(18, 2)) `{$year}01`,
|
||
cast(if(a.account_period < '{$year}02', 0, a.`{$year}02` - ifnull(b.`{$year}02`, 0)) as decimal(18, 2)) `{$year}02`,
|
||
cast(if(a.account_period < '{$year}03', 0, a.`{$year}03` - ifnull(b.`{$year}03`, 0)) as decimal(18, 2)) `{$year}03`,
|
||
cast(if(a.account_period < '{$year}04', 0, a.`{$year}04` - ifnull(b.`{$year}04`, 0)) as decimal(18, 2)) `{$year}04`,
|
||
cast(if(a.account_period < '{$year}05', 0, a.`{$year}05` - ifnull(b.`{$year}05`, 0)) as decimal(18, 2)) `{$year}05`,
|
||
cast(if(a.account_period < '{$year}06', 0, a.`{$year}06` - ifnull(b.`{$year}06`, 0)) as decimal(18, 2)) `{$year}06`,
|
||
cast(if(a.account_period < '{$year}07', 0, a.`{$year}07` - ifnull(b.`{$year}07`, 0)) as decimal(18, 2)) `{$year}07`,
|
||
cast(if(a.account_period < '{$year}08', 0, a.`{$year}08` - ifnull(b.`{$year}08`, 0)) as decimal(18, 2)) `{$year}08`,
|
||
cast(if(a.account_period < '{$year}09', 0, a.`{$year}09` - ifnull(b.`{$year}09`, 0)) as decimal(18, 2)) `{$year}09`,
|
||
cast(if(a.account_period < '{$year}10', 0, a.`{$year}10` - ifnull(b.`{$year}10`, 0)) as decimal(18, 2)) `{$year}10`,
|
||
cast(if(a.account_period < '{$year}11', 0, a.`{$year}11` - ifnull(b.`{$year}11`, 0)) as decimal(18, 2)) `{$year}11`,
|
||
cast(if(a.account_period < '{$year}12', 0, a.`{$year}12` - ifnull(b.`{$year}12`, 0)) as decimal(18, 2)) `{$year}12`
|
||
from
|
||
(
|
||
select
|
||
b.agent_id,
|
||
b.channel_id,
|
||
b.nickname,
|
||
a.account_period,
|
||
b.`{$year}01`,
|
||
b.`{$year}02`,
|
||
b.`{$year}03`,
|
||
b.`{$year}04`,
|
||
b.`{$year}05`,
|
||
b.`{$year}06`,
|
||
b.`{$year}07`,
|
||
b.`{$year}08`,
|
||
b.`{$year}09`,
|
||
b.`{$year}10`,
|
||
b.`{$year}11`,
|
||
b.`{$year}12`
|
||
from
|
||
(
|
||
select distinct account_period from ct_channel_account_period_online where substr(account_period, 1, 4) = {$year}
|
||
) a,
|
||
(
|
||
select
|
||
a.agent_id,
|
||
a.channel_id,
|
||
b.nickname,
|
||
sum(case a.account_period when '{$year}01' then a.realtotal else 0 end) `{$year}01`,
|
||
sum(case a.account_period when '{$year}02' then a.realtotal else 0 end) `{$year}02`,
|
||
sum(case a.account_period when '{$year}03' then a.realtotal else 0 end) `{$year}03`,
|
||
sum(case a.account_period when '{$year}04' then a.realtotal else 0 end) `{$year}04`,
|
||
sum(case a.account_period when '{$year}05' then a.realtotal else 0 end) `{$year}05`,
|
||
sum(case a.account_period when '{$year}06' then a.realtotal else 0 end) `{$year}06`,
|
||
sum(case a.account_period when '{$year}07' then a.realtotal else 0 end) `{$year}07`,
|
||
sum(case a.account_period when '{$year}08' then a.realtotal else 0 end) `{$year}08`,
|
||
sum(case a.account_period when '{$year}09' then a.realtotal else 0 end) `{$year}09`,
|
||
sum(case a.account_period when '{$year}10' then a.realtotal else 0 end) `{$year}10`,
|
||
sum(case a.account_period when '{$year}11' then a.realtotal else 0 end) `{$year}11`,
|
||
sum(case a.account_period when '{$year}12' then a.realtotal else 0 end) `{$year}12`
|
||
from
|
||
ct_channel_account_period_online a inner join
|
||
ct_channel_list b on a.agent_id = b.agent_id and a.channel_id = b.channel_id
|
||
where
|
||
a.is_enable != 0 and substr(a.account_period, 1, 4) = {$year}
|
||
group by
|
||
a.agent_id, a.channel_id, b.nickname
|
||
) b
|
||
) a
|
||
left join
|
||
(
|
||
select
|
||
a.agent_id,
|
||
a.channel_id,
|
||
b.nickname,
|
||
-- date_format(c.pay_time, '%Y%m') account_period,
|
||
c.account_period,
|
||
sum(a.realpay) realpay,
|
||
sum(a.carryover) carryover,
|
||
sum(a.realincome) realincome,
|
||
sum(case a.account_period when '{$year}01' then a.realincome else 0 end) `{$year}01`,
|
||
sum(case a.account_period when '{$year}02' then a.realincome else 0 end) `{$year}02`,
|
||
sum(case a.account_period when '{$year}03' then a.realincome else 0 end) `{$year}03`,
|
||
sum(case a.account_period when '{$year}04' then a.realincome else 0 end) `{$year}04`,
|
||
sum(case a.account_period when '{$year}05' then a.realincome else 0 end) `{$year}05`,
|
||
sum(case a.account_period when '{$year}06' then a.realincome else 0 end) `{$year}06`,
|
||
sum(case a.account_period when '{$year}07' then a.realincome else 0 end) `{$year}07`,
|
||
sum(case a.account_period when '{$year}08' then a.realincome else 0 end) `{$year}08`,
|
||
sum(case a.account_period when '{$year}09' then a.realincome else 0 end) `{$year}09`,
|
||
sum(case a.account_period when '{$year}10' then a.realincome else 0 end) `{$year}10`,
|
||
sum(case a.account_period when '{$year}11' then a.realincome else 0 end) `{$year}11`,
|
||
sum(case a.account_period when '{$year}12' then a.realincome else 0 end) `{$year}12`
|
||
from
|
||
ct_channel_account_period_online_pay_log a inner join
|
||
ct_channel_list b on a.agent_id = b.agent_id and a.channel_id = b.channel_id inner join
|
||
ct_channel_pay_log c on a.pay_log_id = c.id
|
||
where
|
||
a.is_enable != 0 and c.is_enable != 0 and year(c.pay_time) = {$year}
|
||
group by
|
||
a.agent_id, a.channel_id, b.nickname, date_format(c.pay_time, '%Y%m')
|
||
) b on a.agent_id = b.agent_id and a.channel_id = b.channel_id and a.account_period = b.account_period
|
||
where
|
||
a.agent_id = ? and a.channel_id = ?
|
||
order by
|
||
a.account_period
|
||
EOL;
|
||
else
|
||
{
|
||
$return->seterrors(ERRORCODE_TYPEERROR, ERRORINFO_TYPEERROR);
|
||
return false;
|
||
}
|
||
|
||
$ret = $this->pdo_request($cmd, $agent_id, $channel_id);
|
||
if (!$this->pdo_isdone())
|
||
{
|
||
$return->seterrors($this->geterrorcode(), $this->geterrorinfo() . '(' . __LINE__ . ')');
|
||
return false;
|
||
}
|
||
|
||
if(is_array($ret) && isset($ret[0])) {
|
||
$data['title'] = array_keys($ret[0]);
|
||
foreach ($ret as $k => $v) {
|
||
foreach ($v as $q) {
|
||
$data['data'][$k][] = $q;
|
||
}
|
||
}
|
||
}else{
|
||
$data = [];
|
||
}
|
||
|
||
$return->biz_content = $data;
|
||
return true;
|
||
}
|
||
|
||
|
||
/**
|
||
* @note 保存营业收入数据
|
||
* 被请求方法示例:参数固定为RequestParameter和ReturnParameter对象,返回值固定为true(成功)和false(失败)
|
||
* @param RequestParameter $request
|
||
* @param ReturnParameter $return
|
||
* @return bool
|
||
*/
|
||
public function business_income_new($request, $return)
|
||
{
|
||
$param = (array)$request->biz_content;
|
||
if (!is_array($param))
|
||
{
|
||
/// 参数格式错误
|
||
$return->SetErrors(ERRORCODE_INPARAMERROR, ERRORINFO_INPARAMERROR);
|
||
return false;
|
||
}
|
||
|
||
$account_period = @$param['date']; /// 账期(yyyymm)
|
||
if (empty($account_period))
|
||
{
|
||
$return->seterrors(ERRORCODE_ACCOUNTPERIODERROR, ERRORINFO_ACCOUNTPERIODERROR);
|
||
return false;
|
||
}
|
||
$account_period = str_replace('-', '', $account_period);
|
||
|
||
/// 处理字符串
|
||
$account_period = $this->NewMasterCommand()->GetIdentifiers($account_period, true);
|
||
|
||
$this->pdo_begintransaction();
|
||
try
|
||
{
|
||
/// 删除往期账期数据
|
||
$cmd = /** @lang text */<<<EOL
|
||
delete from ct_business_income where account_period = {$account_period}
|
||
EOL;
|
||
$ret = $this->pdo_execute($cmd);
|
||
if (!$ret)
|
||
throw new Exception($this->geterrorinfo() . '(' . __LINE__ . ')', $this->geterrorcode());
|
||
|
||
/// 插入账期数据
|
||
$cmd = /** @lang text */<<<EOL
|
||
insert into ct_business_income(
|
||
agent_id, # 代理商id
|
||
channel_id, # 渠道id
|
||
channel_name, # 渠道名称
|
||
account_period, # 账期
|
||
card_count_total, # 总计出售房卡数
|
||
card_count_free, # 赠送卡数
|
||
card_count_settle, # 结算卡数
|
||
card_price_settle, # 房卡结算单价
|
||
card_price_real, # 房卡实际单价
|
||
card_money_settle, # 房卡结算金额
|
||
card_money_proportions, # 房卡渠道分成金额
|
||
card_money_income, # 房卡营业收入
|
||
gold_count_total, # 总计出售金币数
|
||
gold_count_free, # 赠送金币数
|
||
gold_count_settle, # 结算金币数
|
||
gold_price_settle, # 金币结算单价
|
||
gold_price_real, # 金币实际单价
|
||
gold_money_settle, # 金币结算金额
|
||
gold_money_proportions, # 金币渠道分成金额
|
||
gold_money_income, # 金币营业收入
|
||
pay_money, # 渠道转款实收款项
|
||
card_count_sell, # 自助购买房卡数
|
||
card_money_sell, # 自助购买房卡金额
|
||
card_money_income_sell, # 自助购买房卡营业收入
|
||
gold_count_sell, # 自助购买金币数
|
||
gold_money_sell, # 自助购买金币金额
|
||
gold_money_income_sell, # 自助购买金币营业收入
|
||
diamond_count_sell, # 自助购买钻石数
|
||
diamond_money_sell, # 自助购买钻石金额
|
||
diamond_money_income_sell, # 自助购买钻石营业收入
|
||
pay_money_sell, # 渠道自助购买实收款项
|
||
money_settle, # 结算金额
|
||
money_total, # 实际收款
|
||
money_receivable) # 累计未收
|
||
select
|
||
a.agent_id, # 代理商id
|
||
a.channel_id, # 渠道id
|
||
a.nickname, # 渠道名称
|
||
{$account_period}, # 账期
|
||
(ifnull(b.sum_card, 0) + ifnull(i.sum_ask_card, 0) + ifnull(j.sum_player_card, 0)), # 总计出售房卡数
|
||
ifnull(d.free_card, 0), # 赠送卡数
|
||
(ifnull(b.sum_card, 0) + ifnull(i.sum_ask_card, 0) + ifnull(j.sum_player_card, 0)) - ifnull(d.free_card, 0), # 结算卡数
|
||
ifnull(d.price_card, 0), # 房卡结算单价
|
||
(((ifnull(b.sum_card, 0) + ifnull(i.sum_ask_card, 0) + ifnull(j.sum_player_card, 0)) - ifnull(d.free_card, 0)) * ifnull(d.price_card, 0)) / ifnull(b.sum_card, 1), # 房卡实际单价
|
||
(((ifnull(b.sum_card, 0) + ifnull(i.sum_ask_card, 0) + ifnull(j.sum_player_card, 0)) - ifnull(d.free_card, 0)) * ifnull(d.price_card, 0)), # 房卡结算金额
|
||
(((ifnull(b.sum_card, 0) + ifnull(i.sum_ask_card, 0) + ifnull(j.sum_player_card, 0)) - ifnull(d.free_card, 0)) * ifnull(d.price_card, 0)) * ifnull(a.proportions, 0), # 房卡渠道分成金额
|
||
(((ifnull(b.sum_card, 0) + ifnull(i.sum_ask_card, 0) + ifnull(j.sum_player_card, 0)) - ifnull(d.free_card, 0)) * ifnull(d.price_card, 0)) - (((ifnull(b.sum_card, 0) + ifnull(i.sum_ask_card, 0) + ifnull(j.sum_player_card, 0)) - ifnull(d.free_card, 0)) * ifnull(d.price_card, 0)) * ifnull(a.proportions, 0), # 房卡营业收入
|
||
|
||
(ifnull(c.sum_gold, 0) + ifnull(k.sum_player_gold, 0) + ifnull(l.sum_ask_gold, 0)), # 总计出售金币数
|
||
ifnull(d.free_gold, 0), # 赠送金币数
|
||
(ifnull(c.sum_gold, 0) + ifnull(k.sum_player_gold, 0) + ifnull(l.sum_ask_gold, 0)) - ifnull(d.free_gold, 0), # 结算金币数
|
||
ifnull(d.price_gold, 0), # 金币结算单价
|
||
(((ifnull(c.sum_gold, 0) + ifnull(k.sum_player_gold, 0) + ifnull(l.sum_ask_gold, 0)) - ifnull(d.free_gold, 0)) * ifnull(d.price_gold, 0)) / case when (ifnull(c.sum_gold, 0) + ifnull(k.sum_player_gold, 0) + ifnull(l.sum_ask_gold, 0)) = 0 then 1 else (ifnull(c.sum_gold, 0) + ifnull(k.sum_player_gold, 0) + ifnull(l.sum_ask_gold, 0)) end, # 金币实际单价
|
||
(((ifnull(c.sum_gold, 0) + ifnull(k.sum_player_gold, 0) + ifnull(l.sum_ask_gold, 0)) - ifnull(d.free_gold, 0)) * ifnull(d.price_gold, 0)), # 金币结算金额
|
||
(((ifnull(c.sum_gold, 0) + ifnull(k.sum_player_gold, 0) + ifnull(l.sum_ask_gold, 0)) - ifnull(d.free_gold, 0)) * ifnull(d.price_gold, 0)) * ifnull(a.proportions, 0), # 金币渠道分成金额
|
||
(((ifnull(c.sum_gold, 0) + ifnull(k.sum_player_gold, 0) + ifnull(l.sum_ask_gold, 0)) - ifnull(d.free_gold, 0)) * ifnull(d.price_gold, 0)) - (((ifnull(c.sum_gold, 0) + ifnull(k.sum_player_gold, 0) + ifnull(l.sum_ask_gold, 0)) - ifnull(d.free_gold, 0)) * ifnull(d.price_gold, 0)) * ifnull(a.proportions, 0), # 金币营业收入
|
||
|
||
ifnull(e.pay_fee, 0), # 渠道转款实收款项
|
||
|
||
(ifnull(f.sum_card_sell, 0) + ifnull(o.sum_card_sell_third, 0)), # 自助购买房卡数
|
||
(ifnull(f.sum_card_money, 0) + ifnull(o.sum_card_money_third, 0)), # 自助购买房卡金额
|
||
(ifnull(f.sum_card_money, 0) + ifnull(o.sum_card_money_third, 0)) * 0.99 * (1 - a.proportions), # 自助购买房卡营业收入
|
||
|
||
(ifnull(f.sum_gold_sell, 0) + ifnull(o.sum_gold_sell_third, 0)), # 自助购买金币数
|
||
(ifnull(f.sum_gold_money, 0) + ifnull(o.sum_gold_money_third, 0)), # 自助购买金币金额
|
||
(ifnull(f.sum_gold_money, 0) + ifnull(o.sum_gold_money_third, 0)) * 0.99 * (1 - a.proportions), # 自助购买金币营业收入
|
||
|
||
ifnull(f.sum_diamond_sell, 0), # 自助购买钻石数
|
||
ifnull(f.sum_diamond_money, 0), # 自助购买钻石金额
|
||
ifnull(f.sum_diamond_money, 0) * 0.99 * (1 - a.proportions), # 自助购买钻石营业收入
|
||
|
||
ifnull(e.pay_fee_online, 0), # 渠道自助购买实收款项
|
||
|
||
((((ifnull(b.sum_card, 0) + ifnull(i.sum_ask_card, 0) + ifnull(j.sum_player_card, 0)) - ifnull(d.free_card, 0)) * ifnull(d.price_card, 0)) - (((ifnull(b.sum_card, 0) + ifnull(i.sum_ask_card, 0) + ifnull(j.sum_player_card, 0)) - ifnull(d.free_card, 0)) * ifnull(d.price_card, 0)) * ifnull(a.proportions, 0)) +
|
||
((ifnull(f.sum_card_money, 0) + ifnull(o.sum_card_money_third, 0)) * 0.99 * (1 - a.proportions)) +
|
||
((ifnull(f.sum_gold_money, 0) + ifnull(o.sum_gold_money_third, 0)) * 0.99 * (1 - a.proportions)) +
|
||
(ifnull(f.sum_diamond_money, 0) * 0.99 * (1 - a.proportions)), # 结算金额
|
||
|
||
ifnull(e.pay_fee, 0) + ifnull(e.pay_fee_online, 0), # 应收实收
|
||
|
||
ifnull(h.receivable, 0) # 累计应收未收
|
||
from
|
||
ct_channel_list a
|
||
left join
|
||
(
|
||
select
|
||
a.satr_agentid agent_id,
|
||
a.channel_id,
|
||
sum(a.satr_amount) sum_card # 给代理转卡数
|
||
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) = 1 and
|
||
ifnull(c.statistic_type, 0) = 0 and
|
||
date_format(a.satr_transfertime, '%Y%m') = {$account_period}
|
||
group by
|
||
a.satr_agentid, a.channel_id
|
||
) b
|
||
on
|
||
a.agent_id = b.agent_id and a.channel_id = b.channel_id
|
||
left join
|
||
(
|
||
select
|
||
a.saab_agentid agent_id,
|
||
a.channel_id channel_id,
|
||
ifnull(sum(saab_amount), 0) sum_ask_card # 给玩家和代理的索卡数
|
||
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
|
||
left join
|
||
sales_user c
|
||
on
|
||
a.saab_agentid = c.saus_agentid and a.channel_id = c.saus_channelid and (a.saab_type in (0, 2) and a.saab_askid = c.player_id or a.saab_type in (1, 3) and a.saab_askid = c.saus_salesid)
|
||
where
|
||
ifnull(b.statistic_type, 0) = 1 and
|
||
ifnull(c.statistic_type, 0) = 0 and
|
||
a.saab_state = 1 and
|
||
a.saab_type in (0, 1) and
|
||
date_format(a.saab_dealtime, '%Y%m') = {$account_period}
|
||
group by
|
||
a.saab_agentid, a.channel_id
|
||
) i
|
||
on
|
||
a.agent_id = i.agent_id and a.channel_id = i.channel_id
|
||
left join
|
||
(
|
||
select
|
||
a.sase_agentid agent_id,
|
||
a.channel_id channel_id,
|
||
ifnull(sum(sase_amount), 0) sum_player_card # 给玩家的转卡数
|
||
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
|
||
where
|
||
ifnull(b.statistic_type, 0) = 1 and
|
||
ifnull(c.statistic_type, 0) = 0 and
|
||
date_format(a.sase_selltime, '%Y%m') = {$account_period}
|
||
group by
|
||
a.sase_agentid, a.channel_id
|
||
) j
|
||
on
|
||
a.agent_id = j.agent_id and a.channel_id = j.channel_id
|
||
left join
|
||
(
|
||
select
|
||
a.agent_id,
|
||
a.channel_id,
|
||
sum(a.amount) sum_gold # 给代理的转星数
|
||
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) = 1 and
|
||
ifnull(c.statistic_type, 0) = 0 and
|
||
date_format(a.op_time, '%Y%m') = {$account_period}
|
||
group by
|
||
a.agent_id, a.channel_id
|
||
) c
|
||
on
|
||
a.agent_id = c.agent_id and a.channel_id = c.channel_id
|
||
left join
|
||
(
|
||
select
|
||
a.ssbe_agentid agent_id,
|
||
a.channel_id channel_id,
|
||
sum(a.ssbe_amount) sum_player_gold # 给玩家的转星数
|
||
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
|
||
where
|
||
ifnull(b.statistic_type, 0) = 1 and
|
||
ifnull(c.statistic_type, 0) = 0 and
|
||
date_format(a.ssbe_selltime, '%Y%m') = {$account_period}
|
||
group by
|
||
a.ssbe_agentid, a.channel_id
|
||
) k
|
||
on
|
||
a.agent_id = k.agent_id and a.channel_id = k.channel_id
|
||
left join
|
||
(
|
||
select
|
||
a.saab_agentid agent_id,
|
||
a.channel_id channel_id,
|
||
ifnull(sum(saab_amount), 0) sum_ask_gold # 给玩家和代理的索星星数
|
||
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
|
||
left join
|
||
sales_user c
|
||
on
|
||
a.saab_agentid = c.saus_agentid and a.channel_id = c.saus_channelid and (a.saab_type in (0, 2) and a.saab_askid = c.player_id or a.saab_type in (1, 3) and a.saab_askid = c.saus_salesid)
|
||
where
|
||
ifnull(b.statistic_type, 0) = 1 and
|
||
ifnull(c.statistic_type, 0) = 0 and
|
||
a.saab_state = 1 and
|
||
a.saab_type in (2,3) and
|
||
date_format(a.saab_dealtime, '%Y%m') = {$account_period}
|
||
group by
|
||
a.saab_agentid, a.channel_id
|
||
) l
|
||
on
|
||
a.agent_id = i.agent_id and a.channel_id = i.channel_id
|
||
left join
|
||
(
|
||
select
|
||
agent_id,
|
||
channel_id,
|
||
free_card,
|
||
free_gold,
|
||
price_card,
|
||
price_gold
|
||
from
|
||
ct_channel_account_period
|
||
where
|
||
account_period = {$account_period}
|
||
group by
|
||
agent_id, channel_id
|
||
) d
|
||
on
|
||
a.agent_id = d.agent_id and a.channel_id = d.channel_id
|
||
left join
|
||
(
|
||
select
|
||
agent_id,
|
||
channel_id,
|
||
sum(pay_fee) pay_fee,
|
||
sum(pay_fee_online) pay_fee_online
|
||
from
|
||
ct_channel_pay_log
|
||
where
|
||
is_enable != 0 and date_format(pay_time, '%Y%m') = {$account_period}
|
||
group by
|
||
agent_id, channel_id
|
||
) e
|
||
on
|
||
a.agent_id = e.agent_id and a.channel_id = e.channel_id
|
||
/*
|
||
left join
|
||
(
|
||
select
|
||
sabu_agentid agent_id,
|
||
sabu_channelid channel_id,
|
||
sum(sabu_amount) sum_card_sell,
|
||
sum(sabu_paymoney) sum_card_money
|
||
from
|
||
sales_buybill
|
||
where
|
||
sabu_paystate = 1 and date_format(sabu_paytime, '%Y%m') = {$account_period}
|
||
group by
|
||
sabu_agentid, sabu_channelid
|
||
) f
|
||
on
|
||
a.agent_id = f.agent_id and a.channel_id = f.channel_id
|
||
left join
|
||
(
|
||
select
|
||
agent_id,
|
||
channel_id,
|
||
sum(star_amount) sum_gold_sell,
|
||
sum(pay_money) sum_gold_money
|
||
from
|
||
order_star
|
||
where
|
||
`status` = 1 and date_format(pay_time, '%Y%m') = {$account_period}
|
||
group by
|
||
agent_id, channel_id
|
||
) g
|
||
on
|
||
a.agent_id = g.agent_id and a.channel_id = g.channel_id
|
||
*/
|
||
left join
|
||
(
|
||
select
|
||
agent_id,
|
||
channel_id,
|
||
sum(case product_type when 0 then product_amount else 0 end) sum_card_sell, # 总售房卡数
|
||
sum(case product_type when 0 then pay_money else 0 end) sum_card_money, # 总售房卡金额
|
||
sum(case product_type when 1 then product_amount else 0 end) sum_gold_sell, # 总售金币数
|
||
sum(case product_type when 1 then pay_money else 0 end) sum_gold_money, # 总售金币金额
|
||
sum(case product_type when 2 then product_amount else 0 end) sum_diamond_sell, # 总售钻石数
|
||
sum(case product_type when 2 then pay_money else 0 end) sum_diamond_money # 总售钻石金额
|
||
from
|
||
ct_order_info
|
||
where
|
||
pay_status = 1 and date_format(from_unixtime(pay_time), '%Y%m') = {$account_period}
|
||
group by
|
||
agent_id, channel_id
|
||
) f
|
||
on
|
||
a.agent_id = f.agent_id and a.channel_id = f.channel_id
|
||
left join
|
||
(
|
||
select
|
||
agent_id,
|
||
channel_id,
|
||
sum(receivable) receivable
|
||
from
|
||
ct_channel_account_period
|
||
where
|
||
is_enable != 0 and account_period <= {$account_period}
|
||
group by
|
||
agent_id, channel_id
|
||
) h
|
||
on
|
||
a.agent_id = h.agent_id and a.channel_id = h.channel_id
|
||
left join
|
||
(
|
||
select
|
||
a.agent_id,
|
||
a.channel_id,
|
||
sum(case a.production_type when 1 then a.amount else 0 end) card_system_produce,
|
||
sum(case a.production_type when 2 then a.amount else 0 end) gold_system_produce
|
||
from
|
||
ct_production_info a
|
||
where
|
||
a.amount > 0 and
|
||
date_format(a.create_time, '%Y%m') = {$account_period}
|
||
group by
|
||
a.agent_id, a.channel_id
|
||
) m
|
||
on
|
||
a.agent_id = m.agent_id and a.channel_id = m.channel_id
|
||
|
||
left join
|
||
(
|
||
select
|
||
agent_id,
|
||
channel_id,
|
||
sum(case type when 1 then amount else 0 end) sum_card_sell_third,
|
||
sum(case type when 2 then amount else 0 end) sum_gold_sell_third,
|
||
sum(case type when 1 then fee else 0 end) sum_card_money_third,
|
||
sum(case type when 2 then fee else 0 end) sum_gold_money_third
|
||
from
|
||
ct_pay_for_third
|
||
where
|
||
date_format(create_time, '%Y%m') = {$account_period}
|
||
group by
|
||
agent_id, channel_id
|
||
) o
|
||
on
|
||
a.agent_id = o.agent_id and a.channel_id = o.channel_id
|
||
where
|
||
a.is_open = 1
|
||
EOL;
|
||
$ret = $this->pdo_execute($cmd);
|
||
if (!$ret)
|
||
throw new Exception($this->geterrorinfo() . '(' . __LINE__ . ')', $this->geterrorcode());
|
||
$this->pdo_commit();
|
||
}
|
||
catch (Exception $Exception)
|
||
{
|
||
$this->pdo_rollback();
|
||
$return->seterrors($Exception->getcode(), $Exception->getmessage());
|
||
return false;
|
||
}
|
||
|
||
return true;
|
||
}
|
||
|
||
/**
|
||
* @note 获取营业收入数据
|
||
* 被请求方法示例:参数固定为RequestParameter和ReturnParameter对象,返回值固定为true(成功)和false(失败)
|
||
* @param RequestParameter $request
|
||
* @param ReturnParameter $return
|
||
* @return bool
|
||
*/
|
||
public function business_income_report($request, $return)
|
||
{
|
||
$param = (array)$request->biz_content;
|
||
if (!is_array($param))
|
||
{
|
||
/// 参数格式错误
|
||
$return->SetErrors(ERRORCODE_INPARAMERROR, ERRORINFO_INPARAMERROR);
|
||
return false;
|
||
}
|
||
|
||
$account_period = @$param['date']; /// 账期(yyyymm)
|
||
if (empty($account_period))
|
||
{
|
||
$return->seterrors(ERRORCODE_ACCOUNTPERIODERROR, ERRORINFO_ACCOUNTPERIODERROR);
|
||
return false;
|
||
}
|
||
$account_period = str_replace('-', '', $account_period);
|
||
|
||
/// 处理字符串
|
||
$account_period = $this->NewMasterCommand()->GetIdentifiers($account_period, true);
|
||
|
||
// 1-实时数据 0-历史数据
|
||
$type = isset($param['type']) ? (int)$param['type'] : 0;
|
||
|
||
/// 先查询往期数据,
|
||
$cmd = /** @lang text */<<<EOL
|
||
select
|
||
channel_name `渠道`, # 渠道名称
|
||
account_period `账期`, # 账期
|
||
card_count_total `总售卡数`, # 总计出售房卡数
|
||
card_count_free `赠送卡数`, # 赠送卡数
|
||
card_count_settle `结算卡数`, # 结算卡数
|
||
card_price_settle `结算单价[房卡]`, # 房卡结算单价
|
||
card_price_real `实际单价[房卡]`, # 房卡实际单价
|
||
card_money_settle `结算金额[房卡]`, # 房卡结算金额
|
||
card_money_proportions `渠道分成[房卡]`, # 房卡渠道分成金额
|
||
card_money_income `业务收入[房卡]`, # 房卡营业收入
|
||
|
||
gold_count_total `总金币数`, # 总计出售金币数
|
||
gold_count_free `赠送金币数`, # 赠送金币数
|
||
gold_count_settle `结算金币数`, # 结算金币数
|
||
gold_price_settle `结算单价[金币]`, # 金币结算单价
|
||
gold_price_real `实际单价[金币]`, # 金币实际单价
|
||
gold_money_settle `结算金额[金币]`, # 金币结算金额
|
||
gold_money_proportions `渠道分成[金币]`, # 金币渠道分成金额
|
||
gold_money_income `业务收入[金币]`, # 金币营业收入
|
||
|
||
pay_money `实收款[渠道转款]`, # 渠道转款实收款项
|
||
card_count_sell `售卡数量`, # 自助购买房卡数
|
||
card_money_sell `售卡金额`, # 自助购买房卡金额
|
||
card_money_income_sell `售卡公司分成`, # 自助购买房卡营业收入
|
||
gold_count_sell `售金币数`, # 自助购买金币数
|
||
gold_money_sell `售金币金额`, # 自助购买金币金额
|
||
gold_money_income_sell `售金币公司分成`, # 自助购买金币营业收入
|
||
diamond_count_sell `售钻石数`, # 自助购买钻石数
|
||
diamond_money_sell `售钻石金额`, # 自助购买钻石金额
|
||
diamond_money_income_sell `售钻石公司分成`, # 自助购买钻石营业收入
|
||
pay_money_sell `实收款[线上支付]`, # 渠道自助购买实收款项
|
||
money_settle `结算金额`, # 结算金额
|
||
money_total `应收实收`, # 实际收款
|
||
money_receivable `累计应收未收` # 累计未收
|
||
from
|
||
ct_business_income
|
||
where
|
||
account_period = {$account_period}
|
||
EOL;
|
||
$items = $this->pdo_request($cmd);
|
||
if (!$this->pdo_isdone())
|
||
{
|
||
$return->seterrors($this->geterrorinfo() . '(' . __LINE__ . ')', $this->geterrorcode());
|
||
return false;
|
||
}
|
||
|
||
if ($type === 1) /// 如果没有往期数据则根据指定账期动态查询
|
||
{
|
||
$cmd = /** @lang text */<<<EOL
|
||
select
|
||
a.nickname `渠道`,
|
||
{$account_period} `账期`,
|
||
(ifnull(b.sum_card, 0) + ifnull(i.sum_ask_card, 0) + ifnull(j.sum_player_card, 0)) `总售卡数`,
|
||
ifnull(d.free_card, 0) `赠送卡数`,
|
||
(ifnull(b.sum_card, 0) + ifnull(i.sum_ask_card, 0) + ifnull(j.sum_player_card, 0)) - ifnull(d.free_card, 0) `结算卡数`,
|
||
ifnull(d.price_card, 0) `结算单价[房卡]`,
|
||
(((ifnull(b.sum_card, 0) + ifnull(i.sum_ask_card, 0) + ifnull(j.sum_player_card, 0)) - ifnull(d.free_card, 0)) * ifnull(d.price_card, 0)) / ifnull(b.sum_card, 1) `实际单价[房卡]`,
|
||
(((ifnull(b.sum_card, 0) + ifnull(i.sum_ask_card, 0) + ifnull(j.sum_player_card, 0)) - ifnull(d.free_card, 0)) * ifnull(d.price_card, 0)) `结算金额[房卡]`,
|
||
(((ifnull(b.sum_card, 0) + ifnull(i.sum_ask_card, 0) + ifnull(j.sum_player_card, 0)) - ifnull(d.free_card, 0)) * ifnull(d.price_card, 0)) * ifnull(a.proportions, 0) `渠道分成[房卡]`,
|
||
(((ifnull(b.sum_card, 0) + ifnull(i.sum_ask_card, 0) + ifnull(j.sum_player_card, 0)) - ifnull(d.free_card, 0)) * ifnull(d.price_card, 0)) - (((ifnull(b.sum_card, 0) + ifnull(i.sum_ask_card, 0) + ifnull(j.sum_player_card, 0)) - ifnull(d.free_card, 0)) * ifnull(d.price_card, 0)) * ifnull(a.proportions, 0) `业务收入[房卡]`,
|
||
|
||
(ifnull(c.sum_gold, 0) + ifnull(k.sum_player_gold, 0) + ifnull(l.sum_ask_gold, 0)) `总金币数`,
|
||
ifnull(d.free_gold, 0) `赠送金币数`,
|
||
(ifnull(c.sum_gold, 0) + ifnull(k.sum_player_gold, 0) + ifnull(l.sum_ask_gold, 0)) - ifnull(d.free_gold, 0) `结算金币数`,
|
||
ifnull(d.price_gold, 0) `结算单价[金币]`,
|
||
(((ifnull(c.sum_gold, 0) + ifnull(k.sum_player_gold, 0) + ifnull(l.sum_ask_gold, 0)) - ifnull(d.free_gold, 0)) * ifnull(d.price_gold, 0)) / case when (ifnull(c.sum_gold, 0) + ifnull(k.sum_player_gold, 0) + ifnull(l.sum_ask_gold, 0)) = 0 then 1 else (ifnull(c.sum_gold, 0) + ifnull(k.sum_player_gold, 0) + ifnull(l.sum_ask_gold, 0)) end `实际单价[金币]`,
|
||
(((ifnull(c.sum_gold, 0) + ifnull(k.sum_player_gold, 0) + ifnull(l.sum_ask_gold, 0)) - ifnull(d.free_gold, 0)) * ifnull(d.price_gold, 0)) `结算金额[金币]`,
|
||
(((ifnull(c.sum_gold, 0) + ifnull(k.sum_player_gold, 0) + ifnull(l.sum_ask_gold, 0)) - ifnull(d.free_gold, 0)) * ifnull(d.price_gold, 0)) * ifnull(a.proportions, 0) `渠道分成[金币]`,
|
||
(((ifnull(c.sum_gold, 0) + ifnull(k.sum_player_gold, 0) + ifnull(l.sum_ask_gold, 0)) - ifnull(d.free_gold, 0)) * ifnull(d.price_gold, 0)) - (((ifnull(c.sum_gold, 0) + ifnull(k.sum_player_gold, 0) + ifnull(l.sum_ask_gold, 0)) - ifnull(d.free_gold, 0)) * ifnull(d.price_gold, 0)) * ifnull(a.proportions, 0) `业务收入[金币]`,
|
||
|
||
ifnull(e.pay_fee, 0) `实收款[渠道转款]`,
|
||
|
||
(ifnull(f.sum_card_sell, 0) + ifnull(o.sum_card_sell_third, 0)) `售卡数量`,
|
||
(ifnull(f.sum_card_money, 0) + ifnull(o.sum_card_money_third, 0)) `售卡金额`,
|
||
(ifnull(f.sum_card_money, 0) + ifnull(o.sum_card_money_third, 0)) * 0.99 * (1 - a.proportions) `售卡公司分成`,
|
||
|
||
(ifnull(f.sum_gold_sell, 0) + ifnull(o.sum_gold_sell_third, 0)) `售金币数`,
|
||
(ifnull(f.sum_gold_money, 0) + ifnull(o.sum_gold_money_third, 0)) `售金币金额`,
|
||
(ifnull(f.sum_gold_money, 0) + ifnull(o.sum_gold_money_third, 0)) * 0.99 * (1 - a.proportions) `售金币公司分成`,
|
||
|
||
ifnull(f.sum_diamond_sell, 0) `购买钻石数`,
|
||
ifnull(f.sum_diamond_money, 0) `购买钻石金额`,
|
||
ifnull(f.sum_diamond_money, 0) * 0.99 * (1 - a.proportions) `售钻石公司分成`,
|
||
|
||
ifnull(e.pay_fee_online, 0) `实收款[线上支付]`,
|
||
|
||
((((ifnull(b.sum_card, 0) + ifnull(i.sum_ask_card, 0) + ifnull(j.sum_player_card, 0)) - ifnull(d.free_card, 0)) * ifnull(d.price_card, 0)) - (((ifnull(b.sum_card, 0) + ifnull(i.sum_ask_card, 0) + ifnull(j.sum_player_card, 0)) - ifnull(d.free_card, 0)) * ifnull(d.price_card, 0)) * ifnull(a.proportions, 0)) +
|
||
((ifnull(f.sum_card_money, 0) + ifnull(o.sum_card_money_third, 0)) * 0.99 * (1 - a.proportions)) +
|
||
((ifnull(f.sum_gold_money, 0) + ifnull(o.sum_gold_money_third, 0)) * 0.99 * (1 - a.proportions)) +
|
||
(ifnull(f.sum_diamond_money, 0) * 0.99 * (1 - a.proportions)) `结算金额`,
|
||
|
||
ifnull(e.pay_fee, 0) + ifnull(e.pay_fee_online, 0) `应收实收`,
|
||
|
||
ifnull(h.receivable, 0) `累计应收未收`
|
||
from
|
||
ct_channel_list a
|
||
left join
|
||
(
|
||
select
|
||
a.satr_agentid agent_id,
|
||
a.channel_id,
|
||
sum(a.satr_amount) sum_card # 给代理转卡数
|
||
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) = 1 and
|
||
ifnull(c.statistic_type, 0) = 0 and
|
||
date_format(a.satr_transfertime, '%Y%m') = {$account_period}
|
||
group by
|
||
a.satr_agentid, a.channel_id
|
||
) b
|
||
on
|
||
a.agent_id = b.agent_id and a.channel_id = b.channel_id
|
||
left join
|
||
(
|
||
select
|
||
a.saab_agentid agent_id,
|
||
a.channel_id channel_id,
|
||
ifnull(sum(saab_amount), 0) sum_ask_card # 给玩家和代理的索卡数
|
||
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
|
||
left join
|
||
sales_user c
|
||
on
|
||
a.saab_agentid = c.saus_agentid and a.channel_id = c.saus_channelid and (a.saab_type in (0, 2) and a.saab_askid = c.player_id or a.saab_type in (1, 3) and a.saab_askid = c.saus_salesid)
|
||
where
|
||
ifnull(b.statistic_type, 0) = 1 and
|
||
ifnull(c.statistic_type, 0) = 0 and
|
||
a.saab_state = 1 and
|
||
a.saab_type in (0, 1) and
|
||
date_format(a.saab_dealtime, '%Y%m') = {$account_period}
|
||
group by
|
||
a.saab_agentid, a.channel_id
|
||
) i
|
||
on
|
||
a.agent_id = i.agent_id and a.channel_id = i.channel_id
|
||
left join
|
||
(
|
||
select
|
||
a.sase_agentid agent_id,
|
||
a.channel_id channel_id,
|
||
ifnull(sum(sase_amount), 0) sum_player_card # 给玩家的转卡数
|
||
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
|
||
where
|
||
ifnull(b.statistic_type, 0) = 1 and
|
||
ifnull(c.statistic_type, 0) = 0 and
|
||
date_format(a.sase_selltime, '%Y%m') = {$account_period}
|
||
group by
|
||
a.sase_agentid, a.channel_id
|
||
) j
|
||
on
|
||
a.agent_id = j.agent_id and a.channel_id = j.channel_id
|
||
left join
|
||
(
|
||
select
|
||
a.agent_id,
|
||
a.channel_id,
|
||
sum(a.amount) sum_gold # 给代理的转星数
|
||
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) = 1 and
|
||
ifnull(c.statistic_type, 0) = 0 and
|
||
date_format(a.op_time, '%Y%m') = {$account_period}
|
||
group by
|
||
a.agent_id, a.channel_id
|
||
) c
|
||
on
|
||
a.agent_id = c.agent_id and a.channel_id = c.channel_id
|
||
left join
|
||
(
|
||
select
|
||
a.ssbe_agentid agent_id,
|
||
a.channel_id channel_id,
|
||
sum(a.ssbe_amount) sum_player_gold # 给玩家的转星数
|
||
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
|
||
where
|
||
ifnull(b.statistic_type, 0) = 1 and
|
||
ifnull(c.statistic_type, 0) = 0 and
|
||
date_format(a.ssbe_selltime, '%Y%m') = {$account_period}
|
||
group by
|
||
a.ssbe_agentid, a.channel_id
|
||
) k
|
||
on
|
||
a.agent_id = k.agent_id and a.channel_id = k.channel_id
|
||
left join
|
||
(
|
||
select
|
||
a.saab_agentid agent_id,
|
||
a.channel_id channel_id,
|
||
ifnull(sum(saab_amount), 0) sum_ask_gold # 给玩家和代理的索星星数
|
||
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
|
||
left join
|
||
sales_user c
|
||
on
|
||
a.saab_agentid = c.saus_agentid and a.channel_id = c.saus_channelid and (a.saab_type in (0, 2) and a.saab_askid = c.player_id or a.saab_type in (1, 3) and a.saab_askid = c.saus_salesid)
|
||
where
|
||
ifnull(b.statistic_type, 0) = 1 and
|
||
ifnull(c.statistic_type, 0) = 0 and
|
||
a.saab_state = 1 and
|
||
a.saab_type in (2,3) and
|
||
date_format(a.saab_dealtime, '%Y%m') = {$account_period}
|
||
group by
|
||
a.saab_agentid, a.channel_id
|
||
) l
|
||
on
|
||
a.agent_id = i.agent_id and a.channel_id = i.channel_id
|
||
left join
|
||
(
|
||
select
|
||
agent_id,
|
||
channel_id,
|
||
free_card,
|
||
free_gold,
|
||
price_card,
|
||
price_gold
|
||
from
|
||
ct_channel_account_period
|
||
where
|
||
account_period = {$account_period}
|
||
group by
|
||
agent_id, channel_id
|
||
) d
|
||
on
|
||
a.agent_id = d.agent_id and a.channel_id = d.channel_id
|
||
left join
|
||
(
|
||
select
|
||
agent_id,
|
||
channel_id,
|
||
sum(pay_fee) pay_fee,
|
||
sum(pay_fee_online) pay_fee_online
|
||
from
|
||
ct_channel_pay_log
|
||
where
|
||
is_enable != 0 and date_format(pay_time, '%Y%m') = {$account_period}
|
||
group by
|
||
agent_id, channel_id
|
||
) e
|
||
on
|
||
a.agent_id = e.agent_id and a.channel_id = e.channel_id
|
||
/*
|
||
left join
|
||
(
|
||
select
|
||
sabu_agentid agent_id,
|
||
sabu_channelid channel_id,
|
||
sum(sabu_amount) sum_card_sell,
|
||
sum(sabu_paymoney) sum_card_money
|
||
from
|
||
sales_buybill
|
||
where
|
||
sabu_paystate = 1 and date_format(sabu_paytime, '%Y%m') = {$account_period}
|
||
group by
|
||
sabu_agentid, sabu_channelid
|
||
) f
|
||
on
|
||
a.agent_id = f.agent_id and a.channel_id = f.channel_id
|
||
left join
|
||
(
|
||
select
|
||
agent_id,
|
||
channel_id,
|
||
sum(star_amount) sum_gold_sell,
|
||
sum(pay_money) sum_gold_money
|
||
from
|
||
order_star
|
||
where
|
||
`status` = 1 and date_format(pay_time, '%Y%m') = {$account_period}
|
||
group by
|
||
agent_id, channel_id
|
||
) g
|
||
on
|
||
a.agent_id = g.agent_id and a.channel_id = g.channel_id
|
||
*/
|
||
left join
|
||
(
|
||
select
|
||
agent_id,
|
||
channel_id,
|
||
sum(case product_type when 0 then product_amount else 0 end) sum_card_sell, # 总售房卡数
|
||
sum(case product_type when 0 then pay_money else 0 end) sum_card_money, # 总售房卡金额
|
||
sum(case product_type when 1 then product_amount else 0 end) sum_gold_sell, # 总售金币数
|
||
sum(case product_type when 1 then pay_money else 0 end) sum_gold_money, # 总售金币金额
|
||
sum(case product_type when 2 then product_amount else 0 end) sum_diamond_sell, # 总售钻石数
|
||
sum(case product_type when 2 then pay_money else 0 end) sum_diamond_money # 总售钻石金额
|
||
from
|
||
ct_order_info
|
||
where
|
||
pay_status = 1 and date_format(from_unixtime(pay_time), '%Y%m') = {$account_period}
|
||
group by
|
||
agent_id, channel_id
|
||
) f
|
||
on
|
||
a.agent_id = f.agent_id and a.channel_id = f.channel_id
|
||
left join
|
||
(
|
||
select
|
||
agent_id,
|
||
channel_id,
|
||
sum(receivable) receivable
|
||
from
|
||
ct_channel_account_period
|
||
where
|
||
is_enable != 0 and account_period <= {$account_period}
|
||
group by
|
||
agent_id, channel_id
|
||
) h
|
||
on
|
||
a.agent_id = h.agent_id and a.channel_id = h.channel_id
|
||
left join
|
||
(
|
||
select
|
||
a.agent_id,
|
||
a.channel_id,
|
||
sum(case a.production_type when 1 then a.amount else 0 end) card_system_produce,
|
||
sum(case a.production_type when 2 then a.amount else 0 end) gold_system_produce
|
||
from
|
||
ct_production_info a
|
||
where
|
||
a.amount > 0 and
|
||
date_format(a.create_time, '%Y%m') = {$account_period}
|
||
group by
|
||
a.agent_id, a.channel_id
|
||
) m
|
||
on
|
||
a.agent_id = m.agent_id and a.channel_id = m.channel_id
|
||
|
||
left join
|
||
(
|
||
select
|
||
agent_id,
|
||
channel_id,
|
||
sum(case type when 1 then amount else 0 end) sum_card_sell_third,
|
||
sum(case type when 2 then amount else 0 end) sum_gold_sell_third,
|
||
sum(case type when 1 then fee else 0 end) sum_card_money_third,
|
||
sum(case type when 2 then fee else 0 end) sum_gold_money_third
|
||
from
|
||
ct_pay_for_third
|
||
where
|
||
date_format(create_time, '%Y%m') = {$account_period}
|
||
group by
|
||
agent_id, channel_id
|
||
) o
|
||
on
|
||
a.agent_id = o.agent_id and a.channel_id = o.channel_id
|
||
where
|
||
a.is_open = 1
|
||
EOL;
|
||
$items = $this->pdo_request($cmd);
|
||
if (!$this->pdo_isdone())
|
||
{
|
||
$return->seterrors($this->geterrorinfo() . '(' . __LINE__ . ')', $this->geterrorcode());
|
||
return false;
|
||
}
|
||
}
|
||
|
||
$data = [];
|
||
if(is_array($items) && isset($items[0])) {
|
||
$data['title'] = array_keys($items[0]);
|
||
foreach ($items as $k => $v) {
|
||
foreach ($v as $q) {
|
||
if(is_numeric($q))
|
||
$q = round($q, 2);
|
||
|
||
$data['data'][$k][] = $q;
|
||
}
|
||
}
|
||
}
|
||
|
||
// 5、数据返回部分
|
||
$return->biz_content = $data;
|
||
|
||
return true;
|
||
}
|
||
}
|