infochangelogic.go 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. Results.DeliveryAddress = mc.InterfaceToStr(data["deliveryAddress"])
  75. if data["related_id"] != nil && mc.IntAll(data["related_id"]) != 0 {
  76. Related.Id = se.SE.EncodeString(mc.InterfaceToStr(data["related_id"]))
  77. Related.Title = mc.InterfaceToStr(data["relatedTitle"])
  78. Results.InfoDetailRelated = &Related
  79. }
  80. } else {
  81. dataRes.ErrCode = -1
  82. dataRes.ErrMsg = "查询数据失败"
  83. break
  84. }
  85. }
  86. Results.Province = mc.InterfaceToStr(data["province"])
  87. Results.City = mc.InterfaceToStr(data["city"])
  88. Results.AppId = mc.InterfaceToStr(data["app_id"])
  89. Results.Title = mc.InterfaceToStr(data["title"])
  90. Results.MsgType = mc.Int64All(data["type"])
  91. Results.Detail = mc.InterfaceToStr(data["detail"])
  92. Results.Attach = mc.InterfaceToStr(data["attach"])
  93. Results.CreateTime = mc.InterfaceToStr(data["create_time"])
  94. status := mc.Int64All(data["status"])
  95. published := mc.IntAll(data["published"])
  96. Review.Status = 1
  97. if published == 2 {
  98. Review.Status = 2
  99. } else if status == -1 || status == -2 {
  100. Review.Status = 3
  101. }
  102. Review.Time = mc.InterfaceToStr(data["review_time"])
  103. Review.Detail = mc.InterfaceToStr(data["review_desc"])
  104. Results.InfoDetailReview = &Review
  105. InfoDetailContact.Name = mc.InterfaceToStr(data["contact_person"])
  106. InfoDetailContact.Phone = mc.InterfaceToStr(data["contact_phone"])
  107. InfoDetailContact.Overt = mc.Int64All(data["contact_overt"])
  108. Results.InfoDetailContact = &InfoDetailContact
  109. dataRes.Results = &Results
  110. case 1:
  111. query["id"] = mc.IntAll(msgId)
  112. query["app_id"] = in.AppId
  113. switch in.MsgType {
  114. case 3:
  115. if data := model.Mysql.FindOne("supply_info", query, "", ""); data != nil && len(*data) > 0 {
  116. upQuery["is_del"] = -1
  117. if !model.Mysql.Update("supply_info", query, upQuery) {
  118. dataRes.ErrCode = -1
  119. dataRes.ErrMsg = "物理删除失败"
  120. break
  121. } else if mc.IntAll((*data)["published"]) == 2 {
  122. if !esmd.DelSupplyInfo(mc.InterfaceToStr((*data)["id"])) {
  123. dataRes.ErrCode = -1
  124. dataRes.ErrMsg = "es删除供应信息失败"
  125. }
  126. }
  127. } else {
  128. dataRes.ErrCode = -1
  129. dataRes.ErrMsg = "查询数据失败"
  130. }
  131. default:
  132. if data := model.Mysql.FindOne("information", query, "", ""); data != nil && len(*data) > 0 {
  133. upQuery["is_del"] = -1
  134. if !model.Mysql.Update("information", query, upQuery) {
  135. dataRes.ErrCode = -1
  136. dataRes.ErrMsg = "物理删除失败"
  137. return &dataRes, fmt.Errorf("物理删除失败")
  138. } else if mc.IntAll((*data)["published"]) == 2 {
  139. //如果是已经正常发布的信息 同步调用nsq删除
  140. nsq, err := util.NewNsqInfo(model.NsqConfig.Ip, model.NsqConfig.Topic, mc.InterfaceToStr((*data)["id"]), "3", mc.InterfaceToStr((*data)["type"]), false, *data)
  141. if err != nil || nsq.NsqPushInfo() != nil {
  142. dataRes.ErrCode = -1
  143. dataRes.ErrMsg = "nsq回调删除,同步删除信息失败"
  144. }
  145. }
  146. } else {
  147. dataRes.ErrCode = -1
  148. dataRes.ErrMsg = "查询数据失败"
  149. }
  150. }
  151. default:
  152. dataRes.ErrCode = -1
  153. dataRes.ErrMsg = "数据格式有误"
  154. }
  155. return &dataRes, nil
  156. }