增加了用户支付次数,购买次数等字段维护
This commit is contained in:
parent
8094cd3c51
commit
f3833ee5d5
@ -93,10 +93,19 @@ func (r *CallBack) WxPaySingle(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 增加题目支付次数
|
// 增加单项支付次数
|
||||||
questionDao := dao.QuestionDao{}
|
questionService := service.QuestionService{}
|
||||||
err = questionDao.Inc(tx, orderSingle.QuestionId, "pay_count", 1)
|
res, err := questionService.AddQuestionPayCount(tx, orderSingle.QuestionId)
|
||||||
if err != nil {
|
if err != nil || res == false {
|
||||||
|
tx.Rollback()
|
||||||
|
responses.FailWithMessage("内部错误", c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 增加用户单项支付次数
|
||||||
|
userService := service.UserService{}
|
||||||
|
res, err = userService.AddUserSingleSubmitCount(tx, orderSingle.UserId)
|
||||||
|
if err != nil || res == false {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
responses.FailWithMessage("内部错误", c)
|
responses.FailWithMessage("内部错误", c)
|
||||||
return
|
return
|
||||||
@ -223,6 +232,15 @@ func (r *CallBack) WxPayMember(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 增加用户单项提交次数
|
||||||
|
userService := service.UserService{}
|
||||||
|
res, err := userService.AddUserMemberBuyCount(tx, user.UserId)
|
||||||
|
if err != nil || res == false {
|
||||||
|
tx.Rollback()
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"code": "ERROR", "message": "增加用户会员到期时间失败"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
tx.Commit()
|
tx.Commit()
|
||||||
c.JSON(http.StatusOK, gin.H{"code": "SUCCESS", "message": "OK"})
|
c.JSON(http.StatusOK, gin.H{"code": "SUCCESS", "message": "OK"})
|
||||||
}
|
}
|
||||||
|
|||||||
@ -297,6 +297,8 @@ func (r *Question) PutQuestionClickCount(c *gin.Context) {
|
|||||||
|
|
||||||
// PutQuestionSubmitCount 增加问题提交次数
|
// PutQuestionSubmitCount 增加问题提交次数
|
||||||
func (r *Question) PutQuestionSubmitCount(c *gin.Context) {
|
func (r *Question) PutQuestionSubmitCount(c *gin.Context) {
|
||||||
|
userId := c.GetInt64("UserId")
|
||||||
|
|
||||||
id := c.Param("question_id")
|
id := c.Param("question_id")
|
||||||
if id == "" {
|
if id == "" {
|
||||||
responses.FailWithMessage("缺少参数", c)
|
responses.FailWithMessage("缺少参数", c)
|
||||||
@ -331,8 +333,19 @@ func (r *Question) PutQuestionSubmitCount(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
err = questionDao.Inc(tx, questionId, "submit_count", 1)
|
// 增加单项提交次数
|
||||||
if err != nil {
|
questionService := service.QuestionService{}
|
||||||
|
res, err := questionService.AddQuestionSubmitCount(tx, questionId)
|
||||||
|
if err != nil || res == false {
|
||||||
|
tx.Rollback()
|
||||||
|
responses.FailWithMessage("内部错误", c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 增加用户单项提交次数
|
||||||
|
userService := service.UserService{}
|
||||||
|
res, err = userService.AddUserSingleSubmitCount(tx, userId)
|
||||||
|
if err != nil || res == false {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
responses.FailWithMessage("内部错误", c)
|
responses.FailWithMessage("内部错误", c)
|
||||||
return
|
return
|
||||||
|
|||||||
@ -115,3 +115,21 @@ func (r *UserDao) GetUserListByMemberValidTime(maps interface{}, startTime, endT
|
|||||||
}
|
}
|
||||||
return m, nil
|
return m, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Inc 自增
|
||||||
|
func (r *UserDao) Inc(tx *gorm.DB, userId int64, field string, numeral int) error {
|
||||||
|
err := tx.Model(&model.User{}).Where("user_id = ?", userId).UpdateColumn(field, gorm.Expr(field+" + ?", numeral)).Error
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Dec 自减
|
||||||
|
func (r *UserDao) Dec(tx *gorm.DB, userId int64, field string, numeral int) error {
|
||||||
|
err := tx.Model(&model.User{}).Where("user_id = ?", userId).UpdateColumn(field, gorm.Expr(field+" - ?", numeral)).Error
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|||||||
@ -372,6 +372,9 @@ func (r *OrderSingleService) GetAppPrepay(m *model.OrderSingle) (prepay *app.Pre
|
|||||||
|
|
||||||
// CompleteUnPayOrderSingle 完成未支付单项订单-开通会员成功时使用
|
// CompleteUnPayOrderSingle 完成未支付单项订单-开通会员成功时使用
|
||||||
func (r *OrderSingleService) CompleteUnPayOrderSingle(tx *gorm.DB, userId int64) (bool, error) {
|
func (r *OrderSingleService) CompleteUnPayOrderSingle(tx *gorm.DB, userId int64) (bool, error) {
|
||||||
|
questionService := QuestionService{}
|
||||||
|
userService := UserService{}
|
||||||
|
|
||||||
// 获取所有未支付单项订单
|
// 获取所有未支付单项订单
|
||||||
orderSingleDao := dao.OrderSingleDao{}
|
orderSingleDao := dao.OrderSingleDao{}
|
||||||
maps := make(map[string]interface{})
|
maps := make(map[string]interface{})
|
||||||
@ -399,10 +402,15 @@ func (r *OrderSingleService) CompleteUnPayOrderSingle(tx *gorm.DB, userId int64)
|
|||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 增加题目支付次数
|
// 增加单项支付次数
|
||||||
questionDao := dao.QuestionDao{}
|
res, err := questionService.AddQuestionPayCount(tx, single.QuestionId)
|
||||||
err = questionDao.Inc(tx, single.QuestionId, "pay_count", 1)
|
if err != nil || res == false {
|
||||||
if err != nil {
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// 增加用户单项支付次数
|
||||||
|
res, err = userService.AddUserSingleSubmitCount(tx, userId)
|
||||||
|
if err != nil || res == false {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,6 +2,7 @@ package service
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"gorm.io/gorm"
|
||||||
"hepa-calc-api/api/dao"
|
"hepa-calc-api/api/dao"
|
||||||
"hepa-calc-api/api/model"
|
"hepa-calc-api/api/model"
|
||||||
"time"
|
"time"
|
||||||
@ -206,3 +207,25 @@ func (r *QuestionService) HandleQuestionDiscountPrice(discountPrice *float64, di
|
|||||||
|
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AddQuestionSubmitCount 增加单项提交次数
|
||||||
|
func (r *QuestionService) AddQuestionSubmitCount(tx *gorm.DB, questionId int64) (bool, error) {
|
||||||
|
questionDao := dao.QuestionDao{}
|
||||||
|
err := questionDao.Inc(tx, questionId, "submit_count", 1)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddQuestionPayCount 增加单项支付次数
|
||||||
|
func (r *QuestionService) AddQuestionPayCount(tx *gorm.DB, userId int64) (bool, error) {
|
||||||
|
questionDao := dao.QuestionDao{}
|
||||||
|
err := questionDao.Inc(tx, userId, "pay_count", 1)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
|||||||
@ -105,3 +105,36 @@ func (r *UserService) AddUserMemberValidDate(tx *gorm.DB, user *model.User, d in
|
|||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AddUserSingleSubmitCount 增加用户单项提交次数
|
||||||
|
func (r *UserService) AddUserSingleSubmitCount(tx *gorm.DB, userId int64) (bool, error) {
|
||||||
|
userDao := dao.UserDao{}
|
||||||
|
err := userDao.Inc(tx, userId, "single_submit_count", 1)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddUserSinglePayCount 增加用户单项支付次数
|
||||||
|
func (r *UserService) AddUserSinglePayCount(tx *gorm.DB, userId int64) (bool, error) {
|
||||||
|
userDao := dao.UserDao{}
|
||||||
|
err := userDao.Inc(tx, userId, "single_pay_count", 1)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddUserMemberBuyCount 增加用户会员购买次数
|
||||||
|
func (r *UserService) AddUserMemberBuyCount(tx *gorm.DB, userId int64) (bool, error) {
|
||||||
|
userDao := dao.UserDao{}
|
||||||
|
err := userDao.Inc(tx, userId, "member_buy_count", 1)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user