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" "app.yhyue.com/moapp/jyInfo/rpc/util" se "app.yhyue.com/moapp/jybase/encrypt" "context" "log" mc "app.yhyue.com/moapp/jybase/common" "github.com/zeromicro/go-zero/core/logx" ) type InfoRelatedLogic struct { ctx context.Context svcCtx *svc.ServiceContext logx.Logger } func NewInfoRelatedLogic(ctx context.Context, svcCtx *svc.ServiceContext) *InfoRelatedLogic { return &InfoRelatedLogic{ ctx: ctx, svcCtx: svcCtx, Logger: logx.WithContext(ctx), } } // 关联公告 func (l *InfoRelatedLogic) InfoRelated(in *consumerinfo.UserIdReq) (*consumerinfo.InfoRelatedResp, error) { // todo: add your logic here and delete this line var ( queryName string resp consumerinfo.InfoRelatedResp ) log.Println("关联公告接口调用", in) if in.AppId != "" { queryName += ` and app_id = ` + util.StrFormat(in.AppId) } if in.EntId != 0 { queryName += ` and ent_id = ` + mc.InterfaceToStr(in.EntId) } switch in.MsgId { case 0: queryName += ` and type=` + mc.InterfaceToStr(in.MsgType) if in.Match != "" { queryName += ` and title LIKE '%` + in.Match + `%' ` } allData := model.Mysql.SelectBySql(`SELECT * from information WHERE user_id="` + in.UserId + `" and published=2 and is_del=1` + queryName + ` order by create_time desc limit 50`) if allData == nil || len(*allData) == 0 { return &resp, nil } for _, v := range *allData { var data consumerinfo.InfoData data.Id = se.SE.EncodeString(mc.InterfaceToStr(v["id"])) //关联信息加密 data.Title = mc.InterfaceToStr(v["title"]) data.Person = mc.InterfaceToStr(v["contact_person"]) data.Phone = mc.InterfaceToStr(v["contact_phone"]) data.Overt = mc.Int64All(v["contact_overt"]) data.RecommendedService = mc.Int64All(v["recommended_service"]) resp.Data = append(resp.Data, &data) } case 1: allData := model.Mysql.SelectBySql(`SELECT a.id,a.title,a.create_time,a.contact_person,a.contact_phone,a.contact_overt from (SELECT id,title,create_time,contact_person,contact_phone,contact_overt from information WHERE user_id= "` + in.UserId + `" union all SELECT id,title,create_time,contact_person,contact_phone,contact_overt from supply_info WHERE is_del = 1 and user_id= "` + in.UserId + `" ) a order by a.create_time desc limit 1`) oneData := model.Mysql.SelectBySql(`SELECT * from information WHERE user_id="` + in.UserId + `" order by create_time desc limit 1`) if allData == nil || len(*allData) == 0 { return &resp, nil } for _, v := range *allData { var data consumerinfo.InfoData data.Id = se.SE.EncodeString(mc.InterfaceToStr(v["id"])) //关联信息加密 data.Title = mc.InterfaceToStr(v["title"]) data.Person = mc.InterfaceToStr(v["contact_person"]) data.Phone = mc.InterfaceToStr(v["contact_phone"]) data.Overt = mc.Int64All(v["contact_overt"]) if oneData != nil && len(*oneData) > 0 { data.RecommendedService = mc.Int64All((*oneData)[0]["recommended_service"]) } resp.Data = append(resp.Data, &data) } } return &resp, nil }