فهرست منبع

连接体验版数据库

xyxie 3 ماه پیش
والد
کامیت
db306b10cc

+ 470 - 0
controllers/eta_trial/user.go

@@ -0,0 +1,470 @@
+package eta_trial
+
+import (
+	"encoding/json"
+	"eta/eta_forum_hub/controllers"
+	"eta/eta_forum_hub/models"
+	"eta/eta_forum_hub/models/eta_trial"
+	eta_trial2 "eta/eta_forum_hub/services/eta_trial"
+	"eta/eta_forum_hub/utils"
+	"time"
+)
+
+type EtaTrialController struct {
+	controllers.BaseAuthController
+}
+
+// GetUserByMobile
+// @Description 手机号获取用户信息
+// @Success 200 {string} string "操作成功"
+// @Router /user/mobile_fetch [post]
+func (this *EtaTrialController) GetUserByMobile() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	var req eta_trial.GetUserReq
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+	if req.Mobile == "" {
+		br.Msg = "请输入手机号"
+		return
+	}
+
+	item, e := models.GetEtaTrialByMobile(req.Mobile)
+	if e != nil && e.Error() != utils.ErrNoRow() {
+		br.Msg = "操作失败"
+		br.ErrMsg = "获取试用客户信息失败, Err:" + e.Error()
+		return
+	}
+
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "操作成功"
+	br.Data = item
+}
+
+// Disable
+// @Description 禁用
+// @Success 200 {string} string "操作成功"
+// @Router /user/disable [post]
+func (this *EtaTrialController) Disable() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	var req eta_trial.GetUserReq
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+
+	if req.Mobile == "" {
+		br.Msg = "请输入手机号"
+		return
+	}
+
+	if e := models.DisableEtaTrailByMobile(req.Mobile); e != nil {
+		br.Msg = "操作失败"
+		br.ErrMsg = "禁用试用客户失败, Err:" + e.Error()
+		return
+	}
+
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "操作成功"
+	br.Data = true
+}
+
+// Edit
+// @Description 编辑
+// @Success 200 {string} string "操作成功"
+// @Router /user/edit [post]
+func (this *EtaTrialController) Edit() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	var req eta_trial.UserEditReq
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+
+	if e := models.UpdateEtaTrialPositionByMobile(req.RealName, req.Position, req.Mobile, req.Enabled); e != nil {
+		br.Msg = "操作失败"
+		br.ErrMsg = "更新试用客户失败, Err:" + e.Error()
+		return
+	}
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "操作成功"
+	br.Data = true
+}
+
+// Remove
+// @Description 删除用户
+// @Success 200 {string} string "操作成功"
+// @Router /user/remove [post]
+func (this *EtaTrialController) Remove() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	var req eta_trial.GetUserReq
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+
+	if req.Mobile == "" {
+		br.Msg = "请输入手机号"
+		return
+	}
+
+	if e := models.DeleteEtaTrialByMobile(req.Mobile); e != nil {
+		br.Msg = "操作失败"
+		br.ErrMsg = "删除试用客户失败, Err:" + e.Error()
+		return
+	}
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "操作成功"
+	br.Data = true
+}
+
+// UpdateLogin
+// @Description 更新登录时间和次数
+// @Success 200 {string} string "操作成功"
+// @Router /user/update_login [post]
+func (this *EtaTrialController) UpdateLogin() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	var req eta_trial.UpdateUserLoginReq
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+
+	if req.Mobile == "" {
+		br.Msg = "请输入手机号"
+		return
+	}
+
+	if e := models.UpdateEtaTrialLoginByMobile(req.Mobile); e != nil {
+		br.Msg = "操作失败"
+		br.ErrMsg = "更新试用客户登录时间和次数失败, Err:" + e.Error()
+		return
+	}
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "操作成功"
+	br.Data = true
+}
+
+// UpdateIndexNum
+// @Description 更新累计新增指标数
+// @Success 200 {string} string "操作成功"
+// @Router /user/update_index_num [post]
+func (this *EtaTrialController) UpdateIndexNum() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	var req eta_trial.UpdateUserIndexNumReq
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+
+	if req.Mobile == "" {
+		br.Msg = "请输入手机号"
+		return
+	}
+
+	if e := models.UpdateEtaTrialIndexNumByMobile(req.Mobile); e != nil {
+		br.Msg = "操作失败"
+		br.ErrMsg = "更新试用客户累计新增指标数失败, Err:" + e.Error()
+		return
+	}
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "操作成功"
+	br.Data = true
+}
+
+// UpdateChartNum
+// @Description 更新累计新增图表数
+// @Success 200 {string} string "操作成功"
+// @Router /user/update_chart_num [post]
+func (this *EtaTrialController) UpdateChartNum() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	var req eta_trial.UpdateUserIndexNumReq
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+
+	if req.Mobile == "" {
+		br.Msg = "请输入手机号"
+		return
+	}
+
+	if e := models.UpdateEtaTrialChartNumByMobile(req.Mobile); e != nil {
+		br.Msg = "操作失败"
+		br.ErrMsg = "更新试用客户累计新增图表数失败, Err:" + e.Error()
+		return
+	}
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "操作成功"
+	br.Data = true
+}
+
+// UpdateActiveTime
+// @Description 更新活跃时间
+// @Success 200 {string} string "操作成功"
+// @Router /user/update_active_time [post]
+func (this *EtaTrialController) UpdateActiveTime() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	var req eta_trial.UpdateUserActiveTimeReq
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+
+	record := new(models.EtaTrialActiveRecord)
+	record.UserName = req.UserName
+	record.Mobile = req.Mobile
+	record.ActiveTime = req.ActiveTime
+	record.Part = req.Part
+	record.CreateTime = time.Now().Local()
+	if e := record.Create(); e != nil {
+		br.Msg = "操作失败"
+		br.ErrMsg = "新增试用客户活跃记录失败, Err:" + e.Error()
+		return
+	}
+	if e := models.UpdateEtaTrailActiveTime(req.ActiveTime, req.Mobile); e != nil {
+		br.Msg = "操作失败"
+		br.ErrMsg = "更新试用客户累计活跃时长失败, Err:" + e.Error()
+		return
+	}
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "操作成功"
+	br.Data = true
+}
+
+// UpdateLoginDuration
+// @Description 更新登录时长
+// @Success 200 {string} string "操作成功"
+// @Router /user/update_login_duration [post]
+func (this *EtaTrialController) UpdateLoginDuration() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	var req eta_trial.UpdateUserLoginDurationReq
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+
+	record := new(models.EtaTrialLoginDurationRecord)
+	record.UserName = req.UserName
+	record.Mobile = req.Mobile
+	record.Duration = req.ActiveTime
+	record.CreateTime = time.Now().Local()
+	if e := record.Create(); e != nil {
+		br.Msg = "操作失败"
+		br.ErrMsg = "新增试用客户登录时长记录失败, Err:" + e.Error()
+		return
+	}
+	if e := models.UpdateEtaTrailLastLoginDuration(req.ActiveTime, req.Mobile); e != nil {
+		br.Msg = "操作失败"
+		br.ErrMsg = "更新试用客户登录时长失败, Err:" + e.Error()
+		return
+	}
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "操作成功"
+	br.Data = true
+}
+
+// AddEtaTrialAdmin
+// @Title 新增或者编辑系统用户
+// @Description 新增系统用户接口
+// @Param	request	body system.SysuserAddReq true "type json string"
+// @Success 200 新增成功
+// @router /admin/add [post]
+func (this *EtaTrialController) AddEtaTrialAdmin() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	var req eta_trial.AddEtaTrialAdminReq
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+	//新增至试用平台的Admin
+
+	adminItem, err := eta_trial.GetSysUserByRoleAndDepartment("试用", "ETA试用客户")
+	if err != nil {
+		br.Msg = "获取用户信息失败"
+		br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
+		return
+	}
+
+	admin := new(eta_trial.ETATrialAdmin)
+	admin.AdminName = req.Account
+	admin.RealName = req.UserName
+	admin.Password = utils.MD5(req.Password)
+	admin.LastUpdatedPasswordTime = time.Now().Format(utils.FormatDateTime)
+	admin.Enabled = 1
+	admin.LastLoginTime = time.Now().Format(utils.FormatDateTime)
+	admin.CreatedTime = time.Now()
+	admin.LastUpdatedTime = time.Now().Format(utils.FormatDateTime)
+	admin.Mobile = req.Mobile
+	admin.RoleType = 0
+
+	admin.RoleId = adminItem.RoleId
+	admin.RoleName = "试用"
+	admin.RoleTypeCode = "管理员"
+	admin.DepartmentId = adminItem.DepartmentId
+	admin.DepartmentName = "ETA试用客户"
+	admin.Role = "admin"
+	admin.Position = req.Position
+
+	newId, err := eta_trial.AddAdmin(admin)
+	if err != nil {
+		br.Msg = "新增失败"
+		br.ErrMsg = "新增失败,AddAdmin Err:" + err.Error()
+		return
+	}
+
+	// 新增试用客户手工权限
+	go func() {
+		//_ = services.CreateTrialUserManualAuth(newId, admin.RealName)
+		_ = eta_trial2.EtaTrialManualUserAddAuth(newId, admin.RealName)
+	}()
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "新增成功"
+}
+
+// EnabledEtaTrialAdmin
+// @Title 新增或者编辑系统用户
+// @Description 新增系统用户接口
+// @Param	request	body system.SysuserAddReq true "type json string"
+// @Success 200 新增成功
+// @router /admin/enabled [post]
+func (this *EtaTrialController) EnabledEtaTrialAdmin() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	var req eta_trial.EnabledEtaTrialAdminReq
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+	//新增至试用平台的Admin
+	if req.Mobile == "" {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:手机号不能为空"
+		return
+	}
+	err = eta_trial.UpdateAdminEnable(req.Mobile)
+	if err != nil {
+		br.Msg = "启用失败"
+		br.ErrMsg = "启用失败,Err:" + err.Error()
+		return
+	}
+
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "操作成功"
+}
+
+// GetMobileCount
+// @Title 新增或者编辑系统用户
+// @Description 新增系统用户接口
+// @Param	request	body system.SysuserAddReq true "type json string"
+// @Success 200 新增成功
+// @router /mobile/count [post]
+func (this *EtaTrialController) GetMobileCount() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	var req eta_trial.GetMobileCountReq
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+	//新增至试用平台的Admin
+	if req.Mobile == "" {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:手机号不能为空"
+		return
+	}
+	mobileCount, err := eta_trial.GetSysAdminCountByMobile(req.Mobile, 0)
+	if err != nil {
+		br.Msg = "启用失败"
+		br.ErrMsg = "启用失败,Err:" + err.Error()
+		return
+	}
+	data := new(eta_trial.GetMobileCountResp)
+	data.Count = mobileCount
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "操作成功"
+	br.Data = data
+}

