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.
82 lines
2.0 KiB
82 lines
2.0 KiB
package jyy
|
|
|
|
import (
|
|
"path/filepath"
|
|
"recook/internal/static_path"
|
|
"recook/internal/v2/lib/excel"
|
|
"recook/internal/v2/model/recook/goods"
|
|
|
|
"git.oa00.com/go/mysql"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
type ArgsSaleEntry struct {
|
|
SkuID uint `json:"sku_id"`
|
|
Inventory uint `json:"inventory"`
|
|
Min uint `json:"min"`
|
|
Limit uint `json:"limit"`
|
|
}
|
|
|
|
type ArgsSaleUpdate struct {
|
|
SkuList []ArgsSaleEntry `json:"sku_list"`
|
|
}
|
|
|
|
func (o logic) UpdateSale(args ArgsSaleUpdate) error {
|
|
if err := mysql.Db.Transaction(func(tx *gorm.DB) error {
|
|
for _, v := range args.SkuList {
|
|
if err := tx.Table((&goods.RecookGoodsSkuModel{}).TableName()).Where("id = ?", v.SkuID).Updates(goods.RecookGoodsSkuModel{
|
|
SaleInventory: v.Inventory,
|
|
Min: int(v.Min),
|
|
Limit: int(v.Limit),
|
|
}).Error; err != nil {
|
|
return err
|
|
}
|
|
}
|
|
return nil
|
|
}); err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
type ArgsPublish struct {
|
|
GoodsID uint `json:"goods_id" validate:"required"`
|
|
Status uint `json:"status" validate:"oneof=0 1"`
|
|
}
|
|
|
|
func (o logic) UpdateStatus(args ArgsPublish) error {
|
|
if err := mysql.Db.Table((&goods.RecookGoodsInfoModel{}).TableName()).Where("id = ?", args.GoodsID).Updates(map[string]interface{}{
|
|
"sale_publish": args.Status,
|
|
}).Error; err != nil {
|
|
return err
|
|
}
|
|
var gs goods.RecookGoodsInfoModel
|
|
mysql.Db.Preload("SecondCategory").First(&gs, "id = ?", args.GoodsID)
|
|
gs.Publish()
|
|
return nil
|
|
}
|
|
|
|
type ArgsUploadSku struct {
|
|
Path string `json:"path"`
|
|
}
|
|
|
|
type GoodsFile struct {
|
|
GoodsID uint `excel:"name:goods_id"`
|
|
}
|
|
|
|
func (o logic) UploadSku(args ArgsUploadSku) error {
|
|
path := filepath.Join(static_path.Dir.Root, args.Path)
|
|
f1, err := excel.OpenFile(path)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
var gl []GoodsFile
|
|
f1.FromExcel(&gl, f1.GetSheetName(f1.GetActiveSheetIndex()))
|
|
ids := make([]uint, 0)
|
|
for _, v := range gl {
|
|
ids = append(ids, v.GoodsID)
|
|
}
|
|
return mysql.Db.Table((&goods.RecookGoodsInfoModel{}).TableName()).Where("id in (?) ", ids).Where("third_party_type != 3").Update("is_sale", 1).Error
|
|
}
|