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

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