package logic import ( "app.yhyue.com/moapp/jyInfo/rpc/model" "context" "fmt" "time" "app.yhyue.com/moapp/jyInfo/rpc/consumer/consumerclient" "app.yhyue.com/moapp/jyInfo/rpc/consumer/internal/svc" mc "app.yhyue.com/moapp/jybase/common" "github.com/zeromicro/go-zero/core/logx" ) type InfoByUserIdLogic struct { ctx context.Context svcCtx *svc.ServiceContext logx.Logger } func NewInfoByUserIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *InfoByUserIdLogic { return &InfoByUserIdLogic{ ctx: ctx, svcCtx: svcCtx, Logger: logx.WithContext(ctx), } } func GetZeroTime(d time.Time) time.Time { return time.Date(d.Year(), d.Month(), d.Day(), 0, 0, 0, 0, d.Location()) } // 根据用户id获取当月已发布信息数量 func (l *InfoByUserIdLogic) InfoByUserId(in *consumerclient.UserIdReq) (*consumerclient.InfoByUserIdResp, error) { // todo: add your logic here and delete this line //qurey := make(map[string]interface{}) var data = consumerclient.InfoByUserIdResp{} endTime := time.Now().Format("2006-01-02 15:04:05") startTime := time.Date(time.Now().Year(), time.Now().Month(), 1, 0, 0, 0, 0, time.Now().Location()) //query := fmt.Sprintf("select count(1) from information where user_id = %s and published = 1 and publish_time>='%s' and publish_time<='%s'", in.UserId, startTime, endTime) supplyquery := fmt.Sprintf("select count(1) from supply_info where user_id = '%s' and published = 2 and publish_time>='%s' and publish_time<='%s'", in.UserId, startTime, endTime) //number := model.Mysql.CountBySql(query) + model.Mysql.CountBySql(supplyquery) number := model.Mysql.CountBySql(supplyquery) var resp consumerclient.InfoByUserIdData resp.Total = mc.Int64All(model.SupplyTotal) resp.Surplus = mc.Int64All(model.SupplyTotal) - number data.Results = &resp return &data, nil }