package manage

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

func GetArticleById(id int64) (domain.Article, error) {
	var article domain.Article
	_, err := configs.Engine.Table("article").Where("id = ?", id).Get(&article)
	if err != nil {
		return article, err
	}
	return article, nil
}

func GetArticleListInId(ids []int64) ([]domain.Article, error) {
	rows, err := configs.Engine.Table("article").In("id", ids).Rows(&domain.Article{})
	if err != nil {
		return make([]domain.Article, 0), err
	}
	defer rows.Close()
	var list []domain.Article
	for rows.Next() {
		var u domain.Article
		rows.Scan(&u)
		list = append(list, u)
	}
	return list, nil
}

func GetArticleList(article domain.Article, pageNum, pageSize int) (vo.BaseListVo, error) {
	var arr []domain.Article
	Count, err := configs.Engine.Table("article").Limit(pageSize, (pageNum-1)*pageSize).FindAndCount(&arr, &article)
	var vo vo.BaseListVo
	if err != nil {
		return vo, err
	}
	if err != nil {
		return vo, err
	}
	vo.PageNum = pageNum
	vo.PageSize = pageSize
	vo.List = make([]any, len(arr))
	for i, v := range arr {
		vo.List[i] = v
	}
	vo.Total = int(Count)
	return vo, nil
}
func Get2ArticleList(query domain.ArticleQuery, pageNum, pageSize int) (vo.BaseListVo, error) {
	var arr []domain.Article
	session := configs.Engine.Table("article").Limit(pageSize, (pageNum-1)*pageSize)

	if query.Id != 0 {
		session.Where("id = ?", query.Id)
	}

	if query.ArticleTitle != "" {
		session.Where("article_title like ?", "%"+query.ArticleTitle+"%")
	}

	if query.ArticleContent != "" {
		session.Where("article_content like ?", "%"+query.ArticleContent+"%")
	}

	if query.State != "" {
		session.Where("state = ?", query.State)
	}

	if query.ArticleTagIds != "" {
		session.Where("article_tag_ids = ?", query.ArticleTagIds)
	}

	if query.ArticleTopicId != 0 {
		session.Where("article_topic_id = ?", query.ArticleTopicId)
	}

	if query.Image != "" {
		session.Where("image = ?", query.Image)
	}

	if query.PublishTimeStart != "" || query.PublishTimeEnd != "" {
		session.Where("publish_time between ? and ?", query.PublishTimeStart, query.PublishTimeEnd)
	}

	if query.EyeFillStart != 0 || query.EyeFillEnd != 0 {
		session.Where("eye_fill between ? and ?", query.EyeFillStart, query.EyeFillEnd)
	}

	if query.LikeCountStart != 0 || query.LikeCountEnd != 0 {
		session.Where("like_count between ? and ?", query.LikeCountStart, query.LikeCountEnd)
	}

	if query.CreateBy != "" {
		session.Where("create_by = ?", query.CreateBy)
	}

	if query.CreateTime != "" {
		session.Where("create_time = ?", query.CreateTime)
	}

	if query.UpdateBy != "" {
		session.Where("update_by = ?", query.UpdateBy)
	}

	if query.UpdateTime != "" {
		session.Where("update_time = ?", query.UpdateTime)
	}

	if query.ArticleDesc != "" {
		session.Where("article_desc like ?", "%"+query.ArticleDesc+"%")
	}
	Count, err := session.FindAndCount(&arr)
	var vo vo.BaseListVo
	if err != nil {
		return vo, err
	}
	if err != nil {
		return vo, err
	}
	vo.PageNum = pageNum
	vo.PageSize = pageSize
	vo.List = make([]any, len(arr))
	for i, v := range arr {
		vo.List[i] = v
	}
	vo.Total = int(Count)
	return vo, nil
}
func SaveArticle(article *domain.Article) (domain.Article, error) {
	_, err := configs.Engine.Table("article").Insert(&article)
	if err != nil {
		return *article, err
	}
	return *article, nil
}

func SetArticle(articleMap map[string]interface{}, id int64) (domain.Article, bool, error) {
	var article domain.Article
	_, err := configs.Engine.Table("article").Where("id = ?", id).Update(articleMap)
	if err != nil {
		return article, false, err
	}
	return article, true, nil
}

func DeleteArticle(id int64) bool {
	var article domain.Article
	i, err := configs.Engine.Table("article").Where("id = ?", id).Delete(&article)
	if err != nil {
		return false
	}
	return i > 0
}

func GetArticleTagById(id int64) (domain.ArticleTag, error) {
	var articleTag domain.ArticleTag
	_, err := configs.Engine.Table("article_tag").Where("id = ?", id).Get(&articleTag)
	if err != nil {
		return articleTag, err
	}
	return articleTag, nil
}

func GetArticleTagListInId(ids []int64) ([]domain.ArticleTag, error) {
	rows, err := configs.Engine.Table("article_tag").In("id", ids).Rows(&domain.ArticleTag{})
	if err != nil {
		return make([]domain.ArticleTag, 0), err
	}
	defer rows.Close()
	var list []domain.ArticleTag
	for rows.Next() {
		var u domain.ArticleTag
		rows.Scan(&u)
		list = append(list, u)
	}
	return list, nil
}

func GetArticleTagList(articleTag domain.ArticleTag, pageNum, pageSize int) (vo.BaseListVo, error) {
	var arr []domain.ArticleTag
	Count, err := configs.Engine.Table("article_tag").Limit(pageSize, (pageNum-1)*pageSize).FindAndCount(&arr, &articleTag)
	var vo vo.BaseListVo
	if err != nil {
		return vo, err
	}
	if err != nil {
		return vo, err
	}
	vo.PageNum = pageNum
	vo.PageSize = pageSize
	vo.List = make([]any, len(arr))
	for i, v := range arr {
		vo.List[i] = v
	}
	vo.Total = int(Count)
	return vo, nil
}
func Get2ArticleTagList(query domain.ArticleTagQuery, pageNum, pageSize int) (vo.BaseListVo, error) {
	var arr []domain.ArticleTag
	session := configs.Engine.Table("article_tag").Limit(pageSize, (pageNum-1)*pageSize)

	if query.Id != 0 {
		session.Where("id = ?", query.Id)
	}

	if query.TagName != "" {
		session.Where("tag_name = ?", query.TagName)
	}

	if query.TagDesc != "" {
		session.Where("tag_desc like ?", "%"+query.TagDesc+"%")
	}

	if query.TagTextColor != "" {
		session.Where("tag_text_color = ?", query.TagTextColor)
	}

	if query.TagBackgroundColor != "" {
		session.Where("tag_background_color = ?", query.TagBackgroundColor)
	}
	Count, err := session.FindAndCount(&arr)
	var vo vo.BaseListVo
	if err != nil {
		return vo, err
	}
	if err != nil {
		return vo, err
	}
	vo.PageNum = pageNum
	vo.PageSize = pageSize
	vo.List = make([]any, len(arr))
	for i, v := range arr {
		vo.List[i] = v
	}
	vo.Total = int(Count)
	return vo, nil
}
func SaveArticleTag(articleTag *domain.ArticleTag) (domain.ArticleTag, error) {
	_, err := configs.Engine.Table("article_tag").Insert(&articleTag)
	if err != nil {
		return *articleTag, err
	}
	return *articleTag, nil
}

func SetArticleTag(articleTagMap map[string]interface{}, id int64) (domain.ArticleTag, bool, error) {
	var articleTag domain.ArticleTag
	_, err := configs.Engine.Table("article_tag").Where("id = ?", id).Update(articleTagMap)
	if err != nil {
		return articleTag, false, err
	}
	return articleTag, true, nil
}

func DeleteArticleTag(id int64) bool {
	var articleTag domain.ArticleTag
	i, err := configs.Engine.Table("article_tag").Where("id = ?", id).Delete(&articleTag)
	if err != nil {
		return false
	}
	return i > 0
}

func GetArticleTopicById(id int64) (domain.ArticleTopic, error) {
	var articleTopic domain.ArticleTopic
	_, err := configs.Engine.Table("article_topic").Where("id = ?", id).Get(&articleTopic)
	if err != nil {
		return articleTopic, err
	}
	return articleTopic, nil
}

func GetArticleTopicListInId(ids []int64) ([]domain.ArticleTopic, error) {
	rows, err := configs.Engine.Table("article_topic").In("id", ids).Rows(&domain.ArticleTopic{})
	if err != nil {
		return make([]domain.ArticleTopic, 0), err
	}
	defer rows.Close()
	var list []domain.ArticleTopic
	for rows.Next() {
		var u domain.ArticleTopic
		rows.Scan(&u)
		list = append(list, u)
	}
	return list, nil
}

func GetArticleTopicList(articleTopic domain.ArticleTopic, pageNum, pageSize int) (vo.BaseListVo, error) {
	var arr []domain.ArticleTopic
	Count, err := configs.Engine.Table("article_topic").Limit(pageSize, (pageNum-1)*pageSize).FindAndCount(&arr, &articleTopic)
	var vo vo.BaseListVo
	if err != nil {
		return vo, err
	}
	if err != nil {
		return vo, err
	}
	vo.PageNum = pageNum
	vo.PageSize = pageSize
	vo.List = make([]any, len(arr))
	for i, v := range arr {
		vo.List[i] = v
	}
	vo.Total = int(Count)
	return vo, nil
}
func Get2ArticleTopicList(query domain.ArticleTopicQuery, pageNum, pageSize int) (vo.BaseListVo, error) {
	var arr []domain.ArticleTopic
	session := configs.Engine.Table("article_topic").Limit(pageSize, (pageNum-1)*pageSize)

	if query.Id != 0 {
		session.Where("id = ?", query.Id)
	}

	if query.Image != "" {
		session.Where("image = ?", query.Image)
	}

	if query.TopicName != "" {
		session.Where("topic_name like ?", "%"+query.TopicName+"%")
	}

	if query.TopicDesc != "" {
		session.Where("topic_desc like ?", "%"+query.TopicDesc+"%")
	}
	Count, err := session.FindAndCount(&arr)
	var vo vo.BaseListVo
	if err != nil {
		return vo, err
	}
	if err != nil {
		return vo, err
	}
	vo.PageNum = pageNum
	vo.PageSize = pageSize
	vo.List = make([]any, len(arr))
	for i, v := range arr {
		vo.List[i] = v
	}
	vo.Total = int(Count)
	return vo, nil
}
func SaveArticleTopic(articleTopic *domain.ArticleTopic) (domain.ArticleTopic, error) {
	_, err := configs.Engine.Table("article_topic").Insert(&articleTopic)
	if err != nil {
		return *articleTopic, err
	}
	return *articleTopic, nil
}

func SetArticleTopic(articleTopicMap map[string]interface{}, id int64) (domain.ArticleTopic, bool, error) {
	var articleTopic domain.ArticleTopic
	_, err := configs.Engine.Table("article_topic").Where("id = ?", id).Update(articleTopicMap)
	if err != nil {
		return articleTopic, false, err
	}
	return articleTopic, true, nil
}

func DeleteArticleTopic(id int64) bool {
	var articleTopic domain.ArticleTopic
	i, err := configs.Engine.Table("article_topic").Where("id = ?", id).Delete(&articleTopic)
	if err != nil {
		return false
	}
	return i > 0
}

func GetBackAuthorityById(id int64) (domain.BackAuthority, error) {
	var backAuthority domain.BackAuthority
	_, err := configs.Engine.Table("back_authority").Where("id = ?", id).Get(&backAuthority)
	if err != nil {
		return backAuthority, err
	}
	return backAuthority, nil
}

func GetBackAuthorityListInId(ids []int64) ([]domain.BackAuthority, error) {
	rows, err := configs.Engine.Table("back_authority").In("id", ids).Rows(&domain.BackAuthority{})
	if err != nil {
		return make([]domain.BackAuthority, 0), err
	}
	defer rows.Close()
	var list []domain.BackAuthority
	for rows.Next() {
		var u domain.BackAuthority
		rows.Scan(&u)
		list = append(list, u)
	}
	return list, nil
}

