Commit 6b64b200 authored by wangzhengwen's avatar wangzhengwen

看板

parent cc006d51
......@@ -8,6 +8,7 @@ use app\BaseController;
use app\model\Course as courseModel;
use app\model\Payment;
use app\model\ProjectTag;
use think\facade\Cache;
use think\facade\Db;
use think\Request;
use app\model\project as projectModel;
......@@ -150,25 +151,45 @@ class Index extends BaseController
{
$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)) {
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();
$result = $payment->getOrderStatistics($range,$userId);
$result = $payment->getOrderStatistics($range, $userId);
// 格式化数据
$formattedData = $this->formatStatisticsData($result['data'], $result['format']);
return $this->returnMsg('success', 1, [
$returnData = [
'data' => $formattedData,
'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
])
->group("time_period")
->order("time_period ASC")
// ->where('userId',$userId)
->where('userId',$userId)
->select()
->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