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

124 lines
4.7 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
// +----------------------------------------------------------------------
// | 每日12更新数据统计缓存 [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
namespace app\admin\controller;
use app\common\controller\Admin;
use think\Cache;
use think\Controller;
class Dailyupcache extends Controller{
public function index(){
$info = $this->orderCoutInfo();
$a = Cache::store('redis')->set('info-30',$info);
}
//订单大数据统计 30天数据展示
public function orderCoutInfo(){
$sourceid = 1;
$agentid = '';
$wxmpid = '';
$map = array();
$nowday= date('Y-m-d');
$info=array();
// 30天历史统计列表
for($i=30;$i>=1;$i--){
$date=strtotime($nowday)-(30-$i)*24*3600;
$map['create_time'] = array(array('gt',$date),array('lt',$date+86399));
$map['status'] = 1;
$info[date('Y-m-d',$date)] = array(
// 充值金额
"pay"=> db('order')->where('iscontrol',0)->where($map)->sum('money'),
// 普通充值
"paynormal"=> db('order')->where('iscontrol',0)->where($map)->where(array(
'type'=>1
))->sum('money'),
"normalnum"=> db('order')->where('iscontrol',0)->where(array_merge($map,array('type'=>1)))->count('uid'),//普通充值人数
"payvip"=> db('order')->where('iscontrol',0)->where($map)->where(array(
'type'=>2
))->sum('money'),//年费VIP会员充值金额
"vipnum"=> db('order')->where('iscontrol',0)->where(array_merge($map,array('type'=>2)))->count(),//充值人数
"payOffer"=> db('order')->where('iscontrol',0)->where($map)->where(array(
'type'=>3
))->sum('money'),//活动充值充值金额
"Offernum"=> db('order')->where('iscontrol',0)->where(array_merge($map,array('type'=>3)))->count(),//活动充值充值人数
"payPaid"=>$this->statistics($wxmpid,$sourceid,'1',0,$date,$date+86399,1,1,0,0,$agentid),//普通充值支付订单数
"payUnpaid"=> $this->statistics($wxmpid,$sourceid,'1',0,$date,$date+86399,1,0,0,0,$agentid),//未付款
"payYaerPaid"=>$this->statistics($wxmpid,$sourceid,'1',0,$date,$date+86399,2,1,0,0,$agentid),//年费VIP会员支付订单数
"payYaerUnpaid"=> $this->statistics($wxmpid,$sourceid,'1',0,$date,$date+86399,2,0,0,0,$agentid),//未付款
"payOfferPaid"=>$this->statistics($wxmpid,$sourceid,'1',0,$date,$date+86399,3,1,0,0,$agentid),//活动充值支付订单数
"payOfferUnpaid"=> $this->statistics($wxmpid,$sourceid,'1',0,$date,$date+86399,3,0,0,0,$agentid),//活动充值未付款
);
}
return $info;
}
/**
* statistics [充值笔数]
*
* @param type $sourceid [来源 1cps 2APP]
* @param type $model [1:小说,2:漫画]
* @param type $is_kouliang [是否扣量]
* @param type $startData [开始时间]
* @param type $endData [结束时间]
* @param type $type [订单类型]
* @param type $status [订单状态]
* @param type $recharge_type [充值方式 1直接充值 2引导充值]
* @return type
**/
protected function statistics($wxmpid,$sourceid,$model='1',$is_kouliang=0,$startData,$endData,$type=0,$status=0,$articleid=0,$recharge_type=0,$agentid=0) {
if($startData && $endData){
$map['create_time'] = array(array('gt',$startData),array('lt',$endData)) ;
}
if($sourceid){
$map['sourceid'] = $sourceid;
}
if($type){
$map['type'] = array('in',$type);
}
if($recharge_type){
$map['recharge_type'] = $recharge_type;
}
if($articleid){
$map['articleid'] = $articleid;
}
if(strpos($model,",")!==false){
$map['model'] = array('IN',$model);
}else{
$map['model'] = $model;
}
if($is_kouliang){
$map['is_kouliang'] = 1;
}else{
$map['is_kouliang'] = 0;
}
$map['status'] = $status;
if($endData<strtotime(date("Y-m-d"))){
$cachename = 'statistics'.md5(serialize($map));
$total = db('order')->where('iscontrol',0)->where($map)->count();
}else{
$total = db('order')->where('iscontrol',0)->where($map)->count();
}
return $total;
}
}