Commit 3018043d authored by wangzhengwen's avatar wangzhengwen

看板

parent 6b64b200
......@@ -11,7 +11,7 @@ use app\model\ProjectTag;
use think\facade\Cache;
use think\facade\Db;
use think\Request;
use app\model\project as projectModel;
use app\model\Project as projectModel;
use app\model\project\User as userModel;
class Index extends BaseController
......@@ -233,14 +233,13 @@ class Index extends BaseController
if (empty($userId)) {
return $this->returnMsg('用户ID不能为空');
}
try {
// 查询该高校下的所有作业
$works = Db::name('course_work')
->alias('zy')
->join('course kc','zy.course_id=kc.id')
->join('course_category kcfl','kc.cate_id=kcfl.id')
->where('user_id', $userId)
->where('zy.user_id', $userId)
->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')
->select()
......
......@@ -83,12 +83,19 @@ class Payment extends Model
}
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)
$query = $this->where('pay_status', 1)
->where('order_type', 1);
->where('order_type', 1)
->where('store_user_id', $userId);
// 根据时间范围设置条件
switch ($range) {
......@@ -110,7 +117,7 @@ class Payment extends Model
break;
case 'all':
default:
$startTime = null;
$startTime = strtotime('-5 year'); // 默认统计最近5年
$timeFormat = "%Y-%m"; // 按月
break;
}
......@@ -127,14 +134,65 @@ class Payment extends Model
])
->group("time_period")
->order("time_period ASC")
->where('userId',$userId)
->select()
->toArray();
if ($range != 'all')
{
// 自动补全缺失的时间段数据
$filledData = $this->fillMissingTimePeriods($result, $timeFormat, $startTime);
}else{
$filledData = $result;
}
return [
'data' => $result,
'data' => $filledData,
'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