@ -24,6 +24,185 @@ class MarketPercentageController extends ThinkController
$admin_id = $_SESSION['onethink_admin']['user_auth']['uid'];
$map['admin_id'] = $admin_id;
$map['is_settlement'] = 1;
if(is_administrator()||session('user_group_id') == 15||session('user_group_id') == 14||session('user_group_id') == 19||session('user_group_id') == 23) {
unset($map['admin_id']);
$admin_data = M("member")
->field("access.uid admin_id")
->join("left join sys_auth_group_access access on sys_member.uid = access.uid")
->join("left join sys_auth_group auth on access.group_id=auth.id")
->where(['group_id'=>['in','11,12,21']])
->select();
if ($admin_data) {
$map['admin_id'] = ['in',array_column($admin_data,'admin_id')];
}
$_REQUEST['admin_id']?($map['admin_id'] = $_REQUEST['admin_id']):'';
}
$search_date = [];
if (isset($_REQUEST['time_start']) & & isset($_REQUEST['time_end'])) {
$end = $_REQUEST['time_end'];
$start = $_REQUEST['time_start'];
$i = 0;
do {
$date = date('Y-m', strtotime($start . ' + ' . $i . ' month'));
$search_date[] = $date;
$i++;
}while ($date < date ( ' Y-m ' , strtotime ( " { $ end } " ) ) ) ;
if ($search_date) {
$map['pay_time'] = ['in', $search_date];
}
} elseif (isset($_REQUEST['time_start'])) {
$end = date("Y-m",time());
$start = $_REQUEST['time_start'];
$i = 0;
do {
$date = date('Y-m', strtotime($start . ' + ' . $i . ' month'));
$search_date[] = $date;
$i++;
}while ($date < date ( ' Y-m ' , strtotime ( " { $ end } " ) ) ) ;
if ($search_date) {
$map['pay_time'] = ['in', $search_date];
}
} elseif (isset($_REQUEST['time_end'])) {
$end = $_REQUEST['time_end'];
$start = '2019-08';
$i = 0;
do {
$date = date('Y-m', strtotime($start . ' + ' . $i . ' month'));
$search_date[] = $date;
$i++;
}while ($date < date ( ' Y-m ' , strtotime ( " { $ end } " ) ) ) ;
if ($search_date) {
$map['pay_time'] = ['in', $search_date];
}
}
// dump($map);die();
// var_dump($map);die();
$data = M("settleup_marketorder","tab_")
->field("pay_time,promote_account,company_name,company_belong,member.real_name,develop_type,game_name,
sum(pay_amount) pay_amount,sum(cp_amount) cp_amount,sum(promote_amount) promote_amount,
sum(channel_amount) channel_amount, sum(company_tax) company_tax,sum(company_profit) company_profit")
->join("left join sys_member member on member.uid=admin_id");
if ($_REQUEST['export']) {
$data = $data->where($map)
->group("promote_id,game_name,pay_time,admin_id")
->order("pay_time DESC")
->select();
} else {
$data = $data->page($p, $row)
->where($map)
->group("promote_id,game_name,pay_time,admin_id")
->order("pay_time DESC")
->select();
}
$sum = M("settleup_marketorder","tab_")
->field("pay_time,promote_account,company_belong,real_name,develop_type,game_name,
sum(pay_amount) pay_amount,sum(cp_amount) cp_amount,sum(promote_amount) promote_amount,
sum(channel_amount) channel_amount, sum(company_tax) company_tax,sum(company_profit) company_profit")
->where($map)
->find();
$this->assign("sum",$sum);
foreach ($data as $key => $value) {
if ($value['company_belong'] == 0) {
$data[$key]['company_belong'] = '内团';
} else if ($value['company_belong'] == 1) {
$data[$key]['company_belong'] = '外团';
} else if ($value['company_belong'] == 2) {
$data[$key]['company_belong'] = '外团-分发联盟';
} else {
$data[$key]['company_belong'] = '无';
}
if ($value['develop_type'] == 1) {
$data[$key]['develop_type'] = '自主开发';
} else if ($value['develop_type'] == 2) {
$data[$key]['develop_type'] = '自主开发及维护';
} else if ($value['develop_type'] == 3) {
$data[$key]['develop_type'] = '只维护';
} else {
$data[$key]['develop_type'] = '无';
}
}
if ($_REQUEST['export']) {
$title = ['pay_time' => '时间',
'company_name'=>'公司名称',
'promote_account' => '会长账号',
'company_belong' => '内外团',
'real_name' => '所属市场专员',
'develop_type' => '类型',
'game_name' => '游戏名称',
'pay_amount' => '总流水',
'cp_amount' => '上游结算流水',
'promote_amount' => '下游结算流水',
'channel_amount' => '支付渠道费用',
'company_tax' => '公司税费',
'company_profit' => '税后毛利额'];
foreach ($data as $key => $value) {
$data[$key]['pay_time'] = '`'.$data[$key]['pay_time'];
}
$sum['pay_time'] = '';
$sum['promote_account'] = '';
$sum['company_belong'] = '合计';
$sum['real_name'] = '';
$sum['develop_type'] = '';
$sum['game_name'] = '';
$data = array_merge($data,[$sum]);
data2csv($data,'市场毛利统计',$title);
}
$count = M("settleup_marketorder","tab_")
->where($map)
->group("promote_id,game_name,pay_time,admin_id")
->select(false);
$count = M()->table("({$count}) count")->count();
$page = set_pagination($count, $row);
if ($page) {
$this->assign('_page', $page);
}
$this->checkListOrCountAuthRestMap($map,[]);
$this->assign("list_data",$data);
$this->display();
}
public function indexuncaculate($row = 10, $p = 1){
$map = [];
// $_REQUEST['pay_time']?($map['pay_time'] = $_REQUEST['pay_time']):'';
$_REQUEST['promote_id']?($map['promote_id'] = $_REQUEST['promote_id']):'';
$_REQUEST['relation_game_id']?($map['relation_game_id'] = $_REQUEST['relation_game_id']):'';
$_REQUEST['sdk_version']?($map['sdk_version'] = $_REQUEST['sdk_version']):'';
$_REQUEST['admin_id']?($map['admin_id'] = $_REQUEST['admin_id']):'';
($_REQUEST['company_id']||$_REQUEST['company_id']=='0')?($map['company_id'] = $_REQUEST['company_id']):'';
$admin_id = $_SESSION['onethink_admin']['user_auth']['uid'];
$map['admin_id'] = $admin_id;
$map['is_settlement'] = 0;
if(is_administrator()||session('user_group_id') == 15||session('user_group_id') == 14||session('user_group_id') == 19||session('user_group_id') == 23) {
unset($map['admin_id']);
$admin_data = M("member")
@ -1262,15 +1441,15 @@ class MarketPercentageController extends ThinkController
foreach ($data as $key => $value) {
$data[$key]["begin_time"] = date("Y-m-d",$value['begin_time'] );
$data[$key]["end_time"] = date("Y-m-d",$value['end_time'] );
$data[$key]["begin_time"] = date("Y-m-01",strtotime($value['time']) );
$data[$key]["end_time"] = date("Y-m-t",strtotime($value['time']) );
$where_game = $value['game_ids'];
if ($_REQUEST['relation_game_id']) {
$where_game = $_REQUEST['relation_game_id'];
}
// dump($where_game);die();
$game = [];
if ($where_game) {
$game = M("game","tab_")
@ -1307,12 +1486,8 @@ class MarketPercentageController extends ThinkController
$data = $_POST;
if (!$data['begin_time']) {
$this->ajaxReturn(['msg'=>"请填写开始时间","status"=>0]);
}
if (!$data['end_time']) {
$this->ajaxReturn(['msg'=>"请填写截止时间","status"=>0]);
if (!$data['time']) {
$this->ajaxReturn(['msg'=>"请填写生效月份","status"=>0]);
}
if (!$data['game_ids']) {
@ -1322,25 +1497,22 @@ class MarketPercentageController extends ThinkController
$data['game_ids'] = array_merge([''],$data['game_ids'],['']);
$data['game_ids'] = implode(',',$data['game_ids']);
// $data['game_ids'] = json_encode($data['game_ids']);
$data['begin_time'] = strtotime($data['begin_time']);
$data['end_time'] = strtotime($data['end_time']);
// $data['time'] = strtotime($data['time']);
// $data['end_time'] = strtotime($data['end_time']);
$belong_game = M("company_belong_game","tab_")
->where("(begin_ time< ={$data[ 'begin_time']} and end_time >= {$data['begin_ time']}) or (begin_time< ={$data[ 'end_time']} and end_time >={$data['end_time']}) ")
->where("time='{$data['time']}'")
->select();
if ($belong_game) {
$this->ajaxReturn(['msg'=>"时间段重叠,不能增加已经相交的时间段 ","status"=>0]);
$this->ajaxReturn(['msg'=>"已添加月份,请勿重复添加 ","status"=>0]);
}
M("company_belong_game","tab_")->add($data);
$this->ajaxReturn(['msg'=>"添加成功","status"=>1]);
} else {
$this->display();
}
@ -1355,12 +1527,8 @@ class MarketPercentageController extends ThinkController
if (IS_POST) {
$data = $_POST;
if (!$data['begin_time']) {
$this->ajaxReturn(['msg'=>"请填写开始时间","status"=>0]);
}
if (!$data['end_time']) {
$this->ajaxReturn(['msg'=>"请填写截止时间","status"=>0]);
if (!$data['time']) {
$this->ajaxReturn(['msg'=>"请填写生效月份","status"=>0]);
}
if (!$data['game_ids']) {
@ -1369,18 +1537,27 @@ class MarketPercentageController extends ThinkController
// $data['game_ids'] = json_encode($data['game_ids']);
$data['game_ids'] = explode(',',$data['game_ids']);
foreach ($data['game_ids'] as $key => $value) {
if ($value == "0") {
unset($data['game_ids'][$key]);
}
}
$data['game_ids'] = array_merge([''],$data['game_ids'],['']);
$data['game_ids'] = implode(',',$data['game_ids']);
$data['begin_time'] = strtotime($data['begin_time']);
$data['end_time'] = strtotime($data['end_time']);
// $data['begin_time'] = strtotime($data['begin_time']);
// $data['end_time'] = strtotime($data['end_time']);
$belong_game = M("company_belong_game","tab_")
->where("((begin_time< ={$data['begin_time']} and end_time >={$data['begin_time']}) or (begin_time< ={$data['end_time']} and end_time >={$data['end_time']})) and id != {$id}")
->where("time='{$data['time']}' and id != {$id}")
->select();
if ($belong_game) {
$this->ajaxReturn(['msg'=>"时间段重叠,不能修改成已经相交的时间段 ","status"=>0]);
$this->ajaxReturn(['msg'=>"已添加月份,请勿重复添加 ","status"=>0]);
}
// dump($data);die();
M("company_belong_game","tab_")->where(['id'=>$id])->save($data);