infochangelogic.go 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. package logic
  2. import (
  3. "app.yhyue.com/moapp/jyInfo/rpc/consumer/consumer"
  4. "app.yhyue.com/moapp/jyInfo/rpc/consumer/internal/svc"
  5. "app.yhyue.com/moapp/jyInfo/rpc/model"
  6. esmd "app.yhyue.com/moapp/jyInfo/rpc/model/es"
  7. "app.yhyue.com/moapp/jyInfo/rpc/util"
  8. se "app.yhyue.com/moapp/jybase/encrypt"
  9. "context"
  10. "fmt"
  11. "strings"
  12. mc "app.yhyue.com/moapp/jybase/common"
  13. "github.com/zeromicro/go-zero/core/logx"
  14. )
  15. type InfoChangeLogic struct {
  16. ctx context.Context
  17. svcCtx *svc.ServiceContext
  18. logx.Logger
  19. }
  20. func NewInfoChangeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *InfoChangeLogic {
  21. return &InfoChangeLogic{
  22. ctx: ctx,
  23. svcCtx: svcCtx,
  24. Logger: logx.WithContext(ctx),
  25. }
  26. }
  27. // 更新发布的信息0:获取详情;1:物理删除
  28. func (l *InfoChangeLogic) InfoChange(in *consumer.InfoDetailReq) (*consumer.InfoDetailResp, error) {
  29. // todo: add your logic here and delete this line
  30. var (
  31. dataRes consumer.InfoDetailResp
  32. )
  33. query := make(map[string]interface{})
  34. upQuery := make(map[string]interface{})
  35. msgId := se.SE.DecodeString(in.MsgId) //信息id解密
  36. switch in.Type {
  37. case 0:
  38. var (
  39. Results consumer.InfoDetailData //信息
  40. Review consumer.Review //审核信息
  41. InfoDetailContact consumer.InfoDetailContact //联系人信息
  42. )
  43. data := make(map[string]interface{})
  44. if in.MsgType == 1 || in.MsgType == 2 {
  45. if _d := model.Mysql.SelectBySql(`SELECT a.*,b.title as relatedTitle FROM information a
  46. LEFT JOIN information b on (a.related_id =b.id) where a.id = ? and a.app_id = `+util.StrFormat(in.AppId), mc.IntAll(msgId)); _d != nil && len(*_d) > 0 {
  47. data = (*_d)[0]
  48. var (
  49. Related consumer.Related
  50. )
  51. Results.Code = mc.InterfaceToStr(data["project_code"])
  52. Results.Industry = strings.Split(mc.InterfaceToStr(data["industry"]), ",")
  53. Results.Buyer = mc.InterfaceToStr(data["buyer"])
  54. Results.Budget = mc.Float64All(data["budget"])
  55. Results.Winner = mc.InterfaceToStr(data["winner"])
  56. Results.Amount = mc.Float64All(data["amount"])
  57. Results.Detail = mc.InterfaceToStr(data["detail"])
  58. Results.CreateTime = mc.InterfaceToStr(data["create_time"])
  59. if data["related_id"] != nil && mc.IntAll(data["related_id"]) != 0 {
  60. Related.Id = se.SE.EncodeString(mc.InterfaceToStr(data["related_id"]))
  61. Related.Title = mc.InterfaceToStr(data["relatedTitle"])
  62. Results.InfoDetailRelated = &Related
  63. }
  64. } else {
  65. dataRes.ErrCode = -1
  66. dataRes.ErrMsg = "查询数据失败"
  67. break
  68. }
  69. } else if in.MsgType == 3 {
  70. if _d := model.Mysql.SelectBySql(`SELECT * FROM supply_info where id = ? and app_id = `+util.StrFormat(in.AppId), mc.IntAll(msgId)); _d != nil && len(*_d) > 0 {
  71. data = (*_d)[0]
  72. Results.ValidityTime = mc.InterfaceToStr(data["validity_time"])
  73. } else {
  74. dataRes.ErrCode = -1
  75. dataRes.ErrMsg = "查询数据失败"
  76. break
  77. }
  78. }
  79. Results.Province = mc.InterfaceToStr(data["province"])
  80. Results.City = mc.InterfaceToStr(data["city"])
  81. Results.AppId = mc.InterfaceToStr(data["app_id"])
  82. Results.Title = mc.InterfaceToStr(data["title"])
  83. Results.MsgType = mc.Int64All(data["type"])
  84. Results.Detail = mc.InterfaceToStr(data["detail"])
  85. Results.Attach = mc.InterfaceToStr(data["attach"])
  86. Results.CreateTime = mc.InterfaceToStr(data["create_time"])
  87. status := mc.Int64All(data["status"])
  88. published := mc.IntAll(data["published"])
  89. Review.Status = 1
  90. if published == 2 {
  91. Review.Status = 2
  92. } else if status == -1 || status == -2 {
  93. Review.Status = 3
  94. }
  95. Review.Time = mc.InterfaceToStr(data["review_time"])
  96. Review.Detail = mc.InterfaceToStr(data["review_desc"])
  97. Results.InfoDetailReview = &Review
  98. InfoDetailContact.Name = mc.InterfaceToStr(data["contact_person"])
  99. InfoDetailContact.Phone = mc.InterfaceToStr(data["contact_phone"])
  100. InfoDetailContact.Overt = mc.Int64All(data["contact_overt"])
  101. Results.InfoDetailContact = &InfoDetailContact
  102. dataRes.Results = &Results
  103. case 1:
  104. query["id"] = mc.IntAll(msgId)
  105. query["app_id"] = in.AppId
  106. if in.MsgType == 1 || in.MsgType == 2 {
  107. if data := model.Mysql.FindOne("information", query, "", ""); data != nil && len(*data) > 0 {
  108. upQuery["is_del"] = -1
  109. if !model.Mysql.Update("information", query, upQuery) {
  110. dataRes.ErrCode = -1
  111. dataRes.ErrMsg = "物理删除失败"
  112. return &dataRes, fmt.Errorf("物理删除失败")
  113. } else if mc.IntAll((*data)["published"]) == 2 {
  114. //如果是已经正常发布的信息 同步调用nsq删除
  115. nsq, err := util.NewNsqInfo(model.NsqConfig.Ip, model.NsqConfig.Topic, mc.InterfaceToStr((*data)["id"]), "3", mc.InterfaceToStr((*data)["type"]), false, *data)
  116. if err != nil || nsq.NsqPushInfo() != nil {
  117. dataRes.ErrCode = -1
  118. dataRes.ErrMsg = "nsq回调删除,同步删除信息失败"
  119. }
  120. }
  121. } else {
  122. dataRes.ErrCode = -1
  123. dataRes.ErrMsg = "查询数据失败"
  124. }
  125. } else if in.MsgType == 3 {
  126. if data := model.Mysql.FindOne("supply_info", query, "", ""); data != nil && len(*data) > 0 {
  127. upQuery["is_del"] = -1
  128. if !model.Mysql.Update("supply_info", query, upQuery) {
  129. dataRes.ErrCode = -1
  130. dataRes.ErrMsg = "物理删除失败"
  131. break
  132. } else if mc.IntAll((*data)["published"]) == 2 {
  133. if !esmd.DelSupplyInfo(mc.InterfaceToStr((*data)["id"])) {
  134. dataRes.ErrCode = -1
  135. dataRes.ErrMsg = "es删除供应信息失败"
  136. }
  137. }
  138. } else {
  139. dataRes.ErrCode = -1
  140. dataRes.ErrMsg = "查询数据失败"
  141. }
  142. }
  143. default:
  144. dataRes.ErrCode = -1
  145. dataRes.ErrMsg = "数据格式有误"
  146. }
  147. return &dataRes, nil
  148. }