func GetBackAuthorityList(backAuthority domain.BackAuthority, pageNum, pageSize int) (vo.BaseListVo, error) {
	var arr []domain.BackAuthority
	Count, err := configs.Engine.Table("back_authority").Limit(pageSize, (pageNum-1)*pageSize).FindAndCount(&arr, &backAuthority)
	var vo vo.BaseListVo
	if err != nil {
		return vo, err
	}
	if err != nil {
		return vo, err
	}
	vo.PageNum = pageNum
	vo.PageSize = pageSize
	vo.List = make([]any, len(arr))
	for i, v := range arr {
		vo.List[i] = v
	}
	vo.Total = int(Count)
	return vo, nil
}
func Get2BackAuthorityList(query domain.BackAuthorityQuery, pageNum, pageSize int) (vo.BaseListVo, error) {
	var arr []domain.BackAuthority
	session := configs.Engine.Table("back_authority").Limit(pageSize, (pageNum-1)*pageSize)

	if query.Id != 0 {
		session.Where("id = ?", query.Id)
	}

	if query.AuthorityName != "" {
		session.Where("authority_name like ?", "%"+query.AuthorityName+"%")
	}

	if query.AuthorityPath != "" {
		session.Where("authority_path like ?", "%"+query.AuthorityPath+"%")
	}

	if query.Method != "" {
		session.Where("method = ?", query.Method)
	}

	if query.State != "" {
		session.Where("state = ?", query.State)
	}

	if query.AuthorityVerification != "" {
		session.Where("authority_verification like ?", "%"+query.AuthorityVerification+"%")
	}

	if query.CreateTimeStart != "" || query.CreateTimeEnd != "" {
		session.Where("create_time between ? and ?", query.CreateTimeStart, query.CreateTimeEnd)
	}
	Count, err := session.FindAndCount(&arr)
	var vo vo.BaseListVo
	if err != nil {
		return vo, err
	}
	if err != nil {
		return vo, err
	}
	vo.PageNum = pageNum
	vo.PageSize = pageSize
	vo.List = make([]any, len(arr))
	for i, v := range arr {
		vo.List[i] = v
	}
	vo.Total = int(Count)
	return vo, nil
}
func SaveBackAuthority(backAuthority *domain.BackAuthority) (domain.BackAuthority, error) {
	_, err := configs.Engine.Table("back_authority").Insert(&backAuthority)
	if err != nil {
		return *backAuthority, err
	}
	return *backAuthority, nil
}

func SetBackAuthority(backAuthorityMap map[string]interface{}, id int64) (domain.BackAuthority, bool, error) {
	var backAuthority domain.BackAuthority
	_, err := configs.Engine.Table("back_authority").Where("id = ?", id).Update(backAuthorityMap)
	if err != nil {
		return backAuthority, false, err
	}
	return backAuthority, true, nil
}

func DeleteBackAuthority(id int64) bool {
	var backAuthority domain.BackAuthority
	i, err := configs.Engine.Table("back_authority").Where("id = ?", id).Delete(&backAuthority)
	if err != nil {
		return false
	}
	return i > 0
}

func GetBackMenuById(id int64) (domain.BackMenu, error) {
	var backMenu domain.BackMenu
	_, err := configs.Engine.Table("back_menu").Where("id = ?", id).Get(&backMenu)
	if err != nil {
		return backMenu, err
	}
	return backMenu, nil
}

func GetBackMenuListInId(ids []int64) ([]domain.BackMenu, error) {
	rows, err := configs.Engine.Table("back_menu").In("id", ids).Rows(&domain.BackMenu{})
	if err != nil {
		return make([]domain.BackMenu, 0), err
	}
	defer rows.Close()
	var list []domain.BackMenu
	for rows.Next() {
		var u domain.BackMenu
		rows.Scan(&u)
		list = append(list, u)
	}
	return list, nil
}

func GetBackMenuList(backMenu domain.BackMenu, pageNum, pageSize int) (vo.BaseListVo, error) {
	var arr []domain.BackMenu
	Count, err := configs.Engine.Table("back_menu").Limit(pageSize, (pageNum-1)*pageSize).FindAndCount(&arr, &backMenu)
	var vo vo.BaseListVo
	if err != nil {
		return vo, err
	}
	if err != nil {
		return vo, err
	}
	vo.PageNum = pageNum
	vo.PageSize = pageSize
	vo.List = make([]any, len(arr))
	for i, v := range arr {
		vo.List[i] = v
	}
	vo.Total = int(Count)
	return vo, nil
}
func Get2BackMenuList(query domain.BackMenuQuery, pageNum, pageSize int) (vo.BaseListVo, error) {
	var arr []domain.BackMenu
	session := configs.Engine.Table("back_menu").Limit(pageSize, (pageNum-1)*pageSize)

	if query.Id != 0 {
		session.Where("id = ?", query.Id)
	}

	if query.BackMenuName != "" {
		session.Where("back_menu_name like ?", "%"+query.BackMenuName+"%")
	}

	if query.BackMenuPater != 0 {
		session.Where("back_menu_pater = ?", query.BackMenuPater)
	}

	if query.Sort != 0 {
		session.Where("sort = ?", query.Sort)
	}

	if query.Icon != "" {
		session.Where("icon = ?", query.Icon)
	}

	if query.Remark != "" {
		session.Where("remark like ?", "%"+query.Remark+"%")
	}

	if query.BackRouterPath != "" {
		session.Where("back_router_path like ?", "%"+query.BackRouterPath+"%")
	}

	if query.State != "" {
		session.Where("state = ?", query.State)
	}
	Count, err := session.FindAndCount(&arr)
	var vo vo.BaseListVo
	if err != nil {
		return vo, err
	}
	if err != nil {
		return vo, err
	}
	vo.PageNum = pageNum
	vo.PageSize = pageSize
	vo.List = make([]any, len(arr))
	for i, v := range arr {
		vo.List[i] = v
	}
	vo.Total = int(Count)
	return vo, nil
}
func SaveBackMenu(backMenu *domain.BackMenu) (domain.BackMenu, error) {
	_, err := configs.Engine.Table("back_menu").Insert(&backMenu)
	if err != nil {
		return *backMenu, err
	}
	return *backMenu, nil
}

func SetBackMenu(backMenuMap map[string]interface{}, id int64) (domain.BackMenu, bool, error) {
	var backMenu domain.BackMenu
	_, err := configs.Engine.Table("back_menu").Where("id = ?", id).Update(backMenuMap)
	if err != nil {
		return backMenu, false, err
	}
	return backMenu, true, nil
}

func DeleteBackMenu(id int64) bool {
	var backMenu domain.BackMenu
	i, err := configs.Engine.Table("back_menu").Where("id = ?", id).Delete(&backMenu)
	if err != nil {
		return false
	}
	return i > 0
}

func GetBackRoleById(id int64) (domain.BackRole, error) {
	var backRole domain.BackRole
	_, err := configs.Engine.Table("back_role").Where("id = ?", id).Get(&backRole)
	if err != nil {
		return backRole, err
	}
	return backRole, nil
}

func GetBackRoleListInId(ids []int64) ([]domain.BackRole, error) {
	rows, err := configs.Engine.Table("back_role").In("id", ids).Rows(&domain.BackRole{})
	if err != nil {
		return make([]domain.BackRole, 0), err
	}
	defer rows.Close()
	var list []domain.BackRole
	for rows.Next() {
		var u domain.BackRole
		rows.Scan(&u)
		list = append(list, u)
	}
	return list, nil
}

func GetBackRoleList(backRole domain.BackRole, pageNum, pageSize int) (vo.BaseListVo, error) {
	var arr []domain.BackRole
	Count, err := configs.Engine.Table("back_role").Limit(pageSize, (pageNum-1)*pageSize).FindAndCount(&arr, &backRole)
	var vo vo.BaseListVo
	if err != nil {
		return vo, err
	}
	if err != nil {
		return vo, err
	}
	vo.PageNum = pageNum
	vo.PageSize = pageSize
	vo.List = make([]any, len(arr))
	for i, v := range arr {
		vo.List[i] = v
	}
	vo.Total = int(Count)
	return vo, nil
}
func Get2BackRoleList(query domain.BackRoleQuery, pageNum, pageSize int) (vo.BaseListVo, error) {
	var arr []domain.BackRole
	session := configs.Engine.Table("back_role").Limit(pageSize, (pageNum-1)*pageSize)

	if query.Id != 0 {
		session.Where("id = ?", query.Id)
	}

	if query.RoleName != "" {
		session.Where("role_name like ?", "%"+query.RoleName+"%")
	}
	Count, err := session.FindAndCount(&arr)
	var vo vo.BaseListVo
	if err != nil {
		return vo, err
	}
	if err != nil {
		return vo, err
	}
	vo.PageNum = pageNum
	vo.PageSize = pageSize
	vo.List = make([]any, len(arr))
	for i, v := range arr {
		vo.List[i] = v
	}
	vo.Total = int(Count)
	return vo, nil
}
func SaveBackRole(backRole *domain.BackRole) (domain.BackRole, error) {
	_, err := configs.Engine.Table("back_role").Insert(&backRole)
	if err != nil {
		return *backRole, err
	}
	return *backRole, nil
}

func SetBackRole(backRoleMap map[string]interface{}, id int64) (domain.BackRole, bool, error) {
	var backRole domain.BackRole
	_, err := configs.Engine.Table("back_role").Where("id = ?", id).Update(backRoleMap)
	if err != nil {
		return backRole, false, err
	}
	return backRole, true, nil
}

func DeleteBackRole(id int64) bool {
	var backRole domain.BackRole
	i, err := configs.Engine.Table("back_role").Where("id = ?", id).Delete(&backRole)
	if err != nil {
		return false
	}
	return i > 0
}

func GetBackRoleAuthorityById(id int64) (domain.BackRoleAuthority, error) {
	var backRoleAuthority domain.BackRoleAuthority
	_, err := configs.Engine.Table("back_role_authority").Where("id = ?", id).Get(&backRoleAuthority)
	if err != nil {
		return backRoleAuthority, err
	}
	return backRoleAuthority, nil
}

func GetBackRoleAuthorityListInId(ids []int64) ([]domain.BackRoleAuthority, error) {
	rows, err := configs.Engine.Table("back_role_authority").In("id", ids).Rows(&domain.BackRoleAuthority{})
	if err != nil {
		return make([]domain.BackRoleAuthority, 0), err
	}
	defer rows.Close()
	var list []domain.BackRoleAuthority
	for rows.Next() {
		var u domain.BackRoleAuthority
		rows.Scan(&u)
		list = append(list, u)
	}
	return list, nil
}

func GetBackRoleAuthorityList(backRoleAuthority domain.BackRoleAuthority, pageNum, pageSize int) (vo.BaseListVo, error) {
	var arr []domain.BackRoleAuthority
	Count, err := configs.Engine.Table("back_role_authority").Limit(pageSize, (pageNum-1)*pageSize).FindAndCount(&arr, &backRoleAuthority)
	var vo vo.BaseListVo
	if err != nil {
		return vo, err
	}
	if err != nil {
		return vo, err
	}
	vo.PageNum = pageNum
	vo.PageSize = pageSize
	vo.List = make([]any, len(arr))
	for i, v := range arr {
		vo.List[i] = v
	}
	vo.Total = int(Count)
	return vo, nil
}
func Get2BackRoleAuthorityList(query domain.BackRoleAuthorityQuery, pageNum, pageSize int) (vo.BaseListVo, error) {
	var arr []domain.BackRoleAuthority
	session := configs.Engine.Table("back_role_authority").Limit(pageSize, (pageNum-1)*pageSize)

	if query.Id != 0 {
		session.Where("id = ?", query.Id)
	}

	if query.RoleId != 0 {
		session.Where("role_id = ?", query.RoleId)
	}

	if query.AuthorityId != 0 {
		session.Where("authority_id = ?", query.AuthorityId)
	}
	Count, err := session.FindAndCount(&arr)
	var vo vo.BaseListVo
	if err != nil {
		return vo, err
	}
	if err != nil {
		return vo, err
	}
	vo.PageNum = pageNum
	vo.PageSize = pageSize
	vo.List = make([]any, len(arr))
	for i, v := range arr {
		vo.List[i] = v
	}
	vo.Total = int(Count)
	return vo, nil
}
func SaveBackRoleAuthority(backRoleAuthority *domain.BackRoleAuthority) (domain.BackRoleAuthority, error) {
	_, err := configs.Engine.Table("back_role_authority").Insert(&backRoleAuthority)
	if err != nil {
		return *backRoleAuthority, err
	}
	return *backRoleAuthority, nil
}

func SetBackRoleAuthority(backRoleAuthorityMap map[string]interface{}, id int64) (domain.BackRoleAuthority, bool, error) {
	var backRoleAuthority domain.BackRoleAuthority
	_, err := configs.Engine.Table("back_role_authority").Where("id = ?", id).Update(backRoleAuthorityMap)
	if err != nil {
		return backRoleAuthority, false, err
	}
	return backRoleAuthority, true, nil
}

func DeleteBackRoleAuthority(id int64) bool {
	var backRoleAuthority domain.BackRoleAuthority
	i, err := configs.Engine.Table("back_role_authority").Where("id = ?", id).Delete(&backRoleAuthority)
	if err != nil {
		return false
	}
	return i > 0
}

func GetBackRoleMenuById(id int64) (domain.BackRoleMenu, error) {
	var backRoleMenu domain.BackRoleMenu
	_, err := configs.Engine.Table("back_role_menu").Where("id = ?", id).Get(&backRoleMenu)
	if err != nil {
		return backRoleMenu, err
	}
	return backRoleMenu, nil
}

