1.修改GameCardInfo接口,查看详情无需用户登录;
2.修改搜索相关接口,搜索无需登录; 3.修改租赁订单接口,解决重复下单缺陷;
This commit is contained in:
parent
d467e3b978
commit
db83bd9d8a
|
@ -80,8 +80,20 @@ func GameCardInfo(c *gin.Context) {
|
|||
return
|
||||
}
|
||||
uc := auth.GetCurrentUser(c)
|
||||
if uc == nil {
|
||||
RespJson(c, status.Unauthorized, nil)
|
||||
if uc == 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
|
||||
}
|
||||
|
||||
|
@ -127,8 +139,8 @@ func GameCardSearch(c *gin.Context) {
|
|||
}
|
||||
uc := auth.GetCurrentUser(c)
|
||||
if uc == nil {
|
||||
RespJson(c, status.Unauthorized, nil)
|
||||
return
|
||||
//RespJson(c, status.Unauthorized, nil)
|
||||
//return
|
||||
}
|
||||
|
||||
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)
|
||||
return
|
||||
}
|
||||
err = model.SearchHistoryAdd(uc.Uid, req.Name)
|
||||
if err != nil {
|
||||
logger.Error("err:", err)
|
||||
RespJson(c, status.InternalServerError, nil)
|
||||
return
|
||||
|
||||
if uc != nil { // 登录过的用户才记录搜索历史
|
||||
err = model.SearchHistoryAdd(uc.Uid, req.Name)
|
||||
if err != nil {
|
||||
logger.Error("err:", err)
|
||||
RespJson(c, status.InternalServerError, nil)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
ret := map[string]interface{}{
|
||||
"card_list": cardList,
|
||||
"cur_page": req.Page,
|
||||
|
@ -154,7 +170,8 @@ func GameCardSearch(c *gin.Context) {
|
|||
func GameCardSearchHistory(c *gin.Context) {
|
||||
uc := auth.GetCurrentUser(c)
|
||||
if uc == nil {
|
||||
RespJson(c, status.Unauthorized, nil)
|
||||
//RespJson(c, status.Unauthorized, nil)
|
||||
RespOK(c, []model.SearchHistory{})
|
||||
return
|
||||
}
|
||||
historyList, err := model.GetSearchHistoryList(uc.Uid)
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
"fmt"
|
||||
"github.com/codinl/go-logger"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/jinzhu/gorm"
|
||||
"golang.org/x/sync/errgroup"
|
||||
"io/ioutil"
|
||||
"mh-server/kuaidi"
|
||||
|
@ -241,19 +242,40 @@ func RentCardOrderCreate(c *gin.Context) {
|
|||
cardCount += v.Count
|
||||
}
|
||||
|
||||
rentCard := model.GetUserRentCard(uc.Uid)
|
||||
if rentCard == nil {
|
||||
//logger.Error(errors.New("GetUserByUid err"))
|
||||
//RespJson(c, status.InternalServerError, nil)
|
||||
//return
|
||||
rentCard = &model.UserRentCard{LevelRentCount: memberConfig.CardMax, CanRentCount: memberConfig.CardMax}
|
||||
var rentCard *model.UserRentCard
|
||||
var tx *gorm.DB
|
||||
if req.Price == 0 {
|
||||
fmt.Println("*********** req.Price == 0 ***********")
|
||||
tx = model.TransactionBegin()
|
||||
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 {
|
||||
// rentCard.CanRentCount -= 1
|
||||
//}
|
||||
if cardCount > rentCard.CanRentCount {
|
||||
logger.Error("GetMemberConfig err:", err)
|
||||
if req.Price == 0 {
|
||||
tx.Rollback()
|
||||
}
|
||||
logger.Error("err:", "会员超过可借卡数")
|
||||
RespJson(c, status.OrderOutRentCount, nil)
|
||||
return
|
||||
}
|
||||
|
@ -376,7 +398,7 @@ func RentCardOrderCreate(c *gin.Context) {
|
|||
|
||||
//fmt.Println("PayPrice:", order.PayPrice)
|
||||
if req.Price == 0 {
|
||||
tx := model.TransactionBegin()
|
||||
//tx := model.TransactionBegin()
|
||||
order.PayStatus = model.PayStatusPaid
|
||||
fmt.Println("orderId:", order.PayStatus)
|
||||
err = order.OrderCreate(tx)
|
||||
|
|
|
@ -362,12 +362,21 @@ func GetUserEffectiveStore(uid uint32) (*StoreInfo, error) {
|
|||
return &validStores[0], nil
|
||||
}
|
||||
|
||||
func GetUserRentCard(uid uint32) *UserRentCard {
|
||||
func GetUserRentCard(db *gorm.DB, uid uint32) *UserRentCard {
|
||||
userRent := new(UserRentCard)
|
||||
if err := NewUserRentCardQuerySet(DB).UidEq(uid).One(userRent); err != nil {
|
||||
logger.Error(err, uid)
|
||||
return nil
|
||||
if db == nil {
|
||||
if err := NewUserRentCardQuerySet(DB).UidEq(uid).One(userRent); err != 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
|
||||
}
|
||||
|
||||
|
|
|
@ -58,7 +58,7 @@ func ConfigAppRouter(r gin.IRouter) {
|
|||
gameCard.POST("game_type", controller.GameCardTypes) // 游戏标签
|
||||
gameCard.POST("type/list", controller.GameCardTypeList) // 游戏类型列表
|
||||
|
||||
gameCard.Use(auth.UserAccessAuth)
|
||||
//gameCard.Use(auth.UserAccessAuth)
|
||||
gameCard.POST("info", controller.GameCardInfo) // 游戏卡详情
|
||||
gameCard.POST("list", controller.GameCardList) // 游戏卡列表
|
||||
gameCard.POST("banner", controller.HomeCarouselList) // 轮播图
|
||||
|
@ -69,7 +69,7 @@ func ConfigAppRouter(r gin.IRouter) {
|
|||
search.POST("list", controller.GameCardSearch) // 游戏卡搜索列表
|
||||
search.POST("hot", controller.GameCardHotSearch) // 游戏卡搜索列表
|
||||
|
||||
search.Use(auth.UserAccessAuth)
|
||||
//search.Use(auth.UserAccessAuth)
|
||||
search.POST("history", controller.GameCardSearchHistory) // 游戏卡搜索历史
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user