You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
229 lines
9.5 KiB
PHP
229 lines
9.5 KiB
PHP
<?php
|
|
namespace Admin\Controller;
|
|
/**
|
|
* cp/公会对账单
|
|
* @author yyh
|
|
*/
|
|
class StatementController extends ThinkController
|
|
{
|
|
//创建
|
|
public function createCpStatement()
|
|
{
|
|
$this->display();
|
|
}
|
|
public function editCpStatement(){
|
|
if(!isset($_REQUEST['id'])) $this->error("参数错误");
|
|
$id = $_REQUEST['id'];
|
|
$dbres = M("statement","tab_")->where("id = '{$id}'")->find();
|
|
$first_party_info = json_decode($dbres['first_party_info'],true);
|
|
$second_party_info = json_decode($dbres['second_party_info'],true);
|
|
$statement_info = json_decode($dbres['statement_info'],true);
|
|
$fine = array_pop($statement_info);
|
|
$senddata = array(
|
|
"first_part_company"=>$first_party_info['partner'],
|
|
"second_part_company"=>$second_party_info['partner'],
|
|
"statement_type"=>$_REQUEST['pay_type'] == 0 ? 1 :0,
|
|
"first_party_info"=>$first_party_info,
|
|
"second_party_info"=>$second_party_info,
|
|
"statement_info"=>$statement_info,
|
|
"statement_count"=>array("sum_money"=>$dbres['statement_money'],"pay_amount"=>$dbres['pay_amount']),
|
|
"fine"=>$fine['sum_money'],
|
|
"statement_begin_time"=>date("Y-m-d",$dbres['statement_begin_time']),
|
|
"statement_end_time"=>date("Y-m-d",$dbres['statement_end_time'])
|
|
);
|
|
$this->assign("data",$senddata);
|
|
if($_REQUEST['pay_type'] == 0){
|
|
$this->assign("company",$dbres['company_name']);
|
|
}else{
|
|
$this->assign("company",$first_party_info['partner']);
|
|
}
|
|
$this->assign("company_id",$dbres['company_id']);
|
|
$this->assign("company_name",$dbres['company_name']);
|
|
$this->assign("statement_begin_time",date("Y-m-d",$dbres['statement_begin_time']));
|
|
$this->assign("statement_end_time",date("Y-m-d",$dbres['statement_end_time']));
|
|
$this->assign("id",$dbres['id']);
|
|
$this->display();
|
|
|
|
}
|
|
public function delCpStatement()
|
|
{
|
|
if(!isset($_REQUEST['id'])) $this->error("参数错误");
|
|
$id = $_REQUEST['id'];
|
|
$res = M("statement","tab_")->where("id = '{$id}'")->delete();
|
|
if($res !== false){
|
|
$this->ajaxReturn(array("success"=>"ok","code"=>0));
|
|
}else{
|
|
$this->ajaxReturn(array("error"=>"database error","code"=>2000));
|
|
}
|
|
}
|
|
//获取推广公司基础信息
|
|
public function getCpCompanyInfo()
|
|
{
|
|
$CompanyId = $_REQUEST['company_id'];
|
|
if($CompanyId == 0){
|
|
$mycompany = M("tool","tab_")->field("config")->where("name='company_info'")->find();
|
|
$info = json_decode($mycompany['config'],true);
|
|
$info['id'] = 0;
|
|
unset($info['status']);
|
|
}else{
|
|
$info = M("partner","tab_")->field("id,partner,link_man,link_phone,address,company_tax_no,payee_name,bank_account,opening_bank")->where("id = '{$CompanyId}'")->find();
|
|
}
|
|
if(empty($info)){
|
|
$this->ajaxReturn(array("error"=>"no find","code"=>2000));
|
|
}else{
|
|
$this->ajaxReturn(array("success"=>$info,"code"=>0));
|
|
}
|
|
|
|
}
|
|
//按时间-公司id-获取订单及分成比例
|
|
public function getSpendStatement()
|
|
{
|
|
$map["pay_status"] = 1;
|
|
|
|
$CompanyId = $_REQUEST['company_id']; //对账公司id
|
|
$statement_type = $_REQUEST['statement_type'];
|
|
|
|
$is_month = false;//是否是月结判断,非月结无需梯度计算
|
|
if (isset($_REQUEST['time_start']) && isset($_REQUEST['time_end'])) {
|
|
//判断是否是月结
|
|
$tm = explode('-',$_REQUEST['time_start']);
|
|
$en = mktime(0,0,0,$tm[1]-0+1,1,$tm[0])-1; //当月最后一天时间戳
|
|
$en2 = strtotime($_REQUEST['time_end']) + 86399; //上传的订单时间
|
|
if($tm[2] == 1 && $en == $en2){
|
|
$is_month = true;
|
|
}
|
|
$map['pay_time'] = ['between', [strtotime($_REQUEST['time_start']), strtotime($_REQUEST['time_end']) + 86399]];
|
|
}
|
|
//判断是否有重叠时间
|
|
$Statement = M("statement","tab_");
|
|
$repart =false;
|
|
$errorstr = '';
|
|
//开始时间被重叠部分
|
|
$checkmap = array(
|
|
"statement_begin_time"=>array("ELT",strtotime($_REQUEST['time_start'])),
|
|
"statement_end_time"=>array("EGT",strtotime($_REQUEST['time_start'])),
|
|
"company_id"=>$CompanyId
|
|
);
|
|
$bres = $Statement->field("id,statement_begin_time,statement_end_time")->where($checkmap)->find();
|
|
if($bres){
|
|
$repart=true;
|
|
$begin = $_REQUEST['time_start'];
|
|
//统计相交时间
|
|
if(strtotime($_REQUEST['time_end']) > $bres["statement_end_time"]){
|
|
$end = date("Y-m-d",$bres["statement_end_time"]);
|
|
}else{
|
|
$end = $_REQUEST['time_end'];
|
|
}
|
|
$errorstr .= ($begin."到".$end."期间的数据已经结算过<br/>");
|
|
}
|
|
//结束被重复的部分
|
|
$checkmap = array(
|
|
"statement_begin_time"=>array("ELT",strtotime($_REQUEST['time_end'])),
|
|
"statement_end_time"=>array("EGT",strtotime($_REQUEST['time_end'])),
|
|
"company_id"=>$CompanyId
|
|
);
|
|
if($repart){
|
|
$checkmap["id"]=array("NEQ",$bres["id"]);
|
|
}
|
|
$bres = $Statement->field("statement_begin_time,statement_end_time")->where($checkmap)->find();
|
|
if($bres){
|
|
$repart=true;
|
|
$begin = date("Y-m-d",$bres["statement_begin_time"]);
|
|
//统计相交时间
|
|
$end = $_REQUEST['time_end'];
|
|
$errorstr .= ($begin."到".$end."期间的数据已经结算过<br/>");
|
|
}
|
|
if($repart){
|
|
$this->ajaxReturn(array("error"=>$errorstr,"code"=>2001));
|
|
}
|
|
|
|
//获取对应cp公司的游戏
|
|
$game_list = M("game","tab_")->field("id")->where("partner_id = '{$CompanyId}'")->select();
|
|
if($game_list){
|
|
$map['game_id'] = ['in', implode(',', array_column($game_list,'id'))];
|
|
}
|
|
//获取统计
|
|
$list = M("Spend","tab_")->field('sum(pay_amount) pay_amount,game_id,game_name')->where($map)->group('game_id')->select();
|
|
$CpGameRatio = M("CpGameRatio","tab_");
|
|
$countarr = array(
|
|
"pay_amount"=>0,
|
|
"sum_money"=>0
|
|
);
|
|
foreach($list as $k=>&$v){
|
|
$map = array(
|
|
"game_id"=>$v['game_id'],
|
|
"begin_total_amount"=>0,
|
|
);
|
|
// if($is_month){
|
|
// $map['begin_total_amount'] = array("ELT",$v['pay_amount']);
|
|
// };
|
|
// $ratiores = $CpGameRatio->where($map)->order("begin_total_amount desc")->limit(1)->select();
|
|
// if(empty($ratiores)){
|
|
// $redio = 0;
|
|
// }else{
|
|
// $redio = $ratiores[0]['ratio'];
|
|
// }
|
|
$redio = getGameCpRadio($v['game_id'],$v['pay_amount'],$is_month);//获取分成比例
|
|
$v['second_ratio'] = $redio;
|
|
$v['first_ratio'] = (100-$redio);
|
|
if($statement_type == 0){
|
|
$v['sum_money'] = round($v['pay_amount']*$v['first_ratio']/100,2);
|
|
}else{
|
|
$v['sum_money'] = round($v['pay_amount']*$v['second_ratio']/100,2);
|
|
}
|
|
|
|
$countarr['pay_amount'] += $v['pay_amount'];
|
|
$countarr['sum_money'] += $v['sum_money'];
|
|
$v['fax_ratio'] = 0;
|
|
$v['promote_ratio'] = 0;
|
|
$v['statement_begin_time']=$_REQUEST['time_start'];
|
|
$v['statement_end_time']=$_REQUEST['time_end'];
|
|
$v['statement_type']=0;
|
|
}
|
|
$countarr['pay_amount'] = round($countarr['pay_amount'],2);
|
|
$countarr['sum_money'] = round($countarr['sum_money'],2);
|
|
|
|
$this->ajaxReturn(array("success"=>$list,"count"=>$countarr,"code"=>0));
|
|
|
|
}
|
|
//添加数据
|
|
public function doAddCpStatement($id = 0){
|
|
$second_party_info = $_REQUEST['second_party_info'];
|
|
$statement_info = $_REQUEST['statement_info'];
|
|
$statement_info[] = array(
|
|
"sum_money"=>$_REQUEST['fine'],
|
|
"type_name"=>"罚款",
|
|
"statement_type"=>1
|
|
);
|
|
//拼凑数据
|
|
$adddata = array(
|
|
"statement_type"=>0,
|
|
"company_id"=>$second_party_info['id'],
|
|
"company_name"=>$second_party_info['partner'],
|
|
"link_phone"=>$second_party_info['link_phone'],
|
|
"statement_begin_time"=>strtotime($_REQUEST['statement_begin_time']),
|
|
"statement_end_time"=>strtotime($_REQUEST['statement_end_time']),
|
|
'create_time'=>time(),
|
|
"statement_money"=>$_REQUEST['statement_count']['sum_money'],
|
|
"pay_amount"=>$_REQUEST['statement_count']['pay_amount'],
|
|
"is_confirm"=>0,
|
|
"pay_type"=>$_REQUEST['statement_type'] == 0 ? 1 :0,
|
|
"first_party_info"=>json_encode($_REQUEST['first_party_info'],JSON_UNESCAPED_UNICODE),
|
|
"second_party_info"=>json_encode($_REQUEST['second_party_info'],JSON_UNESCAPED_UNICODE),
|
|
"statement_info"=>json_encode($statement_info,JSON_UNESCAPED_UNICODE)
|
|
);
|
|
if($id == 0){
|
|
$res = M("statement","tab_")->add($adddata);
|
|
}else{
|
|
$res = M("statement","tab_")->where("id = '{$id}'")->save($adddata);
|
|
}
|
|
if($res !== false){
|
|
$this->ajaxReturn(array("success"=>"ok","code"=>0));
|
|
}else{
|
|
$this->ajaxReturn(array("error"=>"database error","code"=>2000));
|
|
}
|
|
|
|
|
|
}
|
|
}
|