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

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