Explorar o código

订单提交修改

Administrator %!s(int64=2) %!d(string=hai) anos
pai
achega
ff00796ead
Modificáronse 5 ficheiros con 23 adicións e 11 borrados
  1. 17 11
      data/dao/OrderDao.go
  2. 1 0
      router/BackGoodsRouter.go
  3. 1 0
      router/BackRouter.go
  4. 1 0
      router/OrderRouter.go
  5. 3 0
      router/UserRouter.go

+ 17 - 11
data/dao/OrderDao.go

@@ -139,22 +139,28 @@ func OrderPaySuccess(orderId int64, userId int64) error {
 	if err != nil {
 		return err
 	}
-	configs.Engine.Table("goods_order").ID(orderId).Cols("state").Update(map[string]any{"state": 1})
+	update, err := configs.Engine.Table("goods_order").Where("id = ?", orderId).Update(map[string]any{"state": 1})
+	if err != nil {
+		fmt.Println(update, err)
+	}
 
 	//获取价格
 	var price = order.TotalPrice
 	//给推荐人分成
 	user, err := manage.GetUserById(userId)
-	wallet := domain.UserWallet{UserId: user.InviterBy}
-	list, err := manage.GetUserWalletList(wallet, 0, 1)
-	if err != nil {
-		return err
-	}
-	userWallet, ok := list.List[0].(domain.UserWallet)
-	if ok {
-		//userWallet.Balance = userWallet.Balance + (price * 0.1)
-		userWallet.PromotionAmount = userWallet.PromotionAmount + (price * 0.1)
-		configs.Engine.Table("user_wallet").ID(userWallet.Id).Cols("balance").Update(map[string]any{"promotion_amount": userWallet.PromotionAmount})
+	if user.InviterBy != 0 {
+		wallet := domain.UserWallet{UserId: user.InviterBy}
+		list, err := manage.GetUserWalletList(wallet, 0, 1)
+		if err != nil {
+			return err
+		}
+		userWallet, ok := list.List[0].(domain.UserWallet)
+		if ok {
+			//userWallet.Balance = userWallet.Balance + (price * 0.1)
+			userWallet.PromotionAmount = userWallet.PromotionAmount + (price * 0.1)
+			configs.Engine.Table("user_wallet").ID(userWallet.Id).Cols("balance").
+				Update(map[string]any{"promotion_amount": userWallet.PromotionAmount})
+		}
 	}
 	return nil
 }

+ 1 - 0
router/BackGoodsRouter.go

@@ -65,6 +65,7 @@ func GetGoodsAndIntroductionList(c *gin.Context) {
 	intrs, err := manage.GetGoodsIntroductionListInId(intrIds)
 	if err != nil {
 		c.JSON(200, CreateResultError(500, "查询错误"))
+		return
 	}
 
 	dataMap := make(map[int64]vo.GoodsVo)

+ 1 - 0
router/BackRouter.go

@@ -48,6 +48,7 @@ func SaveGenTableColumnList(c *gin.Context) {
 	arr, ok := genTableColumnParam.([]interface{})
 	if !ok {
 		c.JSON(200, CreateResultError(400, "参数错误"))
+		return
 	}
 	for i := 0; i < len(arr); i++ {
 		data, ok := arr[i].(map[string]interface{})

+ 1 - 0
router/OrderRouter.go

@@ -44,6 +44,7 @@ func CreateOrder(c *gin.Context) {
 	//查询库存数量
 	if sku.InventoryNumber < cast.ToInt64(count) {
 		c.JSON(200, CreateResultError(1000, "库存不足"))
+		return
 	}
 
 	tp := sku.Price * float64(cast.ToInt(count))

+ 3 - 0
router/UserRouter.go

@@ -143,11 +143,13 @@ func GetUserWallet(c *gin.Context) {
 	userWallet, err := dao.GetUserWalletByUserId(id)
 	if err != nil {
 		c.JSON(200, CreateResultError(500, "获取钱包失败"))
+		return
 	}
 	vo.Wallet = userWallet
 	vo.CouponUserJDM, err = dao.GetUserCouponByUserId(id)
 	if err != nil {
 		c.JSON(200, CreateResultError(500, "获取优惠券失败"))
+		return
 	}
 	c.JSON(200, CreateResultData(vo))
 }
@@ -184,6 +186,7 @@ func GetUserOrder(c *gin.Context) {
 	vo, err := dao.GetListGoodsOrder(cast.ToString(state), id, cast.ToInt(pageNum), cast.ToInt(pageSize))
 	if err != nil {
 		c.JSON(200, CreateResultError(500, "获取订单失败"))
+		return
 	}
 	c.JSON(200, CreateResultData(vo))
 }