数据驾驶舱接口编写

机构后台订单百万级导出
This commit is contained in:
15090180611 2025-01-08 18:05:59 +08:00
parent c522d234a0
commit 823852b0a6
7 changed files with 756 additions and 6 deletions

View File

@ -2,6 +2,7 @@
namespace app\api\controller; namespace app\api\controller;
use addons\epay\library\Service;
use app\admin\model\school\help\Cate; use app\admin\model\school\help\Cate;
use app\common\controller\Api; use app\common\controller\Api;
use app\common\job\test\DemoJob; use app\common\job\test\DemoJob;
@ -72,7 +73,12 @@ class Demo extends Api
//数字加1 //数字加1
//再存入缓存 //再存入缓存
//再写入test.txt文件末尾记得回车换行 //再写入test.txt文件末尾记得回车换行
file_put_contents("test.txt",$num."\r\n",FILE_APPEND); // file_put_contents("test.txt",$num."\r\n",FILE_APPEND);
// 实例对应的接口对象
$scheme = new \WeMini\Total(Service::wechatConfig());
$res= $scheme->create($q_params);
}catch (\Throwable $e){ }catch (\Throwable $e){
$lock->free(); $lock->free();

View File

@ -2,6 +2,7 @@
namespace app\api\controller; namespace app\api\controller;
use addons\epay\library\Service;
use app\common\controller\Api; use app\common\controller\Api;
use app\common\library\Sqlscript; use app\common\library\Sqlscript;
use app\common\library\Virtual; use app\common\library\Virtual;
@ -163,4 +164,35 @@ class Index extends Api
} }
/**
* @ApiTitle(微信小程序访问分析)
* @ApiSummary(微信小程序访问分析)
* @ApiMethod(POST)
* @ApiParams (name="begin_date", type="string", required=true, description="开始日期。格式为 yyyymmdd 如20170611 开始日期")
* @ApiParams (name="end_date", type="string", required=true, description="结束日期,格式为 yyyymmdd 如20170611 结束日期限定查询1天数据end_date允许设置的最大值为昨日")
* @ApiReturn({
"code" => 1,
"msg" => "获取成功",
"data" => {}
*})
*/
public function getWeanalysisAppidDailyVisittrend() {
$begin_date = $this->request->post('begin_date/s',0);
$end_date = $this->request->post('end_date/s',0);
try {
// 实例对应的接口对象
$weMiniTotal = new \WeMini\Total(Service::wechatConfig());
$res = $weMiniTotal->getWeanalysisAppidDailyVisittrend($begin_date, $end_date);
} catch (\Exception $e){
// Log::log($e->getMessage());
$this->error($e->getMessage(),['errcode'=>$e->getCode()]);
}
$this->success('生成成功', $res);
}
} }

View File

