面包店
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
8 months ago
7 months ago
8 months ago
7 months ago
8 months ago
7 months ago
8 months ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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["enterprise_name"] != "" {
  125. var enterprise []model.Enterprise
  126. eg.Where("name like ?", "%"+param["enterprise_name"]+"%").Find(&enterprise)
  127. oids := []int{-1}
  128. for _, v := range enterprise {
  129. oids = append(oids, v.Id)
  130. }
  131. sess.In("enterprise_id", oids)
  132. }
  133. size := 10000
  134. start := (utils.StrToInt(param["page"]) - 1) * size
  135. if param["ids"] == "" {
  136. sess.Limit(size, start)
  137. }
  138. err := sess.OrderBy("id asc").Find(&order)
  139. if err != nil {
  140. return nil
  141. }
  142. return &order
  143. }
  144. func GetOrderListByIpad(eg *xorm.Engine, param map[string]string) (*[]model.Order, int64) {
  145. var order []model.Order
  146. sess := eg.Where("state!=5")
  147. if param["keyword"] != "" {
  148. var data []model.Enterprise
  149. eg.Where("name like ?", "%"+param["keyword"]+"%").Find(&data)
  150. ids := []string{"-1"}
  151. for _, v := range data {
  152. ids = append(ids, utils.IntToStr(v.Id))
  153. }
  154. sess.And("enterprise_id in ("+php2go.Implode(",", ids)+") or oid like ?", "%"+param["keyword"]+"%")
  155. }
  156. if param["state"] != "" && param["state"] != "1" {
  157. sess.And("state =?", param["state"])
  158. }
  159. if param["state"] == "1" {
  160. sess.In("state", []string{"1", "2"})
  161. }
  162. size := utils.StrToInt(param["limit"])
  163. start := (utils.StrToInt(param["page"]) - 1) * size
  164. count, err := sess.Limit(size, start).OrderBy("id asc").FindAndCount(&order)
  165. if err != nil {
  166. return nil, count
  167. }
  168. return &order, count
  169. }