+ 22 - 0
models/db.go

@@ -16,12 +16,25 @@ func init() {
 	db, _ := orm.GetDB("default")
 	db.SetConnMaxLifetime(10 * time.Minute)
 
+	_ = orm.RegisterDataBase("weekly_trial", "mysql", utils.MYSQL_URL_WEEKLY_TRIAL)
+	orm.SetMaxIdleConns("weekly_trial", 50)
+	orm.SetMaxOpenConns("weekly_trial", 100)
+
+	_ = orm.RegisterDataBase("edb_trial", "mysql", utils.MYSQL_URL_EDB_TRIAL)
+	orm.SetMaxIdleConns("edb_trial", 50)
+	orm.SetMaxOpenConns("edb_trial", 100)
+
+	_ = orm.RegisterDataBase("hz_data_trial", "mysql", utils.MYSQL_URL_HZ_DATA_TRIAL)
+	orm.SetMaxIdleConns("hz_data_trial", 50)
+	orm.SetMaxOpenConns("hz_data_trial", 100)
+
 	orm.Debug = true
 	orm.DebugLog = orm.NewLog(utils.Binlog)
 
 	initChart()
 	initEdbData()
 	initSystem()
+	initEtaTrial()
 }
 
 // initChart 图表 数据表
@@ -53,3 +66,12 @@ func initSystem() {
 		new(system.SysGroup),
 	)
 }
