package eta_trial import ( "eta/eta_forum_admin/utils" "github.com/beego/beego/v2/client/orm" "github.com/rdlucklib/rdluck_tools/paging" "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 TrialAccountTransferReq struct { EtaTrialIdList []int `description:"转移使用用户id列表"` CurrentSellerId int `description:"转移后员工id"` CurrentSellerName string `description:"转移后员工名称"` IsCheckAll bool `description:"是否全选"` } // Update 更新用户基础信息 func (item *EtaTrial) Update(cols []string) (err error) { o := orm.NewOrm() _, err = o.Update(item, cols...) return } func GetETATrialList(condition, sortStr string, pars []interface{}, startSize, pageSize int) (items []*ETATrialListRespItem, err error) { sql := `SELECT * FROM eta_trial WHERE 1=1 ` if sortStr == "" { sortStr = "ORDER BY create_time DESC " } if condition != "" { sql += condition } sql += sortStr + ` LIMIT ?,? ` o := orm.NewOrm() _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items) return } func GetETATrialListCount(condition string, pars []interface{}) (count int, err error) { sql := `SELECT COUNT(1) AS count FROM eta_trial WHERE 1 = 1 ` o := orm.NewOrm() if condition != "" { sql += condition } err = o.Raw(sql, pars).QueryRow(&count) return } type ETATrialListRespItem struct { EtaTrialId int `orm:"column(eta_trial_id);pk" description:"eta试用客户id"` UserName string `description:"客户名称"` CompanyName string `description:"客户公司姓名"` Position string `description:"职位"` Mobile string `description:"手机号"` ActiveTime string `description:"累计活跃时长"` LastLoginTime string `description:"最后一次登陆时间"` SellerId int `description:"销售id"` Seller string `description:"销售员名称"` InterestModule string `description:"感兴趣模块"` Expiration int `description:"账号到期时长"` Enabled int `description:"1:有效,0:禁用"` IndexNum int `description:"累计添加指标"` ChartNum int `description:"累计添加图表"` LoginNum int `description:"累计登录次数"` Password string Account string CreateTime string ModifyTime string LastLoginDuration string `description:"最后一次登录时长"` } type ETATrialListRespList struct { List []*ETATrialListRespItem Paging *paging.PagingItem ApprovalNum int } type ETATrialAddItem struct { UserName string `description:"客户名称"` CompanyName string `description:"客户公司姓名"` Position string `description:"职位"` Mobile string `description:"手机号"` } type ETATrialAddReq struct { List []ETATrialAddItem } func GetETATrialByMobile(mobile string) (item *EtaTrial, err error) { sql := `SELECT * FROM eta_trial WHERE mobile = ? ` o := orm.NewOrm() err = o.Raw(sql, mobile).QueryRow(&item) return } // 新增客户 func AddETATrial(item *EtaTrial) (lastId int64, err error) { o := orm.NewOrm() lastId, err = o.Insert(item) return } func GetETATrialByAccount(account string) (items []*EtaTrial, err error) { sql := `SELECT * FROM eta_trial WHERE account LIKE '%` + account + `%' ` o := orm.NewOrm() _, err = o.Raw(sql).QueryRows(&items) return } func UpdateETATrialEnable(mobile string) (err error) { o := orm.NewOrm() sql := `UPDATE eta_trial SET enabled=1,modify_time=NOW() WHERE mobile=? ` _, err = o.Raw(sql, mobile).Exec() return } // TransferETATrial 转移试用用户跟进销售人员 func TransferETATrial(item *TrialAccountTransferReq) (err error) { o := orm.NewOrm() sql := `UPDATE eta_trial SET seller=?,seller_id=?,modify_time=NOW() WHERE 1 = 1 ` var condition string var params []interface{} if item.IsCheckAll { if len(item.EtaTrialIdList) > 0 { condition = ` AND eta_trial_id not IN (` + utils.GetOrmInReplace(len(item.EtaTrialIdList)) + `)` for _, id := range item.EtaTrialIdList { params = append(params, id) } } } else { condition = ` AND eta_trial_id IN (` + utils.GetOrmInReplace(len(item.EtaTrialIdList)) + `)` for _, id := range item.EtaTrialIdList { params = append(params, id) } } sql += condition params = append([]interface{}{item.CurrentSellerName, item.CurrentSellerId}, params...) _, err = o.Raw(sql, params...).Exec() return } func GetETATrialByCondition(condition string, pars []interface{}) (item []*EtaTrial, err error) { o := orm.NewOrm() sql := `SELECT * FROM eta_trial WHERE 1=1 ` sql += condition _, err = o.Raw(sql, pars...).QueryRows(&item) if err != nil { return nil, err } return item, nil }