添加后台代理代码

This commit is contained in:
2026-03-15 01:27:05 +08:00
parent 11f9ac4dc1
commit ea08c9366a
5254 changed files with 721042 additions and 0 deletions

View File

@@ -0,0 +1,882 @@
<?php
/**
* Created by PhpStorm.
* User: abcdefg
* Date: 2017/7/10
* Time: 9:29
*/
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';
class report extends BaseMethod
{
/// 全局比例
private $global_rate = 1;
/// 白名单比例
private $whitelist_rate = 1;
/// 白名单
private $whitelist = array(
'00bA05haB0d9ZC0fwGD09Q2OA30insbQfrdt0C1GG0t91P0McFo0rbA1he5yurbS' => array( /// 全国
),
'z9kh0TRia0hF3C1m4lt5kuSfH02HoBBtjh9H0sp7t0Lapg0hGbz1sAfa44sqA1yA' => array( /// 上饶
),
'wVcn0icGP0pgGK2hjBh0McJrOq2H92wXmdog06zrG0Grxp0AWNd1ipgtLCcmG0wm' => array( /// 休闲
),
'cRif0rNjh0Wfhm2q1XE1qJonKxHkndDxDjBx0ishk0Chps0Ypga1bdrfO6W5Nzwi' => array( /// (测试)
),
'BCmh0jkhw0dBHy2uXia8gkg3Av3gkrvxhpcL0Slbq0fFkj0xfuy1vej6nglPDfU1' => array( /// 武汉
),
'Cm2K0jK8e0tUl20gywl8iOkeKhSV4lSay2SK0h4df0rfGa0c9D17o589g7vXtw3L' => array( /// 海南
),
'bjdc0emtp0irtD2cKcA2MBAZxk1AJRiuXgjo0UzHy0keYw0vMrf1kwzZoku9mpUl' => array( /// 168游戏平台
),
'cjcH0Yrkq0EUfb2NvZu3pm7CG4y5fmo5RGsj0TiHx0Kmju0IUVo1dv6e9j6ZV39y' => array( /// 崇仁聚友棋牌
),
'veRa0qrBf0df2K1G4de2tgfmVxB2jxpvFtJf073aa0d6rI1xD8J1Y42fINTm0ziK' => array( /// 进贤
),
'hwky0lx17041Ss1TwnF3kSujL7cTlwbiursc0nZpf0acmj0ZU2m15X4T99GEmOoL' => array( /// 嘻哈
),
'lNVL0tHmk0Maod2Bz1Q7g11ptboai9URghYu0egkk0rNez0Awdb1u2ne0qa7VmGR' => array( /// 0598游戏
),
'fGex0vtan0czcx2KQsJ4HtQs997rmxygouEK0BeCc0nvHk0mxdY1HtddNcfo5ifm' => array( /// 有味棋牌
),
'Fyjd04w1k0hSsZ1y0pl8nbPSbfK8DslquGvv0gxJd0tT3g0d7Of1cso0sL6eVZzM' => array( /// 广东
),
'vPlg0pjcs0khhr3EtuB0ypFF20bi5Rc7iPuH0wAZf0gFBH0kggh1cmyfjkdv0dbq' => array( /// 陈默友乐大厅
),
'm57z0hFgA0rNlb1en0f9Xyb37tpHz6Crc4Wn0Qsku0Vlgs0g79y1Z1VHkHlEa9CU' => array( /// 凡凡
),
'UgUp0mzfs0uney3jira1nujd6mf8z9XtkhEh0nxja0kTad0YfPL1dGeR9dGwOHta' => array( /// 睿龙互动
),
'VJJb0dhkf0ioRS2jhsh6akhVt91QVkwtrskL0Dvmp0hEOJ0ihLd1Ynz03cGH0x9K' => array( /// 丰城星星剑邑娱乐
),
'uQgZ0uehf0greK3Ryjz2pEemhp37eddjtyug0dnjH0SLmu0rCuk1rdfGbpCR56c1' => array( /// 袋鼠娱乐
),
'nMjx0zLil0jouv3EJsq3URziCdu9jtnCnjgu0snwd0kA1h0dsys1yn5xwb72VMj2' => array( /// 萍乡
),
'ljke0uLyb0Kgdv3hqpt41oyyHfycudo7Qbhf0zTri0gkxF0zVxQ1zs8pX15v53c2' => array( /// 永盛在线游戏
),
'nkTs0yPsV0jepu2kqFL5LafiuyF8fvoAmGoU0pJNt0hjkD0jdgq1pqThbcd8SEus' => array( /// H5
),
'GsbU0eMWu0Lttw3fDSc5jd5Iez5L1iuwGGBh0ZsQB0aoop0duZb1YOknit8Em236' => array( /// 友乐东乡翻天
),
'Gwuq0ljKm0uowP3srkp7dfhBK7b4mmnxFdsA0ltAc0Jgik0ZDcc1HvLwGzhm16D0' => array( /// 广州聚友
),
'dTdK0QuCR0tcGw3Ucaf6yJg7CPL0lylxxuRv0pPyD0iYyb0nEmW1PmClud27cp5H' => array( /// 慈溪聚友
),
'nJkC0ppYG0pbfv3XvnJ8g02603ddtwvkcdhz0ysai0yeiw0jdlv1Gb9y3j495fql' => array( /// 花色棋牌
),
'styc0JLaY0nIeu3xMPn9Uvjus5945pNjPUXY0JmKC0YLUt0ifHt1crgiTkjVCQ9S' => array( /// 永新游戏
),
'JkMw0wkez0xIRo4bcQv0ukNhzwDsLEk8cRqi0cBey0PnGe0nbMW1RETRvhZ1Y9Bb' => array( /// 古田棋牌
),
'Brhz0sSkV0umvh4geNS1ngkpvlWxhggfUKpU0zjlF0xpYB0ujov1KQuopCjs04uf' => array( /// 康鹏娱乐
),
);
/**
* @param ISQLCommand $command
* @param string $mask
* @param string $agentid
* @param string $channelid
* @param string $gameid
* @param string $starttime
* @param string $endtime
* @return string|null
*/
private function format_command_line($command, $mask, $agentid, $channelid, $gameid, $starttime, $endtime)
{
if ($command instanceof ISQLCommand)
{
$mask = str_ireplace('%agentid%', $command->GetIdentifiers($agentid, true), $mask);
$mask = str_ireplace('%channelid%', $command->GetIdentifiers($channelid, true), $mask);
$mask = str_ireplace('%gameid%', $command->GetIdentifiers($gameid, true), $mask);
$mask = str_ireplace('%starttime%', $command->GetIdentifiers($starttime, true), $mask);
$mask = str_ireplace('%endtime%', $command->GetIdentifiers($endtime, true), $mask);
}
return $mask;
}
private function sum_array($array)
{
$return = 0;
if (is_object($array))
$array = (array)$array;
if (is_array($array))
{
foreach ($array as $item)
{
if (is_object($item) || is_array($item))
$return += $this->sum_array($item);
elseif (is_numeric($item))
$return += intval($item);
else
$return += 0;
}
}
return $return;
}
private function extract_array($array)
{
$return = array();
if (is_object($array))
$array = (array)$array;
if (is_array($array))
{
foreach ($array as $item)
{
if (is_object($item) || is_array($item))
array_push($return, $this->extract_array($item));
else
array_push($return, $item);
}
}
else
{
array_push($return, $array);
}
return $return;
}
/**
* @note 获取报表列表
* @param RequestParameter $request
* @param ReturnParameter $return
* @return bool
*/
// public function querybatch($request, &$return)
// {
// /// 代理
// $agentid = isset($request->biz_content['agentid']) ? $request->biz_content['agentid'] : '';
// /// 渠道
// $channelid = isset($request->biz_content['channelid']) ? $request->biz_content['channelid'] : '';
// /// 游戏
// $gameid = isset($request->biz_content['gameid']) ? $request->biz_content['gameid'] : '';
// /// 是否需要默认数据(当天、昨天、当月)
// $needdata = isset($request->biz_content['needdata']) ? $request->biz_content['needdata'] : 0;
//
// if (empty($agentid))
// {
// $return->SetErrors(ERRORCODE_PARAMETERNOTFOUND, sprintf(ERRORINFO_PARAMETERNOTFOUND, 'agentid'));
// return false;
// }
//
// if (empty($channelid))
// {
// $return->SetErrors(ERRORCODE_PARAMETERNOTFOUND, sprintf(ERRORINFO_PARAMETERNOTFOUND, 'channelid'));
// return false;
// }
//
// $cmd = $this->NewMasterCommand();
//
// /// 如果不需要数据则返回列表
// if (0 == $needdata)
// {
// $return->biz_content = $cmd
// ->Select('reportid', 'reportname', 'agentid', 'channelid', 'reportcaption')
// ->From('ct_report_info')
// ->Where('(ifnull(agentid, \'\') = \'\' and ifnull(channelid, \'\') = \'\') or (agentid = ? and channelid = ?)')
// ->BindParameters($agentid, $channelid)
// ->Request();
//
// $return->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
// return $this->PDO_IsDone();
// }
//
// /// 如果需要数据则需要多查询出脚本
// $data = $cmd
// ->Select('reportid', 'reportname', 'agentid', 'channelid', 'reportcaption', 'commandline')
// ->From('ct_report_info')
// ->Where('(ifnull(agentid, \'\') = \'\' and ifnull(channelid, \'\') = \'\') or (agentid = ? and channelid = ?)')
// ->BindParameters($agentid, $channelid)
// ->Request();
// if (!$this->PDO_IsDone())
// {
// $return->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
// return false;
// }
//
// foreach ($data as &$item)
// {
// /// 取当前
// $starttime = date('Y-m-d');
// $endtime = date('Y-m-d');
// $commandline = $this->format_command_line($cmd, $item['commandline'], $agentid, $channelid, $gameid, $starttime, $endtime);
// $item['today'] = $this->sum_array($this->PDO_Request($commandline));
//
// /// 取昨天
// $starttime = date('Y-m-d', strtotime('-1 days'));
// $endtime = date('Y-m-d', strtotime('-1 days'));
// $commandline = $this->format_command_line($cmd, $item['commandline'], $agentid, $channelid, $gameid, $starttime, $endtime);
// $item['yesterday'] = $this->sum_array($this->PDO_Request($commandline));
//
// /// 取本月
// $starttime = date('Y-m-') . '01';
// $endtime = date('Y-m-') . '31';
// $commandline = $this->format_command_line($cmd, $item['commandline'], $agentid, $channelid, $gameid, $starttime, $endtime);
// $item['currmonth'] = $this->sum_array($this->PDO_Request($commandline));
//
// if (empty($item['today']))
// $item['today'] = 0;
// if (empty($item['yesterday']))
// $item['yesterday'] = 0;
// if (empty($item['currmonth']))
// $item['currmonth'] = 0;
//
// unset($item['commandline']);
// }
//
// $return->biz_content = $data;
// $return->SetErrors(ERRORCODE_SUCCESS, ERRORINFO_SUCCESS);
// return true;
// }
public function querybatch($request, &$return)
{
/// 代理
$agentid = isset($request->biz_content['agentid']) ? $request->biz_content['agentid'] : '';
/// 渠道
$channelid = isset($request->biz_content['channelid']) ? $request->biz_content['channelid'] : '';
/// 游戏
$gameid = isset($request->biz_content['gameid']) ? $request->biz_content['gameid'] : '';
/// 是否需要默认数据(当天、昨天、当月)
$needdata = isset($request->biz_content['needdata']) ? $request->biz_content['needdata'] : 0;
/// 是否需要显示所有数据
$alldata = isset($request->biz_content['alldata']) ? $request->biz_content['alldata'] : 0;
/// 代理id
$salesid = isset($request->biz_content['salesid']) ? $request->biz_content['salesid'] : 0;
if (empty($agentid)) {
$return->SetErrors(ERRORCODE_PARAMETERNOTFOUND, sprintf(ERRORINFO_PARAMETERNOTFOUND, 'agentid'));
return false;
}
if (empty($channelid)) {
$return->SetErrors(ERRORCODE_PARAMETERNOTFOUND, sprintf(ERRORINFO_PARAMETERNOTFOUND, 'channelid'));
return false;
}
$group = 0 == intval($alldata) ? ' and ifnull(is_admin, 0) = 0' : '';
$base_command = /** @lang text */ <<<EOL
select
a.agent_id, a.channel_id, a.report_id, a.report_name, a.report_caption, a.summary_type, a.command_line, a.is_mobile
from
(
select
b.agent_id agent_id, b.channel_id channel_id, a.report_id, a.report_name, a.report_caption, a.summary_type, a.command_line, a.is_mobile
from
ct_report_list a, ct_channel_list b
where
ifnull(a.agent_id, '') = '' and ifnull(a.channel_id, '') = ''{$group} and ifnull(a.is_enabled, 0) != 0
) a
left join
(
select
agent_id, channel_id, report_id, report_name, report_caption, summary_type, command_line, is_mobile
from
ct_report_list
where
ifnull(agent_id, '') != '' and ifnull(channel_id, '') != ''{$group} and ifnull(is_enabled, 0) != 0
) b
on a.agent_id = b.agent_id and a.channel_id = b.channel_id and a.report_name = b.report_name
where
b.report_id is null
union all
select
agent_id, channel_id, report_id, report_name, report_caption, summary_type, command_line, is_mobile
from
ct_report_list
where
ifnull(agent_id, '') != '' and ifnull(channel_id, '') != ''{$group} and ifnull(is_enabled, 0) != 0
EOL;
$cmd = $this->NewMasterCommand();
if (0 == $needdata) {
/// 如果不需要数据则返回列表
$command_line = /** @lang text */ <<<EOL
select
agent_id, channel_id, report_id, report_name, report_caption
from
(
{$base_command}
) a
where
a.agent_id = ? and a.channel_id = ? and a.is_mobile != 0
EOL;
$return->biz_content = $cmd->request($command_line, $agentid, $channelid);
} else {
$rate = $this->global_rate * empty($this->whitelist[$agentid . $channelid][$salesid]) ? 1 : $this->whitelist_rate;
/// 如果需要数据则需要多查询出脚本
$command_line = /** @lang text */ <<<EOL
select
a.agent_id, a.channel_id, b.sales_id, a.report_id, a.report_name, a.report_caption,
#cast(sum(case when date_format(b.report_date, '%Y-%m-%d') = date_format(now(), '%Y-%m-%d') then ifnull(b.report_data, 0) else 0 end) * {$rate} as decimal(18, 0)) today,
cast(sum(case when date_format(b.report_date, '%Y-%m-%d') = date_format(date_sub(now(), interval 1 day), '%Y-%m-%d') then ifnull(b.report_data, 0) else 0 end) * {$rate} as decimal(18, 0)) yesterday,
cast(
case a.summary_type
when 0 then sum(case when date_format(b.report_date, '%Y-%m') = date_format(now(), '%Y-%m') then ifnull(b.report_data, 0) else 0 end) # 累加
when 1 then max(case when date_format(b.report_date, '%Y-%m') = date_format(now(), '%Y-%m') then ifnull(b.report_data, 0) else 0 end) # 最大
when 2 then min(case when date_format(b.report_date, '%Y-%m') = date_format(now(), '%Y-%m') then ifnull(b.report_data, 0) else 0 end) # 最小
when 3 then avg(case when date_format(b.report_date, '%Y-%m') = date_format(now(), '%Y-%m') then ifnull(b.report_data, 0) else 0 end) # 平均
when 4 then (select ifnull(report_data, 0) from ct_report_info t where a.report_id = t.report_id and a.agent_id = t.agent_id and a.channel_id = t.channel_id and date_format(report_date, '%Y-%m') = date_format(now(), '%Y-%m') order by report_date asc limit 1) # 第一个值
when 5 then (select ifnull(report_data, 0) from ct_report_info t where a.report_id = t.report_id and a.agent_id = t.agent_id and a.channel_id = t.channel_id and date_format(report_date, '%Y-%m') = date_format(now(), '%Y-%m') order by report_date desc limit 1) # 最后一个值
else 0
end * {$rate} as decimal(18, 0)) currmonth
from
(
{$base_command}
) a
left join
(
select
a.agent_id, a.channel_id, a.sales_id, a.report_id, a.report_date, a.report_data
from
ct_report_info a
where
ifnull(a.sales_id, 0) in (0, ?)
) b on a.report_id = b.report_id and a.agent_id = b.agent_id and a.channel_id = b.channel_id
where
a.agent_id = ? and a.channel_id = ? and a.is_mobile != 0
group by
a.agent_id, a.channel_id, b.sales_id, a.report_id, a.report_name, a.report_caption
order by
a.report_id asc
EOL;
$return->biz_content = $cmd->request($command_line, $salesid, $agentid, $channelid);
}
$return->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
return $this->PDO_IsDone();
}
/**
* @note 获取报表详情
* @param RequestParameter $request
* @param ReturnParameter $return
* @return bool
*/
// public function querydetail($request, &$return)
// {
// /// 代理
// $agentid = isset($request->biz_content['agentid']) ? $request->biz_content['agentid'] : '';
// /// 渠道
// $channelid = isset($request->biz_content['channelid']) ? $request->biz_content['channelid'] : '';
// /// 游戏
// $gameid = isset($request->biz_content['gameid']) ? $request->biz_content['gameid'] : '';
// /// 报表id
// $reportid = isset($request->biz_content['reportid']) ? $request->biz_content['reportid'] : '';
// /// 起始时间
// $starttime = isset($request->biz_content['starttime']) ? $request->biz_content['starttime'] : '';
// /// 终止时间
// $endtime = isset($request->biz_content['endtime']) ? $request->biz_content['endtime'] : '';
//
//
// if (empty($agentid))
// {
// $return->SetErrors(ERRORCODE_PARAMETERNOTFOUND, sprintf(ERRORINFO_PARAMETERNOTFOUND, 'agentid'));
// return false;
// }
//
// if (empty($channelid))
// {
// $return->SetErrors(ERRORCODE_PARAMETERNOTFOUND, sprintf(ERRORINFO_PARAMETERNOTFOUND, 'channelid'));
// return false;
// }
//
// if (empty($reportid))
// {
// $return->SetErrors(ERRORCODE_PARAMETERNOTFOUND, sprintf(ERRORINFO_PARAMETERNOTFOUND, 'reportid'));
// return false;
// }
//
// $cmd = $this->NewMasterCommand();
// $return->biz_content = $cmd
// ->Select('reportid', 'reportname', 'agentid', 'channelid', 'reportcaption', 'commandline')
// ->From('ct_report_info')
// ->Where(array('reportid' => $reportid,))
// ->Request();
//
// if (!$this->PDO_IsDone())
// {
// $return->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
// return false;
// }
//
// if (empty($return->biz_content) || empty($return->biz_content[0]))
// {
// $return->SetErrors(ERRORCODE_NODATAERROR, ERRORINFO_NODATAERROR);
// return false;
// }
// $return->biz_content = $return->biz_content[0];
// $commandline = $this->format_command_line($cmd, $return->biz_content['commandline'], $agentid, $channelid, $gameid, $starttime, $endtime);
// //$report = array_values((array)$this->PDO_Request(commandline));
// $report = $this->PDO_Request($commandline);
// while (is_array($report))
// {
// if (1 == count($report))
// $report = current($report);
// else
// break;
// }
//
// unset($return->biz_content['commandline']);
// $return->biz_content['data'] = $this->extract_array($report);
//
// $return->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
// return $this->PDO_IsDone();
// }
public function querydetail($request, &$return)
{
/// 代理
$agentid = isset($request->biz_content['agentid']) ? $request->biz_content['agentid'] : '';
/// 渠道
$channelid = isset($request->biz_content['channelid']) ? $request->biz_content['channelid'] : '';
/// 游戏
$gameid = isset($request->biz_content['gameid']) ? $request->biz_content['gameid'] : '';
/// 代理id
$salesid = isset($request->biz_content['salesid']) ? $request->biz_content['salesid'] : 0;
/// 报表id
$reportid = isset($request->biz_content['reportid']) ? $request->biz_content['reportid'] : '';
/// 起始时间
$starttime = isset($request->biz_content['starttime']) ? $request->biz_content['starttime'] : '';
/// 终止时间
$endtime = isset($request->biz_content['endtime']) ? $request->biz_content['endtime'] : '';
if (empty($agentid)) {
$return->SetErrors(ERRORCODE_PARAMETERNOTFOUND, sprintf(ERRORINFO_PARAMETERNOTFOUND, 'agentid'));
return false;
}
if (empty($channelid)) {
$return->SetErrors(ERRORCODE_PARAMETERNOTFOUND, sprintf(ERRORINFO_PARAMETERNOTFOUND, 'channelid'));
return false;
}
if (empty($reportid)) {
$return->SetErrors(ERRORCODE_PARAMETERNOTFOUND, sprintf(ERRORINFO_PARAMETERNOTFOUND, 'reportid'));
return false;
}
$rate = $this->global_rate * empty($this->whitelist[$agentid . $channelid][$salesid]) ? 1 : $this->whitelist_rate;
$cmd = $this->NewMasterCommand();
$command_line = /** @lang text */"select report_date, cast(report_data * {$rate} as decimal(18, 0)) report_data from ct_report_info where report_id = ? and agent_id = ? and channel_id = ? and ifnull(sales_id, 0) in (0, ?)";
if (empty($starttime) && empty($endtime)) {
$command_line .= ' order by report_date desc';
$return->biz_content = $cmd->request($command_line, $reportid, $agentid, $channelid, $salesid);
} else {
$command_line .= ' and (report_date between ? and ?) order by report_date desc';
$return->biz_content = $cmd->request($command_line, $reportid, $agentid, $channelid, $salesid, $starttime, $endtime);
}
$return->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
return $this->PDO_IsDone();
}
/**
* @note 订单流水
* @param RequestParameter $request
* @param ReturnParameter $return
* @return bool
*/
public function querybillbatch($request, &$return)
{
/// 代理
$agentid = isset($request->biz_content['agentid']) ? $request->biz_content['agentid'] : '';
/// 渠道
$channelid = isset($request->biz_content['channelid']) ? $request->biz_content['channelid'] : '';
/// 起始时间
$starttime = isset($request->biz_content['starttime']) ? $request->biz_content['starttime'] : '';
/// 终止时间
$endtime = isset($request->biz_content['endtime']) ? $request->biz_content['endtime'] : '';
$page_index = isset($request->biz_content['page_index']) ? intval($request->biz_content['page_index']) : 1;
$page_size = isset($request->biz_content['page_size']) ? intval($request->biz_content['page_size']) : 50;
$start = ($page_index - 1) * $page_size ;
$stop = $page_size;
if (empty($agentid))
{
$return->SetErrors(ERRORCODE_PARAMETERNOTFOUND, sprintf(ERRORINFO_PARAMETERNOTFOUND, 'agentid'));
return false;
}
if (empty($channelid))
{
$return->SetErrors(ERRORCODE_PARAMETERNOTFOUND, sprintf(ERRORINFO_PARAMETERNOTFOUND, 'channelid'));
return false;
}
// $command = <<<EOL
//select
// a.sabu_playername, #用户昵称
// a.sabu_billcode, #订单号
// a.sabu_amount, #房卡数
// a.sabu_money, #订单金额
// a.sabu_createtime, #下单时间
// case ifnull(a.sabu_paystate, 0) when 0 then '未支付' when 1 then '已支付' else '未知' end sabu_paystate, #支付状态
// a.sabu_paymoney, #支付金额
// a.sabu_paytime, #支付时间
// case ifnull(a.sabu_billtype, 0) when 0 then '个人玩家购卡' when 1 then '个人代理购卡' else '未知' end sabu_billtype, #订单类型
// b1.agen_name agen_name1, #一级代理名
// a.sabu_pushrate1, #一级代理提成比例
// a.sabu_pushmoney1, #一级代理提成金额
// b2.agen_name agen_name2, #二级代理名
// a.sabu_pushrate2, #二级代理提成比例
// a.sabu_pushmoney2, #二级代理提成金额
// case ifnull(a.sabu_pushstate, 0) when 0 then '未提现' when 1 then '已提现' else '未知' end sabu_pushstate #提现状态
//from
// sales_buybill a
//left join
// agent b1
//on
// a.sabu_pushsalesid1 = b1.idx
//left join
// agent b2
//on
// a.sabu_pushsalesid2 = b2.idx
//where
// sabu_agentid = ? and
// sabu_channelid = ? and
// sabu_createtime between cast(? as datetime) and cast(? as datetime)
//LIMIT ?, ?
//EOL;
$command = /** @lang text */<<<EOL
select
nick_name sabu_playername, #用户昵称
order_id sabu_billcode, #订单号
product_amount sabu_amount, #房卡数
product_money sabu_money, #订单金额
order_time sabu_createtime, #下单时间
case ifnull(pay_status, 0) when 0 then '未支付' when 1 then '已支付' else '未知' end sabu_paystate, #支付状态
pay_money sabu_paymoney, #支付金额
pay_time sabu_paytime, #支付时间
case ifnull(order_type, 0) when 0 then '个人玩家购卡' when 1 then '个人代理购卡' else '未知' end sabu_billtype #订单类型
from
ct_order_info a
where
agent_id = ? and
channel_id = ? and
order_time between unix_timestamp(?) and unix_timestamp(?)
limit ?, ?
EOL;
$orderList = $this->PDO_Request($command, $agentid, $channelid, $starttime, $endtime, $start, $stop);
if(!is_array($orderList))
{
$return->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
return false;
}
// $dbCount = $this->PDO_Request(
// /** @lang text */
// '
// select
// a.sabu_playername
// from
// sales_buybill a left join
// agent b1 on a.sabu_pushsalesid1 = b1.idx left join
// agent b2 on a.sabu_pushsalesid2 = b2.idx
// where
// sabu_agentid = ? and sabu_channelid = ? and sabu_createtime between cast(? as datetime) and cast(? as datetime)',
// $agentid, $channelid, $starttime, $endtime);
// if(!is_array($dbCount))
// {
// $return->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
// return false;
// }
//
// $page_count = ceil(count($dbCount) / $page_size);
$command = /** @lang text */<<<EOL
select
count(0) c
from
ct_order_info
where
agent_id = ? and
channel_id = ? and
order_time between unix_timestamp(?) and unix_timestamp(?)
EOL;
$ret = $this->pdo_request($command, $agentid, $channelid, $starttime, $endtime);
$page_count = intval(@$ret[0]['c']);
$return->biz_content = array(
'list' => $orderList,
'page_index' => $page_index,
'page_size' => $page_size,
'page_count' => $page_count
);
return true;
}
/**
* 1今日新增人数茶水费
* 2昨日新增人数茶水费
* 3近7日新增人数茶水费
* 4近30日新增人数茶水费
* @param $request
* @param $return
* @return bool
*/
public function increasePeople($request, &$return)
{
$params = $request->biz_content;
$agentid = isset($params['agentid']) ? $params['agentid'] : '';
$channelid = isset($params['channelid']) ? $params['channelid'] : '';
$salesid = isset($params['salesid']) ? intval($params['salesid']) : '';
$type = isset($params['type']) ? intval($params['type']) : 1;
$day = isset($params['day']) ? intval($params['day']) : 0;
if (empty($agentid))
{
$return->SetErrors(ERRORCODE_AGENTIDERROR, ERRORINFO_AGENTIDERROR);
return false;
}
if (empty($channelid))
{
$return->SetErrors(ERRORCODE_CHANNELIDERROR, ERRORINFO_CHANNELIDERROR);
return false;
}
if (empty($salesid))
{
$return->SetErrors(ERRORCODE_SALESIDERROR, ERRORINFO_SALESIDERROR);
return false;
}
// 888 表示总代理查询,否则就是查自己的下级
if($type === 888) {
$where = '';
} else {
$where = " and saus_invitecode={$salesid}";
}
// 如果有传具体的天数
if($day !== 0) {
$sql = <<<EOL
SELECT
'近{$day}日' AS `NAME`,
count(1) AS `VALUE`
FROM
sales_user
WHERE
(
TO_DAYS(now()) - TO_DAYS(saus_firsttime) <= {$day}
)
AND saus_agentid = '{$agentid}'
AND saus_channelid = '{$channelid}'
{$where}
EOL;
}
else
{
$sql = <<<EOL
SELECT
'今日' AS `NAME`,
count(1) AS `VALUE`
FROM
sales_user
WHERE
saus_agentid = '{$agentid}'
AND saus_channelid = '{$channelid}'
AND date_format(saus_firsttime, '%Y-%m-%d') = curdate()
{$where}
union
SELECT
'昨日' AS `NAME`,
count(1) AS `VALUE`
FROM
sales_user
WHERE
(
TO_DAYS(now()) - TO_DAYS(saus_firsttime) = 1
)
AND saus_agentid = '{$agentid}'
AND saus_channelid = '{$channelid}'
{$where}
union
SELECT
'近7日' AS `NAME`,
count(1) AS `VALUE`
FROM
sales_user
WHERE
(
TO_DAYS(now()) - TO_DAYS(saus_firsttime) <= 7
)
AND saus_agentid = '{$agentid}'
AND saus_channelid = '{$channelid}'
{$where}
union
SELECT
'近30日' AS `NAME`,
count(1) AS `VALUE`
FROM
sales_user
WHERE
(
TO_DAYS(now()) - TO_DAYS(saus_firsttime) <= 30
)
AND saus_agentid = '{$agentid}'
AND saus_channelid = '{$channelid}'
{$where}
EOL;
}
$res = $this->PDO_Request($sql);
if (!$this->PDO_isdone())
{
$return->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
return false;
}
$return->biz_content = $res;
return true;
}
/**
* 操作类型 1购买房卡11购买星星
* @param $request
* @param $return
* @return bool
*/
public function buy($request, &$return)
{
$params = $request->biz_content;
$agentid = isset($params['agentid']) ? $params['agentid'] : '';
$channelid = isset($params['channelid']) ? $params['channelid'] : '';
$salesid = isset($params['salesid']) ? intval($params['salesid']) : '';
$type = isset($params['type']) ? intval($params['type']) : 1;
if (empty($agentid))
{
$return->SetErrors(ERRORCODE_AGENTIDERROR, ERRORINFO_AGENTIDERROR);
return false;
}
if (empty($channelid))
{
$return->SetErrors(ERRORCODE_CHANNELIDERROR, ERRORINFO_CHANNELIDERROR);
return false;
}
if (empty($salesid))
{
$return->SetErrors(ERRORCODE_SALESIDERROR, ERRORINFO_SALESIDERROR);
return false;
}
// 888 表示总代理查询,否则就是查自己的下级
if($type === 888) {
$where = '';
} else {
$where = " and parentid={$salesid}";
}
$sql = <<<EOL
SELECT
'今日' AS `NAME`,
ifnull(sum(money), 0) AS `VALUE`
FROM
ct_user_process_log
WHERE
to_agent = '{$agentid}'
AND to_channel = '{$channelid}'
AND oper_type in (1,11)
AND date_format(FROM_UNIXTIME(oper_time), '%Y-%m-%d') = curdate()
{$where}
union
SELECT
'昨日' AS `NAME`,
ifnull(sum(money), 0) AS `VALUE`
FROM
ct_user_process_log
WHERE
(
TO_DAYS(now()) - TO_DAYS(FROM_UNIXTIME(oper_time)) = 1
)
AND to_agent = '{$agentid}'
AND to_channel = '{$channelid}'
AND oper_type in (1,11)
{$where}
union
SELECT
'近7日' AS `NAME`,
ifnull(sum(money), 0) AS `VALUE`
FROM
ct_user_process_log
WHERE
(
TO_DAYS(now()) - TO_DAYS(FROM_UNIXTIME(oper_time)) <= 7
)
AND to_agent = '{$agentid}'
AND to_channel = '{$channelid}'
AND oper_type in (1,11)
{$where}
union
SELECT
'近30日' AS `NAME`,
ifnull(sum(money), 0) AS `VALUE`
FROM
ct_user_process_log
WHERE
(
TO_DAYS(now()) - TO_DAYS(FROM_UNIXTIME(oper_time)) <= 30
)
AND to_agent = '{$agentid}'
AND to_channel = '{$channelid}'
AND oper_type in (1,11)
{$where}
EOL;
$res = $this->PDO_Request($sql);
if (!$this->PDO_isdone())
{
$return->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
return false;
}
$return->biz_content = $res;
return true;
}
}