|
|
<?php
|
|
|
// 游戏默认分成比例模板
|
|
|
namespace Admin\Controller;
|
|
|
|
|
|
class CompanyGameRatioController extends AdminController
|
|
|
{
|
|
|
public $admininfo;
|
|
|
public $DBModel;
|
|
|
public $MarketEvent;
|
|
|
public $OpAuthList=[];
|
|
|
public $Status = [
|
|
|
"-2"=>"管理员拒绝",
|
|
|
"-1"=>"市场部拒绝",
|
|
|
"0"=>"待审核",
|
|
|
"1"=>"市场部通过",
|
|
|
"2"=>"管理员通过"
|
|
|
];
|
|
|
public $SettlementType=[
|
|
|
"-1"=>"未设定",
|
|
|
"0"=>"无",
|
|
|
"1"=>"周结",
|
|
|
"2"=>"月结"
|
|
|
];
|
|
|
public function _initialize()
|
|
|
{
|
|
|
$this->admininfo = $_SESSION['onethink_admin']['user_auth'];
|
|
|
$this->DBModel = M("company_game_ratio","tab_");
|
|
|
$this->MarketEvent = A("Market","Event");
|
|
|
parent::_initialize();
|
|
|
}
|
|
|
|
|
|
public function setCompanyBelong($company_belong = 0) {
|
|
|
if($company_belong == '0') {
|
|
|
return '内团';
|
|
|
} elseif($company_belong == '1') {
|
|
|
return '外团';
|
|
|
} else {
|
|
|
return '外团-分发';
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public function index()
|
|
|
{
|
|
|
$params = I('get.');
|
|
|
$page = $params['p'] ? intval($params['p']) : 1;
|
|
|
$row = $params['row'] ? intval($params['row']) : 10;
|
|
|
//权限分配
|
|
|
if(!IS_ROOT){
|
|
|
$this->OpAuthList= getModuleControllerAuth();
|
|
|
}
|
|
|
|
|
|
$gamewhere['_string'] = '1 = 1';
|
|
|
$where['_string'] = '1 = 1';
|
|
|
if(isset($params['relation_game_id'])){
|
|
|
$gamewhere['relation_game_id'] = $params['relation_game_id'];
|
|
|
$where['m.relation_game_id'] = $params['relation_game_id'];
|
|
|
}
|
|
|
$pwhere = false;
|
|
|
// if(isset($params['company_belong'])){
|
|
|
// $pwhere = " and p.company_belong = {$params['company_belong']}";
|
|
|
// }
|
|
|
|
|
|
if(isset($params['company_id'])){
|
|
|
$where['m.company_id'] = $params['company_id'];
|
|
|
}
|
|
|
|
|
|
if(isset($params['game_type'])){
|
|
|
$gamewhere['game_type_id'] = $params['game_type'];
|
|
|
}
|
|
|
|
|
|
if(isset($params['settlement_type'])){
|
|
|
$companyid = $this->returnSettlementTypeCompanyid($params['settlement_type']);
|
|
|
if(empty($companyid)){
|
|
|
$where['_string'] = "m.company_id = -1";
|
|
|
}else{
|
|
|
if($params['settlement_type'] != -1){
|
|
|
$where['_string'] = "m.company_id in ({$companyid})";
|
|
|
}else{
|
|
|
$where['_string'] = "m.company_id NOT IN ({$companyid})";
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
$gid = session('user_group_id');
|
|
|
$markerGroup = $this->MarketEvent->isMarketAdminGroup($gid);
|
|
|
if($markerGroup){
|
|
|
$companyIds = $this->MarketEvent->getAdminCompanyId();
|
|
|
//取消0
|
|
|
$companyIds = implode(",",array_diff(explode(",",$companyIds),[0]));
|
|
|
$marketCondition = 'm.company_id in(' . $companyIds . ')';
|
|
|
if($markerGroup['department_level'] == $this->MarketEvent->getConfig("DirectorLevel")){
|
|
|
//总监
|
|
|
$marketCondition .= " OR (m.company_id = 0 AND m.company_belong != 0 )";
|
|
|
}
|
|
|
$where['_string'] = isset($where['_string']) ? $where['_string'] . ' and ' . $marketCondition : $marketCondition;
|
|
|
}
|
|
|
|
|
|
if (isset($_REQUEST['time_start']) && isset($_REQUEST['time_end'])) {
|
|
|
$time_start = strtotime($_REQUEST['time_start']);
|
|
|
$time_end = strtotime($_REQUEST['time_end'])+ 86399;
|
|
|
$where["_string"] = "(begin_time BETWEEN {$time_start} AND {$time_end}) OR (end_time BETWEEN {$time_start} AND {$time_end}) OR (begin_time <= {$time_end} AND end_time >= {$time_end}) OR (begin_time >0 AND end_time = 0)";
|
|
|
} elseif (isset($_REQUEST['time_start'])) {
|
|
|
$time_start = strtotime($_REQUEST['time_start']);
|
|
|
$where["_string"] = "end_time >= {$time_start} OR end_time = 0";
|
|
|
} elseif (isset($_REQUEST['time_end'])) {
|
|
|
$time_end = strtotime($_REQUEST['time_end'])+ 86399;
|
|
|
$where["_string"] = "begin_time <= {$time_end}";
|
|
|
}
|
|
|
|
|
|
$gameres = M("game","tab_")->field("tab_game.relation_game_id,tab_game.relation_game_name,IF(tab_game.original_package_name='','未配置',tab_game.original_package_name) original_package_name,tab_game_type.type_name game_type_name")->where($gamewhere)->join("tab_game_type on tab_game.game_type_id = tab_game_type.id")->group("tab_game.relation_game_id")->select(false);
|
|
|
|
|
|
$dbres = M("company_game_ratio","tab_")
|
|
|
->alias('m')
|
|
|
->field("g.game_type_name,g.original_package_name,g.relation_game_name,m.company_id,p.company_name,(CASE WHEN p.company_belong is not null THEN p.company_belong ELSE m.company_belong END) company_belong,IFNULL(r.settlement_type,-1) settlement_type,group_concat(turnover_type ORDER BY begin_time ASC SEPARATOR '|') turnover_type,group_concat(ratio ORDER BY begin_time ASC SEPARATOR '|') ratio,group_concat(begin_time ORDER BY begin_time ASC SEPARATOR '|') begin_time,group_concat(end_time ORDER BY begin_time ASC SEPARATOR '|') end_time,group_concat(m.turnover_ratio ORDER BY begin_time ASC SEPARATOR '|') turnover_ratio,group_concat(m.id ORDER BY begin_time ASC SEPARATOR '|') operate_id")
|
|
|
->join("JOIN ({$gameres}) g ON m.relation_game_id = g.relation_game_id")
|
|
|
->join("left JOIN tab_promote_company p ON ( m.company_id = p.id".$pwhere.")")
|
|
|
->join("left JOIN tab_company_relation r ON (r.first_company_type =2 AND r.first_company_id = m.company_id) OR (r.second_company_type =2 AND r.second_company_id = m.company_id)")
|
|
|
->where($where)->group("company_id,m.relation_game_id,p.company_belong")
|
|
|
->select(false);
|
|
|
|
|
|
if(isset($params['company_belong'])){
|
|
|
$secwhere['company_belong'] = $params['company_belong'];
|
|
|
}
|
|
|
|
|
|
$dbres = M()->table("({$dbres})a")
|
|
|
->where("company_id = '0' or company_name is not null")
|
|
|
->where($secwhere);
|
|
|
if(isset($params['export'])){
|
|
|
$dbres = $dbres->select();
|
|
|
}else{
|
|
|
$dbres = $dbres->page($page, $row)->select();
|
|
|
}
|
|
|
// dump($dbres);die();
|
|
|
foreach($dbres as $k=>&$v){
|
|
|
|
|
|
$begin_time = explode('|',$v['begin_time']);
|
|
|
$end_time = explode('|',$v['end_time']);
|
|
|
$turnover_type = explode('|',$v['turnover_type']);
|
|
|
|
|
|
if (!$v['company_name']) {
|
|
|
$v['company_name'] = '无';
|
|
|
}
|
|
|
|
|
|
foreach ($begin_time as $tk => $tv) {
|
|
|
|
|
|
$begintime = date("Y-m-d",$tv);
|
|
|
$endtime = $end_time[$tk] ? date('Y-m-d', $end_time[$tk]) : '永久';
|
|
|
$v["valid"][$tk] = "{$begintime} ~ {$endtime}";
|
|
|
|
|
|
if($turnover_type[$tk] == 0) {
|
|
|
$v["turnover_types"][$tk] = "无";
|
|
|
} elseif($turnover_type[$tk] == 1) {
|
|
|
$v["turnover_types"][$tk] = "月流水";
|
|
|
} elseif($turnover_type[$tk] == 2) {
|
|
|
$v["turnover_types"][$tk] = "历史流水";
|
|
|
} elseif($turnover_type[$tk] == 3) {
|
|
|
$v["turnover_types"][$tk] = "cp月流水";
|
|
|
} elseif($turnover_type[$tk] == 4) {
|
|
|
$v["turnover_types"][$tk] = "cp历史流水";
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
// $v['begin_time'] = date("Y-m-d",$v['begin_time']);
|
|
|
// $v['end_time'] = $v['end_time'] ? date('Y-m-d', $v['end_time']) : '永久';
|
|
|
//
|
|
|
// $v["valid"] = "{$v['begin_time']} ~ {$v['end_time']}";
|
|
|
|
|
|
$v['company_belong'] ="下游".getCompanyBlong($v['company_belong']);
|
|
|
// $v['company_belong'] ="下游".$this->setCompanyBelong($v['company_belong']);
|
|
|
|
|
|
if (isset($params['export'])) {
|
|
|
$symbol = "\n";
|
|
|
} else {
|
|
|
$symbol = "<br>";
|
|
|
}
|
|
|
$v['settlement_type'] = $this->SettlementType[$v['settlement_type']];
|
|
|
$this->readTurnoverRatio($v);
|
|
|
|
|
|
$getId = explode('|',$v['operate_id']);
|
|
|
|
|
|
foreach ($getId as $key => $value) {
|
|
|
$v['oplist'][] = $this->OpAuth(['id'=>$value]);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
$this->assign('data', $dbres);
|
|
|
if(isset($_REQUEST['export'])){
|
|
|
$GetData = $_GET;
|
|
|
unset($GetData['export']);
|
|
|
addOperationLog(['op_type'=>3,'key'=>getNowDate(),"op_name"=>"导出",'url'=>U(CONTROLLER_NAME.'/'.ACTION_NAME,$GetData)]);
|
|
|
$this->display("export");
|
|
|
exit();
|
|
|
}
|
|
|
|
|
|
$count = M("company_game_ratio","tab_")->alias('m')->field("m.company_id,p.company_name,m.id,p.company_belong,m.relation_game_id")
|
|
|
->join("JOIN ({$gameres}) g ON m.relation_game_id = g.relation_game_id")
|
|
|
->join("left JOIN tab_promote_company p ON ( m.company_id = p.id".$pwhere.")")
|
|
|
->where($where)
|
|
|
->group("company_id,m.relation_game_id,m.company_belong")
|
|
|
->select(false);
|
|
|
|
|
|
$count = M()->table("({$count})a")
|
|
|
->where("company_id = '0' or company_name is not null")
|
|
|
->where($secwhere)
|
|
|
->group("company_id,relation_game_id,company_belong")
|
|
|
->select(false);
|
|
|
// dump($count);die();
|
|
|
|
|
|
$count = M()->table("({$count})a")->count();
|
|
|
|
|
|
$page = set_pagination($count, $row,$params);
|
|
|
if($page) {
|
|
|
$this->assign('_page', $page);
|
|
|
}
|
|
|
$this->assign("companyList",D("PromoteCompany")->getList());
|
|
|
$this->assign("gameList",D("Game")->getRelationGameLits());
|
|
|
$this->assign("SettlementType",$this->SettlementType);
|
|
|
$this->display();
|
|
|
}
|
|
|
|
|
|
public function lists()
|
|
|
{
|
|
|
$params = I('get.');
|
|
|
$page = $params['p'] ? intval($params['p']) : 1;
|
|
|
$row = $params['row'] ? intval($params['row']) : 10;
|
|
|
//权限分配
|
|
|
if(!IS_ROOT){
|
|
|
$this->OpAuthList= getModuleControllerAuth();
|
|
|
}
|
|
|
|
|
|
$gamewhere['_string'] = '1 = 1';
|
|
|
$where['_string'] = '1 = 1';
|
|
|
if(isset($params['relation_game_id'])){
|
|
|
$gamewhere['relation_game_id'] = $params['relation_game_id'];
|
|
|
$where['m.relation_game_id'] = $params['relation_game_id'];
|
|
|
}
|
|
|
if(isset($params['status'])){
|
|
|
$where['m.status'] = $params['status'];
|
|
|
}
|
|
|
|
|
|
// $pwhere = false;
|
|
|
// if(isset($params['company_belong'])){
|
|
|
// $pwhere = " and p.company_belong = {$params['company_belong']}";
|
|
|
// }
|
|
|
|
|
|
if(isset($params['company_id'])){
|
|
|
$where['m.company_id'] = $params['company_id'];
|
|
|
}
|
|
|
|
|
|
if(isset($params['game_type'])){
|
|
|
$gamewhere['game_type_id'] = $params['game_type'];
|
|
|
}
|
|
|
|
|
|
if(isset($params['settlement_type'])){
|
|
|
$companyid = $this->returnSettlementTypeCompanyid($params['settlement_type']);
|
|
|
if(empty($companyid)){
|
|
|
$where['_string'] = "m.company_id = -1";
|
|
|
}else{
|
|
|
if($params['settlement_type'] != -1){
|
|
|
$where['_string'] = "m.company_id in ({$companyid})";
|
|
|
}else{
|
|
|
$where['_string'] = "m.company_id NOT IN ({$companyid})";
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
$gid = session('user_group_id');
|
|
|
$markerGroup = $this->MarketEvent->isMarketAdminGroup($gid);
|
|
|
if($markerGroup){
|
|
|
$companyIds = $this->MarketEvent->getAdminCompanyId();
|
|
|
//取消0
|
|
|
$companyIds = implode(",",array_diff(explode(",",$companyIds),[0]));
|
|
|
$marketCondition = 'm.company_id in(' . $companyIds . ')';
|
|
|
if($markerGroup['department_level'] == $this->MarketEvent->getConfig("DirectorLevel")){
|
|
|
//总监
|
|
|
$marketCondition .= " OR (m.company_id = 0 AND m.company_belong != 0 )";
|
|
|
}
|
|
|
$where['_string'] = isset($where['_string']) ? $where['_string'] . ' and ' . $marketCondition : $marketCondition;
|
|
|
}
|
|
|
|
|
|
|
|
|
if (isset($_REQUEST['time_start']) && isset($_REQUEST['time_end'])) {
|
|
|
$time_start = strtotime($_REQUEST['time_start']);
|
|
|
$time_end = strtotime($_REQUEST['time_end'])+ 86399;
|
|
|
$where["_string"] = "(begin_time BETWEEN {$time_start} AND {$time_end}) OR (end_time BETWEEN {$time_start} AND {$time_end}) OR (begin_time <= {$time_end} AND end_time >= {$time_end}) OR (begin_time <{$time_start} AND (end_time >{$time_end} or end_time = 0))";
|
|
|
} elseif (isset($_REQUEST['time_start'])) {
|
|
|
$time_start = strtotime($_REQUEST['time_start']);
|
|
|
$where["_string"] = "end_time >= {$time_start} OR end_time = 0";
|
|
|
} elseif (isset($_REQUEST['time_end'])) {
|
|
|
$time_end = strtotime($_REQUEST['time_end'])+ 86399;
|
|
|
$where["_string"] = "begin_time <= {$time_end}";
|
|
|
}
|
|
|
|
|
|
//TODO:未计算公司类型
|
|
|
// $this->checkListOrCountAuthRestMap($where);
|
|
|
$gameres = M("game","tab_")->field("tab_game.relation_game_id,tab_game.relation_game_name,IF(tab_game.original_package_name='','未配置',tab_game.original_package_name) original_package_name,tab_game_type.type_name game_type_name")->where($gamewhere)->join("tab_game_type on tab_game.game_type_id = tab_game_type.id")->group("tab_game.relation_game_id")->select(false);
|
|
|
$dbres = M("company_game_ratio_log","tab_")
|
|
|
->alias('m')
|
|
|
->field("m.id,m.status,g.game_type_name,g.original_package_name,g.relation_game_name,m.company_id,p.company_name,m.turnover_type,begin_time,end_time,m.turnover_ratio,last_ratio,last_turnover_ratio,m.ratio,verify_log,(CASE WHEN p.company_belong is not null THEN p.company_belong ELSE m.company_belong END) company_belong,IFNULL(r.settlement_type,0) settlement_type")
|
|
|
->join("JOIN ({$gameres}) g ON m.relation_game_id = g.relation_game_id")
|
|
|
->join("left JOIN tab_promote_company p ON ( m.company_id = p.id)")
|
|
|
->join("left JOIN tab_company_relation r ON (r.first_company_type =2 AND r.first_company_id = m.company_id) OR (r.second_company_type =2 AND r.second_company_id = m.company_id)")
|
|
|
->where($where)
|
|
|
->order("FIELD(m.status,0,1,-1,-2,2),m.id desc")
|
|
|
->select(false);
|
|
|
|
|
|
if(isset($params['company_belong'])){
|
|
|
$secwhere['company_belong'] = $params['company_belong'];
|
|
|
}
|
|
|
|
|
|
$dbres = M()->table("({$dbres})a")
|
|
|
->where("company_id = '0' or company_name is not null")
|
|
|
->where($secwhere);
|
|
|
|
|
|
if(isset($params['export'])){
|
|
|
$dbres = $dbres->select();
|
|
|
}else{
|
|
|
$dbres = $dbres->page($page, $row)->select();
|
|
|
}
|
|
|
// dump($dbres);die();
|
|
|
foreach($dbres as $k=>&$v){
|
|
|
$v['settlement_type'] = $this->SettlementType[$v['settlement_type']];
|
|
|
$v['begin_time'] = date("Y-m-d",$v['begin_time']);
|
|
|
$v['end_time'] = $v['end_time'] ? date('Y-m-d', $v['end_time']) : '永久';
|
|
|
|
|
|
if (!$v['company_name']) {
|
|
|
$v['company_name'] = '无';
|
|
|
}
|
|
|
|
|
|
$v["valid"] = "{$v['begin_time']} ~ {$v['end_time']}";
|
|
|
|
|
|
if($v["turnover_type"] == 0) {
|
|
|
$v["turnover_types"] = "无";
|
|
|
} elseif($v["turnover_type"] == 1) {
|
|
|
$v["turnover_types"] = "月流水";
|
|
|
} elseif($v["turnover_type"] == 2) {
|
|
|
$v["turnover_types"] = "历史流水";
|
|
|
} elseif($v["turnover_type"] == 3) {
|
|
|
$v["turnover_types"] = "cp月流水";
|
|
|
} elseif($v["turnover_type"] == 4) {
|
|
|
$v["turnover_types"] = "cp历史流水";
|
|
|
}
|
|
|
|
|
|
|
|
|
$v['company_belong'] ="下游".getCompanyBlong($v['company_belong']);
|
|
|
// $v['company_belong'] ="下游".$this->setCompanyBelong($v['company_belong']);
|
|
|
$v['verify_log'] = json_decode($v['verify_log'], true);
|
|
|
if (isset($params['export'])) {
|
|
|
$symbol = "\n";
|
|
|
} else {
|
|
|
$symbol = "<br>";
|
|
|
}
|
|
|
|
|
|
$v["create"]= "{$v['verify_log']['create_user']} {$symbol} {$v['verify_log']['create_time']}";
|
|
|
if(isset($v['verify_log']['market_user'])){
|
|
|
if($v['status'] == -1){
|
|
|
$ts = "审核拒绝";
|
|
|
}else{
|
|
|
$ts = "审核通过";
|
|
|
}
|
|
|
$v["market"]= "{$ts}({$v['verify_log']['market_user']}) {$symbol} {$v['verify_log']['market_time']}";
|
|
|
}else{
|
|
|
$v["market"] = '--';
|
|
|
}
|
|
|
|
|
|
if(isset($v['verify_log']['admin_user'])){
|
|
|
if($v['status'] == -2){
|
|
|
$ts = "审核拒绝";
|
|
|
}else{
|
|
|
$ts = "审核通过";
|
|
|
}
|
|
|
$v["admin"]= "{$ts}({$v['verify_log']['admin_user']}) {$symbol} {$v['verify_log']['admin_time']}";
|
|
|
}else{
|
|
|
$v["admin"] = '--';
|
|
|
}
|
|
|
//新
|
|
|
$thisTurnoverRatios = $v['turnover_ratio'] ? json_decode($v['turnover_ratio'], true) : [];
|
|
|
$thisRatioDtl = "默认:{$v['ratio']}%";
|
|
|
if ($thisTurnoverRatios) {
|
|
|
|
|
|
foreach ($thisTurnoverRatios as $thisTurnoverRatio) {
|
|
|
$thisIntervalClosedStatusText = isset($thisTurnoverRatio['instanceof']) ? ($thisTurnoverRatio['instanceof'] == 1 ? '≥' : '>') : '≥';
|
|
|
$thisRatioDtl .= "{$symbol}月流水{$thisIntervalClosedStatusText}{$thisTurnoverRatio['turnover']},比例:{$thisTurnoverRatio['ratio']}%";
|
|
|
}
|
|
|
}
|
|
|
$v['turnover_ratio_str'] = $thisRatioDtl;
|
|
|
//旧
|
|
|
$lastTurnoverRatios = $v['last_turnover_ratio'] ? json_decode($v['last_turnover_ratio'], true) : [];
|
|
|
$lastRatioDtl = "默认:{$v['last_ratio']}%";
|
|
|
if ($lastTurnoverRatios) {
|
|
|
foreach ($lastTurnoverRatios as $thisTurnoverRatio) {
|
|
|
$thisIntervalClosedStatusText = isset($thisTurnoverRatio['instanceof']) ? ($thisTurnoverRatio['instanceof'] == 1 ? '≥' : '>') : '≥';
|
|
|
$lastRatioDtl .= "{$symbol}月流水{$thisIntervalClosedStatusText}{$thisTurnoverRatio['turnover']},比例:{$thisTurnoverRatio['ratio']}%";
|
|
|
}
|
|
|
}
|
|
|
$v['last_turnover_ratio_str'] = $lastRatioDtl;
|
|
|
$v['oplist'] = $this->OpAuth($v);
|
|
|
|
|
|
}
|
|
|
|
|
|
if(isset($_REQUEST['export'])){
|
|
|
$GetData = $_GET;
|
|
|
unset($GetData['export']);
|
|
|
addOperationLog(['op_type'=>3,'key'=>getNowDate(),"op_name"=>"导出",'url'=>U(CONTROLLER_NAME.'/'.ACTION_NAME,$GetData)]);
|
|
|
|
|
|
data2csv($dbres,'特殊比例申请管理',array(
|
|
|
"company_name"=>"公司名称",
|
|
|
"company_belong"=>"内外团",
|
|
|
"settlement_type"=>"结算周期",
|
|
|
"game_type_name"=>"游戏类型",
|
|
|
"original_package_name"=>"原游戏名称",
|
|
|
"relation_game_name"=>"现游戏名称",
|
|
|
"valid"=>"生效时间",
|
|
|
"last_turnover_ratio_str"=>"原比例",
|
|
|
"turnover_ratio_str"=>"申请比例",
|
|
|
"create"=>"创建记录",
|
|
|
"market"=>"市场部审批",
|
|
|
"admin"=>"管理员审批",
|
|
|
"remark"=>"备注"
|
|
|
));
|
|
|
}
|
|
|
|
|
|
// $count =M("company_game_ratio_log","tab_")->alias('m')->field("m.id,p.company_belong,m.company_id,p.company_name")
|
|
|
// ->join("JOIN ({$gameres}) g ON m.relation_game_id = g.relation_game_id")
|
|
|
// ->join("left JOIN tab_promote_company p ON ( m.company_id = p.id)")
|
|
|
// ->where($where)
|
|
|
// ->select(false);
|
|
|
|
|
|
$count = M("company_game_ratio_log","tab_")
|
|
|
->alias('m')
|
|
|
->field("m.id,m.company_id,p.company_name,m.turnover_type,(CASE WHEN p.company_belong is not null THEN p.company_belong ELSE m.company_belong END) company_belong")
|
|
|
->join("JOIN ({$gameres}) g ON m.relation_game_id = g.relation_game_id")
|
|
|
->join("left JOIN tab_promote_company p ON ( m.company_id = p.id)")
|
|
|
->join("left JOIN tab_company_relation r ON (r.first_company_type =2 AND r.first_company_id = m.company_id) OR (r.second_company_type =2 AND r.second_company_id = m.company_id)")
|
|
|
->where($where)
|
|
|
->order("FIELD(m.status,0,1,-1,-2,2),m.id desc")
|
|
|
->select(false);
|
|
|
|
|
|
if(isset($params['company_belong'])){
|
|
|
$secwhere['company_belong'] = $params['company_belong'];
|
|
|
}
|
|
|
// die($count);
|
|
|
$count = M()->table("({$count})a")
|
|
|
->field("count(id) count")
|
|
|
->where("company_id = '0' or company_name is not null")
|
|
|
->where($secwhere)
|
|
|
->find()['count'];
|
|
|
|
|
|
$this->assign('data', $dbres);
|
|
|
$page = set_pagination($count, $row,$params);
|
|
|
if($page) {
|
|
|
$this->assign('_page', $page);
|
|
|
}
|
|
|
$this->assign('status',$this->Status);
|
|
|
|
|
|
$this->assign('menubtn',$this->menuAuth());
|
|
|
|
|
|
$this->assign("companyList",D("PromoteCompany")->getList());
|
|
|
$this->assign("gameList",D("Game")->getRelationGameLits());
|
|
|
$this->assign("SettlementType",$this->SettlementType);
|
|
|
$this->display();
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function marketAgree(){
|
|
|
if(!isset($_REQUEST['ids'])) $this->error("参数错误");
|
|
|
$ids = $_REQUEST['ids'];
|
|
|
$company_game_ratio_log = M("company_game_ratio_log","tab_");
|
|
|
$dbres = $company_game_ratio_log->field("id,status,verify_log")->where("id in ({$ids})")->select();
|
|
|
foreach($dbres as $k=>&$v){
|
|
|
if($v['status'] != 0) continue;
|
|
|
$v['verify_log'] = json_decode($v['verify_log'],true);
|
|
|
$v['verify_log']['market_user']=$this->admininfo["username"];
|
|
|
$v['verify_log']['market_time']=date("Y-m-d H:i:s");
|
|
|
$v['verify_log'] = json_encode($v['verify_log']);
|
|
|
$v['status']=1;
|
|
|
$company_game_ratio_log->save($v);
|
|
|
addOperationLog(['op_type'=>1,'key'=>$v['id'],"op_name"=>"市场部审核",'url'=>U('lists')]);
|
|
|
}
|
|
|
$this->ajaxReturn(array(
|
|
|
'status' => 1,
|
|
|
"info"=>"市场部审核通过成功"
|
|
|
));
|
|
|
}
|
|
|
public function marketRefuse(){
|
|
|
if(!isset($_REQUEST['ids'])) $this->error("参数错误");
|
|
|
$ids = $_REQUEST['ids'];
|
|
|
$company_game_ratio_log = M("company_game_ratio_log","tab_");
|
|
|
$dbres = $company_game_ratio_log->field("id,status,verify_log")->where("id in ({$ids})")->select();
|
|
|
foreach($dbres as $k=>&$v){
|
|
|
if($v['status'] != 0) continue;
|
|
|
$v['verify_log'] = json_decode($v['verify_log'],true);
|
|
|
$v['verify_log']['market_user']=$this->admininfo["username"];
|
|
|
$v['verify_log']['market_time']=date("Y-m-d H:i:s");
|
|
|
$v['verify_log'] = json_encode($v['verify_log']);
|
|
|
$v['status']=-1;
|
|
|
$company_game_ratio_log->save($v);
|
|
|
addOperationLog(['op_type'=>1,'key'=>$v['id'],"op_name"=>"市场部审核",'url'=>U('lists')]);
|
|
|
}
|
|
|
$this->ajaxReturn(array(
|
|
|
'status' => 1,
|
|
|
"info"=>"市场部审核拒绝成功"
|
|
|
));
|
|
|
}
|
|
|
public function adminRefuse(){
|
|
|
if(!isset($_REQUEST['ids'])) $this->error("参数错误");
|
|
|
$ids = $_REQUEST['ids'];
|
|
|
$company_game_ratio_log = M("company_game_ratio_log","tab_");
|
|
|
$dbres = $company_game_ratio_log->field("id,status,verify_log")->where("id in ({$ids})")->select();
|
|
|
foreach($dbres as $k=>&$v){
|
|
|
if($v['status'] != 1) continue;
|
|
|
$v['verify_log'] = json_decode($v['verify_log'],true);
|
|
|
$v['verify_log']['admin_user']=$this->admininfo["username"];
|
|
|
$v['verify_log']['admin_time']=date("Y-m-d H:i:s");
|
|
|
$v['verify_log'] = json_encode($v['verify_log']);
|
|
|
$v['status']=-2;
|
|
|
$company_game_ratio_log->save($v);
|
|
|
addOperationLog(['op_type'=>1,'key'=>$v['id'],"op_name"=>"管理员审核",'url'=>U('lists')]);
|
|
|
}
|
|
|
$this->ajaxReturn(array(
|
|
|
'status' => 1,
|
|
|
"info"=>"管理员审核拒绝成功"
|
|
|
));
|
|
|
}
|
|
|
//管理员成功
|
|
|
public function adminAgree(){
|
|
|
if(!isset($_REQUEST['ids'])) $this->error("参数错误");
|
|
|
$ids = $_REQUEST['ids'];
|
|
|
$company_game_ratio_log = M("company_game_ratio_log","tab_");
|
|
|
$company_game_ratio = M("company_game_ratio","tab_");
|
|
|
$dbres = $company_game_ratio_log->field("*")->where("id in ({$ids})")->select();
|
|
|
foreach($dbres as $k=>&$v){
|
|
|
if($v['status'] != 1) continue;
|
|
|
$v['verify_log'] = json_decode($v['verify_log'],true);
|
|
|
$v['verify_log']['admin_user']=$this->admininfo["username"];
|
|
|
$v['verify_log']['admin_time']=date("Y-m-d H:i:s");
|
|
|
$v['verify_log'] = json_encode($v['verify_log']);
|
|
|
$v['status']=2;
|
|
|
$company_game_ratio_log->save($v);
|
|
|
//保存到其他表
|
|
|
//查找是否存在
|
|
|
$ratiov = [
|
|
|
'company_belong'=>$v['company_belong'],
|
|
|
"company_id"=>$v['company_id'],
|
|
|
"relation_game_id"=>$v['relation_game_id'],
|
|
|
"ratio"=>$v['ratio'],
|
|
|
"turnover_ratio"=>$v['turnover_ratio'],
|
|
|
"begin_time"=>$v['begin_time'],
|
|
|
"end_time"=>$v['end_time'],
|
|
|
"turnover_type"=>$v['turnover_type'],
|
|
|
];
|
|
|
|
|
|
$this->companyRatioTimeChange($v['company_belong'],$v['company_id'],$v['relation_game_id'],$v['begin_time'],$v['end_time'],$ratiov);
|
|
|
|
|
|
// $has = $company_game_ratio->where("company_id='{$v['company_id']}' and relation_game_id='{$v['relation_game_id']}' and begin_time={$v['begin_time']} and end_time={$v['end_time']}")->find();
|
|
|
// if(isset($has['id'])){
|
|
|
// $ratiov['id'] = $has['id'];
|
|
|
// $company_game_ratio->save($ratiov);
|
|
|
// }else{
|
|
|
// $company_game_ratio->add($ratiov);
|
|
|
// }
|
|
|
//
|
|
|
addOperationLog(['op_type'=>1,'key'=>$v['id'],"op_name"=>"管理员审核",'url'=>U('lists')]);
|
|
|
}
|
|
|
$this->ajaxReturn(array(
|
|
|
'status' => 1,
|
|
|
"info"=>"管理员审核通过成功"
|
|
|
));
|
|
|
}
|
|
|
|
|
|
public function companyRatioTimeChange($company_belong = 0,$company_id = 0, $relation_game_id = 0, $begin_time = 0, $end_time = 0,$ratiov=[]) {
|
|
|
|
|
|
if (!$relation_game_id) {
|
|
|
$this->error("公司与游戏的参数错误.");
|
|
|
}
|
|
|
// dump($end_time);dump($begin_time);die();
|
|
|
$check_data = M("company_game_ratio","tab_")
|
|
|
->where(['company_id'=>$company_id,'relation_game_id'=>$relation_game_id,'begin_time'=>$begin_time,'end_time'=>$end_time])
|
|
|
->find();
|
|
|
if ($check_data) {
|
|
|
M("company_game_ratio","tab_")
|
|
|
->where(['company_id'=>$company_id,'relation_game_id'=>$relation_game_id,'begin_time'=>$begin_time,'end_time'=>$end_time])
|
|
|
->save($ratiov);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
M("company_game_ratio","tab_")
|
|
|
// ->where(['company_id'=>$company_id,'relation_game_id'=>$relation_game_id,'begin_time'=>['egt',$begin_time],'end_time'=>['elt',$end_time]])
|
|
|
->where("company_id={$company_id} and relation_game_id={$relation_game_id} and begin_time>={$begin_time} and end_time <= {$end_time} and end_time!=0")
|
|
|
->delete();
|
|
|
|
|
|
$data = M("company_game_ratio","tab_")
|
|
|
->where(['company_id'=>$company_id,'relation_game_id'=>$relation_game_id])
|
|
|
->order("begin_time DESC")
|
|
|
->select();
|
|
|
|
|
|
foreach($data as $key => $value) {
|
|
|
|
|
|
if ($value['begin_time'] > $begin_time) {
|
|
|
|
|
|
if (!$end_time) {
|
|
|
M("company_game_ratio","tab_")
|
|
|
->where(['company_id'=>$company_id,'relation_game_id'=>$relation_game_id,'begin_time'=>$value['begin_time'],'end_time'=>$value['end_time']])
|
|
|
->delete();
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
if ($value['begin_time'] >= $end_time && $value['end_time']!=0) {
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
if ($end_time > $value['begin_time'] && ($end_time < $value['end_time']||$value['end_time']==0)) {
|
|
|
M("company_game_ratio","tab_")
|
|
|
->where(['company_id'=>$company_id,'relation_game_id'=>$relation_game_id,'begin_time'=>$value['begin_time'],'end_time'=>$value['end_time']])
|
|
|
->save(['begin_time'=>$end_time+1]);
|
|
|
} else if ($end_time > $value['begin_time'] && ($end_time >= $value['end_time']&&$value['end_time']!=0)) {
|
|
|
M("company_game_ratio","tab_")
|
|
|
->where(['company_id'=>$company_id,'relation_game_id'=>$relation_game_id,'begin_time'=>$value['begin_time'],'end_time'=>$value['end_time']])
|
|
|
->save(['begin_time'=>$begin_time,'end_time'=>$end_time]);
|
|
|
}
|
|
|
|
|
|
} else if ($value['begin_time'] <= $begin_time) {
|
|
|
if (!$end_time&&($value['end_time']>$begin_time||$value['end_time']==0)) {
|
|
|
M("company_game_ratio","tab_")
|
|
|
->where(['company_id'=>$company_id,'relation_game_id'=>$relation_game_id,'begin_time'=>$value['begin_time'],'end_time'=>$value['end_time']])
|
|
|
->save(['end_time'=>$begin_time-1]);
|
|
|
continue;
|
|
|
}else if (!$end_time) {
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
if ($begin_time >= $value['end_time']&& $value['end_time']!=0) {
|
|
|
continue;
|
|
|
}
|
|
|
if ($begin_time > $value['begin_time'] && ($end_time >= $value['end_time'] && $value['end_time']!=0)) {
|
|
|
M("company_game_ratio","tab_")
|
|
|
->where(['company_id'=>$company_id,'relation_game_id'=>$relation_game_id,'begin_time'=>$value['begin_time'],'end_time'=>$value['end_time']])
|
|
|
->save(['end_time'=>$begin_time-1]);
|
|
|
} else if ($begin_time > $value['begin_time'] && ($end_time < $value['end_time']||$value['end_time']==0)) {
|
|
|
M("company_game_ratio","tab_")
|
|
|
->where(['company_id'=>$company_id,'relation_game_id'=>$relation_game_id,'begin_time'=>$value['begin_time'],'end_time'=>$value['end_time']])
|
|
|
->save(['end_time'=>$begin_time-1]);
|
|
|
$dataValue = $value;
|
|
|
$dataValue['begin_time'] = $end_time+1;
|
|
|
unset($dataValue['id']);
|
|
|
M("company_game_ratio","tab_")->add($dataValue);
|
|
|
|
|
|
} else if ($begin_time == $value['begin_time'] && ($end_time < $value['end_time']||$value['end_time']==0)) {
|
|
|
M("company_game_ratio","tab_")
|
|
|
->where(['company_id'=>$company_id,'relation_game_id'=>$relation_game_id,'begin_time'=>$value['begin_time'],'end_time'=>$value['end_time']])
|
|
|
->save(['begin_time'=>$end_time+1]);
|
|
|
} else if ($end_time == $value['end_time']&&$begin_time>$value['begin_time']) {
|
|
|
M("company_game_ratio","tab_")
|
|
|
->where(['company_id'=>$company_id,'relation_game_id'=>$relation_game_id,'begin_time'=>$value['begin_time'],'end_time'=>$value['end_time']])
|
|
|
->save(['end_time'=>$begin_time-1]);
|
|
|
} else if ($end_time == $value['end_time']&&$begin_time == $value['begin_time']) {
|
|
|
M("company_game_ratio","tab_")
|
|
|
->where(['company_id'=>$company_id,'relation_game_id'=>$relation_game_id,'begin_time'=>$value['begin_time'],'end_time'=>$value['end_time']])
|
|
|
->save(['begin_time'=>$begin_time,'end_time'=>$end_time]);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
M("company_game_ratio","tab_")->add($ratiov);
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
public function addRatio()
|
|
|
{
|
|
|
if ($_POST) {
|
|
|
$params = I('post.');
|
|
|
if (empty($params['begin_time'])) {
|
|
|
$this->error('请选择开始时间');
|
|
|
}
|
|
|
if (!empty($params['end_time'])) {
|
|
|
if (strtotime($params['end_time']) < strtotime($params['begin_time'])) {
|
|
|
$this->error('结束时间不得小于开始时间');
|
|
|
}
|
|
|
}
|
|
|
if (!isset($params['ratio']) || $params['ratio'] === '') {
|
|
|
$this->error('默认分成比例不能为空');
|
|
|
}
|
|
|
|
|
|
if(!$params['company_id']) {
|
|
|
$save['company_belong'] = $params['company_belong'] ?? 0;
|
|
|
}
|
|
|
|
|
|
$save['turnover_ratio'] = $this->setTurnoverRatio($params);
|
|
|
$save['ratio'] = $params['ratio'] ?? 0;
|
|
|
$save['relation_game_id'] = $params['relation_game_id'] ?? 0;
|
|
|
$save['company_id'] = $params['company_id'] ?? 0;
|
|
|
$save['begin_time'] = strtotime($params['begin_time']);
|
|
|
$save['end_time'] = $params['end_time'] ? strtotime($params['end_time'])+86399 : 0;
|
|
|
$save['remark'] = $params['remark'] ?? '';
|
|
|
$save['status'] = 0;
|
|
|
$save['turnover_type'] = $params["turnover_type"] ?? 1;
|
|
|
$save['verify_log']=json_encode(["create_user"=>$this->admininfo["username"],"create_time"=>date("Y-m-d H:i:s")]);
|
|
|
//获取旧比例
|
|
|
$this->getOldRatio($save);
|
|
|
|
|
|
$promote_data = M("promote_company","tab_")->where(['id'=>$save['company_id']])->find();
|
|
|
|
|
|
if ($promote_data['company_belong'] != '1' && $promote_data['company_belong'] != '2') {
|
|
|
$save['verify_log'] = json_decode($save['verify_log'],true);
|
|
|
$save['verify_log']['market_user']="AUTO";
|
|
|
$save['verify_log']['market_time']=date("Y-m-d H:i:s");
|
|
|
$save['verify_log'] = json_encode($save['verify_log']);
|
|
|
$save['status']=1;
|
|
|
}
|
|
|
|
|
|
//判断已有未审核
|
|
|
$where = [
|
|
|
"company_belong"=>$save['company_belong'],
|
|
|
"relation_game_id"=>$save['relation_game_id'],
|
|
|
"company_id"=>$save['company_id'],
|
|
|
"status"=>["LT",2],//管理员未确认
|
|
|
"begin_time"=>$save['begin_time'],
|
|
|
"end_time"=>$save['end_time']
|
|
|
];
|
|
|
$hasdb = M("company_game_ratio_log","tab_")->field("count(id) count")->where($where)->find()['count'];
|
|
|
if($hasdb > 0){
|
|
|
$this->error('已经有审批单,请直接搜索后修改');
|
|
|
}
|
|
|
|
|
|
$id = M("company_game_ratio_log","tab_")->add($save);
|
|
|
addOperationLog(['op_type'=>0,'key'=>$id,'op_name'=>'新增','url'=>U('lists')]);
|
|
|
$this->ajaxReturn(["msg"=>"添加成功","code"=>1,"url"=>U("lists")]);
|
|
|
|
|
|
} else {
|
|
|
$companyList = D("PromoteCompany")->getList();
|
|
|
$this->assign("companyList",$companyList);
|
|
|
$this->assign("gameList",D("Game")->getRelationGameLits());
|
|
|
$this->display();
|
|
|
}
|
|
|
|
|
|
}
|
|
|
public function edit()
|
|
|
{
|
|
|
if ($_POST) {
|
|
|
$params = I('post.');
|
|
|
if(!isset($params['id'])){
|
|
|
$this->error('参数错误');
|
|
|
}
|
|
|
if (empty($params['begin_time'])) {
|
|
|
$this->error('请选择开始时间');
|
|
|
}
|
|
|
if (!empty($params['end_time'])) {
|
|
|
if (strtotime($params['end_time']) < strtotime($params['begin_time'])) {
|
|
|
$this->error('结束时间不得小于开始时间');
|
|
|
}
|
|
|
}
|
|
|
if (!isset($params['ratio']) || $params['ratio'] === '') {
|
|
|
$this->error('默认分成比例不能为空');
|
|
|
}
|
|
|
//查询
|
|
|
$y = M("company_game_ratio","tab_")->where("id='{$params['id']}'")->find();
|
|
|
$save['turnover_ratio'] = $this->setTurnoverRatio($params);
|
|
|
$save['ratio'] = $params['ratio'] ?? 0;
|
|
|
$save['last_turnover_ratio'] = $params['last_turnover_ratio'];
|
|
|
$save['last_ratio'] = $params['last_ratio'];
|
|
|
$save['relation_game_id'] = $params['relation_game_id'] ?? 0;
|
|
|
$save['company_id'] = $params['company_id'] ?? 0;
|
|
|
$save['begin_time'] = strtotime($params['begin_time']);
|
|
|
$save['end_time'] = $params['end_time'] ? strtotime($params['end_time'])+86399 : 0;
|
|
|
$save['remark'] = $params['remark'] ?? '';
|
|
|
$save['turnover_type'] = $params['turnover_type'] ?? 1;
|
|
|
$save['status'] = 0;
|
|
|
$save['verify_log']=json_encode(["create_user"=>$this->admininfo["username"],"create_time"=>date("Y-m-d H:i:s")]);
|
|
|
$save['company_belong'] = $y['company_belong'] ?? 0;
|
|
|
|
|
|
if($y['ratio'] != $save['ratio'] || $y['turnover_ratio'] != $save['turnover_ratio'] || $y['begin_time'] != $save['begin_time'] || $y['end_time'] != $save['end_time']){
|
|
|
$save['status'] = 0;
|
|
|
$save['verify_log'] = json_encode(["create_user"=>$this->admininfo["username"],"create_time"=>date("Y-m-d H:i:s")]);
|
|
|
}
|
|
|
M("company_game_ratio_log","tab_")->add($save);
|
|
|
addOperationLog(['op_type'=>1,'key'=>$params['id'],'op_name'=>'修改','url'=>U('index')]);
|
|
|
$this->ajaxReturn(["msg"=>"修改申请提交成功","code"=>1,"url"=>U("index")]);
|
|
|
} else {
|
|
|
$params = I('get.');
|
|
|
$id = $params['id'] ?? 0;
|
|
|
$id = intval($id);
|
|
|
$map['m.id'] = $id;
|
|
|
|
|
|
$gameres = M("game","tab_")->field("tab_game.relation_game_id,tab_game.relation_game_name,IF(tab_game.original_package_name='','未配置',tab_game.original_package_name) original_package_name,tab_game_type.type_name game_type_name")->join("tab_game_type on tab_game.game_type_id = tab_game_type.id")->group("tab_game.relation_game_id")->select(false);
|
|
|
$dbres = M("company_game_ratio","tab_")
|
|
|
->alias('m')
|
|
|
->field("m.*,g.*,p.company_name,m.company_belong")
|
|
|
->join("left JOIN ({$gameres}) g ON m.relation_game_id = g.relation_game_id")
|
|
|
->join("left JOIN tab_promote_company p ON m.company_id = p.id")
|
|
|
->where($map)
|
|
|
->find();
|
|
|
|
|
|
$dbres['company_belong'] ="下游".$this->setCompanyBelong($dbres['company_belong']);
|
|
|
$dbres['turnover_ratio'] = $dbres['turnover_ratio'] ? json_decode($dbres['turnover_ratio'], true) : $dbres['turnover_ratio'];
|
|
|
$dbres['begin_time'] = date("Y-m-d",$dbres['begin_time']);
|
|
|
$dbres['end_time'] = empty($dbres['end_time']) ? '' :date("Y-m-d",$dbres['end_time']);
|
|
|
$this->assign('data', $dbres);
|
|
|
$this->display();
|
|
|
}
|
|
|
}
|
|
|
public function editRatio()
|
|
|
{
|
|
|
if ($_POST) {
|
|
|
$params = I('post.');
|
|
|
if(!isset($params['id'])){
|
|
|
$this->error('参数错误');
|
|
|
}
|
|
|
if (empty($params['begin_time'])) {
|
|
|
$this->error('请选择开始时间');
|
|
|
}
|
|
|
if (!empty($params['end_time'])) {
|
|
|
if (strtotime($params['end_time']) < strtotime($params['begin_time'])) {
|
|
|
$this->error('结束时间不得小于开始时间');
|
|
|
}
|
|
|
}
|
|
|
if (!isset($params['ratio']) || $params['ratio'] === '') {
|
|
|
$this->error('默认分成比例不能为空');
|
|
|
}
|
|
|
//查询
|
|
|
$y = M("company_game_ratio_log","tab_")->where("id='{$params['id']}'")->find();
|
|
|
$save['id'] = $params['id'];
|
|
|
$save['ratio'] = $params['ratio'] ?? 0;
|
|
|
$save['turnover_ratio'] = $this->setTurnoverRatio($params);
|
|
|
|
|
|
$save['begin_time'] = strtotime($params['begin_time']);
|
|
|
$save['end_time'] = $params['end_time'] ? strtotime($params['end_time'])+86399 : 0;
|
|
|
$save['remark'] = $params['remark'] ?? '';
|
|
|
$save['turnover_type'] = $params['turnover_type'] ?? 1;
|
|
|
$save['company_belong'] = $y['company_belong'] ?? 0;
|
|
|
if($y['ratio'] != $save['ratio'] || $y['turnover_ratio'] != $save['turnover_ratio'] || $y['begin_time'] != $save['begin_time'] || $y['end_time'] != $save['end_time'] || $y['turnover_type'] != $save['turnover_type']){
|
|
|
$save['status'] = 0;
|
|
|
$save['verify_log'] = json_encode(["create_user"=>$this->admininfo["username"],"create_time"=>date("Y-m-d H:i:s")]);
|
|
|
|
|
|
$promote_data = M("promote_company","tab_")->where(['id'=>$y['company_id']])->find();
|
|
|
|
|
|
if ($promote_data['company_belong'] != '1' && $promote_data['company_belong'] != '2') {
|
|
|
$save['verify_log'] = json_decode($save['verify_log'],true);
|
|
|
$save['verify_log']['market_user']="AUTO";
|
|
|
$save['verify_log']['market_time']=date("Y-m-d H:i:s");
|
|
|
$save['verify_log'] = json_encode($save['verify_log']);
|
|
|
$save['status']=1;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
M("company_game_ratio_log","tab_")->save($save);
|
|
|
addOperationLog(['op_type'=>1,'key'=>$save['id'],'op_name'=>'修改','url'=>U('lists')]);
|
|
|
$this->ajaxReturn(["msg"=>"修改成功","code"=>1,"url"=>U("lists")]);
|
|
|
} else {
|
|
|
$params = I('get.');
|
|
|
$id = $params['id'] ?? 0;
|
|
|
$id = intval($id);
|
|
|
$map['m.id'] = $id;
|
|
|
|
|
|
$gameres = M("game","tab_")->field("tab_game.relation_game_id,tab_game.relation_game_name,IF(tab_game.original_package_name='','未配置',tab_game.original_package_name) original_package_name,tab_game_type.type_name game_type_name")->join("tab_game_type on tab_game.game_type_id = tab_game_type.id")->group("tab_game.relation_game_id")->select(false);
|
|
|
$dbres = M("company_game_ratio_log","tab_")
|
|
|
->alias('m')
|
|
|
->field("m.*,g.*,p.company_name,m.company_belong")
|
|
|
->join("left JOIN ({$gameres}) g ON m.relation_game_id = g.relation_game_id")
|
|
|
->join("left JOIN tab_promote_company p ON m.company_id = p.id")
|
|
|
->where($map)
|
|
|
->find();
|
|
|
$dbres['company_belong'] ="下游".$this->setCompanyBelong($dbres['company_belong']);
|
|
|
$dbres['turnover_ratio'] = $dbres['turnover_ratio'] ? json_decode($dbres['turnover_ratio'], true) : $dbres['turnover_ratio'];
|
|
|
$dbres['begin_time'] = date("Y-m-d",$dbres['begin_time']);
|
|
|
$dbres['end_time'] = empty($dbres['end_time']) ? '' :date("Y-m-d",$dbres['end_time']);
|
|
|
$this->assign('data', $dbres);
|
|
|
$this->display();
|
|
|
}
|
|
|
}
|
|
|
public function delRatio()
|
|
|
{
|
|
|
if(!isset($_REQUEST['id'])){
|
|
|
$this->error('参数错误');
|
|
|
}
|
|
|
$id = $_REQUEST['id'];
|
|
|
$res = M("company_game_ratio_log","tab_")->where("id='{$id}'")->delete();
|
|
|
if($res !== false){
|
|
|
addOperationLog(['op_type'=>2,'key'=>$id,'op_name'=>'删除','url'=>U('lists')]);
|
|
|
$this->ajaxReturn(["msg"=>"删除成功","code"=>1,"url"=>U("lists")]);
|
|
|
}else{
|
|
|
$this->error('删除错误');
|
|
|
}
|
|
|
}
|
|
|
public function delGameRatio()
|
|
|
{
|
|
|
if(!isset($_REQUEST['id'])){
|
|
|
$this->error('参数错误');
|
|
|
}
|
|
|
$id = $_REQUEST['id'];
|
|
|
$res = M("company_game_ratio","tab_")->where("id='{$id}'")->delete();
|
|
|
if($res !== false){
|
|
|
addOperationLog(['op_type'=>2,'key'=>$id,'op_name'=>'删除','url'=>U('index')]);
|
|
|
$this->ajaxReturn(["msg"=>"删除成功","code"=>1,"url"=>U("index")]);
|
|
|
}else{
|
|
|
$this->error('删除错误');
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public function menuAuth()
|
|
|
{
|
|
|
$addurl = U("addRatio");
|
|
|
$mentBtn = [
|
|
|
"addRatio"=>"<a class='butn' href='{$addurl}'>新增特殊比例</a>",
|
|
|
"marketAgree"=>"<a class='butn' id='marketAgree'>市场部审批通过</a>",
|
|
|
"marketRefuse"=>"<a class='butn' id='marketRefuse' style='background-color: red;'>市场部审核拒绝</a>",
|
|
|
"adminAgree"=>"<a class='butn' id='adminAgree'>管理员审核通过</a>",
|
|
|
"adminRefuse"=>"<a class='butn' id='adminRefuse' style='background-color: red;'>管理员审核拒绝</a>"
|
|
|
];
|
|
|
$resarr = [];
|
|
|
foreach ($mentBtn as $k => $v) {
|
|
|
if(IS_ROOT){
|
|
|
$resarr[] = $v;
|
|
|
}else{
|
|
|
if(in_array($k,$this->OpAuthList)){
|
|
|
$resarr[] = $v;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return $resarr;
|
|
|
}
|
|
|
public function OpAuth($info)
|
|
|
{
|
|
|
$id = $info['id'];
|
|
|
//原始列表
|
|
|
$opBtn = [
|
|
|
"editRatio"=>"<a class='confirm editRatio' data-id='{$id}'>编辑</a>",
|
|
|
"delRatio"=>"<a class='confirm delRatio' data-id='{$id}' style='color: red;'>删除</a>",
|
|
|
"delGameRatio"=>"<a class='confirm delGameRatio' data-id='{$id}' style='color: red;'>删除</a>",
|
|
|
];
|
|
|
//操作对应菜单
|
|
|
if(!isset($info['status'])){
|
|
|
$optist = ["editRatio","delGameRatio"];
|
|
|
}else{
|
|
|
if($info['status'] == 2){
|
|
|
$optist = [];
|
|
|
}else{
|
|
|
$optist = ["editRatio","delRatio"];
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//
|
|
|
$resarr = [];
|
|
|
foreach ($optist as $k => $v) {
|
|
|
if(IS_ROOT){
|
|
|
$resarr[] = $opBtn[$v];
|
|
|
}else{
|
|
|
if(in_array($v,$this->OpAuthList)){
|
|
|
$resarr[] = $opBtn[$v];
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return $resarr;
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function setTurnoverRatio($params)
|
|
|
{
|
|
|
$save['turnover_ratio'] = [];
|
|
|
if (!empty(array_filter($params['turnover'])) || !empty(array_filter($params['turnover_ratio'])) ) {
|
|
|
if (is_array($params['turnover']) && is_array($params['turnover_ratio']) && is_array($params['instanceof'])) {
|
|
|
foreach ($params['turnover'] as $turnover) {
|
|
|
if (empty($turnover)) {
|
|
|
$this->error('月流水不能为空');
|
|
|
}
|
|
|
}
|
|
|
foreach ($params['turnover_ratio'] as $turnoverRatio) {
|
|
|
if (empty($turnoverRatio)) {
|
|
|
$this->error('月流水分成比例不能为空');
|
|
|
}
|
|
|
}
|
|
|
foreach ($params['instanceof'] as $intervalClosedStatus) {
|
|
|
if (!in_array($intervalClosedStatus, [1, 2])) {
|
|
|
$this->error('月流水分符号不能为空');
|
|
|
}
|
|
|
}
|
|
|
$turnoverCount = count($params['turnover']);
|
|
|
$sortTurnover = $params['turnover'];
|
|
|
sort($sortTurnover);
|
|
|
if ($params['turnover'] != $sortTurnover || $turnoverCount != count(array_unique($params['turnover']))) {
|
|
|
$this->error('月流水必须以正序的方式填写,且必须大于上一个月流水');
|
|
|
}
|
|
|
$ratio = $params['ratio'] ?? 0;
|
|
|
// if ($params['turnover_ratio'][0] <= $ratio) {
|
|
|
// $this->error('月流水分成比例必须大于默认分成比例');
|
|
|
// }
|
|
|
$turnoverRatioCount = count($params['turnover_ratio']);
|
|
|
$sortTurnoverRatio = $params['turnover_ratio'];
|
|
|
sort($sortTurnoverRatio);
|
|
|
// if ($params['turnover_ratio'] != $sortTurnoverRatio || $turnoverRatioCount != count(array_unique($params['turnover_ratio']))) {
|
|
|
// $this->error('月流水分成比例必须以正序的方式填写,且必须大于上一个月流水分成比例');
|
|
|
// }
|
|
|
|
|
|
foreach ($params['turnover'] as $key => $turnover) {
|
|
|
$save['turnover_ratio'][] = [
|
|
|
'turnover' => bcdiv($turnover, 1, 2),
|
|
|
'ratio' => bcdiv($params['turnover_ratio'][$key], 1, 2),
|
|
|
'instanceof' => (isset($params['instanceof'][$key]) ? $params['instanceof'][$key] : 1),
|
|
|
];
|
|
|
}
|
|
|
$save['turnover_ratio'] = json_encode($save['turnover_ratio']);
|
|
|
}
|
|
|
}
|
|
|
if(empty($save['turnover_ratio'])){
|
|
|
$save['turnover_ratio'] = '';
|
|
|
}
|
|
|
return $save['turnover_ratio'];
|
|
|
|
|
|
}
|
|
|
public function getOldRatio(&$save)
|
|
|
{
|
|
|
$tmap = [
|
|
|
"company_id"=>$save['company_id'],
|
|
|
"relation_game_id"=>$save['relation_game_id'],
|
|
|
];
|
|
|
$ratio_dbres = $this->DBModel->where($tmap)->find();
|
|
|
if(isset($ratio_dbres['ratio'])){
|
|
|
$save['last_ratio']=$ratio_dbres['ratio'];
|
|
|
$save['last_turnover_ratio']=$ratio_dbres['turnover_ratio'];
|
|
|
return ;
|
|
|
}
|
|
|
|
|
|
$cmap = [
|
|
|
"id"=>$save['company_id'],
|
|
|
];
|
|
|
$com = M("promote_company","tab_")->field("company_belong")->where($cmap)->find();
|
|
|
if(!isset($com['company_belong'])){
|
|
|
$save['last_ratio']=0;
|
|
|
$save['last_turnover_ratio']="";
|
|
|
return ;
|
|
|
}
|
|
|
//查询模板
|
|
|
$mmap = [
|
|
|
"company_belong"=>$com['company_belong'],
|
|
|
"relation_game_id"=>$save['relation_game_id']
|
|
|
];
|
|
|
$mould = M("game_ratio_mould","tab_")->where($mmap)->find();
|
|
|
if(isset($mould['ratio'])){
|
|
|
$save['last_ratio']=$mould['ratio'];
|
|
|
$save['last_turnover_ratio']=$mould['turnover_ratio'];
|
|
|
}else{
|
|
|
$save['last_ratio']=0;
|
|
|
$save['last_turnover_ratio']="";
|
|
|
}
|
|
|
return ;
|
|
|
|
|
|
}
|
|
|
public function error($data)
|
|
|
{
|
|
|
header('Content-Type:application/json; charset=utf-8');
|
|
|
$data =json_encode(['msg'=>$data,"code"=>4000],JSON_UNESCAPED_UNICODE);
|
|
|
exit($data);
|
|
|
}
|
|
|
protected function returnSettlementTypeCompanyid($st)
|
|
|
{
|
|
|
if($st != -1){
|
|
|
$setwhere = [
|
|
|
"settlement_type"=>$st,
|
|
|
"_string"=>"first_company_type=2 OR second_company_type=2"
|
|
|
];
|
|
|
}else{
|
|
|
$setwhere = [
|
|
|
"_string"=>"first_company_type=2 OR second_company_type=2"
|
|
|
];
|
|
|
}
|
|
|
$scompany_id = M("company_relation","tab_")->field("first_company_type,second_company_type,first_company_id,second_company_id")->where($setwhere)->select();
|
|
|
$company_id = [];
|
|
|
foreach($scompany_id as $k=>$v){
|
|
|
if($v['first_company_type'] == 0){
|
|
|
$company_id[] = $v['second_company_id'];
|
|
|
}else{
|
|
|
$company_id[] = $v['first_company_id'];
|
|
|
}
|
|
|
}
|
|
|
unset($scompany_id);
|
|
|
$company_id = implode(",",$company_id);
|
|
|
return $company_id;
|
|
|
}
|
|
|
// //设置比例阶梯
|
|
|
// protected function readTurnoverRatio(&$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']);
|
|
|
// }
|
|
|
|
|
|
//设置比例阶梯
|
|
|
protected function readTurnoverRatio(&$v){
|
|
|
|
|
|
$radio = explode('|',$v['ratio']);
|
|
|
$turnover_ratio = explode('|',$v['turnover_ratio']);
|
|
|
$turnover_type = $v['turnover_types'];
|
|
|
|
|
|
$sec_row = 1;
|
|
|
|
|
|
foreach ($radio as $key => $value) {
|
|
|
|
|
|
$turnoverratio = json_decode($turnover_ratio[$key],true);
|
|
|
$v['turnover_ratios'][$key] = array(
|
|
|
array("ratio"=>floatval($value)."%","name"=>"默认比例")
|
|
|
);
|
|
|
|
|
|
foreach($turnoverratio as $ke=>$va){
|
|
|
$t=array("ratio"=>floatval($va["ratio"])."%");
|
|
|
if(array_key_exists("instanceof",$va)){
|
|
|
//存在
|
|
|
if($va['instanceof']=='1'){
|
|
|
$t['name']="{$turnover_type[$key]}≥".$va['turnover'];
|
|
|
}else{
|
|
|
$t['name']="{$turnover_type[$key]}>".$va['turnover'];
|
|
|
}
|
|
|
}else{
|
|
|
$t['name']="{$turnover_type[$key]}≥".$va['turnover'];
|
|
|
}
|
|
|
$sec_row++;
|
|
|
$v['turnover_ratios'][$key][]=$t;
|
|
|
}
|
|
|
$v['sec_row'][$key] = $sec_row;
|
|
|
$sec_row = 1;
|
|
|
}
|
|
|
$v['row'] = array_sum($v['sec_row']);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
} |