123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- package models
- import (
- "github.com/beego/beego/v2/client/orm"
- "time"
- )
- type EtaTrial struct {
- EtaTrialId int `orm:"column(eta_trial_id);pk" description:"eta试用客户id"`
- UserName string `description:"客户名称"`
- CompanyName string `description:"客户公司姓名"`
- Position string `description:"职位"`
- Password string `json:"-"`
- Account string `json:"-"`
- Mobile string `description:"手机号"`
- Enabled int `description:"1:有效,0:禁用"`
- ActiveTime int `description:"累计活跃时长"`
- LastLoginTime time.Time `description:"最后一次登陆时间"`
- SellerId int `description:"销售id"`
- Seller string `description:"销售员名称"`
- CreateTime time.Time
- ModifyTime time.Time
- LastLoginDuration int `description:"最后一次登录时长"`
- }
- type EtaTrialItem struct {
- EtaTrialId int `orm:"column(eta_trial_id);pk"`
- UserName string
- CompanyName string
- Position string // 职务
- Account string // 账号
- Password string // 账号
- Mobile string // 手机号 s
- ActiveTime int // 累计活跃时长
- IndexNum int // 累计添加指标
- ChartNum int // 累计添加图表
- LoginNum int // 累计登录次数
- Enabled int // 1:有效,0:禁用
- LastLoginTime time.Time // 最后一次登陆时间
- CreateTime time.Time // 申请时间
- ModifyTime time.Time // 账号更新时间
- Seller string // 销售员
- SellerId int // 销售员id
- }
- // Update 更新用户基础信息
- func (item *EtaTrial) Update(cols []string) (err error) {
- o := orm.NewOrm()
- _, err = o.Update(item, cols...)
- return
- }
- // GetEtaTrialByMobile 手机号获取试用客户
- func GetEtaTrialByMobile(mobile string) (item *EtaTrialItem, err error) {
- o := orm.NewOrm()
- sql := `SELECT * FROM eta_trial WHERE mobile = ?`
- err = o.Raw(sql, mobile).QueryRow(&item)
- return
- }
- // DisableEtaTrailByMobile 禁用客户
- func DisableEtaTrailByMobile(mobile string) (err error) {
- expTime := time.Now().AddDate(0, 0, -14)
- sql := `UPDATE eta_trial SET enabled = 0, modify_time = ? WHERE mobile = ?`
- o := orm.NewOrm()
- _, err = o.Raw(sql, expTime, mobile).Exec()
- return
- }
- // DeleteEtaTrialByMobile 删除客户
- func DeleteEtaTrialByMobile(mobile string) (err error) {
- sql := `DELETE FROM eta_trial WHERE mobile = ?`
- o := orm.NewOrm()
- _, err = o.Raw(sql, mobile).Exec()
- return
- }
- // UpdateEtaTrailActiveTime 更新用户累计活跃时间
- func UpdateEtaTrailActiveTime(activeTime int, mobile string) (err error) {
- sql := `UPDATE eta_trial SET active_time = active_time + ? WHERE mobile = ?`
- o := orm.NewOrm()
- _, err = o.Raw(sql, activeTime, mobile).Exec()
- return
- }
- // UpdateEtaTrialLoginByMobile 更新用户最后登录时间和次数
- func UpdateEtaTrialLoginByMobile(mobile string) (err error) {
- sql := `UPDATE eta_trial SET last_login_time = NOW(), login_num = login_num + 1 WHERE mobile = ?`
- o := orm.NewOrm()
- _, err = o.Raw(sql, mobile).Exec()
- return
- }
- // UpdateEtaTrialIndexNumByMobile 更新累计添加指标数
- func UpdateEtaTrialIndexNumByMobile(mobile string) (err error) {
- sql := `UPDATE eta_trial SET index_num = index_num + 1 WHERE mobile = ?`
- o := orm.NewOrm()
- _, err = o.Raw(sql, mobile).Exec()
- return
- }
- // UpdateEtaTrialChartNumByMobile 更新累计添加图表数
- func UpdateEtaTrialChartNumByMobile(mobile string) (err error) {
- sql := `UPDATE eta_trial SET chart_num = chart_num + 1 WHERE mobile = ?`
- o := orm.NewOrm()
- _, err = o.Raw(sql, mobile).Exec()
- return
- }
- // UpdateEtaTrialPositionByMobile 更新用户相关信息
- func UpdateEtaTrialPositionByMobile(realName, position, mobile string, enable int) (err error) {
- o := orm.NewOrm()
- sql := ``
- // 禁用
- if enable == 0 {
- expTime := time.Now().AddDate(0, 0, -14)
- sql = `UPDATE eta_trial SET user_name = ?, position = ?, enabled = ?, modify_time = ? WHERE mobile = ?`
- _, err = o.Raw(sql, realName, position, enable, expTime, mobile).Exec()
- return
- }
- // 启用
- sql = `UPDATE eta_trial SET user_name = ?, position = ?, enabled = ? WHERE mobile = ?`
- _, err = o.Raw(sql, realName, position, enable, mobile).Exec()
- return
- }
- // UpdateEtaTrailLastLoginDuration 更新用户最后一次登录时长
- func UpdateEtaTrailLastLoginDuration(activeTime int, mobile string) (err error) {
- o := orm.NewOrm()
- sql := `UPDATE eta_trial SET last_login_duration = ? WHERE mobile = ?`
- _, err = o.Raw(sql, activeTime, mobile).Exec()
- return
- }
|