package my_chart_classify

import (
	"fmt"
	"hongze/hongze_yb/global"
	"time"
)

// UpdateMyChartClassifySortByClassifyId 根据分类ID更新排序
func UpdateMyChartClassifySortByClassifyId(adminId, classifyId, nowSort int, updateSort string) (err error) {
	sql := ` update my_chart_classify set sort = ` + updateSort + ` WHERE admin_id = ? and sort > ? `
	if classifyId > 0 {
		sql += ` or ( my_chart_classify_id > ` + fmt.Sprint(classifyId) + ` and sort = ` + fmt.Sprint(nowSort) + `)`
	}
	err = global.MYSQL["data"].Exec(sql, adminId, nowSort).Error

	return
}

// UpdateClassifySort 更新分类排序
func UpdateClassifySort(adminId, classifyId, nowSort int, modifyTime time.Time) (err error) {
	err = global.MYSQL["data"].Model(MyChartClassify{}).Select("Sort", "ModifyTime").Where("admin_id = ? AND my_chart_classify_id = ?", adminId, classifyId).Updates(MyChartClassify{
		Sort: nowSort,
		ModifyTime: modifyTime,
	}).Error
	return
}
