123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308 |
- package services
- import (
- "fmt"
- "hongze/hz_crm_api/models/company"
- "hongze/hz_crm_api/models/company_todo"
- "hongze/hz_crm_api/models/system"
- "hongze/hz_crm_api/utils"
- "time"
- )
- // AddCompanyTodo 添加任务待办
- func AddCompanyTodo(companyId, productId int, content string, endTime time.Time, createUserInfo *system.Admin) (errMsg string, err error) {
- defer func() {
- if err != nil {
- if errMsg == `` {
- errMsg = "添加任务失败"
- }
- }
- }()
- // 获取客户信息
- companyProductInfo, err := company.GetCompanyProductByCompanyIdAndProductId(companyId, productId)
- if err != nil {
- errMsg = `获取客户信息异常`
- return
- }
- sellerId := companyProductInfo.SellerId
- sellerName := companyProductInfo.SellerName
- //是否在允许创建任务的角色里面
- if createUserInfo.RoleTypeCode != utils.ROLE_TYPE_CODE_ADMIN &&
- createUserInfo.RoleTypeCode != utils.ROLE_TYPE_CODE_FICC_ADMIN &&
- createUserInfo.RoleTypeCode != utils.ROLE_TYPE_CODE_FICC_GROUP &&
- createUserInfo.RoleTypeCode != utils.ROLE_TYPE_CODE_FICC_TEAM &&
- createUserInfo.RoleTypeCode != utils.ROLE_TYPE_CODE_FICC_SELLER &&
- createUserInfo.RoleTypeCode != utils.ROLE_TYPE_CODE_RAI_ADMIN &&
- createUserInfo.RoleTypeCode != utils.ROLE_TYPE_CODE_RAI_GROUP &&
- createUserInfo.RoleTypeCode != utils.ROLE_TYPE_CODE_RAI_SELLER {
- errMsg = `操作人角色异常,不允许新增任务:` + createUserInfo.RoleName
- err = fmt.Errorf(errMsg)
- return
- }
- //超管和部门管理员所有客户都能操作,那就不判断了
- //如果是普通销售,那么只能操作自己的客户
- if createUserInfo.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER || createUserInfo.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER {
- if sellerId != createUserInfo.AdminId {
- errMsg = `该客户不是当前账号所属,不允许新增任务`
- err = fmt.Errorf(errMsg)
- return
- }
- }
- //获取客户所属销售信息
- sellerInfo, err := system.GetSysUserById(companyProductInfo.SellerId)
- if err != nil {
- errMsg = `获取客户所属销售信息异常`
- return
- }
- // 销售主管、组长权限判断
- switch createUserInfo.RoleTypeCode {
- case utils.ROLE_TYPE_CODE_FICC_GROUP: //ficc主管
- isSame, tmpErr := CheckAdminIsSameBigGroup(createUserInfo, sellerInfo)
- if tmpErr != nil {
- errMsg = `获取客户所属销售信息异常`
- err = fmt.Errorf("判断主管与该客户所属销售是否属于同一大组失败,err:" + tmpErr.Error())
- return
- }
- if !isSame {
- errMsg = `该客户不是当前账号所属组员,不允许新增任务`
- err = fmt.Errorf(errMsg)
- return
- }
- case utils.ROLE_TYPE_CODE_FICC_TEAM, utils.ROLE_TYPE_CODE_RAI_GROUP: //ficc组长、权益组长
- if sellerInfo.GroupId != createUserInfo.GroupId {
- errMsg = `该客户不是当前账号所属组员,不允许新增任务`
- err = fmt.Errorf(errMsg)
- return
- }
- }
- // 获取正在处理中的任务数量
- total, err := company_todo.GetCountDoingCompanyTodo(companyId, productId)
- if err != nil {
- return
- }
- if total > 0 {
- errMsg = "当前存在待处理的任务,不允许添加新的任务待办"
- err = fmt.Errorf(errMsg)
- return
- }
- companyTodoInfo := &company_todo.CompanyTodo{
- //Id: 0,
- CompanyId: companyId,
- ProductId: productId,
- Content: content,
- SellerId: sellerId,
- SellerName: sellerName,
- CreatedCompanyStatus: companyProductInfo.Status,
- CreateUserId: createUserInfo.AdminId,
- CreateUserName: createUserInfo.RealName,
- //ApproveUserId: 0,
- //ApproveUserName: "",
- Status: "进行中",
- ModifyTime: time.Now(),
- CreateTime: time.Now(),
- EndTime: endTime,
- }
- _, err = company_todo.AddCompanyTodo(companyTodoInfo)
- return
- }
- // EditCompanyTodo 修改任务待办
- func EditCompanyTodo(id int, content string, endTime time.Time, createUserInfo *system.Admin) (errMsg string, err error) {
- defer func() {
- if err != nil {
- if errMsg == `` {
- errMsg = "编辑任务失败"
- }
- }
- }()
- // 获取正在处理中的任务数量
- companyTodoInfo, err := company_todo.GetCompanyTodoById(id)
- if err != nil {
- return
- }
- if companyTodoInfo.Status != "进行中" {
- errMsg = `任务状态异常:` + companyTodoInfo.Status + `,不允许编辑该任务待办`
- err = fmt.Errorf(errMsg)
- return
- }
- // 获取客户信息
- companyProductInfo, err := company.GetCompanyProductByCompanyIdAndProductId(companyTodoInfo.CompanyId, companyTodoInfo.ProductId)
- if err != nil {
- errMsg = "获取客户信息异常,err:" + err.Error()
- return
- }
- sellerId := companyProductInfo.SellerId
- sellerName := companyProductInfo.SellerName
- //是否在允许创建任务的角色里面
- if createUserInfo.RoleTypeCode != utils.ROLE_TYPE_CODE_ADMIN &&
- createUserInfo.RoleTypeCode != utils.ROLE_TYPE_CODE_FICC_ADMIN &&
- createUserInfo.RoleTypeCode != utils.ROLE_TYPE_CODE_FICC_GROUP &&
- createUserInfo.RoleTypeCode != utils.ROLE_TYPE_CODE_FICC_TEAM &&
- createUserInfo.RoleTypeCode != utils.ROLE_TYPE_CODE_FICC_SELLER &&
- createUserInfo.RoleTypeCode != utils.ROLE_TYPE_CODE_RAI_ADMIN &&
- createUserInfo.RoleTypeCode != utils.ROLE_TYPE_CODE_RAI_GROUP &&
- createUserInfo.RoleTypeCode != utils.ROLE_TYPE_CODE_RAI_SELLER {
- errMsg = `操作人角色异常,不允许新增任务:` + createUserInfo.RoleName
- err = fmt.Errorf(errMsg)
- return
- }
- //超管和部门管理员所有客户都能操作,那就不判断了
- //如果是普通销售,那么只能操作自己的客户
- if createUserInfo.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER || createUserInfo.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER {
- if sellerId != createUserInfo.AdminId {
- errMsg = `该客户不是当前账号所属,不允许编辑任务`
- err = fmt.Errorf(errMsg)
- return
- }
- }
- //获取客户所属销售信息
- sellerInfo, err := system.GetSysUserById(companyProductInfo.SellerId)
- if err != nil {
- errMsg = `获取客户所属销售信息异常`
- return
- }
- // 销售主管、组长权限判断
- switch createUserInfo.RoleTypeCode {
- case utils.ROLE_TYPE_CODE_FICC_GROUP: //ficc主管
- isSame, tmpErr := CheckAdminIsSameBigGroup(createUserInfo, sellerInfo)
- if tmpErr != nil {
- errMsg = `获取客户所属销售信息异常`
- err = fmt.Errorf("判断主管与该客户所属销售是否属于同一大组失败,err:" + tmpErr.Error())
- return
- }
- if !isSame {
- errMsg = `该客户不是当前账号所属组员,不允许新增任务`
- err = fmt.Errorf(errMsg)
- return
- }
- case utils.ROLE_TYPE_CODE_FICC_TEAM, utils.ROLE_TYPE_CODE_RAI_GROUP: //ficc组长、权益组长
- if sellerInfo.GroupId != createUserInfo.GroupId {
- errMsg = `该客户不是当前账号所属组员,不允许新增任务`
- err = fmt.Errorf(errMsg)
- return
- }
- }
- companyTodoInfo.Content = content
- companyTodoInfo.SellerId = sellerId
- companyTodoInfo.SellerName = sellerName
- companyTodoInfo.CreatedCompanyStatus = companyProductInfo.Status
- companyTodoInfo.ModifyTime = time.Now()
- companyTodoInfo.EndTime = endTime
- err = companyTodoInfo.EditCompanyTodo([]string{"Content", "SellerId", "SellerName", "CreatedCompanyStatus", "ModifyTime", "EndTime"})
- return
- }
- // ApproveCompanyTodo 审批任务待办
- func ApproveCompanyTodo(id int, remark string, approveUserInfo *system.Admin) (errMsg string, err error) {
- defer func() {
- if err != nil {
- if errMsg == `` {
- errMsg = "编辑任务失败"
- }
- }
- }()
- // 获取正在处理中的任务数量
- companyTodoInfo, err := company_todo.GetCompanyTodoById(id)
- if err != nil {
- return
- }
- if companyTodoInfo.Status != "进行中" {
- errMsg = `任务状态异常:` + companyTodoInfo.Status + `,不允许编辑该任务待办`
- err = fmt.Errorf(errMsg)
- return
- }
- // 获取客户信息
- companyProductInfo, err := company.GetCompanyProductByCompanyIdAndProductId(companyTodoInfo.CompanyId, companyTodoInfo.ProductId)
- if err != nil {
- errMsg = "获取客户信息异常,err:" + err.Error()
- return
- }
- //sellerId := companyProductInfo.SellerId
- //sellerName := companyProductInfo.SellerName
- //获取客户所属销售信息
- sellerInfo, err := system.GetSysUserById(companyProductInfo.SellerId)
- if err != nil {
- errMsg = `获取客户所属销售信息异常`
- return
- }
- // 销售主管、组长权限判断
- switch approveUserInfo.RoleTypeCode {
- case utils.ROLE_TYPE_CODE_FICC_ADMIN, utils.ROLE_TYPE_CODE_RAI_ADMIN:
- // ficc管理员可以全部审批通过
- case utils.ROLE_TYPE_CODE_FICC_GROUP, utils.ROLE_TYPE_CODE_RAI_GROUP: //ficc主管、权益组长
- isSame, tmpErr := CheckAdminIsSameBigGroup(approveUserInfo, sellerInfo)
- if tmpErr != nil {
- errMsg = `获取客户所属销售信息异常`
- err = fmt.Errorf("判断主管与该客户所属销售是否属于同一大组失败,err:" + tmpErr.Error())
- return
- }
- if !isSame {
- errMsg = `该客户不是当前账号所属组员,不允许审批任务`
- err = fmt.Errorf(errMsg)
- return
- }
- case utils.ROLE_TYPE_CODE_FICC_TEAM: //ficc组长
- if sellerInfo.GroupId != approveUserInfo.GroupId {
- errMsg = `该客户不是当前账号所属组员,不允许审批任务`
- err = fmt.Errorf(errMsg)
- return
- }
- case utils.ROLE_TYPE_CODE_RAI_SELLER: //权益销售
- if sellerInfo.AdminId != approveUserInfo.AdminId {
- //approveUserInfo.
- errMsg = `没有审批权限,不允许审批任务`
- err = fmt.Errorf(errMsg)
- return
- }
- has := CheckRaiApprovePermission(approveUserInfo.AdminId)
- if !has {
- errMsg = `当前账号没有审批权限,不允许审批任务`
- err = fmt.Errorf(errMsg)
- return
- }
- default:
- errMsg = `操作人角色异常,不允许审批任务:` + approveUserInfo.RoleName
- err = fmt.Errorf(errMsg)
- return
- }
- //companyTodoInfo.SellerId = sellerId
- //companyTodoInfo.SellerName = sellerName
- companyTodoInfo.Status = "已完成"
- companyTodoInfo.ApproveUserId = approveUserInfo.AdminId
- companyTodoInfo.ApproveUserName = approveUserInfo.RealName
- companyTodoInfo.ModifyTime = time.Now()
- companyTodoInfo.ApproveTime = time.Now()
- companyTodoInfo.Remark = remark
- companyTodoInfo.ApprovedCompanyStatus = companyProductInfo.Status
- companyTodoInfo.ApprovedSellerId = companyProductInfo.SellerId
- companyTodoInfo.ApprovedSellerName = companyProductInfo.SellerName
- err = companyTodoInfo.ApproveCompanyTodo([]string{"Status", "ApproveUserId", "ApproveUserName", "ModifyTime", "ApproveTime", "ApprovedCompanyStatus", "ApprovedSellerId", "ApprovedSellerName", "Remark"})
- return
- }
- // CheckRaiApprovePermission 检测权益销售的审批权限
- func CheckRaiApprovePermission(id int) (has bool) {
- adminIdArr := []int{238, 115, 392, 198, 286, 185, 285, 186, 378, 503, 489}
- has = utils.InArrayByInt(adminIdArr, id)
- return
- }
|