123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- package logic
- import (
- "app.yhyue.com/moapp/jyInfo/rpc/manager/internal/svc"
- "app.yhyue.com/moapp/jyInfo/rpc/manager/type/manager"
- "app.yhyue.com/moapp/jyInfo/rpc/model"
- "app.yhyue.com/moapp/jyInfo/rpc/util"
- se "app.yhyue.com/moapp/jybase/encrypt"
- "context"
- "fmt"
- "strings"
- "app.yhyue.com/moapp/jybase/common"
- "github.com/zeromicro/go-zero/core/logx"
- )
- type InfoListLogic struct {
- ctx context.Context
- svcCtx *svc.ServiceContext
- logx.Logger
- }
- func NewInfoListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *InfoListLogic {
- return &InfoListLogic{
- ctx: ctx,
- svcCtx: svcCtx,
- Logger: logx.WithContext(ctx),
- }
- }
- //InfoList 信息列表
- func (l *InfoListLogic) InfoList(in *manager.InfoListReq) (*manager.InfoListResp, error) {
- var (
- query []string
- queryInfo string
- count int64
- results []*manager.InfoList
- )
- if in.MsgType != 0 {
- query = append(query, `type=`+common.InterfaceToStr(in.MsgType)+` `)
- }
- if in.PhoneType != 0 {
- if in.PhoneType == 1 {
- query = append(query, ` phone LIKE '%`+in.Phone+`%' `)
- } else {
- query = append(query, ` contact_phone LIKE '%`+in.Phone+`%' `)
- }
- }
- if in.ApplyStartTime != "" {
- query = append(query, ` create_time >="`+in.ApplyStartTime+`"`)
- }
- if in.RecommendedService != 0 {
- query = append(query, ` recommended_service =`+common.InterfaceToStr(in.RecommendedService))
- }
- if in.JyPublishingMedia != 0 {
- query = append(query, ` publishing_media =`+common.InterfaceToStr(in.JyPublishingMedia))
- }
- if in.IsDel != 0 {
- query = append(query, ` is_del =`+common.InterfaceToStr(in.IsDel))
- }
- if in.Published != 0 {
- query = append(query, ` published =`+common.InterfaceToStr(in.Published))
- }
- if in.ApplyEndTime != "" {
- query = append(query, ` create_time <="`+in.ApplyEndTime+`"`)
- }
- if in.AppId != "" {
- query = append(query, ` app_id = `+util.StrFormat(in.AppId))
- }
- //supQuery := query
- if in.ReviewStatus != 0 {
- query = append(query, ` status =`+common.InterfaceToStr(in.ReviewStatus))
- //supQuery = append(supQuery, ` status =`+common.Str(in.ReviewStatus))
- }
- if len(query) > 0 {
- queryInfo = fmt.Sprintf(" where %s", strings.Join(query, " and "))
- //querySup = fmt.Sprintf(" where %s", strings.Join(supQuery, " and "))
- }
- if in.PageSize <= 0 {
- in.PageSize = 10
- }
- count = model.Mysql.CountBySql(`SELECT count(1) from (SELECT id,type,status,phone,contact_person,contact_phone,title,create_time,is_del,published from information ` + queryInfo + `
- union all
- SELECT id,type,status,phone,contact_person,contact_phone,title,create_time,is_del,published from supply_info ` + queryInfo + ` ) a`)
- var offset int
- if in.PageIndex <= 1 {
- offset = 0
- } else {
- offset = common.IntAll((in.PageIndex - 1) * in.PageSize)
- }
- allData := model.Mysql.SelectBySql(`SELECT * from (SELECT id,type,status,phone,contact_person,contact_phone,title,create_time,is_del,published from information `+queryInfo+`
- union all
- SELECT id,type,status,phone,contact_person,contact_phone,title,create_time,is_del,published from supply_info `+queryInfo+` ) a order by a.create_time limit ?,? `, offset, in.PageSize)
- if allData != nil && len(*allData) > 0 {
- for _, v := range *allData {
- res := manager.InfoList{}
- var contact manager.Contact
- res.Id = se.SE.EncodeString(common.InterfaceToStr(v["id"])) //信息id加密
- res.Title = common.InterfaceToStr(v["title"])
- res.MsgType = common.Int64All(v["type"])
- res.Phone = common.InterfaceToStr(v["phone"])
- res.ReviewStatus = common.Int64All(v["status"])
- res.Published = common.Int64All(v["published"])
- res.IsDel = common.Int64All(v["is_del"])
- res.ApplyTime = common.InterfaceToStr(v["create_time"])
- contact.Name = common.InterfaceToStr(v["contact_person"])
- contact.Phone = common.InterfaceToStr(v["contact_phone"])
- res.Contact = &contact
- results = append(results, &res)
- }
- }
- data := manager.Data{}
- data.Count = count
- data.List = results
- return &manager.InfoListResp{
- ErrCode: 0,
- ErrMsg: "",
- Data: &data,
- }, nil
- }
|