discount_gift.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. package dao
  2. import (
  3. "context"
  4. "errors"
  5. "fmt"
  6. "go-common/app/service/live/gift/model"
  7. "go-common/library/database/sql"
  8. "go-common/library/log"
  9. "go-common/library/xstr"
  10. )
  11. var _getDiscountGift = "SELECT id,discount_id,gift_id,user_type,discount_price,corner_mark,corner_position FROM discount_gift WHERE discount_id in (%s)"
  12. // GetByDiscountIds GetByDiscountIds
  13. func (d *Dao) GetByDiscountIds(ctx context.Context, ids []int64) (res []*model.DiscountGift, err error) {
  14. log.Info("GetByDiscountIds,ids:%v", ids)
  15. if len(ids) == 0 {
  16. log.Error("query GetByDiscountIds params null")
  17. err = errors.New("params error")
  18. return
  19. }
  20. var rows *sql.Rows
  21. if rows, err = d.db.Query(ctx, fmt.Sprintf(_getDiscountGift, xstr.JoinInts(ids))); err != nil {
  22. log.Error("query GetByDiscountIds error,err %v", err)
  23. return
  24. }
  25. defer rows.Close()
  26. for rows.Next() {
  27. d := &model.DiscountGift{}
  28. if err = rows.Scan(&d.Id, &d.DiscountId, &d.GiftId, &d.UserType, &d.DiscountPrice, &d.CornerMark, &d.CornerPosition); err != nil {
  29. log.Error("GetByDiscountIds scan error,err %v", err)
  30. return
  31. }
  32. res = append(res, d)
  33. }
  34. return
  35. }