+
+// initEtaTrial 试用相关
+func initEtaTrial() {
+	orm.RegisterModel(
+		new(EtaTrial),
+		new(EtaTrialActiveRecord),
+		new(EtaTrialLoginDurationRecord),
+	)
+}

+ 133 - 0
models/eta_trial.go

@@ -0,0 +1,133 @@
+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
+}

+ 28 - 0
models/eta_trial/edbdata_classify.go

@@ -0,0 +1,28 @@
+package eta_trial
+
+import (
+	"hongze/hz_crm_eta/global"
+	"time"
+)
+
+type EdbdataClassify struct {
+	ClassifyId   int    `orm:"column(classify_id);pk"`
+	ClassifyName string // 分类名称
+	ParentId     int    // 父级分类id
+	CreateTime   time.Time
+	Sort         int // 分类排序
+	IsShow       int // 1:展示,0:不展示
+}
+
+func (m *EdbdataClassify) TableName() string {
+	return "edbdata_classify"
+}
+
+func (m *EdbdataClassify) GetItemsByCondition(cond string, pars []interface{}, fieldArr []string, orderRule string) (items []*EdbdataClassify, err error) {
+	order := `create_time DESC`
+	if orderRule != "" {
+		order = orderRule
+	}
+	err = global.MYSQL["edb_trial"].Where(cond, pars...).Order(order).Find(&items).Error
+	return
+}

+ 31 - 0
models/eta_trial/manual_user.go

@@ -0,0 +1,31 @@
+package eta_trial
+
+import (
+	"hongze/hz_crm_eta/global"
+	"time"
+)
+
+// ManualUser 手工数据关联用户
+type ManualUser struct {
+	ManualUserId    int `orm:"column(manual_user_id);pk"`
+	AdminId         int
+	AdminRealName   string
+	SysUserId       int
+	SysUserRealName string
+	CreateTime      time.Time
+}
+
+func (m *ManualUser) TableName() string {
+	return "manual_user"
+}
+
+func (m *ManualUser) Create() (err error) {
+	err = global.MYSQL["hz_data_trial"].Create(m).Error
+	return
+}
+
+// CreateManualAuthReq 新增手工数据权限
+type CreateManualAuthReq struct {
+	AdminId   int    `json:"admin_id" description:"用户ID"`
+	AdminName string `json:"admin_name" description:"用户姓名"`
+}

+ 26 - 0
models/eta_trial/manual_user_classify.go

@@ -0,0 +1,26 @@
+package eta_trial
+
+import (
+	"time"
+)
+
+type ManualUserClassify struct {
+	ManualUserClassifyId int `orm:"column(manual_user_classify_id);pk"`
+	AdminId              int
+	ClassifyId           int
+	CreateTime           time.Time
+}
+
+func (m *ManualUserClassify) TableName() string {
+	return "manual_user_classify"
+}
+
+func (m *ManualUserClassify) Create() (err error) {
+	err = global.MYSQL["hz_data_trial"].Create(m).Error
+	return
+}
+
+func (m *ManualUserClassify) BatchCreate(items []*ManualUserClassify) (err error) {
+	err = global.MYSQL["hz_data_trial"].CreateInBatches(items, len(items)).Error
+	return
+}

+ 150 - 0
models/eta_trial/sys_user.go

