Merge branch 'feature/platfrom_aggregate_finance' of wmtx/platform into release

优化新增重算
master
廖金灵 4 years ago committed by Gogs
commit 3945fc9429

@ -111,7 +111,6 @@ class CompanyGameRatioController extends AdminController
$this->assign("companyList",D("PromoteCompany")->getList());
$this->assign("gameList",D("Game")->getRelationGameLits());
$this->display();
dd( $dbres);
}
public function lists()

@ -117,7 +117,7 @@ class CompanyStatementController extends ThinkController
$data = M("company_statement","tab_")
->field("id,withdraw_type,company_name,company_belong,statement_begin_time,statement_end_time,statement_money,platform_amount,verify_status,verify_log,op_time,remark")
->where($map)
->order("op_time Desc")->page($page,$row)->select();
->order("FIELD(verify_status,0,1,-1,2,3,-2,4,5),id desc")->page($page,$row)->select();
foreach($data as $k => &$v) {
$v['statement_begin_time'] = date('Y-m-d',$v['statement_begin_time']);
@ -700,7 +700,95 @@ class CompanyStatementController extends ThinkController
$savedata['statement_end_time'] = $v['statement_end_time'];
}
}
//设定并保存数据
//新增结算
//获取要结算的公司及日期
public function getNewStatement()
{
$senddata = [];
//1.获取要计算的公司
$statement = M("company_statement","tab_")->field("count(id) count,company_id")->group("company_id")->select();
$has_company_id =implode(",",array_column($statement, 'company_id'));
if(empty($has_company_id)){
$where = "1=1";
}else{
$where = "(first_company_type > 0 AND first_company_id NOT IN ({$has_company_id}) ) OR ( second_company_type > 0 AND second_company_id NOT IN ({$has_company_id}) )";
}
$relation = M("company_relation","tab_")->field("first_company_id,first_company_type,second_company_id,second_company_type")->where($where)->select();
$up_company_id = [];
$dowm_company_id= [];
foreach($relation as $k=>$v){
if($v['first_company_type'] == 0){
if($v['second_company_type'] == 1){
$up_company_id[] = $v['second_company_id'];
}else{
$dowm_company_id[] = $v['second_company_id'];
}
}else{
if($v['first_company_type'] == 1){
$up_company_id[] = $v['first_company_id'];
}else{
$dowm_company_id[]=$v['first_company_id'];
}
}
}
if(count($up_company_id) < 1 && count($dowm_company_id) < 1){
$this->ajaxReturn(["error"=>'无新增关系,无需重算']);
}
$senddata['up_company_id'] = implode(",",$up_company_id);
$senddata['dowm_company_id'] = implode(",",$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 OpAuth($info)
@ -762,7 +850,8 @@ class CompanyStatementController extends ThinkController
"launch"=>"<a class='butn' id='launch'>对外发起</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>"
"export"=>"<a class='butn' id='export'>批量导出</a>",
"updateNewStatement"=>"<a class='butn' id='updateNewStatement' style='background-color: green;'>新增结算</a>",
];
$resarr = [];
foreach ($mentBtn as $k => $v) {

@ -97,7 +97,7 @@ class CompanyStatementSetController extends Controller {
* 上游结算
* @param [string] $type 0:周结 1:月结 2周结补点
*/
public function cpStatement($type,$stime,$company_id=false)
public function cpStatement($type,$stime,$company_id=false,$recount=true)
{
$t = $this->setBeginAndEndTime($type,$stime);;
$begintime = $t[0];
@ -109,7 +109,7 @@ class CompanyStatementSetController extends Controller {
];
}else{
$where = [
"_string"=>"(first_company_type = '1' AND first_company_id = '{$company_id}') OR (second_company_type = '1' AND second_company_id = '{$company_id}')"
"_string"=>"(first_company_type = '1' AND first_company_id in ({$company_id}) ) OR (second_company_type = '1' AND second_company_id in ({$company_id}) )"
];
}
//获取哪些要结算
@ -241,6 +241,7 @@ class CompanyStatementSetController extends Controller {
$promote_ratio = $cp[$add_data['company_id']]['channel_rate'] ?? 0;
$fax_ratio = $cp[$add_data['company_id']]['invoice_rate'] ?? 0;
//游戏统计
if(!isset($v['list'])){continue;}
foreach($v['list'] as $ke=>$va){
$game =[];
$game['pay_amount'] =$va['pay_money'];
@ -339,12 +340,11 @@ class CompanyStatementSetController extends Controller {
return;
}
//添加
if($company_id === false){
if($recount && $company_id !== false){
//非重算
$StatementDb->add($add_data);
}else{
return $add_data;
}
$StatementDb->add($add_data);
}
}
@ -402,9 +402,8 @@ class CompanyStatementSetController extends Controller {
/**
* 下游结算
*/
public function promoteCompanyStatement($type,$stime,$company_id=false)
public function promoteCompanyStatement($type,$stime,$company_id=false,$recount=true)
{
$t = $this->setBeginAndEndTime($type,$stime);
$begintime = $t[0];
$endtime = $t[1];
@ -416,7 +415,7 @@ class CompanyStatementSetController extends Controller {
];
}else{
$where = [
"_string"=>"(first_company_type = '2' AND first_company_id = '{$company_id}') OR (second_company_type = '2' AND second_company_id = '{$company_id}')"
"_string"=>"(first_company_type = '2' AND first_company_id in ({$company_id}) ) OR (second_company_type = '2' AND second_company_id in ({$company_id}) )"
];
}
//获取哪些要结算
@ -427,7 +426,6 @@ class CompanyStatementSetController extends Controller {
$where['settlement_type']=1;
$pcDbRes = M("CompanyRelation","tab_")->where($where)->select();
}
$pcList=[];
$js_id = [];//己方公司
foreach ($pcDbRes as $k => $v) {
@ -454,6 +452,7 @@ class CompanyStatementSetController extends Controller {
foreach ($tmpp as $v) {
$pc[$v['id']]=$v;
}
unset($tmpp);
//获取己方公司
$our = [];
@ -471,7 +470,9 @@ class CompanyStatementSetController extends Controller {
$statement_begin_time = date("Y-m-d",$begintime);
$statement_end_time = date("Y-m-d",$endtime);
$RewardRecord = M("RewardRecord","tab_");
foreach($pcList as $k=>$v){
if(!isset($pc[$k])){continue;}//不存在的公司不结算
$add_data=[];
@ -511,8 +512,7 @@ class CompanyStatementSetController extends Controller {
$company_belong = $pc[$add_data['company_id']]['company_belong'];
$add_data['company_belong']=$company_belong;
$add_data['company_type']=$pc[$add_data['company_id']]['company_type'];
if(!isset($v['list'])){continue;}
//游戏统计
foreach($v['list'] as $ke=>$va){
$game =[];
@ -549,7 +549,6 @@ class CompanyStatementSetController extends Controller {
$game['statement_type']=0;
$add_data['statement_info'][] = $game;
}
$add_data['platform_amount'] = $add_data['pay_amount'];
if($type < 2){
//非补点计算奖罚
@ -600,17 +599,17 @@ class CompanyStatementSetController extends Controller {
if($add_data['platform_amount'] <= 0){
return;
}
// dd($add_data);
//添加
if($company_id === false){
if($recount && $company_id !== false){
//非重算
$StatementDb->add($add_data);
}else{
return $add_data;
}
$StatementDb->add($add_data);
}
}
//设定开始结束时间
protected function setBeginAndEndTime($type,$stime){
public function setBeginAndEndTime($type,$stime){
if($type == 0){
$begintime = mktime(0,0,0,date('m',$stime),date('d',$stime)-7,date('Y',$stime));
$endtime = mktime(0,0,0,date('m',$stime),date('d',$stime),date('Y',$stime))-1;
@ -632,7 +631,7 @@ class CompanyStatementSetController extends Controller {
return [$begintime,$endtime];
}
//获取推广公司推广金额
protected function getPromoteCompanySpend(&$pcList,$idarr,$begintime,$endtime){
public function getPromoteCompanySpend(&$pcList,$idarr,$begintime,$endtime){
$res = [];
//获取推广员
if(count($idarr) == 0){return $res;}
@ -759,6 +758,7 @@ class CompanyStatementSetController extends Controller {
$v['fine'] = 0;
$v['reward'] = 0;
$v['platform_amount'] = 0;
if(!isset($v['list'])){continue;}
foreach($v['list'] as $ke=>$va){
$game =[];
$game['pay_amount'] =$va['pay_amount'];
@ -922,7 +922,7 @@ class CompanyStatementSetController extends Controller {
/**
* 保存信息汇总信息
*/
protected function savePromotateUserPool($data){
public function savePromotateUserPool($data){
if(empty($data['create_lack_ids']) && empty($data['del_lack_ids']) && empty($data['info_ids'])){ return;}
if($data['statement_money'] == 0 && $type ==2){ return;}
if($data['statement_money'] == 0){
@ -947,7 +947,7 @@ class CompanyStatementSetController extends Controller {
/**
* 获取公司额为信息
*/
protected function getCompanyOtherInfo($company_info,$company_id)
public function getCompanyOtherInfo($company_info,$company_id)
{
$pl = M("promote_company","tab_")
->alias('pc')
@ -965,7 +965,7 @@ class CompanyStatementSetController extends Controller {
/**
* 获取游戏分类名称
*/
protected function getGameTypeName($relation_game_id){
public function getGameTypeName($relation_game_id){
return M("Game","tab_")->field("game_type_name")->where("relation_game_id = '{$relation_game_id}'")->find()['game_type_name'];
}

@ -56,11 +56,33 @@
font-weight: 400;
font-size: 14px;
}
.main-place .question_content:before{
right: 20px;
left: auto;
}
</style>
<div class="cf main-place top_nav_list navtab_list">
<h3 class="page_title">联运平台结算单管理</h3>
<p class="description_text" id="order_url"></p>
<p class="description_text" id="order_url"></p>
<div class="question" style="float: right;margin-right: 20px;">
<i class="question_mark">?</i>
<ul class="question_content" style="right: -20px;left: auto;">
<li class="question_title">数据相关说明</li>
<li class="question_list">
<span class="">重算金额:</span>
<span class="">仅会重算当前公司,当前时间的结算金额</span>
</li>
<li class="question_list">
<span class="">撤销汇总:</span>
<span class="">需要进行重算才可以再次汇总</span>
</li>
<li class="question_list">
<span class="">新增结算:</span>
<span class="">对新增绑定的公司进行结算,仅统计当月数据(不含下游个人)</span>
</li>
</ul>
</div>
</div>
@ -235,6 +257,15 @@
</if>
{$_page|default=''}
</div>
<div style="width: 100vw;height: 100vh;padding: 0;position: absolute;top: 0;z-index: 9999;display: none;" id="creat_msg">
<div class="layui-layer layui-layer-dialog layui-layer-border layui-layer-msg layui-layer-hui"
type="dialog" times="1" showtime="50000" contype="string" style="z-index: 19891015; top:30%; left:45%;">
<div class="layui-layer-content" style="padding: 15px 0 5px;font-size: 20px;font-weight: 600;color: white;">执行进度</div>
<div id="tip_msg" class="layui-layer-content" style="color: white;">开始时间与结束时间都不允许为空</div>
<div class="layui-layer-content" style="padding: 5px 10px 15px;font-size: 10px;color: #BBB;">TIP:未执行完成之前请勿刷新或关闭此页面</div>
<span class="layui-layer-setwin"></span>
</div>
</div>
</block>
<block name="script">
@ -256,6 +287,66 @@
Think.setValue('{$key}',"{$vo}");
</volist>
$(".select_gallery").select2();
var DATA={};
var MSG={
showmsg:function(str){
$("#creat_msg").show();
$("#tip_msg").html(str);
},
hidemsg:function(){
$("#creat_msg").hide();
$("#tip_msg").html('');
}
}
var COMPARE={
publiucAjax:function(url,senddata,callback){
$.ajax({
type: 'post',
url: url,
data:senddata,
success: function(data) {
if(data.success){
callback(data.data);
}else{
MSG.hidemsg();
layer.alert(data.error);
return false;
}
},
error:function(){
MSG.hidemsg();
layer.alert("网络错误或超时");
return false;
}
});
},
//获取基础参数
getNewStatement:function(callback){
MSG.showmsg("初始化获取校验中....");
COMPARE.publiucAjax("{:U('getNewStatement')}",{},function(data){
DATA = data;
DATA.now = 1;
MSG.showmsg("校验通过,开始统计 [0/"+DATA.count+"] ......");
callback();
});
},
//开始统计
updateNewStatement:function(callback){
var senddata = {date:DATA.datelist[(DATA.now-1)],up_company_id:DATA.up_company_id,dowm_company_id:DATA.dowm_company_id};
console.log(senddata);
COMPARE.publiucAjax("{:U('updateNewStatement')}",senddata,function(){
MSG.showmsg("开始统计 ["+DATA.now+"/"+DATA.count+"] ......");
DATA.now ++;
if( DATA.now > DATA.count){
callback();
}else{
COMPARE.updateNewStatement(callback)
}
});
}
}
</script>
<script type="text/javascript">
//导航高亮
@ -300,6 +391,20 @@
var order_url = window.location.protocol+"//"+window.location.host+"/admin.php?s=/Public/cp_login.html";
$("#order_url").html("流程说明:结算自动生成对账单--->财务审核对账单--->发起对外对账--->合作方进行确认--->进入报销流程【合作方确认地址:"+order_url+"】");
$("#updateNewStatement").on("click",function(){
layer.confirm("新增结算需要花费2分钟左右时间,并且只计算一个月内的新增结算,请勿在中途关闭页面,无需新增结算请取消",{title:false}, function(index){
COMPARE.getNewStatement(function(){
COMPARE.updateNewStatement(function(){
MSG.showmsg("统计完成,等待跳转中....");
setTimeout(function(){
window.location.reload();
},2000)
});
});
layer.close(index);
});
})
$(".viewStatement").click(function () {
var id = $(this).data("id");
var url = "{:U('viewStatement')}"+"&id="+id

Loading…
Cancel
Save