@ -11,7 +11,7 @@ use app\common\model\style\HomeImages;
*/ */
class WechatUtil extends Api class WechatUtil extends Api
{ {
protected $noNeedLogin = ['scheme','link',"codeunlimit"]; protected $noNeedLogin = '*';
protected $noNeedRight = ['*']; protected $noNeedRight = ['*'];
@ -191,4 +191,303 @@ class WechatUtil extends Api
/**
* @ApiTitle(微信小程序生成用户画像)
* @ApiSummary(微信小程序生成用户画像)
* @ApiMethod(POST)
* @ApiParams (name="begin_date", type="string", required=true, description="开始日期。格式为 yyyymmdd 如20170611")
* @ApiParams (name="end_date", type="string", required=true, description="结束日期,格式为 yyyymmdd 如20170611 开始日期与结束日期相差的天数限定为0/6/29分别表示查询最近1/7/30天数据end_date允许设置的最大值为昨日")
* @ApiReturn({
"code" => 1,
"msg" => "获取成功",
"data" => {}
*})
*/
public function getWeanalysisAppidUserportrait() {
$begin_date = $this->request->post('begin_date/s',0);
$end_date = $this->request->post('end_date/s',0);
try {
// 实例对应的接口对象
$weMiniTotal = new \WeMini\Total(Service::wechatConfig());
$res = $weMiniTotal->getWeanalysisAppidUserportrait($begin_date, $end_date);
} catch (\Exception $e){
// Log::log($e->getMessage());
$this->error($e->getMessage(),['errcode'=>$e->getCode()]);
}
$this->success('生成成功', $res);
}
/**
* @ApiTitle(微信小程序访问页面)
* @ApiSummary(微信小程访问页面)
* @ApiMethod(POST)
* @ApiParams (name="begin_date", type="string", required=true, description="开始日期。格式为 yyyymmdd 如20170611")
* @ApiParams (name="end_date", type="string", required=true, description="结束日期,格式为 yyyymmdd 如20170611 结束日期限定查询1天数据end_date允许设置的最大值为昨日")
* @ApiReturn({
"code" => 1,
"msg" => "获取成功",
"data" => {}
*})
*/
public function getWeanalysisAppidVisitPage() {
$begin_date = $this->request->post('begin_date/s',0);
$end_date = $this->request->post('end_date/s',0);
try {
// 实例对应的接口对象
$weMiniTotal = new \WeMini\Total(Service::wechatConfig());
$res = $weMiniTotal->getWeanalysisAppidVisitPage($begin_date, $end_date);
} catch (\Exception $e){
// Log::log($e->getMessage());
$this->error($e->getMessage(),['errcode'=>$e->getCode()]);
}
$this->success('生成成功', $res);
}
/**
* @ApiTitle(微信小程序月留存)
* @ApiSummary(微信小程序月留存)
* @ApiMethod(POST)
* @ApiParams (name="begin_date", type="string", required=true, description="开始日期。格式为 yyyymmdd 如20170611 开始日期,为自然月第一天")
* @ApiParams (name="end_date", type="string", required=true, description="结束日期,格式为 yyyymmdd 如20170611 结束日期,为自然月最后一天,限定查询一个月数据")
* @ApiReturn({
"code" => 1,
"msg" => "获取成功",
"data" => {}
*})
*/
public function getWeanalysisAppidMonthlyRetaininfo() {
$begin_date = $this->request->post('begin_date/s',0);
$end_date = $this->request->post('end_date/s',0);
try {
// 实例对应的接口对象
$weMiniTotal = new \WeMini\Total(Service::wechatConfig());
$res = $weMiniTotal->getWeanalysisAppidMonthlyRetaininfo($begin_date, $end_date);
} catch (\Exception $e){
// Log::log($e->getMessage());
$this->error($e->getMessage(),['errcode'=>$e->getCode()]);
}
$this->success('生成成功', $res);
}
/**
* @ApiTitle(微信小程序周留存)
* @ApiSummary(微信小程序周留存)
* @ApiMethod(POST)
* @ApiParams (name="begin_date", type="string", required=true, description="开始日期。格式为 yyyymmdd 如20170611 开始日期,为周一日期")
* @ApiParams (name="end_date", type="string", required=true, description="结束日期,格式为 yyyymmdd 如20170611 结束日期,为周日日期,限定查询一周数据")
* @ApiReturn({
"code" => 1,
"msg" => "获取成功",
"data" => {}
*})
*/
public function getWeanalysisAppidWeeklyRetaininfo() {
$begin_date = $this->request->post('begin_date/s',0);
$end_date = $this->request->post('end_date/s',0);
try {
// 实例对应的接口对象
$weMiniTotal = new \WeMini\Total(Service::wechatConfig());
$res = $weMiniTotal->getWeanalysisAppidWeeklyRetaininfo($begin_date, $end_date);
} catch (\Exception $e){
// Log::log($e->getMessage());
$this->error($e->getMessage(),['errcode'=>$e->getCode()]);
}
$this->success('生成成功', $res);
}
/**
* @ApiTitle(微信小程序日留存)
* @ApiSummary(微信小程序日留存)
* @ApiMethod(POST)
* @ApiParams (name="begin_date", type="string", required=true, description="开始日期。格式为 yyyymmdd 如20170611 开始日期")
* @ApiParams (name="end_date", type="string", required=true, description="结束日期,格式为 yyyymmdd 如20170611 结束日期限定查询1天数据end_date允许设置的最大值为昨日")
* @ApiReturn({
"code" => 1,
"msg" => "获取成功",
"data" => {}
*})
*/
public function getWeanalysisAppidDailyRetaininfo() {
$begin_date = $this->request->post('begin_date/s',0);
$end_date = $this->request->post('end_date/s',0);
try {
// 实例对应的接口对象
$weMiniTotal = new \WeMini\Total(Service::wechatConfig());
$res = $weMiniTotal->getWeanalysisAppidDailyRetaininfo($begin_date, $end_date);
} catch (\Exception $e){
// Log::log($e->getMessage());
$this->error($e->getMessage(),['errcode'=>$e->getCode()]);
}
$this->success('生成成功', $res);
}
/**
* @ApiTitle(微信小程序访问分布)
* @ApiSummary(微信小程序访问分布)
* @ApiMethod(POST)
* @ApiParams (name="begin_date", type="string", required=true, description="开始日期。格式为 yyyymmdd 如20170611 开始日期")
* @ApiParams (name="end_date", type="string", required=true, description="结束日期,格式为 yyyymmdd 如20170611 结束日期限定查询1天数据end_date允许设置的最大值为昨日")
* @ApiReturn({
"code" => 1,
"msg" => "获取成功",
"data" => {}
*})
*/
public function getWeanalysisAppidVisitdistribution() {
$begin_date = $this->request->post('begin_date/s',0);
$end_date = $this->request->post('end_date/s',0);
try {
// 实例对应的接口对象
$weMiniTotal = new \WeMini\Total(Service::wechatConfig());
$res = $weMiniTotal->getWeanalysisAppidVisitdistribution($begin_date, $end_date);
} catch (\Exception $e){
// Log::log($e->getMessage());
$this->error($e->getMessage(),['errcode'=>$e->getCode()]);
}
$this->success('生成成功', $res);
}
/**
* @ApiTitle(微信小程序月趋势)
* @ApiSummary(微信小程序月趋势)
* @ApiMethod(POST)
* @ApiParams (name="begin_date", type="string", required=true, description="开始日期。格式为 yyyymmdd 如20170611 开始日期,为自然月第一天")
* @ApiParams (name="end_date", type="string", required=true, description="结束日期,格式为 yyyymmdd 如20170611 结束日期,为自然月最后一天,限定查询一个月数据")
* @ApiReturn({
"code" => 1,
"msg" => "获取成功",
"data" => {}
*})
*/
public function getWeanalysisAppidMonthlyVisittrend() {
$begin_date = $this->request->post('begin_date/s',0);
$end_date = $this->request->post('end_date/s',0);
try {
// 实例对应的接口对象
$weMiniTotal = new \WeMini\Total(Service::wechatConfig());
$res = $weMiniTotal->getWeanalysisAppidMonthlyVisittrend($begin_date, $end_date);
} catch (\Exception $e){
// Log::log($e->getMessage());
$this->error($e->getMessage(),['errcode'=>$e->getCode()]);
}
$this->success('生成成功', $res);
}
/**
* @ApiTitle(微信小程序周趋势)
* @ApiSummary(微信小程序周趋势)
* @ApiMethod(POST)
* @ApiParams (name="begin_date", type="string", required=true, description="开始日期。格式为 yyyymmdd 如20170611 开始日期,为周一日期")
* @ApiParams (name="end_date", type="string", required=true, description="结束日期,格式为 yyyymmdd 如20170611 结束日期,为周日日期,限定查询一周数据")
* @ApiReturn({
"code" => 1,
"msg" => "获取成功",
"data" => {}
*})
*/
public function getWeanalysisAppidWeeklyVisittrend() {
$begin_date = $this->request->post('begin_date/s',0);
$end_date = $this->request->post('end_date/s',0);
try {
// 实例对应的接口对象
$weMiniTotal = new \WeMini\Total(Service::wechatConfig());
$res = $weMiniTotal->getWeanalysisAppidWeeklyVisittrend($begin_date, $end_date);
} catch (\Exception $e){
// Log::log($e->getMessage());
$this->error($e->getMessage(),['errcode'=>$e->getCode()]);
}
$this->success('生成成功', $res);
}
/**
* @ApiTitle(微信小程序访问分析)
* @ApiSummary(微信小程序访问分析)
* @ApiMethod(POST)
* @ApiParams (name="begin_date", type="string", required=true, description="开始日期。格式为 yyyymmdd 如20170611 开始日期")
* @ApiParams (name="end_date", type="string", required=true, description="结束日期,格式为 yyyymmdd 如20170611 结束日期限定查询1天数据end_date允许设置的最大值为昨日")
* @ApiReturn({
"code" => 1,
"msg" => "获取成功",
"data" => {}
*})
*/
public function getWeanalysisAppidDailyVisittrend() {
$begin_date = $this->request->post('begin_date/s',0);
$end_date = $this->request->post('end_date/s',0);
try {
// 实例对应的接口对象
$weMiniTotal = new \WeMini\Total(Service::wechatConfig());
$res = $weMiniTotal->getWeanalysisAppidDailyVisittrend($begin_date, $end_date);
} catch (\Exception $e){
// Log::log($e->getMessage());
$this->error($e->getMessage(),['errcode'=>$e->getCode()]);
}
$this->success('生成成功', $res);
}
/**
* @ApiTitle(微信小程序数据分析)
* @ApiSummary(微信小程序数据分析)
* @ApiMethod(POST)
* @ApiParams (name="begin_date", type="string", required=true, description="开始日期。格式为 yyyymmdd 如20170611 开始日期")
* @ApiParams (name="end_date", type="string", required=true, description="结束日期,格式为 yyyymmdd 如20170611 结束日期限定查询1天数据end_date允许设置的最大值为昨日")
* @ApiReturn({
"code" => 1,
"msg" => "获取成功",
"data" => {}
*})
*/
public function getWeanalysisAppidDailySummarytrend() {
$begin_date = $this->request->post('begin_date/s',0);
$end_date = $this->request->post('end_date/s',0);
try {
// 实例对应的接口对象
$weMiniTotal = new \WeMini\Total(Service::wechatConfig());
$res = $weMiniTotal->getWeanalysisAppidDailySummarytrend($begin_date, $end_date);
} catch (\Exception $e){
// Log::log($e->getMessage());
$this->error($e->getMessage(),['errcode'=>$e->getCode()]);
}
$this->success('生成成功', $res);
}
} }

