面包店
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

140 lines
3.7 KiB

  1. package db
  2. import (
  3. "applet/app/db/model"
  4. "applet/app/utils"
  5. "xorm.io/xorm"
  6. )
  7. func GetOrderGoodsMakeStockByIpad(eg *xorm.Engine, param map[string]string) (*[]model.OrderGoodsMakeStock, int64) {
  8. var order []model.OrderGoodsMakeStock
  9. sess := eg.Where("goods_type=0")
  10. if param["state"] == "1" {
  11. sess.And("wait_make_num >0")
  12. }
  13. if param["state"] == "2" {
  14. sess.And("wait_baking_num >0")
  15. }
  16. if param["state"] == "3" {
  17. sess.And("wait_sorting_num >0")
  18. }
  19. if param["keyword"] != "" {
  20. sess.And("goods_title like ?", "%"+param["keyword"]+"%")
  21. }
  22. size := utils.StrToInt(param["limit"])
  23. start := (utils.StrToInt(param["page"]) - 1) * size
  24. count, err := sess.Limit(size, start).OrderBy("make_date asc,id asc").FindAndCount(&order)
  25. if err != nil {
  26. return nil, count
  27. }
  28. return &order, count
  29. }
  30. func GetOrderGoodsMakeStockByBigData(eg *xorm.Engine, param map[string]string) (*[]model.OrderGoodsMakeStock, int64) {
  31. var order []model.OrderGoodsMakeStock
  32. sess := eg.Where("1=1")
  33. goodsSess := eg.Where("state!=5")
  34. if param["now"] != "" {
  35. sess.And("make_date=?", param["now"])
  36. goodsSess.And("make_date=?", param["now"])
  37. }
  38. if param["state"] == "1" {
  39. sess.And("wait_make_num >=0")
  40. } else {
  41. sess.And("goods_type =0")
  42. }
  43. if param["state"] == "2" {
  44. sess.And("wait_make_num =0 and wait_baking_num >=0")
  45. }
  46. if param["state"] == "3" {
  47. sess.And("wait_baking_num =0 and wait_sorting_num >=0")
  48. }
  49. if param["keyword"] != "" {
  50. sess.And("goods_title like ?", "%"+param["keyword"]+"%")
  51. }
  52. var goodsData []model.OrderGoods
  53. goodsSess.Find(&goodsData)
  54. gids := make([]int64, 0)
  55. skuids := make([]int64, 0)
  56. gids = append(gids, -1)
  57. skuids = append(skuids, -1)
  58. if len(goodsData) > 0 {
  59. for _, v := range goodsData {
  60. gids = append(gids, v.GoodsId)
  61. skuids = append(skuids, v.SkuId)
  62. }
  63. }
  64. sess.In("gid", gids)
  65. sess.In("sku_id", skuids)
  66. count, err := sess.OrderBy("id asc").FindAndCount(&order)
  67. if err != nil {
  68. return nil, count
  69. }
  70. return &order, count
  71. }
  72. func GetOrderGoodsMakeStock(sess *xorm.Session, gid, skuId int64) *model.OrderGoodsMakeStock {
  73. var data model.OrderGoodsMakeStock
  74. get, err := sess.Where("gid=? and sku_id=?", gid, skuId).Get(&data)
  75. if err != nil {
  76. return nil
  77. }
  78. if get == false {
  79. data = model.OrderGoodsMakeStock{
  80. Gid: gid,
  81. SkuId: skuId,
  82. }
  83. insert, err := sess.Insert(&data)
  84. if insert == 0 || err != nil {
  85. return nil
  86. }
  87. }
  88. return &data
  89. }
  90. func GetOrderGoodsMakeStockById(sess *xorm.Session, id int64) *model.OrderGoodsMakeStock {
  91. var data model.OrderGoodsMakeStock
  92. get, err := sess.Where("id=? ", id).Get(&data)
  93. if err != nil || get == false {
  94. return nil
  95. }
  96. return &data
  97. }
  98. func GetOrderGoodsMakeStockAll(sess *xorm.Session, gid, skuId int64, goodsType int) *model.OrderGoodsMakeStock {
  99. var data model.OrderGoodsMakeStock
  100. get, err := sess.Where("gid=? and sku_id=? and goods_type=?", gid, skuId, goodsType).Get(&data)
  101. if err != nil || get == false {
  102. return nil
  103. }
  104. return &data
  105. }
  106. func GetOrderGoodsMakeStockAllByDate(sess *xorm.Session, gid, skuId int64, goodsType int, date int) *model.OrderGoodsMakeStock {
  107. var data model.OrderGoodsMakeStock
  108. get, err := sess.Where("gid=? and sku_id=? and goods_type=? and make_date=?", gid, skuId, goodsType, date).Get(&data)
  109. if err != nil || get == false {
  110. return nil
  111. }
  112. return &data
  113. }
  114. func GetOrderGoodsMakeStockByDate(sess *xorm.Session, gid, skuId int64, date int) *model.OrderGoodsMakeStock {
  115. var data model.OrderGoodsMakeStock
  116. get, err := sess.Where("gid=? and sku_id=? and make_date=?", gid, skuId, date).Get(&data)
  117. if err != nil {
  118. return nil
  119. }
  120. if get == false {
  121. data = model.OrderGoodsMakeStock{
  122. Gid: gid,
  123. SkuId: skuId,
  124. MakeDate: date,
  125. }
  126. insert, err := sess.Insert(&data)
  127. if insert == 0 || err != nil {
  128. return nil
  129. }
  130. }
  131. return &data
  132. }