bigmember.go 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. package product
  2. import (
  3. "context"
  4. "fmt"
  5. "github.com/gogf/gf/v2/frame/g"
  6. "github.com/gogf/gf/v2/util/gconv"
  7. "strings"
  8. )
  9. type (
  10. JyBigProductFilter struct {
  11. ComboId int `json:"comboId"`
  12. BuyAccountCount int `json:"buyAccountCount"` //购买数量
  13. GiftAccountCount int `json:"giftAccountCount"` //赠送数量
  14. FreeAccountCount int `json:"freeAccountCount"` //免费数量
  15. Count int `json:"count"` //招投标次数免费数量
  16. BuyCycle int `json:"buy_cycle"` //购买周期
  17. BuyType int `json:"buy_type"` //购买周期 类型 1天 2月 3年 4季度
  18. GiftCycle int `json:"give_cycle"` //赠送周期
  19. GiftType int `json:"give_type"` //赠送周期 类型 1天 2月 3年 4季度
  20. ServiceIds []string `json:"serviceIds"` //服务id
  21. SupServiceIds []string `json:"supServiceIds"`
  22. FinalAccountCount int `json:"finalAccountCount"` //当前套餐最终
  23. FinalAreaCount int `json:"finalAreaCount"`
  24. }
  25. )
  26. func GetBigFilter(data map[string]interface{}) (g.Map, string, error) {
  27. var (
  28. bigFilter g.Map
  29. bigCode string
  30. )
  31. filter := gconv.Map(data["filter"])
  32. if filter["comboId"] != nil {
  33. bigFilter["comboId"] = gconv.Int(filter["comboId"])
  34. } else {
  35. //1:专业版;2:智慧版;3:商机版;4:试用版 5:试用版 6:商机版2.0 7:专家版2.0 30190:商机版2.0(单省版)
  36. bigFilter["comboId"] = gconv.Int(filter["level"])
  37. }
  38. switch bigFilter["comboId"] {
  39. case 0:
  40. bigCode = "dyh001"
  41. case 6:
  42. bigCode = "dyh002"
  43. case 7:
  44. bigCode = "dyh003"
  45. case 30190:
  46. bigCode = "dyh004"
  47. }
  48. ctx := context.Background()
  49. bigFilter["finalAreaCount"] = -1
  50. if gconv.Int(filter["areaCount"]) > 0 {
  51. bigFilter["finalAreaCount"] = gconv.Int(filter["areaCount"])
  52. }
  53. switch gconv.String(data["product_type"]) {
  54. case "大会员", "大会员-子账号":
  55. bigFilter["buy_cycle"] = gconv.Int(filter["cycle"])
  56. if gconv.Int(filter["level"]) == 4 || gconv.Int(filter["cycleType"]) == 1 {
  57. bigFilter["buy_type"] = 1
  58. } else if gconv.Int(filter["cycleType"]) == 0 {
  59. bigFilter["buy_type"] = 2
  60. } else {
  61. bigFilter["buy_type"] = 3
  62. }
  63. bigFilter["buyAccountCount"] = gconv.Int(data["buy_count"]) //购买账号数
  64. if gconv.Int(filter["pay_sub_num"]) > 0 { //老订单购买的付费账号
  65. bigFilter["buyAccountCount"] = gconv.Int(bigFilter["buyAccountCount"]) + gconv.Int(filter["pay_sub_num"])
  66. }
  67. bigFilter["freeAccountCount"] = gconv.Int(filter["free_sub_num"])
  68. bigFilter["finalAccountCount"] = gconv.Int(bigFilter["buyAccountCount"]) + gconv.Int(bigFilter["freeAccountCount"])
  69. switch gconv.Int(filter["createType"]) {
  70. case 2:
  71. if supServiceId := gconv.String(filter["new_serverArr"]); supServiceId != "" {
  72. bigFilter["supServiceIds"] = strings.Split(supServiceId, ",")
  73. bigFilter["serviceIds"] = strings.Split(gconv.String(filter["serversId"]), ",")
  74. } else {
  75. bigFilter["supServiceIds"] = strings.Split(gconv.String(filter["serversId"]), ",")
  76. ids, _ := g.DB().Ctx(ctx).GetOne(ctx, fmt.Sprintf(`SELECT ROUP_CONCAT(DISTINCT s_serviceid ORDER BY s_serviceid SEPARATOR ',') AS concatenated_ids FROM bigmember_service_user WHERE s_userid ='%s'`, gconv.String(data["user_id"])))
  77. if !ids.IsEmpty() {
  78. bigFilter["serviceIds"] = strings.Split(gconv.String(ids.Map()["concatenated_ids"]), ",")
  79. }
  80. }
  81. }
  82. case "大会员-AI中标预测包", "大会员-招标文件解读":
  83. bigFilter["buyAccountCount"] = gconv.Int(filter["count"])
  84. case "大会员-补充包": //补充服务为原有服务 增加份数
  85. bigFilter["serviceIds"] = strings.Split(gconv.String(filter["serversId"]), ",")
  86. var supIds []string
  87. for _, m := range gconv.Maps(filter["supplys"]) { //补充服务id
  88. supIds = append(supIds, gconv.String(m["id"]))
  89. }
  90. bigFilter["supServiceIds"] = supIds
  91. }
  92. return bigFilter, bigCode, nil
  93. }