1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596 |
- package services
- import (
- "encoding/json"
- "errors"
- "fmt"
- "github.com/beego/beego/v2/client/orm"
- "hongze/hz_crm_api/models"
- "hongze/hz_crm_api/models/company"
- "hongze/hz_crm_api/models/company_user"
- "hongze/hz_crm_api/models/cygx"
- "hongze/hz_crm_api/models/system"
- "hongze/hz_crm_api/services/alarm_msg"
- "hongze/hz_crm_api/utils"
- "strconv"
- "strings"
- "time"
- )
- // AddCompanyPermission 新增客户权限
- func AddCompanyPermission(companyId, sysUserId, productId int, productName, sysUserName, permissionStr, startDate, endDate string) (companyReportPermissionList []*company.CompanyReportPermission, err error) {
- if permissionStr == "" {
- return
- }
- permissionArr := strings.Split(permissionStr, ",")
- count, _ := company.GetCompanyReportPermissionCount(companyId, productId)
- //删除权限
- if count > 0 {
- err = company.DeleteCompanyReportPermission(companyId, productId)
- if err != nil {
- return
- }
- }
- //如果是ficc类型的客户,且权限列表中没有 宏观权限,那么需要默认将宏观加进去
- if productId == utils.COMPANY_PRODUCT_FICC_ID && !utils.InArrayByStr(permissionArr, "1") {
- permissionArr = append(permissionArr, "1")
- }
- for _, pv := range permissionArr {
- permissionId, tmpErr := strconv.Atoi(pv)
- if productId == utils.COMPANY_PRODUCT_RAI_ID && permissionId == 1 {
- continue
- }
- if tmpErr != nil {
- err = tmpErr
- return
- }
- permission := new(company.CompanyReportPermission)
- permission.CompanyId = companyId
- permission.ReportPermissionId = permissionId
- permission.CreatedTime = time.Now()
- permission.LastUpdatedTime = time.Now()
- permission.ChartPermissionId = permissionId
- permission.StartDate = startDate
- permission.EndDate = endDate
- permission.ProductId = productId
- permission.ProductName = productName
- permission.ModifyTime = time.Now()
- permission.Status = "试用"
- err = company.AddCompanyReportPermission(permission)
- if err != nil {
- return
- }
- companyReportPermissionList = append(companyReportPermissionList, permission)
- cpLog := new(company.CompanyPermissionLog)
- cpLog.CompanyId = companyId
- cpLog.ChartPermissionId = permissionId
- cpLog.CreateTime = time.Now()
- cpLog.SysUserId = sysUserId
- cpLog.SysUserName = sysUserName
- cpLog.StartDate = startDate
- cpLog.EndDate = endDate
- cpLog.ProductId = productId
- cpLog.ProductName = productName
- go company.AddCompanyPermissionLog(cpLog)
- }
- return
- }
- func AddCompanyProductLog(companyProduct *company.CompanyProduct, adminId int, logType string) (err error) {
- defer func() {
- if err != nil {
- go alarm_msg.SendAlarmMsg("services:AddCompanyProductLog;Err:"+err.Error(), 3)
- //go utils.SendEmail(utils.APPNAME+"失败提醒"+utils.RunMode, "services:AddCompanyProductLog;Err:"+err.Error(), utils.EmailSendToUsers)
- }
- }()
- productLog := new(company.CompanyProductLog)
- productLog.CompanyProductId = companyProduct.CompanyProductId
- productLog.CompanyId = companyProduct.CompanyId
- productLog.ProductId = companyProduct.ProductId
- productLog.ProductName = companyProduct.ProductName
- productLog.CompanyName = companyProduct.CompanyName
- productLog.CompanyName = companyProduct.CompanyName
- productLog.Source = companyProduct.Source
- productLog.Reasons = companyProduct.Reasons
- productLog.Status = companyProduct.Status
- productLog.IndustryId = companyProduct.IndustryId
- productLog.IndustryName = companyProduct.IndustryName
- productLog.SellerId = companyProduct.SellerId
- productLog.SellerName = companyProduct.SellerName
- productLog.GroupId = companyProduct.GroupId
- productLog.DepartmentId = companyProduct.DepartmentId
- productLog.IsSuspend = companyProduct.IsSuspend
- productLog.SuspendTime = companyProduct.SuspendTime
- productLog.ApproveStatus = companyProduct.ApproveStatus
- productLog.FreezeTime = companyProduct.FreezeTime
- productLog.Remark = companyProduct.Remark
- productLog.StartDate = companyProduct.StartDate
- productLog.EndDate = companyProduct.EndDate
- productLog.CreateTime = companyProduct.CreateTime
- productLog.ModifyTime = companyProduct.ModifyTime
- productLog.LoseReason = companyProduct.LoseReason
- productLog.LossTime = companyProduct.LossTime
- productLog.LogType = logType
- productLog.LogCreateTime = time.Now()
- productLog.AdminId = adminId
- err = company.AddCompanyProductLog(productLog)
- //修改公司更新时间
- sql := `UPDATE company SET last_updated_time=NOW() WHERE company_id=? `
- o := orm.NewOrm()
- o.Raw(sql, companyProduct.CompanyId).Exec()
- return
- }
- func AddCompanyOperationRecord(companyId, sellerId, sysUserId, productId, approveAdminId int, companyName, productName, sysUserRealName, remark, operation, approveContent, approveUserRealName, approveRemark, status string) (err error) {
- defer func() {
- if err != nil {
- go alarm_msg.SendAlarmMsg("services:AddCompanyOperationRecord;Err:"+err.Error(), 3)
- //go utils.SendEmail(utils.APPNAME+"失败提醒"+utils.RunMode, "services:AddCompanyOperationRecord;Err:"+err.Error(), utils.EmailSendToUsers)
- }
- }()
- record := new(company.CompanyOperationRecord)
- record.CompanyId = companyId
- record.CompanyName = companyName
- record.SellerId = sellerId
- record.SysUserId = sysUserId
- record.SysRealName = sysUserRealName
- record.Remark = remark
- record.Operation = operation
- record.CreateTime = time.Now()
- record.ProductId = productId
- record.ProductName = productName
- record.ApproveUserId = approveAdminId
- record.ApproveRealName = approveUserRealName
- record.ApproveContent = approveContent
- record.ApproveRemark = approveRemark
- record.Status = status
- _, err = company.AddCompanyOperationRecord(record)
- return
- }
- // AddCompanyOperationRecordMore 添加操作记录(包含补充信息)
- func AddCompanyOperationRecordMore(companyId, sellerId, sysUserId, productId, approveAdminId int, companyName, productName, sysUserRealName, remark, operation, approveContent, approveContentExtra, approveUserRealName, approveRemark, status string) (err error) {
- defer func() {
- if err != nil {
- go alarm_msg.SendAlarmMsg("services:AddCompanyOperationRecordMore;Err:"+err.Error(), 3)
- //go utils.SendEmail(utils.APPNAME+"失败提醒"+utils.RunMode, "services:AddCompanyOperationRecord;Err:"+err.Error(), utils.EmailSendToUsers)
- }
- }()
- record := new(company.CompanyOperationRecord)
- record.CompanyId = companyId
- record.CompanyName = companyName
- record.SellerId = sellerId
- record.SysUserId = sysUserId
- record.SysRealName = sysUserRealName
- record.Remark = remark
- record.Operation = operation
- record.CreateTime = time.Now()
- record.ProductId = productId
- record.ProductName = productName
- record.ApproveUserId = approveAdminId
- record.ApproveRealName = approveUserRealName
- record.ApproveContent = approveContent
- record.ApproveContentExtra = approveContentExtra
- record.ApproveRemark = approveRemark
- record.Status = status
- _, err = company.AddCompanyOperationRecord(record)
- return
- }
- func GetProductId(roleTypeCode string) (productId int) {
- if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER ||
- roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN ||
- roleTypeCode == utils.ROLE_TYPE_CODE_FICC_TEAM ||
- roleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP ||
- roleTypeCode == utils.ROLE_TYPE_CODE_FICC_DEPARTMENT {
- productId = 1
- } else if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER ||
- roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN ||
- roleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP ||
- roleTypeCode == utils.ROLE_TYPE_CODE_RAI_DEPARTMENT {
- productId = 2
- } else {
- productId = 0
- }
- return
- }
- // CheckAdminIsSeller 根据用户权限码获取是否属于销售
- func CheckAdminIsSeller(roleTypeCode string) (isSeller bool) {
- if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER ||
- roleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP ||
- roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER ||
- roleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
- isSeller = true
- }
- return
- }
- //func GetCompanyPermissionButton(roleTypeCode, status string, itemGroupId, sysUserGroupId, itemSellerId, sysUserId, authority, productId int) (button company.ButtonPermission) {
- // button.BtnView = true
- // if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN { //超级管理员
- // if !strings.Contains(status, "/") {
- // if status == utils.COMPANY_STATUS_FORMAL { //正式
- // //button.BtnModifySeller = true
- // return
- // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
- // button.BtnEdit = true
- // button.BtnDelete = true
- // //button.BtnModifySeller = true
- // return
- // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
- // //button.BtnModifySeller = true
- // return
- // } else if status == utils.COMPANY_STATUS_LOSE { //流失
- // //button.BtnModifySeller = true
- // button.BtnDelete = true
- // return
- // } else { //永续
- // //button.BtnModifySeller = true
- // button.BtnDelete = true
- // button.BtnEdit = true
- // return
- // }
- // }
- // } else if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN {
- // if productId != 1 {
- // return
- // } else {
- // if !strings.Contains(status, "/") {
- // if status == utils.COMPANY_STATUS_FORMAL { //正式
- // button.BtnModifySeller = true
- // return
- // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
- // button.BtnEdit = true
- // button.BtnDelete = true
- // button.BtnModifySeller = true
- // return
- // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
- // //button.BtnModifySeller = true
- // return
- // } else if status == utils.COMPANY_STATUS_LOSE { //流失
- // //button.BtnModifySeller = true
- // button.BtnDelete = true
- // return
- // } else { //永续
- // return
- // }
- // }
- // }
- // } else if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
- // if !strings.Contains(status, "/") {
- // if status == utils.COMPANY_STATUS_FORMAL { //正式
- // button.BtnModifySeller = true
- // return
- // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
- // button.BtnEdit = true
- // button.BtnDelete = true
- // return
- // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
- // return
- // } else if status == utils.COMPANY_STATUS_LOSE { //流失
- // button.BtnDelete = true
- // return
- // } else { //永续
- // return
- // }
- // }
- // } else if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER {
- // if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER && productId == 2 {
- // return
- // }
- // if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER && productId == 1 {
- // return
- // }
- // //管理权限,0:无,1:部门负责人,2:小组负责人,3:超级管理员
- // if authority == 2 { //组长
- // if !strings.Contains(status, "/") {
- // if sysUserId == itemSellerId { //自己客户
- // if status == utils.COMPANY_STATUS_FORMAL { //正式
- // button.BtnUpdate = true
- // button.BtnModifySeller = true
- // return
- // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
- // button.BtnEdit = true
- // button.BtnDelete = true
- // button.BtnSuspend = true
- // button.BtnDelay = true
- // button.BtnTurnPositive = true
- // button.BtnModifySeller = true
- // return
- // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
- // button.BtnThaw = true
- // return
- // } else if status == utils.COMPANY_STATUS_LOSE { //流失
- // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
- // button.BtnApplyReceive = true
- // } else {
- // button.BtnReceive = true
- // }
- // if itemSellerId == sysUserId || (itemGroupId == sysUserGroupId && authority > 0) {
- // button.BtnDelete = true
- // }
- // return
- // } else { //永续
- // button.BtnDelete = true
- // return
- // }
- // } else {
- // if productId == 1 {
- // if status == utils.COMPANY_STATUS_FORMAL { //正式
- // button.BtnModifySeller=true
- // return
- // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
- // button.BtnModifySeller=true
- // return
- // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
- // button.BtnThaw = true
- // return
- // } else if status == utils.COMPANY_STATUS_LOSE { //流失
- // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
- // button.BtnApplyReceive = true
- // } else {
- // button.BtnReceive = true
- // }
- // return
- // } else { //永续
- // button.BtnDelete = true
- // return
- // }
- // } else {
- // button.BtnReceive = true
- // }
- // }
- // }
- // } else { //销售
- // if !strings.Contains(status, "/") {
- // if itemSellerId == sysUserId {
- // if status == utils.COMPANY_STATUS_FORMAL { //正式
- // button.BtnUpdate = true
- // return
- // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
- // button.BtnEdit = true
- // button.BtnDelete = true
- // button.BtnSuspend = true
- // button.BtnDelay = true
- // button.BtnTurnPositive = true
- // return
- // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
- // button.BtnThaw = true
- // return
- // } else if status == utils.COMPANY_STATUS_LOSE { //流失
- // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
- // button.BtnApplyReceive = true
- // } else {
- // button.BtnReceive = true
- // }
- // if itemSellerId == sysUserId || (itemGroupId == sysUserGroupId && authority > 0) {
- // button.BtnDelete = true
- // }
- // return
- // } else { //永续
- // button.BtnDelete = true
- // return
- // }
- // } else {
- // if productId == 1 {
- // if status == utils.COMPANY_STATUS_FORMAL { //正式
- // return
- // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
- // return
- // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
- // button.BtnThaw = true
- // return
- // } else if status == utils.COMPANY_STATUS_LOSE { //流失
- // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
- // button.BtnApplyReceive = true
- // } else {
- // button.BtnReceive = true
- // }
- // return
- // } else { //永续
- // button.BtnDelete = true
- // return
- // }
- // } else {
- // button.BtnReceive = true
- // }
- // }
- // }
- // }
- // } else if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER {
- // if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER && productId == 2 {
- // return
- // }
- // if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER && productId == 1 {
- // return
- // }
- // if !strings.Contains(status, "/") {
- // if authority == 2 { //组长
- // if itemSellerId==sysUserId {
- // if status == utils.COMPANY_STATUS_FORMAL { //正式
- // button.BtnUpdate = true
- // button.BtnModifySeller = true
- // return
- // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
- // button.BtnEdit = true
- // button.BtnDelete = true
- // button.BtnSuspend = true
- // button.BtnDelay = true
- // button.BtnTurnPositive = true
- // button.BtnModifySeller = true
- // return
- // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
- // button.BtnThaw = true
- // return
- // } else if status == utils.COMPANY_STATUS_LOSE { //流失
- // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
- // button.BtnApplyReceive = true
- // } else {
- // button.BtnReceive = true
- // }
- // if itemSellerId == sysUserId || (itemGroupId == sysUserGroupId && authority > 0) {
- // button.BtnDelete = true
- // }
- // return
- // } else { //永续
- // button.BtnDelete = true
- // return
- // }
- // }else{
- // if productId==1 {
- // button.BtnReceive=true
- // }else{
- // if status == utils.COMPANY_STATUS_FORMAL { //正式
- // button.BtnModifySeller=true
- // return
- // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
- // button.BtnModifySeller=true
- // return
- // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
- // button.BtnThaw = true
- // return
- // } else if status == utils.COMPANY_STATUS_LOSE { //流失
- // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
- // button.BtnApplyReceive = true
- // } else {
- // button.BtnReceive = true
- // }
- // return
- // } else { //永续
- // button.BtnDelete = true
- // return
- // }
- // }
- // }
- // } else {
- // if itemSellerId==sysUserId {
- // if status == utils.COMPANY_STATUS_FORMAL { //正式
- // button.BtnUpdate = true
- // return
- // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
- // button.BtnEdit = true
- // button.BtnDelete = true
- // button.BtnSuspend = true
- // button.BtnDelay = true
- // button.BtnTurnPositive = true
- // return
- // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
- // button.BtnThaw = true
- // return
- // } else if status == utils.COMPANY_STATUS_LOSE { //流失
- // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
- // button.BtnApplyReceive = true
- // } else {
- // button.BtnReceive = true
- // }
- // if itemSellerId == sysUserId || (itemGroupId == sysUserGroupId && authority > 0) {
- // button.BtnDelete = true
- // }
- // return
- // } else { //永续
- // button.BtnDelete = true
- // return
- // }
- // }else{
- // if productId==1 {
- // button.BtnReceive=true
- // }else{
- // if status == utils.COMPANY_STATUS_FORMAL { //正式
- // return
- // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
- // return
- // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
- // button.BtnThaw = true
- // return
- // } else if status == utils.COMPANY_STATUS_LOSE { //流失
- // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
- // button.BtnApplyReceive = true
- // } else {
- // button.BtnReceive = true
- // }
- // return
- // } else { //永续
- // button.BtnDelete = true
- // return
- // }
- // }
- // }
- // }
- // }
- // }
- // return button
- //}
- //func GetCompanyPermissionButton(roleTypeCode, status string, itemGroupId, sysUserGroupId, itemSellerId, sysUserId, authority, productId int) (button company.ButtonPermission) {
- // button.BtnView = true
- // if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN { //超级管理员
- // if !strings.Contains(status, "/") {
- // if status == utils.COMPANY_STATUS_FORMAL { //正式
- // button.BtnView = true
- // button.BtnModifySeller = true
- // return
- // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
- // button.BtnEdit = true
- // button.BtnDelete = true
- // button.BtnFreeze=true
- // return
- // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
- // button.BtnModifySeller = true
- // button.BtnView = true
- // return
- // } else if status == utils.COMPANY_STATUS_LOSE { //流失
- // button.BtnDelete = true
- // button.BtnModifySeller = true
- // return
- // } else { //永续
- // button.BtnDelete = true
- // button.BtnEdit = true
- // return
- // }
- // }
- // } else if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN {
- // fmt.Println("itemSellerId:",itemSellerId)
- // fmt.Println("sysUserId:",sysUserId)
- // if !strings.Contains(status, "/") {
- // if itemSellerId == sysUserId {
- // if productId == 1 {
- // if status == utils.COMPANY_STATUS_FORMAL { //正式
- // button.BtnModifySeller = true
- // button.BtnUpdate = true
- // return
- // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
- // button.BtnEdit = true
- // button.BtnDelete = true
- // button.BtnModifySeller = true
- // button.BtnSuspend = true
- // button.BtnDelay = true
- // button.BtnTurnPositive = true
- // button.BtnFreeze=true
- // return
- // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
- // button.BtnModifySeller = true
- // button.BtnView = true
- // return
- // } else if status == utils.COMPANY_STATUS_LOSE { //流失
- // button.BtnModifySeller = true
- // if itemSellerId == sysUserId || (itemGroupId == sysUserGroupId && authority > 0) {
- // button.BtnDelete = true
- // }
- // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
- // button.BtnApplyReceive = true
- // } else {
- // button.BtnReceive = true
- // }
- // return
- // } else { //永续
- // button.BtnDelete = true
- // return
- // }
- // } else {
- // //button.BtnReceiveOther=true
- // return
- // }
- // } else {
- // if productId == 1 {
- // if status == utils.COMPANY_STATUS_FORMAL { //正式
- // button.BtnModifySeller = true
- // return
- // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
- // button.BtnEdit = true
- // button.BtnDelete = true
- // return
- // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
- // button.BtnModifySeller = true
- // button.BtnView = true
- // return
- // } else if status == utils.COMPANY_STATUS_LOSE { //流失
- // button.BtnModifySeller = true
- // button.BtnDelete = true
- // button.BtnView = true
- // return
- // } else { //永续
- // return
- // }
- // } else {
- // button.BtnReceiveOther = true
- // return
- // }
- // }
- // }
- // } else if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
- // if !strings.Contains(status, "/") {
- // if itemSellerId == sysUserId {
- // if productId == 2 {
- // if status == utils.COMPANY_STATUS_FORMAL { //正式
- // button.BtnModifySeller = true
- // button.BtnUpdate = true
- // return
- // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
- // button.BtnEdit = true
- // button.BtnDelete = true
- // button.BtnModifySeller = true
- // button.BtnSuspend = true
- // button.BtnDelay = true
- // button.BtnTurnPositive = true
- // button.BtnFreeze=true
- // return
- // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
- // button.BtnModifySeller = true
- // return
- // } else if status == utils.COMPANY_STATUS_LOSE { //流失
- // button.BtnModifySeller = true
- // if itemSellerId == sysUserId || (itemGroupId == sysUserGroupId && authority > 0) {
- // button.BtnDelete = true
- // }
- // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
- // button.BtnApplyReceive = true
- // } else {
- // button.BtnReceive = true
- // }
- // return
- // } else { //永续
- // button.BtnDelete = true
- // return
- // }
- // } else {
- // return
- // }
- // } else {
- // if productId == 2 {
- // if status == utils.COMPANY_STATUS_FORMAL { //正式
- // button.BtnModifySeller = true
- // button.BtnView = true
- // return
- // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
- // button.BtnEdit = true
- // button.BtnDelete = true
- // return
- // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
- // button.BtnView = true
- // button.BtnModifySeller = true
- // return
- // } else if status == utils.COMPANY_STATUS_LOSE { //流失
- // button.BtnModifySeller = true
- // button.BtnDelete = true
- // button.BtnView = true
- // return
- // } else { //永续
- // return
- // }
- // } else {
- // //button.BtnReceive = true
- // return
- // }
- // }
- // }
- // } else if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER {
- // if !strings.Contains(status, "/") {
- // if itemSellerId == sysUserId {
- // if productId == 1 {
- // if status == utils.COMPANY_STATUS_FORMAL { //正式
- // button.BtnUpdate = true
- // return
- // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
- // button.BtnDelete = true
- // button.BtnEdit = true
- // button.BtnSuspend = true
- // button.BtnDelay = true
- // button.BtnTurnPositive = true
- // button.BtnFreeze=true
- // return
- // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
- // button.BtnThaw = true
- // return
- // } else if status == utils.COMPANY_STATUS_LOSE { //流失
- // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
- // button.BtnApplyReceive = true
- // } else {
- // button.BtnReceive = true
- // }
- // if itemSellerId == sysUserId || (sysUserGroupId == itemGroupId && authority == 2) {
- // button.BtnDelete = true
- // }
- // return
- // } else { //永续
- // button.BtnDelete = true
- // return
- // }
- // } else {
- // button.BtnReceiveOther = true
- // return
- // }
- // } else {
- // if productId == 1 {
- // if status == utils.COMPANY_STATUS_FORMAL { //正式
- // return
- // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
- // return
- // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
- // button.BtnApplyReceive = true
- // button.BtnView = false
- // return
- // } else if status == utils.COMPANY_STATUS_LOSE { //流失
- // if itemGroupId == sysUserGroupId {
- // button.BtnApplyReceive = true
- // } else {
- // button.BtnReceive = true
- // }
- // button.BtnView = false
- // return
- // } else { //永续
- // button.BtnDelete = true
- // return
- // }
- // } else {
- // button.BtnReceiveOther = true
- // button.BtnView = false
- // return
- // }
- // }
- // }
- // } else if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER {
- // if !strings.Contains(status, "/") {
- // if itemSellerId == sysUserId {
- // if productId == 2 {
- // if status == utils.COMPANY_STATUS_FORMAL { //正式
- // button.BtnUpdate = true
- // return
- // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
- // button.BtnDelete = true
- // button.BtnEdit = true
- // button.BtnSuspend = true
- // button.BtnDelay = true
- // button.BtnTurnPositive = true
- // button.BtnFreeze=true
- // return
- // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
- // button.BtnThaw = true
- // return
- // } else if status == utils.COMPANY_STATUS_LOSE { //流失
- // if itemGroupId == sysUserGroupId {
- // button.BtnApplyReceive = true
- // } else {
- // button.BtnReceive = true
- // }
- // if sysUserGroupId == itemGroupId && authority == 2 {
- // button.BtnDelete = true
- // }
- // return
- // } else { //永续
- // button.BtnDelete = true
- // return
- // }
- // } else {
- // button.BtnReceiveOther = true
- // return
- // }
- // } else {
- // if productId == 2 {
- // if status == utils.COMPANY_STATUS_FORMAL { //正式
- // return
- // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
- // return
- // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
- // button.BtnApplyReceive = true
- // button.BtnView = false
- // return
- // } else if status == utils.COMPANY_STATUS_LOSE { //流失
- // if itemGroupId == sysUserGroupId {
- // button.BtnApplyReceive = true
- // } else {
- // button.BtnReceive = true
- // }
- // button.BtnView = false
- // return
- // } else { //永续
- // button.BtnDelete = true
- // return
- // }
- // } else {
- // button.BtnReceiveOther = true
- // button.BtnView = false
- // return
- // }
- // }
- // }
- // }
- // return button
- //}
- //
- func GetCompanyPermissionButton(roleTypeCode, status, itemSellerIds, itemGroupIdS string, itemGroupId, sysUserGroupId, itemSellerId, sysUserId, authority, productId, shareSellerId int, shareSellerIds string) (button company.ButtonPermission) {
- //产品状态map
- productStatusMap := make(map[int]string)
- if productId == 1 {
- productStatusMap[1] = status
- } else if productId == 2 {
- productStatusMap[2] = status
- }
- if strings.Contains(status, "/") {
- statusSlice := strings.Split(status, "/")
- productStatusMap[1] = statusSlice[0]
- productStatusMap[2] = statusSlice[1]
- }
- //所属销售map
- sellerIdMap := make(map[int]int)
- if productId == 1 {
- sellerIdMap[1] = itemSellerId
- } else if productId == 2 {
- sellerIdMap[2] = itemSellerId
- }
- if strings.Contains(itemSellerIds, "/") {
- sellerIdSlice := strings.Split(itemSellerIds, "/")
- sellerIdMap[1], _ = strconv.Atoi(sellerIdSlice[0])
- sellerIdMap[2], _ = strconv.Atoi(sellerIdSlice[1])
- }
- //分组map
- groupIdMap := make(map[int]int)
- if productId == 1 {
- groupIdMap[1] = itemGroupId
- } else if productId == 2 {
- groupIdMap[2] = itemGroupId
- }
- if strings.Contains(itemGroupIdS, "/") {
- groupIdSlice := strings.Split(itemGroupIdS, "/")
- groupIdMap[1], _ = strconv.Atoi(groupIdSlice[0])
- groupIdMap[2], _ = strconv.Atoi(groupIdSlice[1])
- }
- shareSellerIdArr := strings.Split(shareSellerIds, ",")
- if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN { //超级管理员
- button.BtnView = true //查看详情权限
- if !strings.Contains(status, "/") {
- if status == utils.COMPANY_STATUS_FORMAL { //正式
- //button.BtnModifySeller = true
- if productId == utils.COMPANY_PRODUCT_RAI_ID {
- button.BtnRemarkViewHistory = true
- } else {
- button.BtnRemarkView = true
- }
- return
- } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
- button.BtnEdit = true
- button.BtnDelete = true
- if productId == utils.COMPANY_PRODUCT_RAI_ID {
- button.BtnRemarkViewHistory = true
- } else {
- button.BtnRemarkView = true
- }
- //button.BtnModifySeller = true
- button.BtnFreeze = false
- if productId == utils.COMPANY_PRODUCT_FICC_ID {
- button.BtnClose = true // 超管/FICC管理员可关闭试用客户
- }
- return
- } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
- //button.BtnModifySeller = true
- if productId == utils.COMPANY_PRODUCT_RAI_ID {
- button.BtnRemarkViewHistory = true
- } else {
- button.BtnRemarkView = true
- }
- return
- } else if status == utils.COMPANY_STATUS_LOSE { //流失
- //button.BtnModifySeller = true
- button.BtnDelete = true
- if productId == utils.COMPANY_PRODUCT_RAI_ID {
- button.BtnRemarkViewHistory = true
- }
- return
- } else if status == utils.COMPANY_STATUS_CLOSE { // 关闭
- //button.BtnModifySeller = true
- button.BtnDelete = true
- if productId == utils.COMPANY_PRODUCT_FICC_ID {
- button.BtnLoss = true // 超管/FICC管理员可关闭转流失
- }
- return
- } else { //永续
- //button.BtnModifySeller = true
- button.BtnDelete = true
- button.BtnEdit = true
- if productId == utils.COMPANY_PRODUCT_RAI_ID {
- button.BtnRemarkViewHistory = true
- }
- return
- }
- }
- } else if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN {
- //查看详情权限
- productStatus, hasProduct := productStatusMap[1]
- if hasProduct {
- button.BtnView = true
- if productStatus == utils.COMPANY_STATUS_FORMAL { //正式
- button.BtnModifySeller = true
- button.BtnShare = true
- return
- } else if productStatus == utils.COMPANY_STATUS_TRY_OUT { //试用
- button.BtnEdit = true
- //button.BtnDelete = true
- button.BtnModifySeller = true
- button.BtnFreeze = false
- button.BtnClose = true // 超管/FICC管理员可关闭试用客户
- return
- } else if productStatus == utils.COMPANY_STATUS_FREEZE { //冻结
- button.BtnModifySeller = true
- return
- } else if productStatus == utils.COMPANY_STATUS_LOSE { //流失
- //button.BtnModifySeller = true
- //button.BtnDelete = true
- return
- } else if productStatus == utils.COMPANY_STATUS_CLOSE { // 关闭
- button.BtnLoss = true // 超管/FICC管理员可关闭转流失
- return
- } else { //永续
- return
- }
- } else {
- productStatus2, hasProduct2 := productStatusMap[2]
- //如果没有权限的话,那么允许领取其他部门客户按钮权限
- if hasProduct2 {
- //其他产品的流失客户可以有查看权限
- if productStatus2 == utils.COMPANY_STATUS_LOSE {
- button.BtnView = true //查看权限
- }
- }
- }
- return
- } else if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
- //查看详情权限
- productStatus, hasProduct := productStatusMap[2]
- if hasProduct {
- button.BtnView = true
- if productStatus == utils.COMPANY_STATUS_FORMAL { //正式
- button.BtnModifySeller = true
- button.BtnShare = true
- button.BtnRemarkViewHistory = true
- } else if productStatus == utils.COMPANY_STATUS_TRY_OUT { //试用
- button.BtnEdit = true
- //button.BtnDelete = true
- button.BtnModifySeller = true
- button.BtnFreeze = false
- // CRM14.7.2 权益管理员可以设置试用客户为共享
- button.BtnShare = true
- button.BtnRemarkViewHistory = true
- } else if productStatus == utils.COMPANY_STATUS_FREEZE { //冻结
- button.BtnModifySeller = true
- button.BtnRemarkViewHistory = true
- } else if productStatus == utils.COMPANY_STATUS_LOSE { //流失
- //button.BtnDelete = true
- button.BtnRemarkViewHistory = true
- } else { //永续
- button.BtnModifySeller = true
- button.BtnShare = true
- button.BtnRemarkViewHistory = true
- }
- } else {
- productStatus2, hasProduct2 := productStatusMap[1]
- //如果没有权限的话,那么允许领取其他部门客户按钮权限
- if hasProduct2 {
- //其他产品的流失客户可以有查看权限
- if productStatus2 == utils.COMPANY_STATUS_LOSE {
- button.BtnView = true //查看权限
- }
- }
- }
- return
- } else if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER || roleTypeCode == utils.ROLE_TYPE_CODE_FICC_TEAM || roleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
- //判断该客户是否有ficc权限
- productStatus, hasProduct := productStatusMap[1]
- if hasProduct {
- //如果有权限的话:
- //获取当前ficc的销售id
- sellerId, hasSellerId := sellerIdMap[1]
- //获取当前ficc的销售分组id
- groupId, hasGroupId := groupIdMap[1]
- //如果是自己客户,那么拥有查看权限
- if hasSellerId {
- if sellerId == sysUserId || utils.InArrayByStr(shareSellerIdArr, strconv.Itoa(sysUserId)) || shareSellerId == sysUserId {
- button.BtnView = true //显示权限、详情
- if productStatus == utils.COMPANY_STATUS_FORMAL { //正式
- button.BtnUpdate = true //服务更新
- button.BtnAddAgreement = true //补充协议
- button.BtnTryOut = true
- button.BtnModifySeller = true
- button.BtnShare = true
- button.BtnRemarkEdit = true
- button.BtnRemarkView = true
- if sellerId != sysUserId {
- button.BtnModifySeller = false
- }
- } else if productStatus == utils.COMPANY_STATUS_TRY_OUT { //试用
- button.BtnEdit = true
- button.BtnDelete = true
- button.BtnSuspend = true
- button.BtnDelay = true
- button.BtnTurnPositive = true
- button.BtnFreeze = true
- button.BtnModifySeller = true
- button.BtnRemarkEdit = true
- button.BtnRemarkView = true
- if sellerId != sysUserId {
- button.BtnModifySeller = false
- }
- } else if productStatus == utils.COMPANY_STATUS_FREEZE { //冻结
- button.BtnThaw = true
- button.BtnModifySeller = true
- button.BtnRemarkEdit = true
- button.BtnRemarkView = true
- if sellerId != sysUserId {
- button.BtnModifySeller = false
- }
- } else if productStatus == utils.COMPANY_STATUS_LOSE { //流失
- button.BtnApplyReceive = true
- } else { //永续
- //button.BtnDelete = true
- }
- } else {
- if productStatus == utils.COMPANY_STATUS_LOSE { //流失
- button.BtnView = true //显示权限、详情
- //如果不是自己客户,那么判断是否是本小组的,如果是本小组,那么还是申请领取,非本小组的话,那就是领取
- if groupId == sysUserGroupId {
- button.BtnApplyReceive = true
- } else {
- button.BtnReceive = true
- }
- }
- }
- }
- //如果是组长,且该客户属于本组客户
- if authority == 4 && hasGroupId && groupId == sysUserGroupId && roleTypeCode == utils.ROLE_TYPE_CODE_FICC_TEAM {
- button.BtnView = true //查看详情权限
- if productStatus == utils.COMPANY_STATUS_FORMAL { //正式
- button.BtnModifySeller = true
- button.BtnShare = true
- button.BtnRemarkView = true
- } else if productStatus == utils.COMPANY_STATUS_TRY_OUT { //试用
- button.BtnModifySeller = true
- button.BtnRemarkView = true
- } else if productStatus == utils.COMPANY_STATUS_FREEZE { //冻结
- button.BtnModifySeller = true
- button.BtnRemarkView = true
- //button.BtnThaw = false
- } else if productStatus == utils.COMPANY_STATUS_LOSE { //流失
- if sellerId == sysUserId || groupId == sysUserGroupId || utils.InArrayByStr(shareSellerIdArr, strconv.Itoa(sysUserId)) || shareSellerId == sysUserId {
- button.BtnApplyReceive = true
- } else {
- button.BtnReceive = true
- }
- } else { //永续
- //button.BtnDelete = true
- }
- }
- //如果是ficc销售主管,且该客户属于本组客户
- //获取父级groupId
- groupIdpid, err := company.GetParentIdFromGroup(groupId)
- if err != nil {
- fmt.Println(err.Error())
- }
- sysUserGroupIdpid, err := company.GetParentIdFromGroup(sysUserGroupId)
- if err != nil {
- fmt.Println(err.Error())
- }
- var pidBool bool
- //处理主管和销售在不同的二三级分组下的情况
- if groupIdpid != nil && sysUserGroupIdpid != nil {
- pidBool = *groupIdpid == *sysUserGroupIdpid || *groupIdpid == sysUserGroupId || groupId == sysUserGroupId || groupId == *sysUserGroupIdpid
- }
- if authority == 2 && hasGroupId && pidBool && roleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
- button.BtnView = true //查看详情权限
- if productStatus == utils.COMPANY_STATUS_FORMAL { //正式
- button.BtnModifySeller = true
- button.BtnShare = true
- button.BtnRemarkView = true
- } else if productStatus == utils.COMPANY_STATUS_TRY_OUT { //试用
- button.BtnModifySeller = true
- button.BtnRemarkView = true
- } else if productStatus == utils.COMPANY_STATUS_FREEZE { //冻结
- button.BtnModifySeller = true
- button.BtnRemarkView = true
- //button.BtnThaw = false
- } else if productStatus == utils.COMPANY_STATUS_LOSE { //流失
- if sellerId == sysUserId || groupId == sysUserGroupId || utils.InArrayByStr(shareSellerIdArr, strconv.Itoa(sysUserId)) || shareSellerId == sysUserId {
- button.BtnApplyReceive = true
- } else {
- button.BtnReceive = true
- }
- } else { //永续
- //button.BtnDelete = true
- }
- }
- //ficc同一个大组当作一个小组来处理领取按钮
- var ids []*string
- if groupIdpid != nil && *groupIdpid != 0 {
- ids, err = company.GetGroupIdsByParentId(*groupIdpid)
- if err != nil {
- fmt.Println(err.Error())
- }
- }
- var idSlice []string
- var sid string
- for _, id := range ids {
- idSlice = append(idSlice, *id)
- }
- sid = strings.Join(idSlice, ",")
- if strings.Contains(sid, strconv.Itoa(itemGroupId)) {
- if productStatus == utils.COMPANY_STATUS_LOSE { //流失
- button.BtnApplyReceive = true
- button.BtnReceive = false
- }
- }
- } else {
- productStatus2, hasProduct2 := productStatusMap[2]
- //如果没有权限的话,那么允许领取其他部门客户按钮权限
- if hasProduct2 {
- //如果客户ficc权限是永续,那么也没有其他部门客户的按钮权限
- if productStatus2 != utils.COMPANY_STATUS_FOREVER {
- button.BtnReceiveOther = true //领取其他部门客户按钮权限
- }
- //其他产品的流失客户可以有查看权限
- if productStatus2 == utils.COMPANY_STATUS_LOSE {
- button.BtnView = true //查看权限
- }
- }
- }
- return
- } else if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER || roleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
- //判断该客户是否有权益权限
- productStatus, hasProduct := productStatusMap[2]
- if hasProduct {
- //如果有权限的话:
- //获取当前 权益 的销售id
- sellerId, hasSellerId := sellerIdMap[2]
- //获取当前 权益 的销售分组id
- groupId, hasGroupId := groupIdMap[2]
- //如果是自己客户,那么拥有查看权限
- if hasSellerId {
- if sellerId == sysUserId || utils.InArrayByStr(shareSellerIdArr, strconv.Itoa(sysUserId)) || shareSellerId == sysUserId {
- button.BtnView = true //显示权限、详情
- if productStatus == utils.COMPANY_STATUS_FORMAL { //正式
- button.BtnUpdate = true
- button.BtnTryOut = true
- button.BtnModifySeller = true
- //button.BtnShare = true
- button.BtnRemarkEdit = true
- //button.BtnRemarkView = true //权益销售隐藏
- button.BtnRemarkViewHistory = true
- } else if productStatus == utils.COMPANY_STATUS_TRY_OUT { //试用
- button.BtnEdit = true
- button.BtnDelete = true
- button.BtnSuspend = true
- button.BtnDelay = true
- button.BtnTurnPositive = true
- button.BtnModifySeller = true
- button.BtnFreeze = true
- button.BtnRemarkEdit = true
- //button.BtnRemarkView = true //权益销售隐藏
- button.BtnRemarkViewHistory = true
- //button.BtnShare = true
- } else if productStatus == utils.COMPANY_STATUS_FREEZE { //冻结
- button.BtnThaw = true
- button.BtnModifySeller = true
- button.BtnRemarkEdit = true
- button.BtnRemarkView = true
- } else if productStatus == utils.COMPANY_STATUS_LOSE { //流失
- button.BtnApplyReceive = true
- button.BtnRemarkViewHistory = true
- } else if productStatus == utils.COMPANY_STATUS_FOREVER { //永续
- button.BtnTurnPositive = true
- button.BtnRemarkViewHistory = true
- }
- } else {
- if productStatus == utils.COMPANY_STATUS_LOSE { //流失
- button.BtnView = true //显示权限、详情
- button.BtnRemarkViewHistory = true
- //如果不是自己客户,那么判断是否是本小组的,如果是本小组,那么还是申请领取,非本小组的话,那就是领取
- if groupId == sysUserGroupId {
- button.BtnApplyReceive = true
- } else {
- button.BtnReceive = true
- }
- }
- }
- }
- //如果是组长,且该客户属于本组客户
- if authority == 2 && hasGroupId && groupId == sysUserGroupId {
- button.BtnView = true //查看详情权限
- button.BtnRemarkViewHistory = true //历史备注
- if productStatus == utils.COMPANY_STATUS_FORMAL { //正式
- button.BtnModifySeller = true
- //button.BtnShare = true
- //button.BtnRemarkView = true //权益销售隐藏
- //button.BtnRemarkViewHistory = true
- } else if productStatus == utils.COMPANY_STATUS_TRY_OUT { //试用
- button.BtnModifySeller = true
- //button.BtnRemarkView = true //权益销售隐藏
- //button.BtnRemarkViewHistory = true
- //button.BtnShare = true
- } else if productStatus == utils.COMPANY_STATUS_FREEZE { //冻结
- button.BtnModifySeller = true
- //button.BtnRemarkView = true //权益销售隐藏
- //button.BtnRemarkViewHistory = true
- } else if productStatus == utils.COMPANY_STATUS_LOSE { //流失
- if sellerId == sysUserId || groupId == sysUserGroupId || utils.InArrayByStr(shareSellerIdArr, strconv.Itoa(sysUserId)) || shareSellerId == sysUserId {
- button.BtnApplyReceive = true
- } else {
- button.BtnReceive = true
- }
- //button.BtnRemarkViewHistory = true
- } else { //永续
- //button.BtnDelete = true
- //button.BtnRemarkViewHistory = true
- }
- }
- } else {
- productStatus2, hasProduct2 := productStatusMap[1]
- //如果没有权限的话,那么允许领取其他部门客户按钮权限
- if hasProduct2 {
- //如果客户 权益 权限是永续,那么也没有其他部门客户的按钮权限
- if productStatus2 != utils.COMPANY_STATUS_FOREVER {
- button.BtnReceiveOther = true //领取其他部门客户按钮权限
- }
- //其他产品的流失客户可以有查看权限
- if productStatus2 == utils.COMPANY_STATUS_LOSE {
- button.BtnView = true //查看权限
- }
- }
- }
- return
- }
- return button
- }
- // GetCompanyPermissionButtonByReceiveEnabled 查询当前销售 "添加客户" 权限来判断按钮权限
- func GetCompanyPermissionButtonByReceiveEnabled(btnItem *company.ButtonPermission, receiveEnabled bool) (buttonNew *company.ButtonPermission) {
- //查询当前销售 "添加客户" 权限是否为禁用
- if !receiveEnabled {
- //申请领取、领取客户、领取其他部门客户按钮权限按钮显示时
- if btnItem.BtnApplyReceive || btnItem.BtnReceive || btnItem.BtnReceiveOther {
- btnItem.BtnApplyReceive = false
- btnItem.BtnReceive = false
- btnItem.BtnReceiveOther = false
- }
- if btnItem.BtnThaw {
- btnItem.BtnThaw = false
- }
- }
- buttonNew = btnItem
- return buttonNew
- }
- //func GetCompanyPermissionButtonOld(roleTypeCode, status string, itemGroupId, sysUserGroupId, itemSellerId, sysUserId, authority, productId int) (button company.ButtonPermission) {
- // button.BtnView = true
- // if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN { //超级管理员
- // if !strings.Contains(status, "/") {
- // if status == utils.COMPANY_STATUS_FORMAL { //正式
- // //button.BtnModifySeller = true
- // return
- // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
- // button.BtnEdit = true
- // button.BtnDelete = true
- // //button.BtnModifySeller = true
- // button.BtnFreeze = false
- // return
- // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
- // //button.BtnModifySeller = true
- // return
- // } else if status == utils.COMPANY_STATUS_LOSE { //流失
- // //button.BtnModifySeller = true
- // button.BtnDelete = true
- // return
- // } else { //永续
- // //button.BtnModifySeller = true
- // button.BtnDelete = true
- // button.BtnEdit = true
- // return
- // }
- // }
- // } else if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN {
- // if productId != 1 {
- // return
- // } else {
- // if !strings.Contains(status, "/") {
- // if status == utils.COMPANY_STATUS_FORMAL { //正式
- // button.BtnModifySeller = true
- // return
- // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
- // //button.BtnEdit = true
- // //button.BtnDelete = true
- // button.BtnModifySeller = true
- // button.BtnFreeze = false
- // return
- // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
- // //button.BtnModifySeller = true
- // return
- // } else if status == utils.COMPANY_STATUS_LOSE { //流失
- // //button.BtnModifySeller = true
- // //button.BtnDelete = true
- // return
- // } else { //永续
- // return
- // }
- // }
- // }
- // } else if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
- // if !strings.Contains(status, "/") {
- // if status == utils.COMPANY_STATUS_FORMAL { //正式
- // button.BtnModifySeller = true
- // return
- // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
- // //button.BtnEdit = true
- // //button.BtnDelete = true
- // button.BtnModifySeller = true
- // button.BtnFreeze = false
- // return
- // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
- // return
- // } else if status == utils.COMPANY_STATUS_LOSE { //流失
- // //button.BtnDelete = true
- // return
- // } else { //永续
- // return
- // }
- // }
- // } else if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER {
- // if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER && productId == 2 {
- // if !strings.Contains(status, "/") {
- // button.BtnReceiveOther = true //领取其他部门客户按钮权限
- // } else {
- // //共享客户,需要取出当前销售对应的 产品 权限(目前是ficc销售,所以是ficc的权限,也就是第1个)
- // statusSlice := strings.Split(status, "/")
- // ficcStatus := statusSlice[0]
- // if ficcStatus == utils.COMPANY_STATUS_LOSE { //流失
- // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
- // button.BtnApplyReceive = true //申请领取按钮权限
- // } else {
- // button.BtnReceive = true //领取客户按钮权限
- // }
- // return
- // }
- // }
- // return
- // }
- // if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER && productId == 1 {
- // return
- // }
- // //管理权限,0:无,1:部门负责人,2:小组负责人,3:超级管理员
- // if authority == 2 { //组长
- // if !strings.Contains(status, "/") {
- // if sysUserId == itemSellerId { //自己客户
- // if status == utils.COMPANY_STATUS_FORMAL { //正式
- // button.BtnUpdate = true
- // button.BtnModifySeller = true
- // button.BtnTryOut = true
- // return
- // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
- // button.BtnEdit = true
- // button.BtnDelete = true
- // button.BtnSuspend = true
- // button.BtnDelay = true
- // button.BtnTurnPositive = true
- // button.BtnModifySeller = true
- // button.BtnFreeze = true
- // return
- // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
- // button.BtnThaw = true
- // return
- // } else if status == utils.COMPANY_STATUS_LOSE { //流失
- // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
- // button.BtnApplyReceive = true
- // } else {
- // button.BtnReceive = true
- // }
- // if itemSellerId == sysUserId || (itemGroupId == sysUserGroupId && authority > 0) {
- // //button.BtnDelete = true
- // }
- // return
- // } else { //永续
- // button.BtnDelete = true
- // return
- // }
- // } else {
- // if productId == 1 {
- // if status == utils.COMPANY_STATUS_FORMAL { //正式
- // button.BtnModifySeller = true
- // return
- // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
- // button.BtnModifySeller = true
- // return
- // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
- // button.BtnThaw = false
- // return
- // } else if status == utils.COMPANY_STATUS_LOSE { //流失
- // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
- // button.BtnApplyReceive = true
- // } else {
- // button.BtnReceive = true
- // }
- // return
- // } else { //永续
- // button.BtnDelete = true
- // return
- // }
- // } else {
- // //button.BtnReceive = true
- // }
- // }
- // }
- // } else { //销售
- // if !strings.Contains(status, "/") {
- // if itemSellerId == sysUserId {
- // if status == utils.COMPANY_STATUS_FORMAL { //正式
- // button.BtnUpdate = true
- // button.BtnTryOut = true
- // return
- // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
- // button.BtnEdit = true
- // button.BtnDelete = true
- // button.BtnSuspend = true
- // button.BtnDelay = true
- // button.BtnTurnPositive = true
- // button.BtnFreeze = true
- // return
- // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
- // button.BtnThaw = true
- // return
- // } else if status == utils.COMPANY_STATUS_LOSE { //流失
- // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
- // button.BtnApplyReceive = true
- // } else {
- // button.BtnReceive = true
- // }
- // if itemSellerId == sysUserId || (itemGroupId == sysUserGroupId && authority > 0) {
- // //button.BtnDelete = true
- // }
- // return
- // } else { //永续
- // button.BtnDelete = true
- // return
- // }
- // } else {
- // if productId == 1 {
- // if status == utils.COMPANY_STATUS_FORMAL { //正式
- // return
- // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
- // return
- // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
- // button.BtnThaw = false
- // return
- // } else if status == utils.COMPANY_STATUS_LOSE { //流失
- // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
- // button.BtnApplyReceive = true
- // } else {
- // button.BtnReceive = true
- // }
- // return
- // } else { //永续
- // button.BtnDelete = true
- // return
- // }
- // } else {
- // //button.BtnReceive = true
- // }
- // }
- // } else {
- // //共享客户,需要取出当前销售对应的 产品 权限(目前是ficc销售,所以是ficc的权限,也就是第1个)
- // statusSlice := strings.Split(status, "/")
- // ficcStatus := statusSlice[0]
- // if ficcStatus == utils.COMPANY_STATUS_LOSE { //流失
- // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
- // button.BtnApplyReceive = true //申请领取按钮权限
- // } else {
- // button.BtnReceive = true //领取客户按钮权限
- // }
- // return
- // }
- // }
- // }
- // } else if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER {
- // if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER && productId == 2 {
- // return
- // }
- // if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER && productId == 1 {
- // if !strings.Contains(status, "/") {
- // button.BtnReceiveOther = true //领取其他部门客户按钮权限
- // } else {
- // //共享客户,需要取出当前销售对应的 产品 权限(目前是权益销售,所以是权益的权限,也就是第2个)
- // statusSlice := strings.Split(status, "/")
- // raiStatus := statusSlice[1]
- // if raiStatus == utils.COMPANY_STATUS_LOSE { //流失
- // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
- // button.BtnApplyReceive = true //申请领取按钮权限
- // } else {
- // button.BtnReceive = true //领取客户按钮权限
- // }
- // return
- // }
- // }
- // return
- // }
- // if !strings.Contains(status, "/") {
- // if authority == 2 { //组长
- // if itemSellerId == sysUserId {
- // if status == utils.COMPANY_STATUS_FORMAL { //正式
- // button.BtnUpdate = true
- // button.BtnModifySeller = true
- // button.BtnTryOut = true
- // return
- // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
- // button.BtnEdit = true
- // button.BtnDelete = true
- // button.BtnSuspend = true
- // button.BtnDelay = true
- // button.BtnTurnPositive = true
- // button.BtnModifySeller = true
- // button.BtnFreeze = true
- // return
- // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
- // button.BtnThaw = true
- // return
- // } else if status == utils.COMPANY_STATUS_LOSE { //流失
- // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
- // button.BtnApplyReceive = true
- // } else {
- // button.BtnReceive = true
- // }
- // if itemSellerId == sysUserId || (itemGroupId == sysUserGroupId && authority > 0) {
- // //button.BtnDelete = true
- // }
- // return
- // } else { //永续
- // button.BtnDelete = true
- // return
- // }
- // } else {
- // if productId == 1 {
- // //button.BtnReceive = true
- // } else {
- // if status == utils.COMPANY_STATUS_FORMAL { //正式
- // button.BtnModifySeller = true
- // return
- // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
- // button.BtnModifySeller = true
- // return
- // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
- // button.BtnThaw = false
- // return
- // } else if status == utils.COMPANY_STATUS_LOSE { //流失
- // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
- // button.BtnApplyReceive = true
- // } else {
- // button.BtnReceive = true
- // }
- // return
- // } else { //永续
- // button.BtnDelete = true
- // return
- // }
- // }
- // }
- // } else {
- // if itemSellerId == sysUserId {
- // if status == utils.COMPANY_STATUS_FORMAL { //正式
- // button.BtnUpdate = true
- // button.BtnTryOut = true
- // return
- // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
- // button.BtnEdit = true
- // button.BtnDelete = true
- // button.BtnSuspend = true
- // button.BtnDelay = true
- // button.BtnTurnPositive = true
- // button.BtnFreeze = true
- // return
- // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
- // button.BtnThaw = true
- // return
- // } else if status == utils.COMPANY_STATUS_LOSE { //流失
- // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
- // button.BtnApplyReceive = true //申请领取按钮权限
- // } else {
- // button.BtnReceive = true //领取客户按钮权限
- // }
- // if itemSellerId == sysUserId || (itemGroupId == sysUserGroupId && authority > 0) {
- // //button.BtnDelete = true
- // }
- // return
- // } else { //永续
- // button.BtnDelete = true
- // return
- // }
- // } else {
- // if productId == 1 {
- // //button.BtnReceive = true
- // } else {
- // if status == utils.COMPANY_STATUS_FORMAL { //正式
- // return
- // } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用
- // return
- // } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
- // button.BtnThaw = false
- // return
- // } else if status == utils.COMPANY_STATUS_LOSE { //流失
- // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
- // button.BtnApplyReceive = true //申请领取按钮权限
- // } else {
- // button.BtnReceive = true //领取客户按钮权限
- // }
- // return
- // } else { //永续
- // button.BtnDelete = true
- // return
- // }
- // }
- // }
- // }
- // } else {
- // //共享客户,需要取出当前销售对应的 产品 权限(目前是权益销售,所以是权益的权限,也就是第2个)
- // statusSlice := strings.Split(status, "/")
- // raiStatus := statusSlice[1]
- // if raiStatus == utils.COMPANY_STATUS_LOSE { //流失
- // if itemSellerId == sysUserId || itemGroupId == sysUserGroupId {
- // button.BtnApplyReceive = true //申请领取按钮权限
- // } else {
- // button.BtnReceive = true //领取客户按钮权限
- // }
- // return
- // }
- // }
- // }
- // return button
- //}
- // 校验当前操作员是否具有联系人权限是否有操作权限
- func CheckCompanyUserButton(roleTypeCode string, itemSellerId, sysUserId, productId, shareSellerId int, status string) (ok bool) {
- if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
- ok = true
- return
- }
- if sysUserId == itemSellerId || shareSellerId == sysUserId {
- ok = true
- //如果客户状态是流失,那么就无法操作
- if status == utils.COMPANY_STATUS_LOSE || status == utils.COMPANY_STATUS_CLOSE {
- ok = false
- return
- }
- return
- } else {
- if productId == 1 && roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN {
- //如果是ficc类型,同时当前账户是ficc管理员
- ok = true
- } else if productId == 2 && roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
- //如果是权益类型,同时当前账户是 权益管理员
- ok = true
- }
- }
- return
- }
- // 校验当前操作员是否具给联系人开通个人研选的权限
- func CheckCompanyUserYanXuanButton(roleTypeCode string, adminMobile string) (ok bool, err error) {
- if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER || roleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
- ok = true
- return
- }
- crmConfig, err := company.GetConfigDetailByCode("rai_wx_user_yanxuan_button")
- if err != nil {
- return
- }
- sliceMobile := strings.Split(crmConfig.ConfigValue, ",")
- for _, v := range sliceMobile {
- if v == adminMobile {
- ok = true
- return
- }
- }
- return
- }
- // GenerateOpenCompanyCode 生成第三方code编号
- func GenerateOpenCompanyCode(companyId int) (openCode string) {
- openCode = utils.MD5(fmt.Sprint(companyId, "hzyj20210902"))
- return
- }
- // GenerateOpenCompanyProductCode 生成客户产品第三方code编号
- func GenerateOpenCompanyProductCode(companyId, productId int) (openCode string) {
- openCode = utils.MD5(fmt.Sprint(companyId, "_", productId, "hzyj20210902"))
- return
- }
- // GetApplyTurnContractType
- // 获取客户申请合同类型
- func GetApplyTurnContractType(companyId, productId int) (contractType string, err error) {
- //合同类型
- contractType = "新签合同"
- companyProduct, err := company.GetCompanyProductByCompanyIdAndProductId(companyId, productId)
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- err = nil
- return
- }
- err = errors.New("获取客户信息失败,Err:" + err.Error())
- return
- }
- // 当前客户产品状态为试用,那么是续约合同
- if companyProduct.Status == "正式" {
- contractType = "续约合同"
- }
- var condition string
- var pars []interface{}
- condition += " AND product_id = ?"
- pars = append(pars, productId)
- condition += " AND status = ?"
- pars = append(pars, 1)
- list, err := company.GetCompanyContractListByCompanyId(companyId, condition, pars)
- if err != nil {
- err = errors.New("获取合同信息失败,Err:" + err.Error())
- return
- }
- if len(list) > 0 {
- contractType = "续约合同"
- }
- //查询是否存在正式转试用的记录,如果存在,那么合同类型是续约合同
- total, err := company.GetCompanyProductOperationRecordCount(companyProduct.CompanyId, companyProduct.ProductId)
- if err != nil {
- err = errors.New("查询用户变更记录异常,Err:" + err.Error())
- return
- }
- if total > 0 {
- contractType = "续约合同"
- }
- return
- }
- // GetLastContractPermissionList
- // 获取客户的最近合同的权限期限
- func GetLastContractPermissionList(companyId, productId int) (permissionMap map[int]company.PermissionLookItem, err error) {
- permissionMap = map[int]company.PermissionLookItem{}
- contractList, err := company.GetCompanyWillContractList(companyId, productId)
- if err != nil {
- err = errors.New("获取合同信息失败,Err:" + err.Error())
- return
- }
- for _, contractInfo := range contractList {
- permissionList, permissionErr := company.GetCompanyContractPermissionListByContractIds(strconv.Itoa(contractInfo.CompanyContractId))
- if permissionErr != nil {
- err = errors.New("获取合同信息失败,Err:" + permissionErr.Error())
- return
- }
- for _, v := range permissionList {
- if permission, ok := permissionMap[v.ChartPermissionId]; ok {
- nowEndDateTime, tmpErr := time.Parse(utils.FormatDate, v.EndDate)
- if tmpErr != nil {
- err = errors.New("获取合同信息失败,合同结束日期格式化失败,Err:" + tmpErr.Error())
- return
- }
- perEndDateTime, tmpErr := time.Parse(utils.FormatDate, permission.EndDate)
- if err != nil {
- err = errors.New("获取合同信息失败,合同结束日期格式化失败2,Err:" + tmpErr.Error())
- return
- }
- //如果当前合同的权限期限晚于已经记录的权限期限,那么重新赋值
- if nowEndDateTime.After(perEndDateTime) {
- permissionMap[v.ChartPermissionId] = company.PermissionLookItem{
- ChartPermissionId: v.ChartPermissionId,
- PermissionName: v.ChartPermissionName,
- StartDate: v.StartDate,
- EndDate: v.EndDate,
- //Status string `description:"'正式','试用','关闭'"`
- //ExpireDay string `description:"到期天数"`
- ClassifyName: v.ClassifyName,
- }
- }
- } else {
- permissionMap[v.ChartPermissionId] = company.PermissionLookItem{
- ChartPermissionId: v.ChartPermissionId,
- PermissionName: v.ChartPermissionName,
- StartDate: v.StartDate,
- EndDate: v.EndDate,
- //Status string `description:"'正式','试用','关闭'"`
- //ExpireDay string `description:"到期天数"`
- ClassifyName: v.ClassifyName,
- }
- }
- }
- }
- //获取权限
- permissionList, permissionErr := company.GetCompanyReportPermissionListByProductId(companyId, productId)
- if permissionErr != nil {
- err = errors.New("获取权限失败,Err:" + permissionErr.Error())
- return
- }
- for _, v := range permissionList {
- if permission, ok := permissionMap[v.ChartPermissionId]; ok {
- nowEndDateTime, tmpErr := time.Parse(utils.FormatDate, v.EndDate)
- if tmpErr != nil {
- err = errors.New("获取合同信息失败,合同结束日期格式化失败,Err:" + tmpErr.Error())
- return
- }
- perEndDateTime, tmpErr := time.Parse(utils.FormatDate, permission.EndDate)
- if err != nil {
- err = errors.New("获取合同信息失败,合同结束日期格式化失败2,Err:" + tmpErr.Error())
- return
- }
- //如果当前合同的权限期限晚于已经记录的权限期限,那么重新赋值
- if nowEndDateTime.After(perEndDateTime) {
- permissionMap[v.ChartPermissionId] = company.PermissionLookItem{
- ChartPermissionId: v.ChartPermissionId,
- PermissionName: v.PermissionName,
- StartDate: v.StartDate,
- EndDate: v.EndDate,
- //Status string `description:"'正式','试用','关闭'"`
- //ExpireDay string `description:"到期天数"`
- ClassifyName: v.ClassifyName,
- }
- }
- } else {
- permissionMap[v.ChartPermissionId] = company.PermissionLookItem{
- ChartPermissionId: v.ChartPermissionId,
- PermissionName: v.PermissionName,
- StartDate: v.StartDate,
- EndDate: v.EndDate,
- //Status string `description:"'正式','试用','关闭'"`
- //ExpireDay string `description:"到期天数"`
- ClassifyName: v.ClassifyName,
- }
- }
- }
- return
- }
- // GetFiccLastUserViewHistoryByCompanyIds 根据客户id集合map获取ficc最后一次阅读时间
- func GetFiccLastUserViewHistoryByCompanyIds(companyIdStr string, mobileList, emailList []string, mobileCompanyIdMap, emailCompanyIdMap map[string]int) (companyViewTime map[int]time.Time, err error) {
- //user_view_record mobile
- companyViewTime = make(map[int]time.Time)
- userViewList, err := models.GetLastUserViewHistoryByCompanyIdsMobile(companyIdStr)
- if err != nil {
- return
- }
- for _, userView := range userViewList {
- companyViewTime[userView.CompanyId] = userView.ViewTime
- }
- //user_view_record email
- userViewList, err = models.GetLastUserViewHistoryByCompanyIdsEmail(companyIdStr)
- if err != nil {
- return
- }
- checkLastTime(companyViewTime, userViewList)
- //AdvisoryArticleViewRecord mobile
- userViewList, err = models.GetLastAdvisoryArticleViewRecordByCompanyIdsMobile(companyIdStr)
- if err != nil {
- return
- }
- checkLastTime(companyViewTime, userViewList)
- //AdvisoryArticleViewRecord email
- userViewList, err = models.GetLastAdvisoryArticleViewRecordByCompanyIdsEmail(companyIdStr)
- if err != nil {
- return
- }
- checkLastTime(companyViewTime, userViewList)
- //ReportViewRecord mobile
- mobileOrEmailViewList, err := models.GetLastReportViewRecordByMobileList(mobileList)
- if err != nil {
- return
- }
- checkMobileOrEmailLastTime(companyViewTime, mobileOrEmailViewList, mobileCompanyIdMap)
- //ReportViewRecord email
- mobileOrEmailViewList, err = models.GetLastReportViewRecordByEmailList(emailList)
- if err != nil {
- return
- }
- checkMobileOrEmailLastTime(companyViewTime, mobileOrEmailViewList, emailCompanyIdMap)
- //UserViewStatistics mobile
- userViewList, err = models.GetLastUserViewStatisticsByCompanyIdsMobile(companyIdStr)
- if err != nil {
- return
- }
- checkLastTime(companyViewTime, userViewList)
- //UserViewStatistics email
- userViewList, err = models.GetLastUserViewStatisticsByCompanyIdsEmail(companyIdStr)
- if err != nil {
- return
- }
- checkLastTime(companyViewTime, userViewList)
- return
- }
- // GetRaiLastUserViewHistoryByCompanyIds 根据客户id集合map获取权益最后一次阅读时间
- func GetRaiLastUserViewHistoryByCompanyIds(companyIdStr string) (companyViewTime map[int]time.Time, err error) {
- //CygxArticleViewRecord mobile
- companyViewTime = make(map[int]time.Time)
- userViewList, err := models.GetLastCygxArticleViewRecordByCompanyIdsMobile(companyIdStr)
- if err != nil {
- return
- }
- for _, userView := range userViewList {
- companyViewTime[userView.CompanyId] = userView.ViewTime
- }
- //CygxArticleViewRecord email
- userViewList, err = models.GetLastCygxArticleViewRecordByCompanyIdsEmail(companyIdStr)
- if err != nil {
- return
- }
- checkLastTime(companyViewTime, userViewList)
- return
- }
- // checkLastTime 检测最后的时间并重新赋值
- func checkLastTime(companyViewTime map[int]time.Time, userViewList []*models.CompanyLastViewSlice) {
- for _, userView := range userViewList {
- if viewTime, ok := companyViewTime[userView.CompanyId]; ok {
- if userView.ViewTime.After(viewTime) { //如果当前时间晚于 map中的时间,那么重新赋值
- companyViewTime[userView.CompanyId] = userView.ViewTime
- }
- } else { //如果没有数据,那么直接赋值
- companyViewTime[userView.CompanyId] = userView.ViewTime
- }
- }
- return
- }
- // checkMobileOrEmailLastTime 根据用户信息检测最后的时间并重新赋值
- func checkMobileOrEmailLastTime(companyViewTime map[int]time.Time, userViewList []*models.MobileOrEmailLastViewSlice, companyMap map[string]int) {
- for _, userView := range userViewList {
- // 先找到客户id
- companyId, ok := companyMap[userView.Mobile]
- if !ok {
- continue
- }
- // 相同客户id的数据进行比较
- if viewTime, ok := companyViewTime[companyId]; ok {
- if userView.ViewTime.After(viewTime) { //如果当前时间晚于 map中的时间,那么重新赋值
- companyViewTime[companyId] = userView.ViewTime
- }
- } else { //如果没有数据,那么直接赋值
- companyViewTime[companyId] = userView.ViewTime
- }
- }
- return
- }
- // GetFiccCountUserViewHistoryByCompanyIds 根据客户id集合map获取ficc的阅读次数
- func GetFiccCountUserViewHistoryByCompanyIds(companyIdStr string, mobileList, emailList []string, mobileCompanyIdMap, emailCompanyIdMap map[string]int) (companyViewTotal map[int]int, err error) {
- //user_view_record mobile
- companyViewTotal = make(map[int]int)
- userViewList, err := models.GetCountUserViewHistoryByCompanyIdsMobile(companyIdStr)
- if err != nil {
- return
- }
- for _, userView := range userViewList {
- companyViewTotal[userView.CompanyId] = userView.ViewTotal
- }
- userViewList, err = models.GetCountUserViewHistoryByCompanyIdsEmail(companyIdStr)
- if err != nil {
- return
- }
- checkCount(companyViewTotal, userViewList)
- //AdvisoryArticleViewRecord mobile
- userViewList, err = models.GetCountAdvisoryArticleViewRecordByCompanyIdsMobile(companyIdStr)
- if err != nil {
- return
- }
- checkCount(companyViewTotal, userViewList)
- //AdvisoryArticleViewRecord email
- userViewList, err = models.GetCountAdvisoryArticleViewRecordByCompanyIdsEmail(companyIdStr)
- if err != nil {
- return
- }
- checkCount(companyViewTotal, userViewList)
- //ReportViewRecord mobile
- mobileOrEmailViewList, err := models.GetCountReportViewRecordByMobileList(mobileList)
- if err != nil {
- return
- }
- checkMobileOrEmailCount(companyViewTotal, mobileOrEmailViewList, mobileCompanyIdMap)
- //ReportViewRecord email
- mobileOrEmailViewList, err = models.GetCountReportViewRecordByEmailList(emailList)
- if err != nil {
- return
- }
- checkMobileOrEmailCount(companyViewTotal, mobileOrEmailViewList, emailCompanyIdMap)
- //UserViewStatistics mobile
- userViewList, err = models.GetUserViewStatisticsByCompanyIdsMobile(companyIdStr)
- if err != nil {
- return
- }
- checkCount(companyViewTotal, userViewList)
- //UserViewStatistics email
- userViewList, err = models.GetUserViewStatisticsByCompanyIdsEmail(companyIdStr)
- if err != nil {
- return
- }
- checkCount(companyViewTotal, userViewList)
- return
- }
- // GetRaiCountUserViewHistoryByCompanyIds 根据客户id集合map获取权益的阅读次数
- func GetRaiCountUserViewHistoryByCompanyIds(companyIdStr string) (companyViewTotal map[int]int, err error) {
- //CygxArticleViewRecord mobile
- companyViewTotal = make(map[int]int)
- userViewList, err := models.GetCountCygxArticleViewRecordByCompanyIdsMobile(companyIdStr)
- if err != nil {
- return
- }
- for _, userView := range userViewList {
- companyViewTotal[userView.CompanyId] = userView.ViewTotal
- }
- //CygxArticleViewRecord email
- userViewList, err = models.GetCountCygxArticleViewRecordByCompanyIdsEmail(companyIdStr)
- if err != nil {
- return
- }
- checkCount(companyViewTotal, userViewList)
- return
- }
- // GetAllCountUserViewHistoryByCompanyIds 根据客户id集合map获取所有的阅读次数
- //func GetAllCountUserViewHistoryByCompanyIds(companyIdStr string) (companyViewTotal map[int]int, err error) {
- // companyViewTotal = make(map[int]int)
- // companyFiccViewTotal, err := GetFiccCountUserViewHistoryByCompanyIds(companyIdStr)
- // if err != nil {
- // return
- // }
- //
- // companyRaiViewTotal, err := GetRaiCountUserViewHistoryByCompanyIds(companyIdStr)
- // if err != nil {
- // return
- // }
- //
- // companyIdList := strings.Split(companyIdStr, ",")
- //
- // for _, companyIdStr := range companyIdList {
- // companyId, _ := strconv.Atoi(companyIdStr)
- // ficcTotal, ok := companyFiccViewTotal[companyId]
- // if !ok {
- // ficcTotal = 0
- // }
- // raiTotal, ok := companyRaiViewTotal[companyId]
- // if !ok {
- // raiTotal = 0
- // }
- // companyViewTotal[companyId] = ficcTotal + raiTotal
- // }
- // return
- //}
- func checkCount(companyViewTotal map[int]int, userViewList []*models.CompanyViewTotalSlice) {
- for _, userView := range userViewList {
- if viewTotal, ok := companyViewTotal[userView.CompanyId]; ok {
- companyViewTotal[userView.CompanyId] = viewTotal + userView.ViewTotal
- } else { //如果没有数据,那么直接赋值
- companyViewTotal[userView.CompanyId] = userView.ViewTotal
- }
- }
- return
- }
- // checkMobileOrEmailCount 根据手机号或者邮箱进行数据比较
- func checkMobileOrEmailCount(companyViewTotal map[int]int, mobileOrEmailViewList []*models.MobileOrEmailViewTotalSlice, companyMap map[string]int) {
- for _, userView := range mobileOrEmailViewList {
- // 先找到客户id
- companyId, ok := companyMap[userView.Mobile]
- if !ok {
- continue
- }
- // 相同客户id的数据进行比较
- if viewTotal, ok := companyViewTotal[companyId]; ok {
- companyViewTotal[companyId] = viewTotal + userView.ViewTotal
- } else { //如果没有数据,那么直接赋值
- companyViewTotal[companyId] = userView.ViewTotal
- }
- }
- return
- }
- // ModifyCompanyProductLastViewData 修改客户产品的总共阅读次数以及最近阅读时间
- func ModifyCompanyProductLastViewData(companyIdList []int) (err error) {
- defer func() {
- if err != nil {
- go alarm_msg.SendAlarmMsg("修改客户产品的总共阅读次数以及最近阅读时间失败,"+fmt.Sprint("companyIdList:", companyIdList, ";err:", err), 3)
- //go utils.SendEmail("修改客户产品的总共阅读次数以及最近阅读时间失败", fmt.Sprint("companyIdList:", companyIdList, ";err:", err), utils.EmailSendToUsers)
- }
- }()
- wxUserList, err := models.GetWxUserByCompanyIds(companyIdList)
- if err != nil {
- return
- }
- mobileList := make([]string, 0)
- mobileCompanyIdMap := make(map[string]int, 0)
- emailList := make([]string, 0)
- emailCompanyIdMap := make(map[string]int, 0)
- for _, v := range wxUserList {
- if v.Mobile != `` {
- mobileList = append(mobileList, v.Mobile)
- mobileCompanyIdMap[v.Mobile] = v.CompanyId
- }
- if v.Email != `` {
- emailList = append(emailList, v.Email)
- emailCompanyIdMap[v.Email] = v.CompanyId
- }
- }
- // 根据companyId列表获取客户公司的阅读情况
- companyViewRecordList, err := models.GetUserViewHistoryByCompanyIdList(companyIdList)
- if err != nil {
- return
- }
- companyViewRecordMap := make(map[int]*models.CompanyViewRecord)
- for _, v := range companyViewRecordList {
- companyViewRecordMap[v.CompanyId] = v
- }
- for _, companyId := range companyIdList {
- companyViewRecord, ok := companyViewRecordMap[companyId]
- //ficc
- var companyFiccViewTotal, companyRaiViewTotal int
- var companyFiccLastView, companyRaiLastView time.Time
- var companyFiccLastViewStr, companyRaiLastViewStr string
- if ok && companyViewRecord != nil {
- companyFiccViewTotal = companyViewRecord.FiccViewTotal
- companyFiccLastView = companyViewRecord.FiccLastViewTime
- companyRaiViewTotal = companyViewRecord.RaiViewTotal
- companyRaiLastView = companyViewRecord.RaiLastViewTime
- }
- if companyFiccLastView.IsZero() {
- companyFiccLastViewStr = "0000-00-00 00:00:00"
- } else {
- companyFiccLastViewStr = companyFiccLastView.Format(utils.FormatDateTime)
- }
- company.ModifyCompanyProductLastViewData(companyId, 1, companyFiccViewTotal, companyFiccLastViewStr)
- //权益
- if companyRaiLastView.IsZero() {
- companyRaiLastViewStr = "0000-00-00 00:00:00"
- } else {
- companyRaiLastViewStr = companyRaiLastView.Format(utils.FormatDateTime)
- }
- company.ModifyCompanyProductLastViewData(companyId, 2, companyRaiViewTotal, companyRaiLastViewStr)
- }
- return
- }
- // CompanyDeleteBakInfo 删除客户时的备份信息
- type CompanyDeleteBakInfo struct {
- CompanyId int `description:"客户id"`
- CompanyName string `description:"客户名称"`
- CompanyInfo *company.Company `description:"客户主表信息"`
- CompanyProductInfo []*company.CompanyProduct `description:"客户产品信息"`
- CompanyPermissionInfo []*company.CompanyReportPermission `description:"客户产品权限信息"`
- UserSellerRelationInfo []*models.UserSellerRelation `description:"联系人与销售关系信息"`
- UserRecordInfo []*models.UserRecord `description:"联系人关系信息"`
- UserInfo []*models.WxUser `description:"联系人信息"`
- CompanyChartPermissionInfo []*company_user.ChartClassifyPermission `description:"客户图表权限信息"`
- CompanyContract []*company.CompanyContract `description:"客户合同信息"`
- CompanyContractPermission []*company.CompanyContractPermission `description:"客户合同权限信息"`
- OpUserId int `description:"操作人id"`
- OpUserName string `description:"操作人名称"`
- }
- // GetBeforeDeleteCompanyInfo 获取删除客户之前的信息
- func GetBeforeDeleteCompanyInfo(companyId int) (companyProductLists []*company.CompanyProduct, companyReportPermissions []*company.CompanyReportPermission, wxUsers []*models.WxUser, userSellerRelations []*models.UserSellerRelation, companyContracts []*company.CompanyContract, companyContractPermissions []*company.CompanyContractPermission, companyInfo *company.Company, err error) {
- o := orm.NewOrm()
- //删除客户产品
- bakSql := `SELECT * FROM company_product WHERE company_id=? `
- _, err = o.Raw(bakSql, companyId).QueryRows(&companyProductLists)
- if err != nil {
- return
- }
- //删除客户权限
- bakSql = `SELECT * FROM company_report_permission WHERE company_id=? `
- _, err = o.Raw(bakSql, companyId).QueryRows(&companyReportPermissions)
- if err != nil {
- return
- }
- //联系人表
- bakSql = `SELECT * FROM wx_user WHERE company_id=? `
- _, err = o.Raw(bakSql, companyId).QueryRows(&wxUsers)
- if err != nil {
- return
- }
- //联系人 与 销售 关系表
- bakSql = `SELECT * FROM user_seller_relation WHERE company_id=? `
- _, err = o.Raw(bakSql, companyId).QueryRows(&userSellerRelations)
- if err != nil {
- return
- }
- // 合同
- bakSql = `SELECT * FROM company_contract WHERE company_id=? `
- _, err = o.Raw(bakSql, companyId).QueryRows(&companyContracts)
- if err != nil {
- return
- }
- // 合同权限
- bakSql = `SELECT * FROM company_contract_permission WHERE company_id=? `
- _, err = o.Raw(bakSql, companyId).QueryRows(&companyContractPermissions)
- if err != nil {
- return
- }
- // 客户
- bakSql = `SELECT * FROM company WHERE company_id=? `
- err = o.Raw(bakSql, companyId).QueryRow(&companyInfo)
- if err != nil {
- return
- }
- return
- }
- // CheckCompanyReceiveButton 查询领取客户按钮的权限
- func CheckCompanyReceiveButton(adminId int) (receiveEnabled bool, err error) {
- receiveEnabled = true
- receivePermissionInfo, err := company.GetSellerCompanyPermissionByAdminIdType(adminId, 1)
- if err != nil {
- if err.Error() != utils.ErrNoRow() {
- err = errors.New("获取账号权限失败,Err:" + err.Error())
- return
- }
- } else {
- if receivePermissionInfo != nil && receivePermissionInfo.Enabled == 0 {
- receiveEnabled = false
- }
- }
- return
- }
- // AddWxUserOpLog 记录新增用户的日志
- func AddWxUserOpLog(wxUserOpLog company.WxUserOpLog) {
- userSellerRelationList, err := models.GetUserSellerRelationList(wxUserOpLog.UserId)
- if err != nil {
- return
- }
- userSellerRelationInfo, _ := json.Marshal(userSellerRelationList)
- wxUserOpLog.UserSellerInfo = string(userSellerRelationInfo)
- company.AddWxUserOpLog(&wxUserOpLog)
- }
- // FilterReadAndContractAuth 根据已购品种和阅读权限获取筛选条件
- func FilterReadAndContractAuth(chartPermissions, contractPermissions, condition string) (cond string, empty bool, err error) {
- cond = condition
- var queryChart, queryContract bool
- if chartPermissions != "" && chartPermissions != "1" {
- queryChart = true
- }
- if contractPermissions != "" && contractPermissions != "1" {
- queryContract = true
- }
- if !queryChart && !queryContract {
- return
- }
- readIds := make([]int, 0)
- buyIds := make([]int, 0)
- // 阅读权限
- if queryChart {
- {
- // 处理权益的主观客观的筛选条件搜索
- ids := make([]int, 0)
- strIdArr := strings.Split(chartPermissions, ",")
- for _, s := range strIdArr {
- v, _ := strconv.Atoi(s)
- ids = append(ids, v)
- }
- if len(ids) == 0 {
- err = fmt.Errorf("权限ID有误")
- return
- }
- names, e := company.GetPermissionNameByPermissionIds(ids)
- if e != nil {
- err = fmt.Errorf("根据权限ID获取名称失败, Err: %s", e.Error())
- return
- }
- permissionIds, e := company.GetPermissionIdsByPermissionNames(names)
- if e != nil {
- err = fmt.Errorf("根据权限名称获取ID失败, Err: %s", e.Error())
- return
- }
- companyIds, e := company.GetCompanyIdsStrByReportPermissionIds(permissionIds)
- if e != nil {
- err = fmt.Errorf("根据合同权限获取公司ID失败, Err: %s", e.Error())
- return
- }
- readIds = companyIds
- }
- }
- // 已购合同权限
- if queryContract {
- {
- // 处理权益的主观客观的筛选条件搜索
- ids := make([]int, 0)
- strIdArr := strings.Split(contractPermissions, ",")
- for _, s := range strIdArr {
- v, _ := strconv.Atoi(s)
- ids = append(ids, v)
- }
- if len(ids) == 0 {
- err = fmt.Errorf("权限ID有误")
- return
- }
- names, e := company.GetPermissionNameByPermissionIds(ids)
- if e != nil {
- err = fmt.Errorf("根据权限ID获取名称失败, Err: %s", e.Error())
- return
- }
- permissionIds, e := company.GetPermissionIdsByPermissionNames(names)
- if e != nil {
- err = fmt.Errorf("根据权限名称获取ID失败, Err: %s", e.Error())
- return
- }
- companyIds, e := company.GetCompanyIdsStrByContractPermissionIds(permissionIds)
- if e != nil {
- err = fmt.Errorf("根据合同权限获取公司ID失败, Err: %s", e.Error())
- return
- }
- buyIds = companyIds
- // 勾选了已购品种的, 仅筛选正式客户
- cond += ` AND b.status = '正式'`
- }
- }
- queryIds := make([]int, 0)
- queryIdArr := make([]string, 0)
- // 阅读权限和已购品种同时筛选取两者的companyIds交集
- if queryChart && queryContract {
- queryIds = utils.IntersectInt(readIds, buyIds)
- } else if queryChart && !queryContract {
- queryIds = readIds
- } else if !queryChart && queryContract {
- queryIds = buyIds
- }
- if len(queryIds) == 0 {
- empty = true
- return
- }
- for _, q := range queryIds {
- queryIdArr = append(queryIdArr, strconv.Itoa(q))
- }
- cond += ` AND a.company_id IN (` + strings.Join(queryIdArr, ",") + `) `
- return
- }
- // GetShareCompanyPermissionButton 正式客户共享-权限按钮
- func GetShareCompanyPermissionButton(roleTypeCode, statuses string, productId int, item *company.CompanyItem, sysUser *system.Admin) (button *company.ButtonPermission) {
- statuses = strings.Replace(statuses, "(共享)", "", -1)
- statusMap := make(map[int]string)
- statusMap[productId] = statuses
- if strings.Contains(statuses, "/") {
- statusArr := strings.Split(statuses, "/")
- statusMap[1] = statusArr[0]
- statusMap[2] = statusArr[1]
- }
- //roleTypeCode, itemStatus, item.SellerIds, item.GroupIds, item.GroupId, sysUser.GroupId, item.SellerId, sysUser.AdminId, sysUser.Authority, item.ProductId, item.ShareSellerId
- //所属销售map
- sellerIdMap := make(map[int]string)
- sellerIdMap[productId] = item.SellerIds
- if strings.Contains(item.SellerIds, "/") {
- sellerIdSlice := strings.Split(item.SellerIds, "/")
- sellerIdMap[1] = sellerIdSlice[0]
- sellerIdMap[2] = sellerIdSlice[1]
- }
- //分组map
- groupIdMap := make(map[int]string)
- groupIdMap[productId] = item.GroupIds
- if strings.Contains(item.GroupIds, "/") {
- groupIdSlice := strings.Split(item.GroupIds, "/")
- groupIdMap[1] = groupIdSlice[0]
- groupIdMap[2] = groupIdSlice[1]
- }
- // 查看权限均有
- button = new(company.ButtonPermission)
- button.BtnView = true
- // 超管, FICC管理员
- if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
- button.BtnModifySeller = true
- button.BtnRemarkView = true
- button.BtnServiceRecord = true
- }
- //梁春悦、罗礼智的单独展示
- if sysUser.RoleName == "权益服务组长" || sysUser.RoleName == "权益销售组长(外部)" {
- button.BtnModifySeller = true
- }
- if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
- button.BtnModifySeller = false
- }
- status, _ := statusMap[1]
- //if !ok {
- // return
- //}
- // 客户非关闭状态可见沟通记录按钮
- if status != utils.COMPANY_STATUS_CLOSE {
- button.BtnServiceRecord = true
- }
- // 销售
- sellerArr := []string{
- utils.ROLE_TYPE_CODE_FICC_GROUP, utils.ROLE_TYPE_CODE_FICC_TEAM, utils.ROLE_TYPE_CODE_FICC_SELLER,
- utils.ROLE_TYPE_CODE_RAI_GROUP, utils.ROLE_TYPE_CODE_RAI_SELLER, utils.ROLE_TYPE_CODE_RAI_ADMIN,
- }
- if !utils.InArrayByStr(sellerArr, roleTypeCode) {
- return
- }
- if status == utils.COMPANY_STATUS_TRY_OUT {
- button.BtnTurnPositive = true
- button.BtnRemarkEdit = true
- button.BtnRemarkView = true
- button.BtnServiceRecord = true
- }
- if status == utils.COMPANY_STATUS_FORMAL {
- button.BtnUpdate = true
- button.BtnAddAgreement = true
- button.BtnTryOut = true
- button.BtnRemarkEdit = true
- button.BtnRemarkView = true
- button.BtnServiceRecord = true
- }
- companyButton := GetCompanyPermissionButton(roleTypeCode, statuses, item.SellerIds, item.GroupIds, item.GroupId, sysUser.GroupId, item.SellerId, sysUser.AdminId, sysUser.Authority, item.ProductId, -1, item.ShareSellerIds)
- if companyButton.BtnShare == true {
- button.BtnShare = true
- }
- //备注与历史备注修改 CRM15.9.1
- button.BtnRemarkView = companyButton.BtnRemarkView
- if productId == 2 {
- button.BtnRemarkView = false
- button.BtnRemarkViewHistory = true
- }
- if utils.InArrayByStr([]string{utils.ROLE_TYPE_CODE_RAI_ADMIN, utils.ROLE_TYPE_CODE_RAI_SELLER, utils.ROLE_TYPE_CODE_RAI_GROUP}, roleTypeCode) {
- button.BtnServiceRecord = false //王芳,权益销售,权益销售组长,这三种身份看不到这个按钮
- }
- return
- }
- // AddWxUserMoveLog 添加用户移动日志记录
- func AddWxUserMoveLog(wxUser *models.WxUser, adminUser *system.Admin, newCompanyId int) (err error) {
- if wxUser.CompanyId == newCompanyId {
- return
- }
- defer func() {
- if err != nil {
- go alarm_msg.SendAlarmMsg("添加用户移动日志记录失败,AddWxUserMoveLog "+fmt.Sprint("UserId:", wxUser.UserId, ";err:", err), 3)
- }
- }()
- //获取老的客户信息
- companyInfoOld, e := company.GetCompanyById(wxUser.CompanyId)
- if e != nil {
- err = errors.New("GetCompanyById, Old Err: " + e.Error())
- return
- }
- //获取老的客户信息
- companyInfoNew, e := company.GetCompanyById(newCompanyId)
- if e != nil {
- err = errors.New("GetCompanyById, New Err: " + e.Error())
- return
- }
- item := new(company.WxUserMoveLog)
- item.UserId = int(wxUser.UserId)
- item.RealName = wxUser.RealName
- item.Mobile = wxUser.Mobile
- item.Email = wxUser.Email
- item.CompanyId = wxUser.CompanyId
- item.CompanyName = companyInfoOld.CompanyName
- item.CompanyIdMove = companyInfoNew.CompanyId
- item.CompanyNameMove = companyInfoNew.CompanyName
- item.SysUserId = adminUser.AdminId
- item.SysUserRealName = adminUser.RealName
- item.CreateTime = time.Now()
- e = company.AddWxUserMoveLog(item)
- if e != nil {
- err = errors.New("AddWxUserMoveLog, New Err: " + e.Error())
- return
- }
- e = cygx.RemoveCygxUserRemind(int(wxUser.UserId)) //取消个人提醒
- if e != nil {
- err = errors.New("RemoveCygxUserRemind, New Err: " + e.Error())
- return
- }
- return
- }
- // GetWxUserHaveMoveMap 根据手机号,获取用户是否有过移动的记录
- func GetWxUserHaveMoveMap(mobiles []string) (moveMap map[string]bool) {
- lenArr := len(mobiles)
- if lenArr == 0 {
- return
- }
- var err error
- defer func() {
- if err != nil {
- go alarm_msg.SendAlarmMsg("添加用户移动日志记录失败,GetWxUserHaveMoveMap "+fmt.Sprint("mobiles:", mobiles, ";err:", err), 3)
- }
- }()
- listMobileMove, e := company.GetWxUserMoveLogListmByMobiles(mobiles)
- if e != nil {
- err = errors.New("GetWxUserMoveLogListmByMobiles Err: " + e.Error())
- return
- }
- moveMap = make(map[string]bool)
- for _, v := range listMobileMove {
- moveMap[v.Mobile] = true
- }
- return
- }
|