Commit 3018043d authored by wangzhengwen's avatar wangzhengwen

看板

parent 6b64b200
...@@ -11,7 +11,7 @@ use app\model\ProjectTag; ...@@ -11,7 +11,7 @@ use app\model\ProjectTag;
use think\facade\Cache; 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;
use app\model\project\User as userModel; use app\model\project\User as userModel;
class Index extends BaseController class Index extends BaseController
...@@ -233,14 +233,13 @@ class Index extends BaseController ...@@ -233,14 +233,13 @@ class Index extends BaseController
if (empty($userId)) { if (empty($userId)) {
return $this->returnMsg('用户ID不能为空'); return $this->returnMsg('用户ID不能为空');
} }
try { try {
// 查询该高校下的所有作业 // 查询该高校下的所有作业
$works = Db::name('course_work') $works = Db::name('course_work')
->alias('zy') ->alias('zy')
->join('course kc','zy.course_id=kc.id') ->join('course kc','zy.course_id=kc.id')
->join('course_category kcfl','kc.cate_id=kcfl.id') ->join('course_category kcfl','kc.cate_id=kcfl.id')
->where('user_id', $userId) ->where('zy.user_id', $userId)
->where('zy.is_del', 0) ->where('zy.is_del', 0)
->field('zy.id, zy.title, zy.course_id,kc.title as course_name,kc.cate_id,kcfl.title as course_category') ->field('zy.id, zy.title, zy.course_id,kc.title as course_name,kc.cate_id,kcfl.title as course_category')
->select() ->select()
......
...@@ -83,12 +83,19 @@ class Payment extends Model ...@@ -83,12 +83,19 @@ class Payment extends Model
} }
return $title; return $title;
} }
/**
public function getOrderStatistics($range = 'month',$userId=0) * 获取订单统计信息
* @param string $range 时间范围: month(近一个月), quarter(近三个月), halfyear(近半年), year(近一年), all(全部)
* @param int $userId 用户ID
* @return array
*/
public function getOrderStatistics($range = 'month', $userId = 0)
{ {
// 基础查询条件:支付成功(1)且订单类型为课程(1) // 基础查询条件:支付成功(1)且订单类型为课程(1)
$query = $this->where('pay_status', 1) $query = $this->where('pay_status', 1)
->where('order_type', 1); ->where('order_type', 1)
->where('store_user_id', $userId);
// 根据时间范围设置条件 // 根据时间范围设置条件
switch ($range) { switch ($range) {
...@@ -110,7 +117,7 @@ class Payment extends Model ...@@ -110,7 +117,7 @@ class Payment extends Model
break; break;
case 'all': case 'all':
default: default:
$startTime = null; $startTime = strtotime('-5 year'); // 默认统计最近5年
$timeFormat = "%Y-%m"; // 按月 $timeFormat = "%Y-%m"; // 按月
break; break;
} }
...@@ -127,14 +134,65 @@ class Payment extends Model ...@@ -127,14 +134,65 @@ class Payment extends Model
]) ])
->group("time_period") ->group("time_period")
->order("time_period ASC") ->order("time_period ASC")
->where('userId',$userId)
->select() ->select()
->toArray(); ->toArray();
if ($range != 'all')
{
// 自动补全缺失的时间段数据
$filledData = $this->fillMissingTimePeriods($result, $timeFormat, $startTime);
}else{
$filledData = $result;
}
return [ return [
'data' => $result, 'data' => $filledData,
'format' => $timeFormat === "%Y-%m-%d" ? 'day' : 'month' 'format' => $timeFormat === "%Y-%m-%d" ? 'day' : 'month'
]; ];
} }
/**
* 补全缺失的时间段数据(私有方法确保不会重复)
*/
private function fillMissingTimePeriods($data, $timeFormat, $startTime)
{
if (empty($data)) {
return [];
}
$filledData = [];
$current = $startTime ?: strtotime($data[0]['time_period']);
$end = strtotime('today 23:59:59');
// 根据格式确定时间间隔
$isDaily = ($timeFormat === "%Y-%m-%d");
$interval = $isDaily ? '1 day' : '1 month';
$dateFormat = $isDaily ? 'Y-m-d' : 'Y-m';
while ($current <= $end) {
$period = date($dateFormat, $current);
$found = false;
foreach ($data as $item) {
if ($item['time_period'] === $period) {
$filledData[] = $item;
$found = true;
break;
}
}
if (!$found) {
$filledData[] = [
'time_period' => $period,
'order_count' => 0,
'total_amount' => 0.00
];
}
$current = strtotime("+{$interval}", $current);
}
return $filledData;
}
} }
\ No newline at end of file
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