12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582 |
- 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/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) {
- 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)
- 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
- }
|