Procházet zdrojové kódy

Merge branch 'feature/eta2.3.4_business_user' into debug

xyxie před 1 dnem
rodič
revize
0bcbf740dd

+ 17 - 2
controllers/chart_collect_stat.go

@@ -214,6 +214,7 @@ func (this *ChartCollectStatController) UserDetailList() {
 	userId, _ := this.GetInt("UserId")
 	pageSize, _ := this.GetInt("PageSize")
 	currentIndex, _ := this.GetInt("CurrentIndex")
+	keyword := this.GetString("Keyword")
 
 	var startSize int
 	if pageSize <= 0 {
@@ -240,7 +241,7 @@ func (this *ChartCollectStatController) UserDetailList() {
 			br.Msg = "请选择正确的开始日期"
 			return
 		}
-		condition += ` AND collect_time >= ? `
+		condition += ` AND a.collect_time >= ? `
 		pars = append(pars, startDate)
 	}
 	if endDate != "" {
@@ -250,11 +251,25 @@ func (this *ChartCollectStatController) UserDetailList() {
 			br.Msg = "请选择正确的结束日期"
 			return
 		}
-		condition += ` AND collect_time < ? `
+		condition += ` AND a.collect_time < ? `
 		nextDate := endTime.AddDate(0, 0, 1).Format(utils.FormatDate)
 		pars = append(pars, nextDate)
 	}
 
+	if keyword != "" {
+		// 根据空格拆分
+		keys := strings.Split(keyword, " ")
+		condition += ` AND ( `
+		for _, v := range keys {
+			if v != "" {
+				condition += ` b.chart_name like ? and`
+				pars = append(pars, "%"+v+"%")
+			}
+		}
+		condition = condition[:len(condition)-3]
+		condition += ` )`
+	}
+
 	total, err := chart_collect.GetChartCollectCountByCondition(condition, pars)
 	if err != nil {
 		br.Msg = "获取失败"

+ 68 - 0
controllers/company_industry.go

@@ -0,0 +1,68 @@
+package controllers
+
+import (
+	"eta/eta_forum_admin/models"
+	"eta/eta_forum_admin/models/company"
+	"eta/eta_forum_admin/utils"
+)
+
+// 行业管理
+type CompanyIndustryController struct {
+	BaseAuthController
+}
+
+// @Title 根据客户类型获取行业列表
+// @Description 根据客户类型获取行业列表接口
+// @Param   Classify   query   string  true       "客户类型:ficc,合作伙伴,权益"
+// @Success 200 {object} models.CompanyIndustryResp
+// @router /industry/list [get]
+func (this *CompanyIndustryController) List() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	sysUser := this.SysUser
+	if sysUser == nil {
+		br.Msg = "请登录"
+		br.ErrMsg = "请登录,SysUser Is Empty"
+		br.Ret = 408
+		return
+	}
+	roleCodeType := sysUser.RoleTypeCode
+
+	classify := this.GetString("Classify")
+
+	if classify == "" {
+		if roleCodeType == utils.ROLE_TYPE_CODE_FICC_ADMIN || roleCodeType == utils.ROLE_TYPE_CODE_FICC_SELLER {
+			classify = utils.COMPANY_CLASSIFY_FICC
+		} else if roleCodeType == utils.ROLE_TYPE_CODE_RAI_SELLER || roleCodeType == utils.ROLE_TYPE_CODE_RAI_ADMIN {
+			classify = utils.COMPANY_CLASSIFY_RAI
+		}
+	}
+	list, err := company.GetCompanyIndustry(classify)
+	if err != nil {
+		br.Msg = "获取行业数据失败"
+		br.ErrMsg = "获取行业数据失败,Err:" + err.Error()
+		return
+	}
+	lenList := len(list)
+	for i := 0; i < lenList; i++ {
+		child, err := company.GetCompanyIndustryChildren(classify, list[i].IndustryId)
+		if err != nil {
+			br.Msg = "获取行业数据失败"
+			br.ErrMsg = "获取行业数据失败,Err:" + err.Error()
+			return
+		}
+		list[i].Children = child
+	}
+	if lenList <= 0 {
+		list = make([]*company.CompanyIndustryItem, 0)
+	}
+	resp := new(company.CompanyIndustryResp)
+	resp.List = list
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = resp
+}

+ 151 - 0
controllers/company_seller.go

@@ -0,0 +1,151 @@
+package controllers
+
+import (
+	"eta/eta_forum_admin/models"
+	"eta/eta_forum_admin/models/system"
+	"eta/eta_forum_admin/services"
+	"eta/eta_forum_admin/utils"
+	"fmt"
+)
+
+// 销售管理
+type CompanySellerController struct {
+	BaseAuthController
+}
+
+// RoadshowFiccList
+// @Title 路演FICC销售列表
+// @Description 路演FICC销售列表
+// @Success 200 {object} system.RoadshowGroupResp
+// @router /seller/roadshow_ficc/list [get]
+func (this *CompanySellerController) RoadshowFiccList() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		if br.ErrMsg == "" {
+			br.IsSendEmail = false
+		}
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	sysUser := this.SysUser
+	if sysUser == nil {
+		br.Msg = "请登录"
+		br.ErrMsg = "请登录,SysUser Is Empty"
+		br.Ret = 408
+		return
+	}
+
+	resp := new(system.RoadshowGroupResp)
+	productId := services.GetProductId(sysUser.RoleTypeCode)
+	if productId == utils.COMPANY_PRODUCT_RAI_ID {
+		br.Ret = 200
+		br.Success = true
+		br.Msg = "获取成功"
+		br.Data = resp
+		return
+	}
+
+	// 分组
+	departmentId := 2
+	groups, e := system.GetGroupByDepartmentId(departmentId)
+	if e != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取FICC分组失败, Err: " + e.Error()
+		return
+	}
+	teamGroupId := make(map[int]int, 0) // 小组ID对应的大组ID
+	var list []system.RoadshowGroups
+	for _, g := range groups {
+		if g.ParentId > 0 {
+			teamGroupId[g.GroupId] = g.ParentId
+			continue
+		}
+
+		// 大组
+		list = append(list, system.RoadshowGroups{
+			GroupId:   g.GroupId,
+			GroupName: g.GroupName,
+		})
+	}
+
+	// 销售
+	roleArr := []string{
+		utils.ROLE_TYPE_CODE_FICC_ADMIN, utils.ROLE_TYPE_CODE_FICC_DEPARTMENT, utils.ROLE_TYPE_CODE_FICC_GROUP,
+		utils.ROLE_TYPE_CODE_FICC_TEAM, utils.ROLE_TYPE_CODE_FICC_SELLER,
+	}
+	cond := fmt.Sprintf(` AND role_type_code IN (%s) AND enabled = 1`, utils.GetOrmInReplace(len(roleArr)))
+	pars := make([]interface{}, 0)
+	pars = append(pars, roleArr)
+	sellers, e := system.GetSysUserItemsOrderByCreated(cond, pars)
+	if e != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取FICC销售失败, Err: " + e.Error()
+		return
+	}
+
+	groupIdChild := make(map[int][]system.RoadshowGroupSellers) // 大组ID对应的销售
+	for _, s := range sellers {
+		var seller system.RoadshowGroupSellers
+		seller.AdminId = s.AdminId
+		seller.AdminName = s.RealName
+
+		gid := teamGroupId[s.GroupId]
+		if gid > 0 {
+			// 小组
+			seller.GroupId = gid
+			seller.TeamId = s.GroupId
+		} else {
+			// 大组
+			seller.GroupId = s.GroupId
+		}
+		groupIdChild[seller.GroupId] = append(groupIdChild[seller.GroupId], seller)
+	}
+
+	// 根据当前角色过滤可选项
+
+	for _, v := range list {
+		// 如果是销售、组长、主管, 那么过滤掉自己大组外的其他组
+		if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_TEAM || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER {
+			if sysUser.GroupId != v.GroupId && teamGroupId[sysUser.GroupId] != v.GroupId {
+				continue
+			}
+		}
+		child := groupIdChild[v.GroupId]
+
+		// 如果是小组长, 那么只能看到自己小组的信息
+		if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_TEAM {
+			var team []system.RoadshowGroupSellers
+			for _, c := range child {
+				if c.TeamId == sysUser.GroupId {
+					team = append(team, c)
+				}
+			}
+			v.Child = team
+			resp.List = append(resp.List, v)
+			continue
+		}
+
+		// 如果是普通销售, 那么只能看到分组中的自己
+		if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER {
+			var self []system.RoadshowGroupSellers
+			for _, c := range child {
+				if c.AdminId == sysUser.AdminId {
+					self = append(self, c)
+					break
+				}
+			}
+			v.Child = self
+			resp.List = append(resp.List, v)
+			continue
+		}
+
+		// 非以上两种情况, 可见该大组所有销售
+		v.Child = child
+		resp.List = append(resp.List, v)
+	}
+
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = resp
+}

