Browse Source

fix:计费修改

duxin 2 months ago
parent
commit
cd72c1acfd
2 changed files with 41 additions and 66 deletions
  1. 33 31
      internal/logic/product/bigmember/price.go
  2. 8 35
      internal/logic/user/getService.go

+ 33 - 31
internal/logic/product/bigmember/price.go

@@ -54,7 +54,7 @@ func (p jyBigProduct) GetPrice() (price int64, err error) {
 		if p.param.Filter.ComboId != 0 { //套餐
 		if p.param.Filter.ComboId != 0 { //套餐
 			price = thisPriceSetting.UnityPrice(gconv.Float64(p.param.Filter.BuyCycle+p.param.Filter.GiftCycle), cycleType, gconv.Int(finalAccountCount), 0, p.param.ReqSubject == 2)
 			price = thisPriceSetting.UnityPrice(gconv.Float64(p.param.Filter.BuyCycle+p.param.Filter.GiftCycle), cycleType, gconv.Int(finalAccountCount), 0, p.param.ReqSubject == 2)
 		} else if len(p.param.Filter.ServiceIds) > 0 { //自定义
 		} else if len(p.param.Filter.ServiceIds) > 0 { //自定义
-			price = DiyBigMember(context.Background(), 1, gconv.Int(finalAccountCount+1), utility.GetMonthNum(p.param.Filter.BuyCycle+p.param.Filter.GiftCycle, cycleType), p.param.UserId, p.param.Filter.ServiceIds, p.param.ReqSubject == 2)
+			price = DiyBigMember(context.Background(), 1, gconv.Int(finalAccountCount+1), utility.GetMonthNum(p.param.Filter.BuyCycle+p.param.Filter.GiftCycle, cycleType), nil, p.param.Filter.ServiceIds, p.param.ReqSubject == 2)
 			//获取各个服务
 			//获取各个服务
 			/*var (
 			/*var (
 				diyPrice, specialPrice int64
 				diyPrice, specialPrice int64
@@ -95,10 +95,6 @@ func (p jyBigProduct) GetPrice() (price int64, err error) {
 			return 0, fmt.Errorf("查询关联订单异常")
 			return 0, fmt.Errorf("查询关联订单异常")
 		}
 		}
 
 
-		//filter, _, _, err := common2.GetLinkBigCycleFilter(context.Background(), p.param.LinkedOrderId)
-		//if err != nil {
-		//	return 0, err
-		//}
 		finalAccountCount := gconv.Int64(count - 1)
 		finalAccountCount := gconv.Int64(count - 1)
 		if gconv.String(re.Map()["code"]) != "dyh001" {
 		if gconv.String(re.Map()["code"]) != "dyh001" {
 			//套餐
 			//套餐
@@ -145,6 +141,10 @@ func (p jyBigProduct) GetPrice() (price int64, err error) {
 			}*/
 			}*/
 			price += thisPriceSetting.UnityPrice(gconv.Float64(p.param.Filter.BuyCycle+p.param.Filter.GiftCycle), cycleType, gconv.Int(finalAccountCount), 0, p.param.ReqSubject == 2)
 			price += thisPriceSetting.UnityPrice(gconv.Float64(p.param.Filter.BuyCycle+p.param.Filter.GiftCycle), cycleType, gconv.Int(finalAccountCount), 0, p.param.ReqSubject == 2)
 		} else { //自定义
 		} else { //自定义
+			filter, _, _, err := common2.GetLinkBigCycleFilter(context.Background(), p.param.LinkedOrderId)
+			if err != nil {
+				return 0, err
+			}
 			//获取各个服务
 			//获取各个服务
 			/*var (
 			/*var (
 				diyPrice, specialPrice int64
 				diyPrice, specialPrice int64
@@ -167,7 +167,7 @@ func (p jyBigProduct) GetPrice() (price int64, err error) {
 				}
 				}
 			}
 			}
 			price = thisPriceSetting.UnityPrice(p.param.Filter.BuyCycle+p.param.Filter.GiftCycle, cycleType, gconv.Int(finalAccountCount), gconv.Int(diyPrice), p.param.ReqSubject == 2) + specialPrice*/
 			price = thisPriceSetting.UnityPrice(p.param.Filter.BuyCycle+p.param.Filter.GiftCycle, cycleType, gconv.Int(finalAccountCount), gconv.Int(diyPrice), p.param.ReqSubject == 2) + specialPrice*/
-			price = DiyBigMember(context.Background(), 3, gconv.Int(finalAccountCount+1), utility.GetMonthNum(p.param.Filter.BuyCycle+p.param.Filter.GiftCycle, cycleType), p.param.UserId, p.param.Filter.ServiceIds, p.param.ReqSubject == 2)
+			price = DiyBigMember(context.Background(), 3, gconv.Int(finalAccountCount+1), utility.GetMonthNum(p.param.Filter.BuyCycle+p.param.Filter.GiftCycle, cycleType), filter.ServiceIds, p.param.Filter.ServiceIds, p.param.ReqSubject == 2)
 		}
 		}
 
 
 	case 3: //升级
 	case 3: //升级
