12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510 |
- 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/response"
- "hongze/hz_crm_api/models/system"
- "hongze/hz_crm_api/services"
- cygxService "hongze/hz_crm_api/services/cygx"
- "os"
- "path/filepath"
- "strconv"
- "strings"
- //"hongze/hz_crm_api/services"
- "hongze/hz_crm_api/utils"
- //"strings"
- "time"
- )
- // 统计报表模块下权益合同合并
- // StatisticReportController 统计报告基类
- type StatisticCompanyMergerController struct {
- BaseAuthController
- }
- // MergeCompanyList
- // @Title 权益客户统计列表(合同进行合并之后的)
- // @Description 权益客户统计列表接口
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param Keyword query string true "客户名称"
- // @Param CompanyType query string true "客户类型:传空字符串或者不传为全部,'ficc','权益'"
- // @Param AdminId query string true "销售id,多个用英文逗号隔开,空字符串为全部"
- // @Param RegionType query string false "所属区域:传空字符串或者不传为全部,'国内','海外'"
- // @Param StartDate query string false "开始日期"
- // @Param EndDate query string false "结束日期"
- // @Param DataType query string false "报表类型,枚举值:`新增试用`,`新签客户`,`续约客户`,`未续约客户`"
- // @Param TryOutType query string false " '试用', '非试用' 非试用即为冻结/流失"
- // @Param IsExport query bool false "是否导出excel,默认是false"
- // @Param IsConfirm query int false "是否确认续约: -1-默认全部; 0-待确认; 1-已确认 ;2-到期合同"
- // @Param CompanyAscribeId query int false "归因ID"
- // @Param PackageDifference query string false "和上一份合同的区别,枚举值:`增加套餐`,`减少套餐`,`维持套餐`"
- // @Success 200 {object} response.IncrementalCompanyListResp
- // @router /merge_company_list [get]
- func (this *StatisticCompanyMergerController) MergeCompanyList() {
- 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
- }
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- adminId := this.GetString("AdminId")
- regionType := this.GetString("RegionType")
- //companyType := this.GetString("CompanyType")
- dataType := this.GetString("DataType")
- tryOutType := this.GetString("TryOutType")
- keyword := this.GetString("Keyword")
- packageDifference := this.GetString("PackageDifference")
- startDate := this.GetString("StartDate")
- endDate := this.GetString("EndDate")
- isConfirm, _ := this.GetInt("IsConfirm", -1)
- companyAscribeId, _ := this.GetInt("CompanyAscribeId", -1)
- if dataType != "续约客户" {
- packageDifference = "" // 只有续约客户才会有值,过滤前端传过来的脏数据
- }
- if startDate == "" {
- startDate = "2015-01-01"
- }
- if endDate == "" {
- endDate = time.Now().Format(utils.FormatDate)
- }
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = utils.StartIndex(currentIndex, pageSize)
- //是否导出报表
- isExport, _ := this.GetBool("IsExport")
- if isExport {
- pageSize = 10000
- currentIndex = 1
- }
- var condition string
- var pars []interface{}
- //条件
- //if adminId != "" {
- // //condition += ` AND a.seller_id_init in (` + adminId + `) `
- // //condition += ` AND c.seller_id in (` + adminId + `) `
- // //pars = append(pars, adminId)
- //} else {
- //
- // //if dataType == "未续约客户" {
- // // //根据当前角色来获取查询条件
- // // condition, pars = getQueryParams(condition, pars, sysUser, "c.")
- // //} else {
- // // //根据当前角色来获取查询条件
- // // condition, pars = getQueryParamsInit(condition, pars, sysUser, "c.")
- // //}
- //
- //}
- if regionType != "" {
- condition += ` AND b.region_type = ? `
- pars = append(pars, regionType)
- }
- //关键字搜索
- if keyword != "" {
- condition += ` and b.company_name like "%` + keyword + `%" `
- }
- var conditionAscribRai string // 处理权益未续约客户检索列表SQL查询条件
- var conditionAscribRaiTotal string // 处理权益未续约客户总量查询条件
- var conditionAscribRaiToBeTotal string // 处理权益未续约客户待确认总量查询条件
- var parsAscribeRai []interface{}
- var parsAscribeRaiTotal []interface{} // 处理权益未续约客户总量查询条件
- var parsAscribeRaiTobeTotal []interface{} // 处理权益未续约客户待确认总量查询条件
- var conditionConfirm string
- var parsConfirm []interface{}
- companyConfirmList, err := company.GetCompanyContractNoRenewedAscribeList(conditionConfirm, parsConfirm, 0, 0)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,GetCompanyNoRenewedAscribeList Err:" + err.Error()
- return
- }
- var noRenewedcompanyContractIds []int //已经确定未续约的公司ID
- if len(companyConfirmList) == 0 {
- noRenewedcompanyContractIds = append(noRenewedcompanyContractIds, 0) // 给一个不存在的ID
- } else {
- for _, v := range companyConfirmList {
- noRenewedcompanyContractIds = append(noRenewedcompanyContractIds, v.CompanyContractId)
- }
- }
- //是否确认续约 CRM 13.9
- conditionAscribRaiTotal += ` AND a.company_contract_id IN (` + utils.GetOrmInReplace(len(noRenewedcompanyContractIds)) + `) ` // 已确认
- parsAscribeRaiTotal = append(parsAscribeRaiTotal, noRenewedcompanyContractIds)
- conditionAscribRaiToBeTotal += ` AND a.company_contract_id NOT IN (` + utils.GetOrmInReplace(len(noRenewedcompanyContractIds)) + `) ` // 待确认
- parsAscribeRaiTobeTotal = append(parsAscribeRaiTobeTotal, noRenewedcompanyContractIds)
- if isConfirm != -1 {
- if isConfirm == 0 {
- conditionAscribRai += ` AND a.company_contract_id NOT IN (` + utils.GetOrmInReplace(len(noRenewedcompanyContractIds)) + `) ` // 待确认
- parsAscribeRai = append(parsAscribeRai, noRenewedcompanyContractIds)
- } else if isConfirm == 1 {
- conditionAscribRai += ` AND a.company_contract_id IN (` + utils.GetOrmInReplace(len(noRenewedcompanyContractIds)) + `) ` // 已确认
- parsAscribeRai = append(parsAscribeRai, noRenewedcompanyContractIds)
- } else if isConfirm == 2 {
- conditionAscribRai += ` AND a.start_date < ? ` // 已确认
- parsAscribeRai = append(parsAscribeRai, time.Now().Format(utils.FormatDate))
- }
- }
- //归因ID CRM 13.9
- if companyAscribeId > 0 {
- var conditionAscribe string
- var parsAscribe []interface{}
- conditionAscribe = " AND company_ascribe_id = ? "
- parsAscribe = append(parsAscribe, companyAscribeId)
- companyNoRenewedAscribeList, err := company.GetCompanyContractNoRenewedAscribeList(conditionAscribe, parsAscribe, 0, 0)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,GetCompanyNoRenewedAscribeList Err:" + err.Error()
- return
- }
- var noRenewedcompanyContractIds []int
- if len(companyNoRenewedAscribeList) == 0 {
- noRenewedcompanyContractIds = append(noRenewedcompanyContractIds, 0) // 给一个不存在的ID
- } else {
- for _, v := range companyNoRenewedAscribeList {
- noRenewedcompanyContractIds = append(noRenewedcompanyContractIds, v.CompanyContractId)
- }
- }
- conditionAscribRai += ` AND a.company_contract_id IN (` + utils.GetOrmInReplace(len(noRenewedcompanyContractIds)) + `)`
- parsAscribeRai = append(parsAscribeRai, noRenewedcompanyContractIds)
- }
- condition += ` AND c.product_id = ? `
- pars = append(pars, 2)
- var list []*models.IncrementalList
- //moreListMap := make(map[int][]*models.IncrementalList)
- var newCompanyTotal int //新签合同数量
- var notRenewalCompanyTotal int //未续约客户数已确认
- var notRenewalCompanyToBeConfirmTotal int //未续约客户数待确认
- var dataTotal, trialTotal, renewalCompanyTotal int
- var notRenewalTryOut, notRenewalNotTryOut int
- //试用客户数
- {
- condition1 := condition
- pars1 := pars
- //销售筛选条件
- if adminId != "" {
- condition1 += ` AND c.seller_id in (` + adminId + `) `
- } else {
- condition1, pars1 = getQueryParams(condition1, pars1, sysUser, "c.")
- }
- condition1 += ` AND a.create_time >= ? AND a.create_time <= ? AND a.operation in ("add","receive") AND b.company_id NOT IN ( SELECT company_id FROM company_operation_record WHERE product_id = 2 AND operation ="loss" GROUP BY company_id ) AND c.status = '试用' `
- pars1 = append(pars1, startDate, endDate)
- total, err := models.GetIncrementalCompanyCountByOperationRecord(condition1, pars1)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- trialTotal = total
- if dataType == "新增试用" {
- //列表数据数量
- total, err := models.GetIncrementalCompanyProductCountByOperationRecord(condition1, pars1)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- //列表页数据
- tmpList, err := models.GetIncrementalCompanyListByOperationRecord(condition1, pars1, startSize, pageSize)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- for _, v := range tmpList {
- v.SellerName = v.SellerNameInit
- }
- list = tmpList
- dataTotal = total
- }
- }
- //新签客户数
- {
- condition1 := condition
- pars1 := pars
- //销售筛选条件
- if adminId != "" {
- condition1 += ` AND a.seller_id_init in (` + adminId + `) `
- } else {
- condition1, pars1 = getQueryParamsInit(condition1, pars1, sysUser, "c.")
- }
- condition1 += ` AND a.status = 1 AND a.start_date >= ? AND a.start_date <= ? `
- pars1 = append(pars1, startDate, endDate)
- condition1 += ` AND a.rai_contract_type = ? `
- pars1 = append(pars1, "新签合同")
- newCompanyTotal, err = company.GetIncrementalNewCompanyProductMergeCount(condition1, pars1)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if dataType == "新签客户" {
- //列表数据数量
- total, err := company.GetIncrementalNewCompanyProductMergeCount(condition1, pars1)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- //列表页数据
- tmpList, err := models.GetIncrementalCompanyMergeList(condition1, pars1, startSize, pageSize)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- list = tmpList
- dataTotal = total
- }
- }
- //续约客户数
- {
- condition1 := condition
- pars1 := pars
- condition1 += ` AND a.status = 1 AND a.start_date >= ? AND a.start_date <= ? `
- pars1 = append(pars1, startDate, endDate)
- condition1 += ` AND a.rai_contract_type = ? `
- pars1 = append(pars1, "续约合同")
- //销售筛选条件
- if adminId != "" {
- condition1 += ` AND a.seller_id_init in (` + adminId + `) `
- } else {
- condition1, pars1 = getQueryParamsInit(condition1, pars1, sysUser, "c.")
- }
- ////额外条件(续约合同的起始日期包含在所选时间段内且不包含在新签合同存续期内的客户)
- //pars1 = append(pars1, endDate)
- total, err := company.GetIncrementalNewCompanyProductMergeCount(condition1, pars1)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- renewalCompanyTotal = total
- if dataType == "续约客户" {
- //续约的客户才会查询
- if packageDifference != "" {
- condition1 += ` AND a.package_difference = ? `
- pars1 = append(pars1, packageDifference)
- }
- //列表数据数量
- total, err := company.GetIncrementalRenewalCompanyProductMergeCount(condition1, pars1)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- //列表页数据
- tmpList, err := models.GetIncrementalCompanyMergeList(condition1, pars1, startSize, pageSize)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- list = tmpList
- dataTotal = total
- }
- }
- //未续约客户数
- {
- condition1 := condition
- pars1 := pars
- condition1 += condition
- pars1 = append(pars1, pars)
- condition1 += ` AND a.not_renewal_hide = 0 AND a.status = 1 AND a.start_date >= '2020-01-01' AND a.end_date >= ? AND a.end_date <= ? `
- pars1 = append(pars1, startDate, endDate)
- //condition1 += ` AND a.operation = ? `
- //pars1 = append(pars1, "try_out")
- condition1 += ` AND c.status not in ("永续","正式","关闭") `
- //销售筛选条件
- if adminId != "" {
- condition1 += ` AND c.seller_id_last in (` + adminId + `) `
- } else {
- condition1, pars1 = getQueryParamsLast(condition1, pars1, sysUser, "c.")
- }
- //未续约已确认数量
- notRenewalCondition := condition1
- notRenewalPars := pars1
- notRenewalCondition += conditionAscribRaiTotal
- notRenewalPars = append(notRenewalPars, parsAscribeRaiTotal)
- total, err := company.GetIncrementalRenewalCompanyProductMergeCount(notRenewalCondition, notRenewalPars)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- notRenewalCompanyTotal = total
- //未续约待确认数量
- notRenewalToBeCondition := condition1
- notRenewalToBePars := pars1
- notRenewalToBeCondition += conditionAscribRaiToBeTotal
- notRenewalToBePars = append(notRenewalToBePars, parsAscribeRaiTobeTotal)
- notRenewalCompanyToBeConfirmTotal, err = company.GetIncrementalRenewalCompanyProductMergeCount(notRenewalToBeCondition, notRenewalToBePars)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- condition1 += conditionAscribRai
- pars1 = append(pars1, parsAscribeRai)
- if dataType == "未续约客户" {
- //统计数据
- for _, v := range []string{"试用", "非试用"} {
- totalCondition1 := condition1
- totalPars1 := pars1
- var tmpTotal int
- if v == "试用" {
- totalCondition1 += ` AND c.status = "试用" `
- tmpTotal, err = company.GetIncrementalRenewalCompanyProductMergeCount(totalCondition1, totalPars1)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- notRenewalTryOut = tmpTotal
- } else if v == "非试用" {
- totalCondition1 += ` AND c.status IN ("冻结","流失") `
- tmpTotal, err = company.GetIncrementalRenewalCompanyProductMergeCount(totalCondition1, totalPars1)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- notRenewalNotTryOut = tmpTotal
- }
- }
- //列表数据数量
- if tryOutType == "试用" {
- condition1 += ` AND c.status = "试用" `
- total = notRenewalTryOut
- } else if tryOutType == "非试用" {
- condition1 += ` AND c.status IN ("冻结","流失") `
- total = notRenewalNotTryOut
- }
- //分页total单独计算
- total, err = company.GetIncrementalRenewalCompanyProductMergeCount(condition1, pars1)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- //return
- //列表页数据
- tmpList, err := models.GetIncrementalCompanyListByOperationRecordMerge(condition1, pars1, startSize, pageSize)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- var ascribecompanyIds []int
- var companyContractIds []int
- for _, item := range tmpList {
- //endDateTime, _ := time.Parse(utils.FormatDateTime, item.CreateTime)
- //item.EndDate = endDateTime.Format(utils.FormatDate)
- ascribecompanyIds = append(ascribecompanyIds, item.CompanyId)
- companyContractIds = append(companyContractIds, item.CompanyContractId)
- }
- //合同归因标签
- mapGetCompanyAscribeContent, mapContent := services.GetCompanyContractAscribeContentMap(companyContractIds)
- mapNoRenewedNote := services.GetCompanyNoRenewedNoteMap(ascribecompanyIds)
- for _, item := range tmpList {
- item.AscribeContent = mapGetCompanyAscribeContent[item.CompanyContractId]
- item.Content = mapContent[item.CompanyContractId]
- item.IsShowNoRenewedNote = mapNoRenewedNote[fmt.Sprint("CID_", item.CompanyId, "PID_", item.ProductId)]
- }
- list = tmpList
- dataTotal = total
- }
- }
- listLen := len(list)
- if listLen == 0 {
- list = make([]*models.IncrementalList, 0)
- }
- var companyContractIds []int
- var companyIds []int
- for i := 0; i < listLen; i++ {
- item := list[i]
- companyContractIds = append(companyContractIds, item.CompanyContractId)
- //新增试用不需要计算剩余日期
- if dataType != "新增试用" {
- //剩余可用天数
- endDateTime, _ := time.Parse(utils.FormatDate, item.EndDate)
- endDateTime = endDateTime.AddDate(0, 0, 1)
- sub := endDateTime.Sub(time.Now())
- expireDay := fmt.Sprintf("%v", int(sub.Hours()/24))
- list[i].ExpireDay = expireDay
- }
- companyIds = append(companyIds, item.CompanyId)
- }
- //合并合同所对应的权限
- mappermissionName, err := cygxService.GetCompanyContractPermissionNameMapById(companyContractIds)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- mapIsUserMaker := cygxService.GetCompanyProductIsUserMakerByCompanyIds(companyIds) //根据公司ID获取近四周之内有决策人互动的客户
- for _, v := range list {
- v.PermissionName = mappermissionName[v.CompanyContractId]
- v.IsUserMaker = mapIsUserMaker[v.CompanyId]
- }
- page := paging.GetPaging(currentIndex, pageSize, dataTotal)
- resp := response.IncrementalCompanyListResp{
- Paging: page,
- List: list,
- TrialTotal: trialTotal,
- NewCompanyTotal: newCompanyTotal,
- RenewalCompanyTotal: renewalCompanyTotal,
- NotRenewalCompanyTotal: notRenewalCompanyTotal,
- NotRenewalCompanyToBeConfirmTotal: notRenewalCompanyToBeConfirmTotal,
- NotRenewalTryOut: notRenewalTryOut,
- NotRenewalNotTryOut: notRenewalNotTryOut,
- }
- //fmt.Println()
- //导出excel
- if isExport {
- MergeCompanyListListExport(this, dataType, resp, br)
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // IncrementalCompanyListExport 导出增量客户数据报表excel
- func MergeCompanyListListExport(this *StatisticCompanyMergerController, dataType string, resp response.IncrementalCompanyListResp, br *models.BaseResponse) {
- 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(0, 0, 30)
- sheel.SetColWidth(1, 1, 15)
- sheel.SetColWidth(2, 2, 15)
- sheel.SetColWidth(3, 3, 18)
- sheel.SetColWidth(4, 4, 40)
- sheel.SetColWidth(5, 5, 18)
- //统计数据
- statisticRow := sheel.AddRow()
- cell1 := statisticRow.AddCell()
- cell1.SetStyle(style)
- cell1.SetValue(fmt.Sprint("新增试用客户数:", resp.TrialTotal))
- cell2 := statisticRow.AddCell()
- cell2.SetStyle(style)
- cell2.SetValue(fmt.Sprint("新签客户数:", resp.NewCompanyTotal))
- cell3 := statisticRow.AddCell()
- cell3.SetStyle(style)
- cell3.SetValue(fmt.Sprint("续约客户数:", resp.RenewalCompanyTotal))
- cell4 := statisticRow.AddCell()
- cell4.SetStyle(style)
- cell4.SetValue(fmt.Sprint("未续约客户数:", resp.NotRenewalCompanyTotal))
- //表头
- titleRow := sheel.AddRow()
- cellName := titleRow.AddCell()
- cellName.SetStyle(style)
- cellName.SetValue("客户名称")
- //cellProName := titleRow.AddCell()
- //cellProName.SetStyle(style)
- //cellProName.SetValue("客户类型")
- cellSellerName := titleRow.AddCell()
- cellSellerName.SetStyle(style)
- cellSellerName.SetValue("所属销售")
- if dataType != "新增试用" {
- cellShareSeller := titleRow.AddCell()
- cellShareSeller.SetStyle(style)
- cellShareSeller.SetValue("服务销售")
- cellMoney := titleRow.AddCell()
- cellMoney.SetStyle(style)
- cellMoney.SetValue("合同金额")
- }
- cellTime := titleRow.AddCell()
- cellTime.SetStyle(style)
- switch dataType {
- case "新增试用":
- cellTime.SetValue("新增时间")
- case "新签客户":
- cellTime.SetValue("合同期限")
- case "续约客户":
- cellTime.SetValue("合同期限")
- case "未续约客户":
- cellTime.SetValue("合同期限")
- cellAscribeContent := titleRow.AddCell()
- cellAscribeContent.SetStyle(style)
- cellAscribeContent.SetValue("不续约归因")
- cellContent := titleRow.AddCell()
- cellContent.SetStyle(style)
- cellContent.SetValue("详细原因")
- }
- if dataType != "新增试用" {
- cellPermissionName := titleRow.AddCell()
- cellPermissionName.SetStyle(style)
- cellPermissionName.SetValue("签约套餐")
- }
- for _, v := range resp.List {
- dataRow := sheel.AddRow()
- dataRow.SetHeight(20)
- cellDataName := dataRow.AddCell()
- cellDataName.SetStyle(style)
- cellDataName.SetValue(v.CompanyName)
- //cellDataProName := dataRow.AddCell()
- //cellDataProName.SetStyle(style)
- //cellDataProName.SetValue(v.ProductName)
- cellDataSellerName := dataRow.AddCell()
- cellDataSellerName.SetStyle(style)
- cellDataSellerName.SetValue(v.SellerName)
- if dataType != "新增试用" {
- cellDataShareSeller := dataRow.AddCell()
- cellDataShareSeller.SetStyle(style)
- cellDataShareSeller.SetValue(v.ShareSeller)
- cellDataMoney := dataRow.AddCell()
- cellDataMoney.SetStyle(style)
- cellDataMoney.SetValue(v.Money)
- }
- //if dataType == "新签客户" || dataType == "续约客户" {
- //}
- cellDataTime := dataRow.AddCell()
- cellDataTime.SetStyle(style)
- switch dataType {
- case "新增试用":
- cellDataTime.SetValue(v.CreateTime)
- case "新签客户":
- cellDataTime.SetValue(fmt.Sprint(v.StartDate, " ~ ", v.EndDate))
- case "续约客户":
- cellDataTime.SetValue(fmt.Sprint(v.StartDate, " ~ ", v.EndDate))
- case "未续约客户":
- cellDataTime.SetValue(fmt.Sprint(v.StartDate, " ~ ", v.EndDate))
- cellAscribeContent := dataRow.AddCell()
- cellAscribeContent.SetStyle(style)
- cellAscribeContent.SetValue(v.AscribeContent)
- cellContent := dataRow.AddCell()
- cellContent.SetStyle(style)
- cellContent.SetValue(v.Content)
- }
- cellDataPermissionName := dataRow.AddCell()
- cellDataPermissionName.SetStyle(style)
- cellDataPermissionName.SetValue(v.PermissionName)
- }
- err = xlsxFile.Save(downLoadnFilePath)
- if err != nil {
- br.Msg = "保存文件失败"
- br.ErrMsg = "保存文件失败"
- return
- }
- randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
- downloadFileName := dataType + "数据_" + randStr + ".xlsx"
- this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
- defer func() {
- os.Remove(downLoadnFilePath)
- }()
- br.Ret = 200
- br.Success = true
- br.Msg = "导出成功"
- }
- // @Title 上一份合同详情
- // @Description 上一份合同详情接口
- // @Param CompanyContractId query int true "合同ID"
- // @Success Ret=200 {object} company.GetCompanyContractMergeDetailResp
- // @router /merge_company_previous/detail [get]
- func (this *StatisticCompanyMergerController) CompanyPreviousDetail() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- AdminUser := this.SysUser
- if AdminUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,用户信息为空"
- br.Ret = 408
- return
- }
- resp := new(company.GetCompanyContractDetailResp)
- companyContractId, _ := this.GetInt("CompanyContractId")
- if companyContractId < 1 {
- br.Msg = "请输入合同ID"
- return
- }
- var condition string
- var pars []interface{}
- //获取最新的一条到期的合同信息
- condition = " AND company_contract_id = ? "
- pars = append(pars, companyContractId)
- detail, err := company.GetCompanyContracDetail(condition, pars)
- if err != nil {
- br.Msg = "详情不存在"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- //获取前一份合同的信息
- pars = make([]interface{}, 0)
- condition = " AND company_id = ? AND company_contract_id < ? AND status = 1 AND product_id = 2 ORDER BY company_contract_id DESC LIMIT 1 "
- pars = append(pars, detail.CompanyId, companyContractId)
- detailPrevious, err := company.GetCompanyContracDetail(condition, pars)
- if err != nil {
- br.Msg = "详情不存在"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- //合并合同所对应的权限
- mappermissionName, err := cygxService.GetCompanyContractPermissionNameMapById([]int{detailPrevious.CompanyContractId})
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- detailPrevious.PermissionName = mappermissionName[detailPrevious.CompanyContractId]
- resp.Detail = detailPrevious
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // @Title 权益行业套餐统计
- // @Description 权益客户统计列表接口
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param Keyword query string true "客户名称"
- // @Param AdminId query string true "销售id,多个用英文逗号隔开,空字符串为全部"
- // @Param StartDate query string false "开始日期"
- // @Param EndDate query string false "结束日期"
- // @Param DataType query string false "报表类型,枚举值:`行业新签`,`行业续约`,`行业未续约`"
- // @Param PermissionName query string false "行业权限名称"
- // @Param IsExport query bool false "是否导出excel,默认是false"
- // @Success 200 {object} response.IncrementalCompanyListResp
- // @router /merge_company/company_contract_permission/list [get]
- func (this *StatisticCompanyMergerController) CompanyContractPermissionList() {
- 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
- }
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- adminId := this.GetString("AdminId")
- regionType := this.GetString("RegionType")
- //companyType := this.GetString("CompanyType")
- dataType := this.GetString("DataType")
- keyword := this.GetString("Keyword")
- startDate := this.GetString("StartDate")
- endDate := this.GetString("EndDate")
- permissionName := this.GetString("PermissionName")
- if permissionName == "" { //默认所筛选行业为医药
- permissionName = "医药"
- }
- //if startDate == "" || endDate == "" {
- // br.Msg = "获取失败,开始日期或结束日期未传"
- // br.ErrMsg = "获取失败,开始日期或结束日期未传"
- // return
- //}
- if startDate == "" {
- startDate = "2015-01-01"
- }
- if endDate == "" {
- endDate = time.Now().Format(utils.FormatDate)
- }
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = utils.StartIndex(currentIndex, pageSize)
- //是否导出报表
- isExport, _ := this.GetBool("IsExport")
- if isExport {
- pageSize = 10000
- currentIndex = 1
- permissionName = "" //点击下载的时候不做行业筛选
- }
- var condition string
- var pars []interface{}
- //条件
- if adminId != "" {
- condition += ` AND c.seller_id in (` + adminId + `) `
- //pars = append(pars, adminId)
- } else {
- //根据当前角色来获取查询条件
- condition, pars = getQueryParams(condition, pars, sysUser, "c.")
- }
- if regionType != "" {
- condition += ` AND b.region_type = ? `
- pars = append(pars, regionType)
- }
- //关键字搜索
- if keyword != "" {
- condition += ` and b.company_name like "%` + keyword + `%" `
- }
- var conditionAscribRai string // 处理权益未续约客户检索列表SQL查询条件
- var conditionAscribRaiTotal string // 处理权益未续约客户总量查询条件
- var parsAscribeRai []interface{}
- var parsAscribeRaiTotal []interface{} // 处理权益未续约客户总量查询条件
- condition += ` AND c.product_id = ? AND a.status = 1 `
- pars = append(pars, 2)
- var list []*models.IncrementalList
- var listPessionGroup []*models.CompanyContractPermissionNameGroupCountResp
- var newCompanyTotal int //新签合同数量
- var notRenewalCompanyTotal int //未续约客户数已确认
- var notRenewalCompanyToBeConfirmTotal int //未续约客户数待确认
- var dataTotal, trialTotal, renewalCompanyTotal int
- var notRenewalTryOut, notRenewalNotTryOut int
- //if dataType == "行业未续约" {
- // condition += ` AND a.end_date >= ? AND a.end_date <= ? `
- // pars = append(pars, startDate, endDate)
- //} else {
- // condition += ` AND a.start_date >= ? AND a.start_date <= ? `
- // pars = append(pars, startDate, endDate)
- //}
- //
- //conditionPerssion := condition
- //parsPerssion := pars
- //conditionPerssion += ` AND d.permission_name IN ('医药','消费','科技','智造','策略','买方研选')`
- //
- //listPessionGroup, err := models.GetCompanyContractPermissionNameGroupCount(conditionPerssion, parsPerssion)
- //if err != nil && err.Error() != utils.ErrNoRow() {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取失败,Err:" + err.Error()
- // return
- //}
- //if permissionName == "" {
- condition += ` AND d.permission_name IN ('医药','消费','科技','智造','策略','研选订阅','研选扣点包')`
- //}
- var err error
- //新签客户数
- {
- condition1 := condition
- pars1 := pars
- condition1 += ` AND a.start_date >= ? AND a.start_date <= ? `
- pars1 = append(pars1, startDate, endDate)
- condition1 += ` AND d.contract_type = ? `
- pars1 = append(pars1, "行业新签")
- newCompanyTotal, err = company.GetIncrementalNewCompanyProductPermissionCount(condition1, pars1)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if dataType == "行业新签" {
- conditionPerssion := condition1
- parsPerssion := pars1
- conditionPerssion += ` AND d.permission_name IN ('医药','消费','科技','智造','策略','研选订阅','研选扣点包')`
- listPessionGroup, err = models.GetCompanyContractPermissionNameGroupCount(conditionPerssion, parsPerssion)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- //行业筛选查询
- if permissionName != "" {
- condition1 += ` AND d.permission_name = ? `
- pars1 = append(pars1, permissionName)
- }
- total, err := company.GetIncrementalNewCompanyProductPermissionCount(condition1, pars1)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- //列表页数据
- tmpList, err := models.GetIncrementalCompanyPermissionList(condition1, pars1, startSize, pageSize)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- list = tmpList
- dataTotal = total
- }
- }
- //续约客户数
- {
- condition1 := condition
- pars1 := pars
- condition1 += ` AND a.start_date >= ? AND a.start_date <= ? `
- pars1 = append(pars1, startDate, endDate)
- condition1 += ` AND d.contract_type = ? `
- pars1 = append(pars1, "行业续约")
- ////额外条件(续约合同的起始日期包含在所选时间段内且不包含在新签合同存续期内的客户)
- //pars1 = append(pars1, endDate)
- total, err := company.GetIncrementalNewCompanyProductPermissionCount(condition1, pars1)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- renewalCompanyTotal = total
- if dataType == "行业续约" {
- conditionPerssion := condition1
- parsPerssion := pars1
- conditionPerssion += ` AND d.permission_name IN ('医药','消费','科技','智造','策略','研选订阅','研选扣点包')`
- listPessionGroup, err = models.GetCompanyContractPermissionNameGroupCount(conditionPerssion, parsPerssion)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- //行业筛选查询
- if permissionName != "" {
- condition1 += ` AND d.permission_name = ? `
- pars1 = append(pars1, permissionName)
- }
- //列表数据数量
- total, err := company.GetIncrementalNewCompanyProductPermissionCount(condition1, pars1)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- //列表页数据
- tmpList, err := models.GetIncrementalCompanyPermissionList(condition1, pars1, startSize, pageSize)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- list = tmpList
- dataTotal = total
- }
- }
- //return
- //行业未续约
- {
- condition1 := condition
- pars1 := pars
- condition1 += ` AND a.end_date >= ? AND a.end_date <= ? `
- pars1 = append(pars1, startDate, endDate)
- condition1 += ` AND c.status not in ("永续","正式","关闭") `
- //未续约数量
- notRenewalCondition := condition1
- notRenewalPars := pars1
- notRenewalCondition += conditionAscribRaiTotal
- notRenewalPars = append(notRenewalPars, parsAscribeRaiTotal)
- total, err := company.GetIncrementalNewCompanyProductPermissionCount(notRenewalCondition, notRenewalPars)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- notRenewalCompanyTotal = total
- condition1 += conditionAscribRai
- pars1 = append(pars1, parsAscribeRai)
- if dataType == "行业未续约" {
- conditionPerssion := condition1
- parsPerssion := pars1
- conditionPerssion += ` AND d.permission_name IN ('医药','消费','科技','智造','策略','研选订阅','研选扣点包')`
- listPessionGroup, err = models.GetCompanyContractPermissionNameGroupCount(conditionPerssion, parsPerssion)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- //行业筛选查询
- if permissionName != "" {
- condition1 += ` AND d.permission_name = ? `
- pars1 = append(pars1, permissionName)
- }
- //分页total单独计算
- total, err = company.GetIncrementalNewCompanyProductPermissionCount(condition1, pars1)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- //return
- //列表页数据
- tmpList, err := models.GetIncrementalCompanyPermissionList(condition1, pars1, startSize, pageSize)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- list = tmpList
- dataTotal = total
- }
- }
- listLen := len(list)
- if listLen == 0 {
- list = make([]*models.IncrementalList, 0)
- }
- var companyContractIds []int
- var companyIds []int
- for i := 0; i < listLen; i++ {
- item := list[i]
- companyContractIds = append(companyContractIds, item.CompanyContractId)
- companyIds = append(companyIds, item.CompanyId)
- //新增试用不需要计算剩余日期
- if dataType != "新增试用" {
- //剩余可用天数
- endDateTime, _ := time.Parse(utils.FormatDate, item.EndDate)
- endDateTime = endDateTime.AddDate(0, 0, 1)
- sub := endDateTime.Sub(time.Now())
- expireDay := fmt.Sprintf("%v", int(sub.Hours()/24))
- list[i].ExpireDay = expireDay
- }
- }
- //行业未续约 需要处理公司对应行业权限下的权限状态
- if dataType == "行业未续约" {
- mappermissionNameStatus, err := cygxService.GetCompanyPermissionNameStatusMapByCompanyId(companyIds)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- for _, v := range list {
- v.PermissionNameStatus = mappermissionNameStatus[fmt.Sprint(v.CompanyId, v.PermissionNameExport)]
- }
- }
- //合并合同所对应的权限
- mappermissionName, err := cygxService.GetCompanyContractPermissionNameMapById(companyContractIds)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- for _, v := range list {
- v.PermissionName = mappermissionName[v.CompanyContractId]
- }
- //处理展示顺序
- permissionNameSlice := []string{"医药", "消费", "科技", "智造", "策略", utils.CHART_PERMISSION_NAME_MF_YANXUAN, utils.YAN_XUAN_KOU_DIAN_BAO_NAME}
- var itemspermissionNameSlice []*models.CompanyContractPermissionNameGroupCountResp
- for _, vName := range permissionNameSlice {
- item := new(models.CompanyContractPermissionNameGroupCountResp)
- for _, v := range listPessionGroup {
- if v.PermissionName != vName {
- continue
- }
- item.Total = v.Total
- }
- item.PermissionName = vName
- itemspermissionNameSlice = append(itemspermissionNameSlice, item)
- }
- page := paging.GetPaging(currentIndex, pageSize, dataTotal)
- resp := response.IncrementalCompanyListResp{
- Paging: page,
- ListPermissionName: itemspermissionNameSlice,
- List: list,
- TrialTotal: trialTotal,
- NewCompanyTotal: newCompanyTotal,
- RenewalCompanyTotal: renewalCompanyTotal,
- NotRenewalCompanyTotal: notRenewalCompanyTotal,
- NotRenewalCompanyToBeConfirmTotal: notRenewalCompanyToBeConfirmTotal,
- NotRenewalTryOut: notRenewalTryOut,
- NotRenewalNotTryOut: notRenewalNotTryOut,
- }
- //fmt.Println()
- //导出excel
- if isExport {
- PermissionCompanyListListExport(this, dataType, resp, br)
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // PermissionCompanyListListExport 导出增量客户数据报表excel
- func PermissionCompanyListListExport(this *StatisticCompanyMergerController, dataType string, resp response.IncrementalCompanyListResp, br *models.BaseResponse) {
- 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,
- }
- permissionNameSlice := []string{"医药", "消费", "科技", "智造", "策略", "买方研选"}
- mapExport := make(map[string][]*models.IncrementalList)
- type IncrementalCompanyListExport struct {
- PermissionName string `description:"权限名"`
- List []*models.IncrementalList
- }
- for _, v := range resp.List {
- if v.PermissionNameExport == "" {
- continue
- }
- mapExport[v.PermissionNameExport] = append(mapExport[v.PermissionNameExport], v)
- }
- style.Alignment = alignment
- style.ApplyAlignment = true
- for _, vName := range permissionNameSlice {
- sheel, err := xlsxFile.AddSheet(vName)
- if err != nil {
- br.Msg = "新增Sheet失败"
- br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
- return
- }
- sheel.SetColWidth(0, 0, 30)
- sheel.SetColWidth(1, 1, 15)
- sheel.SetColWidth(2, 2, 15)
- sheel.SetColWidth(3, 3, 18)
- sheel.SetColWidth(4, 4, 40)
- sheel.SetColWidth(5, 5, 18)
- //表头
- titleRow := sheel.AddRow()
- cellName := titleRow.AddCell()
- cellName.SetStyle(style)
- cellName.SetValue("客户名称")
- cellSellerName := titleRow.AddCell()
- cellSellerName.SetStyle(style)
- cellSellerName.SetValue("所属销售")
- cellMoney := titleRow.AddCell()
- cellMoney.SetStyle(style)
- cellMoney.SetValue("合同金额")
- cellTime := titleRow.AddCell()
- cellTime.SetStyle(style)
- cellTime.SetValue("合同期限")
- cellPermissionName := titleRow.AddCell()
- cellPermissionName.SetStyle(style)
- cellPermissionName.SetValue("签约套餐")
- if dataType == "行业未续约" {
- cellPermissionNameStatus := titleRow.AddCell()
- cellPermissionNameStatus.SetStyle(style)
- cellPermissionNameStatus.SetValue("当前行业状态")
- cellCompanyProductStatus := titleRow.AddCell()
- cellCompanyProductStatus.SetStyle(style)
- cellCompanyProductStatus.SetValue("当前客户状态")
- }
- for _, v := range mapExport[vName] {
- dataRow := sheel.AddRow()
- dataRow.SetHeight(20)
- cellDataName := dataRow.AddCell()
- cellDataName.SetStyle(style)
- cellDataName.SetValue(v.CompanyName)
- cellDataSellerName := dataRow.AddCell()
- cellDataSellerName.SetStyle(style)
- cellDataSellerName.SetValue(v.SellerName)
- cellDataMoney := dataRow.AddCell()
- cellDataMoney.SetStyle(style)
- cellDataMoney.SetValue(v.Money)
- cellDataTime := dataRow.AddCell()
- cellDataTime.SetStyle(style)
- cellDataTime.SetValue(v.StartDate + "~" + v.EndDate)
- cellDataPermissionName := dataRow.AddCell()
- cellDataPermissionName.SetStyle(style)
- cellDataPermissionName.SetValue(v.PermissionName)
- if dataType == "行业未续约" {
- cellDataPermissionNameStatus := dataRow.AddCell()
- cellDataPermissionNameStatus.SetStyle(style)
- cellDataPermissionNameStatus.SetValue(v.PermissionNameStatus)
- cellDataCompanyProductStatus := dataRow.AddCell()
- cellDataCompanyProductStatus.SetStyle(style)
- cellDataCompanyProductStatus.SetValue(v.CompanyProductStatus)
- }
- }
- }
- err = xlsxFile.Save(downLoadnFilePath)
- if err != nil {
- br.Msg = "保存文件失败"
- br.ErrMsg = "保存文件失败"
- return
- }
- randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
- downloadFileName := dataType + "数据_" + randStr + ".xlsx"
- this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
- defer func() {
- os.Remove(downLoadnFilePath)
- }()
- br.Ret = 200
- br.Success = true
- br.Msg = "导出成功"
- }
- // @Title 权益客户续约率统计
- // @Description 权益客户续约率统计接口
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param AdminId query string true "销售id,多个用英文逗号隔开,空字符串为全部"
- // @Param StartDate query string false "开始日期"
- // @Param EndDate query string false "结束日期"
- // @Param ContractDataType query string false "合同类型,枚举值:`续约合同`,`到期合同`"
- // @Success 200 {object} response.IncrementalCompanyListResp
- // @router /merge_company/company_contract_percentage/list [get]
- func (this *StatisticCompanyMergerController) CompanyContractPercentageList() {
- 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
- }
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- adminId := this.GetString("AdminId")
- contractDataType := this.GetString("ContractDataType")
- startDate := this.GetString("StartDate")
- endDate := this.GetString("EndDate")
- initendDate := this.GetString("EndDate")
- if startDate == "" || endDate == "" {
- br.Msg = "开始时间或结束时间不能为空"
- return
- }
- //如果传的查询方式是今年,那么就以当前时间作为截止时间
- //if endDate == strconv.Itoa(time.Now().Year())+"-12-31" {
- // endDate = time.Now().Format(utils.FormatDate)
- //}
- //判断结束时间是否晚于当前时间,如果晚于当前时间,那么就把当前时间作为截止时间。
- endDateTime, _ := time.Parse(utils.FormatDate, endDate)
- if endDateTime.After(time.Now()) {
- endDate = time.Now().Format(utils.FormatDate)
- }
- //fmt.Println("endDate", endDate)
- if contractDataType == "" {
- contractDataType = "续约合同"
- }
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = utils.StartIndex(currentIndex, pageSize)
- var condition string
- var pars []interface{}
- //条件
- if adminId != "" {
- condition += ` AND c.seller_id in (` + adminId + `) `
- } else {
- //根据当前角色来获取查询条件
- condition, pars = getQueryParams(condition, pars, sysUser, "c.")
- }
- //权益有效合同
- condition += ` AND c.product_id = 2 AND a.status = 1 `
- var list []*models.IncrementalList
- var renewalRateMoney string //合同金额续约率
- var renewalRateMoneyContent string //合同金额续约率详情
- var renewalRateTotal string //合同数量续约率
- var renewalRateTotalContent string //合同数量续约率详情
- var renewalContractTotal int //续约合同数量
- var renewalContractMoney int //续约合同数量
- var expireRenewalContractTotal int //到期合同数量
- var expireRenewalContractMoney int //到期合同数量
- var dataTotal int //分页数据
- conditionRenewal := condition // 续约合同查询条件查询条件
- parsRenewal := pars
- conditionRenewal += ` AND a.start_date >= ? AND a.start_date <= ? `
- parsRenewal = append(parsRenewal, startDate, endDate)
- conditionRenewal += ` AND a.rai_contract_type = ? `
- parsRenewal = append(parsRenewal, "续约合同")
- totalRenewal, err := company.GetIncrementalRenewalCompanyProductMergeCount(conditionRenewal, parsRenewal)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- totalMoneyRenewal, err := company.GetIncrementalRenewalCompanyProductMergeSumMoney(conditionRenewal, parsRenewal)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- //续约合同查询条件查询条件 end
- conditionRenewalEnd := condition // 今年结束的续约合同查询条件
- parsRenewalEnd := pars
- conditionRenewalEnd += ` AND a.end_date >= ? AND a.end_date <= ? `
- parsRenewalEnd = append(parsRenewalEnd, startDate, endDate)
- conditionRenewalEnd += ` AND a.rai_contract_type = ? `
- parsRenewalEnd = append(parsRenewalEnd, "续约合同")
- totalRenewalEnd, err := company.GetIncrementalRenewalCompanyProductMergeCount(conditionRenewalEnd, parsRenewalEnd)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- totalMoneyRenewalEnd, err := company.GetIncrementalRenewalCompanyProductMergeSumMoney(conditionRenewalEnd, parsRenewalEnd)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- } // 今年结束的续约合同查询条件end
- conditionNew := condition // 新签合同查询条件
- parsNew := pars
- conditionNew += ` AND a.end_date >= ? AND a.end_date <= ? `
- parsNew = append(parsNew, startDate, endDate)
- conditionNew += ` AND a.rai_contract_type = ? `
- parsNew = append(parsNew, "新签合同")
- totalNew, err := company.GetIncrementalRenewalCompanyProductMergeCount(conditionNew, parsNew)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- totalMoneyNew, err := company.GetIncrementalRenewalCompanyProductMergeSumMoney(conditionNew, parsNew)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- } // 新签合同查询条件 end
- //分子或者分母为零的时候,不做计算
- if totalRenewal == 0 || totalNew+totalRenewalEnd == 0 {
- renewalRateMoney = "0%"
- renewalRateTotal = "0%"
- } else {
- renewalRateMoney = fmt.Sprint(utils.SubFloatToString(float64(totalMoneyRenewal)/float64(totalMoneyNew+totalMoneyRenewalEnd)*100, 2), "%")
- renewalRateTotal = fmt.Sprint(utils.SubFloatToString(float64(totalRenewal)/float64(totalNew+totalRenewalEnd)*100, 2), "%")
- }
- renewalRateTotalContent = fmt.Sprint(int(totalMoneyRenewal), "/", int(totalMoneyNew+totalMoneyRenewalEnd))
- renewalRateMoneyContent = fmt.Sprint(totalRenewal, "份/", totalNew+totalRenewalEnd, "份")
- if contractDataType == "续约合同" {
- condition1 := condition
- pars1 := pars
- condition1 += ` AND a.start_date >= ? AND a.start_date <= ? `
- pars1 = append(pars1, startDate, endDate)
- condition1 += ` AND a.rai_contract_type = ? `
- pars1 = append(pars1, "续约合同")
- total, err := company.GetIncrementalRenewalCompanyProductMergeCount(condition1, pars1)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- totalMoney, err := company.GetIncrementalRenewalCompanyProductMergeSumMoney(condition1, pars1)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- renewalContractTotal = total
- renewalContractMoney = int(totalMoney)
- //列表页数据
- tmpList, err := models.GetIncrementalCompanyMergeList(condition1, pars1, startSize, pageSize)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- list = tmpList
- dataTotal = total
- }
- if contractDataType == "到期合同" {
- condition1 := condition
- pars1 := pars
- //判断结束时间是否晚于当前时间,如果晚于当前时间,那么就把当前时间作为截止时间。并且当前这天的到期的合同,不查询
- endDateTime, _ := time.Parse(utils.FormatDate, initendDate)
- if endDateTime.After(time.Now()) {
- endDate = time.Now().Format(utils.FormatDate)
- condition1 += ` AND a.end_date >= ? AND a.end_date < ? `
- } else {
- condition1 += ` AND a.end_date >= ? AND a.end_date <= ? `
- }
- //condition1 += ` AND a.end_date >= ? AND a.end_date <= ? `
- pars1 = append(pars1, startDate, endDate)
- total, err := company.GetIncrementalRenewalCompanyProductMergeCount(condition1, pars1)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- totalMoney, err := company.GetIncrementalRenewalCompanyProductMergeSumMoney(condition1, pars1)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- expireRenewalContractTotal = total
- expireRenewalContractMoney = int(totalMoney)
- //列表页数据
- tmpList, err := models.GetIncrementalCompanyMergeListEnd(condition1, pars1, startSize, pageSize)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- list = tmpList
- dataTotal = total
- }
- listLen := len(list)
- if listLen == 0 {
- list = make([]*models.IncrementalList, 0)
- }
- var companyContractIds []int
- for i := 0; i < listLen; i++ {
- item := list[i]
- companyContractIds = append(companyContractIds, item.CompanyContractId)
- }
- //合并合同所对应的权限
- mappermissionName, err := cygxService.GetCompanyContractPermissionNameMapById(companyContractIds)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- for _, v := range list {
- v.PermissionName = mappermissionName[v.CompanyContractId]
- }
- page := paging.GetPaging(currentIndex, pageSize, dataTotal)
- resp := response.IncrementalCompanyPercentageListResp{
- Paging: page,
- RenewalContractTotal: renewalContractTotal,
- RenewalContractMoney: renewalContractMoney,
- ExpireRenewalContractTotal: expireRenewalContractTotal,
- ExpireRenewalContractMoney: expireRenewalContractMoney,
- RenewalRateMoney: renewalRateMoney,
- RenewalRateMoneyContent: renewalRateMoneyContent,
- RenewalRateTotal: renewalRateTotal,
- RenewalRateTotalContent: renewalRateTotalContent,
- List: list,
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // @Title 权益客户续约率统计所能查询的年份
- // @Description权益客户续约率统计所能查询的年份接口
- // @Success 200 {object} response.IncrementalCompanyListResp
- // @router /merge_company/get_year_list [get]
- func (this *StatisticCompanyMergerController) GetYearList() {
- 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
- }
- thisYear := time.Now().Year()
- startYear := 2022 //初始查询年份
- resp := new(company.SearchYearListResp)
- var yearList []int
- for i := startYear; i <= thisYear; i++ {
- yearList = append(yearList, i)
- }
- resp.List = yearList
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // @Title 权益客户续约率统计
- // @Description 权益客户续约率统计接口
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param AdminId query string true "销售id,多个用英文逗号隔开,空字符串为全部"
- // @Param StartDate query string false "开始日期"
- // @Param EndDate query string false "结束日期"
- // @Param ContractDataType query string false "合同类型,枚举值:`续约合同`,`到期合同`"
- // @Success 200 {object} response.IncrementalCompanyListResp
- // @router /merge_company/company_contract_percentage/listV2 [get]
- func (this *StatisticCompanyMergerController) CompanyContractPercentageListV2() {
- 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
- }
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- adminId := this.GetString("AdminId")
- contractDataType := this.GetString("ContractDataType")
- startDate := this.GetString("StartDate")
- endDate := this.GetString("EndDate")
- //initendDate := this.GetString("EndDate")
- if startDate == "" || endDate == "" {
- br.Msg = "开始时间或结束时间不能为空"
- return
- }
- //如果传的查询方式是今年,那么就以当前时间作为截止时间
- //if endDate == strconv.Itoa(time.Now().Year())+"-12-31" {
- // endDate = time.Now().Format(utils.FormatDate)
- //}
- //判断结束时间是否晚于当前时间,如果晚于当前时间,那么就把当前时间作为截止时间。
- endDateTime, _ := time.Parse(utils.FormatDate, endDate)
- if endDateTime.After(time.Now()) {
- endDate = time.Now().Format(utils.FormatDate)
- }
- //fmt.Println("endDate", endDate)
- if contractDataType == "" {
- contractDataType = "续约合同"
- }
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = utils.StartIndex(currentIndex, pageSize)
- var condition string
- var pars []interface{}
- //条件
- if adminId != "" {
- condition += ` AND c.seller_id in (` + adminId + `) `
- } else {
- //根据当前角色来获取查询条件
- condition, pars = getQueryParams(condition, pars, sysUser, "c.")
- }
- //权益有效合同
- condition += ` AND c.product_id = 2 AND a.status = 1 `
- var list []*models.IncrementalList
- var renewalRateMoney string //合同金额续约率
- var renewalRateMoneyContent string //合同金额续约率详情
- var renewalRateTotal string //合同数量续约率
- var renewalRateTotalContent string //合同数量续约率详情
- var renewalContractTotal int //续约合同数量
- var renewalContractMoney int //续约合同数量
- var expireRenewalContractTotal int //到期合同数量
- var expireRenewalContractMoney int //到期合同数量
- var dataTotal int //分页数据
- //conditionRenewal := condition // 续约合同查询条件查询条件
- //parsRenewal := pars
- //conditionRenewal += ` AND a.start_date >= ? AND a.start_date <= ? `
- //conditionRenewal += ` AND a.end_date >= ? AND a.end_date <= ? `
- //parsRenewal = append(parsRenewal, startDate, endDate)
- ////conditionRenewal += ` AND a.rai_contract_type = ? `
- ////parsRenewal = append(parsRenewal, "续约合同")
- //
- //conditionRenewal += ` AND a.company_ascribe_id > 0 AND a.company_ascribe_id !=9 ` // 已确认未续约
- //totalRenewal, err := company.GetIncrementalRenewalCompanyProductMergeCount(conditionRenewal, parsRenewal)
- //if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取失败,Err:" + err.Error()
- // return
- //}
- //
- //totalMoneyRenewal, err := company.GetIncrementalRenewalCompanyProductMergeSumMoney(conditionRenewal, parsRenewal)
- //if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取失败,Err:" + err.Error()
- // return
- //}
- //续约合同查询条件查询条件 end
- //conditionRenewalEnd := condition // 今年结束的续约合同查询条件
- //parsRenewalEnd := pars
- //
- ////startDateTime, _ := time.Parse(utils.FormatDate, endDate)
- ////startDateTime = startDateTime.AddDate(-1, 0, 2) //合同开始时间,与查询的结束时间,之间相差的天数大于 365天。
- ////fmt.Println("startDateTime", startDateTime)
- //conditionRenewalEnd += ` AND a.end_date >= ? AND a.end_date <= ? `
- //parsRenewalEnd = append(parsRenewalEnd, startDate, endDate)
- //conditionRenewalEnd += ` AND a.rai_contract_type = ? `
- //parsRenewalEnd = append(parsRenewalEnd, "续约合同")
- //
- //totalRenewalEnd, err := company.GetIncrementalRenewalCompanyProductMergeCount(conditionRenewalEnd, parsRenewalEnd)
- //if err != nil && err.Error() != utils.ErrNoRow() {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取失败,Err:" + err.Error()
- // return
- //}
- ////return
- //totalMoneyRenewalEnd, err := company.GetIncrementalRenewalCompanyProductMergeSumMoney(conditionRenewalEnd, parsRenewalEnd)
- //if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取失败,Err:" + err.Error()
- // return
- //} // 今年结束的续约合同查询条件end
- //
- //conditionNew := condition // 新签合同查询条件
- //parsNew := pars
- //conditionNew += ` AND a.end_date >= ? AND a.end_date <= ? `
- //parsNew = append(parsNew, startDate, endDate)
- //conditionNew += ` AND a.rai_contract_type = ? `
- //parsNew = append(parsNew, "新签合同")
- //totalNew, err := company.GetIncrementalRenewalCompanyProductMergeCount(conditionNew, parsNew)
- //if err != nil && err.Error() != utils.ErrNoRow() {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取失败,Err:" + err.Error()
- // return
- //}
- //totalMoneyNew, err := company.GetIncrementalRenewalCompanyProductMergeSumMoney(conditionNew, parsNew)
- //if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取失败,Err:" + err.Error()
- // return
- //} // 新签合同查询条件 end
- //fmt.Println("totalNew", totalNew)
- //fmt.Println("totalRenewalEnd", totalRenewalEnd)
- condition1 := condition
- pars1 := pars
- //condition1 += ` AND a.start_date >= ? AND a.start_date <= ? `
- condition1 += ` AND a.end_date >= ? AND a.end_date <= ? `
- pars1 = append(pars1, startDate, endDate)
- //condition1 += ` AND a.rai_contract_type = ? `
- //pars1 = append(pars1, "续约合同")
- condition1 += ` AND a.company_ascribe_id > 0 AND a.company_ascribe_id !=9 ` // 已确认未续约
- totalNo, err := company.GetIncrementalRenewalCompanyProductMergeCount(condition1, pars1)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- totalMoney, err := company.GetIncrementalRenewalCompanyProductMergeSumMoney(condition1, pars1)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- renewalContractTotal = totalNo
- renewalContractMoney = int(totalMoney)
- if contractDataType == "续约合同" || contractDataType == "确认不续约合同" {
- //列表页数据
- tmpList, err := models.GetIncrementalCompanyMergeListEnd(condition1, pars1, startSize, pageSize)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- list = tmpList
- dataTotal = totalNo
- }
- conditionEnd1 := condition
- parsEnd1 := pars
- //判断结束时间是否晚于当前时间,如果晚于当前时间,那么就把当前时间作为截止时间。并且当前这天的到期的合同,不查询
- //endDateTime, _ := time.Parse(utils.FormatDate, initendDate)
- //if endDateTime.After(time.Now()) {
- // endDate = time.Now().Format(utils.FormatDate)
- // condition1 += ` AND a.end_date >= ? AND a.end_date < ? `
- //} else {
- // condition1 += ` AND a.end_date >= ? AND a.end_date <= ? `
- //}
- conditionEnd1 += ` AND a.end_date >= ? AND a.end_date <= ? AND a.company_ascribe_id !=9 `
- parsEnd1 = append(parsEnd1, startDate, endDate)
- //condition1 += ` AND a.start_date < ? `
- //pars1 = append(pars1, startDateTime)
- totalEnd, err := company.GetIncrementalRenewalCompanyProductMergeCount(conditionEnd1, parsEnd1)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- totalMoneyEnd, err := company.GetIncrementalRenewalCompanyProductMergeSumMoney(conditionEnd1, parsEnd1)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- expireRenewalContractTotal = totalEnd
- expireRenewalContractMoney = int(totalMoneyEnd)
- if contractDataType == "到期合同" {
- //列表页数据
- tmpList, err := models.GetIncrementalCompanyMergeListEnd(conditionEnd1, parsEnd1, startSize, pageSize)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- list = tmpList
- dataTotal = totalEnd
- }
- //分子或者分母为零的时候,不做计算
- if totalNo == 0 || totalEnd == 0 {
- renewalRateMoney = "0%"
- renewalRateTotal = "0%"
- } else {
- renewalRateMoney = fmt.Sprint(utils.SubFloatToString(float64(totalMoney)/float64(totalMoneyEnd)*100, 2), "%")
- renewalRateTotal = fmt.Sprint(utils.SubFloatToString(float64(totalNo)/float64(totalEnd)*100, 2), "%")
- }
- renewalRateTotalContent = fmt.Sprint(int(totalMoney), "/", int(totalMoneyEnd))
- renewalRateMoneyContent = fmt.Sprint(totalNo, "份/", totalEnd, "份")
- listLen := len(list)
- if listLen == 0 {
- list = make([]*models.IncrementalList, 0)
- }
- var companyContractIds []int
- for i := 0; i < listLen; i++ {
- item := list[i]
- companyContractIds = append(companyContractIds, item.CompanyContractId)
- }
- //合同归因标签
- mapGetCompanyAscribeContent, mapContent := services.GetCompanyContractAscribeContentMap(companyContractIds)
- //合并合同所对应的权限
- mappermissionName, err := cygxService.GetCompanyContractPermissionNameMapById(companyContractIds)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- for _, v := range list {
- v.PermissionName = mappermissionName[v.CompanyContractId]
- if mapGetCompanyAscribeContent[v.CompanyContractId] != "" {
- v.Content = mapContent[v.CompanyContractId]
- v.AscribeContent = mapGetCompanyAscribeContent[v.CompanyContractId]
- v.IsShowNoRenewedNote = true
- }
- }
- page := paging.GetPaging(currentIndex, pageSize, dataTotal)
- resp := response.IncrementalCompanyPercentageListResp{
- Paging: page,
- RenewalContractTotal: renewalContractTotal,
- RenewalContractMoney: renewalContractMoney,
- ExpireRenewalContractTotal: expireRenewalContractTotal,
- ExpireRenewalContractMoney: expireRenewalContractMoney,
- RenewalRateMoney: renewalRateMoney,
- RenewalRateMoneyContent: renewalRateMoneyContent,
- RenewalRateTotal: renewalRateTotal,
- RenewalRateTotalContent: renewalRateTotalContent,
- List: list,
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // @Title 权益客户未续约率下载
- // @Description 权益客户未续约率下载接口
- // @Param AdminId query string true "销售id,多个用英文逗号隔开,空字符串为全部"
- // @Param StartDate query string false "开始日期"
- // @Param EndDate query string false "结束日期"
- // @Param ExportType query int true "下载类型 1:下载当前销售的合同明细数据;2:下载所有销售未续约数据列表"
- // @Success 200 {object} response.IncrementalCompanyListResp
- // @router /merge_company/company_contract_percentage/list_export [get]
- func (this *StatisticCompanyMergerController) CompanyContractPercentageListExport() {
- 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
- }
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- exportType, _ := this.GetInt("ExportType")
- adminId := this.GetString("AdminId")
- contractDataType := this.GetString("ContractDataType")
- startDate := this.GetString("StartDate")
- endDate := this.GetString("EndDate")
- //initendDate := this.GetString("EndDate")
- if startDate == "" || endDate == "" {
- br.Msg = "开始时间或结束时间不能为空"
- return
- }
- //判断结束时间是否晚于当前时间,如果晚于当前时间,那么就把当前时间作为截止时间。
- endDateTime, _ := time.Parse(utils.FormatDate, endDate)
- if endDateTime.After(time.Now()) {
- endDate = time.Now().Format(utils.FormatDate)
- }
- //fmt.Println("endDate", endDate)
- if contractDataType == "" {
- contractDataType = "续约合同"
- }
- var startSize int
- if pageSize <= 0 {
- pageSize = 10000
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = utils.StartIndex(currentIndex, pageSize)
- var condition string
- var pars []interface{}
- if exportType == 1 {
- //条件
- if adminId != "" {
- condition += ` AND a.seller_id_init in (` + adminId + `) `
- }
- }
- //权益有效合同
- condition += ` AND c.product_id = 2 AND a.status = 1 `
- condition += ` AND c.status not in ("永续","正式","关闭") `
- //var list []*models.IncrementalList
- condition1 := condition
- pars1 := pars
- condition1 += ` AND a.end_date >= ? AND a.end_date <= ? `
- pars1 = append(pars1, startDate, endDate)
- condition1 += ` AND a.company_ascribe_id > 0 AND a.company_ascribe_id !=9 ` // 已确认未续约
- //if contractDataType == "续约合同" || contractDataType == "确认不续约合同" {
- //不续约列表数据
- listRenewal, err := models.GetIncrementalCompanyMergeListEnd(condition1, pars1, startSize, pageSize)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- conditionEnd1 := condition
- parsEnd1 := pars
- conditionEnd1 += ` AND a.end_date >= ? AND a.end_date <= ? AND a.company_ascribe_id !=9 `
- parsEnd1 = append(parsEnd1, startDate, endDate)
- //if contractDataType == "到期合同" {
- //到期列表数据
- listEndDate, err := models.GetIncrementalCompanyMergeListEnd(conditionEnd1, parsEnd1, startSize, pageSize)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- var companyContractIds []int
- for _, v := range listRenewal {
- companyContractIds = append(companyContractIds, v.CompanyContractId)
- v.SellerId = v.SellerIdInit
- }
- for _, v := range listEndDate {
- companyContractIds = append(companyContractIds, v.CompanyContractId)
- v.SellerId = v.SellerIdInit
- }
- //合同归因标签
- mapGetCompanyAscribeContent, mapContent := services.GetCompanyContractAscribeContentMap(companyContractIds)
- //合并合同所对应的权限
- mappermissionName, err := cygxService.GetCompanyContractPermissionNameMapById(companyContractIds)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- for _, v := range listRenewal {
- v.PermissionName = mappermissionName[v.CompanyContractId]
- if mapGetCompanyAscribeContent[v.CompanyContractId] != "" {
- v.Content = mapContent[v.CompanyContractId]
- v.AscribeContent = mapGetCompanyAscribeContent[v.CompanyContractId]
- v.IsShowNoRenewedNote = true
- }
- }
- for _, v := range listEndDate {
- v.PermissionName = mappermissionName[v.CompanyContractId]
- if mapGetCompanyAscribeContent[v.CompanyContractId] != "" {
- v.Content = mapContent[v.CompanyContractId]
- v.AscribeContent = mapGetCompanyAscribeContent[v.CompanyContractId]
- v.IsShowNoRenewedNote = true
- }
- }
- //创建excel
- 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
- if exportType == 1 {
- for pidIndex := 0; pidIndex <= 1; pidIndex++ {
- var sheetName string
- var listDate []*models.IncrementalList
- if pidIndex == 0 {
- sheetName = "确认不续约合同"
- listDate = listRenewal
- } else {
- sheetName = "到期合同"
- listDate = listEndDate
- }
- sheet, err := xlsxFile.AddSheet(sheetName)
- if err != nil {
- br.Msg = "新增Sheet失败"
- br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
- return
- }
- //标头
- rowTitle := sheet.AddRow()
- cellA := rowTitle.AddCell()
- cellA.Value = "客户名称"
- cellB := rowTitle.AddCell()
- cellB.Value = "客户状态"
- cellC := rowTitle.AddCell()
- cellC.Value = "所属销售"
- cellCSeller := rowTitle.AddCell()
- cellCSeller.Value = "服务销售"
- cellD := rowTitle.AddCell()
- cellD.Value = "合同期限"
- cellE := rowTitle.AddCell()
- cellE.Value = "签约套餐"
- cellF := rowTitle.AddCell()
- cellF.Value = "合同金额"
- if pidIndex == 0 {
- cellG := rowTitle.AddCell()
- cellG.Value = "不续约归因"
- }
- for _, item := range listDate {
- row := sheet.AddRow()
- cellAData := row.AddCell()
- cellAData.Value = item.CompanyName
- cellBData := row.AddCell()
- cellBData.Value = item.ProductStatus
- cellCData := row.AddCell()
- cellCData.Value = item.SellerName
- cellCSellerData := row.AddCell()
- cellCSellerData.Value = item.ShareSeller
- cellDData := row.AddCell()
- cellDData.Value = item.StartDate + "~" + item.EndDate
- cellEData := row.AddCell()
- cellEData.Value = item.PermissionName
- cellFData := row.AddCell()
- cellFData.Value = fmt.Sprint(item.Money)
- if pidIndex == 0 {
- cellGData := row.AddCell()
- cellGData.Value = item.Content
- }
- }
- }
- err = xlsxFile.Save(downLoadnFilePath)
- if err != nil {
- br.Msg = "保存文件失败"
- br.ErrMsg = "保存文件失败"
- return
- }
- } else {
- var sheetName string
- //var listDate []*models.IncrementalList
- sheetName = "未续约率"
- sheet, err := xlsxFile.AddSheet(sheetName)
- if err != nil {
- br.Msg = "新增Sheet失败"
- br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
- return
- }
- //标头
- rowTitle := sheet.AddRow()
- cellA := rowTitle.AddCell()
- cellA.Value = "姓名"
- cellB := rowTitle.AddCell()
- cellB.Value = "确认不续约合同数"
- cellC := rowTitle.AddCell()
- cellC.Value = "确认不续约合同金额"
- cellD := rowTitle.AddCell()
- cellD.Value = "到期合同数"
- cellE := rowTitle.AddCell()
- cellE.Value = "到期合同金额"
- cellF := rowTitle.AddCell()
- cellF.Value = "确认不续约率"
- listRaiSeller, err := system.GetSysuserRaiListNoServer()
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取权益销售信息失败,Err:" + err.Error()
- return
- }
- //NoRenewalContractTotal int `description:"确认不续约合同数"`
- //NoRenewalContractMoney int `description:"确认不续约合同金额"`
- //ExpireRenewalContractTotal int `description:"到期合同数量"`
- //ExpireRenewalContractMoney int `description:"到期合同总金额"`
- //NoRenewalContractPercentage string `description:"确认不续约率"`
- mapNoRenewalContractTotal := make(map[int]int)
- mapNoRenewalContractMoney := make(map[int]float64)
- mapExpireRenewalContractTotal := make(map[int]int)
- mapExpireRenewalContractMoney := make(map[int]float64)
- //mapData := make(map[int]*response.IncrementalCompanyPercentageExportResp)
- for _, v := range listRenewal {
- mapNoRenewalContractTotal[v.SellerId]++
- mapNoRenewalContractMoney[v.SellerId] += v.Money
- }
- for _, v := range listEndDate {
- mapExpireRenewalContractTotal[v.SellerId]++
- mapExpireRenewalContractMoney[v.SellerId] += v.Money
- }
- for _, item := range listRaiSeller {
- row := sheet.AddRow()
- cellAData := row.AddCell()
- cellAData.Value = item.RealName
- cellBData := row.AddCell()
- cellBData.Value = fmt.Sprint(mapNoRenewalContractTotal[item.AdminId])
- cellCData := row.AddCell()
- cellCData.Value = utils.SubFloatToString(mapNoRenewalContractMoney[item.AdminId], 2)
- cellEData := row.AddCell()
- cellEData.Value = fmt.Sprint(mapExpireRenewalContractTotal[item.AdminId])
- cellFData := row.AddCell()
- cellFData.Value = utils.SubFloatToString(mapExpireRenewalContractMoney[item.AdminId], 2)
- cellGData := row.AddCell()
- //分子或者分母为零的时候,不做计算
- if mapNoRenewalContractMoney[item.AdminId] == 0 || mapExpireRenewalContractMoney[item.AdminId] == 0 {
- cellGData.Value = "0%"
- } else {
- cellGData.Value = fmt.Sprint(utils.SubFloatToString(float64(mapNoRenewalContractMoney[item.AdminId])/float64(mapExpireRenewalContractMoney[item.AdminId])*100, 2), "%")
- }
- }
- 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 = "导出成功"
- }
- // @Title 获取上一年的合同列表
- // @Description 获取上一年的合同列表接口
- // @Param CompanyContractId query int true "合同ID"
- // @Success Ret=200 {object} company.GetCompanyContractDetailListResp
- // @router /merge_company_previous/last_year [get]
- func (this *StatisticCompanyMergerController) CompanyPreviousLastYear() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- AdminUser := this.SysUser
- if AdminUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,用户信息为空"
- br.Ret = 408
- return
- }
- resp := new(company.GetCompanyContractDetailListResp)
- companyContractId, _ := this.GetInt("CompanyContractId")
- if companyContractId < 1 {
- br.Msg = "请输入合同ID"
- return
- }
- var condition string
- var pars []interface{}
- //获取最新的一条到期的合同信息
- condition = " AND company_contract_id = ? "
- pars = append(pars, companyContractId)
- detail, err := company.GetCompanyContracDetail(condition, pars)
- if err != nil {
- br.Msg = "详情不存在"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- startDateContrac := detail.StartDate // 合同开始时间
- startDateYear := utils.StrDateToDate(startDateContrac).AddDate(-1, 0, 0).Year() //所要查询的年份
- startDate := fmt.Sprint(startDateYear, "-01-01")
- endDate := fmt.Sprint(startDateYear, "-12-31")
- //获取前一份合同的信息
- pars = make([]interface{}, 0)
- condition = " AND company_id = ? AND status = 1 AND start_date >= ? AND start_date <= ? AND product_id = 2 ORDER BY start_date DESC "
- pars = append(pars, detail.CompanyId, startDate, endDate)
- detailPreviousList, err := company.GetCompanyContracList(condition, pars)
- if err != nil {
- br.Msg = "详情不存在"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- var companyContractIds []int
- for _, v := range detailPreviousList {
- companyContractIds = append(companyContractIds, v.CompanyContractId)
- }
- //合并合同所对应的权限
- mappermissionName, err := cygxService.GetCompanyContractPermissionNameMapById(companyContractIds)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- for _, v := range detailPreviousList {
- v.PermissionName = mappermissionName[v.CompanyContractId]
- }
- resp.List = detailPreviousList
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- func init213() {
- var condition string
- var pars []interface{}
- condition = " AND rai_contract_type = '续约合同' AND product_id = 2 "
- var companyContractIds []string
- companyContractList, e := company.GetCompanyContractList(condition, pars)
- if e != nil && e.Error() != utils.ErrNoRow() {
- fmt.Println(e)
- return
- }
- for _, v := range companyContractList {
- fmt.Println(v.CompanyContractId)
- startDateTime, _ := time.Parse(utils.FormatDate, v.StartDate)
- startDateTime = startDateTime.AddDate(-1, 0, 0)
- totalLastYear, err := company.GetCompanyContractCountRaiByLastYear(v.CompanyId, startDateTime.Format(utils.FormatDate))
- if err != nil {
- fmt.Println(err)
- return
- }
- if totalLastYear > 0 {
- companyContractIds = append(companyContractIds, strconv.Itoa(v.CompanyContractId))
- }
- }
- fmt.Println("companyContractIds", len(companyContractIds))
- fmt.Println(strings.Join(companyContractIds, ","))
- err := company.UpdateCompanyContractRaiContractTypeInit(strings.Join(companyContractIds, ","))
- fmt.Println(err)
- return
- }
- func init323() {
- var conditionConfirm string
- var parsConfirm []interface{}
- companyConfirmList, err := company.GetCompanyContractNoRenewedAscribeList(conditionConfirm, parsConfirm, 0, 0)
- if err != nil && err.Error() != utils.ErrNoRow() {
- fmt.Println(err)
- return
- }
- for _, v := range companyConfirmList {
- err = company.UpdateCompanyContractCompanyAscribeId(v.CompanyAscribeId, v.CompanyContractId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- fmt.Println(err)
- return
- }
- }
- }
- //func init() {
- // init16_1_06()
- //}
- func init16_1_01() {
- var condition string
- var pars []interface{}
- condition = " AND product_id = 2 "
- var companyIds []int
- companyContractList, e := company.GetCompanyContractList(condition, pars)
- if e != nil && e.Error() != utils.ErrNoRow() {
- fmt.Println(e)
- return
- }
- for _, v := range companyContractList {
- if utils.InArrayByInt(companyIds, v.CompanyId) {
- continue
- }
- companyIds = append(companyIds, v.CompanyId)
- }
- condition = " AND company_id IN (" + (utils.GetOrmInReplace(len(companyIds))) + ") AND product_id = 2 AND share_seller_id > 0 "
- pars = append(pars, companyIds)
- listCompanyProduct, e := company.GetCompanyProductList(condition, pars)
- if e != nil {
- fmt.Println(e)
- return
- }
- for _, v := range listCompanyProduct {
- fmt.Println(v.ShareSellerId, v.ShareSeller)
- e = company.UpdateCompanyContractTypeinit16_1_01(v.ShareSeller, v.ShareSellerId, v.CompanyId)
- if e != nil {
- fmt.Println(e)
- return
- }
- }
- }
- func init16_1_02() {
- var condition string
- var pars []interface{}
- condition = " AND product_id = 2 AND company_contract_id > 0 "
- CompanyApprovalList, e := company.GetCompanyApprovalList(condition, pars)
- if e != nil && e.Error() != utils.ErrNoRow() {
- fmt.Println(e)
- return
- }
- for _, v := range CompanyApprovalList {
- fmt.Println(v.CompanyId, v.CompanyContractId, "__", v.CompanyApprovalId)
- e = company.UpdateCompanyContractTypeinit16_1_02(v.ApplyRealName, v.ApplyUserId, v.CompanyContractId)
- if e != nil {
- fmt.Println(e)
- return
- }
- }
- }
- func init16_1_03() {
- CompanyApprovalList, e := company.GetCompanyOperationRecordListinitcrm16_1()
- if e != nil && e.Error() != utils.ErrNoRow() {
- fmt.Println(e)
- return
- }
- for _, v := range CompanyApprovalList {
- fmt.Println(v.CompanyId, v.SellerId, "__", v.SysRealName)
- e = company.UpdateCompanyProductsellerInit(v.SellerId, v.SysRealName, v.CompanyId, 2)
- if e != nil {
- fmt.Println(e)
- return
- }
- }
- }
- func init16_1_04() {
- var condition string
- var pars []interface{}
- condition = " AND product_id = 2 AND seller_id_init = 0 "
- CompanyApprovalList, e := company.GetCompanyContracList(condition, pars)
- if e != nil && e.Error() != utils.ErrNoRow() {
- fmt.Println(e)
- return
- }
- for _, v := range CompanyApprovalList {
- productItem, e := company.GetCompanyProductByCompanyIdAndProductId(v.CompanyId, 2)
- if e != nil && e.Error() != utils.ErrNoRow() {
- fmt.Println(e)
- return
- }
- if productItem == nil {
- continue
- }
- e = company.UpdateCompanyContractTypeinit16_1_02(productItem.SellerName, productItem.SellerId, v.CompanyContractId)
- if e != nil {
- fmt.Println(e)
- return
- }
- }
- }
- //func init16_1_05() {
- // var condition string
- // var pars []interface{}
- //
- // condition = " AND product_id = 2 "
- //
- // listProduct, e := company.GetCompanyProductList(condition, pars)
- // if e != nil {
- // fmt.Println(e)
- // return
- // }
- // for _, v := range listProduct {
- // e = company.UpdateCompanyProductSellerUnexpiredInitinit16_1_05(v.SellerId, v.SellerName, v.CompanyId)
- // if e != nil {
- // fmt.Println(e)
- // return
- // }
- // }
- // fmt.Println("end")
- //}
- func init16_1_06() {
- var condition string
- var pars []interface{}
- listContractMax, e := company.GetCompanyContracListInit(condition, pars)
- if e != nil {
- fmt.Println(e)
- return
- }
- maxId := make(map[int]int)
- for _, v := range listContractMax {
- maxId[v.MaxCompanyContractId] = v.MaxCompanyContractId
- }
- listContract, e := company.GetCompanyContracListInit_CRM_16_1(condition, pars)
- if e != nil {
- fmt.Println(e)
- return
- }
- var updateId []string
- for _, v := range listContract {
- if maxId[v.CompanyContractId] > 0 {
- continue
- }
- updateId = append(updateId, strconv.Itoa(v.CompanyContractId))
- }
- err := company.UpdateCompanyContracthide(updateId)
- fmt.Println((err))
- fmt.Println((updateId))
- }
- //更新权益销客户后一个正式的销售为当前销售
- //func init(){
- // SELECT * FROM company_product WHERE 1= 1 AND product_id =2 AND share_seller_id > 0 ;
- //}
|