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