Commit 6b64b200 authored by wangzhengwen's avatar wangzhengwen

看板

parent cc006d51
...@@ -8,6 +8,7 @@ use app\BaseController; ...@@ -8,6 +8,7 @@ use app\BaseController;
use app\model\Course as courseModel; use app\model\Course as courseModel;
use app\model\Payment; use app\model\Payment;
use app\model\ProjectTag; use app\model\ProjectTag;
use think\facade\Cache;
use think\facade\Db; use think\facade\Db;
use think\Request; use think\Request;
use app\model\project as projectModel; use app\model\project as projectModel;
...@@ -150,25 +151,45 @@ class Index extends BaseController ...@@ -150,25 +151,45 @@ class Index extends BaseController
{ {
$range = $request->param('range', 'month'); $range = $request->param('range', 'month');
$validRanges = ['month', 'quarter', 'halfyear', 'all','year']; $validRanges = ['month', 'quarter', 'halfyear', 'all', 'year'];
$userId = $request->userId;
if (!in_array($range, $validRanges)) { if (!in_array($range, $validRanges)) {
return $this->returnMsg('无效时间范围'); return $this->returnMsg('无效时间范围');
} }
$userId = $request->userId;
// 构建缓存键,包含用户ID和时间范围
$cacheKey = 'payment_stats:' . $userId . ':' . $range;
// 尝试从缓存获取数据
if (Cache::has($cacheKey)) {
$cachedData = Cache::get($cacheKey);
return $this->returnMsg('success', 1, $cachedData);
}
// 缓存不存在,从数据库获取
$payment = new Payment(); $payment = new Payment();
$result = $payment->getOrderStatistics($range,$userId); $result = $payment->getOrderStatistics($range, $userId);
// 格式化数据 // 格式化数据
$formattedData = $this->formatStatisticsData($result['data'], $result['format']); $formattedData = $this->formatStatisticsData($result['data'], $result['format']);
$returnData = [
return $this->returnMsg('success', 1, [
'data' => $formattedData, 'data' => $formattedData,
'time_format' => $result['format'] 'time_format' => $result['format']
]); ];
// 设置缓存,不同范围设置不同过期时间
$expireTimes = [
'month' => 3600, // 1小时
'quarter' => 3600, // 3小时
'halfyear' => 3600, // 6小时
'year' => 3600, // 12小时
'all' => 3600 // 24小时
];
Cache::set($cacheKey, $returnData, $expireTimes[$range]);
return $this->returnMsg('success', 1, $returnData);
} }
......
...@@ -127,7 +127,7 @@ class Payment extends Model ...@@ -127,7 +127,7 @@ class Payment extends Model
]) ])
->group("time_period") ->group("time_period")
->order("time_period ASC") ->order("time_period ASC")
// ->where('userId',$userId) ->where('userId',$userId)
->select() ->select()
->toArray(); ->toArray();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment