面包店
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

db_sku.go 1.1 KiB

8 months ago
5 months ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package db
  2. import (
  3. "applet/app/db/model"
  4. "xorm.io/xorm"
  5. )
  6. func FindSkuByGoodsID(engine *xorm.Engine, goodsId string) ([]*model.Sku, error) {
  7. var skus []*model.Sku
  8. err := engine.Where("goods_id = ?", goodsId).Find(&skus)
  9. return skus, err
  10. }
  11. func GetMallSkuBySkuCode(engine *xorm.Engine, skuCode, goodsId string) (isHas bool, mm *model.Sku, err error) {
  12. isHas = false
  13. var m model.Sku
  14. isHas, err = engine.Where("sku_code=?", skuCode).And("goods_id!=?", goodsId).Get(&m)
  15. if err != nil {
  16. return isHas, &m, err
  17. }
  18. return isHas, &m, nil
  19. }
  20. func GetMallSkuBySkuId(engine *xorm.Engine, skuId, goodsId string) (isHas bool, mm *model.Sku, err error) {
  21. isHas = false
  22. var m model.Sku
  23. isHas, err = engine.Where("sku_id=?", skuId).And("goods_id=?", goodsId).Get(&m)
  24. if err != nil {
  25. return isHas, &m, err
  26. }
  27. return isHas, &m, nil
  28. }
  29. func GetSkuMore(engine *xorm.Engine, skuIds []int64) map[int64]model.Sku {
  30. skuMap := make(map[int64]model.Sku)
  31. var skus []model.Sku
  32. err := engine.Table("sku").In("sku_id", skuIds).Find(&skus)
  33. if err != nil {
  34. return skuMap
  35. }
  36. for _, v := range skus {
  37. skuMap[v.SkuId] = v
  38. }
  39. return skuMap
  40. }