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.

197 lines
8.5 KiB
PHP

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<?php
// 公司关系绑定
namespace Admin\Controller;
class GameMarginController extends AdminController
{
public $DBModel;
public function _initialize()
{
$this->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();
$this->marginCount($info);
$this->assign("year", $info['count_year']);
$this->assign("month", $info['count_month']);
$this->assign("id", $id);
$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);
}
/**
* 编辑
*/
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"=>'任务添加失败']);
}
}
}