fix:
This commit is contained in:
parent
8575db059a
commit
b5972292ab
|
@ -28,6 +28,8 @@ func AuthLogin(c *gin.Context) {
|
||||||
}
|
}
|
||||||
fmt.Println("WxAppId", config.AppConfig.WxAppId)
|
fmt.Println("WxAppId", config.AppConfig.WxAppId)
|
||||||
fmt.Println("WxAppSecret", config.AppConfig.WxAppSecret)
|
fmt.Println("WxAppSecret", config.AppConfig.WxAppSecret)
|
||||||
|
model.AuthLoginMutex.Lock()
|
||||||
|
defer model.AuthLoginMutex.Unlock()
|
||||||
|
|
||||||
resp, err := weapp.Login(config.AppConfig.WxAppId, config.AppConfig.WxAppSecret, req.Code)
|
resp, err := weapp.Login(config.AppConfig.WxAppId, config.AppConfig.WxAppSecret, req.Code)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -334,7 +334,7 @@ func PushWXPayNotice(c *gin.Context) {
|
||||||
if invite.FromUid != 0 {
|
if invite.FromUid != 0 {
|
||||||
inviteUser := model.GetUserByUid(invite.FromUid)
|
inviteUser := model.GetUserByUid(invite.FromUid)
|
||||||
if inviteUser.UserType != 2 && user.MemberLevel != 2 {
|
if inviteUser.UserType != 2 && user.MemberLevel != 2 {
|
||||||
err := model.CodeSendToUser(invite.FromUid, model.CodeTypeMemberCard30)
|
err := model.CodeSendToUser(invite.FromUid, model.CodeTypeMemberCard30,model.RedeemCodeActivityTypeUserInvite)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error("err:", err)
|
logger.Error("err:", err)
|
||||||
}
|
}
|
||||||
|
@ -343,6 +343,13 @@ func PushWXPayNotice(c *gin.Context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if user.MemberLevel != 2 {
|
||||||
|
err = model.CodeSendToUser(user.Uid, model.CodeTypeMemberCard30,model.RedeemCodeActivityTypeStore)
|
||||||
|
if err != nil {
|
||||||
|
logger.Error("err:", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("notify.TotalFee:", notify.TotalFee)
|
fmt.Println("notify.TotalFee:", notify.TotalFee)
|
||||||
|
|
|
@ -3,6 +3,7 @@ package controller
|
||||||
import (
|
import (
|
||||||
"github.com/codinl/go-logger"
|
"github.com/codinl/go-logger"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
"mh-server/lib/auth"
|
||||||
"mh-server/lib/status"
|
"mh-server/lib/status"
|
||||||
"mh-server/model"
|
"mh-server/model"
|
||||||
)
|
)
|
||||||
|
@ -45,3 +46,113 @@ func StoreInfo(c *gin.Context) {
|
||||||
RespOK(c, store)
|
RespOK(c, store)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ShoppingCartAdd(c *gin.Context) {
|
||||||
|
req := &struct {
|
||||||
|
GameCardId uint32 `json:"game_card_id"`
|
||||||
|
AddType uint32 `json:"add_type"` // 1-加 2-减
|
||||||
|
}{}
|
||||||
|
if err := c.ShouldBindJSON(&req); err != nil {
|
||||||
|
logger.Error(err)
|
||||||
|
RespJson(c, status.BadRequest, nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if req.GameCardId == 0 {
|
||||||
|
logger.Error("GameCardId is 0")
|
||||||
|
RespJson(c, status.BadRequest, nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
uc := auth.GetCurrentUser(c)
|
||||||
|
if uc == nil {
|
||||||
|
RespJson(c, status.Unauthorized, nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var shoppingCart model.ShoppingCart
|
||||||
|
err := model.NewShoppingCartQuerySet(model.DB).UidEq(uint64(uc.Uid)).GameCardIdEq(uint64(req.GameCardId)).One(&shoppingCart)
|
||||||
|
if err != nil && err != model.RecordNotFound {
|
||||||
|
logger.Error("err:", err)
|
||||||
|
RespJson(c, status.InternalServerError, nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err == model.RecordNotFound {
|
||||||
|
shoppingCart = model.ShoppingCart{
|
||||||
|
Uid: uint64(uc.Uid),
|
||||||
|
GameCardId: uint64(req.GameCardId),
|
||||||
|
Count: 1,
|
||||||
|
}
|
||||||
|
err := model.DB.Create(&shoppingCart).Error
|
||||||
|
if err != nil {
|
||||||
|
logger.Error("err:", err)
|
||||||
|
RespJson(c, status.InternalServerError, nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
RespOK(c, shoppingCart)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if req.AddType == 1 {
|
||||||
|
shoppingCart.Count += 1
|
||||||
|
} else if req.AddType == 2 {
|
||||||
|
shoppingCart.Count -= 1
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = model.NewShoppingCartQuerySet(model.DB).IDEq(shoppingCart.ID).GetUpdater().SetCount(shoppingCart.Count).UpdateNum()
|
||||||
|
if err != nil {
|
||||||
|
logger.Error("err:", err)
|
||||||
|
RespJson(c, status.InternalServerError, nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
RespOK(c, shoppingCart)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func ShoppingCartList(c *gin.Context) {
|
||||||
|
req := &model.ShoppingCartListReq{}
|
||||||
|
if err := c.ShouldBindJSON(&req); err != nil {
|
||||||
|
logger.Error(err)
|
||||||
|
RespJson(c, status.BadRequest, nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
uc := auth.GetCurrentUser(c)
|
||||||
|
if uc == nil {
|
||||||
|
RespJson(c, status.Unauthorized, nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
req.Uid = uc.Uid
|
||||||
|
list, err := req.List()
|
||||||
|
if err != nil {
|
||||||
|
logger.Error("err:", err)
|
||||||
|
RespJson(c, status.InternalServerError, nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
RespOK(c, list)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func ShoppingCartDel(c *gin.Context) {
|
||||||
|
req := &struct {
|
||||||
|
ShoppingCartIds []uint32 `json:"shopping_cart_ids"`
|
||||||
|
}{}
|
||||||
|
if err := c.ShouldBindJSON(&req); err != nil {
|
||||||
|
logger.Error(err)
|
||||||
|
RespJson(c, status.BadRequest, nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
uc := auth.GetCurrentUser(c)
|
||||||
|
if uc == nil {
|
||||||
|
RespJson(c, status.Unauthorized, nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err := model.NewShoppingCartQuerySet(model.DB).UidEq(uint64(uc.Uid)).IDIn(req.ShoppingCartIds...).Delete()
|
||||||
|
if err != nil {
|
||||||
|
logger.Error("err:", err)
|
||||||
|
RespJson(c, status.InternalServerError, nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
RespOK(c, nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
|
@ -205,14 +205,6 @@ func UserInfoUpdate(c *gin.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func OpenMember(c *gin.Context) {
|
func OpenMember(c *gin.Context) {
|
||||||
//req := struct {
|
|
||||||
// PayType uint32 `json:"pay_type"` // 1-开通会员 2-
|
|
||||||
//}{}
|
|
||||||
//if c.ShouldBindJSON(&req) != nil {
|
|
||||||
// RespJson(c, status.BadRequest, nil)
|
|
||||||
// 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)
|
||||||
|
@ -220,16 +212,6 @@ func OpenMember(c *gin.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
user := model.GetUserByUid(uc.Uid)
|
user := model.GetUserByUid(uc.Uid)
|
||||||
//uid := fmt.Sprintf("%d", uc.Uid)
|
|
||||||
//totalFee := MemberFee + DepositFee
|
|
||||||
//uid := "623892011"
|
|
||||||
//user := model.GetUserByUid(62389201)
|
|
||||||
|
|
||||||
//totalFee = uint32(3)
|
|
||||||
//if user.MemberLevel > 1 {
|
|
||||||
// totalFee = DepositFee
|
|
||||||
// //totalFee = uint32(1)
|
|
||||||
//}
|
|
||||||
|
|
||||||
configInfo, err := model.PayConfigInfo()
|
configInfo, err := model.PayConfigInfo()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -356,7 +338,7 @@ func RefundDeposit(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
count, err := model.NewDepositRefundRecordQuerySet(model.DB).UidEq(uc.Uid).StatusNotIn(model.DepositRefundStatusRefunded,model.DepositRefundStatusRefused).Count()
|
count, err := model.NewDepositRefundRecordQuerySet(model.DB).UidEq(uc.Uid).StatusNotIn(model.DepositRefundStatusRefunded, model.DepositRefundStatusRefused).Count()
|
||||||
if err != nil || count > 0 {
|
if err != nil || count > 0 {
|
||||||
logger.Error("count is not 0")
|
logger.Error("count is not 0")
|
||||||
RespJson(c, status.RefundDepositSubmitted, nil)
|
RespJson(c, status.RefundDepositSubmitted, nil)
|
||||||
|
@ -396,3 +378,11 @@ func UserDepositRefundRecordList(c *gin.Context) {
|
||||||
|
|
||||||
RespOK(c, resp)
|
RespOK(c, resp)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 升级 1-黄金会员 2-白金会员 3-黑金会员
|
||||||
|
// 开通会员
|
||||||
|
// 升级会员
|
||||||
|
// 订单
|
||||||
|
// 购物车
|
||||||
|
// 押金
|
||||||
|
|
||||||
|
|
|
@ -230,11 +230,21 @@ type (
|
||||||
FeeType string `xml:"fee_type,CDATA" json:"fee_type"`
|
FeeType string `xml:"fee_type,CDATA" json:"fee_type"`
|
||||||
CashFee uint `xml:"cash_fee,CDATA" json:"cash_fee"`
|
CashFee uint `xml:"cash_fee,CDATA" json:"cash_fee"`
|
||||||
CashFeeType string `xml:"cash_fee_type,CDATA" json:"cash_fee_type"`
|
CashFeeType string `xml:"cash_fee_type,CDATA" json:"cash_fee_type"`
|
||||||
|
|
||||||
CouponFee uint `xml:"coupon_fee,CDATA" json:"coupon_fee"`
|
CouponFee uint `xml:"coupon_fee,CDATA" json:"coupon_fee"`
|
||||||
CouponCount uint `xml:"coupon_count,CDATA" json:"coupon_count"`
|
CouponCount uint `xml:"coupon_count,CDATA" json:"coupon_count"`
|
||||||
CouponType0 uint `xml:"coupon_type_0,CDATA" json:"coupon_type"`
|
CouponType0 uint `xml:"coupon_type_0,CDATA" json:"coupon_type"`
|
||||||
CouponId0 string `xml:"coupon_id_0,CDATA" json:"coupon_id"`
|
CouponId0 string `xml:"coupon_id_0,CDATA" json:"coupon_id"`
|
||||||
CouponFee0 uint `xml:"coupon_fee_0,CDATA" json:"coupon_fee0"`
|
CouponFee0 uint `xml:"coupon_fee_0,CDATA" json:"coupon_fee0"`
|
||||||
|
//CouponCount string `json:"coupon_count"`
|
||||||
|
//CouponFee string `json:"coupon_fee"`
|
||||||
|
//CouponFee0 string `json:"coupon_fee_0"`
|
||||||
|
//CouponId0 string `json:"coupon_id_0"`
|
||||||
|
|
||||||
|
CouponFee1 uint `xml:"coupon_fee_1,CDATA" json:"coupon_fee_1"`
|
||||||
|
CouponId1 string `xml:"coupon_id_1,CDATA" json:"coupon_id_1"`
|
||||||
|
|
||||||
|
|
||||||
TransactionId string `xml:"transaction_id,CDATA" json:"transaction_id"`
|
TransactionId string `xml:"transaction_id,CDATA" json:"transaction_id"`
|
||||||
OutTradeNo string `xml:"out_trade_no,CDATA" json:"out_trade_no"`
|
OutTradeNo string `xml:"out_trade_no,CDATA" json:"out_trade_no"`
|
||||||
Attach string `xml:"attach,CDATA" json:"attach"`
|
Attach string `xml:"attach,CDATA" json:"attach"`
|
||||||
|
@ -262,6 +272,39 @@ type (
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//type T struct {
|
||||||
|
// Xml struct {
|
||||||
|
// Appid string `json:"appid"`
|
||||||
|
// Attach string `json:"attach"`
|
||||||
|
// BankType string `json:"bank_type"`
|
||||||
|
// CashFee string `json:"cash_fee"`
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// CouponCount string `json:"coupon_count"`
|
||||||
|
// CouponFee string `json:"coupon_fee"`
|
||||||
|
// CouponFee0 string `json:"coupon_fee_0"`
|
||||||
|
// CouponFee1 string `json:"coupon_fee_1"`
|
||||||
|
// CouponId0 string `json:"coupon_id_0"`
|
||||||
|
// CouponId1 string `json:"coupon_id_1"`
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// DeviceInfo string `json:"device_info"`
|
||||||
|
// FeeType string `json:"fee_type"`
|
||||||
|
// IsSubscribe string `json:"is_subscribe"`
|
||||||
|
// MchId string `json:"mch_id"`
|
||||||
|
// NonceStr string `json:"nonce_str"`
|
||||||
|
// Openid string `json:"openid"`
|
||||||
|
// OutTradeNo string `json:"out_trade_no"`
|
||||||
|
// ResultCode string `json:"result_code"`
|
||||||
|
// ReturnCode string `json:"return_code"`
|
||||||
|
// Sign string `json:"sign"`
|
||||||
|
// TimeEnd string `json:"time_end"`
|
||||||
|
// TotalFee string `json:"total_fee"`
|
||||||
|
// TradeType string `json:"trade_type"`
|
||||||
|
// TransactionId string `json:"transaction_id"`
|
||||||
|
// } `json:"xml"`
|
||||||
|
//}
|
||||||
|
|
||||||
////app 微信支付
|
////app 微信支付
|
||||||
////totalFee 单位是分
|
////totalFee 单位是分
|
||||||
//func AppPay(totalFee int, openId string) (*AppWxPayRet, string, error) {
|
//func AppPay(totalFee int, openId string) (*AppWxPayRet, string, error) {
|
||||||
|
|
|
@ -215,62 +215,6 @@ func (qs ShoppingCartQuerySet) DeletedAtNe(deletedAt time.Time) ShoppingCartQuer
|
||||||
return qs.w(qs.db.Where("deleted_at != ?", deletedAt))
|
return qs.w(qs.db.Where("deleted_at != ?", deletedAt))
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeliveryTypeEq is an autogenerated method
|
|
||||||
// nolint: dupl
|
|
||||||
func (qs ShoppingCartQuerySet) DeliveryTypeEq(deliveryType uint8) ShoppingCartQuerySet {
|
|
||||||
return qs.w(qs.db.Where("delivery_type = ?", deliveryType))
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeliveryTypeGt is an autogenerated method
|
|
||||||
// nolint: dupl
|
|
||||||
func (qs ShoppingCartQuerySet) DeliveryTypeGt(deliveryType uint8) ShoppingCartQuerySet {
|
|
||||||
return qs.w(qs.db.Where("delivery_type > ?", deliveryType))
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeliveryTypeGte is an autogenerated method
|
|
||||||
// nolint: dupl
|
|
||||||
func (qs ShoppingCartQuerySet) DeliveryTypeGte(deliveryType uint8) ShoppingCartQuerySet {
|
|
||||||
return qs.w(qs.db.Where("delivery_type >= ?", deliveryType))
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeliveryTypeIn is an autogenerated method
|
|
||||||
// nolint: dupl
|
|
||||||
func (qs ShoppingCartQuerySet) DeliveryTypeIn(deliveryType ...uint8) ShoppingCartQuerySet {
|
|
||||||
if len(deliveryType) == 0 {
|
|
||||||
qs.db.AddError(errors.New("must at least pass one deliveryType in DeliveryTypeIn"))
|
|
||||||
return qs.w(qs.db)
|
|
||||||
}
|
|
||||||
return qs.w(qs.db.Where("delivery_type IN (?)", deliveryType))
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeliveryTypeLt is an autogenerated method
|
|
||||||
// nolint: dupl
|
|
||||||
func (qs ShoppingCartQuerySet) DeliveryTypeLt(deliveryType uint8) ShoppingCartQuerySet {
|
|
||||||
return qs.w(qs.db.Where("delivery_type < ?", deliveryType))
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeliveryTypeLte is an autogenerated method
|
|
||||||
// nolint: dupl
|
|
||||||
func (qs ShoppingCartQuerySet) DeliveryTypeLte(deliveryType uint8) ShoppingCartQuerySet {
|
|
||||||
return qs.w(qs.db.Where("delivery_type <= ?", deliveryType))
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeliveryTypeNe is an autogenerated method
|
|
||||||
// nolint: dupl
|
|
||||||
func (qs ShoppingCartQuerySet) DeliveryTypeNe(deliveryType uint8) ShoppingCartQuerySet {
|
|
||||||
return qs.w(qs.db.Where("delivery_type != ?", deliveryType))
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeliveryTypeNotIn is an autogenerated method
|
|
||||||
// nolint: dupl
|
|
||||||
func (qs ShoppingCartQuerySet) DeliveryTypeNotIn(deliveryType ...uint8) ShoppingCartQuerySet {
|
|
||||||
if len(deliveryType) == 0 {
|
|
||||||
qs.db.AddError(errors.New("must at least pass one deliveryType in DeliveryTypeNotIn"))
|
|
||||||
return qs.w(qs.db)
|
|
||||||
}
|
|
||||||
return qs.w(qs.db.Where("delivery_type NOT IN (?)", deliveryType))
|
|
||||||
}
|
|
||||||
|
|
||||||
// GameCardIdEq is an autogenerated method
|
// GameCardIdEq is an autogenerated method
|
||||||
// nolint: dupl
|
// nolint: dupl
|
||||||
func (qs ShoppingCartQuerySet) GameCardIdEq(gameCardId uint64) ShoppingCartQuerySet {
|
func (qs ShoppingCartQuerySet) GameCardIdEq(gameCardId uint64) ShoppingCartQuerySet {
|
||||||
|
@ -431,12 +375,6 @@ func (qs ShoppingCartQuerySet) OrderAscByDeletedAt() ShoppingCartQuerySet {
|
||||||
return qs.w(qs.db.Order("deleted_at ASC"))
|
return qs.w(qs.db.Order("deleted_at ASC"))
|
||||||
}
|
}
|
||||||
|
|
||||||
// OrderAscByDeliveryType is an autogenerated method
|
|
||||||
// nolint: dupl
|
|
||||||
func (qs ShoppingCartQuerySet) OrderAscByDeliveryType() ShoppingCartQuerySet {
|
|
||||||
return qs.w(qs.db.Order("delivery_type ASC"))
|
|
||||||
}
|
|
||||||
|
|
||||||
// OrderAscByGameCardId is an autogenerated method
|
// OrderAscByGameCardId is an autogenerated method
|
||||||
// nolint: dupl
|
// nolint: dupl
|
||||||
func (qs ShoppingCartQuerySet) OrderAscByGameCardId() ShoppingCartQuerySet {
|
func (qs ShoppingCartQuerySet) OrderAscByGameCardId() ShoppingCartQuerySet {
|
||||||
|
@ -479,12 +417,6 @@ func (qs ShoppingCartQuerySet) OrderDescByDeletedAt() ShoppingCartQuerySet {
|
||||||
return qs.w(qs.db.Order("deleted_at DESC"))
|
return qs.w(qs.db.Order("deleted_at DESC"))
|
||||||
}
|
}
|
||||||
|
|
||||||
// OrderDescByDeliveryType is an autogenerated method
|
|
||||||
// nolint: dupl
|
|
||||||
func (qs ShoppingCartQuerySet) OrderDescByDeliveryType() ShoppingCartQuerySet {
|
|
||||||
return qs.w(qs.db.Order("delivery_type DESC"))
|
|
||||||
}
|
|
||||||
|
|
||||||
// OrderDescByGameCardId is an autogenerated method
|
// OrderDescByGameCardId is an autogenerated method
|
||||||
// nolint: dupl
|
// nolint: dupl
|
||||||
func (qs ShoppingCartQuerySet) OrderDescByGameCardId() ShoppingCartQuerySet {
|
func (qs ShoppingCartQuerySet) OrderDescByGameCardId() ShoppingCartQuerySet {
|
||||||
|
@ -622,13 +554,6 @@ func (u ShoppingCartUpdater) SetDeletedAt(deletedAt *time.Time) ShoppingCartUpda
|
||||||
return u
|
return u
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetDeliveryType is an autogenerated method
|
|
||||||
// nolint: dupl
|
|
||||||
func (u ShoppingCartUpdater) SetDeliveryType(deliveryType uint8) ShoppingCartUpdater {
|
|
||||||
u.fields[string(ShoppingCartDBSchema.DeliveryType)] = deliveryType
|
|
||||||
return u
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetGameCardId is an autogenerated method
|
// SetGameCardId is an autogenerated method
|
||||||
// nolint: dupl
|
// nolint: dupl
|
||||||
func (u ShoppingCartUpdater) SetGameCardId(gameCardId uint64) ShoppingCartUpdater {
|
func (u ShoppingCartUpdater) SetGameCardId(gameCardId uint64) ShoppingCartUpdater {
|
||||||
|
@ -685,38 +610,35 @@ func (f ShoppingCartDBSchemaField) String() string {
|
||||||
|
|
||||||
// ShoppingCartDBSchema stores db field names of ShoppingCart
|
// ShoppingCartDBSchema stores db field names of ShoppingCart
|
||||||
var ShoppingCartDBSchema = struct {
|
var ShoppingCartDBSchema = struct {
|
||||||
ID ShoppingCartDBSchemaField
|
ID ShoppingCartDBSchemaField
|
||||||
CreatedAt ShoppingCartDBSchemaField
|
CreatedAt ShoppingCartDBSchemaField
|
||||||
UpdatedAt ShoppingCartDBSchemaField
|
UpdatedAt ShoppingCartDBSchemaField
|
||||||
DeletedAt ShoppingCartDBSchemaField
|
DeletedAt ShoppingCartDBSchemaField
|
||||||
Uid ShoppingCartDBSchemaField
|
Uid ShoppingCartDBSchemaField
|
||||||
GameCardId ShoppingCartDBSchemaField
|
GameCardId ShoppingCartDBSchemaField
|
||||||
DeliveryType ShoppingCartDBSchemaField
|
Count ShoppingCartDBSchemaField
|
||||||
Count ShoppingCartDBSchemaField
|
|
||||||
}{
|
}{
|
||||||
|
|
||||||
ID: ShoppingCartDBSchemaField("id"),
|
ID: ShoppingCartDBSchemaField("id"),
|
||||||
CreatedAt: ShoppingCartDBSchemaField("created_at"),
|
CreatedAt: ShoppingCartDBSchemaField("created_at"),
|
||||||
UpdatedAt: ShoppingCartDBSchemaField("updated_at"),
|
UpdatedAt: ShoppingCartDBSchemaField("updated_at"),
|
||||||
DeletedAt: ShoppingCartDBSchemaField("deleted_at"),
|
DeletedAt: ShoppingCartDBSchemaField("deleted_at"),
|
||||||
Uid: ShoppingCartDBSchemaField("uid"),
|
Uid: ShoppingCartDBSchemaField("uid"),
|
||||||
GameCardId: ShoppingCartDBSchemaField("game_card_id"),
|
GameCardId: ShoppingCartDBSchemaField("game_card_id"),
|
||||||
DeliveryType: ShoppingCartDBSchemaField("delivery_type"),
|
Count: ShoppingCartDBSchemaField("count"),
|
||||||
Count: ShoppingCartDBSchemaField("count"),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update updates ShoppingCart fields by primary key
|
// Update updates ShoppingCart fields by primary key
|
||||||
// nolint: dupl
|
// nolint: dupl
|
||||||
func (o *ShoppingCart) Update(db *gorm.DB, fields ...ShoppingCartDBSchemaField) error {
|
func (o *ShoppingCart) Update(db *gorm.DB, fields ...ShoppingCartDBSchemaField) error {
|
||||||
dbNameToFieldName := map[string]interface{}{
|
dbNameToFieldName := map[string]interface{}{
|
||||||
"id": o.ID,
|
"id": o.ID,
|
||||||
"created_at": o.CreatedAt,
|
"created_at": o.CreatedAt,
|
||||||
"updated_at": o.UpdatedAt,
|
"updated_at": o.UpdatedAt,
|
||||||
"deleted_at": o.DeletedAt,
|
"deleted_at": o.DeletedAt,
|
||||||
"uid": o.Uid,
|
"uid": o.Uid,
|
||||||
"game_card_id": o.GameCardId,
|
"game_card_id": o.GameCardId,
|
||||||
"delivery_type": o.DeliveryType,
|
"count": o.Count,
|
||||||
"count": o.Count,
|
|
||||||
}
|
}
|
||||||
u := map[string]interface{}{}
|
u := map[string]interface{}{}
|
||||||
for _, f := range fields {
|
for _, f := range fields {
|
||||||
|
|
|
@ -548,3 +548,8 @@ func MergingGameCards() {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func UpdateUserName() {
|
||||||
|
InitDBProd()
|
||||||
|
|
||||||
|
}
|
|
@ -167,7 +167,7 @@ func UserRedeemCodeConvert(uid uint32, serialCode string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func CodeSendToUser(uid uint32, codeType string) error {
|
func CodeSendToUser(uid uint32, codeType string,activityType uint32) error {
|
||||||
count, err := NewUserRedeemCodeQuerySet(DB).UidEq(uid).Count()
|
count, err := NewUserRedeemCodeQuerySet(DB).UidEq(uid).Count()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error("err:", err)
|
logger.Error("err:", err)
|
||||||
|
@ -198,7 +198,8 @@ func CodeSendToUser(uid uint32, codeType string) error {
|
||||||
Status: UserRedeemCodeStatusHold,
|
Status: UserRedeemCodeStatusHold,
|
||||||
SerialCode: redeemCode.SerialCode,
|
SerialCode: redeemCode.SerialCode,
|
||||||
CodeType: redeemCode.CodeType,
|
CodeType: redeemCode.CodeType,
|
||||||
ActivityType: RedeemCodeActivityTypeUserInvite,
|
ActivityType: activityType ,
|
||||||
|
//ActivityType: RedeemCodeActivityTypeUserInvite,
|
||||||
}
|
}
|
||||||
err = begin.Create(userRedeemCode).Error
|
err = begin.Create(userRedeemCode).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -1,16 +1,88 @@
|
||||||
package model
|
package model
|
||||||
|
|
||||||
|
import "github.com/codinl/go-logger"
|
||||||
|
|
||||||
//go:generate goqueryset -in shopping_cart.go
|
//go:generate goqueryset -in shopping_cart.go
|
||||||
// gen:qs
|
// gen:qs
|
||||||
type ShoppingCart struct {
|
type ShoppingCart struct {
|
||||||
Model
|
Model
|
||||||
|
|
||||||
Uid uint64 `json:"uid" gorm:"index"`
|
Uid uint64 `json:"uid" gorm:"index"`
|
||||||
GameCardId uint64 `json:"game_card_id"` // 游戏卡id
|
GameCardId uint64 `json:"game_card_id"` // 游戏卡id
|
||||||
DeliveryType uint8 `json:"delivery_type"` // 发货类型
|
Count uint32 `json:"count"` // 数量
|
||||||
Count uint32 `json:"count"` // 数量
|
|
||||||
|
GameCard GameCard `json:"game_card" gorm:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*ShoppingCart) TableName() string {
|
func (*ShoppingCart) TableName() string {
|
||||||
return "shopping_cart"
|
return "shopping_cart"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ShoppingCartListReq struct {
|
||||||
|
Uid uint32 `json:"uid"`
|
||||||
|
PageNum int `json:"page_num"`
|
||||||
|
PageSize int `json:"page_size"`
|
||||||
|
}
|
||||||
|
type ShoppingCartListResp struct {
|
||||||
|
List []ShoppingCart `json:"list"`
|
||||||
|
Total int `json:"total"`
|
||||||
|
PageNum int `json:"page_num"`
|
||||||
|
//PageSize int `json:"page_size"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *ShoppingCartListReq) List() (*ShoppingCartListResp, error) {
|
||||||
|
resp := &ShoppingCartListResp{
|
||||||
|
PageNum: m.PageNum,
|
||||||
|
}
|
||||||
|
page := m.PageNum - 1
|
||||||
|
if page < 0 {
|
||||||
|
page = 0
|
||||||
|
}
|
||||||
|
if m.PageSize == 0 {
|
||||||
|
m.PageSize = 10
|
||||||
|
}
|
||||||
|
qs := NewShoppingCartQuerySet(DB).UidEq(uint64(m.Uid))
|
||||||
|
count, err := qs.Count()
|
||||||
|
if err != nil {
|
||||||
|
logger.Error("err:", err)
|
||||||
|
return resp, err
|
||||||
|
}
|
||||||
|
resp.Total = count/m.PageSize + 1
|
||||||
|
var shoppingCart []ShoppingCart
|
||||||
|
err = qs.OrderDescByID().Offset(page * m.PageSize).Limit(m.PageSize).All(&shoppingCart)
|
||||||
|
if err != nil && err != RecordNotFound {
|
||||||
|
logger.Error("err:", err)
|
||||||
|
return resp, err
|
||||||
|
}
|
||||||
|
resp.List = ShoppingCartListSetGameCard(shoppingCart)
|
||||||
|
return resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func ShoppingCartListSetGameCard(list []ShoppingCart) []ShoppingCart {
|
||||||
|
if len(list) == 0 {
|
||||||
|
return list
|
||||||
|
}
|
||||||
|
ids := make([]uint32, 0)
|
||||||
|
for i, _ := range list {
|
||||||
|
ids = append(ids, uint32(list[i].GameCardId))
|
||||||
|
}
|
||||||
|
var gameCards []GameCard
|
||||||
|
err := NewGameCardQuerySet(DB).IDIn(ids...).All(&gameCards)
|
||||||
|
if err != nil {
|
||||||
|
logger.Error("err:", err)
|
||||||
|
return list
|
||||||
|
}
|
||||||
|
gameCardMap := make(map[uint32]GameCard, 0)
|
||||||
|
for i, _ := range gameCards {
|
||||||
|
gameCardMap[gameCards[i].ID] = gameCards[i]
|
||||||
|
}
|
||||||
|
|
||||||
|
for i, _ := range list {
|
||||||
|
v, ok := gameCardMap[uint32(list[i].GameCardId)]
|
||||||
|
if ok {
|
||||||
|
list[i].GameCard = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return list
|
||||||
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"github.com/codinl/go-logger"
|
"github.com/codinl/go-logger"
|
||||||
"mh-server/lib/utils"
|
"mh-server/lib/utils"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -362,3 +363,30 @@ func GetDepositRefundRecordList(uid uint32) ([]DepositRefundRecord, error) {
|
||||||
}
|
}
|
||||||
return deposits, nil
|
return deposits, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
var userMutexMap map[string]*sync.Mutex
|
||||||
|
|
||||||
|
func GetUserMutexMap() map[string]*sync.Mutex {
|
||||||
|
if userMutexMap == nil {
|
||||||
|
userMutexMap = make(map[string]*sync.Mutex, 0)
|
||||||
|
}
|
||||||
|
return userMutexMap
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetUserMutex(mutexKey string) *sync.Mutex {
|
||||||
|
mutexMap := GetUserMutexMap()
|
||||||
|
if v, ok := mutexMap[mutexKey]; ok {
|
||||||
|
return v
|
||||||
|
} else {
|
||||||
|
mutexMap[mutexKey] = new(sync.Mutex)
|
||||||
|
return mutexMap[mutexKey]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//func AuthLoginMutex(uid uint32) *sync.Mutex {
|
||||||
|
// return GetUserMutex(fmt.Sprintf("AuthLogin:%d", uid))
|
||||||
|
//}
|
||||||
|
|
||||||
|
|
||||||
|
var AuthLoginMutex = sync.Mutex{}
|
|
@ -123,7 +123,7 @@ func ConfigAppRouter(r gin.IRouter) {
|
||||||
order.POST("express", controller.OrderExpress) // 订单物流
|
order.POST("express", controller.OrderExpress) // 订单物流
|
||||||
order.POST("express_company/list", controller.ExpressCompanyList) // 物流公司列表
|
order.POST("express_company/list", controller.ExpressCompanyList) // 物流公司列表
|
||||||
order.POST("order/wx_pay/success", controller.WXPaySuccess) // 微信支付成功
|
order.POST("order/wx_pay/success", controller.WXPaySuccess) // 微信支付成功
|
||||||
order.POST("cancel", controller.OrderCancel) // 订单取消
|
order.POST("cancel", controller.OrderCancel) // 订单取消
|
||||||
|
|
||||||
order.Use(auth.UserAccessAuth) // TODO
|
order.Use(auth.UserAccessAuth) // TODO
|
||||||
order.POST("create", controller.OrderCreate) // 创建订单
|
order.POST("create", controller.OrderCreate) // 创建订单
|
||||||
|
@ -158,5 +158,14 @@ func ConfigAppRouter(r gin.IRouter) {
|
||||||
activity.POST("redeem_code/user/convert", controller.UserConvertRedeemCode) // 会员兑换码
|
activity.POST("redeem_code/user/convert", controller.UserConvertRedeemCode) // 会员兑换码
|
||||||
|
|
||||||
}
|
}
|
||||||
|
shoppingCart := api.Group("shopping_cart")
|
||||||
|
{
|
||||||
|
|
||||||
|
shoppingCart.Use(auth.UserAccessAuth)
|
||||||
|
shoppingCart.POST("list", controller.ShoppingCartList) // 详情
|
||||||
|
shoppingCart.POST("add", controller.ShoppingCartAdd) //
|
||||||
|
shoppingCart.POST("del", controller.ShoppingCartDel) //
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user