func GetBackRoleMenuListInId(ids []int64) ([]domain.BackRoleMenu, error) {
	rows, err := configs.Engine.Table("back_role_menu").In("id", ids).Rows(&domain.BackRoleMenu{})
	if err != nil {
		return make([]domain.BackRoleMenu, 0), err
	}
	defer rows.Close()
	var list []domain.BackRoleMenu
	for rows.Next() {
		var u domain.BackRoleMenu
		rows.Scan(&u)
		list = append(list, u)
	}
	return list, nil
}

func GetBackRoleMenuList(backRoleMenu domain.BackRoleMenu, pageNum, pageSize int) (vo.BaseListVo, error) {
	var arr []domain.BackRoleMenu
	Count, err := configs.Engine.Table("back_role_menu").Limit(pageSize, (pageNum-1)*pageSize).FindAndCount(&arr, &backRoleMenu)
	var vo vo.BaseListVo
	if err != nil {
		return vo, err
	}
	if err != nil {
		return vo, err
	}
	vo.PageNum = pageNum
	vo.PageSize = pageSize
	vo.List = make([]any, len(arr))
	for i, v := range arr {
		vo.List[i] = v
	}
	vo.Total = int(Count)
	return vo, nil
}
func Get2BackRoleMenuList(query domain.BackRoleMenuQuery, pageNum, pageSize int) (vo.BaseListVo, error) {
	var arr []domain.BackRoleMenu
	session := configs.Engine.Table("back_role_menu").Limit(pageSize, (pageNum-1)*pageSize)

	if query.Id != 0 {
		session.Where("id = ?", query.Id)
	}

	if query.RoleId != 0 {
		session.Where("role_id = ?", query.RoleId)
	}

	if query.MenuId != 0 {
		session.Where("menu_id = ?", query.MenuId)
	}
	Count, err := session.FindAndCount(&arr)
	var vo vo.BaseListVo
	if err != nil {
		return vo, err
	}
	if err != nil {
		return vo, err
	}
	vo.PageNum = pageNum
	vo.PageSize = pageSize
	vo.List = make([]any, len(arr))
	for i, v := range arr {
		vo.List[i] = v
	}
	vo.Total = int(Count)
	return vo, nil
}
func SaveBackRoleMenu(backRoleMenu *domain.BackRoleMenu) (domain.BackRoleMenu, error) {
	_, err := configs.Engine.Table("back_role_menu").Insert(&backRoleMenu)
	if err != nil {
		return *backRoleMenu, err
	}
	return *backRoleMenu, nil
}

func SetBackRoleMenu(backRoleMenuMap map[string]interface{}, id int64) (domain.BackRoleMenu, bool, error) {
	var backRoleMenu domain.BackRoleMenu
	_, err := configs.Engine.Table("back_role_menu").Where("id = ?", id).Update(backRoleMenuMap)
	if err != nil {
		return backRoleMenu, false, err
	}
	return backRoleMenu, true, nil
}

func DeleteBackRoleMenu(id int64) bool {
	var backRoleMenu domain.BackRoleMenu
	i, err := configs.Engine.Table("back_role_menu").Where("id = ?", id).Delete(&backRoleMenu)
	if err != nil {
		return false
	}
	return i > 0
}

func GetGenTableById(id int64) (domain.GenTable, error) {
	var genTable domain.GenTable
	_, err := configs.Engine.Table("gen_table").Where("id = ?", id).Get(&genTable)
	if err != nil {
		return genTable, err
	}
	return genTable, nil
}

func GetGenTableListInId(ids []int64) ([]domain.GenTable, error) {
	rows, err := configs.Engine.Table("gen_table").In("id", ids).Rows(&domain.GenTable{})
	if err != nil {
		return make([]domain.GenTable, 0), err
	}
	defer rows.Close()
	var list []domain.GenTable
	for rows.Next() {
		var u domain.GenTable
		rows.Scan(&u)
		list = append(list, u)
	}
	return list, nil
}

func GetGenTableList(genTable domain.GenTable, pageNum, pageSize int) (vo.BaseListVo, error) {
	var arr []domain.GenTable
	Count, err := configs.Engine.Table("gen_table").Limit(pageSize, (pageNum-1)*pageSize).FindAndCount(&arr, &genTable)
	var vo vo.BaseListVo
	if err != nil {
		return vo, err
	}
	if err != nil {
		return vo, err
	}
	vo.PageNum = pageNum
	vo.PageSize = pageSize
	vo.List = make([]any, len(arr))
	for i, v := range arr {
		vo.List[i] = v
	}
	vo.Total = int(Count)
	return vo, nil
}
func Get2GenTableList(query domain.GenTableQuery, pageNum, pageSize int) (vo.BaseListVo, error) {
	var arr []domain.GenTable
	session := configs.Engine.Table("gen_table").Limit(pageSize, (pageNum-1)*pageSize)

	if query.Id != 0 {
		session.Where("id = ?", query.Id)
	}

	if query.TableName != "" {
		session.Where("table_name like ?", "%"+query.TableName+"%")
	}

	if query.TableComment != "" {
		session.Where("table_comment like ?", "%"+query.TableComment+"%")
	}

	if query.Name != "" {
		session.Where("name like ?", "%"+query.Name+"%")
	}

	if query.RouterName != "" {
		session.Where("router_name like ?", "%"+query.RouterName+"%")
	}

	if query.Remark != "" {
		session.Where("remark like ?", "%"+query.Remark+"%")
	}
	Count, err := session.FindAndCount(&arr)
	var vo vo.BaseListVo
	if err != nil {
		return vo, err
	}
	if err != nil {
		return vo, err
	}
	vo.PageNum = pageNum
	vo.PageSize = pageSize
	vo.List = make([]any, len(arr))
	for i, v := range arr {
		vo.List[i] = v
	}
	vo.Total = int(Count)
	return vo, nil
}
func SaveGenTable(genTable *domain.GenTable) (domain.GenTable, error) {
	_, err := configs.Engine.Table("gen_table").Insert(&genTable)
	if err != nil {
		return *genTable, err
	}
	return *genTable, nil
}

func SetGenTable(genTableMap map[string]interface{}, id int64) (domain.GenTable, bool, error) {
	var genTable domain.GenTable
	_, err := configs.Engine.Table("gen_table").Where("id = ?", id).Update(genTableMap)
	if err != nil {
		return genTable, false, err
	}
	return genTable, true, nil
}

func DeleteGenTable(id int64) bool {
	var genTable domain.GenTable
	i, err := configs.Engine.Table("gen_table").Where("id = ?", id).Delete(&genTable)
	if err != nil {
		return false
	}
	return i > 0
}

func GetGenTableColumnById(id int64) (domain.GenTableColumn, error) {
	var genTableColumn domain.GenTableColumn
	_, err := configs.Engine.Table("gen_table_column").Where("id = ?", id).Get(&genTableColumn)
	if err != nil {
		return genTableColumn, err
	}
	return genTableColumn, nil
}

func GetGenTableColumnListInId(ids []int64) ([]domain.GenTableColumn, error) {
	rows, err := configs.Engine.Table("gen_table_column").In("id", ids).Rows(&domain.GenTableColumn{})
	if err != nil {
		return make([]domain.GenTableColumn, 0), err
	}
	defer rows.Close()
	var list []domain.GenTableColumn
	for rows.Next() {
		var u domain.GenTableColumn
		rows.Scan(&u)
		list = append(list, u)
	}
	return list, nil
}

func GetGenTableColumnList(genTableColumn domain.GenTableColumn, pageNum, pageSize int) (vo.BaseListVo, error) {
	var arr []domain.GenTableColumn
	Count, err := configs.Engine.Table("gen_table_column").Limit(pageSize, (pageNum-1)*pageSize).FindAndCount(&arr, &genTableColumn)
	var vo vo.BaseListVo
	if err != nil {
		return vo, err
	}
	if err != nil {
		return vo, err
	}
	vo.PageNum = pageNum
	vo.PageSize = pageSize
	vo.List = make([]any, len(arr))
	for i, v := range arr {
		vo.List[i] = v
	}
	vo.Total = int(Count)
	return vo, nil
}
func Get2GenTableColumnList(query domain.GenTableColumnQuery, pageNum, pageSize int) (vo.BaseListVo, error) {
	var arr []domain.GenTableColumn
	session := configs.Engine.Table("gen_table_column").Limit(pageSize, (pageNum-1)*pageSize)

	if query.Id != 0 {
		session.Where("id = ?", query.Id)
	}

	if query.TableId != 0 {
		session.Where("table_id = ?", query.TableId)
	}

	if query.Sort != 0 {
		session.Where("sort = ?", query.Sort)
	}

	if query.ColumnComment != "" {
		session.Where("column_comment like ?", "%"+query.ColumnComment+"%")
	}

	if query.ColumnType != "" {
		session.Where("column_type like ?", "%"+query.ColumnType+"%")
	}

	if query.GoType != "" {
		session.Where("go_type like ?", "%"+query.GoType+"%")
	}

	if query.GoField != "" {
		session.Where("go_field like ?", "%"+query.GoField+"%")
	}

	if query.IsKey != "" {
		session.Where("is_key = ?", query.IsKey)
	}

	if query.IsIncrement != "" {
		session.Where("is_increment = ?", query.IsIncrement)
	}

	if query.IsRequired != "" {
		session.Where("is_required = ?", query.IsRequired)
	}

	if query.QueryType != "" {
		session.Where("query_type = ?", query.QueryType)
	}

	if query.VueShowType != "" {
		session.Where("vue_show_type = ?", query.VueShowType)
	}

	if query.DictType != "" {
		session.Where("dict_type like ?", "%"+query.DictType+"%")
	}

	if query.ColumnName != "" {
		session.Where("column_name like ?", "%"+query.ColumnName+"%")
	}
	Count, err := session.FindAndCount(&arr)
	var vo vo.BaseListVo
	if err != nil {
		return vo, err
	}
	if err != nil {
		return vo, err
	}
	vo.PageNum = pageNum
	vo.PageSize = pageSize
	vo.List = make([]any, len(arr))
	for i, v := range arr {
		vo.List[i] = v
	}
	vo.Total = int(Count)
	return vo, nil
}
func SaveGenTableColumn(genTableColumn *domain.GenTableColumn) (domain.GenTableColumn, error) {
	_, err := configs.Engine.Table("gen_table_column").Insert(&genTableColumn)
	if err != nil {
		return *genTableColumn, err
	}
	return *genTableColumn, nil
}

func SetGenTableColumn(genTableColumnMap map[string]interface{}, id int64) (domain.GenTableColumn, bool, error) {
	var genTableColumn domain.GenTableColumn
	_, err := configs.Engine.Table("gen_table_column").Where("id = ?", id).Update(genTableColumnMap)
	if err != nil {
		return genTableColumn, false, err
	}
	return genTableColumn, true, nil
}

func DeleteGenTableColumn(id int64) bool {
	var genTableColumn domain.GenTableColumn
	i, err := configs.Engine.Table("gen_table_column").Where("id = ?", id).Delete(&genTableColumn)
	if err != nil {
		return false
	}
	return i > 0
}

func GetGoodsById(id int64) (domain.Goods, error) {
	var goods domain.Goods
	_, err := configs.Engine.Table("goods").Where("id = ?", id).Get(&goods)
	if err != nil {
		return goods, err
	}
	return goods, nil
}

func GetGoodsListInId(ids []int64) ([]domain.Goods, error) {
	rows, err := configs.Engine.Table("goods").In("id", ids).Rows(&domain.Goods{})
	if err != nil {
		return make([]domain.Goods, 0), err
	}
	defer rows.Close()
	var list []domain.Goods
	for rows.Next() {
		var u domain.Goods
		rows.Scan(&u)
		list = append(list, u)
	}
	return list, nil
}

