92 lines
2.2 KiB
Go
92 lines
2.2 KiB
Go
package controller
|
|
|
|
import (
|
|
"case-api/api/dao"
|
|
"case-api/api/dto"
|
|
"case-api/api/requests"
|
|
"case-api/api/responses"
|
|
"case-api/api/service"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
type ProjectPlatform struct{}
|
|
|
|
// GetProjectPlatform 获取详情
|
|
func (b *ProjectPlatform) GetProjectPlatform(c *gin.Context) {
|
|
projectPlatformRequest := requests.ProjectPlatformRequest{}
|
|
req := projectPlatformRequest.GetProjectPlatform
|
|
if err := c.ShouldBind(&req); err != nil {
|
|
responses.FailWithMessage(err.Error(), c)
|
|
return
|
|
}
|
|
|
|
userId := c.GetInt64("UserId") // 用户id
|
|
if userId == 0 {
|
|
responses.FailWithMessage("内部错误", c)
|
|
return
|
|
}
|
|
|
|
platformId := c.GetInt64("PlatformId") // 平台id
|
|
if platformId == 0 {
|
|
responses.FailWithMessage("内部错误", c)
|
|
return
|
|
}
|
|
|
|
platformDao := dao.PlatformDao{}
|
|
platform, err := platformDao.GetPlatformById(platformId)
|
|
if err != nil {
|
|
responses.FailWithMessage("数据异常", c)
|
|
return
|
|
}
|
|
|
|
if platform.PlatformStatus == 2 {
|
|
responses.FailWithMessage("数据异常", c)
|
|
return
|
|
}
|
|
|
|
projectPlatformDao := dao.ProjectPlatformDao{}
|
|
maps := make(map[string]interface{})
|
|
maps["project_id"] = req.ProjectId
|
|
maps["platform_id"] = platformId
|
|
projectPlatform, err := projectPlatformDao.GetProjectPlatform(maps)
|
|
if err != nil {
|
|
responses.FailWithMessage("数据异常", c)
|
|
return
|
|
}
|
|
|
|
if projectPlatform.Status == 0 {
|
|
responses.FailWithMessage("数据异常", c)
|
|
return
|
|
}
|
|
|
|
g := dto.GetProjectPlatformDto(projectPlatform)
|
|
|
|
// 加载数据-平台名称
|
|
g.LoadPlatFormName(platform)
|
|
|
|
// 获取用户信息
|
|
userDao := dao.UserDao{}
|
|
user, err := userDao.GetUserById(userId)
|
|
if err != nil {
|
|
responses.FailWithMessage("数据异常", c)
|
|
return
|
|
}
|
|
|
|
// 检测用户是否属于白名单
|
|
projectPlatformWhiteService := service.ProjectPlatformWhiteService{}
|
|
isWhite, _ := projectPlatformWhiteService.CheckProjectPlatformWhiteByUser(user, projectPlatform.ProjectId, platformId)
|
|
|
|
// 加载数据-用户白名单
|
|
g.LoadIsWhiteUser(isWhite)
|
|
|
|
if platformId == 2 {
|
|
g.SingleCaseScore = g.SingleCaseScore * 10
|
|
g.CompleteRead = g.CompleteRead * 10
|
|
g.CompleteReadTime = g.CompleteReadTime * 10
|
|
g.FirstHighQuality = g.FirstHighQuality * 10
|
|
g.OnceMoreHighQuality = g.OnceMoreHighQuality * 10
|
|
}
|
|
|
|
responses.OkWithData(g, c)
|
|
}
|