initInfo.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. "identity_info": 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. "business": "",
  56. "company": "",
  57. "isInit": false,
  58. "isUpdate": false,
  59. }
  60. if t.PositionType == 1 {
  61. isInit := false
  62. userInfo := Middleground.PowerCheckCenter.Check("10000", t.MgoUserId, t.NewUserId, gconv.Int64(t.AccountId), t.EntId, t.PositionType, gconv.Int64(t.PositionId))
  63. entUserInfo, _ := Mgo.FindOne("ent_user", map[string]interface{}{"i_entid": t.EntId, "i_userid": t.EntUserId})
  64. if userInfo != nil && len(*entUserInfo) > 0 {
  65. isInit = gconv.Bool((*entUserInfo)["is_init"])
  66. returnJson["isInit"] = isInit
  67. }
  68. if isInit {
  69. entInfo := JianyuMysql.FindOne("entniche_info", map[string]interface{}{
  70. "id": t.EntId,
  71. }, "", "")
  72. if (*entInfo)["identity_info"] != nil {
  73. entMap := gconv.Map((*entInfo)["identity_info"])
  74. returnJson["company"] = entMap["company"]
  75. returnJson["business"] = entMap["business"]
  76. }
  77. }
  78. if userInfo.Ent.EntRoleId == 1 {
  79. //企业管理员
  80. returnJson["isUpdate"] = true
  81. if !isInit {
  82. //查询订单信息
  83. 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)
  84. if dataOrder != nil && len(*dataOrder) > 0 {
  85. if gconv.String((*dataOrder)[0]["company_name"]) != "" {
  86. returnJson["company"] = gconv.String((*dataOrder)[0]["company_name"])
  87. }
  88. }
  89. }
  90. } else {
  91. //个人
  92. returnJson["isUpdate"] = false
  93. }
  94. //企业
  95. } else {
  96. //个人
  97. user, ok := Mgo.FindById("user", t.MgoUserId, "")
  98. log.Println("用户信息", user)
  99. if ok && user != nil && len(*user) > 0 {
  100. if _, ok1 := (*user)["identity_info"]; !ok1 {
  101. returnJson["isInit"] = false
  102. return returnJson
  103. }
  104. identityInfo := gconv.Map((*user)["identity_info"])
  105. if _, ok1 := identityInfo["is_init"]; !ok1 {
  106. returnJson["isInit"] = false
  107. return returnJson
  108. }
  109. if _, ok1 := (*user)["s_company"]; ok1 {
  110. log.Println("公司名字", (*user)["s_company"])
  111. returnJson["company"] = gconv.String((*user)["s_company"])
  112. }
  113. if !gconv.Bool(identityInfo["is_init"]) {
  114. //设置过
  115. returnJson["business"] = gconv.String(identityInfo["ent_businessType"])
  116. 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)
  117. if dataOrder != nil && len(*dataOrder) > 0 {
  118. returnJson["company"] = gconv.String((*dataOrder)[0]["company_name"])
  119. }
  120. }
  121. }
  122. returnJson["isInit"] = true
  123. returnJson["isUpdate"] = true
  124. }
  125. return returnJson
  126. }