0, "partner" => "海南万盟天下科技有限公司", "link_man" => "雷丽华", "link_phone" => "13067391751", "address" => "福建省福州市鼓楼区福大怡山创业园区11号103", "company_tax_no" => "1243245", "payee_name" => "雷丽华", "bank_account" => "1654654564364635456", "opening_bank" => "福州市福大分行" ); //创建 public function createCpStatement() { $this->display(); //获取cp推广公司 } //获取推广公司基础信息 public function getCpCompanyInfo() { $CompanyId = $_REQUEST['company_id']; if($CompanyId == 0){ $info = $this->mycompany; }else{ $info = M("partner","tab_")->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]]; } //获取对应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']; } $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(){ $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) ); $res = M("statement","tab_")->add($adddata); if($res){ $this->ajaxReturn(array("success"=>"ok","code"=>0)); }else{ $this->ajaxReturn(array("error"=>"database error","code"=>2000)); } } //测试数据 public function testData() { $mycompany = array( "id" => 0, "partner" => "甲方海南万盟天下科技有限公司", "link_man" => "雷丽华", "link_phone" => "13067391751", "address" => "福建省福州市鼓楼区福大怡山创业园区11号103", "company_tax_no" => "1243245", "payee_name" => "雷丽华", "bank_account" => "1423134654531321564561636", "opening_bank" => "福州市福大分行" ); $cpcompany = array( "id" => 1, "partner" => "乙方海南万盟天下科技有限公司", "link_man" => "乙方雷丽华", "link_phone" => "13067391752", "address" => "福建省福州市鼓楼区福大怡山创业园区11号103", "company_tax_no" => "1243245445646", "payee_name" => "乙方王大锤", "bank_account" => "2343254353462332423", "opening_bank" => "福州市鼓楼区分行" ); $statement =array( array( "pay_amount"=>10000, "game_id"=>77, "game_name"=>"帝王的纷争(安卓版)", "second_ratio"=>40, "first_ratio"=>60, "promote_ratio"=>1, "fax_ratio"=>1, "sum_money"=>5880.6, "statement_begin_time"=>"2019-11-01", "statement_end_time"=>"2019-11-30", "statement_type"=>0 ), array( "sum_money"=>2000, "type_name"=>"罚款", "statement_type"=>1 ) ); $arr = array( "statement_type"=>0, "company_id"=>3, "company_name"=>'福州品象网络科技有限公司', "link_phone"=>'18959188422', "statement_begin_time"=>'1572537600', "statement_end_time"=>'1575129599', 'create_time'=>'1578397556', "statement_money"=>3880.6, "is_confirm"=>0, "pay_type"=>0, "first_party_info"=>json_encode($mycompany,JSON_UNESCAPED_UNICODE), "second_party_info"=>json_encode($cpcompany,JSON_UNESCAPED_UNICODE), "statement_info"=>json_encode($statement,JSON_UNESCAPED_UNICODE) ); $res = M("statement","tab_")->add($arr); dd($res); } }