initInfo.go 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. package service
  2. import (
  3. . "bp.jydev.jianyu360.cn/CRM/networkManage/api/common"
  4. "encoding/json"
  5. "github.com/gogf/gf/v2/util/gconv"
  6. "log"
  7. )
  8. type InitInfoService struct {
  9. PositionType int64
  10. MgoUserId string
  11. EntId int64
  12. NewUserId int64
  13. AccountId int64
  14. PositionId int64
  15. EntUserId int64
  16. }
  17. func (t *InitInfoService) UpdateInitInfo(company, business string) bool {
  18. fool := false
  19. if t.PositionType == 1 {
  20. //企业
  21. userInfo := Middleground.PowerCheckCenter.Check("10000", t.MgoUserId, t.NewUserId, gconv.Int64(t.AccountId), t.EntId, t.PositionType, gconv.Int64(t.PositionId))
  22. fool = Mgo.Update("ent_user", map[string]interface{}{
  23. "i_entid": t.EntId,
  24. "i_userid": t.EntUserId,
  25. }, map[string]interface{}{
  26. "$set": map[string]interface{}{
  27. "is_init": true,
  28. },
  29. }, false, false)
  30. if userInfo.Ent.EntRoleId == 1 {
  31. //企业管理员
  32. info, _ := json.Marshal(map[string]interface{}{
  33. "company": company,
  34. "business": business,
  35. })
  36. fool = JianyuMysql.Update("entniche_info", map[string]interface{}{
  37. "id": t.EntId,
  38. }, map[string]interface{}{
  39. "identityInfo": string(info),
  40. })
  41. }
  42. } else {
  43. fool = Mgo.UpdateById("user", t.MgoUserId, map[string]interface{}{
  44. "$set": map[string]interface{}{
  45. "identity_info.is_init": true,
  46. "identity_info.ent_businessType": business,
  47. "s_company": company,
  48. },
  49. })
  50. }
  51. return fool
  52. }
  53. func (t *InitInfoService) FindInitInfo() map[string]interface{} {
  54. returnJson := map[string]interface{}{}
  55. if t.PositionType == 1 {
  56. isInit := false
  57. userInfo := Middleground.PowerCheckCenter.Check("10000", t.MgoUserId, t.NewUserId, gconv.Int64(t.AccountId), t.EntId, t.PositionType, gconv.Int64(t.PositionId))
  58. entUserInfo, _ := Mgo.FindOne("ent_user", map[string]interface{}{"i_entid": t.EntId, "i_userid": t.EntUserId})
  59. if userInfo != nil && len(*entUserInfo) > 0 {
  60. isInit = gconv.Bool((*entUserInfo)["is_init"])
  61. returnJson["isInit"] = isInit
  62. }
  63. if isInit {
  64. entInfo := JianyuMysql.FindOne("entniche_info", map[string]interface{}{
  65. "id": t.EntId,
  66. }, "", "")
  67. if (*entInfo)["identityInfo"] != nil {
  68. entMap := gconv.Map((*entInfo)["identityInfo"])
  69. returnJson["company"] = entMap["company"]
  70. returnJson["business"] = entMap["business"]
  71. }
  72. }
  73. if userInfo.Ent.EntRoleId == 1 {
  74. //企业管理员
  75. returnJson["isUpdate"] = true
  76. if !isInit {
  77. //查询订单信息
  78. dataOrder := JianyuMysql.SelectBySql(`select company_name from dataexport_order where user_id=? and order_status=1 and product_type LIKE "%大会员%" and vip_endtime>now()`, t.PositionId)
  79. if dataOrder != nil && len(*dataOrder) > 0 {
  80. if gconv.String((*dataOrder)[0]["company_name"]) != "" {
  81. returnJson["company"] = gconv.String((*dataOrder)[0]["company_name"])
  82. }
  83. }
  84. }
  85. } else {
  86. //个人
  87. returnJson["isUpdate"] = false
  88. }
  89. //企业
  90. } else {
  91. //个人
  92. user, ok := Mgo.FindById("user", t.MgoUserId, "")
  93. log.Println("用户信息", user)
  94. if ok && user != nil && len(*user) > 0 {
  95. if _, ok1 := (*user)["identity_info"]; !ok1 {
  96. returnJson["isInit"] = false
  97. return returnJson
  98. }
  99. identityInfo := gconv.Map((*user)["identity_info"])
  100. if _, ok1 := identityInfo["is_init"]; !ok1 {
  101. returnJson["isInit"] = false
  102. return returnJson
  103. }
  104. if _, ok1 := (*user)["s_company"]; ok1 {
  105. log.Println("公司名字", (*user)["s_company"])
  106. returnJson["company"] = gconv.String((*user)["s_company"])
  107. }
  108. if !gconv.Bool(identityInfo["is_init"]) {
  109. //设置过
  110. returnJson["business"] = gconv.String(identityInfo["ent_businessType"])
  111. dataOrder := JianyuMysql.SelectBySql(`select company_name from dataexport_order where user_id=? and order_status=1 and product_type LIKE "%大会员%" and vip_endtime>now()`, t.MgoUserId)
  112. if dataOrder != nil && len(*dataOrder) > 0 {
  113. returnJson["company"] = gconv.String((*dataOrder)[0]["company_name"])
  114. }
  115. }
  116. }
  117. returnJson["isInit"] = true
  118. returnJson["isUpdate"] = true
  119. }
  120. return returnJson
  121. }