newestbiddinglogic.go 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. package logic
  2. import (
  3. "context"
  4. "encoding/json"
  5. "fmt"
  6. IC "jyBXBase/rpc/init"
  7. "jyBXBase/rpc/model"
  8. "log"
  9. "sort"
  10. "strings"
  11. "time"
  12. MC "app.yhyue.com/moapp/jybase/common"
  13. "app.yhyue.com/moapp/jybase/redis"
  14. "jyBXBase/rpc/internal/svc"
  15. "jyBXBase/rpc/type/bxbase"
  16. "github.com/zeromicro/go-zero/core/logx"
  17. )
  18. type NewestBiddingLogic struct {
  19. ctx context.Context
  20. svcCtx *svc.ServiceContext
  21. logx.Logger
  22. }
  23. func NewNewestBiddingLogic(ctx context.Context, svcCtx *svc.ServiceContext) *NewestBiddingLogic {
  24. return &NewestBiddingLogic{
  25. ctx: ctx,
  26. svcCtx: svcCtx,
  27. Logger: logx.WithContext(ctx),
  28. }
  29. }
  30. // 首页最新招标信息
  31. func (l *NewestBiddingLogic) NewestBidding(in *bxbase.NewestBiddingReq) (*bxbase.NewsetBiddingResp, error) {
  32. t := time.Now()
  33. userType := ""
  34. r := func(in *bxbase.NewestBiddingReq) *bxbase.NewsetBiddingResp {
  35. var res = &bxbase.NewsetBiddingResp{
  36. Data: &bxbase.NewsetBidding{
  37. List: []*bxbase.NewestList{},
  38. },
  39. }
  40. //主体处理(fType:普通用户;vType:超级订阅用户;mType:大会员用户;eType:商机管理用户)
  41. infoCount := IC.MainMysql.CountBySql("select count(id) from entniche_wait_empower where ent_id=? and end_time>NOW() and (product_type like '%VIP订阅%' or product_type like '%大会员%') ", in.EntId)
  42. if infoCount > 0 {
  43. //主体等于企业的
  44. userType = "e"
  45. }
  46. rks := ""
  47. if userType == "e" {
  48. rks = MC.If(in.UserId != "", MC.InterfaceToStr(in.EntUserId), in.City).(string)
  49. } else {
  50. rks = MC.If(in.UserId != "", in.UserId, in.City).(string)
  51. }
  52. redisByte, err := redis.GetBytes("other", "p1_indexMessage_new_"+rks)
  53. if err == nil && redisByte != nil && len(*redisByte) > 0 {
  54. err := json.Unmarshal(*redisByte, res.Data)
  55. if err != nil {
  56. res.ErrCode = -1
  57. res.ErrMsg = fmt.Sprintf("读取缓存 序列化异常,err:%s", err.Error())
  58. }
  59. return res
  60. }
  61. //登录用户
  62. if in.UserId != "" {
  63. //优先级 由测试确认 大会员 》 商机管理 》 VIP 》 普通用户 》 搜索历史
  64. //获取订阅信息
  65. userMap, ok := IC.Mgo.FindById("user", in.UserId, `{"o_jy":1,"o_vipjy":1,"i_vip_status":1,"o_member_jy":1,"i_member_status":1,"s_m_phone":1,"s_phone":1}`)
  66. if !ok || userMap == nil || len(*userMap) == 0 {
  67. //查询出错
  68. res.ErrCode = -1
  69. res.ErrMsg = fmt.Errorf("未查询到用户信息").Error()
  70. return res
  71. }
  72. //var isPayUser bool = false
  73. //付费用户如果没有数据 直接返回 需求来源:测试
  74. //vip用户
  75. vipStatus := MC.IntAll((*userMap)["i_vip_status"])
  76. //大会员用户
  77. bigStatus := MC.Int64All((*userMap)["i_member_status"])
  78. if bigStatus > 0 {
  79. o_msgset := MC.ObjToMap((*userMap)["o_member_jy"])
  80. big_items, ok := (*o_msgset)["a_items"].([]interface{})
  81. //大会员推送历史
  82. result := []*bxbase.NewestList{}
  83. if userType == "e" {
  84. result = model.GetNewestInfo(rks, "e", MC.Int64All(in.EntUserId)).GetPushHistory()
  85. } else {
  86. result = model.GetNewestInfo(rks, "m", in.NewUserId).GetPushHistory()
  87. }
  88. res.Data.Count = int64(len(result))
  89. if res.Data.Count > 0 {
  90. res.Data.HasSubKeys = ok && len(big_items) > 0
  91. res.Data.List = result
  92. res.Data.SubFlag = "m"
  93. }
  94. return res
  95. }
  96. if phone := MC.If((*userMap)["s_phone"] != nil, MC.ObjToString((*userMap)["s_phone"]), MC.ObjToString((*userMap)["s_m_phone"])).(string); phone != "" && in.EntUserId != "" && in.EntId != "" {
  97. //商机管理
  98. entNicheInfos := IC.MainMysql.SelectBySql(`SELECT i.power_source,u.power FROM entniche_user u LEFT JOIN entniche_info i ON u.ent_id=i.id WHERE u.phone=? and i.status=1 AND i.id = ?`, phone, in.EntId)
  99. if entNicheInfos != nil && len(*entNicheInfos) > 0 {
  100. entNicheInfo := (*entNicheInfos)[0]
  101. //排除商机管理服务
  102. if MC.IntAll(entNicheInfo["power_source"]) != 1 {
  103. // 已分发权限
  104. if MC.IntAll(entNicheInfo["power"]) > 0 {
  105. //商机管理推送历史
  106. result := model.GetNewestInfo(in.EntUserId, "e", MC.Int64All(in.EntUserId)).GetPushHistory()
  107. res.Data.Count = int64(len(result))
  108. if res.Data.Count > 0 {
  109. res.Data.List = result
  110. res.Data.SubFlag = "e"
  111. }
  112. return res
  113. }
  114. }
  115. }
  116. }
  117. if vipStatus > 0 {
  118. o_msgset := MC.ObjToMap((*userMap)["o_vipjy"])
  119. vip_items, ok := (*o_msgset)["a_items"].([]interface{})
  120. //vip查询推送历史
  121. result := []*bxbase.NewestList{}
  122. if userType == "e" {
  123. result = model.GetNewestInfo(rks, "e", MC.Int64All(in.EntUserId)).GetPushHistory()
  124. } else {
  125. result = model.GetNewestInfo(rks, "v", in.NewUserId).GetPushHistory()
  126. }
  127. res.Data.IsVip = true
  128. res.Data.HasSubKeys = ok && len(vip_items) > 0
  129. res.Data.Count = int64(len(result))
  130. res.Data.List = result
  131. res.Data.SubFlag = "v"
  132. return res
  133. }
  134. //普通用户用户- 有关键词
  135. o_msgset := MC.ObjToMap((*userMap)["o_jy"])
  136. items, ok := (*o_msgset)["a_key"].([]interface{})
  137. if ok && len(items) > 0 {
  138. //普通用户查询推送历史
  139. result := model.GetNewestInfo(rks, "f", in.NewUserId).GetPushHistory()
  140. res.Data.IsVip = false
  141. res.Data.HasSubKeys = ok && len(items) > 0
  142. res.Data.Count = int64(len(result))
  143. res.Data.List = result
  144. res.Data.SubFlag = "f"
  145. return res
  146. }
  147. //搜索历史-关键词
  148. hKeys := redis.GetStr("other", fmt.Sprintf("s_%s", in.UserId))
  149. if hKeys != "" && len(strings.Split(hKeys, ",")) > 0 {
  150. //历史搜索
  151. res.Data.History = strings.Split(hKeys, ",")
  152. //根据订阅词获取查询语句
  153. query := model.NewestQuery("", hKeys)
  154. result := model.NewestES(query)
  155. res.Data.IsVip = false
  156. res.Data.HasSubKeys = false
  157. res.Data.Count = int64(len(result))
  158. res.Data.List = result
  159. return res
  160. }
  161. }
  162. if in.IsSearch == 2 { //定位查询(默认全国)
  163. query := model.NewestQuery(rks, "")
  164. result := model.NewestES(query)
  165. res.Data.IsVip = false
  166. res.Data.HasSubKeys = false
  167. res.Data.Count = int64(len(result))
  168. res.Data.List = result
  169. return res
  170. }
  171. return res
  172. }(in)
  173. if r.Data.Count > 0 {
  174. //排序
  175. sort.Slice(r.Data.List, func(i, j int) bool {
  176. return r.Data.List[i].PublishTime > r.Data.List[j].PublishTime
  177. })
  178. //
  179. rks := ""
  180. if userType == "e" {
  181. rks = MC.If(in.UserId != "", MC.InterfaceToStr(in.EntUserId), in.City).(string)
  182. } else {
  183. rks = MC.If(in.UserId != "", in.UserId, in.City).(string)
  184. }
  185. //rks := MC.If(in.UserId != "", in.UserId, in.City).(string)
  186. b, err := json.Marshal(r.Data)
  187. if err != nil {
  188. r.ErrCode = -1
  189. r.ErrMsg = fmt.Sprintf("保存缓存 序列化异常,err:%s", err.Error())
  190. } else {
  191. if err := redis.PutBytes("other", "p1_indexMessage_new_"+rks, &b, 2*60*60); err != nil {
  192. r.ErrCode = -1
  193. r.ErrMsg = fmt.Sprintf("保存缓存 redis 异常,err:%s", err.Error())
  194. }
  195. }
  196. }
  197. model.MakeCollection(in.UserId, r.Data.List)
  198. log.Println("接口耗时:", time.Since(t).Seconds())
  199. return r, nil
  200. }