Skip to content

Commit

Permalink
⚡:优化代码
Browse files Browse the repository at this point in the history
  • Loading branch information
dalaohekele committed Oct 30, 2022
1 parent d05839f commit dcefd9c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
26 changes: 26 additions & 0 deletions model/common/enum/goods_status.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package enum

type GoodsStatusEnum int

const (
GOODS_DEFAULT GoodsStatusEnum = -9
GOODS_UNDER GoodsStatusEnum = 0
)

func GetNewBeeMallGoodsStatusEnumByStatus(status int) (int, string) {
switch status {
case 0:
return 0, "已下架"
default:
return -9, "error"
}
}

func (g GoodsStatusEnum) Code() int {
switch g {
case GOODS_UNDER:
return 0
default:
return -9
}
}
4 changes: 2 additions & 2 deletions service/mall/mall_order.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (m *MallOrderService) SaveOrder(token string, userAddress mall.MallUserAddr
global.GVA_DB.Where("goods_id in ? ", goodsIds).Find(&newBeeMallGoods)
//检查是否包含已下架商品
for _, mallGoods := range newBeeMallGoods {
if mallGoods.GoodsSellStatus != 0 {
if mallGoods.GoodsSellStatus != enum.GOODS_UNDER.Code() {
return errors.New("已下架,无法生成订单"), orderNo
}
}
Expand Down Expand Up @@ -115,7 +115,7 @@ func (m *MallOrderService) PaySuccess(orderNo string, payType int) (err error) {
if mallOrder.OrderStatus != 0 {
return errors.New("订单状态异常!")
}
mallOrder.OrderStatus = 1
mallOrder.OrderStatus = enum.ORDER_PAID.Code()
mallOrder.PayType = payType
mallOrder.PayStatus = 1
mallOrder.PayTime = common.JSONTime{time.Now()}
Expand Down

0 comments on commit dcefd9c

Please sign in to comment.