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

143 行
3.8 KiB

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