publishinfologic.go 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. package logic
  2. import (
  3. "app.yhyue.com/moapp/jyInfo/rpc/consumer/consumerinfo"
  4. "app.yhyue.com/moapp/jyInfo/rpc/consumer/internal/svc"
  5. "app.yhyue.com/moapp/jyInfo/rpc/model"
  6. "app.yhyue.com/moapp/jyInfo/rpc/util"
  7. "context"
  8. "encoding/json"
  9. "fmt"
  10. "log"
  11. "strings"
  12. "time"
  13. se "app.yhyue.com/moapp/jybase/encrypt"
  14. mc "app.yhyue.com/moapp/jybase/common"
  15. "app.yhyue.com/moapp/jybase/redis"
  16. "github.com/zeromicro/go-zero/core/logx"
  17. )
  18. type PublishInfoLogic struct {
  19. ctx context.Context
  20. svcCtx *svc.ServiceContext
  21. logx.Logger
  22. }
  23. func NewPublishInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PublishInfoLogic {
  24. return &PublishInfoLogic{
  25. ctx: ctx,
  26. svcCtx: svcCtx,
  27. Logger: logx.WithContext(ctx),
  28. }
  29. }
  30. // 发布信息
  31. func (l *PublishInfoLogic) PublishInfo(in *consumerinfo.PublishInfoReq) (*consumerinfo.PublishInfoResp, error) {
  32. res := consumerinfo.PublishInfoResp{}
  33. log.Println("信息发布in数据:", in)
  34. if in.MsgType == 8 && in.DeliveryAddress == "" {
  35. res.ErrCode = -1
  36. res.ErrMsg = "缺少交付地址"
  37. return &res, nil
  38. }
  39. //信息类型1:招标信息 2:采购信息 3:供应信息
  40. publishData := make(map[string]interface{})
  41. publishData["user_id"] = in.UserId //发布人用户ID
  42. publishData["phone"] = in.Phone //注册手机号
  43. publishData["title"] = in.Title //信息标题
  44. publishData["province"] = in.Province //项目省份
  45. if v, ok := (*model.PublishCity)[in.Province]; ok && v != "" {
  46. publishData["city"] = v
  47. } else {
  48. publishData["city"] = in.City
  49. } //项目城市
  50. publishData["detail"] = util.NewCut().ClearHtml(in.Detail) //正文信息
  51. publishData["create_time"] = time.Now().Format("2006-01-02 15:04:05") //申请时间
  52. publishData["attach"] = in.Attach //附件(多个附件逗号分割)
  53. publishData["contact_person"] = in.Contact.Person //联系人
  54. publishData["contact_phone"] = in.Contact.Phone //联系人电话
  55. publishData["is_del"] = 1 // 0:全部;1:未删除;-1:删除
  56. publishData["published"] = 1 // 0:全部;1:未发布;2:已发布
  57. publishData["type"] = mc.IntAll(in.MsgType) //1:招标信息|2:采购信息|3:供应信息
  58. publishData["ent_id"] = mc.IntAll(in.EntId)
  59. publishData["app_id"] = in.AppId
  60. publishData["ent_name"] = in.EntName
  61. // 0:全部;1:待审核;2:待人工审核(敏感词审核不通过||敏感词审核通过);3:自动审核通过;4:人工审核通过;-1:自动审核不通过(机构冻结);-2:人工审核不通过;
  62. publishData["status"] = 1
  63. switch in.MsgType {
  64. case 3:
  65. publishData["contact_overt"] = mc.Int64All(mc.If(in.Contact.Overt == 0, 2, in.Contact.Overt)) //是否公开 默认不公开
  66. if in.Deadline != "" {
  67. publishData["validity_time"] = in.Deadline //信息有效期
  68. }
  69. case 8: //阳光采购
  70. publishData["contact_overt"] = 1 //是否公开 默认不公开
  71. publishData["publishing_media"] = 1 //是否同意剑鱼发布平台 1 是 -1 否
  72. publishData["recommended_service"] = in.RecommendedService //是否推荐供应商 1 是 -1 否
  73. publishData["project_code"] = in.Code //项目编号
  74. publishData["industry"] = strings.Join(in.Industry, ",") //项目行业,多个逗号分隔
  75. publishData["buyer"] = in.Buyer //采购单位
  76. publishData["winner"] = in.Winner //中标单位
  77. deliveryAddress := mc.StringToMap(in.DeliveryAddress)
  78. for _, s := range []string{"香港", "澳门", "台湾", "北京", "上海", "重庆", "天津", "钓鱼岛"} {
  79. if strings.Contains(mc.InterfaceToStr(deliveryAddress["city"]), s) {
  80. deliveryAddress["city"] = ""
  81. jsonData, err := json.Marshal(deliveryAddress)
  82. if err != nil {
  83. fmt.Println("Error marshalling JSON:", err)
  84. }
  85. in.DeliveryAddress = string(jsonData)
  86. }
  87. }
  88. publishData["deliveryAddress"] = in.DeliveryAddress //交易地址
  89. if in.Budget != "" {
  90. publishData["budget"] = mc.Float64All(in.Budget) // 预算单位元
  91. }
  92. if in.Amount != "" {
  93. publishData["amount"] = mc.Float64All(in.Amount) //中标金额
  94. }
  95. default:
  96. if in.EntName == in.Buyer {
  97. publishData["contact_overt"] = mc.Int64All(mc.If(in.Contact.Overt == 0, 2, in.Contact.Overt)) //是否公开 默认不公开
  98. } else {
  99. publishData["contact_overt"] = 0
  100. }
  101. publishData["publishing_media"] = in.JyPublishingMedia //是否同意剑鱼发布平台 1 是 -1 否
  102. publishData["recommended_service"] = in.RecommendedService //是否推荐供应商 1 是 -1 否
  103. publishData["related_id"] = mc.IntAll(se.SE.DecodeString(in.RelatedId)) //关联公告id
  104. publishData["project_code"] = in.Code //项目编号
  105. publishData["industry"] = strings.Join(in.Industry, ",") //项目行业,多个逗号分隔
  106. publishData["buyer"] = in.Buyer //采购单位
  107. publishData["winner"] = in.Winner //中标单位
  108. if in.Budget != "" {
  109. publishData["budget"] = mc.Float64All(in.Budget) // 预算单位元
  110. }
  111. if in.Amount != "" {
  112. publishData["amount"] = mc.Float64All(in.Amount) //中标金额
  113. }
  114. }
  115. id := model.Mysql.Insert("information", publishData)
  116. if id < 1 {
  117. res.ErrCode = -1
  118. res.ErrMsg = "信息保存失败"
  119. return &res, nil
  120. }
  121. var InfoId consumerinfo.PublishId
  122. InfoId.InformationId = se.SE.EncodeString(mc.InterfaceToStr(id)) //信息id加密
  123. res.PublishId = &InfoId
  124. appendInfo := make(map[string]interface{})
  125. if in.Title != "" {
  126. appendInfo["title"] = in.Title
  127. }
  128. if in.Detail != "" {
  129. appendInfo["detail"] = publishData["detail"]
  130. }
  131. if in.Attach != "" && in.Attach != "{}" {
  132. appendInfo["attach"] = mc.StringToMap(in.Attach)
  133. }
  134. log.Println("发送nsq敏感词信息", model.NsqConfig, appendInfo)
  135. nsq, err := util.NewNsqInfo(model.NsqConfig.Ip, model.NsqConfig.Topic, mc.InterfaceToStr(id), "1", mc.InterfaceToStr(in.MsgType), false, appendInfo)
  136. if err != nil {
  137. log.Println("初始化NSQ信息失败", err.Error())
  138. res.ErrCode = -1
  139. res.ErrMsg = "信息发布失败"
  140. return &res, nil
  141. }
  142. if err = nsq.NsqPushInfo(); err != nil {
  143. log.Println("发送nsq敏感词信息失败nsq++++++++++++", model.NsqConfig, appendInfo, err.Error())
  144. res.ErrCode = -1
  145. res.ErrMsg = "信息发布失败"
  146. return &res, nil
  147. }
  148. if in.MsgType == 3 {
  149. entNameKye := fmt.Sprintf("userEntName_%s_%d_%d", in.UserId, id, in.MsgType)
  150. redis.Put("other", entNameKye, in.EntName, 3*24*60*60)
  151. }
  152. return &res, nil
  153. }