diff --git a/Application/Admin/Controller/CompanyStatementController.class.php b/Application/Admin/Controller/CompanyStatementController.class.php index 0743c12af..a1fbdf569 100644 --- a/Application/Admin/Controller/CompanyStatementController.class.php +++ b/Application/Admin/Controller/CompanyStatementController.class.php @@ -19,13 +19,18 @@ class CompanyStatementController extends ThinkController "9"=>"上游" ]; public $VerifyStatus=[ - "-2"=>"汇总撤销", - "-1"=>"审批拒绝", + "-3"=>"汇总撤销", + "-2"=>"审核拒绝", + "-1"=>"管理员审批拒绝", "0"=>"未审批", - "1"=>"审核通过", - "2"=>"对外发起", - "3"=>"合作确认", - "4"=>"已汇总" + "1"=>"管理员审核通过", + "2"=>"审核通过", + "3"=>"已汇总" + ]; + public $ConfirmStatus=[ + "0"=>"未发起", + "1"=>"已发起", + "2"=>"已确认" ]; public $admininfo; public $DBModel; @@ -112,12 +117,15 @@ class CompanyStatementController extends ThinkController if(isset($_REQUEST['verify_status'])){ $map['verify_status'] = $_REQUEST['verify_status']; } + if(isset($_REQUEST['confirm_status'])){ + $map['confirm_status'] = $_REQUEST['confirm_status']; + } // $this->checkListOrCountAuthRestMap($map);//导出权限 //条件end $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") + ->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("FIELD(verify_status,0,1,-1,2,3,-2,4,5),id desc")->page($page,$row)->select(); + ->order("FIELD(verify_status,0,1,-1,2,3,-2,-3),id desc")->page($page,$row)->select(); foreach($data as $k => &$v) { $v['statement_begin_time'] = date('Y-m-d',$v['statement_begin_time']); @@ -132,14 +140,26 @@ class CompanyStatementController extends ThinkController $v['withdraw_type_2'] = ($v['withdraw_type'] == 2 ? "补点" :"正常结算"); $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 = "
"; } $v["create"]= "{$v['verify_log']['create_user']} {$symbol} {$v['verify_log']['create_time']}"; - if(isset($v['verify_log']['verify_user'])){ + 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['verify_log']['verify_user'])){ + if($v['verify_status'] == -2){ $ts = "审核拒绝"; }else{ $ts = "审核通过"; @@ -149,21 +169,21 @@ class CompanyStatementController extends ThinkController $v["verify"] = '--'; } - if(isset($v['verify_log']['launch_user'])){ + if(isset($v['confirm_log']['launch_user'])){ $ts = "已发起"; - $v["launch"]= "{$ts}({$v['verify_log']['launch_user']}) {$symbol} {$v['verify_log']['launch_time']}"; + $v["launch"]= "{$ts}({$v['confirm_log']['launch_user']}) {$symbol} {$v['confirm_log']['launch_time']}"; }else{ $v["launch"] = '--'; } - if(isset($v['verify_log']['confirm_user'])){ + if(isset($v['confirm_log']['confirm_user'])){ $ts = "已确认"; - $v["confirm"]= "{$ts}({$v['verify_log']['confirm_user']}) {$symbol} {$v['verify_log']['confirm_time']}"; + $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){ + if($v['verify_status'] == -3){ $ts = "撤销汇总"; $v["pool"]= "{$ts}({$v['verify_log']['pool_user']}){$symbol} {$v['verify_log']['pool_time']}"; }else{ @@ -190,6 +210,7 @@ class CompanyStatementController extends ThinkController $this->assign('CompanyType',$this->CompanyType); $this->assign('CompanyBelong',$this->CompanyBelong); $this->assign('VerifyStatus',$this->VerifyStatus); + $this->assign('ConfirmStatus',$this->ConfirmStatus); $this->display(); } @@ -296,15 +317,40 @@ class CompanyStatementController extends ThinkController } } //审批通过 + public function adminAgree(){ + $this->setVerifyStatus(0,1,"admin"); + } + public function adminRefuse(){ + $this->setVerifyStatus(0,-1,"admin"); + } public function verifyAgree(){ - $this->setVerifyStatus(0,1,"verify"); + $this->setVerifyStatus(1,2,"verify"); } public function verifyRefuse(){ - $this->setVerifyStatus(0,-1,"verify"); + $this->setVerifyStatus(1,-2,"verify"); } + public function launch(){ - $this->setVerifyStatus(1,2,"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("参数错误"); @@ -457,7 +503,7 @@ class CompanyStatementController extends ThinkController } foreach ($dbres as $k=>$v) { - if($v['verify_status'] != 3) continue; + if($v['verify_status'] != 2) continue; if($v['company_belong'] == 9){ //上游 if($v['is_payment'] == 1){ @@ -498,7 +544,12 @@ class CompanyStatementController extends ThinkController $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; + } $pool_id = $Pool->add($v); if($pool_id == false){ $this->ajaxReturn(array('status' => 0,"info"=>"汇总失败")); @@ -511,7 +562,7 @@ class CompanyStatementController extends ThinkController M("company_lack_statement_info","tab_")->where("id in ({$v['del_lack_ids']})")->save(["is_pool"=>1]); } //修改结算单规则 - $this->updatePoolVerifyStatus($v['statement_ids'],3,4,"pool",$v['statement_num']); + $this->updatePoolVerifyStatus($v['statement_ids'],2,3,"pool",$v['statement_num']); } $this->ajaxReturn(array( 'status' => 1, @@ -838,9 +889,6 @@ class CompanyStatementController extends ThinkController case '3': $optist = ["viewStatement","addRemark","viewRemark","editRemark"]; break; - case '4': - $optist = ["viewStatement","addRemark","viewRemark","editRemark"]; - break; default: break; } @@ -866,13 +914,15 @@ class CompanyStatementController extends ThinkController public function menuAuth() { $mentBtn = [ + "adminAgree"=>"管理员审核通过", + "adminRefuse"=>"管理员审核拒绝", "verifyAgree"=>"审批通过", "verifyRefuse"=>"审核拒绝", - "launch"=>"对外发起", "pool"=>"发起汇总", "updateStatement"=>"重算金额", "export"=>"批量导出", "updateNewStatement"=>"新增结算", + "launch"=>"对外发起", ]; $resarr = []; foreach ($mentBtn as $k => $v) { diff --git a/Application/Admin/Controller/CompanyStatementPoolController.class.php b/Application/Admin/Controller/CompanyStatementPoolController.class.php index 8882d4205..c9d1e4b49 100644 --- a/Application/Admin/Controller/CompanyStatementPoolController.class.php +++ b/Application/Admin/Controller/CompanyStatementPoolController.class.php @@ -16,7 +16,11 @@ class CompanyStatementPoolController extends ThinkController "1"=>"是", "2"=>"否" ]; - + public $WithdrawType = [ + "0"=>"周结", + "1"=>"月结", + "2"=>"下游个人补点" + ]; public $VerifyStatus=[ "-2"=>"拒绝打款", "-1"=>"审批拒绝", @@ -94,6 +98,9 @@ class CompanyStatementPoolController extends ThinkController if(isset($_REQUEST['is_payment'])){ $map['is_payment'] = $_REQUEST['is_payment']; } + if(isset($_REQUEST['withdraw_type'])){ + $map['withdraw_type'] = $_REQUEST['withdraw_type']; + } // $this->checkListOrCountAuthRestMap($map);//导出权限 @@ -111,11 +118,15 @@ class CompanyStatementPoolController extends ThinkController $v['company_type_str'] = $this->CompanyType[$v['company_type']]; $v['is_payment_str'] = $this->IsPayment[$v['is_payment']]; $v['can_export'] = $v['statement_money'] == 0 ? "0" : '1'; + if($v['company_type'] == 2){ + $v['can_export'] = 1; + } $v['op_time'] = date('Y-m-d H:i:s',$v['op_time']); $v["valid"] = "{$v['statement_begin_time']} ~ {$v['statement_end_time']}"; $v['ext_file_type'] = empty($v['ext_file']) ? "无" : "有"; + $v['withdraw_type'] = $this->WithdrawType[$v['withdraw_type']];; $v['verify_log'] = json_decode($v['verify_log'], true); if (isset($params['export'])) { @@ -177,6 +188,7 @@ class CompanyStatementPoolController extends ThinkController $this->assign('CompanyType',$this->CompanyType); $this->assign('IsPayment',$this->IsPayment); $this->assign('VerifyStatus',$this->VerifyStatus); + $this->assign('WithdrawType',$this->WithdrawType); $this->display(); } @@ -192,9 +204,11 @@ class CompanyStatementPoolController extends ThinkController $is_export = true; } //获取基本信息 - $infolist = M("company_statement_info","tab_")->where("pool_id = '{$id}'")->select(); + $infolist = M("company_statement_info","tab_")->field("*,'1' as st")->where("pool_id = '{$id}'")->select(); //获取母单 - $statement_num = M("company_statement_pool","tab_")->field('statement_num')->where("id={$id}")->find()['statement_num']; + $statement_num = + $pool_info = M("company_statement_pool","tab_")->field('statement_num,create_lack_ids')->where("id={$id}")->find(); + $statement_num = $pool_info['statement_num']; $this->assign("title",$statement_num); if($infolist[0]['company_type'] == 3){ @@ -204,12 +218,20 @@ class CompanyStatementPoolController extends ThinkController //下游公司 $this->viewPcPool($infolist,$is_export); }else{ + //获取母单 + if(!empty($pool_info['create_lack_ids'])){ + $l_ids = $pool_info['create_lack_ids']; + $lack_info = M("company_lack_statement_info","tab_")->field("*,'0' as st")->where("id in ({$l_ids})")->select(); + + $infolist += $lack_info; + } $this->viewPuPool($infolist,$is_export); } } //个人汇总结算查看 public function viewPuPool(&$infolist,$is_export){ + // dd($infolist); $line = 1; $count = []; //获取对接人 @@ -232,13 +254,20 @@ class CompanyStatementPoolController extends ThinkController if($is_export){ //J3*(K3+L3)+M3-N3 - $va['sum_money'] = "=J{$line}*(K{$line}+L{$line})+M{$line}-N{$line}"; - $count['sum_money_exp'] .= "O{$line}+"; - $count['platform_amount_exp'] .= "J{$line}+"; - + if($va['statement_type'] > 0){ //罚款服务器费用 + $va['sum_money'] = "=J{$line}"; + }else{ + $va['sum_money'] = "=J{$line}*(K{$line}+L{$line})+M{$line}-N{$line}"; + } + if($v['st'] == 1){ + $count['sum_money_exp'] .= "O{$line}+"; + $count['platform_amount_exp'] .= "J{$line}+"; + } }else{ - $count['platform_amount'] += $va['pay_amount']; - $count['sum_money'] += $va['sum_money']; + if($v['st'] == 1){ + $count['platform_amount'] += $va['pay_amount']; + $count['sum_money'] += $va['sum_money']; + } } } $v['statement_count'] = count($v['statement_info']); @@ -284,7 +313,7 @@ class CompanyStatementPoolController extends ThinkController if($is_export){ $v['statement_money_exp'] .= "H{$line}+"; - + $va['d_statement_money'] = "=D{$line}*(1-G{$line})*(E{$line}+F{$line})"; $count['platform_amount_exp'] .= "D{$line}+"; @@ -626,6 +655,62 @@ class CompanyStatementPoolController extends ThinkController 'info' => "删除成功" )); } + //不结算 + public function cancelStatement() + { + if(!isset($_REQUEST['id'])) $this->error("参数错误"); + $id = $_REQUEST['id']; + //获取结算信息 + $v = M("company_statement_info","tab_")->where("id = '{$id}'")->find(); + if(empty($v)){ + $this->error("请勿重复操作"); + } + $pool = M("company_statement_pool","tab_")->where("id = {$v['pool_id']}")->find(); + // dump($pool); + //保存未结算 + $lackcompany =[ + "company_id"=>$v['company_id'], + "company_type"=>$v['company_type'], + "company_name"=>$v['company_name'], + "company_info"=>$v['company_info'], + "statement_money"=>$v['statement_money'], + "pay_amount"=>$v['pay_amount'], + "platform_amount"=>$v['platform_amount'], + "fine"=>$v['fine'], + "reward"=>$v['reward'], + "statement_begin_time"=>$v['statement_begin_time'], + "statement_end_time"=>$v['statement_end_time'], + "is_payment"=>$pool['is_payment'], + "statement_pool_num"=>$pool['statement_num'], + "statement_info"=>$v['statement_info'], + ]; + $l_id = M("company_lack_statement_info","tab_")->add($lackcompany); + + //汇总表 + $pool_data = [ + "id"=>$pool['id'], + 'statement_money'=>$pool['statement_money']-$v['statement_money'], + 'pay_amount'=>$pool['pay_amount']-$v['pay_amount'], + 'fine'=>$pool['fine']-$v['fine'], + 'reward'=>$pool['reward']-$v['reward'], + 'lack_statement_money'=>$pool['lack_statement_money']+$v['statement_money'], + 'lack_platform_amount'=>$pool['lack_platform_amount']-0+$v['platform_amount'] + ]; + // + if(empty($pool_data['create_lack_ids'])){ + $pool_data['create_lack_ids'] = $l_id; + }else{ + $pool_data['create_lack_ids'] = $pool_data['create_lack_ids'].",".$l_id; + } + $info_ids = explode(",",$pool['info_ids']); + $pool_data['info_ids'] =implode(",",array_diff($info_ids,[$id])); + M("company_statement_pool","tab_")->save($pool_data); + M("company_statement_info","tab_")->where("id='{$id}'")->delete(); + $this->ajaxReturn(array( + 'status' => 1, + "info"=>"不结算成功" + )); + } //撤销汇总 public function cancelPool(){ @@ -855,7 +940,7 @@ class CompanyStatementPoolController extends ThinkController break; } // - if($info['platform_amount'] <= 0){ + if($info['platform_amount'] <= 0 && $info['company_type'] != 2){ $optist = array_diff($optist, ["viewPool"]); } //个人重算,上游撤销 diff --git a/Application/Admin/Controller/CompanyStatementSetController.class.php b/Application/Admin/Controller/CompanyStatementSetController.class.php index 05ae0c7ee..2ca7cbe75 100644 --- a/Application/Admin/Controller/CompanyStatementSetController.class.php +++ b/Application/Admin/Controller/CompanyStatementSetController.class.php @@ -6,6 +6,7 @@ use Think\Controller; /** * 聚合渠道结算接口对接 * @author cz + * TODO: 罚款的游戏没有流水不统计,补点为0 无法重算 */ class CompanyStatementSetController extends Controller { public $cpapihost; @@ -91,7 +92,7 @@ class CompanyStatementSetController extends Controller { echo "∟----推广公司月结&补点统计ok".PHP_EOL; $this->promoteUserPool(1,$stime); - // $this->promoteUserPool(2,$stime); + $this->promoteUserPool(2,$stime); echo "∟----推广个人月结&补点统计ok".PHP_EOL; } }else{ @@ -143,7 +144,7 @@ class CompanyStatementSetController extends Controller { $cp_id = implode(",",array_flip(array_flip(array_keys($cpList)))); $js_id = implode(",",array_unique($js_id)); //获取cp公司 - $tmpp = M("Partner","tab_")->field("id,partner,link_man,link_phone,address,company_tax_no,payee_name,bank_account,opening_bank,channel_rate,invoice_rate,company_type,ali_user,ali_account")->where(["id"=>['in',$cp_id]])->select(); + $tmpp = M("Partner","tab_")->field("id,partner,link_man,link_phone,address,company_tax_no,payee_name,bank_account,opening_bank,channel_rate,invoice_rate,taxation_rate,company_type,ali_user,ali_account,has_advance_charge,has_server_fee,server_fee")->where(["id"=>['in',$cp_id]])->select(); $cp =[]; foreach ($tmpp as $v) { $cp[$v['id']]=$v; @@ -242,9 +243,9 @@ class CompanyStatementSetController extends Controller { $add_data['company_belong']=9;//上游 $add_data['company_type']=$cp[$add_data['company_id']]['company_type']; $add_data['is_payment']=$v['is_payment']; - //获取渠道及发票税率 + //获取渠道及税费费率 $promote_ratio = $cp[$add_data['company_id']]['channel_rate'] ?? 0; - $fax_ratio = $cp[$add_data['company_id']]['invoice_rate'] ?? 0; + $fax_ratio = $cp[$add_data['company_id']]['taxation_rate'] ?? 0; //游戏统计 if(!isset($v['list'])){continue;} foreach($v['list'] as $ke=>$va){ @@ -298,14 +299,15 @@ class CompanyStatementSetController extends Controller { if($type < 2){ //非补点奖罚 $rrmap = array( - "reward_time" => ['between', [$begintime,$endtime]], + "confirm_time" => ['between', [$begintime,$endtime]], "company_type"=>1, - "company_id"=>$add_data['company_id'] + "company_id"=>$add_data['company_id'], + "settlement_type"=>2, ); - $rfres = M("RewardRecord","tab_") + $rfres = M("RewardDetail","tab_") ->field(" - IFNULL(SUM(CASE WHEN reward_type = 1 THEN money ELSE 0 END),0) as reward_count, - IFNULL(SUM(CASE WHEN reward_type = 2 THEN money ELSE 0 END),0) as fine_count + IFNULL(SUM(CASE WHEN type = 1 THEN amount ELSE 0 END),0) as reward_count, + IFNULL(SUM(CASE WHEN type = 2 THEN amount ELSE 0 END),0) as fine_count ") ->where($rrmap)->find(); if($rfres['reward_count'] > 0){ @@ -333,7 +335,22 @@ class CompanyStatementSetController extends Controller { ); $add_data['statement_money'] -= $fine_count; $add_data['pay_amount'] -= $fine_count;; - } + } + //获取服务器费用 + $tmp_company_info= $cp[$add_data['company_id']]; + if($tmp_company_info['has_server_fee'] == 1 && $tmp_company_info['server_fee'] >0){ + $server_count = $tmp_company_info['server_fee']; + $add_data['statement_info'][] = array( + "statement_begin_time"=>$statement_begin_time, + "statement_end_time"=>$statement_end_time, + 'statement_type'=>1, + "game_name"=>"服务器费用", + 'pay_amount'=>$server_count, + 'sum_money'=>$server_count, + ); + $add_data['statement_money'] -= $server_count; + $add_data['pay_amount'] -= $server_count;; + } } $add_data['statement_info'] = json_encode($add_data['statement_info'],JSON_UNESCAPED_UNICODE); @@ -361,7 +378,7 @@ class CompanyStatementSetController extends Controller { { $game_where = "partner_id in ({$cp_id})"; $game = M('game','tab_'); - $gameDbRes = $game->field("id,relation_game_name as game_name,partner_id as cp_id,original_package_name")->where($game_where)->select(); + $gameDbRes = $game->field("id,relation_game_name as game_name,partner_id as cp_id,original_package_name,select_package_name")->where($game_where)->select(); $gameList=[]; foreach ($gameDbRes as $k => $v) { $gameList[$v['id']] =$v; @@ -392,7 +409,11 @@ class CompanyStatementSetController extends Controller { if(empty($v['original_package_name'])){ $game_name = $v['game_name']; }else{ - $game_name = $v['original_package_name']; + if($v['select_package_name'] == 1){ + $game_name = $v['original_package_name']; + }else{ + $game_name = $v['game_name']; + } } $cp_id = $v['cp_id']; unset($v['cp_id']); @@ -430,7 +451,7 @@ class CompanyStatementSetController extends Controller { }else{ $where['settlement_type']=1; $pcDbRes = M("CompanyRelation","tab_")->where($where)->select(); - } + } $pcList=[]; $js_id = [];//己方公司 foreach ($pcDbRes as $k => $v) { @@ -450,11 +471,25 @@ class CompanyStatementSetController extends Controller { return ; } //获取pc公司 - $tmpp = M("PromoteCompany","tab_")->field("id,uid,company_name partner,settlement_contact link_man,contact_phone link_phone,bank_name opening_bank,bank_address payee_name,bank_card bank_account,fax_ratio,company_belong,company_type,ali_user,ali_account") + $tmpp = M("PromoteCompany","tab_")->field("id,uid,company_name partner,settlement_contact link_man,contact_phone link_phone,bank_name opening_bank,bank_address payee_name,bank_card bank_account,fax_ratio,taxation_rate,company_belong,company_type,ali_user,ali_account,has_server_fee,server_fee,has_ratio,turnover_ratio") ->where(["id"=>['in',$pc_id],"company_type"=>1]) ->select(); - $pc =[]; + $pc =[]; + $Promote = M("Promote","tab_"); foreach ($tmpp as $v) { + //获取会长的支付宝账号 + $p_map = [ + "company_id"=>$v['id'], + "withdraw_done"=>1 + ]; + $pres = $Promote->field("alipay_account,alipay_real_name")->where($p_map)->find(); + if(!empty($pres) && !empty($pres['alipay_account']) && !empty($pres['alipay_real_name'])){ + $v['ali_user'] = $pres['alipay_real_name']; + $v['ali_account'] = $pres['alipay_account']; + } + if($v['has_ratio']){ + $v['turnover_ratio'] = json_decode($v['turnover_ratio'],true); + } $pc[$v['id']]=$v; } @@ -466,20 +501,24 @@ class CompanyStatementSetController extends Controller { $our[$v['id']]=$v; } unset($tmpp); - unset($js_id); - $this->getPromoteCompanySpend($pcList,array_unique(array_keys($pcList)),$begintime,$endtime); + unset($js_id); + $this->getPromoteCompanySpend($pcList,array_unique(array_keys($pcList)),$begintime,$endtime); + // dd($pcList); //数据整合 $verify_log=json_encode(["create_user"=>"system","create_time"=>date("Y-m-d H:i:s")]); $StatementDb = M("CompanyStatement","tab_"); $statement_begin_time = date("Y-m-d",$begintime); $statement_end_time = date("Y-m-d",$endtime); - $RewardRecord = M("RewardRecord","tab_"); + $RewardRecord = M("RewardDetail","tab_"); foreach($pcList as $k=>$v){ - - if(!isset($pc[$k])){continue;}//不存在的公司不结算 - + if(!isset($pc[$k])){continue;}//不存在的公司不结算 + if($pc[$k]['has_ratio'] == 1){ + $company_ratio = $this->getCompanyRatio($v['pay_amount'],$pc[$k]['turnover_ratio']); + }else{ + $company_ratio = 0; + } $add_data=[]; //1.获取甲乙方信息 if($v['first_company_type'] > 0){ @@ -513,7 +552,7 @@ class CompanyStatementSetController extends Controller { $add_data['statement_info'] =[]; //获取渠道及发票税率 - $fax_ratio = $pc[$add_data['company_id']]['fax_ratio'] ?? 0; + $fax_ratio = $pc[$add_data['company_id']]['taxation_rate'] ?? 0; //税费费率 $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']; @@ -526,14 +565,15 @@ class CompanyStatementSetController extends Controller { //获取比例 $game['relation_game_id']=$va['relation_game_id']; if($type == 1){ - $tratio = getGamePromoteCompanyRadio($add_data['company_id'],$va['relation_game_id'],$endtime,$va['pay_amount'],true,$company_belong); + $tratio = getGamePromoteCompanyRadio($add_data['company_id'],$va['relation_game_id'],$endtime,$va['pay_amount'],true,$company_belong); + $tratio += $company_ratio; }elseif($type == 0){ $tratio = getGamePromoteCompanyRadio($add_data['company_id'],$va['relation_game_id'],$endtime,$va['pay_amount'],false,$company_belong); }else{ //补点 $tratio1 = getGamePromoteCompanyRadio($add_data['company_id'],$va['relation_game_id'],$endtime,$va['pay_amount'],true,$company_belong);; $tratio2 = getGamePromoteCompanyRadio($add_data['company_id'],$va['relation_game_id'],$endtime,$va['pay_amount'],false,$company_belong); - $tratio = $tratio1-$tratio2; + $tratio = $tratio1-$tratio2+$company_ratio; if($tratio <= 0){ continue;} } @@ -544,7 +584,7 @@ class CompanyStatementSetController extends Controller { } $add_data['pay_amount'] += $va['pay_amount']; - $game['sum_money']=round($va['pay_amount']*$tratio*(100-$fax_ratio)/(100*100),2);//结算金额=平台总额*(1-渠道费)*分成比例*(1-税费费率) + $game['sum_money']=round($va['pay_amount']*$tratio*(100-$fax_ratio)/(100*100),2);//结算金额=平台总额*(分成比例+补点比例)*(1-税费费率) $add_data['statement_money'] += $game['sum_money']; $game['fax_ratio']=$fax_ratio; @@ -558,14 +598,15 @@ class CompanyStatementSetController extends Controller { if($type < 2){ //非补点计算奖罚 $rrmap = array( - "reward_time" => ['between', [$begintime,$endtime]], + "confirm_time" => ['between', [$begintime,$endtime]], "company_type"=>2, - "company_id"=>$add_data['company_id'] + "company_id"=>$add_data['company_id'], + "settlement_type"=>2, ); - $rfres = M("RewardRecord","tab_") + $rfres = M("RewardDetail","tab_") ->field(" - IFNULL(SUM(CASE WHEN reward_type = 1 THEN money ELSE 0 END),0) as reward_count, - IFNULL(SUM(CASE WHEN reward_type = 2 THEN money ELSE 0 END),0) as fine_count + IFNULL(SUM(CASE WHEN type = 1 THEN amount ELSE 0 END),0) as reward_count, + IFNULL(SUM(CASE WHEN type = 2 THEN amount ELSE 0 END),0) as fine_count ") ->where($rrmap)->find(); if($rfres['reward_count'] > 0){ @@ -593,7 +634,22 @@ class CompanyStatementSetController extends Controller { ); $add_data['statement_money'] -= $fine_count; $add_data['pay_amount'] -= $fine_count;; - } + } + //获取服务器费用 + $tmp_company_info= $pc[$add_data['company_id']]; + if($tmp_company_info['has_server_fee'] == 1 && $tmp_company_info['server_fee'] >0){ + $server_count = $tmp_company_info['server_fee']; + $add_data['statement_info'][] = array( + "statement_begin_time"=>$statement_begin_time, + "statement_end_time"=>$statement_end_time, + 'statement_type'=>1, + "game_name"=>"服务器费用", + 'pay_amount'=>$server_count, + 'sum_money'=>$server_count, + ); + $add_data['statement_money'] -= $server_count; + $add_data['pay_amount'] -= $server_count;; + } } $add_data['statement_info'] = json_encode($add_data['statement_info'],JSON_UNESCAPED_UNICODE); @@ -647,7 +703,8 @@ class CompanyStatementSetController extends Controller { "s.pay_time"=>['between', [$begintime,$endtime]], ]; for ($i=0; $i field("group_concat(id) ids,count(id) count")->where("company_id = '{$company_id}'")->group("company_id")->find(); if($pres['count'] ==0 ){continue;} $spenMap['s.promote_id']=["in",$pres['ids']]; @@ -657,6 +714,11 @@ class CompanyStatementSetController extends Controller { ->select(); if(empty($list)){continue;} foreach($list as $k=>$v){ + try { + $res[$company_id]["pay_amount"] += $v['pay_amount']; + } catch (\Throwable $th) { + $res[$company_id]["pay_amount"] = $v['pay_amount']; + } if(isset($res[$company_id][$v['relation_game_id']])){ // $res[$company_id][$v['relation_game_id']]['pay_amount'] += $v['pay_amount']; @@ -665,9 +727,12 @@ class CompanyStatementSetController extends Controller { $res[$company_id][$v['relation_game_id']]= $v; } } - } + } foreach($res as $k=>$v){ + $pcList[$k]["pay_amount"] = $v['pay_amount']; + unset($v['pay_amount']); $pcList[$k]['list'] = $v; + } } public function promoteUserPool($type,$stime,$recount = false){ @@ -703,13 +768,18 @@ class CompanyStatementSetController extends Controller { if($type == 0){//周结 $this->doPromoteUserPool($user,$users,$type,$stime,$recount); - }else{ + }else if($type == 1){ $users['withdraw_type'] = 1; $user['withdraw_type'] = 1; //月结&补点 $this->doPromoteUserPool($user,$users,1,$stime,$recount); + + }else{ + $users['withdraw_type'] = 2; + $user['withdraw_type'] = 2; $this->doPromoteUserPool($user,$users,2,$stime,$recount); } + $this->savePromotateUserPool($users); $this->savePromotateUserPool($user); } @@ -748,13 +818,28 @@ class CompanyStatementSetController extends Controller { } //获取pc公司 $pc_id = implode(",",array_flip(array_flip(array_keys($pcList)))); - $tmpp = M("PromoteCompany","tab_")->field("id,uid,company_name partner,settlement_contact link_man,contact_phone link_phone,bank_name opening_bank,bank_address payee_name,bank_card bank_account,fax_ratio,company_belong,company_type,ali_user,ali_account") + $tmpp = M("PromoteCompany","tab_") + ->field("id,uid,company_name partner,settlement_contact link_man,contact_phone link_phone,bank_name opening_bank,bank_address payee_name,bank_card bank_account,fax_ratio,taxation_rate,company_belong,company_type,ali_user,ali_account,has_server_fee,server_fee,has_ratio,turnover_ratio") ->where(["id"=>['in',$pc_id],"company_type"=>2]) ->select(); if(count($tmpp)<1){return;} $pc =[]; + $Promote = M("Promote","tab_"); foreach ($tmpp as $v) { + $p_map = [ + "company_id"=>$v['id'], + "withdraw_done"=>1 + ]; + $pres = $Promote->field("alipay_account,alipay_real_name")->where($p_map)->find(); + if(!empty($pres) && !empty($pres['alipay_account']) && !empty($pres['alipay_real_name'])){ + $v['ali_user'] = $pres['alipay_real_name']; + $v['ali_account'] = $pres['alipay_account']; + } + if($v['has_ratio']){ + $v['turnover_ratio'] = json_decode($v['turnover_ratio'],true); + } + $pc[$v['id']]=$v; $pc[$v['id']]['is_payment']=$pcList[$v['id']]['is_payment']; } @@ -764,11 +849,18 @@ class CompanyStatementSetController extends Controller { $StatementDb = M("CompanyStatement","tab_"); $statement_begin_time = date("Y-m-d",$begintime); $statement_end_time = date("Y-m-d",$endtime); - $RewardRecord = M("RewardRecord","tab_"); + // $RewardRecord = M("RewardRecord","tab_"); $LackStatement = M("company_lack_statement_info","tab_"); $StatementInfo = M("company_statement_info","tab_"); foreach($pc as $k=>&$v){ + $fax_ratio = $v['taxation_rate']; + $RewardRecordRes = $this->getPromoteUserRewardRecord($v['id'],$begintime,$endtime); + if($v['has_ratio'] == 1){ + $company_ratio = $this->getCompanyRatio($v['pay_amount'],$pc[$k]['turnover_ratio']); + }else{ + $company_ratio = 0; + } //获取其他信息 $v = $this->getCompanyOtherInfo($v,$k); if($v['is_payment'] == 1){ @@ -782,6 +874,21 @@ class CompanyStatementSetController extends Controller { $v['reward'] = 0; $v['platform_amount'] = 0; if(!isset($v['list'])){continue;} + //服务器费用 + if ($type < 2) { + if ($v['has_server_fee'] == 1 && $v['server_fee'] > 0) { + $v['statement_info'][] = [ + "game_name"=>"服务器费用", + "sum_money"=>-$v['server_fee'], + "pay_amount"=>-$v['server_fee'], + 'statement_type'=>1, + "statement_begin_time"=>$statement_begin_time, + "statement_end_time"=>$statement_end_time + ]; + $v['pay_amount'] -= $v['server_fee']; + $v['statement_money'] -= $v['server_fee']; + } + } foreach($v['list'] as $ke=>$va){ $game =[]; $game['pay_amount'] =$va['pay_amount']; @@ -792,13 +899,14 @@ class CompanyStatementSetController extends Controller { if($type == 1){ $tratio = getGamePromoteCompanyRadio($v['id'],$va['relation_game_id'],$endtime,$va['pay_amount'],true,$company_belong); + $tratio += $company_ratio; }elseif($type == 0){ $tratio = getGamePromoteCompanyRadio($v['id'],$va['relation_game_id'],$endtime,$va['pay_amount'],false,$company_belong); }else{ //补点 $tratio1 = getGamePromoteCompanyRadio($v['id'],$va['relation_game_id'],$endtime,$va['pay_amount'],true,$company_belong);; $tratio2 = getGamePromoteCompanyRadio($v['id'],$va['relation_game_id'],$endtime,$va['pay_amount'],false,$company_belong); - $tratio = $tratio1-$tratio2; + $tratio = $tratio1-$tratio2+$company_ratio; if($tratio <= 0){ continue; } @@ -813,23 +921,18 @@ class CompanyStatementSetController extends Controller { //判断是否是个人 if($type < 2){ //非补点 - $rrmap = array( - "reward_time" => ['between', [$begintime,$endtime]], - "company_type"=>2, - "company_id"=>$k, - "relation_game_id"=>$va['relation_game_id'] - ); - $rrfres =$RewardRecord->field("IFNULL(SUM(CASE WHEN reward_type = 1 THEN money ELSE 0 END),0) as reward_count,IFNULL(SUM(CASE WHEN reward_type = 2 THEN money ELSE 0 END),0) as fine_count")->where($rrmap)->find(); - $v['fine'] += $rrfres['fine_count']; - $v['reward'] += $rrfres['reward_count']; - + if($RewardRecordRes){ + $rrfres = $RewardRecordRes[$va['relation_game_id']]; + }else{ + $rrfres = [ + 'reward_count'=>0, + 'fine_count'=>0, + ]; + } $game['reward'] = $rrfres['reward_count']; $game['fine'] = $rrfres['fine_count']; - - $game['sum_money']=round($va['pay_amount']*$tratio/100,2)+$game['reward']-$game['fine']; - }else{ - $game['sum_money']=round($va['pay_amount']*$tratio*(100-$fax_ratio)/(100*100),2);//结算金额=平台总额*(1-渠道费)*分成比例*(1-税费费率) } + $game['sum_money']=round($va['pay_amount']*$tratio/100,2)+$game['reward']-$game['fine']; //个人等于 结算金额*比例-罚款+奖励 $v['statement_money'] += $game['sum_money']; $game['fax_ratio']=$fax_ratio; @@ -944,7 +1047,9 @@ class CompanyStatementSetController extends Controller { * 保存信息汇总信息 */ public function savePromotateUserPool($data){ - if(empty($data['create_lack_ids']) && empty($data['del_lack_ids']) && empty($data['info_ids'])){ return;} + if(empty($data['create_lack_ids']) && empty($data['del_lack_ids']) && empty($data['info_ids'])){ //补点为空不重算 + return ; + } if($data['statement_money'] == 0){ $data['verify_status'] = 5; $data['verify_log'] = json_encode(["create_user"=>"system","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")]); @@ -988,6 +1093,63 @@ class CompanyStatementSetController extends Controller { 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']; } + /** + * 获取公司比例加成 + * @param [type] $paymount 支付金额 + * @param [type] $turnover_ratio 梯度 + */ + protected function getCompanyRatio($paymount,$turnover_ratio) + { + $ratio = 0; + foreach($turnover_ratio as $k=>$v){ + if($v['instanceof'] == 1){ + if($paymount >= $v['turnover']){ + $ratio = $v['ratio']; + } + }else{ + if($paymount > $v['turnover']){ + $ratio = $v['ratio']; + } + } + } + return $ratio; + } + /** + * 获取公司比例加成 + * @param [type] $paymount 支付金额 + * @param [type] $turnover_ratio 梯度 + */ + protected function getPromoteUserRewardRecord($cpmpamy_id,$begintime,$endtime) + { + //获取所有公司的奖罚 + $rrmap = array( + "d.confirm_time" => ['between', [$begintime,$endtime]], + "d.company_type"=>2, + "d.company_id"=>$cpmpamy_id, + "d.settlement_type"=>2, + ); + $rfres = M("RewardDetail","tab_") + ->alias("d") + ->field(" + IFNULL(SUM(CASE WHEN type = 1 THEN amount ELSE 0 END),0) as reward_count, + IFNULL(SUM(CASE WHEN type = 2 THEN amount ELSE 0 END),0) as fine_count, + r.relation_game_id + ") + ->where($rrmap) + ->join("tab_reward_record as r on d.record_id = r.id") + ->group("record_id,company_id") + ->select(); + if(empty($rfres)){ + return false; + }else{ + $s = []; + foreach($rfres as $k=>$v){ + $s[$v['relation_game_id']] = $v; + } + return $s; + } + + } /** * 重算接口 diff --git a/Application/Admin/View/CompanyStatement/lists.html b/Application/Admin/View/CompanyStatement/lists.html index 1aaafbdae..f4972427c 100644 --- a/Application/Admin/View/CompanyStatement/lists.html +++ b/Application/Admin/View/CompanyStatement/lists.html @@ -146,6 +146,15 @@ +
+ +
+
 -  @@ -186,10 +195,11 @@ 结算金额 结算流水 创建记录 + 管理员审核 审批状态 + 汇总状态 对外发起 合作确认 - 汇总状态 操作 @@ -204,7 +214,7 @@ - + {$data.company_name} {$data.company_belong} {$data.valid} @@ -215,6 +225,17 @@ {$data.create} +
+ {$data.admin} +
+ +
+ {$data.admin} +
+
+ + +
{$data.verify}
@@ -224,10 +245,8 @@
- {$data.launch} - {$data.confirm} - +
{$data.pool}
@@ -237,6 +256,8 @@
+ {$data.launch} + {$data.confirm} {$vo} @@ -244,7 +265,7 @@ - 合计结算总金额: {$count.statement_money}     结算总流水: {$count['platform_amount']} (补点不重复统计在内) + 合计结算总金额: {$count.statement_money}     结算总流水: {$count['platform_amount']} (补点不重复统计在内) @@ -386,7 +407,7 @@ //设置对账网址 var order_url = window.location.protocol+"//"+window.location.host+"/admin.php?s=/Public/cp_login.html"; - $("#order_url").html("流程说明:结算自动生成对账单--->财务审核对账单--->发起对外对账--->合作方进行确认--->进入报销流程【合作方确认地址:"+order_url+"】"); + $("#order_url").html("流程说明:结算自动生成对账单--->管理员审核--->财务审核对账单--->发起汇总 / 确认流程: 发起对外对账--->合作方进行确认【合作方确认地址:"+order_url+"】"); $("#updateNewStatement").on("click",function(){ layer.confirm("新增结算需要花费2分钟左右时间,并且只计算一个月内的新增结算,请勿在中途关闭页面,无需新增结算请取消",{title:false}, function(index){ @@ -428,33 +449,38 @@ }); }); - $("#verifyAgree,#verifyRefuse,#launch,#pool,#updateStatement").on("click",function(){ + $("#adminAgree,#adminRefuse,#verifyAgree,#verifyRefuse,#pool,#updateStatement").on("click",function(){ var id = $(this).attr("id"); - if(id == "verifyAgree"){ - var opname = "审批通过"; - var opurl = "{:U('verifyAgree')}"; + if(id == "adminAgree"){ + var opname = "管理员审批通过"; + var opurl = "{:U('adminAgree')}"; + var opst ="[未进行审批]"; + var status = [0]; + }else if(id=="adminRefuse"){ + var opname = "管理员审批拒绝"; + var opurl = "{:U('adminRefuse')}"; var opst ="[未进行审批]"; var status = [0]; + }else if(id == "verifyAgree"){ + var opname = "审批通过"; + var opurl = "{:U('verifyAgree')}"; + var opst ="[管理员审批通过]"; + var status = [1]; }else if(id=="verifyRefuse"){ var opname = "审批拒绝"; var opurl = "{:U('verifyRefuse')}"; - var opst ="[未进行审批]"; - var status = [0]; - }else if(id=="launch"){ - var opname = "对外发起"; - var opurl = "{:U('launch')}"; - var opst ="[审批通过]"; + var opst ="[管理员审批通过]"; var status = [1]; }else if(id=="pool"){ var opname = "发起汇总"; var opurl = "{:U('pool')}"; - var opst ="[合作方确认]"; - var status = [3]; + var opst ="[审批通过]"; + var status = [2]; }else if(id=="updateStatement"){ var opname = "重算金额"; var opurl = "{:U('updateStatement')}"; - var opst ="[汇总撤销,审批拒绝,未进行审批,审批通过,对外发起]"; - var status = [-2,-1,0,1,2]; + var opst ="[汇总撤销,管理员审批拒绝,审批拒绝,未进行审批,管理员审批通过,审批通过]"; + var status = [-3,-2,-1,0,1,2]; var confirm = true; } var confirm = confirm ? confirm :false; @@ -521,6 +547,49 @@ }); } }) + $("#launch").on("click",function(){ + var text = $("input:checkbox[name='ids[]']:checked").map(function(index,elem) { + if($(elem).data("confirm") == 0){ + return $(elem).val(); + } + }).get(); + if(text.length < 1){ + layer.msg("" + '无需要进行[对外发起]的申请,仅[未发起]状态可以进行[对外发起]操作'); + return; + } + text = text.join(","); + layer.confirm('【警告】[对外发起]将不可回退,如需继续请点击确认', { + btn: ['确认','取消'], + title:false + }, function(index){ + layer.close(index); + _doAgreeApply(); + }); + function _doAgreeApply(){ + //执行 + layer.load(2); + $.ajax({ + type: "POST", + url: "{:U('launch')}", + dataType: 'json', + async: true, + data: {ids:text}, + success:function(data){ + layer.closeAll('loading'); + if(data.status==1){ + layer.msg("" + data.info + ""); + setTimeout(function(){ + window.location.reload(); + },1500); + }else{ + layer.msg("" + data.info + ""); + return false; + } + } + }); + } + + }) $("#export").click(function () { var text = $("input:checkbox[name='ids[]']:checked").map(function(index,elem) { diff --git a/Application/Admin/View/CompanyStatementPool/lists.html b/Application/Admin/View/CompanyStatementPool/lists.html index d83953056..d40073fee 100644 --- a/Application/Admin/View/CompanyStatementPool/lists.html +++ b/Application/Admin/View/CompanyStatementPool/lists.html @@ -102,6 +102,15 @@ +
+ +
+