func GetGoodsList(goods domain.Goods, pageNum, pageSize int) (vo.BaseListVo, error) {
	var arr []domain.Goods
	Count, err := configs.Engine.Table("goods").Limit(pageSize, (pageNum-1)*pageSize).FindAndCount(&arr, &goods)
	var vo vo.BaseListVo
	if err != nil {
		return vo, err
	}
	if err != nil {
		return vo, err
	}
	vo.PageNum = pageNum
	vo.PageSize = pageSize
	vo.List = make([]any, len(arr))
	for i, v := range arr {
		vo.List[i] = v
	}
	vo.Total = int(Count)
	return vo, nil
}
func Get2GoodsList(query domain.GoodsQuery, pageNum, pageSize int) (vo.BaseListVo, error) {
	var arr []domain.Goods
	session := configs.Engine.Table("goods").Limit(pageSize, (pageNum-1)*pageSize)

	if query.Id != 0 {
		session.Where("id = ?", query.Id)
	}

	if query.TypeId != 0 {
		session.Where("type_id = ?", query.TypeId)
	}

	if query.GoodsName != "" {
		session.Where("goods_name like ?", "%"+query.GoodsName+"%")
	}

	if query.IntroductionId != 0 {
		session.Where("introduction_id = ?", query.IntroductionId)
	}

	if query.SalesVolumeStart != 0 || query.SalesVolumeEnd != 0 {
		session.Where("sales_volume between ? and ?", query.SalesVolumeStart, query.SalesVolumeEnd)
	}

	if query.TagIds != "" {
		session.Where("tag_ids = ?", query.TagIds)
	}
	Count, err := session.FindAndCount(&arr)
	var vo vo.BaseListVo
	if err != nil {
		return vo, err
	}
	if err != nil {
		return vo, err
	}
	vo.PageNum = pageNum
	vo.PageSize = pageSize
	vo.List = make([]any, len(arr))
	for i, v := range arr {
		vo.List[i] = v
	}
	vo.Total = int(Count)
	return vo, nil
}
func SaveGoods(goods *domain.Goods) (domain.Goods, error) {
	_, err := configs.Engine.Table("goods").Insert(&goods)
	if err != nil {
		return *goods, err
	}
	return *goods, nil
}

func SetGoods(goodsMap map[string]interface{}, id int64) (domain.Goods, bool, error) {
	var goods domain.Goods
	_, err := configs.Engine.Table("goods").Where("id = ?", id).Update(goodsMap)
	if err != nil {
		return goods, false, err
	}
	return goods, true, nil
}

func DeleteGoods(id int64) bool {
	var goods domain.Goods
	i, err := configs.Engine.Table("goods").Where("id = ?", id).Delete(&goods)
	if err != nil {
		return false
	}
	return i > 0
}

func GetGoodsCommodityAreaById(id int64) (domain.GoodsCommodityArea, error) {
	var goodsCommodityArea domain.GoodsCommodityArea
	_, err := configs.Engine.Table("goods_commodity_area").Where("id = ?", id).Get(&goodsCommodityArea)
	if err != nil {
		return goodsCommodityArea, err
	}
	return goodsCommodityArea, nil
}

func GetGoodsCommodityAreaListInId(ids []int64) ([]domain.GoodsCommodityArea, error) {
	rows, err := configs.Engine.Table("goods_commodity_area").In("id", ids).Rows(&domain.GoodsCommodityArea{})
	if err != nil {
		return make([]domain.GoodsCommodityArea, 0), err
	}
	defer rows.Close()
	var list []domain.GoodsCommodityArea
	for rows.Next() {
		var u domain.GoodsCommodityArea
		rows.Scan(&u)
		list = append(list, u)
	}
	return list, nil
}

func GetGoodsCommodityAreaList(goodsCommodityArea domain.GoodsCommodityArea, pageNum, pageSize int) (vo.BaseListVo, error) {
	var arr []domain.GoodsCommodityArea
	Count, err := configs.Engine.Table("goods_commodity_area").Limit(pageSize, (pageNum-1)*pageSize).FindAndCount(&arr, &goodsCommodityArea)
	var vo vo.BaseListVo
	if err != nil {
		return vo, err
	}
	if err != nil {
		return vo, err
	}
	vo.PageNum = pageNum
	vo.PageSize = pageSize
	vo.List = make([]any, len(arr))
	for i, v := range arr {
		vo.List[i] = v
	}
	vo.Total = int(Count)
	return vo, nil
}
func Get2GoodsCommodityAreaList(query domain.GoodsCommodityAreaQuery, pageNum, pageSize int) (vo.BaseListVo, error) {
	var arr []domain.GoodsCommodityArea
	session := configs.Engine.Table("goods_commodity_area").Limit(pageSize, (pageNum-1)*pageSize)

	if query.Id != 0 {
		session.Where("id = ?", query.Id)
	}

	if query.GoodsId != 0 {
		session.Where("goods_id = ?", query.GoodsId)
	}

	if query.CommodityAreaName != "" {
		session.Where("commodity_area_name like ?", "%"+query.CommodityAreaName+"%")
	}

	if query.DetailImage != "" {
		session.Where("detail_image = ?", query.DetailImage)
	}

	if query.DetailIntroductionId != 0 {
		session.Where("detail_introduction_id = ?", query.DetailIntroductionId)
	}
	Count, err := session.FindAndCount(&arr)
	var vo vo.BaseListVo
	if err != nil {
		return vo, err
	}
	if err != nil {
		return vo, err
	}
	vo.PageNum = pageNum
	vo.PageSize = pageSize
	vo.List = make([]any, len(arr))
	for i, v := range arr {
		vo.List[i] = v
	}
	vo.Total = int(Count)
	return vo, nil
}
func SaveGoodsCommodityArea(goodsCommodityArea *domain.GoodsCommodityArea) (domain.GoodsCommodityArea, error) {
	_, err := configs.Engine.Table("goods_commodity_area").Insert(&goodsCommodityArea)
	if err != nil {
		return *goodsCommodityArea, err
	}
	return *goodsCommodityArea, nil
}

func SetGoodsCommodityArea(goodsCommodityAreaMap map[string]interface{}, id int64) (domain.GoodsCommodityArea, bool, error) {
	var goodsCommodityArea domain.GoodsCommodityArea
	_, err := configs.Engine.Table("goods_commodity_area").Where("id = ?", id).Update(goodsCommodityAreaMap)
	if err != nil {
		return goodsCommodityArea, false, err
	}
	return goodsCommodityArea, true, nil
}

func DeleteGoodsCommodityArea(id int64) bool {
	var goodsCommodityArea domain.GoodsCommodityArea
	i, err := configs.Engine.Table("goods_commodity_area").Where("id = ?", id).Delete(&goodsCommodityArea)
	if err != nil {
		return false
	}
	return i > 0
}

func GetGoodsCouponById(id int64) (domain.GoodsCoupon, error) {
	var goodsCoupon domain.GoodsCoupon
	_, err := configs.Engine.Table("goods_coupon").Where("id = ?", id).Get(&goodsCoupon)
	if err != nil {
		return goodsCoupon, err
	}
	return goodsCoupon, nil
}

func GetGoodsCouponListInId(ids []int64) ([]domain.GoodsCoupon, error) {
	rows, err := configs.Engine.Table("goods_coupon").In("id", ids).Rows(&domain.GoodsCoupon{})
	if err != nil {
		return make([]domain.GoodsCoupon, 0), err
	}
	defer rows.Close()
	var list []domain.GoodsCoupon
	for rows.Next() {
		var u domain.GoodsCoupon
		rows.Scan(&u)
		list = append(list, u)
	}
	return list, nil
}

func GetGoodsCouponList(goodsCoupon domain.GoodsCoupon, pageNum, pageSize int) (vo.BaseListVo, error) {
	var arr []domain.GoodsCoupon
	Count, err := configs.Engine.Table("goods_coupon").Limit(pageSize, (pageNum-1)*pageSize).FindAndCount(&arr, &goodsCoupon)
	var vo vo.BaseListVo
	if err != nil {
		return vo, err
	}
	if err != nil {
		return vo, err
	}
	vo.PageNum = pageNum
	vo.PageSize = pageSize
	vo.List = make([]any, len(arr))
	for i, v := range arr {
		vo.List[i] = v
	}
	vo.Total = int(Count)
	return vo, nil
}
func Get2GoodsCouponList(query domain.GoodsCouponQuery, pageNum, pageSize int) (vo.BaseListVo, error) {
	var arr []domain.GoodsCoupon
	session := configs.Engine.Table("goods_coupon").Limit(pageSize, (pageNum-1)*pageSize)

	if query.Id != 0 {
		session.Where("id = ?", query.Id)
	}

	if query.CouponName != "" {
		session.Where("coupon_name like ?", "%"+query.CouponName+"%")
	}

	if query.CouponDesc != "" {
		session.Where("coupon_desc like ?", "%"+query.CouponDesc+"%")
	}

	if query.CashBackPoint != 0 {
		session.Where("cash_back_point = ?", query.CashBackPoint)
	}

	if query.CashBackPrice != 0 {
		session.Where("cash_back_price = ?", query.CashBackPrice)
	}

	if query.ConditionByTopic != "" {
		session.Where("condition_by_topic = ?", query.ConditionByTopic)
	}

	if query.ConditionByType != "" {
		session.Where("condition_by_type = ?", query.ConditionByType)
	}

	if query.ConditionByGoods != "" {
		session.Where("condition_by_goods = ?", query.ConditionByGoods)
	}

	if query.GrantCount != "" {
		session.Where("grant_count = ?", query.GrantCount)
	}

	if query.Count != 0 {
		session.Where("count = ?", query.Count)
	}

	if query.ReceiveType != "" {
		session.Where("receive_type = ?", query.ReceiveType)
	}

	if query.Validity != "" {
		session.Where("validity = ?", query.Validity)
	}

	if query.ValidityPeriodStart != "" || query.ValidityPeriodEnd != "" {
		session.Where("validity_period between ? and ?", query.ValidityPeriodStart, query.ValidityPeriodEnd)
	}
	Count, err := session.FindAndCount(&arr)
	var vo vo.BaseListVo
	if err != nil {
		return vo, err
	}
	if err != nil {
		return vo, err
	}
	vo.PageNum = pageNum
	vo.PageSize = pageSize
	vo.List = make([]any, len(arr))
	for i, v := range arr {
		vo.List[i] = v
	}
	vo.Total = int(Count)
	return vo, nil
}
func SaveGoodsCoupon(goodsCoupon *domain.GoodsCoupon) (domain.GoodsCoupon, error) {
	_, err := configs.Engine.Table("goods_coupon").Insert(&goodsCoupon)
	if err != nil {
		return *goodsCoupon, err
	}
	return *goodsCoupon, nil
}

func SetGoodsCoupon(goodsCouponMap map[string]interface{}, id int64) (domain.GoodsCoupon, bool, error) {
	var goodsCoupon domain.GoodsCoupon
	_, err := configs.Engine.Table("goods_coupon").Where("id = ?", id).Update(goodsCouponMap)
	if err != nil {
		return goodsCoupon, false, err
	}
	return goodsCoupon, true, nil
}

func DeleteGoodsCoupon(id int64) bool {
	var goodsCoupon domain.GoodsCoupon
	i, err := configs.Engine.Table("goods_coupon").Where("id = ?", id).Delete(&goodsCoupon)
	if err != nil {
		return false
	}
	return i > 0
}

func GetGoodsCouponUserById(id int64) (domain.GoodsCouponUser, error) {
	var goodsCouponUser domain.GoodsCouponUser
	_, err := configs.Engine.Table("goods_coupon_user").Where("id = ?", id).Get(&goodsCouponUser)
	if err != nil {
		return goodsCouponUser, err
	}
	return goodsCouponUser, nil
}

func GetGoodsCouponUserListInId(ids []int64) ([]domain.GoodsCouponUser, error) {
	rows, err := configs.Engine.Table("goods_coupon_user").In("id", ids).Rows(&domain.GoodsCouponUser{})
	if err != nil {
		return make([]domain.GoodsCouponUser, 0), err
	}
	defer rows.Close()
	var list []domain.GoodsCouponUser
	for rows.Next() {
		var u domain.GoodsCouponUser
		rows.Scan(&u)
		list = append(list, u)
	}
	return list, nil
}

func GetGoodsCouponUserList(goodsCouponUser domain.GoodsCouponUser, pageNum, pageSize int) (vo.BaseListVo, error) {
	var arr []domain.GoodsCouponUser
	Count, err := configs.Engine.Table("goods_coupon_user").Limit(pageSize, (pageNum-1)*pageSize).FindAndCount(&arr, &goodsCouponUser)
	var vo vo.BaseListVo
	if err != nil {
		return vo, err
	}
	if err != nil {
		return vo, err
	}
	vo.PageNum = pageNum
	vo.PageSize = pageSize
	vo.List = make([]any, len(arr))
	for i, v := range arr {
		vo.List[i] = v
	}
	vo.Total = int(Count)
	return vo, nil
}
func Get2GoodsCouponUserList(query domain.GoodsCouponUserQuery, pageNum, pageSize int) (vo.BaseListVo, error) {
	var arr []domain.GoodsCouponUser
	session := configs.Engine.Table("goods_coupon_user").Limit(pageSize, (pageNum-1)*pageSize)

	if query.Id != 0 {
		session.Where("id = ?", query.Id)
	}

	if query.UserId != 0 {
		session.Where("user_id = ?", query.UserId)
	}

	if query.CouponId != 0 {
		session.Where("coupon_id = ?", query.CouponId)
	}

	if query.CollectionTime != "" {
		session.Where("collection_time = ?", query.CollectionTime)
	}

	if query.State != "" {
		session.Where("state = ?", query.State)
	}
	Count, err := session.FindAndCount(&arr)
	var vo vo.BaseListVo
	if err != nil {
		return vo, err
	}
	if err != nil {
		return vo, err
	}
	vo.PageNum = pageNum
	vo.PageSize = pageSize
	vo.List = make([]any, len(arr))
	for i, v := range arr {
		vo.List[i] = v
	}
	vo.Total = int(Count)
	return vo, nil
}
func SaveGoodsCouponUser(goodsCouponUser *domain.GoodsCouponUser) (domain.GoodsCouponUser, error) {
	_, err := configs.Engine.Table("goods_coupon_user").Insert(&goodsCouponUser)
	if err != nil {
		return *goodsCouponUser, err
	}
	return *goodsCouponUser, nil
}

