master
chenzhi 5 years ago
parent b4c93cc433
commit c71c142227

@ -102,16 +102,41 @@ class CompanyStatementSetController extends Controller {
}
//获取哪些要结算
if($type == 1){
$cpDbRes = M("Partner","tab_")->where("settlement_type = 2")->select();
$cpDbRes = M("CompanyRelation","tab_")->where("settlement_type = 2 AND (first_company_type = '1' OR second_company_type = '1')")->select();
}else{
$cpDbRes = M("Partner","tab_")->where("settlement_type = 1")->select();
$cpDbRes = M("CompanyRelation","tab_")->where("settlement_type = 1 AND (first_company_type = '1' OR second_company_type = '1')")->select();
}
$cpList=[];
$js_id = [];//己方公司
foreach ($cpDbRes as $k => $v) {
$cpList[$v['id']] =$v;
if($v['first_company_type'] == 1){
$cpList[$v['first_company_id']] =$v;
$js_id[] =$v['second_company_id'];
}else{
$cpList[$v['second_company_id']] =$v;
$js_id[] =$v['first_company_id'];
}
}
$cp_id = implode(",",array_flip(array_flip(array_column($cpDbRes,'id'))));
$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")->where(["id"=>['in',$cp_id]])->select();
$cp =[];
foreach ($tmpp as $v) {
$cp[$v['id']]=$v;
}
unset($tmpp);
//获取己方公司
$our = [];
$tmpp = M("CompanyInfo","tab_")->field("id,partner,link_man,link_phone,address,company_tax_no,payee_name,bank_account,opening_bank")->where(["id"=>['in',$js_id]])->select();
foreach ($tmpp as $v) {
$our[$v['id']]=$v;
}
unset($tmpp);
unset($js_id);
//获取本地数据
$locals = $this->getLocalStatementData($begintime,$endtime,$cp_id);
//获取聚合数据
@ -154,8 +179,79 @@ class CompanyStatementSetController extends Controller {
}
//比例计算及保存
foreach($cpList as $v){
// TODO:此处不判断现游戏名=原包名,但却不是同一款游戏
$verify_log=json_encode(["create_user"=>$_SESSION['onethink_admin']['user_auth']["username"],"create_time"=>date("Y-m-d H:i:s")]);
$GameDb = M("Game","tab_");
$statement_begin_time = date("Y-m-d",$begintime);
$statement_end_time = date("Y-m-d",$endtime);
foreach($cpList as $k=>$v){
$add_data=[];
//1.获取甲乙方信息
if($v['first_company_type'] == 1){
//甲方上游
$add_data['first_party_info'] = json_encode($cp[$v['first_company_id']],JSON_UNESCAPED_UNICODE);
$add_data['second_party_info'] = json_encode($our[$v['second_company_id']],JSON_UNESCAPED_UNICODE);
$add_data['company_id'] = $v['first_company_id'];
$add_data['company_name'] = $v['first_company_name'];
}else{
//乙方上游
$add_data['first_party_info'] = json_encode($our[$v['first_company_id']],JSON_UNESCAPED_UNICODE);
$add_data['second_party_info'] = json_encode($cp[$v['second_company_id']],JSON_UNESCAPED_UNICODE);
$add_data['company_id'] = $v['second_company_id'];
$add_data['company_name'] = $v['second_company_name'];
}
$add_data['pay_type'] = $v['collection'];
$add_data['withdraw_type'] = $type;
$add_data['statement_begin_time'] = $begintime;
$add_data['statement_end_time'] = $endtime;
$add_data['statement_money'] = 0;
$add_data['pay_amount'] = 0;
$add_data['verify_log'] = $verify_log;
$add_data['op_time'] =time();
foreach($v['list'] as $ke=>$va){
$game =[];
$game['pay_amount'] =$va['pay_money'];
//获取游戏id及比例
$game_id = $GameDb->where("game_name='{$ke}' OR relation_game_name='{$ke}'")->field("id")->find();
if(empty($game_id)){
$game['id']=0;
// $game['sum_money']=0;
$tratio = 0;
}else{
//获取比例
$game['id']=$game_id['id'];
if($type > 0){
$tratio = getGameCpRadio($game_id['id'],$va['pay_money'],true);
}else{
$tratio = getGameCpRadio($game_id['id'],$va['pay_money'],false);
}
}
if($v['first_company_type'] == 1){
$game['first_ratio']=$tratio;
$game['second_ratio']=100-$tratio;
}else{
$game['first_ratio']=100-$tratio;
$game['second_ratio']=$tratio;
}
$game['sum_money']=round($va['pay_money']*$tratio/100,2);
$game['fax_ratio']=0;
$game['promote_ratio']=0;
$game['statement_begin_time']=$statement_begin_time;
$game['statement_end_time']=$statement_end_time;
$game['statement_type']=0;
dump($game);
}
dd($v['list']);
dd($v);
//获取游戏比例
}
# code...

@ -1847,4 +1847,31 @@ CREATE TABLE `tab_company_relation_log` (
KEY `status` (`status`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='公司关系绑定申请记录';
--
CREATE TABLE `tab_company_statement` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '自增主键',
`withdraw_type` tinyint(2) DEFAULT '0' COMMENT '对账类型(0-周结 1月结 2补点)',
`company_id` int(11) DEFAULT '0' COMMENT '对账公司id',
`company_name` varchar(60) NOT NULL DEFAULT '' COMMENT '对账公司名称',
`statement_begin_time` int(11) NOT NULL DEFAULT '0' COMMENT '对账开始时间',
`statement_end_time` int(11) NOT NULL DEFAULT '0' COMMENT '对账截止时间',
`statement_money` decimal(10,2) DEFAULT '0.00' COMMENT '对账金额',
`pay_amount` decimal(10,2) DEFAULT '0.00' COMMENT '流水金额',
`verify_status` tinyint(2) NOT NULL DEFAULT '0' COMMENT '审核状态 -2:汇总驳回 -1审批拒绝 0:系统生成 1:审核通过 2:对外发起 3:合作确认 4:汇总',
`verify_log` text NOT NULL DEFAULT '' COMMENT '审批相关信息json',
`pay_type` tinyint(2) DEFAULT '0' COMMENT '1甲方收款;2乙方收款',
`first_party_info` text NOT NULL DEFAULT '' COMMENT '甲方相关信息json',
`second_party_info` text NOT NULL DEFAULT '' COMMENT '乙方相关信息json',
`statement_info` text NOT NULL DEFAULT '' COMMENT '订单相关信息json',
`op_time` int(11) NOT NULL DEFAULT '0' COMMENT '操作时间',
PRIMARY KEY (`id`),
KEY `withdraw_type` (`withdraw_type`) USING BTREE,
KEY `company_id` (`company_id`) USING BTREE,
KEY `statement_begin_time` (`statement_begin_time`) USING BTREE,
KEY `statement_end_time` (`statement_end_time`) USING BTREE,
KEY `verify_status` (`verify_status`) USING BTREE,
KEY `op_time` (`op_time`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COMMENT='聚合上游联运上下游对账单';

Loading…
Cancel
Save