附近小店
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 

145 wiersze
3.6 KiB

  1. package db
  2. import (
  3. "applet/app/db/model"
  4. "applet/app/md"
  5. "applet/app/utils"
  6. "xorm.io/xorm"
  7. )
  8. func GetOrderByOid(eg *xorm.Engine, oid string) *model.CommunityTeamOrder {
  9. var data model.CommunityTeamOrder
  10. get, err := eg.Where("oid=?", oid).Get(&data)
  11. if get == false || err != nil {
  12. return nil
  13. }
  14. return &data
  15. }
  16. func GetOrderEg(eg *xorm.Engine, oid string) *model.CommunityTeamOrder {
  17. var data model.CommunityTeamOrder
  18. get, err := eg.Where("oid=?", oid).Get(&data)
  19. if get == false || err != nil {
  20. return nil
  21. }
  22. return &data
  23. }
  24. func GetOrder(sess *xorm.Session, oid string) *model.CommunityTeamOrder {
  25. var data model.CommunityTeamOrder
  26. get, err := sess.Where("oid=?", oid).Get(&data)
  27. if get == false || err != nil {
  28. return nil
  29. }
  30. return &data
  31. }
  32. func GetOrderInfo(sess *xorm.Session, oid string) *[]model.CommunityTeamOrderInfo {
  33. var data []model.CommunityTeamOrderInfo
  34. err := sess.Where("oid=?", oid).Find(&data)
  35. if err != nil {
  36. return nil
  37. }
  38. return &data
  39. }
  40. func GetOrderInfoAllEg(eg *xorm.Engine, oid string) *[]model.CommunityTeamOrderInfo {
  41. var data []model.CommunityTeamOrderInfo
  42. err := eg.Where("oid=?", oid).Find(&data)
  43. if err != nil {
  44. return nil
  45. }
  46. return &data
  47. }
  48. func GetOrderInfoEg(eg *xorm.Engine, oid string) *model.CommunityTeamOrderInfo {
  49. var data model.CommunityTeamOrderInfo
  50. get, err := eg.Where("oid=?", oid).Asc("id").Get(&data)
  51. if get == false || err != nil {
  52. return nil
  53. }
  54. return &data
  55. }
  56. func GetOrderList(eg *xorm.Engine, arg map[string]string) *[]model.CommunityTeamOrder {
  57. var data []model.CommunityTeamOrder
  58. sess := eg.Where("1=1")
  59. if arg["uid"] != "" {
  60. sess.And("uid=?", arg["uid"])
  61. }
  62. if arg["state"] != "" {
  63. sess.And("state=?", arg["state"])
  64. }
  65. if arg["store_uid"] != "" {
  66. sess.And("store_uid=?", arg["store_uid"])
  67. }
  68. if arg["code"] != "" {
  69. sess.And("code=?", arg["code"])
  70. }
  71. limit := utils.StrToInt(arg["size"])
  72. start := (utils.StrToInt(arg["p"]) - 1) * limit
  73. err := sess.OrderBy("id desc").Limit(limit, start).Find(&data)
  74. if err != nil {
  75. return nil
  76. }
  77. return &data
  78. }
  79. func GetStoreOrderList(eg *xorm.Engine, req md.StoreOrder, parent_uid int) (*[]model.CommunityTeamOrder, int64, error) {
  80. var data []model.CommunityTeamOrder
  81. sess := eg.Where("1=1")
  82. if req.Oid != "" {
  83. sess.And("oid like ?", "%"+req.Oid+"%")
  84. }
  85. if req.StoreName != "" {
  86. var store []model.CommunityTeamStore
  87. eg.Where("name like ?", "%"+req.StoreName+"%").Find(&store)
  88. ids := []int{-1}
  89. for _, v := range store {
  90. ids = append(ids, v.Id)
  91. }
  92. sess.In("store_uid", ids)
  93. }
  94. if req.Phone != "" {
  95. var user []model.User
  96. eg.Where("phone like ?", "%"+req.Phone+"%").Find(&user)
  97. ids := []int{-1}
  98. for _, v := range user {
  99. ids = append(ids, v.Uid)
  100. }
  101. sess.In("uid", ids)
  102. }
  103. if req.Nickname != "" {
  104. var user []model.User
  105. eg.Where("nickname like ?", "%"+req.Nickname+"%").Find(&user)
  106. ids := []int{-1}
  107. for _, v := range user {
  108. ids = append(ids, v.Uid)
  109. }
  110. sess.In("uid", ids)
  111. }
  112. if req.StoreUid != "" {
  113. sess.And("store_uid=?", req.StoreUid)
  114. }
  115. if req.StoreType != "" {
  116. sess.And("store_type=?", req.StoreType)
  117. }
  118. if parent_uid > 0 {
  119. sess.And("parent_uid=?", parent_uid)
  120. }
  121. if req.StartTime != "" {
  122. sess.And("create_at>=?", req.StartTime)
  123. }
  124. if req.EndTime != "" {
  125. sess.And("create_at<=?", req.EndTime)
  126. }
  127. if req.ConfirmStartTime != "" {
  128. sess.And("confirm_at>=?", req.ConfirmStartTime)
  129. }
  130. if req.ConfirmEndTime != "" {
  131. sess.And("confirm_at<=?", req.ConfirmEndTime)
  132. }
  133. size := utils.StrToInt(req.Size)
  134. start := (utils.StrToInt(req.P) - 1) * size
  135. count, err := sess.Limit(size, start).OrderBy("create_at desc,id desc").FindAndCount(&data)
  136. if err != nil {
  137. return nil, 0, err
  138. }
  139. return &data, count, nil
  140. }