package wx_user

import (
	"errors"
	"hongze/hongze_yb/global"
	"hongze/hongze_yb/utils"
)

// GetByMobile 根据手机号获取信息
func GetByMobile(mobile string) (wxUser *WxUser, err error) {
	err = global.DEFAULT_MYSQL.Where("mobile = ? ", mobile).First(&wxUser).Error
	return
}

// GetByEmail 根据邮箱号号获取信息
func GetByEmail(email string) (wxUser *WxUser, err error) {
	err = global.DEFAULT_MYSQL.Where("email = ? ", email).First(&wxUser).Error
	return
}

// GetByWhereMap 根据查询条件map获取信息
func GetByWhereMap(where map[string]interface{}) (wxUser *WxUser, err error) {
	cond, whereVal, buildErr := utils.WhereBuild(where)
	if buildErr != nil {
		err = errors.New("系统异常，生成查询语句失败")
		return
	}
	err = global.DEFAULT_MYSQL.Where(cond, whereVal...).First(&wxUser).Error
	return
}

// GetByUserId 根据user_id获取用户信息
func GetByUserId(userId int) (wxUser *WxUser, err error) {
	err = global.DEFAULT_MYSQL.Where("user_id =  ? ", userId).First(&wxUser).Error
	return
}
