12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798 |
- package controllers
- import (
- "fmt"
- "github.com/rdlucklib/rdluck_tools/paging"
- "github.com/tealeg/xlsx"
- "hongze/hz_crm_api/models"
- "hongze/hz_crm_api/models/company"
- "hongze/hz_crm_api/models/company_todo"
- "hongze/hz_crm_api/services"
- cygxService "hongze/hz_crm_api/services/cygx"
- "hongze/hz_crm_api/utils"
- "os"
- "path/filepath"
- "strconv"
- "strings"
- "time"
- )
- // FullCompanyController 全量客户管理
- type FullCompanyController struct {
- BaseAuthController
- }
- // List
- // @Title 客户列表
- // @Description 客户列表接口
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param Status query string true "状态:'试用','永续','冻结','流失','正式'"
- // @Param CompanyType query string true "客户类型:传空字符串或者不传为全部,'ficc','权益'"
- // @Param IndustryId query int true "行业id,0为全部"
- // @Param AdminId query string true "销售id,多个用英文逗号隔开,空字符串为全部"
- // @Param ChartPermissionIds query string false "阅读权限品种ID,多个用英文逗号分开,空字符串为全部"
- // @Param ContractPermissionIds query string false "已购品种ID,多个用英文逗号分开,空字符串为全部"
- // @Param StartDate query string true "开始时间"
- // @Param EndDate query string true "结束时间"
- // @Param CreateStartDate query string true "创建开始时间"
- // @Param CreateEndDate query string true "创建结束时间"
- // @Param KeyWord query string true "搜索关键词"
- // @Param Address query string true "地址 , 多个用英文逗号分开 "
- // @Param Province query string true "省 , 多个用英文逗号分开 "
- // @Param City query string true "市 , 多个用英文逗号分开 "
- // @Param PackageType query int true "套餐类型,0:无,1:大套餐,2:小套餐"
- // @Param TodoStatus query string true "任务处理状态;枚举值:'无任务','未完成','已完成'"
- // @Param SortParam query string false "排序字段参数,用来排序的字段, 枚举值:'viewTotal':总阅读次数 、 'viewTime':阅读时间 、 'roadShowTotal':累计路演次数 、`expireDay:到期时间` 、 `createTime:创建时间` 、 'formalTime': 转正时间 、 'freezeTime':冻结时间 、'lossTime':流失时间 、'tryStage':试用标签 、'deadline':距离未完成的任务的截止日期的天数、'tryOutDay':试用天数"
- // @Param SortType query string true "如何排序,是正序还是倒序,枚举值:`asc 正序`,`desc 倒叙`"
- // @Param SortByTodo query bool true "是否根据待办排序,true或false"
- // @Param TryStage query int false "试用客户子标签:0全部、1未分类、2 推进、3 跟踪、4 预备"
- // @Success 200 {object} company.CompanyListResp
- // @router /full/list [get]
- func (this *FullCompanyController) List() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- roleTypeCode := sysUser.RoleTypeCode
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- status := this.GetString("Status")
- companyType := this.GetString("CompanyType")
- industryId, _ := this.GetInt("IndustryId")
- adminId := this.GetString("AdminId")
- chartPermissionIds := this.GetString("ChartPermissionIds")
- contractPermissionIds := this.GetString("ContractPermissionIds")
- startDate := this.GetString("StartDate")
- endDate := this.GetString("EndDate")
- createStartDate := this.GetString("CreateStartDate")
- createEndDate := this.GetString("CreateEndDate")
- keyWord := this.GetString("KeyWord")
- address := this.GetString("Address")
- province := this.GetString("Province")
- city := this.GetString("City")
- keyWord = strings.Trim(keyWord, " ")
- keyWord = strings.Replace(keyWord, "'", "", -1)
- todoStatus := this.GetString("TodoStatus") //任务状态
- tryStage, _ := this.GetInt("TryStage") //试用客户标签
- // 套餐类型
- packageType, _ := this.GetInt("PackageType")
- //排序参数
- sortParam := this.GetString("SortParam")
- sortType := this.GetString("SortType")
- sortByTodo, _ := this.GetBool("SortByTodo")
- var total int
- page := paging.GetPaging(currentIndex, pageSize, total)
- resp := new(company.CompanyListResp)
- statusItems := make([]*company.CompanyStatus, 0)
- var statusArr = [...]string{"全部", "试用", "正式", "冻结", "流失", "关闭", "永续"}
- //var statusArr = [...]string{"全部", "试用-活跃", "试用-非活跃", "正式", "冻结", "流失", "永续"}
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = paging.StartIndex(currentIndex, pageSize)
- var condition string
- var pars []interface{}
- //流失
- var lossCondition string
- var lossPars []interface{}
- //状态分类查询条件
- var permissionCondition string
- var permissionPars []interface{}
- // 角色为销售主管时, 可见所有, 其余角色依旧走原来的判断
- if companyType != "" && sysUser.RoleName != utils.ROLE_NAME_FICC_DIRECTOR {
- condition += ` AND b.product_name=? `
- pars = append(pars, companyType)
- }
- if industryId > 0 {
- condition += ` AND b.industry_id=? `
- pars = append(pars, industryId)
- }
- if adminId != "" {
- condition += ` AND b.seller_id IN (` + adminId + `) `
- }
- if startDate != "" {
- condition += ` AND b.start_date>=? `
- pars = append(pars, startDate)
- }
- if endDate != "" {
- condition += ` AND b.end_date<=? `
- pars = append(pars, endDate)
- }
- if createStartDate != "" {
- condition += ` AND a.created_time>=? `
- pars = append(pars, createStartDate)
- }
- if createEndDate != "" {
- condition += ` AND a.created_time<=? `
- pars = append(pars, createEndDate)
- }
- if address != "" {
- var addressSql string
- slice := strings.Split(address, ",")
- for _, v := range slice {
- addressSql += "'" + v + "'" + ","
- }
- addressSql = strings.TrimRight(addressSql, ",")
- condition += ` AND a.address IN (` + addressSql + `) `
- }
- if province != "" {
- var provinceSql string
- slice := strings.Split(province, ",")
- for _, v := range slice {
- provinceSql += "'" + v + "'" + ","
- }
- provinceSql = strings.TrimRight(provinceSql, ",")
- condition += ` AND a.province IN (` + provinceSql + `) `
- }
- if city != "" {
- var citySql string
- slice := strings.Split(city, ",")
- for _, v := range slice {
- citySql += "'" + v + "'" + ","
- }
- citySql = strings.TrimRight(citySql, ",")
- condition += ` AND a.city IN (` + citySql + `) `
- }
- if keyWord != "" {
- companyIdStr, err := company.GetCompanyIdByKeyWord(keyWord)
- if err != nil {
- br.Msg = "获取客户信息失败"
- br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
- return
- }
- if companyIdStr != "" {
- condition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.credit_code LIKE '%` + keyWord + `%' OR a.company_id IN(` + companyIdStr + `)) `
- } else {
- condition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.credit_code LIKE '%` + keyWord + `%' ) `
- }
- }
- //任务状态
- if todoStatus != "" {
- condition += ` AND b.todo_status =? `
- pars = append(pars, todoStatus)
- }
- // 阅读权限/已购品种筛选
- cond, emp, e := services.FilterReadAndContractAuth(chartPermissionIds, contractPermissionIds, condition)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "FilterReadAndContractAuth err: " + e.Error()
- return
- }
- if emp {
- for _, v := range statusArr {
- statusCount := new(company.CompanyStatus)
- if v == "全部" {
- statusCount.Status = "全部"
- statusCount.Count = 0
- } else {
- statusCount.Status = v
- statusCount.Count = 0
- }
- statusItems = append(statusItems, statusCount)
- }
- items := make([]*company.CompanyListItem, 0)
- resp.List = items
- resp.Paging = page
- resp.StatusCount = statusItems
- br.Msg = "获取成功"
- br.Ret = 200
- br.Data = resp
- return
- }
- condition = cond
- //套餐类型
- if packageType > 0 {
- condition += ` AND b.package_type=? `
- pars = append(pars, packageType)
- }
- lossCondition = condition
- lossPars = pars
- permissionCondition = condition
- permissionPars = pars
- //流失客户统计
- lossCondition += ` AND status='流失' `
- productId := services.GetProductId(roleTypeCode)
- //权限控制
- {
- //如果不是超级管理员或者财务或者销售主管
- if roleTypeCode != utils.ROLE_TYPE_CODE_ADMIN && roleTypeCode != utils.ROLE_TYPE_CODE_FINANCE && sysUser.RoleName != utils.ROLE_NAME_FICC_DIRECTOR {
- //如果是部门管理员
- if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
- condition += ` AND b.product_id=? `
- pars = append(pars, productId)
- lossCondition += ` AND b.product_id=? `
- lossPars = append(lossPars, productId)
- permissionCondition += ` AND b.product_id=? `
- permissionPars = append(permissionPars, productId)
- //}
- //else if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_DIRECTOR {
- // condition += ` AND b.product_id=? `
- // pars = append(pars, productId)
- //
- // lossCondition += ` AND b.product_id=? `
- // lossPars = append(lossPars, productId)
- //
- // permissionCondition += ` AND b.product_id=? `
- // permissionPars = append(permissionPars, productId)
- } else {
- condition += ` AND b.product_id=? `
- pars = append(pars, productId)
- lossCondition += ` AND b.product_id=? `
- lossPars = append(lossPars, productId)
- permissionCondition += ` AND b.product_id=? `
- permissionPars = append(permissionPars, productId)
- if status == "全部" {
- ////如果是筛选了流失客户状态
- if sysUser.Authority <= 0 {
- condition += ` AND (b.seller_id=? OR status='流失') `
- pars = append(pars, sysUser.AdminId)
- permissionCondition += ` AND b.seller_id=? `
- permissionPars = append(permissionPars, sysUser.AdminId)
- } else {
- if sysUser.Authority == 1 {
- condition += ` AND (b.department_id=? OR status='流失')`
- pars = append(pars, sysUser.DepartmentId)
- permissionCondition += ` AND b.department_id=? `
- permissionPars = append(permissionPars, sysUser.DepartmentId)
- }
- if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
- if status != utils.COMPANY_STATUS_LOSE {
- condition += ` AND (b.group_id=? OR status='流失') `
- pars = append(pars, sysUser.GroupId)
- }
- permissionCondition += ` AND b.group_id=? `
- permissionPars = append(permissionPars, sysUser.GroupId)
- }
- if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
- pid, err := company.GetParentIdFromGroup(sysUser.GroupId)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "查询父级id异常" + err.Error()
- return
- }
- var ids []*string
- if pid != nil {
- if *pid != 0 {
- //销售主管放在三级列表中
- ids, err = company.GetGroupIdsByParentId(*pid)
- if err != nil {
- fmt.Println(err.Error())
- }
- } else {
- //销售主管放在二级列表中
- ids, err = company.GetGroupIdsByParentId(sysUser.GroupId)
- if err != nil {
- fmt.Println(err.Error())
- }
- }
- }
- var idSlice []string
- var sid string
- for _, id := range ids {
- idSlice = append(idSlice, *id)
- }
- //加入父级groupId
- if *pid > 0 {
- idSlice = append(idSlice, strconv.Itoa(*pid))
- } else {
- idSlice = append(idSlice, strconv.Itoa(sysUser.GroupId))
- }
- sid = strings.Join(idSlice, ",")
- if len(sid) > 0 {
- if status != utils.COMPANY_STATUS_LOSE {
- condition += ` AND (b.group_id IN (` + sid + `) OR status='流失') `
- //pars = append(pars, sysUser.GroupId)
- }
- permissionCondition += ` AND b.group_id IN (` + sid + `) `
- } else {
- if status != utils.COMPANY_STATUS_LOSE {
- condition += ` AND (b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) OR status='流失') `
- //pars = append(pars, sysUser.GroupId)
- }
- permissionCondition += ` AND b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) `
- }
- //permissionPars = append(permissionPars, sysUser.GroupId)
- }
- if sysUser.Authority == 4 {
- //pid, err := company.GetParentIdFromGroup(sysUser.GroupId)
- //if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "查询父级id异常" + err.Error()
- // return
- //}
- //ids,err := company.GetGroupIdsByParentId(*pid)
- //if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "查询父级id异常" + err.Error()
- // return
- //}
- //var idSlice []string
- //var sid string
- //for _, id := range ids {
- // idSlice = append(idSlice, *id)
- //}
- //sid = strings.Join(idSlice,",")
- if status != utils.COMPANY_STATUS_LOSE {
- condition += ` AND (b.group_id =? OR status='流失') `
- pars = append(pars, sysUser.GroupId)
- }
- permissionCondition += ` AND b.group_id=? `
- permissionPars = append(permissionPars, sysUser.GroupId)
- }
- }
- } else {
- //如果没有筛选了流失客户状态,那么需要加客户归属条件加入到查询中去
- if sysUser.Authority <= 0 {
- if status != utils.COMPANY_STATUS_LOSE {
- condition += ` AND b.seller_id=? `
- pars = append(pars, sysUser.AdminId)
- }
- permissionCondition += ` AND b.seller_id=? `
- permissionPars = append(permissionPars, sysUser.AdminId)
- } else {
- if sysUser.Authority == 1 {
- if status != utils.COMPANY_STATUS_LOSE {
- condition += ` AND b.department_id=?`
- pars = append(pars, sysUser.DepartmentId)
- }
- permissionCondition += ` AND b.department_id=? `
- permissionPars = append(permissionPars, sysUser.DepartmentId)
- }
- if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
- if status != utils.COMPANY_STATUS_LOSE {
- condition += ` AND b.group_id=? `
- pars = append(pars, sysUser.GroupId)
- }
- permissionCondition += ` AND b.group_id=? `
- permissionPars = append(permissionPars, sysUser.GroupId)
- }
- if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
- pid, err := company.GetParentIdFromGroup(sysUser.GroupId)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "查询父级id异常" + err.Error()
- return
- }
- var ids []*string
- if pid != nil {
- if *pid != 0 {
- //销售主管放在三级列表中
- ids, err = company.GetGroupIdsByParentId(*pid)
- if err != nil {
- fmt.Println(err.Error())
- }
- } else {
- //销售主管放在二级列表中
- ids, err = company.GetGroupIdsByParentId(sysUser.GroupId)
- if err != nil {
- fmt.Println(err.Error())
- }
- }
- }
- var idSlice []string
- var sid string
- for _, id := range ids {
- idSlice = append(idSlice, *id)
- }
- //加入父级groupId
- if *pid > 0 {
- idSlice = append(idSlice, strconv.Itoa(*pid))
- } else {
- idSlice = append(idSlice, strconv.Itoa(sysUser.GroupId))
- }
- sid = strings.Join(idSlice, ",")
- if len(sid) > 0 {
- if status != utils.COMPANY_STATUS_LOSE {
- condition += ` AND (b.group_id IN (` + sid + `) OR status='流失') `
- //pars = append(pars, sysUser.GroupId)
- }
- permissionCondition += ` AND b.group_id IN (` + sid + `) `
- } else {
- if status != utils.COMPANY_STATUS_LOSE {
- condition += ` AND (b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) OR status='流失') `
- //pars = append(pars, sysUser.GroupId)
- }
- permissionCondition += ` AND b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) `
- }
- }
- if sysUser.Authority == 4 {
- if status != utils.COMPANY_STATUS_LOSE {
- condition += ` AND b.group_id =? `
- pars = append(pars, sysUser.GroupId)
- }
- permissionCondition += ` AND b.group_id=? `
- permissionPars = append(permissionPars, sysUser.GroupId)
- }
- }
- }
- }
- }
- }
- //状态控制
- if status != "" && status != "全部" {
- //switch status {
- //case "试用-活跃":
- // condition += ` AND b.status="试用" and b.view_total>= ? `
- // pars = append(pars, statistic_report.ActiveViewNum)
- //case "试用-非活跃":
- // condition += ` AND b.status="试用" and b.view_total < ? `
- // pars = append(pars, statistic_report.ActiveViewNum)
- //default:
- // condition += ` AND b.status=? `
- // pars = append(pars, status)
- //}
- condition += ` AND b.status=? `
- pars = append(pars, status)
- // 试用客户标签
- if status == "试用" && tryStage > 0 {
- condition += ` AND b.try_stage=? `
- pars = append(pars, tryStage)
- }
- }
- total, err := company.GetCompanyListCount(condition, pars)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据总数失败,Err:" + err.Error()
- return
- }
- //
- sortStr := ``
- if !sortByTodo {
- if sortParam != "" && sortType != "" {
- if sortParam == "expireDay" {
- if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
- if sortType == "asc" {
- sortStr = " ORDER BY min_end_date"
- } else {
- sortStr = " ORDER BY max_end_date"
- }
- } else {
- sortStr = " ORDER BY b.end_date "
- }
- } else if sortParam == "createTime" {
- sortStr = " ORDER BY a.created_time "
- } else if sortParam == "viewTotal" {
- if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
- sortStr = " ORDER BY all_view_total"
- } else {
- sortStr = " ORDER BY b.view_total "
- }
- } else if sortParam == "viewTime" {
- if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
- if sortType == "asc" {
- sortStr = " ORDER BY min_last_view_time"
- } else {
- sortStr = " ORDER BY max_last_view_time"
- }
- } else {
- sortStr = " ORDER BY b.last_view_time "
- }
- } else if sortParam == "roadShowTotal" {
- sortStr = " ORDER BY b.road_show_total "
- } else if sortParam == "formalTime" {
- sortStr = " ORDER BY b.formal_time "
- } else if sortParam == "freezeTime" {
- sortStr = " ORDER BY b.freeze_time "
- } else if sortParam == "lossTime" {
- sortStr = " ORDER BY b.loss_time "
- } else if sortParam == "todoCreateTime" {
- sortStr = " ORDER BY b.todo_create_time "
- } else if sortParam == "todoApproveTime" {
- sortStr = " ORDER BY b.todo_approve_time "
- } else if sortParam == "tryStage" && status == "试用" {
- if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
- sortStr = " ORDER BY sort_try_stage asc, all_view_total desc, a.created_time desc"
- } else {
- sortStr = " ORDER BY sort_try_stage asc, b.view_total desc, a.created_time desc"
- }
- } else if sortParam == "deadline" {
- if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
- sortStr = " ORDER BY sort_todo_end_time asc, all_view_total desc, a.created_time desc"
- } else {
- sortStr = " ORDER BY sort_todo_end_time asc, b.view_total desc, a.created_time desc"
- }
- } else if sortParam == "tryOutDay" {
- if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
- sortStr = " ORDER BY all_try_out_day_total "
- } else {
- sortStr = " ORDER BY b.try_out_day_total "
- }
- } else {
- br.Msg = "获取失败"
- br.ErrMsg = "排序字段传入数据异常:" + sortParam
- return
- }
- if sortParam != "tryStage" && sortParam != "deadline" {
- if sortType == "asc" {
- sortStr += " ASC "
- } else if sortType == "desc" {
- sortStr += " DESC "
- } else {
- br.Msg = "获取失败"
- br.ErrMsg = "排序类型传入数据异常:" + sortType
- return
- }
- }
- } else {
- //2、客户列表选择“全部”时,支持按照“状态和阅读数”对“全部”分类下所有客户列表进行升降序排列;选择“正式”时按照“转正时间”、选择“冻结”时按照“冻结时间”、选择“流失”时按照“流失时间”、选择“永续”时按照“创建时间”;
- if status == "全部" {
- if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
- sortStr = " ORDER BY sort_status asc, all_view_total desc, a.created_time "
- } else {
- sortStr = " ORDER BY sort_status asc, b.view_total desc, a.created_time "
- }
- } else if status == "永续" {
- sortStr = " ORDER BY a.created_time "
- } else if status == "正式" {
- // 正式客户默认按照周阅读活跃ASC, 同为不活跃则按照转正时间DESC
- sortStr = " ORDER BY week_view_active ASC, b.formal_time "
- //sortStr = " ORDER BY b.formal_time "
- } else if status == "冻结" {
- sortStr = " ORDER BY b.freeze_time "
- } else if status == "流失" {
- sortStr = " ORDER BY b.loss_time "
- } else if status == "试用" {
- if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
- sortStr = " ORDER BY all_view_total desc, a.created_time "
- } else {
- sortStr = " ORDER BY b.view_total desc, a.created_time "
- }
- } else if status == utils.COMPANY_STATUS_CLOSE {
- // 关闭客户按照关闭时间DESC
- sortStr = " ORDER BY b.close_time "
- }
- sortStr += " DESC "
- }
- } else {
- sortStr = " ORDER BY FIELD (todo_status,'未完成','已完成','无任务'), todo_modify_time DESC "
- }
- //任务状态
- if todoStatus != "" {
- //排序,筛选出的未完成、已完成客户列表排序分别按照 最近一个任务的创建时间、最近一个任务的审核时间排序;
- switch todoStatus {
- case "未完成":
- if sortStr != "" {
- sortStr += " ,b.todo_create_time desc "
- } else {
- sortStr = " ORDER BY b.todo_create_time desc "
- }
- case "已完成":
- if sortStr != "" {
- sortStr += " ,b.todo_approve_time desc "
- } else {
- sortStr = " ORDER BY b.todo_approve_time desc "
- }
- }
- }
- list, err := company.GetCompanyList(condition, status, sortStr, pars, startSize, pageSize)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- //企业用户数组切片
- companyIdSlice := make([]string, 0)
- companyIds := make([]int, 0)
- for _, v := range list {
- companyIdSlice = append(companyIdSlice, strconv.Itoa(v.CompanyId))
- companyIds = append(companyIds, v.CompanyId)
- }
- //企业用户产品开通数
- companyIdStr := strings.Join(companyIdSlice, ",")
- companyProductTotalList, _ := company.GetCountProductByCompanyIds(companyIdStr)
- companyProductTotalMap := make(map[int]*company.CompanyProductTotalSlice)
- for _, companyProductTotal := range companyProductTotalList {
- companyProductTotalMap[companyProductTotal.CompanyId] = companyProductTotal
- }
- lenList := len(list)
- //companyFiccViewTimeMap := make(map[int]time.Time)
- //companyRaiViewTimeMap := make(map[int]time.Time)
- //companyFiccViewTotal := make(map[int]int)
- //companyRaiViewTotal := make(map[int]int)
- //获取最近阅读时间 和 累计阅读次数
- //if lenList > 0 {
- // //ficc 或者 全品种
- // if productId == 1 || productId == 0 {
- // companyFiccViewTimeMap, err = services.GetFiccLastUserViewHistoryByCompanyIds(companyIdStr)
- // if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取数据失败,Err:" + err.Error()
- // return
- // }
- // }
- //
- // if productId == 2 || productId == 0 {
- // companyRaiViewTimeMap, err = services.GetRaiLastUserViewHistoryByCompanyIds(companyIdStr)
- // if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取数据失败,Err:" + err.Error()
- // return
- // }
- // }
- //
- // companyFiccViewTotal, err = services.GetFiccCountUserViewHistoryByCompanyIds(companyIdStr)
- // if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取ficc阅读数据失败,Err:" + err.Error()
- // return
- // }
- // companyRaiViewTotal, err = services.GetRaiCountUserViewHistoryByCompanyIds(companyIdStr)
- // if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取权益阅读数据失败,Err:" + err.Error()
- // return
- // }
- //}
- // 客户产品详细信息
- companyProductMap := make(map[string]*company.CompanyProduct)
- var companyProductCondition string
- var companyProductPars []interface{}
- switch companyType {
- case "ficc":
- companyProductCondition += ` AND product_id=? `
- companyProductPars = append(companyProductPars, 1)
- case "权益":
- companyProductCondition += ` AND product_id=? `
- companyProductPars = append(companyProductPars, 2)
- default:
- }
- companyProductList, err := company.GetCompanyProductsByCompanyIds(companyIdStr, companyProductCondition, companyProductPars)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取客户产品数据失败,Err:" + err.Error()
- return
- }
- for _, companyProduct := range companyProductList {
- key := fmt.Sprint(companyProduct.CompanyId, "_", companyProduct.ProductId)
- companyProductMap[key] = companyProduct
- }
- //任务待办
- companyTodoMap := make(map[string]*company_todo.CompanyTodo)
- {
- var companyTodoCondition string
- var companyTodoPars []interface{}
- switch companyType {
- case "ficc":
- companyTodoCondition += ` AND product_id=? `
- companyTodoPars = append(companyTodoPars, 1)
- case "权益":
- companyTodoCondition += ` AND product_id=? `
- companyTodoPars = append(companyTodoPars, 2)
- default:
- }
- companyTodoList, err := company_todo.GetDoingCompanyTodoByCompanyIds(companyIdStr, companyTodoCondition, companyTodoPars)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取客户产品数据失败,Err:" + err.Error()
- return
- }
- for _, companyTodo := range companyTodoList {
- key := fmt.Sprint(companyTodo.CompanyId)
- companyTodoMap[key] = companyTodo
- }
- }
- // 查询是否有服务记录
- btnServiceRecordMap := make(map[int]bool)
- if len(companyIds) > 0 {
- serRecOB := new(company.CompanyServiceRecord)
- serRecCond := ` AND company_id IN (` + utils.GetOrmInReplace(len(companyIds)) + `) AND company_type = ? `
- serRecPars := make([]interface{}, 0)
- serRecPars = append(serRecPars, companyIds, 2)
- serRecs, e := serRecOB.GetItemsByCondition(serRecCond, serRecPars, []string{"company_service_record_id", "company_id"}, "")
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取客户服务记录失败, Err: " + e.Error()
- return
- }
- for _, s := range serRecs {
- btnServiceRecordMap[s.CompanyId] = true
- }
- }
- // 查询当前销售是否有领取客户的权限
- receiveEnabled, _ := services.CheckCompanyReceiveButton(sysUser.AdminId)
- for i := 0; i < lenList; i++ {
- item := list[i]
- //校验该客户是否存在多个产品,如果是,那么代表是共享客户
- if companyProductTotal, ok := companyProductTotalMap[int(item.CompanyId)]; ok {
- if companyProductTotal.Total > 1 {
- list[i].IsShared = true
- }
- }
- var expireDay string
- itemStatus := item.Status
- if itemStatus != "" {
- if !strings.Contains(item.Status, "/") {
- if itemStatus == utils.COMPANY_STATUS_FOREVER { //永续
- expireDay = "-"
- } else if itemStatus == utils.COMPANY_STATUS_TRY_OUT || itemStatus == utils.COMPANY_STATUS_FORMAL { //试用/正式
- if item.StartDate != "" && item.EndDate != "" {
- endDateTime, _ := time.Parse(utils.FormatDate, item.EndDate)
- endDateTime = endDateTime.AddDate(0, 0, 1)
- sub := endDateTime.Sub(time.Now())
- if sub < 0 {
- sub = 0
- }
- expireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
- } else {
- expireDay = "-"
- }
- } else if itemStatus == utils.COMPANY_STATUS_LOSE {
- expireDay = "-"
- } else if itemStatus == utils.COMPANY_STATUS_FREEZE {
- if item.StartDate != "" && item.EndDate != "" {
- endDateTime, _ := time.Parse(utils.FormatDate, item.EndDate)
- endDateTime = endDateTime.AddDate(0, 0, 0)
- sub := endDateTime.Sub(time.Now())
- if sub < 0 {
- sub = 0
- }
- expireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
- } else {
- expireDay = "-"
- }
- } else {
- expireDay = "-"
- }
- } else {
- tmpStatusArr := strings.Split(item.Status, "/")
- ficcStatus := tmpStatusArr[0]
- raiStatus := tmpStatusArr[1]
- var ficcEndDate, tryEndDate string
- var ficcExpireDay, tryExpireDay string
- if item.EndDate != "" {
- endDateArr := strings.Split(item.EndDate, "/")
- if len(endDateArr) == 1 {
- ficcEndDate = endDateArr[0]
- } else if len(endDateArr) > 1 {
- ficcEndDate = endDateArr[0]
- tryEndDate = endDateArr[1]
- }
- if ficcStatus == utils.COMPANY_STATUS_FOREVER { //永续
- ficcExpireDay = "-"
- } else if ficcStatus == utils.COMPANY_STATUS_TRY_OUT || ficcStatus == utils.COMPANY_STATUS_FORMAL { //试用/正式
- if ficcEndDate != "" {
- endDateTime, _ := time.Parse(utils.FormatDate, ficcEndDate)
- endDateTime = endDateTime.AddDate(0, 0, 1)
- sub := endDateTime.Sub(time.Now())
- if sub < 0 {
- sub = 0
- }
- ficcExpireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
- } else {
- ficcExpireDay = "-"
- }
- } else if ficcStatus == utils.COMPANY_STATUS_LOSE { //流失
- ficcExpireDay = "-"
- } else if ficcStatus == utils.COMPANY_STATUS_FREEZE { //冻结
- if item.StartDate != "" && item.EndDate != "" {
- endDateTime, _ := time.Parse(utils.FormatDate, ficcEndDate)
- endDateTime = endDateTime.AddDate(0, 0, 0)
- sub := endDateTime.Sub(time.Now())
- if sub < 0 {
- sub = 0
- }
- ficcExpireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
- } else {
- ficcExpireDay = "-"
- }
- } else {
- ficcExpireDay = "-"
- }
- if raiStatus == utils.COMPANY_STATUS_FOREVER { //永续
- tryExpireDay = "-"
- } else if raiStatus == utils.COMPANY_STATUS_TRY_OUT || raiStatus == utils.COMPANY_STATUS_FORMAL { //试用/正式
- if tryEndDate != "" {
- endDateTime, _ := time.Parse(utils.FormatDate, tryEndDate)
- endDateTime = endDateTime.AddDate(0, 0, 1)
- sub := endDateTime.Sub(time.Now())
- if sub < 0 {
- sub = 0
- }
- tryExpireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
- } else {
- tryExpireDay = "-"
- }
- } else if raiStatus == utils.COMPANY_STATUS_LOSE { //流失
- tryExpireDay = "-"
- } else if raiStatus == utils.COMPANY_STATUS_FREEZE { //冻结
- if item.StartDate != "" && item.EndDate != "" {
- endDateTime, _ := time.Parse(utils.FormatDate, tryEndDate)
- endDateTime = endDateTime.AddDate(0, 0, 0)
- sub := endDateTime.Sub(time.Now())
- if sub < 0 {
- sub = 0
- }
- tryExpireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
- } else {
- tryExpireDay = "-"
- }
- } else {
- tryExpireDay = "-"
- }
- }
- expireDay = ficcExpireDay + "/" + tryExpireDay
- }
- }
- list[i].ExpireDay = expireDay
- // 按钮控制, 仅显示查看权限
- btnItem := new(company.ButtonPermission)
- btnItem.BtnView = true
- list[i].BtnItem = btnItem
- //按钮显示控制
- //btnItem := new(company.ButtonPermission)
- //if item.CompanyId != 1 {
- // *btnItem = services.GetCompanyPermissionButton(roleTypeCode, itemStatus, item.GroupIds, item.GroupIds, item.GroupId, sysUser.GroupId, item.SellerId, sysUser.AdminId, sysUser.Authority, item.ProductId, item.ShareSellerId)
- // //根据销售"领取客户"的权限对部分按钮做限制
- // btnItem = services.GetCompanyPermissionButtonByReceiveEnabled(btnItem, receiveEnabled)
- //}
- //if list[i].IsShare == 1 && btnItem.BtnModifySeller == true {
- // //如果已经是共享客户了,取消共享按钮全都显示,和修改销售权限一样
- // btnItem.BtnShare = true
- //}
- //list[i].BtnItem = btnItem
- if item.FreezeStartDate != "" && item.FreezeEndDate != "" && item.Status == utils.COMPANY_STATUS_FREEZE {
- freezeEndDate, _ := time.Parse(utils.FormatDate, item.FreezeEndDate)
- if time.Now().Before(freezeEndDate) {
- expireDays := freezeEndDate.Sub(time.Now()).Hours() / 24
- list[i].FreezeExpireDays = int(expireDays) + 1
- }
- }
- //btnItem.BtnServiceRecord = btnServiceRecordMap[list[i].CompanyId]
- ficcKey := fmt.Sprint(item.CompanyId, "_", 1)
- //ficc
- if tmpCompanyProduct, ok := companyProductMap[ficcKey]; ok {
- //套餐类型
- item.FiccPackageType = tmpCompanyProduct.PackageType
- //总试用天数
- item.FiccTryOutDay = tmpCompanyProduct.TryOutDayTotal
- //总阅读次数
- item.FiccView = tmpCompanyProduct.ViewTotal
- if !tmpCompanyProduct.LastViewTime.IsZero() {
- //最近一次阅读时间
- item.FiccLastViewTime = tmpCompanyProduct.LastViewTime.Format(utils.FormatDateTime)
- }
- }
- //权益
- raiKey := fmt.Sprint(item.CompanyId, "_", 2)
- if tmpCompanyProduct, ok := companyProductMap[raiKey]; ok {
- //总阅读次数
- item.RaiView = tmpCompanyProduct.ViewTotal
- //总试用天数
- item.RaiTryOutDay = tmpCompanyProduct.TryOutDayTotal
- if !tmpCompanyProduct.LastViewTime.IsZero() {
- //最近一次阅读时间
- item.RaiLastViewTime = tmpCompanyProduct.LastViewTime.Format(utils.FormatDateTime)
- }
- }
- // 试用客户子标签
- if strings.Contains(item.Status, "试用") {
- statusSlice := strings.Split(item.Status, "/")
- stageItemSlice := strings.Split(item.TryStageStr, "/")
- productIdSlice := strings.Split(item.ProductIds, "/")
- for sk, sv := range statusSlice {
- if sv != "试用" {
- continue
- }
- tryItem := new(company.TryStageSliceItem)
- if len(productIdSlice) < (sk+1) || len(stageItemSlice) < (sk+1) {
- continue
- }
- key := fmt.Sprint(item.CompanyId, "_", productIdSlice[sk])
- if pro, ok := companyProductMap[key]; ok {
- tryItem.ProductId, _ = strconv.Atoi(productIdSlice[sk])
- if pro.SellerId == sysUser.AdminId { //产品销售ID和登录ID相等
- tryItem.HasPermission = true
- }
- tryItem.TryStage, _ = strconv.Atoi(stageItemSlice[sk])
- list[i].TryStageSlice = append(list[i].TryStageSlice, tryItem)
- }
- }
- }
- // To-Do任务状态为未完成的对应任务的截止日期-当前日期;
- if strings.Contains(item.TodoStatuss, "未完成") {
- if strings.Contains(item.TodoEndTimeStr, "/") {
- edtSlice := strings.Split(item.TodoEndTimeStr, "/")
- item.TodoEndTime, _ = time.ParseInLocation(utils.FormatDateTime, edtSlice[0], time.Local)
- } else {
- item.TodoEndTime, _ = time.ParseInLocation(utils.FormatDateTime, item.TodoEndTimeStr, time.Local)
- }
- tmpEndTime := item.TodoEndTime.Format(utils.FormatDate)
- if tmpEndTime == "0001-01-01" {
- tmpEndTime = ""
- }
- if tmpEndTime != "" {
- dlTime1 := time.Date(time.Now().Year(), time.Now().Month(), time.Now().Day(), 0, 0, 0, 0, time.Local)
- dlTime2 := time.Date(item.TodoEndTime.Year(), item.TodoEndTime.Month(), item.TodoEndTime.Day(), 0, 0, 0, 0, time.Local)
- dldays := int(dlTime2.Sub(dlTime1).Hours() / 24)
- list[i].Deadline = strconv.Itoa(dldays)
- }
- }
- }
- statusCount, err := company.GetCompanyStatusCount(permissionCondition, permissionPars)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取状态数量失败,Err:" + err.Error()
- return
- }
- statusMap := make(map[string]int, 0)
- var totalCount int
- for _, sv := range statusCount {
- totalCount = totalCount + sv.Count
- statusMap[sv.Status] = sv.Count
- }
- // 统计试用客户的子标签数量,只在试用状态页面统计
- var tryStageCountResp []*company.CompanyTryStageCount
- if status == "试用" {
- tryStageCount, err := company.GetCompanyTryStageCount(permissionCondition, permissionPars)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取试用状态标签数量失败,Err:" + err.Error()
- return
- }
- tryStageMap := make(map[int]int)
- for _, v := range tryStageCount {
- tryStageMap[0] += v.Count
- tryStageMap[v.TryStage] = v.Count
- }
- tryStageAllMap := map[int]string{
- 0: "全部",
- 2: "推进",
- 3: "跟踪",
- 4: "预备",
- 1: "未分类",
- }
- for k, v := range tryStageAllMap {
- item := new(company.CompanyTryStageCount)
- item.TryStageStr = v
- item.TryStage = k
- if count, ok := tryStageMap[k]; ok {
- item.Count = count
- }
- tryStageCountResp = append(tryStageCountResp, item)
- }
- }
- //
- ////试用-活跃
- //{
- // tmpPermissionCondition := permissionCondition
- // tmpPermissionPars := permissionPars
- // tmpPermissionCondition += ` and b.view_total>=? `
- // tmpPermissionPars = append(tmpPermissionPars, statistic_report.ActiveViewNum)
- //
- // tryOutActiveCount, err := company.GetCompanyTryOutStatusCount(tmpPermissionCondition, tmpPermissionPars)
- // if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取状态数量失败,Err:" + err.Error()
- // return
- // }
- // statusMap["试用-活跃"] = tryOutActiveCount.Count
- //}
- //
- ////试用-非活跃
- //{
- // tmpPermissionCondition := permissionCondition
- // tmpPermissionPars := permissionPars
- // tmpPermissionCondition += ` and b.view_total <? `
- // tmpPermissionPars = append(tmpPermissionPars, statistic_report.ActiveViewNum)
- //
- // tryOutActiveCount, err := company.GetCompanyTryOutStatusCount(tmpPermissionCondition, tmpPermissionPars)
- // if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取状态数量失败,Err:" + err.Error()
- // return
- // }
- // statusMap["试用-非活跃"] = tryOutActiveCount.Count
- //}
- lossItem, err := company.GetCompanyStatusLoseCount(lossCondition, lossPars)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取流失状态数量失败,Err:" + err.Error()
- return
- }
- totalCount = totalCount + lossItem.Count
- for _, v := range statusArr {
- s := new(company.CompanyStatus)
- if v == "全部" {
- s.Status = "全部"
- s.Count = totalCount
- } else if v == utils.COMPANY_STATUS_LOSE {
- s.Status = v
- s.Count = lossItem.Count
- } else {
- s.Status = v
- if val, ok := statusMap[v]; ok {
- s.Count = val
- }
- }
- statusItems = append(statusItems, s)
- }
- companyLists := make([]*company.CompanyListItem, 0)
- //查询阅读次数
- if list == nil {
- companyLists = make([]*company.CompanyListItem, 0)
- } else {
- for _, v := range list {
- //viewTotal:=GetviewTotal(v.CompanyId)
- //活跃(客户状态)
- if v.IsShare != 1 {
- if v.BtnItem.BtnModifySeller == true {
- v.BtnItem.BtnModifySeller = false
- }
- }
- //productIdSlice := strings.Split(v.ProductIds, "/")
- //statusSlice := strings.Split(v.Status, "/")
- //for productIndex, tmpProductId := range productIdSlice {
- // tmpStatusIndex := 0
- // if len(statusSlice) > 1 {
- // tmpStatusIndex = productIndex
- // }
- // tmpProductStatus := statusSlice[tmpStatusIndex]
- // if strings.Contains(tmpProductStatus, "试用") {
- // activeType := "非活跃"
- // viewNum := v.FiccView
- // if tmpProductId == "2" {
- // viewNum = v.RaiView
- // }
- // if viewNum >= statistic_report.ActiveViewNum {
- // activeType = "活跃"
- // }
- // statusSlice[tmpStatusIndex] = fmt.Sprint(tmpProductStatus, "(", activeType, ")")
- //
- // tmpStatus = strings.Join(statusSlice, "/")
- // }
- //}
- //ficcViewTotal, ok := companyFiccViewTotal[v.CompanyId]
- //if !ok {
- // ficcViewTotal = 0
- //}
- //raiViewTotal, ok := companyRaiViewTotal[v.CompanyId]
- //if !ok {
- // raiViewTotal = 0
- //}
- // 是否存在进行中的任务
- var todoStatus bool
- if _, ok := companyTodoMap[fmt.Sprint(v.CompanyId)]; ok {
- todoStatus = true
- }
- //是否支持确认完成待办任务
- var canConfirm bool
- var hiddenConfirm bool //是否隐藏确定完成按钮
- var hiddenCreate bool //是否隐藏新增/编辑按钮
- hiddenConfirm = true
- hiddenCreate = true
- for _, vProductId := range []int{1, 2} {
- ficcKey := fmt.Sprint(v.CompanyId, "_", vProductId)
- //ficc
- if tmpCompanyProduct, ok := companyProductMap[ficcKey]; ok {
- if tmpCompanyProduct.Status != utils.COMPANY_STATUS_LOSE && tmpCompanyProduct.Status != utils.COMPANY_STATUS_CLOSE { //非流失
- hiddenCreate = false
- switch this.SysUser.RoleTypeCode {
- case utils.ROLE_TYPE_CODE_FICC_ADMIN, utils.ROLE_TYPE_CODE_RAI_ADMIN, utils.ROLE_TYPE_CODE_FICC_GROUP, utils.ROLE_TYPE_CODE_RAI_GROUP:
- //部门管理员、ficc主管、权益组长
- hiddenConfirm = false //不展示
- if todoStatus { //有任务,需要展示
- canConfirm = true
- }
- case utils.ROLE_TYPE_CODE_FICC_TEAM: //ficc组长
- if todoStatus { //有任务,需要展示
- canConfirm = true
- }
- if v.SellerId != this.SysUser.AdminId { //不是自己的客户
- hiddenConfirm = false //展示
- }
- case utils.ROLE_TYPE_CODE_RAI_SELLER: //权益销售
- if v.SellerId == this.SysUser.AdminId { //是自己的客户
- has := services.CheckRaiApprovePermission(sysUser.AdminId) //这些个权益销售是有权限的
- if has {
- if todoStatus { //有任务,需要展示
- canConfirm = true
- }
- hiddenConfirm = false //展示
- }
- }
- }
- }
- }
- }
- todoButtonColor := `green`
- //'无任务','未完成','已完成'
- if strings.Contains(v.TodoStatuss, "未完成") {
- todoButtonColor = "red"
- } else if strings.Contains(v.TodoStatuss, "已完成") {
- todoButtonColor = "green"
- } else if strings.Contains(v.TodoStatuss, "无任务") {
- todoButtonColor = "gray"
- }
- //if str
- companyList := &company.CompanyListItem{
- CompanyId: v.CompanyId,
- CompanyName: v.CompanyName,
- CreditCode: v.CreditCode,
- CompanyCode: v.CompanyCode,
- StartDate: v.StartDate,
- EndDate: v.EndDate,
- LoseReason: v.LoseReason,
- RenewalReason: v.RenewalReason,
- FreezeReason: v.FreezeReason,
- LossTime: v.LossTime,
- Status: v.StatusStr,
- CompanyType: v.CompanyType,
- ApproveStatus: v.ApproveStatus,
- SellerName: v.SellerName,
- SellerId: v.SellerId,
- SellerIds: v.SellerIds,
- ExpireDay: v.ExpireDay,
- FreezeTime: v.FreezeTime,
- GroupId: v.GroupId,
- GroupIds: v.GroupIds,
- DepartmentId: v.DepartmentId,
- IndustryName: v.IndustryName,
- IsSuspend: v.IsSuspend,
- CreatedTime: v.CreatedTime,
- Source: v.Source,
- Province: v.Province,
- City: v.City,
- Address: v.Address,
- Reasons: v.Reasons,
- FreezeStartDate: v.FreezeStartDate,
- FreezeEndDate: v.FreezeEndDate,
- FreezeExpireDays: v.FreezeExpireDays,
- BtnItem: v.BtnItem,
- ProductId: v.ProductId,
- FormalTime: v.FormalTime,
- IsShared: v.IsShared,
- RegionType: v.RegionType,
- FiccPackageType: v.FiccPackageType,
- FiccLastViewTime: v.FiccLastViewTime,
- RaiLastViewTime: v.RaiLastViewTime,
- //FiccView: viewTotal[0],
- //RaiView: viewTotal[1],
- //FiccView: ficcViewTotal,
- //RaiView: raiViewTotal,
- FiccView: v.FiccView,
- RaiView: v.RaiView,
- FiccTryOutDay: v.FiccTryOutDay,
- RaiTryOutDay: v.RaiTryOutDay,
- AllViewTotal: v.AllViewTotal,
- RoadShowTotal: v.RoadShowTotal,
- TodoStatus: todoStatus,
- CanConfirm: canConfirm,
- HiddenConfirm: hiddenConfirm,
- HiddenCreate: hiddenCreate,
- TodoButtonColor: todoButtonColor,
- TryStageSlice: v.TryStageSlice,
- Deadline: v.Deadline,
- WeekViewActive: v.WeekViewActive,
- IsShare: v.IsShare,
- CloseTime: v.CloseTime,
- CloseReason: v.CloseReason,
- ShareSellerId: v.ShareSellerId,
- }
- companyLists = append(companyLists, companyList)
- }
- }
- if companyLists == nil {
- companyLists = make([]*company.CompanyListItem, 0)
- }
- page = paging.GetPaging(currentIndex, pageSize, total)
- resp.List = companyLists
- resp.StatusCount = statusItems
- resp.TryStageCount = tryStageCountResp
- resp.Paging = page
- resp.AddCompanyBtn = receiveEnabled
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // Export
- // @Title 客户导出
- // @Description 客户导出接口
- // @Param Status query string true "状态:'试用','永续','冻结','流失','正式'"
- // @Param CompanyType query string true "客户类型:传空字符串或者不传为全部,'ficc','权益'"
- // @Param IndustryId query int true "行业id,0为全部"
- // @Param AdminId query string true "销售id,多个用英文逗号隔开,空字符串为全部"
- // @Param ChartPermissionIds query string false "阅读权限品种ID,多个用英文逗号分开,空字符串为全部"
- // @Param ContractPermissionIds query string false "已购品种ID,多个用英文逗号分开,空字符串为全部"
- // @Param StartDate query string true "开始时间"
- // @Param EndDate query string true "结束时间"
- // @Param CreateStartDate query string true "创建开始时间"
- // @Param CreateEndDate query string true "创建结束时间"
- // @Param KeyWord query string true "搜索关键词"
- // @Param Address query string true "地址 , 多个用英文逗号分开 "
- // @Param Province query string true "省 , 多个用英文逗号分开 "
- // @Param City query string true "市 , 多个用英文逗号分开 "
- // @Param PackageType query int true "套餐类型,0:无,1:大套餐,2:小套餐"
- // @Success 200 {object} company.CompanyListResp
- // @router /full/export [get]
- func (this *FullCompanyController) Export() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- roleTypeCode := sysUser.RoleTypeCode
- status := this.GetString("Status")
- companyType := this.GetString("CompanyType")
- industryId, _ := this.GetInt("IndustryId")
- adminId := this.GetString("AdminId")
- chartPermissionIds := this.GetString("ChartPermissionIds")
- contractPermissionIds := this.GetString("ContractPermissionIds")
- startDate := this.GetString("StartDate")
- endDate := this.GetString("EndDate")
- createStartDate := this.GetString("CreateStartDate")
- createEndDate := this.GetString("CreateEndDate")
- keyWord := this.GetString("KeyWord")
- keyWord = strings.Trim(keyWord, " ")
- address := this.GetString("Address")
- province := this.GetString("Province")
- city := this.GetString("City")
- // 套餐类型
- packageType, _ := this.GetInt("PackageType")
- resp := new(company.CompanyListResp)
- statusItems := make([]*company.CompanyStatus, 0)
- var statusArr = [...]string{"全部", "试用", "正式", "冻结", "流失", "永续"}
- var condition string
- var pars []interface{}
- //状态分类查询条件
- var permissionCondition string
- var permissionPars []interface{}
- if companyType != "" && sysUser.RoleName != utils.ROLE_NAME_FICC_DIRECTOR {
- condition += ` AND b.product_name=? `
- pars = append(pars, companyType)
- }
- if industryId > 0 {
- condition += ` AND b.industry_id=? `
- pars = append(pars, industryId)
- }
- if adminId != "" {
- condition += ` AND b.seller_id IN (` + adminId + `) `
- }
- if startDate != "" {
- condition += ` AND b.start_date>=? `
- pars = append(pars, startDate)
- }
- if endDate != "" {
- condition += ` AND b.end_date<=? `
- pars = append(pars, endDate)
- }
- if createStartDate != "" {
- condition += ` AND a.created_time>=? `
- pars = append(pars, createStartDate)
- }
- if createEndDate != "" {
- condition += ` AND a.created_time<=? `
- pars = append(pars, createEndDate)
- }
- if address != "" {
- var addressSql string
- slice := strings.Split(address, ",")
- for _, v := range slice {
- addressSql += "'" + v + "'" + ","
- }
- addressSql = strings.TrimRight(addressSql, ",")
- condition += ` AND a.address IN (` + addressSql + `) `
- }
- if province != "" {
- var provinceSql string
- slice := strings.Split(province, ",")
- for _, v := range slice {
- provinceSql += "'" + v + "'" + ","
- }
- provinceSql = strings.TrimRight(provinceSql, ",")
- condition += ` AND a.province IN (` + provinceSql + `) `
- }
- if city != "" {
- var citySql string
- slice := strings.Split(city, ",")
- for _, v := range slice {
- citySql += "'" + v + "'" + ","
- }
- citySql = strings.TrimRight(citySql, ",")
- condition += ` AND a.city IN (` + citySql + `) `
- }
- if keyWord != "" {
- companyIdStr, err := company.GetCompanyIdByKeyWord(keyWord)
- if err != nil {
- br.Msg = "获取客户信息失败"
- br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
- return
- }
- if companyIdStr != "" {
- condition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.company_id IN(` + companyIdStr + `)) `
- } else {
- condition += ` AND (a.company_name LIKE '%` + keyWord + `%' ) `
- }
- }
- //if chartPermissionIds != "" && chartPermissionIds != "1" {
- // companyIdStr, err := company.GetCompanyListCompanyIdByPermissionIdStr(chartPermissionIds)
- // if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "根据权限获取公司ID失败,Err:" + err.Error()
- // return
- // }
- // if companyIdStr != "" {
- // condition += ` AND a.company_id IN (` + companyIdStr + `) `
- // } else {
- // for _, v := range statusArr {
- // statusCount := new(company.CompanyStatus)
- // if v == "全部" {
- // statusCount.Status = "全部"
- // statusCount.Count = 0
- // } else {
- // statusCount.Status = v
- // statusCount.Count = 0
- // }
- // statusItems = append(statusItems, statusCount)
- // }
- // items := make([]*company.CompanyListItem, 0)
- // resp.List = items
- // resp.StatusCount = statusItems
- // br.Msg = "获取成功"
- // br.Ret = 200
- // br.Data = resp
- // return
- // }
- //}
- // 阅读权限/已购品种筛选
- cond, emp, e := services.FilterReadAndContractAuth(chartPermissionIds, contractPermissionIds, condition)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "FilterReadAndContractAuth err: " + e.Error()
- return
- }
- if emp {
- for _, v := range statusArr {
- statusCount := new(company.CompanyStatus)
- if v == "全部" {
- statusCount.Status = "全部"
- statusCount.Count = 0
- } else {
- statusCount.Status = v
- statusCount.Count = 0
- }
- statusItems = append(statusItems, statusCount)
- }
- items := make([]*company.CompanyListItem, 0)
- resp.List = items
- resp.StatusCount = statusItems
- br.Msg = "获取成功"
- br.Ret = 200
- br.Data = resp
- return
- }
- condition = cond
- //套餐类型
- if packageType > 0 {
- condition += ` AND b.package_type=? `
- pars = append(pars, packageType)
- }
- permissionCondition = condition
- permissionPars = pars
- productId := services.GetProductId(roleTypeCode)
- //权限控制
- {
- //如果不是超级管理员/ficc销售经理
- if roleTypeCode != utils.ROLE_TYPE_CODE_ADMIN && sysUser.RoleName != utils.ROLE_NAME_FICC_DIRECTOR {
- //如果是部门管理员
- if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
- condition += ` AND b.product_id=? `
- pars = append(pars, productId)
- permissionCondition += ` AND b.product_id=? `
- permissionPars = append(permissionPars, productId)
- } else {
- condition += ` AND b.product_id=? `
- pars = append(pars, productId)
- permissionCondition += ` AND b.product_id=? `
- permissionPars = append(permissionPars, productId)
- if status == "全部" {
- ////如果是筛选了流失客户状态
- if sysUser.Authority <= 0 {
- condition += ` AND (b.seller_id=? OR status='流失') `
- pars = append(pars, sysUser.AdminId)
- permissionCondition += ` AND b.seller_id=? `
- permissionPars = append(permissionPars, sysUser.AdminId)
- } else {
- if sysUser.Authority == 1 {
- condition += ` AND (b.department_id=? OR status='流失')`
- pars = append(pars, sysUser.DepartmentId)
- permissionCondition += ` AND b.department_id=? `
- permissionPars = append(permissionPars, sysUser.DepartmentId)
- }
- if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
- if status != utils.COMPANY_STATUS_LOSE {
- condition += ` AND (b.group_id=? OR status='流失') `
- pars = append(pars, sysUser.GroupId)
- }
- permissionCondition += ` AND b.group_id=? `
- permissionPars = append(permissionPars, sysUser.GroupId)
- }
- if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
- pid, err := company.GetParentIdFromGroup(sysUser.GroupId)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "查询父级id异常" + err.Error()
- return
- }
- var ids []*string
- if pid != nil && *pid != 0 {
- ids, err = company.GetGroupIdsByParentId(*pid)
- if err != nil {
- fmt.Println(err.Error())
- }
- } else {
- ids, err = company.GetGroupIdsByParentId(sysUser.GroupId)
- if err != nil {
- fmt.Println(err.Error())
- }
- }
- var idSlice []string
- var sid string
- for _, id := range ids {
- idSlice = append(idSlice, *id)
- }
- //加入父级groupId
- if *pid > 0 {
- idSlice = append(idSlice, strconv.Itoa(*pid))
- } else {
- idSlice = append(idSlice, strconv.Itoa(sysUser.GroupId))
- }
- sid = strings.Join(idSlice, ",")
- if len(sid) > 0 {
- if status != utils.COMPANY_STATUS_LOSE {
- condition += ` AND (b.group_id IN (` + sid + `) OR status='流失') `
- //pars = append(pars, sysUser.GroupId)
- }
- permissionCondition += ` AND b.group_id IN (` + sid + `) `
- } else {
- if status != utils.COMPANY_STATUS_LOSE {
- condition += ` AND (b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) OR status='流失') `
- //pars = append(pars, sysUser.GroupId)
- }
- permissionCondition += ` AND b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) `
- }
- }
- }
- } else {
- ////如果没有筛选了流失客户状态
- if sysUser.Authority <= 0 {
- condition += ` AND b.seller_id=? `
- pars = append(pars, sysUser.AdminId)
- permissionCondition += ` AND b.seller_id=? `
- permissionPars = append(permissionPars, sysUser.AdminId)
- } else {
- if sysUser.Authority == 1 {
- condition += ` AND b.department_id=?`
- pars = append(pars, sysUser.DepartmentId)
- permissionCondition += ` AND b.department_id=? `
- permissionPars = append(permissionPars, sysUser.DepartmentId)
- }
- if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
- if status != utils.COMPANY_STATUS_LOSE {
- condition += ` AND b.group_id=? `
- pars = append(pars, sysUser.GroupId)
- }
- permissionCondition += ` AND b.group_id=? `
- permissionPars = append(permissionPars, sysUser.GroupId)
- }
- if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
- pid, err := company.GetParentIdFromGroup(sysUser.GroupId)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "查询父级id异常" + err.Error()
- return
- }
- var ids []*string
- if pid != nil && *pid != 0 {
- ids, err = company.GetGroupIdsByParentId(*pid)
- if err != nil {
- fmt.Println(err.Error())
- }
- } else {
- ids, err = company.GetGroupIdsByParentId(sysUser.GroupId)
- if err != nil {
- fmt.Println(err.Error())
- }
- }
- var idSlice []string
- var sid string
- for _, id := range ids {
- idSlice = append(idSlice, *id)
- }
- //加入父级groupId
- if *pid > 0 {
- idSlice = append(idSlice, strconv.Itoa(*pid))
- } else {
- idSlice = append(idSlice, strconv.Itoa(sysUser.GroupId))
- }
- sid = strings.Join(idSlice, ",")
- if len(sid) > 0 {
- if status != utils.COMPANY_STATUS_LOSE {
- condition += ` AND (b.group_id IN (` + sid + `) OR status='流失') `
- //pars = append(pars, sysUser.GroupId)
- }
- permissionCondition += ` AND b.group_id IN (` + sid + `) `
- } else {
- if status != utils.COMPANY_STATUS_LOSE {
- condition += ` AND (b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) OR status='流失') `
- //pars = append(pars, sysUser.GroupId)
- }
- permissionCondition += ` AND b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) `
- }
- }
- if sysUser.Authority == 4 {
- if status != utils.COMPANY_STATUS_LOSE {
- condition += ` AND b.group_id =? `
- pars = append(pars, sysUser.GroupId)
- }
- permissionCondition += ` AND b.group_id=? `
- permissionPars = append(permissionPars, sysUser.GroupId)
- }
- }
- }
- }
- }
- }
- //状态控制
- if status != "" && status != "全部" && status != utils.COMPANY_STATUS_LOSE {
- condition += ` AND b.status=? `
- pars = append(pars, status)
- }
- dir, err := os.Executable()
- exPath := filepath.Dir(dir)
- downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
- xlsxFile := xlsx.NewFile()
- if err != nil {
- br.Msg = "生成文件失败"
- br.ErrMsg = "生成文件失败"
- return
- }
- style := xlsx.NewStyle()
- alignment := xlsx.Alignment{
- Horizontal: "center",
- Vertical: "center",
- WrapText: true,
- }
- style.Alignment = alignment
- style.ApplyAlignment = true
- sheel, err := xlsxFile.AddSheet("客户数据")
- if err != nil {
- br.Msg = "新增Sheet失败"
- br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
- return
- }
- titleArr := []string{"客户名称", "客户地址", "客户类型", "所属行业", "所属销售", "客户状态", "服务期限", "到期天数", "创建时间", "权限详情"}
- titleLen := len(titleArr)
- titleRow := sheel.AddRow()
- remarkRow := sheel.AddRow() // 备注行
- // 填充空白至Z列
- emptyColNum := 0
- for i := 0; i < 26; i++ {
- remarkRow.AddCell().SetValue("")
- if i >= titleLen {
- emptyColNum += 1
- titleRow.AddCell().SetValue("")
- continue
- }
- titleRow.AddCell().SetValue(titleArr[i])
- }
- // 第二行, 在品种权限开始列加一行标红备注
- styleRed := xlsx.NewStyle()
- styleRed.Font.Color = "ff0000"
- remarkCell := remarkRow.AddCell()
- remarkCell.SetStyle(styleRed)
- remarkCell.SetString(`第一位数字表示是否已购买该品种,1表示已购,0表示未购;第二位数字表示是否有阅读权限,1表示有权限,0表示没有`)
- // AA列开始为品种权限
- ficcPermissions := make([]int, 0) // 用于后续判断试用暂停客户是否需要暂停这部分权限
- raiPermissions := make([]int, 0)
- permissions, e := models.GetChartPermissionList()
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取品种数据失败,Err:" + err.Error()
- return
- }
- raiArr := []string{"医药", "消费", "科技", "智造"}
- for _, p := range permissions {
- if p.ProductId == 1 {
- ficcPermissions = append(ficcPermissions, p.ChartPermissionId)
- }
- if p.ProductId == 2 {
- raiPermissions = append(raiPermissions, p.ChartPermissionId)
- }
- if utils.InArrayByStr(raiArr, p.PermissionName) {
- titleRow.AddCell().SetValue(p.Remark)
- continue
- }
- titleRow.AddCell().SetValue(p.PermissionName)
- }
- list, err := company.GetCompanyListExport(condition, pars)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- companyIds := make([]int, 0)
- for _, c := range list {
- companyIds = append(companyIds, c.CompanyId)
- }
- // 获取客户对应的阅读和合同权限集合
- contractPermissionMap := make(map[int][]int)
- contractPermissions, e := company.GetContractPermissionIdsByCompanyIds(companyIds)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取已购权限失败, Err: " + e.Error()
- return
- }
- for _, p := range contractPermissions {
- ids := make([]int, 0)
- if p.ChartPermissionIds != "" {
- idArr := strings.Split(p.ChartPermissionIds, ",")
- for _, i := range idArr {
- id, _ := strconv.Atoi(i)
- ids = append(ids, id)
- }
- }
- contractPermissionMap[p.CompanyId] = ids
- }
- reportPermissionMap := make(map[int][]int)
- reportPermissions, e := company.GetReportPermissionIdsByCompanyIds(companyIds)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取阅读权限失败, Err: " + e.Error()
- return
- }
- for _, p := range reportPermissions {
- ids := make([]int, 0)
- if p.ChartPermissionIds != "" {
- idArr := strings.Split(p.ChartPermissionIds, ",")
- for _, i := range idArr {
- id, _ := strconv.Atoi(i)
- ids = append(ids, id)
- }
- }
- reportPermissionMap[p.CompanyId] = ids
- }
- cpMap := make(map[int][]*company.ExportCompanyProduct)
- permissionMap := make(map[string]string)
- for _, v := range list {
- cpList := make([]*company.ExportCompanyProduct, 1)
- if cps, ok := cpMap[v.CompanyId]; ok {
- cpList = cps
- } else {
- companyProduct, err := company.GetExportCompanyProduct(v.CompanyId)
- if err != nil {
- br.Msg = "导出失败"
- br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
- return
- }
- cpMap[v.CompanyId] = companyProduct
- cpList = companyProduct
- }
- var companyName, companyType, industryName, sellerName, status, timeLimt, createTime, source, permissionStr, expireDay string
- isFiccSuspend := 0
- isRaiSuspend := 0
- for ck, cv := range cpList {
- companyName = cv.CompanyName
- if ck >= 1 {
- companyType = companyType + "/" + cv.ProductName
- status = status + "/" + cv.Status
- } else {
- companyType = cv.ProductName
- status = cv.Status
- }
- if cv.ProductId == 1 {
- industryName = "ficc:" + cv.IndustryName
- sellerName = "ficc:" + cv.SellerName
- startDateStr := cv.StartDate.Format("2006/01/02")
- endDateStr := cv.EndDate.Format("2006/01/02")
- timeLimt = "ficc:" + startDateStr + "~" + endDateStr
- createTime = "ficc:" + cv.CreateTime
- source = "ficc:" + cv.Source
- sub := cv.EndDate.Sub(time.Now())
- if sub < 0 {
- sub = 0
- }
- expireDay = "ficc:" + fmt.Sprintf("%v", int(sub.Hours()/24))
- permissionKey := strconv.Itoa(v.CompanyId) + "_" + strconv.Itoa(cv.ProductId)
- permissionStr = "ficc:"
- if newPermissionStr, ok := permissionMap[permissionKey]; ok {
- permissionStr += newPermissionStr
- } else {
- getPermissionStr, err := company.GetExportPermissionName(v.CompanyId, cv.ProductId)
- if err != nil {
- br.Msg = "导出失败"
- br.ErrMsg = "获取客户权限信息失败,Err:" + err.Error()
- return
- }
- permissionMap[permissionKey] = getPermissionStr
- permissionStr += getPermissionStr
- }
- isFiccSuspend = cv.IsSuspend
- } else {
- industryName = industryName + "\n" + "权益:" + cv.IndustryName
- sellerName = sellerName + "\n" + "权益:" + cv.SellerName
- startDateStr := cv.StartDate.Format("2006/01/02")
- endDateStr := cv.EndDate.Format("2006/01/02")
- timeLimt = timeLimt + "\n" + "权益:" + startDateStr + "~" + endDateStr
- createTime = createTime + "\n" + "权益:" + cv.CreateTime
- source = source + "\n" + "权益:" + cv.Source
- sub := cv.EndDate.Sub(time.Now())
- if sub < 0 {
- sub = 0
- }
- expireDay = "\n" + "权益:" + fmt.Sprintf("%v", int(sub.Hours()/24))
- permissionKey := strconv.Itoa(v.CompanyId) + "_" + strconv.Itoa(cv.ProductId)
- if permissionStr != "" {
- permissionStr = permissionStr + "\n" + "权益:"
- } else {
- permissionStr = "权益:"
- }
- if newPermissionStr, ok := permissionMap[permissionKey]; ok {
- permissionStr += newPermissionStr
- } else {
- getPermissionStr, err := company.GetExportPermissionName(v.CompanyId, cv.ProductId)
- if err != nil {
- br.Msg = "导出失败"
- br.ErrMsg = "获取客户权限信息失败,Err:" + err.Error()
- return
- }
- permissionMap[permissionKey] = getPermissionStr
- permissionStr += getPermissionStr
- }
- isRaiSuspend = cv.IsSuspend
- }
- }
- dataRow := sheel.AddRow()
- dataRow.SetHeight(20)
- dataRow.AddCell().SetString(companyName)
- dataRow.AddCell().SetString(v.Address)
- dataRow.AddCell().SetString(companyType)
- dataRow.AddCell().SetString(v.IndustryName)
- dataRow.AddCell().SetString(v.SellerName)
- dataRow.AddCell().SetString(v.Status)
- dataRow.AddCell().SetString(timeLimt)
- dataRow.AddCell().SetString(expireDay)
- dataRow.AddCell().SetString(v.CreatedTime)
- //dataRow.AddCell().SetString(v.Source)
- dataRow.AddCell().SetString(permissionStr)
- // 填充空白至Z列, AA列开始为权限
- for i := 0; i < emptyColNum; i++ {
- dataRow.AddCell().SetString("")
- }
- cpIds := contractPermissionMap[v.CompanyId]
- rpIds := reportPermissionMap[v.CompanyId]
- for _, p := range permissions {
- // 数字含义:11-表示已购且有阅读权限, 01-表示未购买但有阅读权限
- first := 0
- if utils.InArrayByInt(cpIds, p.ChartPermissionId) {
- first = 1
- }
- second := 0
- if utils.InArrayByInt(rpIds, p.ChartPermissionId) {
- second = 1
- // 如果客户是试用暂停, 即使有这部分权限, 也标记为0
- if isFiccSuspend == 1 && utils.InArrayByInt(ficcPermissions, p.ChartPermissionId) {
- second = 0
- }
- if isRaiSuspend == 1 && utils.InArrayByInt(raiPermissions, p.ChartPermissionId) {
- second = 0
- }
- }
- dataRow.AddCell().SetString(fmt.Sprintf("%d%d", first, second))
- }
- }
- err = xlsxFile.Save(downLoadnFilePath)
- if err != nil {
- br.Msg = "保存文件失败"
- br.ErrMsg = "保存文件失败"
- return
- }
- randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
- downloadFileName := "客户列表_" + randStr + ".xlsx"
- this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
- defer func() {
- os.Remove(downLoadnFilePath)
- }()
- br.Ret = 200
- br.Success = true
- br.Msg = "导出成功"
- }
- // CompanyUserExport
- // @Title 导出联系人
- // @Description 导出接口
- // @Param Status query string true "状态:”试用','永续','冻结','流失','正式'"
- // @Param CompanyType query string true "客户类型:传空字符串或者不传为全部,'ficc','权益'"
- // @Param IndustryId query int true "行业id,0为全部"
- // @Param AdminId query string true "销售id,多个用英文逗号隔开,空字符串为全部"
- // @Param ChartPermissionIds query string false "阅读权限品种ID,多个用英文逗号分开,空字符串为全部"
- // @Param ContractPermissionIds query string false "已购品种ID,多个用英文逗号分开,空字符串为全部"
- // @Param StartDate query string true "开始时间"
- // @Param EndDate query string true "结束时间"
- // @Param KeyWord query string true "搜索关键词"
- // @Param Address query string true "地址 , 多个用英文逗号分开 "
- // @Param Province query string true "省 , 多个用英文逗号分开 "
- // @Param City query string true "市 , 多个用英文逗号分开 "
- // @Param PackageType query int true "套餐类型,0:无,1:大套餐,2:小套餐"
- // @Success Ret=200 移动成功
- // @router /full/user/export [get]
- func (this *FullCompanyController) CompanyUserExport() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- roleTypeCode := sysUser.RoleTypeCode
- status := this.GetString("Status")
- companyType := this.GetString("CompanyType")
- industryId, _ := this.GetInt("IndustryId")
- adminId := this.GetString("AdminId")
- chartPermissionIds := this.GetString("ChartPermissionIds")
- contractPermissionIds := this.GetString("ContractPermissionIds")
- startDate := this.GetString("StartDate")
- endDate := this.GetString("EndDate")
- createStartDate := this.GetString("CreateStartDate")
- createEndDate := this.GetString("CreateEndDate")
- keyWord := this.GetString("KeyWord")
- address := this.GetString("Address")
- province := this.GetString("Province")
- city := this.GetString("City")
- // 套餐类型
- packageType, _ := this.GetInt("PackageType")
- var condition string
- var pars []interface{}
- if status != "" && status != "全部" {
- condition += ` AND b.status=? `
- pars = append(pars, status)
- }
- if companyType != "" && sysUser.RoleName != utils.ROLE_NAME_FICC_DIRECTOR {
- condition += ` AND b.product_name=? `
- pars = append(pars, companyType)
- }
- if industryId > 0 {
- condition += ` AND b.industry_id=? `
- pars = append(pars, industryId)
- }
- if adminId != "" {
- condition += ` AND b.seller_id IN (` + adminId + `) `
- }
- if startDate != "" {
- condition += ` AND b.start_date>=? `
- pars = append(pars, startDate)
- }
- if endDate != "" {
- condition += ` AND b.end_date<=? `
- pars = append(pars, endDate)
- }
- if createStartDate != "" {
- condition += ` AND a.created_time>=? `
- pars = append(pars, createStartDate)
- }
- if createEndDate != "" {
- condition += ` AND a.created_time<=? `
- pars = append(pars, createEndDate)
- }
- if keyWord != "" {
- condition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR c.mobile LIKE '%` + keyWord + `%' OR c.email LIKE '%` + keyWord + `%') `
- }
- // 阅读权限/已购品种筛选
- cond, emp, e := services.FilterReadAndContractAuth(chartPermissionIds, contractPermissionIds, condition)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "FilterReadAndContractAuth err: " + e.Error()
- return
- }
- if emp {
- condition += ` AND 1 = 2`
- } else {
- condition = cond
- }
- if address != "" {
- var addressSql string
- slice := strings.Split(address, ",")
- for _, v := range slice {
- addressSql += "'" + v + "'" + ","
- }
- addressSql = strings.TrimRight(addressSql, ",")
- condition += ` AND a.address IN (` + addressSql + `) `
- }
- if province != "" {
- var provinceSql string
- slice := strings.Split(province, ",")
- for _, v := range slice {
- provinceSql += "'" + v + "'" + ","
- }
- provinceSql = strings.TrimRight(provinceSql, ",")
- condition += ` AND a.province IN (` + provinceSql + `) `
- }
- if city != "" {
- var citySql string
- slice := strings.Split(city, ",")
- for _, v := range slice {
- citySql += "'" + v + "'" + ","
- }
- citySql = strings.TrimRight(citySql, ",")
- condition += ` AND a.city IN (` + citySql + `) `
- }
- //套餐类型
- if packageType > 0 {
- condition += ` AND b.package_type=? `
- pars = append(pars, packageType)
- }
- //权限控制
- {
- // 角色不为ficc销售经理时走权限控制
- if sysUser.RoleName != utils.ROLE_NAME_FICC_DIRECTOR {
- if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER ||
- roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER {
- if status != utils.COMPANY_STATUS_LOSE && status != utils.COMPANY_STATUS_FOREVER {
- condition += ` AND b.seller_id=? `
- pars = append(pars, sysUser.AdminId)
- }
- }
- if sysUser.Authority == 1 {
- condition += ` AND b.department_id=? `
- pars = append(pars, sysUser.DepartmentId)
- }
- if sysUser.Authority == 2 {
- condition += ` AND b.group_id=? `
- pars = append(pars, sysUser.GroupId)
- }
- }
- }
- var statusCond string
- var statusPars []interface{}
- // 根据当前用户角色
- productId := services.GetProductId(roleTypeCode)
- if sysUser.RoleName == utils.ROLE_NAME_FICC_DIRECTOR {
- productId = 0
- }
- if productId > 0 {
- condition += ` AND b.product_id = ? `
- pars = append(pars, productId)
- statusCond += ` AND b.product_id = ? `
- statusPars = append(statusPars, productId)
- }
- companyIds, err := company.GetExportCompanyIds(condition, pars)
- if err != nil {
- br.Msg = "导出失败"
- br.ErrMsg = "导出失败,Err:" + err.Error()
- return
- }
- dir, err := os.Executable()
- exPath := filepath.Dir(dir)
- downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
- xlsxFile := xlsx.NewFile()
- if err != nil {
- br.Msg = "生成文件失败"
- br.ErrMsg = "生成文件失败"
- return
- }
- style := xlsx.NewStyle()
- alignment := xlsx.Alignment{
- Horizontal: "center",
- Vertical: "center",
- WrapText: true,
- }
- style.Alignment = alignment
- style.ApplyAlignment = true
- sheel, err := xlsxFile.AddSheet("联系人数据")
- if err != nil {
- br.Msg = "新增Sheet失败"
- br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
- return
- }
- sheel.SetColWidth(7, 7, 10)
- sheel.SetColWidth(8, 10, 16)
- sheel.SetColWidth(9, 11, 20)
- sheel.SetColWidth(12, 12, 35)
- sheel.SetColWidth(13, 13, 15)
- sheel.SetColWidth(14, 14, 80)
- titleRow := sheel.AddRow()
- titleRow.AddCell().SetValue("联系人")
- titleRow.AddCell().SetValue("是否关注公众号")
- titleRow.AddCell().SetValue("手机号")
- titleRow.AddCell().SetValue("邮箱")
- titleRow.AddCell().SetValue("是否决策人")
- titleRow.AddCell().SetValue("客户名称")
- titleRow.AddCell().SetValue("客户状态")
- if companyIds != "" {
- companyIds = strings.Trim(companyIds, ",")
- users, err := company.GetExportUser(companyIds)
- if err != nil {
- br.Msg = "导出失败"
- br.ErrMsg = "获取联系人信息失败,Err:" + err.Error()
- return
- }
- // 获取客户状态
- companyIntIds := make([]int, 0)
- companyIdArr := strings.Split(companyIds, ",")
- for _, c := range companyIdArr {
- id, e := strconv.Atoi(c)
- if e != nil {
- br.Msg = "导出失败"
- br.ErrMsg = "客户ID有误"
- return
- }
- companyIntIds = append(companyIntIds, id)
- }
- if len(companyIntIds) > 0 {
- statusCond += fmt.Sprintf(` AND a.company_id IN (%s) `, utils.GetOrmInReplace(len(companyIntIds)))
- statusPars = append(statusPars, companyIntIds)
- }
- statusMap := make(map[int]string)
- nameMap := make(map[int]string)
- companyStatusList, e := company.GetExportUserCompanyStatus(statusCond, statusPars)
- if e != nil {
- br.Msg = "导出失败"
- br.ErrMsg = "获取客户状态失败, Err: " + e.Error()
- return
- }
- for _, s := range companyStatusList {
- statusMap[s.CompanyId] = s.CompanyStatus
- nameMap[s.CompanyId] = s.CompanyName
- }
- for _, v := range users {
- dataRow := sheel.AddRow()
- dataRow.SetHeight(20)
- dataRow.AddCell().SetString(v.RealName)
- if v.IsSubscribe == 1 {
- dataRow.AddCell().SetString("是") // 是否关注公众号
- } else {
- dataRow.AddCell().SetString("")
- }
- dataRow.AddCell().SetString(v.Mobile)
- dataRow.AddCell().SetString(v.Email)
- if v.IsMaker == 1 {
- dataRow.AddCell().SetString("是")
- } else {
- dataRow.AddCell().SetString("否")
- }
- dataRow.AddCell().SetString(nameMap[v.CompanyId])
- dataRow.AddCell().SetString(statusMap[v.CompanyId]) // 客户状态
- }
- }
- err = xlsxFile.Save(downLoadnFilePath)
- if err != nil {
- br.Msg = "保存文件失败"
- br.ErrMsg = "保存文件失败"
- return
- }
- randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
- downloadFileName := "联系人列表" + randStr + ".xlsx"
- this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
- defer func() {
- os.Remove(downLoadnFilePath)
- }()
- br.Ret = 200
- br.Success = true
- br.Msg = "导出成功"
- }
- // Detail
- // @Title 获取客户详情
- // @Description 获取客户详情接口
- // @Param CompanyId query int true "客户id"
- // @Success 200 {object} company.CompanyDetailResp
- // @router /full/detail [get]
- func (this *FullCompanyController) Detail() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- companyId, _ := this.GetInt("CompanyId")
- if companyId <= 0 {
- br.Msg = "参数错误"
- br.ErrMsg = "客户参数小于等于0"
- return
- }
- // CRM8.8-是否为编辑页的客户详情
- isEdit, _ := this.GetBool("IsEdit")
- item, err := company.GetCompanyDetailById(companyId)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- var productName string
- productId := services.GetProductId(sysUser.RoleTypeCode)
- // 销售经理赋予admin查看权限
- if sysUser.RoleName == utils.ROLE_NAME_FICC_DIRECTOR {
- productId = 0
- }
- if productId == 1 {
- productName = utils.COMPANY_PRODUCT_FICC_NAME
- } else if productId == 2 {
- productName = utils.COMPANY_PRODUCT_RAI_NAME
- } else {
- productName = "admin"
- }
- resp := new(company.CompanyDetailResp)
- resp.ProductName = productName
- //获取客户产品
- productList, err := company.GetCompanyProductsByCompanyId(companyId)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取产品信息失败,Err:" + err.Error()
- return
- }
- roleTypeCode := sysUser.RoleTypeCode
- itemLen := len(productList)
- btnDetailItem := new(company.ButtonDetailPermission)
- //产品权限map
- statusMap := make(map[int]string)
- for i := 0; i < itemLen; i++ {
- item := productList[i]
- //添加产品权限map
- statusMap[item.ProductId] = item.Status
- if i == 0 {
- if item.ProductId == 1 {
- resp.CreateAuth = 1
- } else {
- resp.CreateAuth = 2
- }
- }
- if item.ProductId == 1 {
- if strings.Contains(sysUser.RoleTypeCode, "ficc") {
- if item.Status == utils.COMPANY_STATUS_FREEZE || item.Status == utils.COMPANY_STATUS_LOSE {
- btnDetailItem.BtnHistoryList = true
- } else {
- if item.SellerId == sysUser.AdminId || item.ShareSellerId == sysUser.AdminId {
- btnDetailItem.BtnHistoryList = true
- }
- if sysUser.Authority > 0 {
- if item.GroupId == sysUser.GroupId {
- btnDetailItem.BtnHistoryList = true
- }
- if item.DepartmentId == sysUser.DepartmentId {
- btnDetailItem.BtnHistoryList = true
- }
- }
- }
- }
- //子权限切片集合
- allFiccPermissions, permissionMap, e := services.GetBasePermissionLookItem(utils.COMPANY_PRODUCT_FICC_ID)
- if e != nil {
- br.Msg = "查询基础权限失败"
- br.ErrMsg = "查询基础权限失败,Err:" + e.Error()
- return
- }
- //遍历获取
- for _, v := range allFiccPermissions {
- if v.ParentId == 0 {
- checkList := make([]int, 0)
- plist := new(company.PermissionLookList)
- items, ok := permissionMap[v.ChartPermissionId]
- if !ok {
- br.Msg = "获取权限信息失败"
- return
- }
- for itemK, n := range items {
- permission, err := company.GetCompanyPermissionCheckItem(companyId, n.ChartPermissionId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
- return
- }
- if permission != nil && permission.ChartPermissionId > 0 {
- checkList = append(checkList, n.ChartPermissionId)
- items[itemK].StartDate = permission.StartDate
- items[itemK].EndDate = permission.EndDate
- items[itemK].Status = permission.Status
- endDateTime, _ := time.Parse(utils.FormatDate, permission.EndDate)
- endDateTime = endDateTime.AddDate(0, 0, 1)
- sub := endDateTime.Sub(time.Now())
- if sub < 0 {
- sub = 0
- }
- expireDay := fmt.Sprintf("%v", int(sub.Hours()/24))
- items[itemK].ExpireDay = expireDay
- }
- //count, err := company.GetCompanyPermissionCheck(companyId, n.ChartPermissionId)
- //if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
- // return
- //}
- //if count > 0 {
- // checkList = append(checkList, n.ChartPermissionId)
- //}
- }
- plist.Items = items
- plist.ClassifyName = v.PermissionName
- plist.CheckList = checkList
- item.PermissionList = append(item.PermissionList, plist)
- }
- }
- resp.FiccItem = item
- if (roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER ||
- roleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP || roleTypeCode == utils.ROLE_TYPE_CODE_FICC_DEPARTMENT) &&
- item.Status == utils.COMPANY_STATUS_TRY_OUT && item.ApproveStatus != "待审批" {
- resp.IsButtonShow = 1
- }
- } else {
- if strings.Contains(sysUser.RoleTypeCode, "rai") {
- if item.Status == utils.COMPANY_STATUS_FREEZE || item.Status == utils.COMPANY_STATUS_LOSE {
- btnDetailItem.BtnHistoryList = true
- } else {
- if item.SellerId == sysUser.AdminId {
- btnDetailItem.BtnHistoryList = true
- }
- if sysUser.Authority > 0 {
- if item.GroupId == sysUser.GroupId {
- btnDetailItem.BtnHistoryList = true
- }
- if item.DepartmentId == sysUser.DepartmentId {
- btnDetailItem.BtnHistoryList = true
- }
- }
- }
- }
- // CRM8.8-权益权限列表调用较多、统一进行调整
- plist, e := services.RaiCompanyPermissionAndCheckList(companyId, isEdit, []string{"调研"})
- if e != nil {
- br.Msg = "获取客户权益权限列表信息失败"
- br.ErrMsg = "获取客户权益权限列表信息失败,Err:" + e.Error()
- return
- }
- // cygx8.2专项产业调研展示
- item.SpecialSurplus, err = cygxService.GetSpecialSurplusByCompanyNew(companyId)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取专项调研信息失败,Err:" + err.Error()
- return
- }
- item.PermissionList = append(item.PermissionList, plist)
- resp.RaiItem = item
- if (roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER ||
- roleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP ||
- roleTypeCode == utils.ROLE_TYPE_CODE_RAI_DEPARTMENT) &&
- item.Status == utils.COMPANY_STATUS_TRY_OUT && item.ApproveStatus != "待审批" {
- resp.IsButtonShow = 1
- }
- }
- btnItem := services.GetCompanyPermissionButton(roleTypeCode, item.Status, strconv.Itoa(item.SellerId), strconv.Itoa(item.GroupId),
- item.GroupId, sysUser.GroupId, item.SellerId, sysUser.AdminId, sysUser.Authority, item.ProductId, item.ShareSellerId, "")
- //if itemLen > 1 {
- // btnDetailItem.BtnEdit = false
- // btnDetailItem.BtnDelete = false
- //} else {
- // btnDetailItem.BtnEdit = btnItem.BtnEdit
- // btnDetailItem.BtnDelete = btnItem.BtnDelete
- //}
- switch item.ProductId {
- case 1:
- btnDetailItem.FiccEdit = btnItem.BtnEdit
- btnDetailItem.FiccDelete = btnItem.BtnDelete
- case 2:
- btnDetailItem.RaiEdit = btnItem.BtnEdit
- btnDetailItem.RaiDelete = btnItem.BtnDelete
- }
- if !btnDetailItem.BtnEdit {
- btnDetailItem.BtnEdit = btnItem.BtnEdit
- }
- if !btnDetailItem.BtnDelete {
- btnDetailItem.BtnDelete = btnItem.BtnDelete
- }
- //联系人操作权限
- if resp.IsContractButtonShow == false {
- resp.IsContractButtonShow = services.CheckCompanyUserButton(sysUser.RoleTypeCode, item.SellerId, sysUser.AdminId, item.ProductId, item.ShareSellerId, item.Status)
- }
- }
- if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN ||
- roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN ||
- roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
- resp.IsButtonShow = 1
- btnDetailItem.BtnHistoryList = true
- }
- //ficc权限
- if ficcStatus, ok := statusMap[1]; ok {
- if ficcStatus == utils.COMPANY_STATUS_TRY_OUT {
- if raiStatus, ok := statusMap[2]; ok {
- //另一个权限也是 试用 、冻结、流失
- if raiStatus == utils.COMPANY_STATUS_TRY_OUT || raiStatus == utils.COMPANY_STATUS_FREEZE || raiStatus == utils.COMPANY_STATUS_LOSE {
- //那么超管、部门管理员、销售可以编辑
- if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER || roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
- btnDetailItem.BaseInfoEdit = true
- }
- }
- //权益是永续时,超管可编辑基础信息
- if raiStatus == utils.COMPANY_STATUS_FOREVER {
- if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
- btnDetailItem.BaseInfoEdit = true
- }
- }
- } else {
- //权限未开,有编辑基础信息权限
- btnDetailItem.BaseInfoEdit = true
- }
- }
- if ficcStatus == utils.COMPANY_STATUS_FOREVER {
- if raiStatus, ok := statusMap[2]; ok {
- //另一个权限也是 永续 、冻结、流失
- if raiStatus == utils.COMPANY_STATUS_TRY_OUT || raiStatus == utils.COMPANY_STATUS_FOREVER || raiStatus == utils.COMPANY_STATUS_FREEZE || raiStatus == utils.COMPANY_STATUS_LOSE {
- //超管可编辑基础信息
- if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
- btnDetailItem.BaseInfoEdit = true
- }
- }
- } else {
- //权限未开,有编辑基础信息权限
- btnDetailItem.BaseInfoEdit = true
- }
- }
- }
- //权益销售
- if raiStatus, ok := statusMap[2]; ok {
- if raiStatus == utils.COMPANY_STATUS_TRY_OUT {
- if ficcStatus, ok := statusMap[1]; ok {
- //另一个权限也是 试用 、冻结、流失
- if ficcStatus == utils.COMPANY_STATUS_TRY_OUT || ficcStatus == utils.COMPANY_STATUS_FREEZE || ficcStatus == utils.COMPANY_STATUS_LOSE {
- //那么超管、部门管理员、销售可以编辑
- if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER || roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
- btnDetailItem.BaseInfoEdit = true
- }
- }
- //ficc是永续时,超管可编辑基础信息
- if ficcStatus == utils.COMPANY_STATUS_FOREVER {
- if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
- btnDetailItem.BaseInfoEdit = true
- }
- }
- } else {
- //权限未开,有编辑基础信息权限
- btnDetailItem.BaseInfoEdit = true
- }
- }
- if raiStatus == utils.COMPANY_STATUS_FOREVER {
- if ficcStatus, ok := statusMap[1]; ok {
- //另一个权限也是 试用、永续 、冻结、流失
- if ficcStatus == utils.COMPANY_STATUS_TRY_OUT || ficcStatus == utils.COMPANY_STATUS_FOREVER || ficcStatus == utils.COMPANY_STATUS_FREEZE || ficcStatus == utils.COMPANY_STATUS_LOSE {
- //超管可编辑基础信息
- if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
- btnDetailItem.BaseInfoEdit = true
- }
- }
- } else {
- //权限未开,有编辑基础信息权限
- btnDetailItem.BaseInfoEdit = true
- }
- }
- }
- // 隐藏销售列表相关操作按钮, 仅可查看基础内容及历史签约
- resp.IsContractButtonShow = false
- btn := new(company.ButtonDetailPermission)
- btn.BtnHistoryList = true
- btnDetailItem = btn
- resp.Item = item
- resp.BtnItem = btnDetailItem
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // PermissionLook
- // @Title 查看客户权限
- // @Description 查看客户权限接口
- // @Param CompanyId query int true "客户id"
- // @Param LookType query int true "调用类型:1增开试用,0其他"
- // @Success 200 {object} company.PermissionLookResp
- // @router /full/permission/look [get]
- func (this *FullCompanyController) PermissionLook() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- roleTypeCode := sysUser.RoleTypeCode
- companyId, _ := this.GetInt("CompanyId")
- if companyId <= 0 {
- br.Msg = "参数错误"
- br.ErrMsg = "参数错误,CompanyId 小于等于0 "
- return
- }
- lookType, _ := this.GetInt("LookType")
- productId := services.GetProductId(roleTypeCode)
- // ficc销售经理可查看ficc和权益的
- if sysUser.RoleName == utils.ROLE_NAME_FICC_DIRECTOR {
- productId = 0
- }
- resp := new(company.PermissionLookResp)
- permissionArr := make([]*models.ChartPermission, 0)
- var err error
- if lookType == 1 {
- permissionArr, err = services.GetPermissionFirstArr(productId)
- } else {
- permissionArr, err = services.GetPermissionFirstArr(0)
- }
- if err != nil {
- br.Msg = "获取权限失败"
- br.ErrMsg = "获取权限失败 err:" + err.Error()
- return
- }
- /*if lookType == 1 {
- if productId == 1 {
- for _, permission := range utils.PermissionFiccClassifyArr {
- permissionArr = append(permissionArr, permission)
- }
- } else if productId == 2 {
- permissionArr = []string{"权益"}
- } else {
- for _, permission := range utils.PermissionAllClassifyArr {
- permissionArr = append(permissionArr, permission)
- }
- }
- } else {
- for _, permission := range utils.PermissionAllClassifyArr {
- permissionArr = append(permissionArr, permission)
- }
- }*/
- //ficc权限类目
- for _, v := range permissionArr {
- checkList := make([]int, 0)
- p := new(company.PermissionLookList)
- p.Items = make([]*company.PermissionLookItem, 0)
- var productId int
- //if v == "权益" {
- // productId = 2
- //} else {
- // productId = 1
- //}
- if v.PermissionName != "权益" {
- productId = 1
- //mapPermissionName := make(map[string]int)
- items, err := company.GetPermissionLookItemsByParentId(productId, v.ChartPermissionId)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
- return
- }
- itemLen := len(items)
- permissionList := make([]*company.PermissionLookItem, 0)
- for i := 0; i < itemLen; i++ {
- var isAdd bool
- item := items[i]
- permission, err := company.GetCompanyPermissionCheckItem(companyId, item.ChartPermissionId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
- return
- }
- if permission != nil && permission.ChartPermissionId > 0 {
- items[i].StartDate = permission.StartDate
- items[i].EndDate = permission.EndDate
- items[i].Status = permission.Status
- //判断主观、客观
- if items[i].PermissionType == 1 {
- items[i].PermissionTypeName = "主观"
- } else if items[i].PermissionType == 2 {
- items[i].PermissionTypeName = "客观"
- }
- checkList = append(checkList, item.ChartPermissionId)
- isAdd = true
- ////如果主观客观 都有,则不显示类型,如果只有一种就显示主观,或者客观
- //if mapPermissionName[items[i].PermissionName] == 0 {
- // checkList = append(checkList, item.ChartPermissionId)
- // mapPermissionName[items[i].PermissionName] = i + 1
- //
- //} else {
- // items[mapPermissionName[items[i].PermissionName]-1].PermissionTypeName = ""
- //}
- }
- endDateTime, _ := time.Parse(utils.FormatDate, item.EndDate)
- endDateTime = endDateTime.AddDate(0, 0, 1)
- sub := endDateTime.Sub(time.Now())
- if sub < 0 {
- sub = 0
- }
- expireDay := fmt.Sprintf("%v", int(sub.Hours()/24))
- items[i].ExpireDay = expireDay
- items[i].ClassifyName = v.PermissionName
- if lookType == 1 {
- permissionList = append(permissionList, items[i])
- } else {
- if isAdd {
- permissionList = append(permissionList, items[i])
- }
- }
- }
- //合并主观客观
- mapPermissionNameList := make(map[string]int)
- for _, v := range permissionList {
- if mapPermissionNameList[v.PermissionName] == 0 {
- p.Items = append(p.Items, v)
- mapPermissionNameList[v.PermissionName] = v.ChartPermissionId
- }
- }
- p.ClassifyName = v.PermissionName
- //p.Items = permissionList
- p.CheckList = checkList
- if lookType == 1 {
- resp.List = append(resp.List, p)
- } else {
- if len(checkList) > 0 {
- resp.List = append(resp.List, p)
- }
- }
- }
- }
- //权益权限类目
- for _, v := range permissionArr {
- if v.PermissionName == "权益" {
- // CRM8.8-权益权限列表调用较多、统一进行调整
- unify := false
- if lookType == 1 {
- unify = true
- }
- p, e := services.RaiCompanyPermissionAndCheckList(companyId, unify, []string{"调研"})
- if e != nil {
- br.Msg = "获取客户权益权限列表信息失败"
- br.ErrMsg = "获取客户权益权限列表信息失败,Err:" + e.Error()
- return
- }
- if lookType == 1 {
- resp.ListRai = append(resp.ListRai, p)
- } else {
- if len(p.CheckList) > 0 {
- resp.ListRai = append(resp.ListRai, p)
- }
- }
- }
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
|