面包店
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

db_order_list.go 6.6 KiB

8 个月前
4 个月前
5 个月前
5 个月前
8 个月前
8 个月前
8 个月前
8 个月前
7 个月前
6 个月前
6 个月前
6 个月前
8 个月前
8 个月前
6 个月前
5 个月前
8 个月前
6 个月前
8 个月前
7 个月前
8 个月前
6 个月前
8 个月前
6 个月前
7 个月前
7 个月前
6 个月前
8 个月前
5 个月前
8 个月前
8 个月前
8 个月前
8 个月前
8 个月前
8 个月前
8 个月前
6 个月前
8 个月前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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 GetOrderByMore(sess *xorm.Session, args map[string]string) *[]model.Order {
  18. var order []model.Order
  19. sess1 := sess.Where("state!=5")
  20. if args["ids"] != "" {
  21. sess1.In("oid", strings.Split(args["ids"], ","))
  22. }
  23. err := sess1.Find(&order)
  24. if err != nil {
  25. return nil
  26. }
  27. return &order
  28. }
  29. func GetOrderByIds(eg *xorm.Engine, id []string) *[]model.Order {
  30. var order []model.Order
  31. err := eg.In("oid", id).Find(&order)
  32. if err != nil {
  33. return nil
  34. }
  35. return &order
  36. }
  37. func GetOrderByIdsSess(sess *xorm.Session, id []string) *[]model.Order {
  38. var order []model.Order
  39. err := sess.In("oid", id).Find(&order)
  40. if err != nil {
  41. return nil
  42. }
  43. return &order
  44. }
  45. func GetOrderByIdSess(sess *xorm.Session, id string) *model.Order {
  46. var order model.Order
  47. get, err := sess.Where("oid=?", id).Get(&order)
  48. if get == false || err != nil {
  49. return nil
  50. }
  51. return &order
  52. }
  53. func GetOrderGoodsBySkuId(eg *xorm.Engine, oid, skuId string) *model.OrderGoods {
  54. var order model.OrderGoods
  55. get, err := eg.Where("oid=? and sku_id=?", oid, skuId).Get(&order)
  56. if get == false || err != nil {
  57. return nil
  58. }
  59. return &order
  60. }
  61. func GetOrderGoodsBySkuIdSess(sess *xorm.Session, oid, skuId string) *model.OrderGoods {
  62. var order model.OrderGoods
  63. get, err := sess.Where("oid=? and sku_id=?", oid, skuId).Get(&order)
  64. if get == false || err != nil {
  65. return nil
  66. }
  67. return &order
  68. }
  69. func GetOrderList(eg *xorm.Engine, param map[string]string) (*[]model.Order, int64) {
  70. var order []model.Order
  71. sess := eg.Where("1=1")
  72. if param["phone"] != "" {
  73. sess.And("buy_phone like ?", "%"+param["phone"]+"%")
  74. }
  75. if param["oid"] != "" {
  76. sess.And("oid like ?", "%"+param["oid"]+"%")
  77. }
  78. if param["ord_no"] != "" {
  79. sess.And("ord_no like ?", "%"+param["ord_no"]+"%")
  80. }
  81. if param["state"] != "" {
  82. sess.And("state =?", param["state"])
  83. }
  84. if param["start_at"] != "" {
  85. sess.And("create_at >= ?", param["start_at"])
  86. }
  87. if param["end_at"] != "" {
  88. sess.And("create_at <= ?", param["end_at"])
  89. }
  90. if param["date"] != "" {
  91. param["date"] = strings.ReplaceAll(param["date"], "-", "")
  92. sess.And("date = ?", param["date"])
  93. }
  94. if param["make_date"] != "" {
  95. param["make_date"] = strings.ReplaceAll(param["make_date"], "-", "")
  96. sess.And("make_date = ?", param["make_date"])
  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. if param["inside_name"] != "" {
  108. var enterprise []model.Enterprise
  109. eg.Where("inside_name like ?", "%"+param["inside_name"]+"%").Find(&enterprise)
  110. oids := []int{-1}
  111. for _, v := range enterprise {
  112. oids = append(oids, v.Id)
  113. }
  114. sess.In("enterprise_id", oids)
  115. }
  116. size := utils.StrToInt(param["limit"])
  117. start := (utils.StrToInt(param["page"]) - 1) * size
  118. count, err := sess.Limit(size, start).OrderBy("id asc").FindAndCount(&order)
  119. if err != nil {
  120. return nil, count
  121. }
  122. return &order, count
  123. }
  124. func GetOrderListExport(eg *xorm.Engine, param map[string]string) (*[]model.Order, int64) {
  125. var order []model.Order
  126. sess := eg.Where("state!=5")
  127. if param["phone"] != "" {
  128. sess.And("buy_phone like ?", "%"+param["phone"]+"%")
  129. }
  130. if param["oid"] != "" {
  131. sess.And("oid like ?", "%"+param["oid"]+"%")
  132. }
  133. if param["state"] != "" {
  134. sess.And("state =?", param["state"])
  135. }
  136. if param["start_at"] != "" {
  137. sess.And("create_at >= ?", param["start_at"])
  138. }
  139. if param["end_at"] != "" {
  140. sess.And("create_at <= ?", param["end_at"])
  141. }
  142. if param["start_at_for_date"] != "" && param["start_at_for_date"] != "00010101" {
  143. sess.And("date >= ?", param["start_at_for_date"])
  144. }
  145. if param["end_at_for_date"] != "" && param["end_at_for_date"] != "00010101" {
  146. sess.And("date <= ?", param["end_at_for_date"])
  147. }
  148. if param["enterprise_id"] != "" && param["enterprise_id"] != "0" {
  149. sess.And("enterprise_id = ?", param["enterprise_id"])
  150. }
  151. if param["enterprise_name"] != "" {
  152. var enterprise []model.Enterprise
  153. eg.Where("name like ?", "%"+param["enterprise_name"]+"%").Find(&enterprise)
  154. oids := []int{-1}
  155. for _, v := range enterprise {
  156. oids = append(oids, v.Id)
  157. }
  158. sess.In("enterprise_id", oids)
  159. }
  160. count, err := sess.OrderBy("id asc").FindAndCount(&order)
  161. if err != nil {
  162. return nil, count
  163. }
  164. return &order, count
  165. }
  166. func GetOrderListOutput(eg *xorm.Engine, param map[string]string) *[]model.Order {
  167. var order []model.Order
  168. sess := eg.Where("state!=5")
  169. if param["phone"] != "" {
  170. sess.And("buy_phone like ?", "%"+param["phone"]+"%")
  171. }
  172. if param["oid"] != "" {
  173. sess.And("oid like ?", "%"+param["oid"]+"%")
  174. }
  175. if param["state"] != "" {
  176. sess.And("state =?", param["state"])
  177. }
  178. if param["ids"] != "" {
  179. sess.In("id", strings.Split(param["ids"], ","))
  180. }
  181. if param["start_at"] != "" {
  182. sess.And("create_at >= ?", param["start_at"])
  183. }
  184. if param["end_at"] != "" {
  185. sess.And("create_at <= ?", param["end_at"])
  186. }
  187. if param["date"] != "" {
  188. param["date"] = strings.ReplaceAll(param["date"], "-", "")
  189. sess.And("date = ?", param["date"])
  190. }
  191. if param["enterprise_name"] != "" {
  192. var enterprise []model.Enterprise
  193. eg.Where("name like ?", "%"+param["enterprise_name"]+"%").Find(&enterprise)
  194. oids := []int{-1}
  195. for _, v := range enterprise {
  196. oids = append(oids, v.Id)
  197. }
  198. sess.In("enterprise_id", oids)
  199. }
  200. err := sess.OrderBy("id asc").Find(&order)
  201. if err != nil {
  202. return nil
  203. }
  204. return &order
  205. }
  206. func GetOrderListByIpad(eg *xorm.Engine, param map[string]string) (*[]model.Order, int64) {
  207. var order []model.Order
  208. sess := eg.Where("state!=5")
  209. if param["now"] != "" {
  210. sess.And("make_date=?", param["now"])
  211. }
  212. if param["keyword"] != "" {
  213. var data []model.Enterprise
  214. eg.Where("name like ?", "%"+param["keyword"]+"%").Find(&data)
  215. ids := []string{"-1"}
  216. for _, v := range data {
  217. ids = append(ids, utils.IntToStr(v.Id))
  218. }
  219. sess.And("enterprise_id in ("+php2go.Implode(",", ids)+") or oid like ?", "%"+param["keyword"]+"%")
  220. }
  221. if param["state"] != "" && param["state"] != "1" {
  222. sess.And("state =?", param["state"])
  223. }
  224. if param["state"] == "1" {
  225. sess.In("state", []string{"1", "2"})
  226. }
  227. size := utils.StrToInt(param["limit"])
  228. start := (utils.StrToInt(param["page"]) - 1) * size
  229. count, err := sess.Limit(size, start).OrderBy("make_date asc,id asc").FindAndCount(&order)
  230. if err != nil {
  231. return nil, count
  232. }
  233. return &order, count
  234. }