func SetGoodsCouponUser(goodsCouponUserMap map[string]interface{}, id int64) (domain.GoodsCouponUser, bool, error) {
	var goodsCouponUser domain.GoodsCouponUser
	_, err := configs.Engine.Table("goods_coupon_user").Where("id = ?", id).Update(goodsCouponUserMap)
	if err != nil {
		return goodsCouponUser, false, err
	}
	return goodsCouponUser, true, nil
}

func DeleteGoodsCouponUser(id int64) bool {
	var goodsCouponUser domain.GoodsCouponUser
	i, err := configs.Engine.Table("goods_coupon_user").Where("id = ?", id).Delete(&goodsCouponUser)
	if err != nil {
		return false
	}
	return i > 0
}

func GetGoodsIntroductionById(id int64) (domain.GoodsIntroduction, error) {
	var goodsIntroduction domain.GoodsIntroduction
	_, err := configs.Engine.Table("goods_introduction").Where("id = ?", id).Get(&goodsIntroduction)
	if err != nil {
		return goodsIntroduction, err
	}
	return goodsIntroduction, nil
}

func GetGoodsIntroductionListInId(ids []int64) ([]domain.GoodsIntroduction, error) {
	rows, err := configs.Engine.Table("goods_introduction").In("id", ids).Rows(&domain.GoodsIntroduction{})
	if err != nil {
		return make([]domain.GoodsIntroduction, 0), err
	}
	defer rows.Close()
	var list []domain.GoodsIntroduction
	for rows.Next() {
		var u domain.GoodsIntroduction
		rows.Scan(&u)
		list = append(list, u)
	}
	return list, nil
}

func GetGoodsIntroductionList(goodsIntroduction domain.GoodsIntroduction, pageNum, pageSize int) (vo.BaseListVo, error) {
	var arr []domain.GoodsIntroduction
	Count, err := configs.Engine.Table("goods_introduction").Limit(pageSize, (pageNum-1)*pageSize).FindAndCount(&arr, &goodsIntroduction)
	var vo vo.BaseListVo
	if err != nil {
		return vo, err
	}
	if err != nil {
		return vo, err
	}
	vo.PageNum = pageNum
	vo.PageSize = pageSize
	vo.List = make([]any, len(arr))
	for i, v := range arr {
		vo.List[i] = v
	}
	vo.Total = int(Count)
	return vo, nil
}
func Get2GoodsIntroductionList(query domain.GoodsIntroductionQuery, pageNum, pageSize int) (vo.BaseListVo, error) {
	var arr []domain.GoodsIntroduction
	session := configs.Engine.Table("goods_introduction").Limit(pageSize, (pageNum-1)*pageSize)

	if query.Id != 0 {
		session.Where("id = ?", query.Id)
	}

	if query.GoodsArticleName != "" {
		session.Where("goods_article_name like ?", "%"+query.GoodsArticleName+"%")
	}

	if query.GoodsArticle != "" {
		session.Where("goods_article = ?", query.GoodsArticle)
	}

	if query.CreateBy != "" {
		session.Where("create_by = ?", query.CreateBy)
	}

	if query.CreateTime != "" {
		session.Where("create_time = ?", query.CreateTime)
	}

	if query.UpdateBy != "" {
		session.Where("update_by = ?", query.UpdateBy)
	}

	if query.UpdateTime != "" {
		session.Where("update_time = ?", query.UpdateTime)
	}
	Count, err := session.FindAndCount(&arr)
	var vo vo.BaseListVo
	if err != nil {
		return vo, err
	}
	if err != nil {
		return vo, err
	}
	vo.PageNum = pageNum
	vo.PageSize = pageSize
	vo.List = make([]any, len(arr))
	for i, v := range arr {
		vo.List[i] = v
	}
	vo.Total = int(Count)
	return vo, nil
}
func SaveGoodsIntroduction(goodsIntroduction *domain.GoodsIntroduction) (domain.GoodsIntroduction, error) {
	_, err := configs.Engine.Table("goods_introduction").Insert(&goodsIntroduction)
	if err != nil {
		return *goodsIntroduction, err
	}
	return *goodsIntroduction, nil
}

func SetGoodsIntroduction(goodsIntroductionMap map[string]interface{}, id int64) (domain.GoodsIntroduction, bool, error) {
	var goodsIntroduction domain.GoodsIntroduction
	_, err := configs.Engine.Table("goods_introduction").Where("id = ?", id).Update(goodsIntroductionMap)
	if err != nil {
		return goodsIntroduction, false, err
	}
	return goodsIntroduction, true, nil
}

func DeleteGoodsIntroduction(id int64) bool {
	var goodsIntroduction domain.GoodsIntroduction
	i, err := configs.Engine.Table("goods_introduction").Where("id = ?", id).Delete(&goodsIntroduction)
	if err != nil {
		return false
	}
	return i > 0
}

func GetGoodsOrderById(id int64) (domain.GoodsOrder, error) {
	var goodsOrder domain.GoodsOrder
	_, err := configs.Engine.Table("goods_order").Where("id = ?", id).Get(&goodsOrder)
	if err != nil {
		return goodsOrder, err
	}
	return goodsOrder, nil
}

func GetGoodsOrderListInId(ids []int64) ([]domain.GoodsOrder, error) {
	rows, err := configs.Engine.Table("goods_order").In("id", ids).Rows(&domain.GoodsOrder{})
	if err != nil {
		return make([]domain.GoodsOrder, 0), err
	}
	defer rows.Close()
	var list []domain.GoodsOrder
	for rows.Next() {
		var u domain.GoodsOrder
		rows.Scan(&u)
		list = append(list, u)
	}
	return list, nil
}

func GetGoodsOrderList(goodsOrder domain.GoodsOrder, pageNum, pageSize int) (vo.BaseListVo, error) {
	var arr []domain.GoodsOrder
	Count, err := configs.Engine.Table("goods_order").Limit(pageSize, (pageNum-1)*pageSize).FindAndCount(&arr, &goodsOrder)
	var vo vo.BaseListVo
	if err != nil {
		return vo, err
	}
	if err != nil {
		return vo, err
	}
	vo.PageNum = pageNum
	vo.PageSize = pageSize
	vo.List = make([]any, len(arr))
	for i, v := range arr {
		vo.List[i] = v
	}
	vo.Total = int(Count)
	return vo, nil
}
func Get2GoodsOrderList(query domain.GoodsOrderQuery, pageNum, pageSize int) (vo.BaseListVo, error) {
	var arr []domain.GoodsOrder
	session := configs.Engine.Table("goods_order").Limit(pageSize, (pageNum-1)*pageSize)

	if query.Id != 0 {
		session.Where("id = ?", query.Id)
	}

	if query.OrderName != "" {
		session.Where("order_name like ?", "%"+query.OrderName+"%")
	}

	if query.SkuId != 0 {
		session.Where("sku_id = ?", query.SkuId)
	}

	if query.CountStart != 0 || query.CountEnd != 0 {
		session.Where("count between ? and ?", query.CountStart, query.CountEnd)
	}

	if query.PriceStart != 0 || query.PriceEnd != 0 {
		session.Where("price between ? and ?", query.PriceStart, query.PriceEnd)
	}

	if query.TotalPriceStart != 0 || query.TotalPriceEnd != 0 {
		session.Where("total_price between ? and ?", query.TotalPriceStart, query.TotalPriceEnd)
	}

	if query.ContactInformation != "" {
		session.Where("contact_information like ?", "%"+query.ContactInformation+"%")
	}

	if query.CouponUserId != 0 {
		session.Where("coupon_user_id = ?", query.CouponUserId)
	}

	if query.State != "" {
		session.Where("state = ?", query.State)
	}

	if query.CreateBy != 0 {
		session.Where("create_by = ?", query.CreateBy)
	}

	if query.CreateTime != "" {
		session.Where("create_time = ?", query.CreateTime)
	}

	if query.OtherData != "" {
		session.Where("other_data = ?", query.OtherData)
	}
	Count, err := session.FindAndCount(&arr)
	var vo vo.BaseListVo
	if err != nil {
		return vo, err
	}
	if err != nil {
		return vo, err
	}
	vo.PageNum = pageNum
	vo.PageSize = pageSize
	vo.List = make([]any, len(arr))
	for i, v := range arr {
		vo.List[i] = v
	}
	vo.Total = int(Count)
	return vo, nil
}
func SaveGoodsOrder(goodsOrder *domain.GoodsOrder) (domain.GoodsOrder, error) {
	_, err := configs.Engine.Table("goods_order").Insert(&goodsOrder)
	if err != nil {
		return *goodsOrder, err
	}
	return *goodsOrder, nil
}

func SetGoodsOrder(goodsOrderMap map[string]interface{}, id int64) (domain.GoodsOrder, bool, error) {
	var goodsOrder domain.GoodsOrder
	_, err := configs.Engine.Table("goods_order").Where("id = ?", id).Update(goodsOrderMap)
	if err != nil {
		return goodsOrder, false, err
	}
	return goodsOrder, true, nil
}

func DeleteGoodsOrder(id int64) bool {
	var goodsOrder domain.GoodsOrder
	i, err := configs.Engine.Table("goods_order").Where("id = ?", id).Delete(&goodsOrder)
	if err != nil {
		return false
	}
	return i > 0
}

func GetGoodsSkuById(id int64) (domain.GoodsSku, error) {
	var goodsSku domain.GoodsSku
	_, err := configs.Engine.Table("goods_sku").Where("id = ?", id).Get(&goodsSku)
	if err != nil {
		return goodsSku, err
	}
	return goodsSku, nil
}

func GetGoodsSkuListInId(ids []int64) ([]domain.GoodsSku, error) {
	rows, err := configs.Engine.Table("goods_sku").In("id", ids).Rows(&domain.GoodsSku{})
	if err != nil {
		return make([]domain.GoodsSku, 0), err
	}
	defer rows.Close()
	var list []domain.GoodsSku
	for rows.Next() {
		var u domain.GoodsSku
		rows.Scan(&u)
		list = append(list, u)
	}
	return list, nil
}

func GetGoodsSkuList(goodsSku domain.GoodsSku, pageNum, pageSize int) (vo.BaseListVo, error) {
	var arr []domain.GoodsSku
	Count, err := configs.Engine.Table("goods_sku").Limit(pageSize, (pageNum-1)*pageSize).FindAndCount(&arr, &goodsSku)
	var vo vo.BaseListVo
	if err != nil {
		return vo, err
	}
	if err != nil {
		return vo, err
	}
	vo.PageNum = pageNum
	vo.PageSize = pageSize
	vo.List = make([]any, len(arr))
	for i, v := range arr {
		vo.List[i] = v
	}
	vo.Total = int(Count)
	return vo, nil
}
func Get2GoodsSkuList(query domain.GoodsSkuQuery, pageNum, pageSize int) (vo.BaseListVo, error) {
	var arr []domain.GoodsSku
	session := configs.Engine.Table("goods_sku").Limit(pageSize, (pageNum-1)*pageSize)

	if query.Id != 0 {
		session.Where("id = ?", query.Id)
	}

	if query.SkuImage != "" {
		session.Where("sku_image = ?", query.SkuImage)
	}

	if query.SkuName != "" {
		session.Where("sku_name like ?", "%"+query.SkuName+"%")
	}

	if query.Price != 0 {
		session.Where("price = ?", query.Price)
	}

	if query.HistoricalPrices != 0 {
		session.Where("historical_prices = ?", query.HistoricalPrices)
	}

	if query.InventoryNumber != 0 {
		session.Where("inventory_number = ?", query.InventoryNumber)
	}

	if query.CommodityAreaId != 0 {
		session.Where("commodity_area_id = ?", query.CommodityAreaId)
	}

	if query.GoodsId != 0 {
		session.Where("goods_id = ?", query.GoodsId)
	}

	if query.CreateBy != "" {
		session.Where("create_by = ?", query.CreateBy)
	}

	if query.CreateTimeStart != "" || query.CreateTimeEnd != "" {
		session.Where("create_time between ? and ?", query.CreateTimeStart, query.CreateTimeEnd)
	}
	Count, err := session.FindAndCount(&arr)
	var vo vo.BaseListVo
	if err != nil {
		return vo, err
	}
	if err != nil {
		return vo, err
	}
	vo.PageNum = pageNum
	vo.PageSize = pageSize
	vo.List = make([]any, len(arr))
	for i, v := range arr {
		vo.List[i] = v
	}
	vo.Total = int(Count)
	return vo, nil
}
func SaveGoodsSku(goodsSku *domain.GoodsSku) (domain.GoodsSku, error) {
	_, err := configs.Engine.Table("goods_sku").Insert(&goodsSku)
	if err != nil {
		return *goodsSku, err
	}
	return *goodsSku, nil
}

