附近小店
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

db_good.go 1.3 KiB

2 months ago
2 months ago
2 months ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package db
  2. import (
  3. "applet/app/db/model"
  4. "applet/app/utils"
  5. "xorm.io/xorm"
  6. )
  7. func GetStoreGoods(eg *xorm.Engine, req map[string]string) (*[]model.CommunityTeamGoods, int64) {
  8. var data []model.CommunityTeamGoods
  9. limit := utils.StrToInt(req["size"])
  10. start := (utils.StrToInt(req["p"]) - 1) * limit
  11. sess := eg.Where("uid=?", req["uid"]).OrderBy("sort desc,id desc").Limit(limit, start)
  12. if req["title"] != "" {
  13. sess.And("title like ?", "%"+req["title"]+"%")
  14. }
  15. if req["cid"] != "" {
  16. sess.And("cid=?", req["cid"])
  17. }
  18. if req["store_type"] != "" {
  19. sess.And("store_type=?", req["store_type"])
  20. }
  21. if req["is_up"] != "" {
  22. sess.And("state=?", 0)
  23. }
  24. if req["start_time"] != "" {
  25. sess.And("create_at>=?", req["start_time"])
  26. }
  27. if req["end_time"] != "" {
  28. sess.And("create_at<=?", req["end_time"])
  29. }
  30. count, err := sess.FindAndCount(&data)
  31. if err != nil {
  32. return nil, count
  33. }
  34. return &data, count
  35. }
  36. func GetGoodsById(eg *xorm.Engine, id string) *model.CommunityTeamGoods {
  37. var data model.CommunityTeamGoods
  38. get, err := eg.Where("id=?", id).Get(&data)
  39. if get == false || err != nil {
  40. return nil
  41. }
  42. return &data
  43. }
  44. func GetGoodsByIdSess(sess *xorm.Session, id string) *model.CommunityTeamGoods {
  45. var data model.CommunityTeamGoods
  46. get, err := sess.Where("id=?", id).Get(&data)
  47. if get == false || err != nil {
  48. return nil
  49. }
  50. return &data
  51. }