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

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