bigmember.go 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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. DataPackNum int `json:"dataPackNum"` //赠送的数据流量包
  25. }
  26. )
  27. func GetBigFilter(data map[string]interface{}) (g.Map, string, int, error) {
  28. var (
  29. bigFilter = make(g.Map)
  30. bigCode string
  31. recordPayType int
  32. )
  33. filter := gconv.Map(data["filter"])
  34. if vs, ok := filter["recordPayType"]; ok && vs != nil {
  35. recordPayType = gconv.Int(filter["recordPayType"])
  36. } else {
  37. if gconv.Int(filter["createType"]) == 2 {
  38. recordPayType = 3
  39. } else if gconv.Int(filter["createType"]) == 3 {
  40. recordPayType = 1
  41. } else {
  42. recordPayType = gconv.Int(filter["createType"])
  43. }
  44. }
  45. if filter["comboId"] != nil {
  46. bigFilter["comboId"] = gconv.Int(filter["comboId"])
  47. } else {
  48. //1:专业版;2:智慧版;3:商机版;4:试用版 5:试用版 6:商机版2.0 7:专家版2.0 30190:商机版2.0(单省版)
  49. bigFilter["comboId"] = gconv.Int(filter["level"])
  50. }
  51. switch bigFilter["comboId"] {
  52. case 0:
  53. bigCode = "dyh001"
  54. case 6:
  55. bigCode = "dyh002"
  56. case 7:
  57. bigCode = "dyh003"
  58. }
  59. bigFilter["dataPackNum"] = gconv.Int(filter["dataPackNum"])
  60. ctx := context.Background()
  61. bigFilter["finalAreaCount"] = -1
  62. if gconv.Int(filter["areaCount"]) > 0 {
  63. bigFilter["finalAreaCount"] = gconv.Int(filter["areaCount"])
  64. }
  65. if gconv.Int(filter["areaCount"]) == 1 && gconv.Int(filter["comboId"]) == 6 {
  66. bigCode = "dyh004"
  67. }
  68. bigFilter["serviceIds"] = strings.Split(gconv.String(filter["serversId"]), ",")
  69. switch gconv.String(data["product_type"]) {
  70. case "大会员", "大会员-子账号":
  71. bigFilter["buy_cycle"] = gconv.Int(filter["cycle"])
  72. if gconv.Int(filter["level"]) == 4 || gconv.Int(filter["cycleType"]) == 1 {
  73. bigFilter["buy_type"] = 1
  74. } else if gconv.Int(filter["cycleType"]) == 0 {
  75. bigFilter["buy_type"] = 2
  76. } else {
  77. bigFilter["buy_type"] = 3
  78. }
  79. bigFilter["buyAccountCount"] = gconv.Int(data["buy_count"]) //购买账号数
  80. if gconv.Int(filter["pay_sub_num"]) > 0 { //老订单购买的付费账号
  81. bigFilter["buyAccountCount"] = gconv.Int(bigFilter["buyAccountCount"]) + gconv.Int(filter["pay_sub_num"])
  82. }
  83. bigFilter["freeAccountCount"] = gconv.Int(filter["free_sub_num"])
  84. bigFilter["finalAccountCount"] = gconv.Int(bigFilter["buyAccountCount"]) + gconv.Int(bigFilter["freeAccountCount"])
  85. switch gconv.Int(filter["createType"]) {
  86. case 2:
  87. if supServiceId := gconv.String(filter["new_serverArr"]); supServiceId != "" {
  88. bigFilter["supServiceIds"] = strings.Split(supServiceId, ",")
  89. bigFilter["serviceIds"] = strings.Split(gconv.String(filter["serversId"]), ",")
  90. } else {
  91. bigFilter["supServiceIds"] = strings.Split(gconv.String(filter["serversId"]), ",")
  92. 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"])))
  93. if !ids.IsEmpty() {
  94. bigFilter["serviceIds"] = strings.Split(gconv.String(ids.Map()["concatenated_ids"]), ",")
  95. }
  96. }
  97. }
  98. case "大会员-AI中标预测包", "大会员-招标文件解读":
  99. bigFilter["buyAccountCount"] = gconv.Int(filter["count"])
  100. case "大会员-补充包": //补充服务为原有服务 增加份数
  101. bigFilter["serviceIds"] = strings.Split(gconv.String(filter["serversId"]), ",")
  102. var supIds []string
  103. for _, m := range gconv.Maps(filter["supplys"]) { //补充服务id
  104. supIds = append(supIds, gconv.String(m["id"]))
  105. }
  106. bigFilter["supServiceIds"] = supIds
  107. }
  108. return bigFilter, bigCode, recordPayType, nil
  109. }
  110. func OrderSeal() error {
  111. res, err := g.DB().Query(context.Background(), `SELECT * FROM order_seal `)
  112. if err != nil {
  113. return err
  114. }
  115. for _, i2 := range res.List() {
  116. var (
  117. applicant_id []string
  118. salesman_id string
  119. )
  120. res1, _ := g.DB().Query(context.Background(), fmt.Sprintf(`SELECT phone FROM cadmin.admin_user where id in (%s) `, gconv.String(i2["applicant_id"])))
  121. if !res1.IsEmpty() {
  122. for _, m := range res1.List() {
  123. res11, _ := g.DB().GetOne(context.Background(), `SELECT id FROM entniche_user where ent_id=25917 and phone =? `, m["phone"])
  124. if !res11.IsEmpty() {
  125. applicant_id = append(applicant_id, gconv.String(res11.Map()["id"]))
  126. }
  127. }
  128. }
  129. res2, _ := g.DB().GetOne(context.Background(), `SELECT phone FROM cadmin.admin_user where id =? `, i2["salesman_id"])
  130. if !res1.IsEmpty() {
  131. res22, _ := g.DB().GetOne(context.Background(), `SELECT id FROM entniche_user where ent_id=25917 and phone =? `, res2.Map()["phone"])
  132. if !res22.IsEmpty() {
  133. salesman_id = gconv.String(res22.Map()["id"])
  134. }
  135. }
  136. g.DB().Update(context.Background(), "order_seal", map[string]interface{}{
  137. "applicant_id": strings.Join(applicant_id, ","),
  138. "salesman_id": salesman_id,
  139. }, map[string]interface{}{
  140. "id": i2["id"],
  141. })
  142. }
  143. return nil
  144. }