1266 lines
41 KiB
Plaintext
1266 lines
41 KiB
Plaintext
<?php
|
||
/**
|
||
* Created by PhpStorm.
|
||
* User: bahamut
|
||
* Date: 2018/1/15
|
||
* Time: 14:03
|
||
*/
|
||
|
||
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';
|
||
|
||
/*******************************************************************************
|
||
* 当使用json字符串标记参数时,支援的属性为: *
|
||
* name: 参数名 *
|
||
* type: 参数类型 *
|
||
* mask: 参数格式 *
|
||
* value: 参数值(最终确定的值) *
|
||
* default: 参数默认值 *
|
||
* options: 参数可选值(enum类型有效) *
|
||
* script: 参数要执行的脚本(sql脚本类型有效) *
|
||
* returnfield: 参数返回字段名(sql脚本类型有效) *
|
||
*******************************************************************************
|
||
* 参数类型可选: *
|
||
* unknown: 未知类型 *
|
||
* string: 字符串类型 *
|
||
* number: 数值类型 *
|
||
* enum: 枚举类型(options有效并忽略mask属性) *
|
||
* date: 日期类型(mask固定为yyyy-mm-dd) *
|
||
* time: 时间类型(mask固定为hh:nn:ss) *
|
||
* datetime: 日期时间类型(mask固定为yyyy-mm-dd hh:nn:ss) *
|
||
* sql: sql脚本类型(script和returnfield有效并忽略mask属性) *
|
||
*******************************************************************************/
|
||
class ReportParameter
|
||
{
|
||
const PARAMETERTYPE_UNKNOWN = 'unknown'; /// 未知类型
|
||
const PARAMETERTYPE_STRING = 'string'; /// 字符串类型
|
||
const PARAMETERTYPE_NUMBER = 'number'; /// 数值类型
|
||
const PARAMETERTYPE_ENUM = 'enum'; /// 枚举类型(options有效并忽略mask属性)
|
||
const PARAMETERTYPE_DATE = 'date'; /// 日期类型(mask固定为yyyy-mm-dd)
|
||
const PARAMETERTYPE_TIME = 'time'; /// 时间类型(mask固定为hh:nn:ss)
|
||
const PARAMETERTYPE_DATETIME = 'datetime'; /// 日期时间类型(mask固定为yyyy-mm-dd hh:nn:ss)
|
||
const PARAMETERTYPE_SQL = 'sql'; /// sql脚本类型(script和returnfield有效并忽略mask属性)
|
||
|
||
/**
|
||
* @note 参数名
|
||
* @var string
|
||
*/
|
||
public $name;
|
||
/**
|
||
* @note 参数类型
|
||
* @var string
|
||
*/
|
||
public $type;
|
||
/**
|
||
* @note 参数格式
|
||
* @var string
|
||
*/
|
||
public $mask;
|
||
/**
|
||
* @note 参数值
|
||
* @var mixed
|
||
*/
|
||
public $value;
|
||
/**
|
||
* @note 参数默认值
|
||
* @var mixed
|
||
*/
|
||
public $default;
|
||
/**
|
||
* @note 参数可选值(enum类型有效)
|
||
* @var array|mixed
|
||
*/
|
||
public $options;
|
||
/**
|
||
* @note 参数要执行的脚本(sql脚本类型有效)
|
||
* @var string
|
||
*/
|
||
public $script;
|
||
/**
|
||
* @note 参数返回字段名(sql脚本类型有效)
|
||
* @var string
|
||
*/
|
||
public $returnfield;
|
||
|
||
public function __construct($String)
|
||
{
|
||
$this->name = null;
|
||
$this->type = null;
|
||
$this->mask = null;
|
||
$this->value = null;
|
||
$this->default = null;
|
||
$this->options = null;
|
||
$this->script = null;
|
||
$this->returnfield = null;
|
||
|
||
$this->FromString($String);
|
||
}
|
||
|
||
|
||
public function FromArray($Array)
|
||
{
|
||
if (is_null($Array))
|
||
return false;
|
||
if (is_object($Array))
|
||
$Array = (array)$Array;
|
||
if (!is_array($Array))
|
||
{
|
||
$this->Name = strval($Array);
|
||
return true;
|
||
}
|
||
|
||
$Reflect = new ReflectionClass($this);
|
||
foreach($Array as $Key => $Value)
|
||
{
|
||
//if (!$Reflect->HasProperty($Key))
|
||
// continue;
|
||
if ($Property = $Reflect->GetProperty($Key))
|
||
{
|
||
//if ($Property->IsPublic())
|
||
$Property->SetValue($this, $Value);
|
||
}
|
||
}
|
||
|
||
return true;
|
||
}
|
||
|
||
|
||
public function FromString($String)
|
||
{
|
||
if (!$this->FromArray(JsonStringToJsonObject( strtr($String, array("\r" => ' ', "\n" => ' ', )))))
|
||
$this->name = empty($String) ? '' : $String;
|
||
|
||
return true;
|
||
}
|
||
}
|
||
|
||
|
||
class report extends BaseMethod
|
||
{
|
||
private $sql_table = 'ct_report_list';
|
||
|
||
/**
|
||
* @param $String
|
||
* @param int $SplitLength
|
||
* @return array|bool
|
||
*/
|
||
function utf8_str_split($String, $SplitLength = 1)
|
||
{
|
||
if (!preg_match('/^[0-9]+$/', $SplitLength) || $SplitLength < 1)
|
||
return false;
|
||
|
||
$Length = mb_strlen($String, 'UTF-8');
|
||
if ($Length <= $SplitLength)
|
||
return array($String);
|
||
|
||
preg_match_all('/.{' . $SplitLength . '}|[^x00]{1,' . $SplitLength . '}$/us', $String, $Result);
|
||
|
||
return $Result[0];
|
||
}
|
||
|
||
/**
|
||
* Convert a string to an array
|
||
* @param string $String
|
||
* @param integer $SplitLength
|
||
* @param string $Charset
|
||
* @return array of char
|
||
*/
|
||
function mb_str_split($String, $SplitLength = 1 ,$Charset = USEDCHARSET)
|
||
{
|
||
if (strcasecmp($Charset, 'utf-8') == 0)
|
||
return $this->utf8_str_split($String, $SplitLength);
|
||
elseif (func_num_args() == 1)
|
||
return preg_split('/(?<!^)(?!$)/u', $String);
|
||
|
||
if ($SplitLength < 1)
|
||
return false;
|
||
|
||
$Length = mb_strlen($String, $Charset);
|
||
$Result = array();
|
||
for ($Index = 0; $Index < $Length; $Index += $SplitLength)
|
||
{
|
||
$Result[] = mb_substr($String, $Index, $SplitLength, $Charset);
|
||
}
|
||
|
||
return $Result;
|
||
}
|
||
|
||
|
||
|
||
/*******************************************************************************
|
||
* 函数名: ParseSqlCommand *
|
||
* 功 能: 解析sql脚本并分离出参数列表 *
|
||
* 参 数: *
|
||
* pszSqlCommand: 要处理的sql语句 *
|
||
* pSqlParameters: 处理后的参数列表 *
|
||
* pszForwadChars: 参数前缀字符集合 *
|
||
* pszReplaceIdentifier: 用来替换的参数占位符(默认为问号,一般不用修改) *
|
||
* 返回值: *
|
||
* 成功返回TRUE, 否则返回FALSE *
|
||
*******************************************************************************
|
||
*******************************************************************************
|
||
* 当使用json字符串标记参数时,支援的属性为: *
|
||
* name: 参数名 *
|
||
* type: 参数类型 *
|
||
* mask: 参数格式 *
|
||
* value: 参数值(最终确定的值) *
|
||
* default: 参数默认值 *
|
||
* options: 参数可选值(enum类型有效) *
|
||
* script: 参数要执行的脚本(sql脚本类型有效) *
|
||
* returnfield: 参数返回字段名(sql脚本类型有效) *
|
||
*******************************************************************************
|
||
* 参数类型可选: *
|
||
* unknown: 未知类型 *
|
||
* string: 字符串类型 *
|
||
* number: 数值类型 *
|
||
* enum: 枚举类型(options有效并忽略mask属性) *
|
||
* date: 日期类型(mask固定为yyyy-mm-dd) *
|
||
* time: 时间类型(mask固定为hh:nn:ss) *
|
||
* datetime: 日期时间类型(mask固定为yyyy-mm-dd hh:nn:ss) *
|
||
* sql: sql脚本类型(script和returnfield有效并忽略mask属性) *
|
||
*******************************************************************************
|
||
* @param string $SqlCommand sql语句
|
||
* @param array $SqlParameters 返回的参数列表
|
||
* @param string $ForwadChars 前导字符,作为判断参数的起始字符
|
||
* @param string $ReplaceIdentifier 替换后的参数占位符
|
||
* @return bool
|
||
* @throws
|
||
*******************************************************************************/
|
||
private function ParseSqlCommand(
|
||
&$SqlCommand, /// sql语句
|
||
&$SqlParameters, /// 返回的参数列表
|
||
$ForwadChars = '&:', /// 前导字符,作为判断参数的起始字符
|
||
$ReplaceIdentifier = '?' /// 替换后的参数占位符
|
||
)
|
||
{
|
||
$SqlParameters = array();
|
||
|
||
if (empty($SqlCommand))
|
||
return false;
|
||
|
||
$CommandLength = mb_strlen($SqlCommand, USEDCHARSET);
|
||
$Result = '';
|
||
/// 前导字符,作为判断参数的起始字符
|
||
$StringDelimiter = "{$ForwadChars}`'\"-/\0";
|
||
/// 分割字符
|
||
$NameDelimiter = "{$ForwadChars} ,;()[]{}`=<>\r\n";
|
||
///
|
||
$CurrentIndex = 0;
|
||
$StartIndex = 0;
|
||
//$SqlCommandArray = str_split($SqlCommand);
|
||
$SqlCommandArray = $this->mb_str_split($SqlCommand, 1, USEDCHARSET);
|
||
//$SqlCommandArray = $this->utf8_str_split($SqlCommand);
|
||
|
||
while ($CurrentIndex < $CommandLength)
|
||
{
|
||
$c = $SqlCommandArray[$CurrentIndex];
|
||
//$c = mb_substr($SqlCommand, $CurrentIndex, 1, USEDCHARSET);
|
||
|
||
/// 先过滤掉不需要判断的字符,一直碰到参数的前导字符或者是引号
|
||
while ($CurrentIndex < $CommandLength)
|
||
{
|
||
$c = $SqlCommandArray[$CurrentIndex];
|
||
//$c = mb_substr($SqlCommand, $CurrentIndex, 1, USEDCHARSET);
|
||
if (mb_strstr($StringDelimiter, $c, false, USEDCHARSET))
|
||
break;
|
||
else
|
||
$CurrentIndex++;
|
||
}
|
||
|
||
switch ($c)
|
||
{
|
||
/// 字符串结束
|
||
case "\0":
|
||
case '':
|
||
break;
|
||
|
||
/// 引号表示字符串
|
||
case '`':
|
||
case '\'':
|
||
case '"':
|
||
/// 记录下这个标记,表示现在是字符串开始;再碰到一个同样的标记表示字符串结束。
|
||
$cLiteral = $c;
|
||
|
||
do
|
||
{
|
||
/// 快速跳过字符串内容
|
||
$CurrentIndex++;
|
||
$c = $SqlCommandArray[$CurrentIndex];
|
||
//$c = mb_substr($SqlCommand, $CurrentIndex, 1, USEDCHARSET);
|
||
if ($cLiteral == $c)
|
||
break;
|
||
} while ($CurrentIndex < $CommandLength);
|
||
$CurrentIndex++;
|
||
break;
|
||
|
||
default:
|
||
$CurrentString = mb_substr($SqlCommand, $CurrentIndex, 2, USEDCHARSET);
|
||
if (0 == strcasecmp($CurrentString, '--')) /// 单行注释
|
||
{
|
||
$CurrentIndex += 2;
|
||
$c = $SqlCommandArray[$CurrentIndex];
|
||
//$c = mb_substr($SqlCommand, $CurrentIndex, 1, USEDCHARSET);
|
||
|
||
/// 迅速跳过注释行
|
||
while ($CurrentIndex < $CommandLength)
|
||
{
|
||
if ("\r" == $c || "\n" == $c)
|
||
{
|
||
while ("\r" == $c || "\n" == $c)
|
||
{
|
||
$CurrentIndex++;
|
||
$c = $SqlCommandArray[$CurrentIndex];
|
||
//$c = mb_substr($SqlCommand, $CurrentIndex, 1, USEDCHARSET);
|
||
}
|
||
break;
|
||
}
|
||
else
|
||
{
|
||
$CurrentIndex++;
|
||
$c = $SqlCommandArray[$CurrentIndex];
|
||
//$c = mb_substr($SqlCommand, $CurrentIndex, 1, USEDCHARSET);
|
||
}
|
||
}
|
||
break;
|
||
}
|
||
else if (0 == strcasecmp($CurrentString, '/*')) /// 多行注释
|
||
{
|
||
$CurrentIndex += 2;
|
||
/// 迅速跳过注释内容
|
||
while ($CurrentIndex < $CommandLength)
|
||
{
|
||
$CurrentString = mb_substr($SqlCommand, $CurrentIndex, 2, USEDCHARSET);
|
||
if (0 == strcasecmp($CurrentString, '*/'))
|
||
{
|
||
$CurrentIndex += 2;
|
||
break;
|
||
}
|
||
else
|
||
{
|
||
$CurrentIndex++;
|
||
}
|
||
}
|
||
break;
|
||
}
|
||
else if (mb_strstr($ForwadChars, $c, false, USEDCHARSET))
|
||
{
|
||
$CurrentIndex++;
|
||
$c = $SqlCommandArray[$CurrentIndex];
|
||
//$c = mb_substr($SqlCommand, $CurrentIndex, 1, USEDCHARSET);
|
||
|
||
if (mb_strstr($ForwadChars, $c, false, USEDCHARSET))
|
||
{
|
||
$CurrentIndex++;
|
||
$c = $SqlCommandArray[$CurrentIndex];
|
||
//$c = mb_substr($SqlCommand, $CurrentIndex, 1, USEDCHARSET);
|
||
}
|
||
|
||
$Result .= mb_substr($SqlCommand, $StartIndex, $CurrentIndex - $StartIndex - 1) . $ReplaceIdentifier;
|
||
if ('{' == $c) /// 处理json字符串表示的参数
|
||
{
|
||
$ParameterIndex = $CurrentIndex;
|
||
$JsonFlagCount = 0;
|
||
|
||
while ($CurrentIndex < $CommandLength)
|
||
{
|
||
$c = $SqlCommandArray[$CurrentIndex];
|
||
//$c = mb_substr($SqlCommand, $CurrentIndex, 1, USEDCHARSET);
|
||
$CurrentIndex++;
|
||
switch ($c)
|
||
{
|
||
case '{':
|
||
$JsonFlagCount++;
|
||
break;
|
||
case '}':
|
||
$JsonFlagCount--;
|
||
break;
|
||
}
|
||
if (0 == $JsonFlagCount)
|
||
break;
|
||
}
|
||
}
|
||
else /// 非json表示的参数
|
||
{
|
||
$cLiteral = '';
|
||
if (mb_strstr('`\'"', $c, false, USEDCHARSET))
|
||
{
|
||
$cLiteral = $c;
|
||
$CurrentIndex++;
|
||
}
|
||
|
||
$ParameterIndex = $CurrentIndex;
|
||
while ($CurrentIndex < $CommandLength)
|
||
{
|
||
$c = $SqlCommandArray[$CurrentIndex];
|
||
//$c = mb_substr($SqlCommand, $CurrentIndex, 1, USEDCHARSET);
|
||
if (($cLiteral == $c) || ('' == $cLiteral && mb_strstr($NameDelimiter, $c, false, USEDCHARSET)))
|
||
break;
|
||
$CurrentIndex++;
|
||
}
|
||
}
|
||
|
||
$Parameter = mb_substr($SqlCommand, $ParameterIndex, $CurrentIndex - $ParameterIndex, USEDCHARSET);
|
||
array_push($SqlParameters, new ReportParameter($Parameter));
|
||
$StartIndex = $CurrentIndex;
|
||
}
|
||
break;
|
||
}
|
||
}
|
||
|
||
$Result .= mb_substr($SqlCommand, $StartIndex, $CurrentIndex - $StartIndex);
|
||
$SqlCommand = $Result;
|
||
return true;
|
||
}
|
||
|
||
|
||
/**
|
||
* 获取菜单
|
||
* @param RequestParameter $request
|
||
* @param ReturnParameter $return
|
||
* @return bool
|
||
*/
|
||
public function getMenus($request, &$return)
|
||
{
|
||
try {
|
||
$biz_content = $request->biz_content;
|
||
//查询用户
|
||
$admin_id = isset($biz_content['admin_id']) ? $biz_content['admin_id'] : false; // 管理员id
|
||
|
||
if(!$admin_id){
|
||
$return->SetErrors(ERRORCODE_INPARAMERROR, ERRORINFO_INPARAMERROR);
|
||
return false;
|
||
}
|
||
|
||
$admin = $this->PDO_Request(/** @lang text */'
|
||
SELECT
|
||
level
|
||
FROM ct_manager_info m
|
||
WHERE `login_id` = ? AND `is_enabled` = ?;', $admin_id, 1);
|
||
if (!$this->pdo_isdone())
|
||
{
|
||
$return->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
|
||
return false;
|
||
}
|
||
if (!$admin) {
|
||
$return->SetErrors(ERRORCODE_NOPOWERERROR, ERRORINFO_NOPOWERERROR);
|
||
return false;
|
||
}
|
||
|
||
$cmd = $this->NewMasterCommand();
|
||
// 获取所有报表脚本信息
|
||
$items = $this->PDO_Request(/** @lang text */"
|
||
select
|
||
a.id as cate_id, a.name, a.icon,
|
||
b.report_id, b.report_name, b.command_line, b.url, b.desc
|
||
from ct_report_cate as a
|
||
left join {$this->sql_table} as b
|
||
on
|
||
a.`id` = b.`cate_id`
|
||
inner join ct_manager_auth c
|
||
on b.report_id = c.report_id
|
||
where
|
||
a.`status` = 1 and
|
||
b.`is_enabled` = 1 and
|
||
c.login_id = ? and
|
||
c.status = 1
|
||
group by
|
||
cate_id, report_id", $admin_id);
|
||
|
||
$menu = array();
|
||
foreach($items as $key=>$val) {
|
||
// 主菜单部分
|
||
$menu[$val['cate_id']]['id'] = $val['cate_id'];
|
||
$menu[$val['cate_id']]['name'] = $val['name'];
|
||
$menu[$val['cate_id']]['icon'] = $val['icon'];
|
||
|
||
$this->ParseSqlCommand($val['command_line'], $SqlParameters);
|
||
//$SqlParameters = json_decode( json_encode( $SqlParameters),true);
|
||
foreach ($SqlParameters as $sk => $sv) {
|
||
// 脚本处理
|
||
if (strcasecmp($sv->type, 'sql') == 0) {
|
||
$replace_admin_id = $cmd->getidentifiers($admin_id, true); // 处理sql引号
|
||
$script = str_replace('[%adminId%]', $replace_admin_id, $sv->script);
|
||
$result = $this->PDO_Request($script);
|
||
if (!$this->pdo_isdone())
|
||
{
|
||
$return->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
|
||
return false;
|
||
}
|
||
$SqlParameters[$sk]->options = $result;
|
||
unset($SqlParameters[$sk]->script);
|
||
}
|
||
}
|
||
|
||
// 子菜单部分
|
||
$menu[$val['cate_id']]['child'][] = [
|
||
'report_id' => $val['report_id'],
|
||
'report_name' => $val['report_name'],
|
||
'url' => $val['url'],
|
||
'desc' => '',
|
||
'values' => $SqlParameters,
|
||
];
|
||
}
|
||
|
||
// 5、数据返回部分
|
||
$return->biz_content = $menu;
|
||
return true;
|
||
}
|
||
catch (Exception $e) {
|
||
$return->SetErrors($e->getCode(), $e->getMessage());
|
||
return false;
|
||
}
|
||
}
|
||
|
||
|
||
/**
|
||
* 处理查询
|
||
* @param RequestParameter $request
|
||
* @param ReturnParameter $return
|
||
* @return bool
|
||
*/
|
||
public function getReport($request, &$return)
|
||
{
|
||
try {
|
||
// 获取具体id
|
||
$biz_content = $request->biz_content;
|
||
$report_id = isset($biz_content['report_id']) ? $biz_content['report_id'] : false; // 报表id
|
||
$admin_id = isset($biz_content['admin_id']) ? $biz_content['admin_id'] : false; // 管理员id
|
||
$channel = isset($biz_content['channel']) ? $biz_content['channel'] : false; // 指定渠道key
|
||
if(!$report_id || !$admin_id){
|
||
$return->SetErrors(ERRORCODE_INPARAMERROR, ERRORINFO_INPARAMERROR);
|
||
return false;
|
||
}
|
||
//查询用户
|
||
$admin = $this->PDO_Request(/** @lang text */'
|
||
SELECT
|
||
LEVEL
|
||
FROM
|
||
ct_manager_info m
|
||
INNER JOIN
|
||
ct_manager_auth b
|
||
ON
|
||
m.login_id = b.login_id
|
||
WHERE
|
||
b.login_id = ? AND
|
||
b.report_id = ? AND
|
||
b.status = 1 AND
|
||
m.is_enabled = 1;', $admin_id, $report_id);
|
||
if (!$this->pdo_isdone())
|
||
{
|
||
$return->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
|
||
return false;
|
||
}
|
||
if (!$admin) {
|
||
$return->SetErrors(ERRORCODE_NOPOWERERROR, ERRORINFO_NOPOWERERROR);
|
||
return false;
|
||
}
|
||
|
||
$item = $this->PDO_Request(/** @lang text */'
|
||
SELECT
|
||
report_id, report_name, command_line, url
|
||
FROM '.$this->sql_table.'
|
||
WHERE report_id = ?;
|
||
', $report_id);
|
||
if (!$this->pdo_isdone())
|
||
{
|
||
$return->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
|
||
return false;
|
||
}
|
||
|
||
|
||
$SqlCommand = $item[0]['command_line'];
|
||
# 分页信息
|
||
$page_index = empty($biz_content['page_index']) ? 1 : intval($biz_content['page_index']); // 当前页
|
||
$page_size = empty($biz_content['page_size']) ? 20: intval($biz_content['page_size']); // 单页容量
|
||
$start = ($page_index - 1) * $page_size;
|
||
if (!empty($page_index))
|
||
$strPage = " LIMIT {$start},{$page_size} ";
|
||
$SqlCommand = str_replace("[%strPage%]", $strPage, $SqlCommand);
|
||
$cmd=$this->NewMasterCommand();
|
||
$replace_admin_id = $cmd->getidentifiers($admin_id, true); // 处理sql引号
|
||
$SqlCommand = str_replace('[%adminId%]', $replace_admin_id, $SqlCommand);
|
||
$this->ParseSqlCommand($SqlCommand, $SqlParameters);
|
||
$SqlParameters = json_decode( json_encode( $SqlParameters),true);
|
||
|
||
$params = []; // 查询参数
|
||
foreach ($SqlParameters as $key => $value) {
|
||
if($value['type'] === 'sql') {
|
||
// 脚本处理
|
||
$result = $this->PDO_Request(/** @lang text */
|
||
$value['script']);
|
||
if (!$this->pdo_isdone())
|
||
{
|
||
$return->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
|
||
return false;
|
||
}
|
||
if(DEBUG_MODE){
|
||
//按指定渠道查询
|
||
if($channel){
|
||
if(!strstr($result[0]['value'], $channel)){
|
||
$return->SetErrors(ERRORCODE_NOPOWERERROR, ERRORINFO_NOPOWERERROR);
|
||
return false;
|
||
}
|
||
}else{
|
||
$value['default'] = $result[0]['value'];
|
||
}
|
||
}
|
||
}
|
||
$params[] = isset($biz_content[$value['returnfield']]) ? $biz_content[$value['returnfield']] : $value['default'];
|
||
}
|
||
|
||
// 最终查询
|
||
$items = $this->PDO_Request(/** @lang text */
|
||
$SqlCommand, $params);
|
||
if (!$this->pdo_isdone())
|
||
{
|
||
$return->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
|
||
return false;
|
||
}
|
||
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;
|
||
}
|
||
}
|
||
}else{
|
||
$data = [];
|
||
}
|
||
|
||
// 5、数据返回部分
|
||
$return->biz_content = $data;
|
||
return true;
|
||
}
|
||
|
||
catch (Exception $e) {
|
||
$return->SetErrors($e->getCode(), $e->getMessage());
|
||
return false;
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 导出报表
|
||
* @param RequestParameter $request
|
||
* @param ReturnParameter $return
|
||
* @return bool
|
||
*/
|
||
public function exportReport($request, &$return)
|
||
{
|
||
// 获取具体id
|
||
$biz_content = $request->biz_content;
|
||
$report_id = isset($biz_content['report_id']) ? $biz_content['report_id'] : false; // 报表id
|
||
$admin_id = isset($biz_content['admin_id']) ? $biz_content['admin_id'] : false; // 管理员id
|
||
$channel = isset($biz_content['channel']) ? $biz_content['channel'] : false; // 指定渠道key
|
||
if(!$report_id || !$admin_id){
|
||
$return->SetErrors(ERRORCODE_INPARAMERROR, ERRORINFO_INPARAMERROR);
|
||
return false;
|
||
}
|
||
//查询用户
|
||
$admin = $this->PDO_Request(/** @lang text */'
|
||
SELECT
|
||
LEVEL
|
||
FROM
|
||
ct_manager_info m
|
||
INNER JOIN
|
||
ct_manager_auth b
|
||
ON
|
||
m.login_id = b.login_id
|
||
WHERE
|
||
b.login_id = ? AND
|
||
b.report_id = ? AND
|
||
b.status = 1 AND
|
||
m.is_enabled = 1;', $admin_id, $report_id);
|
||
if (!$this->pdo_isdone())
|
||
{
|
||
$return->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
|
||
return false;
|
||
}
|
||
if (!$admin) {
|
||
$return->SetErrors(ERRORCODE_NOPOWERERROR, ERRORINFO_NOPOWERERROR);
|
||
return false;
|
||
}
|
||
|
||
$item = $this->PDO_Request(/** @lang text */'
|
||
SELECT
|
||
report_id, report_name, command_line, url
|
||
FROM '.$this->sql_table.'
|
||
WHERE report_id = ?;
|
||
', $report_id);
|
||
if (!$this->pdo_isdone())
|
||
{
|
||
$return->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
|
||
return false;
|
||
}
|
||
$SqlCommand = $item[0]['command_line'];
|
||
$SqlCommand = str_replace("[%strPage%]", '', $SqlCommand); // 去掉分页
|
||
$cmd=$this->NewMasterCommand();
|
||
$replace_admin_id = $cmd->getidentifiers($admin_id, true); // 处理sql引号
|
||
$SqlCommand = str_replace('[%adminId%]', $replace_admin_id, $SqlCommand);
|
||
$this->ParseSqlCommand($SqlCommand, $SqlParameters);
|
||
$SqlParameters = json_decode( json_encode( $SqlParameters),true);
|
||
|
||
$params = []; // 查询参数
|
||
foreach ($SqlParameters as $key => $value) {
|
||
if($value['type'] === 'sql') {
|
||
// 脚本处理
|
||
$result = $this->PDO_Request(/** @lang text */
|
||
$value['script']);
|
||
if (!$this->pdo_isdone())
|
||
{
|
||
$return->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
|
||
return false;
|
||
}
|
||
if(DEBUG_MODE){
|
||
//按指定渠道查询
|
||
if($channel){
|
||
if(!strstr($result[0]['value'], $channel)){
|
||
$return->SetErrors(ERRORCODE_NOPOWERERROR, ERRORINFO_NOPOWERERROR);
|
||
return false;
|
||
}
|
||
}else{
|
||
$value['default'] = $result[0]['value'];
|
||
}
|
||
}
|
||
}
|
||
$params[] = isset($biz_content[$value['returnfield']]) ? $biz_content[$value['returnfield']] : $value['default'];
|
||
}
|
||
$Helper = $this->GetMasterDatabase();
|
||
// $Helper->ExportToFile('test', $SqlCommand, $params);
|
||
$Helper->ExportToBrowser($SqlCommand, $params);
|
||
die;
|
||
}
|
||
|
||
/**
|
||
* 导出报表工具方法
|
||
* @param RequestParameter $request
|
||
* @param ReturnParameter $return
|
||
* @return bool
|
||
*/
|
||
public function exportData($confg)
|
||
{
|
||
$name = isset($confg['name']) ? $confg['name'] : time(); // 导出文件名
|
||
$body = isset($confg['body'])&&is_array($confg['body']) ? $confg['body'] : false; // 表格结构
|
||
$data = isset($confg['data'])&&is_array($confg['data']) ? $confg['data'] : false; // 表数据
|
||
$type = isset($confg['type']) ? $confg['type'] : 'xls'; // 导出拓展名
|
||
|
||
if (!$body || !$data) {
|
||
return false;
|
||
}
|
||
$table = '';
|
||
$table .= '<table>
|
||
<thead>
|
||
<tr>';
|
||
foreach ($body as $v) {
|
||
$table .= "<td class='name'>{$v}</td>";
|
||
}
|
||
|
||
$table .= '</tr>
|
||
</thead>
|
||
<tbody>';
|
||
foreach ($data as $k=>$v) {
|
||
$v = array_values($v);
|
||
$table .= "<tr>";
|
||
foreach ($body as $bk=>$bv) {
|
||
$table .= "<td class='name'>{$v[$bk]}</td>";
|
||
}
|
||
$table .= " </tr>";
|
||
}
|
||
$table .= '</tbody>
|
||
</table>';
|
||
|
||
// 通过header头控制输出excel表格
|
||
header("Pragma: public");
|
||
header("Expires: 0");
|
||
header("Cache-Control:must-revalidate, post-check=0, pre-check=0");
|
||
header("Content-Type:application/force-download");
|
||
header("Content-Type:application/vnd.ms-execl");
|
||
header("Content-Type:application/octet-stream");
|
||
header("Content-Type:application/download");
|
||
header('Content-Disposition:attachment;filename='.$name.'.'.$type);
|
||
header("Content-Transfer-Encoding:binary");
|
||
echo $table;
|
||
die;
|
||
}
|
||
|
||
/**
|
||
* 返回营业收入的sql语句
|
||
*/
|
||
/*private function _businessIncomeSql($start_time, $end_time)
|
||
{
|
||
$business_income_sql = <<<EOL
|
||
select
|
||
|
||
|
||
|
||
|
||
SELECT
|
||
#a.agent_id,
|
||
l.nickname 渠道,
|
||
a.trans_card 转卡数,
|
||
ifnull(c.send_card, 0) 赠卡数,
|
||
(a.trans_card - ifnull(c.send_card, 0)) 房卡结算数,
|
||
cast((c.price_card) as DECIMAL(9,2)) 房卡结算单价,
|
||
cast( ( ((a.trans_card - ifnull(c.send_card, 0)) * c.price_card) / ifnull(a.trans_card, 1) ) as decimal(9,2) ) 实际单价,
|
||
cast(((a.trans_card - ifnull(c.send_card, 0)) * c.price_card) as DECIMAL(9,2)) 房卡结算金额,
|
||
cast(((a.trans_card - ifnull(c.send_card, 0)) * c.price_card * l.proportions) as DECIMAL(9,2)) 渠道收入,
|
||
cast((((a.trans_card - ifnull(c.send_card, 0)) * c.price_card) - (a.trans_card - ifnull(c.send_card, 0)) * c.price_card * l.proportions) as DECIMAL(9,2)) 平台收入,
|
||
a.buy_card 售卡数,
|
||
a.buy_card_money 售卡金额,
|
||
cast(a.buy_card_money * l.proportions as decimal(9,2)) 渠道售卡结算金额,
|
||
#ifnull(b.wechat_income_money, 0) 售卡实收款,
|
||
a.buy_star 金币销售数,
|
||
a.buy_star_money 金币销售金额,
|
||
c.send_star 金币赠送数,
|
||
cast( c.price_gold as DECIMAL(9,2) ) 金币单价,
|
||
cast(( ((a.trans_card - ifnull(c.send_card, 0)) * c.price_card) + a.buy_card_money ) as DECIMAL(9,2)) 合计结算金额,
|
||
cast( c.income_money as DECIMAL(9,2) ) 合计实收款,
|
||
cast((ifnull(c.unincome_money, 0)) as DECIMAL(9,2)) 合计应收款
|
||
#b.star_real_income_money 金币实收款
|
||
#a.trans_star 转星数
|
||
from
|
||
ct_channel_list l
|
||
INNER JOIN (
|
||
select
|
||
#report_date '日期',
|
||
agent_id,
|
||
report_date,
|
||
(sum(ifnull(case report_id when 10056 then report_data else 0 end, 0)) + sum(ifnull(case report_id when 10057 then report_data else 0 end, 0)) ) trans_card,
|
||
#(sum(ifnull(case report_id when 10058 then report_data else 0 end, 0)) + sum(ifnull(case report_id when 10045 then report_data else 0 end, 0)) ) trans_star,
|
||
(sum(ifnull(case report_id when 10060 then report_data else 0 end, 0)) + sum(ifnull(case report_id when 10038 then report_data else 0 end, 0)) ) buy_card,
|
||
(sum(ifnull(case report_id when 10061 then report_data else 0 end, 0)) + sum(ifnull(case report_id when 10039 then report_data else 0 end, 0)) ) buy_card_money,
|
||
(sum(ifnull(case report_id when 10062 then report_data else 0 end, 0)) + sum(ifnull(case report_id when 10040 then report_data else 0 end, 0)) ) buy_star,
|
||
(sum(ifnull(case report_id when 10062 then report_data else 0 end, 0)) + sum(ifnull(case report_id when 10041 then report_data else 0 end, 0)) ) buy_star_money
|
||
from
|
||
ct_report_info
|
||
where
|
||
report_date between '{$start_time}' and '{$end_time}'
|
||
group by
|
||
agent_id
|
||
) a on a.agent_id = l.agent_id
|
||
INNER join (
|
||
select
|
||
agent_id,
|
||
sum(receivable) unincome_money,
|
||
ifnull(sum(free_card), 0) send_card,
|
||
ifnull(sum(free_gold), 0) send_star,
|
||
price_card,
|
||
price_gold,
|
||
realincome income_money
|
||
from
|
||
ct_channel_account_period
|
||
where
|
||
is_enable = 1 and
|
||
account_period between date_format('{$start_time}', '%Y%m') and date_format('{$end_time}', '%Y%m')
|
||
GROUP BY
|
||
agent_id
|
||
) c on a.agent_id = c.agent_id
|
||
where
|
||
l.is_open = 1
|
||
EOL;
|
||
|
||
return $business_income_sql;
|
||
}*/
|
||
|
||
public function _businessIncomeSql($date)
|
||
{
|
||
$date = str_replace('-', '', $date);
|
||
|
||
$sql = <<<EOL
|
||
select
|
||
#a.agent_id,
|
||
#a.channel_id,
|
||
a.nickname `渠道`,
|
||
|
||
(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(f.sum_card_money, 0) `售卡金额`,
|
||
ifnull(f.sum_card_money, 0) * 0.99 * (1 - a.proportions) `售卡公司分成`,
|
||
ifnull(g.sum_gold_sell, 0) `售金币数`,
|
||
ifnull(g.sum_gold_money, 0) `售金币金额`,
|
||
|
||
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(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(f.sum_card_money, 0) * 0.99 * (1 - a.proportions) +
|
||
-- ifnull(g.sum_gold_money, 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) * 0.99 * (1 - a.proportions)) +
|
||
ifnull(g.sum_gold_money, 0) `结算金额`,
|
||
|
||
ifnull(e.pay_fee, 0) +
|
||
-- ifnull(f.sum_card_money, 0) * 0.99 * (1 - a.proportions) +
|
||
-- ifnull(g.sum_gold_money, 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
|
||
where
|
||
ifnull(b.statistic_type, 0) = 1 and date_format(a.satr_transfertime, '%Y%m') = '{$date}'
|
||
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
|
||
where
|
||
b.statistic_type = 1
|
||
and a.saab_state = 1
|
||
and a.saab_type in (0,1)
|
||
and date_format(a.saab_dealtime, '%Y%m') = '{$date}'
|
||
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
|
||
where
|
||
b.statistic_type = 1 and date_format(a.sase_selltime, '%Y%m') = '{$date}'
|
||
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
|
||
where
|
||
ifnull(b.statistic_type, 0) = 1 and date_format(a.op_time, '%Y%m') = '{$date}'
|
||
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
|
||
where
|
||
ifnull(b.statistic_type, 0) = 1 and date_format(a.ssbe_selltime, '%Y%m') = '{$date}'
|
||
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
|
||
where
|
||
b.statistic_type = 1
|
||
and a.saab_state = 1
|
||
and a.saab_type in (2,3)
|
||
and date_format(a.saab_dealtime, '%Y%m') = '{$date}'
|
||
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 = '{$date}'
|
||
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') = '{$date}'
|
||
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') = '{$date}'
|
||
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') = '{$date}'
|
||
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(receivable) receivable
|
||
from
|
||
ct_channel_account_period
|
||
where
|
||
is_enable != 0 and account_period <= '{$date}'
|
||
group by
|
||
agent_id, channel_id
|
||
) h on a.agent_id = h.agent_id and a.channel_id = h.channel_id
|
||
|
||
where a.is_open = 1
|
||
EOL;
|
||
|
||
return $sql;
|
||
}
|
||
|
||
|
||
/**
|
||
* 查询营业收入
|
||
*/
|
||
public function businessIncome($request, &$return)
|
||
{
|
||
|
||
$params = $request->biz_content;
|
||
$start_time = isset($params['date']) ? $params['date'] : '201801';
|
||
//$end_time = isset($params['end_time']) ? $params['end_time'] : '2018-12-31';
|
||
|
||
$sql = $this->_businessIncomeSql($start_time);
|
||
|
||
$items = $this->PDO_Request($sql);
|
||
if (!$this->pdo_isdone())
|
||
{
|
||
$return->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
|
||
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;
|
||
}
|
||
|
||
/**
|
||
* 导出营业收入
|
||
*/
|
||
public function exportBusinessIncome($request, &$return)
|
||
{
|
||
$params = $request->biz_content;
|
||
$start_time = isset($params['start_time']) ? $params['start_time'] : '2018-01-01';
|
||
$end_time = isset($params['end_time']) ? $params['end_time'] : '2018-12-31';
|
||
|
||
$sql = $this->_businessIncomeSql($start_time, $end_time);
|
||
$Helper = $this->GetMasterDatabase();
|
||
// $Helper->ExportToFile('test', $SqlCommand, $params);
|
||
$Helper->ExportToBrowser($sql);
|
||
|
||
die;
|
||
}
|
||
|
||
/**
|
||
* 添加线下数据
|
||
* @param $request
|
||
* @param $return
|
||
* @return bool
|
||
*/
|
||
public function addOfflineData($request, &$return)
|
||
{
|
||
$param = $request->biz_content;
|
||
|
||
$agent_id = @$param['agentid']; /// 代理id
|
||
$channel_id = @$param['channelid']; /// 渠道id
|
||
$checked_time = @$param['checked_time']; /// 选中的时间
|
||
/// 类型 0-待定 1-房卡赠送数 2-房卡实收款 3-平台实收款 4-金币实收款
|
||
$type = intval(@$param['type']) ? intval($param['type']) : 0;
|
||
$remark = isset($param['remark']) ? $param['remark'] : '';
|
||
$data = isset($param['data']) ? intval($param['data']) : 0;
|
||
|
||
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($checked_time))
|
||
{
|
||
$return->seterrors(ERRORCODE_FINANCEYEARERROR, '请输入年份年份');
|
||
return false;
|
||
}
|
||
|
||
$sql = 'update ct_report_offline_data set `status` = 0 WHERE `agent_id` = ? AND `channel_id` = ? AND `type` = ? AND `status` = 1 AND date_format(`checked_time`, "%Y-%m") = date_format(?, "%Y-%m");';
|
||
$this->PDO_Request($sql, $agent_id, $channel_id, $type, $checked_time);
|
||
|
||
$sql = /** @lang text */'insert into ct_report_offline_data (
|
||
agent_id, channel_id, data, type, remark, checked_time, status
|
||
) VALUES (?,?,?,?,?,?,1);';
|
||
$items = $this->PDO_Request($sql, $agent_id, $channel_id, $data, $type, $remark, $checked_time);
|
||
if (!$this->pdo_isdone())
|
||
{
|
||
$return->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
|
||
return false;
|
||
}
|
||
|
||
return true;
|
||
}
|
||
|
||
/**
|
||
* 区域玩家人数统计
|
||
* @param $request
|
||
* @param $return
|
||
* @return bool
|
||
*/
|
||
public function areaNumberOfPeople($request, &$return)
|
||
{
|
||
$param = $request->biz_content;
|
||
|
||
// agentid eg: '00bA05haB0d9ZC0fwGD09Q2OA30insbQ','1B2h0ccl205c390Y28m1Ajdplkuu4wgy'
|
||
$channel_array = isset($param['channel_array']) ? $param['channel_array'] : '';
|
||
$group_by = isset($param['group_by']) ? $param['group_by'] : 'play_a_province';
|
||
|
||
// 筛选渠道
|
||
$sql_channel_where = '';
|
||
if(!empty($channel_array))
|
||
$sql_channel_where = "and play_agentid in ({$channel_array})";
|
||
|
||
// 查询字段集
|
||
$query_field = ['play_a_country', 'play_a_province', 'play_a_city', 'play_a_citycode', 'play_a_district'];
|
||
|
||
// 筛除不需要的查询字段
|
||
$tmp = [];
|
||
foreach ($query_field as $k => $v) {
|
||
array_push($tmp, $v);
|
||
if($group_by == $v)
|
||
break;
|
||
}
|
||
$sql_query_field = implode($tmp, ',');
|
||
|
||
$sql = <<<EOF
|
||
SELECT
|
||
*
|
||
FROM
|
||
(
|
||
SELECT
|
||
count(*) AS number_of_people,
|
||
{$sql_query_field}
|
||
#play_a_street
|
||
#play_a_address
|
||
FROM
|
||
player
|
||
WHERE
|
||
1=1
|
||
{$sql_channel_where}
|
||
GROUP BY
|
||
{$group_by}
|
||
) a
|
||
ORDER BY
|
||
number_of_people desc
|
||
EOF;
|
||
|
||
$items = $this->PDO_Request($sql);
|
||
if (!$this->pdo_isdone())
|
||
{
|
||
$return->SetErrors($this->GetErrorCode(), $this->GetErrorInfo());
|
||
return false;
|
||
}
|
||
|
||
$data = [];
|
||
if(is_array($items) && isset($items[0])) {
|
||
$data['header'] = array_keys($items[0]);
|
||
foreach ($items as $k => $v) {
|
||
foreach ($v as $q) {
|
||
$data['body'][$k][] = $q;
|
||
}
|
||
}
|
||
}
|
||
|
||
$return->biz_content = $data;
|
||
|
||
return true;
|
||
}
|
||
} |