func SetGoodsSku(goodsSkuMap map[string]interface{}, id int64) (domain.GoodsSku, bool, error) {
	var goodsSku domain.GoodsSku
	_, err := configs.Engine.Table("goods_sku").Where("id = ?", id).Update(goodsSkuMap)
	if err != nil {
		return goodsSku, false, err
	}
	return goodsSku, true, nil
}

func DeleteGoodsSku(id int64) bool {
	var goodsSku domain.GoodsSku
	i, err := configs.Engine.Table("goods_sku").Where("id = ?", id).Delete(&goodsSku)
	if err != nil {
		return false
	}
	return i > 0
}

func GetGoodsSkuCardById(id int64) (domain.GoodsSkuCard, error) {
	var goodsSkuCard domain.GoodsSkuCard
	_, err := configs.Engine.Table("goods_sku_card").Where("id = ?", id).Get(&goodsSkuCard)
	if err != nil {
		return goodsSkuCard, err
	}
	return goodsSkuCard, nil
}

func GetGoodsSkuCardListInId(ids []int64) ([]domain.GoodsSkuCard, error) {
	rows, err := configs.Engine.Table("goods_sku_card").In("id", ids).Rows(&domain.GoodsSkuCard{})
	if err != nil {
		return make([]domain.GoodsSkuCard, 0), err
	}
	defer rows.Close()
	var list []domain.GoodsSkuCard
	for rows.Next() {
		var u domain.GoodsSkuCard
		rows.Scan(&u)
		list = append(list, u)
	}
	return list, nil
}

func GetGoodsSkuCardList(goodsSkuCard domain.GoodsSkuCard, pageNum, pageSize int) (vo.BaseListVo, error) {
	var arr []domain.GoodsSkuCard
	Count, err := configs.Engine.Table("goods_sku_card").Limit(pageSize, (pageNum-1)*pageSize).FindAndCount(&arr, &goodsSkuCard)
	var vo vo.BaseListVo
	if err != nil {
		return vo, err
	}
	if err != nil {
		return vo, err
	}
	vo.PageNum = pageNum
	vo.PageSize = pageSize
	vo.List = make([]any, len(arr))
	for i, v := range arr {
		vo.List[i] = v
	}
	vo.Total = int(Count)
	return vo, nil
}
func Get2GoodsSkuCardList(query domain.GoodsSkuCardQuery, pageNum, pageSize int) (vo.BaseListVo, error) {
	var arr []domain.GoodsSkuCard
	session := configs.Engine.Table("goods_sku_card").Limit(pageSize, (pageNum-1)*pageSize)

	if query.Id != 0 {
		session.Where("id = ?", query.Id)
	}

	if query.CardName != "" {
		session.Where("card_name like ?", "%"+query.CardName+"%")
	}

	if query.State != "" {
		session.Where("state = ?", query.State)
	}

	if query.Count != 0 {
		session.Where("count = ?", query.Count)
	}

	if query.TotalCount != "" {
		session.Where("total_count = ?", query.TotalCount)
	}

	if query.CardKey != "" {
		session.Where("card_key like ?", "%"+query.CardKey+"%")
	}

	if query.Use != "" {
		session.Where("use = ?", query.Use)
	}

	if query.UploadTimeStart != "" || query.UploadTimeEnd != "" {
		session.Where("upload_time between ? and ?", query.UploadTimeStart, query.UploadTimeEnd)
	}

	if query.SkuId != 0 {
		session.Where("sku_id = ?", query.SkuId)
	}

	if query.Sort != "" {
		session.Where("sort = ?", query.Sort)
	}
	Count, err := session.FindAndCount(&arr)
	var vo vo.BaseListVo
	if err != nil {
		return vo, err
	}
	if err != nil {
		return vo, err
	}
	vo.PageNum = pageNum
	vo.PageSize = pageSize
	vo.List = make([]any, len(arr))
	for i, v := range arr {
		vo.List[i] = v
	}
	vo.Total = int(Count)
	return vo, nil
}
func SaveGoodsSkuCard(goodsSkuCard *domain.GoodsSkuCard) (domain.GoodsSkuCard, error) {
	_, err := configs.Engine.Table("goods_sku_card").Insert(&goodsSkuCard)
	if err != nil {
		return *goodsSkuCard, err
	}
	return *goodsSkuCard, nil
}

func SetGoodsSkuCard(goodsSkuCardMap map[string]interface{}, id int64) (domain.GoodsSkuCard, bool, error) {
	var goodsSkuCard domain.GoodsSkuCard
	_, err := configs.Engine.Table("goods_sku_card").Where("id = ?", id).Update(goodsSkuCardMap)
	if err != nil {
		return goodsSkuCard, false, err
	}
	return goodsSkuCard, true, nil
}

func DeleteGoodsSkuCard(id int64) bool {
	var goodsSkuCard domain.GoodsSkuCard
	i, err := configs.Engine.Table("goods_sku_card").Where("id = ?", id).Delete(&goodsSkuCard)
	if err != nil {
		return false
	}
	return i > 0
}

func GetGoodsTagById(id int64) (domain.GoodsTag, error) {
	var goodsTag domain.GoodsTag
	_, err := configs.Engine.Table("goods_tag").Where("id = ?", id).Get(&goodsTag)
	if err != nil {
		return goodsTag, err
	}
	return goodsTag, nil
}

func GetGoodsTagListInId(ids []int64) ([]domain.GoodsTag, error) {
	rows, err := configs.Engine.Table("goods_tag").In("id", ids).Rows(&domain.GoodsTag{})
	if err != nil {
		return make([]domain.GoodsTag, 0), err
	}
	defer rows.Close()
	var list []domain.GoodsTag
	for rows.Next() {
		var u domain.GoodsTag
		rows.Scan(&u)
		list = append(list, u)
	}
	return list, nil
}

func GetGoodsTagList(goodsTag domain.GoodsTag, pageNum, pageSize int) (vo.BaseListVo, error) {
	var arr []domain.GoodsTag
	Count, err := configs.Engine.Table("goods_tag").Limit(pageSize, (pageNum-1)*pageSize).FindAndCount(&arr, &goodsTag)
	var vo vo.BaseListVo
	if err != nil {
		return vo, err
	}
	if err != nil {
		return vo, err
	}
	vo.PageNum = pageNum
	vo.PageSize = pageSize
	vo.List = make([]any, len(arr))
	for i, v := range arr {
		vo.List[i] = v
	}
	vo.Total = int(Count)
	return vo, nil
}
func Get2GoodsTagList(query domain.GoodsTagQuery, pageNum, pageSize int) (vo.BaseListVo, error) {
	var arr []domain.GoodsTag
	session := configs.Engine.Table("goods_tag").Limit(pageSize, (pageNum-1)*pageSize)

	if query.Id != 0 {
		session.Where("id = ?", query.Id)
	}

	if query.Name != "" {
		session.Where("name like ?", "%"+query.Name+"%")
	}

	if query.IconUrl != "" {
		session.Where("icon_url = ?", query.IconUrl)
	}

	if query.Tag != "" {
		session.Where("tag = ?", query.Tag)
	}
	Count, err := session.FindAndCount(&arr)
	var vo vo.BaseListVo
	if err != nil {
		return vo, err
	}
	if err != nil {
		return vo, err
	}
	vo.PageNum = pageNum
	vo.PageSize = pageSize
	vo.List = make([]any, len(arr))
	for i, v := range arr {
		vo.List[i] = v
	}
	vo.Total = int(Count)
	return vo, nil
}
func SaveGoodsTag(goodsTag *domain.GoodsTag) (domain.GoodsTag, error) {
	_, err := configs.Engine.Table("goods_tag").Insert(&goodsTag)
	if err != nil {
		return *goodsTag, err
	}
	return *goodsTag, nil
}

func SetGoodsTag(goodsTagMap map[string]interface{}, id int64) (domain.GoodsTag, bool, error) {
	var goodsTag domain.GoodsTag
	_, err := configs.Engine.Table("goods_tag").Where("id = ?", id).Update(goodsTagMap)
	if err != nil {
		return goodsTag, false, err
	}
	return goodsTag, true, nil
}

func DeleteGoodsTag(id int64) bool {
	var goodsTag domain.GoodsTag
	i, err := configs.Engine.Table("goods_tag").Where("id = ?", id).Delete(&goodsTag)
	if err != nil {
		return false
	}
	return i > 0
}

func GetGoodsTypeById(id int64) (domain.GoodsType, error) {
	var goodsType domain.GoodsType
	_, err := configs.Engine.Table("goods_type").Where("id = ?", id).Get(&goodsType)
	if err != nil {
		return goodsType, err
	}
	return goodsType, nil
}

func GetGoodsTypeListInId(ids []int64) ([]domain.GoodsType, error) {
	rows, err := configs.Engine.Table("goods_type").In("id", ids).Rows(&domain.GoodsType{})
	if err != nil {
		return make([]domain.GoodsType, 0), err
	}
	defer rows.Close()
	var list []domain.GoodsType
	for rows.Next() {
		var u domain.GoodsType
		rows.Scan(&u)
		list = append(list, u)
	}
	return list, nil
}

func GetGoodsTypeList(goodsType domain.GoodsType, pageNum, pageSize int) (vo.BaseListVo, error) {
	var arr []domain.GoodsType
	Count, err := configs.Engine.Table("goods_type").Limit(pageSize, (pageNum-1)*pageSize).FindAndCount(&arr, &goodsType)
	var vo vo.BaseListVo
	if err != nil {
		return vo, err
	}
	if err != nil {
		return vo, err
	}
	vo.PageNum = pageNum
	vo.PageSize = pageSize
	vo.List = make([]any, len(arr))
	for i, v := range arr {
		vo.List[i] = v
	}
	vo.Total = int(Count)
	return vo, nil
}
func Get2GoodsTypeList(query domain.GoodsTypeQuery, pageNum, pageSize int) (vo.BaseListVo, error) {
	var arr []domain.GoodsType
	session := configs.Engine.Table("goods_type").Limit(pageSize, (pageNum-1)*pageSize)

	if query.Id != 0 {
		session.Where("id = ?", query.Id)
	}

	if query.Sort != 0 {
		session.Where("sort = ?", query.Sort)
	}

	if query.TypeImage != "" {
		session.Where("type_image = ?", query.TypeImage)
	}

	if query.TypeName != "" {
		session.Where("type_name like ?", "%"+query.TypeName+"%")
	}

	if query.CreateTimeStart != "" || query.CreateTimeEnd != "" {
		session.Where("create_time between ? and ?", query.CreateTimeStart, query.CreateTimeEnd)
	}
	Count, err := session.FindAndCount(&arr)
	var vo vo.BaseListVo
	if err != nil {
		return vo, err
	}
	if err != nil {
		return vo, err
	}
	vo.PageNum = pageNum
	vo.PageSize = pageSize
	vo.List = make([]any, len(arr))
	for i, v := range arr {
		vo.List[i] = v
	}
	vo.Total = int(Count)
	return vo, nil
}
func SaveGoodsType(goodsType *domain.GoodsType) (domain.GoodsType, error) {
	_, err := configs.Engine.Table("goods_type").Insert(&goodsType)
	if err != nil {
		return *goodsType, err
	}
	return *goodsType, nil
}

func SetGoodsType(goodsTypeMap map[string]interface{}, id int64) (domain.GoodsType, bool, error) {
	var goodsType domain.GoodsType
	_, err := configs.Engine.Table("goods_type").Where("id = ?", id).Update(goodsTypeMap)
	if err != nil {
		return goodsType, false, err
	}
	return goodsType, true, nil
}

func DeleteGoodsType(id int64) bool {
	var goodsType domain.GoodsType
	i, err := configs.Engine.Table("goods_type").Where("id = ?", id).Delete(&goodsType)
	if err != nil {
		return false
	}
	return i > 0
}

func GetUserById(id int64) (domain.User, error) {
	var user domain.User
	_, err := configs.Engine.Table("user").Where("id = ?", id).Get(&user)
	if err != nil {
		return user, err
	}
	return user, nil
}

func GetUserListInId(ids []int64) ([]domain.User, error) {
	rows, err := configs.Engine.Table("user").In("id", ids).Rows(&domain.User{})
	if err != nil {
		return make([]domain.User, 0), err
	}
	defer rows.Close()
	var list []domain.User
	for rows.Next() {
		var u domain.User
		rows.Scan(&u)
		list = append(list, u)
	}
	return list, nil
}