View File

@ -0,0 +1,220 @@
<?php
namespace app\api\controller\school;
use addons\epay\library\Service;
use app\admin\model\school\help\Cate;
use app\common\controller\Api;
use app\common\library\NightSchoolBigData;
use bw\UrlLock;
use think\Cache;
/**
* 数据驾驶舱接口
*/
class BigData extends Api
{
// 无需登录的接口,*表示全部
protected $noNeedLogin = '*';
// 无需鉴权的接口,*表示全部
protected $noNeedRight = ['test2'];
/**
* @ApiTitle(按区域统计接口)
* @ApiSummary(按区域统计接口)
* @ApiMethod(GET)
* @ApiParams(name = "province", type = "string",required=false,description = "省编号(非必填)")
* @ApiParams(name = "city", type = "string",required=false,description = "市编号(非必填)")
* @ApiParams(name = "district", type = "string",required=false,description = "区域编号(非必填)")
* @ApiReturn({
"code" => 1,
"msg" => "获取成功",
"data" => {}
*})
*/
public function getAreaBaseData()
{
try{
$lock = new UrlLock(1,"area-base-data-lock-suffix",120,"您的请求过于频繁请您稍后再试请求最大锁定间隔5秒/一次!");
$lock->lock();
$province = $this->request->request("province/s","");
$city = $this->request->request("city/s","");
$district = $this->request->request("district/s","");
$res = NightSchoolBigData::getAreaBaseData($province,$city,$district);
}catch (\Throwable $e){
$lock->free();
// file_put_contents("test.txt",$e->getMessage().$e->getFile().$e->getLine());//写入文件,一般做正式环境测试
$this->error($e->getMessage());
}
$lock->free();
$this->success('返回成功', $res);
}
/**
* @ApiTitle(按课程类型统计累计报名人数)
* @ApiSummary(按课程类型统计累计报名人数)
* @ApiMethod(GET)
* @ApiReturn({
"code" => 1,
"msg" => "获取成功",
"data" => {}
*})
*/
public function accumulatedNumberOfApplicants()
{
try{
$lock = new UrlLock(1,"accumulatedNumberOfApplicants-data-lock-suffix",120,"您的请求过于频繁请您稍后再试请求最大锁定间隔5秒/一次!");
$lock->lock();
$res = NightSchoolBigData::accumulatedNumberOfApplicants();
}catch (\Throwable $e){
$lock->free();
// file_put_contents("test.txt",$e->getMessage().$e->getFile().$e->getLine());//写入文件,一般做正式环境测试
$this->error($e->getMessage());
}
$lock->free();
$this->success('返回成功', $res);
}
/**
* @ApiTitle(各区域上课数量和上课人数)
* @ApiSummary(各区域上课数量和上课人数)
* @ApiParams(name = "province", type = "string",required=false,description = "省编号(非必填)")
* @ApiParams(name = "city", type = "string",required=false,description = "市编号(非必填)")
* @ApiParams(name = "time", type = "string",required=false,description = "复合时间查询:today今天,week本周,month本月,year本年,yesterday昨天,last year上一年,last week上周last month上個月lately7最近7天 lately30最近30天按开始时间区间查传值格式Y/m/d H:M:S-Y/m/d H:M:S")
* @ApiMethod(GET)
* @ApiReturn({
"code" => 1,
"msg" => "获取成功",
"data" => {}
*})
*/
public function numberOfClassesInEachRegion()
{
try{
$lock = new UrlLock(1,"numberOfClassesInEachRegion-data-lock-suffix",120,"您的请求过于频繁请您稍后再试请求最大锁定间隔5秒/一次!");
$lock->lock();
$province = $this->request->request("province/s","");
$city = $this->request->request("city/s","");
$time = $this->request->request("time/s","");
$res = NightSchoolBigData::numberOfClassesInEachRegion($province,$city,$time);
}catch (\Throwable $e){
$lock->free();
// file_put_contents("test.txt",$e->getMessage().$e->getFile().$e->getLine());//写入文件,一般做正式环境测试
$this->error($e->getMessage());
}
$lock->free();
$this->success('返回成功', $res);
}
/**
* @ApiTitle(按课程类型统计七天内报名人数)
* @ApiSummary(按课程类型统七天内报名人数)
* @ApiMethod(GET)
* @ApiReturn({
"code" => 1,
"msg" => "获取成功",
"data" => {}
*})
*/
public function accumulatedSevenNumberOfApplicants()
{
try{
$lock = new UrlLock(1,"accumulatedSevenNumberOfApplicants-data-lock-suffix",120,"您的请求过于频繁请您稍后再试请求最大锁定间隔5秒/一次!");
$lock->lock();
$res = NightSchoolBigData::accumulatedSevenNumberOfApplicants();
}catch (\Throwable $e){
$lock->free();
// file_put_contents("test.txt",$e->getMessage().$e->getFile().$e->getLine());//写入文件,一般做正式环境测试
$this->error($e->getMessage());
}
$lock->free();
$this->success('返回成功', $res);
}
/**
* @ApiTitle(前N名累计活跃课程)
* @ApiSummary(前N名累计活跃课程)
* @ApiParams(name = "number", type = "string",required=false,description = "前N名累计活跃课程")
* @ApiMethod(GET)
* @ApiReturn({
"code" => 1,
"msg" => "获取成功",
"data" => {}
*})
*/
public function topNCumulativeActiveCourses()
{
try{
$lock = new UrlLock(1,"topNCumulativeActiveCourses-data-lock-suffix",120,"您的请求过于频繁请您稍后再试请求最大锁定间隔5秒/一次!");
$lock->lock();
$N = $this->request->request("number/d",20);
$res = NightSchoolBigData::topNCumulativeActiveCourses($N);
}catch (\Throwable $e){
$lock->free();
// file_put_contents("test.txt",$e->getMessage().$e->getFile().$e->getLine());//写入文件,一般做正式环境测试
$this->error($e->getMessage());
}
$lock->free();
$this->success('返回成功', $res);
}
/**
* @ApiTitle(七天内活动报名人数和活跃热度)
* @ApiSummary(七天内活动报名人数和活跃热度)
* @ApiMethod(GET)
* @ApiReturn({
"code" => 1,
"msg" => "获取成功",
"data" => {}
*})
*/
public function accumulatedSevenNumberOfActivity()
{
try{
$lock = new UrlLock(1,"accumulatedSevenNumberOfActivity-data-lock-suffix",120,"您的请求过于频繁请您稍后再试请求最大锁定间隔5秒/一次!");
$lock->lock();
$res = NightSchoolBigData::accumulatedSevenNumberOfActivity();
}catch (\Throwable $e){
$lock->free();
// file_put_contents("test.txt",$e->getMessage().$e->getFile().$e->getLine());//写入文件,一般做正式环境测试
$this->error($e->getMessage());
}
$lock->free();
$this->success('返回成功', $res);
}
}

