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