|
|
<?php
|
|
|
// +----------------------------------------------------------------------
|
|
|
// | OneThink [ WE CAN DO IT JUST THINK IT ]
|
|
|
// +----------------------------------------------------------------------
|
|
|
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
|
|
|
// +----------------------------------------------------------------------
|
|
|
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
|
|
|
// +----------------------------------------------------------------------
|
|
|
|
|
|
namespace Home\Model;
|
|
|
use Think\Model;
|
|
|
|
|
|
/**
|
|
|
* 分类模型
|
|
|
*/
|
|
|
class SpendModel extends Model{
|
|
|
|
|
|
protected $_validate = array(
|
|
|
|
|
|
);
|
|
|
|
|
|
protected $_auto = array(
|
|
|
);
|
|
|
|
|
|
/**
|
|
|
* 构造函数
|
|
|
* @param string $name 模型名称
|
|
|
* @param string $tablePrefix 表前缀
|
|
|
* @param mixed $connection 数据库连接信息
|
|
|
*/
|
|
|
public function __construct($name = '', $tablePrefix = '', $connection = '') {
|
|
|
/* 设置默认的表前缀 */
|
|
|
$this->tablePrefix ='tab_';
|
|
|
/* 执行构造方法 */
|
|
|
parent::__construct($name, $tablePrefix, $connection);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 按照时间分组统计充值总额
|
|
|
* @param integer $start 开始时间(时间戳)
|
|
|
* @param integer $end 结束时间(时间戳)
|
|
|
* @param integer $game_id 游戏编号
|
|
|
* @param integer/string $promote_id 渠道编号或渠道编号列表字符串(字符串逗号分隔)
|
|
|
* @return array 详细数据
|
|
|
* @author 鹿文学
|
|
|
*/
|
|
|
public function money_amount_by_time($start,$end,$game_id=0,$promote_id=0,$bangbi=true) {
|
|
|
|
|
|
$map['pay_status']=1;
|
|
|
|
|
|
$map['pay_time'] = array('between',array($start,$end));
|
|
|
|
|
|
$map['game_id'] = $game_id>0?$game_id:array('gt',0);
|
|
|
|
|
|
$map['promote_id'] = is_numeric($promote_id)?$promote_id:array('in',$promote_id);
|
|
|
|
|
|
$map['pay_way'] = $bangbi ? array('neq','-10') : array('neq',-1);
|
|
|
|
|
|
$field = 'FROM_UNIXTIME(pay_time,"%Y-%m-%d") as pay_time,sum(pay_amount) as money_amount';
|
|
|
|
|
|
|
|
|
$data = $this->field($field)->where($map)->group('FROM_UNIXTIME(pay_time,"%Y-%m-%d")')->select();
|
|
|
|
|
|
return $data;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 统计给定时间前的付费玩家总数
|
|
|
* @param integer $start 开始时间(时间戳)
|
|
|
* @param integer $game_id 游戏编号
|
|
|
* @param integer/string $promote_id 渠道编号或渠道编号列表字符串(字符串逗号分隔)
|
|
|
* @return integer 结果
|
|
|
* @author 鹿文学
|
|
|
*/
|
|
|
public function payUsersStatisticsAgo($start,$game_id,$promote_id,$bangbi=true) {
|
|
|
|
|
|
$map['pay_status']=1;
|
|
|
|
|
|
$map['pay_time'] = array('lt',$start);
|
|
|
|
|
|
$map['game_id'] = $game_id>0?$game_id:array('gt',0);
|
|
|
|
|
|
$map['promote_id'] = is_numeric($promote_id)?$promote_id:array('in',$promote_id);
|
|
|
|
|
|
$map['pay_way'] = $bangbi ? array('neq','-10') : array('neq',-1);
|
|
|
|
|
|
$data = $this->field('count(DISTINCT user_id) as user_id')->where($map)->select();
|
|
|
|
|
|
return $data[0]['user_id']?$data[0]['user_id']:0;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 按照时间分组统计付费玩家总数
|
|
|
* @param integer $start 开始时间(时间戳)
|
|
|
* @param integer $end 结束时间(时间戳)
|
|
|
* @param integer $game_id 游戏编号
|
|
|
* @param integer/string $promote_id 渠道编号或渠道编号列表字符串(字符串逗号分隔)
|
|
|
* @return array 详细数据
|
|
|
* @author 鹿文学
|
|
|
*/
|
|
|
public function pay_count_by_time($start,$end,$game_id=0,$promote_id=0,$bangbi=true) {
|
|
|
|
|
|
$map['pay_status']=1;
|
|
|
|
|
|
$map['pay_time'] = array('between',array($start,$end));
|
|
|
|
|
|
$map['game_id'] = $game_id>0?$game_id:array('gt',0);
|
|
|
|
|
|
$map['promote_id'] = is_numeric($promote_id)?$promote_id:array('in',$promote_id);
|
|
|
|
|
|
$map['pay_way'] = $bangbi ? array('neq','-10') : array('neq',-1);
|
|
|
|
|
|
$field = 'FROM_UNIXTIME(pay_time,"%Y-%m-%d") as pay_time,user_id as pay_num';
|
|
|
|
|
|
$subTable = $this->field($field)->where($map)->group('pay_time')->buildSql();
|
|
|
|
|
|
return $this->field('a.pay_time,count(distinct a.pay_num) as pay_num')->table('(' . $subTable . ') as a')->group('a.pay_time')->select();
|
|
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 按照时间分组统计付费玩家总数
|
|
|
* @param integer $start 开始时间(时间戳)
|
|
|
* @param integer $end 结束时间(时间戳)
|
|
|
* @param integer $game_id 游戏编号
|
|
|
* @param integer/string $promote_id 渠道编号或渠道编号列表字符串(字符串逗号分隔)
|
|
|
* @return array 详细数据
|
|
|
* @author 鹿文学
|
|
|
*/
|
|
|
public function pay_game_by_time($start,$end,$game_id=0,$promote_id=0,$bangbi=true) {
|
|
|
|
|
|
$map['pay_status']=1;
|
|
|
|
|
|
$map['pay_time'] = array('between',array($start,$end));
|
|
|
|
|
|
$map['game_id'] = $game_id>0?$game_id:array('gt',0);
|
|
|
|
|
|
$map['promote_id'] = is_numeric($promote_id)?$promote_id:array('in',$promote_id);
|
|
|
|
|
|
$map['pay_way'] = $bangbi ? array('neq','-10') : array('neq',-1);
|
|
|
|
|
|
$field = 'FROM_UNIXTIME(pay_time,"%Y-%m-%d") as pay_time,game_id as pay_num';
|
|
|
|
|
|
$sql = $this->field($field)->where($map)->group('pay_time')->select(false);
|
|
|
$data = $this->field('a.pay_time,count(DISTINCT a.pay_num) as pay_num')->table('('.$sql.') as a')->group('a.pay_time')->select();
|
|
|
// dump($this->getlastsql());exit;
|
|
|
return $data;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 按照时间分组统计付费玩家总数(新付费用户指用户第一次付费)
|
|
|
* @param array $daylist 时间序列
|
|
|
* @param integer $game_id 游戏编号
|
|
|
* @param integer/string $promote_id 渠道编号或渠道编号列表字符串(字符串逗号分隔)
|
|
|
* @param integer $flag 类别(1:新玩家,2:老玩家)
|
|
|
* @return array 详细数据
|
|
|
* @author 鹿文学
|
|
|
*/
|
|
|
public function pay_count_by_time_class_game($daylist,$game_id=0,$promote_id=0,$flag=1,$bangbi=true) {
|
|
|
|
|
|
$map['pay_status']=1;
|
|
|
|
|
|
$oldmap['game_id'] = $map['game_id'] = $game_id>0?$game_id:array('gt',0);
|
|
|
|
|
|
$map['promote_id'] = is_numeric($promote_id)?$promote_id:array('in',$promote_id);
|
|
|
|
|
|
$map['pay_way'] = $bangbi ? array('neq','-10') : array('neq',-1);
|
|
|
|
|
|
if ($flag == 1) {$str='user_id not in ';$map['_string']='(small_id=0 or small_id=user_id)';} else {$str = 'user_id in';}
|
|
|
|
|
|
foreach ($daylist as $value) {
|
|
|
|
|
|
$time = strtotime($value);
|
|
|
|
|
|
$oldmap['pay_time'] = array('lt',$time);
|
|
|
|
|
|
$old_sdk_id=$this->field('user_id')
|
|
|
|
|
|
->where($oldmap)->group('user_id')
|
|
|
|
|
|
->buildSql();
|
|
|
|
|
|
$map['pay_time'] = array(array('egt',$time),array('elt',strtotime("+1 day",$time)-1));
|
|
|
$map['_string'] = $map['_string']?($map['_string'].' and '.$str.$old_sdk_id):($str.$old_sdk_id);
|
|
|
$sql=$this
|
|
|
->field('user_id,FROM_UNIXTIME(pay_time,"%Y-%m-%d") as pay_time')
|
|
|
|
|
|
|
|
|
->where($map)
|
|
|
->group('user_id')
|
|
|
->buildSql();
|
|
|
|
|
|
$d = $this->query('select count(a.user_id) as pay_num, a.pay_time as pay_time from '.$sql.' as a group by pay_time');
|
|
|
|
|
|
|
|
|
if ($d)
|
|
|
$data[]=$d[0];
|
|
|
|
|
|
}
|
|
|
|
|
|
return $data;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 按照时间分组统计付费玩家付费数(新付费用户指用户第一次付费)
|
|
|
* @param array $daylist 时间序列
|
|
|
* @param integer $game_id 游戏编号
|
|
|
* @param integer/string $promote_id 渠道编号或渠道编号列表字符串(字符串逗号分隔)
|
|
|
* @param integer $flag 类别(1:新玩家,2:老玩家)
|
|
|
* @return array 详细数据
|
|
|
* @author 鹿文学
|
|
|
*/
|
|
|
public function pay_sum_by_time_class_game($daylist,$game_id=0,$promote_id=0,$flag=1,$bangbi=true) {
|
|
|
$map['pay_status']=1;
|
|
|
$oldmap['game_id'] = $map['game_id'] = $game_id>0?$game_id:array('gt',0);
|
|
|
$map['promote_id'] = is_numeric($promote_id)?$promote_id:array('in',$promote_id);
|
|
|
$map['pay_way'] = $bangbi ? array('neq','-10') : array('neq',-1);
|
|
|
if ($flag == 1) {$str='user_id not in ';$map['_string']='(small_id=0 or small_id=user_id)';} else {$str = 'user_id in';}
|
|
|
foreach ($daylist as $value) {
|
|
|
$time = strtotime($value);
|
|
|
$oldmap['pay_time'] = array('lt',$time);
|
|
|
$old_sdk_id=$this->field('user_id')
|
|
|
->where($oldmap)->group('user_id')
|
|
|
->buildSql();
|
|
|
$map['pay_time'] = array(array('egt',$time),array('elt',strtotime("+1 day",$time)-1));
|
|
|
$map['_string'] = $map['_string']?($map['_string'].' and '.$str.$old_sdk_id):($str.$old_sdk_id);
|
|
|
$sql=$this
|
|
|
->field('user_id,pay_amount,FROM_UNIXTIME(pay_time,"%Y-%m-%d") as pay_time')
|
|
|
|
|
|
->where($map)
|
|
|
->buildSql();
|
|
|
$d = $this->query('select sum(a.pay_amount) as pay_sum, a.pay_time as pay_time from '.$sql.' as a group by pay_time');
|
|
|
|
|
|
if ($d)
|
|
|
$data[]=$d[0];
|
|
|
}
|
|
|
return $data;
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 按照时间分组统计付费玩家总数
|
|
|
* @param array $daylist 时间序列
|
|
|
* @param integer $game_id 游戏编号
|
|
|
* @param integer/string $promote_id 渠道编号或渠道编号列表字符串(字符串逗号分隔)
|
|
|
* @param integer $flag 类别(1:新玩家,2:老玩家)
|
|
|
* @return array 详细数据
|
|
|
* @author 鹿文学
|
|
|
*/
|
|
|
public function pay_count_by_time_class($daylist,$game_id=0,$promote_id=0,$flag=1,$bangbi=true) {
|
|
|
|
|
|
$map['pay_status']=1;
|
|
|
|
|
|
$map['game_id'] = $game_id>0?$game_id:array('gt',0);
|
|
|
|
|
|
$map['promote_id'] = is_numeric($promote_id)?$promote_id:array('in',$promote_id);
|
|
|
|
|
|
$map['pay_way'] = $bangbi ? array('neq','-10') : array('neq',-1);
|
|
|
|
|
|
if ($flag == 1) {$str='user_id not in ';$map['_string']='(small_id=0 or small_id=user_id)';} else {$str = 'user_id in';}
|
|
|
|
|
|
foreach ($daylist as $value) {
|
|
|
|
|
|
$time = strtotime($value);
|
|
|
|
|
|
$old_sdk_id=$this->field('user_id')
|
|
|
|
|
|
->where(array('pay_time'=>array('lt',$time)))->group('user_id')
|
|
|
|
|
|
->buildSql();
|
|
|
|
|
|
$map['pay_time'] = array(array('egt',$time),array('elt',strtotime("+1 day",$time)-1));
|
|
|
$map['_string'] = $map['_string']?($map['_string'].' and '.$str.$old_sdk_id):($str.$old_sdk_id);
|
|
|
$sql=$this
|
|
|
->field('user_id,FROM_UNIXTIME(pay_time,"%Y-%m-%d") as pay_time')
|
|
|
|
|
|
->where($map)
|
|
|
->group('user_id')
|
|
|
->buildSql();
|
|
|
|
|
|
$d = $this->query('select count(a.user_id) as pay_num, a.pay_time as pay_time from '.$sql.' as a group by pay_time');
|
|
|
|
|
|
|
|
|
if ($d)
|
|
|
$data[]=$d[0];
|
|
|
|
|
|
}
|
|
|
|
|
|
return $data;
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|