附近小店
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.
 
 
 

176 lines
4.5 KiB

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