123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- package crm
- import (
- "hongze/hz_crm_eta/global"
- "time"
- )
- // EtaTrial ETA试用
- type EtaTrial struct {
- EtaTrialId int `gorm:"primaryKey;column:eta_trial_id;type:int(11);not null" json:"eta_trial_id"`
- UserName string `gorm:"column:user_name;type:varchar(100);default:''" json:"user_name"`
- CompanyName string `gorm:"column:company_name;type:varchar(100);default:''" json:"company_name"`
- Position string `gorm:"column:position;type:varchar(100);default:''" json:"position"` // 职务
- Account string `gorm:"column:account;type:varchar(100);default:''" json:"account"` // 账号
- Password string `gorm:"column:password;type:varchar(100);default:''" json:"password"` // 账号
- Mobile string `gorm:"column:mobile;type:varchar(20)" json:"mobile"` // 手机号
- ActiveTime int `gorm:"column:active_time;type:int(11) unsigned;default:0" json:"active_time"` // 累计活跃时长
- IndexNum int `gorm:"column:index_num;type:int(11) unsigned;default:0" json:"index_num"` // 累计添加指标
- ChartNum int `gorm:"column:chart_num;type:int(11) unsigned;default:0" json:"chart_num"` // 累计添加图表
- LoginNum int `gorm:"column:login_num;type:int(11) unsigned;default:0" json:"login_num"` // 累计登录次数
- Enabled int `gorm:"column:enabled;type:tinyint(1);not null;default:1" json:"enabled"` // 1:有效,0:禁用
- LastLoginTime time.Time `gorm:"column:last_login_time;type:datetime" json:"last_login_time"` // 最后一次登陆时间
- CreateTime time.Time `gorm:"column:create_time;type:datetime" json:"create_time"` // 申请时间
- ModifyTime time.Time `gorm:"column:modify_time;type:datetime" json:"modify_time"` // 账号更新时间
- Seller string `gorm:"column:seller;type:varchar(200);default:''" json:"seller"` // 销售员
- SellerId int `gorm:"column:seller_id;type:bigint(20);default:0" json:"seller_id"` // 销售员id
- }
- type EtaTrialItem struct {
- EtaTrialId int `gorm:"primaryKey;column:eta_trial_id;type:int(11);not null"`
- UserName string `gorm:"column:user_name;type:varchar(100);default:''"`
- CompanyName string `gorm:"column:company_name;type:varchar(100);default:''"`
- Position string `gorm:"column:position;type:varchar(100);default:''"` // 职务
- Account string `gorm:"column:account;type:varchar(100);default:''"` // 账号
- Password string `gorm:"column:password;type:varchar(100);default:''"` // 账号
- Mobile string `gorm:"column:mobile;type:varchar(20)"` // 手机号
- ActiveTime int `gorm:"column:active_time;type:int(11) unsigned;default:0"` // 累计活跃时长
- IndexNum int `gorm:"column:index_num;type:int(11) unsigned;default:0"` // 累计添加指标
- ChartNum int `gorm:"column:chart_num;type:int(11) unsigned;default:0"` // 累计添加图表
- LoginNum int `gorm:"column:login_num;type:int(11) unsigned;default:0"` // 累计登录次数
- Enabled int `gorm:"column:enabled;type:tinyint(1);not null;default:1"` // 1:有效,0:禁用
- LastLoginTime time.Time `gorm:"column:last_login_time;type:datetime"` // 最后一次登陆时间
- CreateTime time.Time `gorm:"column:create_time;type:datetime"` // 申请时间
- ModifyTime time.Time `gorm:"column:modify_time;type:datetime"` // 账号更新时间
- Seller string `gorm:"column:seller;type:varchar(200);default:''"` // 销售员
- SellerId int `gorm:"column:seller_id;type:bigint(20);default:0"` // 销售员id
- }
- func (m *EtaTrial) TableName() string {
- return "eta_trial"
- }
- // Create 新增
- func (m *EtaTrial) Create() (err error) {
- err = global.MYSQL["hz_crm"].Create(m).Error
- return
- }
- // Update 更新
- func (m *EtaTrial) Update(cols []string) (err error) {
- err = global.MYSQL["hz_crm"].Model(m).Select(cols).Updates(m).Error
- return
- }
- // GetEtaTrialByMobile 手机号获取试用客户
- func GetEtaTrialByMobile(mobile string) (item *EtaTrialItem, err error) {
- err = global.MYSQL["hz_crm"].Model(EtaTrial{}).Where("mobile = ?", mobile).First(&item).Error
- 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 = ?`
- err = global.MYSQL["hz_crm"].Exec(sql, expTime, mobile).Error
- return
- }
- // DeleteEtaTrialByMobile 删除客户
- func DeleteEtaTrialByMobile(mobile string) (err error) {
- sql := `DELETE FROM eta_trial WHERE mobile = ?`
- err = global.MYSQL["hz_crm"].Exec(sql, mobile).Error
- return
- }
- // UpdateEtaTrailActiveTime 更新用户累计活跃时间
- func UpdateEtaTrailActiveTime(activeTime int, mobile string) (err error) {
- sql := `UPDATE eta_trial SET active_time = active_time + ? WHERE mobile = ?`
- err = global.MYSQL["hz_crm"].Exec(sql, activeTime, mobile).Error
- return
- }
- // UpdateEtaTrialLoginByMobile 更新用户最后登录时间和次数
- func UpdateEtaTrialLoginByMobile(mobile string) (err error) {
- sql := `UPDATE eta_trial SET last_login_time = NOW(), login_num = login_num + 1 WHERE mobile = ?`
- err = global.MYSQL["hz_crm"].Exec(sql, mobile).Error
- return
- }
- // UpdateEtaTrialIndexNumByMobile 更新累计添加指标数
- func UpdateEtaTrialIndexNumByMobile(mobile string) (err error) {
- sql := `UPDATE eta_trial SET index_num = index_num + 1 WHERE mobile = ?`
- err = global.MYSQL["hz_crm"].Exec(sql, mobile).Error
- return
- }
- // UpdateEtaTrialChartNumByMobile 更新累计添加图表数
- func UpdateEtaTrialChartNumByMobile(mobile string) (err error) {
- sql := `UPDATE eta_trial SET chart_num = chart_num + 1 WHERE mobile = ?`
- err = global.MYSQL["hz_crm"].Exec(sql, mobile).Error
- return
- }
- // UpdateEtaTrialPositionByMobile 更新用户相关信息
- func UpdateEtaTrialPositionByMobile(realName, position, mobile string, enable int) (err error) {
- 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 = global.MYSQL["hz_crm"].Exec(sql, realName, position, enable, expTime, mobile).Error
- return
- }
- // 启用
- sql = `UPDATE eta_trial SET user_name = ?, position = ?, enabled = ? WHERE mobile = ?`
- err = global.MYSQL["hz_crm"].Exec(sql, realName, position, enable, mobile).Error
- return
- }
- // UpdateEtaTrailLastLoginDuration 更新用户最后一次登录时长
- func UpdateEtaTrailLastLoginDuration(activeTime int, mobile string) (err error) {
- sql := `UPDATE eta_trial SET last_login_duration = ? WHERE mobile = ?`
- err = global.MYSQL["hz_crm"].Exec(sql, activeTime, mobile).Error
- return
- }
|