DiverseYouthNightSchool/application/common/library/NightSchoolBigData.php

225 lines
9.0 KiB
PHP
Raw Normal View History

2025-01-08 10:50:01 +08:00
<?php
namespace app\common\library;
use addons\epay\library\Service;
2025-01-08 10:50:01 +08:00
use app\common\model\BaseModel;
use app\common\model\manystore\Shop;
use app\common\model\school\Area;
use app\common\model\school\classes\activity\Activity;
2025-01-08 10:50:01 +08:00
use app\common\model\school\classes\ClassesLib;
use app\common\model\school\classes\hourorder\Order;
use app\common\model\school\classes\Teacher;
use app\common\model\school\classes\Type;
use app\common\model\User;
2025-01-08 10:50:01 +08:00
/**
* 夜校大数据类
*/
class NightSchoolBigData extends BaseModel
{
public static function getAreaBaseData($province,$city,$district){
$whereArea = function ($query)use($province,$city,$district){
$query = $query->where('1=1');
2025-01-08 10:50:01 +08:00
if( $province)$query = $query->where('province',$province);
if( $city)$query = $query->where('city',$city);
if( $district)$query = $query->where('district',$district);
};
//统计当前课程总数
$classes_num = ClassesLib::where($whereArea)->count();
2025-01-08 10:50:01 +08:00
$activity_num = Activity::where($whereArea)->count();
//统计当前总报名人数
$classes_sign_num = ClassesLib::where($whereArea)->sum('sign_num');
2025-01-08 10:50:01 +08:00
$activity_sign_num = Activity::where($whereArea)->sum('sign_num');
//认证讲师数量
$shop_ids = implode(",",Shop::where($whereArea)->column("id"));
if($shop_ids){
$teacher_num = Teacher::where('shop_id','in',$shop_ids)->count();
//近七天报名数量
$classes_sign_num_7 = Order::where("shop_id",'in',$shop_ids)->where("status","in",["-1","0","3"])->whereTime('createtime', 'between', [strtotime("-7 day"), time()])->count();
$activity_sign_num_7 = \app\common\model\school\classes\activity\order\Order::where("shop_id",'in',$shop_ids)->whereTime('createtime', 'between', [strtotime("-7 day"), time()])->where("status","not in",["-3","6"])->count();
}else{
$teacher_num = Teacher::count();
$classes_sign_num_7 = Order::where("status","in",["-1","0","3"])->whereTime('createtime', 'between', [strtotime("-7 day"), time()])->count();
$activity_sign_num_7 = \app\common\model\school\classes\activity\order\Order::whereTime('createtime', 'between', [strtotime("-7 day"), time()])->where("status","not in",["-3","6"])->count();
}
//所有课程累计访问
$classes_views = ClassesLib::where($whereArea)->sum('views');
$activity_views = Activity::where($whereArea)->sum('views');
//注册总人数
$user_num = User::count();
//总点击
$visitn_nmber = Virtual::getVisitNnmber();
return compact( "activity_views","activity_sign_num" , "activity_sign_num_7","user_num","activity_num","visitn_nmber",'classes_num','classes_sign_num','teacher_num','classes_sign_num_7','classes_views');
}
/** 累计报名人数
* @return
*/
public static function accumulatedNumberOfApplicants(){
//得到所有类型课程类型
$types = Type::where("status",'1')->select();
foreach ($types as &$type){
$type["classes_views"] = ClassesLib::where("classes_type",$type["id"])->sum('views');
$type["classes_sign_num"] = ClassesLib::where("classes_type",$type["id"])->sum('sign_num');
$type["classes_num"] = ClassesLib::where("classes_type",$type["id"])->count();
}
return $types;
}
public static function getAreaData($province,$city){
$model = new Area();
if($province && !$city){
$model = $model->where("pid",$province)->where("level",2);
}elseif ($city){
$model = $model->where("pid",$city)->where("level",3);
}else{
$model = $model->where("level",1);
}
$data = $model->order('id asc')->field('id as value, name as label, pid, level')->select();
return $data;
}
public static function getAreaDataLevel($province,$city){
if($province && !$city){
$level = "city";
}elseif ($city){
$level = "district";
}else{
$level = "province";
}
return $level;
}
/** 各区域上课数量和上课人数
*
*/
public static function numberOfClassesInEachRegion($province,$city,$time=null){
$areas = self::getAreaData($province,$city);
$level = self::getAreaDataLevel($province,$city);
foreach ($areas as &$area){
$classes_num_model = new ClassesLib;
if ($time){
$classes_num_model = $classes_num_model->time(["createtime",$time]);
}
//课程数量
$area["classes_num"] = $classes_num_model->where($level,$area["value"])->count();
if ($time){
$classesLibIds = implode(",",ClassesLib::where($level,$area["value"])->column('id'));
$area["classes_sign_num"] = Order::where("classes_lib_id",'in',$classesLibIds)->where("status","in",["-1","0","3"])->time(["createtime",$time])->count();
}else{
$area["classes_sign_num"] = ClassesLib::where($level,$area["value"])->sum('sign_num');
}
//结束时间过了当前时间为往期课程
// 往期直接统计限定人数
// $area["classes_sign_num_past"] = ClassesLib::where($level,$area["value"])->where("end_time","<",time())->sum('limit_num');
//
// //非往期课程统计报名人数
// $area["classes_sign_num"] = ClassesLib::where($level,$area["value"])->where("end_time",">=",time())->sum('sign_num');
// $area["classes_sign_num"] = $area["classes_sign_num"]+$area["classes_sign_num_past"];
// unset( $area["classes_sign_num_past"]);
}
return $areas;
}
/** 七天内报名人数
* @return
*/
public static function accumulatedSevenNumberOfApplicants(){
//得到所有类型课程类型
$types = Type::where("status",'1')->select();
//得到从今天开始往前七天的每天的开始和结束时间
$dates = [];
for ($i=0;$i<7;$i++){
$date = [
"today"=>false,
"start"=>strtotime("-".$i." day",strtotime(date("Y-m-d 0:0:0",time())) ),
"end"=>strtotime("-".($i-1)." day",strtotime(date("Y-m-d 0:0:0",time())))-1,
];
$date["text"] = date("m.d",$date["start"]);
if ($i==0){
$date["today"] = true;
$date["text"] = "今日";
}
$dates[] = $date;
}
$dates = array_reverse($dates);
$type_data = [];
foreach ($dates as &$time){
foreach ($types as &$type){
$classesLibIds = implode(",",ClassesLib::where("classes_type",$type["id"])->column('id'));
if(!isset($type_data[$type["id"]]))$type_data[$type["id"]]= $type->toArray();
//加入时间查询条件
$type_data[$type["id"]]["classes_sign_num"][] = Order::where( "createtime",'between',[$time["start"],$time["end"]])->where("classes_lib_id",'in',$classesLibIds)->where("status","in",["-1","0","3"])->count();
$type_data[$type["id"]]["classes_nums"][] = ClassesLib::where( "createtime",'between',[$time["start"],$time["end"]])->where("classes_type",$type["id"])->count();
}
}
return compact("dates","type_data");
}
/**前N名累计活跃课程
*
*/
public static function topNCumulativeActiveCourses($N){
//浏览量views 前N的课程
$classes_views = ClassesLib::field( "id,title,views,sign_num,weigh")->order("views desc,sign_num desc,id desc")->limit($N)->select();
return ["classes_views"=>$classes_views];
2025-01-08 10:50:01 +08:00
}
/** 七天内活动报名人数和活跃热度
* @return
*/
public static function accumulatedSevenNumberOfActivity(){
//得到从今天开始往前七天的每天的开始和结束时间
$dates = [];
for ($i=0;$i<7;$i++){
$date = [
"today"=>false,
"start"=>strtotime("-".$i." day",strtotime(date("Y-m-d 0:0:0",time())) ),
"end"=>strtotime("-".($i-1)." day",strtotime(date("Y-m-d 0:0:0",time())))-1,
];
$date["text"] = date("m.d",$date["start"]);
if ($i==0){
$date["today"] = true;
$date["text"] = "今日";
}
$dates[] = $date;
}
$dates = array_reverse($dates);
$type_data = [];
foreach ($dates as &$time){
//加入时间查询条件
$type_data["activity_sign_num"][] = \app\common\model\school\classes\activity\order\Order::where( "createtime",'between',[$time["start"],$time["end"]])->where("status","not in",["-3","6"])->count();
$type_data["activity_num"][] = Activity::where( "createtime",'between',[$time["start"],$time["end"]])->count();
}
return compact("dates","type_data");
}
2025-01-08 10:50:01 +08:00
}