publishinfologic.go 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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 in.MsgType == 8 || (*model.PublishCity)[in.Province] == "" {
  46. publishData["city"] = in.City
  47. } else {
  48. publishData["city"] = (*model.PublishCity)[in.Province]
  49. }
  50. //项目城市
  51. publishData["detail"] = util.NewCut().ClearHtml(in.Detail) //正文信息
  52. publishData["create_time"] = time.Now().Format("2006-01-02 15:04:05") //申请时间
  53. publishData["attach"] = in.Attach //附件(多个附件逗号分割)
  54. publishData["contact_person"] = in.Contact.Person //联系人
  55. publishData["contact_phone"] = in.Contact.Phone //联系人电话
  56. publishData["is_del"] = 1 // 0:全部;1:未删除;-1:删除
  57. publishData["published"] = 1 // 0:全部;1:未发布;2:已发布
  58. publishData["type"] = mc.IntAll(in.MsgType) //1:招标信息|2:采购信息|3:供应信息
  59. publishData["ent_id"] = mc.IntAll(in.EntId)
  60. publishData["app_id"] = in.AppId
  61. publishData["ent_name"] = in.EntName
  62. // 0:全部;1:待审核;2:待人工审核(敏感词审核不通过||敏感词审核通过);3:自动审核通过;4:人工审核通过;-1:自动审核不通过(机构冻结);-2:人工审核不通过;
  63. publishData["status"] = 1
  64. switch in.MsgType {
  65. case 3:
  66. publishData["contact_overt"] = mc.Int64All(mc.If(in.Contact.Overt == 0, 2, in.Contact.Overt)) //是否公开 默认不公开
  67. if in.Deadline != "" {
  68. publishData["validity_time"] = in.Deadline //信息有效期
  69. }
  70. case 8: //阳光采购
  71. publishData["contact_overt"] = 1 //是否公开 默认不公开
  72. publishData["publishing_media"] = 1 //是否同意剑鱼发布平台 1 是 -1 否
  73. publishData["recommended_service"] = in.RecommendedService //是否推荐供应商 1 是 -1 否
  74. publishData["project_code"] = in.Code //项目编号
  75. publishData["industry"] = strings.Join(in.Industry, ",") //项目行业,多个逗号分隔
  76. publishData["buyer"] = in.Buyer //采购单位
  77. publishData["winner"] = in.Winner //中标单位
  78. deliveryAddress := mc.StringToMap(in.DeliveryAddress)
  79. for _, s := range []string{"香港", "澳门", "台湾", "北京", "上海", "重庆", "天津", "钓鱼岛"} {
  80. if strings.Contains(mc.InterfaceToStr(deliveryAddress["city"]), s) {
  81. deliveryAddress["city"] = ""
  82. jsonData, err := json.Marshal(deliveryAddress)
  83. if err != nil {
  84. fmt.Println("Error marshalling JSON:", err)
  85. }
  86. in.DeliveryAddress = string(jsonData)
  87. }
  88. }
  89. publishData["deliveryAddress"] = in.DeliveryAddress //交易地址
  90. if in.Budget != "" {
  91. publishData["budget"] = mc.Float64All(in.Budget) // 预算单位元
  92. }
  93. if in.Amount != "" {
  94. publishData["amount"] = mc.Float64All(in.Amount) //中标金额
  95. }
  96. default:
  97. if in.EntName == in.Buyer {
  98. publishData["contact_overt"] = mc.Int64All(mc.If(in.Contact.Overt == 0, 2, in.Contact.Overt)) //是否公开 默认不公开
  99. } else {
  100. publishData["contact_overt"] = 0
  101. }
  102. publishData["publishing_media"] = in.JyPublishingMedia //是否同意剑鱼发布平台 1 是 -1 否
  103. publishData["recommended_service"] = in.RecommendedService //是否推荐供应商 1 是 -1 否
  104. publishData["related_id"] = mc.IntAll(se.SE.DecodeString(in.RelatedId)) //关联公告id
  105. publishData["project_code"] = in.Code //项目编号
  106. publishData["industry"] = strings.Join(in.Industry, ",") //项目行业,多个逗号分隔
  107. publishData["buyer"] = in.Buyer //采购单位
  108. publishData["winner"] = in.Winner //中标单位
  109. if in.Budget != "" {
  110. publishData["budget"] = mc.Float64All(in.Budget) // 预算单位元
  111. }
  112. if in.Amount != "" {
  113. publishData["amount"] = mc.Float64All(in.Amount) //中标金额
  114. }
  115. }
  116. id := model.Mysql.Insert("information", publishData)
  117. if id < 1 {
  118. res.ErrCode = -1
  119. res.ErrMsg = "信息保存失败"
  120. return &res, nil
  121. }
  122. var InfoId consumerinfo.PublishId
  123. InfoId.InformationId = se.SE.EncodeString(mc.InterfaceToStr(id)) //信息id加密
  124. res.PublishId = &InfoId
  125. appendInfo := make(map[string]interface{})
  126. if in.Title != "" {
  127. appendInfo["title"] = in.Title
  128. }
  129. if in.Detail != "" {
  130. appendInfo["detail"] = publishData["detail"]
  131. }
  132. if in.Attach != "" && in.Attach != "{}" {
  133. appendInfo["attach"] = mc.StringToMap(in.Attach)
  134. }
  135. log.Println("发送nsq敏感词信息", model.NsqConfig, appendInfo)
  136. nsq, err := util.NewNsqInfo(model.NsqConfig.Ip, model.NsqConfig.Topic, mc.InterfaceToStr(id), "1", mc.InterfaceToStr(in.MsgType), false, appendInfo)
  137. if err != nil {
  138. log.Println("初始化NSQ信息失败", err.Error())
  139. res.ErrCode = -1
  140. res.ErrMsg = "信息发布失败"
  141. return &res, nil
  142. }
  143. if err = nsq.NsqPushInfo(); err != nil {
  144. log.Println("发送nsq敏感词信息失败nsq++++++++++++", model.NsqConfig, appendInfo, err.Error())
  145. res.ErrCode = -1
  146. res.ErrMsg = "信息发布失败"
  147. return &res, nil
  148. }
  149. if in.MsgType == 3 {
  150. entNameKye := fmt.Sprintf("userEntName_%s_%d_%d", in.UserId, id, in.MsgType)
  151. redis.Put("other", entNameKye, in.EntName, 3*24*60*60)
  152. }
  153. return &res, nil
  154. }