diff --git a/Application/Admin/Controller/GameMarginSetController.class.php b/Application/Admin/Controller/GameMarginSetController.class.php index e0fc6cd57..02729dfa4 100644 --- a/Application/Admin/Controller/GameMarginSetController.class.php +++ b/Application/Admin/Controller/GameMarginSetController.class.php @@ -23,6 +23,8 @@ class GameMarginSetController extends Controller { */ public function setFreeMonth($count_date) { + //设置转换精度 + ini_set('serialize_precision',14); $month = $count_date; if(empty($month)) die("参数错误"); @@ -44,16 +46,15 @@ class GameMarginSetController extends Controller { */ private function reCount() { - // $recount = I("recount"); - // if(empty($recount) || $recount != 1){return ;} - // # code... - // //清理之前的聚合 - // $temp =array( - // "count_year"=>$this->year, - // "count_month"=>$this->month - // ); - // $this->FinancialSummaryModel->where($temp)->delete(); - // echo "重置成功执行重新生成:"; + $recount = I("recount"); + if(empty($recount) || $recount != 1){return ;} + //清理之前的聚合 + $temp =array( + "count_year"=>$this->year, + "count_month"=>$this->month + ); + M("GameMargin","tab_")->where($temp)->delete(); + echo "旧数据清理成功".PHP_EOL; } private function setGameMargin() @@ -64,7 +65,8 @@ class GameMarginSetController extends Controller { $this->getJuheStatement(); $this->getPuStatement(); $this->getPcStatement(); - dd($this->adddata); + $this->setMarginCount(); + echo "{$this->year}-{$this->month}生成成功".PHP_EOL; } /** * 内部公司 @@ -351,6 +353,7 @@ class GameMarginSetController extends Controller { }else{ $this->adddata[$game]['cp_statement_amount'] = $statement_money; } + $this->adddata[$game]['cp_promote_ratio'] = $val['promote_ratio']; } } } @@ -400,5 +403,79 @@ class GameMarginSetController extends Controller { } } } + //相关属性计算 + private function setMarginCount() + { + $baseCell = [ + "jh_pay_amount"=>0, + "jh_statement_amount"=>0, + "jh_ratio"=>0, + "jh_margin_amount"=>0, + "jh_margin_ratio"=>0, + + "pu_pay_amount"=>0, + "pu_statement_amount"=>0, + "pu_ratio"=>0, + "pu_margin_amount"=>0, + "pu_margin_ratio"=>0, + + "pc_pay_amount"=>0, + "pc_statement_amount"=>0, + "pc_ratio"=>0, + "pc_margin_amount"=>0, + "pc_margin_ratio"=>0, + + "pay_amount"=>0, + "cp_statement_amount"=>0, + "cp_promote_ratio"=>0, + "cp_rebate_ratio"=>0, + "cp_rebate_amount"=>0, + "cp_other_amount"=>0, + ]; + $margin_amount = 0; + + $pay_amount = 0; + foreach ($this->adddata as &$v) { + foreach ($baseCell as $bkey=>$bval) array_key_exists($bkey,$v) ?: $v[$bkey] = $bval; + $v["cp_ratio"] = round($v["cp_statement_amount"]/$v['pay_amount'],4)*100; + + if($v["pc_pay_amount"] > 0){ + $v["pc_ratio"] = round($v["pc_statement_amount"]/$v['pc_pay_amount'],4)*100; + $v["pc_margin_amount"] = round($v["pc_pay_amount"]*(1-$v['cp_promote_ratio']/100)*(100-$v["cp_ratio"]-$v['cp_rebate_ratio']-$v["pc_ratio"])/100,2); + $v["pc_margin_ratio"] = round($v["pc_margin_amount"]/$v['pc_pay_amount'],4)*100; + } + if ($v["pu_pay_amount"] > 0) { + $v["pu_ratio"] = round($v["pu_statement_amount"]/$v['pu_pay_amount'],4)*100; + $v["pu_margin_amount"] = round($v["pu_pay_amount"]-$v["pu_pay_amount"]*(1-$v['cp_promote_ratio']/100)*($v["cp_ratio"]+$v['cp_rebate_ratio'])/100-$v["pu_statement_amount"],2); + $v["pu_margin_ratio"] = round($v["pu_margin_amount"]/$v['pu_pay_amount'],4)*100; + } + + $v['platform_margin_ratio'] = round(($v['pay_amount']-$v['jh_pay_amount']-$v['cp_statement_amount']-$v['cp_rebate_amount']-$v['cp_other_amount']-$v['pc_statement_amount']-$v['pu_statement_amount'])/($v['pay_amount']-$v['jh_pay_amount']),4)*100; + + if($v['jh_pay_amount'] > 0){ + $v["jh_ratio"] = round($v["jh_statement_amount"]/$v['jh_pay_amount'],4)*100; + $v["jh_margin_amount"] = round( $v["jh_statement_amount"]-$v["jh_pay_amount"]*(1-$v['cp_promote_ratio']/100)*($v["cp_ratio"]+$v['cp_rebate_ratio'])/100 ,2); + $v["jh_margin_ratio"] = round($v["jh_margin_amount"]/$v['jh_pay_amount'],4)*100; + } + + $v['margin_amount'] = round( ($v['pay_amount']-$v['cp_statement_amount']-$v['cp_rebate_amount']-$v['cp_other_amount']-$v['pc_statement_amount']-$v['pu_statement_amount']+$v['jh_statement_amount']),2); + $v['margin_ratio'] = round($v['margin_amount']/$v['pay_amount'],4)*100; + + $pay_amount += $v['pay_amount']; + $margin_amount += $v['margin_amount']; + } + $margin_ratio = round( $margin_amount/$pay_amount ,4)*100; + //保存数据库 + $adddata = [ + "margin_ratio"=>$margin_ratio, + "margin_amount"=>$margin_amount, + "pay_amount"=>$pay_amount, + "margin_info"=>json_encode(array_values($this->adddata),JSON_UNESCAPED_UNICODE), + "count_month"=>$this->month, + "count_year"=>$this->year, + "create_time"=>time() + ]; + M("GameMargin","tab_")->add($adddata); + } }