You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

90 lines
3.4 KiB

4 years ago
package user
import (
"github.com/golangkit/formatime"
"github.com/jinzhu/gorm"
"recook/internal/model/user"
"recook/internal/v2/lib/db"
4 years ago
manage "recook/internal/v2/model/recook/order"
4 years ago
)
type RecookUserInfoModel struct {
db.BaseModel
Id uint `gorm:"column:id" json:"id"`
RoleId uint `json:"roleId"`
Nickname string `json:"nickname"`
HeadImgUrl string `json:"headImgUrl"`
RemarkName string `json:"remarkName"`
Phone string `json:"phone"`
Mobile string `json:"-"`
WechatNo string `json:"wechatNo"`
WxUnionID string `json:"-"`
4 years ago
Secret uint `json:"secret"`
CreatedAt formatime.Second `json:"createdAt"`
RoleUpdateTime formatime.Second `json:"roleUpdateTime"`
Birthday formatime.Second `gorm:"column:birthday" json:"birthday"`
Gender uint `gorm:"column:gender;default:0" json:"gender"`
RealName string
IDCard string
Province string
City string
4 years ago
Wallet user.Wallet `gorm:"foreignKey:UserID"`
Level int `json:"level"`
ParentID uint `json:"parent_id"`
UpgradeTime1 formatime.Second `json:"upgrade_time1"`
UpgradeTime2 formatime.Second `json:"upgrade_time2"`
AgentID uint `json:"agent_id"`
OrderList []manage.RecookOrderInfoModel `json:"-" gorm:"foreignKey:user_id"`
4 years ago
}
// TableName sets the insert table name for this struct type
func (r *RecookUserInfoModel) TableName() string {
return "recook_user_info"
}
// @Style 添加
func (r *RecookUserInfoModel) Create(data *RecookUserInfoModel) {
r.GetDb().Create(data)
}
// @Style 根据userId获取数据
func (r *RecookUserInfoModel) FindById(userId uint) (result RecookUserInfoModel) {
r.GetDb().Model(&RecookUserInfoModel{}).First(&result, "id = ?", userId)
return
}
// @Style 根据userIds获取数据
func (r *RecookUserInfoModel) FindByIds(userIds []uint) (result []RecookUserInfoModel) {
r.GetDb().Model(&RecookUserInfoModel{}).Find(&result, "id in (?)", userIds)
return
}
// @Style 更新个人信息
func (r *RecookUserInfoModel) UpdateById(userId uint, data map[string]interface{}) error {
return r.GetDb().Model(&RecookUserInfoModel{}).Where("id = ?", userId).Updates(data).Error
}
// @Style 获取列表数量
func (r *RecookUserInfoModel) ListCount(query interface{}, args ...interface{}) *gorm.SqlExpr {
return r.GetDb().Model(&RecookUserInfoModel{}).Select("id").Where(query, args...).SubQuery()
}
// @Style 更新个人信息
func (r *RecookUserInfoModel) Updates(data map[string]interface{}, query interface{}, args ...interface{}) error {
return r.GetDb().Model(&RecookUserInfoModel{}).Where(query, args...).Updates(data).Error
}
// @Style 获取列表数量
func (r *RecookUserInfoModel) List(start, limit int, order string, query interface{}, args ...interface{}) (result []RecookUserInfoModel) {
r.GetDb().Model(&RecookUserInfoModel{}).Offset(start).Limit(limit).Where(query, args...).Order(order).Find(&result)
return
}
func (r *RecookUserInfoModel) WXUnbuding(id uint) error {
data := make(map[string]interface{})
data["wx_union_id"] = ""
data["wx_app_open_id"] = ""
data["wechat_no"] = ""
return r.GetDb().Model(&RecookUserInfoModel{}).Where("id=?", id).Updates(data).Error
}