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

db_order_goods_list.go 4.7 KiB

8 months ago
5 months ago
8 months ago
6 months ago
7 months ago
8 months ago
8 months ago
6 months ago
8 months ago
8 months ago
6 months ago
5 months ago
5 months ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. package db
  2. import (
  3. "applet/app/db/model"
  4. "applet/app/utils"
  5. "fmt"
  6. "github.com/syyongx/php2go"
  7. "strings"
  8. "xorm.io/xorm"
  9. )
  10. func GetOrderGoodsListByIpad(eg *xorm.Engine, param map[string]string) (*[]model.OrderGoods, int64) {
  11. var order []model.OrderGoods
  12. sess := eg.Where("state!=5 and goods_type=0")
  13. if param["sorting"] == "1" {
  14. sess.And("state!=4")
  15. }
  16. if param["oid"] != "" {
  17. sess.And("oid = ?", param["oid"])
  18. }
  19. if param["gid"] != "" {
  20. sess.And("goods_id = ?", param["gid"])
  21. }
  22. if param["sku_id"] != "" {
  23. sess.And("sku_id = ?", param["sku_id"])
  24. }
  25. if param["state"] != "" {
  26. sess.And("state =?", param["state"])
  27. }
  28. if param["keyword"] != "" {
  29. sess.And("goods_title like ?", "%"+param["keyword"]+"%")
  30. }
  31. size := utils.StrToInt(param["limit"])
  32. start := (utils.StrToInt(param["page"]) - 1) * size
  33. count, err := sess.Limit(size, start).OrderBy("make_date asc,id asc").FindAndCount(&order)
  34. if err != nil {
  35. return nil, count
  36. }
  37. return &order, count
  38. }
  39. func GetOrderGoodsById(eg *xorm.Engine, id string) *model.OrderGoods {
  40. var order model.OrderGoods
  41. get, err := eg.Where("id=?", id).Get(&order)
  42. if get == false || err != nil {
  43. return nil
  44. }
  45. return &order
  46. }
  47. func GetOrderGoodsByIds(sess *xorm.Session, id string) *[]model.OrderGoods {
  48. var order []model.OrderGoods
  49. err := sess.Where("oid=?", id).Find(&order)
  50. if err != nil {
  51. return nil
  52. }
  53. return &order
  54. }
  55. func GetOrderGoodsByIdSess(sess *xorm.Session, id string) *model.OrderGoods {
  56. var order model.OrderGoods
  57. get, err := sess.Where("id=?", id).Get(&order)
  58. if get == false || err != nil {
  59. return nil
  60. }
  61. return &order
  62. }
  63. func GetOrderGoods(sess *xorm.Session, oid, gid, skuId string) *model.OrderGoods {
  64. var data model.OrderGoods
  65. get, err := sess.Where("oid=? and goods_id=? and sku_id=?", oid, gid, skuId).Get(&data)
  66. if err != nil || get == false {
  67. return nil
  68. }
  69. return &data
  70. }
  71. func GetOrderGoodsAll(sess *xorm.Session, oid string) *[]model.OrderGoods {
  72. var order []model.OrderGoods
  73. err := sess.Where("oid=? and goods_type=0", oid).Find(&order)
  74. if err != nil {
  75. return nil
  76. }
  77. return &order
  78. }
  79. func GetOrderGoodsByOid(eg *xorm.Engine, oid []int64) *[]model.OrderGoods {
  80. var order []model.OrderGoods
  81. err := eg.In("oid", oid).And("goods_type=0").Find(&order)
  82. if err != nil {
  83. return nil
  84. }
  85. return &order
  86. }
  87. func GetOrderGoodsList(eg *xorm.Engine, param map[string]string) ([]map[string]string, int64) {
  88. where := "goods_type=0"
  89. if param["phone"] != "" {
  90. where += " and o.buy_phone like '%" + param["phone"] + "%'"
  91. }
  92. if param["oid"] != "" {
  93. where += " and o.oid like '%" + param["oid"] + "%'"
  94. }
  95. if param["ord_no"] != "" {
  96. where += " and o.ord_no like '%" + param["ord_no"] + "%'"
  97. }
  98. if param["goods_title"] != "" {
  99. where += " and og.goods_title like '%" + param["goods_title"] + "%'"
  100. }
  101. if param["state"] != "" {
  102. where += " and o.state =" + param["state"]
  103. }
  104. if param["start_at"] != "" {
  105. where += " and o.create_at >='" + param["start_at"] + "'"
  106. }
  107. if param["end_at"] != "" {
  108. where += " and o.create_at <='" + param["end_at"] + "'"
  109. }
  110. if param["date"] != "" {
  111. param["date"] = strings.ReplaceAll(param["date"], "-", "")
  112. where += " and o.date ='" + param["date"] + "'"
  113. }
  114. if param["make_date"] != "" {
  115. param["make_date"] = strings.ReplaceAll(param["make_date"], "-", "")
  116. where += " and o.make_date ='" + param["make_date"] + "'"
  117. }
  118. if param["enterprise_name"] != "" {
  119. var enterprise []model.Enterprise
  120. eg.Where("name like ?", "%"+param["enterprise_name"]+"%").Find(&enterprise)
  121. oids := []string{"-1"}
  122. for _, v := range enterprise {
  123. oids = append(oids, utils.IntToStr(v.Id))
  124. }
  125. where += " and o.enterprise_id in(" + php2go.Implode(",", oids) + ")"
  126. }
  127. if param["inside_name"] != "" {
  128. var enterprise []model.Enterprise
  129. eg.Where("inside_name like ?", "%"+param["inside_name"]+"%").Find(&enterprise)
  130. oids := []string{"-1"}
  131. for _, v := range enterprise {
  132. oids = append(oids, utils.IntToStr(v.Id))
  133. }
  134. where += " and o.enterprise_id in(" + php2go.Implode(",", oids) + ")"
  135. }
  136. size := utils.StrToInt(param["limit"])
  137. start := (utils.StrToInt(param["page"]) - 1) * size
  138. sql := "SELECT %s FROM order_goods og left join `order` o on o.oid=og.oid where %s order by og.id desc %s"
  139. sql1 := fmt.Sprintf(sql, "og.deduct_memo,og.oid,og.goods_id,og.sku_id,og.num,og.price,og.state,og.sku_code,og.goods_title,og.sku,og.success_num,og.memo,og.time,og.admin_id,og.enterprise_id,og.deduct_memo,og.ord_no,og.make_date,o.create_at,o.buy_info,o.buy_phone", where, "limit "+utils.IntToStr(start)+","+utils.IntToStr(size))
  140. sql2 := fmt.Sprintf(sql, "COUNT(*) as count", where, "")
  141. nativeString, _ := QueryNativeString(eg, sql2)
  142. count := 0
  143. for _, v := range nativeString {
  144. count = utils.StrToInt(v["count"])
  145. }
  146. nativeString1, _ := QueryNativeString(eg, sql1)
  147. return nativeString1, int64(count)
  148. }