@@ -176,7 +176,7 @@ func (p jyBigProduct) GetPrice() (price int64, err error) {
 		//if err != nil {
 		//if err != nil {
 		//	return 0, fmt.Errorf("查询关联订单异常")
 		//	return 0, fmt.Errorf("查询关联订单异常")
 		//}
 		//}
-		_, _, entTime, err := common2.GetLinkBigCycleFilter(context.Background(), p.param.LinkedOrderId)
+		filter, _, entTime, err := common2.GetLinkBigCycleFilter(context.Background(), p.param.LinkedOrderId)
 		if err != nil {
 		if err != nil {
 			return 0, fmt.Errorf("查询关联订单异常")
 			return 0, fmt.Errorf("查询关联订单异常")
 		}
 		}
@@ -190,7 +190,7 @@ func (p jyBigProduct) GetPrice() (price int64, err error) {
 		if p.param.ProductCode != "dyh001" { //升级子账号
 		if p.param.ProductCode != "dyh001" { //升级子账号
 			price = thisPriceSetting.UnityPrice(gconv.Float64(utility.GetMonthDayNum(time.Now(), entTime)), 2, gconv.Int(finalAccountCount), 0, p.param.ReqSubject == 2, "1")
 			price = thisPriceSetting.UnityPrice(gconv.Float64(utility.GetMonthDayNum(time.Now(), entTime)), 2, gconv.Int(finalAccountCount), 0, p.param.ReqSubject == 2, "1")
 		} else { //补充服务和升级子账号
 		} else { //补充服务和升级子账号
-			price = DiyBigMember(context.Background(), 2, gconv.Int(finalAccountCount), utility.GetMonthNumTime(time.Now(), entTime), p.param.UserId, p.param.Filter.SupServiceIds, p.param.ReqSubject == 2)
+			price = DiyBigMember(context.Background(), 2, gconv.Int(finalAccountCount), utility.GetMonthNumTime(time.Now(), entTime), filter.ServiceIds, p.param.Filter.SupServiceIds, p.param.ReqSubject == 2)
 		}
 		}
 
 
 		/*mNum, day := utility.GetMonthDayNum(time.Now(), entTime)
 		/*mNum, day := utility.GetMonthDayNum(time.Now(), entTime)
@@ -262,7 +262,7 @@ func GetMonthDisc(monthCount int) float64 {
 	return monthDiscount * gconv.Float64(monthCount)
 	return monthDiscount * gconv.Float64(monthCount)
 }
 }
 
 
-func DiyBigMember(ctx context.Context, createType, count int, month int, userId string, serversId []string, isEnt bool) int64 {
+func DiyBigMember(ctx context.Context, createType, count int, month int, serversId, supServersId []string, isEnt bool) int64 {
 	var (
 	var (
 		price                                           float64
 		price                                           float64
 		subAccountPrice, packPrice, primaryAccountPrice int
 		subAccountPrice, packPrice, primaryAccountPrice int
@@ -280,41 +280,43 @@ func DiyBigMember(ctx context.Context, createType, count int, month int, userId
 	idArr := map[int]bool{}
 	idArr := map[int]bool{}
 	var dataService int
 	var dataService int
 	if createType == 2 {
 	if createType == 2 {
-		serOneData, _ := g.DB().GetOne(context.Background(), fmt.Sprintf(`SELECT id,i_price_year,s_new_name FROM bigmember_service WHERE i_class=4 and   id in ('%s') order by  i_price_year desc limit 1`, strings.Join(serversId, `','`)))
+		serOneData, _ := g.DB().GetOne(context.Background(), fmt.Sprintf(`SELECT id,i_price_year,s_new_name FROM bigmember_service WHERE i_class=4 and   id in ('%s') order by  i_price_year desc limit 1`, strings.Join(supServersId, `','`)))
 		if !serOneData.IsEmpty() {
 		if !serOneData.IsEmpty() {
 			dataService = gconv.Int(serOneData.Map()["i_price_year"])
 			dataService = gconv.Int(serOneData.Map()["i_price_year"])
 		}
 		}
 		//补充服务
 		//补充服务
 		//价格计算需要去掉之前购买服务
 		//价格计算需要去掉之前购买服务
-		userServer, _ := g.DB().Query(ctx, "SELECT * FROM bigmember_service_user  WHERE s_userid = ? and i_status =0", userId)
-		if !userServer.IsEmpty() {
-			isHUa, _ := g.DB().GetCount(ctx, `SELECT count(1) as count FROM bigmember_service_user WHERE s_userid = ? and i_status =0 and (s_serviceid=4 or s_serviceid =19)`, userId)
-			for _, v := range userServer.List() {
-				if isHUa > 0 && v["s_serviceid"] == 26 {
-					continue
-				}
-				if common.IntAll(v["s_smainid"]) == 0 {
-					if common.IntAll(v["s_serviceid"]) == 12 {
-						idArr[23] = true
-					} else {
-						idArr[common.IntAll(v["s_serviceid"])] = true
-					}
+		var isHUa bool
+		for _, s := range serversId {
+			if s == "4" || s == "19" {
+				isHUa = true
+			}
+		}
+		for _, v := range serversId {
+			if isHUa && v == "26" {
+				continue
+			}
+			if common.IntAll(v) == 0 {
+				if v == "12" {
+					idArr[23] = true
 				} else {
 				} else {
-					if common.IntAll(v["s_smainid"]) == 12 {
-						idArr[23] = true
-					} else {
-						idArr[common.IntAll(v["s_serviceid"])] = true
-					}
+					idArr[common.IntAll(v)] = true
 				}
 				}
-				if common.IntAll(v["s_serviceid"]) == 12 {
-					idArr[20] = true
+			} else {
+				if v == "12" {
 					idArr[23] = true
 					idArr[23] = true
+				} else {
+					idArr[common.IntAll(v)] = true
 				}
 				}
 			}
 			}
+			if v == "12" {
+				idArr[20] = true
+				idArr[23] = true
+			}
 		}
 		}
 
 
 	}
 	}
-	for _, v := range serversId {
+	for _, v := range supServersId {
 		if common.IntAll(v) == 3 || common.IntAll(v) == 13 || common.IntAll(v) == 21 {
 		if common.IntAll(v) == 3 || common.IntAll(v) == 13 || common.IntAll(v) == 21 {
 			continue
 			continue
 		}
 		}

+ 8 - 35
internal/logic/user/getService.go

@@ -93,7 +93,6 @@ WHERE %s and jod.status =1 order by dor.create_time desc`, whereSql))
 						endTime                                                             string
 						endTime                                                             string
 						orderArr                                                            []map[string]interface{}
 						orderArr                                                            []map[string]interface{}
 						serviceList                                                         []int
 						serviceList                                                         []int
-						userId                                                              = common.InterfaceToStr((*userData)["_id"])
 					)
 					)
 					startTime := common.Int64All((*userData)["i_member_starttime"])
 					startTime := common.Int64All((*userData)["i_member_starttime"])
 					bigEnd := common.Int64All((*userData)["i_member_endtime"])
 					bigEnd := common.Int64All((*userData)["i_member_endtime"])
@@ -102,17 +101,21 @@ INNER JOIN dataexport_order b on a.order_code = b.order_code
 WHERE a.status = 1  and b.user_phone = ? and b.buy_subject = 1 and a.product_type like '%大会员%' ORDER BY b.create_time desc `, param.Phone)
 WHERE a.status = 1  and b.user_phone = ? and b.buy_subject = 1 and a.product_type like '%大会员%' ORDER BY b.create_time desc `, param.Phone)
 					if !orderData.IsEmpty() {
 					if !orderData.IsEmpty() {
 						for _, m2 := range orderData.List() {
 						for _, m2 := range orderData.List() {
+							var ttt model.JyBigProductFilter
+							if err := gconv.Struct(m2["filter"], &ttt); err != nil {
+								continue
+							}
 							if linkedId == 0 {
 							if linkedId == 0 {
 								linkedId = gconv.Int(m2["id"])
 								linkedId = gconv.Int(m2["id"])
+								for _, id := range ttt.ServiceIds {
+									serviceList = append(serviceList, gconv.Int(id))
+								}
 							}
 							}
 							serviceStarttime := gconv.String(m2["service_starttime"])
 							serviceStarttime := gconv.String(m2["service_starttime"])
 							serviceEndtime := gconv.String(m2["service_endtime"])
 							serviceEndtime := gconv.String(m2["service_endtime"])
 							if time.Unix(startTime, 0).Format("2006-01-02 15:04:05") <= serviceStarttime &&
 							if time.Unix(startTime, 0).Format("2006-01-02 15:04:05") <= serviceStarttime &&
 								time.Unix(bigEnd, 0).Format("2006-01-02 15:04:05") >= serviceEndtime && gconv.Int(m2["service_type"]) != 2 {
 								time.Unix(bigEnd, 0).Format("2006-01-02 15:04:05") >= serviceEndtime && gconv.Int(m2["service_type"]) != 2 {
-								var ttt model.JyBigProductFilter
-								if err := gconv.Struct(m2["filter"], &ttt); err != nil {
-									continue
-								}
+
 								gifUserCount += ttt.GiftAccountCount
 								gifUserCount += ttt.GiftAccountCount
 								payUserCount += ttt.BuyAccountCount
 								payUserCount += ttt.BuyAccountCount
 							}
 							}
@@ -141,36 +144,6 @@ WHERE a.status = 1  and b.user_phone = ? and b.buy_subject = 1 and a.product_typ
 					if (subStatus == 0 && memberStatus < 0 && mainId != "") || (subStatus == 1 && memberStatus > 0 && mainId != "") {
 					if (subStatus == 0 && memberStatus < 0 && mainId != "") || (subStatus == 1 && memberStatus > 0 && mainId != "") {
 						vipExist = true
 						vipExist = true
 					}
 					}
-					userServer, _ := g.DB().Query(ctx, fmt.Sprintf(`SELECT s_serviceid,s_smainid,l_endtime,l_starttime FROM bigmember_service_user WHERE s_userid = '%s' and i_status =0`, userId))
-					if !userServer.IsEmpty() {
-						vipExist = true
-						serMap := make(map[int]bool)
-						count, _ := g.DB().GetCount(ctx, fmt.Sprintf(`SELECT *  FROM bigmember_service_user WHERE s_userid = '%s' and i_status =0 and (s_serviceid=4 or s_serviceid =19)`, userId))
-						isHUa := count > 0
-						for _, v := range userServer.List() {
-							if isHUa && v["s_serviceid"] == 26 {
-								continue
-							}
-							var serviceId int
-							if common.IntAll(v["s_smainid"]) == 0 {
-								if common.IntAll(v["s_serviceid"]) == 12 {
-									serviceId = 23
-								} else {
-									serviceId = common.IntAll(v["s_serviceid"])
-								}
-							} else {
-								if common.IntAll(v["s_smainid"]) == 12 {
-									serviceId = 23
-								} else {
-									serviceId = common.IntAll(v["s_smainid"])
-								}
-							}
-							if !serMap[serviceId] {
-								serviceList = append(serviceList, serviceId)
-								serMap[serviceId] = true
-							}
-						}
-					}
 					if vipExist {
 					if vipExist {
 						paySubNum = common.IntAll((*userData)["i_pay_sub_num"]) + common.IntAll((*userData)["i_free_sub_num"]) + 1
 						paySubNum = common.IntAll((*userData)["i_pay_sub_num"]) + common.IntAll((*userData)["i_free_sub_num"]) + 1
 					}
 					}