Browse Source

剑鱼币订单 数量为负的情况处理

wangshan 4 years ago
parent
commit
6dea30aa64
1 changed files with 14 additions and 8 deletions
  1. 14 8
      src/jfw/modules/subscribepay/src/service/integral.go

+ 14 - 8
src/jfw/modules/subscribepay/src/service/integral.go

@@ -39,12 +39,13 @@ func (b *Integral) GetPrice() {
 			return Result{-1, "未登录", nil}
 		}
 		score, _ := b.GetInteger("score")
-		order_money := getIntegralMoney(userId, -1, score)
+		order_money, order_score := getIntegralMoney(userId, -1, score)
 		if order_money == -1 {
-			return Result{-1, "剑鱼币生成订单价格计算错误", nil}
+			return Result{-1, "-剑鱼币生成订单价格计算错误-", nil}
 		}
 		return Result{Data: map[string]interface{}{
 			"price": order_money,
+			"score": order_score,
 		},
 		}
 	}()
@@ -69,7 +70,7 @@ func (b *Integral) CreateOrder() {
 		price, _ := b.GetInteger("price")
 		score, _ := b.GetInteger("score")
 		phone := b.GetString("phone")
-		order_money := getIntegralMoney(userId, price, score)
+		order_money, order_score := getIntegralMoney(userId, price, score)
 		if order_money == -1 {
 			return Result{-1, "剑鱼币生成订单价格计算错误", nil}
 		}
@@ -77,6 +78,7 @@ func (b *Integral) CreateOrder() {
 		filter_map := map[string]interface{}{
 			"price":       price,
 			"score":       score,
+			"order_score": order_score,
 			"isPermanent": true,
 			"phone":       phone,
 		}
@@ -111,9 +113,13 @@ func (b *Integral) CreateOrder() {
 }
 
 //验证价格
-func getIntegralMoney(userId string, price, score int) int {
+func getIntegralMoney(userId string, price, score int) (int, int) {
+	original_score := score
+	if original_score < 0 {
+		original_score = original_score * -1
+	}
 	//原价(分)
-	original_price := score * 100 / config.IntegralConfig.SlewRate
+	original_price := original_score * 100 / config.IntegralConfig.SlewRate
 	//基础折扣
 	order_price := original_price * config.IntegralConfig.BasicDiscount
 	if config.IntegralConfig.ActiveIng {
@@ -123,10 +129,10 @@ func getIntegralMoney(userId string, price, score int) int {
 	if price > 0 {
 		//价格验证
 		if order_price == price {
-			return price
+			return price, original_score
 		}
 	} else {
-		return order_price
+		return order_price, original_score
 	}
-	return -1
+	return -1, 0
 }