infochangelogic.go 5.6 KB

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