2023-01-29 10:26:52 +08:00

145 lines
6.7 KiB
PHP

<?php
// +----------------------------------------------------------------------
// | 小说系统 推广链接数据详情 [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
namespace app\admin\controller;
use app\common\controller\Admin;
use Think\Cache;
class Spreadinfo extends Admin {
public function beinfo()
{
$data = input('');
if ($data) {
$id = $data['id'];
$articleid = db('tuiguang')->where('id',$id)->value('articleid');
$date = $data['date'];
$starttime = strtotime( date("Y-m-d") ); //今日凌晨
$endtime = time(); //当前时间
if($date == 2){
$starttime = strtotime( date("Y-m-d",strtotime("-1 day")) ); //昨日凌晨
$endtime = strtotime( date("Y-m-d") ); //今日凌晨
}
if($date == 3){
$starttime = strtotime( date("Y-m-01") ); //本月第一天
}
if($date == 4){
$starttime = strtotime( date('Y-m-01', strtotime('-1 month')) ); //上月第一天
$endtime = strtotime( date('Y-m-t', strtotime('-1 month')) ) + 86399; //上月最后一天
}
if($date == 5){
$starttime = 946656000;
}
$list = db('chapter')->field('id,chapterorder,chaptername,isvip')->where('articleid',$articleid)->order('chapterorder asc')->select();
if($list){
foreach($list as $k=>$v){
$num = $v['chapterorder'] + 1;
$list[$k]['seenum'] = db('history_read')
->where('articleid',$articleid)
->where('order',$v['chapterorder'])
->whereTime('create_time', 'between', [$starttime,$endtime])
->count('distinct(uid)');
if($num > 0){
$list[$k]['survivenum'] = db('history_read')
->where('articleid',$articleid)->where('order',$num)
->whereTime('create_time', 'between', [$starttime,$endtime])
->count('distinct(uid)');
if(empty($list[$k]['survivenum'])){
$list[$k]['survivenum'] = $list[$k]['seenum'];
}
}else{
$list[$k]['survivenum'] = $list[$k]['seenum'];
}
if($list[$k]['survivenum'] > $list[$k]['seenum']){
$list[$k]['survivenum'] = $list[$k]['seenum'];
$list[$k]['nums'] = 0;
}else{
$list[$k]['nums'] = $list[$k]['seenum'] - $list[$k]['survivenum'];
}
if(empty($list[$k]['subscription'])){
$list[$k]['subscription'] = 0;
}
if($v['isvip']==1){
$list[$k]['seenum'] = '-';
$list[$k]['nums'] = '-';
$list[$k]['chaptername'] = $v['chaptername'].' vip';
}
}
exit(json_encode(array('status'=>1,'reg'=>'成功','data'=>$list)));
}else{
exit(json_encode(array('status'=>2,'reg'=>'无数据')));
}
}
}
public function beinfopay()
{
$data = input('');
if ($data) {
$id = $data['id'];
$articleid = db('tuiguang')->where('id',$id)->value('articleid');
$chapterid = db('chapter')->where('articleid',$articleid)->where('isvip', '=' ,1)->value('id');
$date = $data['date'];
$starttime = strtotime( date("Y-m-d") ); //今日凌晨
$endtime = time(); //当前时间
if($date == 2){
$starttime = strtotime( date("Y-m-d",strtotime("-1 day")) ); //昨日凌晨
$endtime = strtotime( date("Y-m-d") ); //今日凌晨
}
if($date == 3){
$starttime = strtotime( date("Y-m-01") ); //本月第一天
}
if($date == 4){
$starttime = strtotime( date('Y-m-01', strtotime('-1 month')) ); //上月第一天
$endtime = strtotime( date('Y-m-t', strtotime('-1 month')) ) + 86399; //上月最后一天
}
if($date == 5){
$starttime = 946656000;
}
$list = db('order')->where('iscontrol',0)->where('articleid',$articleid)->where('status',1)->where('money','>','9.9')->where('channel',$id)->where('is_complex',1)->whereTime('create_time', 'between', [$starttime,$endtime])->field('uid,create_time')->group('uid')->select();
$array = array();
if($list){
$i = 0;
foreach($list as $k=>$v){
$list[$k]['starttime'] = db('history_read')->where('articleid',$articleid)->where('uid',$v['uid'])->order('id asc')->value('create_time');
$list[$k]['duration'] = $v['create_time'] - $list[$k]['starttime'];
if($list[$k]['duration'] < 180 || $list[$k]['duration'] > 1200){
$array[$k] = $v;
$array[$k]['duration'] = $this->changeTimeType($list[$k]['duration']);
$array[$k]['starttime'] = date("Y-m-d H:i:s", $list[$k]['starttime']);
$array[$k]['create_time'] = date("Y-m-d H:i:s", $v['create_time']);
unset($list[$k]);
}else{
$i += $list[$k]['duration'];
$list[$k]['duration'] = $this->changeTimeType($list[$k]['duration']);
$list[$k]['starttime'] = date("Y-m-d H:i:s", $list[$k]['starttime']);
$list[$k]['create_time'] = date("Y-m-d H:i:s", $v['create_time']);
}
}
if($i){
$i = intval($i / count($list));
$i = '平均时长:'.$this->changeTimeType($i);
}
exit(json_encode(array('status'=>1,'reg'=>'成功','data'=>$list,'array'=>$array,'num'=>$i)));
}else{
exit(json_encode(array('status'=>2,'reg'=>'无数据')));
}
}
}
function changeTimeType($seconds){
if ($seconds > 3600){
$hours = intval($seconds/3600);
$minutes = $seconds % 3600;
if($hours){
$time = $hours."".gmstrftime('%M分%S秒', $minutes);
}else{
$time = gmstrftime('%M:%S', $minutes);
}
}else{
$time = gmstrftime('%M分%S秒', $seconds);
}
return $time;
}
}