新增下游渠道比例

master
chenzhi 4 years ago
parent b4c6f4316a
commit 1bc3dab93c

@ -15,6 +15,7 @@ use Think\Controller;
class PromoteCompanyController extends ThinkController
{
private $modelName = 'PromoteCompany';
public $ratio = [];
public function _initialize()
{
$this->admininfo = $_SESSION['onethink_admin']['user_auth'];
@ -196,7 +197,6 @@ class PromoteCompanyController extends ThinkController
$v["company_belong"] = ($v["company_belong"]=="0" ? "内团" : ($v["company_belong"]=="1" ? "外团" : ($v["company_belong"]=="2" ? "外团分发" : '无')));
}
// dd($companyres);
//公司及会长数量统计
@ -205,7 +205,6 @@ class PromoteCompanyController extends ThinkController
$companyallids = implode(',', array_column($companycount, 'id'));
$promotemap['company_id']=["in",$companyallids];
$promotecount = M("Promote","tab_")->where($promotemap)->count();
$this->assign('listData', $companyres);
$this->assign('count', $count);
$this->assign('promotecount', $promotecount);
@ -1140,6 +1139,164 @@ class PromoteCompanyController extends ThinkController
}
return $resarr;
}
/**
* 返回公司的游戏分成比例
*
* @param [type] $company_id
* @param [type] $game_ids
* @param boolean $is_export
* @return void
*/
public function getGamePromoteCompanyRadio($company_id,$game_ids,$is_export = false){
//判断是否有生效
$senddata = [];
//获取cp分成比例
if($is_export){
$CpRadio = $this->getPromoteCompanyCpRadio($game_ids);
}
$endtime = time();
$rwhere = "(end_time = 0 OR end_time >= '{$endtime}') and company_id='{$company_id}' and relation_game_id in ({$game_ids})";
$cgr_res = M("CompanyGameRatio","tab_")->where($rwhere)->select();
//判断哪些游戏为空
$game_arr = array_flip(explode(",",$game_ids));
if(!empty($cgr_res)){
foreach ($cgr_res as $k => $v) {
$t_gid = $v['relation_game_id'];
unset($game_arr[$t_gid]);
$senddata[$t_gid] = ["turnover_ratio"=>$v['turnover_ratio'],"ratio"=>$v['ratio'],"relation_game_id"=>$v['relation_game_id']];
$this->setPromoteRadio($senddata[$t_gid]);
if($is_export){
if(isset($CpRadio[$t_gid])){
$senddata[$t_gid]["cp_ratio"] = $CpRadio[$t_gid];
if( count($CpRadio[$t_gid]) > $senddata[$t_gid]['row'] ){
$senddata[$t_gid]['row'] = count($CpRadio[$t_gid]);
}
}
}
}
}
if(empty($game_arr)){
//结束
}
$diff_ids = implode(",",array_keys($game_arr));
$company_belong = M("PromoteCompany","tab_")->field("company_belong")->where("id='{$company_id}'")->find()['company_belong'];
$mwhere = "company_belong='{$company_belong}' and relation_game_id in ({$diff_ids})";
$m_res = M("GameRatioMould","tab_")->where($mwhere)->select();
if(!empty($m_res)){
foreach ($m_res as $k => $v) {
$t_gid = $v['relation_game_id'];
unset($game_arr[$t_gid]);
$senddata[$t_gid] = ["turnover_ratio"=>$v['turnover_ratio'],"ratio"=>$v['ratio'],"relation_game_id"=>$v['relation_game_id']];
$this->setPromoteRadio($senddata[$t_gid]);
if($is_export){
if(isset($CpRadio[$t_gid])){
$senddata[$t_gid]["cp_ratio"] = $CpRadio[$t_gid];
if( count($CpRadio[$t_gid]) > $senddata[$t_gid]['row'] ){
$senddata[$t_gid]['row'] = count($CpRadio[$t_gid]);
}
}
}
}
}
if(empty($game_arr)){
//结束
}
foreach($game_arr as $k=>$v){
$senddata[$k]= ["turnover_ratio"=>'[]',"ratio"=>0,"relation_game_id"=>$k,"cp_ratio"=>'[]',"row"=>1];
}
// dd($senddata);
$this->getPromoteGameRadio($company_id,$senddata);
}
protected function getPromoteGameRadio($company_id,$ratio){
//获取会长信息
$rdata = [];
$promotemap['company_id']=$company_id;
$promotemap['level'] = 1;
$promoteres = M("Promote","tab_")
->field("id,company_id,account,game_ids")
->where($promotemap)
->select();
if(empty($promoteres)){
//结束
}
foreach ($promoteres as $k => &$v) {
$v['list'] = [];
$game_arr = array_flip(explode(",",$v['game_ids']));
foreach($game_arr as $ke=>$va){
if(isset($ratio[$ke])){
$v['list'][] = $ratio[$ke];
}
}
$rdata[] = $v;
}
dd($rdata);
}
//获取cp分成比例
protected function getPromoteCompanyCpRadio($game_ids)
{
$cp_game_ratio_map['game_id'] = ["in", $game_ids];
$cp_game_ratio_map['is_del'] = '0';
$gameradiores = M("cp_game_ratio","tab_")
->alias("cg")
->field("cg.ratio,cg.instanceof,cg.game_id,cg.begin_total_amount")
->where($cp_game_ratio_map)
->group('game_id,begin_total_amount')
->order("begin_total_amount asc")
->select();
$parseGameRadiores = array();//合作方分成比例
foreach ($gameradiores as $key =>$val) {
$val['row'] = 1;
if ($val['begin_total_amount'] == 0) {
$val['name'] = '默认比例';
if (isset($parseGameRadiores[$val['game_id']])) {
$parseGameRadiores[$val['game_id']] = [];
}
} else {
if($val['instanceof']=='1'){
$val['name']="月流水≥".$val['begin_total_amount'];
}else{
$val['name']="月流水>".$val['begin_total_amount'];
}
}
$parseGameRadiores[$val['game_id']][] =['name'=>$val['name'],"ratio"=>$val['ratio']];
}
return $parseGameRadiores;
}
//设置比例阶梯
protected function setPromoteRadio(&$v){
$turnover_ratio = json_decode($v['turnover_ratio'],true);
$v['turnover_ratio'] = array(
array("ratio"=>$v['ratio']."%","name"=>"默认比例")
);
foreach($turnover_ratio as $ke=>$va){
$t=array("ratio"=>$va["ratio"]."%");
if(array_key_exists("instanceof",$va)){
//存在
if($va['instanceof']=='1'){
$t['name']="月流水≥".$va['turnover'];
}else{
$t['name']="月流水>".$va['turnover'];
}
}else{
$t['name']="月流水≥".$va['turnover'];
}
$v['turnover_ratio'][]=$t;
}
$v['row'] = count($v['turnover_ratio']);
}
}

Loading…
Cancel
Save