Browse Source

fix:刷库更新

duxin 1 month ago
parent
commit
5d09f706f6
6 changed files with 153 additions and 29 deletions
  1. 0 2
      go.mod
  2. 0 4
      go.sum
  3. 1 1
      run/orderFlush/main.go
  4. 68 10
      run/orderFlush/product/bigmember.go
  5. 63 0
      run/orderFlush/product/init.go
  6. 21 12
      run/orderFlush/product/vip.go

+ 0 - 2
go.mod

@@ -5,7 +5,6 @@ go 1.18
 require (
 require (
 	app.yhyue.com/moapp/jybase v0.0.0-20240226084952-7e7b38ef8a66
 	app.yhyue.com/moapp/jybase v0.0.0-20240226084952-7e7b38ef8a66
 	github.com/PuerkitoBio/goquery v1.9.1
 	github.com/PuerkitoBio/goquery v1.9.1
-	github.com/aliyun/aliyun-oss-go-sdk v3.0.2+incompatible
 	github.com/go-sql-driver/mysql v1.7.1
 	github.com/go-sql-driver/mysql v1.7.1
 	github.com/gogf/gf/contrib/drivers/clickhouse/v2 v2.6.3
 	github.com/gogf/gf/contrib/drivers/clickhouse/v2 v2.6.3
 	github.com/gogf/gf/contrib/drivers/mysql/v2 v2.6.4
 	github.com/gogf/gf/contrib/drivers/mysql/v2 v2.6.4
@@ -59,7 +58,6 @@ require (
 	golang.org/x/sync v0.1.0 // indirect
 	golang.org/x/sync v0.1.0 // indirect
 	golang.org/x/sys v0.17.0 // indirect
 	golang.org/x/sys v0.17.0 // indirect
 	golang.org/x/text v0.14.0 // indirect
 	golang.org/x/text v0.14.0 // indirect
-	golang.org/x/time v0.8.0 // indirect
 	gopkg.in/yaml.v3 v3.0.1 // indirect
 	gopkg.in/yaml.v3 v3.0.1 // indirect
 	gorm.io/driver/mysql v1.0.5 // indirect
 	gorm.io/driver/mysql v1.0.5 // indirect
 	gorm.io/gorm v1.21.3 // indirect
 	gorm.io/gorm v1.21.3 // indirect

+ 0 - 4
go.sum

@@ -19,8 +19,6 @@ github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuy
 github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
 github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
 github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
 github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
 github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho=
 github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho=
-github.com/aliyun/aliyun-oss-go-sdk v3.0.2+incompatible h1:8psS8a+wKfiLt1iVDX79F7Y6wUM49Lcha2FMXt4UM8g=
-github.com/aliyun/aliyun-oss-go-sdk v3.0.2+incompatible/go.mod h1:T/Aws4fEfogEE9v+HPhhw+CntffsBHJ8nXQCwKr0/g8=
 github.com/andybalholm/cascadia v1.3.2 h1:3Xi6Dw5lHF15JtdcmAHD3i1+T8plmv7BQ/nsViSLyss=
 github.com/andybalholm/cascadia v1.3.2 h1:3Xi6Dw5lHF15JtdcmAHD3i1+T8plmv7BQ/nsViSLyss=
 github.com/andybalholm/cascadia v1.3.2/go.mod h1:7gtRlve5FxPPgIgX36uWBX58OdBsSS6lUvCFb+h7KvU=
 github.com/andybalholm/cascadia v1.3.2/go.mod h1:7gtRlve5FxPPgIgX36uWBX58OdBsSS6lUvCFb+h7KvU=
 github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
 github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
@@ -414,8 +412,6 @@ golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
 golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
 golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
 golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
 golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
 golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
 golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
-golang.org/x/time v0.8.0 h1:9i3RxcPv3PZnitoVGMPDKZSq1xW1gK1Xy3ArNOGZfEg=
-golang.org/x/time v0.8.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
 golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
 golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
 golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
 golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
 golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
 golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=

+ 1 - 1
run/orderFlush/main.go

@@ -83,7 +83,7 @@ func FlushOrder(ctx context.Context) error {
 
 
 		switch productType {
 		switch productType {
 		case "VIP订阅":
 		case "VIP订阅":
-			newFilterMap, product_code, err = product.GetVipFilter(filter, buy_count, buy_subject)
+			newFilterMap, product_code, err = product.GetVipFilter(filter, buy_count, buy_subject, m)
 			if err != nil {
 			if err != nil {
 				g.Log().Error(ctx, "格式化超级订阅订单%s 异常%v", orderCode, err.Error())
 				g.Log().Error(ctx, "格式化超级订阅订单%s 异常%v", orderCode, err.Error())
 			}
 			}

+ 68 - 10
run/orderFlush/product/bigmember.go

@@ -1,11 +1,13 @@
 package product
 package product
 
 
 import (
 import (
+	"app.yhyue.com/moapp/jybase/common"
 	"context"
 	"context"
 	"fmt"
 	"fmt"
 	"github.com/gogf/gf/v2/frame/g"
 	"github.com/gogf/gf/v2/frame/g"
 	"github.com/gogf/gf/v2/util/gconv"
 	"github.com/gogf/gf/v2/util/gconv"
 	"strings"
 	"strings"
+	"time"
 )
 )
 
 
 type (
 type (
@@ -41,11 +43,11 @@ func GetBigFilter(data map[string]interface{}) (g.Map, string, int, error) {
 	if vs, ok := filter["recordPayType"]; ok && vs != nil {
 	if vs, ok := filter["recordPayType"]; ok && vs != nil {
 		recordPayType = gconv.Int(filter["recordPayType"])
 		recordPayType = gconv.Int(filter["recordPayType"])
 	} else {
 	} else {
-		if gconv.Int(filter["createType"]) == 2 {
+		if gconv.Int(filter["createType"]) == 2 { //升级
 			recordPayType = 3
 			recordPayType = 3
-		} else if gconv.Int(filter["createType"]) == 3 {
+		} else if gconv.Int(filter["createType"]) == 3 { //续费
 			recordPayType = 1
 			recordPayType = 1
-		} else {
+		} else { //购买
 			recordPayType = gconv.Int(filter["createType"])
 			recordPayType = gconv.Int(filter["createType"])
 		}
 		}
 	}
 	}
@@ -76,6 +78,14 @@ func GetBigFilter(data map[string]interface{}) (g.Map, string, int, error) {
 	bigFilter["serviceIds"] = strings.Split(gconv.String(filter["serversId"]), ",")
 	bigFilter["serviceIds"] = strings.Split(gconv.String(filter["serversId"]), ",")
 	switch gconv.String(data["product_type"]) {
 	switch gconv.String(data["product_type"]) {
 	case "大会员", "大会员-子账号":
 	case "大会员", "大会员-子账号":
+		var (
+			finalAccountCount int64
+		)
+		if gconv.Int(data["buy_subject"]) == 2 {
+			finalAccountCount, _, _, _ = entUserCountAndTime(gconv.Int64(data["id"]))
+		} else if gconv.Int(data["buy_subject"]) == 1 {
+			finalAccountCount, _, _ = userCountAndTime(gconv.String(data["user_id"]))
+		}
 		bigFilter["buy_cycle"] = gconv.Int(filter["cycle"])
 		bigFilter["buy_cycle"] = gconv.Int(filter["cycle"])
 		if gconv.Int(filter["level"]) == 4 || gconv.Int(filter["cycleType"]) == 1 {
 		if gconv.Int(filter["level"]) == 4 || gconv.Int(filter["cycleType"]) == 1 {
 			bigFilter["buy_type"] = 1
 			bigFilter["buy_type"] = 1
@@ -84,21 +94,44 @@ func GetBigFilter(data map[string]interface{}) (g.Map, string, int, error) {
 		} else {
 		} else {
 			bigFilter["buy_type"] = 3
 			bigFilter["buy_type"] = 3
 		}
 		}
-		bigFilter["buyAccountCount"] = gconv.Int(data["buy_count"]) //购买账号数
-		if gconv.Int(filter["pay_sub_num"]) > 0 {                   //老订单购买的付费账号
-			bigFilter["buyAccountCount"] = gconv.Int(bigFilter["buyAccountCount"]) + gconv.Int(filter["pay_sub_num"])
+		if finalAccountCount == 0 {
+			bigFilter["buyAccountCount"] = gconv.Int(data["buy_count"]) //购买账号数
+			if gconv.Int(filter["pay_sub_num"]) > 0 {                   //老订单购买的付费账号
+				bigFilter["buyAccountCount"] = gconv.Int(bigFilter["buyAccountCount"]) + gconv.Int(filter["pay_sub_num"])
+			}
+			bigFilter["freeAccountCount"] = gconv.Int(filter["free_sub_num"])
+			finalAccountCount = gconv.Int64(bigFilter["buyAccountCount"]) + gconv.Int64(bigFilter["freeAccountCount"])
 		}
 		}
-		bigFilter["freeAccountCount"] = gconv.Int(filter["free_sub_num"])
-		bigFilter["finalAccountCount"] = gconv.Int(bigFilter["buyAccountCount"]) + gconv.Int(bigFilter["freeAccountCount"])
+
+		bigFilter["finalAccountCount"] = finalAccountCount
 
 
 		switch gconv.Int(filter["createType"]) {
 		switch gconv.Int(filter["createType"]) {
 		case 2:
 		case 2:
+			if oldSerName := gconv.String(filter["oldSerName"]); oldSerName != "" {
+				bigFilter["oldServiceListName"] = oldSerName
+			}
 			if supServiceId := gconv.String(filter["new_serverArr"]); supServiceId != "" {
 			if supServiceId := gconv.String(filter["new_serverArr"]); supServiceId != "" {
+				serverDataArr, _ := g.DB().Query(ctx, `SELECT id, CASE
+    WHEN id = 1 THEN "基础服务"
+    ELSE s_new_name
+  END AS s_new_name FROM bigmember_service WHERE id in (%s)`, gconv.String(filter["serversId"]))
+				if !serverDataArr.IsEmpty() {
+					var newSerName []string
+					for _, m2 := range serverDataArr.List() {
+						for _, s := range strings.Split(gconv.String(supServiceId), ",") {
+							if common.InterfaceToStr(m2["id"]) == s {
+								newSerName = append(newSerName, common.InterfaceToStr(m2["s_new_name"]))
+								break
+							}
+						}
+					}
+					bigFilter["supServiceListName"] = strings.Join(newSerName, ",")
+				}
 				bigFilter["supServiceIds"] = strings.Split(supServiceId, ",")
 				bigFilter["supServiceIds"] = strings.Split(supServiceId, ",")
 				bigFilter["serviceIds"] = strings.Split(gconv.String(filter["serversId"]), ",")
 				bigFilter["serviceIds"] = strings.Split(gconv.String(filter["serversId"]), ",")
 			} else {
 			} else {
 				bigFilter["supServiceIds"] = strings.Split(gconv.String(filter["serversId"]), ",")
 				bigFilter["supServiceIds"] = strings.Split(gconv.String(filter["serversId"]), ",")
-				ids, _ := g.DB().Ctx(ctx).GetOne(ctx, fmt.Sprintf(`SELECT GROUP_CONCAT(DISTINCT s_serviceid SEPARATOR ',') AS concatenated_ids FROM bigmember_service_user WHERE s_userid ='%s'`, gconv.String(data["user_id"])))
+				ids, _ := g.DB().Ctx(ctx).GetOne(ctx, fmt.Sprintf(`SELECT GROUP_CONCAT(DISTINCT s_serviceid SEPARATOR ',') AS concatenated_ids FROM bigmember_service_user WHERE s_userid ='%s' and i_status in (0,1)`, gconv.String(data["user_id"])))
 				if !ids.IsEmpty() {
 				if !ids.IsEmpty() {
 					bigFilter["serviceIds"] = strings.Split(gconv.String(ids.Map()["concatenated_ids"]), ",")
 					bigFilter["serviceIds"] = strings.Split(gconv.String(ids.Map()["concatenated_ids"]), ",")
 				}
 				}
@@ -135,7 +168,6 @@ func OrderSeal() error {
 					applicant_id = append(applicant_id, gconv.String(res11.Map()["id"]))
 					applicant_id = append(applicant_id, gconv.String(res11.Map()["id"]))
 				}
 				}
 			}
 			}
-
 		}
 		}
 		res2, _ := g.DB().GetOne(context.Background(), `SELECT phone FROM cadmin.admin_user where id =? `, i2["salesman_id"])
 		res2, _ := g.DB().GetOne(context.Background(), `SELECT phone FROM cadmin.admin_user where id =? `, i2["salesman_id"])
 		if !res1.IsEmpty() {
 		if !res1.IsEmpty() {
@@ -153,3 +185,29 @@ func OrderSeal() error {
 	}
 	}
 	return nil
 	return nil
 }
 }
+
+func userCountAndTime(userId string) (userCount int64, sTime, eTime string) {
+	data, _ := MG.DB().FindById("user", userId, "")
+	if data != nil && len(*data) > 0 {
+		userCount = gconv.Int64((*data)["i_free_sub_num"]) + gconv.Int64((*data)["i_pay_sub_num"])
+		if gconv.Int64((*data)["i_member_endtime"]) < time.Now().Unix() || gconv.Int64((*data)["i_member_status"]) < 0 {
+			return
+		}
+		eTime = time.Unix(gconv.Int64((*data)["i_member_endtime"]), 0).Format("2006-01-02 15:04:05")
+		sTime = time.Unix(gconv.Int64((*data)["i_member_starttime"]), 0).Format("2006-01-02 15:04:05")
+	}
+	return
+}
+
+func entUserCountAndTime(orderId int64) (userCount, areaCount int64, sTime, eTime string) {
+	data, _ := g.DB().GetOne(context.Background(), `SELECT * FROM entniche_wait_empower ewe
+INNER JOIN entniche_order eo on ewe.id = eo.wait_empower_id
+WHERE eo.order_id = ?`, orderId)
+	if !data.IsEmpty() {
+		userCount = gconv.Int64(data.Map()["empower_count"])
+		areaCount = gconv.Int64(data.Map()["province_count"])
+		sTime = gconv.String(data.Map()["start_time"])
+		eTime = gconv.String(data.Map()["end_time"])
+	}
+	return
+}

+ 63 - 0
run/orderFlush/product/init.go

@@ -0,0 +1,63 @@
+package product
+
+import (
+	"app.yhyue.com/moapp/jybase/mongodb"
+	"context"
+	"github.com/gogf/gf/v2/frame/g"
+	"github.com/gogf/gf/v2/util/gconv"
+)
+
+type (
+	mgConf struct {
+		Address  string `json:"address"`
+		Size     int    `json:"size"`
+		DbName   string `json:"dbName"`
+		ReplSet  string `json:"replSet"`
+		UserName string `json:"userName"`
+		Password string `json:"password"`
+	}
+	mgObj struct {
+		mgMap map[string]*mongodb.MongodbSim
+	}
+)
+
+var (
+	MG = &mgObj{
+		mgMap: map[string]*mongodb.MongodbSim{},
+	}
+)
+
+func init() {
+	var (
+		ctx = context.Background()
+	)
+	for key, val := range g.Cfg().MustGet(ctx, "mongodb").Map() {
+		var cf mgConf
+		if err := gconv.Struct(val, &cf); err != nil {
+			g.Log().Errorf(ctx, "初始化mongodb %s出错", key)
+			continue
+		}
+		mgo := &mongodb.MongodbSim{
+			MongodbAddr: cf.Address,
+			Size:        cf.Size,
+			DbName:      cf.DbName,
+			ReplSet:     cf.ReplSet,
+			UserName:    cf.UserName,
+			Password:    cf.Password,
+		}
+		mgo.InitPool()
+		MG.mgMap[key] = mgo
+		g.Log().Infof(ctx, "初始化 mongodb %s 成功", key)
+	}
+}
+
+func (t *mgObj) DB(alias ...string) *mongodb.MongodbSim {
+	if len(alias) != 0 {
+		for _, s := range alias {
+			if esObj, ok := t.mgMap[s]; ok {
+				return esObj
+			}
+		}
+	}
+	return t.mgMap["default"]
+}

+ 21 - 12
run/orderFlush/product/vip.go

@@ -84,19 +84,19 @@ func getVipProductCode(areaCount int) string {
 	return "cjdy016"
 	return "cjdy016"
 }
 }
 
 
-func GetVipFilter(filter string, buy_count, buy_subject int) (g.Map, string, error) {
+func GetVipFilter(filter string, buy_count, buy_subject int, m map[string]interface{}) (g.Map, string, error) {
 	var f VipSimpleMsg
 	var f VipSimpleMsg
 	if err := gconv.Struct(filter, &f); err != nil {
 	if err := gconv.Struct(filter, &f); err != nil {
 		return nil, "", err
 		return nil, "", err
 	}
 	}
 	var (
 	var (
-		t, c int
+		t, c, t1, c1 int
 	)
 	)
 	if f.SellerGiveType > 0 && f.SellerGiveCycle > 0 {
 	if f.SellerGiveType > 0 && f.SellerGiveCycle > 0 {
 		t, c = f.SellerGiveType, f.SellerGiveCycle
 		t, c = f.SellerGiveType, f.SellerGiveCycle
 	}
 	}
-	if f.GiveCycle > 0 && f.SellerGiveType > 0 {
-		t, c = f.SellerGiveType, f.GiveCycle
+	if f.GiveCycle > 0 && f.GiveType > 0 {
+		t1, c1 = f.SellerGiveType, f.GiveCycle
 	}
 	}
 
 
 	var buyCount int
 	var buyCount int
@@ -107,17 +107,26 @@ func GetVipFilter(filter string, buy_count, buy_subject int) (g.Map, string, err
 	} else {
 	} else {
 		return gconv.Map(filter), "", nil
 		return gconv.Map(filter), "", nil
 	}
 	}
+	//代用户下单 计算赠送周期
 	rData := g.Map{
 	rData := g.Map{
-		"buy_cycle":         f.Cyclecount,
-		"buy_type":          vipUnitConvert(f.Cycleunit), // 类型 1天 2月 3年 4季度
-		"finalAccountCount": 1,
-		"finalAreaCount":    buyCount,
-		"seller_give_type":  t,
-		"seller_give_cycle": c,
+		"buy_cycle":           f.Cyclecount,
+		"buy_type":            vipUnitConvert(f.Cycleunit), // 类型 1天 2月 3年 4季度
+		"finalAccountCount":   1,
+		"finalAreaCount":      buyCount,
+		"seller_give_type":    t,
+		"seller_give_cycle":   c,
+		"activity_give_type":  t1,
+		"activity_give_cycle": c1,
 	}
 	}
-
+	var finalAccountCount int64
 	if buy_subject == 2 { //企业版
 	if buy_subject == 2 { //企业版
-		rData["buyAccountCount"] = common.If(buy_count > 0, buy_count, 1)
+		rData["buyAccountCount"] = common.If(buy_count-1 > 0, buy_count-1, 0)
+		finalAccountCount, _, _, _ = entUserCountAndTime(gconv.Int64(m["id"]))
+		if finalAccountCount > 0 {
+			rData["finalAccountCount"] = finalAccountCount
+		} else {
+			rData["finalAccountCount"] = buy_count
+		}
 	}
 	}
 	return rData, getVipProductCode(buyCount), nil
 	return rData, getVipProductCode(buyCount), nil
 }
 }