123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- package logic
- import (
- se "app.yhyue.com/moapp/jybase/encrypt"
- "context"
- "app.yhyue.com/moapp/jyInfo/rpc/consumer/consumer"
- "app.yhyue.com/moapp/jyInfo/rpc/consumer/internal/svc"
- "app.yhyue.com/moapp/jyInfo/rpc/model"
- mc "app.yhyue.com/moapp/jybase/common"
- "github.com/zeromicro/go-zero/core/logx"
- )
- type MyPublishListLogic struct {
- ctx context.Context
- svcCtx *svc.ServiceContext
- logx.Logger
- }
- func NewMyPublishListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MyPublishListLogic {
- return &MyPublishListLogic{
- ctx: ctx,
- svcCtx: svcCtx,
- Logger: logx.WithContext(ctx),
- }
- }
- // MyPublishList 我的发布列表
- func (l *MyPublishListLogic) MyPublishList(in *consumer.MyPublishListReq) (*consumer.MyPublishListResp, error) {
- // todo: add your logic here and delete this line
- var (
- queryName string
- data consumer.MyPublishListResp
- amount, inReview, approved, auditFailed, total int64
- ListData consumer.MyPublishListData
- )
- if in.Match != "" {
- queryName = ` and title LIKE '%` + in.Match + `%' `
- }
- if in.MsgType != 0 {
- queryName = queryName + ` and type=` + mc.InterfaceToStr(in.MsgType)
- }
- if in.AppId != "" {
- queryName = queryName + ` and app_id = "` + in.AppId + `"`
- }
- if in.PageIndex == 1 {
- //全部
- amount = model.Mysql.CountBySql(`SELECT count(1) from (SELECT id from information WHERE is_del = 1 and user_id= "` + in.UserId + `" ` + queryName + `
- union all
- SELECT id from supply_info WHERE is_del = 1 and user_id= "` + in.UserId + `" ` + queryName + `) a`)
- //审核中
- inReview = model.Mysql.CountBySql(`SELECT count(1) from (SELECT id from information WHERE is_del = 1 and user_id= "` + in.UserId + `" ` + queryName + ` and status in (0,1,2,3,4) and published = 1
- union all
- SELECT id from supply_info WHERE is_del = 1 and user_id= "` + in.UserId + `" ` + queryName + ` and status in (0,1,2,3,4) and published = 1) a`)
- //审核通过
- approved = model.Mysql.CountBySql(`SELECT count(1) from (SELECT id from information WHERE is_del = 1 and user_id= "` + in.UserId + `" ` + queryName + ` and published = 2
- union all
- SELECT id from supply_info WHERE is_del = 1 and user_id= "` + in.UserId + `" ` + queryName + ` and published = 2) a`)
- //审核不通过
- auditFailed = model.Mysql.CountBySql(`SELECT count(1) from (SELECT id from information WHERE is_del = 1 and user_id= "` + in.UserId + `" ` + queryName + ` and status in (-1,-2) and published = 1` + `
- union all
- SELECT id from supply_info WHERE is_del = 1 and user_id= "` + in.UserId + `" ` + queryName + ` and status in (-1,-2) and published = 1) a`)
- }
- if in.ReviewStatus != 0 {
- if in.ReviewStatus == 1 {
- queryName = queryName + ` and status in (0,1,2,3,4) and published = 1`
- } else if in.ReviewStatus == 2 {
- queryName = queryName + ` and published = 2`
- } else if in.ReviewStatus == 3 {
- queryName = queryName + ` and status in (-1,-2)`
- }
- }
- if in.PageSize <= 0 {
- in.PageSize = 10
- }
- var offset int
- if in.PageIndex <= 1 {
- offset = 0
- } else {
- offset = mc.IntAll((in.PageIndex - 1) * in.PageSize)
- }
- if in.PageIndex == 1 {
- count := model.Mysql.CountBySql(`SELECT count(1) from (SELECT id,type,title,create_time,status,published from information WHERE is_del = 1 and user_id= "` + in.UserId + `" ` + queryName + `
- union all
- SELECT id,type,title,create_time,status,published from supply_info WHERE is_del = 1 and user_id= "` + in.UserId + `" ` + queryName + ` ) a`)
- total = mc.Int64All(mc.MathCeil(mc.Float64All(count) / mc.Float64All(in.PageSize)))
- }
- allData := model.Mysql.SelectBySql(`SELECT a.id,a.type,a.title,a.create_time,a.published,a.status from (SELECT id,type,title,create_time,status,published from information WHERE is_del = 1 and user_id= "`+in.UserId+`" `+queryName+`
- union all
- SELECT id,type,title,create_time,status,published from supply_info WHERE is_del = 1 and user_id= "`+in.UserId+`" `+queryName+` ) a order by a.create_time desc limit ?,?`, offset, in.PageSize)
- if allData != nil && len(*allData) > 0 {
- for _, v := range *allData {
- var vs = consumer.ListResp{}
- vs.Id = se.SE.EncodeString(mc.InterfaceToStr(v["id"])) //信息id加密
- vs.ReviewStatus = 1
- status := mc.IntAll(v["status"])
- published := mc.IntAll(v["published"])
- //1 审核中 2 已发布(审核通过)3 status(-1,-2) 审核不通过
- if published == 2 {
- vs.ReviewStatus = 2
- } else if status == -2 || status == -1 {
- vs.ReviewStatus = 3
- }
- ListData.Total = total
- vs.MsgType = mc.Int64All(v["type"])
- vs.CreateTime = mc.InterfaceToStr(v["create_time"])
- vs.Title = mc.InterfaceToStr(v["title"])
- ListData.List = append(ListData.List, &vs)
- }
- }
- ListData.Amount = amount
- ListData.Approved = approved
- ListData.InReview = inReview
- ListData.AuditFailed = auditFailed
- data.Results = &ListData
- return &data, nil
- }
|