@@ -0,0 +1,150 @@
+package eta_trial
+
+import (
+	"fmt"
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+type ETATrialAdmin struct {
+	AdminId                   int    `orm:"column(admin_id);pk" description:"系统用户id"`
+	AdminName                 string `description:"系统用户名称"`
+	AdminAvatar               string `description:"用户头像"`
+	RealName                  string `description:"系统用户姓名"`
+	Password                  string `json:"-"`
+	LastUpdatedPasswordTime   string `json:"-"`
+	Enabled                   int
+	Email                     string `description:"系统用户邮箱"`
+	LastLoginTime             string
+	CreatedTime               time.Time
+	LastUpdatedTime           string
+	Role                      string    `description:"系统用户角色"`
+	Mobile                    string    `description:"手机号"`
+	RoleType                  int       `description:"角色类型:1需要录入指标,0:不需要"`
+	RoleId                    int       `description:"角色ID"`
+	RoleName                  string    `description:"角色名称"`
+	RoleTypeCode              string    `description:"角色类型编码"`
+	DepartmentId              int       `description:"部门id"`
+	DepartmentName            string    `description:"部门名称"`
+	GroupId                   int       `description:"分组id"`
+	GroupName                 string    `description:"分组名称"`
+	Authority                 int       `description:"管理权限,0:无,1:部门负责人,2:小组负责人,或者ficc销售主管,3:超级管理员,4:ficc销售组长"`
+	Position                  string    `description:"职位"`
+	DisableTime               time.Time `description:"禁用时间"`
+	ChartPermission           int8      `description:"图表权限id"`
+	OpenId                    string    `description:"弘则部门公众号的openid"`
+	UnionId                   string    `description:"微信公众平台唯一标识"`
+	EdbPermission             int8      `description:"指标库操作权限,0:只能操作 自己的,1:所有指标可操作"`
+	MysteelChemicalPermission int8      `description:"钢联化工指标操作权限,0:只能操作 自己的,1:所有指标可操作"`
+}
+
+func (item *ETATrialAdmin) Update(cols []string) (err error) {
+	o := orm.NewOrm()
+	_, err = o.Update(item, cols...)
+	return
+}
+
+func AddAdmin(item *ETATrialAdmin) (lastId int, err error) {
+	o := orm.NewOrmUsingDB("weekly_trial")
+	sql := `INSERT INTO admin ( admin_name, real_name, password, last_updated_password_time, enabled, last_login_time, created_time, last_updated_time, mobile, role_id, role_name, role_type_code, department_id, department_name, role, position) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )`
+	_, err = o.Raw(sql, item.AdminName, item.RealName, item.Password, item.LastUpdatedPasswordTime, item.Enabled, item.LastLoginTime, item.CreatedTime, item.LastUpdatedTime, item.Mobile, item.RoleId, item.RoleName, item.RoleTypeCode, item.DepartmentId, item.DepartmentName, item.Role, item.Position).Exec()
+
+	sql = `SELECT MAX(admin_id) FROM admin`
+	err = o.Raw(sql).QueryRow(&lastId)
+	return
+}
+
+func GetSysUserByRoleAndDepartment(role, dep string) (item *ETATrialAdmin, err error) {
+	sql := `SELECT * FROM admin WHERE role_name=? AND department_name=? LIMIT 1`
+	o := orm.NewOrmUsingDB("weekly_trial")
+	err = o.Raw(sql, role, dep).QueryRow(&item)
+	return
+}
+
+// GetSysAdminCountByMobile 查询系统中是否存在该手机号(如果有传入用户id,那么排除该用户)
+func GetSysAdminCountByMobile(mobile string, adminId int) (count int, err error) {
+	sql := `SELECT COUNT(1) AS count FROM admin WHERE mobile=? `
+	if adminId > 0 {
+		sql += ` AND admin_id != ` + fmt.Sprint(adminId)
+	}
+	o := orm.NewOrmUsingDB("weekly_trial")
+	err = o.Raw(sql, mobile).QueryRow(&count)
+	return
+}
+
+func (item *ETATrialAdmin) TableName() string {
+	return "admin"
+}
+
+func UpdateAdminEnable(mobile string) (err error) {
+	sql := `UPDATE admin SET enabled=1 WHERE mobile=? `
+	o := orm.NewOrmUsingDB("weekly_trial")
+	_, err = o.Raw(sql, mobile).Exec()
+	return
+}
+
+type AddEtaTrialAdminReq struct {
+	UserName    string `description:"客户名称"`
+	Password    string
+	Account     string
+	CompanyName string `description:"客户公司姓名"`
+	Position    string `description:"职位"`
+	Mobile      string `description:"手机号"`
+	Enabled     int    `description:"1:有效,0:禁用"`
+	CreateTime  time.Time
+	ModifyTime  time.Time
+}
+
+type EnabledEtaTrialAdminReq struct {
+	Mobile string `description:"手机号"`
+}
+
+type GetMobileCountReq struct {
+	Mobile string `description:"手机号"`
+}
+type GetMobileCountResp struct {
+	Count int `description:"手机号数量"`
+}
+
+// GetUserReq 获取用户请求体
+type GetUserReq struct {
+	Mobile string `description:"手机号"`
+}
+
+// UserEditReq 更新用户信息请求体
+type UserEditReq struct {
+	RealName string `description:"姓名"`
+	Position string `description:"职务"`
+	Mobile   string `description:"手机号"`
+	Enabled  int    `description:"禁启用"`
+}
+
+// UpdateUserLoginReq 更新用户登录请求体
+type UpdateUserLoginReq struct {
+	Mobile string `description:"手机号"`
+}
+
+// UpdateUserIndexNumReq 更新用户累计新增指标数请求体
+type UpdateUserIndexNumReq struct {
+	Mobile string `description:"手机号"`
+}
+
+// UpdateUserChartNumReq 更新用户累计新增图表数请求体
+type UpdateUserChartNumReq struct {
+	Mobile string `description:"手机号"`
+}
+
+// UpdateUserActiveTimeReq 更新用户活跃时间请求体
+type UpdateUserActiveTimeReq struct {
+	Mobile     string `description:"手机号"`
+	UserName   string `description:"用户姓名"`
+	ActiveTime int    `description:"活跃时长, 单位秒"`
+	Part       string `description:"活跃板块"`
+}
+
+// UpdateUserLoginDurationReq 更新用户登录时长请求体
+type UpdateUserLoginDurationReq struct {
+	Mobile     string `description:"手机号"`
+	UserName   string `description:"用户姓名"`
+	ActiveTime int    `description:"活跃时长, 单位秒"`
+}

+ 34 - 0
models/eta_trial_active_record.go

@@ -0,0 +1,34 @@
+package models
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+// EtaTrialActiveRecord ETA试用用户活跃记录表
+type EtaTrialActiveRecord struct {
+	RecordId   int `orm:"column(record_id);pk"`
+	UserName   string
+	Mobile     string    // 手机号
+	ActiveTime int       // 累计活跃时长
+	CreateTime time.Time // 申请时间
+	Part       string    // 活跃板块
+}
+
+func (m *EtaTrialActiveRecord) TableName() string {
+	return "eta_trial_active_record"
+}
+
+// Create 新增
+func (m *EtaTrialActiveRecord) Create() (err error) {
+	o := orm.NewOrm()
+	_, err = o.Insert(m)
+	return
+}
+
+// Update 更新
+func (m *EtaTrialActiveRecord) Update(cols []string) (err error) {
+	o := orm.NewOrm()
+	_, err = o.Update(m, cols...)
+	return
+}

+ 33 - 0
models/eta_trial_login_duration_record.go

@@ -0,0 +1,33 @@
+package models
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+// EtaTrialLoginDurationRecord ETA试用客户登录时长记录表
+type EtaTrialLoginDurationRecord struct {
+	RecordId   int       `orm:"column(record_id);pk"`
+	UserName   string    // 用户名称
+	Mobile     string    // 手机号
+	Duration   int       // 登录时长,单位秒
+	CreateTime time.Time // 创建时间
+}
+
+func (m *EtaTrialLoginDurationRecord) TableName() string {
+	return "eta_trial_login_duration_record"
+}
+
+// Create 新增
+func (m *EtaTrialLoginDurationRecord) Create() (err error) {
+	o := orm.NewOrm()
+	_, err = o.Insert(m)
+	return
+}
+
+// Update 更新
+func (m *EtaTrialLoginDurationRecord) Update(cols []string) (err error) {
+	o := orm.NewOrm()
+	_, err = o.Update(m, cols...)
+	return
+}

+ 27 - 0
routers/commentsRouter.go

@@ -7,6 +7,33 @@ import (
 
 func init() {
 
+    beego.GlobalControllerRouter["eta/eta_forum_hub/controllers/eta_trial:EtaTrialController"] = append(beego.GlobalControllerRouter["eta/eta_forum_hub/controllers/eta_trial:EtaTrialController"],
+        beego.ControllerComments{
+            Method: "AddEtaTrialAdmin",
+            Router: `/admin/add`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["eta/eta_forum_hub/controllers/eta_trial:EtaTrialController"] = append(beego.GlobalControllerRouter["eta/eta_forum_hub/controllers/eta_trial:EtaTrialController"],
+        beego.ControllerComments{
+            Method: "EnabledEtaTrialAdmin",
+            Router: `/admin/enabled`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["eta/eta_forum_hub/controllers/eta_trial:EtaTrialController"] = append(beego.GlobalControllerRouter["eta/eta_forum_hub/controllers/eta_trial:EtaTrialController"],
+        beego.ControllerComments{
+            Method: "GetMobileCount",
+            Router: `/mobile/count`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["eta/eta_forum_hub/controllers/system:SysDepartmentController"] = append(beego.GlobalControllerRouter["eta/eta_forum_hub/controllers/system:SysDepartmentController"],
         beego.ControllerComments{
             Method: "Delete",

+ 6 - 0
routers/router.go

@@ -9,6 +9,7 @@ package routers
 
 import (
 	"eta/eta_forum_hub/controllers"
+	"eta/eta_forum_hub/controllers/eta_trial"
 	"eta/eta_forum_hub/controllers/system"
 	"github.com/beego/beego/v2/server/web"
 )
@@ -41,6 +42,11 @@ func init() {
 				&system.SysRoleController{},
 			),
 		),
+		web.NSNamespace("/eta_trial",
+			web.NSInclude(
+				&eta_trial.EtaTrialController{},
+			),
+		),
 	)
 	web.AddNamespace(ns)
 }

+ 54 - 0
services/eta_trial/user.go

@@ -0,0 +1,54 @@
+package eta_trial
+
+import (
+	"eta/eta_forum_hub/models/eta_trial"
+	"fmt"
+	"time"
+)
+
+func EtaTrialManualUserAddAuth(adminId int, adminName string) (err error) {
+	if adminId <= 0 {
+		err = fmt.Errorf("CreateManualAuth参数有误, AdminId: %d", adminId)
+		return
+	}
+
+	// 从ETA试用平台的edb库中读取手工数据分类
+	classifyIds := make([]int, 0)
+	{
+		classifyOb := new(eta_trial.EdbdataClassify)
+		cond := `is_show = 1`
+		pars := make([]interface{}, 0)
+		list, e := classifyOb.GetItemsByCondition(cond, pars, []string{}, "")
+		if e != nil {
+			err = fmt.Errorf("操作失败", "获取手工数据分类失败, Err: "+e.Error())
+			return
+		}
+		for _, v := range list {
+			classifyIds = append(classifyIds, v.ClassifyId)
+		}
+	}
+
+	// 新增用户及权限
+	manualUser := new(eta_trial.ManualUser)
+	manualUser.AdminId = adminId
+	manualUser.AdminRealName = adminName
+	manualUser.CreateTime = time.Now().Local()
+	if e := manualUser.Create(); e != nil {
+		err = fmt.Errorf("操作失败", "新增权限用户失败, Err: "+e.Error())
+		return
+	}
+	userClassifies := make([]*eta_trial.ManualUserClassify, 0)
+	for _, v := range classifyIds {
+		userClassifies = append(userClassifies, &eta_trial.ManualUserClassify{
+			AdminId:    adminId,
+			ClassifyId: v,
+			CreateTime: time.Now().Local(),
+		})
+	}
+	userClassifyOb := new(eta_trial.ManualUserClassify)
+	if e := userClassifyOb.BatchCreate(userClassifies); e != nil {
+		err = fmt.Errorf("操作失败", "批量新增权限用户分类失败, Err: "+e.Error())
+		return
+	}
+	return
+}

+ 6 - 0
utils/common.go

@@ -1302,3 +1302,9 @@ func (ms MapSorter) Less(i, j int) bool {
 func (ms MapSorter) Swap(i, j int) {
 	ms[i], ms[j] = ms[j], ms[i]
 }
+
+// md5加密
+func MD5(data string) string {
+	m := md5.Sum([]byte(data))
+	return hex.EncodeToString(m[:])
+}

+ 9 - 3
utils/config.go

@@ -9,9 +9,12 @@ import (
 )
 
 var (
-	RunMode     string //运行模式
-	APP_NAME_CN string
-	MYSQL_URL   string //数据库连接
+	RunMode                 string //运行模式
+	APP_NAME_CN             string
+	MYSQL_URL               string //数据库连接
+	MYSQL_URL_WEEKLY_TRIAL  string //eta试用数据库
+	MYSQL_URL_EDB_TRIAL     string
+	MYSQL_URL_HZ_DATA_TRIAL string //
 	/*MONGODB_URL        string //mongodb连接
 	MONGODB_COMMUNITY  string //mongodb库名
 	MONGODB_CREDENTIAL string*/
@@ -105,6 +108,9 @@ func init() {
 
 	MYSQL_URL = config["mysql_url"]
 
+	MYSQL_URL_WEEKLY_TRIAL = config["mysql_url_weekly_trial"]
+	MYSQL_URL_EDB_TRIAL = config["mysql_url_edb_trial"]
+	MYSQL_URL_HZ_DATA_TRIAL = config["mysql_url_hz_data_trial"]
 	// mongodb数据库连接配置
 	MgoUrlData = config["mgo_url_data"]