fix grand_id

master
jbrazz 5 years ago
parent edc6a7be73
commit c9996e071c

@ -572,14 +572,8 @@ function get_game_set_field($game_id,$field=""){
* @return mixed
*/
function promote_lists($type){
if($type == 1){
$map['parent_id'] = 0;
}elseif($type == 2){
$map['parent_id'] = ['neq',0];
$map['grand_id'] = 0;
}elseif($type == 3) {
$map['parent_id'] = ['gt',0];
$map['grand_id'] = ['gt', 0];
if($type){
$map['level'] = $type;
} else{
$map = '';
}
@ -1066,17 +1060,19 @@ function get_promote_parent($promote_id,$field='account'){
function get_promote_parent_acc($promote_id){
$Promote = M('promote','tab_');
$data = $Promote->field('account,parent_id,grand_id')->find($promote_id);
$data = $Promote->field('account,parent_id')->find($promote_id);
if(empty($data)){
return $data["account"]="官方渠道";exit;
}
if($data['grand_id'] !=0){
$data = $Promote->find($data['grand_id']);
}elseif($data['parent_id'] != 0){
$data = $Promote->find($data['parent_id']);
$chain = trim($data['chain'], '/');
if ($chain == '') {
return '------';
} else {
$topPromoteId = explode('/', $chain)[0];
$parent_promote = M('promote', 'tab_')->where(['id' => $topPromoteId])->find();
return $parent_promote['account'] ?: '------';
}
return $data["account"]?$data['account']:'------';
}
//获取所有苹果证书id

@ -433,10 +433,8 @@ class ExportController extends Controller
unset($_REQUEST['end']);
}
if(!empty(I('parent_id'))){
$maps['parent_id'] = I('parent_id');
$maps['grand_id'] =I('parent_id');
$maps['_logic'] = 'or';
$pro = M('promote','tab_')->field('id')->where($maps)->select();
$parent_id = I('parent_id');
$pro = M('promote','tab_')->field('id')->where("chain like '%/{$parent_id}/%'")->select();
$pro_ids = array_column($pro,'id');
$pro_ids[] = I('parent_id');
if (!empty($pro_ids)){
@ -1786,7 +1784,6 @@ class ExportController extends Controller
$arraypage=$page;
$row = 10;
$user=M('User','tab_');
$map['promote_id']=array('egt',0);
if(isset($_REQUEST['timestart'])&&isset($_REQUEST['timeend'])){
$map['register_time'] =array('BETWEEN',array(strtotime($_REQUEST['timestart']),strtotime($_REQUEST['timeend'])+24*60*60-1));
unset($_REQUEST['timestart']);unset($_REQUEST['timeend']);
@ -1795,24 +1792,34 @@ class ExportController extends Controller
$map['register_time'] =array('BETWEEN',array(strtotime($_REQUEST['start']),strtotime($_REQUEST['end'])+24*60*60-1));
unset($_REQUEST['start']);unset($_REQUEST['end']);
}
if(isset($_REQUEST['promote_id'])){
$map['_string'] = "promote_id = {$_REQUEST['promote_id']} or tab_promote.parent_id = {$_REQUEST['promote_id']} or tab_promote.grand_id = {$_REQUEST['promote_id']} ";
unset($_REQUEST['promote_id']);
$play_info_map = '';
if (isset($_REQUEST['game_name'])) {
$map['fgame_name'] = $_REQUEST['game_name'];
$play_info_map .= " and upi.game_name = '{$_REQUEST['game_name']}' ";
unset($_REQUEST['game_name']);
}
if (isset($_REQUEST['server_id'])) {
$play_info_map .= " and upi.server_name = '{$_REQUEST['server_id']}' ";
}
$today=total(1);
$week=total(2);
$mounth=total(3);
$map['puid'] = 0;
$data=$user
->field('promote_account,promote_id,date_format(FROM_UNIXTIME(register_time),"%Y-%m-%d") AS time, count(tab_user.id) as count,
IF(tab_promote.grand_id>0,tab_promote.grand_id,IF(tab_promote.grand_id=0 and tab_promote.parent_id >0,tab_promote.parent_id,promote_id)) as promote_id1 ,
if (isset($_REQUEST['promote_id'])) {
$map['tp1.id'] = $_REQUEST['promote_id'];
} else {
$map['tp1.chain'] = '/';
}
$data = M('promote', 'tab_')->alias('tp1')->field('tp1.account as promote_account,tp1.id as promote_id, date_format(FROM_UNIXTIME(register_time),"%Y-%m-%d") AS time, count(u.id) as count,
count(IF(register_time ' . $today . ',1,null)) as today,
count(IF(register_time ' . $week . ',1,null)) as week,
count(IF(register_time ' . $mounth . ',1,null)) as mounth')
->join('tab_promote on promote_id = tab_promote.id','left')
->join("tab_promote AS tp2 ON tp2.`chain` LIKE CONCAT('%/', tp1.id, '/%')", 'left')
->join("tab_user as u on tp2.id = u.promote_id", 'left')
->join($play_info_map ? "tab_user_play_info as upi on upi.user_id = u.id " . $play_info_map : false)
->where($map)
->group('promote_id1')
->having('promote_id != 0')
->group('tp1.id')
->order('count desc, register_time')
->select();
$count=count($data);
@ -1874,7 +1881,7 @@ class ExportController extends Controller
$page = $page ? $page : 1; //默认显示第一页数据
$arraypage=$page;
$row = 10;
$map['promote_id']=array('gt',0);
$map1['promote_id'] = $map['promote_id'] = array('egt', 0);
$spend=M('Spend','tab_');
if(isset($_REQUEST['timestart'])&&isset($_REQUEST['timeend'])){
$map['pay_time'] =array('BETWEEN',array(strtotime($_REQUEST['timestart']),strtotime($_REQUEST['timeend'])+24*60*60-1));
@ -1888,7 +1895,8 @@ class ExportController extends Controller
// $map['promote_id'] =$_REQUEST['promote_id'];
// unset($_REQUEST['promote_id']);
// }
$map['pay_status']=1;
$map1['pay_status'] = $map['pay_status']=1;
$map1['pay_way'] = $map['pay_way'] = array('gt', 0);
$today=total(1);
$week=total(2);
$mounth=total(3);
@ -1936,14 +1944,14 @@ class ExportController extends Controller
->group('promote_id')
->select(false);
}
$promote_map = "tp1.`chain` = '/'";
if (isset($_REQUEST['promote_id'])) {
$condition['_string'] = "promote_id = {$_REQUEST['promote_id']} or tab_promote.parent_id = {$_REQUEST['promote_id']} or tab_promote.grand_id = {$_REQUEST['promote_id']} ";
$promote_map = "tp1.`id` = {$_REQUEST['promote_id']}";
unset($_REQUEST['promote_id']);
}
$data = $spend->field('a.promote_account,a.promote_id,a.time,sum(a.count) as count,sum(a.today) as today,sum(a.week) as week,sum(a.mounth) as mounth,IF(tab_promote.grand_id>0,tab_promote.grand_id,IF(tab_promote.grand_id=0 and tab_promote.parent_id >0,tab_promote.parent_id,promote_id)) as promote_id1')
->join('tab_promote on promote_id = tab_promote.id','left')
->where($condition)
->table('('.$data.') as a')->group('promote_id')->order('a.count desc,a.ordertime')->select();
$data = $spend->field('t.pid as promote_id,t.promote_account,sum(a.count) AS count,sum(a.today) AS today,sum(a. WEEK) AS WEEK,sum(a.mounth) AS mounth')
->join("INNER JOIN (SELECT tp2.*, tp1.id AS pid, tp1.account as promote_account FROM tab_promote tp1 LEFT JOIN tab_promote tp2 ON tp2.`chain` LIKE CONCAT('%/', tp1.id, '/%') where $promote_map ) AS t ON promote_id = t.id")
->where($condition)->table('(' . $data . ') as a')->group('t.pid')->order('count desc,a.ordertime')->select();
$count=count($data);
foreach ($data as $key => $value) {
static $i=0;
@ -4465,15 +4473,7 @@ if ($key == 'model'){
}
$map['id']=array('in',$zid);
}
if(I('promote_level') == 1){
$map['parent_id'] = 0;
}elseif(I('promote_level') == 2){
$map['parent_id'] = ['neq',0];
$map['grand_id'] = 0;
}elseif (I('promote_level') == 3) {
$map['parent_id'] = ['neq',0];
$map['grand_id'] = ['neq',0];
}
$map['level'] = I('promote_level');
}
@ -4513,7 +4513,7 @@ if ($key == 'model'){
$v['status'] = get_info_status($v['status'],3);
$v['business_affairs'] = get_business_affairs_account($v['ba_id']);
$v['grand_account'] = get_top_promote($v['id'],$v['grand_id']?$v['grand_id']:$v['parent_id']);
$v['grand_account'] = getTopPromote($v['id'])['id'];
$v['promote_levels'] = get_promote_levels($v['id']);
$xlsData[] = $v;
@ -5212,10 +5212,8 @@ if ($key == 'model'){
} else {
$maps['parent_id'] = I('parent_id');
$maps['grand_id'] =I('parent_id');
$maps['_logic'] = 'or';
$pro = M('promote','tab_')->field('id')->where([array('id'=>$map['promote_id']),$maps])->select();
$parent_id = I('parent_id');
$pro = M('promote','tab_')->field('id')->where("id={$map['promote_id']} and chain like '%/{$parent_id}/%'")->select();
if(!$pro) {
$map['promote_id'] = array('eq',999999999);
@ -5224,10 +5222,7 @@ if ($key == 'model'){
}
} else {
$maps['parent_id'] = $map['promote_id'];
$maps['grand_id'] =$map['promote_id'];
$maps['_logic'] = 'or';
$pro = M('promote','tab_')->field('id')->where($maps)->select();
$pro = M('promote','tab_')->field('id')->where("chain like '%/{$map['promote_id']}/%'")->select();
$pro_ids = array_column($pro,'id');
$pro_ids[] = $map['promote_id'];
if (!empty($pro_ids)){
@ -5243,10 +5238,8 @@ if ($key == 'model'){
}else{
if(!empty(I('parent_id'))){
$maps['parent_id'] = I('parent_id');
$maps['grand_id'] =I('parent_id');
$maps['_logic'] = 'or';
$pro = M('promote','tab_')->field('id')->where($maps)->select();
$parent_id = I('parent_id');
$pro = M('promote','tab_')->field('id')->where("chain like '%/{$parent_id}/%'")->select();
$pro_ids = array_column($pro,'id');
$pro_ids[] = I('parent_id');
if (!empty($pro_ids)){
@ -5646,7 +5639,7 @@ if ($key == 'model'){
$data = M('promote','tab_')
->field("id")
->where("parent_id={$root_id} or grand_id={$root_id}")
->where("chain like '%/{$root_id}/%'")
->select();
$handleData = [];

@ -597,7 +597,7 @@ class FinanceController extends ThinkController
$data = M('promote','tab_')
->field("id")
->where("parent_id={$root_id} or grand_id={$root_id}")
->where("chain like '%/{$root_id}/%'")
->select();
$handleData = [];

@ -360,6 +360,10 @@ class PlatformController extends ThinkController
$play_info_map .= " and upi.game_name = '{$_REQUEST['game_name']}' ";
unset($_REQUEST['game_name']);
}
if (isset($_REQUEST['server_id'])) {
$play_info_map .= " and upi.server_name = '{$_REQUEST['server_id']}' ";
}
$today = total(1);
$week = total(2);
$mounth = total(3);
@ -372,11 +376,6 @@ class PlatformController extends ThinkController
}
if (isset($_REQUEST['server_id'])) {
$play_info_map .= " and upi.server_name = '{$_REQUEST['server_id']}' ";
}
$data = M('promote', 'tab_')->alias('tp1')->field('tp1.account as promote_account,tp1.id, date_format(FROM_UNIXTIME(register_time),"%Y-%m-%d") AS time, count(u.id) as count,
count(IF(register_time ' . $today . ',1,null)) as today,
count(IF(register_time ' . $week . ',1,null)) as week,
@ -454,15 +453,6 @@ class PlatformController extends ThinkController
$week = total(2);
$mounth = total(3);
$map1['pay_way'] = $map['pay_way'] = array('gt', 0);
/* $data=$spend
->field('promote_account,promote_id,date_format(FROM_UNIXTIME(pay_time),"%Y-%m-%d") AS time, sum(pay_amount) as count,
sum(IF(pay_time '.$today.',pay_amount,0)) as today,
sum(IF(pay_time '.$week.',pay_amount,0)) as week,
sum(IF(pay_time '.$mounth.',pay_amount,0)) as mounth')
->where($map)
->group('promote_id')
->order('count desc,pay_time')
->select(); */
$bindrecharge_data = M('bind_recharge', 'tab_')
->field('max(id) as id,promote_account,promote_id,create_time as ordertime,date_format(FROM_UNIXTIME(create_time),"%Y-%m-%d") AS time,

@ -166,15 +166,12 @@ class PromoteCoinController extends ThinkController {
$extend['type'] = 2;
$extend['source_id'] = ['neq',0];
/*if(isset($_REQUEST['source_id'])) {$extend['source_id'] = $_REQUEST['source_id'];}*/
if(isset($_REQUEST['promote_id'])) {$extend['promote_id'] = $_REQUEST['promote_id'];}
if(!empty($_REQUEST['source_id']) && !empty($_REQUEST['grand_id'])) {
$extend['source_id'] = ['in',[$_REQUEST['source_id'],$_REQUEST['grand_id']]];
} elseif (!empty($_REQUEST['source_id'])) {
$extend['source_id'] = $_REQUEST['source_id'];
} elseif (!empty($_REQUEST['grand_id'])) {
$extend['source_id'] = $_REQUEST['grand_id'];
}
$source_ids = [];
if (!empty($_REQUEST['source_id'])) $source_ids[] = $_REQUEST['source_id'];
if (!empty($_REQUEST['grand_id'])) $source_ids[] = $_REQUEST['grand_id'];
if (!empty($_REQUEST['child_id'])) $source_ids[] = $_REQUEST['child_id'];
if (!empty($source_ids)) $extend['source_id'] = ['in', $source_ids];
$map = $extend;
$map['create_time'] = total(1,false);
@ -198,7 +195,7 @@ class PromoteCoinController extends ThinkController {
$pc = D(self::model_name);
$data=$pc->alias('c')
->field('c.*,p.account as source_name, p.parent_id, p.grand_id')
->field('c.*,p.account as source_name, p.parent_id, p.level')
->join('tab_promote p on c.source_id = p.id', 'left')
->where($extend)
->order('id desc')

@ -39,8 +39,17 @@ class SettlementEvent extends ThinkEvent {
$spend = M('Spend','tab_');
$ssql=$spend
->field('tab_spend.pay_order_number,tab_spend.game_id,tab_spend.game_name,if(tab_promote.grand_id = 0,if(tab_promote.parent_id=0,tab_spend.promote_id,tab_promote.parent_id),grand_id) as pid,pay_amount,if(isnull(tab_apply.promote_ratio),tab_game.ratio,tab_apply.promote_ratio) as ratio,if(isnull(tab_apply.promote_money),tab_game.money,tab_apply.promote_money) as money')
->join('tab_promote on tab_spend.promote_id = tab_promote.id')
->field('tab_spend.pay_order_number,tab_spend.game_id,tab_spend.game_name,t.pid as pid,pay_amount,if(isnull(tab_apply.promote_ratio),tab_game.ratio,tab_apply.promote_ratio) as ratio,if(isnull(tab_apply.promote_money),tab_game.money,tab_apply.promote_money) as money')
->join("INNER JOIN (
SELECT
tp2.*, tp1.id AS pid,
tp1.account AS promote_account
FROM
tab_promote tp1
LEFT JOIN tab_promote tp2 ON tp2.`chain` LIKE CONCAT('%/', tp1.id, '/%')
WHERE
tp1. LEVEL = 1
) AS t ON promote_id = t.id")
->join('tab_game on tab_spend.game_id= tab_game.id')
->join('left join tab_apply on tab_apply.game_id = tab_game.id and tab_apply.promote_id = '.$pid['id'])
->where($smap)
@ -52,7 +61,6 @@ class SettlementEvent extends ThinkEvent {
->group('game_id')
->select();
foreach($sdata as $k => $v) {
if (empty($sdata[0]['pid'])) {unset($sdata[$k]);}
if(get_settlement($_REQUEST['timestart'],$_REQUEST['timeend'],$pid['id'],$v['game_id'])) {

@ -79,10 +79,7 @@ class BusinessAffairsModel extends Model{
*/
public function update_child($id=0,$new_id=null,$promote_id=null){
$p_ids = array();
$childMap['parent_id'] = $promote_id;
$childMap['grand_id'] = $promote_id;
$childMap['_logic'] = 'or';
$data_child = D('Promote')->where($childMap)->getField('id',true);
$data_child = D('Promote')->where("chain like '%/{$promote_id}/%'")->getField('id',true);
if(empty($data_child)){
$p_ids[0] = $promote_id;
}else{
@ -108,7 +105,7 @@ class BusinessAffairsModel extends Model{
$ba_new_ids = explode(",", $ba_new_ids);
array_push($ba_new_ids,$p_ids);
}
D('Promote')->where('parent_id='.$promote_id.' or grand_id='.$promote_id)->setField('ba_id',$new_id);
D('Promote')->where("chain like '%/{$promote_id}/%'")->setField('ba_id',$new_id);
$this->where("id=".$new_id)->setField('promote_id', implode(",", $ba_new_ids));
$this->where("id=".$new_id)->setInc("inferiors",count($p_ids));
}

@ -119,12 +119,6 @@ class PromoteModel extends Model{
'create_time' => NOW_TIME,
'ba_id' => $add_data['ba_id'],
);
//三级渠道
if($add_data['grand_id']>0){
$grand_id = $this->where(array('id'=>$add_data['parent_id']))->getField('parent_id');
$data['grand_id'] = $add_data['grand_id'];
$data['grand_account'] = get_promote_name($grand_id);
}
/* 添加用户 */
if($this->create($data)){
$uid = $this->add();
@ -375,17 +369,6 @@ class PromoteModel extends Model{
public function getPromotersByLevel($level=1)
{
$result = [];
// switch ($level) {
// case 1: // 会长
// $result = $this->field("id, nickname")->where("grand_id = 0 and parent_id = 0")->select();
// break;
// case 2: // 组长
// $result = $this->field("id, nickname")->where("grand_id = 0 and parent_id > 0")->select();
// break;
// case 3: //组员
// $result = $this->field("id, nickname")->where("parent_id > 0 and grand_id > 0")->select();
// break;
// }
$result = $this->field("*")->where("level={$level}")->select();
return $result;
}

@ -72,6 +72,14 @@
</volist>
</select>
</div>
<div class="input-list">
<select name="child_id" class="select_gallery" style="width:120px;">
<option value="">四级推广员</option>
<volist name=":promote_lists(4)" id="vo">
<option value="{$vo.id}">{$vo.account}</option>
</volist>
</select>
</div>
<div class="input-list">
<a class="sch-btn" href="javascript:;" id="search" url="{:U('record','model='.$model['name'] .'&row='.I('row'),false)}">搜索</a>
</div>
@ -92,6 +100,7 @@
<th>一级推广员</th>
<th>二级推广员</th>
<th>三级推广员</th>
<th>四级推广员</th>
<th>转移数量</th>
<th>转移时间</th>
</tr>
@ -108,8 +117,9 @@
<tr>
<!-- <td><input class="ids" type="checkbox" value="{$data['id']},{$data.file_type},{$data['game_id']}" name="ids[]"></td> -->
<td>{:get_promote_account($data['promote_id'])}</td>
<td><if condition="$data['parent_id'] gt 0 and $data['grand_id'] eq 0 ">{$data['source_name']}<else />--</if></td>
<td><if condition="$data['parent_id'] gt 0 and $data['grand_id'] gt 0 ">{$data['source_name']}<else />--</if></td>
<td><if condition="$data['level'] eq 2 ">{$data['source_name']}<else />--</if></td>
<td><if condition="$data['level'] eq 3 ">{$data['source_name']}<else />--</if></td>
<td><if condition="$data['level'] eq 4 ">{$data['source_name']}<else />--</if></td>
<td>{$data.num}</td>
<td>{:time_format($data['create_time'])}</td>
</tr>
@ -148,6 +158,8 @@
Think.setValue("promote_id","{:I('promote_id')}");
Think.setValue("promote_type","{:I('promote_type')}");
Think.setValue("source_id","{:I('source_id')}");
Think.setValue("grand_id","{:I('grand_id')}");
Think.setValue("child_id","{:I('child_id')}");
Think.setValue("row","{:I('row',10)}");
$(".select_gallery").select2();

Loading…
Cancel
Save