package wx_user

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

// Update 更新对应字段数据
func (wxUser *WxUser) Update(updateCols []string) (err error) {
	err = global.DEFAULT_MYSQL.Model(wxUser).Select(updateCols).Updates(*wxUser).Error
	return
}

// ModifyWxUserRegisterStatus 变更联系人是否已注册状态
func (wxUser *WxUser) ModifyWxUserRegisterStatus(isRegister, source int8, registerTime time.Time) (err error) {

	wxUser.IsRegister = isRegister
	wxUser.Source = source
	wxUser.RegisterTime = registerTime
	var updateCols = []string{"IsRegister", "Source", "RegisterTime"}
	err = wxUser.Update(updateCols)

	return
}

// ModifyFirstLogin 变更联系人是否第一次登录
func ModifyFirstLogin(userId uint64) (err error) {
	err = global.DEFAULT_MYSQL.Model(WxUser{}).Select("FirstLogin").Where("user_id = ? ", userId).Updates(WxUser{
		FirstLogin: 0,
	}).Error
	return
}

// SetWxUserReportLastViewTime 修改最新阅读时间
func (wxUser *WxUser) SetWxUserReportLastViewTime() (err error) {
	wxUser.ReportLastViewTime = time.Now()
	var updateCols = []string{"ReportLastViewTime"}
	err = wxUser.Update(updateCols)
	return
}
