面包店
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.
 
 
 
 
 

132 lines
3.5 KiB

  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["enterprise_name"] != "" {
  54. var enterprise []model.Enterprise
  55. eg.Where("name like ?", "%"+param["enterprise_name"]+"%").Find(&enterprise)
  56. oids := []int{-1}
  57. for _, v := range enterprise {
  58. oids = append(oids, v.Id)
  59. }
  60. sess.In("enterprise_id", oids)
  61. }
  62. size := utils.StrToInt(param["limit"])
  63. start := (utils.StrToInt(param["page"]) - 1) * size
  64. count, err := sess.Limit(size, start).OrderBy("id desc").FindAndCount(&order)
  65. if err != nil {
  66. return nil, count
  67. }
  68. return &order, count
  69. }
  70. func GetOrderListOutput(eg *xorm.Engine, param map[string]string) *[]model.Order {
  71. var order []model.Order
  72. sess := eg.Where("1=1")
  73. if param["phone"] != "" {
  74. sess.And("buy_phone like ?", "%"+param["phone"]+"%")
  75. }
  76. if param["oid"] != "" {
  77. sess.And("oid like ?", "%"+param["oid"]+"%")
  78. }
  79. if param["state"] != "" {
  80. sess.And("state =?", param["state"])
  81. }
  82. if param["ids"] != "" {
  83. sess.In("id", strings.Split(param["ids"], ","))
  84. }
  85. if param["enterprise_name"] != "" {
  86. var enterprise []model.Enterprise
  87. eg.Where("name like ?", "%"+param["enterprise_name"]+"%").Find(&enterprise)
  88. oids := []int{-1}
  89. for _, v := range enterprise {
  90. oids = append(oids, v.Id)
  91. }
  92. sess.In("enterprise_id", oids)
  93. }
  94. size := 10000
  95. start := (utils.StrToInt(param["page"]) - 1) * size
  96. if param["ids"] == "" {
  97. sess.Limit(size, start)
  98. }
  99. err := sess.OrderBy("id asc").Find(&order)
  100. if err != nil {
  101. return nil
  102. }
  103. return &order
  104. }
  105. func GetOrderListByIpad(eg *xorm.Engine, param map[string]string) (*[]model.Order, int64) {
  106. var order []model.Order
  107. sess := eg.Where("state!=5")
  108. if param["keyword"] != "" {
  109. var data []model.Enterprise
  110. eg.Where("name like ?", "%"+param["keyword"]+"%").Find(&data)
  111. ids := []string{"-1"}
  112. for _, v := range data {
  113. ids = append(ids, utils.IntToStr(v.Id))
  114. }
  115. sess.And("enterprise_id in (?) or oid like ?", php2go.Implode(",", ids), "%"+param["keyword"]+"%")
  116. }
  117. if param["state"] != "" {
  118. sess.And("state =?", param["state"])
  119. }
  120. size := utils.StrToInt(param["limit"])
  121. start := (utils.StrToInt(param["page"]) - 1) * size
  122. count, err := sess.Limit(size, start).OrderBy("id asc").FindAndCount(&order)
  123. if err != nil {
  124. return nil, count
  125. }
  126. return &order, count
  127. }