diff --git a/Application/Admin/Controller/AggregateFinanceSetController.class.php b/Application/Admin/Controller/AggregateFinanceSetController.class.php index da422bfd9..9d6598787 100644 --- a/Application/Admin/Controller/AggregateFinanceSetController.class.php +++ b/Application/Admin/Controller/AggregateFinanceSetController.class.php @@ -152,6 +152,34 @@ class AggregateFinanceSetController extends Controller { "bank_account"=>$v['bank_card'], "opening_bank"=>$v['bank_name'], ],JSON_UNESCAPED_UNICODE); + $relationData = $this->setAggregateStatement($v['channel_id']); + + if ($relationData) { + $v['first_party_info'] = json_encode($relationData['first_company_info']); + $v['second_party_info'] = json_encode($relationData['second_company_info']); + + $statementInfo = json_decode($v['statement_info'],true); + if ($relationData['tax_ratio']) { + $v['ratio_money'] = 0; + + foreach ($statementInfo as $key => $value) { + + $statementInfo[$key]['ratio_money'] = round($value['ratio_money'] * ((100-$relationData['tax_ratio'])/100),2); + $statementInfo[$key]['fax_ratio'] = $relationData['tax_ratio']; + $v['ratio_money'] += $statementInfo[$key]['ratio_money']; + } + } + $v['statement_info'] = json_encode($statementInfo); + $pay_type = 0; + if ($relationData['pay_type']==1) { + $pay_type = 1; + } elseif($relationData['pay_type']==2) { + $pay_type = 0; + } + + $v['pay_type'] = $pay_type; + $v['verify_status'] = 3; + } $Aggregate->add($v); } } @@ -164,6 +192,32 @@ class AggregateFinanceSetController extends Controller { echo "----补点统计ok".PHP_EOL; } } + + /** + * 自动开票 + */ + public function setAggregateStatement($channel_id = 0) { + + $where = "(first_company_type = 3 and first_company_id={$channel_id}) OR (second_company_type = 3 and second_company_id={$channel_id})"; + + $relationData = M("company_relation","tab_") + ->where($where) + ->find(); + + if ($relationData) { + + $first_company_info = json_decode($relationData['first_company_info'],true); + $second_company_info = json_decode($relationData['second_company_info'],true); + $tax_ratio = $first_company_info['tax_ratio']?$first_company_info['tax_ratio']:$second_company_info['tax_ratio']; + $pay_type = $relationData['collection']; + + return ['first_company_info'=>$first_company_info,'second_company_info'=>$second_company_info,'tax_ratio'=>$tax_ratio,'pay_type'=>$pay_type]; + } else { + return false; + } + + } + /** * 重算聚合接口数据 * @param [type] $id @@ -229,6 +283,36 @@ class AggregateFinanceSetController extends Controller { $v['first_party_info'] = ''; $v['pay_type'] =0; + $relationData = $this->setAggregateStatement($v['channel_id']); + + if ($relationData) { + $v['first_party_info'] = json_encode($relationData['first_company_info']); + $v['second_party_info'] = json_encode($relationData['second_company_info']); + + $statementInfo = json_decode($v['statement_info'],true); + if ($relationData['tax_ratio']) { + $v['ratio_money'] = 0; + + foreach ($statementInfo as $key => $value) { + + $statementInfo[$key]['ratio_money'] = round($value['ratio_money'] * ((100-$relationData['tax_ratio'])/100),2); + $statementInfo[$key]['fax_ratio'] = $relationData['tax_ratio']; + $v['ratio_money'] += $statementInfo[$key]['ratio_money']; + } + } + $v['statement_info'] = json_encode($statementInfo); + + $pay_type = 0; + if ($relationData['pay_type']==1) { + $pay_type = 1; + } elseif($relationData['pay_type']==2) { + $pay_type = 0; + } + + $v['pay_type'] = $pay_type; + + $v['verify_status'] = 3; + } // } else { // $v['second_party_info'] = // json_encode([ diff --git a/Application/Admin/Controller/AggregateFinanceStatementController.class.php b/Application/Admin/Controller/AggregateFinanceStatementController.class.php index e7307bb34..140ede852 100644 --- a/Application/Admin/Controller/AggregateFinanceStatementController.class.php +++ b/Application/Admin/Controller/AggregateFinanceStatementController.class.php @@ -14,7 +14,8 @@ class AggregateFinanceStatementController extends ThinkController "2"=>"审批同意", "3"=>"已开票", "4"=>"已上传凭证", - "5"=>"已到账" + "5"=>"已到账", + "6"=>"已汇总", ]; public $admininfo; public $OpAuthList=[]; @@ -686,7 +687,10 @@ class AggregateFinanceStatementController extends ThinkController break; case '5': $optist = ["viewStatement","uploadVoucher","viewVoucher","editVoucher","addRemark","viewRemark","editRemark"]; - break; + break; + case "6": + $optist = ["viewStatement","addRemark","viewRemark","editRemark"]; + break; default: break; } @@ -718,10 +722,11 @@ class AggregateFinanceStatementController extends ThinkController } public function menuAuth() { - $optist = ['agreeApply',"refuseApply","Invoiced","Received","updateStatement","export"]; + $optist = ['agreeApply',"refuseApply","pool","Invoiced","Received","updateStatement","export"]; $mentBtn = [ "agreeApply"=>"审批通过", "refuseApply"=>"审批拒绝", + "pool"=>"发起汇总", "Invoiced"=>"已开票", "Received"=>"已到账", "updateStatement"=>"重算结算金额", @@ -761,5 +766,289 @@ class AggregateFinanceStatementController extends ThinkController addOperationLog(['op_type'=>1,'key'=>$key,"op_name"=>$op_name,'url'=>U(CONTROLLER_NAME.'/lists',$GetData),'menu'=>$menu]); } + //汇总 + public function pool() + { + if(!isset($_REQUEST['ids'])) $this->error("参数错误"); + $ids = $_REQUEST['ids']; + $dbres = M("aggregate_statement","tab_")->field("*")->where("id in ({$ids})")->select(); + //分单 + $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 = ["aggregate"]; + //初始化数据 + foreach($datas as $k=>$v){ + if($v =="aggregate"){ + $basedata['company_type']=3; + $basedata['is_payment']=2; + } + $datas[$v]=$basedata; + unset($datas[$k]); + } + + foreach ($dbres as $k=>$v) { + if($v['verify_status'] != 3) continue; + + $this->setDf($datas['aggregate'],$v); + } + + $Pool = M("aggregate_statement_pool","tab_"); + $Statemen = M("aggregate_statement","tab_"); + 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; + } + $pool_id = $Pool->add($v); + if($pool_id == false){ + $this->ajaxReturn(array('status' => 0,"info"=>"汇总失败")); + } + if(!empty($info)){ + $save["pool_id"]=$pool_id; + M("aggregate_statement_info","tab_")->where("id in ({$info})")->save($save); + } + if(!empty($v['del_lack_ids'])){ + M("aggregate_lack_statement_info","tab_")->where("id in ({$v['del_lack_ids']})")->save(["is_pool"=>1]); + } + //修改结算单规则 + $this->updatePoolVerifyStatus($v['statement_ids'],3,6,"pool",$v['statement_num']); + } + $this->ajaxReturn(array( + 'status' => 1, + "info"=>"汇总成功" + )); + } + //设定组合的子操作 + 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['channel_id']])){ + //存在游戏合并 + $a = &$savedata['company_list'][$v['channel_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['pay_money']; + $a['pay_amount'] += $v['pay_money']; + $a['statement_money'] += $v['ratio_money']; + }else{ + if($v['pay_type'] == 2){ + //乙方收款 + $v['company_info'] =json_decode($v['second_party_info'],true); + $v['company_info']['pay_type'] = 2; + $v['company_info_other'] = json_decode($v['first_party_info'],true); + }else{ + $v['company_info'] = json_decode($v['first_party_info'],true); + $v['company_info']['pay_type'] = 1; + $v['company_info_other'] = json_decode($v['second_party_info'],true); + } + //先分配好订单号,防止重复提交 + $tdata = [ + "company_info"=>$v['company_info'], + "company_info_other"=>$v['company_info_other'], + "company_name"=>$v['channel_name'], + "platform_amount"=>$v['pay_money'], + "pay_amount"=>$v['pay_money'], + "statement_money"=>$v['ratio_money'], + "fine"=>$fine, + "reward"=>$reward, + "statement_info"=>$v['statement_info'], + "statement_num"=>"JS_".date('Ymd').date('His').$v['company_id'].sp_random_string(5) + ]; + $savedata['company_list'][$v['channel_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['begintime']; + }elseif($v['begintime'] < $savedata['statement_begin_time']){ + $savedata['statement_begin_time'] = $v['begintime']; + } + if($savedata['statement_end_time'] == 0){ + $savedata['statement_end_time'] = $v['endtime']; + }elseif($v['endtime'] > $savedata['statement_end_time']){ + $savedata['statement_end_time'] = $v['endtime']; + } + } + + protected function addStatementInfo($va,$k,&$v){ + $StatementInfo = M("aggregate_statement_info","tab_"); + $company_info = $va['company_info']; + $company_info_other = $va['company_info_other']; + + $LackStatement = M("aggregate_lack_statement_info","tab_"); + $no_pool_money = 300; + //统一比例字段 + if($k == "up" || $k=="ups"){ + $no_pool_money = 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($k=="ups" || $k=='downs'){ + $is_payment = 1; + $verify_status = 0; + }else{ + $is_payment = 2; + $verify_status = 2; + } + + //创建基础未满基础信息 + if($va['platform_amount'] < $no_pool_money){ + $lackcompany =[ + "company_id"=>$company_info['id'], + "company_name"=>$company_info['partner'], + 'company_belong_name'=>$company_info_other['partner'], + "company_info"=>json_encode($company_info,JSON_UNESCAPED_UNICODE), + "statement_money"=>$va['ratio_money'], + "pay_amount"=>$va['pay_money'], + "platform_amount"=>$va['pay_money'], + "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), + ]; + } + + //整合数据 + $lsres = $LackStatement->where("company_id={$company_info['id']} and is_pool = 0")->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']); + } + } +// dump($no_pool_money); +// dump($va); +// dump($k);die(); + if($va['platform_amount'] < $no_pool_money){ + //依旧小于不结算金额存旧版 + 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_name"=>$company_info['partner'], + 'company_belong_name'=>$company_info_other['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 + ]; + + $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 updatePoolVerifyStatus($ids,$old_status,$change_status,$op_pre,$num){ + $dbres = M("aggregate_statement","tab_")->field("id,verify_status")->where("id in ({$ids})")->select(); + foreach($dbres as $k=>&$v){ + if($v['verify_status'] != $old_status) continue; + + $v['verify_status']=$change_status; + $v['op_time']=time(); + M("aggregate_statement","tab_")->save($v); + } + } } diff --git a/Application/Admin/Controller/AggregateRelationController.class.php b/Application/Admin/Controller/AggregateRelationController.class.php index 4ece94f56..d764db912 100644 --- a/Application/Admin/Controller/AggregateRelationController.class.php +++ b/Application/Admin/Controller/AggregateRelationController.class.php @@ -17,6 +17,7 @@ class AggregateRelationController extends AdminController const COMPANY_TYPE_DEFAULT_B = '2'; public $aggregateCompanyList = []; + public $aggregateCompanyInfo = ''; public $admininfo; public $DBModel; @@ -393,6 +394,14 @@ class AggregateRelationController extends AdminController (second_company_type ='{$params['second_company_type']}' and second_company_id = '{$params['second_company_id']}') "; } + $params['first_company_info'] = $this->getCompanyInfo($params['first_company_type'],$params['first_company_id']); + $params['first_company_info']['type'] = 'first_party_info'; + $params['first_company_info'] = json_encode($params['first_company_info']); + + $params['second_company_info'] = $this->getCompanyInfo($params['second_company_type'],$params['second_company_id']); + $params['second_company_info']['type'] = 'second_party_info'; + $params['second_company_info'] = json_encode($params['second_company_info']); + $r_res = $this->DBModel->where($where)->find(); if(!empty($r_res)){ $this->error('当前合作方已有绑定关系'); @@ -566,6 +575,16 @@ class AggregateRelationController extends AdminController } + public function getAggegateCompanyInfo($b = '') { + + $client = new AggregateClient(); + + $result = $client->api('aggregate-companyinfo', ['id'=>$b]); + + $this->aggregateCompanyInfo = $result['data']; + + } + public function getCompanyList($type) { if($type ==''){ @@ -602,7 +621,7 @@ class AggregateRelationController extends AdminController $companyInfo = []; if($type == 0){ //己方公司 - $companyInfo = M("CompanyInfo","tab_")->field("id,partner company_name,link_man,link_phone")->where("status='1' AND id='{$id}'")->find(); + $companyInfo = M("CompanyInfo","tab_")->field("id,partner company_name,partner,link_man,link_phone,address,company_tax_no,payee_name,bank_account,opening_bank,'' invoice_item,'' invoice_type")->where("status='1' AND id='{$id}'")->find(); } if($type == 1){ //上游 @@ -612,6 +631,11 @@ class AggregateRelationController extends AdminController //下游游 $companyInfo = M("PromoteCompany","tab_")->field("id,company_belong,company_name,company_type,settlement_contact link_man,contact_phone link_phone")->where("status='1' AND id='{$id}'")->find(); } + if($type == 3) { + $this->getAggegateCompanyInfo($id); + //聚合下游 + $companyInfo = $this->aggregateCompanyInfo; + } if(isset($companyInfo['company_belong'])){ $companyInfo['company_belong'] = getCompanyBlong($companyInfo['company_belong']); } diff --git a/Application/Admin/Controller/AggregateStatementLackController.class.php b/Application/Admin/Controller/AggregateStatementLackController.class.php new file mode 100644 index 000000000..5cfe2abd4 --- /dev/null +++ b/Application/Admin/Controller/AggregateStatementLackController.class.php @@ -0,0 +1,376 @@ +"下游公司", + "2"=>"下游个人", + "3"=>"上游公司" + ]; + public $IsPayment = [ + "1"=>"是", + "2"=>"否" + ]; + + public $admininfo; + public $DBModel; + public function _initialize() + { + $this->admininfo = $_SESSION['onethink_admin']['user_auth']; + $this->DBModel = M("AggregateLackStatementInfo","tab_"); + 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 = [ + "is_pool"=>0 + ]; + if (isset($_REQUEST['time_start']) && isset($_REQUEST['time_end'])) { + $time_start = strtotime($_REQUEST['time_start']); + $time_end = strtotime($_REQUEST['time_end'])+ 86399; + $map["_string"] = "(statement_begin_time BETWEEN {$time_start} AND {$time_end}) OR (statement_end_time BETWEEN {$time_start} AND {$time_end}) OR (statement_begin_time <= {$time_end} AND statement_end_time >= {$time_end})"; + } elseif (isset($_REQUEST['time_start'])) { + $time_start = strtotime($_REQUEST['time_start']); + $map["_string"] = "(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"] = "(statement_begin_time <= {$time_end} ) OR (statement_end_time <= {$time_end})"; + } + + //其他 + if(isset($_REQUEST['company_type'])){ + $map['company_type'] = $_REQUEST['company_type']; + } + if(isset($_REQUEST['company_name'])){ + $map['company_name'] =["LIKE","%{$_REQUEST['company_name']}%"]; + } + if(isset($_REQUEST['statement_pool_num'])){ + $map['statement_pool_num'] =["LIKE","%{$_REQUEST['statement_pool_num']}%"]; + } + if(isset($_REQUEST['is_payment'])){ + $map['is_payment'] = $_REQUEST['is_payment']; + } + + // $this->checkListOrCountAuthRestMap($map);//导出权限 + + //条件end + $data = $this->DBModel + ->field("*") + ->where($map) + ->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['is_payment_str'] = $this->IsPayment[$v['is_payment']]; + $v['company_type_str'] = $this->CompanyType[$v['company_type']]; + $v["valid"] = "{$v['statement_begin_time']} ~ {$v['statement_end_time']}"; + $v['oplist'] = $this->OpAuth($v); + } + + $count = $this->DBModel->field("count(id) count,sum(statement_money) 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('data',$data); + $this->assign('count',$count); + $this->assign('CompanyType',$this->CompanyType); + $this->assign('IsPayment',$this->IsPayment); + $this->display(); + + } + //查看 + public function viewStatement() + { + if(!isset($_REQUEST['id'])){ + $this->error('参数错误'); + } + $id = $_REQUEST['id']; + $is_export= false; + if (isset($_REQUEST['export']) && $_REQUEST['export']==1){ + $is_export = true; + } + //获取基本信息 + $dbres = $this->DBModel->where("id='{$id}'")->select(); + $title = $dbres[0]['company_name']; + $this->assign("title",$title); + + if($dbres[0]['company_type'] == 3){ + //上游 + A("AggregateStatementPool")->viewCpPool($dbres,$is_export); + }elseif($dbres[0]['company_type'] == 1){ + //下游公司 + A("AggregateStatementPool")->viewPcPool($dbres,$is_export); + }else{ + A("AggregateStatementPool")->viewPuPool($dbres,$is_export); + } + } + + //汇总 + public function pool() + { + if(!isset($_REQUEST['ids'])) $this->error("参数错误"); + $ids = $_REQUEST['ids']; + $dbres = $this->DBModel->field("*")->where("id in ({$ids})")->select(); + //分单 + $basedata = [ + "pay_amount"=>0, + "statement_money"=>0, + "lack_statement_money"=>0, + "platform_amount"=>0, + "lack_platform_amount"=>0, + "del_lack_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 = ["ups","up","downs","down","user","users"]; + //初始化数据 + foreach($datas as $k=>$v){ + if($v =="ups"){ + $basedata['company_type']=3; + $basedata['is_payment']=1; + } + if($v =="up"){ + $basedata['company_type']=3; + $basedata['is_payment']=2; + } + + if($v =="downs"){ + $basedata['company_type']=1; + $basedata['is_payment']=1; + } + if($v =="down"){ + $basedata['company_type']=1; + $basedata['is_payment']=2; + } + if($v =="users"){ + $basedata['company_type']=2; + $basedata['is_payment']=1; + } + if($v =="user"){ + $basedata['company_type']=2; + $basedata['is_payment']=2; + } + $datas[$v]=$basedata; + unset($datas[$k]); + } + + + foreach ($dbres as $k=>$v) { + if($v['company_type'] == 3){ + //上游 + if($v['is_payment'] == 1){ + $this->setDf($datas['ups'],$v); + }else{ + $this->setDf($datas['up'],$v); + } + }elseif($v['company_type'] == 1){ + if($v['is_payment'] == 1){ + $this->setDf($datas['downs'],$v); + }else{ + $this->setDf($datas['down'],$v); + } + }else{ + if($v['is_payment'] == 1){ + $this->setDf($datas['users'],$v); + }else{ + $this->setDf($datas['user'],$v); + } + } + } + $Pool = M("aggregate_statement_pool","tab_"); + $Statemen = M("aggregate_statement","tab_"); + foreach ($datas as $k => $v) { + if(count($v['company_list']) <= 0){continue;} + //保存公司信息 + $company_list = $v['company_list']; + foreach ($company_list as $ke => $va) { + $this->addStatementInfo($va,$ke,$v,$k); + } + + if(empty($v['create_lack_ids']) && empty($v['del_lack_ids']) && empty($v['info_ids'])){ continue;} + + $v['statement_num'] = "QZ_".date('Ymd').date('His').sp_random_num(3); + + $v['del_lack_ids'] = implode(",",$v['del_lack_ids']) ?? ''; + $info = implode(",",$v['info_ids']); + unset($v['info_ids']); + unset($v['company_list']); + $pool_id = $Pool->add($v); + if($pool_id == false){ + $this->ajaxReturn(array('status' => 0,"info"=>"汇总失败")); + } + if(!empty($info)){ + $save["pool_id"]=$pool_id; + M("aggregate_statement_info","tab_")->where("id in ({$info})")->save($save); + } + if(!empty($v['del_lack_ids'])){ + M("aggregate_lack_statement_info","tab_")->where("id in ({$v['del_lack_ids']})")->save(["is_pool"=>1]); + } + } + $this->ajaxReturn(array( + 'status' => 1, + "info"=>"汇总成功" + )); + } + protected function addStatementInfo($va,$ke,&$v,$k){ + if($k=="ups" || $k=='downs' || $k =="users"){ + $verify_status = 0; + }else{ + $verify_status = 2; + } + + $StatementInfo = M("aggregate_statement_info","tab_"); + if($va['pay_amount'] > 0){ + //存成功 + $company =[ + "pool_id"=>0, + "company_id"=>$ke, + "company_type"=>$v['company_type'], + "company_name"=>$va['company_name'], + "company_info"=>$va['company_info'], + "fine"=>$va['fine'], + "reward"=>$va['reward'], + "statement_money"=>$va['statement_money'], + "pay_amount"=>$va['pay_amount'], + "platform_amount"=>$va['platform_amount'], + "statement_money"=>$va['statement_money'], + "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 + ]; + $companyid = $StatementInfo->add($company); + $v['info_ids'][] =$companyid; + $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['del_lack_ids'][] = $v['id']; + unset($v['id']); + $v['statement_info'] = json_decode( $v['statement_info'],true); + $fine = $v['fine']; + $reward = $v['reward']; + + 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{ + //先分配好订单号,防止重复提交 + $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) + ]; + $savedata['company_list'][$v['company_id']] = $tdata; + } + // $savedata['fine'] += $v['fine']; + // $savedata['reward'] += $v['reward']; + // $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 OpAuth($info) + { + $id = $info['id']; + $type = $info['company_type']; + //原始列表 + $opBtn = [ + "viewStatement"=>"查看", + ]; + //操作对应菜单 + $optist = ["viewStatement"]; + $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 = [ + "pool"=>"发起汇总", + "export"=>"批量导出" + ]; + $resarr = []; + foreach ($mentBtn as $k => $v) { + if(IS_ROOT){ + $resarr[] = $v; + }else{ + if(in_array($k,$this->OpAuthList)){ + $resarr[] = $v; + } + } + } + return $resarr; + } + +} diff --git a/Application/Admin/Controller/AggregateStatementPoolController.class.php b/Application/Admin/Controller/AggregateStatementPoolController.class.php new file mode 100644 index 000000000..2e6ec696a --- /dev/null +++ b/Application/Admin/Controller/AggregateStatementPoolController.class.php @@ -0,0 +1,1010 @@ +"下游公司", + "2"=>"下游个人", + "3"=>"上游CP" + ]; + public $IsPayment = [ + "1"=>"是", + "2"=>"否" + ]; + public $WithdrawType = [ + "0"=>"周结", + "1"=>"月结", + "2"=>"下游个人补点", + "3"=>"其他", + ]; + public $VerifyStatus=[ + "-2"=>"拒绝打款", + "-1"=>"审批拒绝", + "0"=>"未审批", + "1"=>"审批通过", + "2"=>"待打款", + "3"=>"打款中", + "4"=>"打款成功", + "5"=>"无需打款" + ]; + public $InfoVerifyStatus=[ + "-1"=>"配置信息不全", + "0"=>"信息未确认", + "1"=>"允许打款", + "2"=>"线下无需打款" + ]; + public $PayStatus=[ + "-1"=>"打款失败", + "0"=>"未打款", + "1"=>"打款成功" + ]; + public $admininfo; + public $DBModel; + public function _initialize() + { + $this->admininfo = $_SESSION['onethink_admin']['user_auth']; + $this->DBModel = M("AggregateStatementPool","tab_"); + 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" + ]; + if (isset($_REQUEST['time_start']) && isset($_REQUEST['time_end'])) { + $time_start = strtotime($_REQUEST['time_start']); + $time_end = strtotime($_REQUEST['time_end'])+ 86399; + $map["_string"] = "(statement_begin_time BETWEEN {$time_start} AND {$time_end}) OR (statement_end_time BETWEEN {$time_start} AND {$time_end}) OR (statement_begin_time <= {$time_end} AND statement_end_time >= {$time_end})"; + } elseif (isset($_REQUEST['time_start'])) { + $time_start = strtotime($_REQUEST['time_start']); + $map["_string"] = "(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"] = "(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]; + } + + //其他 + + if(isset($_REQUEST['company_type'])){ + $map['company_type'] = $_REQUEST['company_type']; + } + if(isset($_REQUEST['verify_status'])){ + $map['verify_status'] = $_REQUEST['verify_status']; + } + if(isset($_REQUEST['statement_num'])){ + $map['statement_num'] = $_REQUEST['statement_num']; + } + 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);//导出权限 + //条件end + $data = $this->DBModel + ->field("*") + ->where($map) + ->order("FIELD(verify_status,0,1,-1,-2,2,3,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']); + $v['statement_end_time'] = date('Y-m-d',$v['statement_end_time']); + + $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'])) { + $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($v['verify_status'] == -1){ + $ts = "审核拒绝"; + }else{ + $ts = "审核通过"; + } + $v["verify"]= "{$ts}({$v['verify_log']['verify_user']}) {$symbol} {$v['verify_log']['verify_time']}"; + }else{ + $v["verify"] = '--'; + } + + + if(isset($v['verify_log']['payment_user'])){ + if($v['verify_status'] == -2){ + $ts = "拒绝打款"; + $v["payment"]= "{$ts}({$v['verify_log']['payment_user']}){$symbol} {$v['verify_log']['payment_time']}"; + }elseif($v['verify_status'] == 2){ + $ts = "待打款"; + $v["payment"]= "{$ts}({$v['verify_log']['payment_user']}){$symbol} {$v['verify_log']['payment_time']}"; + }elseif($v['verify_status'] == 3){ + $ts = "打款中"; + $v["payment"]= "{$ts}({$v['verify_log']['payment_user']}){$symbol} {$v['verify_log']['payment_time']}"; + }elseif($v['verify_status'] == 4){ + if($v['is_payment']==1){ + $ts="线上打款成功"; + }else{ + $ts="线下打款成功"; + } + $v["payment"]= "{$ts}({$v['verify_log']['payment_user']}){$symbol} {$v['verify_log']['payment_time']}"; + }elseif($v['verify_status'] == 5){ + $ts="无需打款"; + $v["payment"]= "{$ts}({$v['verify_log']['payment_user']}){$symbol} {$v['verify_log']['payment_time']}"; + } + }else{ + $v["payment"] = '--'; + } + + $v['oplist'] = $this->OpAuth($v); + } + $count = $this->DBModel->field("count(id) count,SUM(statement_money) as statement_money,SUM(lack_statement_money) lack_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('data',$data); + $this->assign('count',$count); + $this->assign('CompanyType',$this->CompanyType); + $this->assign('IsPayment',$this->IsPayment); + $this->assign('VerifyStatus',$this->VerifyStatus); + $this->assign('WithdrawType',$this->WithdrawType); + $this->display(); + + } + //查看 + public function viewPool() + { + if(!isset($_REQUEST['id'])){ + $this->error('参数错误'); + } + $id = $_REQUEST['id']; + $is_export= false; + if (isset($_REQUEST['export']) && $_REQUEST['export']==1){ + $is_export = true; + } + //获取基本信息 + $infolist = M("aggregate_statement_info","tab_")->field("*,'1' as st")->where("pool_id = '{$id}'")->select(); + //获取母单 + $pool_info = M("aggregate_statement_pool","tab_")->field('statement_num,create_lack_ids,verify_status,is_payment')->where("id={$id}")->find(); + $statement_num = $pool_info['statement_num']; + $this->assign("title",$statement_num); + $this->assign("pool_status",$pool_info['verify_status']); + $this->assign("pool_status",$pool_info['verify_status']); + $this->assign("is_payment",$pool_info['is_payment']); + + //获取母单 + if(!empty($pool_info['create_lack_ids'])){ + $l_ids = $pool_info['create_lack_ids']; + $lack_info = M("aggregate_lack_statement_info","tab_")->field("*,'0' as st")->where("id in ({$l_ids})")->select(); + + $infolist =array_merge($infolist,$lack_info); + } + + $this->viewPuPool($infolist,$is_export); + + } + //个人汇总结算查看 + public function viewPuPool(&$infolist,$is_export){ + // dd($infolist); + $line = 1; + $count = []; + //获取对接人 + foreach($infolist as $k=>&$v){ + $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']); + $cline = $line+1; + if($is_export){ + $v['sum_money_exp'] = "="; + } + foreach($v['statement_info'] as $ke=>&$va){ + $line ++; + if(isset($va['ratio'])){ + $va['increment_ratio'] = 0; + }else{ + $va['ratio'] = 0; + } + + if($is_export){ + //J3*(K3+L3)+M3-N3 + if($va['statement_type'] > 0){ //罚款服务器费用 + $va['sum_money'] = "=J{$line}"; + }else{ + $va['sum_money'] = "=J{$line}*(K{$line}+L{$line})+M{$line}-N{$line}"; + } + }else{ + $count['platform_amount'] += $va['money']; + $count['sum_money'] += $va['ratio_money']; + } + } + $v['statement_count'] = count($v['statement_info']); + } + if($is_export){ + $count["platform_amount"] = "=SUM(J2:J".$line.")"; + $count["sum_money"] = "=SUM(O2:O".$line.")"; + } + + $this->assign("data",$infolist); + $this->assign("count",$count); + $this->assign("is_export",$is_export); + $this->display("AggregateStatementPool/viewPuPool"); + } + //下游汇总结算查看 + public function viewPcPool(&$infolist,$is_export){ + $line = 1; + $count = []; + //获取对接人 + $p_id = array_column($infolist,'company_id'); + $map['id'] = ['in',$p_id]; + $pl = M("promote_company","tab_")->field("id,settlement_contact")->where($map)->select(); + $Partner = []; + foreach($pl as $k=>$v){ + $Partner[$v['id']] = $v['settlement_contact']; + } + unset($pl); + foreach($infolist as $k=>&$v){ + $v['statement_info'] = json_decode($v['statement_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']); + $cline = $line+1; + if($is_export){ + $v['statement_money_exp'] = "="; + } + foreach($v['statement_info'] as $ke=>&$va){ + $line ++; + if(isset($va['ratio'])){ + $va['increment_ratio'] = 0; + }else{ + $va['ratio'] = 0; + } + + 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}+"; + $count['d_statement_money_exp'] .= "H{$line}+"; + + }else{ + $va['d_statement_money'] = round($va['pay_amount']*($va['ratio']+$va['increment_ratio'])*(100-$va['fax_ratio'])/100/100,2); + + $count['platform_amount'] += $va['pay_amount']; + + $count['d_statement_money'] += $va['d_statement_money']; + } + } + $v['settlement_contact'] = $Partner[$v['company_id']]; + + if($is_export){ + $v['statement_money_exp'] .= "J{$cline}-I{$cline}"; + $v['statement_money'] = $v['statement_money_exp']; + + $count['fine_exp'] .= "I{$cline}+"; + $count['reward_exp'] .= "J{$cline}+"; + + $count['statement_money_exp'] .= "K{$cline}+"; + }else{ + $count['fine'] += $v['fine']; + $count['reward'] += $v['reward']; + $count['statement_money'] += $v['statement_money']; + } + $v['statement_count'] = count($v['statement_info']); + + } + if($is_export){ + $count["d_statement_money"] = "=".trim($count["d_statement_money_exp"],"+"); + $count["platform_amount"] = "=".trim($count["platform_amount_exp"],"+"); + $count["fine"] = "=".trim($count["fine_exp"],"+"); + $count["reward"] = "=".trim($count["reward_exp"],"+"); + $count["statement_money"] = "=".trim($count["statement_money_exp"],"+"); + } + + $this->assign("data",$infolist); + $this->assign("count",$count); + $this->assign("is_export",$is_export); + $this->display("AggregateStatementPool/viewPcPool"); + + } + + //上游汇总查看及导出 + public function viewCpPool(&$infolist,$is_export) + { + $line = 2; + $count = []; + //获取平台名 + $p_id = array_column($infolist,'company_id'); + $map['id'] = ['in',$p_id]; + $pl = M("Partner","tab_")->field("id,matche_platform")->where($map)->select(); + $Partner = []; + foreach($pl as $k=>$v){ + $Partner[$v['id']] = $v['matche_platform']; + } + unset($pl); + // + foreach($infolist as $k=>&$v){ + $v['statement_info'] = json_decode($v['statement_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']); + $cline = $line+1; + if($is_export){ + $v['statement_money_exp'] = "="; + } + foreach($v['statement_info'] as $ke=>&$va){ + $line ++; + $va['company_ratio'] = 100-$va['ratio']; + if($is_export){ + $v['statement_money_exp'] .= "K{$line}+"; + $va['d_statement_money'] = "=F{$line}*G{$line}"; + $count['platform_amount_exp'] .= "E{$line}+"; + $count['platform_amount_exp2'] .= "F{$line}+"; + $count['d_statement_money_exp'] .= "K{$line}+"; + }else{ + $va['d_statement_money'] = round($va['pay_amount']*$va['ratio']/100,2); + $count['platform_amount'] += $va['pay_amount']; + $count['platform_amount2'] += $va['pay_amount']; + $count['d_statement_money'] += $va['d_statement_money']; + } + } + $v['matche_platform'] = $Partner[$v['company_id']]; + if($is_export){ + $v['statement_money_exp'] .= "M{$cline}-L{$cline}"; + $v['statement_money'] = $v['statement_money_exp']; + $count['fine_exp'] .= "L{$cline}+"; + $count['reward_exp'] .= "M{$cline}+"; + $count['statement_money_exp'] .= "N{$cline}+"; + }else{ + $count['fine'] += $v['fine']; + $count['reward'] += $v['reward']; + $count['statement_money'] += $v['statement_money']; + } + $v['statement_count'] = count($v['statement_info']); + + } + if($is_export){ + $count["d_statement_money"] = "=".trim($count["d_statement_money_exp"],"+"); + $count["platform_amount"] = "=".trim($count["platform_amount_exp"],"+"); + $count["platform_amount2"] = "=".trim($count["platform_amount_exp2"],"+"); + $count["fine"] = "=".trim($count["fine_exp"],"+"); + $count["reward"] = "=".trim($count["reward_exp"],"+"); + $count["statement_money"] = "=".trim($count["statement_money_exp"],"+"); + } + $this->assign("data",$infolist); + $this->assign("count",$count); + $this->assign("is_export",$is_export); + $this->display("AggregateStatementPool/viewCpPool"); + } + + //审批通过 + public function verifyAgree(){ + $this->setVerifyStatus(0,1,"verify"); + } + public function verifyRefuse(){ + $this->setVerifyStatus(0,-1,"verify"); + } + //线下打款 + public function setUlPayment() + { + if(!isset($_REQUEST['ids'])) $this->error("参数错误"); + $ids = $_REQUEST['ids']; + + //修改info + $ires = M("aggregate_statement_info","tab_")->where("pool_id='{$ids}'")->save(['pay_type'=>3,'pay_status'=>1]); + if($ires !== false){ + $this->setVerifyStatus(1,4,"payment"); + } + $this->ajaxReturn(array( + 'status' =>0, + "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; + $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."成功" + )); + } + + protected function setOneVerifyStatus($change_status,$op_pre,$id,$mgs = "操作") + { + $dbres = $this->DBModel->field("id,verify_status,verify_log")->where("id = {$id}")->find(); + $dbres['verify_log'] = json_decode($dbres['verify_log'],true); + $dbres['verify_log'][$op_pre.'_user']=$this->admininfo["username"]; + $dbres['verify_log'][$op_pre.'_time']=date("Y-m-d H:i:s"); + $dbres['verify_log'] = json_encode($dbres['verify_log']); + $dbres['verify_status']=$change_status; + $this->DBModel->save($dbres); + addOperationLog(['op_type'=>1,'key'=>$id,"op_name"=>$mgs,'url'=>U('lists')]); + $this->ajaxReturn(array( + 'status' => 1, + "info"=>$mgs."成功" + )); + } + + //打款设置 + public function setPayment(){ + if(!isset($_REQUEST['id'])) $this->error("参数错误"); + $id = $_REQUEST['id']; + $CompanyInfo = M("aggregate_statement_info","tab_") + ->alias('i') + ->field("i.id,i.pool_id,i.company_name,i.company_info,i.statement_money,p.statement_num,i.remark,i.pay_status,p.statement_money all_money") + ->join("tab_company_statement_pool p ON p.id = i.pool_id") + ->where("pool_id='{$id}'") + ->select(); + foreach($CompanyInfo as $k=>&$v){ + $v['company_info'] = json_decode($v['company_info'],true); + $v['company_info']['ali_user'] ?? ''; + $v['company_info']['ali_account'] ?? ''; + } + + $this->assign("CompanyInfo",$CompanyInfo); + $this->assign("id",$id); + $this->display(); + } + //修改打款设置 + public function editPayment(){ + if(!isset($_REQUEST['info'])) $this->error("参数错误"); + $info = $_REQUEST['info']; + $CompanyInfo = M("aggregate_statement_info","tab_"); + //循环保存 + foreach($info as $k=>$v){ + $ydata = $CompanyInfo->where("id= '{$k}'")->find(); + if($ydata['verify_status'] == 2){continue;} + + $company_info = json_decode($ydata['company_info'],true); + $company_info['ali_user'] = $v['ali_user']; + $company_info['ali_account'] = $v['ali_account']; + $savedata = [ + "company_info"=>json_encode($company_info,JSON_UNESCAPED_UNICODE), + "remark"=>$v['remark'], + "id"=>$k + ]; + if(empty($v['ali_user']) || empty($v['ali_account'])){ + $savedata['verify_status'] = -1; + }else{ + $savedata['verify_status'] = 1; + } + $CompanyInfo->save($savedata); + } + //修改状态 + $this->setOneVerifyStatus(2,"payment",$_REQUEST['pool_id'],$mgs = "打款信息提交"); + } + //查看打款信息 + public function viewPayment(){ + if(!isset($_REQUEST['id'])) $this->error("参数错误"); + $id = $_REQUEST['id']; + $CompanyInfo = M("aggregate_statement_info","tab_") + ->alias('i') + ->field("i.id,i.pool_id,i.company_name,i.company_info,i.statement_money,p.statement_num,i.remark,i.pay_status,i.verify_status,p.statement_money all_money") + ->join("tab_company_statement_pool p ON p.id = i.pool_id") + ->where("pool_id='{$id}'") + ->select(); + foreach($CompanyInfo as $k=>&$v){ + $v['company_info'] = json_decode($v['company_info'],true); + $v['company_info']['ali_user'] ?? ''; + $v['company_info']['ali_account'] ?? ''; + $v['verify_status_str'] = $this->InfoVerifyStatus[ $v['verify_status']]; + + if($v['verify_status'] == 1){ + + $v['verify_status_str'] = $this->PayStatus[$v['pay_status']]; + if($v['pay_status'] == 1){ + $v['pay_type'] = $v['pay_type'] == 1 ? "提现" :"线上打款"; + $v['verify_status_str'] .= ("/". $v['pay_type']); + } + } + } + + $this->assign("CompanyInfo",$CompanyInfo); + $this->display(); + } + + //保存备注 + 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 uploadVoucher() + { + if(!isset($_REQUEST['id'])) $this->error("参数错误"); + $id = $_REQUEST['id']; + $this->assign("id",$id); + $this->display(); + } + //修改凭证 + public function editVoucher() + { + if(!isset($_REQUEST['id'])) $this->error("参数错误"); + $id = $_REQUEST['id']; + $info = $this->DBModel->field("id,ext_file")->where("id = '{$id}'")->find(); + $this->assign("id",$id); + $this->assign("ext_file",$info['ext_file']); + $this->display(); + } + //保存凭证 + public function saveVoucher() + { + if(!isset($_REQUEST['id'])) $this->error("参数错误"); + $id = $_REQUEST['id']; + + $path = '/Uploads/'; + $upload = new \Think\Upload();// 实例化上传类 + $upload->maxSize = 0 ;// 设置附件上传大小 + $upload->exts = array('jpg', 'gif', 'png', 'jpeg');;// 设置附件上传类型 + $upload->rootPath = '.'.$path; // 设置附件上传根目录 + $upload->savePath = ''; // 设置附件上传(子)目录 + // 上传文件 + $info = $upload->upload(); + if(!$info) {// 上传错误提示错误信息 + $msg = $upload->getError(); + $array= array('status' => 0, 'info' => $msg); + }else{// 上传成功 + // + $pf = $path.$info['file']['savepath'].$info['file']['savename']; + $save = [ + "ext_file"=>$pf, + ]; + //获取旧值,存在删除 + $info = $this->DBModel->field("id,ext_file")->where("id = '{$id}'")->find(); + if(!empty($info['ext_file'])){ + unlink("./".$info['ext_file']); + } + $this->DBModel->where("id = '{$id}'")->save($save); + $array=array( + 'status' => 1, + "info"=>"上传成功", + "file_path"=>$pf, + ); + } + $this->ajaxReturn($array); + } + //删除凭证 + public function delVoucher(){ + if(!isset($_REQUEST['id'])) $this->error("参数错误"); + $id = $_REQUEST['id']; + $info = $this->DBModel->field("id,ext_file")->where("id = '{$id}'")->find(); + if(!empty($info['ext_file'])){ + unlink("./".$info['ext_file']); + } + $save = [ + "ext_file"=>'', + ]; + + $this->DBModel->where("id = '{$id}'")->save($save); + // $this->doAddOperationLog($id,"删除凭证"); + $this->ajaxReturn(array( + 'status' => 1, + 'info' => "删除成功" + )); + } + //不结算 + public function cancelStatement() + { + if(!isset($_REQUEST['id'])) $this->error("参数错误"); + $id = $_REQUEST['id']; + //获取结算信息 + $v = M("aggregate_statement_info","tab_")->where("id = '{$id}'")->find(); + if(empty($v)){ + $this->error("请勿重复操作"); + } + $pool = M("aggregate_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_belong_name"=>$v['company_belong_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("aggregate_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'], + 'verify_status'=>0 + ]; + // + 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("aggregate_statement_pool","tab_")->save($pool_data); + M("aggregate_statement_info","tab_")->where("id='{$id}'")->delete(); + $this->ajaxReturn(array( + 'status' => 1, + "info"=>"不结算成功" + )); + } + + //撤销汇总 + public function cancelPool(){ + if(!isset($_REQUEST['id'])) $this->error("参数错误"); + $id = $_REQUEST['id']; + //获取基础信息 + $db_res = $this->DBModel->where("id='{$id}'")->find(); + + $is_qz = (substr($db_res['statement_num'],0,2) == "QZ" ? true :false); //强制汇总的都允许回退 + if($is_qz){ + //强制汇总回退 + $this->cancelQzPool($db_res); + } + + $re_op = true; + $create_lack_ids = $db_res['create_lack_ids']; + if(!empty($create_lack_ids) && !$is_qz){ + $clsi = M("aggregate_lack_statement_info","tab_")->where("is_pool = 1 and id in ({$create_lack_ids})")->find(); + $re_op = true; + if(!empty($clsi)){ + $re_op = false; //被引用无法重算 + } + } + if($re_op){ + //公司及上游回退 + if($db_res['company_type'] == 2){ + $this->retry($db_res); //个人重算 + }else{ + $this->cancelCompanyPool($db_res);//公司撤回 + } + } + + } + /** + * 重算 先全删再进行二次生成 + */ + public function retry($info) + { + //执行删除 + $dids = $info['del_lack_ids']; + $cids = $info['create_lack_ids']; + M()->startTrans(); + //删除info + $infores = M("aggregate_statement_info","tab_")->where("pool_id = {$info['id']}")->delete(); + if($infores === false){ + M()->rollback(); + $this->ajaxReturn(array('status' => 0,"info"=>"重算失败")); + } + //删除自己 + $poolres = $this->DBModel->where("id = {$info['id']}")->delete(); + if($poolres === false){ + M()->rollback(); + $this->ajaxReturn(array('status' => 0,"info"=>"重算失败")); + } + //修改引用不足单 + if(!empty($dids)){ + $dres = M("aggregate_lack_statement_info","tab_")->where("id in ({$dids})")->save(['is_pool'=>0]); + if($dres === false){ + M()->rollback(); + $this->ajaxReturn(array('status' => 0,"info"=>"重算失败")); + } + } + //删除创建的不足单 + if(!empty($cids)){ + $cres = M("aggregate_lack_statement_info","tab_")->where("id in ({$cids})")->delete(); + if($cres === false){ + M()->rollback(); + $this->ajaxReturn(array('status' => 0,"info"=>"重算失败")); + } + } + M()->commit(); + + //重新计算 + $stime = $info['statement_end_time']-0+1; + $type = $info['withdraw_type']; + A("AggregateStatementSet")->promoteUserPool($type,$stime,true,$info['is_payment']); + $this->ajaxReturn(array( + 'status' => 1, + 'info' => "重算成功" + )); + } + + public function cancelQzPool($info){ + if(!empty($info['del_lack_ids'])){ + M()->startTrans();//事务 + $dbres = M("aggregate_lack_statement_info","tab_")->where("id in ({$info['del_lack_ids']})")->save(['is_pool'=>0]); + $poolres = $this->DBModel->where("id = {$info['id']}")->delete(); + $infores = M("aggregate_statement_info","tab_")->where("pool_id = {$info['id']}")->delete(); + if($dbres !== false && $poolres !== false && $infores !== false){ + M()->commit(); + $this->ajaxReturn(array( + 'status' => 1, + 'info' => "撤销汇总成功" + )); + } + } + M()->rollback(); + $this->ajaxReturn(array( + 'status' => 0, + 'info' => "撤销汇总失败" + )); + } + + public function cancelCompanyPool($info) + { + if(in_array($info['verify_status'],[3,4])) return;//有打款就不允许回退 + + $sids = $info['statement_ids']; + $dids = $info['del_lack_ids']; + $cids = $info['create_lack_ids']; + + M()->startTrans();//事务 + //删除info + $infores = M("aggregate_statement_info","tab_")->where("pool_id = {$info['id']}")->delete(); + if($infores === false){ + M()->rollback(); + $this->ajaxReturn(array('status' => 0,"info"=>"撤销汇总失败")); + } + //删除自己 + $poolres = $this->DBModel->where("id = {$info['id']}")->delete(); + if($poolres === false){ + M()->rollback(); + $this->ajaxReturn(array('status' => 0,"info"=>"撤销汇总失败")); + } + //修改结算单信息 + $st_res = M("aggregate_statement","tab_")->field("id,verify_status,verify_log")->where("id in ({$sids})")->select(); + foreach($st_res 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'] = json_encode($v['verify_log']); + $v['verify_status']=-3; + $stres = M("aggregate_statement","tab_")->save($v); + if($stres === false){ + M()->rollback(); + $this->ajaxReturn(array('status' => 0,"info"=>"撤销汇总失败")); + } + } + //修改引用不足单 + if(!empty($dids)){ + $dres = M("aggregate_lack_statement_info","tab_")->where("id in ({$dids})")->save(['is_pool'=>0]); + if($dres === false){ + M()->rollback(); + $this->ajaxReturn(array('status' => 0,"info"=>"撤销汇总失败")); + } + } + //删除创建的不足单 + if(!empty($cids)){ + $cres = M("aggregate_lack_statement_info","tab_")->where("id in ({$cids})")->delete(); + if($cres === false){ + M()->rollback(); + $this->ajaxReturn(array('status' => 0,"info"=>"撤销汇总失败")); + } + } + M()->commit(); + $this->ajaxReturn(array( + 'status' => 1, + "info"=>"撤销汇总成功" + )); + } + + + + public function OpAuth($info) + { + $id = $info['id']; + $img = $info['ext_file']; + $remark = $info['remark']; + $create_lack_ids = $info['create_lack_ids']; + $is_qz = (substr($info['statement_num'],0,2) == "QZ" ? true :false); //强制汇总的都允许回退 + + $re_op = true; + if(!empty($create_lack_ids) && !$is_qz){ + $clsi = M("aggregate_lack_statement_info","tab_")->where("is_pool = 1 and id in ({$create_lack_ids})")->find(); + $re_op = true; + if(!empty($clsi)){ + $re_op = false; //被引用无法重算 + } + } + + //原始列表 + $opBtn = [ + "viewPool"=>"查看", + + "addRemark"=>"新增备注", + "editRemark"=>"修改备注", + "viewRemark"=>"查看备注", + + "uploadVoucher"=>"上传凭证", + "viewVoucher"=>"查看凭证", + "editVoucher"=>" 编辑凭证", + + "setUlPayment"=>"线下打款", + + "setPayment"=>"打款信息提交", + "editPayment"=>"打款信息编辑", + "viewPayment"=>"打款详情", + + 'reCount'=>"重算", + 'cancelPool'=>"撤销汇总", + + ]; + //操作对应菜单 + $optist = []; + switch ($info['verify_status']) { + case '-2': + case '-1': + case '0': + $optist = ["viewPool","reCount","cancelPool"]; + break; + case '1': + $optist = ["viewPool","addRemark","viewRemark","editRemark","viewVoucher","editVoucher","uploadVoucher","setPayment","setUlPayment"]; + break; + case '2': + $optist = ["viewPool","addRemark","viewRemark","editRemark","viewVoucher","editVoucher","uploadVoucher","editPayment"]; + break; + case '3': + $optist = ["viewPool","addRemark","viewRemark","editRemark","viewVoucher","editVoucher","uploadVoucher","editPayment","viewPayment"]; + break; + case '4': + $optist = ["viewPool","addRemark","viewRemark","editRemark","viewVoucher","editVoucher","uploadVoucher","viewPayment"]; + break; + case '5': + $optist = ["viewPool","addRemark","viewRemark","editRemark","reCount","cancelPool"]; + break; + default: + break; + } + $optist = ["viewPool"]; + // + if($info['platform_amount'] <= 0 && $info['company_type'] != 2){ + $optist = array_diff($optist, ["viewPool"]); + } + //个人重算,上游撤销 + if($re_op){ + + if($is_qz){ + $optist = array_diff($optist, ["reCount"]); + }else{ + if($info['company_type'] == 2){ + $optist = array_diff($optist, ["cancelPool"]); + }else{ + $optist = array_diff($optist, ["reCount"]); + } + } + + }else{ + $optist = array_diff($optist, ["cancelPool","reCount"]); + } + + if(empty($info['ext_file'])){ + //未上传凭证 + $optist = array_diff($optist, ["viewVoucher", "editVoucher"]); + }else{ + $optist = array_diff($optist, ["uploadVoucher"]); + } + + if($info['is_payment'] == 1){ + $optist = array_diff($optist, ["setUlPayment"]); + }else{ + $optist = array_diff($optist, ["setPayment","editPayment","viewPayment"]); + } + + if(empty($info['remark'])){ + //未上传备注 + $optist = array_diff($optist, ["editRemark", "viewRemark"]); + }else{ + $optist = array_diff($optist, ["addRemark"]); + } + + // + $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 = [ + "verifyAgree"=>"审批通过", + "verifyRefuse"=>"审核拒绝", + "export"=>"批量导出" + ]; + $resarr = []; + foreach ($mentBtn as $k => $v) { + if(IS_ROOT){ + $resarr[] = $v; + }else{ + if(in_array($k,$this->OpAuthList)){ + $resarr[] = $v; + } + } + } + return $resarr; + } + +} diff --git a/Application/Admin/Controller/AggregateStatementSetController.class.php b/Application/Admin/Controller/AggregateStatementSetController.class.php new file mode 100644 index 000000000..f890c5063 --- /dev/null +++ b/Application/Admin/Controller/AggregateStatementSetController.class.php @@ -0,0 +1,1254 @@ +"周结", + "1"=>"月结", + "2"=>"补点" + ]; + public $token = "LYHTQDJS"; + + public function _initialize(){ + $cpapihost = M("Kv")->field("value")->where("`key` = 'aggregate_cp_settlement_api'")->find(); + + if(empty($cpapihost)){ + echo "请先设置请求接口aggregate_cp_settlement_api的值".PHP_EOL;die; + } + $this->cpapihost = $cpapihost['value']; + } + /** + * Undocumented function + * + * @param [type] $begin 开始时间 2020-04-01 + * @param string $end 结束时间,默认今天 + * @param string $company all/pc/cp/pu 全部 下游公司 上游 下游个人 + * @return void + */ + public function setFreeDateCount($begin,$end='',$company='all') + { + if($end == '') $end = $begin; + //判断日期格式 + $patten = "/^\d{4}[\-](0?[1-9]|1[012])[\-](0?[1-9]|[12][0-9]|3[01])$/"; + if (!preg_match($patten, $begin)) { + die("开始时间格式错误"); + } + if (!preg_match($patten, $end)) { + die("结束时间格式错误"); + } + if(strtotime($end) < strtotime($begin)){ + die("结束时间不能比开始时间小"); + } + if(strtotime($end)+86399-24*3600 > time()){ + die("结束时间不能大于当前"); + } + + $starttime = $begin?strtotime($begin):mktime(0,0,0,date('m'),date('d'),date('Y')); + $endtime = $end?strtotime($end)+86399:$starttime+86399; + $datelist = get_date_list($starttime,$endtime,1); + $countdate = count($datelist); + for($i=0;$i<$countdate;$i++){ + $this->setDailyCount($datelist[$i],$company); + } + } + public function setDailyCount($stime="now",$company='all') + { + if(!IS_CLI){ + die("只支持脚本访问"); + } + if($stime=="now"){ + $stime=time(); + }else{ + $stime = strtotime($stime); + } + $nowdate = date("Y-m-d",$stime); + $w = (int)date("w",$stime); + $d = (int)date("d",$stime); + + if($w == 1 || $d == 1){ + if($w == 1){ + if($company == "all"){ + echo $nowdate.":".PHP_EOL; + echo "--周结begin".PHP_EOL; + + $this->cpStatement(0,$stime); + echo "∟----CP周结统计ok".PHP_EOL; + + $this->promoteCompanyStatement(0,$stime); + echo "∟----推广公司周结统计ok".PHP_EOL; + + $this->promoteUserPool(0,$stime); + echo "∟----推广个人周结ok".PHP_EOL; + } + if($company == "cp"){ + $this->cpStatement(0,$stime); + echo "∟----CP周结统计ok".PHP_EOL; + } + if($company == "pc"){ + $this->promoteCompanyStatement(0,$stime); + echo "∟----推广公司周结统计ok".PHP_EOL; + } + if($company == "pu"){ + $this->promoteUserPool(0,$stime); + echo "∟----推广个人周结ok".PHP_EOL; + } + + } + if($d == 1){ + if($company == "all"){ + echo $nowdate.":".PHP_EOL; + echo "--月结&补点begin".PHP_EOL; + + $this->cpStatement(1,$stime); + $this->cpStatement(2,$stime); + echo "∟----CP月结&补点统计ok".PHP_EOL; + + $this->promoteCompanyStatement(1,$stime); + $this->promoteCompanyStatement(2,$stime); + echo "∟----推广公司月结&补点统计ok".PHP_EOL; + + $this->promoteUserPool(1,$stime); + $this->promoteUserPool(2,$stime); + echo "∟----推广个人月结&补点统计ok".PHP_EOL; + } + if($company == "cp"){ + $this->cpStatement(1,$stime); + $this->cpStatement(2,$stime); + echo "∟----CP月结&补点统计ok".PHP_EOL; + } + if($company == "pc"){ + $this->promoteCompanyStatement(1,$stime); + $this->promoteCompanyStatement(2,$stime); + echo "∟----推广公司月结&补点统计ok".PHP_EOL; + } + if($company == "pu"){ + $this->promoteUserPool(1,$stime); + $this->promoteUserPool(2,$stime); + echo "∟----推广个人月结&补点统计ok".PHP_EOL; + } + } + }else{ + echo $nowdate."非周一和月初,无需任何处理".PHP_EOL; + } + } + /** + * 上游结算 + * @param [string] $type 0:周结 1:月结 2:周结补点 + */ + public function cpStatement($type,$stime,$company_id=false,$recount=true) + { + $t = $this->setBeginAndEndTime($type,$stime);; + $begintime = $t[0]; + $endtime = $t[1]; + if($company_id === false){ + //非重算 + $where = [ + "_string"=>"first_company_type = '1' OR second_company_type = '1'" + ]; + }else{ + $where = [ + "_string"=>"(first_company_type = '1' AND first_company_id in ({$company_id}) ) OR (second_company_type = '1' AND second_company_id in ({$company_id}) )" + ]; + } + //获取哪些要结算 + if($type == 1){ + $where['settlement_type']=2; + $cpDbRes = M("CompanyRelation","tab_")->where($where)->select(); + }else{ + $where['settlement_type']=1; + $cpDbRes = M("CompanyRelation","tab_")->where($where)->select(); + } + + $cpList=[]; + $js_id = [];//己方公司 + foreach ($cpDbRes as $k => $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']; + } + + } + if(count($js_id) ==0 || count($cpList) == 0){return ;} + + $cp_id = implode(",",array_flip(array_flip(array_keys($cpList))));//已绑定关系 + $js_id = implode(",",array_unique($js_id)); + //获取cp公司 + $cpmap = [ + "id"=>['in',$cp_id], + "_string"=>"(validity_start_time > 0 AND validity_end_time = 0 ) OR validity_end_time >= {$endtime}" + ]; + $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($cpmap)->select(); + if(empty($tmpp)){ + return true; + } + $cp =[]; + foreach ($tmpp as $v) { + $cp[$v['id']]=$v; + } + $cp_id = implode(",",array_column($tmpp,"id")); //结算的id + 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); + //获取聚合数据 + $sign = md5($begintime.$endtime."1".$this->token); + $arr = [ + "begintime"=>$begintime, + "endtime"=>$endtime, + "type"=>1, + "sign"=>$sign, + "cp_id"=>$cp_id + ]; + $dataurl .= $this->cpapihost."&".http_build_query($arr); + $html = file_get_contents($dataurl); + //防止并发压力 + sleep(3); + $rsp = json_decode($html,true); + if($rsp['code'] != 1){ + echo $rsp['error'].PHP_EOL;die; + }else{ + $rsp = $rsp['data']; + } + //整合数据本地 + + foreach($locals as $k=>$v){ + $cpList[$k]["list"] = $v["list"]; + } + + //整合数据,聚合 + foreach($rsp as $k=>$v){ + if(isset($cpList[$k]["list"])){ + //已经存在 + foreach($rsp[$k]["list"] as $ke=>$va){ + if(isset($cpList[$k]["list"][$ke])){ + $cpList[$k]["list"][$ke]['pay_money'] += $va['pay_money']; + }else{ + $cpList[$k]["list"][$ke] = $va; + } + } + }else{ + $cpList[$k]["list"] = $v["list"]; + } + + } + //比例计算及保存 + // TODO:此处不判断现游戏名=原包名,但却不是同一款游戏 + $verify_log=json_encode(["create_user"=>"system","create_time"=>date("Y-m-d H:i:s")]); + $GameDb = M("Game","tab_"); + $StatementDb = M("CompanyStatement","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){ + //甲方上游 + $cp[$v['first_company_id']]['invoice_type'] = $v['invoice_type']; + $cp[$v['first_company_id']]['invoice_content'] = $v['invoice_content']; + + $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{ + //乙方上游 + $cp[$v['second_company_id']]['invoice_type'] = $v['invoice_type']; + $cp[$v['second_company_id']]['invoice_content'] = $v['invoice_content']; + + $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(); + $add_data['statement_info'] =[]; + $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']]['taxation_rate'] ?? 0; + //游戏统计 + if(!isset($v['list'])){continue;} + foreach($v['list'] as $ke=>$va){ + $game =[]; + $game['pay_amount'] =$va['pay_money']; + $game['game_name'] =$ke; + //获取游戏id及比例 + $game_id = $GameDb->where("relation_game_name='{$ke}' OR original_package_name='{$ke}'")->field("id,relation_game_id")->find(); + if(empty($game_id) && isset($va['unique_code']) && !empty($va['unique_code'])){ + $unique_code = $va['unique_code']; + $game_id = $GameDb->where("unique_code='{$unique_code }'")->field("id,relation_game_id")->find(); + } + if(empty($game_id)){ + $game['relation_game_id']=0; + $tratio = 0; + }else{ + //获取比例 + $game['relation_game_id']=$game_id['relation_game_id']; + if($type == 1){ + $tratio = getGameCpRadio($game_id['id'],$va['pay_money'],true); + }elseif($type == 0){ + $tratio = getGameCpRadio($game_id['id'],$va['pay_money'],false); + }else{ + //补丁 + $tratio1 = getGameCpRadio($game_id['id'],$va['pay_money'],true); + $tratio2 = getGameCpRadio($game_id['id'],$va['pay_money'],false); + $tratio = $tratio1-$tratio2; + if($tratio <= 0){continue;} + } + } + 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; + } + $add_data['pay_amount'] += $va['pay_money']; + + $game['sum_money']=round($va['pay_money']*(100-$promote_ratio)*$tratio*(100-$fax_ratio)/(100*100*100),2);//结算金额=平台总额*(1-渠道费)*分成比例*(1-税费费率) + + $add_data['statement_money'] += $game['sum_money']; + + $game['fax_ratio']=$fax_ratio; + $game['promote_ratio']=$promote_ratio; + + $game['statement_begin_time']=$statement_begin_time; + $game['statement_end_time']=$statement_end_time; + $game['statement_type']=0; + $add_data['statement_info'][] = $game; + } + $add_data['platform_amount'] = $add_data['pay_amount']; + if($type < 2){ + //非补点奖罚 + $rrmap = array( + "confirm_time" => ['between', [$begintime,$endtime]], + "company_type"=>1, + "company_id"=>$add_data['company_id'], + "settlement_type"=>2, + ); + $rfres = M("RewardDetail","tab_") + ->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 + ") + ->where($rrmap)->find(); + if($rfres['reward_count'] > 0){ + $reward_count = $rfres['reward_count']; + $add_data['statement_info'][] = array( + "statement_begin_time"=>$statement_begin_time, + "statement_end_time"=>$statement_end_time, + 'statement_type'=>2, + "game_name"=>"奖励", + 'pay_amount'=>$reward_count, + 'sum_money'=>$reward_count, + ); + $add_data['statement_money']+=$reward_count; + $add_data['pay_amount']+=$reward_count; + } + if($rfres['fine_count'] > 0){ + $fine_count = $rfres['fine_count']; + $add_data['statement_info'][] = array( + "statement_begin_time"=>$statement_begin_time, + "statement_end_time"=>$statement_end_time, + 'statement_type'=>1, + "game_name"=>"罚款", + 'pay_amount'=>$fine_count, + 'sum_money'=>$fine_count, + ); + $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); + if($type == 2 && $add_data['statement_money'] == 0){ + //金额为0不补点 + continue; + } + if($add_data['platform_amount'] == 0){ + //全等于0表示没有流水,小于0依旧要结算 + return; + } + //添加 + if($recount && $company_id !== false){ + //非重算 + return $add_data; + } + $StatementDb->add($add_data); + + } + } + + /** + * 获取本地上游结算 + */ + public function getLocalStatementData($begintime,$endtime,$cp_id) + { + $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,select_package_name")->where($game_where)->select(); + $gameList=[]; + foreach ($gameDbRes as $k => $v) { + $gameList[$v['id']] =$v; + } + //获取所有id + $gmstr = implode(",",array_flip(array_flip(array_column($gameDbRes,'id')))); + //获取支付记录 + $paywhere = [ + "pay_status"=>1, + "pay_game_status"=>1, + "payed_time"=>["BETWEEN",[$begintime,$endtime]], + "game_id"=>["in",$gmstr] + ]; + $paydb = M('spend','tab_'); + $paylist = $paydb->field("game_id,SUM(pay_amount) pay_amount")->where($paywhere)->group("game_id")->select(); + if(empty($paylist)){ + return []; + } + //绑定价格 + foreach ($paylist as $k => $v) { + $gameList[$v['game_id']]['pay_money'] =$v["pay_amount"]; + } + unset($paylist); + //按游戏名称及cp整理数据 + $cplList = []; + foreach ($gameList as $k => $v) { + if($v['pay_money'] <= 0) continue; //0值不发送 + if(empty($v['original_package_name'])){ + $game_name = $v['game_name']; + }else{ + if($v['select_package_name'] == 0){ + $game_name = $v['original_package_name']; + }else{ + $game_name = $v['game_name']; + } + } + $cp_id = $v['cp_id']; + unset($v['cp_id']); + $ymoney = $cplList[$cp_id]['list'][$game_name]["pay_money"]?:0; + $cplList[$cp_id]['list'][$game_name]["pay_money"] =$ymoney+$v["pay_money"]; + // if($type==2){ + // $cplList[$cp_id]['list'][$game_name]["list"][] =$v; //传递列表详情 + // } + } + return $cplList; + } + /** + * 下游结算 + */ + public function promoteCompanyStatement($type,$stime,$company_id=false,$recount=true) + { + $t = $this->setBeginAndEndTime($type,$stime); + $begintime = $t[0]; + $endtime = $t[1]; + + if($company_id === false){ + //非重算 + $where = [ + "_string"=>"first_company_type = '2' OR second_company_type = '2'" + ]; + }else{ + $where = [ + "_string"=>"(first_company_type = '2' AND first_company_id in ({$company_id}) ) OR (second_company_type = '2' AND second_company_id in ({$company_id}) )" + ]; + } + //获取哪些要结算 + if($type == 1){ + $where['settlement_type']=2; + $pcDbRes = M("CompanyRelation","tab_")->where($where)->select(); + }else{ + $where['settlement_type']=1; + $pcDbRes = M("CompanyRelation","tab_")->where($where)->select(); + } + $pcList=[]; + $js_id = [];//己方公司 + foreach ($pcDbRes as $k => $v) { + if($v['first_company_type'] == 2){ + $pcList[$v['first_company_id']] =$v; + $js_id[] =$v['second_company_id']; + }else{ + $pcList[$v['second_company_id']] =$v; + $js_id[] =$v['first_company_id']; + } + + } + $pc_id = implode(",",array_flip(array_flip(array_keys($pcList)))); + $js_id = implode(",",array_unique($js_id)); + if(count($js_id) ==0 || count($pcList) == 0){ + //无需处理 + return ; + } + $pc_map = [ + "id"=>["IN",$pc_id], + "_string"=>"(validity_start_time > 0 AND validity_end_time = 0 ) OR validity_end_time >= {$endtime}", + "company_type"=>1 + ]; + //获取pc公司 + $tmpp = M("PromoteCompany","tab_")->field("id,uid,company_name partner,settlement_contact link_man,address,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($pc_map) + ->select(); + if(empty($tmpp)){ + return true; + } + $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; + } + + 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); + $this->getPromoteCompanySpend($pcList,array_unique(array_keys($pcList)),$begintime,$endtime); + //数据整合 + $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("RewardDetail","tab_"); + foreach($pcList as $k=>$v){ + 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){ + //甲方合作 + $pc[$v['first_company_id']]['invoice_type'] = $v['invoice_type']; + $pc[$v['first_company_id']]['invoice_content'] = $v['invoice_content']; + + $add_data['first_party_info'] = json_encode($pc[$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{ + //乙方合作 + $pc[$v['second_company_id']]['invoice_type'] = $v['invoice_type']; + $pc[$v['second_company_id']]['invoice_content'] = $v['invoice_content']; + $add_data['first_party_info'] = json_encode($our[$v['first_company_id']],JSON_UNESCAPED_UNICODE); + $add_data['second_party_info'] = json_encode($pc[$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(); + $add_data['is_payment']=$v['is_payment']; + $add_data['statement_info'] =[]; + + //获取渠道及发票税率 + $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']; + if(!isset($v['list'])){continue;} + //游戏统计 + foreach($v['list'] as $ke=>$va){ + $game =[]; + $game['pay_amount'] =$va['pay_amount']; + $game['game_name'] =$va['game_name']; + //获取比例 + $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 += $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+$company_ratio; + if($tratio <= 0){ continue;} + } + + if($v['type'] == 2){ + $game['increment_ratio']=$tratio; + }else{ + $game['ratio']=$tratio; + } + $add_data['pay_amount'] += $va['pay_amount']; + + $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; + + $game['statement_begin_time']=$statement_begin_time; + $game['statement_end_time']=$statement_end_time; + $game['statement_type']=0; + $add_data['statement_info'][] = $game; + } + $add_data['platform_amount'] = $add_data['pay_amount']; + if($type < 2){ + //非补点计算奖罚 + $rrmap = array( + "confirm_time" => ['between', [$begintime,$endtime]], + "company_type"=>2, + "company_id"=>$add_data['company_id'], + "settlement_type"=>2, + ); + $rfres = M("RewardDetail","tab_") + ->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 + ") + ->where($rrmap)->find(); + if($rfres['reward_count'] > 0){ + $reward_count = $rfres['reward_count']; + $add_data['statement_info'][] = array( + "statement_begin_time"=>$statement_begin_time, + "statement_end_time"=>$statement_end_time, + 'statement_type'=>2, + "game_name"=>"奖励", + 'pay_amount'=>$reward_count, + 'sum_money'=>$reward_count, + ); + $add_data['statement_money']+=$reward_count; + $add_data['pay_amount']+=$reward_count; + } + if($rfres['fine_count'] > 0){ + $fine_count = $rfres['fine_count']; + $add_data['statement_info'][] = array( + "statement_begin_time"=>$statement_begin_time, + "statement_end_time"=>$statement_end_time, + 'statement_type'=>1, + "game_name"=>"罚款", + 'pay_amount'=>$fine_count, + 'sum_money'=>$fine_count, + ); + $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); + if($type == 2 && $add_data['statement_money'] == 0){ + //金额为0不补点 + continue; + } + if($add_data['platform_amount'] == 0){ + return; + } + // dd($add_data); + //添加 + if($recount && $company_id !== false){ + //非重算 + return $add_data; + } + $StatementDb->add($add_data); + } + } + //设定开始结束时间 + 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; + }else{ + $thismonth = date('m',$stime); + $thisyear = date('Y',$stime); + if ($thismonth == 1) { + $lastmonth = 12; + $lastyear = $thisyear - 1; + } else { + $lastmonth = $thismonth - 1; + $lastyear = $thisyear; + } + $lastStartDay = $lastyear . '-' . $lastmonth . '-1'; + $lastEndDay = $lastyear . '-' . $lastmonth . '-' . date('t', strtotime($lastStartDay)); + $begintime = strtotime($lastStartDay);//上个月的月初时间戳 + $endtime = strtotime($lastEndDay)+24*3600-1;//上个月的月末时间戳 + } + return [$begintime,$endtime]; + } + //获取推广公司推广金额 + public function getPromoteCompanySpend(&$pcList,$idarr,$begintime,$endtime){ + $res = []; + //获取推广员 + if(count($idarr) == 0){return $res;} + $Promote = M("Promote","tab_"); + $Spend = M("Spend","tab_"); + $spenMap = [ + "s.pay_status"=>1, + "s.payed_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']]; + //获取支付记录 + $list = $Spend->alias('s')->field('sum(s.pay_amount) pay_amount,s.game_id,g.relation_game_id,g.relation_game_name game_name')->where($spenMap)->group('game_id') + ->join("left join tab_game g on s.game_id = g.id") + ->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']; + }else{ + unset($v['game_id']); + $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,$is_payment=false){ + $t = $this->setBeginAndEndTime($type,$stime); + $begintime = $t[0]; + $endtime = $t[1]; + + $basedata = [ + "pay_amount"=>0, + "statement_money"=>0, + "lack_statement_money"=>0, + "withdraw_type"=>$type, + "platform_amount"=>0, + "create_lack_ids"=>[], + "del_lack_ids"=>[], + "statement_begin_time"=>$begintime, + "statement_end_time"=>$endtime, + "fine"=>0, + "reward"=>0, + "verify_status"=>0, + "company_type"=>2, + "verify_log"=>json_encode(["create_user"=>"system","create_time"=>date("Y-m-d H:i:s")]), + "op_time"=>time() + ]; + $users = $user = $basedata; + $users['is_payment'] = 1; + $users['statement_num'] = "PL_".date('Ymd').date('His').sp_random_num(3); + + $user['is_payment'] = 2; + $user['statement_num'] = "PL_".date('Ymd').date('His').sp_random_num(3); + + + + if($type == 0){//周结 + $this->doPromoteUserPool($user,$users,$type,$stime,$recount); + }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); + } + if($is_payment !== false && $is_payment==1){ + $this->savePromotateUserPool($users); + }else if($is_payment !== false && $is_payment==2){ + $this->savePromotateUserPool($user); + }else{ + $this->savePromotateUserPool($users); + $this->savePromotateUserPool($user); + } + + } + + /** + * 下游个人汇总单 + */ + public function doPromoteUserPool(&$user,&$users,$type,$stime,$recount = false) + { + $t = $this->setBeginAndEndTime($type,$stime); + $begintime = $t[0]; + $endtime = $t[1]; + + $where = [ + "_string"=>"first_company_type = '2' OR second_company_type = '2'" + ]; + //获取哪些要结算 + if($type == 1){//月结 + $where['settlement_type']=2; + $pcDbRes = M("CompanyRelation","tab_")->where($where)->select(); + }else{ + $where['settlement_type']=1; + $pcDbRes = M("CompanyRelation","tab_")->where($where)->select(); + } + + $pcList=[]; + $js_id = [];//己方公司 + foreach ($pcDbRes as $k => $v) { + if($v['first_company_type'] == 2){ + $pcList[$v['first_company_id']] =$v; + $js_id[] =$v['second_company_id']; + }else{ + $pcList[$v['second_company_id']] =$v; + $js_id[] =$v['first_company_id']; + } + } + //获取pc公司 + $pc_id = implode(",",array_flip(array_flip(array_keys($pcList)))); + $pu_map = [ + "id"=>["IN",$pc_id], + "_string"=>"(validity_start_time > 0 AND validity_end_time = 0 ) OR validity_end_time >= {$endtime}", + "company_type"=>2 + ]; + $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($pu_map) + ->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']; + } + unset($tmpp); + $this->getPromoteCompanySpend($pc,array_unique(array_keys($pc)),$begintime,$endtime); + + $StatementDb = M("CompanyStatement","tab_"); + $statement_begin_time = date("Y.m.d",$begintime); + $statement_end_time = date("Y.m.d",$endtime); + // $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){ + $countdata = &$users; + }else{ + $countdata = &$user; + } + $v['statement_money'] = 0; + $v['pay_amount'] = 0; + $v['fine'] = 0; + $v['reward'] = 0; + $v['platform_amount'] = 0; + if(!isset($v['list'])){continue;} + $company_belong = $pc[$v['id']]['company_belong']; + //服务器费用 + 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']; + $game['game_name'] =$va['game_name']; + //获取比例 + $game['relation_game_id']=$va['relation_game_id']; + $game['game_type_name'] = $this->getGameTypeName($va['relation_game_id']); + + 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+$company_ratio; + if($tratio <= 0){ + continue; + } + } + if($type == 2){ + $game['increment_ratio']=$tratio; + }else{ + $game['ratio']=$tratio; + } + $v['pay_amount'] += $va['pay_amount']; + $v['platform_amount'] += $va['pay_amount']; + //判断是否是个人 + if($type < 2){ + //非补点 + 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']; //个人等于 结算金额*比例-罚款+奖励 + $v['statement_money'] += $game['sum_money']; + + $game['fax_ratio']=$fax_ratio; + + $game['statement_begin_time']=$statement_begin_time; + $game['statement_end_time']=$statement_end_time; + $game['statement_type']=0; + $v['statement_info'][] = $game; + } + $company_info = [ + 'account'=>$v['account'], + "company_relation_str"=>$v['company_relation_str'], + "company_type_str"=>$v['company_type_str'], + "nickname"=>$v['nickname'], + "payee_name"=>$v['payee_name'], + "bank_account"=>$v['bank_account'], + "opening_bank"=>$v['opening_bank'], + "ali_user"=>$v['ali_user'], + "ali_account"=>$v['ali_account'] + ]; + if($v['pay_amount'] < 300){ + $lackcompany =[ + "company_id"=>$k, + "company_type"=>2, + "company_name"=>$v['partner'], + "company_info"=>json_encode($company_info,JSON_UNESCAPED_UNICODE), + "statement_money"=>$v['statement_money'], + "pay_amount"=>$v['pay_amount'], + "platform_amount"=>$v['platform_amount'], + "fine"=>$v['fine'], + "reward"=>$v['reward'], + "statement_begin_time"=>$begintime, + "statement_end_time"=>$endtime, + + "statement_pool_num"=>$countdata['statement_num'],//母单 + + "is_payment"=>$v['is_payment'], + "statement_info"=>json_encode($v['statement_info'],JSON_UNESCAPED_UNICODE) + ]; + } + //聚合未结算数据 + $lsres = $LackStatement->where("company_id='{$k}' and is_pool = 0")->select(); + + $del_lack_ids = []; + if(count($lsres) > 0){ + //进行聚合 + foreach($lsres as $key=>$val){ + + $del_lack_ids[] = $val['id']; + $v['statement_money'] += $val['statement_money']; + $v['pay_amount'] += $val['pay_amount']; + $v['fine'] += $val['fine']; + $v['reward'] += $val['reward']; + $v['platform_amount'] += $val['platform_amount']; + $v['statement_info'] = array_merge($v['statement_info'],json_decode($val['statement_info'],true)); + + $last_names = array_column($v['statement_info'],'game_name'); + array_multisort($last_names,SORT_DESC,SORT_STRING,$v['statement_info']); + } + } + + if($type == 2 && $v['statement_money'] == 0){ + //补点不存 + }else{ + if($v['platform_amount'] < 300){ + //存未满 + if($lackcompany['pay_amount'] != 0){ + $lask_id = $LackStatement->add($lackcompany); + $countdata['create_lack_ids'][] =$lask_id; + $countdata['lack_statement_money'] +=$lackcompany['statement_money']; + $countdata['lack_platform_amount'] +=$lackcompany['platform_amount']; + } + + }else{ + if($v['pay_amount'] != 0){ + //存成功配置单号 + $company =[ + "pool_id"=>0, + "company_id"=>$k, + "company_type"=>2, + "company_name"=>$v['partner'], + "company_info"=>json_encode($company_info,JSON_UNESCAPED_UNICODE), + "statement_money"=>$v['statement_money'], + "pay_amount"=>$v['pay_amount'], + "platform_amount"=>$v['platform_amount'], + "fine"=>$v['fine'], + "reward"=>$v['reward'], + "statement_begin_time"=>$begintime, + "statement_end_time"=>$endtime, + "statement_info"=>json_encode($v['statement_info'],JSON_UNESCAPED_UNICODE), + "statement_num"=>"JS_".date('Ymd').date('His').$v['company_id'].sp_random_string(5) + ]; + if($v['is_payment'] == 1){ + $company['verify_status'] = 0; + }else{ + $company['verify_status'] = 2; + } + $companyid = $StatementInfo->add($company); + $countdata['info_ids'][] =$companyid; + $countdata['del_lack_ids'] =array_merge($countdata['del_lack_ids'],$del_lack_ids); + $countdata['statement_money'] +=$v['statement_money']; + $countdata['pay_amount'] +=$v['pay_amount']; + $countdata['platform_amount'] +=$v['platform_amount']; + $countdata['fine'] +=$v['fine']; + $countdata['reward'] +=$v['reward']; + } + } + } + } + } + /** + * 保存信息汇总信息 + */ + 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){ + $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")]); + } + $data['create_lack_ids'] = implode(",",$data['create_lack_ids']); + $data['del_lack_ids'] = implode(",",$data['del_lack_ids']); + $info = implode(",",$data['info_ids']); + unset($data['info_ids']); + $id = M("company_statement_pool","tab_")->add($data); + //回写 + if(!empty($info)){ + $save["pool_id"]=$id; + M("company_statement_info","tab_")->where("id in ({$info})")->save($save); + } + if(!empty($data['del_lack_ids'])){ + M("company_lack_statement_info","tab_")->where("id in ({$data['del_lack_ids']})")->save(["is_pool"=>1]); + } + } + + /** + * 获取公司额为信息 + */ + public function getCompanyOtherInfo($company_info,$company_id) + { + $pl = M("promote_company","tab_") + ->alias('pc') + ->field("p.account,p.company_relation,IFNULL(s.nickname,'admin') nickname") + ->join("left join (select company_id,account,company_relation,admin_id from tab_promote where level = 1 group by company_id ) p on p.company_id = pc.id")//获取会长 + ->join("left join sys_member s on s.uid = p.admin_id") + ->where("pc.id = {$company_id}") + ->find(); + $company = array_merge($company_info,$pl); + $company['company_relation_str'] =getCompanyBlong($company['company_belong']).getCompanyRelation($company['company_relation']); + $company['company_type_str'] = "个人"; + return $company; + + } + /** + * 获取游戏分类名称 + */ + 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; + } + + } + + /** + * 重算接口 + * 不进行结算方式重算 + * @param [type] $id 原数据id + * @param string $admin_user 操作用户 + * @return void bool + */ + public function updateCompanyStatementData($id,$admin_user='system') + { + //获取数据 + $StatementDb = M("CompanyStatement","tab_"); + $dbres = $StatementDb->where("id='{$id}'")->find(); + //获取时间 + $stime = $dbres['statement_end_time']-0+1; + $company_id = $dbres['company_id']; + if($dbres['company_belong'] == 9){ + //上游 + $savedata = $this->cpStatement($dbres['withdraw_type'],$stime,$company_id); + }else{ + $savedata = $this->promoteCompanyStatement($dbres['withdraw_type'],$stime,$company_id); + } + //重写用户 + $savedata['verify_log'] = json_encode(["create_user"=>$admin_user,"create_time"=>date("Y-m-d H:i:s")]); + $savedata['verify_status'] = 0; + $savedata['confirm_status'] = 0; + $savedata['confirm_log'] = ''; + $savedata['id'] = $dbres['id']; + return $StatementDb->save($savedata); + } + +} diff --git a/Application/Admin/Controller/CompanyStatementController.class.php b/Application/Admin/Controller/CompanyStatementController.class.php index e727fe19d..8a2b274bb 100644 --- a/Application/Admin/Controller/CompanyStatementController.class.php +++ b/Application/Admin/Controller/CompanyStatementController.class.php @@ -463,6 +463,7 @@ class CompanyStatementController extends ThinkController $ids = $_REQUEST['ids']; $dbres = $this->DBModel->field("*")->where("id in ({$ids})")->select(); //分单 + $basedata = [ "pay_amount"=>0, "statement_money"=>0, diff --git a/Application/Admin/View/AggregateFinanceStatement/lists.html b/Application/Admin/View/AggregateFinanceStatement/lists.html index 4715c0911..782380f03 100644 --- a/Application/Admin/View/AggregateFinanceStatement/lists.html +++ b/Application/Admin/View/AggregateFinanceStatement/lists.html @@ -230,6 +230,53 @@ $("body").append(iframeExcel) } }) + //发起汇总 + $("#pool").on("click",function(){ + var flag = false; + var text = $("input:checkbox[name='ids[]']:checked").map(function(index,elem) { + if($(elem).data("status") != 3){ + flag = true; + }else{ + return $(elem).val(); + } + }).get().join(","); + if(text == ''){ + layer.msg("" + '无需要审批通过的结算单,仅[已审核通过]状态可以进行审批通过' + ""); + return; + } + if(flag){ + layer.confirm("发起汇总仅会对 [已审核通过] 结算单处理,选择中包含其他的状态的结算单将被忽略,点击取消停止操作",{title:false}, function(index){ + _doPoolApply(); + layer.close(index); + }); + }else{ + layer.confirm('【警告】发起汇总将不可回退,如需继续请点击确认', { + btn: ['确认','取消'], + title:false + }, function(index) { + _doPoolApply(); + }) + } + function _doPoolApply(){ + //执行 + $.ajax({ + type: "POST", + url: "{:U('pool')}", + dataType: 'json', + async: false, + data: {ids:text}, + success:function(data){ + if(data.status==1){ + layer.msg("" + data.info + ""); + setTimeout(function(){ + window.location.reload(); + },1500); + } + } + }); + } + }); + //审批通过 $("#agreeApply").on("click",function(){ var flag = false; @@ -245,10 +292,10 @@ return; } if(flag){ - layer.confirm("审批成功仅会对 [已申请发票] 结算单处理,选择中包含其他的状态的结算单将被忽略,点击取消停止操作",{title:false}, function(index){ - _doAgreeApply(); + layer.confirm("审批成功仅会对 [已申请发票] 结算单处理,选择中包含其他的状态的结算单将被忽略,点击取消停止操作",{title:false}, function(index){ + _doAgreeApply(); layer.close(index); - }); + }); }else{ _doAgreeApply(); } @@ -271,6 +318,7 @@ }); } }) + //审批拒绝 $("#refuseApply").on("click",function(){ var flag = false; diff --git a/Application/Admin/View/AggregateRelation/addRelation.html b/Application/Admin/View/AggregateRelation/addRelation.html index 4326e1ee2..8b4839498 100644 --- a/Application/Admin/View/AggregateRelation/addRelation.html +++ b/Application/Admin/View/AggregateRelation/addRelation.html @@ -197,7 +197,8 @@ 开票内容: - + + @@ -386,7 +387,7 @@ $(function(){ function setAggregateInfo(invoice_content,settlement_type,invoice_type) { - $('#invoice_content').val(invoice_content); + $('.invoice_content').val(invoice_content); $('#settlement_type').find("option").each(function() { $(this).removeAttr("selected"); diff --git a/Application/Admin/View/AggregateStatementLack/lists.html b/Application/Admin/View/AggregateStatementLack/lists.html new file mode 100644 index 000000000..71d548201 --- /dev/null +++ b/Application/Admin/View/AggregateStatementLack/lists.html @@ -0,0 +1,404 @@ + + + + + + + + + + + + + + + + + +
+ +
+ +
+ +
+ +
+   +
+ +
+   +
+ +
+ +  -  +
+ + +
+
+ + + +
+ 搜索 +
+ +
+
+ +
+
+ + {$vo} + +
+
+ + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
合作公司公司类型结算时间打款流程结算金额结算流水生成母单来源的汇总单,母单重算将影响子单操作
aOh! 暂时还没有内容!
{$data.company_name}下游聚合{$data.valid}{$data.is_payment_str}{$data.statement_money}{$data.platform_amount}{$data.statement_pool_num} + + {$vo} + +
合计结算总金额: {$count.statement_money}
+
+ +
+
+ + + + {$_page|default=''} +
+
+ + + + if(C('COLOR_STYLE')=='blue_color') echo ' + + '; + + + + + + + + + + diff --git a/Application/Admin/View/AggregateStatementPool/editCpStatement.html b/Application/Admin/View/AggregateStatementPool/editCpStatement.html new file mode 100644 index 000000000..23efb5ce8 --- /dev/null +++ b/Application/Admin/View/AggregateStatementPool/editCpStatement.html @@ -0,0 +1,663 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + +
甲方: +
+ +
+
联系人: + +
联系电话: + +
邮寄地址: + +
公司税号: + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + +
乙方: +
+ +
+
联系人: + +
联系电话: + +
邮寄地址: + +
公司税号: + +
+
+
+
+
+

支付给:{$data.company_name} + +

+
+ +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
结算时间产品平台总额分成比例渠道费率税费费率结算金额
甲方乙方 + 结算金额=平台总额*(1-渠道费)*分成比例*(1-税费费率)
+ 请先选择生成条件后点击生成对账数据 +
+
+
+
+
+
+ + + + + + + + + + + + + + + +
收款方名称: + +
银行账号: + +
开户行: + +
+
+
+ + + + + + + + + + + +
开票项目: + +
发票类型: +
+ +
+
+
+
+
+
+ +
+ + + + + + + + + \ No newline at end of file diff --git a/Application/Admin/View/AggregateStatementPool/editPcStatement.html b/Application/Admin/View/AggregateStatementPool/editPcStatement.html new file mode 100644 index 000000000..d030fc6b8 --- /dev/null +++ b/Application/Admin/View/AggregateStatementPool/editPcStatement.html @@ -0,0 +1,659 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + +
甲方: +
+ +
+
联系人: + +
联系电话: + +
邮寄地址: + +
公司税号: + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + +
乙方: +
+ +
+
联系人: + +
联系电话: + +
邮寄地址: + +
公司税号: + +
+
+
+
+
+

支付给:{$data.company_name} + +

+
+ +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
结算时间产品平台总额(元)补点比例分成比例税费费率结算金额(元)
+ 请先选择生成条件后点击生成对账数据 +
+
+
+
+
+
+ + + + + + + + + + + + + + + +
收款方名称: + +
银行账号: + +
开户行: + +
+
+
+ + + + + + + + + + + +
开票项目: + +
发票类型: +
+ +
+
+
+
+
+
+ +
+ + + + + + + + + \ No newline at end of file diff --git a/Application/Admin/View/AggregateStatementPool/editVoucher.html b/Application/Admin/View/AggregateStatementPool/editVoucher.html new file mode 100644 index 000000000..673de4d9c --- /dev/null +++ b/Application/Admin/View/AggregateStatementPool/editVoucher.html @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + +
+ + + + + + +
文件选择: + + 仅能添加一张凭证,重复添加将覆盖
+
+
+
确认修改
+
删除凭证
+
+
+
+ +
+
+ + + + + + diff --git a/Application/Admin/View/AggregateStatementPool/lists.html b/Application/Admin/View/AggregateStatementPool/lists.html new file mode 100644 index 000000000..aa5018687 --- /dev/null +++ b/Application/Admin/View/AggregateStatementPool/lists.html @@ -0,0 +1,649 @@ + + + + + + + + + + + + + + + + + +
+ +
+
+   +
+ +
+ +
+ + + + +
+ +  -  +
+ + +
+
+ +
+ +
+ +
+ +
+ +
+ +  -  +
+ + +
+
+ +
+ 搜索 +
+ +
+
+ +
+
+ + {$vo} + +
+
+ + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
结算汇总单订单号结算时间结算周期结算金额不结算金额创建记录审批状态打款状态凭证操作
aOh! 暂时还没有内容!
{$data.statement_num}{$data.valid}{$data.withdraw_type}{$data.statement_money}{$data.lack_statement_money}{$data.create} + +
+ {$data.verify} +
+ +
+ {$data.verify} +
+
+
+ +
+ {$data.payment} +
+ +
+ {$data.payment} +
+
+
{$data.ext_file_type} + + {$vo} + +
合计结算总金额: {$count.statement_money}     不结算总金额:{$count.lack_statement_money}   
+
+ +
+
+ + + + {$_page|default=''} +
+
+ + + + if(C('COLOR_STYLE')=='blue_color') echo ' + + '; + + + + + + + + + + diff --git a/Application/Admin/View/AggregateStatementPool/setPayment.html b/Application/Admin/View/AggregateStatementPool/setPayment.html new file mode 100644 index 000000000..9ace64b39 --- /dev/null +++ b/Application/Admin/View/AggregateStatementPool/setPayment.html @@ -0,0 +1,249 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
序号合作公司支付宝真实名称支付宝账号关联结算汇总单订单号金额(元)备注
{$key-0+1}{$vo.company_name}{$vo.statement_num}{$vo.statement_money}
{$key-0+1}{$vo.company_name}{$vo.company_info.ali_user}{$vo.company_info.ali_account}{$vo.statement_num}{$vo.statement_money}{$vo.remark}
合计:打款总金额:{$CompanyInfo[0]['all_money']}
+
+
+
+ +
+ + + + + + \ No newline at end of file diff --git a/Application/Admin/View/AggregateStatementPool/uploadVoucher.html b/Application/Admin/View/AggregateStatementPool/uploadVoucher.html new file mode 100644 index 000000000..45f383823 --- /dev/null +++ b/Application/Admin/View/AggregateStatementPool/uploadVoucher.html @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + +
+ + + + + + +
文件选择: + + 仅能添加一张凭证,重复添加将覆盖
+
+
+
确认添加
+
删除凭证
+
+
+
+ +
+
+ + + + + + diff --git a/Application/Admin/View/AggregateStatementPool/viewCpPool.html b/Application/Admin/View/AggregateStatementPool/viewCpPool.html new file mode 100644 index 000000000..2fe543ae5 --- /dev/null +++ b/Application/Admin/View/AggregateStatementPool/viewCpPool.html @@ -0,0 +1,194 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
合作公司平台结算日期产品平台流水未结算平台流水分成比例渠道费率税费费率合作方待结算分成违规罚款奖励合作待结算金额备注
合作方我方
{$com.company_name}{$com.matche_platform}{$com['statement_info'][0]['statement_begin_time']} - {$com['statement_info'][0]['statement_end_time']}{$com['statement_info'][0]['game_name']}{$com['statement_info'][0]['pay_amount']}{$com['statement_info'][0]['pay_amount']}{$com['statement_info'][0]['ratio']}%{$com['statement_info'][0]['company_ratio']}%{$com['statement_info'][0]['promote_ratio']}%{$com['statement_info'][0]['fax_ratio']}%{$com['statement_info'][0]['d_statement_money']}{$com.fine}{$com.reward}{$com.statement_money}{$com.renark}
{$it['statement_begin_time']} - {$it['statement_end_time']}{$it['game_name']}{$it['pay_amount']}{$it['pay_amount']}{$it['ratio']}%{$it['company_ratio']}%{$it['promote_ratio']}%{$it['fax_ratio']}%{$it['d_statement_money']}
合计:{$count.platform_amount}{$count.platform_amount2}{$count.d_statement_money}{$count.fine}{$count.reward}{$count.statement_money}
+
+
+ + + diff --git a/Application/Admin/View/AggregateStatementPool/viewPayment.html b/Application/Admin/View/AggregateStatementPool/viewPayment.html new file mode 100644 index 000000000..3c2edbee7 --- /dev/null +++ b/Application/Admin/View/AggregateStatementPool/viewPayment.html @@ -0,0 +1,235 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
序号合作公司支付宝真实名称支付宝账号关联结算汇总单订单号金额(元)备注打款状态
{$key-0+1}{$vo.company_name}{$vo.company_info.ali_user}{$vo.company_info.ali_account}{$vo.statement_num}{$vo.statement_money}{$vo.remark}{$vo.verify_status_str}
合计:打款总金额:{$CompanyInfo[0]['all_money']}
+
+
+ + + + + + \ No newline at end of file diff --git a/Application/Admin/View/AggregateStatementPool/viewPcPool.html b/Application/Admin/View/AggregateStatementPool/viewPcPool.html new file mode 100644 index 000000000..1821046e7 --- /dev/null +++ b/Application/Admin/View/AggregateStatementPool/viewPcPool.html @@ -0,0 +1,177 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
序号公司名称合作产品名称平台总额(元)下游内团分成比例补点比例税费费率分成金额/元罚款奖励合计/元对账人结算日期备注
{$key-0+1}{$com.company_name}{$com['statement_info'][0]['game_name']}{$com['statement_info'][0]['pay_amount']}{$com['statement_info'][0]['ratio']}%{$com['statement_info'][0]['increment_ratio']}%{$com['statement_info'][0]['fax_ratio']}%{$com['statement_info'][0]['d_statement_money']}{$com.fine}{$com.reward}{$com.statement_money}{$com.settlement_contact}{$com['statement_info'][0]['statement_begin_time']} - {$com['statement_info'][0]['statement_end_time']}{$com.renark}
{$it['game_name']}{$it['pay_amount']}{$it['ratio']}%{$it['increment_ratio']}%{$it['fax_ratio']}%{$it['d_statement_money']}{$it['statement_begin_time']} - {$it['statement_end_time']}
合计:{$count.platform_amount}{$count.d_statement_money}{$count.fine}{$count.reward}{$count.statement_money}
+
+
+ + + diff --git a/Application/Admin/View/AggregateStatementPool/viewPcStatement.html b/Application/Admin/View/AggregateStatementPool/viewPcStatement.html new file mode 100644 index 000000000..9765e8d35 --- /dev/null +++ b/Application/Admin/View/AggregateStatementPool/viewPcStatement.html @@ -0,0 +1,306 @@ + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
甲方: +
+ +
+
联系人: + +
联系电话: + +
邮寄地址: + +
公司税号: + +
+
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
乙方: +
+ +
+
联系人: + +
联系电话: + +
邮寄地址: + +
公司税号: + +
+
+
+
+ +
+
+

支付给:{$data.company} + +

+
+
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
结算时间产品平台总额(元)补点比例分成比例税费费率结算金额(元)
{$it.statement_begin_time}~{$it.statement_end_time}{$it.game_name}-{$it.pay_amount}{$it.pay_amount}{$it.increment_ratio}%{$it.ratio}%{$it.fax_ratio}%-{$it.sum_money}{$it.sum_money}
合计{$data.statement_count.pay_amount}{$data.statement_count.statement_money}
本月分成总金额(人民币大写):{$data.statement_count.big_ratio_money}
+
+
+ +
+
+ + + + + + + + + + + + + + + +
收款方名称: + +
银行账号: + +
开户行: + +
+
+
+ + + + + + + + + + + +
开票项目: + +
发票类型: +
+ +
+ +
+
+
+
+ + diff --git a/Application/Admin/View/AggregateStatementPool/viewPuPool.html b/Application/Admin/View/AggregateStatementPool/viewPuPool.html new file mode 100644 index 000000000..4bcc05311 --- /dev/null +++ b/Application/Admin/View/AggregateStatementPool/viewPuPool.html @@ -0,0 +1,268 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
归属团体下游名称下游性质产品产品类型结算时间推广流水分成比例税率奖励罚款结算金额开户名银行卡号开户支行帐户类型支付宝真实姓名支付宝账号备注是否结算操作
{$com.company_belong_name}{$com.company_name}聚合{$com['statement_info'][0]['game_name']}{$com['statement_info'][0]['game_type_name']}{$com['statement_info'][0]['begintime']} - {$com['statement_info'][0]['endtime']}{$com['statement_info'][0]['money']}{$com['statement_info'][0]['ratio']|default=0}%{$com['statement_info'][0]['fax_ratio']|default=0}%00{$com['statement_info'][0]['ratio_money']}{$com.company_info.payee_name} {$com.company_info.bank_account}{$com.company_info.opening_bank}企业账户{$com.company_info.ali_user}{$com.company_info.ali_account}{$com.remark} + + 不结算 + +
{$it['game_name']}{$it['game_type_name']}{$it['begintime']} - {$it['endtime']}{$it['money']}{$it['ratio']|default=0}%{$it['fax_ratio']|default=0}%00{$it['ratio_money']}
合计:{$count.platform_amount|default=0}{$count.sum_money|default=0}
+
+
+ + + diff --git a/Application/Base/Tool/AggregateClient.class.php b/Application/Base/Tool/AggregateClient.class.php index b9208f39d..7b1cb0a8a 100644 --- a/Application/Base/Tool/AggregateClient.class.php +++ b/Application/Base/Tool/AggregateClient.class.php @@ -14,7 +14,8 @@ class AggregateClient private $apis = [ 'game-data' => '/index.php?g=api&m=Game&a=rechargeData', 'aggregate-gamename' => '/index.php?g=api&m=Game&a=getAggregatePacket', - 'aggregate-companylist' => '/index.php?g=api&m=Game&a=getAggregateCompanyList' + 'aggregate-companylist' => '/index.php?g=api&m=Game&a=getAggregateCompanyList', + 'aggregate-companyinfo'=>'/index.php?g=api&m=Game&a=getAggregateCompanyInfo' ]; public function __construct() diff --git a/Data/update.sql b/Data/update.sql index 764f5718e..0c4d3dae0 100644 --- a/Data/update.sql +++ b/Data/update.sql @@ -2401,3 +2401,7 @@ INSERT INTO `sys_kv`(`id`, `key`, `value`, `type`, `remark`) VALUES (4, 'cp_comp ALTER TABLE `sj_game_channel`.`sj_cptogether_company` ADD COLUMN `is_qualifity` tinyint(2) NULL COMMENT '是否具有游戏资质 0 否 1 是' AFTER `is_received`; + +ALTER TABLE `tab_company_relation_log` +ADD COLUMN `first_company_info` longtext NULL COMMENT '甲方公司信息' AFTER `first_company_type`, +ADD COLUMN `second_company_info` longtext NULL COMMENT '乙方公司信息' AFTER `second_company_type`; \ No newline at end of file