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

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