package logic import ( "app.yhyue.com/moapp/jyInfo/rpc/consumer/consumer" "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" "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 *consumer.InfoDetailReq) (*consumer.InfoDetailResp, error) { // todo: add your logic here and delete this line var ( dataRes consumer.InfoDetailResp ) query := make(map[string]interface{}) upQuery := make(map[string]interface{}) msgId := se.SE.DecodeString(in.MsgId) //信息id解密 switch in.Type { case 0: var ( Results consumer.InfoDetailData //信息 Review consumer.Review //审核信息 InfoDetailContact consumer.InfoDetailContact //联系人信息 ) data := make(map[string]interface{}) if in.MsgType == 1 || in.MsgType == 2 { 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 consumer.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.Float64All(data["budget"]) Results.Winner = mc.InterfaceToStr(data["winner"]) Results.Amount = mc.Float64All(data["amount"]) Results.Detail = mc.InterfaceToStr(data["detail"]) Results.CreateTime = mc.InterfaceToStr(data["create_time"]) 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 } } else if in.MsgType == 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 } } 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 if in.MsgType == 1 || in.MsgType == 2 { 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 = "查询数据失败" } } else if in.MsgType == 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: dataRes.ErrCode = -1 dataRes.ErrMsg = "数据格式有误" } return &dataRes, nil }