+ 48 - 0
models/company/company_industry.go

@@ -0,0 +1,48 @@
+package company
+
+import "github.com/beego/beego/v2/client/orm"
+
+type CompanyIndustry struct {
+	IndustryId   int    `description:"行业id"`
+	IndustryName string `description:"行业名称"`
+	ParentId     int    `description:"父级id"`
+	Classify     string `description:"分类"`
+}
+
+type CompanyIndustryItem struct {
+	IndustryId   int                       `description:"行业id"`
+	IndustryName string                    `description:"行业名称"`
+	Classify     string                    `description:"分类"`
+	Children     []*CompanyIndustryItemSub `json:"children"`
+}
+
+type CompanyIndustryItemSub struct {
+	IndustryId   int    `description:"行业id"`
+	IndustryName string `description:"行业名称"`
+	Classify     string `description:"分类"`
+}
+
+type CompanyIndustryResp struct {
+	List []*CompanyIndustryItem
+}
+
+func GetCompanyIndustry(productName string) (items []*CompanyIndustryItem, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM company_industry WHERE product_name=? AND parent_id=0 ORDER BY industry_id ASC`
+	_, err = o.Raw(sql, productName).QueryRows(&items)
+	return
+}
+
+func GetCompanyIndustryChildren(classify string, parentId int) (items []*CompanyIndustryItemSub, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM company_industry WHERE product_name=? AND parent_id=? ORDER BY industry_id ASC`
+	_, err = o.Raw(sql, classify, parentId).QueryRows(&items)
+	return
+}
+
+func GetCompanyIndustryById(industryId int) (items *CompanyIndustry, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM company_industry WHERE industry_id=? `
+	err = o.Raw(sql, industryId).QueryRow(&items)
+	return
+}

+ 11 - 0
models/system/admin.go

@@ -212,3 +212,14 @@ type HzEtaBusiness struct {
 	BusinessName string `description:"商家名称"`
 	BusinessCode string
 }
+
+func GetSysUserItemsOrderByCreated(condition string, pars []interface{}) (items []*Admin, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM admin WHERE 1=1 `
+	if condition != "" {
+		sql += condition
+	}
+	sql += ` ORDER BY created_time DESC `
+	_, err = o.Raw(sql, pars).QueryRows(&items)
+	return
+}

