|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- package db
-
- import (
- "applet/app/db/model"
- "applet/app/utils"
- "xorm.io/xorm"
- )
-
- func GetOrderGoodsMakeStockByIpad(eg *xorm.Engine, param map[string]string) (*[]model.OrderGoodsMakeStock, int64) {
- var order []model.OrderGoodsMakeStock
- sess := eg.Where("goods_type=0")
-
- if param["state"] == "1" {
- sess.And("wait_make_num >0")
- }
- if param["state"] == "2" {
- sess.And("wait_baking_num >0")
- }
- if param["state"] == "3" {
- sess.And("wait_sorting_num >0")
- }
- if param["keyword"] != "" {
- sess.And("goods_title like ?", "%"+param["keyword"]+"%")
- }
-
- size := utils.StrToInt(param["limit"])
- start := (utils.StrToInt(param["page"]) - 1) * size
- count, err := sess.Limit(size, start).OrderBy("make_date asc,id asc").FindAndCount(&order)
- if err != nil {
- return nil, count
- }
- return &order, count
- }
- func GetOrderGoodsMakeStockByBigData(eg *xorm.Engine, param map[string]string) (*[]model.OrderGoodsMakeStock, int64) {
- var order []model.OrderGoodsMakeStock
- sess := eg.Where("1=1")
- goodsSess := eg.Where("state!=5")
- if param["now"] != "" {
- sess.And("make_date=?", param["now"])
- goodsSess.And("make_date=?", param["now"])
- }
- if param["state"] == "1" {
- sess.And("wait_make_num >=0")
- } else {
- sess.And("goods_type =0")
- }
- if param["state"] == "2" {
- sess.And("wait_make_num =0 and wait_baking_num >=0")
- }
- if param["state"] == "3" {
- sess.And("wait_baking_num =0 and wait_sorting_num >=0")
- }
- if param["keyword"] != "" {
- sess.And("goods_title like ?", "%"+param["keyword"]+"%")
- }
- var goodsData []model.OrderGoods
- goodsSess.Find(&goodsData)
- gids := make([]int64, 0)
- skuids := make([]int64, 0)
- gids = append(gids, -1)
- skuids = append(skuids, -1)
- if len(goodsData) > 0 {
- for _, v := range goodsData {
- gids = append(gids, v.GoodsId)
- skuids = append(skuids, v.SkuId)
- }
- }
- sess.In("gid", gids)
- sess.In("sku_id", skuids)
- count, err := sess.OrderBy("id asc").FindAndCount(&order)
- if err != nil {
- return nil, count
- }
- return &order, count
- }
-
- func GetOrderGoodsMakeStock(sess *xorm.Session, gid, skuId int64) *model.OrderGoodsMakeStock {
- var data model.OrderGoodsMakeStock
- get, err := sess.Where("gid=? and sku_id=?", gid, skuId).Get(&data)
- if err != nil {
- return nil
- }
- if get == false {
- data = model.OrderGoodsMakeStock{
- Gid: gid,
- SkuId: skuId,
- }
- insert, err := sess.Insert(&data)
- if insert == 0 || err != nil {
- return nil
- }
- }
- return &data
- }
- func GetOrderGoodsMakeStockById(sess *xorm.Session, id int64) *model.OrderGoodsMakeStock {
- var data model.OrderGoodsMakeStock
- get, err := sess.Where("id=? ", id).Get(&data)
- if err != nil || get == false {
- return nil
- }
- return &data
- }
- func GetOrderGoodsMakeStockAll(sess *xorm.Session, gid, skuId int64, goodsType int) *model.OrderGoodsMakeStock {
- var data model.OrderGoodsMakeStock
- get, err := sess.Where("gid=? and sku_id=? and goods_type=?", gid, skuId, goodsType).Get(&data)
- if err != nil || get == false {
- return nil
- }
-
- return &data
- }
- func GetOrderGoodsMakeStockAllByDate(sess *xorm.Session, gid, skuId int64, goodsType int, date int) *model.OrderGoodsMakeStock {
- var data model.OrderGoodsMakeStock
- get, err := sess.Where("gid=? and sku_id=? and goods_type=? and make_date=?", gid, skuId, goodsType, date).Get(&data)
- if err != nil || get == false {
- return nil
- }
-
- return &data
- }
- func GetOrderGoodsMakeStockByDate(sess *xorm.Session, gid, skuId int64, date int) *model.OrderGoodsMakeStock {
- var data model.OrderGoodsMakeStock
- get, err := sess.Where("gid=? and sku_id=? and make_date=?", gid, skuId, date).Get(&data)
- if err != nil {
- return nil
- }
- if get == false {
- data = model.OrderGoodsMakeStock{
- Gid: gid,
- SkuId: skuId,
- MakeDate: date,
- }
- insert, err := sess.Insert(&data)
- if insert == 0 || err != nil {
- return nil
- }
- }
- return &data
- }
|