package dao

import (
	"demo/configs"
	"demo/data/domain"
)

func DeleteSkuByCommodityAreaId(id int64) error {
	ca := domain.GoodsCommodityArea{}
	_, err := configs.Engine.Where("id = ?", id).Delete(&ca)
	if err != nil {
		return err
	}
	sku := domain.GoodsSku{}
	_, err = configs.Engine.Where("commodity_area_id = ? ", id).Delete(&sku)
	if err != nil {
		return err
	}
	return nil
}

func SortSkuList(list []domain.SkuSort) error {
	for _, v := range list {
		_, err := configs.Engine.Where("id = ?", v.Id).Cols("sort").Update(&domain.GoodsSku{Sort: v.Sort})
		if err != nil {
			return err
		}
	}
	return nil
}
