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 {
|
||||
}
|
||||
Reference in New Issue
Block a user