76 lines
1.5 KiB
Go
76 lines
1.5 KiB
Go
package service
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
"yintai-api/app/common/dao"
|
|
err2 "yintai-api/app/common/err"
|
|
"yintai-api/app/common/model"
|
|
"yintai-api/app/common/service"
|
|
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
func Images(s []string) []string {
|
|
imgs := make([]string, 0)
|
|
for _, img := range s {
|
|
temp := service.NewQiniu().ObjectKey(img)
|
|
if temp != "" {
|
|
imgs = append(imgs, temp)
|
|
}
|
|
}
|
|
|
|
return imgs
|
|
}
|
|
|
|
func BizCateCreate(tx *gorm.DB, BizID, cateID int64, cateType string) error {
|
|
cate, err := dao.NewCategory(tx).GetWithType(cateID, cateType)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if cate == nil {
|
|
err2.NotEsxErr(fmt.Sprintf("category not exist: type [%s] id [%d]", cateType, cateID))
|
|
}
|
|
|
|
m := &model.CategoryRelation{
|
|
CategoryId: cateID,
|
|
Type: cateType,
|
|
BizId: BizID,
|
|
CreateTime: time.Now().Unix(),
|
|
}
|
|
|
|
if err = dao.NewCategoryRelation(tx).Create(m); err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func BizCateUpdate(tx *gorm.DB, BizID int64, cateID int64, cateType string) error {
|
|
cate, err := dao.NewCategory(tx).GetWithType(cateID, cateType)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if cate == nil {
|
|
err2.NotEsxErr(fmt.Sprintf("category not exist: type [%s] id [%d]", cateType, cateID))
|
|
}
|
|
|
|
if err = dao.NewCategoryRelation(tx).DeleteByCondition(BizID, cateType); err != nil {
|
|
return err
|
|
}
|
|
|
|
m := &model.CategoryRelation{
|
|
CategoryId: cateID,
|
|
Type: cateType,
|
|
BizId: BizID,
|
|
CreateTime: time.Now().Unix(),
|
|
}
|
|
if err = dao.NewCategoryRelation(tx).Create(m); err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|