面包店
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 5.4 KiB

8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
7 months ago
8 months ago
8 months ago
8 months ago
7 months ago
8 months ago
7 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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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["date"] != "" {
  60. param["date"] = strings.ReplaceAll(param["date"], "-", "")
  61. sess.And("date = ?", param["date"])
  62. }
  63. if param["enterprise_name"] != "" {
  64. var enterprise []model.Enterprise
  65. eg.Where("name like ?", "%"+param["enterprise_name"]+"%").Find(&enterprise)
  66. oids := []int{-1}
  67. for _, v := range enterprise {
  68. oids = append(oids, v.Id)
  69. }
  70. sess.In("enterprise_id", oids)
  71. }
  72. size := utils.StrToInt(param["limit"])
  73. start := (utils.StrToInt(param["page"]) - 1) * size
  74. count, err := sess.Limit(size, start).OrderBy("id desc").FindAndCount(&order)
  75. if err != nil {
  76. return nil, count
  77. }
  78. return &order, count
  79. }
  80. func GetOrderListExport(eg *xorm.Engine, param map[string]string) (*[]model.Order, int64) {
  81. var order []model.Order
  82. sess := eg.Where("1=1")
  83. if param["phone"] != "" {
  84. sess.And("buy_phone like ?", "%"+param["phone"]+"%")
  85. }
  86. if param["oid"] != "" {
  87. sess.And("oid like ?", "%"+param["oid"]+"%")
  88. }
  89. if param["state"] != "" {
  90. sess.And("state =?", param["state"])
  91. }
  92. if param["start_at"] != "" {
  93. sess.And("create_at >= ?", param["start_at"])
  94. }
  95. if param["end_at"] != "" {
  96. sess.And("create_at <= ?", param["end_at"])
  97. }
  98. if param["start_at_for_date"] != "" && param["start_at_for_date"] != "00010101" {
  99. sess.And("date >= ?", param["start_at_for_date"])
  100. }
  101. if param["end_at_for_date"] != "" && param["end_at_for_date"] != "00010101" {
  102. sess.And("date <= ?", param["end_at_for_date"])
  103. }
  104. if param["enterprise_id"] != "" && param["enterprise_id"] != "0" {
  105. sess.And("enterprise_id = ?", param["enterprise_id"])
  106. }
  107. if param["enterprise_name"] != "" {
  108. var enterprise []model.Enterprise
  109. eg.Where("name like ?", "%"+param["enterprise_name"]+"%").Find(&enterprise)
  110. oids := []int{-1}
  111. for _, v := range enterprise {
  112. oids = append(oids, v.Id)
  113. }
  114. sess.In("enterprise_id", oids)
  115. }
  116. count, err := sess.OrderBy("id desc").FindAndCount(&order)
  117. if err != nil {
  118. return nil, count
  119. }
  120. return &order, count
  121. }
  122. func GetOrderListOutput(eg *xorm.Engine, param map[string]string) *[]model.Order {
  123. var order []model.Order
  124. sess := eg.Where("1=1")
  125. if param["phone"] != "" {
  126. sess.And("buy_phone like ?", "%"+param["phone"]+"%")
  127. }
  128. if param["oid"] != "" {
  129. sess.And("oid like ?", "%"+param["oid"]+"%")
  130. }
  131. if param["state"] != "" {
  132. sess.And("state =?", param["state"])
  133. }
  134. if param["ids"] != "" {
  135. sess.In("id", strings.Split(param["ids"], ","))
  136. }
  137. if param["start_at"] != "" {
  138. sess.And("create_at >= ?", param["start_at"])
  139. }
  140. if param["end_at"] != "" {
  141. sess.And("create_at <= ?", param["end_at"])
  142. }
  143. if param["date"] != "" {
  144. param["date"] = strings.ReplaceAll(param["date"], "-", "")
  145. sess.And("date = ?", param["date"])
  146. }
  147. if param["enterprise_name"] != "" {
  148. var enterprise []model.Enterprise
  149. eg.Where("name like ?", "%"+param["enterprise_name"]+"%").Find(&enterprise)
  150. oids := []int{-1}
  151. for _, v := range enterprise {
  152. oids = append(oids, v.Id)
  153. }
  154. sess.In("enterprise_id", oids)
  155. }
  156. err := sess.OrderBy("id asc").Find(&order)
  157. if err != nil {
  158. return nil
  159. }
  160. return &order
  161. }
  162. func GetOrderListByIpad(eg *xorm.Engine, param map[string]string) (*[]model.Order, int64) {
  163. var order []model.Order
  164. sess := eg.Where("state!=5")
  165. if param["keyword"] != "" {
  166. var data []model.Enterprise
  167. eg.Where("name like ?", "%"+param["keyword"]+"%").Find(&data)
  168. ids := []string{"-1"}
  169. for _, v := range data {
  170. ids = append(ids, utils.IntToStr(v.Id))
  171. }
  172. sess.And("enterprise_id in ("+php2go.Implode(",", ids)+") or oid like ?", "%"+param["keyword"]+"%")
  173. }
  174. if param["state"] != "" && param["state"] != "1" {
  175. sess.And("state =?", param["state"])
  176. }
  177. if param["state"] == "1" {
  178. sess.In("state", []string{"1", "2"})
  179. }
  180. size := utils.StrToInt(param["limit"])
  181. start := (utils.StrToInt(param["page"]) - 1) * size
  182. count, err := sess.Limit(size, start).OrderBy("create_at desc,id desc").FindAndCount(&order)
  183. if err != nil {
  184. return nil, count
  185. }
  186. return &order, count
  187. }