面包店
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

db_order_list.go 5.9 KiB

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