Commit d994396c authored by wangzhengwen's avatar wangzhengwen

6.3

parent 2704d431
......@@ -28,8 +28,14 @@ class CourseComment extends BaseController
$courseId = Request::param('course_id/d', 0);
$page = Request::param('page/d', 1);
$pageSize = Request::param('pageSize/d', 10);
$sortBy = Request::param('sort_by/s', 'latest');
$comments = courseCommentModel::getCommentList($courseId, $page, $pageSize);
// 验证排序参数
if (!in_array($sortBy, ['latest', 'likes'])) {
$sortBy = 'latest';
}
$comments = courseCommentModel::getCommentList($courseId, $page, $pageSize, $sortBy);
return $this->returnMsg('success',1, $comments);
}
......
......@@ -8,7 +8,7 @@ use app\api\service\UtilService;
use app\api\validate\CourseValidate;
use app\BaseController;
use app\model\Payment;
use think\Request;
use think\Facade\Request;
use app\api\service\CourseProgressService;
use app\model\Course as CourseModel;
......@@ -32,9 +32,7 @@ class CourseProgress extends BaseController
}
$data = Request::only(['course_id', 'class_id', 'current_time']);
$token = Request::header('token');
$userId = UserService::getUserInfo($token)['id'];
$userId = $this->request->userId;
$result = CourseProgressService::updateProgress(
$userId,
......@@ -57,22 +55,14 @@ class CourseProgress extends BaseController
public function getProgress()
{
// $vo = (new CourseValidate())->goCheck(['course_id']);
// if ($vo !== true) {
// return $vo;
// }
$token = Request::header('token');
$userId = UserService::getUserInfo($token)['id'];
// $data = Request::only(['course_id','page','pageSize']);
$userId = $this->request->userId;
$page = Request::param('page', 1);
$pageSize = Request::param('pageSize', 10);
$type = Request::param('type', 0); // 0:全部 1:付费 2:免费
$progress = CourseProgressService::getUserAllCoursesProgress($userId, $page, $pageSize);
$progress = CourseProgressService::getUserAllCoursesProgress($userId, $page, $pageSize, $type);
return $this->returnMsg('操作成功',1,$progress);
}
/**
......@@ -85,9 +75,8 @@ class CourseProgress extends BaseController
return $vo;
}
$token = Request::header('token');
$userId = $this->request->userId;
$userId = UserService::getUserInfo($token)['id'];
$data = Request::only(['course_id']);
$lastLearn = CourseProgressService::getLearnedClasses($userId, $data['course_id']);
......@@ -105,9 +94,7 @@ class CourseProgress extends BaseController
return $vo;
}
$token = Request::header('token');
$userId = UserService::getUserInfo($token)['id'];
$userId = $this->request->userId;
$data = Request::only(['course_id']);
$userWork = CourseProgressService::addUserWork($userId, $data['course_id']);
......
......@@ -242,7 +242,8 @@ class PayController
$res = json_decode($order, true);
if ($res['trade_state'] == 'SUCCESS') {
// 处理业务逻辑
$res = PayService::handlePaymentNotify($order['out_trade_no'], $order);
$res = PayService::handlePaymentNotify($res['out_trade_no'], $res);
return json(['code' => 1, 'msg' => 'success', 'data' => $res]);
} else {
throw new \Exception("订单处理失败");
......
......@@ -20,6 +20,20 @@ class Cert extends BaseController
return $this->returnMsg('success',1,$list);
}
//项目子分类列表
public function getCertCategoryChildrenList(Request $request)
{
$vo = (new CertValidate())->goCheck(['pid']);
if ($vo !== true) {
return $vo;
}
$data = $request->param();
$list = (new CertCategory())->getCertCategoryList($data['pid']);
return $this->returnMsg('success',1,$list);
}
//项目列表
public function getCertList(Request $request)
{
......
......@@ -32,12 +32,12 @@ class Project extends BaseController
$where = ['user_id' => $request->userId];
if (!empty($data['status']) || $data['status'] == 0) {
if (isset($data['status']) && $data['status'] !== '') {
$where['status'] = (int)$data['status'];
}
if (!empty($data['sh_status'])) {
$where['sh_status'] = $data['sh_status'];
if (isset($data['sh_status']) && $data['sh_status'] !== '') {
$where['sh_status'] = (int)$data['sh_status'];
}
......@@ -95,6 +95,10 @@ class Project extends BaseController
$data = $request->only($filed);
$res = ProjectModel::where(['id'=>$data['project_id'],'user_id'=>$request->userId])->find();
if (!$res)
{
return $this->returnMsg('项目不存在');
}
$applyProgress = StatusConstants::PROGRESS_RULES['apply'][$res->sh_status] ?? 0;
$completeProgress = ($res->sh_status == 2) ? (StatusConstants::PROGRESS_RULES['complete'][$res->status] ?? 0) : 0;
......
......@@ -31,21 +31,25 @@ class Project extends BaseController
]
];
const PROGRESS_RULES = [
/**
* 用户端项目进度规则
* 与管理后台的进度规则(StatusConstants::PROGRESS_RULES)区分
* 用户端只关注主要节点:申请、验收等关键状态
*/
const USER_PROGRESS_RULES = [
'apply' => [
0 => 10, // 申请中
1 => 0, // 申请失败
2 => 20 // 申请成功
1 => 0, // 申请失败
2 => 20 // 申请成功
],
'complete' => array(
0 => 0, // 未上传
1 => 60, // 验收中
2 => 80, // 验收失败
3 => 100 // 验收成功
)
'complete' => [
0 => 0, // 未上传
1 => 60, // 验收中
2 => 80, // 验收失败
3 => 100 // 验收成功
]
];
public function getProjectList(Request $request)
{
......@@ -55,13 +59,13 @@ class Project extends BaseController
$data = $request->param();
$where = ['pp.user_id' => $request->userId];
if (!empty($data['status']) || $data['status'] == 0) {
if (isset($data['status']) && $data['status'] !== '') {
$where['pp.status'] = (int)$data['status'];
}
if (!empty($data['complete_status'])) {
$where['pp.complete_status'] = $data['complete_status'];
if (isset($data['complete_status']) && $data['complete_status'] !== '') {
$where['pp.complete_status'] = (int)$data['complete_status'];
}
......@@ -91,8 +95,8 @@ class Project extends BaseController
// 处理结果集
// 添加调试信息
$list->each(function($item) {
$applyProgress = self::PROGRESS_RULES['apply'][$item->status] ?? 0;
$completeProgress = ($item->status == 2) ? (self::PROGRESS_RULES['complete'][$item->complete_status] ?? 0) : 0;
$applyProgress = self::USER_PROGRESS_RULES['apply'][$item->status] ?? 0;
$completeProgress = ($item->status == 2) ? (self::USER_PROGRESS_RULES['complete'][$item->complete_status] ?? 0) : 0;
$item->progress = max(1, min(100, $applyProgress + $completeProgress));
......@@ -124,11 +128,14 @@ class Project extends BaseController
$item = ProjectPut::where(['id'=>$data['project_put_id'],'user_id'=>$request->userId])
->with(['project'])
->with(['project'=>['getuserdata']])
->find();
$applyProgress = self::PROGRESS_RULES['apply'][$item->status] ?? 0;
$completeProgress = ($item->status == 2) ? (self::PROGRESS_RULES['complete'][$item->complete_status] ?? 0) : 0;
if (!$item)
{
return $this->returnMsg('项目不存在');
}
$applyProgress = self::USER_PROGRESS_RULES['apply'][$item->status] ?? 0;
$completeProgress = ($item->status == 2) ? (self::USER_PROGRESS_RULES['complete'][$item->complete_status] ?? 0) : 0;
$item->progress = max(1, min(100, $applyProgress + $completeProgress));
......
......@@ -12,6 +12,7 @@ use app\api\validate\UserValidate;
use app\BaseController;
use app\model\CertOrder;
use app\model\Course as CourseModel;
use app\model\Payment;
use app\model\project\Mail;
use app\model\project\UserAccount;
use app\model\project\UserMoneyLog;
......@@ -310,5 +311,64 @@ class User extends BaseController
}
//用户订单
public function getOrderList(Request $request)
{
$page = $request->param('page/d', 1);
$pageSize = $request->param('pageSize/d', 10);
$where = ['p.user_id' => $request->userId];
// 搜索条件
$order_no = $request->param('order_no', '');
if ($order_no) {
$where['p.order_no'] = ['like', "%{$order_no}%"];
}
$pay_no = $request->param('pay_no', '');
if ($pay_no) {
$where['p.pay_no'] = ['like', "%{$pay_no}%"];
}
$keyword = $request->param('keyword', '');
$query = Payment::alias('p')
->where($where)
->leftJoin('course c', "p.order_id = c.id AND p.order_type = 1")
->leftJoin('cert ce', "p.order_id = ce.id AND p.order_type = 2")
->field([
'p.order_no',
'p.pay_no',
'p.createtime',
'p.pay_channel',
'p.pay_method',
'p.order_price',
'p.pay_amount',
'p.pay_status',
'p.order_type',
'p.pay_time',
'IF(p.order_type=1, c.title, ce.title) as title',
'IF(p.order_type=1, c.price, ce.price) as price'
]);
if ($keyword) {
$query = $query->where('c.title|ce.title', 'like', "%{$keyword}%");
}
$list = $query->order('p.createtime', 'desc')
->paginate([
'page' => $page,
'list_rows' => $pageSize
]);
// foreach ($list as &$item) {
// $item['order_type_text'] = $item['order_type'] == 1 ? '课程' : '证书';
// $item['pay_method_text'] = $item['pay_method'] == 1 ? '支付宝' : '微信';
// }
// unset($item);
return $this->returnMsg('success', 1, $list);
}
}
\ No newline at end of file
......@@ -6,6 +6,7 @@ use app\api\service\UserService;
use app\api\validate\ProjectValidate;
use app\BaseController;
use app\model\project\UserMoneyLog;
use app\model\ProjectTag;
use think\Request;
use app\model\ProjectCategory;
use app\model\Project as ProjectModel;
......@@ -20,6 +21,20 @@ class Project extends BaseController
return $this->returnMsg('success',1,$list);
}
//项目子分类列表
public function getProjectCategoryChildrenList(Request $request)
{
$vo = (new ProjectValidate())->goCheck(['pid']);
if ($vo !== true) {
return $vo;
}
$data = $request->param();
$list = (new ProjectCategory())->getProjectCategoryList($data['pid']);
return $this->returnMsg('success',1,$list);
}
//项目列表
public function getProjectList(Request $request)
{
......@@ -73,6 +88,61 @@ class Project extends BaseController
}
/**热门标签
* @param Request $request
* @return \app\html
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getProjectHotTags(Request $request)
{
// 获取所有有效项目的标签ID
$projects = ProjectModel::where('sh_status', 2) // 只统计审核通过的项目
->where('status', '<>', 5) // 排除已取消的项目
->column('tag_ids');
// 统计标签使用频率
$tagCount = [];
foreach ($projects as $tagIds) {
if (empty($tagIds)) {
continue;
}
$tagIdArray = explode(',', $tagIds);
foreach ($tagIdArray as $tagId) {
if (!isset($tagCount[$tagId])) {
$tagCount[$tagId] = 0;
}
$tagCount[$tagId]++;
}
}
// 如果没有标签数据
if (empty($tagCount)) {
return $this->returnMsg('success', 1, []);
}
// 获取标签详细信息
$tagIds = array_keys($tagCount);
$tags = ProjectTag::where('id', 'in', $tagIds)
->where('is_del', 0)
->field(['id', 'title'])
->select()
->toArray();
// 组装最终数据,包含使用次数
foreach ($tags as &$tag) {
$tag['count'] = $tagCount[$tag['id']];
}
// 按使用次数降序排序
usort($tags, function($a, $b) {
return $b['count'] - $a['count'];
});
return $this->returnMsg('success', 1, $tags);
}
}
\ No newline at end of file
......@@ -115,9 +115,11 @@ class CourseProgressService
/** 获取当前用户所有课程进度统计
* @param $userId
*
* @param int $page
* @param int $pageSize
* @param int $type 0:全部 1:付费 2:免费
*/
public static function getUserAllCoursesProgress($userId, $page = 1, $pageSize = 10)
public static function getUserAllCoursesProgress($userId, $page = 1, $pageSize = 10, $type = 0)
{
// 获取用户学习过的所有课程ID(去重)
$courseIds = CourseProgress::where('user_id', $userId)
......@@ -134,12 +136,17 @@ class CourseProgressService
];
}
// 分页查询课程基本信息
$query = Course::where('id', 'in', $courseIds)
->with(['thumb'])
->field('id,title,description,thumb');
->field('id,title,description,thumb,price');
// 根据类型筛选课程
if ($type === 1) {
$query->where('price', '>', 0);
} elseif ($type === 2) {
$query->where('price', '<=', 0);
}
$paginator = $query->paginate([
'list_rows' => $pageSize,
......
......@@ -149,12 +149,17 @@ class PayService
}
$pay_time = $payment['pay_method'] == self::PAY_METHOD_ALIPAY ?
strtotime($notifyData['send_pay_date']) : strtotime($notifyData['gmt_payment'] ?? date('Y-m-d H:i:s'));
$pay_no = $payment['pay_method'] == self::PAY_METHOD_ALIPAY ?
$notifyData['trade_no'] : ($notifyData['transaction_id']);
// 更新支付状态
$updateData = [
'pay_status' => self::PAY_STATUS_SUCCESS,
'pay_time' => $pay_time,
'pay_info' => json_encode($notifyData, JSON_UNESCAPED_UNICODE),
'updatetime' => time()
'updatetime' => time(),
'pay_no'=>$pay_no
];
$result = Db::name('payment')
......
......@@ -19,7 +19,7 @@ class CertValidate extends BaseValidate
'other_file_id' => 'require|number',
'pay_type'=>'require|number',
'cert_order_id'=>'require|number',
'pid' => 'require|number',
];
}
\ No newline at end of file
......@@ -32,6 +32,7 @@ class ProjectValidate extends BaseValidate
'cate_id'=>'require|number',
'title'=>'require|checktitle',
'user_id'=>'require|number',
'pid'=>'require|number',
];
protected $message = [
'title.require' => '项目名不能为空',
......
......@@ -43,14 +43,14 @@ class CertCategory extends Model
return $this->hasMany(CertCategory::class, 'pid');
}
public function getCertCategoryList()
public function getCertCategoryList($pid=0)
{
$where[] = ['is_del', '=', 0];
return $this->with(['children' => function($query) use($where) {
$query->where($where);
$query->order('sort', 'asc');
}])
->where('pid', 0)
->where('pid', $pid)
->where($where)
->order('sort', 'asc')
->select();
......
......@@ -4,6 +4,7 @@ namespace app\model;
use app\model\project\User;
use think\Model;
use think\model\concern\SoftDelete;
use think\facade\Db;
class CourseComment extends Model
{
......@@ -34,7 +35,7 @@ class CourseComment extends Model
public function replies()
{
return $this->hasMany(CourseComment::class, 'parent_id', 'id')
->with('user')
->with(['user'])
->order('createtime', 'asc');
}
......@@ -48,27 +49,44 @@ class CourseComment extends Model
public function getUserLikeAttr($value, $data)
{
$userId = request()->userId ?? 0;
return CourseCommentLike::where('comment_id', $data['id'])
->where('user_id', $userId)
->count() > 0;
return $this->likes()->where('user_id', $userId)->count() > 0;
}
// 获取点赞数
public function getLikesCountAttr($value, $data)
{
return CourseCommentLike::where('comment_id', $data['id'])->count();
return $this->likes()->count();
}
// 获取评论列表
public static function getCommentList($courseId, $page = 1, $pageSize = 10)
public static function getCommentList($courseId, $page = 1, $pageSize = 10, $sortBy = 'latest')
{
return self::with(['user', 'replies' => function($query) {
$query->with(['user'])->append(['user_like', 'likes_count']);
}])
->where('course_id', $courseId)
->where('parent_id', 0)
->order('createtime', 'desc')
->append(['user_like', 'likes_count'])
// 基础查询
$query = self::withCount(['likes'])
->with([
'user' => ['headico'], // 加载用户信息和头像
'replies' => function($query) {
$query->with(['user' => ['headico']]) // 加载回复的用户信息和头像
->withCount(['likes']) // 统计回复的点赞数
->append(['user_like', 'likes_count'])
->order('createtime', 'asc'); // 回复按时间正序
}
])
->where([
['course_id', '=', $courseId],
['parent_id', '=', 0] // 只查询一级评论
]);
// 排序处理
if ($sortBy === 'likes') {
$query->order('likes_count', 'desc')
->order('createtime', 'desc');
} else {
$query->order('createtime', 'desc');
}
// 返回分页数据
return $query->append(['user_like', 'likes_count'])
->paginate([
'page' => $page,
'list_rows' => $pageSize
......
......@@ -10,6 +10,7 @@
namespace app\model;
use app\model\system\SystemUploadFile;
use think\facade\Db;
use think\Model;
use think\model\concern\SoftDelete;
......@@ -50,12 +51,20 @@ class ProjectCategory extends Model
return $this->hasMany(ProjectCategory::class, 'pid');
}
public function getProjectCategoryList()
public function thumb()
{
return $this->hasOne(SystemUploadFile::class, 'fileid', 'thumb')
->where('isdel',0)
->field('fileid,filename,filesize,fileurl,filetype');
}
public function getProjectCategoryList($pid = 0)
{
return $this->with(['children' => function($query) {
$query->order('sort', 'asc');
}])
->where('pid', 0)
$query->with(['thumb']);
},'thumb'])
->where('pid', $pid)
->order('sort', 'asc')
->select();
......
......@@ -99,7 +99,7 @@ class ProjectPut extends Model
public function project()
{
return $this->belongsTo(Project::class, 'project_id', 'id')->field('id,sn,title,yusuan,user_id');
return $this->belongsTo(Project::class, 'project_id', 'id')->field('id,sn,title,yusuan,user_id,zhouqi');
}
}
\ 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