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

187 lines
5.1 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["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["start_at_for_date"] != "" && param["start_at_for_date"] != "00010101" {
  95. sess.And("date >= ?", param["start_at_for_date"])
  96. }
  97. if param["end_at_for_date"] != "" && param["end_at_for_date"] != "00010101" {
  98. sess.And("date <= ?", param["end_at_for_date"])
  99. }
  100. if param["enterprise_id"] != "" && param["enterprise_id"] != "0" {
  101. sess.And("enterprise_id = ?", param["enterprise_id"])
  102. }
  103. if param["enterprise_name"] != "" {
  104. var enterprise []model.Enterprise
  105. eg.Where("name like ?", "%"+param["enterprise_name"]+"%").Find(&enterprise)
  106. oids := []int{-1}
  107. for _, v := range enterprise {
  108. oids = append(oids, v.Id)
  109. }
  110. sess.In("enterprise_id", oids)
  111. }
  112. count, err := sess.OrderBy("id desc").FindAndCount(&order)
  113. if err != nil {
  114. return nil, count
  115. }
  116. return &order, count
  117. }
  118. func GetOrderListOutput(eg *xorm.Engine, param map[string]string) *[]model.Order {
  119. var order []model.Order
  120. sess := eg.Where("1=1")
  121. if param["phone"] != "" {
  122. sess.And("buy_phone like ?", "%"+param["phone"]+"%")
  123. }
  124. if param["oid"] != "" {
  125. sess.And("oid like ?", "%"+param["oid"]+"%")
  126. }
  127. if param["state"] != "" {
  128. sess.And("state =?", param["state"])
  129. }
  130. if param["ids"] != "" {
  131. sess.In("id", strings.Split(param["ids"], ","))
  132. }
  133. if param["start_at"] != "" {
  134. sess.And("create_at >= ?", param["start_at"])
  135. }
  136. if param["end_at"] != "" {
  137. sess.And("create_at <= ?", param["end_at"])
  138. }
  139. if param["enterprise_name"] != "" {
  140. var enterprise []model.Enterprise
  141. eg.Where("name like ?", "%"+param["enterprise_name"]+"%").Find(&enterprise)
  142. oids := []int{-1}
  143. for _, v := range enterprise {
  144. oids = append(oids, v.Id)
  145. }
  146. sess.In("enterprise_id", oids)
  147. }
  148. err := sess.OrderBy("id asc").Find(&order)
  149. if err != nil {
  150. return nil
  151. }
  152. return &order
  153. }
  154. func GetOrderListByIpad(eg *xorm.Engine, param map[string]string) (*[]model.Order, int64) {
  155. var order []model.Order
  156. sess := eg.Where("state!=5")
  157. if param["keyword"] != "" {
  158. var data []model.Enterprise
  159. eg.Where("name like ?", "%"+param["keyword"]+"%").Find(&data)
  160. ids := []string{"-1"}
  161. for _, v := range data {
  162. ids = append(ids, utils.IntToStr(v.Id))
  163. }
  164. sess.And("enterprise_id in ("+php2go.Implode(",", ids)+") or oid like ?", "%"+param["keyword"]+"%")
  165. }
  166. if param["state"] != "" && param["state"] != "1" {
  167. sess.And("state =?", param["state"])
  168. }
  169. if param["state"] == "1" {
  170. sess.In("state", []string{"1", "2"})
  171. }
  172. size := utils.StrToInt(param["limit"])
  173. start := (utils.StrToInt(param["page"]) - 1) * size
  174. count, err := sess.Limit(size, start).OrderBy("create_at desc,id desc").FindAndCount(&order)
  175. if err != nil {
  176. return nil, count
  177. }
  178. return &order, count
  179. }