1
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
package controller
|
||||
|
||||
// Api api接口
|
||||
type Api struct {
|
||||
Login // 登录
|
||||
Public // 公共方法
|
||||
Class // 分类
|
||||
Question // 问题
|
||||
User // 用户
|
||||
UserCoupon // 用户优惠卷
|
||||
UserCollection // 用户收藏
|
||||
OrderSingle // 订单-单项
|
||||
SystemMember // 会员配置
|
||||
OrderMember // 订单-会员
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"hepa-calc-api/api/dao"
|
||||
"hepa-calc-api/api/dto"
|
||||
"hepa-calc-api/api/responses"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type Class struct{}
|
||||
|
||||
func (b *Class) GetClassList(c *gin.Context) {
|
||||
// 获取分类数据
|
||||
baseClassDao := dao.BaseClassDao{}
|
||||
|
||||
maps := make(map[string]interface{})
|
||||
maps["class_status"] = 1
|
||||
baseClass, err := baseClassDao.GetBaseClassOrderList(maps)
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 处理返回值
|
||||
g := dto.GetBaseClassListDto(baseClass)
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
responses.OkWithData(g, c)
|
||||
}
|
||||
|
||||
// GetClass 获取分类详情
|
||||
func (r *Class) GetClass(c *gin.Context) {
|
||||
id := c.Param("class_id")
|
||||
if id == "" {
|
||||
responses.FailWithMessage("缺少参数", c)
|
||||
return
|
||||
}
|
||||
|
||||
// 将 id 转换为 int64 类型
|
||||
classId, err := strconv.ParseInt(id, 10, 64)
|
||||
if err != nil {
|
||||
responses.Fail(c)
|
||||
return
|
||||
}
|
||||
|
||||
// 获取数据
|
||||
baseClassDao := dao.BaseClassDao{}
|
||||
baseClass, err := baseClassDao.GetBaseClassById(classId)
|
||||
if err != nil {
|
||||
responses.FailWithMessage("分类不存在", c)
|
||||
return
|
||||
}
|
||||
|
||||
if baseClass.ClassStatus != 1 {
|
||||
responses.FailWithMessage("分类不存在", c)
|
||||
return
|
||||
}
|
||||
|
||||
// 处理返回值
|
||||
g := dto.GetBaseClassDto(baseClass)
|
||||
|
||||
responses.OkWithData(g, c)
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"hepa-calc-api/api/requests"
|
||||
"hepa-calc-api/api/responses"
|
||||
"hepa-calc-api/global"
|
||||
"hepa-calc-api/utils"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type Login struct{}
|
||||
|
||||
// LoginPhone 手机号登录
|
||||
func (r *Login) LoginPhone(c *gin.Context) {
|
||||
token := &utils.Token{
|
||||
UserId: strconv.FormatInt(1, 10),
|
||||
}
|
||||
|
||||
// 生成jwt
|
||||
jwt, err := token.NewJWT()
|
||||
if err != nil {
|
||||
responses.FailWithMessage("登陆失败", c)
|
||||
return
|
||||
}
|
||||
|
||||
responses.OkWithData(jwt, c)
|
||||
}
|
||||
|
||||
// LoginWx 微信授权登录
|
||||
func (r *Login) LoginWx(c *gin.Context) {
|
||||
loginRequest := requests.LoginRequest{}
|
||||
req := loginRequest.LoginWx
|
||||
if err := c.ShouldBind(&req); err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 参数验证
|
||||
if err := global.Validate.Struct(req); err != nil {
|
||||
responses.FailWithMessage(utils.Translate(err), c)
|
||||
return
|
||||
}
|
||||
|
||||
responses.Ok(c)
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"hepa-calc-api/api/dao"
|
||||
"hepa-calc-api/api/dto"
|
||||
"hepa-calc-api/api/requests"
|
||||
"hepa-calc-api/api/responses"
|
||||
"hepa-calc-api/global"
|
||||
"hepa-calc-api/utils"
|
||||
)
|
||||
|
||||
type OrderMember struct{}
|
||||
|
||||
// GetOrderMemberPage 获取会员订单列表-分页
|
||||
func (b *OrderMember) GetOrderMemberPage(c *gin.Context) {
|
||||
orderMemberRequest := requests.OrderMemberRequest{}
|
||||
req := orderMemberRequest.GetOrderMemberPage
|
||||
if err := c.ShouldBind(&req); err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 参数验证
|
||||
if err := global.Validate.Struct(req); err != nil {
|
||||
responses.FailWithMessage(utils.Translate(err), c)
|
||||
return
|
||||
}
|
||||
|
||||
if req.Page == 0 {
|
||||
req.Page = 1
|
||||
}
|
||||
|
||||
if req.PageSize == 0 {
|
||||
req.PageSize = 20
|
||||
}
|
||||
|
||||
userId := c.GetInt64("UserId")
|
||||
req.UserId = userId
|
||||
|
||||
// 获取数据
|
||||
orderMemberDao := dao.OrderMemberDao{}
|
||||
orderMember, total, err := orderMemberDao.GetOrderMemberPageSearch(req, req.Page, req.PageSize)
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 处理返回值
|
||||
g := dto.GetOrderMemberListDto(orderMember)
|
||||
|
||||
result := make(map[string]interface{})
|
||||
result["page"] = req.Page
|
||||
result["page_size"] = req.PageSize
|
||||
result["total"] = total
|
||||
result["data"] = g
|
||||
responses.OkWithData(result, c)
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"hepa-calc-api/api/dao"
|
||||
"hepa-calc-api/api/dto"
|
||||
"hepa-calc-api/api/requests"
|
||||
"hepa-calc-api/api/responses"
|
||||
"hepa-calc-api/global"
|
||||
"hepa-calc-api/utils"
|
||||
)
|
||||
|
||||
type OrderSingle struct{}
|
||||
|
||||
// GetOrderSinglePage 获取单项订单列表-分页
|
||||
func (b *OrderSingle) GetOrderSinglePage(c *gin.Context) {
|
||||
orderSingleRequest := requests.OrderSingleRequest{}
|
||||
req := orderSingleRequest.GetOrderSinglePage
|
||||
if err := c.ShouldBind(&req); err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 参数验证
|
||||
if err := global.Validate.Struct(req); err != nil {
|
||||
responses.FailWithMessage(utils.Translate(err), c)
|
||||
return
|
||||
}
|
||||
|
||||
if req.Page == 0 {
|
||||
req.Page = 1
|
||||
}
|
||||
|
||||
if req.PageSize == 0 {
|
||||
req.PageSize = 20
|
||||
}
|
||||
|
||||
userId := c.GetInt64("UserId")
|
||||
req.UserId = userId
|
||||
|
||||
// 获取数据
|
||||
orderSingleDao := dao.OrderSingleDao{}
|
||||
orderSingle, total, err := orderSingleDao.GetOrderSinglePageSearch(req, req.Page, req.PageSize)
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 处理返回值
|
||||
g := dto.GetOrderSingleListDto(orderSingle)
|
||||
|
||||
result := make(map[string]interface{})
|
||||
result["page"] = req.Page
|
||||
result["page_size"] = req.PageSize
|
||||
result["total"] = total
|
||||
result["data"] = g
|
||||
responses.OkWithData(result, c)
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"hepa-calc-api/api/requests"
|
||||
"hepa-calc-api/api/responses"
|
||||
"hepa-calc-api/api/service"
|
||||
"hepa-calc-api/global"
|
||||
"hepa-calc-api/utils"
|
||||
)
|
||||
|
||||
type Public struct{}
|
||||
|
||||
// GetCaptcha 获取验证码
|
||||
func (b *Public) GetCaptcha(c *gin.Context) {
|
||||
id, b64s, err := utils.GenerateCaptcha()
|
||||
if err != nil {
|
||||
responses.FailWithMessage("验证码获取失败", c)
|
||||
}
|
||||
|
||||
responses.OkWithData(gin.H{
|
||||
"id": id,
|
||||
"b64s": b64s,
|
||||
}, c)
|
||||
}
|
||||
|
||||
// GetPhoneCode 获取手机验证码
|
||||
func (b *Public) GetPhoneCode(c *gin.Context) {
|
||||
publicRequest := requests.PublicRequest{}
|
||||
req := publicRequest.GetPhoneCode
|
||||
if err := c.ShouldBind(&req); err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 参数验证
|
||||
if err := global.Validate.Struct(req); err != nil {
|
||||
responses.FailWithMessage(utils.Translate(err), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 获取手机验证码
|
||||
publicService := service.PublicService{}
|
||||
_, err := publicService.GetPhoneCode(req.Scene, req.Phone)
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
responses.Ok(c)
|
||||
}
|
||||
|
||||
// GetIndex 获取首页数据
|
||||
func (b *Public) GetIndex(c *gin.Context) {
|
||||
userId := c.GetInt64("UserId") // 用户id
|
||||
|
||||
publicService := service.PublicService{}
|
||||
g, err := publicService.GetIndex(userId)
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
responses.OkWithData(g, c)
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"hepa-calc-api/api/dao"
|
||||
"hepa-calc-api/api/dto"
|
||||
"hepa-calc-api/api/requests"
|
||||
"hepa-calc-api/api/responses"
|
||||
"hepa-calc-api/api/service"
|
||||
"hepa-calc-api/global"
|
||||
"hepa-calc-api/utils"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type Question struct{}
|
||||
|
||||
// GetQuestionPage 获取问题列表-分页
|
||||
func (b *Question) GetQuestionPage(c *gin.Context) {
|
||||
questionRequest := requests.QuestionRequest{}
|
||||
req := questionRequest.GetQuestionPage
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 参数验证
|
||||
if err := global.Validate.Struct(req); err != nil {
|
||||
responses.FailWithMessage(utils.Translate(err), c)
|
||||
return
|
||||
}
|
||||
|
||||
if req.Page == 0 {
|
||||
req.Page = 1
|
||||
}
|
||||
|
||||
if req.PageSize == 0 {
|
||||
req.PageSize = 20
|
||||
}
|
||||
|
||||
// 获取数据
|
||||
questionDao := dao.QuestionDao{}
|
||||
question, total, err := questionDao.GetQuestionPageSearch(req, req.Page, req.PageSize)
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 处理返回值
|
||||
g := dto.GetQuestionPageListDto(question)
|
||||
|
||||
result := make(map[string]interface{})
|
||||
result["page"] = req.Page
|
||||
result["page_size"] = req.PageSize
|
||||
result["total"] = total
|
||||
result["data"] = g
|
||||
responses.OkWithData(result, c)
|
||||
}
|
||||
|
||||
// GetQuestionHot 获取问题列表-热榜
|
||||
func (b *Question) GetQuestionHot(c *gin.Context) {
|
||||
// 获取数据
|
||||
questionService := service.QuestionService{}
|
||||
|
||||
// 获取算一算热榜-人气数最高的9个
|
||||
hotQuestions, err := questionService.GetHotList()
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 处理返回值
|
||||
g := dto.GetHotQuestionListDto(hotQuestions)
|
||||
|
||||
responses.OkWithData(g, c)
|
||||
}
|
||||
|
||||
// GetQuestion 获取问题详情
|
||||
func (r *Question) GetQuestion(c *gin.Context) {
|
||||
userId := c.GetInt64("UserId")
|
||||
|
||||
id := c.Param("question_id")
|
||||
if id == "" {
|
||||
responses.FailWithMessage("缺少参数", c)
|
||||
return
|
||||
}
|
||||
|
||||
// 将 id 转换为 int64 类型
|
||||
questionId, err := strconv.ParseInt(id, 10, 64)
|
||||
if err != nil {
|
||||
responses.Fail(c)
|
||||
return
|
||||
}
|
||||
|
||||
// 获取数据
|
||||
questionDao := dao.QuestionDao{}
|
||||
question, err := questionDao.GetQuestionById(questionId)
|
||||
if err != nil {
|
||||
responses.FailWithMessage("题目错误", c)
|
||||
return
|
||||
}
|
||||
|
||||
// 检测问题是否被用户收藏
|
||||
userCollectionService := service.UserCollectionService{}
|
||||
IsCollection := userCollectionService.CheckUserCollectionQuestion(userId, questionId)
|
||||
|
||||
// 获取用户首次购买价格
|
||||
questionService := service.QuestionService{}
|
||||
firstTimePrice, err := questionService.GetUserFirstTimeBuyPrice(userId, questionId)
|
||||
if err != nil {
|
||||
responses.FailWithMessage("题目错误", c)
|
||||
return
|
||||
}
|
||||
|
||||
// 获取问题被购买数量
|
||||
buyCount, err := questionService.GetQuestionBuyCount(userId, questionId)
|
||||
|
||||
g := dto.GetQuestionDto(question)
|
||||
|
||||
// 加载数据-是否收藏
|
||||
g.LoadIsCollection(IsCollection)
|
||||
|
||||
// 加载数据-首次购买价格
|
||||
g.LoadFirstTimePrice(firstTimePrice)
|
||||
|
||||
// 加载数据-问题被购买数量
|
||||
g.LoadBuyCount(buyCount)
|
||||
|
||||
responses.OkWithData(g, c)
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"hepa-calc-api/api/dao"
|
||||
"hepa-calc-api/api/dto"
|
||||
"hepa-calc-api/api/responses"
|
||||
)
|
||||
|
||||
type SystemMember struct{}
|
||||
|
||||
// GetSystemMember 获取会员配置数据
|
||||
func (b *SystemMember) GetSystemMember(c *gin.Context) {
|
||||
systemMemberDao := dao.SystemMemberDao{}
|
||||
|
||||
maps := make(map[string]interface{})
|
||||
systemMember, err := systemMemberDao.GetSystemMemberList(maps)
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 处理返回值
|
||||
g := dto.GetSystemMemberListDto(systemMember)
|
||||
|
||||
responses.OkWithData(g, c)
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"hepa-calc-api/api/dao"
|
||||
"hepa-calc-api/api/dto"
|
||||
"hepa-calc-api/api/responses"
|
||||
)
|
||||
|
||||
type User struct{}
|
||||
|
||||
// GetUser 获取用户数据-基本信息
|
||||
func (r *User) GetUser(c *gin.Context) {
|
||||
userId := c.GetInt64("UserId")
|
||||
|
||||
// 获取用户数据
|
||||
userDao := dao.UserDao{}
|
||||
user, err := userDao.GetUserById(userId)
|
||||
if err != nil || user == nil {
|
||||
responses.FailWithMessage("用户数据错误", c)
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
|
||||
if user.UserStatus == 2 {
|
||||
responses.FailWithMessage("用户已禁用", c)
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
|
||||
g := dto.GetUserDto(user)
|
||||
|
||||
responses.OkWithData(g, c)
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"hepa-calc-api/api/dao"
|
||||
"hepa-calc-api/api/dto"
|
||||
"hepa-calc-api/api/requests"
|
||||
"hepa-calc-api/api/responses"
|
||||
"hepa-calc-api/api/service"
|
||||
"hepa-calc-api/global"
|
||||
"hepa-calc-api/utils"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type UserCollection struct{}
|
||||
|
||||
// GetUserCollectionPage 获取用户收藏题目列表-分页
|
||||
func (b *UserCollection) GetUserCollectionPage(c *gin.Context) {
|
||||
userCollectionRequest := requests.UserCollectionRequest{}
|
||||
req := userCollectionRequest.GetUserCollectionPage
|
||||
if err := c.ShouldBind(&req); err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 参数验证
|
||||
if err := global.Validate.Struct(req); err != nil {
|
||||
responses.FailWithMessage(utils.Translate(err), c)
|
||||
return
|
||||
}
|
||||
|
||||
if req.Page == 0 {
|
||||
req.Page = 1
|
||||
}
|
||||
|
||||
if req.PageSize == 0 {
|
||||
req.PageSize = 20
|
||||
}
|
||||
|
||||
userId := c.GetInt64("UserId")
|
||||
req.UserId = userId
|
||||
|
||||
// 获取数据
|
||||
userCollectionDao := dao.UserCollectionDao{}
|
||||
userCollection, total, err := userCollectionDao.GetUserCollectionPageSearch(req, req.Page, req.PageSize)
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 处理返回值
|
||||
g := dto.GetUserCollectionListDto(userCollection)
|
||||
|
||||
result := make(map[string]interface{})
|
||||
result["page"] = req.Page
|
||||
result["page_size"] = req.PageSize
|
||||
result["total"] = total
|
||||
result["data"] = g
|
||||
responses.OkWithData(result, c)
|
||||
}
|
||||
|
||||
// PutUserCollection 收藏题目
|
||||
func (r *UserCollection) PutUserCollection(c *gin.Context) {
|
||||
userCollectionRequest := requests.UserCollectionRequest{}
|
||||
req := userCollectionRequest.PutUserCollection
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 参数验证
|
||||
if err := global.Validate.Struct(req); err != nil {
|
||||
responses.FailWithMessage(utils.Translate(err), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 将 id 转换为 int64 类型
|
||||
questionId, err := strconv.ParseInt(req.QuestionId, 10, 64)
|
||||
if err != nil {
|
||||
responses.Fail(c)
|
||||
return
|
||||
}
|
||||
|
||||
userId := c.GetInt64("UserId")
|
||||
|
||||
// 业务处理
|
||||
userCollectionService := service.UserCollectionService{}
|
||||
res, err := userCollectionService.PutUserCollection(userId, questionId)
|
||||
if err != nil || res != true {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
responses.Ok(c)
|
||||
}
|
||||
|
||||
// PutUserCollectionCancel 取消收藏题目
|
||||
func (r *UserCollection) PutUserCollectionCancel(c *gin.Context) {
|
||||
userCollectionRequest := requests.UserCollectionRequest{}
|
||||
req := userCollectionRequest.PutUserCollectionCancel
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 参数验证
|
||||
if err := global.Validate.Struct(req); err != nil {
|
||||
responses.FailWithMessage(utils.Translate(err), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 将 id 转换为 int64 类型
|
||||
questionId, err := strconv.ParseInt(req.QuestionId, 10, 64)
|
||||
if err != nil {
|
||||
responses.Fail(c)
|
||||
return
|
||||
}
|
||||
|
||||
userId := c.GetInt64("UserId")
|
||||
|
||||
// 业务处理
|
||||
userCollectionService := service.UserCollectionService{}
|
||||
res, err := userCollectionService.PutUserCollectionCancel(userId, questionId)
|
||||
if err != nil || res != true {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
responses.Ok(c)
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"hepa-calc-api/api/dao"
|
||||
"hepa-calc-api/api/dto"
|
||||
"hepa-calc-api/api/requests"
|
||||
"hepa-calc-api/api/responses"
|
||||
"hepa-calc-api/global"
|
||||
"hepa-calc-api/utils"
|
||||
)
|
||||
|
||||
type UserCoupon struct{}
|
||||
|
||||
// GetUserCouponPage 获取优惠卷列表-分页
|
||||
func (b *UserCoupon) GetUserCouponPage(c *gin.Context) {
|
||||
userCouponRequest := requests.UserCouponRequest{}
|
||||
req := userCouponRequest.GetUserCouponPage
|
||||
if err := c.ShouldBind(&req); err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 参数验证
|
||||
if err := global.Validate.Struct(req); err != nil {
|
||||
responses.FailWithMessage(utils.Translate(err), c)
|
||||
return
|
||||
}
|
||||
|
||||
if req.Page == 0 {
|
||||
req.Page = 1
|
||||
}
|
||||
|
||||
if req.PageSize == 0 {
|
||||
req.PageSize = 20
|
||||
}
|
||||
|
||||
userId := c.GetInt64("UserId")
|
||||
req.UserId = userId
|
||||
|
||||
// 获取数据
|
||||
userCouponDao := dao.UserCouponDao{}
|
||||
userCoupon, total, err := userCouponDao.GetUserCouponPageSearch(req, req.Page, req.PageSize)
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 处理返回值
|
||||
g := dto.GetUserCouponListDto(userCoupon)
|
||||
|
||||
result := make(map[string]interface{})
|
||||
result["page"] = req.Page
|
||||
result["page_size"] = req.PageSize
|
||||
result["total"] = total
|
||||
result["data"] = g
|
||||
responses.OkWithData(result, c)
|
||||
}
|
||||
|
||||
// GetUserCouponUnnotified 获取还未弹窗的优惠卷
|
||||
func (b *UserCoupon) GetUserCouponUnnotified(c *gin.Context) {
|
||||
userId := c.GetInt64("UserId")
|
||||
|
||||
// 获取数据
|
||||
userCouponDao := dao.UserCouponDao{}
|
||||
maps := make(map[string]interface{})
|
||||
maps["user_id"] = userId
|
||||
maps["user_coupon_status"] = 0
|
||||
maps["is_windows"] = 0
|
||||
userCoupon, _ := userCouponDao.GetUserCoupon(maps)
|
||||
if userCoupon == nil {
|
||||
responses.OkWithData(nil, c)
|
||||
return
|
||||
}
|
||||
|
||||
// 获取优惠卷数据
|
||||
couponDao := dao.CouponDao{}
|
||||
coupon, _ := couponDao.GetCouponById(userCoupon.CouponId)
|
||||
if coupon == nil {
|
||||
responses.OkWithData(nil, c)
|
||||
return
|
||||
}
|
||||
|
||||
// 处理返回值
|
||||
g := dto.GetUserCouponDto(userCoupon)
|
||||
|
||||
g.LoadCoupon(coupon)
|
||||
|
||||
responses.OkWithData(g, c)
|
||||
}
|
||||
|
||||
// GetUserUsableCoupon 获取用户当前可用优惠卷
|
||||
func (b *UserCoupon) GetUserUsableCoupon(c *gin.Context) {
|
||||
userCouponRequest := requests.UserCouponRequest{}
|
||||
req := userCouponRequest.GetUserCouponPage
|
||||
if err := c.ShouldBind(&req); err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 参数验证
|
||||
if err := global.Validate.Struct(req); err != nil {
|
||||
responses.FailWithMessage(utils.Translate(err), c)
|
||||
return
|
||||
}
|
||||
|
||||
if req.Page == 0 {
|
||||
req.Page = 1
|
||||
}
|
||||
|
||||
if req.PageSize == 0 {
|
||||
req.PageSize = 20
|
||||
}
|
||||
|
||||
userId := c.GetInt64("UserId")
|
||||
req.UserId = userId
|
||||
|
||||
// 获取数据
|
||||
userCouponDao := dao.UserCouponDao{}
|
||||
userCoupon, total, err := userCouponDao.GetUserCouponPageSearch(req, req.Page, req.PageSize)
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 处理返回值
|
||||
g := dto.GetUserCouponListDto(userCoupon)
|
||||
|
||||
result := make(map[string]interface{})
|
||||
result["page"] = req.Page
|
||||
result["page_size"] = req.PageSize
|
||||
result["total"] = total
|
||||
result["data"] = g
|
||||
responses.OkWithData(result, c)
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
package controller
|
||||
|
||||
// Api api接口
|
||||
type Api struct {
|
||||
}
|
||||
@@ -72,6 +72,15 @@ func (r *BaseClassDao) GetBaseClassList(maps interface{}) (m []*model.BaseClass,
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// GetBaseClassOrderList 获取列表-排序
|
||||
func (r *BaseClassDao) GetBaseClassOrderList(maps interface{}) (m []*model.BaseClass, err error) {
|
||||
err = global.Db.Where(maps).Order("sort desc").Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// GetBaseClassCount 获取数量
|
||||
func (r *BaseClassDao) GetBaseClassCount(maps interface{}) (total int64, err error) {
|
||||
err = global.Db.Model(&model.BaseClass{}).Where(maps).Count(&total).Error
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"hepa-calc-api/api/model"
|
||||
"hepa-calc-api/api/requests"
|
||||
"hepa-calc-api/global"
|
||||
)
|
||||
|
||||
@@ -106,3 +107,69 @@ func (r *OrderMemberDao) GetOrderMember(maps interface{}) (m *model.OrderMember,
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// GetOrderMemberPageSearch 获取列表-分页
|
||||
func (r *OrderMemberDao) GetOrderMemberPageSearch(req requests.GetOrderMemberPage, page, pageSize int) (m []*model.OrderMember, total int64, err error) {
|
||||
var totalRecords int64
|
||||
|
||||
// 构建查询条件
|
||||
query := global.Db.Model(&model.OrderMember{})
|
||||
query = query.Where("user_id = ?", req.UserId)
|
||||
query = query.Where("is_delete = ?", 0)
|
||||
|
||||
query = query.Preload("SystemMember")
|
||||
|
||||
// 会员id
|
||||
if req.SystemMemberId != "" {
|
||||
query = query.Where("system_member_id = ?", req.SystemMemberId)
|
||||
}
|
||||
|
||||
// 订单状态(1:待支付 2:已完成 3:已取消)
|
||||
if req.OrderStatus != nil {
|
||||
query = query.Where("order_status = ?", req.OrderStatus)
|
||||
}
|
||||
|
||||
// 支付渠道
|
||||
if req.PayChannel != nil {
|
||||
query = query.Where("pay_channel = ?", req.PayChannel)
|
||||
}
|
||||
|
||||
// 支付状态
|
||||
if req.PayStatus != nil {
|
||||
query = query.Where("pay_status = ?", req.PayStatus)
|
||||
}
|
||||
|
||||
// 订单退款状态
|
||||
if req.RefundStatus != nil {
|
||||
query = query.Where("refund_status = ?", req.RefundStatus)
|
||||
}
|
||||
|
||||
// 系统订单编号
|
||||
if req.OrderNo != "" {
|
||||
query = query.Where("order_no = ?", req.OrderNo)
|
||||
}
|
||||
|
||||
// 第三方支付流水号
|
||||
if req.EscrowTradeNo != "" {
|
||||
query = query.Where("escrow_trade_no = ?", req.EscrowTradeNo)
|
||||
}
|
||||
|
||||
// 取消状态
|
||||
if req.CancelStatus != nil {
|
||||
query = query.Where("cancel_status = ?", req.CancelStatus)
|
||||
}
|
||||
|
||||
// 排序
|
||||
query = query.Order("created_at desc")
|
||||
|
||||
// 查询总数量
|
||||
if err := query.Count(&totalRecords).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
err = query.Scopes(model.Paginate(page, pageSize)).Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
return m, totalRecords, nil
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"hepa-calc-api/api/model"
|
||||
"hepa-calc-api/api/requests"
|
||||
"hepa-calc-api/global"
|
||||
)
|
||||
|
||||
@@ -106,3 +107,91 @@ func (r *OrderSingleDao) GetOrderSingle(maps interface{}) (m *model.OrderSingle,
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// GetOrderSingleOrderList 获取列表-排序
|
||||
func (r *OrderSingleDao) GetOrderSingleOrderList(maps interface{}, orderField string, limit int) (m []*model.OrderSingle, err error) {
|
||||
err = global.Db.Where(maps).Preload(clause.Associations).Order(orderField).Limit(limit).Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// GetOrderSinglePageSearch 获取列表-分页
|
||||
func (r *OrderSingleDao) GetOrderSinglePageSearch(req requests.GetOrderSinglePage, page, pageSize int) (m []*model.OrderSingle, total int64, err error) {
|
||||
var totalRecords int64
|
||||
|
||||
// 构建查询条件
|
||||
query := global.Db.Model(&model.OrderSingle{})
|
||||
query = query.Where("user_id = ?", req.UserId)
|
||||
query = query.Where("is_delete = ?", 0)
|
||||
|
||||
query = query.Preload("Question")
|
||||
|
||||
// 问题id
|
||||
if req.QuestionId != "" {
|
||||
query = query.Where("question_id = ?", req.QuestionId)
|
||||
}
|
||||
|
||||
// 订单状态(1:待支付 2:已完成 3:已取消)
|
||||
if req.OrderStatus != nil {
|
||||
query = query.Where("order_status = ?", req.OrderStatus)
|
||||
}
|
||||
|
||||
// 支付渠道
|
||||
if req.PayChannel != nil {
|
||||
query = query.Where("pay_channel = ?", req.PayChannel)
|
||||
}
|
||||
|
||||
// 支付状态
|
||||
if req.PayStatus != nil {
|
||||
query = query.Where("pay_status = ?", req.PayStatus)
|
||||
}
|
||||
|
||||
// 订单退款状态
|
||||
if req.RefundStatus != nil {
|
||||
query = query.Where("refund_status = ?", req.RefundStatus)
|
||||
}
|
||||
|
||||
// 系统订单编号
|
||||
if req.OrderNo != "" {
|
||||
query = query.Where("order_no = ?", req.OrderNo)
|
||||
}
|
||||
|
||||
// 第三方支付流水号
|
||||
if req.EscrowTradeNo != "" {
|
||||
query = query.Where("escrow_trade_no = ?", req.EscrowTradeNo)
|
||||
}
|
||||
|
||||
// 取消状态
|
||||
if req.CancelStatus != nil {
|
||||
query = query.Where("cancel_status = ?", req.CancelStatus)
|
||||
}
|
||||
|
||||
// 排序
|
||||
query = query.Order("created_at desc")
|
||||
|
||||
// 查询总数量
|
||||
if err := query.Count(&totalRecords).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
err = query.Scopes(model.Paginate(page, pageSize)).Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
return m, totalRecords, nil
|
||||
}
|
||||
|
||||
// GetUserFirstTimeBuyOrderSingle 获取用户首次购买的订单
|
||||
func (r *OrderSingleDao) GetUserFirstTimeBuyOrderSingle(userId, questionId int64) (m *model.OrderSingle, err error) {
|
||||
err = global.Db.
|
||||
Where("user_id = ?", userId).
|
||||
Where("question_id = ?", questionId).
|
||||
Where("order_status != ?", 3).
|
||||
First(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"hepa-calc-api/api/model"
|
||||
"hepa-calc-api/api/requests"
|
||||
"hepa-calc-api/global"
|
||||
)
|
||||
|
||||
@@ -106,3 +108,146 @@ func (r *QuestionDao) GetQuestion(maps interface{}) (m *model.Question, err erro
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// GetQuestionOrderLimitList 获取列表-排序、限制数量
|
||||
func (r *QuestionDao) GetQuestionOrderLimitList(maps interface{}, orderField string, limit int) (m []*model.Question, err error) {
|
||||
err = global.Db.Where(maps).Order(orderField).Limit(limit).Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// GetQuestionPageSearch 获取题目列表-分页
|
||||
func (r *QuestionDao) GetQuestionPageSearch(req requests.GetQuestionPage, page, pageSize int) (m []*model.Question, total int64, err error) {
|
||||
var totalRecords int64
|
||||
|
||||
// 构建查询条件
|
||||
query := global.Db.Model(&model.Question{})
|
||||
|
||||
// 是否隐藏
|
||||
query = query.Where("is_hide = ?", 0)
|
||||
|
||||
// 主键id
|
||||
if req.QuestionId != "" {
|
||||
query = query.Where("question_id = ?", req.QuestionId)
|
||||
}
|
||||
|
||||
// 标题
|
||||
if req.QuestionTitle != "" {
|
||||
query = query.Where("question_title LIKE ?", "%"+req.QuestionTitle+"%")
|
||||
}
|
||||
|
||||
// 副标题
|
||||
if req.QuestionSubtitle != "" {
|
||||
query = query.Where("question_subtitle LIKE ?", "%"+req.QuestionSubtitle+"%")
|
||||
}
|
||||
|
||||
// 唯一标识
|
||||
if req.QuestionIden != "" {
|
||||
query = query.Where("question_iden = ?", req.QuestionIden)
|
||||
}
|
||||
|
||||
// 问题状态
|
||||
if req.QuestionStatus != nil {
|
||||
query = query.Where("question_status = ?", req.QuestionStatus)
|
||||
}
|
||||
|
||||
// 是否推荐
|
||||
if req.IsRecommend != nil {
|
||||
query = query.Where("is_recommend = ?", req.IsRecommend)
|
||||
}
|
||||
|
||||
// 问题介绍
|
||||
if req.QuestionBrief != "" {
|
||||
query = query.Where("question_brief LIKE ?", "%"+req.QuestionBrief+"%")
|
||||
}
|
||||
|
||||
// 问题解释/科普
|
||||
if req.QuestionExplain != "" {
|
||||
query = query.Where("question_explain LIKE ?", "%"+req.QuestionExplain+"%")
|
||||
}
|
||||
|
||||
// 分类标识
|
||||
if req.ClassId != "" {
|
||||
baseClassQuery := global.Db.Model(&model.BaseClass{}).
|
||||
Select("class_id").
|
||||
Where("class_id = ?", req.ClassId)
|
||||
|
||||
questionClassQuery := global.Db.Model(&model.QuestionClass{}).
|
||||
Select("question_id").
|
||||
Where("class_id IN (?)", baseClassQuery)
|
||||
|
||||
query = query.Where("question_id IN (?)", questionClassQuery)
|
||||
}
|
||||
|
||||
// 排序
|
||||
if req.Order != nil {
|
||||
// 点击次数(点击进入详情页的人次)
|
||||
if req.Order.ClickCount != "" {
|
||||
if req.Order.ClickCount != "desc" && req.Order.ClickCount != "asc" {
|
||||
return nil, 0, errors.New("排序字段错误")
|
||||
}
|
||||
|
||||
query = query.Order("click_count " + req.Order.ClickCount)
|
||||
}
|
||||
|
||||
// 提交次数(提交个人信息进行了算算的人次)
|
||||
if req.Order.SubmitCount != "" {
|
||||
if req.Order.SubmitCount != "desc" && req.Order.SubmitCount != "asc" {
|
||||
return nil, 0, errors.New("排序字段错误")
|
||||
}
|
||||
|
||||
query = query.Order("submit_count " + req.Order.SubmitCount)
|
||||
}
|
||||
|
||||
// 支付次数(查看报告的人次)
|
||||
if req.Order.PayCount != "" {
|
||||
if req.Order.PayCount != "desc" && req.Order.PayCount != "asc" {
|
||||
return nil, 0, errors.New("排序字段错误")
|
||||
}
|
||||
|
||||
query = query.Order("pay_count " + req.Order.PayCount)
|
||||
}
|
||||
|
||||
// 价格(原价)
|
||||
if req.Order.Price != "" {
|
||||
if req.Order.Price != "desc" && req.Order.Price != "asc" {
|
||||
return nil, 0, errors.New("排序字段错误")
|
||||
}
|
||||
|
||||
query = query.Order("price " + req.Order.Price)
|
||||
}
|
||||
|
||||
// 优惠价格
|
||||
if req.Order.DiscountPrice != "" {
|
||||
if req.Order.DiscountPrice != "desc" && req.Order.DiscountPrice != "asc" {
|
||||
return nil, 0, errors.New("排序字段错误")
|
||||
}
|
||||
|
||||
query = query.Order("discount_price " + req.Order.DiscountPrice)
|
||||
}
|
||||
|
||||
if req.Order.UpdatedAt != "" {
|
||||
if req.Order.UpdatedAt != "desc" && req.Order.UpdatedAt != "asc" {
|
||||
return nil, 0, errors.New("排序字段错误")
|
||||
}
|
||||
|
||||
query = query.Order("updated_at " + req.Order.UpdatedAt)
|
||||
}
|
||||
}
|
||||
|
||||
// 排序
|
||||
query = query.Order("created_at desc")
|
||||
|
||||
// 查询总数量
|
||||
if err := query.Count(&totalRecords).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
err = query.Scopes(model.Paginate(page, pageSize)).Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
return m, totalRecords, nil
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"hepa-calc-api/api/model"
|
||||
"hepa-calc-api/api/requests"
|
||||
"hepa-calc-api/global"
|
||||
)
|
||||
|
||||
@@ -106,3 +107,28 @@ func (r *UserCollectionDao) GetUserCollection(maps interface{}) (m *model.UserCo
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// GetUserCollectionPageSearch 获取列表-分页
|
||||
func (r *UserCollectionDao) GetUserCollectionPageSearch(req requests.GetUserCollectionPage, page, pageSize int) (m []*model.UserCollection, total int64, err error) {
|
||||
var totalRecords int64
|
||||
|
||||
// 构建查询条件
|
||||
query := global.Db.Model(&model.UserCollection{})
|
||||
query = query.Where("user_id = ?", req.UserId)
|
||||
|
||||
query = query.Preload("Question")
|
||||
|
||||
// 排序
|
||||
query = query.Order("created_at desc")
|
||||
|
||||
// 查询总数量
|
||||
if err := query.Count(&totalRecords).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
err = query.Scopes(model.Paginate(page, pageSize)).Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
return m, totalRecords, nil
|
||||
}
|
||||
|
||||
@@ -4,7 +4,10 @@ import (
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"hepa-calc-api/api/model"
|
||||
"hepa-calc-api/api/requests"
|
||||
"hepa-calc-api/global"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type UserCouponDao struct {
|
||||
@@ -106,3 +109,85 @@ func (r *UserCouponDao) GetUserCoupon(maps interface{}) (m *model.UserCoupon, er
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// GetUserCouponPageSearch 获取列表-分页
|
||||
func (r *UserCouponDao) GetUserCouponPageSearch(req requests.GetUserCouponPage, page, pageSize int) (m []*model.UserCoupon, total int64, err error) {
|
||||
var totalRecords int64
|
||||
|
||||
// 构建查询条件
|
||||
query := global.Db.Model(&model.UserCoupon{})
|
||||
query = query.Where("user_id = ?", req.UserId)
|
||||
|
||||
// 优惠卷
|
||||
query = query.Preload("Coupon", func(db *gorm.DB) *gorm.DB {
|
||||
return db.Select("coupon_id", "coupon_name", "coupon_type", "coupon_status", "application_scope", "coupon_price", "valid_start_time", "valid_end_time", "coupon_desc")
|
||||
})
|
||||
|
||||
// 优惠券id
|
||||
if req.CouponId != "" {
|
||||
query = query.Where("coupon_id = ?", req.CouponId)
|
||||
}
|
||||
|
||||
// 状态(0:未使用 1:已使用 3:已过期)
|
||||
if req.UserCouponStatus != nil {
|
||||
query = query.Where("user_coupon_status = ?", req.UserCouponStatus)
|
||||
}
|
||||
|
||||
// 是否已弹窗
|
||||
if req.IsWindows != nil {
|
||||
query = query.Where("is_windows = ?", req.IsWindows)
|
||||
}
|
||||
|
||||
// 使用时间
|
||||
if req.CouponUseDate != "" {
|
||||
couponUseDate := strings.Split(req.CouponUseDate, "&")
|
||||
if len(couponUseDate) == 2 {
|
||||
startTime, _ := time.Parse("2006-01-02", couponUseDate[0])
|
||||
endTime, _ := time.Parse("2006-01-02", couponUseDate[1])
|
||||
|
||||
endTime = endTime.Add(23*time.Hour + 59*time.Minute + 59*time.Second)
|
||||
|
||||
query = query.Where("coupon_use_date BETWEEN ? AND ?", startTime, endTime)
|
||||
}
|
||||
}
|
||||
|
||||
// 有效开始时间
|
||||
if req.ValidStartTime != "" {
|
||||
validStartTime := strings.Split(req.ValidStartTime, "&")
|
||||
if len(validStartTime) == 2 {
|
||||
startTime, _ := time.Parse("2006-01-02", validStartTime[0])
|
||||
endTime, _ := time.Parse("2006-01-02", validStartTime[1])
|
||||
|
||||
endTime = endTime.Add(23*time.Hour + 59*time.Minute + 59*time.Second)
|
||||
|
||||
query = query.Where("valid_start_time BETWEEN ? AND ?", startTime, endTime)
|
||||
}
|
||||
}
|
||||
|
||||
// 有效结束时间
|
||||
if req.ValidEndTime != "" {
|
||||
validEndTime := strings.Split(req.ValidEndTime, "&")
|
||||
if len(validEndTime) == 2 {
|
||||
startTime, _ := time.Parse("2006-01-02", validEndTime[0])
|
||||
endTime, _ := time.Parse("2006-01-02", validEndTime[1])
|
||||
|
||||
endTime = endTime.Add(23*time.Hour + 59*time.Minute + 59*time.Second)
|
||||
|
||||
query = query.Where("valid_end_time BETWEEN ? AND ?", startTime, endTime)
|
||||
}
|
||||
}
|
||||
|
||||
// 排序
|
||||
query = query.Order("created_at desc")
|
||||
|
||||
// 查询总数量
|
||||
if err := query.Count(&totalRecords).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
err = query.Scopes(model.Paginate(page, pageSize)).Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
return m, totalRecords, nil
|
||||
}
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"hepa-calc-api/api/model"
|
||||
"hepa-calc-api/utils"
|
||||
)
|
||||
|
||||
// BaseClassDto 基础数据-分类表
|
||||
type BaseClassDto struct {
|
||||
ClassId string `json:"class_id"` // 主键id
|
||||
ClassName string `json:"class_name"` // 分类名称
|
||||
ClassStatus int `json:"class_status"` // 分类状态(1:正常 2:隐藏)
|
||||
ClassIcon string `json:"class_icon"` // 图标地址
|
||||
ClassBrief string `json:"class_brief"` // 分类简介
|
||||
Sort uint `json:"sort"` // 排序值(越大排名越靠前)
|
||||
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
|
||||
UpdatedAt model.LocalTime `json:"updated_at"` // 更新时间
|
||||
}
|
||||
|
||||
// GetBaseClassDto 详情-基础数据-分类表
|
||||
func GetBaseClassDto(m *model.BaseClass) *BaseClassDto {
|
||||
return &BaseClassDto{
|
||||
ClassId: fmt.Sprintf("%d", m.ClassId),
|
||||
ClassName: m.ClassName,
|
||||
ClassStatus: m.ClassStatus,
|
||||
ClassIcon: utils.AddOssDomain(m.ClassIcon),
|
||||
ClassBrief: m.ClassBrief,
|
||||
Sort: m.Sort,
|
||||
CreatedAt: m.CreatedAt,
|
||||
UpdatedAt: m.UpdatedAt,
|
||||
}
|
||||
}
|
||||
|
||||
// GetBaseClassListDto 列表-基础数据-分类表
|
||||
func GetBaseClassListDto(m []*model.BaseClass) []*BaseClassDto {
|
||||
// 处理返回值
|
||||
responses := make([]*BaseClassDto, len(m))
|
||||
|
||||
if len(m) > 0 {
|
||||
for i, v := range m {
|
||||
response := &BaseClassDto{
|
||||
ClassId: fmt.Sprintf("%d", v.ClassId),
|
||||
ClassName: v.ClassName,
|
||||
ClassStatus: v.ClassStatus,
|
||||
ClassIcon: utils.AddOssDomain(v.ClassIcon),
|
||||
ClassBrief: v.ClassBrief,
|
||||
Sort: v.Sort,
|
||||
CreatedAt: v.CreatedAt,
|
||||
UpdatedAt: v.UpdatedAt,
|
||||
}
|
||||
|
||||
// 将转换后的结构体添加到新切片中
|
||||
responses[i] = response
|
||||
}
|
||||
}
|
||||
|
||||
return responses
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"hepa-calc-api/api/model"
|
||||
)
|
||||
|
||||
type CouponDto struct {
|
||||
CouponId string `json:"coupon_id"` // 主键id
|
||||
CouponName string `json:"coupon_name"` // 优惠券名称
|
||||
CouponType string `json:"coupon_type"` // 优惠券类型(1:无门槛 2:满减)
|
||||
CouponStatus int `json:"coupon_status"` // 状态(1:正常 2:强制失效 3:结束 4:删除)
|
||||
ApplicationScope int `json:"application_scope"` // 适用范围(1:全场通用)
|
||||
IsMutex int `json:"is_mutex"` // 是否互斥(0:否 1:是)
|
||||
CouponCount int `json:"coupon_count"` // 发放数量
|
||||
CouponTakeCount int `json:"coupon_take_count"` // 已领取数量
|
||||
CouponUsedCount int `json:"coupon_used_count"` // 已使用数量
|
||||
CouponPrice float64 `json:"coupon_price"` // 优惠券金额
|
||||
WithAmount float64 `json:"with_amount"` // 符合满减标准金额(优惠券类型为满减时使用)
|
||||
ValidType int `json:"valid_type"` // 有效类型(1:绝对时效,xxx-xxx时间段有效 2:相对时效 n天内有效)
|
||||
ValidDays int `json:"valid_days"` // 自领取之日起有效天数
|
||||
ValidStartTime model.LocalTime `json:"valid_start_time"` // 开始使用时间
|
||||
ValidEndTime model.LocalTime `json:"valid_end_time"` // 结束使用时间
|
||||
CouponDesc string `json:"coupon_desc"` // 优惠券描述
|
||||
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
|
||||
UpdatedAt model.LocalTime `json:"updated_at"` // 更新时间
|
||||
}
|
||||
|
||||
// GetCouponDto 优惠卷详情
|
||||
func GetCouponDto(m *model.Coupon) *CouponDto {
|
||||
return &CouponDto{
|
||||
CouponId: fmt.Sprintf("%d", m.CouponId),
|
||||
CouponName: m.CouponName,
|
||||
CouponType: m.CouponType,
|
||||
CouponStatus: m.CouponStatus,
|
||||
ApplicationScope: m.ApplicationScope,
|
||||
IsMutex: m.IsMutex,
|
||||
CouponCount: m.CouponCount,
|
||||
CouponTakeCount: m.CouponTakeCount,
|
||||
CouponUsedCount: m.CouponUsedCount,
|
||||
CouponPrice: m.CouponPrice,
|
||||
WithAmount: m.WithAmount,
|
||||
ValidType: m.ValidType,
|
||||
ValidDays: m.ValidDays,
|
||||
ValidStartTime: m.ValidStartTime,
|
||||
ValidEndTime: m.ValidEndTime,
|
||||
CouponDesc: m.CouponDesc,
|
||||
CreatedAt: m.CreatedAt,
|
||||
UpdatedAt: m.UpdatedAt,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"hepa-calc-api/api/model"
|
||||
)
|
||||
|
||||
// OrderMemberDto 订单-单项
|
||||
type OrderMemberDto struct {
|
||||
OrderId string `json:"order_id"` // 主键id
|
||||
UserId string `json:"user_id"` // 用户id
|
||||
SystemMemberId string `json:"system_member_id"` // 会员id
|
||||
OrderStatus int `json:"order_status"` // 订单状态(1:待支付 2:已完成 3:已取消)
|
||||
IsDelete int `json:"is_delete"` // 用户删除状态(0:否 1:是)
|
||||
PayChannel int `json:"pay_channel"` // 支付渠道(1:h5支付 2:app支付 3:会员支付)
|
||||
PayStatus int `json:"pay_status"` // 支付状态(1:未支付 2:已支付 3:支付中 4:支付失败 5:支付超时 6:支付关闭 7:已撤销 8:转入退款)
|
||||
PayTime model.LocalTime `json:"pay_time"` // 支付时间
|
||||
RefundStatus int `json:"refund_status"` // 订单退款状态(0:无退款 1:申请退款 2:退款中 3:退款成功 4:拒绝退款 5:退款关闭 6:退款异常 7:部分退款)
|
||||
OrderNo string `json:"order_no"` // 系统订单编号
|
||||
EscrowTradeNo string `json:"escrow_trade_no"` // 第三方支付流水号
|
||||
AmountTotal float64 `json:"amount_total"` // 订单金额
|
||||
CouponAmountTotal float64 `json:"coupon_amount_total"` // 优惠卷总金额
|
||||
PaymentAmountTotal float64 `json:"payment_amount_total"` // 实际付款金额
|
||||
CancelStatus int `json:"cancel_status"` // 取消状态(0:否 1:是)
|
||||
CancelTime model.LocalTime `json:"cancel_time"` // 订单取消时间
|
||||
CancelRemarks string `json:"cancel_remarks"` // 取消订单备注
|
||||
OrderRemarks string `json:"order_remarks"` // 订单备注
|
||||
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
|
||||
UpdatedAt model.LocalTime `json:"updated_at"` // 更新时间
|
||||
SystemMember *SystemMemberDto `json:"system_member"` // 会员
|
||||
}
|
||||
|
||||
// GetOrderMemberListDto 列表
|
||||
func GetOrderMemberListDto(m []*model.OrderMember) []*OrderMemberDto {
|
||||
// 处理返回值
|
||||
responses := make([]*OrderMemberDto, len(m))
|
||||
|
||||
if len(m) > 0 {
|
||||
for i, v := range m {
|
||||
response := &OrderMemberDto{
|
||||
OrderId: fmt.Sprintf("%d", v.OrderId),
|
||||
UserId: fmt.Sprintf("%d", v.UserId),
|
||||
SystemMemberId: fmt.Sprintf("%d", v.SystemMemberId),
|
||||
OrderStatus: v.OrderStatus,
|
||||
IsDelete: v.IsDelete,
|
||||
PayChannel: v.PayChannel,
|
||||
PayStatus: v.PayStatus,
|
||||
PayTime: v.PayTime,
|
||||
RefundStatus: v.RefundStatus,
|
||||
OrderNo: v.OrderNo,
|
||||
EscrowTradeNo: v.EscrowTradeNo,
|
||||
AmountTotal: v.AmountTotal,
|
||||
CouponAmountTotal: v.CouponAmountTotal,
|
||||
PaymentAmountTotal: v.PaymentAmountTotal,
|
||||
CancelStatus: v.CancelStatus,
|
||||
CancelTime: v.CancelTime,
|
||||
CancelRemarks: v.CancelRemarks,
|
||||
OrderRemarks: v.OrderRemarks,
|
||||
CreatedAt: v.CreatedAt,
|
||||
UpdatedAt: v.UpdatedAt,
|
||||
}
|
||||
|
||||
// 加载会员数据
|
||||
if v.SystemMember != nil {
|
||||
response = response.LoadSystemMember(v.SystemMember)
|
||||
}
|
||||
|
||||
// 将转换后的结构体添加到新切片中
|
||||
responses[i] = response
|
||||
}
|
||||
}
|
||||
|
||||
return responses
|
||||
}
|
||||
|
||||
// LoadSystemMember 加载会员数据
|
||||
func (r *OrderMemberDto) LoadSystemMember(m *model.SystemMember) *OrderMemberDto {
|
||||
if m != nil {
|
||||
r.SystemMember = GetSystemMemberDto(m)
|
||||
}
|
||||
return r
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"hepa-calc-api/api/model"
|
||||
)
|
||||
|
||||
// OrderSingleDto 订单-单项
|
||||
type OrderSingleDto struct {
|
||||
OrderId string `json:"order_id"` // 主键id
|
||||
UserId string `json:"user_id"` // 用户id
|
||||
QuestionId string `json:"question_id"` // 问题id
|
||||
OrderStatus int `json:"order_status"` // 订单状态(1:待支付 2:已完成 3:已取消)
|
||||
IsDelete int `json:"is_delete"` // 用户删除状态(0:否 1:是)
|
||||
PayChannel int `json:"pay_channel"` // 支付渠道(1:h5支付 2:app支付 3:会员支付)
|
||||
PayStatus int `json:"pay_status"` // 支付状态(1:未支付 2:已支付 3:支付中 4:支付失败 5:支付超时 6:支付关闭 7:已撤销 8:转入退款)
|
||||
PayTime model.LocalTime `json:"pay_time"` // 支付时间
|
||||
RefundStatus int `json:"refund_status"` // 订单退款状态(0:无退款 1:申请退款 2:退款中 3:退款成功 4:拒绝退款 5:退款关闭 6:退款异常 7:部分退款)
|
||||
OrderNo string `json:"order_no"` // 系统订单编号
|
||||
EscrowTradeNo string `json:"escrow_trade_no"` // 第三方支付流水号
|
||||
AmountTotal float64 `json:"amount_total"` // 订单金额
|
||||
CouponAmountTotal float64 `json:"coupon_amount_total"` // 优惠卷总金额
|
||||
PaymentAmountTotal float64 `json:"payment_amount_total"` // 实际付款金额
|
||||
CancelStatus int `json:"cancel_status"` // 取消状态(0:否 1:是)
|
||||
CancelTime model.LocalTime `json:"cancel_time"` // 订单取消时间
|
||||
CancelRemarks string `json:"cancel_remarks"` // 取消订单备注
|
||||
OrderRemarks string `json:"order_remarks"` // 订单备注
|
||||
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
|
||||
UpdatedAt model.LocalTime `json:"updated_at"` // 更新时间
|
||||
Question *QuestionDto `json:"question"` // 问题
|
||||
}
|
||||
|
||||
// GetOrderSingleListDto 列表
|
||||
func GetOrderSingleListDto(m []*model.OrderSingle) []*OrderSingleDto {
|
||||
// 处理返回值
|
||||
responses := make([]*OrderSingleDto, len(m))
|
||||
|
||||
if len(m) > 0 {
|
||||
for i, v := range m {
|
||||
response := &OrderSingleDto{
|
||||
OrderId: fmt.Sprintf("%d", v.OrderId),
|
||||
UserId: fmt.Sprintf("%d", v.UserId),
|
||||
QuestionId: fmt.Sprintf("%d", v.QuestionId),
|
||||
OrderStatus: v.OrderStatus,
|
||||
IsDelete: v.IsDelete,
|
||||
PayChannel: v.PayChannel,
|
||||
PayStatus: v.PayStatus,
|
||||
PayTime: v.PayTime,
|
||||
RefundStatus: v.RefundStatus,
|
||||
OrderNo: v.OrderNo,
|
||||
EscrowTradeNo: v.EscrowTradeNo,
|
||||
AmountTotal: v.AmountTotal,
|
||||
CouponAmountTotal: v.CouponAmountTotal,
|
||||
PaymentAmountTotal: v.PaymentAmountTotal,
|
||||
CancelStatus: v.CancelStatus,
|
||||
CancelTime: v.CancelTime,
|
||||
CancelRemarks: v.CancelRemarks,
|
||||
OrderRemarks: v.OrderRemarks,
|
||||
CreatedAt: v.CreatedAt,
|
||||
UpdatedAt: v.UpdatedAt,
|
||||
}
|
||||
|
||||
// 加载问题数据
|
||||
if v.Question != nil {
|
||||
response = response.LoadQuestion(v.Question)
|
||||
}
|
||||
|
||||
// 将转换后的结构体添加到新切片中
|
||||
responses[i] = response
|
||||
}
|
||||
}
|
||||
|
||||
return responses
|
||||
}
|
||||
|
||||
// LoadQuestion 加载题目数据
|
||||
func (r *OrderSingleDto) LoadQuestion(m *model.Question) *OrderSingleDto {
|
||||
if m != nil {
|
||||
r.Question = GetQuestionDto(m)
|
||||
}
|
||||
return r
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package dto
|
||||
|
||||
import "hepa-calc-api/api/model"
|
||||
|
||||
// IndexDto 首页
|
||||
type IndexDto struct {
|
||||
BaseClass []*BaseClassDto `json:"base_class"` // 分类
|
||||
HotQuestion []*QuestionDto `json:"hot_question"` // 热榜
|
||||
RecommendQuestion []*QuestionDto `json:"recommend_question"` // 为你推荐
|
||||
GuessUserLikeQuestion []*QuestionDto `json:"guess_user_like_question"` // 猜你喜欢
|
||||
}
|
||||
|
||||
// LoadBaseClass 加载数据-分类
|
||||
func (r *IndexDto) LoadBaseClass(m []*model.BaseClass) *IndexDto {
|
||||
if len(m) > 0 {
|
||||
r.BaseClass = GetBaseClassListDto(m)
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
// LoadHotQuestionList 加载数据-热榜
|
||||
func (r *IndexDto) LoadHotQuestionList(m []*model.Question) *IndexDto {
|
||||
if len(m) > 0 {
|
||||
r.HotQuestion = GetHotQuestionListDto(m)
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
// LoadRecommendQuestionList 加载数据-为你推荐
|
||||
func (r *IndexDto) LoadRecommendQuestionList(m []*model.Question) *IndexDto {
|
||||
if len(m) > 0 {
|
||||
r.RecommendQuestion = GetRecommendQuestionListDto(m)
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
// LoadGuessUserLikeList 加载数据-猜你喜欢
|
||||
func (r *IndexDto) LoadGuessUserLikeList(m []*model.Question) *IndexDto {
|
||||
if len(m) > 0 {
|
||||
r.GuessUserLikeQuestion = GetGuessUserLikeListDto(m)
|
||||
}
|
||||
return r
|
||||
}
|
||||
@@ -0,0 +1,210 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"hepa-calc-api/api/model"
|
||||
)
|
||||
|
||||
// QuestionDto 问题表
|
||||
type QuestionDto struct {
|
||||
QuestionId string `json:"question_id"` // 主键id
|
||||
QuestionTitle string `json:"question_title"` // 标题
|
||||
QuestionSubtitle string `json:"question_subtitle"` // 副标题
|
||||
QuestionIden string `json:"question_iden"` // 唯一标识
|
||||
QuestionStatus int `json:"question_status"` // 问题状态(1:正常 2:待发布)
|
||||
IsHide int `json:"is_hide"` // 是否隐藏(0:否 1:是)
|
||||
IsRecommend int `json:"is_recommend"` // 是否推荐(0:否 1:是)
|
||||
ClickCount int `json:"click_count"` // 点击次数(点击进入详情页的人次)
|
||||
SubmitCount int `json:"submit_count"` // 提交次数(提交个人信息进行了算算的人次)
|
||||
PayCount int `json:"pay_count"` // 支付次数(查看报告的人次)
|
||||
Price float64 `json:"price"` // 价格(原价)
|
||||
DiscountPrice float64 `json:"discount_price"` // 优惠价格
|
||||
QuestionBrief string `json:"question_brief"` // 问题介绍
|
||||
QuestionExplain string `json:"question_explain"` // 问题解释/科普
|
||||
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
|
||||
UpdatedAt model.LocalTime `json:"updated_at"` // 更新时间
|
||||
IsCollection bool `json:"is_collection"` // 用户是否收藏
|
||||
FirstTimePrice *float64 `json:"first_time_price"` // 首次购买价格
|
||||
BuyCount int `json:"buy_count"` // 被购买数量
|
||||
}
|
||||
|
||||
// GetQuestionDto 详情-问题
|
||||
func GetQuestionDto(m *model.Question) *QuestionDto {
|
||||
return &QuestionDto{
|
||||
QuestionId: fmt.Sprintf("%d", m.QuestionId),
|
||||
QuestionTitle: m.QuestionTitle,
|
||||
QuestionSubtitle: m.QuestionSubtitle,
|
||||
QuestionIden: m.QuestionIden,
|
||||
QuestionStatus: m.QuestionStatus,
|
||||
IsHide: m.IsHide,
|
||||
IsRecommend: m.IsRecommend,
|
||||
ClickCount: m.ClickCount,
|
||||
SubmitCount: m.SubmitCount,
|
||||
PayCount: m.PayCount,
|
||||
Price: m.Price,
|
||||
DiscountPrice: m.DiscountPrice,
|
||||
QuestionBrief: m.QuestionBrief,
|
||||
QuestionExplain: m.QuestionExplain,
|
||||
CreatedAt: m.CreatedAt,
|
||||
UpdatedAt: m.UpdatedAt,
|
||||
}
|
||||
}
|
||||
|
||||
// GetQuestionListDto 列表-问题
|
||||
func GetQuestionListDto(m []*model.Question) []*QuestionDto {
|
||||
// 处理返回值
|
||||
responses := make([]*QuestionDto, len(m))
|
||||
|
||||
if len(m) > 0 {
|
||||
for i, v := range m {
|
||||
response := &QuestionDto{
|
||||
QuestionId: fmt.Sprintf("%d", v.QuestionId),
|
||||
QuestionTitle: v.QuestionTitle,
|
||||
QuestionSubtitle: v.QuestionSubtitle,
|
||||
QuestionIden: v.QuestionIden,
|
||||
QuestionStatus: v.QuestionStatus,
|
||||
IsHide: v.IsHide,
|
||||
IsRecommend: v.IsRecommend,
|
||||
ClickCount: v.ClickCount,
|
||||
SubmitCount: v.SubmitCount,
|
||||
PayCount: v.PayCount,
|
||||
Price: v.Price,
|
||||
DiscountPrice: v.DiscountPrice,
|
||||
QuestionBrief: v.QuestionBrief,
|
||||
QuestionExplain: v.QuestionExplain,
|
||||
CreatedAt: v.CreatedAt,
|
||||
UpdatedAt: v.UpdatedAt,
|
||||
}
|
||||
|
||||
// 将转换后的结构体添加到新切片中
|
||||
responses[i] = response
|
||||
}
|
||||
}
|
||||
|
||||
return responses
|
||||
}
|
||||
|
||||
// GetHotQuestionListDto 列表-热榜问题
|
||||
func GetHotQuestionListDto(m []*model.Question) []*QuestionDto {
|
||||
// 处理返回值
|
||||
responses := make([]*QuestionDto, len(m))
|
||||
|
||||
if len(m) > 0 {
|
||||
for i, v := range m {
|
||||
response := &QuestionDto{
|
||||
QuestionId: fmt.Sprintf("%d", v.QuestionId),
|
||||
QuestionTitle: v.QuestionTitle,
|
||||
QuestionSubtitle: v.QuestionSubtitle,
|
||||
QuestionIden: v.QuestionIden,
|
||||
ClickCount: v.ClickCount,
|
||||
SubmitCount: v.SubmitCount,
|
||||
PayCount: v.PayCount,
|
||||
}
|
||||
|
||||
// 将转换后的结构体添加到新切片中
|
||||
responses[i] = response
|
||||
}
|
||||
}
|
||||
|
||||
return responses
|
||||
}
|
||||
|
||||
// GetRecommendQuestionListDto 列表-为你推荐
|
||||
func GetRecommendQuestionListDto(m []*model.Question) []*QuestionDto {
|
||||
// 处理返回值
|
||||
responses := make([]*QuestionDto, len(m))
|
||||
|
||||
if len(m) > 0 {
|
||||
for i, v := range m {
|
||||
response := &QuestionDto{
|
||||
QuestionId: fmt.Sprintf("%d", v.QuestionId),
|
||||
QuestionTitle: v.QuestionTitle,
|
||||
QuestionSubtitle: v.QuestionSubtitle,
|
||||
QuestionIden: v.QuestionIden,
|
||||
ClickCount: v.ClickCount,
|
||||
SubmitCount: v.SubmitCount,
|
||||
PayCount: v.PayCount,
|
||||
}
|
||||
|
||||
// 将转换后的结构体添加到新切片中
|
||||
responses[i] = response
|
||||
}
|
||||
}
|
||||
|
||||
return responses
|
||||
}
|
||||
|
||||
// GetGuessUserLikeListDto 列表-猜你喜欢
|
||||
func GetGuessUserLikeListDto(m []*model.Question) []*QuestionDto {
|
||||
// 处理返回值
|
||||
responses := make([]*QuestionDto, len(m))
|
||||
|
||||
if len(m) > 0 {
|
||||
for i, v := range m {
|
||||
response := &QuestionDto{
|
||||
QuestionId: fmt.Sprintf("%d", v.QuestionId),
|
||||
QuestionTitle: v.QuestionTitle,
|
||||
QuestionSubtitle: v.QuestionSubtitle,
|
||||
QuestionIden: v.QuestionIden,
|
||||
ClickCount: v.ClickCount,
|
||||
SubmitCount: v.SubmitCount,
|
||||
PayCount: v.PayCount,
|
||||
}
|
||||
|
||||
// 将转换后的结构体添加到新切片中
|
||||
responses[i] = response
|
||||
}
|
||||
}
|
||||
|
||||
return responses
|
||||
}
|
||||
|
||||
// GetQuestionPageListDto 列表-分页问题
|
||||
func GetQuestionPageListDto(m []*model.Question) []*QuestionDto {
|
||||
// 处理返回值
|
||||
responses := make([]*QuestionDto, len(m))
|
||||
|
||||
if len(m) > 0 {
|
||||
for i, v := range m {
|
||||
response := &QuestionDto{
|
||||
QuestionId: fmt.Sprintf("%d", v.QuestionId),
|
||||
QuestionTitle: v.QuestionTitle,
|
||||
QuestionSubtitle: v.QuestionSubtitle,
|
||||
QuestionIden: v.QuestionIden,
|
||||
ClickCount: v.ClickCount,
|
||||
SubmitCount: v.SubmitCount,
|
||||
PayCount: v.PayCount,
|
||||
Price: v.Price,
|
||||
DiscountPrice: v.DiscountPrice,
|
||||
}
|
||||
|
||||
// 将转换后的结构体添加到新切片中
|
||||
responses[i] = response
|
||||
}
|
||||
}
|
||||
|
||||
return responses
|
||||
}
|
||||
|
||||
// LoadIsCollection 加载数据-是否收藏
|
||||
func (r *QuestionDto) LoadIsCollection(isCollection bool) *QuestionDto {
|
||||
r.IsCollection = isCollection
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
// LoadFirstTimePrice 加载数据-首次购买价格
|
||||
func (r *QuestionDto) LoadFirstTimePrice(firstTimePrice *float64) *QuestionDto {
|
||||
if firstTimePrice != nil {
|
||||
r.FirstTimePrice = firstTimePrice
|
||||
}
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
// LoadBuyCount 加载数据-问题被购买数量
|
||||
func (r *QuestionDto) LoadBuyCount(buyCount int) *QuestionDto {
|
||||
r.BuyCount = buyCount
|
||||
|
||||
return r
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"hepa-calc-api/api/model"
|
||||
)
|
||||
|
||||
// SystemMemberDto 配置-会员配置
|
||||
type SystemMemberDto struct {
|
||||
SystemMemberId string `json:"system_member_id"` // 主键id
|
||||
MemberDays uint `json:"member_days"` // 会员天数
|
||||
Price float64 `json:"price"` // 价格(原价)
|
||||
DiscountPrice float64 `json:"discount_price"` // 优惠价格
|
||||
FirstTimePrice float64 `json:"first_time_price"` // 首次购买价格
|
||||
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
|
||||
UpdatedAt model.LocalTime `json:"updated_at"` // 更新时间
|
||||
}
|
||||
|
||||
// GetSystemMemberListDto 列表
|
||||
func GetSystemMemberListDto(m []*model.SystemMember) []*SystemMemberDto {
|
||||
// 处理返回值
|
||||
responses := make([]*SystemMemberDto, len(m))
|
||||
|
||||
if len(m) > 0 {
|
||||
for i, v := range m {
|
||||
response := &SystemMemberDto{
|
||||
SystemMemberId: fmt.Sprintf("%d", v.SystemMemberId),
|
||||
MemberDays: v.MemberDays,
|
||||
Price: v.Price,
|
||||
DiscountPrice: v.DiscountPrice,
|
||||
FirstTimePrice: v.FirstTimePrice,
|
||||
CreatedAt: v.CreatedAt,
|
||||
UpdatedAt: v.UpdatedAt,
|
||||
}
|
||||
|
||||
// 将转换后的结构体添加到新切片中
|
||||
responses[i] = response
|
||||
}
|
||||
}
|
||||
|
||||
return responses
|
||||
}
|
||||
|
||||
// GetSystemMemberDto 详情
|
||||
func GetSystemMemberDto(m *model.SystemMember) *SystemMemberDto {
|
||||
return &SystemMemberDto{
|
||||
SystemMemberId: fmt.Sprintf("%d", m.SystemMemberId),
|
||||
MemberDays: m.MemberDays,
|
||||
Price: m.Price,
|
||||
DiscountPrice: m.DiscountPrice,
|
||||
FirstTimePrice: m.FirstTimePrice,
|
||||
CreatedAt: m.CreatedAt,
|
||||
UpdatedAt: m.UpdatedAt,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"hepa-calc-api/api/model"
|
||||
"hepa-calc-api/utils"
|
||||
)
|
||||
|
||||
// UserDto 用户表
|
||||
type UserDto struct {
|
||||
UserId string `json:"user_id"` // 用户id
|
||||
UserName string `json:"user_name"` // 用户名称
|
||||
Mobile string `json:"mobile"` // 手机号
|
||||
UserStatus int `json:"user_status"` // 状态(1:正常 2:禁用)
|
||||
RegisterSource int `json:"register_source"` // 注册来源(1:app注册 2:公众号注册)
|
||||
OpenId string `json:"open_id"` // 用户微信标识
|
||||
UnionId string `json:"union_id"` // 微信开放平台标识
|
||||
Age uint `json:"age"` // 年龄
|
||||
Sex uint `json:"sex"` // 性别(0:未知 1:男 2:女)
|
||||
Avatar string `json:"avatar"` // 头像
|
||||
IsMember int `json:"is_member"` // 是否会员(0:否 1:是)
|
||||
MemberExpireDate model.LocalTime `json:"member_expire_date"` // 会员到期时间(非会员时为null)
|
||||
LoginAt model.LocalTime `json:"login_at"` // 登陆时间
|
||||
LoginIp string `json:"login_ip"` // 登陆ip
|
||||
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
|
||||
UpdatedAt model.LocalTime `json:"updated_at"` // 更新时间
|
||||
}
|
||||
|
||||
// GetUserDto 详情-问题
|
||||
func GetUserDto(m *model.User) *UserDto {
|
||||
return &UserDto{
|
||||
UserId: fmt.Sprintf("%d", m.UserId),
|
||||
UserName: m.UserName,
|
||||
Mobile: m.Mobile,
|
||||
UserStatus: m.UserStatus,
|
||||
RegisterSource: m.RegisterSource,
|
||||
Age: m.Age,
|
||||
Sex: m.Sex,
|
||||
Avatar: utils.AddOssDomain(m.Avatar),
|
||||
IsMember: m.IsMember,
|
||||
MemberExpireDate: m.MemberExpireDate,
|
||||
LoginAt: m.LoginAt,
|
||||
LoginIp: m.LoginIp,
|
||||
CreatedAt: m.CreatedAt,
|
||||
UpdatedAt: m.UpdatedAt,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"hepa-calc-api/api/model"
|
||||
)
|
||||
|
||||
type UserCollectionDto struct {
|
||||
CollectionId string `json:"collection_id"` // 主键id
|
||||
UserId string `json:"user_id"` // 用户id
|
||||
QuestionId string `json:"question_id"` // 问题id
|
||||
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
|
||||
UpdatedAt model.LocalTime `json:"updated_at"` // 更新时间
|
||||
Question *QuestionDto `json:"question"` // 问题
|
||||
}
|
||||
|
||||
// GetUserCollectionDto 用户收藏详情
|
||||
func GetUserCollectionDto(m *model.UserCollection) *UserCollectionDto {
|
||||
return &UserCollectionDto{
|
||||
CollectionId: fmt.Sprintf("%d", m.CollectionId),
|
||||
UserId: fmt.Sprintf("%d", m.UserId),
|
||||
QuestionId: fmt.Sprintf("%d", m.QuestionId),
|
||||
CreatedAt: m.CreatedAt,
|
||||
UpdatedAt: m.UpdatedAt,
|
||||
}
|
||||
}
|
||||
|
||||
// GetUserCollectionListDto 列表
|
||||
func GetUserCollectionListDto(m []*model.UserCollection) []*UserCollectionDto {
|
||||
// 处理返回值
|
||||
responses := make([]*UserCollectionDto, len(m))
|
||||
|
||||
if len(m) > 0 {
|
||||
for i, v := range m {
|
||||
response := &UserCollectionDto{
|
||||
CollectionId: fmt.Sprintf("%d", v.CollectionId),
|
||||
UserId: fmt.Sprintf("%d", v.UserId),
|
||||
QuestionId: fmt.Sprintf("%d", v.QuestionId),
|
||||
CreatedAt: v.CreatedAt,
|
||||
UpdatedAt: v.UpdatedAt,
|
||||
}
|
||||
|
||||
// 加载问题数据
|
||||
if v.Question != nil {
|
||||
response = response.LoadQuestion(v.Question)
|
||||
}
|
||||
|
||||
// 将转换后的结构体添加到新切片中
|
||||
responses[i] = response
|
||||
}
|
||||
}
|
||||
|
||||
return responses
|
||||
}
|
||||
|
||||
// LoadQuestion 加载题目数据
|
||||
func (r *UserCollectionDto) LoadQuestion(m *model.Question) *UserCollectionDto {
|
||||
if m != nil {
|
||||
r.Question = GetQuestionDto(m)
|
||||
}
|
||||
return r
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"hepa-calc-api/api/model"
|
||||
)
|
||||
|
||||
type UserCouponDto struct {
|
||||
UserCouponId string `json:"user_coupon_id"` // 主键id
|
||||
UserId string `json:"user_id"` // 用户id
|
||||
CouponId string `json:"coupon_id"` // 优惠券id
|
||||
UserCouponStatus int `json:"user_coupon_status"` // 状态(0:未使用 1:已使用 3:已过期)
|
||||
IsWindows int `json:"is_windows"` // 是否已弹窗(0:否 1:是)
|
||||
CouponUseDate model.LocalTime `json:"coupon_use_date"` // 使用时间
|
||||
ValidStartTime model.LocalTime `json:"valid_start_time"` // 有效开始时间
|
||||
ValidEndTime model.LocalTime `json:"valid_end_time"` // 过期时间
|
||||
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
|
||||
UpdatedAt model.LocalTime `json:"updated_at"` // 更新时间
|
||||
Coupon *CouponDto `json:"coupon"` // 优惠卷
|
||||
}
|
||||
|
||||
// GetUserCouponDto 用户优惠卷详情
|
||||
func GetUserCouponDto(m *model.UserCoupon) *UserCouponDto {
|
||||
return &UserCouponDto{
|
||||
UserCouponId: fmt.Sprintf("%d", m.UserCouponId),
|
||||
UserId: fmt.Sprintf("%d", m.UserId),
|
||||
CouponId: fmt.Sprintf("%d", m.CouponId),
|
||||
UserCouponStatus: m.UserCouponStatus,
|
||||
IsWindows: m.IsWindows,
|
||||
CouponUseDate: m.CouponUseDate,
|
||||
ValidStartTime: m.ValidStartTime,
|
||||
ValidEndTime: m.ValidEndTime,
|
||||
CreatedAt: m.CreatedAt,
|
||||
UpdatedAt: m.UpdatedAt,
|
||||
}
|
||||
}
|
||||
|
||||
// GetUserCouponListDto 列表
|
||||
func GetUserCouponListDto(m []*model.UserCoupon) []*UserCouponDto {
|
||||
// 处理返回值
|
||||
responses := make([]*UserCouponDto, len(m))
|
||||
|
||||
if len(m) > 0 {
|
||||
for i, v := range m {
|
||||
response := &UserCouponDto{
|
||||
UserCouponId: fmt.Sprintf("%d", v.UserCouponId),
|
||||
UserId: fmt.Sprintf("%d", v.UserId),
|
||||
CouponId: fmt.Sprintf("%d", v.CouponId),
|
||||
UserCouponStatus: v.UserCouponStatus,
|
||||
IsWindows: v.IsWindows,
|
||||
CouponUseDate: v.CouponUseDate,
|
||||
ValidStartTime: v.ValidStartTime,
|
||||
ValidEndTime: v.ValidEndTime,
|
||||
CreatedAt: v.CreatedAt,
|
||||
UpdatedAt: v.UpdatedAt,
|
||||
}
|
||||
|
||||
// 加载优惠卷数据
|
||||
if v.Coupon != nil {
|
||||
response = response.LoadCoupon(v.Coupon)
|
||||
}
|
||||
|
||||
// 将转换后的结构体添加到新切片中
|
||||
responses[i] = response
|
||||
}
|
||||
}
|
||||
|
||||
return responses
|
||||
}
|
||||
|
||||
// LoadCoupon 加载优惠卷数据
|
||||
func (r *UserCouponDto) LoadCoupon(m *model.Coupon) *UserCouponDto {
|
||||
if m != nil {
|
||||
d := GetCouponDto(m)
|
||||
|
||||
r.Coupon = d
|
||||
}
|
||||
return r
|
||||
}
|
||||
+26
-40
@@ -2,51 +2,37 @@ package middlewares
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"hepa-calc-api/api/dao"
|
||||
"hepa-calc-api/api/responses"
|
||||
)
|
||||
|
||||
// Auth Auth认证
|
||||
func Auth() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
//// 获取用户id
|
||||
//userId := c.GetInt64("UserId")
|
||||
//if userId == 0 {
|
||||
// responses.Fail(c)
|
||||
// c.Abort()
|
||||
// return
|
||||
//}
|
||||
//
|
||||
//// 获取用户数据
|
||||
//adminUserDao := dao.AdminUserDao{}
|
||||
//adminUser, err := adminUserDao.GetAdminUserFirstById(userId)
|
||||
//if err != nil || adminUser == nil {
|
||||
// responses.FailWithMessage("用户数据错误", c)
|
||||
// c.Abort()
|
||||
// return
|
||||
//}
|
||||
//
|
||||
//if adminUser.Status == 2 {
|
||||
// responses.FailWithMessage("用户审核中", c)
|
||||
// c.Abort()
|
||||
// return
|
||||
//}
|
||||
//
|
||||
//if adminUser.Status == 3 {
|
||||
// responses.FailWithMessage("用户已删除或禁用", c)
|
||||
// c.Abort()
|
||||
// return
|
||||
//}
|
||||
//
|
||||
//if adminUser.IsDisabled == 1 {
|
||||
// responses.FailWithMessage("用户已禁用", c)
|
||||
// c.Abort()
|
||||
// return
|
||||
//}
|
||||
//
|
||||
//if adminUser.IsDeleted == 1 {
|
||||
// responses.FailWithMessage("用户已删除", c)
|
||||
// c.Abort()
|
||||
// return
|
||||
//}
|
||||
// 获取用户id
|
||||
userId := c.GetInt64("UserId")
|
||||
if userId == 0 {
|
||||
responses.Fail(c)
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
|
||||
// 获取用户数据
|
||||
userDao := dao.UserDao{}
|
||||
user, err := userDao.GetUserById(userId)
|
||||
if err != nil || user == nil {
|
||||
responses.FailWithMessage("用户数据错误", c)
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
|
||||
if user.UserStatus == 2 {
|
||||
responses.FailWithMessage("用户已禁用", c)
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
|
||||
c.Set("UserId", userId) // 用户id
|
||||
|
||||
c.Next()
|
||||
}
|
||||
|
||||
+3
-1
@@ -11,7 +11,7 @@ type Coupon struct {
|
||||
CouponName string `gorm:"column:coupon_name;type:varchar(255);comment:优惠卷名称" json:"coupon_name"`
|
||||
CouponType string `gorm:"column:coupon_type;type:varchar(255);comment:优惠卷类型(1:无门槛 2:满减)" json:"coupon_type"`
|
||||
CouponStatus int `gorm:"column:coupon_status;type:tinyint(1);default:1;comment:状态(1:正常 2:强制失效 3:结束 4:删除)" json:"coupon_status"`
|
||||
ApplicationScope int `gorm:"column:application_scope;type:tinyint(1);default:1;comment:适用范围(1:全场通用)" json:"application_scope"`
|
||||
ApplicationScope int `gorm:"column:application_scope;type:tinyint(1);default:1;comment:适用范围(1:全场通用 2:单项 3:会员)" json:"application_scope"`
|
||||
IsMutex int `gorm:"column:is_mutex;type:tinyint(1);default:1;comment:是否互斥(0:否 1:是)互斥情况下无法和其他优惠卷同时使用" json:"is_mutex"`
|
||||
CouponCount int `gorm:"column:coupon_count;type:int(10);default:1;comment:发放数量;NOT NULL" json:"coupon_count"`
|
||||
CouponTakeCount int `gorm:"column:coupon_take_count;type:int(10);comment:已领取数量" json:"coupon_take_count"`
|
||||
@@ -22,6 +22,8 @@ type Coupon struct {
|
||||
ValidDays int `gorm:"column:valid_days;type:int(3);comment:自领取之日起有效天数" json:"valid_days"`
|
||||
ValidStartTime LocalTime `gorm:"column:valid_start_time;type:datetime;comment:开始使用时间" json:"valid_start_time"`
|
||||
ValidEndTime LocalTime `gorm:"column:valid_end_time;type:datetime;comment:结束使用时间" json:"valid_end_time"`
|
||||
QuestionId int64 `gorm:"column:question_id;type:bigint(19);comment:问题id(适用范围为单项时生效,如果此项为null,则表示所有单项通用)" json:"question_id"`
|
||||
SystemMemberId int64 `gorm:"column:system_member_id;type:bigint(19);comment:会员id(适用范围为会员时生效,如果此项为null,则表示所有会员通用)" json:"system_member_id"`
|
||||
CouponDesc string `gorm:"column:coupon_desc;type:varchar(200);comment:优惠卷描述" json:"coupon_desc"`
|
||||
Model
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ type OrderMember struct {
|
||||
CancelRemarks string `gorm:"column:cancel_remarks;type:varchar(255);comment:取消订单备注" json:"cancel_remarks"`
|
||||
OrderRemarks string `gorm:"column:order_remarks;type:varchar(255);comment:订单备注" json:"order_remarks"`
|
||||
Model
|
||||
SystemMember *SystemMember `gorm:"foreignKey:SystemMemberId;references:system_member_id" json:"system_member"`
|
||||
}
|
||||
|
||||
func (m *OrderMember) TableName() string {
|
||||
|
||||
@@ -24,7 +24,6 @@ type OrderMemberRefund struct {
|
||||
func (m *OrderMemberRefund) TableName() string {
|
||||
return "order_member_refund"
|
||||
}
|
||||
|
||||
func (m *OrderMemberRefund) BeforeCreate(tx *gorm.DB) error {
|
||||
if m.OrderRefundId == 0 {
|
||||
m.OrderRefundId = global.Snowflake.Generate().Int64()
|
||||
|
||||
@@ -27,6 +27,7 @@ type OrderSingle struct {
|
||||
CancelRemarks string `gorm:"column:cancel_remarks;type:varchar(255);comment:取消订单备注" json:"cancel_remarks"`
|
||||
OrderRemarks string `gorm:"column:order_remarks;type:varchar(255);comment:订单备注" json:"order_remarks"`
|
||||
Model
|
||||
Question *Question `gorm:"foreignKey:QuestionId;references:question_id" json:"question"`
|
||||
}
|
||||
|
||||
func (m *OrderSingle) TableName() string {
|
||||
|
||||
@@ -11,7 +11,8 @@ type Question struct {
|
||||
QuestionId int64 `gorm:"column:question_id;type:bigint(19);primary_key;comment:主键id" json:"question_id"`
|
||||
QuestionTitle string `gorm:"column:question_title;type:varchar(200);comment:标题" json:"question_title"`
|
||||
QuestionSubtitle string `gorm:"column:question_subtitle;type:varchar(200);comment:副标题" json:"question_subtitle"`
|
||||
QuestionStatus string `gorm:"column:question_status;type:varchar(255);comment:问题状态(1:正常 2:待发布)" json:"question_status"`
|
||||
QuestionIden string `gorm:"column:question_iden;type:varchar(255);comment:唯一标识(用于和前端对应)" json:"question_iden"`
|
||||
QuestionStatus int `gorm:"column:question_status;type:tinyint(1);default:2;comment:问题状态(1:正常 2:待发布)" json:"question_status"`
|
||||
IsHide int `gorm:"column:is_hide;type:tinyint(1);default:0;comment:是否隐藏(0:否 1:是)" json:"is_hide"`
|
||||
IsRecommend int `gorm:"column:is_recommend;type:tinyint(1);default:0;comment:是否推荐(0:否 1:是)" json:"is_recommend"`
|
||||
ClickCount int `gorm:"column:click_count;type:int(5);default:0;comment:点击次数(点击进入详情页的人次)" json:"click_count"`
|
||||
|
||||
@@ -12,6 +12,7 @@ type UserCollection struct {
|
||||
UserId int64 `gorm:"column:user_id;type:bigint(19);comment:用户id" json:"user_id"`
|
||||
QuestionId int64 `gorm:"column:question_id;type:bigint(19);comment:问题id" json:"question_id"`
|
||||
Model
|
||||
Question *Question `gorm:"foreignKey:QuestionId;references:question_id" json:"question"`
|
||||
}
|
||||
|
||||
func (m *UserCollection) TableName() string {
|
||||
|
||||
@@ -11,10 +11,12 @@ type UserCoupon struct {
|
||||
UserId int64 `gorm:"column:user_id;type:bigint(19);comment:用户id;NOT NULL" json:"user_id"`
|
||||
CouponId int64 `gorm:"column:coupon_id;type:bigint(19);comment:优惠卷id;NOT NULL" json:"coupon_id"`
|
||||
UserCouponStatus int `gorm:"column:user_coupon_status;type:tinyint(1);default:0;comment:状态(0:未使用 1:已使用 3:已过期)" json:"user_coupon_status"`
|
||||
IsWindows int `gorm:"column:is_windows;type:tinyint(1);default:0;comment:是否已弹窗(0:否 1:是)" json:"is_windows"`
|
||||
CouponUseDate LocalTime `gorm:"column:coupon_use_date;type:datetime;comment:使用时间" json:"coupon_use_date"`
|
||||
ValidStartTime LocalTime `gorm:"column:valid_start_time;type:datetime;comment:有效使用时间" json:"valid_start_time"`
|
||||
ValidEndTime LocalTime `gorm:"column:valid_end_time;type:datetime;comment:过期使用时间" json:"valid_end_time"`
|
||||
Model
|
||||
Coupon *Coupon `gorm:"foreignKey:CouponId;references:coupon_id" json:"coupon"`
|
||||
}
|
||||
|
||||
func (m *UserCoupon) TableName() string {
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package requests
|
||||
|
||||
type LoginRequest struct {
|
||||
LoginWx // 微信授权登录
|
||||
}
|
||||
|
||||
// LoginWx 微信授权登录
|
||||
type LoginWx struct {
|
||||
Code string `json:"code" form:"code" label:"授权码"`
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package requests
|
||||
|
||||
type OrderMemberRequest struct {
|
||||
GetOrderMemberPage // 获取会员订单列表-分页
|
||||
}
|
||||
|
||||
// GetOrderMemberPage 获取会员订单列表-分页
|
||||
type GetOrderMemberPage struct {
|
||||
Page int `json:"page" form:"page" label:"页码"`
|
||||
PageSize int `json:"page_size" form:"page_size" label:"每页个数"`
|
||||
UserId int64 `json:"user_id" form:"user_id" label:"用户id"`
|
||||
SystemMemberId string `json:"system_member_id" form:"system_member_id" label:"会员id"`
|
||||
OrderStatus *int `json:"order_status" form:"order_status" label:"订单状态"` // 订单状态(1:待支付 2:已完成 3:已取消)
|
||||
PayChannel *int `json:"pay_channel" form:"pay_channel" label:"支付渠道"` // 支付渠道(1:h5支付 2:app支付 3:会员支付)
|
||||
PayStatus *int `json:"pay_status" form:"pay_status" label:"支付状态"` // 支付状态(1:未支付 2:已支付 3:支付中 4:支付失败 5:支付超时 6:支付关闭 7:已撤销 8:转入退款)
|
||||
RefundStatus *int `json:"refund_status" form:"refund_status" label:"订单退款状态"`
|
||||
OrderNo string `json:"order_no" form:"order_no" label:"系统订单编号"`
|
||||
EscrowTradeNo string `json:"escrow_trade_no" form:"escrow_trade_no" label:"第三方支付流水号"`
|
||||
CancelStatus *int `json:"cancel_status" form:"cancel_status" label:"取消状态"`
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package requests
|
||||
|
||||
type OrderSingleRequest struct {
|
||||
GetOrderSinglePage // 获取单项订单列表-分页
|
||||
}
|
||||
|
||||
// GetOrderSinglePage 获取单项订单列表-分页
|
||||
type GetOrderSinglePage struct {
|
||||
Page int `json:"page" form:"page" label:"页码"`
|
||||
PageSize int `json:"page_size" form:"page_size" label:"每页个数"`
|
||||
UserId int64 `json:"user_id" form:"user_id" label:"用户id"`
|
||||
QuestionId string `json:"question_id" form:"question_id" label:"问题id"`
|
||||
OrderStatus *int `json:"order_status" form:"order_status" label:"订单状态"`
|
||||
PayChannel *int `json:"pay_channel" form:"pay_channel" label:"支付渠道"`
|
||||
PayStatus *int `json:"pay_status" form:"pay_status" label:"支付状态"`
|
||||
RefundStatus *int `json:"refund_status" form:"refund_status" label:"订单退款状态"`
|
||||
OrderNo string `json:"order_no" form:"order_no" label:"系统订单编号"`
|
||||
EscrowTradeNo string `json:"escrow_trade_no" form:"escrow_trade_no" label:"第三方支付流水号"`
|
||||
CancelStatus *int `json:"cancel_status" form:"cancel_status" label:"取消状态"`
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package requests
|
||||
|
||||
type PublicRequest struct {
|
||||
GetPhoneCode // 获取手机验证码
|
||||
}
|
||||
|
||||
// GetPhoneCode 获取手机验证码
|
||||
type GetPhoneCode struct {
|
||||
Phone string `json:"phone" form:"phone" label:"手机号" validate:"required,Mobile"`
|
||||
Scene int `json:"scene" form:"scene" label:"场景值" validate:"required,number,min=1,max=1"`
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package requests
|
||||
|
||||
type QuestionRequest struct {
|
||||
GetQuestionPage // 获取问题列表-分页
|
||||
}
|
||||
|
||||
// GetQuestionPage 获取问题列表-分页
|
||||
type GetQuestionPage struct {
|
||||
Page int `json:"page" form:"page" label:"页码"`
|
||||
PageSize int `json:"page_size" form:"page_size" label:"每页个数"`
|
||||
QuestionId string `json:"question_id" form:"question_id" label:"主键id"`
|
||||
QuestionTitle string `json:"question_title" form:"question_title" label:"标题"`
|
||||
QuestionSubtitle string `json:"question_subtitle" form:"question_subtitle" label:"副标题"`
|
||||
QuestionIden string `json:"question_iden" form:"question_iden" label:"唯一标识"`
|
||||
QuestionStatus *int `json:"question_status" form:"question_status" label:"问题状态"`
|
||||
IsRecommend *int `json:"is_recommend" form:"is_recommend" label:"是否推荐"`
|
||||
QuestionBrief string `json:"question_brief" form:"question_brief" label:"问题介绍"`
|
||||
QuestionExplain string `json:"question_explain" form:"question_explain" label:"问题解释/科普"`
|
||||
ClassId string `json:"class_id" form:"question_explain" label:"分类标识"`
|
||||
Order *GetQuestionPageOrder `json:"order" form:"order" label:"排序"`
|
||||
}
|
||||
|
||||
// GetQuestionPageOrder 获取问答题库列表-分页-排序条件
|
||||
type GetQuestionPageOrder struct {
|
||||
ClickCount string `json:"click_count" form:"click_count" label:"排序"` // 点击次数(点击进入详情页的人次)
|
||||
SubmitCount string `json:"submit_count" form:"submit_count" label:"排序"` // 提交次数(提交个人信息进行了算算的人次)
|
||||
PayCount string `json:"pay_count" form:"pay_count" label:"排序"` // 支付次数(查看报告的人次)
|
||||
Price string `json:"price" form:"price" label:"排序"` // 价格(原价)
|
||||
DiscountPrice string `json:"discount_price" form:"discount_price" label:"排序"` // 优惠价格
|
||||
UpdatedAt string `json:"updated_at" form:"updated_at" label:"排序"`
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package requests
|
||||
|
||||
type UserRequest struct {
|
||||
PutUser // 修改用户数据-基本信息
|
||||
}
|
||||
|
||||
// PutUser 修改用户数据-基本信息
|
||||
type PutUser struct {
|
||||
UserName string `json:"user_name" form:"user_name" label:"用户名称" validate:"required"`
|
||||
Mobile string `json:"mobile" form:"mobile" label:"手机号" validate:"required,Mobile"`
|
||||
RegisterSource int `json:"register_source" form:"register_source" label:"注册来源" validate:"required,oneof=1 2"`
|
||||
Age uint `json:"age" form:"age" label:"年龄" validate:"omitempty,min=1,max=120"`
|
||||
Sex uint `json:"sex" form:"sex" label:"性别" validate:"omitempty,oneof=1 2"`
|
||||
Avatar string `json:"avatar" form:"avatar" label:"头像"`
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package requests
|
||||
|
||||
type UserCollectionRequest struct {
|
||||
GetUserCollectionPage // 获取用户收藏题目列表-分页
|
||||
PutUserCollection // 收藏题目
|
||||
PutUserCollectionCancel // 取消收藏题目
|
||||
}
|
||||
|
||||
// GetUserCollectionPage 获取用户收藏列表-分页
|
||||
type GetUserCollectionPage struct {
|
||||
Page int `json:"page" form:"page" label:"页码"`
|
||||
PageSize int `json:"page_size" form:"page_size" label:"每页个数"`
|
||||
UserId int64 `json:"user_id" form:"user_id" label:"用户id"`
|
||||
}
|
||||
|
||||
// PutUserCollection 收藏题目
|
||||
type PutUserCollection struct {
|
||||
QuestionId string `json:"question_id" form:"question_id" label:"问题id" validate:"required"`
|
||||
}
|
||||
|
||||
// PutUserCollectionCancel 取消收藏题目
|
||||
type PutUserCollectionCancel struct {
|
||||
QuestionId string `json:"question_id" form:"question_id" label:"问题id" validate:"required"`
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package requests
|
||||
|
||||
type UserCouponRequest struct {
|
||||
GetUserCouponPage // 获取优惠卷列表-分页
|
||||
}
|
||||
|
||||
// GetUserCouponPage 获取优惠卷列表-分页
|
||||
type GetUserCouponPage struct {
|
||||
Page int `json:"page" form:"page" label:"页码"`
|
||||
PageSize int `json:"page_size" form:"page_size" label:"每页个数"`
|
||||
UserId int64 `json:"user_id" form:"user_id" label:"用户id"`
|
||||
CouponId string `json:"coupon_id" form:"coupon_id" label:"优惠券id"`
|
||||
UserCouponStatus *int `json:"user_coupon_status" form:"user_coupon_status" label:"状态"` // 状态(0:未使用 1:已使用 3:已过期)
|
||||
IsWindows *int `json:"is_windows" form:"is_windows" label:"是否已弹窗"` // 是否已弹窗(0:否 1:是)
|
||||
CouponUseDate string `json:"coupon_use_date" form:"coupon_use_date" label:"使用时间"` // 假设转换为字符串格式
|
||||
ValidStartTime string `json:"valid_start_time" form:"valid_start_time" label:"有效开始时间"` // 同上
|
||||
ValidEndTime string `json:"valid_end_time" form:"valid_end_time" label:"有效结束时间"` // 同上
|
||||
}
|
||||
|
||||
// GetUserUsableCoupon 获取用户当前可用优惠卷
|
||||
type GetUserUsableCoupon struct {
|
||||
UserId int64 `json:"user_id" form:"user_id" label:"用户id"`
|
||||
UserCouponStatus *int `json:"user_coupon_status" form:"user_coupon_status" label:"状态"` // 状态(0:未使用 1:已使用 3:已过期)
|
||||
}
|
||||
@@ -2,7 +2,7 @@ package responses
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"knowledge/consts"
|
||||
"hepa-calc-api/consts"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
|
||||
@@ -72,7 +72,28 @@ func Init() *gin.Engine {
|
||||
|
||||
// publicRouter 公开路由-不验证权限
|
||||
func publicRouter(r *gin.Engine, api controller.Api) {
|
||||
// 登陆
|
||||
loginGroup := r.Group("/login")
|
||||
{
|
||||
// 手机号登录
|
||||
loginGroup.POST("/phone", api.Login.LoginPhone)
|
||||
|
||||
wxGroup := loginGroup.Group("/wx")
|
||||
{
|
||||
// 微信授权登录
|
||||
wxGroup.POST("", api.Login.LoginWx)
|
||||
}
|
||||
}
|
||||
|
||||
// 验证码
|
||||
codeGroup := r.Group("/code")
|
||||
{
|
||||
// 获取手机号验证码
|
||||
codeGroup.POST("/phone", api.Public.GetPhoneCode)
|
||||
}
|
||||
|
||||
// 首页
|
||||
r.GET("/index", api.Public.GetIndex)
|
||||
}
|
||||
|
||||
// adminRouter 公共路由-验证权限
|
||||
@@ -87,5 +108,87 @@ func basicRouter(r *gin.Engine, api controller.Api) {
|
||||
|
||||
// privateRouter 私有路由-验证权限
|
||||
func privateRouter(r *gin.Engine, api controller.Api) {
|
||||
// 分类
|
||||
classGroup := r.Group("/class")
|
||||
{
|
||||
// 获取分类列表
|
||||
classGroup.GET("/list", api.Class.GetClassList)
|
||||
|
||||
// 获取分类详情
|
||||
classGroup.GET("/:class_id", api.Class.GetClass)
|
||||
}
|
||||
|
||||
// 问题
|
||||
questionGroup := r.Group("/question")
|
||||
{
|
||||
// 获取问题列表-分页
|
||||
questionGroup.POST("/page", api.Question.GetQuestionPage)
|
||||
|
||||
// 获取问题列表-热榜
|
||||
questionGroup.GET("/hot", api.Question.GetQuestionHot)
|
||||
|
||||
// 获取问题详情
|
||||
questionGroup.GET("/:question_id", api.Question.GetQuestion)
|
||||
}
|
||||
|
||||
// 用户
|
||||
centerGroup := r.Group("/user")
|
||||
{
|
||||
// 获取用户数据-基本信息
|
||||
centerGroup.GET("", api.User.GetUser)
|
||||
}
|
||||
|
||||
// 优惠卷
|
||||
couponGroup := r.Group("/coupon")
|
||||
{
|
||||
// 获取优惠卷列表-分页
|
||||
couponGroup.GET("", api.UserCoupon.GetUserCouponPage)
|
||||
|
||||
// 获取还未弹窗的优惠卷
|
||||
couponGroup.GET("/unnotified", api.UserCoupon.GetUserCouponUnnotified)
|
||||
|
||||
// 获取用户当前可用优惠卷
|
||||
couponGroup.GET("/usable", api.UserCoupon.GetUserUsableCoupon)
|
||||
}
|
||||
|
||||
// 收藏
|
||||
collectionGroup := r.Group("/collection")
|
||||
{
|
||||
questionGroup := collectionGroup.Group("/question")
|
||||
{
|
||||
// 获取用户收藏题目列表-分页
|
||||
questionGroup.GET("", api.UserCollection.GetUserCollectionPage)
|
||||
|
||||
// 收藏题目
|
||||
questionGroup.POST("", api.UserCollection.PutUserCollection)
|
||||
|
||||
// 取消收藏题目
|
||||
questionGroup.PUT("/cancel", api.UserCollection.PutUserCollectionCancel)
|
||||
}
|
||||
}
|
||||
|
||||
// 订单
|
||||
orderGroup := r.Group("/order")
|
||||
{
|
||||
// 单项订单
|
||||
singleGroup := orderGroup.Group("/single")
|
||||
{
|
||||
// 获取单项订单列表-分页
|
||||
singleGroup.GET("/page", api.OrderSingle.GetOrderSinglePage)
|
||||
}
|
||||
|
||||
// 会员订单
|
||||
memberGroup := orderGroup.Group("/member")
|
||||
{
|
||||
// 获取会员订单列表-分页
|
||||
memberGroup.GET("/page", api.OrderMember.GetOrderMemberPage)
|
||||
}
|
||||
}
|
||||
|
||||
// 会员配置
|
||||
memberGroup := r.Group("/member")
|
||||
{
|
||||
// 获取会员配置数据
|
||||
memberGroup.GET("", api.SystemMember.GetSystemMember)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
package service
|
||||
|
||||
type BaseClassService struct {
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"hepa-calc-api/api/dao"
|
||||
"hepa-calc-api/api/dto"
|
||||
"hepa-calc-api/extend/aliyun"
|
||||
"hepa-calc-api/global"
|
||||
"math/rand"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
type PublicService struct {
|
||||
}
|
||||
|
||||
// GetPhoneCode 获取手机验证码
|
||||
func (r *PublicService) GetPhoneCode(scene int, phone string) (bool, error) {
|
||||
var sendCodeCount int // // 获取验证码最大次数
|
||||
var code string // 验证码
|
||||
var templateCode string // 短信模版
|
||||
|
||||
// 登录获取验证码
|
||||
if scene == 1 {
|
||||
// 验证发送次数
|
||||
res, _ := global.Redis.Get(context.Background(), "login_code_count_"+phone).Result()
|
||||
if res != "" {
|
||||
sendCodeCount, err := strconv.Atoi(res)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
if sendCodeCount > 3 {
|
||||
// 超出规定时间内最大获取次数
|
||||
return false, errors.New("手机号超出规定时间内最大获取次数,请您稍后再试")
|
||||
}
|
||||
}
|
||||
|
||||
// 生成随机数
|
||||
rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
code = strconv.Itoa(rand.Intn(9000) + 1000)
|
||||
|
||||
// 模版
|
||||
templateCode = "SMS_243055263"
|
||||
|
||||
sendCodeCount = sendCodeCount + 1
|
||||
}
|
||||
|
||||
if code == "" || templateCode == "" {
|
||||
return false, errors.New("验证码发送失败,请您稍后再试")
|
||||
}
|
||||
|
||||
// 发送验证码
|
||||
templateParam := make(map[string]interface{})
|
||||
templateParam["code"] = code
|
||||
err := aliyun.SendSms(phone, templateCode, "获取验证码", templateParam)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
// 记录发送次数
|
||||
if sendCodeCount != 0 {
|
||||
_, err = global.Redis.Set(context.Background(), "login_code_count_"+phone, time.Now().Unix(), 60*5*time.Second).Result()
|
||||
if err != nil {
|
||||
return false, errors.New("验证码发送失败,请您稍后再试")
|
||||
}
|
||||
}
|
||||
|
||||
// 设置验证码有效期
|
||||
_, err = global.Redis.Set(context.Background(), "login_code_"+phone, code, 60*30*time.Second).Result()
|
||||
if err != nil {
|
||||
return false, errors.New("验证码发送失败,请您稍后再试")
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// GetIndex 获取首页数据
|
||||
func (r *PublicService) GetIndex(userId int64) (g *dto.IndexDto, err error) {
|
||||
// 获取疾病分类列表
|
||||
baseClassDao := dao.BaseClassDao{}
|
||||
|
||||
maps := make(map[string]interface{})
|
||||
maps["class_status"] = 1
|
||||
baseClasss, err := baseClassDao.GetBaseClassOrderList(maps)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
questionService := &QuestionService{}
|
||||
|
||||
// 获取算一算热榜-人气数最高的9个
|
||||
hotQuestions, err := questionService.GetHotList()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 获取为你推荐-后台指定的推广
|
||||
recommendQuestions, err := questionService.GetRecommendList()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 获取猜你喜欢
|
||||
guessUserLikes, err := questionService.GetGuessUserLIkeList(userId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 处理返回值
|
||||
g = &dto.IndexDto{}
|
||||
|
||||
g.LoadBaseClass(baseClasss)
|
||||
|
||||
g.LoadHotQuestionList(hotQuestions)
|
||||
|
||||
g.LoadRecommendQuestionList(recommendQuestions)
|
||||
|
||||
g.LoadGuessUserLikeList(guessUserLikes)
|
||||
|
||||
return g, nil
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"hepa-calc-api/api/dao"
|
||||
"hepa-calc-api/api/model"
|
||||
)
|
||||
|
||||
type QuestionService struct {
|
||||
}
|
||||
|
||||
// GetHotList 获取算一算热榜-人气数最高的9个
|
||||
func (r *QuestionService) GetHotList() (m []*model.Question, err error) {
|
||||
questionDao := dao.QuestionDao{}
|
||||
|
||||
maps := make(map[string]interface{})
|
||||
maps["question_status"] = 1
|
||||
maps["is_hide"] = 0
|
||||
questions, err := questionDao.GetQuestionOrderLimitList(maps, "click_count desc", 9)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return questions, nil
|
||||
}
|
||||
|
||||
// GetRecommendList 获取为你推荐-后台指定的推广
|
||||
func (r *QuestionService) GetRecommendList() (m []*model.Question, err error) {
|
||||
questionDao := dao.QuestionDao{}
|
||||
|
||||
maps := make(map[string]interface{})
|
||||
maps["question_status"] = 1
|
||||
maps["is_hide"] = 0
|
||||
maps["is_recommend"] = 1
|
||||
questions, err := questionDao.GetQuestionList(maps)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return questions, nil
|
||||
}
|
||||
|
||||
// GetGuessUserLIkeList 获取猜你喜欢-暂用公众参与过的最新算一算,至多显示3个。若未参与,则指定或者随机显示3个
|
||||
func (r *QuestionService) GetGuessUserLIkeList(userId int64) (m []*model.Question, err error) {
|
||||
orderSingleDao := dao.OrderSingleDao{}
|
||||
questionDao := dao.QuestionDao{}
|
||||
|
||||
var questions []*model.Question
|
||||
|
||||
if userId != 0 {
|
||||
maps := make(map[string]interface{})
|
||||
maps["user_id"] = userId
|
||||
orderSingles, err := orderSingleDao.GetOrderSingleOrderList(maps, "created_at desc", 3)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 参与过
|
||||
if len(orderSingles) > 0 {
|
||||
for i, single := range orderSingles {
|
||||
questions[i] = single.Question
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 未参与过/未指定用户
|
||||
if len(questions) == 0 {
|
||||
maps := make(map[string]interface{})
|
||||
maps["question_status"] = 1
|
||||
maps["is_hide"] = 0
|
||||
questions, err = questionDao.GetQuestionListRand(maps, 3)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return questions, nil
|
||||
}
|
||||
|
||||
// CheckUserCollectionQuestion 检测问题是否被用户收藏
|
||||
func (r *QuestionService) CheckUserCollectionQuestion(userId, questionId int64) (bool, error) {
|
||||
userCollectionDao := dao.UserCollectionDao{}
|
||||
|
||||
maps := make(map[string]interface{})
|
||||
maps["user_id"] = userId
|
||||
maps["question_id"] = questionId
|
||||
userCollection, err := userCollectionDao.GetUserCollection(maps)
|
||||
if userCollection == nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// CheckUserBuyQuestion 检测用户是否购买过该问题
|
||||
func (r *QuestionService) CheckUserBuyQuestion(userId, questionId int64) bool {
|
||||
orderSingleDao := dao.OrderSingleDao{}
|
||||
orderSingle, _ := orderSingleDao.GetUserFirstTimeBuyOrderSingle(userId, questionId)
|
||||
if orderSingle == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// GetUserFirstTimeBuyPrice 获取用户首次购买价格
|
||||
func (r *QuestionService) GetUserFirstTimeBuyPrice(userId, questionId int64) (f *float64, err error) {
|
||||
// 检测用户是否购买过该问题
|
||||
isFirstBuy := r.CheckUserBuyQuestion(userId, questionId)
|
||||
if isFirstBuy == false {
|
||||
// 未购买过
|
||||
systemSingleDao := dao.SystemSingleDao{}
|
||||
|
||||
maps := make(map[string]interface{})
|
||||
systemSingle, err := systemSingleDao.GetSystemSingle(maps)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &systemSingle.FirstTimePrice, nil
|
||||
}
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// GetQuestionBuyCount 获取问题被购买数量
|
||||
func (r *QuestionService) GetQuestionBuyCount(userId, questionId int64) (c int, err error) {
|
||||
// 未购买过
|
||||
systemSingleDao := dao.SystemSingleDao{}
|
||||
|
||||
maps := make(map[string]interface{})
|
||||
maps["user_id"] = userId
|
||||
maps["question_id"] = questionId
|
||||
maps["order_status"] = 2
|
||||
maps["refund_status"] = 0
|
||||
buyCount, err := systemSingleDao.GetSystemSingleCount(maps)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return int(buyCount), nil
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package service
|
||||
|
||||
type UserService struct {
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"hepa-calc-api/api/dao"
|
||||
"hepa-calc-api/api/model"
|
||||
"hepa-calc-api/global"
|
||||
)
|
||||
|
||||
type UserCollectionService struct {
|
||||
}
|
||||
|
||||
// CheckUserCollectionQuestion 检测问题是否被用户收藏
|
||||
func (r *UserCollectionService) CheckUserCollectionQuestion(userId, questionId int64) bool {
|
||||
userCollectionDao := dao.UserCollectionDao{}
|
||||
|
||||
maps := make(map[string]interface{})
|
||||
maps["user_id"] = userId
|
||||
maps["question_id"] = questionId
|
||||
userCollection, _ := userCollectionDao.GetUserCollection(maps)
|
||||
if userCollection == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// PutUserCollection 收藏题目
|
||||
func (r *UserCollectionService) PutUserCollection(userId, questionId int64) (bool, error) {
|
||||
// 检测问题是否被用户收藏
|
||||
IsCollection := r.CheckUserCollectionQuestion(userId, questionId)
|
||||
if IsCollection == true {
|
||||
// 已收藏
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// 开始事务
|
||||
tx := global.Db.Begin()
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
tx.Rollback()
|
||||
}
|
||||
}()
|
||||
|
||||
userCollection := &model.UserCollection{
|
||||
UserId: userId,
|
||||
QuestionId: questionId,
|
||||
}
|
||||
|
||||
userCollectionDao := dao.UserCollectionDao{}
|
||||
userCollection, err := userCollectionDao.AddUserCollection(tx, userCollection)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
return false, errors.New("收藏失败")
|
||||
}
|
||||
|
||||
tx.Commit()
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// PutUserCollectionCancel 取消收藏题目
|
||||
func (r *UserCollectionService) PutUserCollectionCancel(userId, questionId int64) (bool, error) {
|
||||
// 检测问题是否被用户收藏
|
||||
IsCollection := r.CheckUserCollectionQuestion(userId, questionId)
|
||||
if IsCollection == false {
|
||||
// 已收藏
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// 开始事务
|
||||
tx := global.Db.Begin()
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
tx.Rollback()
|
||||
}
|
||||
}()
|
||||
|
||||
userCollectionDao := dao.UserCollectionDao{}
|
||||
|
||||
maps := make(map[string]interface{})
|
||||
maps["user_id"] = userId
|
||||
maps["question_id"] = questionId
|
||||
err := userCollectionDao.DeleteUserCollection(tx, maps)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
return false, errors.New("取消收藏失败")
|
||||
}
|
||||
|
||||
tx.Commit()
|
||||
return true, nil
|
||||
}
|
||||
Reference in New Issue
Block a user