123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- package logic
- import (
- "app.yhyue.com/moapp/jyInfo/rpc/consumer/consumerinfo"
- "app.yhyue.com/moapp/jyInfo/rpc/consumer/internal/svc"
- "app.yhyue.com/moapp/jyInfo/rpc/model"
- esmd "app.yhyue.com/moapp/jyInfo/rpc/model/es"
- "app.yhyue.com/moapp/jyInfo/rpc/util"
- se "app.yhyue.com/moapp/jybase/encrypt"
- "context"
- "fmt"
- "log"
- "strings"
- mc "app.yhyue.com/moapp/jybase/common"
- "github.com/zeromicro/go-zero/core/logx"
- )
- type InfoChangeLogic struct {
- ctx context.Context
- svcCtx *svc.ServiceContext
- logx.Logger
- }
- func NewInfoChangeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *InfoChangeLogic {
- return &InfoChangeLogic{
- ctx: ctx,
- svcCtx: svcCtx,
- Logger: logx.WithContext(ctx),
- }
- }
- // 更新发布的信息0:获取详情;1:物理删除
- func (l *InfoChangeLogic) InfoChange(in *consumerinfo.InfoDetailReq) (*consumerinfo.InfoDetailResp, error) {
- // todo: add your logic here and delete this line
- var (
- dataRes consumerinfo.InfoDetailResp
- )
- log.Println("信息变更/删除接口调用", in)
- query := make(map[string]interface{})
- upQuery := make(map[string]interface{})
- msgId := se.SE.DecodeString(in.MsgId) //信息id解密
- switch in.Type {
- case 0:
- var (
- Results consumerinfo.InfoDetailData //信息
- Review consumerinfo.Review //审核信息
- InfoDetailContact consumerinfo.InfoDetailContact //联系人信息
- )
- data := make(map[string]interface{})
- switch in.MsgType {
- case 3:
- 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 {
- data = (*_d)[0]
- Results.ValidityTime = mc.InterfaceToStr(data["validity_time"])
- } else {
- dataRes.ErrCode = -1
- dataRes.ErrMsg = "查询数据失败"
- break
- }
- default:
- if _d := model.Mysql.SelectBySql(`SELECT a.*,b.title as relatedTitle FROM information a
- 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 {
- data = (*_d)[0]
- var (
- Related consumerinfo.Related
- )
- Results.Code = mc.InterfaceToStr(data["project_code"])
- Results.Industry = strings.Split(mc.InterfaceToStr(data["industry"]), ",")
- Results.Buyer = mc.InterfaceToStr(data["buyer"])
- Results.Budget = mc.InterfaceToStr(data["budget"])
- Results.Winner = mc.InterfaceToStr(data["winner"])
- Results.Amount = mc.InterfaceToStr(data["amount"])
- Results.Detail = mc.InterfaceToStr(data["detail"])
- Results.JyPublishingMedia = mc.Int64All(data["publishing_media"])
- Results.RecommendedService = mc.Int64All(data["recommended_service"])
- deliveryAddress := mc.StringToMap(mc.InterfaceToStr(data["deliveryAddress"]))
- Results.DeliveryAddress = fmt.Sprintf(`%s%s%s%s`, deliveryAddress["area"], deliveryAddress["city"], deliveryAddress["districts"], deliveryAddress["detailsAddr"])
- if data["related_id"] != nil && mc.IntAll(data["related_id"]) != 0 {
- Related.Id = se.SE.EncodeString(mc.InterfaceToStr(data["related_id"]))
- Related.Title = mc.InterfaceToStr(data["relatedTitle"])
- Results.InfoDetailRelated = &Related
- }
- } else {
- dataRes.ErrCode = -1
- dataRes.ErrMsg = "查询数据失败"
- break
- }
- }
- Results.Province = mc.InterfaceToStr(data["province"])
- Results.City = mc.InterfaceToStr(data["city"])
- Results.AppId = mc.InterfaceToStr(data["app_id"])
- Results.Title = mc.InterfaceToStr(data["title"])
- Results.MsgType = mc.Int64All(data["type"])
- Results.Detail = mc.InterfaceToStr(data["detail"])
- Results.Attach = mc.InterfaceToStr(data["attach"])
- Results.CreateTime = mc.InterfaceToStr(data["create_time"])
- status := mc.Int64All(data["status"])
- published := mc.IntAll(data["published"])
- Review.Status = 1
- if published == 2 {
- Review.Status = 2
- } else if status == -1 || status == -2 {
- Review.Status = 3
- }
- Review.Time = mc.InterfaceToStr(data["review_time"])
- Review.Detail = mc.InterfaceToStr(data["review_desc"])
- Results.InfoDetailReview = &Review
- InfoDetailContact.Name = mc.InterfaceToStr(data["contact_person"])
- InfoDetailContact.Phone = mc.InterfaceToStr(data["contact_phone"])
- InfoDetailContact.Overt = mc.Int64All(data["contact_overt"])
- Results.InfoDetailContact = &InfoDetailContact
- dataRes.Results = &Results
- case 1:
- query["id"] = mc.IntAll(msgId)
- query["app_id"] = in.AppId
- switch in.MsgType {
- case 3:
- if data := model.Mysql.FindOne("supply_info", query, "", ""); data != nil && len(*data) > 0 {
- upQuery["is_del"] = -1
- if !model.Mysql.Update("supply_info", query, upQuery) {
- dataRes.ErrCode = -1
- dataRes.ErrMsg = "物理删除失败"
- break
- } else if mc.IntAll((*data)["published"]) == 2 {
- if !esmd.DelSupplyInfo(mc.InterfaceToStr((*data)["id"])) {
- dataRes.ErrCode = -1
- dataRes.ErrMsg = "es删除供应信息失败"
- }
- }
- } else {
- dataRes.ErrCode = -1
- dataRes.ErrMsg = "查询数据失败"
- }
- default:
- if data := model.Mysql.FindOne("information", query, "", ""); data != nil && len(*data) > 0 {
- upQuery["is_del"] = -1
- if !model.Mysql.Update("information", query, upQuery) {
- dataRes.ErrCode = -1
- dataRes.ErrMsg = "物理删除失败"
- return &dataRes, fmt.Errorf("物理删除失败")
- } else if mc.IntAll((*data)["published"]) == 2 {
- //如果是已经正常发布的信息 同步调用nsq删除
- nsq, err := util.NewNsqInfo(model.NsqConfig.Ip, model.NsqConfig.Topic, mc.InterfaceToStr((*data)["id"]), "3", mc.InterfaceToStr((*data)["type"]), false, *data)
- if err != nil || nsq.NsqPushInfo() != nil {
- dataRes.ErrCode = -1
- dataRes.ErrMsg = "nsq回调删除,同步删除信息失败"
- }
- }
- } else {
- dataRes.ErrCode = -1
- dataRes.ErrMsg = "查询数据失败"
- }
- }
- default:
- dataRes.ErrCode = -1
- dataRes.ErrMsg = "数据格式有误"
- }
- return &dataRes, nil
- }
|