面包店
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_order_list.go 4.7 KiB

8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
7 months ago
8 months ago
7 months ago
8 months ago
7 months ago
8 months ago
7 months ago
8 months ago
7 months ago
8 months ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. package db
  2. import (
  3. "applet/app/db/model"
  4. "applet/app/utils"
  5. "github.com/syyongx/php2go"
  6. "strings"
  7. "xorm.io/xorm"
  8. )
  9. func GetOrderById(eg *xorm.Engine, id string) *model.Order {
  10. var order model.Order
  11. get, err := eg.Where("oid=?", id).Get(&order)
  12. if get == false || err != nil {
  13. return nil
  14. }
  15. return &order
  16. }
  17. func GetOrderByIdSess(sess *xorm.Session, id string) *model.Order {
  18. var order model.Order
  19. get, err := sess.Where("oid=?", id).Get(&order)
  20. if get == false || err != nil {
  21. return nil
  22. }
  23. return &order
  24. }
  25. func GetOrderGoodsBySkuId(eg *xorm.Engine, oid, skuId string) *model.OrderGoods {
  26. var order model.OrderGoods
  27. get, err := eg.Where("oid=? and sku_id=?", oid, skuId).Get(&order)
  28. if get == false || err != nil {
  29. return nil
  30. }
  31. return &order
  32. }
  33. func GetOrderGoodsBySkuIdSess(sess *xorm.Session, oid, skuId string) *model.OrderGoods {
  34. var order model.OrderGoods
  35. get, err := sess.Where("oid=? and sku_id=?", oid, skuId).Get(&order)
  36. if get == false || err != nil {
  37. return nil
  38. }
  39. return &order
  40. }
  41. func GetOrderList(eg *xorm.Engine, param map[string]string) (*[]model.Order, int64) {
  42. var order []model.Order
  43. sess := eg.Where("1=1")
  44. if param["phone"] != "" {
  45. sess.And("buy_phone like ?", "%"+param["phone"]+"%")
  46. }
  47. if param["oid"] != "" {
  48. sess.And("oid like ?", "%"+param["oid"]+"%")
  49. }
  50. if param["state"] != "" {
  51. sess.And("state =?", param["state"])
  52. }
  53. if param["start_at"] != "" {
  54. sess.And("create_at >= ?", param["start_at"])
  55. }
  56. if param["end_at"] != "" {
  57. sess.And("create_at <= ?", param["end_at"])
  58. }
  59. if param["enterprise_name"] != "" {
  60. var enterprise []model.Enterprise
  61. eg.Where("name like ?", "%"+param["enterprise_name"]+"%").Find(&enterprise)
  62. oids := []int{-1}
  63. for _, v := range enterprise {
  64. oids = append(oids, v.Id)
  65. }
  66. sess.In("enterprise_id", oids)
  67. }
  68. size := utils.StrToInt(param["limit"])
  69. start := (utils.StrToInt(param["page"]) - 1) * size
  70. count, err := sess.Limit(size, start).OrderBy("id desc").FindAndCount(&order)
  71. if err != nil {
  72. return nil, count
  73. }
  74. return &order, count
  75. }
  76. func GetOrderListExport(eg *xorm.Engine, param map[string]string) (*[]model.Order, int64) {
  77. var order []model.Order
  78. sess := eg.Where("1=1")
  79. if param["phone"] != "" {
  80. sess.And("buy_phone like ?", "%"+param["phone"]+"%")
  81. }
  82. if param["oid"] != "" {
  83. sess.And("oid like ?", "%"+param["oid"]+"%")
  84. }
  85. if param["state"] != "" {
  86. sess.And("state =?", param["state"])
  87. }
  88. if param["start_at"] != "" {
  89. sess.And("create_at >= ?", param["start_at"])
  90. }
  91. if param["end_at"] != "" {
  92. sess.And("create_at <= ?", param["end_at"])
  93. }
  94. if param["enterprise_name"] != "" {
  95. var enterprise []model.Enterprise
  96. eg.Where("name like ?", "%"+param["enterprise_name"]+"%").Find(&enterprise)
  97. oids := []int{-1}
  98. for _, v := range enterprise {
  99. oids = append(oids, v.Id)
  100. }
  101. sess.In("enterprise_id", oids)
  102. }
  103. count, err := sess.OrderBy("id desc").FindAndCount(&order)
  104. if err != nil {
  105. return nil, count
  106. }
  107. return &order, count
  108. }
  109. func GetOrderListOutput(eg *xorm.Engine, param map[string]string) *[]model.Order {
  110. var order []model.Order
  111. sess := eg.Where("1=1")
  112. if param["phone"] != "" {
  113. sess.And("buy_phone like ?", "%"+param["phone"]+"%")
  114. }
  115. if param["oid"] != "" {
  116. sess.And("oid like ?", "%"+param["oid"]+"%")
  117. }
  118. if param["state"] != "" {
  119. sess.And("state =?", param["state"])
  120. }
  121. if param["ids"] != "" {
  122. sess.In("id", strings.Split(param["ids"], ","))
  123. }
  124. if param["start_at"] != "" {
  125. sess.And("create_at >= ?", param["start_at"])
  126. }
  127. if param["end_at"] != "" {
  128. sess.And("create_at <= ?", param["end_at"])
  129. }
  130. if param["enterprise_name"] != "" {
  131. var enterprise []model.Enterprise
  132. eg.Where("name like ?", "%"+param["enterprise_name"]+"%").Find(&enterprise)
  133. oids := []int{-1}
  134. for _, v := range enterprise {
  135. oids = append(oids, v.Id)
  136. }
  137. sess.In("enterprise_id", oids)
  138. }
  139. err := sess.OrderBy("id asc").Find(&order)
  140. if err != nil {
  141. return nil
  142. }
  143. return &order
  144. }
  145. func GetOrderListByIpad(eg *xorm.Engine, param map[string]string) (*[]model.Order, int64) {
  146. var order []model.Order
  147. sess := eg.Where("state!=5")
  148. if param["keyword"] != "" {
  149. var data []model.Enterprise
  150. eg.Where("name like ?", "%"+param["keyword"]+"%").Find(&data)
  151. ids := []string{"-1"}
  152. for _, v := range data {
  153. ids = append(ids, utils.IntToStr(v.Id))
  154. }
  155. sess.And("enterprise_id in ("+php2go.Implode(",", ids)+") or oid like ?", "%"+param["keyword"]+"%")
  156. }
  157. if param["state"] != "" && param["state"] != "1" {
  158. sess.And("state =?", param["state"])
  159. }
  160. if param["state"] == "1" {
  161. sess.In("state", []string{"1", "2"})
  162. }
  163. size := utils.StrToInt(param["limit"])
  164. start := (utils.StrToInt(param["page"]) - 1) * size
  165. count, err := sess.Limit(size, start).OrderBy("create_at desc,id desc").FindAndCount(&order)
  166. if err != nil {
  167. return nil, count
  168. }
  169. return &order, count
  170. }