View File

@ -90,7 +90,7 @@ class Api
protected $needUrlLock = []; protected $needUrlLock = [];
public function setUrlLock($url_key="",$url_suffix="",$model=null){ protected function setUrlLock($url_key="",$url_suffix="",$model=null){
if(($this->request->isPost() || (!empty($this->needUrlLock) && in_array($this->request->action(),$this->needUrlLock))) && (!empty($this->model) || $model)){ if(($this->request->isPost() || (!empty($this->needUrlLock) && in_array($this->request->action(),$this->needUrlLock))) && (!empty($this->model) || $model)){
$user_id = 0; $user_id = 0;
$user = $this->auth->getUser();//登录用户 $user = $this->auth->getUser();//登录用户

View File

@ -3,8 +3,16 @@
namespace app\common\library; namespace app\common\library;
use addons\epay\library\Service;
use app\common\model\BaseModel; 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;
use app\common\model\school\classes\ClassesLib; 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;
/** /**
* 夜校大数据类 * 夜校大数据类
@ -14,19 +22,204 @@ class NightSchoolBigData extends BaseModel
public static function getAreaBaseData($province,$city,$district){ public static function getAreaBaseData($province,$city,$district){
$where = function ($query)use($province,$city,$district){ $whereArea = function ($query)use($province,$city,$district){
$query = $query->where('1=1');
if( $province)$query = $query->where('province',$province); if( $province)$query = $query->where('province',$province);
if( $city)$query = $query->where('city',$city); if( $city)$query = $query->where('city',$city);
if( $district)$query = $query->where('district',$district); if( $district)$query = $query->where('district',$district);
}; };
//统计当前课程总数 //统计当前课程总数
$count = ClassesLib::where($where)->sum(""); $classes_num = ClassesLib::where($whereArea)->count();
$activity_num = Activity::where($whereArea)->count();
//统计当前总报名人数
$classes_sign_num = ClassesLib::where($whereArea)->sum('sign_num');
$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];
}
/** 七天内活动报名人数和活跃热度
* @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");
}
} }

View File

@ -150,7 +150,7 @@ class ClassesSpec extends BaseModel
//结束时间不能是已经过去的时间 //结束时间不能是已经过去的时间
$now_time = time(); $now_time = time();
if($end_time<=$now_time){ if($end_time<=$now_time){
throw new \Exception("{$params["name"]}结束时间不能是已经过去的时间"); // throw new \Exception("{$params["name"]}结束时间不能是已经过去的时间");
} }
//如果是员工操作则结束时间必须大于当前时间n秒 //如果是员工操作则结束时间必须大于当前时间n秒