infochangelogic.go 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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 3:
  48. 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 {
  49. data = (*_d)[0]
  50. Results.ValidityTime = mc.InterfaceToStr(data["validity_time"])
  51. } else {
  52. dataRes.ErrCode = -1
  53. dataRes.ErrMsg = "查询数据失败"
  54. break
  55. }
  56. default:
  57. if _d := model.Mysql.SelectBySql(`SELECT a.*,b.title as relatedTitle FROM information a
  58. 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 {
  59. data = (*_d)[0]
  60. var (
  61. Related consumerinfo.Related
  62. )
  63. Results.Code = mc.InterfaceToStr(data["project_code"])
  64. Results.Industry = strings.Split(mc.InterfaceToStr(data["industry"]), ",")
  65. Results.Buyer = mc.InterfaceToStr(data["buyer"])
  66. Results.Budget = mc.InterfaceToStr(data["budget"])
  67. Results.Winner = mc.InterfaceToStr(data["winner"])
  68. Results.Amount = mc.InterfaceToStr(data["amount"])
  69. Results.Detail = mc.InterfaceToStr(data["detail"])
  70. Results.JyPublishingMedia = mc.Int64All(data["publishing_media"])
  71. Results.RecommendedService = mc.Int64All(data["recommended_service"])
  72. deliveryAddress := mc.StringToMap(mc.InterfaceToStr(data["deliveryAddress"]))
  73. Results.DeliveryAddress = fmt.Sprintf(`%s%s%s%s`, deliveryAddress["area"], deliveryAddress["city"], deliveryAddress["districts"], deliveryAddress["detailsAddr"])
  74. if data["related_id"] != nil && mc.IntAll(data["related_id"]) != 0 {
  75. Related.Id = se.SE.EncodeString(mc.InterfaceToStr(data["related_id"]))
  76. Related.Title = mc.InterfaceToStr(data["relatedTitle"])
  77. Results.InfoDetailRelated = &Related
  78. }
  79. } else {
  80. dataRes.ErrCode = -1
  81. dataRes.ErrMsg = "查询数据失败"
  82. break
  83. }
  84. }
  85. Results.Province = mc.InterfaceToStr(data["province"])
  86. Results.City = mc.InterfaceToStr(data["city"])
  87. Results.AppId = mc.InterfaceToStr(data["app_id"])
  88. Results.Title = mc.InterfaceToStr(data["title"])
  89. Results.MsgType = mc.Int64All(data["type"])
  90. Results.Detail = mc.InterfaceToStr(data["detail"])
  91. Results.Attach = mc.InterfaceToStr(data["attach"])
  92. Results.CreateTime = mc.InterfaceToStr(data["create_time"])
  93. status := mc.Int64All(data["status"])
  94. published := mc.IntAll(data["published"])
  95. Review.Status = 1
  96. if published == 2 {
  97. Review.Status = 2
  98. } else if status == -1 || status == -2 {
  99. Review.Status = 3
  100. }
  101. Review.Time = mc.InterfaceToStr(data["review_time"])
  102. Review.Detail = mc.InterfaceToStr(data["review_desc"])
  103. Results.InfoDetailReview = &Review
  104. InfoDetailContact.Name = mc.InterfaceToStr(data["contact_person"])
  105. InfoDetailContact.Phone = mc.InterfaceToStr(data["contact_phone"])
  106. InfoDetailContact.Overt = mc.Int64All(data["contact_overt"])
  107. Results.InfoDetailContact = &InfoDetailContact
  108. dataRes.Results = &Results
  109. case 1:
  110. query["id"] = mc.IntAll(msgId)
  111. query["app_id"] = in.AppId
  112. switch in.MsgType {
  113. case 3:
  114. if data := model.Mysql.FindOne("supply_info", query, "", ""); data != nil && len(*data) > 0 {
  115. upQuery["is_del"] = -1
  116. if !model.Mysql.Update("supply_info", query, upQuery) {
  117. dataRes.ErrCode = -1
  118. dataRes.ErrMsg = "物理删除失败"
  119. break
  120. } else if mc.IntAll((*data)["published"]) == 2 {
  121. if !esmd.DelSupplyInfo(mc.InterfaceToStr((*data)["id"])) {
  122. dataRes.ErrCode = -1
  123. dataRes.ErrMsg = "es删除供应信息失败"
  124. }
  125. }
  126. } else {
  127. dataRes.ErrCode = -1
  128. dataRes.ErrMsg = "查询数据失败"
  129. }
  130. default:
  131. if data := model.Mysql.FindOne("information", query, "", ""); data != nil && len(*data) > 0 {
  132. upQuery["is_del"] = -1
  133. if !model.Mysql.Update("information", query, upQuery) {
  134. dataRes.ErrCode = -1
  135. dataRes.ErrMsg = "物理删除失败"
  136. return &dataRes, fmt.Errorf("物理删除失败")
  137. } else if mc.IntAll((*data)["published"]) == 2 {
  138. //如果是已经正常发布的信息 同步调用nsq删除
  139. nsq, err := util.NewNsqInfo(model.NsqConfig.Ip, model.NsqConfig.Topic, mc.InterfaceToStr((*data)["id"]), "3", mc.InterfaceToStr((*data)["type"]), false, *data)
  140. if err != nil || nsq.NsqPushInfo() != nil {
  141. dataRes.ErrCode = -1
  142. dataRes.ErrMsg = "nsq回调删除,同步删除信息失败"
  143. }
  144. }
  145. } else {
  146. dataRes.ErrCode = -1
  147. dataRes.ErrMsg = "查询数据失败"
  148. }
  149. }
  150. default:
  151. dataRes.ErrCode = -1
  152. dataRes.ErrMsg = "数据格式有误"
  153. }
  154. return &dataRes, nil
  155. }