You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2550 lines
112 KiB
PHP

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<?php
namespace Admin\Controller;
use Base\Factory\BaseFactory;
/**
* 上下游结算单
* @author cz
*/
class CompanyStatementController extends ThinkController
{
public $CompanyType = [
"1"=>"上游cp公司",
"2"=>"联运下游渠道公司"
];
public $CompanyBelong = [
"0"=>"下游内团",
"1"=>"下游外团",
"2"=>"下游分发",
"3"=>"下游无",
"9"=>"上游"
];
public $VerifyStatus=[
"-2"=>"撤销汇总",
"-1"=>"管理员审核拒绝",
"0"=>"未审批",
"1"=>"管理员审核通过",
"2"=>"已汇总"
];
public $ConfirmStatus=[
"0"=>"未发起",
"1"=>"已发起",
"2"=>"已确认"
];
public $admininfo;
public $DBModel;
private $MarketEvent;
static $specialCompoent;
public function _initialize()
{
$this->admininfo = $_SESSION['onethink_admin']['user_auth'];
$this->DBModel = SM("CompanyStatement","tab_");
$this->MarketEvent = A("Market","Event");
$Factory = BaseFactory::getInstance();
self::$specialCompoent = $Factory->factoryClass("SpecialCompoent");
parent::_initialize();
}
public function lists() {
$params = I('get.');
$page = $params['p'] ? intval($params['p']) : 1;
$row = $params['row'] ? intval($params['row']) : 10;
//权限分配
if(!IS_ROOT){
$this->OpAuthList= getModuleControllerAuth();
}
$this->assign('menubtn',$this->menuAuth());
$map = [
"_string"=>"1=1"
];
$gid = session('user_group_id');
$markerGroup = $this->MarketEvent->isMarketAdminGroup($gid);
if($markerGroup){
$companyIds = $this->MarketEvent->getAdminCompanyId();
$map['_string'] .= ' AND company_id in(' . $companyIds . ') and company_belong not in (0,9)';
}
if (isset($_REQUEST['time_start']) && isset($_REQUEST['time_end'])) {
$time_start = strtotime($_REQUEST['time_start']);
$time_end = strtotime($_REQUEST['time_end'])+ 86399;
$map["_string"] .= " AND ( (statement_begin_time BETWEEN {$time_start} AND {$time_end}) OR (statement_end_time BETWEEN {$time_start} AND {$time_end}) )";
} elseif (isset($_REQUEST['time_start'])) {
$time_start = strtotime($_REQUEST['time_start']);
$map["_string"] .= " AND ( (statement_begin_time >= {$time_start} ) OR (statement_end_time >= {$time_start}) )";
} elseif (isset($_REQUEST['time_end'])) {
$time_end = strtotime($_REQUEST['time_end'])+ 86399;
$map["_string"] .= " AND ( (statement_begin_time <= {$time_end} ) OR (statement_end_time <= {$time_end}) )";
}
if (isset($_REQUEST['time_start2']) && isset($_REQUEST['time_end2'])) {
$map['op_time'] = ['between', [strtotime($_REQUEST['time_start2']), strtotime($_REQUEST['time_end2']) + 86399]];
} elseif (isset($_REQUEST['time_start2'])) {
$map['op_time'] = ['EGT', strtotime($_REQUEST['time_start2'])];
} elseif (isset($_REQUEST['time_end2'])) {
$map['op_time'] = ['ELT', strtotime($_REQUEST['time_end2']) + 86399];
}
$typeflag = false;
if (isset($_REQUEST['withdraw_type'])) {
if($_REQUEST['withdraw_type'] == 1){
$typeflag = 1;//月结
$map["withdraw_type"] = 1;
}else{
$typeflag = 2;//周结
$map["withdraw_type"] = ["in",[0,2]];
}
if($_REQUEST['withdraw_type'] == 3){
$typeflag = 3;//特殊补点
$map["withdraw_type"] = 3;
}
}
if (isset($_REQUEST['withdraw_type2'])) {
if($_REQUEST['withdraw_type2'] == 2){
if($typeflag == 1){ //月结的补点找不到
$map['withdraw_type'] = 999;
}else{ //周结的补点就是补点
$map['withdraw_type'] = 2;
}
}else{
if($typeflag == 1){//月结的正常=月结
$map['withdraw_type'] = 1;
}elseif($typeflag == 2){//周结的正常=周结
$map['withdraw_type'] = 0;
}else{//没选的正常是 非补点
$map['withdraw_type'] = ["in",[0,1]];
}
}
if($_REQUEST['withdraw_type2'] == 3){
if ($typeflag == 3 || !$typeflag) {
$map["withdraw_type"] = 3;
} else {
$map["withdraw_type"] = 999; //两者不一搜索为空
}
} else {
if($typeflag == 3) {
$map["withdraw_type"] = 999; //两者不一搜索为空
}
}
}
//其他
if(isset($_REQUEST['company_type'])){
if($_REQUEST['company_type'] == 1){
$map['_string'] .= " AND company_belong='9'";
}else{
$map['_string'] .= " AND company_belong <> '9'";
}
}
if(isset($_REQUEST['company_belong'])){
$map['company_belong'] = $_REQUEST['company_belong'];
}
if(isset($_REQUEST['company_id'])){
$map['company_id'] = $_REQUEST['company_id'];
}
if(isset($_REQUEST['company_name'])){
$map['company_name'] =["LIKE","%{$_REQUEST['company_name']}%"];
}
if(isset($_REQUEST['verify_status'])){
$map['verify_status'] = $_REQUEST['verify_status'];
}
if(isset($_REQUEST['confirm_status'])){
$map['confirm_status'] = $_REQUEST['confirm_status'];
}
// dd($map);
// $this->checkListOrCountAuthRestMap($map);//导出权限
//条件end
$data = $this->DBModel
->field("id,withdraw_type,company_name,company_belong,statement_begin_time,statement_end_time,statement_money,platform_amount,verify_status,verify_log,confirm_status,confirm_log,op_time,remark")
->where($map)
->order("statement_begin_time desc,id desc")->page($page,$row)->select();
foreach($data as $k => &$v) {
$v['statement_begin_time'] = date('Y.m.d',$v['statement_begin_time']);
$v['statement_end_time'] = date('Y.m.d',$v['statement_end_time']);
$v['company_belong'] = $this->CompanyBelong[$v['company_belong']];
$v['op_time'] = date('Y.m.d H:i:s',$v['op_time']);
$v["valid"] = "{$v['statement_begin_time']}-{$v['statement_end_time']}";
$v['withdraw_type_1'] = ($v['withdraw_type'] == 1 ? "月结" : ($v['withdraw_type'] == 3 ?"其他" : "周结"));
$v['withdraw_type_2'] = ($v['withdraw_type'] == 2 ? "补点" : ($v['withdraw_type'] == 3 ?"特殊补点" : "正常结算"));
$v['verify_log'] = json_decode($v['verify_log'], true);
$v['confirm_log'] = json_decode($v['confirm_log'], true);
if (isset($params['export'])) {
$symbol = "\n";
} else {
$symbol = "<br>";
}
$v["create"]= "{$v['verify_log']['create_user']} {$symbol} {$v['verify_log']['create_time']}";
if(isset($v['verify_log']['admin_user'])){
if($v['verify_status'] == -1){
$ts = "管理员审核拒绝";
}else{
$ts = "管理员审核通过";
}
$v["admin"]= "{$ts}({$v['verify_log']['admin_user']}) {$symbol} {$v['verify_log']['admin_time']}";
}else{
$v["admin"] = '--';
}
if(isset($v['confirm_log']['launch_user'])){
$ts = "已发起";
$v["launch"]= "{$ts}({$v['confirm_log']['launch_user']}) {$symbol} {$v['confirm_log']['launch_time']}";
}else{
$v["launch"] = '--';
}
if(isset($v['confirm_log']['confirm_user'])){
$ts = "已确认";
$v["confirm"]= "{$ts}({$v['confirm_log']['confirm_user']}) {$symbol} {$v['confirm_log']['confirm_time']}";
}else{
$v["confirm"] = '--';
}
if(isset($v['verify_log']['pool_user'])){
if($v['verify_status'] == -2){
$ts = "撤销汇总";
$v["pool"]= "{$ts}({$v['verify_log']['pool_user']}){$symbol} {$v['verify_log']['pool_time']}";
}else{
$ts = "已汇总";
$v["pool"]= "{$ts}({$v['verify_log']['pool_user']}){$symbol}汇总单:{$v['verify_log']['pool_num']}{$symbol} {$v['verify_log']['pool_time']}";
}
}else{
$v["pool"] = '--';
}
$v['oplist'] = $this->OpAuth($v);
}
$count = $this->DBModel->field("count(id) count,IFNULL(SUM(CASE WHEN withdraw_type < 2 THEN platform_amount ELSE 0 END),0) as platform_amount,SUM(statement_money) as statement_money")->where($map)->find();
// dd($count);
$params['p'] = $page;
$params['row'] = $row;
$page = set_pagination($count['count'], $row, $params);
if ($page) {
$this->assign('_page', $page);
}
$this->assign("IS_SUBSITE",IS_SUBSITE);
if(IS_SUBSITE){
$SubKvModel = M("Kv","sub_",SUBSITE_DB);//指定子库
$LastSynTime = $SubKvModel->where("`key` = 'sub_spend_syn_time'")->getField("value");
$LastStatementTime = $SubKvModel->where("`key` = 'sub_company_statement'")->getField("value");
$this->assign('lastSynTime',date('Y-m-d',$LastSynTime));
$this->assign('lastStatementTime',date('Y-m-d',$LastStatementTime));
}
$this->assign('data',$data);
$this->assign('count',$count);
$this->assign('CompanyType',$this->CompanyType);
$this->assign('CompanyBelong',$this->CompanyBelong);
$this->assign('VerifyStatus',$this->VerifyStatus);
$this->assign('ConfirmStatus',$this->ConfirmStatus);
$this->display();
}
//查看
public function viewStatement()
{
if(!isset($_REQUEST['id'])){
$this->error('参数错误');
}
$id = $_REQUEST['id'];
//获取基本信息
$dbres = $this->DBModel->where("id='{$id}'")->find();
$first_party_info = json_decode($dbres['first_party_info'],true);
$second_party_info = json_decode($dbres['second_party_info'],true);
$statement_info = json_decode($dbres['statement_info'],true);
foreach ($statement_info as $key => $value) {
if ($value['game_name'] == "罚款" ) {
$dbres['pay_amount'] = $dbres['pay_amount'] + $statement_info[$key]['pay_amount'];
$statement_info[$key]['pay_amount'] = "-";
}
if ($value['game_name'] == "奖励") {
$dbres['pay_amount'] = $dbres['pay_amount'] - $statement_info[$key]['pay_amount'];
$statement_info[$key]['pay_amount'] = "-";
}
}
if($dbres['pay_type'] == 2){
$company = $second_party_info['partner'];
$pyinfo = $second_party_info;
$fkf_pyinfo = $first_party_info;
}else{
$company = $first_party_info['partner'];
$pyinfo = $first_party_info;
$fkf_pyinfo = $second_party_info;
}
$senddata = array(
"company"=>$company,
"payinfo"=>$pyinfo,
"fkf_payinfo"=>$fkf_pyinfo,
"first_part_company"=>$first_party_info['partner'],
"second_part_company"=>$second_party_info['partner'],
"pay_type"=>$dbres['pay_type'],
"is_payment"=>$dbres['is_payment'],
"withdraw_type"=>$dbres['withdraw_type'],//2补丁
"first_party_info"=>$first_party_info,
"second_party_info"=>$second_party_info,
"statement_info"=>$statement_info,
"statement_count"=>array("pay_amount"=>$dbres['pay_amount'],"list_count"=>count($statement_info),"statement_money"=>$dbres['statement_money'],"big_ratio_money"=>convertAmountToCn($dbres['statement_money']))
);
$this->assign("data",$senddata);
if($dbres["company_belong"] == 9){
//上游
if(!IS_SUBSITE){
$this->display("viewCpStatement");
}else{
$this->display("subViewCpStatement");
}
}else{
if ($dbres["withdraw_type"] == 3) {
if($dbres["company_type"] == 1){
$this->display("viewPcStatement");
}else{
if($dbres['company_type'] == 1) {
$dbres['company_type_str'] = '公司';
} elseif($dbres['company_type'] == 2){
$dbres['company_type_str'] = '个人';
}
if($dbres['company_belong'] == '0') {
$dbres['company_belong_str'] = '内团';
} elseif($dbres['company_belong'] == '1') {
$dbres['company_belong_str'] = '外团';
}elseif($dbres['company_belong'] == '2') {
$dbres['company_belong_str'] = '分发联盟';
}elseif($dbres['company_belong'] == '3') {
$dbres['company_belong_str'] = '无';
}
$this->assign('dbres',$dbres);
$this->display("viewPuComplementStatement");
}
} else {
if($dbres["company_type"] == 1){
$this->display("viewPcStatement");
}else{
$this->display("viewPuStatement");
}
}
}
}
//编辑
public function editStatement()
{
if ($_POST) {
$params = I('post.');
if(!isset($params['id'])){
$this->error('参数错误');
}
$params['first_party_info'] = json_encode($params['first_party_info'],JSON_UNESCAPED_UNICODE);
$params['second_party_info'] = json_encode($params['second_party_info'],JSON_UNESCAPED_UNICODE);
$params['statement_info'] = json_encode($params['statement_info'],JSON_UNESCAPED_UNICODE);
$y = $this->DBModel->where("id='{$params['id']}'")->find();
if($y['first_party_info'] != $params['first_party_info'] || $y['second_party_info'] != $params['second_party_info'] || $y['statement_info'] != $params['statement_info']){
$params['verify_status'] = 0;
$params['verify_log'] = json_encode(["create_user"=>$this->admininfo["username"],"create_time"=>date("Y.m.d H:i:s")]);
$params['op_time'] = time();
$this->DBModel->save($params);
}
$this->ajaxReturn(["code"=>0,"msg"=>"ok"]);
}else{
if (!isset($_REQUEST['id'])) {
$this->error('参数错误');
}
$id = $_REQUEST['id'];
//获取基本信息
$dbres = $this->DBModel->where("id='{$id}'")->find();
$dbres['first_party_info'] = json_decode($dbres['first_party_info'], true);
$dbres['second_party_info']= json_decode($dbres['second_party_info'], true);
$dbres['statement_info'] = json_decode($dbres['statement_info'], true);
if(is_array($dbres['statement_info'])) {
foreach ($dbres['statement_info'] as $key => $value) {
$dbres['pay_amount_other'] += $value['platform_money'];
if ($value['game_name'] == "罚款" || $value['game_name'] == "奖励") {
$dbres['statement_info'][$key]['pay_amount'] = "-";
}
$real_statement_amount
= number_format(($value['platform_money']+$value['aggregate_money'])*(1-$value['promote_ratio']/100)*($value['ratio']/100)*(1-$value["fax_ratio"]/100),2,'.','');
if (!$dbres['statement_info'][$key]['other_amount']) {
$dbres['statement_info'][$key]['other_amount'] = number_format($value["sum_money"] - $real_statement_amount,2,'.','');
}
}
}
$this->assign("data", $dbres);
if ($dbres["company_belong"] == 9) {
//上游
if (IS_SUBSITE) {
$this->display("editWmCpStatement");
} else {
$this->display("editCpStatement");
}
} else {
if ($dbres["withdraw_type"] == 3) {
if($dbres["company_type"] == 1){
$this->display("editPcComplementStatement");
}else{
if($dbres['pay_type'] == 2){
$payinfo = $dbres['second_party_info'];
$payinfo['type'] = "second_party_info";
}else{
$payinfo = $dbres['first_party_info'];
$payinfo['type'] = "first_party_info";
}
$this->assign("payinfo", $payinfo);
$this->display("editPuComplementStatement");
}
} else {
if($dbres["company_type"] == 1){
$this->display("editPcStatement");
}else{
if($dbres['pay_type'] == 2){
$payinfo = $dbres['second_party_info'];
$payinfo['type'] = "second_party_info";
}else{
$payinfo = $dbres['first_party_info'];
$payinfo['type'] = "first_party_info";
}
$this->assign("payinfo", $payinfo);
$this->display("editPuStatement");
}
}
}
}
}
public function delStatement(){
if(!isset($_REQUEST['ids'])) $this->error("参数错误");
$ids = $_REQUEST['ids'];
// $dbres = $this->DBModel->where("id in ({$ids}) and verify_status = 0")->delete();
$dbres = $this->DBModel->where("id in ({$ids})")->select();
foreach ($dbres as $key=>$value) {
$this->DBModel->where("id = {$value['id']} and verify_status = 0")->delete();
}
addOperationLog(['op_type'=>2,'key'=>$ids,"op_name"=>"删除结算单",'url'=>U('lists')]);
$this->ajaxReturn(array(
'status' => 1,
"info"=>"删除成功"
));
}
public function checkWmStatement() {
$ids = $_POST['id'];
if (!$ids) {
$this->ajaxReturn(["status"=>0]);
}
$count = SM("company_statement","tab_")
->where("id in({$ids})")
->group("company_type,withdraw_type,company_belong")
->select();
foreach ($count as $key => $value) {
if ($value["company_belong"]==9) {
$this->ajaxReturn(["status"=>0,"msg"=>""]);
}
}
if (count($count)>1) {
$this->ajaxReturn(["status"=>0,"msg"=>""]);
} else {
$this->ajaxReturn(["status"=>1]);
}
}
public function poolWmStatement() {
$ids = $_GET['id'];
$data = SM("company_statement","tab_")
->where("id in({$ids})")
->select();
$list = [];
$amount_data = [];
$company_data = SM("promote_company","tab_")->where(["status"=>1,"company_type"=>$data[0]['company_type']])->select();
//游戏数据整合
foreach ($data as $key => $value) {
$promote_data = SM("promote","tab_")->field("id")->where(['company_id'=>$value['company_id']])->select();
$promote_ids = array_column($promote_data,"id");
$statement_info = json_decode($value['statement_info'],true);
$statement_begin_time = $value['statement_begin_time'];
$statement_end_time = $value['statement_end_time'];
$user_data = SM("user", "tab_")
->field("id")
->where([
'promote_id' => ['in', $promote_ids],
"register_time" => ['between', [$statement_begin_time, $statement_end_time]]
])->select();
$amount_data['user_newcount'] += count($user_data);
if ($value['company_type'] == 1) {
$list = array_merge($list,$statement_info);
foreach ($statement_info as $k => $v) {
if (!$amount_data['statement_begin_time'] || $amount_data['statement_begin_time'] > $v['statement_begin_time']) {
$amount_data['statement_begin_time'] = $v['statement_begin_time'];
}
if (!$amount_data['statement_end_time'] || $amount_data['statement_end_time'] < $v['statement_end_time']) {
$amount_data['statement_end_time'] = $v['statement_end_time'];
}
if ($v['game_name'] != '罚款' && $v['game_name'] != '奖励') {
$amount_data['pay_amount'] += $v["pay_amount"];
}
if ($v['game_name'] == '罚款') {
$amount_data['sum_money'] -= $v["sum_money"];
} else {
$amount_data['sum_money'] += $v["sum_money"];
}
}
} elseif($value['company_type'] == 2) {
foreach ($statement_info as $k => $v) {
$game_list = $v["game_list"];
$list = array_merge($list,$game_list);
foreach ($game_list as $gk=>$gv) {
if (!$amount_data['statement_begin_time'] || $amount_data['statement_begin_time'] > $gv['statement_begin_time']) {
$amount_data['statement_begin_time'] = $gv['statement_begin_time'];
}
if (!$amount_data['statement_end_time'] || $amount_data['statement_end_time'] < $gv['statement_end_time']) {
$amount_data['statement_end_time'] = $gv['statement_end_time'];
}
if ($gv['game_name'] != '罚款' && $gv['game_name'] != '奖励') {
$amount_data['pay_amount'] += $gv["pay_amount"];
}
if ($gv['game_name'] == '罚款') {
$amount_data['sum_money'] -= $gv["sum_money"];
} else {
$amount_data['sum_money'] += $gv["sum_money"];
}
}
}
}
}
$list = array_repeat($list,"game_name");
$this->assign("company_data",$company_data);
$this->assign("row",count($list));
$this->assign("data",$list);
$this->assign("amount_data",$amount_data);
$this->assign("js_amount_data",json_encode($amount_data));
$this->assign("js_data",json_encode($list));
$this->display();
}
//子系统列表
public function showCpStatementList() {
$params = I('get.');
$page = $params['p'] ? intval($params['p']) : 1;
$row = $params['row'] ? intval($params['row']) : 10;
$map['company_belong'] = 9;
if(!$_REQUEST["year"]) {
$_REQUEST["year"] = date("Y");
}
if ($_REQUEST["year"]) {
$start = strtotime($_REQUEST["year"]."-01-01");
$end = strtotime(date("Y-m-t",strtotime($_REQUEST["year"]."-12"))) + 86399;
$map["statement_begin_time"] = ["between",[$start,$end]];
}
$data = SM("company_statement","tab_")
->field("id,company_id,company_name,sum(statement_money) statement_money,sum(platform_amount) platform_amount")
->where($map)
->group("company_id")
->page($page, $row)
->select();
$count = SM("company_statement","tab_")
->field("id")
->where($map)
->group("company_id")
->select();
$count = count($count);
$page = set_pagination($count, $row,$params);
if($page) {
$this->assign('_page', $page);
}
A("FinancialSummary")->getYearList();
$this->assign("year",date("Y"));
$this->assign("data",$data);
$this->display();
}
//上游公司
public function showCpStatementView() {
$company_id = explode(",",$_REQUEST["company_id"]);
$time = $_REQUEST["time"];
$assign_data = [];
$sum = [];
if ($_REQUEST["time"]) {
$start = strtotime($_REQUEST["time"]."-01-01");
$end = strtotime(date("Y-m-t",strtotime($_REQUEST["time"]."-12"))) + 86399;
$map["statement_begin_time"] = ["between",[$start,$end]];
}
foreach ($company_id as $ckey => $cvalue) {
$map["company_id"] = $cvalue;
$map['company_belong'] = 9;
$data = SM("company_statement","tab_")
->field("id,company_id,company_name,FROM_UNIXTIME(statement_begin_time,'%m') time,statement_money,platform_amount,statement_info,withdraw_type")
->where($map)
->select();
$use_data = [
"01"=>["time"=>"01","show_company_name"=>$data[0]["company_name"],"row"=>1,"withdraw_type"=>$data[0]["withdraw_type"],"statement_info"=>[['statement_begin_time'=>$time.'.01.01','statement_end_time'=>$time.'.01.'.date('t',strtotime($time.'01'))]]],
"02"=>["time"=>"02","show_company_name"=>$data[0]["company_name"],"row"=>1,"withdraw_type"=>$data[0]["withdraw_type"],"statement_info"=>[['statement_begin_time'=>$time.'.02.01','statement_end_time'=>$time.'.02.'.date('t',strtotime($time.'02'))]]],
"03"=>["time"=>"03","show_company_name"=>$data[0]["company_name"],"row"=>1,"withdraw_type"=>$data[0]["withdraw_type"],"statement_info"=>[['statement_begin_time'=>$time.'.03.01','statement_end_time'=>$time.'.03.'.date('t',strtotime($time.'03'))]]],
"04"=>["time"=>"04","show_company_name"=>$data[0]["company_name"],"row"=>1,"withdraw_type"=>$data[0]["withdraw_type"],"statement_info"=>[['statement_begin_time'=>$time.'.04.01','statement_end_time'=>$time.'.04.'.date('t',strtotime($time.'04'))]]],
"05"=>["time"=>"05","show_company_name"=>$data[0]["company_name"],"row"=>1,"withdraw_type"=>$data[0]["withdraw_type"],"statement_info"=>[['statement_begin_time'=>$time.'.05.01','statement_end_time'=>$time.'.05.'.date('t',strtotime($time.'05'))]]],
"06"=>["time"=>"06","show_company_name"=>$data[0]["company_name"],"row"=>1,"withdraw_type"=>$data[0]["withdraw_type"],"statement_info"=>[['statement_begin_time'=>$time.'.06.01','statement_end_time'=>$time.'.06.'.date('t',strtotime($time.'06'))]]],
"07"=>["time"=>"07","show_company_name"=>$data[0]["company_name"],"row"=>1,"withdraw_type"=>$data[0]["withdraw_type"],"statement_info"=>[['statement_begin_time'=>$time.'.07.01','statement_end_time'=>$time.'.07.'.date('t',strtotime($time.'07'))]]],
"08"=>["time"=>"08","show_company_name"=>$data[0]["company_name"],"row"=>1,"withdraw_type"=>$data[0]["withdraw_type"],"statement_info"=>[['statement_begin_time'=>$time.'.08.01','statement_end_time'=>$time.'.08.'.date('t',strtotime($time.'08'))]]],
"09"=>["time"=>"09","show_company_name"=>$data[0]["company_name"],"row"=>1,"withdraw_type"=>$data[0]["withdraw_type"],"statement_info"=>[['statement_begin_time'=>$time.'.09.01','statement_end_time'=>$time.'.09.'.date('t',strtotime($time.'09'))]]],
"10"=>["time"=>"10","show_company_name"=>$data[0]["company_name"],"row"=>1,"withdraw_type"=>$data[0]["withdraw_type"],"statement_info"=>[['statement_begin_time'=>$time.'.10.01','statement_end_time'=>$time.'.10.'.date('t',strtotime($time.'10'))]]],
"11"=>["time"=>"11","show_company_name"=>$data[0]["company_name"],"row"=>1,"withdraw_type"=>$data[0]["withdraw_type"],"statement_info"=>[['statement_begin_time'=>$time.'.11.01','statement_end_time'=>$time.'.11.'.date('t',strtotime($time.'11'))]]],
"12"=>["time"=>"12","show_company_name"=>$data[0]["company_name"],"row"=>1,"withdraw_type"=>$data[0]["withdraw_type"],"statement_info"=>[['statement_begin_time'=>$time.'.12.01','statement_end_time'=>$time.'.12.'.date('t',strtotime($time.'12'))]]],
];
$row = 0;
foreach($data as $key => $value) {
$data[$key]['statement_info'] = json_decode($value['statement_info'],true);
$statement_info = $data[$key]['statement_info'];
$data[$key]['row'] = count($data[$key]['statement_info']);
$data[$key]['show_company_name'] = $value["company_name"];
$row += $data[$key]['row'];
foreach ($statement_info as $k => $v) {
$statement_info[$k]['sum_amount'] = $v["platform_money"] + $v["aggregate_money"] ;
$real_statement_amount
= number_format(($v['platform_money']+$value['aggregate_money'])*(1-$v['promote_ratio']/100)*($v['ratio']/100)*(1-$v["fax_ratio"]/100),2,'.','');
if (!$statement_info[$k]['other_amount']) {
$statement_info[$k]['other_amount'] = number_format($v["sum_money"] - $real_statement_amount,2,'.','');
}
$sum[$ckey]["ratio"] += $v["ratio"];
$sum[$ckey]["promote_ratio"] += $v["promote_ratio"];
$sum[$ckey]["fax_ratio"] += $v["fax_ratio"];
$statement_info[$k]['ratio'] = $v["ratio"]."%";
$statement_info[$k]['promote_ratio'] = $v["promote_ratio"]."%";
$statement_info[$k]['fax_ratio'] = $v["fax_ratio"]."%";
$sum[$ckey]["platform_money"] += $v["platform_money"];
$sum[$ckey]["aggregate_money"] += $v["aggregate_money"];
$sum[$ckey]["sum_amount"] += $statement_info[$k]["sum_amount"];
$sum[$ckey]["other_amount"] += $statement_info[$k]["other_amount"];
if ($v["statement_type"] == 2) {
$sum[$ckey]["sum_money"] -= $v["sum_money"];
} else {
$sum[$ckey]["sum_money"] += $v["sum_money"];
}
}
$data[$key]["statement_info"] = $statement_info;
if (!$use_data[$value['time']]["statement_info"]) {
$use_data[$value['time']] = $data[$key];
}
else {
foreach ($statement_info as $sk => $sv) {
array_push($use_data[$value['time']]["statement_info"], $sv);
}
}
}
$sum[$ckey]["ratio"] = number_format($sum[$ckey]["ratio"]/$row,2,'.','')."%";
$sum[$ckey]["promote_ratio"] = number_format($sum[$ckey]["promote_ratio"]/$row,2,'.','')."%";
$sum[$ckey]["fax_ratio"] = number_format($sum[$ckey]["fax_ratio"]/$row,2,'.','')."%";
$assign_data[] = array_values($use_data);
}
// dump($assign_data);
foreach ($assign_data as $key => $value) {
foreach ($value as $k => $v) {
if (count($v["statement_info"]) > 1) {
unset($assign_data[$key][$k]['statement_info'][0]);
$assign_data[$key][$k]['statement_info'] = array_values($assign_data[$key][$k]['statement_info']);
}
$assign_data[$key][$k]["row"] = count($assign_data[$key][$k]["statement_info"])?count($assign_data[$key][$k]["statement_info"]):1;
}
}
// dump($assign_data);
$is_export= false;
if (isset($_REQUEST['is_export']) && $_REQUEST['is_export']==1){
$is_export = true;
}
$this->assign("title","联运结算单汇总上游导出");
$this->assign("is_export",$is_export);
$this->assign("sum",$sum);
$this->assign("time",$time);
$this->assign("data",$assign_data);
$this->display();
}
public function checkCompanyData() {
$statement_id = $_REQUEST["statement_id"];
$company_id = $_REQUEST["company_id"];
$begin_time = strtotime(str_replace(".","-",$_REQUEST["begin_time"]));
$end_time = strtotime(str_replace(".","-",$_REQUEST["end_time"]))+86399;
$check_list = array_column(json_decode($_POST["list"],true),"game_name");
if (!$company_id) {
$data = [];
} else {
$data = SM("company_statement","tab_")
->where("statement_begin_time>={$begin_time} and statement_end_time<={$end_time} and company_id={$company_id} and id not in({$statement_id}) and (verify_status=1 or verify_status=-2)")
->select();
}
$list = [];
$amount_data = json_decode($_REQUEST["amount_data"],true);
//游戏数据整合
foreach ($data as $key => $value) {
$promote_data = SM("promote", "tab_")->field("id")->where(['company_id' => $value['company_id']])->select();
$promote_ids = array_column($promote_data, "id");
$statement_info = json_decode($value['statement_info'], true);
$statement_begin_time = $value['statement_begin_time'];
$statement_end_time = $value['statement_end_time'];
$user_data = [];
if ($promote_ids) {
$user_data = SM("user", "tab_")
->field("id")
->where([
'promote_id' => ['in', $promote_ids?$promote_ids:0],
"register_time" => ['between', [$statement_begin_time, $statement_end_time]]
])->select();
}
$amount_data['user_newcount'] += count($user_data);
if ($value['company_type'] == 1) {
// $list = array_merge(, $statement_info);
foreach ($statement_info as $k => $v) {
if (!in_array($v["game_name"],$check_list)) {
array_push($list,$v);
}
if ($v['game_name'] != '罚款' && $v['game_name'] != '奖励') {
$amount_data['pay_amount'] += $v["pay_amount"];
}
if ($v['game_name'] == '罚款') {
$amount_data['sum_money'] -= $v["sum_money"];
} else {
$amount_data['sum_money'] += $v["sum_money"];
}
}
} elseif($value['company_type'] == 2) {
foreach ($statement_info as $k => $v) {
$game_list = $v["game_list"];
// $list = array_merge($list, $game_list);
foreach ($game_list as $gk=>$gv) {
if (!in_array($gv["game_name"],$check_list)) {
array_push($list,$gv);
}
if (!$amount_data['statement_begin_time'] || $amount_data['statement_begin_time'] > $gv['statement_begin_time']) {
$amount_data['statement_begin_time'] = $gv['statement_begin_time'];
}
if (!$amount_data['statement_end_time'] || $amount_data['statement_end_time'] < $gv['statement_end_time']) {
$amount_data['statement_end_time'] = $gv['statement_end_time'];
}
if ($gv['game_name'] != '罚款' && $gv['game_name'] != '奖励') {
$amount_data['pay_amount'] += floatval($gv["pay_amount"]);
}
if ($gv['game_name'] == '罚款') {
$amount_data['sum_money'] -= floatval($gv["sum_money"]);
} else {
$amount_data['sum_money'] += floatval($gv["sum_money"]);
}
}
}
}
}
if ($list) {
$list = array_repeat($list,"game_name");
}
$amount_data['pay_amount'] = number_format($amount_data['pay_amount'],2,'.','');
$amount_data['sum_money'] = number_format($amount_data['sum_money'],2,'.','');
$this->ajaxReturn(['list'=>$list,'amount_data'=>$amount_data,"row"=>count($list),"status"=>1,"other_id"=>implode(",",array_column($data,"id"))]);
}
public function saveCompanyData() {
$list = array_merge(json_decode($_POST['list'],true),json_decode($_POST['other_list'],true));
$amount_data = json_decode($_POST['amount_data'],true);
$company_id = $_POST["company_id"];
$company_data = M("company_relation","tab_")->where("(first_company_id={$company_id} and first_company_type=2) or (second_company_id = {$company_id} and second_company_type=2)")->find();
$promote_company = [];
$partner = [];
if ($company_data['first_company_type'] == 2) {
$promote_company = M("promote_company","tab_")->where(['id'=>$company_data['first_company_id']])->find();
$partner = M("company_info","tab_")->where(['id'=>$company_data['second_company_id']])->find();
}else if($company_data['second_company_type'] == 2) {
$promote_company = M("promote_company","tab_")->where(['id'=>$company_data['second_company_id']])->find();
$partner = M("company_info","tab_")->where(['id'=>$company_data['first_company_id']])->find();
}
$company_info['id']=$promote_company['id'];
$company_info['partner']=$promote_company['company_name'];
$company_info['link_man']=$promote_company['settlement_contact'];
$company_info['phone']=$promote_company['contact_phone'];
$company_info['address']=$promote_company['address'];
$company_info['bank_card']=$promote_company['bank_card'];
$company_info['bank_cardname']=$promote_company['bank_cardname'];
$company_info['bank_name']=$promote_company['bank_name'];
$company_info['bank_address']=$promote_company['bank_address'];
$company_info['ali_user']=$promote_company['ali_user'];
$company_info['ali_account']=$promote_company['ali_account'];
$company_info['is_payment'] = $company_data['is_payment'];
$partner_info['id'] = $partner['id'];
$partner_info['partner'] = $partner['partner'];
$partner_info['link_man'] = $partner['link_man'];
$partner_info['link_phone'] = $partner['link_phone'];
$partner_info['invoice_type'] = $partner['invoice_type'];
$partner_info['invoice_item'] = $partner['invoice_item'];
$partner_info['address'] = $partner['address'];
if ($company_data['first_company_type'] == 2) {
$first_company_info = $company_info;
$second_company_info = $partner_info;
}else if($company_data['second_company_type'] == 2) {
$first_company_info = $partner_info;
$second_company_info = $company_info;
}
$save['company_id'] = $company_id;
$save['company_name'] = $promote_company["company_name"];
$save['statement_info'] = json_encode($list);
$save['first_party_info'] = json_encode($first_company_info);
$save['second_party_info'] = json_encode($second_company_info);
$save['statement_begin_time'] = strtotime(str_replace(".", "-", $amount_data['statement_begin_time']));
$save['statement_end_time'] = strtotime(str_replace(".", "-", $amount_data['statement_end_time'])) + 86399;
$save['pay_amount'] = $amount_data['pay_amount'];
$save['sum_money'] = $amount_data['sum_money'];
$save['user_newcount'] = $amount_data['user_newcount'];
$save['fax_ratio'] = $_POST['fax_ratio'];
$save['statement_ids'] = $_POST['id'].','.$_POST['other_id'];
$save['create_time'] = time();
$save['statement_num'] = "PL_".date('Ymd').date('His').sp_random_num(3);
$is_success = SM("new_company_statement_info","tab_")->add($save);
if ($_POST['other_id']) {
$statement_id = $_POST['id'].','.$_POST['other_id'];
} else {
$statement_id = $_POST['id'];
}
$dbres = $this->DBModel->field("id,verify_status,verify_log")->where("id in ({$statement_id})")->select();
foreach ($dbres as $k => $v) {
$v['verify_log'] = json_decode($v['verify_log'],true);
$v['verify_log']['pool_user']=$this->admininfo["username"];
$v['verify_log']['pool_time']=date("Y.m.d H:i:s");
$v['verify_log']['pool_num']=$save['statement_num'];
$v['verify_log'] = json_encode($v['verify_log']);
$v['verify_status']=2;
$v['op_time']=time();
SM("company_statement","tab_")->save($v);
}
if ($is_success) {
$this->ajaxReturn(['status'=>1,'msg'=>'操作成功']);
} else {
$this->ajaxReturn(['status'=>0,'msg'=>'操作失败']);
}
}
//审批通过
public function adminAgree(){
$this->setVerifyStatus(0,1,"admin");
}
public function adminRefuse(){
$this->setVerifyStatus(0,-1,"admin");
}
public function adminCancel(){
$canCancel = [1,-1,-2];
if(!isset($_REQUEST['ids'])) $this->error("参数错误");
$ids = $_REQUEST['ids'];
$dbres = $this->DBModel->field("id,verify_status,verify_log")->where("id in ({$ids})")->select();
foreach($dbres as $k=>&$v){
if(!in_array($v['verify_status'],$canCancel)) continue;
$v['verify_log'] = json_decode($v['verify_log'],true);
unset($v['verify_log']['admin_user'],$v['verify_log']['admin_time'],$v['verify_log']['pool_user'],$v['verify_log']['pool_time'],$v['verify_log']['pool_num']);
$v['verify_log'] = json_encode($v['verify_log']);
$v['verify_status'] = 0;
$v['confirm_log'] = '';
$v['confirm_status']=0;
$this->DBModel->save($v);
}
$this->ajaxReturn(array(
'status' => 1,
"info"=>"审核撤回成功"
));
}
public function launch(){
if(!isset($_REQUEST['ids'])) $this->error("参数错误");
$ids = $_REQUEST['ids'];
$dbres = $this->DBModel->field("id,confirm_status,confirm_log")->where("id in ({$ids})")->select();
foreach($dbres as $k=>&$v){
if($v['confirm_status'] != 0) continue;
$v['confirm_log'] = json_decode($v['confirm_log'],true);
$v['confirm_log']['launch_user']=$this->admininfo["username"];
$v['confirm_log']['launch_time']=date("Y.m.d H:i:s");
$v['confirm_log'] = json_encode($v['confirm_log']);
$v['confirm_status']=1;
// $v['op_time'] = time();
$this->DBModel->save($v);
addOperationLog(['op_type'=>1,'key'=>$v['id'],"op_name"=>"发起确认",'url'=>U('lists')]);
}
$this->ajaxReturn(array(
'status' => 1,
"info"=>"对外发起成功"
));
}
protected function setVerifyStatus($old_status,$change_status,$op_pre)
{
if(!isset($_REQUEST['ids'])) $this->error("参数错误");
$ids = $_REQUEST['ids'];
$dbres = $this->DBModel->field("id,verify_status,verify_log")->where("id in ({$ids})")->select();
foreach($dbres as $k=>&$v){
if($v['verify_status'] != $old_status) continue;
$v['verify_log'] = json_decode($v['verify_log'],true);
$v['verify_log'][$op_pre.'_user']=$this->admininfo["username"];
$v['verify_log'][$op_pre.'_time']=date("Y.m.d H:i:s");
$v['verify_log'] = json_encode($v['verify_log']);
$v['verify_status']=$change_status;
$v['op_time'] = time();
$this->DBModel->save($v);
$opname = $this->VerifyStatus[$change_status];
addOperationLog(['op_type'=>1,'key'=>$v['id'],"op_name"=>$opname,'url'=>U('lists')]);
}
$this->ajaxReturn(array(
'status' => 1,
"info"=>$opname."成功"
));
}
//保存备注
public function saveRemark(){
if(!isset($_REQUEST['id'])) $this->error("参数错误");
$id = $_REQUEST['id'];
$remark = $_REQUEST['remark'];
$this->DBModel->where("id = '{$id}'")->save(['remark'=>$remark]);
$this->ajaxReturn(array(
'status' => 1,
'info' => "操作成功"
));
}
//重算
public function updateStatement()
{
if(!isset($_REQUEST['ids'])) $this->error("参数错误");
$ids = $_REQUEST['ids'];
$dbres = $this->DBModel->field("id,verify_status,verify_log,withdraw_type")->where("id in ({$ids})")->select();
foreach($dbres as $k=>&$v){
// if(in_array($v['verify_status'],[3,4])) continue; //合作方确认后不进行重算
//重算
if ($v['withdraw_type']!=3) {
if(IS_SUBSITE){
$res = A("SubCompanyStatementSet")->updateCompanyStatementData($v['id'],$this->admininfo["username"]);
}else{
$res = A("CompanyStatementSet")->updateCompanyStatementData($v['id'],$this->admininfo["username"]);
}
if($res === false){
$this->ajaxReturn(array(
'status' => 0,
"info"=>"重算金额错误"
));
}
} else {
$res = self::$specialCompoent->updateSpecialStatement($v['id'],$v['withdraw_type']);
if($res === false){
$this->ajaxReturn(array(
'status' => 0,
"info"=>"重算金额错误"
));
}
}
}
$this->ajaxReturn(array(
'status' => 1,
"info"=>"重算金额成功"
));
}
//导出
public function export()
{
if(!isset($_REQUEST['id'])) $this->error("参数错误");
$id = $_REQUEST['id'];
$data = $this->DBModel->where(['id' => $id])->find();
$data['first_party_info'] = json_decode($data['first_party_info'], 1);//甲方
$data['second_party_info'] = json_decode($data['second_party_info'], 1);//乙方
$data['statement_info'] = json_decode($data['statement_info'], 1);//结算记录
if(is_array($data['statement_info'])) {
foreach ($data['statement_info'] as $key => $value) {
if ($value['game_name'] == "罚款" || $value['game_name'] == "奖励") {
$data['statement_info'][$key]['pay_amount'] = "-";
}
}
}
//收款方
$all_sum_money = $data['pay_amount'];//合计平台总额
$all_pay_amount = $data['statement_money'];//合计结算金额
$big_all_sum_money = convertAmountToCn($data['statement_money']);//大写
if($data['pay_type'] == 2){
$data['receive_company'] = $data['second_party_info'];//收款方
$data['pay_company'] = $data['first_party_info'];
}else{
$data['receive_company'] = $data['first_party_info'];
$data['pay_company'] = $data['second_party_info'];
}
if($data['receive_company']['invoice_type'] == 0){
$data['receive_company']['invoice_type']="";
} elseif($data['receive_company']['invoice_type'] == 1){
$data['receive_company']['invoice_type']="专票";
} else{
$data['receive_company']['invoice_type']="普票";
}
if($data['company_name'] == $data['first_party_info']['partner']){
$data['my_company'] = $data['second_party_info']['partner'];
}else{
$data['my_company'] = $data['first_party_info']['partner'];
}
if ($data['company_belong'] == 9) {//上游
if(!IS_SUBSITE){
excelUpStreamTemplate($data, $all_sum_money, $all_pay_amount, $big_all_sum_money);
}else{
excelSubUpStreamTemplate($data, $all_sum_money, $all_pay_amount, $big_all_sum_money);
}
} else {
//下游
// if($dbres["company_type"] == 1){
if ($data['withdraw_type'] == 3 && $data['company_type'] == 2) {
$dbres = $this->DBModel->where(['id' => $id])->find();
if($dbres['pay_type'] == 2){
//乙方收款
$dbres['company_info'] = $dbres['second_party_info'];
}else{
$dbres['company_info'] = $dbres['first_party_info'];
}
unset($dbres['second_party_info']);
unset($dbres['first_party_info']);
$dbres=[$dbres];
$this->assign("title","下游个人特殊补点");
$this->assign("is_special_export",true);
$this->exportSpecialComplement($dbres,1);
} else if ($data['withdraw_type'] == 3 && $data['company_type'] != 2){
excelSpecialComplementEmplate($data, $all_sum_money, $all_pay_amount, $big_all_sum_money);
}
else {
excelDownStreamTemplate($data, $all_sum_money, $all_pay_amount, $big_all_sum_money);
}
// }else{
// $data['statement_begin_time'] = date('Ymd',$data['statement_begin_time']);
// $data['statement_end_time'] = date('Ymd',$data['statement_end_time']);
// $data['statement_count'] = count($data['statement_info']);
// // dd($data);
// $this->assign("data",$data);
// $this->display("exportPuStatement");
// }
}
}
public function exportSpecialComplement(&$infolist,$is_export) {
$line = 1;
$count = [];
$week_line = 2;
$withdraw_type = false;
//获取对接人
foreach($infolist as $k=>&$v){
$infolist[$k]['reward'] = 0;
$infolist[$k]['fine'] = 0;
$v['statement_info'] = json_decode($v['statement_info'],true);
$v['company_info'] = json_decode($v['company_info'],true);
$v['statement_begin_time'] = date('Y.m.d',$v['statement_begin_time']);
$v['statement_end_time'] = date('Y.m.d',$v['statement_end_time']);
$v['company_info']['nickname'] = $v['statement_info'][0]['real_name'];
if (isset($v['company_info']['company_type'])) {
if($v['company_info']['company_type'] == 1) {
$v['company_info']['company_type_str'] = '公司';
} elseif($v['company_info']['company_type'] == 2){
$v['company_info']['company_type_str'] = '个人';
}
}
if (isset($v['company_info']['company_belong'])) {
$v['company_info']['company_belong_str'] = getCompanyBlong($v['company_info']['company_belong']);
}
if (isset($v['company_info']['develop_type'])) {
$v['company_info']['company_relation_str'] = getCompanyRelation($v['company_info']['develop_type']);
}
$cline = $line+1;
if($is_export){
$v['statement_money'] = "=ROUND(";
}
$handle_data = A("CompanyStatementPool")->changeDataStruct($v['statement_info'],$is_export,$week_line);
$v['statement_info'] = $handle_data;
$row = 0;
foreach($v['statement_info'] as $ke=>&$va){
$va['row'] = count($va['game_list']);
$row += count($va['game_list']);
foreach($va['game_list'] as $key=>&$val){
if(!$withdraw_type){
$withdraw_type = $v['withdraw_type'];
}
$line ++;
if($v['withdraw_type'] != 3) {
if(isset($val['ratio'])){
$val['increment_ratio'] = 0;
}else{
$val['ratio'] = 0;
}
}
if($is_export){
if($v['withdraw_type'] != 3) {
$val['sum_money'] = "=ROUND((L{$line}-M{$line})*(N{$line}+O{$line}),2)";
} else {
$val['sum_money'] = "=ROUND((L{$line}-M{$line})*(O{$line}),2)";
}
// $val['sum_money'] = "=J{$line}*(K{$line}+L{$line})";
$v['statement_money'] .= "T{$line}+";
}else{
$count['platform_amount'] += $val['pay_amount'];
$count['sum_money'] += $val['sum_money'];
}
}
}
$v['row'] = $row;
if($is_export){
if($v['withdraw_type'] != 3) {
$v['statement_money'] .="N{$cline}-O{$cline},2)";
} else {
$v['statement_money'] = substr($v['statement_money'],0,strlen($v['statement_money'])-1).",2)";
}
}
}
if($is_export){
$count["platform_amount"] = "=ROUND(SUM(L2:L".$line."),2)";
$count["week_money"] = "=ROUND(SUM(T2:T".$line."),2)";
$count["sum_money"] = "=ROUND(SUM(U2:U".$line."),2)";
}
$this->assign("data",$infolist);
$this->assign("count",$count);
$this->assign("is_export",$is_export);
$this->assign("withdraw_type",$withdraw_type);
// dd($infolist);
$this->display("CompanyStatementPool/viewPuPool");
}
public function pool_splice() {
$ids = $_REQUEST['ids'];
$arr_ids = explode(",",$ids);
$dbres = $this->DBModel->field("id,company_id")->where("id in ({$ids}) and withdraw_type=3")->select();
$upset_ids = array_column($dbres,"id");
$handle_data = [];
$hkey = 0;
//拆分特殊补点单相同公司的
foreach ($dbres as $key => $value) {
for (;;) {
if (!$handle_data[$hkey][$value["company_id"]]) {
$handle_data[$hkey][$value["company_id"]]= $value['id'];
break;
} else {
$hkey++;
}
if ($hkey>=50) break;
}
$hkey = 0;
}
// dump($handle_data);
//特殊补点结算单发起汇总
foreach ($handle_data as $key => $value) {
$pool_ids = implode(",",array_values($value));
// dump($pool_ids);
if ($pool_ids) {
$this->pool($pool_ids);
}
}
// die();
//普通结算单发起汇总
$arr_ids = implode(",",array_diff($arr_ids,$upset_ids));
if ($arr_ids) {
$this->pool($arr_ids);
}
$this->ajaxReturn(array(
'status' => 1,
"info"=>"汇总成功"
));
}
//汇总
public function pool($pool_ids = "")
{
if(!isset($pool_ids)) $this->error("参数错误");
$ids = $pool_ids;
$dbres = $this->DBModel->field("*")->where("id in ({$ids})")->select();
$check = [];
$is_complement = 0;
foreach($dbres as $key => $value) {
$check[$value['withdraw_type']] = 1;
if ($value['withdraw_type'] == 3) {
$is_complement = 1;
}
}
if (count($check)>1&&$is_complement) {
$this->error("特殊补点不能与其他结算单一起汇总");
}
//分单
$basedata = [
"pay_amount"=>0,
"statement_money"=>0,
"lack_statement_money"=>0,
"platform_amount"=>0,
"lack_platform_amount"=>0,
"create_lack_ids"=>[],
"del_lack_ids"=>[],
"statement_ids"=>[],
"info_ids"=>[],
"statement_begin_time"=>0,
"statement_end_time"=>0,
"fine"=>0,
"reward"=>0,
"verify_status"=>0,
"verify_log"=>json_encode(["create_user"=>$this->admininfo["username"],"create_time"=>date("Y.m.d H:i:s")]),
"op_time"=>time(),
"company_list"=>[]
];
$datas = ["up","down","complement_down","complement_user"];
//初始化数据
foreach($datas as $k=>$v){
if($v =="up"){
$basedata['company_type']=3;
$basedata['is_payment']=1;
}
if($v =="down"){
$basedata['company_type']=1;
$basedata['is_payment']=1;
}
if($v =="complement_down") {
$basedata['company_type']=1;
$basedata['is_payment']=1;
}
if($v =="complement_user") {
$basedata['company_type']=2;
$basedata['is_payment']=1;
}
$datas[$v]=$basedata;
unset($datas[$k]);
}
foreach ($dbres as $k=>$v) {
if($v['verify_status'] == 1 || $v['verify_status'] == -2){
if($v['company_belong'] == 9){
//上游
$this->setDf($datas['up'],$v);
} elseif($v['withdraw_type'] == 3&&$v['company_type']==1){
$this->setDf($datas['complement_down'],$v);
} elseif($v['withdraw_type'] == 3&&$v['company_type']==2){
$this->setDf($datas['complement_user'],$v);
} else {
$this->setDf($datas['down'],$v);
}
}
}
$Pool = SM("company_statement_pool","tab_");
$Statemen = $this->DBModel;
foreach ($datas as $k => $v) {
if(count($v['company_list']) <= 0){continue;}
$v['statement_num'] = "PL_".date('Ymd').date('His').sp_random_num(3);
//保存公司信息
$company_list = $v['company_list'];
foreach ($company_list as $ke => $va) {
$this->addStatementInfo($va,$k,$v);
}
if(empty($v['create_lack_ids']) && empty($v['del_lack_ids']) && empty($v['info_ids'])){ continue;}
$v['statement_ids'] = implode(",",$v['statement_ids']);
$v['create_lack_ids'] = implode(",",$v['create_lack_ids']);
$v['del_lack_ids'] = implode(",",$v['del_lack_ids']);
$info = implode(",",$v['info_ids']);
unset($v['info_ids']);
unset($v['company_list']);
if($v['statement_money'] == 0){
$v['verify_status'] = 5;
$v['verify_log'] = json_encode(["create_user"=>$this->admininfo["username"],"create_time"=>date("Y.m.d H:i:s"),"verify_user"=>"system","verify_time"=>date("Y.m.d H:i:s"),"payment_user"=>"system","payment_time"=>date("Y.m.d H:i:s")]);
}
//判断周月结
if(($v["statement_end_time"]-$v['statement_begin_time']) > 7*24*3600){
$v["withdraw_type"] = 1;
}else{
$v["withdraw_type"] = 0;
}
if ($is_complement) {
$v["withdraw_type"] = 3;
}
$pool_id = $Pool->add($v);
if($pool_id == false){
$this->ajaxReturn(array('status' => 0,"info"=>"汇总失败"));
}
if(!empty($info)){
$save["pool_id"]=$pool_id;
SM("company_statement_info","tab_")->where("id in ({$info})")->save($save);
}
if(!empty($v['del_lack_ids'])){
SM("company_lack_statement_info","tab_")->where("id in ({$v['del_lack_ids']})")->save(["is_pool"=>1]);
}
//修改结算单规则
$this->updatePoolVerifyStatus($v['statement_ids'],2,"pool",$v['statement_num']);
}
}
//结算单规则
protected function updatePoolVerifyStatus($ids,$change_status,$op_pre,$num){
$dbres = $this->DBModel->field("id,verify_status,verify_log")->where("id in ({$ids})")->select();
foreach($dbres as $k=>&$v){
// if($v['verify_status'] != $old_status) continue;
$v['verify_log'] = json_decode($v['verify_log'],true);
$v['verify_log'][$op_pre.'_user']=$this->admininfo["username"];
$v['verify_log'][$op_pre.'_time']=date("Y.m.d H:i:s");
$v['verify_log'][$op_pre.'_num']=$num;
$v['verify_log'] = json_encode($v['verify_log']);
$v['verify_status']=$change_status;
$v['op_time']=time();
$this->DBModel->save($v);
}
}
//保存
protected function addStatementInfo($va,$k,&$v){
$StatementInfo = SM("company_statement_info","tab_");
$company_info = $va['company_info'];
$LackStatement = SM("company_lack_statement_info","tab_");
$no_pool_money = 0;//公司原定小于300不结算现在取消
//统一比例字段
if($k == "up" || $k=="ups"){
// $no_pool_money = 500;//上游原定小于500不结算现在取消
foreach ($va['statement_info'] as $key => &$value) {
if($company_info['pay_type'] == 2){
$value["ratio"] = $value["second_ratio"];
}else{
$value["ratio"] = $value["first_ratio"];
}
unset($value["first_ratio"]);
unset($value["second_ratio"]);
}
}
if($va['is_payment'] == 1){
$is_payment = 1;
$verify_status = 0;
}else{
$is_payment = 2;
$verify_status = 2;
}
//创建基础未满基础信息
if($va['platform_amount'] < $no_pool_money && $va['withdraw_type']!=3){
$lackcompany =[
"company_id"=>$company_info['id'],
"company_type"=>$v['company_type'],
"company_name"=>$company_info['partner'],
"company_info"=>json_encode($company_info,JSON_UNESCAPED_UNICODE),
"statement_money"=>$va['statement_money'],
"pay_amount"=>$va['pay_amount'],
"platform_amount"=>$va['platform_amount'],
"fine"=>$va['fine'],
"reward"=>$va['reward'],
"statement_begin_time"=>$v['statement_begin_time'],
"statement_end_time"=>$v['statement_end_time'],
"is_payment"=>$is_payment,
"statement_pool_num"=>$v['statement_num'],
"statement_info"=>json_encode($va['statement_info'],JSON_UNESCAPED_UNICODE),
];
}
//整合数据
if ($k!='complement_down' && $k != 'complement_user') {
$lsres = $LackStatement->where("company_id={$company_info['id']} and is_pool = 0 and company_type = {$v['company_type']}")->select();
} else {
$lsres = $LackStatement->where("company_id={$company_info['id']} and is_pool = 0 and withdraw_type = 3 and company_type = {$v['company_type']}")->select();
}
$del_lack_ids = [];
if(count($lsres) > 0){
//进行聚合
foreach($lsres as $key=>$val){
$del_lack_ids[] = $val['id'];
$va['statement_money'] += $val['statement_money'];
$va['pay_amount'] += $val['pay_amount'];
$va['fine'] += $val['fine'];
$va['reward'] += $val['reward'];
$va['platform_amount'] += $val['platform_amount'];
$va['statement_info'] = array_merge($va['statement_info'],json_decode($val['statement_info'],true));
$last_names = array_column($va['statement_info'],'game_name');
array_multisort($last_names,SORT_DESC,SORT_STRING,$va['statement_info']);
}
}
if($va['platform_amount'] < $no_pool_money&&($k!='complement_down' && $k != 'complement_user')){
//依旧小于不结算金额存旧版
if($lackcompany['pay_amount'] != 0){
$lask_id = $LackStatement->add($lackcompany);
$v['create_lack_ids'][] =$lask_id;
$v['lack_statement_money'] +=$lackcompany['statement_money'];
$v['lack_platform_amount'] +=$lackcompany['platform_amount'];
}
}else{
if($va['pay_amount'] != 0){
//存成功
$company =[
"pool_id"=>0,
"company_id"=>$company_info['id'],
"company_type"=>$v['company_type'],
"company_name"=>$company_info['partner'],
"company_info"=>json_encode($company_info,JSON_UNESCAPED_UNICODE),
"fine"=>$va['fine'],
"reward"=>$va['reward'],
"statement_money"=>$va['statement_money'],
"pay_amount"=>$va['pay_amount'],
"platform_amount"=>$va['platform_amount'],
"statement_begin_time"=>$v['statement_begin_time'],
"statement_end_time"=>$v['statement_end_time'],
"statement_info"=>json_encode($va['statement_info'],JSON_UNESCAPED_UNICODE),
"statement_num"=>$va['statement_num'],
"verify_status"=>$verify_status,
"withdraw_type"=>$va['withdraw_type'],
];
$companyid = $StatementInfo->add($company);
$v['info_ids'][] =$companyid;
$v['del_lack_ids'] =array_merge($v['del_lack_ids'],$del_lack_ids);
$v['statement_money'] +=$va['statement_money'];
$v['pay_amount'] +=$va['pay_amount'];
$v['platform_amount'] +=$va['platform_amount'];
$v['fine'] +=$va['fine'];
$v['reward'] +=$va['reward'];
}
}
}
//设定组合的子操作
protected function setDf(&$savedata,$v)
{
$savedata['statement_ids'][] = $v['id'];
unset($v['id']);
$v['statement_info'] = json_decode( $v['statement_info'],true);
$fine = 0;
$reward = 0;
foreach($v['statement_info'] as $ka=>$va){
if($va['statement_type'] == 2){
//奖励
// $savedata['reward'] += $va['sum_money'];
$reward += $va['sum_money'];
unset($v['statement_info'][$ka]);
}else if($va['statement_type'] == 1){
// $savedata['fine'] += $va['sum_money'];
$fine += $va['sum_money'];
unset($v['statement_info'][$ka]);
}
}
if(isset($savedata['company_list'][$v['company_id']])){
//存在游戏合并
$a = &$savedata['company_list'][$v['company_id']];
$a['fine'] += $fine;
$a['reward'] += $reward;
$a['statement_info'] = array_merge($a['statement_info'],$v['statement_info']);
// dump($a['statement_info']);
$a['platform_amount'] += $v['platform_amount'];
$a['pay_amount'] += $v['pay_amount'];
$a['statement_money'] += $v['statement_money'];
}else{
if($v['pay_type'] == 2){
//乙方收款
$v['company_info'] =json_decode($v['second_party_info'],true);
$v['company_info']['pay_type'] = 2;
}else{
$v['company_info'] = json_decode($v['first_party_info'],true);
$v['company_info']['pay_type'] = 1;
}
if (isset($v['company_info']['company_type'])) {
if($v['company_info']['company_type'] == 1) {
$v['company_info']['company_type_str'] = '公司';
} elseif($v['company_info']['company_type'] == 2){
$v['company_info']['company_type_str'] = '个人';
}
}
if (isset($v['company_info']['company_belong'])) {
$v['company_info']['company_belong_str'] = getCompanyBlong($v['company_info']['company_belong']);
}
if (isset($v['company_info']['develop_type'])) {
$v['company_info']['company_relation_str'] = getCompanyRelation($v['company_info']['develop_type']);
}
//先分配好订单号,防止重复提交
$tdata = [
"company_info"=>$v['company_info'],
"company_name"=>$v['company_name'],
"platform_amount"=>$v['platform_amount'],
"pay_amount"=>$v['pay_amount'],
"statement_money"=>$v['statement_money'],
"fine"=>$fine,
"reward"=>$reward,
"statement_info"=>$v['statement_info'],
"statement_num"=>"JS_".date('Ymd').date('His').$v['company_id'].sp_random_string(5),
"is_payment"=>$v['is_payment'],
"withdraw_type"=>$v['withdraw_type'],
];
$savedata['company_list'][$v['company_id']] = $tdata;
}
// $savedata['pay_amount'] += $v['pay_amount'];
// $savedata['statement_money'] += $v['statement_money'];
// $savedata['platform_amount'] += $v['platform_amount'];
if($savedata['statement_begin_time'] == 0){
$savedata['statement_begin_time'] = $v['statement_begin_time'];
}elseif($v['statement_begin_time'] < $savedata['statement_begin_time']){
$savedata['statement_begin_time'] = $v['statement_begin_time'];
}
if($savedata['statement_end_time'] == 0){
$savedata['statement_end_time'] = $v['statement_end_time'];
}elseif($v['statement_end_time'] > $savedata['statement_end_time']){
$savedata['statement_end_time'] = $v['statement_end_time'];
}
}
//新增结算
public function getNewStatement()
{
//获取要结算的公司及日期
$senddata = [
"up_company_id"=>[],
"dowm_company_id"=>[],
];
$statement = $this->DBModel->field("count(id) count,company_id,company_belong")->group("company_id,company_belong")->select();
$up_company_id = [];
$dowm_company_id= [];
foreach( $statement as $k=>$v){
if($v['company_belong'] == 9){
$up_company_id[] = $v['company_id'];
}else{
$dowm_company_id[]= $v['company_id'];
}
};
//获取上游
if(empty($up_company_id)){
$upwhere = "1=1";
}else{
$up_company_id =implode(",",$up_company_id);
$upwhere = "(first_company_type = 1 AND first_company_id NOT IN ({$up_company_id}) ) OR ( second_company_type = 1 AND second_company_id NOT IN ({$up_company_id}) )";
}
$uprelation = M("company_relation","tab_")->field("first_company_id,first_company_type,second_company_id,second_company_type")->where($upwhere)->select();
foreach($uprelation as $k=>$v){
if($v['first_company_type'] == 0){
$senddata["up_company_id"][] = $v['second_company_id'];
}else{
$senddata["up_company_id"][] = $v['first_company_id'];
}
}
//获取下游
if(empty($dowm_company_id)){
$downwhere = "1=1";
}else{
$dowm_company_id =implode(",",$dowm_company_id);
$downwhere = "(first_company_type = 2 AND first_company_id NOT IN ({$dowm_company_id}) ) OR ( second_company_type = 2 AND second_company_id NOT IN ({$dowm_company_id}) )";
}
$downrelation = M("company_relation","tab_")->field("first_company_id,first_company_type,second_company_id,second_company_type")->where($downwhere)->select();
foreach($downrelation as $k=>$v){
if($v['first_company_type'] == 0){
$senddata["dowm_company_id"][] = $v['second_company_id'];
}else{
$senddata["dowm_company_id"][] = $v['first_company_id'];
}
}
if(count($senddata["up_company_id"]) < 1 && count($senddata["dowm_company_id"]) < 1){
$this->ajaxReturn(["error"=>'无新增关系,无需重算']);
}
$senddata['up_company_id'] = implode(",",$senddata['up_company_id']);
$senddata['dowm_company_id'] = implode(",",$senddata['dowm_company_id']);
//获取要结算的日期
$start = strtotime('-1 month');
$end = time();
$temp_datelist = get_date_list($start,$end,1);
$datelist = [];
foreach($temp_datelist as $k=>$v){
$w = (int)date("w",strtotime($v));
$d = (int)date("d",strtotime($v));
if($w == 1 || $d == 1){
$datelist[] = $v;
}
}
$senddata['datelist'] = $datelist;
$senddata['count'] = count($datelist);
$this->ajaxReturn(["success"=>'ok',"data"=>$senddata]);
}
public function updateNewStatement()
{
$up_company_id = $_REQUEST['up_company_id'];
$dowm_company_id = $_REQUEST['dowm_company_id'];
$date = $_REQUEST['date'];
$CompanyStatementSet = A("CompanyStatementSet");
// dd($CompanyStatementSet);
$stime = strtotime($date);
$w = (int)date("w",strtotime($date));
$d = (int)date("d",strtotime($date));
if($w == 1){
if(!empty($up_company_id)){
$CompanyStatementSet->cpStatement(0,$stime,$up_company_id,false);
}
if(!empty($dowm_company_id)){
$CompanyStatementSet->promoteCompanyStatement(0,$stime,$dowm_company_id,false);
}
}
if($d == 1){
if(!empty($up_company_id)){
$CompanyStatementSet->cpStatement(1,$stime,$up_company_id,false);
$CompanyStatementSet->cpStatement(2,$stime,$up_company_id,false);
}
if(!empty($dowm_company_id)){
$CompanyStatementSet->promoteCompanyStatement(1,$stime,$dowm_company_id,false);
$CompanyStatementSet->promoteCompanyStatement(2,$stime,$dowm_company_id,false);
}
}
$this->ajaxReturn(array("success"=>"ok","data"=>[]));
}
//子站新增结算
public function subAddStatement(){
if(!isset($_REQUEST['statement_time'])) $this->error("参数错误");
$statement_time = $_REQUEST['statement_time'];
$end = date("Y-m-d",strtotime($statement_time)+ 86400);
$utime = strtotime($statement_time)+86399;
$LastStatementTime = M("Kv","sub_",SUBSITE_DB)->where("`key` = 'sub_company_statement'")->getField("value");
$begin = date("Y-m-d",$LastStatementTime-0+1);
$params = "php ".SUBSITE_INDEX." SubCompanyStatementSet/setFreeDateCount/begin/{$begin}/end/{$end}/utime/{$utime}";
$r = D("CmdTasks")->addTask("SubCompanyStatementSet",$params);
if($r){
$this->ajaxReturn(["status"=>1,"info"=>"任务登记成功,请等待五分分钟后查看结果"]);
}else{
$this->ajaxReturn(["status"=>0,"info"=>"任务登记错误"]);
}
}
public function viewSpecialComplement() {
$this->display();
}
public function checkComplementHistory() {
$data = json_decode($_REQUEST['data'],true);
$return_data = [];
foreach ($data as $dkey => $dval) {
$check_add = $this->DBModel->field("statement_begin_time,statement_end_time,statement_info,company_type")->where(['company_id'=>$dval['company_id'],'withdraw_type'=>3])->select();
$start_time = strtotime($dval['statement_begin_time']);
$end_time = strtotime($dval['statement_end_time']) + 86399;
$relation_game_data = array_column($dval['statement_info'],'relation_game_id');
foreach ($check_add as $key => $value) {
$statementInfo = json_decode($value['statement_info'],true);;
if ($value['company_type'] == 2) {
foreach ($statementInfo as $sk => $sv) {
$statementInfos = $sv['game_list'];
foreach ($statementInfos as $k => $v) {
if (strtotime(str_replace('.','-',$v['statement_end_time'])) >= $start_time && strtotime(str_replace('.','-',$v['statement_end_time']))<=$end_time
||strtotime(str_replace('.','-',$v['statement_begin_time']))>=$start_time && strtotime(str_replace('.','-',$v['statement_begin_time']))<=$end_time
||strtotime(str_replace('.','-',$v['statement_begin_time']))<=$start_time && strtotime(str_replace('.','-',$v['statement_end_time'])) >= $end_time) {
if (!in_array($v['game_name'], $return_data[$dval['company_name']])) {
$return_data[$dval['company_name']][]=$v['game_name'];
}
}
}
}
} else {
foreach ($statementInfo as $k => $v) {
if (strtotime(str_replace('.','-',$v['statement_end_time'])) >= $start_time && strtotime(str_replace('.','-',$v['statement_end_time']))<=$end_time
||strtotime(str_replace('.','-',$v['statement_begin_time']))>=$start_time && strtotime(str_replace('.','-',$v['statement_begin_time']))<=$end_time
||strtotime(str_replace('.','-',$v['statement_begin_time']))<=$start_time && strtotime(str_replace('.','-',$v['statement_end_time'])) >= $end_time) {
if (!in_array($v['game_name'], $return_data[$dval['company_name']])) {
$return_data[$dval['company_name']][]=$v['game_name'];
}
}
}
}
}
}
$return_str = "";
foreach ($return_data as $key => $value) {
$return_str .= "[{$key}]";
}
if (!$return_data) {
$this->ajaxReturn(['status' => 0, 'data' => $return_str]);
} else {
$this->ajaxReturn(['status' => 1, 'data' => $return_str]);
}
}
public function addSpecialComplement() {
$map = [];
$radioMap = [];
$relation_game_id = implode(',',$_REQUEST['relation_game_id']);
$relation_game_data = $_REQUEST['relation_game_id'];
if ($_REQUEST['relation_game_id']) {
$relation_game_id = implode(',',$_REQUEST['relation_game_id']);
// dd($relation_game_id);
$map['relation_game_id'] = ['in',$relation_game_id];
$radioMap['tab_company_game_ratio.relation_game_id'] = ['in',$relation_game_id];
}
if ($_REQUEST['company_id']) {
$promote_id = M("promote","tab_")
->field("id")
->where(['company_id'=>$_REQUEST['company_id']])
->select();
if ($promote_id) {
$map['promote_id'] = ['in',array_column($promote_id,'id')];
} else {
$map['promote_id'] = '-1';
}
$radioMap['company_id'] = $_REQUEST['company_id'];
}
$start_time = strtotime($_REQUEST['time_start']);
$end_time = strtotime($_REQUEST['time_end']) + 86399;
// $check_add = $this->DBModel->field("statement_begin_time,statement_end_time,statement_info,company_type")->where(['company_id'=>$_REQUEST['company_id'],'withdraw_type'=>3])->select();
//
// foreach ($check_add as $key => $value) {
//
//// if ($value['statement_end_time'] >= $start_time && $value['statement_end_time']<=$end_time
//// ||$value['statement_begin_time']>=$start_time && $value['statement_begin_time']<=$end_time
//// ||$value['statement_begin_time']<=$start_time && $value['statement_end_time'] >= $end_time)
//// {
//
// $statementInfo = json_decode($value['statement_info'],true);;
// if ($value['company_type'] == 2) {
//
// foreach ($statementInfo as $sk => $sv) {
// $statementInfos = $sv['game_list'];
// foreach ($statementInfos as $k => $v) {
// if (strtotime(str_replace('.','-',$v['statement_end_time'])) >= $start_time && strtotime(str_replace('.','-',$v['statement_end_time']))<=$end_time
// ||strtotime(str_replace('.','-',$v['statement_begin_time']))>=$start_time && strtotime(str_replace('.','-',$v['statement_begin_time']))<=$end_time
// ||strtotime(str_replace('.','-',$v['statement_begin_time']))<=$start_time && strtotime(str_replace('.','-',$v['statement_end_time'])) >= $end_time) {
// if (in_array($v['relation_game_id'], $relation_game_data)) {
// $this->ajaxReturn(['status' => 0, 'data' => [], 'msg' => "《{$v['game_name']}》在日期:{$_REQUEST['time_start']}-{$_REQUEST['time_end']}有结算过的部分,请重新选择"]);
// }
// }
// }
// }
// } else {
// foreach ($statementInfo as $k => $v) {
// if (strtotime(str_replace('.','-',$v['statement_end_time'])) >= $start_time && strtotime(str_replace('.','-',$v['statement_end_time']))<=$end_time
// ||strtotime(str_replace('.','-',$v['statement_begin_time']))>=$start_time && strtotime(str_replace('.','-',$v['statement_begin_time']))<=$end_time
// ||strtotime(str_replace('.','-',$v['statement_begin_time']))<=$start_time && strtotime(str_replace('.','-',$v['statement_end_time'])) >= $end_time) {
// if (in_array($v['relation_game_id'], $relation_game_data)) {
// $this->ajaxReturn(['status' => 0, 'data' => [], 'msg' => "《{$v['game_name']}》在日期:{$_REQUEST['time_start']}-{$_REQUEST['time_end']}有结算过的部分,请重新选择"]);
// }
// }
// }
// }
//
//
//// }
//
// }
if (isset($_REQUEST['time_start']) && isset($_REQUEST['time_end'])) {
$map['payed_time'] = ['between', [$start_time, $end_time]];
$radioMap['_string'] = "(begin_time>{$start_time} and begin_time<{$end_time})
or (end_time>{$start_time} and (end_time<{$end_time} and end_time!=0)) or (begin_time<{$start_time} and end_time>{$end_time}) or (begin_time<{$start_time} and end_time = 0)";
} elseif (isset($_REQUEST['time_start'])) {
$map['payed_time'] = ['GT', $start_time];
$radioMap['_string'] = "end_time > {$start_time}";
} elseif (isset($_REQUEST['time_end'])) {
$map['payed_time'] = ['LT', $end_time];
$radioMap['_string'] = "start_time < {$end_time}";
}
$map['tab_spend.pay_status'] = 1;
// $map['pay_way'] = ['egt',0];
$data = M("spend","tab_")
->field("pay_amount,relation_game_id,relation_game_name,payed_time")
->join("left join tab_game game on tab_spend.game_id=game.id")
->where($map)
->select(false);
//默认游戏模板比例
$gameRatioMould = M("game_ratio_mould","tab_")
->field("ratio,turnover_ratio,relation_game_id")
->where(['relation_game_id'=>['in',$relation_game_id],'company_belong'=>$_REQUEST['company_type']])
->select();
//各个游戏的模板比例
$handleRadioMould = [];
foreach($gameRatioMould as $key => $value) {
$handleRadioMould[$value['relation_game_id']]['ratio'] = $value['ratio'];
$handleRadioMould[$value['relation_game_id']]['turnover_ratio'] = $value['turnover_ratio'];
}
$game_data = M("game","tab_")->field("relation_game_id,relation_game_name")->group("relation_game_id")->select(false);
$radioData = M("company_game_ratio","tab_")
->field("tab_company_game_ratio.*,game.relation_game_name")
->join("left join ({$game_data}) game on tab_company_game_ratio.relation_game_id=game.relation_game_id")
->where($radioMap)
->order("begin_time ASC")
->select();
$handleRadioData = [];
foreach($radioData as $key => $value) {
$handleRadioData[$value['relation_game_id']] = $value['relation_game_name'];
}
$relationWhere = '(first_company_type=2 and first_company_id=' . $_REQUEST['company_id'] .
') or (second_company_type=2 and second_company_id=' . $_REQUEST['company_id'] . ')';
$relation = M('company_relation', 'tab_')->where($relationWhere)->find();
$companyData = M("promote_company","tab_")
->field("company_name,ali_user,ali_account,bank_address,bank_card,bank_name")
->where(['id'=>$_REQUEST['company_id']])
->find();
$num = 0;
$handleData = [];
foreach ($relation_game_data as $rkey => $rvalue) {
if (!$handleRadioData[$rvalue]) {
$game_name = M("game","tab_")
->field("relation_game_id,relation_game_name")
->where(['relation_game_id'=>['in',$rvalue]])
->find();
$handleData[$_REQUEST['company_id']]['company_id'] = $_REQUEST['company_id'];
$handleData[$_REQUEST['company_id']]['is_payment'] = $relation['is_payment'];
$handleData[$_REQUEST['company_id']]['ali_user'] = $companyData['ali_user'];
$handleData[$_REQUEST['company_id']]['ali_account'] = $companyData['ali_account'];
$handleData[$_REQUEST['company_id']]['payee_name'] = $companyData['bank_address'];
$handleData[$_REQUEST['company_id']]['bank_account'] = $companyData['bank_card'];
$handleData[$_REQUEST['company_id']]['opening_bank'] = $companyData['bank_name'];
$handleData[$_REQUEST['company_id']]['company_name'] = $companyData['company_name'];
$handleData[$_REQUEST['company_id']]['begin_time'][] = strtotime(I('time_start'));
$handleData[$_REQUEST['company_id']]['end_time'][] = strtotime(I('time_end')) + 86399;
$handleData[$_REQUEST['company_id']]['relation_game_id'][] = $rvalue;
$handleData[$_REQUEST['company_id']]['relation_game_name'][] = $game_name['relation_game_name'];
$handleData[$_REQUEST['company_id']]['ratio'][] = $handleRadioMould[$rvalue]['ratio']?$handleRadioMould[$rvalue]['ratio']:0;
$handleData[$_REQUEST['company_id']]['turnover_ratio'][] = $handleRadioMould[$rvalue]['turnover_ratio'];
}
}
foreach ($relation_game_data as $rk => $rv) {
unset($radioMap['tab_company_game_ratio.relation_game_id']);
$radioMap['tab_company_game_ratio.relation_game_id'] = $rv;
$radioGameRatios = M("company_game_ratio","tab_")
->field("tab_company_game_ratio.*,game.relation_game_name")
->join("left join ({$game_data}) game on tab_company_game_ratio.relation_game_id=game.relation_game_id")
->where($radioMap)
->order("begin_time ASC")
->select();
foreach ($radioGameRatios as $key => $value) {
if (strtotime(I('time_start')) <= $value['begin_time']) {
$handleData[$_REQUEST['company_id']]['begin_time'][] = $value['begin_time'];
} else {
$handleData[$_REQUEST['company_id']]['begin_time'][] = strtotime(I('time_start'));
}
if (strtotime(I('time_end')) > $value['end_time'] && $value['end_time']!=0) {
$handleData[$_REQUEST['company_id']]['end_time'][] = $value['end_time'];
} else {
$handleData[$_REQUEST['company_id']]['end_time'][] = strtotime(I('time_end')) + 86399;
}
$handleData[$_REQUEST['company_id']]['company_id'] = $_REQUEST['company_id'];
$handleData[$_REQUEST['company_id']]['is_payment'] = $relation['is_payment'];
if ($relation['is_payment'] == 1) {
$handleData[$_REQUEST['company_id']]['payee_name'] = $companyData['ali_user'];
$handleData[$_REQUEST['company_id']]['bank_account'] = $companyData['ali_account'];
$handleData[$_REQUEST['company_id']]['opening_bank'] = '';
} else {
$handleData[$_REQUEST['company_id']]['payee_name'] = $companyData['bank_address'];
$handleData[$_REQUEST['company_id']]['bank_account'] = $companyData['bank_card'];
$handleData[$_REQUEST['company_id']]['opening_bank'] = $companyData['bank_name'];
}
$handleData[$_REQUEST['company_id']]['company_name'] = $companyData['company_name'];
$handleData[$_REQUEST['company_id']]['relation_game_id'][] = $value['relation_game_id'];
$handleData[$_REQUEST['company_id']]['relation_game_name'][] = $value['relation_game_name'];
$handleData[$_REQUEST['company_id']]['ratio'][] = $value['ratio'];
$handleData[$_REQUEST['company_id']]['turnover_ratio'][] = $value['turnover_ratio'];
$num++;
//如果结算时间小于比例开始时间
if ($key == 0) {
if (strtotime(I('time_start')) < $value['begin_time']) {
$handleData[$_REQUEST['company_id']]['company_id'] = $_REQUEST['company_id'];
$handleData[$_REQUEST['company_id']]['is_payment'] = $relation['is_payment'];
if ($relation['is_payment'] == 1) {
$handleData[$_REQUEST['company_id']]['payee_name'] = $companyData['ali_user'];
$handleData[$_REQUEST['company_id']]['bank_account'] = $companyData['ali_account'];
$handleData[$_REQUEST['company_id']]['opening_bank'] = '';
} else {
$handleData[$_REQUEST['company_id']]['payee_name'] = $companyData['bank_address'];
$handleData[$_REQUEST['company_id']]['bank_account'] = $companyData['bank_card'];
$handleData[$_REQUEST['company_id']]['opening_bank'] = $companyData['bank_name'];
}
$handleData[$_REQUEST['company_id']]['company_name'] = $companyData['company_name'];
$handleData[$_REQUEST['company_id']]['begin_time'][] = strtotime(I('time_start'));
$handleData[$_REQUEST['company_id']]['end_time'][] = $value['begin_time']-1;
$handleData[$_REQUEST['company_id']]['relation_game_id'][] = $value['relation_game_id'];
$handleData[$_REQUEST['company_id']]['relation_game_name'][] = $value['relation_game_name'];
$handleData[$_REQUEST['company_id']]['ratio'][] = $handleRadioMould[$value['relation_game_id']]['ratio']?$handleRadioMould[$value['relation_game_id']]['ratio']:0;
$handleData[$_REQUEST['company_id']]['turnover_ratio'][] = $handleRadioMould[$value['relation_game_id']]['turnover_ratio'];
}
}
if(!$radioData[$key+1]) {
if (strtotime(I('time_end')) > $value['end_time'] && $value['end_time']!=0) {
$handleData[$_REQUEST['company_id']]['company_id'] = $_REQUEST['company_id'];
$handleData[$_REQUEST['company_id']]['is_payment'] = $relation['is_payment'];
if ($relation['is_payment'] == 1) {
$handleData[$_REQUEST['company_id']]['payee_name'] = $companyData['ali_user'];
$handleData[$_REQUEST['company_id']]['bank_account'] = $companyData['ali_account'];
$handleData[$_REQUEST['company_id']]['opening_bank'] = '';
} else {
$handleData[$_REQUEST['company_id']]['payee_name'] = $companyData['bank_address'];
$handleData[$_REQUEST['company_id']]['bank_account'] = $companyData['bank_card'];
$handleData[$_REQUEST['company_id']]['opening_bank'] = $companyData['bank_name'];
}
$handleData[$_REQUEST['company_id']]['company_name'] = $companyData['company_name'];
$handleData[$_REQUEST['company_id']]['begin_time'][] = $value['end_time'] + 1;
$handleData[$_REQUEST['company_id']]['end_time'][] = strtotime(I('time_end'))+86399;
$handleData[$_REQUEST['company_id']]['relation_game_id'][] = $value['relation_game_id'];
$handleData[$_REQUEST['company_id']]['relation_game_name'][] = $value['relation_game_name'];
$handleData[$_REQUEST['company_id']]['ratio'][] = $handleRadioMould[$value['relation_game_id']]['ratio']?$handleRadioMould[$value['relation_game_id']]['ratio']:0;
$handleData[$_REQUEST['company_id']]['turnover_ratio'][] = $handleRadioMould[$value['relation_game_id']]['turnover_ratio'];
}
}
//如果结算时间中有时间段间隔
if ($radioData[$key+1]) {
if ($radioData[$key+1]['begin_time'] != ($value['end_time']+1)&&$value['end_time']!=0) {
$handleData[$_REQUEST['company_id']]['company_id'] = $_REQUEST['company_id'];
$handleData[$_REQUEST['company_id']]['is_payment'] = $relation['is_payment'];
if ($relation['is_payment'] == 1) {
$handleData[$_REQUEST['company_id']]['payee_name'] = $companyData['ali_user'];
$handleData[$_REQUEST['company_id']]['bank_account'] = $companyData['ali_account'];
$handleData[$_REQUEST['company_id']]['opening_bank'] = '';
} else {
$handleData[$_REQUEST['company_id']]['payee_name'] = $companyData['bank_address'];
$handleData[$_REQUEST['company_id']]['bank_account'] = $companyData['bank_card'];
$handleData[$_REQUEST['company_id']]['opening_bank'] = $companyData['bank_name'];
}
$handleData[$_REQUEST['company_id']]['company_name'] = $companyData['company_name'];
$handleData[$_REQUEST['company_id']]['begin_time'][] = $value['end_time'] + 1;
$handleData[$_REQUEST['company_id']]['end_time'][] = $radioData[$key+1]['begin_time'] - 1;
$handleData[$_REQUEST['company_id']]['relation_game_id'][] = $value['relation_game_id'];
$handleData[$_REQUEST['company_id']]['relation_game_name'][] = $value['relation_game_name'];
$handleData[$_REQUEST['company_id']]['ratio'][] = $handleRadioMould[$value['relation_game_id']]['ratio']?$gameRatioMould['ratio']:0;
$handleData[$_REQUEST['company_id']]['turnover_ratio'][] = $handleRadioMould[$value['relation_game_id']]['turnover_ratio'];
}
}
}
}
foreach ($handleData as $key => $value) {
$handleData[$key]['row'] = 0;
$timeArr = $value['begin_time'];
foreach ($timeArr as $k => $v) {
$handleData[$key]['row']++;
$turnover_ratio = json_decode($value['turnover_ratio'][$k],true);
$amount_time['_string'] = "payed_time between {$value['begin_time'][$k]} and {$value['end_time'][$k]} and relation_game_id={$value['relation_game_id'][$k]}";
$pay_amount = M()->table("({$data})a")
->field("sum(pay_amount) pay_amount")
->where($amount_time)
->find();
$handleData[$key]['pay_amount'][$k] = $pay_amount['pay_amount']?$pay_amount['pay_amount']:"0.00";
// $handleData[$key]['withdraw_amount'][$k] = number_format($pay_amount['pay_amount'] * (((int)$value['ratio'][$k])/100),2,'.','');
$handleData[$key]['withdraw_amount'][$k] = "0.00";
foreach($turnover_ratio as $ke=>$va){
if(array_key_exists("instanceof",$va)){
//存在
if($va['instanceof']=='1'&&$pay_amount['pay_amount']>=$va['turnover']){
$handleData[$key]['ratio'] = $va["ratio"];
// $handleData[$key]['withdraw_amount'][$k] = number_format($pay_amount['pay_amount'] * ($va["ratio"]/100),2,'.','');
$handleData[$key]['withdraw_amount'][$k] = "0.00";
}elseif($pay_amount['pay_amount']>$va['turnover']){
$handleData[$key]['ratio'] = $va["ratio"];
// $handleData[$key]['withdraw_amount'][$k] = number_format($pay_amount['pay_amount'] * ($va["ratio"]/100),2,'.','');
$handleData[$key]['withdraw_amount'][$k] = "0.00";
}
}else{
if ($pay_amount['pay_amount']>=$va['turnover']) {
$handleData[$key]['ratio'] = $va["ratio"];
// $handleData[$key]['withdraw_amount'][$k] = number_format($pay_amount['pay_amount'] * ($va["ratio"]/100),2,'.','');
$handleData[$key]['withdraw_amount'][$k] = "0.00";
}
}
}
$handleData[$key]['begin_time'][$k] = date("Y-m-d",$value['begin_time'][$k]);
$handleData[$key]['end_time'][$k] = date("Y-m-d",$value['end_time'][$k]);
}
}
$this->ajaxReturn(['status'=>1,'data'=>$handleData,'msg'=>'']);
}
public function addSpecialComplementPost( ) {
$data = json_decode($_REQUEST['data'],true);
$company_ids = implode(',',array_column($data,'company_id'));
if ($company_ids) {
$inside = M("promote_company",'tab_')->field("company_name")->where(['id'=>['in',$company_ids],'is_inside'=>1])->select();
if ($inside) {
$inside = implode(',',array_column($inside,'company_name'));
$this->ajaxReturn(['status'=>0,'msg'=>$inside.'为内部公司不能添加特殊补点']);
}
}
$withdraw_type = 3;
$statement_data = [];
M()->startTrans();
foreach ($data as $key => $value) {
$begin_time = 99999999999;
$end_time = 0;
$statement_data = [];
$company_data = M("promote_company","tab_")->where(['id'=>$value['company_id']])->find();
$company_type = M("company_relation","tab_")
->where("(first_company_id={$value['company_id']} and first_company_type =2) or (second_company_id={$value['company_id']} and second_company_type=2)")
->find();
$insert['is_payment'] = $value['is_payment'];
$insert['withdraw_type'] = $withdraw_type;
$insert['company_belong'] = $company_data['company_belong'];
$insert['company_name'] = $company_data['company_name'];
$insert['company_id'] = $value['company_id'];
$insert['company_type'] = $company_data['company_type'];
$insert['pay_type'] = $company_type['collection'];
$insert['verify_log'] = json_encode(["create_user"=>session('user_auth')['username'],"create_time"=>date("Y-m-d H:i:s")]);;
$proCompany_info['id'] = $company_data['id'];
$proCompany_info['partner'] =$company_data['company_name'];
$proCompany_info['link_man'] = $company_data['settlement_contact'];
$proCompany_info['link_phone'] =$company_data['contact_phone'];
$proCompany_info['address'] = $company_data['address'];
$proCompany_info['payee_name'] =$value['payee_name'];
$proCompany_info['bank_account'] = $value['bank_account'];
$proCompany_info['opening_bank'] =$value['opening_bank'];
$proCompany_info['fax_ratio'] = $company_data['fax_ratio'];
$proCompany_info['taxation_rate'] = $company_data['taxation_rate'];
$proCompany_info['company_belong'] = $company_data['company_belong'];
$proCompany_info['company_type'] = $company_data['company_type'];
$proCompany_info['develop_type'] = $company_data['develop_type'];
$proCompany_info['ali_user'] = $value['ali_user'];
$proCompany_info['ali_account'] =$value['ali_account'];
$proCompany_info['has_server_fee'] = $company_data['has_server_fee'];
$proCompany_info['server_fee'] =$company_data['server_fee'];
$proCompany_info['has_ratio'] = $company_data['has_ratio'];
$proCompany_info['turnover_ratio'] =$company_data['turnover_ratio'];
$proCompany_info['invoice_type'] = $company_type['invoice_type'];
$proCompany_info['invoice_content'] = $company_type['invoice_content'];
if ($company_type['first_company_id'] == $value['company_id']) {
$weCompany = M("company_info","tab_")->where(['id'=>$company_type['second_company_id']])->find();
} elseif ($company_type['second_company_id'] == $value['company_id']) {
$weCompany = M("company_info","tab_")->where(['id'=>$company_type['first_company_id']])->find();
}
$secord_info['id'] = $weCompany['id'];
$secord_info['partner'] =$weCompany['partner'];
$secord_info['link_man'] = $weCompany['link_man'];
$secord_info['link_phone'] =$weCompany['link_phone'];
$secord_info['address'] = $weCompany['address'];
$secord_info['company_tax_no'] = $weCompany['company_tax_no'];
$secord_info['payee_name'] =$weCompany['payee_name'];
$secord_info['bank_account'] = $weCompany['bank_account'];
$secord_info['opening_bank'] =$weCompany['opening_bank'];
$secord_info['invoice_type'] = $company_type['invoice_type'];
$secord_info['invoice_content'] = $company_type['invoice_content'];
$statement_info =$value['statement_info'];
$pay_amount = 0;
$statement_money = 0;
foreach($statement_info as $k => $v) {
$pay_amount += $v['pay_amount'];
$statement_money += $v['sum_money'];
}
$insert['pay_amount'] = $pay_amount;
$insert['platform_amount'] = $pay_amount;
$insert['statement_money'] = $statement_money;
$insert['op_time'] = time();
foreach($statement_info as $k => $v) {
$statement_info[$k]['statement_type'] = 0;
$statement_info[$k]['fax_ratio'] = $company_data['fax_ratio'];
$statement_info[$k]['statement_begin_time'] = dateFormat($v['statement_begin_time']);
$statement_info[$k]['statement_end_time'] = dateFormat($v['statement_end_time']);
}
if ($company_data['company_type'] == 2) {
$statement_insert = [];
$promote_id = M("promote","tab_")
->field("id")
->where(['company_id'=>$value['company_id']])
->select();
if ($promote_id) {
$amount_time['promote_id'] = ['in',array_column($promote_id,'id')];
} else {
$amount_time['promote_id'] = '-1';
}
$amount_time['tab_spend.pay_status'] = 1;
// $amount_time['pay_way'] = ['egt',0];
foreach ($statement_info as $k => $v) {
$statement_begin_time = strtotime(str_replace('.','-',$v['statement_begin_time']));
$statement_end_time = strtotime(str_replace('.','-',$v['statement_end_time']))+86399;
if ($statement_begin_time<$begin_time) {
$begin_time = $statement_begin_time;
}
if ($statement_end_time>$end_time) {
$end_time = $statement_end_time;
}
$amount_time['_string'] = "payed_time between {$statement_begin_time} and {$statement_end_time} and relation_game_id={$v['relation_game_id']}";
$dataAmount = M("spend","tab_")
->field("pay_amount,relation_game_id,relation_game_name,payed_time,game_type_name,
CASE WHEN substring_index(substring_index(`chain`,'/',2),'/',-1) !='' THEN substring_index(substring_index(`chain`,'/',2),'/',-1) ELSE promote_id END promote_id,chain,admin_id")
->join("left join tab_promote promote on tab_spend.promote_id=promote.id")
->join("left join tab_game game on tab_spend.game_id=game.id")
->where($amount_time)
->select(false);
$dataAmount = M()->table("({$dataAmount})a")
->field("a.*,sum(pay_amount) pay_amount,promote.account,member.real_name")
->join("left join tab_promote promote on promote_id=promote.id")
->join("left join sys_member member on promote.admin_id=member.uid ")
->group("promote_id")
->select();
foreach ($dataAmount as $akey => $aval) {
$game_list['pay_amount'] = $aval['pay_amount'];
$game_list['relation_game_id'] = $aval['relation_game_id'];
$game_list['game_name'] = $aval['relation_game_name'];
$game_list['game_type_name'] = $aval['game_type_name'];
$game_list['ratio'] = floatval($v['ratio']);
$game_list['fax_ratio'] = $company_data['fax_ratio'];
$game_list['sum_money'] = ($aval['pay_amount']*($v['increment_ratio']))/100;
$game_list['increment_ratio'] = $v['increment_ratio'];
$game_list['statement_begin_time'] = $v['statement_begin_time'];
$game_list['statement_end_time'] = $v['statement_end_time'];
$game_list['statement_type'] = '0';
$statement_data[$aval['account']."-".$aval['real_name']."-".$aval['promote_id']][] = $game_list;
// $statement_insert[] = $statement_data;
}
}
foreach ($statement_data as $k => $v) {
$strKey = explode('-',$k);
$proCompany_info['nickname'] = $strKey[1];
$statement['account'] = $strKey[0];
$statement['real_name'] = $strKey[1];
$statement['promote_id'] = $strKey[2];
$statement['game_list'] = $v;
$statement['row'] = count($v);
$statement_insert[] = $statement;
}
$insert['statement_info'] = json_encode($statement_insert);
} else {
$insert['statement_info'] = json_encode($statement_info);
foreach ($statement_info as $k => $v) {
$statement_begin_time = strtotime(str_replace('.','-',$v['statement_begin_time']));
$statement_end_time = strtotime(str_replace('.','-',$v['statement_end_time']))+86399;
if ($statement_begin_time<$begin_time) {
$begin_time = $statement_begin_time;
}
if ($statement_end_time>$end_time) {
$end_time = $statement_end_time;
}
}
}
$insert['statement_begin_time'] = $begin_time;
$insert['statement_end_time'] = $end_time;
if ($company_type['first_company_id'] == $value['company_id']) {
$insert['first_party_info'] = json_encode($proCompany_info);
$insert['second_party_info'] = json_encode($secord_info);
} elseif ($company_type['second_company_id'] == $value['company_id']) {
$insert['second_party_info'] = json_encode($proCompany_info);
$insert['first_party_info'] = json_encode($secord_info);
}
$is_save = M('company_statement','tab_')->add($insert);
if (!$is_save) {
M()->rollback();
$this->ajaxReturn(['status'=>1001]);
}
}
M()->commit();
$this->ajaxReturn(['status'=>1]);
}
public function OpAuth($info)
{
$id = $info['id'];
$withdraw_type = $info['withdraw_type'];
$img = $info['ext_field'];
$remark = $info['remark'];
//原始列表
$opBtn = [
"viewStatement"=>"<a class='confirm viewStatement' data-id='{$id}'>查看</a>",
"editStatement"=>"<a class='confirm editStatement' data-id='{$id}' data-withdraw_type='{$withdraw_type}'>编辑</a>",
"addRemark"=>"<a class='confirm addRemark' data-id='{$id}'>新增备注</a>",
"editRemark"=>"<a class='confirm editRemark' data-remark='{$remark}' data-id='{$id}'>修改备注</a>",
"viewRemark"=>"<a class='confirm viewRemark' data-remark='{$remark}' data-id='{$id}'>查看备注</a>",
];
//操作对应菜单
$optist = [];
switch ($info['verify_status']) {
case '-2':
case '-1':
case '0':
$optist = ["viewStatement","editStatement","addRemark","viewRemark","editRemark"];
break;
case '1':
case '2':
$optist = ["viewStatement","addRemark","viewRemark","editRemark"];
break;
default:
break;
}
if(empty($info['remark'])){
//未上传备注
$optist = array_diff($optist, ["editRemark", "viewRemark"]);
}else{
$optist = array_diff($optist, ["addRemark"]);
}
// if ($withdraw_type == 3) {
// $optist = array_diff($optist, ["editStatement"]);
// }
$resarr = [];
foreach ($optist as $k => $v) {
if(IS_ROOT){
$resarr[] = $opBtn[$v];
}else{
if(in_array($v,$this->OpAuthList)){
$resarr[] = $opBtn[$v];
}
}
}
return $resarr;
}
public function menuAuth()
{
$mentBtn = [
"adminAgree"=>"<a class='butn' id='adminAgree'>管理员审核通过</a>",
"adminRefuse"=>"<a class='butn' id='adminRefuse' style='background-color: red;'>管理员审核拒绝</a>",
"adminCancel"=>"<a class='butn' id='adminCancel'>管理员审核撤回</a>",
"pool"=>"<a class='butn' id='pool'>发起汇总</a>",
"updateStatement"=>"<a class='butn' id='updateStatement' style='background-color: green;'>重算金额</a>",
"export"=>"<a class='butn' id='export'>批量导出</a>",
"updateNewStatement"=>"<a class='butn' id='updateNewStatement' style='background-color: green;'>新增结算</a>",
"launch"=>"<a class='butn' id='launch'>对外发起</a>",
"viewSpecialComplement"=>"<a class='butn' id='viewSpecialComplement'>特殊补点</a>",
"delStatement"=>"<a class='butn' id='delStatement' style='background-color: red;'>批量删除</a>"
];
if(IS_SUBSITE){
unset($mentBtn['updateNewStatement']);
$is_can_add = D("CmdTasks")->isCanAddTask("SubCompanyStatementSet");
if($is_can_add){
$mentBtn['subAddStatement'] = "<a class='butn' id='subAddStatement' style='background-color: green;'>新增结算</a>";
}
}
$resarr = [];
foreach ($mentBtn as $k => $v) {
if(IS_ROOT){
$resarr[] = $v;
}else{
if(in_array($k,$this->OpAuthList)){
$resarr[] = $v;
}
}
}
return $resarr;
}
}