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

79 lines
2.0 KiB

  1. package db
  2. import (
  3. "applet/app/db/model"
  4. "applet/app/utils"
  5. "xorm.io/xorm"
  6. )
  7. func GetOrderById(eg *xorm.Engine, id string) *model.Order {
  8. var order model.Order
  9. get, err := eg.Where("oid=?", id).Get(&order)
  10. if get == false || err != nil {
  11. return nil
  12. }
  13. return &order
  14. }
  15. func GetOrderGoodsById(eg *xorm.Engine, id string) *model.OrderGoods {
  16. var order model.OrderGoods
  17. get, err := eg.Where("id=?", id).Get(&order)
  18. if get == false || err != nil {
  19. return nil
  20. }
  21. return &order
  22. }
  23. func GetOrderGoodsBySkuId(eg *xorm.Engine, oid, skuId string) *model.OrderGoods {
  24. var order model.OrderGoods
  25. get, err := eg.Where("oid=? and sku_id=?", oid, skuId).Get(&order)
  26. if get == false || err != nil {
  27. return nil
  28. }
  29. return &order
  30. }
  31. func GetOrderGoodsByIdSess(sess *xorm.Session, id string) *model.OrderGoods {
  32. var order model.OrderGoods
  33. get, err := sess.Where("id=?", id).Get(&order)
  34. if get == false || err != nil {
  35. return nil
  36. }
  37. return &order
  38. }
  39. func GetOrderGoodsBySkuIdSess(sess *xorm.Session, oid, skuId string) *model.OrderGoods {
  40. var order model.OrderGoods
  41. get, err := sess.Where("oid=? and sku_id=?", oid, skuId).Get(&order)
  42. if get == false || err != nil {
  43. return nil
  44. }
  45. return &order
  46. }
  47. func GetOrderList(eg *xorm.Engine, param map[string]string) (*[]model.Order, int64) {
  48. var order []model.Order
  49. sess := eg.Where("1=1")
  50. if param["phone"] != "" {
  51. sess.And("buy_phone like ?", "%"+param["phone"]+"%")
  52. }
  53. if param["oid"] != "" {
  54. sess.And("oid like ?", "%"+param["oid"]+"%")
  55. }
  56. if param["state"] != "" {
  57. sess.And("state =", param["state"])
  58. }
  59. if param["goods_title"] != "" {
  60. var orderGoods []model.OrderGoods
  61. eg.Where("goods_title like ?", "%"+param["goods_title"]+"%").Find(&orderGoods)
  62. oids := []int64{-1}
  63. for _, v := range orderGoods {
  64. oids = append(oids, v.Oid)
  65. }
  66. sess.In("oid", 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. }