func GetUserList(user domain.User, pageNum, pageSize int) (vo.BaseListVo, error) {
	var arr []domain.User
	Count, err := configs.Engine.Table("user").Limit(pageSize, (pageNum-1)*pageSize).FindAndCount(&arr, &user)
	var vo vo.BaseListVo
	if err != nil {
		return vo, err
	}
	if err != nil {
		return vo, err
	}
	vo.PageNum = pageNum
	vo.PageSize = pageSize
	vo.List = make([]any, len(arr))
	for i, v := range arr {
		vo.List[i] = v
	}
	vo.Total = int(Count)
	return vo, nil
}
func Get2UserList(query domain.UserQuery, pageNum, pageSize int) (vo.BaseListVo, error) {
	var arr []domain.User
	session := configs.Engine.Table("user").Limit(pageSize, (pageNum-1)*pageSize)

	if query.Id != 0 {
		session.Where("id = ?", query.Id)
	}

	if query.Username != "" {
		session.Where("username like ?", "%"+query.Username+"%")
	}

	if query.Password != "" {
		session.Where("password = ?", query.Password)
	}

	if query.CreationTime != 0 {
		session.Where("creation_time = ?", query.CreationTime)
	}

	if query.LoginTime != 0 {
		session.Where("login_time = ?", query.LoginTime)
	}

	if query.Status != "" {
		session.Where("status = ?", query.Status)
	}

	if query.RoleId != 0 {
		session.Where("role_id = ?", query.RoleId)
	}

	if query.Phone != "" {
		session.Where("phone like ?", "%"+query.Phone+"%")
	}

	if query.Email != "" {
		session.Where("email like ?", "%"+query.Email+"%")
	}

	if query.Name != "" {
		session.Where("name like ?", "%"+query.Name+"%")
	}

	if query.Avatar != "" {
		session.Where("avatar = ?", query.Avatar)
	}

	if query.RecommendCode != "" {
		session.Where("recommend_code = ?", query.RecommendCode)
	}

	if query.InviterBy != 0 {
		session.Where("inviter_by = ?", query.InviterBy)
	}
	Count, err := session.FindAndCount(&arr)
	var vo vo.BaseListVo
	if err != nil {
		return vo, err
	}
	if err != nil {
		return vo, err
	}
	vo.PageNum = pageNum
	vo.PageSize = pageSize
	vo.List = make([]any, len(arr))
	for i, v := range arr {
		vo.List[i] = v
	}
	vo.Total = int(Count)
	return vo, nil
}
func SaveUser(user *domain.User) (domain.User, error) {
	_, err := configs.Engine.Table("user").Insert(&user)
	if err != nil {
		return *user, err
	}
	return *user, nil
}

func SetUser(userMap map[string]interface{}, id int64) (domain.User, bool, error) {
	var user domain.User
	_, err := configs.Engine.Table("user").Where("id = ?", id).Update(userMap)
	if err != nil {
		return user, false, err
	}
	return user, true, nil
}

func DeleteUser(id int64) bool {
	var user domain.User
	i, err := configs.Engine.Table("user").Where("id = ?", id).Delete(&user)
	if err != nil {
		return false
	}
	return i > 0
}

func GetUserWalletById(id int64) (domain.UserWallet, error) {
	var userWallet domain.UserWallet
	_, err := configs.Engine.Table("user_wallet").Where("id = ?", id).Get(&userWallet)
	if err != nil {
		return userWallet, err
	}
	return userWallet, nil
}

func GetUserWalletListInId(ids []int64) ([]domain.UserWallet, error) {
	rows, err := configs.Engine.Table("user_wallet").In("id", ids).Rows(&domain.UserWallet{})
	if err != nil {
		return make([]domain.UserWallet, 0), err
	}
	defer rows.Close()
	var list []domain.UserWallet
	for rows.Next() {
		var u domain.UserWallet
		rows.Scan(&u)
		list = append(list, u)
	}
	return list, nil
}

func GetUserWalletList(userWallet domain.UserWallet, pageNum, pageSize int) (vo.BaseListVo, error) {
	var arr []domain.UserWallet
	Count, err := configs.Engine.Table("user_wallet").Limit(pageSize, (pageNum-1)*pageSize).FindAndCount(&arr, &userWallet)
	var vo vo.BaseListVo
	if err != nil {
		return vo, err
	}
	if err != nil {
		return vo, err
	}
	vo.PageNum = pageNum
	vo.PageSize = pageSize
	vo.List = make([]any, len(arr))
	for i, v := range arr {
		vo.List[i] = v
	}
	vo.Total = int(Count)
	return vo, nil
}
func Get2UserWalletList(query domain.UserWalletQuery, pageNum, pageSize int) (vo.BaseListVo, error) {
	var arr []domain.UserWallet
	session := configs.Engine.Table("user_wallet").Limit(pageSize, (pageNum-1)*pageSize)

	if query.Id != 0 {
		session.Where("id = ?", query.Id)
	}

	if query.UserId != 0 {
		session.Where("user_id = ?", query.UserId)
	}

	if query.BalanceStart != 0 || query.BalanceEnd != 0 {
		session.Where("balance between ? and ?", query.BalanceStart, query.BalanceEnd)
	}

	if query.PromotionAmountStart != 0 || query.PromotionAmountEnd != 0 {
		session.Where("promotion_amount between ? and ?", query.PromotionAmountStart, query.PromotionAmountEnd)
	}

	if query.RechargeAmountStart != 0 || query.RechargeAmountEnd != 0 {
		session.Where("recharge_amount between ? and ?", query.RechargeAmountStart, query.RechargeAmountEnd)
	}
	Count, err := session.FindAndCount(&arr)
	var vo vo.BaseListVo
	if err != nil {
		return vo, err
	}
	if err != nil {
		return vo, err
	}
	vo.PageNum = pageNum
	vo.PageSize = pageSize
	vo.List = make([]any, len(arr))
	for i, v := range arr {
		vo.List[i] = v
	}
	vo.Total = int(Count)
	return vo, nil
}
func SaveUserWallet(userWallet *domain.UserWallet) (domain.UserWallet, error) {
	_, err := configs.Engine.Table("user_wallet").Insert(&userWallet)
	if err != nil {
		return *userWallet, err
	}
	return *userWallet, nil
}

func SetUserWallet(userWalletMap map[string]interface{}, id int64) (domain.UserWallet, bool, error) {
	var userWallet domain.UserWallet
	_, err := configs.Engine.Table("user_wallet").Where("id = ?", id).Update(userWalletMap)
	if err != nil {
		return userWallet, false, err
	}
	return userWallet, true, nil
}

func DeleteUserWallet(id int64) bool {
	var userWallet domain.UserWallet
	i, err := configs.Engine.Table("user_wallet").Where("id = ?", id).Delete(&userWallet)
	if err != nil {
		return false
	}
	return i > 0
}

func GetDictDataById(id int64) (domain.DictData, error) {
	var dictData domain.DictData
	_, err := configs.Engine.Table("dict_data").Where("id = ?", id).Get(&dictData)
	if err != nil {
		return dictData, err
	}
	return dictData, nil
}

func GetDictDataListInId(ids []int64) ([]domain.DictData, error) {
	rows, err := configs.Engine.Table("dict_data").In("id", ids).Rows(&domain.DictData{})
	if err != nil {
		return make([]domain.DictData, 0), err
	}
	defer rows.Close()
	var list []domain.DictData
	for rows.Next() {
		var u domain.DictData
		rows.Scan(&u)
		list = append(list, u)
	}
	return list, nil
}

func GetDictDataList(dictData domain.DictData, pageNum, pageSize int) (vo.BaseListVo, error) {
	var arr []domain.DictData
	Count, err := configs.Engine.Table("dict_data").Limit(pageSize, (pageNum-1)*pageSize).FindAndCount(&arr, &dictData)
	var vo vo.BaseListVo
	if err != nil {
		return vo, err
	}
	if err != nil {
		return vo, err
	}
	vo.PageNum = pageNum
	vo.PageSize = pageSize
	vo.List = make([]any, len(arr))
	for i, v := range arr {
		vo.List[i] = v
	}
	vo.Total = int(Count)
	return vo, nil
}
func Get2DictDataList(query domain.DictDataQuery, pageNum, pageSize int) (vo.BaseListVo, error) {
	var arr []domain.DictData
	session := configs.Engine.Table("dict_data").Limit(pageSize, (pageNum-1)*pageSize)

	if query.Id != 0 {
		session.Where("id = ?", query.Id)
	}

	if query.Sort != 0 {
		session.Where("sort = ?", query.Sort)
	}

	if query.DictLabel != "" {
		session.Where("dict_label like ?", "%"+query.DictLabel+"%")
	}

	if query.DictValue != "" {
		session.Where("dict_value like ?", "%"+query.DictValue+"%")
	}

	if query.DictType != "" {
		session.Where("dict_type like ?", "%"+query.DictType+"%")
	}

	if query.Status != "" {
		session.Where("status = ?", query.Status)
	}

	if query.CssStyle != "" {
		session.Where("css_style = ?", query.CssStyle)
	}

	if query.IsDefault != "" {
		session.Where("is_default = ?", query.IsDefault)
	}

	if query.Remark != "" {
		session.Where("remark like ?", "%"+query.Remark+"%")
	}
	Count, err := session.FindAndCount(&arr)
	var vo vo.BaseListVo
	if err != nil {
		return vo, err
	}
	if err != nil {
		return vo, err
	}
	vo.PageNum = pageNum
	vo.PageSize = pageSize
	vo.List = make([]any, len(arr))
	for i, v := range arr {
		vo.List[i] = v
	}
	vo.Total = int(Count)
	return vo, nil
}
func SaveDictData(dictData *domain.DictData) (domain.DictData, error) {
	_, err := configs.Engine.Table("dict_data").Insert(&dictData)
	if err != nil {
		return *dictData, err
	}
	return *dictData, nil
}

func SetDictData(dictDataMap map[string]interface{}, id int64) (domain.DictData, bool, error) {
	var dictData domain.DictData
	_, err := configs.Engine.Table("dict_data").Where("id = ?", id).Update(dictDataMap)
	if err != nil {
		return dictData, false, err
	}
	return dictData, true, nil
}

func DeleteDictData(id int64) bool {
	var dictData domain.DictData
	i, err := configs.Engine.Table("dict_data").Where("id = ?", id).Delete(&dictData)
	if err != nil {
		return false
	}
	return i > 0
}

func GetDictTypeById(id int64) (domain.DictType, error) {
	var dictType domain.DictType
	_, err := configs.Engine.Table("dict_type").Where("id = ?", id).Get(&dictType)
	if err != nil {
		return dictType, err
	}
	return dictType, nil
}

func GetDictTypeListInId(ids []int64) ([]domain.DictType, error) {
	rows, err := configs.Engine.Table("dict_type").In("id", ids).Rows(&domain.DictType{})
	if err != nil {
		return make([]domain.DictType, 0), err
	}
	defer rows.Close()
	var list []domain.DictType
	for rows.Next() {
		var u domain.DictType
		rows.Scan(&u)
		list = append(list, u)
	}
	return list, nil
}

func GetDictTypeList(dictType domain.DictType, pageNum, pageSize int) (vo.BaseListVo, error) {
	var arr []domain.DictType
	Count, err := configs.Engine.Table("dict_type").Limit(pageSize, (pageNum-1)*pageSize).FindAndCount(&arr, &dictType)
	var vo vo.BaseListVo
	if err != nil {
		return vo, err
	}
	if err != nil {
		return vo, err
	}
	vo.PageNum = pageNum
	vo.PageSize = pageSize
	vo.List = make([]any, len(arr))
	for i, v := range arr {
		vo.List[i] = v
	}
	vo.Total = int(Count)
	return vo, nil
}
func Get2DictTypeList(query domain.DictTypeQuery, pageNum, pageSize int) (vo.BaseListVo, error) {
	var arr []domain.DictType
	session := configs.Engine.Table("dict_type").Limit(pageSize, (pageNum-1)*pageSize)

	if query.Id != 0 {
		session.Where("id = ?", query.Id)
	}

	if query.DictName != "" {
		session.Where("dict_name like ?", "%"+query.DictName+"%")
	}

	if query.DictType != "" {
		session.Where("dict_type like ?", "%"+query.DictType+"%")
	}

	if query.Status != "" {
		session.Where("status = ?", query.Status)
	}

	if query.Remark != "" {
		session.Where("remark like ?", "%"+query.Remark+"%")
	}
	Count, err := session.FindAndCount(&arr)
	var vo vo.BaseListVo
	if err != nil {
		return vo, err
	}
	if err != nil {
		return vo, err
	}
	vo.PageNum = pageNum
	vo.PageSize = pageSize
	vo.List = make([]any, len(arr))
	for i, v := range arr {
		vo.List[i] = v
	}
	vo.Total = int(Count)
	return vo, nil
}
func SaveDictType(dictType *domain.DictType) (domain.DictType, error) {
	_, err := configs.Engine.Table("dict_type").Insert(&dictType)
	if err != nil {
		return *dictType, err
	}
	return *dictType, nil
}

