package db import ( "applet/app/db/model" "applet/app/utils" "time" "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" { var goods []model.OrderGoods eg.Where("goods_type=0 and state=1").Find(&goods) ids := []int64{-1} for _, v := range goods { ids = append(ids, v.SkuId) } sess.And("wait_sorting_num >0").In("sku_id", ids) } 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("create_time asc,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, CreateTime: int(time.Now().Unix()), } 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, CreateTime: int(time.Now().Unix()), } insert, err := sess.Insert(&data) if insert == 0 || err != nil { return nil } } return &data }