infobyuseridlogic.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package logic
  2. import (
  3. "app.yhyue.com/moapp/jyInfo/rpc/model"
  4. "context"
  5. "fmt"
  6. "time"
  7. "app.yhyue.com/moapp/jyInfo/rpc/consumer/consumerclient"
  8. "app.yhyue.com/moapp/jyInfo/rpc/consumer/internal/svc"
  9. mc "app.yhyue.com/moapp/jybase/common"
  10. "github.com/zeromicro/go-zero/core/logx"
  11. )
  12. type InfoByUserIdLogic struct {
  13. ctx context.Context
  14. svcCtx *svc.ServiceContext
  15. logx.Logger
  16. }
  17. func NewInfoByUserIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *InfoByUserIdLogic {
  18. return &InfoByUserIdLogic{
  19. ctx: ctx,
  20. svcCtx: svcCtx,
  21. Logger: logx.WithContext(ctx),
  22. }
  23. }
  24. func GetZeroTime(d time.Time) time.Time {
  25. return time.Date(d.Year(), d.Month(), d.Day(), 0, 0, 0, 0, d.Location())
  26. }
  27. // 根据用户id获取当月已发布信息数量
  28. func (l *InfoByUserIdLogic) InfoByUserId(in *consumerclient.UserIdReq) (*consumerclient.InfoByUserIdResp, error) {
  29. // todo: add your logic here and delete this line
  30. //qurey := make(map[string]interface{})
  31. var data = consumerclient.InfoByUserIdResp{}
  32. endTime := time.Now().Format("2006-01-02 15:04:05")
  33. startTime := time.Date(time.Now().Year(), time.Now().Month(), 1, 0, 0, 0, 0, time.Now().Location())
  34. //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)
  35. 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)
  36. //number := model.Mysql.CountBySql(query) + model.Mysql.CountBySql(supplyquery)
  37. number := model.Mysql.CountBySql(supplyquery)
  38. var resp consumerclient.InfoByUserIdData
  39. resp.Total = mc.Int64All(model.SupplyTotal)
  40. resp.Surplus = mc.Int64All(model.SupplyTotal) - number
  41. data.Results = &resp
  42. return &data, nil
  43. }