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

96 lines
2.6 KiB

  1. package db
  2. import (
  3. "applet/app/db/model"
  4. "applet/app/utils"
  5. "github.com/syyongx/php2go"
  6. "xorm.io/xorm"
  7. )
  8. func GetOrderById(eg *xorm.Engine, id string) *model.Order {
  9. var order model.Order
  10. get, err := eg.Where("oid=?", id).Get(&order)
  11. if get == false || err != nil {
  12. return nil
  13. }
  14. return &order
  15. }
  16. func GetOrderByIdSess(sess *xorm.Session, id string) *model.Order {
  17. var order model.Order
  18. get, err := sess.Where("oid=?", id).Get(&order)
  19. if get == false || err != nil {
  20. return nil
  21. }
  22. return &order
  23. }
  24. func GetOrderGoodsBySkuId(eg *xorm.Engine, oid, skuId string) *model.OrderGoods {
  25. var order model.OrderGoods
  26. get, err := eg.Where("oid=? and sku_id=?", oid, skuId).Get(&order)
  27. if get == false || err != nil {
  28. return nil
  29. }
  30. return &order
  31. }
  32. func GetOrderGoodsBySkuIdSess(sess *xorm.Session, oid, skuId string) *model.OrderGoods {
  33. var order model.OrderGoods
  34. get, err := sess.Where("oid=? and sku_id=?", oid, skuId).Get(&order)
  35. if get == false || err != nil {
  36. return nil
  37. }
  38. return &order
  39. }
  40. func GetOrderList(eg *xorm.Engine, param map[string]string) (*[]model.Order, int64) {
  41. var order []model.Order
  42. sess := eg.Where("1=1")
  43. if param["phone"] != "" {
  44. sess.And("buy_phone like ?", "%"+param["phone"]+"%")
  45. }
  46. if param["oid"] != "" {
  47. sess.And("oid like ?", "%"+param["oid"]+"%")
  48. }
  49. if param["state"] != "" {
  50. sess.And("state =?", param["state"])
  51. }
  52. if param["enterprise_name"] != "" {
  53. var enterprise []model.Enterprise
  54. eg.Where("name like ?", "%"+param["enterprise_name"]+"%").Find(&enterprise)
  55. oids := []int{-1}
  56. for _, v := range enterprise {
  57. oids = append(oids, v.Id)
  58. }
  59. sess.In("enterprise_id", oids)
  60. }
  61. size := utils.StrToInt(param["limit"])
  62. start := (utils.StrToInt(param["page"]) - 1) * size
  63. count, err := sess.Limit(size, start).OrderBy("id desc").FindAndCount(&order)
  64. if err != nil {
  65. return nil, count
  66. }
  67. return &order, count
  68. }
  69. func GetOrderListByIpad(eg *xorm.Engine, param map[string]string) (*[]model.Order, int64) {
  70. var order []model.Order
  71. sess := eg.Where("state!=5")
  72. if param["keyword"] != "" {
  73. var data []model.Enterprise
  74. eg.Where("name like ?", "%"+param["keyword"]+"%").Find(&data)
  75. ids := []string{"-1"}
  76. for _, v := range data {
  77. ids = append(ids, utils.IntToStr(v.Id))
  78. }
  79. sess.And("enterprise_id in (?) or oid like ?", php2go.Implode(",", ids), "%"+param["keyword"]+"%")
  80. }
  81. if param["state"] != "" {
  82. sess.And("state =?", param["state"])
  83. }
  84. size := utils.StrToInt(param["limit"])
  85. start := (utils.StrToInt(param["page"]) - 1) * size
  86. count, err := sess.Limit(size, start).OrderBy("id asc").FindAndCount(&order)
  87. if err != nil {
  88. return nil, count
  89. }
  90. return &order, count
  91. }