func SetDictType(dictTypeMap map[string]interface{}, id int64) (domain.DictType, bool, error) {
	var dictType domain.DictType
	_, err := configs.Engine.Table("dict_type").Where("id = ?", id).Update(dictTypeMap)
	if err != nil {
		return dictType, false, err
	}
	return dictType, true, nil
}

func DeleteDictType(id int64) bool {
	var dictType domain.DictType
	i, err := configs.Engine.Table("dict_type").Where("id = ?", id).Delete(&dictType)
	if err != nil {
		return false
	}
	return i > 0
}

func GetShopTopicById(id int64) (domain.ShopTopic, error) {
	var shopTopic domain.ShopTopic
	_, err := configs.Engine.Table("shop_topic").Where("id = ?", id).Get(&shopTopic)
	if err != nil {
		return shopTopic, err
	}
	return shopTopic, nil
}

func GetShopTopicListInId(ids []int64) ([]domain.ShopTopic, error) {
	rows, err := configs.Engine.Table("shop_topic").In("id", ids).Rows(&domain.ShopTopic{})
	if err != nil {
		return make([]domain.ShopTopic, 0), err
	}
	defer rows.Close()
	var list []domain.ShopTopic
	for rows.Next() {
		var u domain.ShopTopic
		rows.Scan(&u)
		list = append(list, u)
	}
	return list, nil
}

func GetShopTopicList(shopTopic domain.ShopTopic, pageNum, pageSize int) (vo.BaseListVo, error) {
	var arr []domain.ShopTopic
	Count, err := configs.Engine.Table("shop_topic").Limit(pageSize, (pageNum-1)*pageSize).FindAndCount(&arr, &shopTopic)
	var vo vo.BaseListVo
	if err != nil {
		return vo, err
	}
	if err != nil {
		return vo, err
	}
	vo.PageNum = pageNum
	vo.PageSize = pageSize
	vo.List = make([]any, len(arr))
	for i, v := range arr {
		vo.List[i] = v
	}
	vo.Total = int(Count)
	return vo, nil
}
func Get2ShopTopicList(query domain.ShopTopicQuery, pageNum, pageSize int) (vo.BaseListVo, error) {
	var arr []domain.ShopTopic
	session := configs.Engine.Table("shop_topic").Limit(pageSize, (pageNum-1)*pageSize)

	if query.Id != 0 {
		session.Where("id = ?", query.Id)
	}

	if query.Sort != "" {
		session.Where("sort = ?", query.Sort)
	}

	if query.ParentId != 0 {
		session.Where("parent_id = ?", query.ParentId)
	}

	if query.TopicPageImage != "" {
		session.Where("topic_page_image = ?", query.TopicPageImage)
	}

	if query.TopicName != "" {
		session.Where("topic_name like ?", "%"+query.TopicName+"%")
	}

	if query.TopicDesc != "" {
		session.Where("topic_desc like ?", "%"+query.TopicDesc+"%")
	}

	if query.TypeIds != "" {
		session.Where("type_ids = ?", query.TypeIds)
	}
	Count, err := session.FindAndCount(&arr)
	var vo vo.BaseListVo
	if err != nil {
		return vo, err
	}
	if err != nil {
		return vo, err
	}
	vo.PageNum = pageNum
	vo.PageSize = pageSize
	vo.List = make([]any, len(arr))
	for i, v := range arr {
		vo.List[i] = v
	}
	vo.Total = int(Count)
	return vo, nil
}
func SaveShopTopic(shopTopic *domain.ShopTopic) (domain.ShopTopic, error) {
	_, err := configs.Engine.Table("shop_topic").Insert(&shopTopic)
	if err != nil {
		return *shopTopic, err
	}
	return *shopTopic, nil
}

func SetShopTopic(shopTopicMap map[string]interface{}, id int64) (domain.ShopTopic, bool, error) {
	var shopTopic domain.ShopTopic
	_, err := configs.Engine.Table("shop_topic").Where("id = ?", id).Update(shopTopicMap)
	if err != nil {
		return shopTopic, false, err
	}
	return shopTopic, true, nil
}

func DeleteShopTopic(id int64) bool {
	var shopTopic domain.ShopTopic
	i, err := configs.Engine.Table("shop_topic").Where("id = ?", id).Delete(&shopTopic)
	if err != nil {
		return false
	}
	return i > 0
}

func GetShopAdviceCarouselById(id int64) (domain.ShopAdviceCarousel, error) {
	var shopAdviceCarousel domain.ShopAdviceCarousel
	_, err := configs.Engine.Table("shop_advice_carousel").Where("id = ?", id).Get(&shopAdviceCarousel)
	if err != nil {
		return shopAdviceCarousel, err
	}
	return shopAdviceCarousel, nil
}

func GetShopAdviceCarouselListInId(ids []int64) ([]domain.ShopAdviceCarousel, error) {
	rows, err := configs.Engine.Table("shop_advice_carousel").In("id", ids).Rows(&domain.ShopAdviceCarousel{})
	if err != nil {
		return make([]domain.ShopAdviceCarousel, 0), err
	}
	defer rows.Close()
	var list []domain.ShopAdviceCarousel
	for rows.Next() {
		var u domain.ShopAdviceCarousel
		rows.Scan(&u)
		list = append(list, u)
	}
	return list, nil
}

func GetShopAdviceCarouselList(shopAdviceCarousel domain.ShopAdviceCarousel, pageNum, pageSize int) (vo.BaseListVo, error) {
	var arr []domain.ShopAdviceCarousel
	Count, err := configs.Engine.Table("shop_advice_carousel").Limit(pageSize, (pageNum-1)*pageSize).FindAndCount(&arr, &shopAdviceCarousel)
	var vo vo.BaseListVo
	if err != nil {
		return vo, err
	}
	if err != nil {
		return vo, err
	}
	vo.PageNum = pageNum
	vo.PageSize = pageSize
	vo.List = make([]any, len(arr))
	for i, v := range arr {
		vo.List[i] = v
	}
	vo.Total = int(Count)
	return vo, nil
}
func Get2ShopAdviceCarouselList(query domain.ShopAdviceCarouselQuery, pageNum, pageSize int) (vo.BaseListVo, error) {
	var arr []domain.ShopAdviceCarousel
	session := configs.Engine.Table("shop_advice_carousel").Limit(pageSize, (pageNum-1)*pageSize)

	if query.Id != 0 {
		session.Where("id = ?", query.Id)
	}

	if query.Name != "" {
		session.Where("name like ?", "%"+query.Name+"%")
	}

	if query.ToId != 0 {
		session.Where("to_id = ?", query.ToId)
	}

	if query.AdviceType != "" {
		session.Where("advice_type = ?", query.AdviceType)
	}

	if query.Sort != "" {
		session.Where("sort = ?", query.Sort)
	}

	if query.State != "" {
		session.Where("state = ?", query.State)
	}

	if query.ShowType != "" {
		session.Where("show_type = ?", query.ShowType)
	}

	if query.CreateBy != "" {
		session.Where("create_by = ?", query.CreateBy)
	}

	if query.CreateTime != "" {
		session.Where("create_time = ?", query.CreateTime)
	}

	if query.UpdateBy != "" {
		session.Where("update_by = ?", query.UpdateBy)
	}

	if query.UpdateTime != "" {
		session.Where("update_time = ?", query.UpdateTime)
	}

	if query.ImageUrl != "" {
		session.Where("image_url = ?", query.ImageUrl)
	}

	if query.ToType != "" {
		session.Where("to_type = ?", query.ToType)
	}
	Count, err := session.FindAndCount(&arr)
	var vo vo.BaseListVo
	if err != nil {
		return vo, err
	}
	if err != nil {
		return vo, err
	}
	vo.PageNum = pageNum
	vo.PageSize = pageSize
	vo.List = make([]any, len(arr))
	for i, v := range arr {
		vo.List[i] = v
	}
	vo.Total = int(Count)
	return vo, nil
}
func SaveShopAdviceCarousel(shopAdviceCarousel *domain.ShopAdviceCarousel) (domain.ShopAdviceCarousel, error) {
	_, err := configs.Engine.Table("shop_advice_carousel").Insert(&shopAdviceCarousel)
	if err != nil {
		return *shopAdviceCarousel, err
	}
	return *shopAdviceCarousel, nil
}

func SetShopAdviceCarousel(shopAdviceCarouselMap map[string]interface{}, id int64) (domain.ShopAdviceCarousel, bool, error) {
	var shopAdviceCarousel domain.ShopAdviceCarousel
	_, err := configs.Engine.Table("shop_advice_carousel").Where("id = ?", id).Update(shopAdviceCarouselMap)
	if err != nil {
		return shopAdviceCarousel, false, err
	}
	return shopAdviceCarousel, true, nil
}

func DeleteShopAdviceCarousel(id int64) bool {
	var shopAdviceCarousel domain.ShopAdviceCarousel
	i, err := configs.Engine.Table("shop_advice_carousel").Where("id = ?", id).Delete(&shopAdviceCarousel)
	if err != nil {
		return false
	}
	return i > 0
}

func GetShopTopicSkuById(id int64) (domain.ShopTopicSku, error) {
	var shopTopicSku domain.ShopTopicSku
	_, err := configs.Engine.Table("shop_topic_sku").Where("id = ?", id).Get(&shopTopicSku)
	if err != nil {
		return shopTopicSku, err
	}
	return shopTopicSku, nil
}

func GetShopTopicSkuListInId(ids []int64) ([]domain.ShopTopicSku, error) {
	rows, err := configs.Engine.Table("shop_topic_sku").In("id", ids).Rows(&domain.ShopTopicSku{})
	if err != nil {
		return make([]domain.ShopTopicSku, 0), err
	}
	defer rows.Close()
	var list []domain.ShopTopicSku
	for rows.Next() {
		var u domain.ShopTopicSku
		rows.Scan(&u)
		list = append(list, u)
	}
	return list, nil
}

func GetShopTopicSkuList(shopTopicSku domain.ShopTopicSku, pageNum, pageSize int) (vo.BaseListVo, error) {
	var arr []domain.ShopTopicSku
	Count, err := configs.Engine.Table("shop_topic_sku").Limit(pageSize, (pageNum-1)*pageSize).FindAndCount(&arr, &shopTopicSku)
	var vo vo.BaseListVo
	if err != nil {
		return vo, err
	}
	if err != nil {
		return vo, err
	}
	vo.PageNum = pageNum
	vo.PageSize = pageSize
	vo.List = make([]any, len(arr))
	for i, v := range arr {
		vo.List[i] = v
	}
	vo.Total = int(Count)
	return vo, nil
}
func Get2ShopTopicSkuList(query domain.ShopTopicSkuQuery, pageNum, pageSize int) (vo.BaseListVo, error) {
	var arr []domain.ShopTopicSku
	session := configs.Engine.Table("shop_topic_sku").Limit(pageSize, (pageNum-1)*pageSize)

	if query.Id != 0 {
		session.Where("id = ?", query.Id)
	}

	if query.TopicId != 0 {
		session.Where("topic_id = ?", query.TopicId)
	}

	if query.SkuId != 0 {
		session.Where("sku_id = ?", query.SkuId)
	}
	Count, err := session.FindAndCount(&arr)
	var vo vo.BaseListVo
	if err != nil {
		return vo, err
	}
	if err != nil {
		return vo, err
	}
	vo.PageNum = pageNum
	vo.PageSize = pageSize
	vo.List = make([]any, len(arr))
	for i, v := range arr {
		vo.List[i] = v
	}
	vo.Total = int(Count)
	return vo, nil
}
func SaveShopTopicSku(shopTopicSku *domain.ShopTopicSku) (domain.ShopTopicSku, error) {
	_, err := configs.Engine.Table("shop_topic_sku").Insert(&shopTopicSku)
	if err != nil {
		return *shopTopicSku, err
	}
	return *shopTopicSku, nil
}

func SetShopTopicSku(shopTopicSkuMap map[string]interface{}, id int64) (domain.ShopTopicSku, bool, error) {
	var shopTopicSku domain.ShopTopicSku
	_, err := configs.Engine.Table("shop_topic_sku").Where("id = ?", id).Update(shopTopicSkuMap)
	if err != nil {
		return shopTopicSku, false, err
	}
	return shopTopicSku, true, nil
}

func DeleteShopTopicSku(id int64) bool {
	var shopTopicSku domain.ShopTopicSku
	i, err := configs.Engine.Table("shop_topic_sku").Where("id = ?", id).Delete(&shopTopicSku)
	if err != nil {
		return false
	}
	return i > 0
}
