1.修改GameCardInfo接口,查看详情无需用户登录;

2.修改搜索相关接口,搜索无需登录;
3.修改租赁订单接口,解决重复下单缺陷;
This commit is contained in:
chenlin 2024-08-26 18:14:41 +08:00
parent d467e3b978
commit db83bd9d8a
4 changed files with 72 additions and 24 deletions

View File

@ -80,8 +80,20 @@ func GameCardInfo(c *gin.Context) {
return return
} }
uc := auth.GetCurrentUser(c) uc := auth.GetCurrentUser(c)
if uc == nil { if uc == nil { // 如果没有登录,则只查看详情
RespJson(c, status.Unauthorized, nil) //RespJson(c, status.Unauthorized, nil)
//return
info, err := model.GetGameCardInfo(req.GameId, req.StoreId)
if err != nil {
logger.Error("err:", err)
RespJson(c, status.InternalServerError, nil)
return
}
ret := map[string]interface{}{
"card_info": info,
"is_collection": false,
}
RespOK(c, ret)
return return
} }
@ -127,8 +139,8 @@ func GameCardSearch(c *gin.Context) {
} }
uc := auth.GetCurrentUser(c) uc := auth.GetCurrentUser(c)
if uc == nil { if uc == nil {
RespJson(c, status.Unauthorized, nil) //RespJson(c, status.Unauthorized, nil)
return //return
} }
cardList, totalPage, err := model.GetGameCardSearch(req.Name, req.Page, req.PageSize, req.StoreId) cardList, totalPage, err := model.GetGameCardSearch(req.Name, req.Page, req.PageSize, req.StoreId)
@ -137,12 +149,16 @@ func GameCardSearch(c *gin.Context) {
RespJson(c, status.InternalServerError, nil) RespJson(c, status.InternalServerError, nil)
return return
} }
err = model.SearchHistoryAdd(uc.Uid, req.Name)
if err != nil { if uc != nil { // 登录过的用户才记录搜索历史
logger.Error("err:", err) err = model.SearchHistoryAdd(uc.Uid, req.Name)
RespJson(c, status.InternalServerError, nil) if err != nil {
return logger.Error("err:", err)
RespJson(c, status.InternalServerError, nil)
return
}
} }
ret := map[string]interface{}{ ret := map[string]interface{}{
"card_list": cardList, "card_list": cardList,
"cur_page": req.Page, "cur_page": req.Page,
@ -154,7 +170,8 @@ func GameCardSearch(c *gin.Context) {
func GameCardSearchHistory(c *gin.Context) { func GameCardSearchHistory(c *gin.Context) {
uc := auth.GetCurrentUser(c) uc := auth.GetCurrentUser(c)
if uc == nil { if uc == nil {
RespJson(c, status.Unauthorized, nil) //RespJson(c, status.Unauthorized, nil)
RespOK(c, []model.SearchHistory{})
return return
} }
historyList, err := model.GetSearchHistoryList(uc.Uid) historyList, err := model.GetSearchHistoryList(uc.Uid)

View File

@ -6,6 +6,7 @@ import (
"fmt" "fmt"
"github.com/codinl/go-logger" "github.com/codinl/go-logger"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/jinzhu/gorm"
"golang.org/x/sync/errgroup" "golang.org/x/sync/errgroup"
"io/ioutil" "io/ioutil"
"mh-server/kuaidi" "mh-server/kuaidi"
@ -241,19 +242,40 @@ func RentCardOrderCreate(c *gin.Context) {
cardCount += v.Count cardCount += v.Count
} }
rentCard := model.GetUserRentCard(uc.Uid) var rentCard *model.UserRentCard
if rentCard == nil { var tx *gorm.DB
//logger.Error(errors.New("GetUserByUid err")) if req.Price == 0 {
//RespJson(c, status.InternalServerError, nil) fmt.Println("*********** req.Price == 0 ***********")
//return tx = model.TransactionBegin()
rentCard = &model.UserRentCard{LevelRentCount: memberConfig.CardMax, CanRentCount: memberConfig.CardMax} rentCard = model.GetUserRentCard(tx, uc.Uid)
fmt.Println("*********** rentCard is:", rentCard)
if rentCard == nil {
//logger.Error(errors.New("GetUserByUid err"))
//RespJson(c, status.InternalServerError, nil)
//return
rentCard = &model.UserRentCard{LevelRentCount: memberConfig.CardMax, CanRentCount: memberConfig.CardMax}
}
} else {
fmt.Println("*********** req.Price != 0 ***********")
rentCard = model.GetUserRentCard(nil, uc.Uid)
fmt.Println("*********** rentCard is:", rentCard)
if rentCard == nil {
//logger.Error(errors.New("GetUserByUid err"))
//RespJson(c, status.InternalServerError, nil)
//return
rentCard = &model.UserRentCard{LevelRentCount: memberConfig.CardMax, CanRentCount: memberConfig.CardMax}
}
} }
//if uc.Uid == 45935373 { //if uc.Uid == 45935373 {
// rentCard.CanRentCount -= 1 // rentCard.CanRentCount -= 1
//} //}
if cardCount > rentCard.CanRentCount { if cardCount > rentCard.CanRentCount {
logger.Error("GetMemberConfig err:", err) if req.Price == 0 {
tx.Rollback()
}
logger.Error("err:", "会员超过可借卡数")
RespJson(c, status.OrderOutRentCount, nil) RespJson(c, status.OrderOutRentCount, nil)
return return
} }
@ -376,7 +398,7 @@ func RentCardOrderCreate(c *gin.Context) {
//fmt.Println("PayPrice:", order.PayPrice) //fmt.Println("PayPrice:", order.PayPrice)
if req.Price == 0 { if req.Price == 0 {
tx := model.TransactionBegin() //tx := model.TransactionBegin()
order.PayStatus = model.PayStatusPaid order.PayStatus = model.PayStatusPaid
fmt.Println("orderId:", order.PayStatus) fmt.Println("orderId:", order.PayStatus)
err = order.OrderCreate(tx) err = order.OrderCreate(tx)

View File

@ -362,12 +362,21 @@ func GetUserEffectiveStore(uid uint32) (*StoreInfo, error) {
return &validStores[0], nil return &validStores[0], nil
} }
func GetUserRentCard(uid uint32) *UserRentCard { func GetUserRentCard(db *gorm.DB, uid uint32) *UserRentCard {
userRent := new(UserRentCard) userRent := new(UserRentCard)
if err := NewUserRentCardQuerySet(DB).UidEq(uid).One(userRent); err != nil { if db == nil {
logger.Error(err, uid) if err := NewUserRentCardQuerySet(DB).UidEq(uid).One(userRent); err != nil {
return nil logger.Error(err, uid)
return nil
}
} else {
// 手动加锁查询
if err := db.Raw(`SELECT * FROM user_rent_card WHERE uid = ? FOR UPDATE`, uid).Scan(userRent).Error; err != nil {
logger.Error(err, uid)
return nil
}
} }
return userRent return userRent
} }

View File

@ -58,7 +58,7 @@ func ConfigAppRouter(r gin.IRouter) {
gameCard.POST("game_type", controller.GameCardTypes) // 游戏标签 gameCard.POST("game_type", controller.GameCardTypes) // 游戏标签
gameCard.POST("type/list", controller.GameCardTypeList) // 游戏类型列表 gameCard.POST("type/list", controller.GameCardTypeList) // 游戏类型列表
gameCard.Use(auth.UserAccessAuth) //gameCard.Use(auth.UserAccessAuth)
gameCard.POST("info", controller.GameCardInfo) // 游戏卡详情 gameCard.POST("info", controller.GameCardInfo) // 游戏卡详情
gameCard.POST("list", controller.GameCardList) // 游戏卡列表 gameCard.POST("list", controller.GameCardList) // 游戏卡列表
gameCard.POST("banner", controller.HomeCarouselList) // 轮播图 gameCard.POST("banner", controller.HomeCarouselList) // 轮播图
@ -69,7 +69,7 @@ func ConfigAppRouter(r gin.IRouter) {
search.POST("list", controller.GameCardSearch) // 游戏卡搜索列表 search.POST("list", controller.GameCardSearch) // 游戏卡搜索列表
search.POST("hot", controller.GameCardHotSearch) // 游戏卡搜索列表 search.POST("hot", controller.GameCardHotSearch) // 游戏卡搜索列表
search.Use(auth.UserAccessAuth) //search.Use(auth.UserAccessAuth)
search.POST("history", controller.GameCardSearchHistory) // 游戏卡搜索历史 search.POST("history", controller.GameCardSearchHistory) // 游戏卡搜索历史
} }