DBModel = M("game_margin","tab_"); parent::_initialize(); } public function lists() { $params = I('get.'); $page = $params['p'] ? intval($params['p']) : 1; $row = $params['row'] ? intval($params['row']) : 10; $where = [ "_string"=>"1=1" ]; if(array_key_exists('count_date',$params)){ $m = explode("-",$params['count_date']); $where['count_year']=$m[0]; $where['count_month']=$m[1]; } $data = $this->DBModel->where($where)->field("margin_info",true)->order("count_year desc,count_month desc")->page($page,$row)->select(); // dd($data); $count = $this->DBModel->where($where)->count(); $page = set_pagination($count,$row); if($page) {$this->assign('_page', $page);} $this->assign("data",$data); $this->assign("isCanRecount",D("CmdTasks")->isCanAddTask("GameMargin")); $this->display(); } //查看毛利表 public function marginView(){ if(!isset($_REQUEST['id'])){ $this->error('参数错误'); } $id = $_REQUEST['id']; $info = $this->DBModel->where("id = '{$id}'")->find(); if (isset($_REQUEST['export']) && $_REQUEST['export']==1){ $is_export = true; $this->export($info); $this->assign("percent",''); }else{ $is_export= false; $this->marginCount($info); $this->assign("percent",'%'); } $this->assign("year", $info['count_year']); $this->assign("month", $info['count_month']); $this->assign("id", $id); $this->assign("is_export",$is_export); $this->display(); } private function marginCount($info) { $marginInfo = json_decode($info['margin_info'],true); $count = [ "pay_amount"=>$info['pay_amount'], "margin_ratio"=>$info['margin_ratio'], "margin_amount"=>$info['margin_amount'], "cp_statement_amount"=>0, "cp_ratio"=>0, "cp_rebate_amount"=>0, "cp_other_amount"=>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, "platform_margin_ratio"=>0, "jh_pay_amount"=>0, "jh_statement_amount"=>0, "jh_ratio"=>0, "jh_margin_amount"=>0, "jh_margin_ratio"=>0, ]; foreach ($marginInfo as $v) { $count['cp_statement_amount'] += $v['cp_statement_amount']; $count['cp_rebate_amount'] += $v['cp_rebate_amount']; $count['cp_other_amount'] += $v['cp_other_amount']; $count['pu_pay_amount'] += $v['pu_pay_amount']; $count['pu_statement_amount'] += $v['pu_statement_amount']; $count['pu_margin_amount'] += $v['pu_margin_amount']; $count['pc_pay_amount'] += $v['pc_pay_amount']; $count['pc_statement_amount'] += $v['pc_statement_amount']; $count['pc_margin_amount'] += $v['pc_margin_amount']; $count['jh_pay_amount'] += $v['jh_pay_amount']; $count['jh_statement_amount'] += $v['jh_statement_amount']; $count['jh_margin_amount'] += $v['jh_margin_amount']; } $count['cp_ratio'] = round( $count['cp_statement_amount']/$count['pay_amount'] ,4)*100; $count['pu_ratio'] = round( $count['pu_statement_amount']/$count['pu_pay_amount'] ,4)*100; $count['pu_margin_ratio'] = round( $count['pu_margin_amount']/$count['pu_pay_amount'] ,4)*100; $count['pc_ratio'] = round( $count['pc_statement_amount']/$count['pc_pay_amount'] ,4)*100; $count['pc_margin_ratio'] = round( $count['pc_margin_amount']/$count['pc_pay_amount'] ,4)*100; $count['platform_margin_ratio'] = round(($count['pay_amount']-$count['jh_pay_amount']-$count['cp_statement_amount']-$count['cp_rebate_amount']-$count['cp_other_amount']-$count['pc_statement_amount']-$count['pu_statement_amount'])/($count['pay_amount']-$count['jh_pay_amount']),4)*100; $count['jh_ratio'] = round( $count['jh_statement_amount']/$count['jh_pay_amount'] ,4)*100; $count['jh_margin_ratio'] = round( $count['jh_margin_amount']/$count['jh_pay_amount'] ,4)*100; // dd($count); $this->assign("data",$marginInfo); $this->assign("count",$count); } private function export($info) { $marginInfo = json_decode($info['margin_info'],true); $line = 3; foreach ($marginInfo as &$v) { $v["cp_ratio"] = "=ROUND(G{$line}/D{$line},4)"; if($v["pc_pay_amount"] > 0){ $v["pc_ratio"] ="=ROUND(M{$line}/K{$line},4)"; $v["pc_margin_amount"] = "=ROUND((K{$line}*(1-E{$line})*(1-F{$line}-H{$line}-L{$line})),2)"; $v["pc_margin_ratio"] ="=ROUND(N{$line}/K{$line},4)"; } if ($v["pu_pay_amount"] > 0) { $v["pu_ratio"] ="=ROUND(R{$line}/P{$line},4)"; $v["pu_margin_amount"] = "=ROUND((P{$line}-P{$line}*(1-E{$line})*(F{$line}+H{$line})-R{$line}),2)"; $v["pu_margin_ratio"] = "=ROUND(S{$line}/P{$line},4)"; } $v['platform_margin_ratio'] = "=ROUND((D{$line}-V{$line}-G{$line}-I{$line}-J{$line}-M{$line}-R{$line})/(D{$line}-V{$line}),4)"; if($v['jh_pay_amount'] > 0){ $v["jh_ratio"] ="=ROUND(X{$line}/V{$line},4)"; $v["jh_margin_amount"] = "=ROUND((X{$line}-V{$line}*(1-E{$line})*(F{$line}+H{$line})),2)"; $v["jh_margin_ratio"] = "=ROUND(Y{$line}/V{$line},4)"; } $v['margin_amount'] = "=ROUND((D{$line}-G{$line}-I{$line}-J{$line}-M{$line}-R{$line}+X{$line}),2)"; $v['margin_ratio'] = "=ROUND(AB{$line}/D{$line},4)"; $line ++; } $countLine = $line; $line--; $count = [ "pay_amount"=>"=SUM(D3:D{$line})", "cp_ratio"=>"=ROUND(G{$countLine}/D{$countLine},4)", "cp_statement_amount"=>"=SUM(G3:G{$line})", "cp_rebate_amount"=>"=SUM(I3:I{$line})", "cp_other_amount"=>"=SUM(J3:J{$line})", "pc_pay_amount"=>"=SUM(K3:K{$line})", "pc_ratio"=>"=ROUND(M{$countLine}/K{$countLine},4)", "pc_statement_amount"=>"=SUM(M3:M{$line})", "pc_margin_amount"=>"=SUM(N3:N{$line})", "pc_margin_ratio"=>"=ROUND(N{$countLine}/K{$countLine},4)", "pu_pay_amount"=>"=SUM(P3:P{$line})", "pu_statement_amount"=>"=SUM(R3:R{$line})", "pu_ratio"=>"=ROUND(R{$countLine}/P{$countLine},4)", "pu_margin_amount"=>"=SUM(S3:S{$line})", "pu_margin_ratio"=>"=ROUND(S{$countLine}/P{$countLine},4)", "platform_margin_ratio"=>"=ROUND((D{$countLine}-V{$countLine}-G{$countLine}-I{$countLine}-J{$countLine}-M{$countLine}-R{$countLine})/(D{$countLine}-V{$countLine}),4)", "jh_pay_amount"=>"=SUM(V3:V{$line})", "jh_statement_amount"=>"=SUM(X3:X{$line})", "jh_ratio"=>"=ROUND(X{$countLine}/V{$countLine},4)", "jh_margin_amount"=>"=SUM(Y3:Y{$line})", "jh_margin_ratio"=>"=ROUND(Y{$countLine}/V{$countLine},4)", "margin_ratio"=>"=ROUND(AB{$countLine}/D{$countLine},4)", "margin_amount"=>"=SUM(AB3:AB{$line})", ]; $this->assign("data",$marginInfo); $this->assign("count",$count); $this->assign("title","{$info['count_year']}-{$info['count_month']}毛利分析表"); } /** * 编辑 */ public function marginEdit(){ ini_set('serialize_precision',14); if(!isset($_REQUEST['id'])){ $this->error('参数错误'); } $params = I("post."); $data = $this->DBModel->where("id='{$params['id']}'")->find(); $marginInfo = json_decode($data['margin_info'],true); $item = &$marginInfo[$params['key']]; $item['cp_rebate_ratio'] = $params['cp_rebate_ratio']; $item['cp_rebate_amount'] = $params['cp_rebate_amount']; $item['cp_other_amount'] = $params['cp_other_amount']; if($item["pc_pay_amount"] > 0){ $item["pc_margin_amount"] = round($item["pc_pay_amount"]*(1-$item['cp_promote_ratio']/100)*(100-$item["cp_ratio"]-$item['cp_rebate_ratio']-$item["pc_ratio"])/100,2); $item["pc_margin_ratio"] = round($item["pc_margin_amount"]/$item['pc_pay_amount'],4)*100; } if ($item["pu_pay_amount"] > 0) { $item["pu_margin_amount"] = round($item["pu_pay_amount"]-$item["pu_pay_amount"]*(1-$item['cp_promote_ratio']/100)*($item["cp_ratio"]+$item['cp_rebate_ratio'])/100-$item["pu_statement_amount"],2); $item["pu_margin_ratio"] = round($item["pu_margin_amount"]/$item['pu_pay_amount'],4)*100; } $item['platform_margin_ratio'] = round(($item['pay_amount']-$item['jh_pay_amount']-$item['cp_statement_amount']-$item['cp_rebate_amount']-$item['cp_other_amount']-$item['pc_statement_amount']-$item['pu_statement_amount'])/($item['pay_amount']-$item['jh_pay_amount']),4)*100; if($item['jh_pay_amount'] > 0){ $item["jh_margin_amount"] = round( $item["jh_statement_amount"]-$item["jh_pay_amount"]*(1-$item['cp_promote_ratio']/100)*($item["cp_ratio"]+$item['cp_rebate_ratio'])/100 ,2); $item["jh_margin_ratio"] = round($item["jh_margin_amount"]/$item['jh_pay_amount'],4)*100; } $item['margin_amount'] = round( ($item['pay_amount']-$item['cp_statement_amount']-$item['cp_rebate_amount']-$item['cp_other_amount']-$item['pc_statement_amount']-$item['pu_statement_amount']+$item['jh_statement_amount']),2); $item['margin_ratio'] = round($item['margin_amount']/$item['pay_amount'],4)*100; $margin_amount = 0; //总计 foreach ($marginInfo as &$v) { $margin_amount += $v['margin_amount']; } $margin_ratio = round( $margin_amount/$data['pay_amount'] ,4)*100; $save = [ "margin_ratio"=>$margin_ratio, "margin_amount"=>$margin_amount, "margin_info"=>json_encode($marginInfo,JSON_UNESCAPED_UNICODE) ]; $this->DBModel->where("id='{$params['id']}'")->save($save); $this->ajaxReturn(['status'=>1,'msg'=>"修改成功,刷新。。。"]); } public function recount() { if(!isset($_REQUEST['type'])) $this->error("参数错误"); $type = $_REQUEST['type']; if($type == "recount"){ if(!isset($_REQUEST['id'])) $this->error("参数错误"); $id = $_REQUEST['id']; $data = $this->DBModel->field("count_year,count_month")->where("id='{$id}'")->find(); $time = $data['count_year']."-".$data['count_month']; $this->DBModel->where("id='{$id}'")->delete(); }elseif($type == "add"){ $time =$_REQUEST['date']; $m = explode("-",$time); $where = []; $where['count_year']=$m[0]; $where['count_month']=$m[1]; $count = $this->DBModel->where($where)->count(); if($count > 0){ $this->ajaxReturn(["status"=>"0","msg"=>"{$time}已经生成报表,请重算即可"]); } } $params = "php ".SUBSITE_INDEX." GameMarginSet/setFreeMonth/recount/1/count_date/{$time}"; $r = D("CmdTasks")->addTask("GameMargin",$params,true); if($r){ $this->ajaxReturn(["status"=>"1",'msg'=>"任务添加成功,大约需等待5分钟后生成"]); }else{ $this->ajaxReturn(["status"=>"0","msg"=>'任务添加失败']); } } }