GoodsIntroductionDao.go 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. package manage
  2. import (
  3. "demo/configs"
  4. "demo/data/domain"
  5. "demo/data/domain/vo"
  6. )
  7. func GetGoodsIntroductionById(id int64) (domain.GoodsIntroduction, error) {
  8. var goodsIntroduction domain.GoodsIntroduction
  9. _, err := configs.Engine.Table("goods_introduction").Where("id = ?", id).Get(&goodsIntroduction)
  10. if err != nil {
  11. return goodsIntroduction, err
  12. }
  13. return goodsIntroduction, nil
  14. }
  15. func GetGoodsIntroductionListInId(ids []int64) ([]domain.GoodsIntroduction, error) {
  16. rows, err := configs.Engine.Table("goods_introduction").In("id", ids).Rows(&domain.GoodsIntroduction{})
  17. if err != nil {
  18. return make([]domain.GoodsIntroduction, 0), err
  19. }
  20. defer rows.Close()
  21. var list []domain.GoodsIntroduction
  22. for rows.Next() {
  23. var u domain.GoodsIntroduction
  24. rows.Scan(&u)
  25. list = append(list, u)
  26. }
  27. return list, nil
  28. }
  29. func GetGoodsIntroductionList(goodsIntroduction domain.GoodsIntroduction, pageNum, pageSize int) (vo.BaseListVo, error) {
  30. var arr []domain.GoodsIntroduction
  31. Count, err := configs.Engine.Table("goods_introduction").Limit(pageSize, (pageNum-1)*pageSize).FindAndCount(&arr, &goodsIntroduction)
  32. var vo vo.BaseListVo
  33. if err != nil {
  34. return vo, err
  35. }
  36. if err != nil {
  37. return vo, err
  38. }
  39. vo.PageNum = pageNum
  40. vo.PageSize = pageSize
  41. vo.List = make([]any, len(arr))
  42. for i, v := range arr {
  43. vo.List[i] = v
  44. }
  45. vo.Total = int(Count)
  46. return vo, nil
  47. }
  48. func SaveGoodsIntroduction(goodsIntroduction *domain.GoodsIntroduction) (domain.GoodsIntroduction, error) {
  49. _, err := configs.Engine.Table("goods_introduction").Insert(&goodsIntroduction)
  50. if err != nil {
  51. return *goodsIntroduction, err
  52. }
  53. return *goodsIntroduction, nil
  54. }
  55. func SetGoodsIntroduction(goodsIntroductionMap map[string]interface{}, id int64) (domain.GoodsIntroduction, bool, error) {
  56. var goodsIntroduction domain.GoodsIntroduction
  57. _, err := configs.Engine.Table("goods_introduction").Where("id = ?", id).Update(goodsIntroductionMap)
  58. if err != nil {
  59. return goodsIntroduction, false, err
  60. }
  61. return goodsIntroduction, true, nil
  62. }
  63. func DeleteGoodsIntroduction(id int64) bool {
  64. var goodsIntroduction domain.GoodsIntroduction
  65. i, err := configs.Engine.Table("goods_introduction").Where("id = ?", id).Delete(&goodsIntroduction)
  66. if err != nil {
  67. return false
  68. }
  69. return i > 0
  70. }