+ 254 - 0
models/system/sys_group.go

@@ -0,0 +1,254 @@
+package system
+
+import (
+	"eta/eta_forum_admin/utils"
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+type SysGroupAddReq struct {
+	DepartmentId int    `description:"部门Id"`
+	GroupName    string `description:"分组名称,多个用英文逗号隔开"`
+}
+
+type SysGroup struct {
+	GroupId      int       `orm:"column(group_id);pk" description:"分组ID"`
+	DepartmentId int       `description:"部门Id"`
+	ParentId     int       `description:"父级Id"`
+	GroupName    string    `description:"分组名称"`
+	Sort         int       `description:"排序"`
+	CreateTime   time.Time `description:"创建时间"`
+}
+
+func GetSysGroupCount(departmentId int, groupName string) (count int, err error) {
+	sql := `SELECT COUNT(1) AS count FROM sys_group WHERE department_id=? AND group_name=? `
+	o := orm.NewOrm()
+	err = o.Raw(sql, departmentId, groupName).QueryRow(&count)
+	return
+}
+
+func AddSysGroup(item *SysGroup) (lastId int64, err error) {
+	o := orm.NewOrm()
+	lastId, err = o.Insert(item)
+	return
+}
+
+type SysGroupEditReq struct {
+	GroupId   int    `description:"分组ID"`
+	GroupName string `description:"分组名称"`
+}
+
+func GetSysGroupById(groupId int) (item *SysGroup, err error) {
+	sql := `SELECT * FROM sys_group WHERE group_id=? `
+	o := orm.NewOrm()
+	err = o.Raw(sql, groupId).QueryRow(&item)
+	return
+}
+
+func GetSysGroupByName(groupName string) (item *SysGroup, err error) {
+	sql := `SELECT * FROM sys_group WHERE group_name=? `
+	o := orm.NewOrm()
+	err = o.Raw(sql, groupName).QueryRow(&item)
+	return
+}
+
+func ModifySysGroup(groupName string, groupId int) (err error) {
+	o := orm.NewOrm()
+	to, err := o.Begin()
+	if err != nil {
+		return
+	}
+	defer func() {
+		if err != nil {
+			_ = to.Rollback()
+		} else {
+			_ = to.Commit()
+		}
+	}()
+	sql := `UPDATE sys_group SET group_name=? WHERE group_id=? `
+	_, err = to.Raw(sql, groupName, groupId).Exec()
+	sql = `UPDATE admin SET group_name=? WHERE group_id=? `
+	_, err = to.Raw(sql, groupName, groupId).Exec()
+	return
+}
+
+type SysGroupDeleteReq struct {
+	GroupId int `description:"分组ID"`
+}
+
+func DeleteSysGroup(groupId int) (err error) {
+	sql := `DELETE FROM sys_group WHERE group_id=? `
+	o := orm.NewOrm()
+	_, err = o.Raw(sql, groupId).Exec()
+	return
+}
+
+// 因前端显示需要,TopId字段用来当做一级部门id,DepartmentId为当前分组id
+type SysGroupList struct {
+	GroupId      int            `orm:"column(group_id);pk" json:"DepartmentId" description:"分组ID"`
+	ParentId     int            `json:"ParentId" description:"父级ID"`
+	DepartmentId int            `json:"TopId" description:"部门Id"`
+	GroupName    string         `json:"DepartmentName" description:"分组名称"`
+	Child        []*SysTeamList `description:"小组"`
+	CreateTime   time.Time      `description:"创建时间"`
+	IsGroup      bool           `description:"是否为二级部门"`
+}
+
+type SysTeamList struct {
+	GroupId    int       `orm:"column(group_id);pk" json:"DepartmentId" description:"小组ID"`
+	ParentId   int       `json:"GroupId" description:"小组Id"`
+	GroupName  string    `json:"DepartmentName" description:"分组名称"`
+	CreateTime time.Time `description:"创建时间"`
+}
+
+func GetSysGroupByDepartmentId(departmentId int) (items []*SysGroupList, err error) {
+	sql := `SELECT * FROM sys_group WHERE department_id=? AND parent_id=0 ORDER BY sort ASC, create_time ASC`
+	o := orm.NewOrm()
+	_, err = o.Raw(sql, departmentId).QueryRows(&items)
+	return
+}
+
+// GetSysGroupListByDepartmentId 获取该部门下的所有分组(包含大小分组,不包含 “无” 这个分组)
+func GetSysGroupListByDepartmentId(departmentId int) (items []*SysGroupList, err error) {
+	sql := `SELECT * FROM sys_group WHERE department_id=? AND group_name<>'无' ORDER BY sort ASC, create_time ASC`
+	o := orm.NewOrm()
+	_, err = o.Raw(sql, departmentId).QueryRows(&items)
+	return
+}
+
+func ClearSysUserGroup(groupId int) (err error) {
+	sql := `UPDATE admin SET group_id=0,group_name='' WHERE group_id=? `
+	o := orm.NewOrm()
+	_, err = o.Raw(sql, groupId).Exec()
+	return
+}
+
+func GetSysGroupByDirectorId(directorId int) (items []*SysGroupList, err error) {
+	sql := `SELECT * FROM sys_group WHERE group_id=? ORDER BY sort ASC, create_time ASC`
+	o := orm.NewOrm()
+	_, err = o.Raw(sql, directorId).QueryRows(&items)
+	return
+}
+
+func GetSysGroupByGroupIds(groupIds []int) (items []*SysGroupList, err error) {
+	lenArr := len(groupIds)
+	if lenArr == 0 {
+		return
+	}
+	sql := `SELECT * FROM sys_group WHERE group_id IN  (` + utils.GetOrmInReplace(lenArr) + `) ORDER BY sort ASC, create_time ASC`
+	o := orm.NewOrm()
+	_, err = o.Raw(sql, groupIds).QueryRows(&items)
+	return
+}
+
+// GetSysGroupByGroupId 销售主管用,查找销售主管所在大组的名称
+func GetSysGroupByGroupId(groupId int) (items []*SysGroupList, err error) {
+	sql := `SELECT * FROM sys_group WHERE department_id=2 AND parent_id=0 AND group_id=? ORDER BY sort ASC, create_time ASC`
+	o := orm.NewOrm()
+	_, err = o.Raw(sql, groupId).QueryRows(&items)
+	return
+}
+
+// GetChildSysGroupByGroupId 通过上级分组id获取下级的分组id
+func GetChildSysGroupByGroupId(groupId int) (items []*SysGroup, err error) {
+	sql := `SELECT * FROM sys_group WHERE parent_id=? ORDER BY sort ASC, create_time ASC`
+	o := orm.NewOrm()
+	_, err = o.Raw(sql, groupId).QueryRows(&items)
+	return
+}
+
+type SysFullGroup struct {
+	GroupId         int       `orm:"column(group_id);pk" description:"分组ID"`
+	DepartmentId    int       `description:"部门Id"`
+	ParentId        int       `description:"父级Id"`
+	GroupName       string    `description:"分组名称"`
+	ParentGroupName string    `description:"父级分组名称"`
+	DepartmentName  string    `description:"部门名称"`
+	CreateTime      time.Time `description:"创建时间"`
+}
+
+// GetFullGroup 获取完整的分组信息
+func GetFullGroup() (list []*SysFullGroup, err error) {
+	sql := `SELECT s.*,g.group_name as parent_group_name , d.department_name
+from sys_group s 
+LEFT JOIN sys_group g on s.parent_id=g.group_id
+LEFT JOIN sys_department d on s.department_id=d.department_id ORDER BY s.sort ASC, s.create_time ASC`
+	o := orm.NewOrm()
+	_, err = o.Raw(sql).QueryRows(&list)
+	return
+}
+
+type SysGroupSortReq struct {
+	//ParentId      int   `description:"上级部门/分组ID"`
+	DepartmentIds []int `description:"移动后的一级ID排序"`
+	GroupIds      []int `description:"移动后的二级ID排序"`
+	TeamIds       []int `description:"移动后的三级ID排序"`
+}
+
+type GroupSort struct {
+	GroupId int
+	Sort    int
+}
+
+func MultiUpdateGroupSort(items []*GroupSort) (err error) {
+	if len(items) == 0 {
+		return
+	}
+	o := orm.NewOrm()
+	p, err := o.Raw("UPDATE sys_group SET sort = ? WHERE group_id = ?").Prepare()
+	if err != nil {
+		return
+	}
+	defer func() {
+		_ = p.Close()
+	}()
+	for _, v := range items {
+		_, err = p.Exec(v.Sort, v.GroupId)
+		if err != nil {
+			return
+		}
+	}
+	return
+}
+
+func GetGroupByDepartmentId(departmentId int) (list []*SysFullGroup, err error) {
+	sql := `SELECT
+				s.*, g.group_name AS parent_group_name,
+				d.department_name
+			FROM
+				sys_group s
+			LEFT JOIN sys_group g ON s.parent_id = g.group_id
+			LEFT JOIN sys_department d ON s.department_id = d.department_id
+			WHERE
+				s.department_id = ?
+			ORDER BY
+				s.sort ASC,
+				s.create_time ASC`
+	o := orm.NewOrm()
+	_, err = o.Raw(sql, departmentId).QueryRows(&list)
+	return
+}
+
+type RoadshowGroupResp struct {
+	List []RoadshowGroups
+}
+
+type RoadshowGroups struct {
+	GroupId   int                    `description:"分组ID"`
+	GroupName string                 `description:"分组名称"`
+	Child     []RoadshowGroupSellers `description:"销售"`
+}
+
+type RoadshowGroupSellers struct {
+	GroupId   int    `description:"大组ID"`
+	TeamId    int    `description:"小组ID"`
+	AdminId   int    `description:"销售ID"`
+	AdminName string `description:"销售名称"`
+}
+
+func GetAllSysGroupByGroupId(groupId int) (items []*SysGroup, err error) {
+	sql := `SELECT * FROM sys_group WHERE parent_id=? OR parent_id = ? ORDER BY sort ASC, create_time ASC`
+	o := orm.NewOrm()
+	_, err = o.Raw(sql, groupId, groupId).QueryRows(&items)
+	return
+}

+ 18 - 0
routers/commentsRouter.go

@@ -691,6 +691,24 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["eta/eta_forum_admin/controllers:CompanyIndustryController"] = append(beego.GlobalControllerRouter["eta/eta_forum_admin/controllers:CompanyIndustryController"],
+        beego.ControllerComments{
+            Method: "List",
+            Router: `/industry/list`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["eta/eta_forum_admin/controllers:CompanySellerController"] = append(beego.GlobalControllerRouter["eta/eta_forum_admin/controllers:CompanySellerController"],
+        beego.ControllerComments{
+            Method: "RoadshowFiccList",
+            Router: `/seller/roadshow_ficc/list`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["eta/eta_forum_admin/controllers:CrmConfigController"] = append(beego.GlobalControllerRouter["eta/eta_forum_admin/controllers:CrmConfigController"],
         beego.ControllerComments{
             Method: "Fetch",

+ 6 - 0
routers/router.go

@@ -90,6 +90,12 @@ func init() {
 				&eta_training_video.EtaTrainingVideoTagController{},
 			),
 		),
+		web.NSNamespace("/custom",
+			web.NSInclude(
+				&controllers.CompanyIndustryController{},
+				&controllers.CompanySellerController{},
+			),
+		),
 	)
 	web.AddNamespace(ns)
 }

+ 7 - 0
utils/constants.go

@@ -365,3 +365,10 @@ const (
 	STORAGESOURCE_MINIO_NAME = "minio"
 	STORAGESOURCE_S3_NAME    = "s3"
 )
+
+// 客户类型
+const (
+	COMPANY_CLASSIFY_FICC    = "ficc"
+	COMPANY_CLASSIFY_RAI     = "权益"
+	COMPANY_CLASSIFY_PARTNER = "合作伙伴"
+)