company.go 319 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "github.com/rdlucklib/rdluck_tools/paging"
  6. "github.com/tealeg/xlsx"
  7. "hongze/hz_crm_api/cache"
  8. "hongze/hz_crm_api/models"
  9. "hongze/hz_crm_api/models/advisory"
  10. "hongze/hz_crm_api/models/company"
  11. "hongze/hz_crm_api/models/company_report_permission_log"
  12. "hongze/hz_crm_api/models/company_todo"
  13. "hongze/hz_crm_api/models/company_user"
  14. "hongze/hz_crm_api/models/cygx"
  15. "hongze/hz_crm_api/models/response"
  16. statisticModels "hongze/hz_crm_api/models/statistic_report"
  17. "hongze/hz_crm_api/models/system"
  18. "hongze/hz_crm_api/services"
  19. "hongze/hz_crm_api/services/alarm_msg"
  20. cygxService "hongze/hz_crm_api/services/cygx"
  21. "hongze/hz_crm_api/services/statistic_report"
  22. "hongze/hz_crm_api/utils"
  23. "os"
  24. "path/filepath"
  25. "strconv"
  26. "strings"
  27. "time"
  28. )
  29. // 客户管理
  30. type CompanyController struct {
  31. BaseAuthController
  32. }
  33. // @Title 客户检索列表
  34. // @Description 客户检索列表接口
  35. // @Param KeyWord query string true "搜索关键词"
  36. // @Param PageSize query int true "每页数据条数"
  37. // @Param CurrentIndex query int true "当前页页码,从1开始"
  38. // @Success 200 {object} company.CompanySearchListResp
  39. // @router /search/list [get]
  40. func (this *CompanyController) SearchList() {
  41. br := new(models.BaseResponse).Init()
  42. defer func() {
  43. this.Data["json"] = br
  44. this.ServeJSON()
  45. }()
  46. sysUser := this.SysUser
  47. if sysUser == nil {
  48. br.Msg = "请登录"
  49. br.ErrMsg = "请登录,SysUser Is Empty"
  50. br.Ret = 408
  51. return
  52. }
  53. pageSize, _ := this.GetInt("PageSize")
  54. currentIndex, _ := this.GetInt("CurrentIndex")
  55. var startSize int
  56. if pageSize <= 0 {
  57. pageSize = utils.PageSize20
  58. }
  59. if currentIndex <= 0 {
  60. currentIndex = 1
  61. }
  62. startSize = paging.StartIndex(currentIndex, pageSize)
  63. roleTypeCode := sysUser.RoleTypeCode
  64. keyWord := this.GetString("KeyWord")
  65. keyWord = strings.Trim(keyWord, " ")
  66. keyWord = strings.Replace(keyWord, "'", "", -1)
  67. resp := new(company.CompanySearchListResp)
  68. var condition string
  69. var pars []interface{}
  70. //需要忽略的关键字
  71. ignoreStrs := []string{"", "有限", "投资", "资本", "管理", "贸易", "资产", "公司", "股份", "集团", "有限公司"}
  72. if strings.Contains(strings.Join(ignoreStrs, ","), keyWord) {
  73. list := make([]*company.CompanySearchItem, 0)
  74. resp.List = list
  75. br.Ret = 200
  76. br.Success = true
  77. br.Msg = "获取成功"
  78. br.Data = resp
  79. return
  80. }
  81. //正常筛选逻辑
  82. companyIdStr, err := company.GetCompanyIdByKeyWordAll(keyWord)
  83. if err != nil {
  84. br.Msg = "获取失败"
  85. br.ErrMsg = "获取失败,Err:" + err.Error()
  86. return
  87. }
  88. companyIdStr = strings.Trim(companyIdStr, ",")
  89. if companyIdStr != "" {
  90. condition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.company_id IN(` + companyIdStr + `)) `
  91. } else {
  92. condition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.credit_code LIKE '%` + keyWord + `%')`
  93. //pars = append(pars, keyWord)
  94. //pars = append(pars, keyWord)
  95. }
  96. total, err := company.GetCompanySearchCount(condition, pars)
  97. if err != nil {
  98. br.Msg = "获取失败"
  99. br.ErrMsg = "获取数据总数失败,Err:" + err.Error()
  100. return
  101. }
  102. list, err := company.GetCompanySearchList(condition, pars, startSize, pageSize)
  103. if err != nil && err.Error() != utils.ErrNoRow() {
  104. br.Msg = "获取失败"
  105. br.ErrMsg = "获取失败,Err:" + err.Error()
  106. return
  107. }
  108. // 查询当前销售是否有领取客户的权限
  109. receiveEnabled, _ := services.CheckCompanyReceiveButton(sysUser.AdminId)
  110. // 白嫖客户标记
  111. scroungeList, err := company.GetScroungeCompany()
  112. if err != nil {
  113. br.Msg = "获取失败"
  114. br.ErrMsg = "获取白嫖客户信息失败,Err:" + err.Error()
  115. return
  116. }
  117. scroungeMap := make(map[int]int)
  118. for _, v := range scroungeList {
  119. scroungeMap[v.CompanyId] = 1
  120. }
  121. /*
  122. 时长根据客户状态定义,
  123. 若为冻结客户或者流失客户,则展示冻结时长或流失时长;
  124. 若为正式或试用客户,展示到期时长;
  125. */
  126. lenList := len(list)
  127. for i := 0; i < lenList; i++ {
  128. duration := ""
  129. item := list[i]
  130. itemStatus := item.Status
  131. //白嫖客户标记
  132. if _, ok := scroungeMap[item.CompanyId]; ok {
  133. item.IsScrounge = 1
  134. }
  135. if !strings.Contains(item.Status, "/") {
  136. if item.Status == utils.COMPANY_STATUS_FREEZE {
  137. if item.FreezeEndDate != "" {
  138. freeZeTime, _ := time.Parse(utils.FormatDate, item.FreezeEndDate)
  139. freeZeTime = freeZeTime.AddDate(0, 0, 1)
  140. sub := freeZeTime.Sub(time.Now())
  141. if sub < 0 {
  142. sub = 0
  143. }
  144. duration = fmt.Sprintf("%v", int(sub.Hours()/24))
  145. }
  146. } else if item.Status == utils.COMPANY_STATUS_LOSE {
  147. if item.LossTime != "" {
  148. lossTime, err := time.Parse(utils.FormatDateTime, item.LossTime)
  149. if err != nil {
  150. fmt.Println("err:" + err.Error())
  151. }
  152. lossTime = lossTime.AddDate(0, 0, 1)
  153. sub := time.Now().Sub(lossTime)
  154. if sub < 0 {
  155. sub = 0
  156. }
  157. duration = fmt.Sprintf("%v", int(sub.Hours()/24))
  158. }
  159. } else if item.Status == utils.COMPANY_STATUS_FORMAL ||
  160. item.Status == utils.COMPANY_STATUS_TRY_OUT {
  161. if item.EndDate != "" {
  162. endDate, _ := time.Parse(utils.FormatDate, item.EndDate)
  163. endDate = endDate.AddDate(0, 0, 1)
  164. sub := endDate.Sub(time.Now())
  165. if sub < 0 {
  166. sub = 0
  167. }
  168. duration = fmt.Sprintf("%v", int(sub.Hours()/24))
  169. }
  170. } else if item.Status == utils.COMPANY_STATUS_TRY_OUT {
  171. duration = "永续"
  172. } else {
  173. duration = "-"
  174. }
  175. } else {
  176. statusArr := strings.Split(item.Status, "/")
  177. //freezeArr := strings.Split(item.FreezeTime, "/") //0:ficc,1:权益
  178. freezeArr := strings.Split(item.FreezeEndDate, "/") //冻结结束日期:0:ficc,1:权益
  179. lossArr := strings.Split(item.LossTime, "/") //0:ficc,1:权益
  180. endDateArr := strings.Split(item.EndDate, "/")
  181. var ficcFreeze, tryFreeze string
  182. var ficcLoss, tryLoss string
  183. var ficcEndDate, tryEndDate string
  184. ficcStatus := statusArr[0]
  185. tryOutStatus := statusArr[1]
  186. //if len(freezeArr) > 1 {
  187. // ficcFreeze = freezeArr[0]
  188. // tryFreeze = freezeArr[1]
  189. //}
  190. //if len(lossArr) > 1 {
  191. // ficcLoss = lossArr[0]
  192. // tryLoss = lossArr[1]
  193. //}
  194. //结束日期
  195. if len(endDateArr) > 1 {
  196. ficcEndDate = endDateArr[0]
  197. tryEndDate = endDateArr[1]
  198. }
  199. //冻结
  200. if ficcStatus == utils.COMPANY_STATUS_FREEZE && len(freezeArr) > 0 {
  201. //ficc
  202. ficcFreeze = freezeArr[0]
  203. }
  204. if tryOutStatus == utils.COMPANY_STATUS_FREEZE && len(freezeArr) > 0 {
  205. //权益
  206. if len(freezeArr) == 1 {
  207. tryFreeze = freezeArr[0]
  208. } else {
  209. tryFreeze = freezeArr[1]
  210. }
  211. }
  212. //流失
  213. if ficcStatus == utils.COMPANY_STATUS_LOSE && len(lossArr) > 0 {
  214. //ficc
  215. ficcLoss = lossArr[0]
  216. }
  217. if tryOutStatus == utils.COMPANY_STATUS_LOSE && len(lossArr) > 0 {
  218. //权益
  219. if len(lossArr) == 1 {
  220. tryLoss = lossArr[0]
  221. } else {
  222. tryLoss = lossArr[1]
  223. }
  224. }
  225. //ficc的判断
  226. switch ficcStatus {
  227. case utils.COMPANY_STATUS_FREEZE: //冻结
  228. if ficcFreeze != "" {
  229. ficcFreeZeTime, _ := time.Parse(utils.FormatDate, ficcFreeze)
  230. ficcFreeZeTime = ficcFreeZeTime.AddDate(0, 0, 1)
  231. sub := ficcFreeZeTime.Sub(time.Now())
  232. if sub < 0 {
  233. sub = 0
  234. }
  235. duration = fmt.Sprintf("%v", int(sub.Hours()/24))
  236. }
  237. case utils.COMPANY_STATUS_LOSE: //流失
  238. if ficcLoss != "" {
  239. ficcLossTime, _ := time.Parse(utils.FormatDateTime, ficcLoss)
  240. ficcLossTime = ficcLossTime.AddDate(0, 0, 1)
  241. sub := time.Now().Sub(ficcLossTime)
  242. if sub < 0 {
  243. sub = 0
  244. }
  245. duration = fmt.Sprintf("%v", int(sub.Hours()/24))
  246. }
  247. case utils.COMPANY_STATUS_FORMAL, utils.COMPANY_STATUS_TRY_OUT:
  248. if ficcEndDate != "" {
  249. ficcEndDateTime, _ := time.Parse(utils.FormatDate, ficcEndDate)
  250. ficcEndDateTime = ficcEndDateTime.AddDate(0, 0, 1)
  251. sub := ficcEndDateTime.Sub(time.Now())
  252. if sub < 0 {
  253. sub = 0
  254. }
  255. duration = fmt.Sprintf("%v", int(sub.Hours()/24))
  256. }
  257. case utils.COMPANY_STATUS_FOREVER:
  258. duration = "永续"
  259. case utils.COMPANY_STATUS_CLOSE:
  260. duration = "-"
  261. }
  262. //权益的判断
  263. switch tryOutStatus {
  264. case utils.COMPANY_STATUS_FREEZE: //冻结
  265. if tryFreeze != "" {
  266. tryOutFreeZeTime, _ := time.Parse(utils.FormatDate, tryFreeze)
  267. tryOutFreeZeTime = tryOutFreeZeTime.AddDate(0, 0, 1)
  268. sub := tryOutFreeZeTime.Sub(time.Now())
  269. if sub < 0 {
  270. sub = 0
  271. }
  272. if duration != "" {
  273. duration = duration + "/" + fmt.Sprintf("%v", int(sub.Hours()/24))
  274. }
  275. }
  276. case utils.COMPANY_STATUS_LOSE: //流失
  277. if tryLoss != "" {
  278. tryOutLossTime, _ := time.Parse(utils.FormatDateTime, tryLoss)
  279. tryOutLossTime = tryOutLossTime.AddDate(0, 0, 1)
  280. sub := time.Now().Sub(tryOutLossTime)
  281. if sub < 0 {
  282. sub = 0
  283. }
  284. if duration != "" {
  285. duration = duration + "/" + fmt.Sprintf("%v", int(sub.Hours()/24))
  286. }
  287. }
  288. case utils.COMPANY_STATUS_FORMAL, utils.COMPANY_STATUS_TRY_OUT:
  289. if tryEndDate != "" {
  290. tryEndDateTime, _ := time.Parse(utils.FormatDate, tryEndDate)
  291. tryEndDateTime = tryEndDateTime.AddDate(0, 0, 1)
  292. sub := tryEndDateTime.Sub(time.Now())
  293. if sub < 0 {
  294. sub = 0
  295. }
  296. if duration != "" {
  297. duration = duration + "/" + fmt.Sprintf("%v", int(sub.Hours()/24))
  298. }
  299. }
  300. case utils.COMPANY_STATUS_FOREVER:
  301. if duration != "" {
  302. duration = duration + "/" + "永续"
  303. }
  304. case utils.COMPANY_STATUS_CLOSE:
  305. duration = "-"
  306. }
  307. //list[i].ApproveStatus = ""
  308. }
  309. approveStatusMap := make(map[int]string)
  310. if item.ProductId == 1 {
  311. approveStatusMap[1] = item.ApproveStatus
  312. } else if item.ProductId == 2 {
  313. approveStatusMap[2] = item.ApproveStatus
  314. }
  315. if strings.Contains(item.ApproveStatus, "/") {
  316. approveStatusSlice := strings.Split(item.ApproveStatus, "/")
  317. approveStatusMap[1] = approveStatusSlice[0]
  318. approveStatusMap[2] = approveStatusSlice[1]
  319. } else {
  320. approveStatusMap[1] = item.ApproveStatus
  321. approveStatusMap[2] = item.ApproveStatus
  322. }
  323. productIdMap := make(map[int]int)
  324. if strings.Contains(item.ProductIds, "/") {
  325. productIdSlice := strings.Split(item.ProductIds, "/")
  326. productIdMap[1], _ = strconv.Atoi(productIdSlice[0])
  327. productIdMap[2], _ = strconv.Atoi(productIdSlice[1])
  328. }
  329. if strings.Contains(item.ApproveStatus, "/") {
  330. approveStatusSlice := strings.Split(item.ApproveStatus, "/")
  331. approveStatusMap[1] = approveStatusSlice[0]
  332. approveStatusMap[2] = approveStatusSlice[1]
  333. for k, v := range productIdMap {
  334. approveStatusMap[v] = approveStatusSlice[k-1]
  335. }
  336. } else {
  337. for _, v := range productIdMap {
  338. approveStatusMap[v] = item.ApproveStatus
  339. }
  340. }
  341. sysProductId := services.GetProductId(sysUser.RoleTypeCode)
  342. if sysProductId > 0 {
  343. list[i].ApproveStatus = approveStatusMap[sysProductId]
  344. }
  345. list[i].Duration = duration
  346. //按钮显示控制
  347. /*btnItem := services.GetCompanySearchPermissionButton(roleTypeCode, itemStatus, item.GroupId, sysUser.GroupId, item.SellerId, sysUser.AdminId, sysUser.Authority, item.ProductId)
  348. list[i].BtnItem = &btnItem*/
  349. btnItem := new(company.ButtonPermission)
  350. if item.CompanyId != 1 {
  351. *btnItem = services.GetCompanyPermissionButton(roleTypeCode, itemStatus, item.SellerIds, item.GroupIds, item.GroupId, sysUser.GroupId, item.SellerId, sysUser.AdminId, sysUser.Authority, item.ProductId, -1, item.ShareSellerIds)
  352. //根据销售"领取客户"的权限对部分按钮做限制
  353. btnItem = services.GetCompanyPermissionButtonByReceiveEnabled(btnItem, receiveEnabled)
  354. }
  355. if list[i].IsShare == 1 && btnItem.BtnModifySeller == true && roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  356. //如果已经是共享客户了,取消共享按钮全都显示,和修改销售权限一样
  357. btnItem.BtnShare = true
  358. }
  359. // 客户搜索页不要共享客户按钮
  360. btnItem.BtnShare = false
  361. //如果是权益客户,操作者又是权益管理员,那么就对他进行展示研选详情按钮
  362. if strings.Contains(item.CompanyType, utils.COMPANY_CLASSIFY_RAI) && sysUser.RoleName == utils.ROLE_TYPE_RAI_PRODUCT {
  363. btnItem.IsResearchShow = true
  364. }
  365. list[i].BtnItem = btnItem
  366. // 签约未签约按钮回显展示
  367. btnCompanyStatusItem := new(company.CompanyStatusButton)
  368. btnCompanyStatusItem = services.GetLsitCompanyStatusButton(list[i].CompanyType, list[i].Status, list[i].SigningStatus)
  369. list[i].CompanyStatusButton = btnCompanyStatusItem
  370. }
  371. for _, v := range list {
  372. v.Status = strings.Replace(v.Status, utils.COMPANY_STATUS_FOREVER, utils.COMPANY_STATUS_X_CLASS_TRY_OUT, -1) // 永续客户类型,映射成 X类试用
  373. v.Duration = strings.Replace(v.Duration, utils.COMPANY_STATUS_FOREVER, utils.COMPANY_STATUS_X_CLASS_TRY_OUT, -1) // 永续客户类型,映射成 X类试用
  374. }
  375. if list == nil {
  376. list = make([]*company.CompanySearchItem, 0)
  377. }
  378. resp.List = list
  379. page := paging.GetPaging(currentIndex, pageSize, total)
  380. resp.Paging = page
  381. br.Ret = 200
  382. br.Success = true
  383. br.Msg = "获取成功"
  384. br.Data = resp
  385. }
  386. // List
  387. // @Title 客户列表
  388. // @Description 客户列表接口
  389. // @Param PageSize query int true "每页数据条数"
  390. // @Param CurrentIndex query int true "当前页页码,从1开始"
  391. // @Param Status query string true "状态:'试用','永续','冻结','流失','正式'"
  392. // @Param CompanyType query string true "客户类型:传空字符串或者不传为全部,'ficc','权益'"
  393. // @Param IndustryId query int true "行业id,0为全部"
  394. // @Param AdminId query string true "销售id,多个用英文逗号隔开,空字符串为全部"
  395. // @Param ChartPermissionIds query string false "阅读权限品种ID,多个用英文逗号分开,空字符串为全部"
  396. // @Param ContractPermissionIds query string false "已购品种ID,多个用英文逗号分开,空字符串为全部"
  397. // @Param StartDate query string true "开始时间"
  398. // @Param EndDate query string true "结束时间"
  399. // @Param CreateStartDate query string true "创建开始时间"
  400. // @Param CreateEndDate query string true "创建结束时间"
  401. // @Param KeyWord query string true "搜索关键词"
  402. // @Param Address query string true "地址 , 多个用英文逗号分开 "
  403. // @Param Province query string true "省 , 多个用英文逗号分开 "
  404. // @Param City query string true "市 , 多个用英文逗号分开 "
  405. // @Param PackageType query int true "套餐类型,0:无,1:大套餐,2:小套餐"
  406. // @Param TodoStatus query string true "任务处理状态;枚举值:'无任务','未完成','已完成'"
  407. // @Param SortParam query string false "排序字段参数,用来排序的字段, 枚举值:'viewTotal':总阅读次数 、 'viewTime':阅读时间 、 'roadShowTotal':累计路演次数 、`expireDay:到期时间` 、 `createTime:创建时间` 、 'formalTime': 转正时间 、 'freezeTime':冻结时间 、'lossTime':流失时间 、'tryStage':试用标签 、'deadline':距离未完成的任务的截止日期的天数、'tryOutDay':试用天数"
  408. // @Param SortType query string true "如何排序,是正序还是倒序,枚举值:`asc 正序`,`desc 倒叙`"
  409. // @Param SortByTodo query bool true "是否根据待办排序,true或false"
  410. // @Param TryStage query int false "试用客户子标签:0全部、1未分类、2 推进、3 跟踪、4 预备"
  411. // @Param IncludeShare query bool true "是否包含共享客户: true-包含; false-不包含"
  412. // @Param IsSigning query int true "是否签约过: -1-默认全部; 0-否; 1-是"
  413. // @Success 200 {object} company.CompanyListResp
  414. // @router /list [get]
  415. func (this *CompanyController) List() {
  416. br := new(models.BaseResponse).Init()
  417. defer func() {
  418. this.Data["json"] = br
  419. this.ServeJSON()
  420. }()
  421. sysUser := this.SysUser
  422. if sysUser == nil {
  423. br.Msg = "请登录"
  424. br.ErrMsg = "请登录,SysUser Is Empty"
  425. br.Ret = 408
  426. return
  427. }
  428. roleTypeCode := sysUser.RoleTypeCode
  429. pageSize, _ := this.GetInt("PageSize")
  430. currentIndex, _ := this.GetInt("CurrentIndex")
  431. status := this.GetString("Status")
  432. companyType := this.GetString("CompanyType")
  433. industryId, _ := this.GetInt("IndustryId")
  434. adminId := this.GetString("AdminId")
  435. chartPermissionIds := this.GetString("ChartPermissionIds")
  436. contractPermissionIds := this.GetString("ContractPermissionIds")
  437. startDate := this.GetString("StartDate")
  438. endDate := this.GetString("EndDate")
  439. createStartDate := this.GetString("CreateStartDate")
  440. createEndDate := this.GetString("CreateEndDate")
  441. keyWord := this.GetString("KeyWord")
  442. address := this.GetString("Address")
  443. province := this.GetString("Province")
  444. city := this.GetString("City")
  445. regionType := this.GetString("RegionType")
  446. keyWord = strings.Trim(keyWord, " ")
  447. keyWord = strings.Replace(keyWord, "'", "", -1)
  448. todoStatus := this.GetString("TodoStatus") //任务状态
  449. tryStage, _ := this.GetInt("TryStage") //试用客户标签
  450. includeShare, _ := this.GetBool("IncludeShare") // 是否包含试用客户
  451. isSigning, _ := this.GetInt("IsSigning", -1)
  452. // 套餐类型
  453. packageType, _ := this.GetInt("PackageType")
  454. //排序参数
  455. sortParam := this.GetString("SortParam")
  456. sortType := this.GetString("SortType")
  457. sortByTodo, _ := this.GetBool("SortByTodo")
  458. productId := services.GetProductId(roleTypeCode)
  459. var total int
  460. page := paging.GetPaging(currentIndex, pageSize, total)
  461. resp := new(company.CompanyListResp)
  462. statusItems := make([]*company.CompanyStatus, 0)
  463. // 永续客户类型,映射成 X类试用
  464. if status == utils.COMPANY_STATUS_X_CLASS_TRY_OUT {
  465. status = utils.COMPANY_STATUS_FOREVER
  466. }
  467. var statusArr []string
  468. // 对权益用户隐藏关闭
  469. if productId == utils.COMPANY_PRODUCT_RAI_ID {
  470. statusArr = []string{"全部", "试用", "正式", "冻结", "流失", utils.COMPANY_STATUS_X_CLASS_TRY_OUT}
  471. } else {
  472. statusArr = []string{"全部", "试用", "正式", "冻结", "流失", utils.COMPANY_STATUS_CLOSE, utils.COMPANY_STATUS_X_CLASS_TRY_OUT}
  473. }
  474. //var statusArr = [...]string{"全部", "试用-活跃", "试用-非活跃", "正式", "冻结", "流失", "永续"}
  475. var startSize int
  476. if pageSize <= 0 {
  477. pageSize = utils.PageSize20
  478. }
  479. if currentIndex <= 0 {
  480. currentIndex = 1
  481. }
  482. startSize = paging.StartIndex(currentIndex, pageSize)
  483. var condition string
  484. var pars []interface{}
  485. //流失
  486. var lossCondition string
  487. var lossPars []interface{}
  488. //状态分类查询条件
  489. var permissionCondition string
  490. var permissionPars []interface{}
  491. if companyType != "" {
  492. condition += ` AND b.product_name=? `
  493. pars = append(pars, companyType)
  494. }
  495. if industryId > 0 {
  496. condition += ` AND b.industry_id=? `
  497. pars = append(pars, industryId)
  498. }
  499. if adminId != "" {
  500. condition += ` AND b.seller_id IN (` + adminId + `) `
  501. }
  502. if startDate != "" {
  503. condition += ` AND b.start_date>=? `
  504. pars = append(pars, startDate)
  505. }
  506. if endDate != "" {
  507. condition += ` AND b.end_date<=? `
  508. pars = append(pars, endDate)
  509. }
  510. if createStartDate != "" {
  511. condition += ` AND a.created_time>=? `
  512. pars = append(pars, createStartDate)
  513. }
  514. if createEndDate != "" {
  515. condition += ` AND a.created_time<=? `
  516. pars = append(pars, createEndDate)
  517. }
  518. if address != "" {
  519. var addressSql string
  520. slice := strings.Split(address, ",")
  521. for _, v := range slice {
  522. addressSql += "'" + v + "'" + ","
  523. }
  524. addressSql = strings.TrimRight(addressSql, ",")
  525. condition += ` AND a.address IN (` + addressSql + `) `
  526. }
  527. if province != "" {
  528. var provinceSql string
  529. slice := strings.Split(province, ",")
  530. for _, v := range slice {
  531. provinceSql += "'" + v + "'" + ","
  532. }
  533. provinceSql = strings.TrimRight(provinceSql, ",")
  534. condition += ` AND a.province IN (` + provinceSql + `) `
  535. }
  536. if city != "" {
  537. var citySql string
  538. slice := strings.Split(city, ",")
  539. for _, v := range slice {
  540. citySql += "'" + v + "'" + ","
  541. }
  542. citySql = strings.TrimRight(citySql, ",")
  543. condition += ` AND a.city IN (` + citySql + `) `
  544. }
  545. if regionType != "" {
  546. condition += ` AND a.region_type =? `
  547. pars = append(pars, regionType)
  548. }
  549. //是否签约过
  550. if isSigning == 0 || isSigning == 1 {
  551. condition += ` AND b.is_signing = ? `
  552. pars = append(pars, isSigning)
  553. }
  554. if keyWord != "" {
  555. companyIdStr, err := company.GetCompanyIdByKeyWord(keyWord)
  556. if err != nil {
  557. br.Msg = "获取客户信息失败"
  558. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  559. return
  560. }
  561. if companyIdStr != "" {
  562. condition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.credit_code LIKE '%` + keyWord + `%' OR a.company_id IN(` + companyIdStr + `)) `
  563. } else {
  564. condition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.credit_code LIKE '%` + keyWord + `%' ) `
  565. }
  566. }
  567. //任务状态
  568. if todoStatus != "" {
  569. condition += ` AND b.todo_status =? `
  570. pars = append(pars, todoStatus)
  571. }
  572. // 阅读权限/已购品种筛选
  573. cond, emp, e := services.FilterReadAndContractAuth(chartPermissionIds, contractPermissionIds, condition)
  574. if e != nil {
  575. br.Msg = "获取失败"
  576. br.ErrMsg = "FilterReadAndContractAuth err: " + e.Error()
  577. return
  578. }
  579. if emp {
  580. for _, v := range statusArr {
  581. statusCount := new(company.CompanyStatus)
  582. if v == "全部" {
  583. statusCount.Status = "全部"
  584. statusCount.Count = 0
  585. } else {
  586. statusCount.Status = v
  587. statusCount.Count = 0
  588. }
  589. statusItems = append(statusItems, statusCount)
  590. }
  591. items := make([]*company.CompanyListItem, 0)
  592. resp.List = items
  593. resp.Paging = page
  594. resp.StatusCount = statusItems
  595. br.Msg = "获取成功"
  596. br.Ret = 200
  597. br.Data = resp
  598. return
  599. }
  600. condition = cond
  601. //套餐类型
  602. if packageType > 0 {
  603. condition += ` AND b.package_type=? `
  604. pars = append(pars, packageType)
  605. }
  606. lossCondition = condition
  607. lossPars = pars
  608. permissionCondition = condition
  609. permissionPars = pars
  610. //流失客户统计
  611. lossCondition += ` AND status='流失' `
  612. //权限控制
  613. {
  614. //如果不是超级管理员或者财务
  615. if roleTypeCode != utils.ROLE_TYPE_CODE_ADMIN && roleTypeCode != utils.ROLE_TYPE_CODE_FINANCE {
  616. //如果是部门管理员
  617. if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  618. condition += ` AND b.product_id=? `
  619. pars = append(pars, productId)
  620. lossCondition += ` AND b.product_id=? `
  621. lossPars = append(lossPars, productId)
  622. permissionCondition += ` AND b.product_id=? `
  623. permissionPars = append(permissionPars, productId)
  624. //}
  625. //else if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_DIRECTOR {
  626. // condition += ` AND b.product_id=? `
  627. // pars = append(pars, productId)
  628. //
  629. // lossCondition += ` AND b.product_id=? `
  630. // lossPars = append(lossPars, productId)
  631. //
  632. // permissionCondition += ` AND b.product_id=? `
  633. // permissionPars = append(permissionPars, productId)
  634. } else {
  635. condition += ` AND b.product_id=? `
  636. pars = append(pars, productId)
  637. lossCondition += ` AND b.product_id=? `
  638. lossPars = append(lossPars, productId)
  639. permissionCondition += ` AND b.product_id=? `
  640. permissionPars = append(permissionPars, productId)
  641. if status == "全部" {
  642. ////如果是筛选了流失客户状态
  643. if sysUser.Authority <= 0 {
  644. condition += ` AND (b.seller_id=? OR status='流失' OR (b.share_seller_id = ? AND b.is_share = 1)) `
  645. pars = append(pars, sysUser.AdminId, sysUser.AdminId)
  646. permissionCondition += ` AND (b.seller_id=? OR status='流失' OR (b.share_seller_id = ? AND b.is_share = 1)) `
  647. permissionPars = append(permissionPars, sysUser.AdminId, sysUser.AdminId)
  648. } else {
  649. if sysUser.Authority == 1 {
  650. condition += ` AND (b.department_id=? OR status='流失')`
  651. pars = append(pars, sysUser.DepartmentId)
  652. permissionCondition += ` AND b.department_id=? `
  653. permissionPars = append(permissionPars, sysUser.DepartmentId)
  654. }
  655. if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  656. if status != utils.COMPANY_STATUS_LOSE {
  657. condition += ` AND (b.group_id=? OR status='流失') `
  658. pars = append(pars, sysUser.GroupId)
  659. }
  660. permissionCondition += ` AND b.group_id=? `
  661. permissionPars = append(permissionPars, sysUser.GroupId)
  662. }
  663. if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
  664. pid, err := company.GetParentIdFromGroup(sysUser.GroupId)
  665. if err != nil {
  666. br.Msg = "获取失败"
  667. br.ErrMsg = "查询父级id异常" + err.Error()
  668. return
  669. }
  670. var ids []*string
  671. if pid != nil {
  672. if *pid != 0 {
  673. //销售主管放在三级列表中
  674. ids, err = company.GetGroupIdsByParentId(*pid)
  675. if err != nil {
  676. fmt.Println(err.Error())
  677. }
  678. } else {
  679. //销售主管放在二级列表中
  680. ids, err = company.GetGroupIdsByParentId(sysUser.GroupId)
  681. if err != nil {
  682. fmt.Println(err.Error())
  683. }
  684. }
  685. }
  686. var idSlice []string
  687. var sid string
  688. for _, id := range ids {
  689. idSlice = append(idSlice, *id)
  690. }
  691. //加入父级groupId
  692. if *pid > 0 {
  693. idSlice = append(idSlice, strconv.Itoa(*pid))
  694. } else {
  695. idSlice = append(idSlice, strconv.Itoa(sysUser.GroupId))
  696. }
  697. sid = strings.Join(idSlice, ",")
  698. if len(sid) > 0 {
  699. if status != utils.COMPANY_STATUS_LOSE {
  700. condition += ` AND (b.group_id IN (` + sid + `) OR status='流失') `
  701. //pars = append(pars, sysUser.GroupId)
  702. }
  703. permissionCondition += ` AND b.group_id IN (` + sid + `) `
  704. } else {
  705. if status != utils.COMPANY_STATUS_LOSE {
  706. condition += ` AND (b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) OR status='流失') `
  707. //pars = append(pars, sysUser.GroupId)
  708. }
  709. permissionCondition += ` AND b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) `
  710. }
  711. //permissionPars = append(permissionPars, sysUser.GroupId)
  712. }
  713. if sysUser.Authority == 4 {
  714. //pid, err := company.GetParentIdFromGroup(sysUser.GroupId)
  715. //if err != nil {
  716. // br.Msg = "获取失败"
  717. // br.ErrMsg = "查询父级id异常" + err.Error()
  718. // return
  719. //}
  720. //ids,err := company.GetGroupIdsByParentId(*pid)
  721. //if err != nil {
  722. // br.Msg = "获取失败"
  723. // br.ErrMsg = "查询父级id异常" + err.Error()
  724. // return
  725. //}
  726. //var idSlice []string
  727. //var sid string
  728. //for _, id := range ids {
  729. // idSlice = append(idSlice, *id)
  730. //}
  731. //sid = strings.Join(idSlice,",")
  732. if status != utils.COMPANY_STATUS_LOSE {
  733. condition += ` AND (b.group_id =? OR status='流失') `
  734. pars = append(pars, sysUser.GroupId)
  735. }
  736. permissionCondition += ` AND b.group_id=? `
  737. permissionPars = append(permissionPars, sysUser.GroupId)
  738. }
  739. }
  740. } else {
  741. //如果没有筛选了流失客户状态,那么需要加客户归属条件加入到查询中去
  742. if sysUser.Authority <= 0 {
  743. if status != utils.COMPANY_STATUS_LOSE {
  744. //condition += ` AND b.seller_id=? `
  745. //pars = append(pars, sysUser.AdminId)
  746. // 是否包含共享客户(新增合同时, 关键词搜索客户为true)
  747. if includeShare {
  748. condition += ` AND (b.seller_id = ? OR (b.share_seller_id = ? AND b.is_share = 1)) `
  749. pars = append(pars, sysUser.AdminId, sysUser.AdminId)
  750. } else {
  751. condition += ` AND b.seller_id = ? `
  752. pars = append(pars, sysUser.AdminId)
  753. }
  754. }
  755. permissionCondition += ` AND (b.seller_id=? OR (b.share_seller_id = ? AND b.is_share = 1)) `
  756. permissionPars = append(permissionPars, sysUser.AdminId, sysUser.AdminId)
  757. } else {
  758. if sysUser.Authority == 1 {
  759. if status != utils.COMPANY_STATUS_LOSE {
  760. condition += ` AND b.department_id=?`
  761. pars = append(pars, sysUser.DepartmentId)
  762. }
  763. permissionCondition += ` AND b.department_id=? `
  764. permissionPars = append(permissionPars, sysUser.DepartmentId)
  765. }
  766. if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  767. if status != utils.COMPANY_STATUS_LOSE {
  768. condition += ` AND b.group_id=? `
  769. pars = append(pars, sysUser.GroupId)
  770. }
  771. permissionCondition += ` AND b.group_id=? `
  772. permissionPars = append(permissionPars, sysUser.GroupId)
  773. }
  774. if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
  775. pid, err := company.GetParentIdFromGroup(sysUser.GroupId)
  776. if err != nil {
  777. br.Msg = "获取失败"
  778. br.ErrMsg = "查询父级id异常" + err.Error()
  779. return
  780. }
  781. var ids []*string
  782. if pid != nil {
  783. if *pid != 0 {
  784. //销售主管放在三级列表中
  785. ids, err = company.GetGroupIdsByParentId(*pid)
  786. if err != nil {
  787. fmt.Println(err.Error())
  788. }
  789. } else {
  790. //销售主管放在二级列表中
  791. ids, err = company.GetGroupIdsByParentId(sysUser.GroupId)
  792. if err != nil {
  793. fmt.Println(err.Error())
  794. }
  795. }
  796. }
  797. var idSlice []string
  798. var sid string
  799. for _, id := range ids {
  800. idSlice = append(idSlice, *id)
  801. }
  802. //加入父级groupId
  803. if *pid > 0 {
  804. idSlice = append(idSlice, strconv.Itoa(*pid))
  805. } else {
  806. idSlice = append(idSlice, strconv.Itoa(sysUser.GroupId))
  807. }
  808. sid = strings.Join(idSlice, ",")
  809. if len(sid) > 0 {
  810. if status != utils.COMPANY_STATUS_LOSE {
  811. condition += ` AND (b.group_id IN (` + sid + `) OR status='流失') `
  812. //pars = append(pars, sysUser.GroupId)
  813. }
  814. permissionCondition += ` AND b.group_id IN (` + sid + `) `
  815. } else {
  816. if status != utils.COMPANY_STATUS_LOSE {
  817. condition += ` AND (b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) OR status='流失') `
  818. //pars = append(pars, sysUser.GroupId)
  819. }
  820. permissionCondition += ` AND b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) `
  821. }
  822. }
  823. if sysUser.Authority == 4 {
  824. if status != utils.COMPANY_STATUS_LOSE {
  825. condition += ` AND b.group_id =? `
  826. pars = append(pars, sysUser.GroupId)
  827. }
  828. permissionCondition += ` AND b.group_id=? `
  829. permissionPars = append(permissionPars, sysUser.GroupId)
  830. }
  831. }
  832. }
  833. }
  834. }
  835. }
  836. //状态控制
  837. if status != "" && status != "全部" {
  838. //switch status {
  839. //case "试用-活跃":
  840. // condition += ` AND b.status="试用" and b.view_total>= ? `
  841. // pars = append(pars, statistic_report.ActiveViewNum)
  842. //case "试用-非活跃":
  843. // condition += ` AND b.status="试用" and b.view_total < ? `
  844. // pars = append(pars, statistic_report.ActiveViewNum)
  845. //default:
  846. // condition += ` AND b.status=? `
  847. // pars = append(pars, status)
  848. //}
  849. condition += ` AND b.status=? `
  850. pars = append(pars, status)
  851. // 试用客户标签
  852. if status == "试用" && tryStage > 0 {
  853. condition += ` AND b.try_stage=? `
  854. pars = append(pars, tryStage)
  855. }
  856. }
  857. total, err := company.GetCompanyListCount(condition, pars)
  858. if err != nil {
  859. br.Msg = "获取失败"
  860. br.ErrMsg = "获取数据总数失败,Err:" + err.Error()
  861. return
  862. }
  863. //
  864. sortStr := ``
  865. if !sortByTodo {
  866. if sortParam != "" && sortType != "" {
  867. if sortParam == "expireDay" {
  868. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  869. if sortType == "asc" {
  870. sortStr = " ORDER BY min_end_date"
  871. } else {
  872. sortStr = " ORDER BY max_end_date"
  873. }
  874. } else {
  875. sortStr = " ORDER BY b.end_date "
  876. }
  877. } else if sortParam == "createTime" {
  878. sortStr = " ORDER BY a.created_time "
  879. } else if sortParam == "viewTotal" {
  880. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  881. sortStr = " ORDER BY all_view_total"
  882. } else {
  883. sortStr = " ORDER BY b.view_total "
  884. }
  885. } else if sortParam == "viewTime" {
  886. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  887. if sortType == "asc" {
  888. sortStr = " ORDER BY min_last_view_time"
  889. } else {
  890. sortStr = " ORDER BY max_last_view_time"
  891. }
  892. } else {
  893. sortStr = " ORDER BY b.last_view_time "
  894. }
  895. } else if sortParam == "roadShowTotal" {
  896. sortStr = " ORDER BY b.road_show_total "
  897. } else if sortParam == "formalTime" {
  898. sortStr = " ORDER BY b.formal_time "
  899. } else if sortParam == "freezeTime" {
  900. sortStr = " ORDER BY b.freeze_time "
  901. } else if sortParam == "lossTime" {
  902. sortStr = " ORDER BY b.loss_time "
  903. } else if sortParam == "todoCreateTime" {
  904. sortStr = " ORDER BY b.todo_create_time "
  905. } else if sortParam == "todoApproveTime" {
  906. sortStr = " ORDER BY b.todo_approve_time "
  907. } else if sortParam == "tryStage" && status == "试用" {
  908. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  909. sortStr = " ORDER BY sort_try_stage asc, all_view_total desc, a.created_time desc"
  910. } else {
  911. sortStr = " ORDER BY sort_try_stage asc, b.view_total desc, a.created_time desc"
  912. }
  913. } else if sortParam == "deadline" {
  914. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  915. sortStr = " ORDER BY sort_todo_end_time asc, all_view_total desc, a.created_time desc"
  916. } else {
  917. sortStr = " ORDER BY sort_todo_end_time asc, b.view_total desc, a.created_time desc"
  918. }
  919. } else if sortParam == "tryOutDay" {
  920. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  921. sortStr = " ORDER BY all_try_out_day_total "
  922. } else {
  923. sortStr = " ORDER BY b.try_out_day_total "
  924. }
  925. } else if sortParam == "closeTime" {
  926. sortStr = " ORDER BY b.close_time "
  927. } else {
  928. br.Msg = "获取失败"
  929. br.ErrMsg = "排序字段传入数据异常:" + sortParam
  930. return
  931. }
  932. if sortParam != "tryStage" && sortParam != "deadline" {
  933. if sortType == "asc" {
  934. sortStr += " ASC "
  935. } else if sortType == "desc" {
  936. sortStr += " DESC "
  937. } else {
  938. br.Msg = "获取失败"
  939. br.ErrMsg = "排序类型传入数据异常:" + sortType
  940. return
  941. }
  942. }
  943. } else {
  944. //2、客户列表选择“全部”时,支持按照“状态和阅读数”对“全部”分类下所有客户列表进行升降序排列;选择“正式”时按照“转正时间”、选择“冻结”时按照“冻结时间”、选择“流失”时按照“流失时间”、选择“永续”时按照“创建时间”;
  945. if status == "全部" {
  946. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  947. sortStr = " ORDER BY sort_status asc, all_view_total desc, a.created_time "
  948. } else {
  949. sortStr = " ORDER BY sort_status asc, b.view_total desc, a.created_time "
  950. }
  951. } else if status == "永续" {
  952. sortStr = " ORDER BY a.created_time "
  953. } else if status == "正式" {
  954. // 正式客户默认按照周阅读活跃ASC, 同为不活跃则按照转正时间DESC
  955. sortStr = " ORDER BY week_view_active ASC, b.formal_time "
  956. //sortStr = " ORDER BY b.formal_time "
  957. } else if status == "冻结" {
  958. sortStr = " ORDER BY b.freeze_time "
  959. } else if status == "流失" {
  960. sortStr = " ORDER BY b.loss_time "
  961. } else if status == "试用" {
  962. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  963. sortStr = " ORDER BY all_view_total desc, a.created_time "
  964. } else {
  965. sortStr = " ORDER BY b.view_total desc, a.created_time "
  966. }
  967. } else if status == utils.COMPANY_STATUS_CLOSE {
  968. // 关闭客户按照关闭时间DESC
  969. sortStr = " ORDER BY b.close_time "
  970. }
  971. sortStr += " DESC "
  972. }
  973. } else {
  974. sortStr = " ORDER BY FIELD (todo_status,'未完成','已完成','无任务'), todo_modify_time DESC "
  975. }
  976. //任务状态
  977. if todoStatus != "" {
  978. //排序,筛选出的未完成、已完成客户列表排序分别按照 最近一个任务的创建时间、最近一个任务的审核时间排序;
  979. switch todoStatus {
  980. case "未完成":
  981. if sortStr != "" {
  982. sortStr += " ,b.todo_create_time desc "
  983. } else {
  984. sortStr = " ORDER BY b.todo_create_time desc "
  985. }
  986. case "已完成":
  987. if sortStr != "" {
  988. sortStr += " ,b.todo_approve_time desc "
  989. } else {
  990. sortStr = " ORDER BY b.todo_approve_time desc "
  991. }
  992. }
  993. }
  994. list, err := company.GetCompanyList(condition, status, sortStr, pars, startSize, pageSize)
  995. if err != nil {
  996. br.Msg = "获取失败"
  997. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  998. return
  999. }
  1000. //企业用户数组切片
  1001. companyIdSlice := make([]string, 0)
  1002. companyIds := make([]int, 0)
  1003. for _, v := range list {
  1004. companyIdSlice = append(companyIdSlice, strconv.Itoa(v.CompanyId))
  1005. companyIds = append(companyIds, v.CompanyId)
  1006. }
  1007. //企业用户产品开通数
  1008. companyIdStr := strings.Join(companyIdSlice, ",")
  1009. companyProductTotalList, _ := company.GetCountProductByCompanyIds(companyIdStr)
  1010. companyProductTotalMap := make(map[int]*company.CompanyProductTotalSlice)
  1011. for _, companyProductTotal := range companyProductTotalList {
  1012. companyProductTotalMap[companyProductTotal.CompanyId] = companyProductTotal
  1013. }
  1014. lenList := len(list)
  1015. //companyFiccViewTimeMap := make(map[int]time.Time)
  1016. //companyRaiViewTimeMap := make(map[int]time.Time)
  1017. //companyFiccViewTotal := make(map[int]int)
  1018. //companyRaiViewTotal := make(map[int]int)
  1019. //获取最近阅读时间 和 累计阅读次数
  1020. //if lenList > 0 {
  1021. // //ficc 或者 全品种
  1022. // if productId == 1 || productId == 0 {
  1023. // companyFiccViewTimeMap, err = services.GetFiccLastUserViewHistoryByCompanyIds(companyIdStr)
  1024. // if err != nil {
  1025. // br.Msg = "获取失败"
  1026. // br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1027. // return
  1028. // }
  1029. // }
  1030. //
  1031. // if productId == 2 || productId == 0 {
  1032. // companyRaiViewTimeMap, err = services.GetRaiLastUserViewHistoryByCompanyIds(companyIdStr)
  1033. // if err != nil {
  1034. // br.Msg = "获取失败"
  1035. // br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1036. // return
  1037. // }
  1038. // }
  1039. //
  1040. // companyFiccViewTotal, err = services.GetFiccCountUserViewHistoryByCompanyIds(companyIdStr)
  1041. // if err != nil {
  1042. // br.Msg = "获取失败"
  1043. // br.ErrMsg = "获取ficc阅读数据失败,Err:" + err.Error()
  1044. // return
  1045. // }
  1046. // companyRaiViewTotal, err = services.GetRaiCountUserViewHistoryByCompanyIds(companyIdStr)
  1047. // if err != nil {
  1048. // br.Msg = "获取失败"
  1049. // br.ErrMsg = "获取权益阅读数据失败,Err:" + err.Error()
  1050. // return
  1051. // }
  1052. //}
  1053. // 客户产品详细信息
  1054. companyProductMap := make(map[string]*company.CompanyProduct)
  1055. var companyProductCondition string
  1056. var companyProductPars []interface{}
  1057. switch companyType {
  1058. case "ficc":
  1059. companyProductCondition += ` AND product_id=? `
  1060. companyProductPars = append(companyProductPars, 1)
  1061. case "权益":
  1062. companyProductCondition += ` AND product_id=? `
  1063. companyProductPars = append(companyProductPars, 2)
  1064. default:
  1065. }
  1066. companyProductList, err := company.GetCompanyProductsByCompanyIds(companyIdStr, companyProductCondition, companyProductPars)
  1067. if err != nil {
  1068. br.Msg = "获取失败"
  1069. br.ErrMsg = "获取客户产品数据失败,Err:" + err.Error()
  1070. return
  1071. }
  1072. for _, companyProduct := range companyProductList {
  1073. key := fmt.Sprint(companyProduct.CompanyId, "_", companyProduct.ProductId)
  1074. companyProductMap[key] = companyProduct
  1075. }
  1076. //任务待办
  1077. companyTodoMap := make(map[string]*company_todo.CompanyTodo)
  1078. {
  1079. var companyTodoCondition string
  1080. var companyTodoPars []interface{}
  1081. switch companyType {
  1082. case "ficc":
  1083. companyTodoCondition += ` AND product_id=? `
  1084. companyTodoPars = append(companyTodoPars, 1)
  1085. case "权益":
  1086. companyTodoCondition += ` AND product_id=? `
  1087. companyTodoPars = append(companyTodoPars, 2)
  1088. default:
  1089. }
  1090. companyTodoList, err := company_todo.GetDoingCompanyTodoByCompanyIds(companyIdStr, companyTodoCondition, companyTodoPars)
  1091. if err != nil {
  1092. br.Msg = "获取失败"
  1093. br.ErrMsg = "获取客户产品数据失败,Err:" + err.Error()
  1094. return
  1095. }
  1096. for _, companyTodo := range companyTodoList {
  1097. key := fmt.Sprint(companyTodo.CompanyId)
  1098. companyTodoMap[key] = companyTodo
  1099. }
  1100. }
  1101. // 查询是否有服务记录
  1102. btnServiceRecordMap := make(map[int]bool)
  1103. if len(companyIds) > 0 {
  1104. serRecOB := new(company.CompanyServiceRecord)
  1105. serRecCond := ` AND company_id IN (` + utils.GetOrmInReplace(len(companyIds)) + `) AND company_type = ? `
  1106. serRecPars := make([]interface{}, 0)
  1107. serRecPars = append(serRecPars, companyIds, 2)
  1108. serRecs, e := serRecOB.GetItemsByCondition(serRecCond, serRecPars, []string{"company_service_record_id", "company_id"}, "")
  1109. if e != nil {
  1110. br.Msg = "获取失败"
  1111. br.ErrMsg = "获取客户服务记录失败, Err: " + e.Error()
  1112. return
  1113. }
  1114. for _, s := range serRecs {
  1115. btnServiceRecordMap[s.CompanyId] = true
  1116. }
  1117. }
  1118. // 查询当前销售是否有领取客户的权限
  1119. receiveEnabled, _ := services.CheckCompanyReceiveButton(sysUser.AdminId)
  1120. for i := 0; i < lenList; i++ {
  1121. item := list[i]
  1122. //校验该客户是否存在多个产品,如果是,那么代表是共享客户
  1123. if companyProductTotal, ok := companyProductTotalMap[int(item.CompanyId)]; ok {
  1124. if companyProductTotal.Total > 1 {
  1125. list[i].IsShared = true
  1126. }
  1127. }
  1128. var expireDay string
  1129. itemStatus := item.Status
  1130. item.Status = strings.Replace(item.Status, utils.COMPANY_STATUS_FOREVER, utils.COMPANY_STATUS_X_CLASS_TRY_OUT, -1) // 永续客户类型,映射成 X类试用
  1131. if itemStatus != "" {
  1132. if !strings.Contains(item.Status, "/") {
  1133. if itemStatus == utils.COMPANY_STATUS_FOREVER { //永续
  1134. expireDay = "-"
  1135. } else if itemStatus == utils.COMPANY_STATUS_TRY_OUT || itemStatus == utils.COMPANY_STATUS_FORMAL { //试用/正式
  1136. if item.StartDate != "" && item.EndDate != "" {
  1137. endDateTime, _ := time.Parse(utils.FormatDate, item.EndDate)
  1138. endDateTime = endDateTime.AddDate(0, 0, 1)
  1139. sub := endDateTime.Sub(time.Now())
  1140. if sub < 0 {
  1141. sub = 0
  1142. }
  1143. expireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
  1144. } else {
  1145. expireDay = "-"
  1146. }
  1147. } else if itemStatus == utils.COMPANY_STATUS_LOSE {
  1148. expireDay = "-"
  1149. } else if itemStatus == utils.COMPANY_STATUS_FREEZE {
  1150. if item.StartDate != "" && item.EndDate != "" {
  1151. endDateTime, _ := time.Parse(utils.FormatDate, item.EndDate)
  1152. endDateTime = endDateTime.AddDate(0, 0, 0)
  1153. sub := endDateTime.Sub(time.Now())
  1154. if sub < 0 {
  1155. sub = 0
  1156. }
  1157. expireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
  1158. } else {
  1159. expireDay = "-"
  1160. }
  1161. } else {
  1162. expireDay = "-"
  1163. }
  1164. } else {
  1165. tmpStatusArr := strings.Split(item.Status, "/")
  1166. ficcStatus := tmpStatusArr[0]
  1167. raiStatus := tmpStatusArr[1]
  1168. var ficcEndDate, tryEndDate string
  1169. var ficcExpireDay, tryExpireDay string
  1170. if item.EndDate != "" {
  1171. endDateArr := strings.Split(item.EndDate, "/")
  1172. if len(endDateArr) == 1 {
  1173. ficcEndDate = endDateArr[0]
  1174. } else if len(endDateArr) > 1 {
  1175. ficcEndDate = endDateArr[0]
  1176. tryEndDate = endDateArr[1]
  1177. }
  1178. if ficcStatus == utils.COMPANY_STATUS_FOREVER { //永续
  1179. ficcExpireDay = "-"
  1180. } else if ficcStatus == utils.COMPANY_STATUS_TRY_OUT || ficcStatus == utils.COMPANY_STATUS_FORMAL { //试用/正式
  1181. if ficcEndDate != "" {
  1182. endDateTime, _ := time.Parse(utils.FormatDate, ficcEndDate)
  1183. endDateTime = endDateTime.AddDate(0, 0, 1)
  1184. sub := endDateTime.Sub(time.Now())
  1185. if sub < 0 {
  1186. sub = 0
  1187. }
  1188. ficcExpireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
  1189. } else {
  1190. ficcExpireDay = "-"
  1191. }
  1192. } else if ficcStatus == utils.COMPANY_STATUS_LOSE { //流失
  1193. ficcExpireDay = "-"
  1194. } else if ficcStatus == utils.COMPANY_STATUS_FREEZE { //冻结
  1195. if item.StartDate != "" && item.EndDate != "" {
  1196. endDateTime, _ := time.Parse(utils.FormatDate, ficcEndDate)
  1197. endDateTime = endDateTime.AddDate(0, 0, 0)
  1198. sub := endDateTime.Sub(time.Now())
  1199. if sub < 0 {
  1200. sub = 0
  1201. }
  1202. ficcExpireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
  1203. } else {
  1204. ficcExpireDay = "-"
  1205. }
  1206. } else {
  1207. ficcExpireDay = "-"
  1208. }
  1209. if raiStatus == utils.COMPANY_STATUS_FOREVER { //永续
  1210. tryExpireDay = "-"
  1211. } else if raiStatus == utils.COMPANY_STATUS_TRY_OUT || raiStatus == utils.COMPANY_STATUS_FORMAL { //试用/正式
  1212. if tryEndDate != "" {
  1213. endDateTime, _ := time.Parse(utils.FormatDate, tryEndDate)
  1214. endDateTime = endDateTime.AddDate(0, 0, 1)
  1215. sub := endDateTime.Sub(time.Now())
  1216. if sub < 0 {
  1217. sub = 0
  1218. }
  1219. tryExpireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
  1220. } else {
  1221. tryExpireDay = "-"
  1222. }
  1223. } else if raiStatus == utils.COMPANY_STATUS_LOSE { //流失
  1224. tryExpireDay = "-"
  1225. } else if raiStatus == utils.COMPANY_STATUS_FREEZE { //冻结
  1226. if item.StartDate != "" && item.EndDate != "" {
  1227. endDateTime, _ := time.Parse(utils.FormatDate, tryEndDate)
  1228. endDateTime = endDateTime.AddDate(0, 0, 0)
  1229. sub := endDateTime.Sub(time.Now())
  1230. if sub < 0 {
  1231. sub = 0
  1232. }
  1233. tryExpireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
  1234. } else {
  1235. tryExpireDay = "-"
  1236. }
  1237. } else {
  1238. tryExpireDay = "-"
  1239. }
  1240. }
  1241. expireDay = ficcExpireDay + "/" + tryExpireDay
  1242. }
  1243. }
  1244. list[i].ExpireDay = expireDay
  1245. //按钮显示控制
  1246. btnItem := new(company.ButtonPermission)
  1247. if item.CompanyId != 1 {
  1248. *btnItem = services.GetCompanyPermissionButton(roleTypeCode, itemStatus, item.SellerIds, item.GroupIds, item.GroupId, sysUser.GroupId, item.SellerId, sysUser.AdminId, sysUser.Authority, item.ProductId, -1, item.ShareSellerIds)
  1249. //根据销售"领取客户"的权限对部分按钮做限制
  1250. btnItem = services.GetCompanyPermissionButtonByReceiveEnabled(btnItem, receiveEnabled)
  1251. }
  1252. if list[i].IsShare == 1 && btnItem.BtnModifySeller == true && roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  1253. //如果已经是共享客户了,取消共享按钮全都显示,和修改销售权限一样
  1254. btnItem.BtnShare = true
  1255. }
  1256. if list[i].Status == utils.COMPANY_STATUS_FREEZE && list[i].CompanyType == utils.COMPANY_CLASSIFY_RAI && btnItem.BtnModifySeller == true && roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  1257. //权益冻结客户,也可以设置共享。冻结客户操作栏,增加设置共享按钮,可见权限不变(仅对权益管理员开放)
  1258. btnItem.BtnShare = true
  1259. }
  1260. list[i].BtnItem = btnItem
  1261. if item.FreezeStartDate != "" && item.FreezeEndDate != "" && item.Status == utils.COMPANY_STATUS_FREEZE {
  1262. freezeEndDate, _ := time.Parse(utils.FormatDate, item.FreezeEndDate)
  1263. if time.Now().Before(freezeEndDate) {
  1264. expireDays := freezeEndDate.Sub(time.Now()).Hours() / 24
  1265. list[i].FreezeExpireDays = int(expireDays) + 1
  1266. }
  1267. }
  1268. btnItem.BtnServiceRecord = btnServiceRecordMap[list[i].CompanyId]
  1269. // 签约未签约按钮回显展示
  1270. btnCompanyStatusItem := new(company.CompanyStatusButton)
  1271. btnCompanyStatusItem = services.GetLsitCompanyStatusButton(list[i].CompanyType, list[i].Status, list[i].SigningStatus)
  1272. list[i].CompanyStatusButton = btnCompanyStatusItem
  1273. //productIdArr := strings.Split(item.ProductIds, "/")
  1274. //// 套餐类型
  1275. //packageTypeArr := strings.Split(item.PackageTypes, "/")
  1276. //viewTotalArr := strings.Split(item.ViewTotals, "/") //总阅读次数
  1277. //lastViewTimeArr := strings.Split(item.LastViewTimes, "/") //最近阅读时间
  1278. //if len(productIdArr) > 1 {
  1279. // if len(packageTypeArr) == 1 {
  1280. // item.PackageTypes = item.PackageTypes + "/" + item.PackageTypes
  1281. // packageTypeArr = strings.Split(item.PackageTypes, "/")
  1282. // }
  1283. // //阅读次数
  1284. // if len(viewTotalArr) == 1 {
  1285. // item.ViewTotals = item.ViewTotals + "/" + item.ViewTotals
  1286. // viewTotalArr = strings.Split(item.ViewTotals, "/") //总阅读次数
  1287. // }
  1288. //
  1289. // if len(lastViewTimeArr) == 1 {
  1290. // item.LastViewTimes = item.LastViewTimes + "/" + item.LastViewTimes
  1291. // lastViewTimeArr = strings.Split(item.LastViewTimes, "/") //最近阅读时间
  1292. // }
  1293. //}
  1294. //for i, tmpProductId := range productIdArr {
  1295. // packageTypeInt, _ := strconv.Atoi(packageTypeArr[i])
  1296. // viewTotalInt, _ := strconv.Atoi(viewTotalArr[i])
  1297. // lastViewTime := lastViewTimeArr[i]
  1298. // //ficc
  1299. // if tmpProductId == "1" {
  1300. // //套餐类型
  1301. // item.FiccPackageType = packageTypeInt
  1302. //
  1303. // //总阅读次数
  1304. // item.FiccView = viewTotalInt
  1305. //
  1306. // //最近一次阅读时间
  1307. // item.FiccLastViewTime = lastViewTime
  1308. // }
  1309. // //权益
  1310. // if tmpProductId == "2" {
  1311. // //总阅读次数
  1312. // item.RaiView = viewTotalInt
  1313. //
  1314. // //最近一次阅读时间
  1315. // item.RaiLastViewTime = lastViewTime
  1316. // }
  1317. //}
  1318. ficcKey := fmt.Sprint(item.CompanyId, "_", 1)
  1319. //ficc
  1320. if tmpCompanyProduct, ok := companyProductMap[ficcKey]; ok {
  1321. //套餐类型
  1322. item.FiccPackageType = tmpCompanyProduct.PackageType
  1323. //总试用天数
  1324. item.FiccTryOutDay = tmpCompanyProduct.TryOutDayTotal
  1325. //总阅读次数
  1326. item.FiccView = tmpCompanyProduct.ViewTotal
  1327. if !tmpCompanyProduct.LastViewTime.IsZero() {
  1328. //最近一次阅读时间
  1329. item.FiccLastViewTime = tmpCompanyProduct.LastViewTime.Format(utils.FormatDateTime)
  1330. }
  1331. }
  1332. //权益
  1333. raiKey := fmt.Sprint(item.CompanyId, "_", 2)
  1334. if tmpCompanyProduct, ok := companyProductMap[raiKey]; ok {
  1335. //总阅读次数
  1336. item.RaiView = tmpCompanyProduct.ViewTotal
  1337. //总试用天数
  1338. item.RaiTryOutDay = tmpCompanyProduct.TryOutDayTotal
  1339. if !tmpCompanyProduct.LastViewTime.IsZero() {
  1340. //最近一次阅读时间
  1341. item.RaiLastViewTime = tmpCompanyProduct.LastViewTime.Format(utils.FormatDateTime)
  1342. }
  1343. }
  1344. //最近阅读时间
  1345. //if viewTime, ok := companyFiccViewTimeMap[item.CompanyId]; ok {
  1346. // item.FiccLastViewTime = viewTime.Format(utils.FormatDateTime)
  1347. //}
  1348. //
  1349. //if viewTime, ok := companyRaiViewTimeMap[item.CompanyId]; ok {
  1350. // item.RaiLastViewTime = viewTime.Format(utils.FormatDateTime)
  1351. //}
  1352. // 试用客户子标签
  1353. if strings.Contains(item.Status, "试用") {
  1354. statusSlice := strings.Split(item.Status, "/")
  1355. stageItemSlice := strings.Split(item.TryStageStr, "/")
  1356. productIdSlice := strings.Split(item.ProductIds, "/")
  1357. for sk, sv := range statusSlice {
  1358. if sv != "试用" {
  1359. continue
  1360. }
  1361. tryItem := new(company.TryStageSliceItem)
  1362. if len(productIdSlice) < (sk+1) || len(stageItemSlice) < (sk+1) {
  1363. continue
  1364. }
  1365. key := fmt.Sprint(item.CompanyId, "_", productIdSlice[sk])
  1366. if pro, ok := companyProductMap[key]; ok {
  1367. tryItem.ProductId, _ = strconv.Atoi(productIdSlice[sk])
  1368. if pro.SellerId == sysUser.AdminId { //产品销售ID和登录ID相等
  1369. tryItem.HasPermission = true
  1370. }
  1371. tryItem.TryStage, _ = strconv.Atoi(stageItemSlice[sk])
  1372. list[i].TryStageSlice = append(list[i].TryStageSlice, tryItem)
  1373. }
  1374. }
  1375. }
  1376. // To-Do任务状态为未完成的对应任务的截止日期-当前日期;
  1377. if strings.Contains(item.TodoStatuss, "未完成") {
  1378. if strings.Contains(item.TodoEndTimeStr, "/") {
  1379. edtSlice := strings.Split(item.TodoEndTimeStr, "/")
  1380. item.TodoEndTime, _ = time.ParseInLocation(utils.FormatDateTime, edtSlice[0], time.Local)
  1381. } else {
  1382. item.TodoEndTime, _ = time.ParseInLocation(utils.FormatDateTime, item.TodoEndTimeStr, time.Local)
  1383. }
  1384. tmpEndTime := item.TodoEndTime.Format(utils.FormatDate)
  1385. if tmpEndTime == "0001-01-01" {
  1386. tmpEndTime = ""
  1387. }
  1388. if tmpEndTime != "" {
  1389. dlTime1 := time.Date(time.Now().Year(), time.Now().Month(), time.Now().Day(), 0, 0, 0, 0, time.Local)
  1390. dlTime2 := time.Date(item.TodoEndTime.Year(), item.TodoEndTime.Month(), item.TodoEndTime.Day(), 0, 0, 0, 0, time.Local)
  1391. dldays := int(dlTime2.Sub(dlTime1).Hours() / 24)
  1392. list[i].Deadline = strconv.Itoa(dldays)
  1393. }
  1394. }
  1395. }
  1396. statusCount, err := company.GetCompanyStatusCount(permissionCondition, permissionPars)
  1397. if err != nil {
  1398. br.Msg = "获取失败"
  1399. br.ErrMsg = "获取状态数量失败,Err:" + err.Error()
  1400. return
  1401. }
  1402. statusMap := make(map[string]int, 0)
  1403. var totalCount int
  1404. for _, sv := range statusCount {
  1405. sv.Status = strings.Replace(sv.Status, utils.COMPANY_STATUS_FOREVER, utils.COMPANY_STATUS_X_CLASS_TRY_OUT, -1) // 永续客户类型,映射成 X类试用
  1406. totalCount = totalCount + sv.Count
  1407. statusMap[sv.Status] = sv.Count
  1408. }
  1409. // 统计试用客户的子标签数量,只在试用状态页面统计
  1410. var tryStageCountResp []*company.CompanyTryStageCount
  1411. if status == "试用" {
  1412. tryStageCount, err := company.GetCompanyTryStageCount(permissionCondition, permissionPars)
  1413. if err != nil {
  1414. br.Msg = "获取失败"
  1415. br.ErrMsg = "获取试用状态标签数量失败,Err:" + err.Error()
  1416. return
  1417. }
  1418. tryStageMap := make(map[int]int)
  1419. for _, v := range tryStageCount {
  1420. tryStageMap[0] += v.Count
  1421. tryStageMap[v.TryStage] = v.Count
  1422. }
  1423. tryStageAllMap := map[int]string{
  1424. 0: "全部",
  1425. 2: "推进",
  1426. 3: "跟踪",
  1427. 4: "预备",
  1428. 1: "未分类",
  1429. }
  1430. for k, v := range tryStageAllMap {
  1431. item := new(company.CompanyTryStageCount)
  1432. item.TryStageStr = v
  1433. item.TryStage = k
  1434. if count, ok := tryStageMap[k]; ok {
  1435. item.Count = count
  1436. }
  1437. tryStageCountResp = append(tryStageCountResp, item)
  1438. }
  1439. }
  1440. //
  1441. ////试用-活跃
  1442. //{
  1443. // tmpPermissionCondition := permissionCondition
  1444. // tmpPermissionPars := permissionPars
  1445. // tmpPermissionCondition += ` and b.view_total>=? `
  1446. // tmpPermissionPars = append(tmpPermissionPars, statistic_report.ActiveViewNum)
  1447. //
  1448. // tryOutActiveCount, err := company.GetCompanyTryOutStatusCount(tmpPermissionCondition, tmpPermissionPars)
  1449. // if err != nil {
  1450. // br.Msg = "获取失败"
  1451. // br.ErrMsg = "获取状态数量失败,Err:" + err.Error()
  1452. // return
  1453. // }
  1454. // statusMap["试用-活跃"] = tryOutActiveCount.Count
  1455. //}
  1456. //
  1457. ////试用-非活跃
  1458. //{
  1459. // tmpPermissionCondition := permissionCondition
  1460. // tmpPermissionPars := permissionPars
  1461. // tmpPermissionCondition += ` and b.view_total <? `
  1462. // tmpPermissionPars = append(tmpPermissionPars, statistic_report.ActiveViewNum)
  1463. //
  1464. // tryOutActiveCount, err := company.GetCompanyTryOutStatusCount(tmpPermissionCondition, tmpPermissionPars)
  1465. // if err != nil {
  1466. // br.Msg = "获取失败"
  1467. // br.ErrMsg = "获取状态数量失败,Err:" + err.Error()
  1468. // return
  1469. // }
  1470. // statusMap["试用-非活跃"] = tryOutActiveCount.Count
  1471. //}
  1472. lossItem, err := company.GetCompanyStatusLoseCount(lossCondition, lossPars)
  1473. if err != nil {
  1474. br.Msg = "获取失败"
  1475. br.ErrMsg = "获取流失状态数量失败,Err:" + err.Error()
  1476. return
  1477. }
  1478. totalCount = totalCount + lossItem.Count
  1479. for _, v := range statusArr {
  1480. s := new(company.CompanyStatus)
  1481. if v == "全部" {
  1482. s.Status = "全部"
  1483. s.Count = totalCount
  1484. } else if v == utils.COMPANY_STATUS_LOSE {
  1485. s.Status = v
  1486. s.Count = lossItem.Count
  1487. } else {
  1488. s.Status = v
  1489. if val, ok := statusMap[v]; ok {
  1490. s.Count = val
  1491. }
  1492. }
  1493. statusItems = append(statusItems, s)
  1494. }
  1495. sysUserList, err := system.GetAdminList()
  1496. if err != nil {
  1497. br.Msg = "获取失败"
  1498. br.ErrMsg = "获取admin列表失败, Err:" + err.Error()
  1499. return
  1500. }
  1501. adminMap := make(map[int]*system.Admin, 0)
  1502. for _, v := range sysUserList {
  1503. adminMap[v.AdminId] = v
  1504. }
  1505. companyLists := make([]*company.CompanyListItem, 0)
  1506. //查询阅读次数
  1507. if list == nil {
  1508. companyLists = make([]*company.CompanyListItem, 0)
  1509. } else {
  1510. for _, v := range list {
  1511. //viewTotal:=GetviewTotal(v.CompanyId)
  1512. //活跃(客户状态)
  1513. //if v.IsShare != 1 {
  1514. // if v.BtnItem.BtnModifySeller == true {
  1515. // v.BtnItem.BtnModifySeller = false
  1516. // }
  1517. //}
  1518. //productIdSlice := strings.Split(v.ProductIds, "/")
  1519. //statusSlice := strings.Split(v.Status, "/")
  1520. //for productIndex, tmpProductId := range productIdSlice {
  1521. // tmpStatusIndex := 0
  1522. // if len(statusSlice) > 1 {
  1523. // tmpStatusIndex = productIndex
  1524. // }
  1525. // tmpProductStatus := statusSlice[tmpStatusIndex]
  1526. // if strings.Contains(tmpProductStatus, "试用") {
  1527. // activeType := "非活跃"
  1528. // viewNum := v.FiccView
  1529. // if tmpProductId == "2" {
  1530. // viewNum = v.RaiView
  1531. // }
  1532. // if viewNum >= statistic_report.ActiveViewNum {
  1533. // activeType = "活跃"
  1534. // }
  1535. // statusSlice[tmpStatusIndex] = fmt.Sprint(tmpProductStatus, "(", activeType, ")")
  1536. //
  1537. // tmpStatus = strings.Join(statusSlice, "/")
  1538. // }
  1539. //}
  1540. //ficcViewTotal, ok := companyFiccViewTotal[v.CompanyId]
  1541. //if !ok {
  1542. // ficcViewTotal = 0
  1543. //}
  1544. //raiViewTotal, ok := companyRaiViewTotal[v.CompanyId]
  1545. //if !ok {
  1546. // raiViewTotal = 0
  1547. //}
  1548. // 是否存在进行中的任务
  1549. var todoStatus bool
  1550. if _, ok := companyTodoMap[fmt.Sprint(v.CompanyId)]; ok {
  1551. todoStatus = true
  1552. }
  1553. //是否支持确认完成待办任务
  1554. var canConfirm bool
  1555. var hiddenConfirm bool //是否隐藏确定完成按钮
  1556. var hiddenCreate bool //是否隐藏新增/编辑按钮
  1557. hiddenConfirm = true
  1558. hiddenCreate = true
  1559. for _, vProductId := range []int{1, 2} {
  1560. ficcKey := fmt.Sprint(v.CompanyId, "_", vProductId)
  1561. //ficc
  1562. if tmpCompanyProduct, ok := companyProductMap[ficcKey]; ok {
  1563. if tmpCompanyProduct.Status != utils.COMPANY_STATUS_LOSE && tmpCompanyProduct.Status != utils.COMPANY_STATUS_CLOSE { //非流失或关闭
  1564. hiddenCreate = false
  1565. switch this.SysUser.RoleTypeCode {
  1566. 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:
  1567. //部门管理员、ficc主管、权益组长
  1568. hiddenConfirm = false //不展示
  1569. if todoStatus { //有任务,需要展示
  1570. canConfirm = true
  1571. }
  1572. case utils.ROLE_TYPE_CODE_FICC_TEAM: //ficc组长
  1573. if todoStatus { //有任务,需要展示
  1574. canConfirm = true
  1575. }
  1576. if v.SellerId != this.SysUser.AdminId { //不是自己的客户
  1577. hiddenConfirm = false //展示
  1578. }
  1579. case utils.ROLE_TYPE_CODE_RAI_SELLER: //权益销售
  1580. if v.SellerId == this.SysUser.AdminId { //是自己的客户
  1581. has := services.CheckRaiApprovePermission(sysUser.AdminId) //这些个权益销售是有权限的
  1582. if has {
  1583. if todoStatus { //有任务,需要展示
  1584. canConfirm = true
  1585. }
  1586. hiddenConfirm = false //展示
  1587. }
  1588. }
  1589. }
  1590. }
  1591. }
  1592. }
  1593. todoButtonColor := `green`
  1594. //'无任务','未完成','已完成'
  1595. if strings.Contains(v.TodoStatuss, "未完成") {
  1596. todoButtonColor = "red"
  1597. } else if strings.Contains(v.TodoStatuss, "已完成") {
  1598. todoButtonColor = "green"
  1599. } else if strings.Contains(v.TodoStatuss, "无任务") {
  1600. todoButtonColor = "gray"
  1601. }
  1602. //永续客户X类试用客户出参转换
  1603. v.StatusStr = strings.Replace(v.StatusStr, utils.COMPANY_STATUS_FOREVER, utils.COMPANY_STATUS_X_CLASS_TRY_OUT, -1)
  1604. if !utils.InArrayByStr([]string{"正式", "试用", "永续", "X类试用"}, v.Status) { //不是这几种状态不做标红处理
  1605. v.IsUserMaker = 0
  1606. }
  1607. //解决共享客户正式筛选下是否标红的问题
  1608. if v.WeekViewActive == 0 && v.IsUserMaker == 1 {
  1609. v.WeekViewActive = 1
  1610. }
  1611. companyList := &company.CompanyListItem{
  1612. CompanyId: v.CompanyId,
  1613. CompanyName: v.CompanyName,
  1614. CreditCode: v.CreditCode,
  1615. CompanyCode: v.CompanyCode,
  1616. StartDate: v.StartDate,
  1617. EndDate: v.EndDate,
  1618. LoseReason: v.LoseReason,
  1619. RenewalReason: v.RenewalReason,
  1620. FreezeReason: v.FreezeReason,
  1621. LossTime: v.LossTime,
  1622. Status: v.StatusStr,
  1623. CompanyType: v.CompanyType,
  1624. ApproveStatus: v.ApproveStatus,
  1625. SellerName: v.SellerName,
  1626. SellerId: v.SellerId,
  1627. SellerIds: v.SellerIds,
  1628. ExpireDay: v.ExpireDay,
  1629. FreezeTime: v.FreezeTime,
  1630. GroupId: v.GroupId,
  1631. GroupIds: v.GroupIds,
  1632. DepartmentId: v.DepartmentId,
  1633. IndustryName: v.IndustryName,
  1634. IsSuspend: v.IsSuspend,
  1635. CreatedTime: v.CreatedTime,
  1636. Source: v.Source,
  1637. Province: v.Province,
  1638. City: v.City,
  1639. Address: v.Address,
  1640. Reasons: v.Reasons,
  1641. FreezeStartDate: v.FreezeStartDate,
  1642. FreezeEndDate: v.FreezeEndDate,
  1643. FreezeExpireDays: v.FreezeExpireDays,
  1644. BtnItem: v.BtnItem,
  1645. ProductId: v.ProductId,
  1646. FormalTime: v.FormalTime,
  1647. IsShared: v.IsShared,
  1648. RegionType: v.RegionType,
  1649. FiccPackageType: v.FiccPackageType,
  1650. FiccLastViewTime: v.FiccLastViewTime,
  1651. RaiLastViewTime: v.RaiLastViewTime,
  1652. //FiccView: viewTotal[0],
  1653. //RaiView: viewTotal[1],
  1654. //FiccView: ficcViewTotal,
  1655. //RaiView: raiViewTotal,
  1656. FiccView: v.FiccView,
  1657. RaiView: v.RaiView,
  1658. FiccTryOutDay: v.FiccTryOutDay,
  1659. RaiTryOutDay: v.RaiTryOutDay,
  1660. AllViewTotal: v.AllViewTotal,
  1661. RoadShowTotal: v.RoadShowTotal,
  1662. TodoStatus: todoStatus,
  1663. CanConfirm: canConfirm,
  1664. HiddenConfirm: hiddenConfirm,
  1665. HiddenCreate: hiddenCreate,
  1666. TodoButtonColor: todoButtonColor,
  1667. TryStageSlice: v.TryStageSlice,
  1668. Deadline: v.Deadline,
  1669. WeekViewActive: v.WeekViewActive,
  1670. IsShare: v.IsShare,
  1671. CloseTime: v.CloseTime,
  1672. CloseReason: v.CloseReason,
  1673. IsSigning: v.IsSigning,
  1674. CompanyStatusButton: v.CompanyStatusButton,
  1675. ShareSellerId: v.ShareSellerId,
  1676. ShareSellerIds: v.ShareSellerIds,
  1677. IsUserMaker: v.IsUserMaker,
  1678. }
  1679. if v.ShareSellerIds != "" {
  1680. shareSellerIds := strings.Split(v.ShareSellerIds, ",")
  1681. for _, idStr := range shareSellerIds {
  1682. shareSellerId, e := strconv.Atoi(idStr)
  1683. if e != nil {
  1684. err = e
  1685. return
  1686. }
  1687. shareSeller := adminMap[shareSellerId]
  1688. if shareSeller != nil {
  1689. companyList.ShareSeller += shareSeller.RealName + "(" + shareSeller.GroupName + ")" + "/"
  1690. }
  1691. }
  1692. companyList.ShareSeller = strings.TrimRight(companyList.ShareSeller, "/")
  1693. }
  1694. companyLists = append(companyLists, companyList)
  1695. }
  1696. }
  1697. if companyLists == nil {
  1698. companyLists = make([]*company.CompanyListItem, 0)
  1699. }
  1700. // 白嫖客户标记
  1701. scroungeList, err := company.GetScroungeCompany()
  1702. if err != nil {
  1703. br.Msg = "获取失败"
  1704. br.ErrMsg = "获取白嫖客户信息失败,Err:" + err.Error()
  1705. return
  1706. }
  1707. scroungeMap := make(map[int]int)
  1708. for _, v := range scroungeList {
  1709. scroungeMap[v.CompanyId] = 1
  1710. }
  1711. for i, v := range companyLists {
  1712. if _, ok := scroungeMap[v.CompanyId]; ok {
  1713. companyLists[i].IsScrounge = 1
  1714. }
  1715. }
  1716. page = paging.GetPaging(currentIndex, pageSize, total)
  1717. resp.List = companyLists
  1718. resp.StatusCount = statusItems
  1719. resp.TryStageCount = tryStageCountResp
  1720. resp.Paging = page
  1721. resp.AddCompanyBtn = receiveEnabled
  1722. br.Ret = 200
  1723. br.Success = true
  1724. br.Msg = "获取成功"
  1725. br.Data = resp
  1726. }
  1727. //func (this *CompanyController) ListOld() {
  1728. // br := new(models.BaseResponse).Init()
  1729. // defer func() {
  1730. // this.Data["json"] = br
  1731. // this.ServeJSON()
  1732. // }()
  1733. // sysUser := this.SysUser
  1734. // if sysUser == nil {
  1735. // br.Msg = "请登录"
  1736. // br.ErrMsg = "请登录,SysUser Is Empty"
  1737. // br.Ret = 408
  1738. // return
  1739. // }
  1740. // roleTypeCode := sysUser.RoleTypeCode
  1741. //
  1742. // pageSize, _ := this.GetInt("PageSize")
  1743. // currentIndex, _ := this.GetInt("CurrentIndex")
  1744. // status := this.GetString("Status")
  1745. // companyType := this.GetString("CompanyType")
  1746. // industryId, _ := this.GetInt("IndustryId")
  1747. // adminId := this.GetString("AdminId")
  1748. //
  1749. // chartPermissionIds := this.GetString("ChartPermissionIds")
  1750. // startDate := this.GetString("StartDate")
  1751. // endDate := this.GetString("EndDate")
  1752. // createStartDate := this.GetString("CreateStartDate")
  1753. // createEndDate := this.GetString("CreateEndDate")
  1754. // keyWord := this.GetString("KeyWord")
  1755. // keyWord = strings.Trim(keyWord, " ")
  1756. // keyWord = strings.Replace(keyWord, "'", "", -1)
  1757. //
  1758. // //排序参数
  1759. // sortParam := this.GetString("SortParam")
  1760. // sortType := this.GetString("SortType")
  1761. //
  1762. // var total int
  1763. // page := paging.GetPaging(currentIndex, pageSize, total)
  1764. // resp := new(company.CompanyListResp)
  1765. // statusItems := make([]*company.CompanyStatus, 0)
  1766. // var statusArr = [...]string{"全部", "试用", "正式", "冻结", "流失", "永续"}
  1767. //
  1768. // var startSize int
  1769. // if pageSize <= 0 {
  1770. // pageSize = utils.PageSize20
  1771. // }
  1772. // if currentIndex <= 0 {
  1773. // currentIndex = 1
  1774. // }
  1775. // startSize = paging.StartIndex(currentIndex, pageSize)
  1776. // var condition string
  1777. // var pars []interface{}
  1778. //
  1779. // //流失
  1780. // var lossCondition string
  1781. // var lossPars []interface{}
  1782. // //冻结
  1783. // var freezeCondition string
  1784. // var freezePars []interface{}
  1785. //
  1786. // //永续
  1787. // var forverCondition string
  1788. // var forverPars []interface{}
  1789. //
  1790. // var permissionCondition string
  1791. // var permissionPars []interface{}
  1792. //
  1793. // if status != "" && status != "全部" {
  1794. // condition += ` AND b.status=? `
  1795. // pars = append(pars, status)
  1796. //
  1797. // //permissionCondition += ` AND b.status=? `
  1798. // //permissionPars = append(permissionPars, status)
  1799. // }
  1800. // if companyType != "" {
  1801. // condition += ` AND b.product_name=? `
  1802. // pars = append(pars, companyType)
  1803. //
  1804. // lossCondition += ` AND b.product_name=? `
  1805. // lossPars = append(lossPars, companyType)
  1806. //
  1807. // freezeCondition += ` AND b.product_name=? `
  1808. // freezePars = append(freezePars, companyType)
  1809. //
  1810. // forverCondition += ` AND b.product_name=? `
  1811. // forverPars = append(forverPars, companyType)
  1812. //
  1813. // permissionCondition += ` AND b.product_name=? `
  1814. // permissionPars = append(permissionPars, companyType)
  1815. // }
  1816. //
  1817. // if industryId > 0 {
  1818. // condition += ` AND b.industry_id=? `
  1819. // pars = append(pars, industryId)
  1820. //
  1821. // lossCondition += ` AND b.industry_id=? `
  1822. // lossPars = append(lossPars, industryId)
  1823. //
  1824. // freezeCondition += ` AND b.industry_id=? `
  1825. // freezePars = append(freezePars, industryId)
  1826. //
  1827. // forverCondition += ` AND b.industry_id=? `
  1828. // forverPars = append(forverPars, industryId)
  1829. //
  1830. // permissionCondition += ` AND b.industry_id=? `
  1831. // permissionPars = append(permissionPars, industryId)
  1832. // }
  1833. //
  1834. // if adminId != "" {
  1835. // condition += ` AND b.seller_id IN (` + adminId + `) `
  1836. //
  1837. // lossCondition += ` AND b.seller_id IN (` + adminId + `) `
  1838. //
  1839. // freezeCondition += ` AND b.seller_id IN (` + adminId + `) `
  1840. //
  1841. // forverCondition += ` AND b.seller_id IN (` + adminId + `) `
  1842. //
  1843. // permissionCondition += ` AND b.seller_id IN (` + adminId + `) `
  1844. // }
  1845. //
  1846. // if startDate != "" {
  1847. // condition += ` AND b.start_date>=? `
  1848. // pars = append(pars, startDate)
  1849. //
  1850. // lossCondition += ` AND b.start_date>=? `
  1851. // lossPars = append(lossPars, startDate)
  1852. //
  1853. // freezeCondition += ` AND b.start_date>=? `
  1854. // freezePars = append(freezePars, startDate)
  1855. //
  1856. // forverCondition += ` AND b.start_date>=? `
  1857. // forverPars = append(forverPars, startDate)
  1858. //
  1859. // permissionCondition += ` AND b.start_date>=? `
  1860. // permissionPars = append(permissionPars, startDate)
  1861. // }
  1862. //
  1863. // if endDate != "" {
  1864. // condition += ` AND b.end_date<=? `
  1865. // pars = append(pars, endDate)
  1866. //
  1867. // lossCondition += ` AND b.end_date<=? `
  1868. // lossPars = append(lossPars, endDate)
  1869. //
  1870. // freezeCondition += ` AND b.end_date<=? `
  1871. // freezePars = append(freezePars, endDate)
  1872. //
  1873. // forverCondition += ` AND b.end_date<=? `
  1874. // forverPars = append(forverPars, endDate)
  1875. //
  1876. // permissionCondition += ` AND b.end_date<=? `
  1877. // permissionPars = append(permissionPars, endDate)
  1878. // }
  1879. //
  1880. // if createStartDate != "" {
  1881. // condition += ` AND a.created_time>=? `
  1882. // pars = append(pars, createStartDate)
  1883. //
  1884. // lossCondition += ` AND a.created_time>=? `
  1885. // lossPars = append(lossPars, createStartDate)
  1886. //
  1887. // freezeCondition += ` AND a.created_time>=? `
  1888. // freezePars = append(freezePars, createStartDate)
  1889. //
  1890. // forverCondition += ` AND a.created_time>=? `
  1891. // forverPars = append(forverPars, createStartDate)
  1892. //
  1893. // permissionCondition += ` AND a.created_time>=? `
  1894. // permissionPars = append(permissionPars, createStartDate)
  1895. // }
  1896. //
  1897. // if createEndDate != "" {
  1898. // condition += ` AND a.created_time<=? `
  1899. // pars = append(pars, createEndDate)
  1900. //
  1901. // lossCondition += ` AND a.created_time<=? `
  1902. // lossPars = append(lossPars, createEndDate)
  1903. //
  1904. // freezeCondition += ` AND a.created_time<=? `
  1905. // freezePars = append(freezePars, createEndDate)
  1906. //
  1907. // forverCondition += ` AND a.created_time<=? `
  1908. // forverPars = append(forverPars, createEndDate)
  1909. //
  1910. // permissionCondition += ` AND a.created_time<=? `
  1911. // permissionPars = append(permissionPars, createEndDate)
  1912. // }
  1913. //
  1914. // if keyWord != "" {
  1915. // companyIdStr, err := company.GetCompanyIdByKeyWord(keyWord)
  1916. // if err != nil {
  1917. // br.Msg = "获取客户信息失败"
  1918. // br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  1919. // return
  1920. // }
  1921. // if companyIdStr != "" {
  1922. // condition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.company_id IN(` + companyIdStr + `)) `
  1923. // lossCondition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.company_id IN(` + companyIdStr + `)) `
  1924. // freezeCondition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.company_id IN(` + companyIdStr + `)) `
  1925. // forverCondition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.company_id IN(` + companyIdStr + `)) `
  1926. //
  1927. // permissionCondition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.company_id IN(` + companyIdStr + `)) `
  1928. // } else {
  1929. // condition += ` AND (a.company_name LIKE '%` + keyWord + `%' ) `
  1930. // lossCondition += ` AND (a.company_name LIKE '%` + keyWord + `%' ) `
  1931. // freezeCondition += ` AND (a.company_name LIKE '%` + keyWord + `%' ) `
  1932. // forverCondition += ` AND (a.company_name LIKE '%` + keyWord + `%' ) `
  1933. //
  1934. // permissionCondition += ` AND (a.company_name LIKE '%` + keyWord + `%' ) `
  1935. // }
  1936. // }
  1937. // if chartPermissionIds != "" && chartPermissionIds != "1" {
  1938. // //chartPermissionArr := strings.Split(chartPermissionIds, ",")
  1939. // //chartPermissionCount := len(chartPermissionArr)
  1940. // companyIdStr, err := company.GetCompanyListCompanyIdByPermissionIdStr(chartPermissionIds)
  1941. // if err != nil {
  1942. // br.Msg = "获取失败"
  1943. // br.ErrMsg = "根据权限获取公司ID失败,Err:" + err.Error()
  1944. // return
  1945. // }
  1946. // //var companyIdArr []string
  1947. // //for _, v := range companyIdList {
  1948. // // companyIdArr = append(companyIdArr, strconv.Itoa(v.CompanyId))
  1949. // //}
  1950. // //companyIdStr := strings.Join(companyIdArr, ",")
  1951. // if companyIdStr != "" {
  1952. // condition += ` AND a.company_id IN (` + companyIdStr + `) `
  1953. // lossCondition += ` AND a.company_id IN (` + companyIdStr + `) `
  1954. // freezeCondition += ` AND a.company_id IN (` + companyIdStr + `) `
  1955. // forverCondition += ` AND a.company_id IN (` + companyIdStr + `) `
  1956. // permissionCondition += ` AND a.company_id IN (` + companyIdStr + `) `
  1957. // } else {
  1958. // for _, v := range statusArr {
  1959. // statusCount := new(company.CompanyStatus)
  1960. // if v == "全部" {
  1961. // statusCount.Status = "全部"
  1962. // statusCount.Count = 0
  1963. // } else {
  1964. // statusCount.Status = v
  1965. // statusCount.Count = 0
  1966. // }
  1967. // statusItems = append(statusItems, statusCount)
  1968. // }
  1969. // items := make([]*company.CompanyListItem, 0)
  1970. // resp.List = items
  1971. // resp.Paging = page
  1972. // resp.StatusCount = statusItems
  1973. // br.Msg = "获取成功"
  1974. // br.Ret = 200
  1975. // br.Data = resp
  1976. // return
  1977. // }
  1978. // }
  1979. // //权限控制
  1980. // {
  1981. // fmt.Println(roleTypeCode)
  1982. // if roleTypeCode != utils.ROLE_TYPE_CODE_ADMIN {
  1983. // if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN {
  1984. // condition += ` AND b.product_id=? `
  1985. // pars = append(pars, 1)
  1986. //
  1987. // permissionCondition += ` AND b.product_id=? `
  1988. // permissionPars = append(permissionPars, 1)
  1989. // } else if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  1990. // condition += ` AND b.product_id=? `
  1991. // pars = append(pars, 2)
  1992. //
  1993. // permissionCondition += ` AND b.product_id=? `
  1994. // permissionPars = append(permissionPars, 2)
  1995. // } else {
  1996. // if sysUser.Authority <= 0 {
  1997. // if status == utils.COMPANY_STATUS_TRY_OUT || status == utils.COMPANY_STATUS_FORMAL || status == "全部" {
  1998. // if status == "全部" {
  1999. // condition += ` AND (b.seller_id=? OR status='流失' OR status='永续') `
  2000. // pars = append(pars, sysUser.AdminId)
  2001. // } else {
  2002. // condition += ` AND b.seller_id=? `
  2003. // pars = append(pars, sysUser.AdminId)
  2004. // }
  2005. // }
  2006. // permissionCondition += ` AND b.seller_id=? `
  2007. // permissionPars = append(permissionPars, sysUser.AdminId)
  2008. // } else {
  2009. // if sysUser.Authority == 1 {
  2010. // if status == utils.COMPANY_STATUS_TRY_OUT || status == utils.COMPANY_STATUS_FORMAL || status == "全部" {
  2011. // condition += ` AND b.department_id=? `
  2012. // pars = append(pars, sysUser.DepartmentId)
  2013. //
  2014. // permissionCondition += ` AND b.department_id=? `
  2015. // permissionPars = append(permissionPars, sysUser.DepartmentId)
  2016. // } else {
  2017. // permissionCondition += ` AND b.department_id=? `
  2018. // permissionPars = append(permissionPars, sysUser.DepartmentId)
  2019. // }
  2020. // }
  2021. //
  2022. // if sysUser.Authority == 2 {
  2023. // if status == utils.COMPANY_STATUS_TRY_OUT || status == utils.COMPANY_STATUS_FORMAL || status == "全部" {
  2024. // condition += ` AND b.group_id=? `
  2025. // pars = append(pars, sysUser.GroupId)
  2026. //
  2027. // permissionCondition += ` AND b.group_id=? `
  2028. // permissionPars = append(permissionPars, sysUser.GroupId)
  2029. // } else {
  2030. // permissionCondition += ` AND b.group_id=? `
  2031. // permissionPars = append(permissionPars, sysUser.GroupId)
  2032. // }
  2033. // }
  2034. // }
  2035. // }
  2036. // }
  2037. //
  2038. // //if status == utils.COMPANY_STATUS_FREEZE {
  2039. // // condition += ` AND b.seller_id=? `
  2040. // // pars = append(pars, sysUser.AdminId)
  2041. // //
  2042. // // //permissionCondition += ` AND b.seller_id=? `
  2043. // // //permissionPars = append(permissionPars, sysUser.AdminId)
  2044. // //}
  2045. // //if status == "全部" || status == utils.COMPANY_STATUS_FREEZE {
  2046. // // freezeCondition += ` AND b.seller_id=? `
  2047. // // freezePars = append(freezePars, sysUser.AdminId)
  2048. // //}
  2049. // if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  2050. // //freezeCondition += ` AND b.seller_id=? `
  2051. // //freezePars = append(freezePars, sysUser.AdminId)
  2052. // } else if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN {
  2053. // permissionCondition += ` AND b.product_id=? `
  2054. // permissionPars = append(permissionPars, 1)
  2055. // } else if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  2056. // permissionCondition += ` AND b.product_id=? `
  2057. // permissionPars = append(permissionPars, 2)
  2058. // } else {
  2059. // if status == utils.COMPANY_STATUS_FREEZE {
  2060. // condition += ` AND b.seller_id=? `
  2061. // pars = append(pars, sysUser.AdminId)
  2062. // }
  2063. //
  2064. // freezeCondition += ` AND b.seller_id=? `
  2065. // freezePars = append(freezePars, sysUser.AdminId)
  2066. // }
  2067. // }
  2068. //
  2069. // total, err := company.GetCompanyListCount(condition, pars)
  2070. // if err != nil {
  2071. // br.Msg = "获取失败"
  2072. // br.ErrMsg = "获取数据总数失败,Err:" + err.Error()
  2073. // return
  2074. // }
  2075. //
  2076. // sortStr := ``
  2077. // if sortParam != "" && sortType != "" {
  2078. // if sortParam == "endDate" {
  2079. // sortStr = " ORDER BY b.end_date "
  2080. // } else if sortParam == "createTime" {
  2081. // sortStr = " ORDER BY a.created_time "
  2082. // } else {
  2083. // br.Msg = "获取失败"
  2084. // br.ErrMsg = "排序字段传入数据异常:" + sortParam
  2085. // return
  2086. // }
  2087. //
  2088. // if sortType == "asc" {
  2089. // sortStr += " ASC "
  2090. // } else if sortType == "desc" {
  2091. // sortStr += " DESC "
  2092. // } else {
  2093. // br.Msg = "获取失败"
  2094. // br.ErrMsg = "排序类型传入数据异常:" + sortType
  2095. // return
  2096. // }
  2097. // }
  2098. //
  2099. // list, err := company.GetCompanyList(condition, status, sortStr, pars, startSize, pageSize)
  2100. // if err != nil {
  2101. // br.Msg = "获取失败"
  2102. // br.ErrMsg = "获取数据失败,Err:" + err.Error()
  2103. // return
  2104. // }
  2105. //
  2106. //
  2107. // //企业用户数组切片
  2108. // companyIdSlice := make([]string, 0)
  2109. // for _, v := range list {
  2110. // companyIdSlice = append(companyIdSlice, strconv.Itoa(v.CompanyId))
  2111. // }
  2112. //
  2113. // //企业用户产品开通数
  2114. // companyIdStr := strings.Join(companyIdSlice, ",")
  2115. // companyProductTotalList, _ := company.GetCountProductByCompanyIds(companyIdStr)
  2116. // companyProductTotalMap := make(map[int]*company.CompanyProductTotalSlice)
  2117. // for _, companyProductTotal := range companyProductTotalList {
  2118. // companyProductTotalMap[companyProductTotal.CompanyId] = companyProductTotal
  2119. // }
  2120. // lenList := len(list)
  2121. // for i := 0; i < lenList; i++ {
  2122. // item := list[i]
  2123. //
  2124. // //校验该客户是否存在多个产品,如果是,那么代表是共享客户
  2125. // if companyProductTotal, ok := companyProductTotalMap[int(item.CompanyId)]; ok {
  2126. // if companyProductTotal.Total > 1 {
  2127. // list[i].IsShared = true
  2128. // }
  2129. // }
  2130. //
  2131. // var expireDay string
  2132. // itemStatus := item.Status
  2133. // if itemStatus != "" {
  2134. // if !strings.Contains(item.Status, "/") {
  2135. // if itemStatus == utils.COMPANY_STATUS_FOREVER { //永续
  2136. // expireDay = "-"
  2137. // } else if itemStatus == utils.COMPANY_STATUS_TRY_OUT || itemStatus == utils.COMPANY_STATUS_FORMAL { //试用/正式
  2138. // if item.StartDate != "" && item.EndDate != "" {
  2139. // endDateTime, _ := time.Parse(utils.FormatDate, item.EndDate)
  2140. // endDateTime = endDateTime.AddDate(0, 0, 1)
  2141. // sub := endDateTime.Sub(time.Now())
  2142. // if sub < 0 {
  2143. // sub = 0
  2144. // }
  2145. // expireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
  2146. // } else {
  2147. // expireDay = "-"
  2148. // }
  2149. // } else if itemStatus == utils.COMPANY_STATUS_LOSE {
  2150. // expireDay = "-"
  2151. // } else if itemStatus == utils.COMPANY_STATUS_FREEZE {
  2152. // if item.StartDate != "" && item.EndDate != "" {
  2153. // endDateTime, _ := time.Parse(utils.FormatDate, item.EndDate)
  2154. // endDateTime = endDateTime.AddDate(0, 0, 0)
  2155. // sub := endDateTime.Sub(time.Now())
  2156. // if sub < 0 {
  2157. // sub = 0
  2158. // }
  2159. // expireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
  2160. // } else {
  2161. // expireDay = "-"
  2162. // }
  2163. // } else {
  2164. // expireDay = "-"
  2165. // }
  2166. // } else {
  2167. // statusArr := strings.Split(item.Status, "/")
  2168. // ficcStatus := statusArr[0]
  2169. // raiStatus := statusArr[1]
  2170. // var ficcEndDate, tryEndDate string
  2171. // var ficcExpireDay, tryExpireDay string
  2172. // if item.EndDate != "" {
  2173. // endDateArr := strings.Split(item.EndDate, "/")
  2174. // if len(endDateArr) == 1 {
  2175. // ficcEndDate = endDateArr[0]
  2176. // } else if len(endDateArr) > 1 {
  2177. // ficcEndDate = endDateArr[0]
  2178. // tryEndDate = endDateArr[1]
  2179. // }
  2180. // if ficcStatus == utils.COMPANY_STATUS_FOREVER { //永续
  2181. // ficcExpireDay = "-"
  2182. // } else if ficcStatus == utils.COMPANY_STATUS_TRY_OUT || ficcStatus == utils.COMPANY_STATUS_FORMAL { //试用/正式
  2183. // if ficcEndDate != "" {
  2184. // endDateTime, _ := time.Parse(utils.FormatDate, ficcEndDate)
  2185. // endDateTime = endDateTime.AddDate(0, 0, 1)
  2186. // sub := endDateTime.Sub(time.Now())
  2187. // if sub < 0 {
  2188. // sub = 0
  2189. // }
  2190. // ficcExpireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
  2191. // } else {
  2192. // ficcExpireDay = "-"
  2193. // }
  2194. // } else if ficcStatus == utils.COMPANY_STATUS_LOSE { //流失
  2195. // ficcExpireDay = "-"
  2196. // } else if ficcStatus == utils.COMPANY_STATUS_FREEZE { //冻结
  2197. // if item.StartDate != "" && item.EndDate != "" {
  2198. // endDateTime, _ := time.Parse(utils.FormatDate, ficcEndDate)
  2199. // endDateTime = endDateTime.AddDate(0, 0, 0)
  2200. // sub := endDateTime.Sub(time.Now())
  2201. // if sub < 0 {
  2202. // sub = 0
  2203. // }
  2204. // ficcExpireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
  2205. // } else {
  2206. // ficcExpireDay = "-"
  2207. // }
  2208. // } else {
  2209. // ficcExpireDay = "-"
  2210. // }
  2211. //
  2212. // if raiStatus == utils.COMPANY_STATUS_FOREVER { //永续
  2213. // tryExpireDay = "-"
  2214. // } else if raiStatus == utils.COMPANY_STATUS_TRY_OUT || raiStatus == utils.COMPANY_STATUS_FORMAL { //试用/正式
  2215. // if tryEndDate != "" {
  2216. // endDateTime, _ := time.Parse(utils.FormatDate, tryEndDate)
  2217. // endDateTime = endDateTime.AddDate(0, 0, 1)
  2218. // sub := endDateTime.Sub(time.Now())
  2219. // if sub < 0 {
  2220. // sub = 0
  2221. // }
  2222. // tryExpireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
  2223. // } else {
  2224. // tryExpireDay = "-"
  2225. // }
  2226. // } else if raiStatus == utils.COMPANY_STATUS_LOSE { //流失
  2227. // tryExpireDay = "-"
  2228. // } else if raiStatus == utils.COMPANY_STATUS_FREEZE { //冻结
  2229. // if item.StartDate != "" && item.EndDate != "" {
  2230. // endDateTime, _ := time.Parse(utils.FormatDate, tryEndDate)
  2231. // endDateTime = endDateTime.AddDate(0, 0, 0)
  2232. // sub := endDateTime.Sub(time.Now())
  2233. // if sub < 0 {
  2234. // sub = 0
  2235. // }
  2236. // tryExpireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
  2237. // } else {
  2238. // tryExpireDay = "-"
  2239. // }
  2240. // } else {
  2241. // tryExpireDay = "-"
  2242. // }
  2243. // }
  2244. // expireDay = ficcExpireDay + "/" + tryExpireDay
  2245. // }
  2246. // }
  2247. // list[i].ExpireDay = expireDay
  2248. //
  2249. // //按钮显示控制
  2250. // btnItem := new(company.ButtonPermission)
  2251. // if item.CompanyId != 1 {
  2252. // *btnItem = services.GetCompanyPermissionButton(roleTypeCode, itemStatus, item.GroupIds, item.GroupIds, item.GroupId, sysUser.GroupId, item.SellerId, sysUser.AdminId, sysUser.Authority, item.ProductId)
  2253. // }
  2254. // list[i].BtnItem = btnItem
  2255. // if item.FreezeStartDate != "" && item.FreezeEndDate != "" && item.Status == utils.COMPANY_STATUS_FREEZE {
  2256. // freezeEndDate, _ := time.Parse(utils.FormatDate, item.FreezeEndDate)
  2257. // if time.Now().Before(freezeEndDate) {
  2258. // expireDays := freezeEndDate.Sub(time.Now()).Hours() / 24
  2259. // list[i].FreezeExpireDays = int(expireDays) + 1
  2260. // }
  2261. // }
  2262. // }
  2263. //
  2264. // statusCount, err := company.GetCompanyStatusCount(permissionCondition, permissionPars)
  2265. // if err != nil {
  2266. // br.Msg = "获取失败"
  2267. // br.ErrMsg = "获取状态数量失败,Err:" + err.Error()
  2268. // return
  2269. // }
  2270. //
  2271. // statusMap := make(map[string]int, 0)
  2272. // var totalCount int
  2273. // for _, sv := range statusCount {
  2274. // totalCount = totalCount + sv.Count
  2275. // statusMap[sv.Status] = sv.Count
  2276. // }
  2277. //
  2278. // lossItem, err := company.GetCompanyStatusLoseCount(lossCondition, lossPars)
  2279. // if err != nil {
  2280. // br.Msg = "获取失败"
  2281. // br.ErrMsg = "获取流失状态数量失败,Err:" + err.Error()
  2282. // return
  2283. // }
  2284. // totalCount = totalCount + lossItem.Count
  2285. //
  2286. // freezeItem, err := company.GetCompanyStatusFreezeCount(freezeCondition, freezePars)
  2287. // if err != nil {
  2288. // br.Msg = "获取失败"
  2289. // br.ErrMsg = "获取冻结状态数量失败,Err:" + err.Error()
  2290. // return
  2291. // }
  2292. // statusMap["冻结"] = freezeItem.Count
  2293. // totalCount = totalCount + freezeItem.Count
  2294. //
  2295. // forverItem, err := company.GetCompanyStatusForverCount(forverCondition, forverPars)
  2296. // if err != nil {
  2297. // br.Msg = "获取失败"
  2298. // br.ErrMsg = "获取永续状态数量失败,Err:" + err.Error()
  2299. // return
  2300. // }
  2301. // totalCount = totalCount + forverItem.Count
  2302. //
  2303. // for _, v := range statusArr {
  2304. // statusCount := new(company.CompanyStatus)
  2305. // if v == "全部" {
  2306. // statusCount.Status = "全部"
  2307. // statusCount.Count = totalCount
  2308. // } else if v == utils.COMPANY_STATUS_LOSE {
  2309. // statusCount.Status = v
  2310. // statusCount.Count = lossItem.Count
  2311. // } else if v == utils.COMPANY_STATUS_FOREVER {
  2312. // statusCount.Status = v
  2313. // statusCount.Count = forverItem.Count
  2314. // //} else if v == utils.COMPANY_STATUS_FREEZE {
  2315. // // statusCount.Status = v
  2316. // // statusCount.Count = freezeItem.Count
  2317. // //}
  2318. // } else {
  2319. // statusCount.Status = v
  2320. // if val, ok := statusMap[v]; ok {
  2321. // statusCount.Count = val
  2322. // }
  2323. // }
  2324. // statusItems = append(statusItems, statusCount)
  2325. // }
  2326. //
  2327. // companyLists := make([]*company.CompanyListItem, 0)
  2328. // //查询阅读次数
  2329. // if list == nil {
  2330. // companyLists = make([]*company.CompanyListItem, 0)
  2331. // } else {
  2332. // for _, v := range list {
  2333. // viewTotal := GetviewTotal(v.CompanyId)
  2334. // companyList := &company.CompanyListItem{
  2335. // CompanyId: v.CompanyId,
  2336. // CompanyName: v.CompanyName,
  2337. // CreditCode: v.CreditCode,
  2338. // CompanyCode: v.CompanyCode,
  2339. // StartDate: v.StartDate,
  2340. // EndDate: v.EndDate,
  2341. // LoseReason: v.LoseReason,
  2342. // RenewalReason: v.RenewalReason,
  2343. // FreezeReason: v.FreezeReason,
  2344. // LossTime: v.LossTime,
  2345. // Status: v.Status,
  2346. // CompanyType: v.CompanyType,
  2347. // ApproveStatus: v.ApproveStatus,
  2348. // SellerName: v.SellerName,
  2349. // SellerId: v.SellerId,
  2350. // SellerIds: v.SellerIds,
  2351. // ExpireDay: v.ExpireDay,
  2352. // FreezeTime: v.FreezeTime,
  2353. // GroupId: v.GroupId,
  2354. // GroupIds: v.GroupIds,
  2355. // DepartmentId: v.DepartmentId,
  2356. // IndustryName: v.IndustryName,
  2357. // IsSuspend: v.IsSuspend,
  2358. // CreatedTime: v.CreatedTime,
  2359. // Source: v.Source,
  2360. // Province: v.Province,
  2361. // City: v.City,
  2362. // Address: v.Address,
  2363. // Reasons: v.Reasons,
  2364. // FreezeStartDate: v.FreezeStartDate,
  2365. // FreezeEndDate: v.FreezeEndDate,
  2366. // FreezeExpireDays: v.FreezeExpireDays,
  2367. // BtnItem: v.BtnItem,
  2368. // ProductId: v.ProductId,
  2369. // FormalTime: v.FormalTime,
  2370. // IsShared: v.IsShared,
  2371. // RegionType: v.RegionType,
  2372. // FiccView: viewTotal[0],
  2373. // RaiView: viewTotal[1],
  2374. // }
  2375. // companyLists = append(companyLists, companyList)
  2376. // }
  2377. // }
  2378. // if companyLists == nil {
  2379. // companyLists = make([]*company.CompanyListItem, 0)
  2380. // }
  2381. // page = paging.GetPaging(currentIndex, pageSize, total)
  2382. // resp.List = companyLists
  2383. // resp.StatusCount = statusItems
  2384. // resp.Paging = page
  2385. // br.Ret = 200
  2386. // br.Success = true
  2387. // br.Msg = "获取成功"
  2388. // br.Data = resp
  2389. //}
  2390. func GetviewTotal(companyId int) (view []int) {
  2391. list, err := company.GetCompanyUserListById(companyId)
  2392. if err != nil {
  2393. fmt.Println("GetCompanyUserList err:", err.Error())
  2394. return
  2395. }
  2396. //获取企业客户信息
  2397. companyInfo, err := company.GetCompanyById(companyId)
  2398. if err != nil {
  2399. fmt.Println("GetCompanyById err:", err.Error())
  2400. return
  2401. }
  2402. var ficcViewTotal, cygxViewTotal int
  2403. lenList := len(list)
  2404. if lenList > 0 {
  2405. userIdSlice := make([]string, 0)
  2406. mobilesSlice := make([]string, 0)
  2407. emailsSlice := make([]string, 0)
  2408. for _, v := range list {
  2409. userIdSlice = append(userIdSlice, strconv.Itoa(int(v.UserId)))
  2410. if v.Mobile != "" {
  2411. mobilesSlice = append(mobilesSlice, v.Mobile)
  2412. } else if v.Email != "" {
  2413. emailsSlice = append(emailsSlice, v.Email)
  2414. }
  2415. }
  2416. //用户浏览数据
  2417. mobileStr := strings.Join(mobilesSlice, "','")
  2418. mobileStr = "'" + mobileStr + "'"
  2419. emailStr := strings.Join(emailsSlice, "','")
  2420. emailStr = "'" + emailStr + "'"
  2421. //报告统计删除晨报部分统计加入每日资讯 2021-4-9
  2422. //手机号
  2423. userViewMobileTotalMap := make(map[string]*models.UserViewMobileTotalSlice)
  2424. userReportViewMobileTotalMap := make(map[string]*models.ReportViewMobileRecord)
  2425. userAdvisoryViewMobileTotalMap := make(map[string]*advisory.UserViewMobileTotalSlice)
  2426. userCygxArticleHistoryRecordViewMobileTotalMap := make(map[string]*models.UserViewMobileTotalSlice)
  2427. if len(mobilesSlice) > 0 {
  2428. //权益数据
  2429. rightsItems, err := company.GetRightsReportListByMobile(mobileStr)
  2430. if err != nil {
  2431. fmt.Println("GetRightsReportListByMobile err:", err.Error())
  2432. return
  2433. }
  2434. cygxViewTotal = len(rightsItems)
  2435. //FICC数据
  2436. ficcItems, err := company.GetFiccReportListByMobile(mobileStr)
  2437. if err != nil {
  2438. fmt.Println("GetFiccReportListByMobile err:", err.Error())
  2439. return
  2440. }
  2441. ficcViewTotal = len(ficcItems)
  2442. }
  2443. //邮箱
  2444. userViewEmailTotalMap := make(map[string]*models.UserViewEmailTotalSlice)
  2445. userReportViewEmailTotalMap := make(map[string]*models.ReportViewEmailRecord)
  2446. userAdvisoryViewEmailTotalMap := make(map[string]*advisory.UserViewEmailTotalSlice)
  2447. userCygxViewEmailTotalMap := make(map[string]*models.UserViewEmailTotalSlice)
  2448. if len(emailsSlice) > 0 {
  2449. //FICC数据
  2450. ficcItems, err := company.GetFiccReportListByEmail(emailStr)
  2451. if err != nil {
  2452. fmt.Println("GetFiccReportListByEmail err:", err.Error())
  2453. return
  2454. }
  2455. ficcViewTotal += len(ficcItems)
  2456. //权益数据
  2457. rightsItems, err := company.GetRightsReportListByEmail(emailStr)
  2458. if err != nil {
  2459. fmt.Println("GetViewReportListByMobile err:", err.Error())
  2460. return
  2461. }
  2462. cygxViewTotal += len(rightsItems)
  2463. }
  2464. for i := 0; i < lenList; i++ {
  2465. item := list[i]
  2466. //企业名称
  2467. list[i].CompanyName = companyInfo.CompanyName
  2468. //手机号用户累计浏览次数
  2469. if userView, ok := userViewMobileTotalMap[item.Mobile]; ok {
  2470. list[i].ViewTotal += userView.Total
  2471. }
  2472. //邮箱用户累计浏览次数
  2473. if userView, ok := userViewEmailTotalMap[item.Email]; ok {
  2474. //总共浏览的报表数据需要调整为(手机号用户浏览晨报数+邮箱号用户浏览晨报数)
  2475. list[i].ViewTotal += userView.Total
  2476. }
  2477. if item.OpenId != "" {
  2478. list[i].IsRegister = true
  2479. } else {
  2480. if item.RegisterPlatform == 2 {
  2481. if item.Mobile != "" || item.Email != "" {
  2482. list[i].IsRegister = true
  2483. }
  2484. } else if item.RegisterTime != "" {
  2485. list[i].IsRegister = true
  2486. } else {
  2487. list[i].IsRegister = false
  2488. }
  2489. }
  2490. //如果存在手机号用户日评数据,那么需要做处理
  2491. if reportView, ok := userReportViewMobileTotalMap[item.Mobile]; ok {
  2492. //对日评数据做校验,日评时间晚于晨报时间,那么将最近一次浏览时间替换
  2493. if reportView.LastViewTime.After(list[i].LastViewTime) {
  2494. list[i].LastViewTime = reportView.LastViewTime
  2495. list[i].LastViewTimeStr = reportView.LastViewTime.Format(utils.FormatDateTime)
  2496. }
  2497. //总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数)
  2498. list[i].ViewTotal += reportView.ViewTotal
  2499. }
  2500. //如果存在手机号用户日评数据,那么需要做处理
  2501. if reportView, ok := userReportViewEmailTotalMap[item.Email]; ok {
  2502. //对日评数据做校验,日评时间晚于晨报时间,那么将最近一次浏览时间替换
  2503. if reportView.LastViewTime.After(list[i].LastViewTime) {
  2504. list[i].LastViewTime = reportView.LastViewTime
  2505. list[i].LastViewTimeStr = reportView.LastViewTime.Format(utils.FormatDateTime)
  2506. }
  2507. //总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数)
  2508. list[i].ViewTotal += reportView.ViewTotal
  2509. }
  2510. //如果存在手机号用户每日资讯,那么需要做处理
  2511. if advisoryView, ok := userAdvisoryViewMobileTotalMap[item.Mobile]; ok {
  2512. //fmt.Println("蝴蝶眨几次眼睛")
  2513. //对每日资讯数据做校验,每日资讯时间晚日评报时间,那么将最近一次浏览时间替换
  2514. if advisoryView.CreatedTime.After(list[i].LastViewTime) {
  2515. list[i].LastViewTime = advisoryView.CreatedTime
  2516. list[i].LastViewTimeStr = advisoryView.CreatedTime.Format(utils.FormatDateTime)
  2517. }
  2518. //总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数+每日资讯数)
  2519. list[i].ViewTotal += advisoryView.Total
  2520. }
  2521. //如果存在邮箱号用户每日资讯,那么需要做处理
  2522. if advisoryView, ok := userAdvisoryViewEmailTotalMap[item.Email]; ok {
  2523. //对每日资讯数据做校验,每日资讯时间晚日评报时间,那么将最近一次浏览时间替换
  2524. if advisoryView.CreatedTime.After(list[i].LastViewTime) {
  2525. list[i].LastViewTime = advisoryView.CreatedTime
  2526. list[i].LastViewTimeStr = advisoryView.CreatedTime.Format(utils.FormatDateTime)
  2527. }
  2528. //总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数+每日资讯数)
  2529. list[i].ViewTotal += advisoryView.Total
  2530. }
  2531. ficcViewTotal += list[i].ViewTotal
  2532. //如果存在手机号用户查研观向,那么需要做处理
  2533. if cygxView, ok := userCygxArticleHistoryRecordViewMobileTotalMap[item.Mobile]; ok {
  2534. //对每日资讯数据做校验,每日资讯时间晚日评报时间,那么将最近一次浏览时间替换
  2535. if cygxView.CreatedTime.After(list[i].LastViewTime) {
  2536. list[i].LastViewTime = cygxView.CreatedTime
  2537. list[i].LastViewTimeStr = cygxView.CreatedTime.Format(utils.FormatDateTime)
  2538. }
  2539. //总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数+每日资讯数+查研观向)
  2540. cygxViewTotal += cygxView.Total
  2541. list[i].ViewTotal += cygxView.Total
  2542. }
  2543. //如果存在邮箱号用户查研观向,那么需要做处理
  2544. if cygxView, ok := userCygxViewEmailTotalMap[item.Email]; ok {
  2545. //对每日资讯数据做校验,每日资讯时间晚日评报时间,那么将最近一次浏览时间替换
  2546. if cygxView.CreatedTime.After(list[i].LastViewTime) {
  2547. list[i].LastViewTime = cygxView.CreatedTime
  2548. list[i].LastViewTimeStr = cygxView.CreatedTime.Format(utils.FormatDateTime)
  2549. }
  2550. //总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数+每日资讯数+查研观向)
  2551. cygxViewTotal += cygxView.Total
  2552. //list[i].ViewTotal += cygxView.Total
  2553. }
  2554. /*if reportView, ok := userReportViewTotalMap[int(item.UserId)]; ok {
  2555. //对日评数据做校验,日评时间晚于晨报时间,那么将最近一次浏览时间替换
  2556. if reportView.LastViewTime.After(list[i].LastViewTime) {
  2557. list[i].LastViewTime = reportView.LastViewTime
  2558. list[i].LastViewTimeStr = reportView.LastViewTime.Format(utils.FormatDateTime)
  2559. }
  2560. //总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数)
  2561. list[i].ViewTotal += reportView.ViewTotal
  2562. }*/
  2563. }
  2564. }
  2565. view = append(view, ficcViewTotal)
  2566. view = append(view, cygxViewTotal)
  2567. return
  2568. }
  2569. // @Title 新增客户
  2570. // @Description 新增客户接口
  2571. // @Param request body company.CompanyAddReq true "type json string"
  2572. // @Success 200 {object} company.CompanyAddResp
  2573. // @router /add [post]
  2574. func (this *CompanyController) Add() {
  2575. br := new(models.BaseResponse).Init()
  2576. defer func() {
  2577. this.Data["json"] = br
  2578. this.ServeJSON()
  2579. }()
  2580. sysUser := this.SysUser
  2581. if sysUser == nil {
  2582. br.Msg = "请登录"
  2583. br.ErrMsg = "请登录,SysUser Is Empty"
  2584. br.Ret = 408
  2585. return
  2586. }
  2587. roleTypeCode := sysUser.RoleTypeCode
  2588. var req company.CompanyAddReq
  2589. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  2590. if err != nil {
  2591. br.Msg = "参数解析异常!"
  2592. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2593. return
  2594. }
  2595. if req.CompanyName == "" {
  2596. br.Msg = "请填写客户名称"
  2597. return
  2598. }
  2599. if req.CreditCode == "" {
  2600. br.Msg = "请填写社会统一信用码"
  2601. return
  2602. }
  2603. if req.Status == "" {
  2604. br.Msg = "客户状态不可为空"
  2605. return
  2606. }
  2607. //移除空格
  2608. req.CreditCode = utils.TrimStr(req.CreditCode)
  2609. var startDateTime, endDateTime time.Time
  2610. if req.Status == utils.COMPANY_STATUS_TRY_OUT {
  2611. startDateTime = time.Now()
  2612. endDateTime = time.Now().AddDate(0, 2, 0)
  2613. } else if req.Status == utils.COMPANY_STATUS_FOREVER {
  2614. startDateTime = time.Now()
  2615. endDateTime = time.Now().AddDate(100, 0, 0)
  2616. } else {
  2617. br.Msg = "无效的客户状态,请重新选择"
  2618. return
  2619. }
  2620. var startDate, endDate string
  2621. startDate = startDateTime.Format(utils.FormatDate)
  2622. endDate = endDateTime.Format(utils.FormatDate)
  2623. if req.CompanyType == "" {
  2624. br.Msg = "请选择客户类型"
  2625. return
  2626. }
  2627. var productId int
  2628. var productName string
  2629. if req.CompanyType == utils.COMPANY_PRODUCT_FICC_NAME {
  2630. productId = utils.COMPANY_PRODUCT_FICC_ID
  2631. productName = utils.COMPANY_PRODUCT_FICC_NAME
  2632. } else if req.CompanyType == utils.COMPANY_PRODUCT_RAI_NAME {
  2633. productId = utils.COMPANY_PRODUCT_RAI_ID
  2634. productName = utils.COMPANY_PRODUCT_RAI_NAME
  2635. } else {
  2636. br.Msg = "无效的客户类型,请重新选择"
  2637. return
  2638. }
  2639. if req.IndustryId <= 0 {
  2640. br.Msg = "请选择行业"
  2641. return
  2642. }
  2643. if req.SellsId <= 0 {
  2644. br.Msg = "请选择所属销售"
  2645. return
  2646. }
  2647. //if req.Reasons == "" {
  2648. // br.Msg = "请填写新增理由"
  2649. // return
  2650. //}
  2651. if req.PermissionIds == "" {
  2652. br.Msg = "请选择权限"
  2653. return
  2654. } else {
  2655. permissionStr, err := company.GetPermissionIdById(req.PermissionIds)
  2656. if err != nil {
  2657. br.Msg = "获取信息失败"
  2658. br.ErrMsg = "获取主观客观权限信息失败,Err:" + err.Error()
  2659. return
  2660. }
  2661. req.PermissionIds = permissionStr
  2662. }
  2663. industry, err := company.GetCompanyIndustryById(req.IndustryId)
  2664. if err != nil {
  2665. br.Msg = "获取行业信息失败"
  2666. br.ErrMsg = "获取行业信息失败,Err:" + err.Error()
  2667. return
  2668. }
  2669. if industry == nil {
  2670. br.Msg = "行业信息不存在"
  2671. return
  2672. }
  2673. //判断客户是否已经存在
  2674. companyNameIsExist, err := company.GetCompanyCountByCompanyName(req.CompanyName)
  2675. if err != nil {
  2676. br.Msg = "判断客户是否存在失败"
  2677. br.ErrMsg = "判断客户是否存在失败,Err:" + err.Error()
  2678. return
  2679. }
  2680. if companyNameIsExist > 0 {
  2681. br.Msg = "客户已存在,请重新输入客户名称"
  2682. return
  2683. }
  2684. //判断客户是否已经存在
  2685. companyCreditCodeIsExist, err := company.GetCompanyCountByCreditCode(req.CreditCode)
  2686. if err != nil {
  2687. br.Msg = "判断客户是否存在失败"
  2688. br.ErrMsg = "判断客户是否存在失败,Err:" + err.Error()
  2689. return
  2690. }
  2691. if companyCreditCodeIsExist > 0 {
  2692. br.Msg = "客户已存在,统一社会信用代码"
  2693. return
  2694. }
  2695. seller, err := system.GetSysAdminById(req.SellsId)
  2696. if err != nil {
  2697. br.Msg = "获取销售信息失败"
  2698. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  2699. return
  2700. }
  2701. tryOutCount, err := company.GetCompanyTryOutCount(utils.COMPANY_STATUS_TRY_OUT, seller.AdminId)
  2702. if err != nil {
  2703. br.Msg = "判断试用客户量失败"
  2704. br.ErrMsg = "判断试用客户量失败,Err:" + err.Error()
  2705. return
  2706. }
  2707. /*
  2708. ROLE_TYPE_CODE_ADMIN = "admin" //管理员
  2709. ROLE_TYPE_CODE_FICC_ADMIN = "ficc_admin" //ficc管理员
  2710. ROLE_TYPE_CODE_FICC_SELLER = "ficc_seller" //ficc销售
  2711. ROLE_TYPE_CODE_RAI_ADMIN = "rai_admin" //权益管理员
  2712. ROLE_TYPE_CODE_RAI_SELLER = "rai_seller" //权益销售
  2713. ROLE_TYPE_CODE_FICC_GROUP = "ficc_group" //ficc组长
  2714. ROLE_TYPE_CODE_RAI_GROUP = "rai_group" //ficc组长
  2715. ROLE_TYPE_CODE_FICC_DEPARTMENT = "ficc_department" //ficc部门经理
  2716. ROLE_TYPE_CODE_RAI_DEPARTMENT = "rai_department" //权益部门经理
  2717. ROLE_TYPE_CODE_FICC_RESEARCHR = "ficc_researcher" //ficc研究员
  2718. ROLE_TYPE_CODE_RAI_RESEARCHR = "rai_researcher" //权益研究员
  2719. */
  2720. if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_FICC_DEPARTMENT ||
  2721. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER || roleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
  2722. if tryOutCount >= utils.COMPANY_STATUS_TRY_OUT_COUNT {
  2723. br.Msg = "您的试用客户总数,已超过上限,不可继续新增"
  2724. return
  2725. }
  2726. }
  2727. //// 每个权益销售手中的试用客户最多30个
  2728. //if productId == utils.COMPANY_PRODUCT_RAI_ID && tryOutCount >= utils.COMPANY_STATUS_TRY_OUT_COUNT_RAI {
  2729. // br.Msg = "您的试用客户总数,已超过上限,不可继续新增"
  2730. // return
  2731. //}
  2732. //如果是权益客户,在选择非研选行业试用时,需要判断当前有多少非研选的试用客户(试用状态,且行业是非研选)
  2733. if productId == utils.COMPANY_PRODUCT_RAI_ID {
  2734. permissionArr := strings.Split(req.PermissionIds, ",")
  2735. //如果所选行业不属于研选订阅跟研选扣点包,那就是非研选试用客户
  2736. var isNoResearch bool
  2737. for _, v := range permissionArr {
  2738. if v != strconv.Itoa(utils.CHART_PERMISSION_ID_YANXUAN) && v != strconv.Itoa(utils.YAN_XUAN_KOU_DIAN_BAO_ID) {
  2739. isNoResearch = true
  2740. continue
  2741. }
  2742. }
  2743. if isNoResearch {
  2744. tryOutCountRai, err := company.GetRaiCompanyTryOutCountNoResearch(seller.AdminId)
  2745. if err != nil {
  2746. br.Msg = "判断试用客户量失败"
  2747. br.ErrMsg = "判断试用客户量失败,Err:" + err.Error()
  2748. return
  2749. }
  2750. if tryOutCountRai >= utils.COMPANY_STATUS_TRY_OUT_COUNT_RAI {
  2751. br.Msg = "非研选试用客户最多40家"
  2752. return
  2753. }
  2754. }
  2755. }
  2756. if seller == nil {
  2757. br.Msg = "所属销售不存在"
  2758. return
  2759. }
  2760. companyCode, err := company.GetCompanyCode()
  2761. if err != nil {
  2762. br.Msg = "获取客户编码信息失败"
  2763. br.ErrMsg = "获取客户编码信息失败,Err:" + err.Error()
  2764. return
  2765. }
  2766. item := new(company.Company)
  2767. item.CompanyName = req.CompanyName
  2768. item.CreditCode = req.CreditCode
  2769. item.CompanyCode = companyCode
  2770. item.Province = req.Province
  2771. item.City = req.City
  2772. item.Address = req.Province + req.City
  2773. item.StartDate = time.Now().Format(utils.FormatDate)
  2774. if req.Status == utils.COMPANY_STATUS_FOREVER {
  2775. item.EndDate = time.Now().AddDate(100, 0, 0).Format(utils.FormatDate)
  2776. item.CompanyType = 5
  2777. }
  2778. if req.Status == utils.COMPANY_STATUS_TRY_OUT {
  2779. item.EndDate = time.Now().AddDate(0, 2, 0).Format(utils.FormatDate)
  2780. item.CompanyType = 2
  2781. }
  2782. item.FirstStartDate = item.StartDate
  2783. item.FirstEndDate = item.EndDate
  2784. item.CreatedTime = time.Now()
  2785. item.LastUpdatedTime = time.Now()
  2786. item.Enabled = 1
  2787. item.RegionType = req.RegionType
  2788. item.Remark = req.Reasons
  2789. item.Nation = req.Nation
  2790. item.OverseasStatus = "试用"
  2791. item.ResetBtn = 1
  2792. companyId, err := company.AddCompany(item)
  2793. if err != nil {
  2794. br.Msg = "新增失败"
  2795. br.ErrMsg = "新增失败,err:" + err.Error()
  2796. return
  2797. }
  2798. item.CompanyId = int(companyId)
  2799. //生成第三方code编号
  2800. item.OpenCompanyCode = services.GenerateOpenCompanyCode(int(companyId))
  2801. item.Update([]string{"OpenCompanyCode"})
  2802. if req.UserId > 0 {
  2803. //修改联系人
  2804. err = company.ModifyCompanyUserCompanyId(req.UserId, int(companyId))
  2805. if err != nil {
  2806. br.Msg = "新增失败"
  2807. br.ErrMsg = "新增失败,ModifyCompanyUserCompanyId err:" + err.Error()
  2808. return
  2809. }
  2810. //获取联系人详情
  2811. userInfo, err := models.GetWxUserByUserId(req.UserId)
  2812. if err != nil {
  2813. br.Msg = "获取联系人异常!"
  2814. br.ErrMsg = "获取联系人异常,Err:" + err.Error()
  2815. return
  2816. }
  2817. //添加该联系人 与 当前销售的关系
  2818. models.AddUserSellerRelation(int64(req.UserId), int(companyId), seller.AdminId, productId, seller.RealName, userInfo.Mobile, userInfo.Email)
  2819. }
  2820. companyProduct := new(company.CompanyProduct)
  2821. companyProduct.CompanyId = int(companyId)
  2822. companyProduct.ProductId = productId
  2823. companyProduct.ProductName = productName
  2824. companyProduct.CompanyName = req.CompanyName
  2825. companyProduct.Source = req.Source
  2826. companyProduct.Reasons = req.Reasons
  2827. companyProduct.Status = req.Status
  2828. companyProduct.StartDate = startDate
  2829. companyProduct.EndDate = endDate
  2830. companyProduct.IndustryId = req.IndustryId
  2831. companyProduct.IndustryName = industry.IndustryName
  2832. companyProduct.SellerId = seller.AdminId
  2833. companyProduct.SellerName = seller.RealName
  2834. companyProduct.GroupId = seller.GroupId
  2835. companyProduct.DepartmentId = seller.DepartmentId
  2836. companyProduct.IsSuspend = 0
  2837. companyProduct.CreateTime = time.Now()
  2838. companyProduct.ModifyTime = time.Now()
  2839. companyProduct.CompanyType = req.CompanyType
  2840. companyProduct.Scale = req.Scale
  2841. companyProduct.OpenCode = services.GenerateOpenCompanyProductCode(int(companyId), productId)
  2842. companyProduct.TodoStatus = "无任务"
  2843. companyProduct.TryStage = 1
  2844. companyProduct.OverseasLabel = 1
  2845. if seller.Mobile == "13065778668" {
  2846. if req.RegionType == "海外" {
  2847. companyProduct.IsOverseas = 0
  2848. } else {
  2849. companyProduct.IsOverseas = 1
  2850. }
  2851. }
  2852. if productId == utils.COMPANY_PRODUCT_RAI_ID && req.Status == utils.COMPANY_STATUS_FOREVER { // 权益的永续客户给一个状态初始化的记录
  2853. companyProduct.InitStatus = req.Status
  2854. }
  2855. companyProductId, err := company.AddCompanyProduct(companyProduct)
  2856. if err != nil {
  2857. br.Msg = "新增失败"
  2858. br.ErrMsg = "新增客户产品失败,err:" + err.Error()
  2859. return
  2860. }
  2861. companyReportPermissionList, err := services.AddCompanyPermission(int(companyId), seller.AdminId, productId, productName, seller.RealName, req.PermissionIds, startDate, endDate)
  2862. if err != nil {
  2863. br.Msg = "新增失败"
  2864. br.ErrMsg = "新增客户设置权限失败,err:" + err.Error()
  2865. return
  2866. }
  2867. {
  2868. record := new(company.CompanyOperationRecord)
  2869. record.CompanyId = int(companyId)
  2870. record.CompanyName = req.CompanyName
  2871. record.SellerId = seller.AdminId
  2872. record.SysUserId = seller.AdminId
  2873. record.SysRealName = seller.RealName
  2874. record.Remark = "新增客户"
  2875. record.Operation = "add"
  2876. record.CreateTime = time.Now()
  2877. record.ProductId = productId
  2878. record.ProductName = productName
  2879. record.Status = req.Status
  2880. _, err = company.AddCompanyOperationRecord(record)
  2881. if err != nil {
  2882. go alarm_msg.SendAlarmMsg("URI:"+this.Ctx.Input.URI()+"<br/> "+";<br/> Body:"+err.Error(), 3)
  2883. //go utils.SendEmail(utils.APPNAME+"失败提醒"+utils.RunMode, "URI:"+this.Ctx.Input.URI()+"<br/> "+";<br/> Body:"+err.Error(), utils.EmailSendToUsers)
  2884. }
  2885. }
  2886. //新增客户日志
  2887. {
  2888. companyLog := new(company.CompanyLog)
  2889. companyLog.CompanyId = int(companyId)
  2890. companyLog.CompanyName = req.CompanyName
  2891. companyLog.CreditCode = req.CreditCode
  2892. companyLog.CompanyCode = companyCode
  2893. companyLog.Sort = item.Sort
  2894. companyLog.IsFeeCustomer = item.IsFeeCustomer
  2895. companyLog.Country = item.Country
  2896. companyLog.Address = item.Address
  2897. companyLog.City = item.City
  2898. companyLog.Province = item.Province
  2899. companyLog.Enabled = item.Enabled
  2900. companyLog.CreatedTime = item.CreatedTime
  2901. companyLog.LastUpdatedTime = item.LastUpdatedTime
  2902. companyLog.Seller = item.Seller
  2903. companyLog.SellsId = item.SellsId
  2904. companyLog.CompanyBelong = item.CompanyBelong
  2905. companyLog.StartDate = item.StartDate
  2906. companyLog.EndDate = item.EndDate
  2907. companyLog.FirstStartDate = item.FirstStartDate
  2908. companyLog.FirstEndDate = item.FirstEndDate
  2909. companyLog.DateType = item.DateType
  2910. companyLog.AdminId = this.SysUser.AdminId
  2911. companyLog.LogType = "add"
  2912. companyLog.LogCreateTime = time.Now()
  2913. go company.AddCompanyLog(companyLog)
  2914. }
  2915. //新增客户产品日志
  2916. {
  2917. productLog := new(company.CompanyProductLog)
  2918. productLog.CompanyProductId = int(companyProductId)
  2919. productLog.CompanyId = companyProduct.CompanyId
  2920. productLog.ProductId = companyProduct.ProductId
  2921. productLog.ProductName = companyProduct.ProductName
  2922. productLog.CompanyName = companyProduct.CompanyName
  2923. productLog.CompanyName = companyProduct.CompanyName
  2924. productLog.Source = companyProduct.Source
  2925. productLog.Reasons = companyProduct.Reasons
  2926. productLog.Status = companyProduct.Status
  2927. productLog.IndustryId = companyProduct.IndustryId
  2928. productLog.IndustryName = companyProduct.IndustryName
  2929. productLog.SellerId = companyProduct.SellerId
  2930. productLog.SellerName = companyProduct.SellerName
  2931. productLog.GroupId = companyProduct.GroupId
  2932. productLog.DepartmentId = companyProduct.DepartmentId
  2933. productLog.IsSuspend = companyProduct.IsSuspend
  2934. productLog.SuspendTime = companyProduct.SuspendTime
  2935. productLog.ApproveStatus = companyProduct.ApproveStatus
  2936. productLog.FreezeTime = companyProduct.FreezeTime
  2937. productLog.Remark = companyProduct.Remark
  2938. productLog.StartDate = companyProduct.StartDate
  2939. productLog.EndDate = companyProduct.EndDate
  2940. productLog.CreateTime = companyProduct.CreateTime
  2941. productLog.ModifyTime = companyProduct.ModifyTime
  2942. productLog.LoseReason = companyProduct.LoseReason
  2943. productLog.LossTime = companyProduct.LossTime
  2944. productLog.LogType = "add"
  2945. productLog.LogCreateTime = time.Now()
  2946. productLog.AdminId = this.SysUser.AdminId
  2947. productLog.Scale = companyProduct.Scale
  2948. go company.AddCompanyProductLog(productLog)
  2949. }
  2950. //新增客户产品状态变更日志
  2951. {
  2952. companyProductUpdateLog := &company.CompanyProductUpdateLog{
  2953. Id: 0,
  2954. CompanyId: companyProduct.CompanyId,
  2955. ProductId: companyProduct.ProductId,
  2956. Status: "试用",
  2957. Source: "add",
  2958. SellerId: companyProduct.SellerId,
  2959. SellerName: companyProduct.SellerName,
  2960. StartDate: startDateTime,
  2961. EndDate: endDateTime,
  2962. RealEndDate: startDateTime,
  2963. CreateTime: time.Now(),
  2964. }
  2965. go company.AddCompanyProductUpdateLog(companyProductUpdateLog)
  2966. companyProductTryOutUpdateLog := &company.CompanyProductTryOutUpdateLog{
  2967. Id: 0,
  2968. CompanyId: companyProduct.CompanyId,
  2969. ProductId: companyProduct.ProductId,
  2970. Source: "add",
  2971. SellerId: companyProduct.SellerId,
  2972. SellerName: companyProduct.SellerName,
  2973. StartDate: startDateTime,
  2974. EndDate: endDateTime,
  2975. RealEndDate: startDateTime,
  2976. IsStop: 0,
  2977. CreateTime: time.Now(),
  2978. }
  2979. go company.AddCompanyProductTryOutUpdateLog(companyProductTryOutUpdateLog, companyReportPermissionList)
  2980. }
  2981. resp := new(company.CompanyAddResp)
  2982. resp.CompanyId = int(companyId)
  2983. br.Ret = 200
  2984. br.Success = true
  2985. br.Msg = "新增成功"
  2986. br.Data = resp
  2987. }
  2988. // Detail
  2989. // @Title 获取客户详情
  2990. // @Description 获取客户详情接口
  2991. // @Param CompanyId query int true "客户id"
  2992. // @Success 200 {object} company.CompanyDetailResp
  2993. // @router /detail [get]
  2994. func (this *CompanyController) Detail() {
  2995. br := new(models.BaseResponse).Init()
  2996. defer func() {
  2997. this.Data["json"] = br
  2998. this.ServeJSON()
  2999. }()
  3000. sysUser := this.SysUser
  3001. if sysUser == nil {
  3002. br.Msg = "请登录"
  3003. br.ErrMsg = "请登录,SysUser Is Empty"
  3004. br.Ret = 408
  3005. return
  3006. }
  3007. companyId, _ := this.GetInt("CompanyId")
  3008. if companyId <= 0 {
  3009. br.Msg = "参数错误"
  3010. br.ErrMsg = "客户参数小于等于0"
  3011. return
  3012. }
  3013. // CRM8.8-是否为编辑页的客户详情
  3014. isEdit, _ := this.GetBool("IsEdit")
  3015. productId := services.GetProductId(sysUser.RoleTypeCode)
  3016. item, err := company.GetCompanyDetailById(companyId)
  3017. if err != nil {
  3018. br.Msg = "获取信息失败"
  3019. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  3020. return
  3021. }
  3022. shareSellerId := 0
  3023. shareGroupId := 0
  3024. var productItem *company.CompanyProduct
  3025. if productId > 0 {
  3026. var e error
  3027. productItem, e = company.GetCompanyProductByCompanyIdAndProductId(companyId, productId)
  3028. if e != nil && e.Error() != utils.ErrNoRow() {
  3029. br.Msg = "客户信息有误"
  3030. br.ErrMsg = "获取客户信息失败, Err: " + e.Error()
  3031. return
  3032. }
  3033. if productItem != nil {
  3034. shareSellerId = productItem.ShareSellerId
  3035. shareGroupId = productItem.ShareGroupId
  3036. }
  3037. }
  3038. var productName string
  3039. if productId == 1 {
  3040. productName = utils.COMPANY_PRODUCT_FICC_NAME
  3041. } else if productId == 2 {
  3042. productName = utils.COMPANY_PRODUCT_RAI_NAME
  3043. } else {
  3044. productName = "admin"
  3045. }
  3046. resp := new(company.CompanyDetailResp)
  3047. resp.ProductName = productName
  3048. //获取客户产品
  3049. productList, err := company.GetCompanyProductsByCompanyId(companyId)
  3050. if err != nil {
  3051. br.Msg = "获取信息失败"
  3052. br.ErrMsg = "获取产品信息失败,Err:" + err.Error()
  3053. return
  3054. }
  3055. roleTypeCode := sysUser.RoleTypeCode
  3056. itemLen := len(productList)
  3057. btnDetailItem := new(company.ButtonDetailPermission)
  3058. // 客户权限校验
  3059. {
  3060. // 如果不是超管、ficc管理员、权益管理员,那么需要额外校验下权限
  3061. if !utils.InArrayByStr([]string{utils.ROLE_TYPE_CODE_ADMIN, utils.ROLE_TYPE_CODE_FICC_ADMIN, utils.ROLE_TYPE_CODE_RAI_ADMIN}, sysUser.RoleTypeCode) {
  3062. var isOk bool //是否有权限
  3063. var companyHasProduct bool // 客户当前是否有该产品权限
  3064. for _, productInfo := range productList {
  3065. // 只校验拥有的品种权限:ficc或者权益
  3066. if productInfo.ProductId == productId {
  3067. companyHasProduct = true
  3068. // 自己的客户有权限看
  3069. if productInfo.SellerId == sysUser.AdminId {
  3070. isOk = true
  3071. break
  3072. }
  3073. // 流失客户都有权限看
  3074. if productInfo.Status == utils.COMPANY_STATUS_LOSE || productInfo.Status == utils.COMPANY_STATUS_CLOSE {
  3075. isOk = true
  3076. break
  3077. }
  3078. // 分享的客户 也有权限
  3079. if productItem.IsShare == 1 && productItem.ShareSellerId == sysUser.AdminId {
  3080. isOk = true
  3081. break
  3082. }
  3083. // 分享的客户的组长 也有权限
  3084. if productItem.IsShare == 1 && productItem.ShareGroupId == sysUser.GroupId {
  3085. isOk = true
  3086. break
  3087. }
  3088. // 如果是组长,且该客户属于本组客户
  3089. if sysUser.Authority == 4 && productInfo.GroupId > 0 && productInfo.GroupId == sysUser.GroupId && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_TEAM {
  3090. isOk = true
  3091. break
  3092. }
  3093. // 如果是ficc主管或者权益主管
  3094. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  3095. // 获取顶级分组Id
  3096. var sysUserGroupPid, productGroupPid int
  3097. // 当前账号的顶级分组id
  3098. {
  3099. sysUserGroupIdpid, err := company.GetParentIdFromGroup(sysUser.GroupId)
  3100. if err != nil && err.Error() != utils.NotEmpty() {
  3101. break
  3102. }
  3103. if sysUserGroupIdpid == nil || *sysUserGroupIdpid == 0 {
  3104. sysUserGroupPid = sysUser.GroupId
  3105. } else {
  3106. sysUserGroupPid = *sysUserGroupIdpid
  3107. }
  3108. }
  3109. // 当前客户的顶级分组id
  3110. {
  3111. groupIdpid, err := company.GetParentIdFromGroup(productInfo.GroupId)
  3112. if err != nil && err.Error() != utils.NotEmpty() {
  3113. break
  3114. }
  3115. if groupIdpid == nil || *groupIdpid == 0 {
  3116. productGroupPid = productInfo.GroupId
  3117. } else {
  3118. productGroupPid = *groupIdpid
  3119. }
  3120. }
  3121. // 如果客户的顶级分组和当前账号分组id一致
  3122. if sysUserGroupPid == productGroupPid {
  3123. isOk = true
  3124. break
  3125. }
  3126. }
  3127. }
  3128. }
  3129. // 客户当前是否有该产品的权限,如果没有的话,说明是在领取客户,允许访问
  3130. if !companyHasProduct {
  3131. isOk = true
  3132. }
  3133. if !isOk {
  3134. br.Msg = "无访问权限"
  3135. return
  3136. }
  3137. }
  3138. }
  3139. //产品权限map
  3140. statusMap := make(map[int]string)
  3141. for i := 0; i < itemLen; i++ {
  3142. item := productList[i]
  3143. //添加产品权限map
  3144. statusMap[item.ProductId] = item.Status
  3145. if i == 0 {
  3146. if item.ProductId == 1 {
  3147. resp.CreateAuth = 1
  3148. } else {
  3149. resp.CreateAuth = 2
  3150. }
  3151. }
  3152. if item.ProductId == 1 {
  3153. if strings.Contains(sysUser.RoleTypeCode, "ficc") {
  3154. if item.Status == utils.COMPANY_STATUS_FREEZE || item.Status == utils.COMPANY_STATUS_LOSE {
  3155. btnDetailItem.BtnHistoryList = true
  3156. } else {
  3157. if item.SellerId == sysUser.AdminId || shareSellerId == sysUser.AdminId || shareGroupId == sysUser.GroupId {
  3158. btnDetailItem.BtnHistoryList = true
  3159. }
  3160. if sysUser.Authority > 0 {
  3161. if item.GroupId == sysUser.GroupId {
  3162. btnDetailItem.BtnHistoryList = true
  3163. }
  3164. if item.DepartmentId == sysUser.DepartmentId {
  3165. btnDetailItem.BtnHistoryList = true
  3166. }
  3167. }
  3168. }
  3169. }
  3170. // 编辑回显
  3171. allPermissions, e := company.GetPermissionLookItemsByProductId(utils.COMPANY_PRODUCT_FICC_ID)
  3172. if e != nil {
  3173. br.Msg = "获取失败"
  3174. br.ErrMsg = "获取权限信息失败,Err:" + e.Error()
  3175. return
  3176. }
  3177. permissionMap := make(map[int][]*company.PermissionLookItem, 0)
  3178. permissionCheckMap := make(map[int][]int, 0)
  3179. for _, v := range allPermissions {
  3180. if v.ParentId > 0 {
  3181. permissionMap[v.ParentId] = append(permissionMap[v.ParentId], v)
  3182. if v.IsPublic == 1 {
  3183. permissionCheckMap[v.ParentId] = append(permissionCheckMap[v.ParentId], v.ChartPermissionId)
  3184. }
  3185. }
  3186. }
  3187. for _, v := range allPermissions {
  3188. if v.ParentId == 0 {
  3189. checkList := make([]int, 0)
  3190. plist := new(company.PermissionLookList)
  3191. plist.Items = make([]*company.PermissionLookItem, 0)
  3192. plist.ItemsType = make([]*company.PermissionSetItemType, 0)
  3193. items, ok := permissionMap[v.ChartPermissionId]
  3194. if ok {
  3195. for itemK, n := range items {
  3196. permission, err := company.GetCompanyPermissionCheckItem(companyId, n.ChartPermissionId)
  3197. if err != nil && err.Error() != utils.ErrNoRow() {
  3198. br.Msg = "获取失败"
  3199. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  3200. return
  3201. }
  3202. if permission != nil && permission.ChartPermissionId > 0 {
  3203. checkList = append(checkList, n.ChartPermissionId)
  3204. items[itemK].StartDate = permission.StartDate
  3205. items[itemK].EndDate = permission.EndDate
  3206. items[itemK].Status = permission.Status
  3207. endDateTime, _ := time.Parse(utils.FormatDate, permission.EndDate)
  3208. endDateTime = endDateTime.AddDate(0, 0, 1)
  3209. sub := endDateTime.Sub(time.Now())
  3210. if sub < 0 {
  3211. sub = 0
  3212. }
  3213. expireDay := fmt.Sprintf("%v", int(sub.Hours()/24))
  3214. items[itemK].ExpireDay = expireDay
  3215. }
  3216. }
  3217. plist.Items = items
  3218. }
  3219. plist.ClassifyName = v.PermissionName
  3220. plist.CheckList = checkList
  3221. item.PermissionList = append(item.PermissionList, plist)
  3222. }
  3223. }
  3224. resp.FiccItem = item
  3225. if resp.FiccItem.Status == utils.COMPANY_STATUS_FOREVER {
  3226. resp.FiccItem.Status = utils.COMPANY_STATUS_X_CLASS_TRY_OUT
  3227. }
  3228. if (roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER ||
  3229. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP || roleTypeCode == utils.ROLE_TYPE_CODE_FICC_DEPARTMENT) &&
  3230. item.Status == utils.COMPANY_STATUS_TRY_OUT && item.ApproveStatus != "待审批" {
  3231. resp.IsButtonShow = 1
  3232. }
  3233. } else {
  3234. if strings.Contains(sysUser.RoleTypeCode, "rai") {
  3235. if item.Status == utils.COMPANY_STATUS_FREEZE || item.Status == utils.COMPANY_STATUS_LOSE {
  3236. btnDetailItem.BtnHistoryList = true
  3237. } else {
  3238. if item.SellerId == sysUser.AdminId || item.ShareSellerId == sysUser.AdminId || shareGroupId == sysUser.GroupId {
  3239. btnDetailItem.BtnHistoryList = true
  3240. }
  3241. if sysUser.Authority > 0 {
  3242. if item.GroupId == sysUser.GroupId {
  3243. btnDetailItem.BtnHistoryList = true
  3244. }
  3245. if item.DepartmentId == sysUser.DepartmentId {
  3246. btnDetailItem.BtnHistoryList = true
  3247. }
  3248. }
  3249. }
  3250. }
  3251. // CRM8.8-权益权限列表调用较多、统一进行调整
  3252. plist, e := services.RaiCompanyPermissionAndCheckList(companyId, isEdit, []string{"调研"})
  3253. if e != nil {
  3254. br.Msg = "获取客户权益权限列表信息失败"
  3255. br.ErrMsg = "获取客户权益权限列表信息失败,Err:" + e.Error()
  3256. return
  3257. }
  3258. // cygx8.2专项产业调研展示
  3259. item.SpecialSurplus, err = cygxService.GetSpecialSurplusByCompanyNew(companyId)
  3260. if err != nil {
  3261. br.Msg = "获取失败"
  3262. br.ErrMsg = "获取专项调研信息失败,Err:" + err.Error()
  3263. return
  3264. }
  3265. //研选服务点数
  3266. item.Points = cygxService.GetCygxActivityPointsCompanyByCompanyId(companyId)
  3267. item.PermissionList = append(item.PermissionList, plist)
  3268. resp.RaiItem = item
  3269. if resp.RaiItem.Status == utils.COMPANY_STATUS_FOREVER {
  3270. resp.RaiItem.Status = utils.COMPANY_STATUS_X_CLASS_TRY_OUT
  3271. }
  3272. if (roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER ||
  3273. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP ||
  3274. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_DEPARTMENT) &&
  3275. item.Status == utils.COMPANY_STATUS_TRY_OUT && item.ApproveStatus != "待审批" {
  3276. resp.IsButtonShow = 1
  3277. }
  3278. }
  3279. 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, shareSellerId, "")
  3280. //if itemLen > 1 {
  3281. // btnDetailItem.BtnEdit = false
  3282. // btnDetailItem.BtnDelete = false
  3283. //} else {
  3284. // btnDetailItem.BtnEdit = btnItem.BtnEdit
  3285. // btnDetailItem.BtnDelete = btnItem.BtnDelete
  3286. //}
  3287. switch item.ProductId {
  3288. case 1:
  3289. btnDetailItem.FiccEdit = btnItem.BtnEdit
  3290. btnDetailItem.FiccDelete = btnItem.BtnDelete
  3291. case 2:
  3292. btnDetailItem.RaiEdit = btnItem.BtnEdit
  3293. btnDetailItem.RaiDelete = btnItem.BtnDelete
  3294. }
  3295. if !btnDetailItem.BtnEdit {
  3296. btnDetailItem.BtnEdit = btnItem.BtnEdit
  3297. }
  3298. if !btnDetailItem.BtnDelete {
  3299. btnDetailItem.BtnDelete = btnItem.BtnDelete
  3300. }
  3301. //联系人操作权限
  3302. if resp.IsContractButtonShow == false {
  3303. resp.IsContractButtonShow = services.CheckCompanyUserButton(sysUser.RoleTypeCode, item.SellerId, sysUser.AdminId, item.ProductId, shareSellerId, item.Status)
  3304. }
  3305. //校验当前操作员是否具给联系人开通个人研选的权限
  3306. if resp.IsUserYanXuanButtonShow == false {
  3307. resp.IsUserYanXuanButtonShow, err = services.CheckCompanyUserYanXuanButton(sysUser.RoleTypeCode, sysUser.Mobile)
  3308. if err != nil {
  3309. br.Msg = "获取失败"
  3310. br.ErrMsg = "获取专项调研信息失败,Err:" + err.Error()
  3311. return
  3312. }
  3313. }
  3314. }
  3315. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN ||
  3316. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN ||
  3317. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  3318. resp.IsButtonShow = 1
  3319. btnDetailItem.BtnHistoryList = true
  3320. }
  3321. //ficc权限
  3322. if ficcStatus, ok := statusMap[1]; ok {
  3323. if ficcStatus == utils.COMPANY_STATUS_TRY_OUT {
  3324. if raiStatus, ok := statusMap[2]; ok {
  3325. //另一个权限也是 试用 、冻结、流失
  3326. if raiStatus == utils.COMPANY_STATUS_TRY_OUT || raiStatus == utils.COMPANY_STATUS_FREEZE || raiStatus == utils.COMPANY_STATUS_LOSE {
  3327. //那么超管、部门管理员、销售可以编辑
  3328. if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER || roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3329. btnDetailItem.BaseInfoEdit = true
  3330. }
  3331. }
  3332. //权益是永续时,超管可编辑基础信息
  3333. if raiStatus == utils.COMPANY_STATUS_FOREVER {
  3334. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3335. btnDetailItem.BaseInfoEdit = true
  3336. }
  3337. }
  3338. } else {
  3339. //权限未开,有编辑基础信息权限
  3340. btnDetailItem.BaseInfoEdit = true
  3341. }
  3342. }
  3343. if ficcStatus == utils.COMPANY_STATUS_FOREVER {
  3344. if raiStatus, ok := statusMap[2]; ok {
  3345. //另一个权限也是 永续 、冻结、流失
  3346. if raiStatus == utils.COMPANY_STATUS_TRY_OUT || raiStatus == utils.COMPANY_STATUS_FOREVER || raiStatus == utils.COMPANY_STATUS_FREEZE || raiStatus == utils.COMPANY_STATUS_LOSE {
  3347. //超管可编辑基础信息
  3348. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3349. btnDetailItem.BaseInfoEdit = true
  3350. }
  3351. }
  3352. } else {
  3353. //权限未开,有编辑基础信息权限
  3354. btnDetailItem.BaseInfoEdit = true
  3355. }
  3356. }
  3357. }
  3358. //权益销售
  3359. if raiStatus, ok := statusMap[2]; ok {
  3360. if raiStatus == utils.COMPANY_STATUS_TRY_OUT {
  3361. if ficcStatus, ok := statusMap[1]; ok {
  3362. //另一个权限也是 试用 、冻结、流失
  3363. if ficcStatus == utils.COMPANY_STATUS_TRY_OUT || ficcStatus == utils.COMPANY_STATUS_FREEZE || ficcStatus == utils.COMPANY_STATUS_LOSE {
  3364. //那么超管、部门管理员、销售可以编辑
  3365. if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER || roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3366. btnDetailItem.BaseInfoEdit = true
  3367. }
  3368. }
  3369. //ficc是永续时,超管可编辑基础信息
  3370. if ficcStatus == utils.COMPANY_STATUS_FOREVER {
  3371. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3372. btnDetailItem.BaseInfoEdit = true
  3373. }
  3374. }
  3375. } else {
  3376. //权限未开,有编辑基础信息权限
  3377. btnDetailItem.BaseInfoEdit = true
  3378. }
  3379. }
  3380. if raiStatus == utils.COMPANY_STATUS_FOREVER {
  3381. if ficcStatus, ok := statusMap[1]; ok {
  3382. //另一个权限也是 试用、永续 、冻结、流失
  3383. if ficcStatus == utils.COMPANY_STATUS_TRY_OUT || ficcStatus == utils.COMPANY_STATUS_FOREVER || ficcStatus == utils.COMPANY_STATUS_FREEZE || ficcStatus == utils.COMPANY_STATUS_LOSE {
  3384. //超管可编辑基础信息
  3385. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3386. btnDetailItem.BaseInfoEdit = true
  3387. }
  3388. }
  3389. } else {
  3390. //权限未开,有编辑基础信息权限
  3391. btnDetailItem.BaseInfoEdit = true
  3392. }
  3393. }
  3394. }
  3395. // 白嫖客户标记
  3396. scroungeList, err := company.GetScroungeCompany()
  3397. if err != nil {
  3398. br.Msg = "获取失败"
  3399. br.ErrMsg = "获取白嫖客户信息失败,Err:" + err.Error()
  3400. return
  3401. }
  3402. scroungeMap := make(map[int]int)
  3403. for _, v := range scroungeList {
  3404. scroungeMap[v.CompanyId] = 1
  3405. }
  3406. if _, ok := scroungeMap[item.CompanyId]; ok {
  3407. item.IsScrounge = 1
  3408. }
  3409. resp.Item = item
  3410. resp.BtnItem = btnDetailItem
  3411. br.Ret = 200
  3412. br.Success = true
  3413. br.Msg = "获取成功"
  3414. br.Data = resp
  3415. }
  3416. // DetailByCreditCode
  3417. // @Title 根据社会信用码获取客户详情
  3418. // @Description 根据社会信用码获取客户详情接口
  3419. // @Param CreditCode query string true "客户社会信用码"
  3420. // @Success 200 {object} company.CompanyDetailResp
  3421. // @router /detail_by_credit_code [get]
  3422. func (this *CompanyController) DetailByCreditCode() {
  3423. br := new(models.BaseResponse).Init()
  3424. defer func() {
  3425. this.Data["json"] = br
  3426. this.ServeJSON()
  3427. }()
  3428. sysUser := this.SysUser
  3429. if sysUser == nil {
  3430. br.Msg = "请登录"
  3431. br.ErrMsg = "请登录,SysUser Is Empty"
  3432. br.Ret = 408
  3433. return
  3434. }
  3435. resp := new(company.CompanyDetailResp)
  3436. creditCode := this.GetString("CreditCode")
  3437. if creditCode == "" {
  3438. br.Msg = "参数错误"
  3439. br.ErrMsg = "社会信用码必传"
  3440. return
  3441. }
  3442. item, err := company.GetCompanyDetailByCreditCode(creditCode)
  3443. if err != nil {
  3444. br.Ret = 200
  3445. br.Success = true
  3446. br.Msg = "获取成功"
  3447. br.Data = resp
  3448. return
  3449. }
  3450. companyId := item.CompanyId
  3451. var productName string
  3452. productId := services.GetProductId(sysUser.RoleTypeCode)
  3453. if productId == 1 {
  3454. productName = utils.COMPANY_PRODUCT_FICC_NAME
  3455. } else if productId == 2 {
  3456. productName = utils.COMPANY_PRODUCT_RAI_NAME
  3457. } else {
  3458. productName = "admin"
  3459. }
  3460. resp.ProductName = productName
  3461. //获取客户产品
  3462. productList, err := company.GetCompanyProductsByCompanyId(companyId)
  3463. if err != nil {
  3464. br.Msg = "获取信息失败"
  3465. br.ErrMsg = "获取产品信息失败,Err:" + err.Error()
  3466. return
  3467. }
  3468. roleTypeCode := sysUser.RoleTypeCode
  3469. itemLen := len(productList)
  3470. btnDetailItem := new(company.ButtonDetailPermission)
  3471. //产品权限map
  3472. statusMap := make(map[int]string)
  3473. for i := 0; i < itemLen; i++ {
  3474. item := productList[i]
  3475. //添加产品权限map
  3476. statusMap[item.ProductId] = item.Status
  3477. if i == 0 {
  3478. if item.ProductId == 1 {
  3479. resp.CreateAuth = 1
  3480. } else {
  3481. resp.CreateAuth = 2
  3482. }
  3483. }
  3484. if item.ProductId == 1 {
  3485. if strings.Contains(sysUser.RoleTypeCode, "ficc") {
  3486. if item.Status == utils.COMPANY_STATUS_FREEZE || item.Status == utils.COMPANY_STATUS_LOSE {
  3487. btnDetailItem.BtnHistoryList = true
  3488. } else {
  3489. if item.SellerId == sysUser.AdminId {
  3490. btnDetailItem.BtnHistoryList = true
  3491. }
  3492. if sysUser.Authority > 0 {
  3493. if item.GroupId == sysUser.GroupId {
  3494. btnDetailItem.BtnHistoryList = true
  3495. }
  3496. if item.DepartmentId == sysUser.DepartmentId {
  3497. btnDetailItem.BtnHistoryList = true
  3498. }
  3499. }
  3500. }
  3501. }
  3502. //子权限切片集合
  3503. allFiccPermissions, permissionMap, e := services.GetBasePermissionLookItem(utils.COMPANY_PRODUCT_FICC_ID)
  3504. if e != nil {
  3505. br.Msg = "查询基础权限失败"
  3506. br.ErrMsg = "查询基础权限失败,Err:" + e.Error()
  3507. return
  3508. }
  3509. //遍历获取
  3510. for _, v := range allFiccPermissions {
  3511. if v.ParentId == 0 {
  3512. checkList := make([]int, 0)
  3513. plist := new(company.PermissionLookList)
  3514. plist.Items = make([]*company.PermissionLookItem, 0)
  3515. items, ok1 := permissionMap[v.ChartPermissionId]
  3516. if ok1 {
  3517. for itemK, n := range items {
  3518. permission, e := company.GetCompanyPermissionCheckItem(companyId, n.ChartPermissionId)
  3519. if e != nil && e.Error() != utils.ErrNoRow() {
  3520. br.Msg = "获取失败"
  3521. br.ErrMsg = "获取权限信息失败,Err:" + e.Error()
  3522. return
  3523. }
  3524. if permission != nil && permission.ChartPermissionId > 0 {
  3525. checkList = append(checkList, n.ChartPermissionId)
  3526. items[itemK].StartDate = permission.StartDate
  3527. items[itemK].EndDate = permission.EndDate
  3528. items[itemK].Status = permission.Status
  3529. endDateTime, _ := time.Parse(utils.FormatDate, permission.EndDate)
  3530. endDateTime = endDateTime.AddDate(0, 0, 1)
  3531. sub := endDateTime.Sub(time.Now())
  3532. if sub < 0 {
  3533. sub = 0
  3534. }
  3535. expireDay := fmt.Sprintf("%v", int(sub.Hours()/24))
  3536. items[itemK].ExpireDay = expireDay
  3537. }
  3538. }
  3539. plist.Items = items
  3540. }
  3541. plist.ClassifyName = v.PermissionName
  3542. plist.CheckList = checkList
  3543. item.PermissionList = append(item.PermissionList, plist)
  3544. }
  3545. }
  3546. resp.FiccItem = item
  3547. if (roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER ||
  3548. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP || roleTypeCode == utils.ROLE_TYPE_CODE_FICC_DEPARTMENT) &&
  3549. item.Status == utils.COMPANY_STATUS_TRY_OUT && item.ApproveStatus != "待审批" {
  3550. resp.IsButtonShow = 1
  3551. }
  3552. } else {
  3553. if strings.Contains(sysUser.RoleTypeCode, "rai") {
  3554. if item.Status == utils.COMPANY_STATUS_FREEZE || item.Status == utils.COMPANY_STATUS_LOSE {
  3555. btnDetailItem.BtnHistoryList = true
  3556. } else {
  3557. if item.SellerId == sysUser.AdminId {
  3558. btnDetailItem.BtnHistoryList = true
  3559. }
  3560. if sysUser.Authority > 0 {
  3561. if item.GroupId == sysUser.GroupId {
  3562. btnDetailItem.BtnHistoryList = true
  3563. }
  3564. if item.DepartmentId == sysUser.DepartmentId {
  3565. btnDetailItem.BtnHistoryList = true
  3566. }
  3567. }
  3568. }
  3569. }
  3570. classifyName := "权益"
  3571. checkList := make([]int, 0)
  3572. plist := new(company.PermissionLookList)
  3573. items, err := company.GetPermissionLookItems(item.ProductId, classifyName)
  3574. if err != nil {
  3575. br.Msg = "获取失败"
  3576. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  3577. return
  3578. }
  3579. for itemK, n := range items {
  3580. permission, err := company.GetCompanyPermissionCheckItem(companyId, n.ChartPermissionId)
  3581. if err != nil && err.Error() != utils.ErrNoRow() {
  3582. br.Msg = "获取失败"
  3583. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  3584. return
  3585. }
  3586. if permission != nil && permission.ChartPermissionId > 0 {
  3587. checkList = append(checkList, n.ChartPermissionId)
  3588. items[itemK].StartDate = permission.StartDate
  3589. items[itemK].EndDate = permission.EndDate
  3590. items[itemK].Status = permission.Status
  3591. endDateTime, _ := time.Parse(utils.FormatDate, permission.EndDate)
  3592. endDateTime = endDateTime.AddDate(0, 0, 1)
  3593. sub := endDateTime.Sub(time.Now())
  3594. if sub < 0 {
  3595. sub = 0
  3596. }
  3597. expireDay := fmt.Sprintf("%v", int(sub.Hours()/24))
  3598. items[itemK].ExpireDay = expireDay
  3599. }
  3600. //count, err := company.GetCompanyPermissionCheck(companyId, n.ChartPermissionId)
  3601. //if err != nil {
  3602. // br.Msg = "获取失败"
  3603. // br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  3604. // return
  3605. //}
  3606. //if count > 0 {
  3607. // checkList = append(checkList, n.ChartPermissionId)
  3608. //}
  3609. }
  3610. item.SpecialSurplus, err = cygxService.GetSpecialSurplusByCompanyNew(companyId)
  3611. if err != nil {
  3612. br.Msg = "获取失败"
  3613. br.ErrMsg = "获取专项调研信息失败,Err:" + err.Error()
  3614. return
  3615. }
  3616. plist.Items = items
  3617. plist.ClassifyName = classifyName
  3618. plist.CheckList = checkList
  3619. item.PermissionList = append(item.PermissionList, plist)
  3620. resp.RaiItem = item
  3621. if (roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER ||
  3622. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP ||
  3623. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_DEPARTMENT) &&
  3624. item.Status == utils.COMPANY_STATUS_TRY_OUT && item.ApproveStatus != "待审批" {
  3625. resp.IsButtonShow = 1
  3626. }
  3627. }
  3628. btnItem := services.GetCompanyPermissionButton(roleTypeCode, item.Status, strconv.Itoa(item.SellerId), strconv.Itoa(item.GroupId),
  3629. item.GroupId, sysUser.GroupId, item.SellerId, sysUser.AdminId, sysUser.Authority, item.ProductId, item.ShareSellerId, "")
  3630. //if itemLen > 1 {
  3631. // btnDetailItem.BtnEdit = false
  3632. // btnDetailItem.BtnDelete = false
  3633. //} else {
  3634. // btnDetailItem.BtnEdit = btnItem.BtnEdit
  3635. // btnDetailItem.BtnDelete = btnItem.BtnDelete
  3636. //}
  3637. switch item.ProductId {
  3638. case 1:
  3639. btnDetailItem.FiccEdit = btnItem.BtnEdit
  3640. btnDetailItem.FiccDelete = btnItem.BtnDelete
  3641. case 2:
  3642. btnDetailItem.RaiEdit = btnItem.BtnEdit
  3643. btnDetailItem.RaiDelete = btnItem.BtnDelete
  3644. }
  3645. if !btnDetailItem.BtnEdit {
  3646. btnDetailItem.BtnEdit = btnItem.BtnEdit
  3647. }
  3648. if !btnDetailItem.BtnDelete {
  3649. btnDetailItem.BtnDelete = btnItem.BtnDelete
  3650. }
  3651. //联系人操作权限
  3652. if resp.IsContractButtonShow == false {
  3653. resp.IsContractButtonShow = services.CheckCompanyUserButton(sysUser.RoleTypeCode, item.SellerId, sysUser.AdminId, item.ProductId, item.ShareSellerId, item.Status)
  3654. }
  3655. }
  3656. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN ||
  3657. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN ||
  3658. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  3659. resp.IsButtonShow = 1
  3660. btnDetailItem.BtnHistoryList = true
  3661. }
  3662. //ficc权限
  3663. if ficcStatus, ok := statusMap[1]; ok {
  3664. if ficcStatus == utils.COMPANY_STATUS_TRY_OUT {
  3665. if raiStatus, ok := statusMap[2]; ok {
  3666. //另一个权限也是 试用 、冻结、流失
  3667. if raiStatus == utils.COMPANY_STATUS_TRY_OUT || raiStatus == utils.COMPANY_STATUS_FREEZE || raiStatus == utils.COMPANY_STATUS_LOSE {
  3668. //那么超管、部门管理员、销售可以编辑
  3669. if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER || roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3670. btnDetailItem.BaseInfoEdit = true
  3671. }
  3672. }
  3673. //权益是永续时,超管可编辑基础信息
  3674. if raiStatus == utils.COMPANY_STATUS_FOREVER {
  3675. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3676. btnDetailItem.BaseInfoEdit = true
  3677. }
  3678. }
  3679. } else {
  3680. //权限未开,有编辑基础信息权限
  3681. btnDetailItem.BaseInfoEdit = true
  3682. }
  3683. }
  3684. if ficcStatus == utils.COMPANY_STATUS_FOREVER {
  3685. if raiStatus, ok := statusMap[2]; ok {
  3686. //另一个权限也是 永续 、冻结、流失
  3687. if raiStatus == utils.COMPANY_STATUS_TRY_OUT || raiStatus == utils.COMPANY_STATUS_FOREVER || raiStatus == utils.COMPANY_STATUS_FREEZE || raiStatus == utils.COMPANY_STATUS_LOSE {
  3688. //超管可编辑基础信息
  3689. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3690. btnDetailItem.BaseInfoEdit = true
  3691. }
  3692. }
  3693. } else {
  3694. //权限未开,有编辑基础信息权限
  3695. btnDetailItem.BaseInfoEdit = true
  3696. }
  3697. }
  3698. }
  3699. //权益销售
  3700. if raiStatus, ok := statusMap[2]; ok {
  3701. if raiStatus == utils.COMPANY_STATUS_TRY_OUT {
  3702. if ficcStatus, ok := statusMap[1]; ok {
  3703. //另一个权限也是 试用 、冻结、流失
  3704. if ficcStatus == utils.COMPANY_STATUS_TRY_OUT || ficcStatus == utils.COMPANY_STATUS_FREEZE || ficcStatus == utils.COMPANY_STATUS_LOSE {
  3705. //那么超管、部门管理员、销售可以编辑
  3706. if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER || roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3707. btnDetailItem.BaseInfoEdit = true
  3708. }
  3709. }
  3710. //ficc是永续时,超管可编辑基础信息
  3711. if ficcStatus == utils.COMPANY_STATUS_FOREVER {
  3712. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3713. btnDetailItem.BaseInfoEdit = true
  3714. }
  3715. }
  3716. } else {
  3717. //权限未开,有编辑基础信息权限
  3718. btnDetailItem.BaseInfoEdit = true
  3719. }
  3720. }
  3721. if raiStatus == utils.COMPANY_STATUS_FOREVER {
  3722. if ficcStatus, ok := statusMap[1]; ok {
  3723. //另一个权限也是 试用、永续 、冻结、流失
  3724. if ficcStatus == utils.COMPANY_STATUS_TRY_OUT || ficcStatus == utils.COMPANY_STATUS_FOREVER || ficcStatus == utils.COMPANY_STATUS_FREEZE || ficcStatus == utils.COMPANY_STATUS_LOSE {
  3725. //超管可编辑基础信息
  3726. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3727. btnDetailItem.BaseInfoEdit = true
  3728. }
  3729. }
  3730. } else {
  3731. //权限未开,有编辑基础信息权限
  3732. btnDetailItem.BaseInfoEdit = true
  3733. }
  3734. }
  3735. }
  3736. resp.Item = item
  3737. resp.BtnItem = btnDetailItem
  3738. br.Ret = 200
  3739. br.Success = true
  3740. br.Msg = "获取成功"
  3741. br.Data = resp
  3742. }
  3743. // @Title 编辑客户
  3744. // @Description 编辑客户接口
  3745. // @Param request body company.CompanyEditReq true "type json string"
  3746. // @Success Ret=200 保存成功
  3747. // @router /edit [post]
  3748. func (this *CompanyController) Edit() {
  3749. br := new(models.BaseResponse).Init()
  3750. defer func() {
  3751. this.Data["json"] = br
  3752. this.ServeJSON()
  3753. }()
  3754. sysUser := this.SysUser
  3755. if sysUser == nil {
  3756. br.Msg = "请登录"
  3757. br.ErrMsg = "请登录,SysUser Is Empty"
  3758. br.Ret = 408
  3759. return
  3760. }
  3761. //roleTypeCode := sysUser.RoleTypeCode
  3762. var req company.CompanyEditReq
  3763. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  3764. if err != nil {
  3765. br.Msg = "参数解析异常!"
  3766. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  3767. return
  3768. }
  3769. if req.CompanyId <= 0 {
  3770. br.Msg = "参数异常!"
  3771. br.ErrMsg = "CompanyId:" + strconv.Itoa(req.CompanyId)
  3772. return
  3773. }
  3774. if req.CompanyName == "" {
  3775. br.Msg = "请填写客户名称"
  3776. return
  3777. }
  3778. if req.CreditCode == "" {
  3779. br.Msg = "请填写社会统一信用码"
  3780. return
  3781. }
  3782. //移除空格
  3783. req.CreditCode = utils.TrimStr(req.CreditCode)
  3784. productId := services.GetProductId(sysUser.RoleTypeCode) //产品权限id
  3785. for _, v := range req.Products {
  3786. //X类试用,转为永续
  3787. if v.Status == utils.COMPANY_STATUS_X_CLASS_TRY_OUT {
  3788. v.Status = utils.COMPANY_STATUS_FOREVER
  3789. }
  3790. if productId == utils.COMPANY_PRODUCT_RAI_ID {
  3791. //查询客户的产品权限
  3792. companyReportPermissionListOld, err := company.GetCompanyReportPermission(req.CompanyId, productId)
  3793. if err != nil {
  3794. br.Msg = "查询客户的产品权限异常"
  3795. br.ErrMsg = "查询客户的产品权限异常:" + err.Error()
  3796. return
  3797. }
  3798. permissionArr := strings.Split(v.PermissionIds, ",")
  3799. //如果所选行业不属于研选订阅跟研选扣点包,那就是非研选试用客户
  3800. var isNoResearch bool
  3801. for _, v := range permissionArr {
  3802. if v != strconv.Itoa(utils.CHART_PERMISSION_ID_YANXUAN) && v != strconv.Itoa(utils.YAN_XUAN_KOU_DIAN_BAO_ID) {
  3803. isNoResearch = true
  3804. continue
  3805. }
  3806. }
  3807. if isNoResearch && len(companyReportPermissionListOld) != len(permissionArr) {
  3808. tryOutCountRai, err := company.GetRaiCompanyTryOutCountNoResearch(sysUser.AdminId)
  3809. if err != nil {
  3810. br.Msg = "判断试用客户量失败"
  3811. br.ErrMsg = "判断试用客户量失败,Err:" + err.Error()
  3812. return
  3813. }
  3814. if tryOutCountRai >= utils.COMPANY_STATUS_TRY_OUT_COUNT_RAI {
  3815. br.Msg = "非研选试用客户最多40家"
  3816. return
  3817. }
  3818. }
  3819. }
  3820. if v.IndustryId <= 0 {
  3821. br.Msg = "请选择行业"
  3822. br.IsSendEmail = false
  3823. return
  3824. }
  3825. //获取客户产品信息
  3826. productItem, err := company.GetCompanyProductById(v.CompanyProductId)
  3827. if err != nil {
  3828. br.Msg = "数据获取失败!"
  3829. br.ErrMsg = "数据获取失败,Err:" + err.Error()
  3830. return
  3831. }
  3832. if productItem == nil {
  3833. br.Msg = "客户信息不存在!"
  3834. return
  3835. }
  3836. // 如果本身是有权限归属的,同时传入的参数不是当前账号权限的,那么过滤该次循环,进入下次循环
  3837. if productId > 0 && productItem.ProductId != productId {
  3838. continue
  3839. }
  3840. if v.Status == "" {
  3841. br.Msg = "客户状态不可为空"
  3842. return
  3843. }
  3844. //if v.Reasons == "" {
  3845. // br.Msg = "请填写新增理由"
  3846. // return
  3847. //}
  3848. if v.PermissionIds == "" {
  3849. br.Msg = "请选择权限"
  3850. return
  3851. }
  3852. var startDate, endDate string
  3853. startDate = productItem.StartDate
  3854. endDate = productItem.EndDate
  3855. if startDate == "" || endDate == "" {
  3856. br.Msg = "数据错误"
  3857. br.Msg = "数据错误,开始或结束日期为空:startDate:" + startDate + "endDate:" + endDate
  3858. return
  3859. }
  3860. //判断客户是否已经存在
  3861. companyNameIsExist, err := company.GetCompanyCountByCompanyNameAndCompanyId(req.CompanyId, req.CompanyName)
  3862. if err != nil {
  3863. br.Msg = "判断客户是否存在失败"
  3864. br.ErrMsg = "判断客户是否存在失败,Err:" + err.Error()
  3865. return
  3866. }
  3867. if companyNameIsExist > 0 {
  3868. br.Msg = "客户已存在,请重新输入客户名称"
  3869. return
  3870. }
  3871. //判断客户是否已经存在
  3872. companyCreditCodeIsExist, err := company.GetCompanyCountByCreditCodeAndCompanyId(req.CompanyId, req.CreditCode)
  3873. if err != nil {
  3874. br.Msg = "判断客户是否存在失败"
  3875. br.ErrMsg = "判断客户是否存在失败,Err:" + err.Error()
  3876. return
  3877. }
  3878. if companyCreditCodeIsExist > 0 {
  3879. br.Msg = "客户已存在,请重新输入统一社会信用代码"
  3880. return
  3881. }
  3882. seller, err := system.GetSysAdminById(v.SellsId)
  3883. if err != nil {
  3884. br.Msg = "获取销售信息失败"
  3885. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  3886. return
  3887. }
  3888. if seller == nil {
  3889. br.Msg = "所属销售不存在"
  3890. return
  3891. }
  3892. //tryOutCount, err := company.GetCompanyTryOutCount(utils.COMPANY_STATUS_TRY_OUT, seller.AdminId)
  3893. //if err != nil {
  3894. // br.Msg = "判断试用客户量失败"
  3895. // br.ErrMsg = "判断试用客户量失败,Err:" + err.Error()
  3896. // return
  3897. //}
  3898. //if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_FICC_DEPARTMENT ||
  3899. // roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER || roleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
  3900. // if tryOutCount >= utils.COMPANY_STATUS_TRY_OUT_COUNT && v.SellsId == sysUser.AdminId {
  3901. // br.Msg = "您的试用客户总数,已超过上限,不可继续新增"
  3902. // return
  3903. // }
  3904. //}
  3905. industry, err := company.GetCompanyIndustryById(v.IndustryId)
  3906. if err != nil {
  3907. br.Msg = "获取行业信息失败"
  3908. br.ErrMsg = "获取行业信息失败,Err:" + err.Error()
  3909. return
  3910. }
  3911. companyProduct := new(company.CompanyProduct)
  3912. companyProduct.ProductId = productItem.ProductId
  3913. companyProduct.CompanyId = req.CompanyId
  3914. companyProduct.CompanyName = req.CompanyName
  3915. companyProduct.Source = v.Source
  3916. companyProduct.Reasons = v.Reasons
  3917. companyProduct.Status = v.Status
  3918. companyProduct.StartDate = startDate
  3919. companyProduct.EndDate = endDate
  3920. companyProduct.IndustryId = v.IndustryId
  3921. companyProduct.IndustryName = industry.IndustryName
  3922. companyProduct.SellerId = seller.AdminId
  3923. companyProduct.SellerName = seller.RealName
  3924. companyProduct.GroupId = seller.GroupId
  3925. companyProduct.DepartmentId = seller.DepartmentId
  3926. companyProduct.IsSuspend = 0
  3927. companyProduct.ModifyTime = time.Now()
  3928. companyProduct.CompanyProductId = v.CompanyProductId
  3929. companyProduct.Scale = v.Scale
  3930. err = company.ModifyCompanyProduct(companyProduct)
  3931. if err != nil {
  3932. br.Msg = "修改客户信息失败"
  3933. br.ErrMsg = "修改客户产品信息失败,Err:" + err.Error()
  3934. return
  3935. }
  3936. // CRM8.8-下面的需求取消, 编辑的时候根据选择开通对应权限
  3937. // 如果是权益客户,编辑的时候开通主观客观权限
  3938. //if v.CompanyType == utils.COMPANY_CLASSIFY_RAI {
  3939. // permissionStr, err := company.GetPermissionIdById(v.PermissionIds)
  3940. // if err != nil {
  3941. // br.Msg = "修改失败"
  3942. // br.ErrMsg = "获取主观客观权限信息失败,Err:" + err.Error()
  3943. // return
  3944. // }
  3945. // v.PermissionIds = permissionStr
  3946. //}
  3947. //处理权限
  3948. companyReportPermissionList, err := services.AddCompanyPermission(req.CompanyId, seller.AdminId, productItem.ProductId, productItem.ProductName, seller.RealName, v.PermissionIds, startDate, endDate)
  3949. if err != nil {
  3950. br.Msg = "修改失败"
  3951. br.ErrMsg = "新增客户设置权限失败,err:" + err.Error()
  3952. return
  3953. }
  3954. //新增操作记录
  3955. {
  3956. record := new(company.CompanyOperationRecord)
  3957. record.CompanyId = req.CompanyId
  3958. record.CompanyName = req.CompanyName
  3959. record.SellerId = companyProduct.SellerId
  3960. record.SysUserId = this.SysUser.AdminId
  3961. record.SysRealName = this.SysUser.RealName
  3962. record.Remark = "编辑客户"
  3963. record.Operation = "edit"
  3964. record.CreateTime = time.Now()
  3965. record.ProductId = productItem.ProductId
  3966. record.ProductName = productItem.ProductName
  3967. record.Status = productItem.Status
  3968. _, err = company.AddCompanyOperationRecord(record)
  3969. if err != nil {
  3970. go alarm_msg.SendAlarmMsg("URI:"+this.Ctx.Input.URI()+"<br/> "+";<br/> Body:"+err.Error(), 3)
  3971. //go utils.SendEmail(utils.APPNAME+"失败提醒"+utils.RunMode, "URI:"+this.Ctx.Input.URI()+"<br/> "+";<br/> Body:"+err.Error(), utils.EmailSendToUsers)
  3972. }
  3973. }
  3974. //新增客户产品日志
  3975. {
  3976. productLog := new(company.CompanyProductLog)
  3977. productLog.CompanyProductId = v.CompanyProductId
  3978. productLog.CompanyId = companyProduct.CompanyId
  3979. productLog.ProductId = companyProduct.ProductId
  3980. productLog.ProductName = companyProduct.ProductName
  3981. productLog.CompanyName = companyProduct.CompanyName
  3982. productLog.CompanyName = companyProduct.CompanyName
  3983. productLog.Source = companyProduct.Source
  3984. productLog.Reasons = companyProduct.Reasons
  3985. productLog.Status = companyProduct.Status
  3986. productLog.IndustryId = companyProduct.IndustryId
  3987. productLog.IndustryName = companyProduct.IndustryName
  3988. productLog.SellerId = companyProduct.SellerId
  3989. productLog.SellerName = companyProduct.SellerName
  3990. productLog.GroupId = companyProduct.GroupId
  3991. productLog.DepartmentId = companyProduct.DepartmentId
  3992. productLog.IsSuspend = companyProduct.IsSuspend
  3993. productLog.SuspendTime = companyProduct.SuspendTime
  3994. productLog.ApproveStatus = companyProduct.ApproveStatus
  3995. productLog.FreezeTime = companyProduct.FreezeTime
  3996. productLog.Remark = companyProduct.Remark
  3997. productLog.StartDate = companyProduct.StartDate
  3998. productLog.EndDate = companyProduct.EndDate
  3999. productLog.CreateTime = companyProduct.CreateTime
  4000. productLog.ModifyTime = companyProduct.ModifyTime
  4001. productLog.LoseReason = companyProduct.LoseReason
  4002. productLog.LossTime = companyProduct.LossTime
  4003. productLog.LogType = "modify"
  4004. productLog.LogCreateTime = time.Now()
  4005. productLog.AdminId = this.SysUser.AdminId
  4006. productLog.Scale = companyProduct.Scale
  4007. go company.AddCompanyProductLog(productLog)
  4008. }
  4009. //新增客户产品状态变更日志
  4010. {
  4011. startDateTime, _ := time.ParseInLocation(utils.FormatDate, startDate, time.Local)
  4012. endDateTime, _ := time.ParseInLocation(utils.FormatDate, endDate, time.Local)
  4013. companyProductUpdateLog := &company.CompanyProductUpdateLog{
  4014. Id: 0,
  4015. CompanyId: req.CompanyId,
  4016. ProductId: productId,
  4017. Status: "试用",
  4018. Source: "edit",
  4019. SellerId: seller.AdminId,
  4020. SellerName: seller.RealName,
  4021. StartDate: startDateTime,
  4022. EndDate: endDateTime,
  4023. RealEndDate: startDateTime,
  4024. CreateTime: time.Now(),
  4025. }
  4026. go company.AddCompanyProductUpdateLog(companyProductUpdateLog)
  4027. // 添加试用记录
  4028. companyProductTryOutUpdateLog := &company.CompanyProductTryOutUpdateLog{
  4029. Id: 0,
  4030. CompanyId: req.CompanyId,
  4031. ProductId: productId,
  4032. Source: "edit",
  4033. SellerId: seller.AdminId,
  4034. SellerName: seller.RealName,
  4035. StartDate: startDateTime,
  4036. EndDate: endDateTime,
  4037. RealEndDate: startDateTime,
  4038. IsStop: 0,
  4039. CreateTime: time.Now(),
  4040. }
  4041. go company.AddCompanyProductTryOutUpdateLog(companyProductTryOutUpdateLog, companyReportPermissionList)
  4042. }
  4043. }
  4044. companyItem := new(company.Company)
  4045. companyItem.CompanyId = req.CompanyId
  4046. companyItem.CompanyName = req.CompanyName
  4047. companyItem.CreditCode = req.CreditCode
  4048. companyItem.Province = req.Province
  4049. companyItem.City = req.City
  4050. companyItem.Address = req.Province + req.City
  4051. companyItem.LastUpdatedTime = time.Now()
  4052. companyItem.Enabled = 1
  4053. companyItem.Nation = req.Nation
  4054. err = company.ModifyCompany(companyItem)
  4055. if err != nil {
  4056. br.Msg = "修改客户信息失败"
  4057. br.ErrMsg = "修改客户信息失败,Err:" + err.Error()
  4058. return
  4059. }
  4060. //新增客户日志
  4061. {
  4062. companyLog := new(company.CompanyLog)
  4063. companyLog.CompanyId = req.CompanyId
  4064. companyLog.CompanyName = req.CompanyName
  4065. companyLog.CreditCode = req.CreditCode
  4066. companyLog.Address = companyItem.Address
  4067. companyLog.City = companyItem.City
  4068. companyLog.Province = companyItem.Province
  4069. companyLog.LastUpdatedTime = companyItem.LastUpdatedTime
  4070. companyLog.AdminId = this.SysUser.AdminId
  4071. companyLog.LogType = "modify"
  4072. companyLog.LogCreateTime = time.Now()
  4073. go company.AddCompanyLog(companyLog)
  4074. }
  4075. br.Ret = 200
  4076. br.Success = true
  4077. br.Msg = "保存成功"
  4078. }
  4079. // @Title 编辑补充客户信息接口
  4080. // @Description 编辑补充客户信息接口
  4081. // @Param request body company.CompanyInfoEditReq true "type json string"
  4082. // @Success Ret=200 保存成功
  4083. // @router /company_info/edit [post]
  4084. func (this *CompanyController) EditCompanyInfo() {
  4085. br := new(models.BaseResponse).Init()
  4086. defer func() {
  4087. this.Data["json"] = br
  4088. this.ServeJSON()
  4089. }()
  4090. sysUser := this.SysUser
  4091. if sysUser == nil {
  4092. br.Msg = "请登录"
  4093. br.ErrMsg = "请登录,SysUser Is Empty"
  4094. br.Ret = 408
  4095. return
  4096. }
  4097. var req company.CompanyInfoEditReq
  4098. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  4099. if err != nil {
  4100. br.Msg = "参数解析异常!"
  4101. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  4102. return
  4103. }
  4104. if req.CompanyId <= 0 {
  4105. br.Msg = "参数异常!"
  4106. br.ErrMsg = "CompanyId:" + strconv.Itoa(req.CompanyId)
  4107. return
  4108. }
  4109. if req.CompanyName == "" {
  4110. br.Msg = "请填写客户名称"
  4111. return
  4112. }
  4113. if req.CreditCode == "" {
  4114. br.Msg = "请填写社会统一信用码"
  4115. return
  4116. }
  4117. //if req.Province == "" {
  4118. // br.Msg = "请选择省份"
  4119. // return
  4120. //}
  4121. //if req.City == "" {
  4122. // br.Msg = "请选择市区"
  4123. // return
  4124. //}
  4125. //if req.IndustryId <= 0 {
  4126. // br.Msg = "请选择所属行业"
  4127. // return
  4128. //}
  4129. //if req.IndustryName == "" {
  4130. // br.Msg = "请选择所属行业"
  4131. // return
  4132. //}
  4133. //if req.Source == "" {
  4134. // br.Msg = "请选择来源"
  4135. // return
  4136. //}
  4137. //移除空格
  4138. req.CreditCode = utils.TrimStr(req.CreditCode)
  4139. //获取产品权限
  4140. productId := services.GetProductId(sysUser.RoleTypeCode)
  4141. if productId <= 0 {
  4142. br.Msg = "当前账号不允许修改客户信息"
  4143. return
  4144. }
  4145. companyNameIsExist, err := company.GetCompanyCountByCompanyNameAndCompanyId(req.CompanyId, req.CompanyName)
  4146. if err != nil {
  4147. br.Msg = "判断客户是否存在失败"
  4148. br.ErrMsg = "判断客户是否存在失败,Err:" + err.Error()
  4149. return
  4150. }
  4151. if companyNameIsExist > 0 {
  4152. br.Msg = "客户已存在,请重新输入客户名称"
  4153. return
  4154. }
  4155. //判断客户是否已经存在
  4156. companyCreditCodeIsExist, err := company.GetCompanyCountByCreditCodeAndCompanyId(req.CompanyId, req.CreditCode)
  4157. if err != nil {
  4158. br.Msg = "判断客户是否存在失败"
  4159. br.ErrMsg = "判断客户是否存在失败,Err:" + err.Error()
  4160. return
  4161. }
  4162. if companyCreditCodeIsExist > 0 {
  4163. br.Msg = "客户已存在,统一社会信用代码"
  4164. return
  4165. }
  4166. //查询该客户
  4167. companyItem, err := company.GetCompanyById(req.CompanyId)
  4168. if err != nil {
  4169. br.Msg = "查找客户失败"
  4170. br.ErrMsg = "查找客户失败,Err:" + err.Error()
  4171. return
  4172. }
  4173. //待更新字段
  4174. updateCol := make([]string, 0)
  4175. companyItem.CompanyName = req.CompanyName
  4176. companyItem.CreditCode = req.CreditCode
  4177. companyItem.Enabled = 1
  4178. companyItem.LastUpdatedTime = time.Now()
  4179. updateCol = append(updateCol, "CompanyName", "CreditCode", "Enabled", "LastUpdatedTime")
  4180. if req.Province != "" && req.City != "" {
  4181. companyItem.Province = req.Province
  4182. companyItem.City = req.City
  4183. companyItem.Address = req.Province + req.City
  4184. updateCol = append(updateCol, "Province", "City", "Address")
  4185. }
  4186. err = companyItem.Update(updateCol)
  4187. if err != nil {
  4188. br.Msg = "修改客户信息失败"
  4189. br.ErrMsg = "修改客户信息失败,Err:" + err.Error()
  4190. return
  4191. }
  4192. //查询并更新客户产品信息
  4193. companyProduct, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, productId)
  4194. if err != nil {
  4195. if err.Error() != utils.ErrNoRow() {
  4196. br.Msg = "查询客户产品信息失败"
  4197. br.ErrMsg = "查询客户产品信息失败,Err:" + err.Error()
  4198. return
  4199. }
  4200. } else {
  4201. if companyProduct != nil {
  4202. //客户产品待更新字段
  4203. updateCompanyProductCol := make([]string, 0)
  4204. //产品信息(来源、行业)
  4205. if req.IndustryId != 0 && req.IndustryId != companyProduct.IndustryId {
  4206. companyProduct.IndustryId = req.IndustryId
  4207. companyProduct.IndustryName = req.IndustryName
  4208. updateCompanyProductCol = append(updateCompanyProductCol, "IndustryId", "IndustryName")
  4209. }
  4210. if req.Source != "" && req.Source != companyProduct.Source {
  4211. companyProduct.Source = req.Source
  4212. updateCompanyProductCol = append(updateCompanyProductCol, "Source")
  4213. }
  4214. //更新客户产品信息
  4215. if len(updateCompanyProductCol) > 0 {
  4216. err = companyProduct.Update(updateCompanyProductCol)
  4217. if err != nil {
  4218. br.Msg = "修改客户信息失败"
  4219. br.ErrMsg = "修改客户信息失败,Err:" + err.Error()
  4220. return
  4221. }
  4222. }
  4223. }
  4224. }
  4225. //新增客户日志
  4226. {
  4227. companyLog := new(company.CompanyLog)
  4228. companyLog.CompanyId = req.CompanyId
  4229. companyLog.CompanyName = req.CompanyName
  4230. companyLog.CreditCode = req.CreditCode
  4231. companyLog.Address = companyItem.Address
  4232. companyLog.City = companyItem.City
  4233. companyLog.Province = companyItem.Province
  4234. companyLog.LastUpdatedTime = companyItem.LastUpdatedTime
  4235. companyLog.AdminId = this.SysUser.AdminId
  4236. companyLog.LogType = "modify"
  4237. companyLog.LogCreateTime = time.Now()
  4238. go company.AddCompanyLog(companyLog)
  4239. }
  4240. br.Ret = 200
  4241. br.Success = true
  4242. br.Msg = "保存成功"
  4243. }
  4244. // @Title 客户模糊检索(新增/编辑客户页面试用)
  4245. // @Description 客户模糊检索接口(新增/编辑客户页面试用)
  4246. // @Param KeyWord query string true "搜索关键词"
  4247. // @Success 200 {object} company.CompanyFuzzySearchReq
  4248. // @router /fuzzy/search [get]
  4249. func (this *CompanyController) FuzzySearch() {
  4250. br := new(models.BaseResponse).Init()
  4251. defer func() {
  4252. this.Data["json"] = br
  4253. this.ServeJSON()
  4254. }()
  4255. keyWord := this.GetString("KeyWord")
  4256. list, err := company.GetCompanyFuzzySearch(keyWord)
  4257. if err != nil {
  4258. br.Msg = "获取信息失败"
  4259. br.ErrMsg = "获取信息失败,err:" + err.Error()
  4260. return
  4261. }
  4262. resp := new(company.CompanyFuzzySearchReq)
  4263. resp.List = list
  4264. br.Ret = 200
  4265. br.Success = true
  4266. br.Msg = "获取成功"
  4267. br.Data = resp
  4268. }
  4269. // @Title 删除客户
  4270. // @Description 删除客户接口
  4271. // @Param request body company.DeletePptReq true "type json string"
  4272. // @Success Ret=200 保存成功
  4273. // @router /delete [post]
  4274. func (this *CompanyController) Delete() {
  4275. br := new(models.BaseResponse).Init()
  4276. defer func() {
  4277. this.Data["json"] = br
  4278. this.ServeJSON()
  4279. }()
  4280. sysUser := this.SysUser
  4281. if sysUser == nil {
  4282. br.Msg = "请登录"
  4283. br.ErrMsg = "请登录,SysUser Is Empty"
  4284. br.Ret = 408
  4285. return
  4286. }
  4287. var req company.DeletePptReq
  4288. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  4289. if err != nil {
  4290. br.Msg = "参数解析异常!"
  4291. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  4292. return
  4293. }
  4294. if req.CompanyId <= 0 {
  4295. br.Msg = "参数错误"
  4296. br.ErrMsg = "客户ID小于等于0"
  4297. return
  4298. }
  4299. roleTypeCode := this.SysUser.RoleTypeCode
  4300. productId := services.GetProductId(roleTypeCode)
  4301. productItems, err := company.GetCompanyProductsByCompanyId(req.CompanyId)
  4302. if err != nil {
  4303. br.Msg = "删除失败"
  4304. br.ErrMsg = "获取客户产品信息失败,Err:" + err.Error()
  4305. return
  4306. }
  4307. // 备份信息
  4308. companyDeleteBakInfo := services.CompanyDeleteBakInfo{
  4309. CompanyId: req.CompanyId,
  4310. CompanyName: "",
  4311. CompanyInfo: &company.Company{},
  4312. CompanyProductInfo: make([]*company.CompanyProduct, 0),
  4313. CompanyPermissionInfo: make([]*company.CompanyReportPermission, 0),
  4314. UserSellerRelationInfo: make([]*models.UserSellerRelation, 0),
  4315. UserRecordInfo: make([]*models.UserRecord, 0),
  4316. UserInfo: make([]*models.WxUser, 0),
  4317. CompanyChartPermissionInfo: make([]*company_user.ChartClassifyPermission, 0),
  4318. OpUserId: this.SysUser.AdminId,
  4319. OpUserName: this.SysUser.RealName,
  4320. }
  4321. if productId == 0 {
  4322. for _, v := range productItems {
  4323. //永续,试用,流失,关闭
  4324. if v.Status != utils.COMPANY_STATUS_FOREVER && v.Status != utils.COMPANY_STATUS_TRY_OUT && v.Status != utils.COMPANY_STATUS_LOSE && v.Status != utils.COMPANY_STATUS_CLOSE {
  4325. br.Msg = "该客户" + v.ProductName + "属性为" + v.Status + ",暂不可删除"
  4326. br.ErrMsg = "该客户" + v.ProductName + "属性为" + v.Status + ",暂不可删除"
  4327. return
  4328. }
  4329. companyProductList, companyReportPermissionList, err := company.DeleteCompanyProductById(v.CompanyId, v.ProductId, v.CompanyProductId)
  4330. if err != nil {
  4331. br.Msg = "删除失败"
  4332. br.ErrMsg = "删除失败,Err:" + err.Error()
  4333. return
  4334. }
  4335. companyDeleteBakInfo.CompanyProductInfo = append(companyDeleteBakInfo.CompanyProductInfo, companyProductList...)
  4336. companyDeleteBakInfo.CompanyPermissionInfo = append(companyDeleteBakInfo.CompanyPermissionInfo, companyReportPermissionList...)
  4337. //新增操作记录
  4338. {
  4339. record := new(company.CompanyOperationRecord)
  4340. record.CompanyId = req.CompanyId
  4341. record.CompanyName = v.CompanyName
  4342. record.SellerId = v.SellerId
  4343. record.SysUserId = this.SysUser.AdminId
  4344. record.SysRealName = this.SysUser.RealName
  4345. record.Remark = "删除客户"
  4346. record.Operation = "delete"
  4347. record.CreateTime = time.Now()
  4348. record.ProductId = v.ProductId
  4349. record.ProductName = v.ProductName
  4350. _, err = company.AddCompanyOperationRecord(record)
  4351. if err != nil {
  4352. go alarm_msg.SendAlarmMsg("URI:"+this.Ctx.Input.URI()+"<br/> "+";<br/> Body:"+err.Error(), 3)
  4353. //go utils.SendEmail(utils.APPNAME+"失败提醒"+utils.RunMode, "URI:"+this.Ctx.Input.URI()+"<br/> "+";<br/> Body:"+err.Error(), utils.EmailSendToUsers)
  4354. }
  4355. }
  4356. //删除对应产品的联系人
  4357. userSellerRelationList, userRecordList, wxUserList, chartClassifyPermission, _ := services.DeleteCompanyWxUserByProductId(v.CompanyId, v.ProductId)
  4358. //备份信息
  4359. {
  4360. if companyProductList != nil {
  4361. companyDeleteBakInfo.CompanyProductInfo = append(companyDeleteBakInfo.CompanyProductInfo, companyProductList...)
  4362. }
  4363. if companyReportPermissionList != nil {
  4364. companyDeleteBakInfo.CompanyPermissionInfo = append(companyDeleteBakInfo.CompanyPermissionInfo, companyReportPermissionList...)
  4365. }
  4366. if userSellerRelationList != nil {
  4367. companyDeleteBakInfo.UserSellerRelationInfo = append(companyDeleteBakInfo.UserSellerRelationInfo, userSellerRelationList...)
  4368. }
  4369. if userRecordList != nil {
  4370. companyDeleteBakInfo.UserRecordInfo = append(companyDeleteBakInfo.UserRecordInfo, userRecordList...)
  4371. }
  4372. if wxUserList != nil {
  4373. companyDeleteBakInfo.UserInfo = append(companyDeleteBakInfo.UserInfo, wxUserList...)
  4374. }
  4375. if chartClassifyPermission != nil {
  4376. companyDeleteBakInfo.CompanyChartPermissionInfo = append(companyDeleteBakInfo.CompanyChartPermissionInfo, chartClassifyPermission...)
  4377. }
  4378. companyDeleteBakInfo.CompanyName = v.CompanyName
  4379. }
  4380. }
  4381. } else {
  4382. productObj, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, productId)
  4383. if err != nil {
  4384. br.ErrMsg = "获取客户产品信息失败,Err:" + err.Error()
  4385. br.Msg = "删除失败"
  4386. return
  4387. }
  4388. //永续,试用,流失,关闭
  4389. if productObj.Status != utils.COMPANY_STATUS_FOREVER && productObj.Status != utils.COMPANY_STATUS_TRY_OUT && productObj.Status != utils.COMPANY_STATUS_LOSE && productObj.Status != utils.COMPANY_STATUS_CLOSE {
  4390. br.Msg = "该客户" + productObj.ProductName + "属性为" + productObj.Status + ",暂不可删除"
  4391. br.ErrMsg = "该客户" + productObj.ProductName + "属性为" + productObj.Status + ",暂不可删除"
  4392. return
  4393. }
  4394. companyProductList, companyReportPermissionList, err := company.DeleteCompanyProductById(productObj.CompanyId, productObj.ProductId, productObj.CompanyProductId)
  4395. if err != nil {
  4396. br.Msg = "删除失败"
  4397. br.ErrMsg = "删除失败,Err:" + err.Error()
  4398. return
  4399. }
  4400. //新增操作记录
  4401. {
  4402. record := new(company.CompanyOperationRecord)
  4403. record.CompanyId = req.CompanyId
  4404. record.CompanyName = productObj.CompanyName
  4405. record.SellerId = productObj.SellerId
  4406. record.SysUserId = this.SysUser.AdminId
  4407. record.SysRealName = this.SysUser.RealName
  4408. record.Remark = "删除客户"
  4409. record.Operation = "delete"
  4410. record.CreateTime = time.Now()
  4411. record.ProductId = productObj.ProductId
  4412. record.ProductName = productObj.ProductName
  4413. _, err = company.AddCompanyOperationRecord(record)
  4414. if err != nil {
  4415. go alarm_msg.SendAlarmMsg("URI:"+this.Ctx.Input.URI()+"<br/> "+";<br/> Body:"+err.Error(), 3)
  4416. //go utils.SendEmail(utils.APPNAME+"失败提醒"+utils.RunMode, "URI:"+this.Ctx.Input.URI()+"<br/> "+";<br/> Body:"+err.Error(), utils.EmailSendToUsers)
  4417. }
  4418. }
  4419. //删除对应产品的联系人
  4420. userSellerRelationList, userRecordList, wxUserList, chartClassifyPermission, _ := services.DeleteCompanyWxUserByProductId(productObj.CompanyId, productId)
  4421. //备份信息
  4422. {
  4423. if companyProductList != nil {
  4424. companyDeleteBakInfo.CompanyProductInfo = append(companyDeleteBakInfo.CompanyProductInfo, companyProductList...)
  4425. }
  4426. if companyReportPermissionList != nil {
  4427. companyDeleteBakInfo.CompanyPermissionInfo = append(companyDeleteBakInfo.CompanyPermissionInfo, companyReportPermissionList...)
  4428. }
  4429. if userSellerRelationList != nil {
  4430. companyDeleteBakInfo.UserSellerRelationInfo = append(companyDeleteBakInfo.UserSellerRelationInfo, userSellerRelationList...)
  4431. }
  4432. if userRecordList != nil {
  4433. companyDeleteBakInfo.UserRecordInfo = append(companyDeleteBakInfo.UserRecordInfo, userRecordList...)
  4434. }
  4435. if wxUserList != nil {
  4436. companyDeleteBakInfo.UserInfo = append(companyDeleteBakInfo.UserInfo, wxUserList...)
  4437. }
  4438. if chartClassifyPermission != nil {
  4439. companyDeleteBakInfo.CompanyChartPermissionInfo = append(companyDeleteBakInfo.CompanyChartPermissionInfo, chartClassifyPermission...)
  4440. }
  4441. companyDeleteBakInfo.CompanyName = productObj.CompanyName
  4442. }
  4443. }
  4444. productItemsNew, err := company.GetCompanyProductsByCompanyId(req.CompanyId)
  4445. if err != nil {
  4446. br.Msg = "删除失败"
  4447. br.ErrMsg = "获取客户产品信息失败,Err:" + err.Error()
  4448. return
  4449. }
  4450. if len(productItemsNew) == 0 {
  4451. //删除之前查询的数据信息
  4452. {
  4453. companyProductLists, companyReportPermissions, wxUsers, userSellerRelations, companyContracts, companyContractPermissions, companyInfo, _ := services.GetBeforeDeleteCompanyInfo(req.CompanyId)
  4454. //companyDeleteBakInfo
  4455. if companyProductLists != nil {
  4456. companyDeleteBakInfo.CompanyProductInfo = append(companyDeleteBakInfo.CompanyProductInfo, companyProductLists...)
  4457. }
  4458. if companyReportPermissions != nil {
  4459. companyDeleteBakInfo.CompanyPermissionInfo = append(companyDeleteBakInfo.CompanyPermissionInfo, companyReportPermissions...)
  4460. }
  4461. if wxUsers != nil {
  4462. companyDeleteBakInfo.UserInfo = append(companyDeleteBakInfo.UserInfo, wxUsers...)
  4463. }
  4464. if userSellerRelations != nil {
  4465. companyDeleteBakInfo.UserSellerRelationInfo = append(companyDeleteBakInfo.UserSellerRelationInfo, userSellerRelations...)
  4466. }
  4467. if companyContracts != nil {
  4468. companyDeleteBakInfo.CompanyContract = append(companyDeleteBakInfo.CompanyContract, companyContracts...)
  4469. }
  4470. if companyContractPermissions != nil {
  4471. companyDeleteBakInfo.CompanyContractPermission = append(companyDeleteBakInfo.CompanyContractPermission, companyContractPermissions...)
  4472. }
  4473. if companyInfo != nil {
  4474. companyDeleteBakInfo.CompanyName = companyInfo.CompanyName
  4475. companyDeleteBakInfo.CompanyInfo = companyInfo
  4476. }
  4477. }
  4478. err = company.DeleteCompanyById(req.CompanyId)
  4479. if err != nil {
  4480. br.Msg = "删除失败"
  4481. br.ErrMsg = "删除失败,Err:" + err.Error()
  4482. return
  4483. }
  4484. for _, v := range productItems {
  4485. //新增操作记录
  4486. {
  4487. record := new(company.CompanyOperationRecord)
  4488. record.CompanyId = req.CompanyId
  4489. record.CompanyName = v.CompanyName
  4490. record.SellerId = v.SellerId
  4491. record.SysUserId = this.SysUser.AdminId
  4492. record.SysRealName = this.SysUser.RealName
  4493. record.Remark = "删除客户"
  4494. record.Operation = "delete"
  4495. record.CreateTime = time.Now()
  4496. record.ProductId = v.ProductId
  4497. record.ProductName = v.ProductName
  4498. _, err = company.AddCompanyOperationRecord(record)
  4499. if err != nil {
  4500. go alarm_msg.SendAlarmMsg("URI:"+this.Ctx.Input.URI()+"<br/> "+";<br/> Body:"+err.Error(), 3)
  4501. //go utils.SendEmail(utils.APPNAME+"失败提醒"+utils.RunMode, "URI:"+this.Ctx.Input.URI()+"<br/> "+";<br/> Body:"+err.Error(), utils.EmailSendToUsers)
  4502. }
  4503. }
  4504. }
  4505. }
  4506. //数据备份入库
  4507. {
  4508. companyInfoJsonByte, _ := json.Marshal(companyDeleteBakInfo.CompanyInfo)
  4509. companyProductInfoJsonByte, _ := json.Marshal(companyDeleteBakInfo.CompanyProductInfo)
  4510. companyPermissionInfoJsonByte, _ := json.Marshal(companyDeleteBakInfo.CompanyPermissionInfo)
  4511. userSellerRelationInfoJsonByte, _ := json.Marshal(companyDeleteBakInfo.UserSellerRelationInfo)
  4512. userRecordInfoJsonByte, _ := json.Marshal(companyDeleteBakInfo.UserRecordInfo)
  4513. userInfoJsonByte, _ := json.Marshal(companyDeleteBakInfo.UserInfo)
  4514. companyChartPermissionInfoJsonByte, _ := json.Marshal(companyDeleteBakInfo.CompanyChartPermissionInfo)
  4515. companyContractByte, _ := json.Marshal(companyDeleteBakInfo.CompanyContract)
  4516. companyContractPermissionJsonByte, _ := json.Marshal(companyDeleteBakInfo.CompanyContractPermission)
  4517. companyDeleteBak := &company.CompanyDeleteBak{
  4518. //DeleteBakId: 0,
  4519. CompanyId: companyDeleteBakInfo.CompanyId,
  4520. CompanyName: companyDeleteBakInfo.CompanyName,
  4521. CompanyInfo: string(companyInfoJsonByte),
  4522. CompanyProductInfo: string(companyProductInfoJsonByte),
  4523. CompanyPermissionInfo: string(companyPermissionInfoJsonByte),
  4524. UserSellerRelationInfo: string(userSellerRelationInfoJsonByte),
  4525. UserRecordInfo: string(userRecordInfoJsonByte),
  4526. UserInfo: string(userInfoJsonByte),
  4527. CompanyChartPermissionInfo: string(companyChartPermissionInfoJsonByte),
  4528. CompanyContractInfo: string(companyContractByte),
  4529. CompanyContractPermissionInfo: string(companyContractPermissionJsonByte),
  4530. OpUserId: this.SysUser.AdminId,
  4531. OpUserName: this.SysUser.RealName,
  4532. CreateTime: time.Now(),
  4533. }
  4534. _ = company.AddCompanyDeleteBak(companyDeleteBak)
  4535. }
  4536. br.Ret = 200
  4537. br.Success = true
  4538. br.Msg = "删除成功"
  4539. }
  4540. // @Title 领取客户列表
  4541. // @Description 领取客户列表接口
  4542. // @Param PageSize query int true "每页数据条数"
  4543. // @Param CurrentIndex query int true "当前页页码,从1开始"
  4544. // @Param StartDate query string true "开始时间"
  4545. // @Param EndDate query string true "结束时间"
  4546. // @Param KeyWord query string true "搜索关键词"
  4547. // @Success 200 {object} company.CompanyReceiveListResp
  4548. // @router /receive/list [get]
  4549. func (this *CompanyController) ReceiveList() {
  4550. br := new(models.BaseResponse).Init()
  4551. defer func() {
  4552. this.Data["json"] = br
  4553. this.ServeJSON()
  4554. }()
  4555. sysUser := this.SysUser
  4556. if sysUser == nil {
  4557. br.Msg = "请登录"
  4558. br.ErrMsg = "请登录,SysUser Is Empty"
  4559. br.Ret = 408
  4560. return
  4561. }
  4562. var productId, recevieProductId int
  4563. roleTypeCode := sysUser.RoleTypeCode
  4564. productId = services.GetProductId(roleTypeCode)
  4565. if productId == 1 {
  4566. recevieProductId = 2
  4567. } else if productId == 2 {
  4568. recevieProductId = 1
  4569. }
  4570. if productId == 0 {
  4571. br.Msg = "参数错误"
  4572. br.ErrMsg = "客户类型为:" + roleTypeCode
  4573. return
  4574. }
  4575. pageSize, _ := this.GetInt("PageSize")
  4576. currentIndex, _ := this.GetInt("CurrentIndex")
  4577. adminId := this.GetString("AdminId")
  4578. startDate := this.GetString("StartDate")
  4579. endDate := this.GetString("EndDate")
  4580. keyWord := this.GetString("KeyWord")
  4581. var startSize int
  4582. if pageSize <= 0 {
  4583. pageSize = utils.PageSize20
  4584. }
  4585. if currentIndex <= 0 {
  4586. currentIndex = 1
  4587. }
  4588. startSize = paging.StartIndex(currentIndex, pageSize)
  4589. var condition string
  4590. var pars []interface{}
  4591. if adminId != "" {
  4592. condition += ` AND c.seller_id IN (` + adminId + `) `
  4593. }
  4594. if startDate != "" {
  4595. condition += ` AND c.start_date>=? `
  4596. pars = append(pars, startDate)
  4597. }
  4598. if endDate != "" {
  4599. condition += ` AND c.end_date>=? `
  4600. pars = append(pars, endDate)
  4601. }
  4602. if keyWord != "" {
  4603. condition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR b.mobile LIKE '%` + keyWord + `%' OR b.email LIKE '%` + keyWord + `%') `
  4604. }
  4605. total, err := company.GetCompanyReceiveListCount(condition, pars, productId, recevieProductId)
  4606. if err != nil {
  4607. br.Msg = "获取失败"
  4608. br.ErrMsg = "获取数据总数失败,Err:" + err.Error()
  4609. return
  4610. }
  4611. list, err := company.GetCompanyReceiveList(condition, pars, productId, recevieProductId, startSize, pageSize)
  4612. if err != nil {
  4613. br.Msg = "获取失败"
  4614. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  4615. return
  4616. }
  4617. lenList := len(list)
  4618. for i := 0; i < lenList; i++ {
  4619. item := list[i]
  4620. var expireDay string
  4621. if item.Status != "" {
  4622. status := item.Status
  4623. if item.EndDate != "" {
  4624. if status == utils.COMPANY_STATUS_FOREVER { //永续
  4625. expireDay = "-"
  4626. } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用/正式
  4627. endDateTime, _ := time.Parse(utils.FormatDate, item.EndDate)
  4628. sub := endDateTime.Sub(time.Now())
  4629. expireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
  4630. } else if status == utils.COMPANY_STATUS_LOSE { //流失
  4631. expireDay = "-"
  4632. } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  4633. if item.StartDate != "" && item.EndDate != "" {
  4634. endDateTime, _ := time.Parse(utils.FormatDate, item.EndDate)
  4635. sub := endDateTime.Sub(time.Now())
  4636. expireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
  4637. } else {
  4638. expireDay = "-"
  4639. }
  4640. } else {
  4641. expireDay = "-"
  4642. }
  4643. }
  4644. }
  4645. list[i].ExpireDay = expireDay
  4646. }
  4647. page := paging.GetPaging(currentIndex, pageSize, total)
  4648. resp := new(company.CompanyReceiveListResp)
  4649. resp.List = list
  4650. resp.Paging = page
  4651. br.Ret = 200
  4652. br.Success = true
  4653. br.Msg = "获取成功"
  4654. br.Data = resp
  4655. }
  4656. // @Title 领取客户
  4657. // @Description 领取客户接口
  4658. // @Param request body company.CompanyReceiveReq true "type json string"
  4659. // @Success Ret=200 领取成功
  4660. // @router /receive [post]
  4661. func (this *CompanyController) Receive() {
  4662. br := new(models.BaseResponse).Init()
  4663. defer func() {
  4664. this.Data["json"] = br
  4665. this.ServeJSON()
  4666. }()
  4667. sysUser := this.SysUser
  4668. if sysUser == nil {
  4669. br.Msg = "请登录"
  4670. br.ErrMsg = "请登录,SysUser Is Empty"
  4671. br.Ret = 408
  4672. return
  4673. }
  4674. var req company.CompanyReceiveReq
  4675. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  4676. if err != nil {
  4677. br.Msg = "参数解析异常!"
  4678. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  4679. return
  4680. }
  4681. if req.CompanyId <= 0 {
  4682. br.Msg = "参数异常!"
  4683. br.ErrMsg = "CompanyId:" + strconv.Itoa(req.CompanyId)
  4684. return
  4685. }
  4686. //权益主观客观权限一块开
  4687. if req.PermissionIds != "" {
  4688. permissionStr, err := company.GetPermissionIdById(req.PermissionIds)
  4689. if err != nil {
  4690. br.Msg = "获取信息失败"
  4691. br.ErrMsg = "获取主观客观权限信息失败,Err:" + err.Error()
  4692. return
  4693. }
  4694. req.PermissionIds = permissionStr
  4695. }
  4696. roleTypeCode := sysUser.RoleTypeCode
  4697. productId := services.GetProductId(roleTypeCode)
  4698. if productId == 0 {
  4699. br.Msg = "参数错误"
  4700. br.ErrMsg = "客户类型为:" + roleTypeCode
  4701. return
  4702. }
  4703. sellsId := 0
  4704. if req.SellsId <= 0 {
  4705. sellsId = sysUser.AdminId
  4706. } else {
  4707. sellsId = req.SellsId
  4708. }
  4709. seller, err := system.GetSysAdminById(sellsId)
  4710. if err != nil {
  4711. br.Msg = "获取销售信息失败"
  4712. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  4713. return
  4714. }
  4715. companyDetail, err := company.GetCompanyDetailById(req.CompanyId)
  4716. if err != nil {
  4717. br.Msg = "获取客户信息失败"
  4718. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  4719. return
  4720. }
  4721. cp, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, productId)
  4722. if err != nil && err.Error() != utils.ErrNoRow() {
  4723. br.Msg = "获取客户信息失败"
  4724. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  4725. return
  4726. }
  4727. productName := ""
  4728. var status string
  4729. if productId == 1 {
  4730. productName = utils.COMPANY_PRODUCT_FICC_NAME
  4731. } else {
  4732. productName = utils.COMPANY_PRODUCT_RAI_NAME
  4733. }
  4734. if productId == utils.COMPANY_PRODUCT_RAI_ID {
  4735. //查询客户的产品权限
  4736. companyReportPermissionListOld, err := company.GetCompanyReportPermission(req.CompanyId, productId)
  4737. if err != nil {
  4738. br.Msg = "查询客户的产品权限异常"
  4739. br.ErrMsg = "查询客户的产品权限异常:" + err.Error()
  4740. return
  4741. }
  4742. var isNoResearch bool
  4743. for _, v := range companyReportPermissionListOld {
  4744. if v.ChartPermissionId != utils.CHART_PERMISSION_ID_YANXUAN && v.ChartPermissionId != utils.YAN_XUAN_KOU_DIAN_BAO_ID {
  4745. isNoResearch = true
  4746. continue
  4747. }
  4748. }
  4749. //如果所选行业不属于研选订阅跟研选扣点包,那就是非研选试用客户
  4750. if isNoResearch {
  4751. tryOutCountRai, err := company.GetRaiCompanyTryOutCountNoResearch(req.SellsId)
  4752. if err != nil {
  4753. br.Msg = "判断试用客户量失败"
  4754. br.ErrMsg = "判断试用客户量失败,Err:" + err.Error()
  4755. return
  4756. }
  4757. if tryOutCountRai >= utils.COMPANY_STATUS_TRY_OUT_COUNT_RAI {
  4758. br.Msg = "非研选试用客户最多40家"
  4759. return
  4760. }
  4761. }
  4762. }
  4763. if cp != nil {
  4764. if cp.Status != utils.COMPANY_STATUS_LOSE {
  4765. br.Msg = "客户状态为:" + cp.Status + ";不可领取"
  4766. br.ErrMsg = "客户状态为:" + cp.Status + ";不可领取"
  4767. return
  4768. }
  4769. if cp.SellerId == sysUser.AdminId {
  4770. br.Msg = "已为自己客户,不可重复领取"
  4771. br.ErrMsg = "已为自己客户,不可领取:company_id:" + strconv.Itoa(cp.CompanyId)
  4772. return
  4773. }
  4774. //转移 销售
  4775. companyReportPermissionList, startDate, endDate, err := company.MoveSeller(req.CompanyId, productId, seller.AdminId, seller.GroupId, seller.DepartmentId, seller.RealName)
  4776. if err != nil {
  4777. br.Msg = "领取失败"
  4778. br.ErrMsg = "领取失败,Err:" + err.Error()
  4779. return
  4780. }
  4781. //新增客户产品状态变更日志
  4782. {
  4783. companyProductUpdateLog := &company.CompanyProductUpdateLog{
  4784. Id: 0,
  4785. CompanyId: req.CompanyId,
  4786. ProductId: productId,
  4787. Status: "试用",
  4788. Source: "receive",
  4789. SellerId: seller.AdminId,
  4790. SellerName: seller.RealName,
  4791. StartDate: startDate,
  4792. EndDate: endDate,
  4793. RealEndDate: startDate,
  4794. CreateTime: time.Now(),
  4795. }
  4796. go company.AddCompanyProductUpdateLog(companyProductUpdateLog)
  4797. companyProductTryOutUpdateLog := &company.CompanyProductTryOutUpdateLog{
  4798. Id: 0,
  4799. CompanyId: req.CompanyId,
  4800. ProductId: productId,
  4801. Source: "receive",
  4802. SellerId: seller.AdminId,
  4803. SellerName: seller.RealName,
  4804. StartDate: startDate,
  4805. EndDate: endDate,
  4806. RealEndDate: startDate,
  4807. IsStop: 0,
  4808. CreateTime: time.Now(),
  4809. }
  4810. go company.AddCompanyProductTryOutUpdateLog(companyProductTryOutUpdateLog, companyReportPermissionList)
  4811. }
  4812. //流失转试用,企业下面的用户自动添加产业关注
  4813. {
  4814. go cygxService.AddUserFllowCompanyLossToTryOut(req.CompanyId)
  4815. }
  4816. } else {
  4817. //跨部门领取
  4818. var startDateTime, endDateTime time.Time
  4819. if req.Status == utils.COMPANY_STATUS_TRY_OUT {
  4820. startDateTime = time.Now()
  4821. endDateTime = time.Now().AddDate(0, 2, 0)
  4822. } else if req.Status == utils.COMPANY_STATUS_FOREVER {
  4823. startDateTime = time.Now()
  4824. endDateTime = time.Now().AddDate(100, 0, 0)
  4825. } else {
  4826. br.Msg = "无效的客户状态,请重新选择"
  4827. return
  4828. }
  4829. var startDate, endDate string
  4830. startDate = startDateTime.Format(utils.FormatDate)
  4831. endDate = endDateTime.Format(utils.FormatDate)
  4832. if req.PermissionIds == "" {
  4833. br.Msg = "请选择权限!"
  4834. return
  4835. }
  4836. industry, err := company.GetCompanyIndustryById(req.IndustryId)
  4837. if err != nil {
  4838. br.Msg = "获取行业信息失败"
  4839. br.ErrMsg = "获取行业信息失败,Err:" + err.Error()
  4840. return
  4841. }
  4842. if industry == nil {
  4843. br.Msg = "行业信息不存在"
  4844. return
  4845. }
  4846. status = req.Status
  4847. companyProduct := new(company.CompanyProduct)
  4848. companyProduct.CompanyId = req.CompanyId
  4849. companyProduct.ProductId = productId
  4850. companyProduct.ProductName = productName
  4851. companyProduct.CompanyName = companyDetail.CompanyName
  4852. companyProduct.Source = req.Source
  4853. companyProduct.Reasons = req.Reasons
  4854. companyProduct.Status = status
  4855. companyProduct.StartDate = startDate
  4856. companyProduct.EndDate = endDate
  4857. companyProduct.IndustryId = req.IndustryId
  4858. companyProduct.IndustryName = industry.IndustryName
  4859. companyProduct.SellerId = seller.AdminId
  4860. companyProduct.SellerName = seller.RealName
  4861. companyProduct.GroupId = seller.GroupId
  4862. companyProduct.DepartmentId = seller.DepartmentId
  4863. companyProduct.IsSuspend = 0
  4864. companyProduct.CreateTime = time.Now()
  4865. companyProduct.ModifyTime = time.Now()
  4866. companyProduct.CompanyType = req.CompanyType
  4867. companyProduct.OpenCode = services.GenerateOpenCompanyProductCode(req.CompanyId, productId)
  4868. companyProduct.TodoStatus = "无任务"
  4869. companyProduct.TryStage = 1
  4870. _, err = company.AddCompanyProduct(companyProduct)
  4871. if err != nil {
  4872. br.Msg = "新增失败"
  4873. br.ErrMsg = "新增客户产品失败,err:" + err.Error()
  4874. return
  4875. }
  4876. companyReportPermissionList, err := services.AddCompanyPermission(req.CompanyId, seller.AdminId, productId, productName, seller.RealName, req.PermissionIds, startDate, endDate)
  4877. if err != nil {
  4878. br.Msg = "新增失败"
  4879. br.ErrMsg = "新增客户设置权限失败,err:" + err.Error()
  4880. return
  4881. }
  4882. //新增客户产品日志
  4883. {
  4884. go services.AddCompanyProductLog(companyProduct, this.SysUser.AdminId, "add")
  4885. }
  4886. //新增客户产品状态变更日志
  4887. {
  4888. companyProductUpdateLog := &company.CompanyProductUpdateLog{
  4889. Id: 0,
  4890. CompanyId: companyProduct.CompanyId,
  4891. ProductId: companyProduct.ProductId,
  4892. Status: "试用",
  4893. SellerId: seller.AdminId,
  4894. SellerName: seller.RealName,
  4895. Source: "add",
  4896. StartDate: startDateTime,
  4897. EndDate: endDateTime,
  4898. RealEndDate: startDateTime,
  4899. CreateTime: time.Now(),
  4900. }
  4901. go company.AddCompanyProductUpdateLog(companyProductUpdateLog)
  4902. companyProductTryOutUpdateLog := &company.CompanyProductTryOutUpdateLog{
  4903. Id: 0,
  4904. CompanyId: companyProduct.CompanyId,
  4905. ProductId: companyProduct.ProductId,
  4906. SellerId: seller.AdminId,
  4907. SellerName: seller.RealName,
  4908. Source: "add",
  4909. StartDate: startDateTime,
  4910. EndDate: endDateTime,
  4911. RealEndDate: startDateTime,
  4912. IsStop: 0,
  4913. CreateTime: time.Now(),
  4914. }
  4915. go company.AddCompanyProductTryOutUpdateLog(companyProductTryOutUpdateLog, companyReportPermissionList)
  4916. }
  4917. //查询当前客户的所有产品的列表数据,并找出非当前产品的销售去发送模板消息
  4918. companyProductList, err := company.GetCompanyProductsByCompanyId(req.CompanyId)
  4919. for _, companyProduct := range companyProductList {
  4920. //如果是当前领取的产品,那么就退出当前循环,进入下一循环
  4921. if companyProduct.ProductId == productId {
  4922. continue
  4923. }
  4924. //查询其他部门销售的信息
  4925. admin, tmpErr := system.GetSysAdminById(companyProduct.SellerId)
  4926. if tmpErr != nil {
  4927. continue
  4928. }
  4929. //发送模板消息给另一个部门的销售
  4930. go services.SendCompanyReceiveWxTemplateMsg(companyDetail.CompanyName, productName, sysUser.RealName, admin.Mobile)
  4931. }
  4932. }
  4933. //新增操作记录
  4934. {
  4935. remark := "领取客户"
  4936. operation := "receive"
  4937. services.AddCompanyOperationRecord(req.CompanyId, seller.AdminId, sysUser.AdminId, productId, sysUser.AdminId, companyDetail.CompanyName,
  4938. productName, sysUser.RealName, remark, operation, "", sysUser.RealName, "", status)
  4939. }
  4940. br.Ret = 200
  4941. br.Success = true
  4942. br.Msg = "领取成功"
  4943. }
  4944. // @Title 移动销售
  4945. // @Description 移动销售接口
  4946. // @Param request body company.MoveSellerReq true "type json string"
  4947. // @Success Ret=200 移动成功
  4948. // @router /move/seller [post]
  4949. func (this *CompanyController) MoveSeller() {
  4950. br := new(models.BaseResponse).Init()
  4951. defer func() {
  4952. this.Data["json"] = br
  4953. this.ServeJSON()
  4954. }()
  4955. sysUser := this.SysUser
  4956. if sysUser == nil {
  4957. br.Msg = "请登录"
  4958. br.ErrMsg = "请登录,SysUser Is Empty"
  4959. br.Ret = 408
  4960. return
  4961. }
  4962. var req company.MoveSellerReq
  4963. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  4964. if err != nil {
  4965. br.Msg = "参数解析异常!"
  4966. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  4967. return
  4968. }
  4969. if req.CompanyId <= 0 {
  4970. br.Msg = "参数异常!"
  4971. br.ErrMsg = "CompanyId:" + strconv.Itoa(req.CompanyId)
  4972. return
  4973. }
  4974. if req.SellsId <= 0 {
  4975. br.Msg = "参数异常!"
  4976. br.ErrMsg = "SellsId:" + strconv.Itoa(req.SellsId)
  4977. return
  4978. }
  4979. seller, err := system.GetSysAdminById(req.SellsId)
  4980. if err != nil {
  4981. br.Msg = "获取销售信息失败"
  4982. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  4983. return
  4984. }
  4985. roleTypeCode := sysUser.RoleTypeCode
  4986. productId := services.GetProductId(roleTypeCode)
  4987. if productId == 0 {
  4988. if req.CompanyType == utils.COMPANY_CLASSIFY_FICC {
  4989. productId = 1
  4990. } else if req.CompanyType == utils.COMPANY_CLASSIFY_RAI {
  4991. productId = 2
  4992. }
  4993. }
  4994. if productId == 0 {
  4995. br.Msg = "无效的客户类型"
  4996. br.ErrMsg = "无效的客户类型"
  4997. return
  4998. }
  4999. if productId == utils.COMPANY_PRODUCT_RAI_ID {
  5000. //查询客户的产品权限
  5001. companyReportPermissionListOld, err := company.GetCompanyReportPermission(req.CompanyId, productId)
  5002. if err != nil {
  5003. br.Msg = "查询客户的产品权限异常"
  5004. br.ErrMsg = "查询客户的产品权限异常:" + err.Error()
  5005. return
  5006. }
  5007. var isNoResearch bool
  5008. for _, v := range companyReportPermissionListOld {
  5009. if v.ChartPermissionId != utils.CHART_PERMISSION_ID_YANXUAN && v.ChartPermissionId != utils.YAN_XUAN_KOU_DIAN_BAO_ID {
  5010. isNoResearch = true
  5011. continue
  5012. }
  5013. }
  5014. //如果所选行业不属于研选订阅跟研选扣点包,那就是非研选试用客户
  5015. if isNoResearch {
  5016. tryOutCountRai, err := company.GetRaiCompanyTryOutCountNoResearch(req.SellsId)
  5017. if err != nil {
  5018. br.Msg = "判断试用客户量失败"
  5019. br.ErrMsg = "判断试用客户量失败,Err:" + err.Error()
  5020. return
  5021. }
  5022. if tryOutCountRai >= utils.COMPANY_STATUS_TRY_OUT_COUNT_RAI {
  5023. br.Msg = seller.RealName + "的非研选试用客户已超过40家"
  5024. return
  5025. }
  5026. }
  5027. }
  5028. cp, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, productId)
  5029. if err != nil && err.Error() != utils.ErrNoRow() {
  5030. if err.Error() == utils.ErrNoRow() {
  5031. br.Msg = "客户信息不存在"
  5032. br.ErrMsg = "客户信息不存在,Err:" + err.Error()
  5033. return
  5034. }
  5035. br.Msg = "获取客户信息失败"
  5036. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  5037. return
  5038. }
  5039. if cp == nil {
  5040. br.Msg = "客户信息不存在,请刷新页面"
  5041. br.ErrMsg = "客户信息不存在"
  5042. return
  5043. }
  5044. err = company.MoveCompanySeller(req.CompanyId, productId, req.SellsId, seller.GroupId, seller.DepartmentId, seller.RealName)
  5045. if err != nil {
  5046. br.Msg = "移动失败"
  5047. br.ErrMsg = "移动失败,Err:" + err.Error()
  5048. return
  5049. }
  5050. //新增操作记录
  5051. {
  5052. remark := "移动到:" + seller.RealName
  5053. operation := "move_seller"
  5054. services.AddCompanyOperationRecord(req.CompanyId, seller.AdminId, sysUser.AdminId, productId, sysUser.AdminId, cp.CompanyName,
  5055. cp.ProductName, sysUser.RealName, remark, operation, "", sysUser.RealName, "", cp.Status)
  5056. }
  5057. //变更销售员与联系人关系
  5058. _ = models.UpdateUserSellerRelationByCompanyId(req.CompanyId, productId, seller.AdminId, seller.RealName)
  5059. br.Ret = 200
  5060. br.Success = true
  5061. br.Msg = "移动成功"
  5062. }
  5063. // @Title 修改试用客户标签
  5064. // @Description 修改试用客户标签接口
  5065. // @Param request body company.UpdateTryStageReq true "type json string"
  5066. // @Success Ret=200 设置成功
  5067. // @router /update/tryStage [post]
  5068. func (this *CompanyController) UpdateTryStage() {
  5069. br := new(models.BaseResponse).Init()
  5070. defer func() {
  5071. this.Data["json"] = br
  5072. this.ServeJSON()
  5073. }()
  5074. sysUser := this.SysUser
  5075. if sysUser == nil {
  5076. br.Msg = "请登录"
  5077. br.ErrMsg = "请登录,SysUser Is Empty"
  5078. br.Ret = 408
  5079. return
  5080. }
  5081. var req company.UpdateTryStageReq
  5082. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  5083. if err != nil {
  5084. br.Msg = "参数解析异常!"
  5085. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  5086. return
  5087. }
  5088. if req.CompanyId <= 0 {
  5089. br.Msg = "参数异常!"
  5090. br.ErrMsg = "CompanyId:" + strconv.Itoa(req.CompanyId)
  5091. return
  5092. }
  5093. if req.ProductId <= 0 {
  5094. br.Msg = "参数异常!"
  5095. br.ErrMsg = "ProductId:" + strconv.Itoa(req.ProductId)
  5096. return
  5097. }
  5098. if req.TryStage <= 0 {
  5099. br.Msg = "参数异常!"
  5100. br.ErrMsg = "TryStage:" + strconv.Itoa(req.TryStage)
  5101. return
  5102. }
  5103. cp, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, req.ProductId)
  5104. if err != nil && err.Error() != utils.ErrNoRow() {
  5105. if err.Error() == utils.ErrNoRow() {
  5106. br.Msg = "客户信息不存在"
  5107. br.ErrMsg = "客户信息不存在,Err:" + err.Error()
  5108. return
  5109. }
  5110. br.Msg = "获取客户信息失败"
  5111. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  5112. return
  5113. }
  5114. fmt.Println(cp)
  5115. if cp == nil {
  5116. br.Msg = "客户信息不存在,请刷新页面"
  5117. br.ErrMsg = "客户信息不存在"
  5118. return
  5119. }
  5120. if cp.Status != "试用" {
  5121. br.Msg = "客户不是试用状态,不允许修改"
  5122. br.ErrMsg = "客户不是试用状态,不允许修改"
  5123. return
  5124. }
  5125. if cp.SellerId != sysUser.AdminId {
  5126. br.Msg = "无修改权限"
  5127. br.ErrMsg = "无修改权限"
  5128. return
  5129. }
  5130. if cp.TryStage == req.TryStage {
  5131. br.Msg = "与原标签一致,无需修改"
  5132. br.ErrMsg = "与原标签一致,无需修改"
  5133. return
  5134. }
  5135. err = company.UpdateCompanyTryStage(req.CompanyId, req.ProductId, req.TryStage)
  5136. if err != nil {
  5137. br.Msg = "设置失败"
  5138. br.ErrMsg = "设置失败,Err:" + err.Error()
  5139. return
  5140. }
  5141. //新增操作记录
  5142. {
  5143. stage := ""
  5144. tryStageAllMap := map[int]string{
  5145. 1: "未分类",
  5146. 2: "推进",
  5147. 3: "跟踪",
  5148. 4: "预备",
  5149. }
  5150. if v, ok := tryStageAllMap[req.TryStage]; ok {
  5151. stage = v
  5152. }
  5153. remark := "修改试用客户子标签:" + stage
  5154. operation := "UpdateTryStage"
  5155. services.AddCompanyOperationRecord(req.CompanyId, cp.SellerId, sysUser.AdminId, req.ProductId, sysUser.AdminId, cp.CompanyName,
  5156. cp.ProductName, sysUser.RealName, remark, operation, "", sysUser.RealName, "", cp.Status)
  5157. }
  5158. br.Ret = 200
  5159. br.Success = true
  5160. br.Msg = "设置成功"
  5161. }
  5162. // @Title 暂停/启用
  5163. // @Description 暂停/启用接口
  5164. // @Param request body company.SuspendReq true "type json string"
  5165. // @Success Ret=200 移动成功
  5166. // @router /suspend [post]
  5167. func (this *CompanyController) Suspend() {
  5168. br := new(models.BaseResponse).Init()
  5169. defer func() {
  5170. this.Data["json"] = br
  5171. this.ServeJSON()
  5172. }()
  5173. sysUser := this.SysUser
  5174. if sysUser == nil {
  5175. br.Msg = "请登录"
  5176. br.ErrMsg = "请登录,SysUser Is Empty"
  5177. br.Ret = 408
  5178. return
  5179. }
  5180. var req company.SuspendReq
  5181. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  5182. if err != nil {
  5183. br.Msg = "参数解析异常!"
  5184. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  5185. return
  5186. }
  5187. if req.CompanyId <= 0 {
  5188. br.Msg = "参数异常!"
  5189. br.ErrMsg = "CompanyId:" + strconv.Itoa(req.CompanyId)
  5190. return
  5191. }
  5192. roleTypeCode := sysUser.RoleTypeCode
  5193. productId := services.GetProductId(roleTypeCode)
  5194. if productId == 0 {
  5195. br.Msg = "参数错误"
  5196. br.ErrMsg = "角色类型为:" + roleTypeCode
  5197. return
  5198. }
  5199. cp, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, productId)
  5200. if err != nil {
  5201. br.Msg = "获取数据异常!"
  5202. br.ErrMsg = "获取数据异常:" + err.Error()
  5203. return
  5204. }
  5205. suspendStatus := ""
  5206. suspend := 0
  5207. if cp.IsSuspend == 1 {
  5208. suspendStatus = "启用"
  5209. suspend = 0
  5210. } else {
  5211. suspendStatus = "暂停"
  5212. suspend = 1
  5213. }
  5214. if cp.Status != utils.COMPANY_STATUS_TRY_OUT {
  5215. br.Msg = "客户状态为:" + cp.Status + ",不允许进行" + suspendStatus + "操作"
  5216. br.ErrMsg = "客户状态为:" + cp.Status + ",不允许进行" + suspendStatus + "操作"
  5217. return
  5218. }
  5219. err = company.SuspendCompanyProductById(req.CompanyId, productId, suspend)
  5220. if err != nil {
  5221. br.Msg = suspendStatus + "失败"
  5222. br.ErrMsg = suspendStatus + "失败 Err:" + err.Error()
  5223. return
  5224. }
  5225. //新增操作记录
  5226. {
  5227. remark := suspendStatus
  5228. operation := "is_suspend"
  5229. services.AddCompanyOperationRecord(req.CompanyId, cp.SellerId, sysUser.AdminId, productId, sysUser.AdminId, cp.CompanyName,
  5230. cp.ProductName, sysUser.RealName, remark, operation, "", sysUser.RealName, "", cp.Status)
  5231. }
  5232. br.Ret = 200
  5233. br.Success = true
  5234. br.Msg = suspendStatus + "成功"
  5235. }
  5236. // @Title 检测客户名称或社会信用码
  5237. // @Description 检测客户名称或社会信用码接口(新增/编辑客户页面使用)
  5238. // @Param CompanyName query string true "客户名称"
  5239. // @Param CreditCode query string true "社会统一信用码"
  5240. // @Success 200 {object} company.CheckCompanyInfoResp
  5241. // @router /check/companyInfo [get]
  5242. func (this *CompanyController) CheckCompanyInfo() {
  5243. br := new(models.BaseResponse).Init()
  5244. defer func() {
  5245. this.Data["json"] = br
  5246. this.ServeJSON()
  5247. }()
  5248. sysUser := this.SysUser
  5249. if sysUser == nil {
  5250. br.Msg = "请登录"
  5251. br.ErrMsg = "请登录,SysUser Is Empty"
  5252. br.Ret = 408
  5253. return
  5254. }
  5255. roleTypeCode := sysUser.RoleTypeCode
  5256. productId := services.GetProductId(roleTypeCode)
  5257. companyName := this.GetString("CompanyName")
  5258. creditCode := this.GetString("CreditCode")
  5259. var status, comanyId int
  5260. var productName string
  5261. if productId == 0 {
  5262. productId = 1
  5263. checkProductId := 2
  5264. if companyName != "" {
  5265. nameItem, err := company.CheckCompanyProductByName(companyName, productId)
  5266. if err != nil && err.Error() != utils.ErrNoRow() {
  5267. br.Msg = "校验客户名称是否存在失败"
  5268. br.ErrMsg = "校验客户名称是否存在失败,Err:" + err.Error()
  5269. return
  5270. }
  5271. if nameItem != nil && nameItem.CompanyId > 0 {
  5272. br.Msg = "客户名称已存在,请重新填写"
  5273. br.ErrMsg = "客户名称已存在,请重新填写"
  5274. br.Ret = 405
  5275. return
  5276. }
  5277. nameCheckItem, err := company.CheckCompanyProductByName(companyName, checkProductId)
  5278. if err != nil && err.Error() != utils.ErrNoRow() {
  5279. br.Msg = "校验客户名称是否存在失败"
  5280. br.ErrMsg = "校验客户名称是否存在失败,Err:" + err.Error() + " productId:" + strconv.Itoa(productId) + ";checkProductId:" + strconv.Itoa(checkProductId)
  5281. return
  5282. }
  5283. if nameCheckItem != nil && nameCheckItem.CompanyId > 0 {
  5284. status = 1
  5285. productName = nameCheckItem.ProductName
  5286. comanyId = nameCheckItem.CompanyId
  5287. goto Loop
  5288. }
  5289. }
  5290. if creditCode != "" {
  5291. codeItem, err := company.CheckCompanyProductByCreditCode(creditCode, productId)
  5292. if err != nil && err.Error() != utils.ErrNoRow() {
  5293. br.Msg = "校验社会信用码是否存在失败"
  5294. br.ErrMsg = "校验社会信用码是否存在失败,Err:" + err.Error()
  5295. return
  5296. }
  5297. if codeItem != nil && codeItem.CompanyId > 0 {
  5298. br.Msg = "社会信用码已存在,请重新填写"
  5299. br.ErrMsg = "社会信用码已存在,请重新填写"
  5300. br.Ret = 405
  5301. return
  5302. }
  5303. codeCheckItem, err := company.CheckCompanyProductByCreditCode(creditCode, checkProductId)
  5304. if err != nil && err.Error() != utils.ErrNoRow() {
  5305. br.Msg = "校验社会信用码是否存在失败"
  5306. br.ErrMsg = "校验社会信用码是否存在失败,Err:" + err.Error() + " productId:" + strconv.Itoa(productId) + ";checkProductId:" + strconv.Itoa(checkProductId)
  5307. return
  5308. }
  5309. if codeCheckItem != nil && codeCheckItem.CompanyId > 0 {
  5310. status = 1
  5311. productName = codeCheckItem.ProductName
  5312. comanyId = codeCheckItem.CompanyId
  5313. goto Loop
  5314. }
  5315. }
  5316. productId = 2
  5317. checkProductId = 1
  5318. if companyName != "" {
  5319. nameItem, err := company.CheckCompanyProductByName(companyName, productId)
  5320. if err != nil && err.Error() != utils.ErrNoRow() {
  5321. br.Msg = "校验客户名称是否存在失败"
  5322. br.ErrMsg = "校验客户名称是否存在失败,Err:" + err.Error()
  5323. return
  5324. }
  5325. if nameItem != nil && nameItem.CompanyId > 0 {
  5326. br.Msg = "客户名称已存在,请重新填写"
  5327. br.ErrMsg = "客户名称已存在,请重新填写"
  5328. br.Ret = 405
  5329. return
  5330. }
  5331. nameCheckItem, err := company.CheckCompanyProductByName(companyName, checkProductId)
  5332. if err != nil && err.Error() != utils.ErrNoRow() {
  5333. br.Msg = "校验客户名称是否存在失败"
  5334. br.ErrMsg = "校验客户名称是否存在失败,Err:" + err.Error() + " productId:" + strconv.Itoa(productId) + ";checkProductId:" + strconv.Itoa(checkProductId)
  5335. return
  5336. }
  5337. if nameCheckItem != nil && nameCheckItem.CompanyId > 0 {
  5338. status = 1
  5339. productName = nameCheckItem.ProductName
  5340. comanyId = nameCheckItem.CompanyId
  5341. goto Loop
  5342. }
  5343. }
  5344. if creditCode != "" {
  5345. codeItem, err := company.CheckCompanyProductByCreditCode(creditCode, productId)
  5346. if err != nil && err.Error() != utils.ErrNoRow() {
  5347. br.Msg = "校验社会信用码是否存在失败"
  5348. br.ErrMsg = "校验社会信用码是否存在失败,Err:" + err.Error()
  5349. return
  5350. }
  5351. if codeItem != nil && codeItem.CompanyId > 0 {
  5352. br.Msg = "社会信用码已存在,请重新填写"
  5353. br.ErrMsg = "社会信用码已存在,请重新填写"
  5354. br.Ret = 405
  5355. return
  5356. }
  5357. codeCheckItem, err := company.CheckCompanyProductByCreditCode(creditCode, checkProductId)
  5358. if err != nil && err.Error() != utils.ErrNoRow() {
  5359. br.Msg = "校验社会信用码是否存在失败"
  5360. br.ErrMsg = "校验社会信用码是否存在失败,Err:" + err.Error() + " productId:" + strconv.Itoa(productId) + ";checkProductId:" + strconv.Itoa(checkProductId)
  5361. return
  5362. }
  5363. if codeCheckItem != nil && codeCheckItem.CompanyId > 0 {
  5364. status = 1
  5365. productName = codeCheckItem.ProductName
  5366. comanyId = codeCheckItem.CompanyId
  5367. goto Loop
  5368. }
  5369. }
  5370. } else {
  5371. checkProductId := 0
  5372. if productId == 1 {
  5373. checkProductId = 2
  5374. } else if productId == 2 {
  5375. checkProductId = 1
  5376. }
  5377. if companyName != "" {
  5378. nameItem, err := company.CheckCompanyProductByName(companyName, productId)
  5379. if err != nil && err.Error() != utils.ErrNoRow() {
  5380. br.Msg = "校验客户名称是否存在失败"
  5381. br.ErrMsg = "校验客户名称是否存在失败,Err:" + err.Error()
  5382. return
  5383. }
  5384. if nameItem != nil && nameItem.ProductName != "" {
  5385. br.Msg = "客户名称已存在,请重新填写"
  5386. br.ErrMsg = "客户名称已存在,请重新填写"
  5387. br.Ret = 405
  5388. return
  5389. }
  5390. nameCheckoutItem, err := company.CheckCompanyProductByName(companyName, checkProductId)
  5391. if err != nil && err.Error() != utils.ErrNoRow() {
  5392. br.Msg = "校验客户名称是否存在失败"
  5393. br.ErrMsg = "校验客户名称是否存在失败,Err:" + err.Error() + " productId:" + strconv.Itoa(productId) + ";checkProductId:" + strconv.Itoa(checkProductId)
  5394. return
  5395. }
  5396. if nameCheckoutItem != nil && nameCheckoutItem.CompanyId > 0 {
  5397. status = 1
  5398. productName = nameCheckoutItem.ProductName
  5399. comanyId = nameCheckoutItem.CompanyId
  5400. goto Loop
  5401. }
  5402. }
  5403. if creditCode != "" {
  5404. codeItem, err := company.CheckCompanyProductByCreditCode(creditCode, productId)
  5405. if err != nil && err.Error() != utils.ErrNoRow() {
  5406. br.Msg = "校验社会信用码是否存在失败"
  5407. br.ErrMsg = "校验社会信用码是否存在失败,Err:" + err.Error()
  5408. return
  5409. }
  5410. if codeItem != nil && codeItem.CompanyId > 0 {
  5411. br.Msg = "社会信用码已存在,请重新填写"
  5412. br.ErrMsg = "社会信用码已存在,请重新填写"
  5413. br.Ret = 405
  5414. return
  5415. }
  5416. codeCheckItem, err := company.CheckCompanyProductByCreditCode(creditCode, checkProductId)
  5417. if err != nil && err.Error() != utils.ErrNoRow() {
  5418. br.Msg = "校验社会信用码是否存在失败"
  5419. br.ErrMsg = "校验社会信用码是否存在失败,Err:" + err.Error() + " productId:" + strconv.Itoa(productId) + ";checkProductId:" + strconv.Itoa(checkProductId)
  5420. return
  5421. }
  5422. if codeCheckItem != nil && codeCheckItem.CompanyId > 0 {
  5423. status = 1
  5424. productName = codeCheckItem.ProductName
  5425. comanyId = codeCheckItem.CompanyId
  5426. goto Loop
  5427. }
  5428. }
  5429. }
  5430. Loop:
  5431. resp := new(company.CheckCompanyInfoResp)
  5432. resp.Status = status
  5433. resp.ProductName = productName
  5434. resp.CompanyId = comanyId
  5435. br.Ret = 200
  5436. br.Success = true
  5437. br.Msg = "获取成功"
  5438. br.Data = resp
  5439. }
  5440. // @Title 客户导出
  5441. // @Description 客户导出接口
  5442. // @Param Status query string true "状态:'试用','永续','冻结','流失','正式'"
  5443. // @Param CompanyType query string true "客户类型:传空字符串或者不传为全部,'ficc','权益'"
  5444. // @Param IndustryId query int true "行业id,0为全部"
  5445. // @Param AdminId query string true "销售id,多个用英文逗号隔开,空字符串为全部"
  5446. // @Param ChartPermissionIds query string false "阅读权限品种ID,多个用英文逗号分开,空字符串为全部"
  5447. // @Param ContractPermissionIds query string false "已购品种ID,多个用英文逗号分开,空字符串为全部"
  5448. // @Param StartDate query string true "开始时间"
  5449. // @Param EndDate query string true "结束时间"
  5450. // @Param CreateStartDate query string true "创建开始时间"
  5451. // @Param CreateEndDate query string true "创建结束时间"
  5452. // @Param KeyWord query string true "搜索关键词"
  5453. // @Param Address query string true "地址 , 多个用英文逗号分开 "
  5454. // @Param Province query string true "省 , 多个用英文逗号分开 "
  5455. // @Param City query string true "市 , 多个用英文逗号分开 "
  5456. // @Param PackageType query int true "套餐类型,0:无,1:大套餐,2:小套餐"
  5457. // @Success 200 {object} company.CompanyListResp
  5458. // @router /export [get]
  5459. func (this *CompanyController) Export() {
  5460. br := new(models.BaseResponse).Init()
  5461. defer func() {
  5462. this.Data["json"] = br
  5463. this.ServeJSON()
  5464. }()
  5465. sysUser := this.SysUser
  5466. if sysUser == nil {
  5467. br.Msg = "请登录"
  5468. br.ErrMsg = "请登录,SysUser Is Empty"
  5469. br.Ret = 408
  5470. return
  5471. }
  5472. roleTypeCode := sysUser.RoleTypeCode
  5473. status := this.GetString("Status")
  5474. companyType := this.GetString("CompanyType")
  5475. industryId, _ := this.GetInt("IndustryId")
  5476. adminId := this.GetString("AdminId")
  5477. chartPermissionIds := this.GetString("ChartPermissionIds")
  5478. contractPermissionIds := this.GetString("ContractPermissionIds")
  5479. startDate := this.GetString("StartDate")
  5480. endDate := this.GetString("EndDate")
  5481. createStartDate := this.GetString("CreateStartDate")
  5482. createEndDate := this.GetString("CreateEndDate")
  5483. keyWord := this.GetString("KeyWord")
  5484. keyWord = strings.Trim(keyWord, " ")
  5485. address := this.GetString("Address")
  5486. province := this.GetString("Province")
  5487. city := this.GetString("City")
  5488. // 套餐类型
  5489. packageType, _ := this.GetInt("PackageType")
  5490. resp := new(company.CompanyListResp)
  5491. statusItems := make([]*company.CompanyStatus, 0)
  5492. var statusArr = [...]string{"全部", "试用", "正式", "冻结", "流失", "永续"}
  5493. var condition string
  5494. var pars []interface{}
  5495. //状态分类查询条件
  5496. var permissionCondition string
  5497. var permissionPars []interface{}
  5498. if companyType != "" {
  5499. condition += ` AND b.product_name=? `
  5500. pars = append(pars, companyType)
  5501. }
  5502. if industryId > 0 {
  5503. condition += ` AND b.industry_id=? `
  5504. pars = append(pars, industryId)
  5505. }
  5506. if adminId != "" {
  5507. condition += ` AND b.seller_id IN (` + adminId + `) `
  5508. }
  5509. if startDate != "" {
  5510. condition += ` AND b.start_date>=? `
  5511. pars = append(pars, startDate)
  5512. }
  5513. if endDate != "" {
  5514. condition += ` AND b.end_date<=? `
  5515. pars = append(pars, endDate)
  5516. }
  5517. if createStartDate != "" {
  5518. condition += ` AND a.created_time>=? `
  5519. pars = append(pars, createStartDate)
  5520. }
  5521. if createEndDate != "" {
  5522. condition += ` AND a.created_time<=? `
  5523. pars = append(pars, createEndDate)
  5524. }
  5525. if address != "" {
  5526. var addressSql string
  5527. slice := strings.Split(address, ",")
  5528. for _, v := range slice {
  5529. addressSql += "'" + v + "'" + ","
  5530. }
  5531. addressSql = strings.TrimRight(addressSql, ",")
  5532. condition += ` AND a.address IN (` + addressSql + `) `
  5533. }
  5534. if province != "" {
  5535. var provinceSql string
  5536. slice := strings.Split(province, ",")
  5537. for _, v := range slice {
  5538. provinceSql += "'" + v + "'" + ","
  5539. }
  5540. provinceSql = strings.TrimRight(provinceSql, ",")
  5541. condition += ` AND a.province IN (` + provinceSql + `) `
  5542. }
  5543. if city != "" {
  5544. var citySql string
  5545. slice := strings.Split(city, ",")
  5546. for _, v := range slice {
  5547. citySql += "'" + v + "'" + ","
  5548. }
  5549. citySql = strings.TrimRight(citySql, ",")
  5550. condition += ` AND a.city IN (` + citySql + `) `
  5551. }
  5552. if keyWord != "" {
  5553. companyIdStr, err := company.GetCompanyIdByKeyWord(keyWord)
  5554. if err != nil {
  5555. br.Msg = "获取客户信息失败"
  5556. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  5557. return
  5558. }
  5559. if companyIdStr != "" {
  5560. condition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.company_id IN(` + companyIdStr + `)) `
  5561. } else {
  5562. condition += ` AND (a.company_name LIKE '%` + keyWord + `%' ) `
  5563. }
  5564. }
  5565. //if chartPermissionIds != "" && chartPermissionIds != "1" {
  5566. // companyIdStr, err := company.GetCompanyListCompanyIdByPermissionIdStr(chartPermissionIds)
  5567. // if err != nil {
  5568. // br.Msg = "获取失败"
  5569. // br.ErrMsg = "根据权限获取公司ID失败,Err:" + err.Error()
  5570. // return
  5571. // }
  5572. // if companyIdStr != "" {
  5573. // condition += ` AND a.company_id IN (` + companyIdStr + `) `
  5574. // } else {
  5575. // for _, v := range statusArr {
  5576. // statusCount := new(company.CompanyStatus)
  5577. // if v == "全部" {
  5578. // statusCount.Status = "全部"
  5579. // statusCount.Count = 0
  5580. // } else {
  5581. // statusCount.Status = v
  5582. // statusCount.Count = 0
  5583. // }
  5584. // statusItems = append(statusItems, statusCount)
  5585. // }
  5586. // items := make([]*company.CompanyListItem, 0)
  5587. // resp.List = items
  5588. // resp.StatusCount = statusItems
  5589. // br.Msg = "获取成功"
  5590. // br.Ret = 200
  5591. // br.Data = resp
  5592. // return
  5593. // }
  5594. //}
  5595. // 阅读权限/已购品种筛选
  5596. cond, emp, e := services.FilterReadAndContractAuth(chartPermissionIds, contractPermissionIds, condition)
  5597. if e != nil {
  5598. br.Msg = "获取失败"
  5599. br.ErrMsg = "FilterReadAndContractAuth err: " + e.Error()
  5600. return
  5601. }
  5602. if emp {
  5603. for _, v := range statusArr {
  5604. statusCount := new(company.CompanyStatus)
  5605. if v == "全部" {
  5606. statusCount.Status = "全部"
  5607. statusCount.Count = 0
  5608. } else {
  5609. statusCount.Status = v
  5610. statusCount.Count = 0
  5611. }
  5612. statusItems = append(statusItems, statusCount)
  5613. }
  5614. items := make([]*company.CompanyListItem, 0)
  5615. resp.List = items
  5616. resp.StatusCount = statusItems
  5617. br.Msg = "获取成功"
  5618. br.Ret = 200
  5619. br.Data = resp
  5620. return
  5621. }
  5622. condition = cond
  5623. //套餐类型
  5624. if packageType > 0 {
  5625. condition += ` AND b.package_type=? `
  5626. pars = append(pars, packageType)
  5627. }
  5628. permissionCondition = condition
  5629. permissionPars = pars
  5630. productId := services.GetProductId(roleTypeCode)
  5631. //权限控制
  5632. {
  5633. //如果不是超级管理员
  5634. if roleTypeCode != utils.ROLE_TYPE_CODE_ADMIN {
  5635. //如果是部门管理员
  5636. if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  5637. condition += ` AND b.product_id=? `
  5638. pars = append(pars, productId)
  5639. permissionCondition += ` AND b.product_id=? `
  5640. permissionPars = append(permissionPars, productId)
  5641. } else {
  5642. condition += ` AND b.product_id=? `
  5643. pars = append(pars, productId)
  5644. permissionCondition += ` AND b.product_id=? `
  5645. permissionPars = append(permissionPars, productId)
  5646. if status == "全部" {
  5647. ////如果是筛选了流失客户状态
  5648. if sysUser.Authority <= 0 {
  5649. condition += ` AND (b.seller_id=? OR status='流失') `
  5650. pars = append(pars, sysUser.AdminId)
  5651. permissionCondition += ` AND b.seller_id=? `
  5652. permissionPars = append(permissionPars, sysUser.AdminId)
  5653. } else {
  5654. if sysUser.Authority == 1 {
  5655. condition += ` AND (b.department_id=? OR status='流失')`
  5656. pars = append(pars, sysUser.DepartmentId)
  5657. permissionCondition += ` AND b.department_id=? `
  5658. permissionPars = append(permissionPars, sysUser.DepartmentId)
  5659. }
  5660. if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  5661. if status != utils.COMPANY_STATUS_LOSE {
  5662. condition += ` AND (b.group_id=? OR status='流失') `
  5663. pars = append(pars, sysUser.GroupId)
  5664. }
  5665. permissionCondition += ` AND b.group_id=? `
  5666. permissionPars = append(permissionPars, sysUser.GroupId)
  5667. }
  5668. if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
  5669. pid, err := company.GetParentIdFromGroup(sysUser.GroupId)
  5670. if err != nil {
  5671. br.Msg = "获取失败"
  5672. br.ErrMsg = "查询父级id异常" + err.Error()
  5673. return
  5674. }
  5675. var ids []*string
  5676. if pid != nil && *pid != 0 {
  5677. ids, err = company.GetGroupIdsByParentId(*pid)
  5678. if err != nil {
  5679. fmt.Println(err.Error())
  5680. }
  5681. } else {
  5682. ids, err = company.GetGroupIdsByParentId(sysUser.GroupId)
  5683. if err != nil {
  5684. fmt.Println(err.Error())
  5685. }
  5686. }
  5687. var idSlice []string
  5688. var sid string
  5689. for _, id := range ids {
  5690. idSlice = append(idSlice, *id)
  5691. }
  5692. //加入父级groupId
  5693. if *pid > 0 {
  5694. idSlice = append(idSlice, strconv.Itoa(*pid))
  5695. } else {
  5696. idSlice = append(idSlice, strconv.Itoa(sysUser.GroupId))
  5697. }
  5698. sid = strings.Join(idSlice, ",")
  5699. if len(sid) > 0 {
  5700. if status != utils.COMPANY_STATUS_LOSE {
  5701. condition += ` AND (b.group_id IN (` + sid + `) OR status='流失') `
  5702. //pars = append(pars, sysUser.GroupId)
  5703. }
  5704. permissionCondition += ` AND b.group_id IN (` + sid + `) `
  5705. } else {
  5706. if status != utils.COMPANY_STATUS_LOSE {
  5707. condition += ` AND (b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) OR status='流失') `
  5708. //pars = append(pars, sysUser.GroupId)
  5709. }
  5710. permissionCondition += ` AND b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) `
  5711. }
  5712. }
  5713. }
  5714. } else {
  5715. ////如果没有筛选了流失客户状态
  5716. if sysUser.Authority <= 0 {
  5717. condition += ` AND b.seller_id=? `
  5718. pars = append(pars, sysUser.AdminId)
  5719. permissionCondition += ` AND b.seller_id=? `
  5720. permissionPars = append(permissionPars, sysUser.AdminId)
  5721. } else {
  5722. if sysUser.Authority == 1 {
  5723. condition += ` AND b.department_id=?`
  5724. pars = append(pars, sysUser.DepartmentId)
  5725. permissionCondition += ` AND b.department_id=? `
  5726. permissionPars = append(permissionPars, sysUser.DepartmentId)
  5727. }
  5728. if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  5729. if status != utils.COMPANY_STATUS_LOSE {
  5730. condition += ` AND b.group_id=? `
  5731. pars = append(pars, sysUser.GroupId)
  5732. }
  5733. permissionCondition += ` AND b.group_id=? `
  5734. permissionPars = append(permissionPars, sysUser.GroupId)
  5735. }
  5736. if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
  5737. pid, err := company.GetParentIdFromGroup(sysUser.GroupId)
  5738. if err != nil {
  5739. br.Msg = "获取失败"
  5740. br.ErrMsg = "查询父级id异常" + err.Error()
  5741. return
  5742. }
  5743. var ids []*string
  5744. if pid != nil && *pid != 0 {
  5745. ids, err = company.GetGroupIdsByParentId(*pid)
  5746. if err != nil {
  5747. fmt.Println(err.Error())
  5748. }
  5749. } else {
  5750. ids, err = company.GetGroupIdsByParentId(sysUser.GroupId)
  5751. if err != nil {
  5752. fmt.Println(err.Error())
  5753. }
  5754. }
  5755. var idSlice []string
  5756. var sid string
  5757. for _, id := range ids {
  5758. idSlice = append(idSlice, *id)
  5759. }
  5760. //加入父级groupId
  5761. if *pid > 0 {
  5762. idSlice = append(idSlice, strconv.Itoa(*pid))
  5763. } else {
  5764. idSlice = append(idSlice, strconv.Itoa(sysUser.GroupId))
  5765. }
  5766. sid = strings.Join(idSlice, ",")
  5767. if len(sid) > 0 {
  5768. if status != utils.COMPANY_STATUS_LOSE {
  5769. condition += ` AND (b.group_id IN (` + sid + `) OR status='流失') `
  5770. //pars = append(pars, sysUser.GroupId)
  5771. }
  5772. permissionCondition += ` AND b.group_id IN (` + sid + `) `
  5773. } else {
  5774. if status != utils.COMPANY_STATUS_LOSE {
  5775. condition += ` AND (b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) OR status='流失') `
  5776. //pars = append(pars, sysUser.GroupId)
  5777. }
  5778. permissionCondition += ` AND b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) `
  5779. }
  5780. }
  5781. if sysUser.Authority == 4 {
  5782. if status != utils.COMPANY_STATUS_LOSE {
  5783. condition += ` AND b.group_id =? `
  5784. pars = append(pars, sysUser.GroupId)
  5785. }
  5786. permissionCondition += ` AND b.group_id=? `
  5787. permissionPars = append(permissionPars, sysUser.GroupId)
  5788. }
  5789. }
  5790. }
  5791. }
  5792. }
  5793. }
  5794. //状态控制
  5795. if status != "" && status != "全部" && status != utils.COMPANY_STATUS_LOSE {
  5796. condition += ` AND b.status=? `
  5797. pars = append(pars, status)
  5798. }
  5799. dir, err := os.Executable()
  5800. exPath := filepath.Dir(dir)
  5801. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  5802. xlsxFile := xlsx.NewFile()
  5803. if err != nil {
  5804. br.Msg = "生成文件失败"
  5805. br.ErrMsg = "生成文件失败"
  5806. return
  5807. }
  5808. style := xlsx.NewStyle()
  5809. alignment := xlsx.Alignment{
  5810. Horizontal: "center",
  5811. Vertical: "center",
  5812. WrapText: true,
  5813. }
  5814. style.Alignment = alignment
  5815. style.ApplyAlignment = true
  5816. sheel, err := xlsxFile.AddSheet("客户数据")
  5817. if err != nil {
  5818. br.Msg = "新增Sheet失败"
  5819. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  5820. return
  5821. }
  5822. titleArr := []string{"客户名称", "客户地址", "客户类型", "所属行业", "所属销售", "客户状态", "服务期限", "到期天数", "创建时间", "权限详情"}
  5823. titleLen := len(titleArr)
  5824. titleRow := sheel.AddRow()
  5825. remarkRow := sheel.AddRow() // 备注行
  5826. // 填充空白至Z列
  5827. emptyColNum := 0
  5828. for i := 0; i < 26; i++ {
  5829. remarkRow.AddCell().SetValue("")
  5830. if i >= titleLen {
  5831. emptyColNum += 1
  5832. titleRow.AddCell().SetValue("")
  5833. continue
  5834. }
  5835. titleRow.AddCell().SetValue(titleArr[i])
  5836. }
  5837. // AA列开始为品种权限
  5838. ficcPermissions := make([]int, 0) // 用于后续判断试用暂停客户是否需要暂停这部分权限
  5839. raiPermissions := make([]int, 0)
  5840. permissions, e := models.GetChartPermissionList()
  5841. if e != nil {
  5842. br.Msg = "获取失败"
  5843. br.ErrMsg = "获取品种数据失败,Err:" + err.Error()
  5844. return
  5845. }
  5846. raiArr := []string{"医药", "消费", "科技", "智造"}
  5847. for _, p := range permissions {
  5848. if p.ProductId == 1 {
  5849. ficcPermissions = append(ficcPermissions, p.ChartPermissionId)
  5850. }
  5851. if p.ProductId == 2 {
  5852. raiPermissions = append(raiPermissions, p.ChartPermissionId)
  5853. }
  5854. if utils.InArrayByStr(raiArr, p.PermissionName) {
  5855. titleRow.AddCell().SetValue(p.Remark)
  5856. continue
  5857. }
  5858. titleRow.AddCell().SetValue(p.PermissionName)
  5859. }
  5860. // 第二行, 在品种权限开始列加一行标红备注
  5861. styleRed := xlsx.NewStyle()
  5862. styleRed.Font.Color = "ff0000"
  5863. remarkCell := remarkRow.AddCell()
  5864. remarkCell.SetStyle(styleRed)
  5865. remarkCell.SetString(`第一位数字表示是否已购买该品种,1表示已购,0表示未购;第二位数字表示是否有阅读权限,1表示有权限,0表示没有`)
  5866. list, err := company.GetCompanyListExport(condition, pars)
  5867. if err != nil {
  5868. br.Msg = "获取失败"
  5869. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  5870. return
  5871. }
  5872. companyIds := make([]int, 0)
  5873. for _, c := range list {
  5874. companyIds = append(companyIds, c.CompanyId)
  5875. }
  5876. // 获取客户对应的阅读和合同权限集合
  5877. contractPermissionMap := make(map[int][]int)
  5878. contractPermissions, e := company.GetContractPermissionIdsByCompanyIds(companyIds)
  5879. if e != nil {
  5880. br.Msg = "获取失败"
  5881. br.ErrMsg = "获取已购权限失败, Err: " + e.Error()
  5882. return
  5883. }
  5884. for _, p := range contractPermissions {
  5885. ids := make([]int, 0)
  5886. if p.ChartPermissionIds != "" {
  5887. idArr := strings.Split(p.ChartPermissionIds, ",")
  5888. for _, i := range idArr {
  5889. id, _ := strconv.Atoi(i)
  5890. ids = append(ids, id)
  5891. }
  5892. }
  5893. contractPermissionMap[p.CompanyId] = ids
  5894. }
  5895. reportPermissionMap := make(map[int][]int)
  5896. reportPermissions, e := company.GetReportPermissionIdsByCompanyIds(companyIds)
  5897. if e != nil {
  5898. br.Msg = "获取失败"
  5899. br.ErrMsg = "获取阅读权限失败, Err: " + e.Error()
  5900. return
  5901. }
  5902. for _, p := range reportPermissions {
  5903. ids := make([]int, 0)
  5904. if p.ChartPermissionIds != "" {
  5905. idArr := strings.Split(p.ChartPermissionIds, ",")
  5906. for _, i := range idArr {
  5907. id, _ := strconv.Atoi(i)
  5908. ids = append(ids, id)
  5909. }
  5910. }
  5911. reportPermissionMap[p.CompanyId] = ids
  5912. }
  5913. cpMap := make(map[int][]*company.ExportCompanyProduct)
  5914. permissionMap := make(map[string]string)
  5915. for _, v := range list {
  5916. cpList := make([]*company.ExportCompanyProduct, 1)
  5917. if cps, ok := cpMap[v.CompanyId]; ok {
  5918. cpList = cps
  5919. } else {
  5920. companyProduct, err := company.GetExportCompanyProduct(v.CompanyId)
  5921. if err != nil {
  5922. br.Msg = "导出失败"
  5923. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  5924. return
  5925. }
  5926. cpMap[v.CompanyId] = companyProduct
  5927. cpList = companyProduct
  5928. }
  5929. var companyName, companyType, industryName, sellerName, status, timeLimt, createTime, source, permissionStr, expireDay string
  5930. isFiccSuspend := 0
  5931. isRaiSuspend := 0
  5932. for ck, cv := range cpList {
  5933. companyName = cv.CompanyName
  5934. if ck >= 1 {
  5935. companyType = companyType + "/" + cv.ProductName
  5936. status = status + "/" + cv.Status
  5937. } else {
  5938. companyType = cv.ProductName
  5939. status = cv.Status
  5940. }
  5941. if cv.ProductId == 1 {
  5942. industryName = "ficc:" + cv.IndustryName
  5943. sellerName = "ficc:" + cv.SellerName
  5944. startDateStr := cv.StartDate.Format("2006/01/02")
  5945. endDateStr := cv.EndDate.Format("2006/01/02")
  5946. timeLimt = "ficc:" + startDateStr + "~" + endDateStr
  5947. createTime = "ficc:" + cv.CreateTime
  5948. source = "ficc:" + cv.Source
  5949. sub := cv.EndDate.Sub(time.Now())
  5950. if sub < 0 {
  5951. sub = 0
  5952. }
  5953. expireDay = "ficc:" + fmt.Sprintf("%v", int(sub.Hours()/24))
  5954. permissionKey := strconv.Itoa(v.CompanyId) + "_" + strconv.Itoa(cv.ProductId)
  5955. permissionStr = "ficc:"
  5956. if newPermissionStr, ok := permissionMap[permissionKey]; ok {
  5957. permissionStr += newPermissionStr
  5958. } else {
  5959. getPermissionStr, err := company.GetExportPermissionName(v.CompanyId, cv.ProductId)
  5960. if err != nil {
  5961. br.Msg = "导出失败"
  5962. br.ErrMsg = "获取客户权限信息失败,Err:" + err.Error()
  5963. return
  5964. }
  5965. permissionMap[permissionKey] = getPermissionStr
  5966. permissionStr += getPermissionStr
  5967. }
  5968. isFiccSuspend = cv.IsSuspend
  5969. } else {
  5970. industryName = industryName + "\n" + "权益:" + cv.IndustryName
  5971. sellerName = sellerName + "\n" + "权益:" + cv.SellerName
  5972. startDateStr := cv.StartDate.Format("2006/01/02")
  5973. endDateStr := cv.EndDate.Format("2006/01/02")
  5974. timeLimt = timeLimt + "\n" + "权益:" + startDateStr + "~" + endDateStr
  5975. createTime = createTime + "\n" + "权益:" + cv.CreateTime
  5976. source = source + "\n" + "权益:" + cv.Source
  5977. sub := cv.EndDate.Sub(time.Now())
  5978. if sub < 0 {
  5979. sub = 0
  5980. }
  5981. expireDay = "\n" + "权益:" + fmt.Sprintf("%v", int(sub.Hours()/24))
  5982. permissionKey := strconv.Itoa(v.CompanyId) + "_" + strconv.Itoa(cv.ProductId)
  5983. if permissionStr != "" {
  5984. permissionStr = permissionStr + "\n" + "权益:"
  5985. } else {
  5986. permissionStr = "权益:"
  5987. }
  5988. if newPermissionStr, ok := permissionMap[permissionKey]; ok {
  5989. permissionStr += newPermissionStr
  5990. } else {
  5991. getPermissionStr, err := company.GetExportPermissionName(v.CompanyId, cv.ProductId)
  5992. if err != nil {
  5993. br.Msg = "导出失败"
  5994. br.ErrMsg = "获取客户权限信息失败,Err:" + err.Error()
  5995. return
  5996. }
  5997. permissionMap[permissionKey] = getPermissionStr
  5998. permissionStr += getPermissionStr
  5999. }
  6000. isRaiSuspend = cv.IsSuspend
  6001. }
  6002. }
  6003. dataRow := sheel.AddRow()
  6004. dataRow.SetHeight(20)
  6005. dataRow.AddCell().SetString(companyName)
  6006. dataRow.AddCell().SetString(v.Address)
  6007. dataRow.AddCell().SetString(companyType)
  6008. dataRow.AddCell().SetString(v.IndustryName)
  6009. dataRow.AddCell().SetString(v.SellerName)
  6010. dataRow.AddCell().SetString(v.Status)
  6011. dataRow.AddCell().SetString(timeLimt)
  6012. dataRow.AddCell().SetString(expireDay)
  6013. dataRow.AddCell().SetString(v.CreatedTime)
  6014. //dataRow.AddCell().SetString(v.Source)
  6015. dataRow.AddCell().SetString(permissionStr)
  6016. // 填充空白至Z列, AA列开始为权限
  6017. for i := 0; i < emptyColNum; i++ {
  6018. dataRow.AddCell().SetString("")
  6019. }
  6020. cpIds := contractPermissionMap[v.CompanyId]
  6021. rpIds := reportPermissionMap[v.CompanyId]
  6022. for _, p := range permissions {
  6023. // 数字含义:11-表示已购且有阅读权限, 01-表示未购买但有阅读权限
  6024. first := 0
  6025. if utils.InArrayByInt(cpIds, p.ChartPermissionId) {
  6026. first = 1
  6027. }
  6028. second := 0
  6029. if utils.InArrayByInt(rpIds, p.ChartPermissionId) {
  6030. second = 1
  6031. // 如果客户是试用暂停, 即使有这部分权限, 也标记为0
  6032. if isFiccSuspend == 1 && utils.InArrayByInt(ficcPermissions, p.ChartPermissionId) {
  6033. second = 0
  6034. }
  6035. if isRaiSuspend == 1 && utils.InArrayByInt(raiPermissions, p.ChartPermissionId) {
  6036. second = 0
  6037. }
  6038. }
  6039. dataRow.AddCell().SetString(fmt.Sprintf("%d%d", first, second))
  6040. }
  6041. }
  6042. err = xlsxFile.Save(downLoadnFilePath)
  6043. if err != nil {
  6044. br.Msg = "保存文件失败"
  6045. br.ErrMsg = "保存文件失败"
  6046. return
  6047. }
  6048. randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
  6049. downloadFileName := "客户列表_" + randStr + ".xlsx"
  6050. this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  6051. defer func() {
  6052. os.Remove(downLoadnFilePath)
  6053. }()
  6054. br.Ret = 200
  6055. br.Success = true
  6056. br.Msg = "导出成功"
  6057. }
  6058. //func (this *CompanyController) ExportOld() {
  6059. // br := new(models.BaseResponse).Init()
  6060. // defer func() {
  6061. // this.Data["json"] = br
  6062. // this.ServeJSON()
  6063. // }()
  6064. // sysUser := this.SysUser
  6065. // if sysUser == nil {
  6066. // br.Msg = "请登录"
  6067. // br.ErrMsg = "请登录,SysUser Is Empty"
  6068. // br.Ret = 408
  6069. // return
  6070. // }
  6071. // roleTypeCode := sysUser.RoleTypeCode
  6072. //
  6073. // status := this.GetString("Status")
  6074. // companyType := this.GetString("CompanyType")
  6075. // industryId, _ := this.GetInt("IndustryId")
  6076. // adminId := this.GetString("AdminId")
  6077. //
  6078. // chartPermissionIds := this.GetString("ChartPermissionIds")
  6079. // startDate := this.GetString("StartDate")
  6080. // endDate := this.GetString("EndDate")
  6081. // createStartDate := this.GetString("CreateStartDate")
  6082. // createEndDate := this.GetString("CreateEndDate")
  6083. // keyWord := this.GetString("KeyWord")
  6084. // keyWord = strings.Trim(keyWord, " ")
  6085. //
  6086. // resp := new(company.CompanyListResp)
  6087. // statusItems := make([]*company.CompanyStatus, 0)
  6088. // var statusArr = [...]string{"全部", "试用", "正式", "冻结", "流失", "永续"}
  6089. //
  6090. // var condition string
  6091. // var pars []interface{}
  6092. //
  6093. // var lossCondition string
  6094. // var lossPars []interface{}
  6095. //
  6096. // var permissionCondition string
  6097. // var permissionPars []interface{}
  6098. //
  6099. // if status != "" && status != "全部" {
  6100. // condition += ` AND b.status=? `
  6101. // pars = append(pars, status)
  6102. //
  6103. // //permissionCondition += ` AND b.status=? `
  6104. // //permissionPars = append(permissionPars, status)
  6105. // }
  6106. // if companyType != "" {
  6107. // condition += ` AND b.product_name=? `
  6108. // pars = append(pars, companyType)
  6109. //
  6110. // lossCondition += ` AND b.product_name=? `
  6111. // lossPars = append(lossPars, companyType)
  6112. //
  6113. // permissionCondition += ` AND b.product_name=? `
  6114. // permissionPars = append(permissionPars, companyType)
  6115. // }
  6116. //
  6117. // if industryId > 0 {
  6118. // condition += ` AND b.industry_id=? `
  6119. // pars = append(pars, industryId)
  6120. //
  6121. // lossCondition += ` AND b.industry_id=? `
  6122. // lossPars = append(lossPars, industryId)
  6123. //
  6124. // permissionCondition += ` AND b.industry_id=? `
  6125. // permissionPars = append(permissionPars, industryId)
  6126. // }
  6127. //
  6128. // if adminId != "" {
  6129. // condition += ` AND b.seller_id IN (` + adminId + `) `
  6130. //
  6131. // lossCondition += ` AND b.seller_id IN (` + adminId + `) `
  6132. //
  6133. // permissionCondition += ` AND b.seller_id IN (` + adminId + `) `
  6134. // }
  6135. //
  6136. // if startDate != "" {
  6137. // condition += ` AND b.start_date>=? `
  6138. // pars = append(pars, startDate)
  6139. //
  6140. // lossCondition += ` AND b.start_date>=? `
  6141. // lossPars = append(lossPars, startDate)
  6142. //
  6143. // permissionCondition += ` AND b.start_date>=? `
  6144. // permissionPars = append(permissionPars, startDate)
  6145. // }
  6146. //
  6147. // if endDate != "" {
  6148. // condition += ` AND b.end_date<=? `
  6149. // pars = append(pars, endDate)
  6150. //
  6151. // lossCondition += ` AND b.end_date<=? `
  6152. // lossPars = append(lossPars, endDate)
  6153. //
  6154. // permissionCondition += ` AND b.end_date<=? `
  6155. // permissionPars = append(permissionPars, endDate)
  6156. // }
  6157. //
  6158. // if createStartDate != "" {
  6159. // condition += ` AND a.created_time>=? `
  6160. // pars = append(pars, createStartDate)
  6161. //
  6162. // lossCondition += ` AND a.created_time>=? `
  6163. // lossPars = append(lossPars, createStartDate)
  6164. //
  6165. // permissionCondition += ` AND a.created_time>=? `
  6166. // permissionPars = append(permissionPars, createStartDate)
  6167. // }
  6168. //
  6169. // if createEndDate != "" {
  6170. // condition += ` AND a.created_time<=? `
  6171. // pars = append(pars, createEndDate)
  6172. //
  6173. // lossCondition += ` AND a.created_time<=? `
  6174. // lossPars = append(lossPars, createEndDate)
  6175. //
  6176. // permissionCondition += ` AND a.created_time<=? `
  6177. // permissionPars = append(permissionPars, createEndDate)
  6178. // }
  6179. //
  6180. // if keyWord != "" {
  6181. // companyIdStr, err := company.GetCompanyIdByKeyWord(keyWord)
  6182. // if err != nil {
  6183. // return
  6184. // }
  6185. // if companyIdStr != "" {
  6186. // condition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.company_id IN(` + companyIdStr + `)) `
  6187. // lossCondition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.company_id IN(` + companyIdStr + `)) `
  6188. //
  6189. // permissionCondition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.company_id IN(` + companyIdStr + `)) `
  6190. // } else {
  6191. // condition += ` AND (a.company_name LIKE '%` + keyWord + `%' ) `
  6192. // lossCondition += ` AND (a.company_name LIKE '%` + keyWord + `%' ) `
  6193. //
  6194. // permissionCondition += ` AND (a.company_name LIKE '%` + keyWord + `%' ) `
  6195. // }
  6196. // }
  6197. //
  6198. // if chartPermissionIds != "" && chartPermissionIds != "1" {
  6199. // //chartPermissionArr := strings.Split(chartPermissionIds, ",")
  6200. // //chartPermissionCount := len(chartPermissionArr)
  6201. // companyIdStr, err := company.GetCompanyListCompanyIdByPermissionIdStr(chartPermissionIds)
  6202. // if err != nil {
  6203. // br.Msg = "获取失败"
  6204. // br.ErrMsg = "根据权限获取公司ID失败,Err:" + err.Error()
  6205. // return
  6206. // }
  6207. // //var companyIdArr []string
  6208. // //for _, v := range companyIdList {
  6209. // // companyIdArr = append(companyIdArr, strconv.Itoa(v.CompanyId))
  6210. // //}
  6211. // //companyIdStr := strings.Join(companyIdArr, ",")
  6212. //
  6213. // if companyIdStr != "" {
  6214. // condition += ` AND a.company_id IN (` + companyIdStr + `) `
  6215. // lossCondition += ` AND a.company_id IN (` + companyIdStr + `) `
  6216. // permissionCondition += ` AND a.company_id IN (` + companyIdStr + `) `
  6217. // } else {
  6218. // for _, v := range statusArr {
  6219. // statusCount := new(company.CompanyStatus)
  6220. // if v == "全部" {
  6221. // statusCount.Status = "全部"
  6222. // statusCount.Count = 0
  6223. // } else {
  6224. // statusCount.Status = v
  6225. // statusCount.Count = 0
  6226. // }
  6227. // statusItems = append(statusItems, statusCount)
  6228. // }
  6229. // items := make([]*company.CompanyListItem, 0)
  6230. // resp.List = items
  6231. // resp.StatusCount = statusItems
  6232. // br.Msg = "获取成功"
  6233. // br.Ret = 200
  6234. // br.Data = resp
  6235. // return
  6236. // }
  6237. // }
  6238. //
  6239. // //权限控制
  6240. // {
  6241. // if roleTypeCode != utils.ROLE_TYPE_CODE_ADMIN {
  6242. // if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN {
  6243. // condition += ` AND b.product_id=? `
  6244. // pars = append(pars, 1)
  6245. //
  6246. // permissionCondition += ` AND b.product_id=? `
  6247. // permissionPars = append(permissionPars, 1)
  6248. // } else if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  6249. // condition += ` AND b.product_id=? `
  6250. // pars = append(pars, 2)
  6251. //
  6252. // permissionCondition += ` AND b.product_id=? `
  6253. // permissionPars = append(permissionPars, 2)
  6254. // } else {
  6255. // if sysUser.Authority <= 0 {
  6256. // if status != utils.COMPANY_STATUS_LOSE {
  6257. // condition += ` AND b.seller_id=? `
  6258. // pars = append(pars, sysUser.AdminId)
  6259. // }
  6260. //
  6261. // permissionCondition += ` AND b.seller_id=? `
  6262. // permissionPars = append(permissionPars, sysUser.AdminId)
  6263. // } else {
  6264. // if sysUser.Authority == 1 {
  6265. // if status != utils.COMPANY_STATUS_LOSE {
  6266. // condition += ` AND b.department_id=? `
  6267. // pars = append(pars, sysUser.DepartmentId)
  6268. // }
  6269. // permissionCondition += ` AND b.department_id=? `
  6270. // permissionPars = append(permissionPars, sysUser.DepartmentId)
  6271. // }
  6272. //
  6273. // if sysUser.Authority == 2 {
  6274. // if status != utils.COMPANY_STATUS_LOSE {
  6275. // condition += ` AND b.group_id=? `
  6276. // pars = append(pars, sysUser.GroupId)
  6277. // }
  6278. // permissionCondition += ` AND b.group_id=? `
  6279. // permissionPars = append(permissionPars, sysUser.GroupId)
  6280. // }
  6281. // }
  6282. // }
  6283. // }
  6284. // }
  6285. //
  6286. // dir, err := os.Executable()
  6287. // exPath := filepath.Dir(dir)
  6288. // downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  6289. // xlsxFile := xlsx.NewFile()
  6290. // if err != nil {
  6291. // br.Msg = "生成文件失败"
  6292. // br.ErrMsg = "生成文件失败"
  6293. // return
  6294. // }
  6295. // style := xlsx.NewStyle()
  6296. // alignment := xlsx.Alignment{
  6297. // Horizontal: "center",
  6298. // Vertical: "center",
  6299. // WrapText: true,
  6300. // }
  6301. //
  6302. // style.Alignment = alignment
  6303. // style.ApplyAlignment = true
  6304. //
  6305. // sheel, err := xlsxFile.AddSheet("客户数据")
  6306. // if err != nil {
  6307. // br.Msg = "新增Sheet失败"
  6308. // br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  6309. // return
  6310. // }
  6311. // titleRow := sheel.AddRow()
  6312. // titleRow.AddCell().SetValue("客户名称")
  6313. // titleRow.AddCell().SetValue("客户类型")
  6314. // titleRow.AddCell().SetValue("所属行业")
  6315. // titleRow.AddCell().SetValue("所属销售")
  6316. // titleRow.AddCell().SetValue("客户状态")
  6317. // titleRow.AddCell().SetValue("服务期限")
  6318. // titleRow.AddCell().SetValue("到期天数")
  6319. // titleRow.AddCell().SetValue("创建时间")
  6320. // titleRow.AddCell().SetValue("客户来源")
  6321. // titleRow.AddCell().SetValue("阅读权限")
  6322. //
  6323. // list, err := company.GetCompanyListExport(condition, pars)
  6324. // if err != nil {
  6325. // br.Msg = "获取失败"
  6326. // br.ErrMsg = "获取数据失败,Err:" + err.Error()
  6327. // return
  6328. // }
  6329. // cpMap := make(map[int][]*company.ExportCompanyProduct)
  6330. // permissionMap := make(map[string]string)
  6331. // for _, v := range list {
  6332. // cpList := make([]*company.ExportCompanyProduct, 1)
  6333. // if cps, ok := cpMap[v.CompanyId]; ok {
  6334. // cpList = cps
  6335. // } else {
  6336. // companyProduct, err := company.GetExportCompanyProduct(v.CompanyId)
  6337. // if err != nil {
  6338. // br.Msg = "导出失败"
  6339. // br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  6340. // return
  6341. // }
  6342. // cpMap[v.CompanyId] = companyProduct
  6343. // cpList = companyProduct
  6344. // }
  6345. // var companyName, companyType, industryName, sellerName, status, timeLimt, createTime, source, permissionStr, expireDay string
  6346. //
  6347. // for ck, cv := range cpList {
  6348. // companyName = cv.CompanyName
  6349. // if ck >= 1 {
  6350. // companyType = companyType + "/" + cv.ProductName
  6351. // status = status + "/" + cv.Status
  6352. // } else {
  6353. // companyType = cv.ProductName
  6354. // status = cv.Status
  6355. // }
  6356. // if cv.ProductId == 1 {
  6357. // industryName = "ficc:" + cv.IndustryName
  6358. // sellerName = "ficc:" + cv.SellerName
  6359. // startDateStr := cv.StartDate.Format("2006/01/02")
  6360. // endDateStr := cv.EndDate.Format("2006/01/02")
  6361. // timeLimt = "ficc:" + startDateStr + "~" + endDateStr
  6362. // createTime = "ficc:" + cv.CreateTime
  6363. // source = "ficc:" + cv.Source
  6364. // sub := cv.EndDate.Sub(time.Now())
  6365. // if sub < 0 {
  6366. // sub = 0
  6367. // }
  6368. // expireDay = "ficc:" + fmt.Sprintf("%v", int(sub.Hours()/24))
  6369. //
  6370. // permissionKey := strconv.Itoa(v.CompanyId) + "_" + strconv.Itoa(cv.ProductId)
  6371. //
  6372. // permissionStr = "ficc:"
  6373. // if newPermissionStr, ok := permissionMap[permissionKey]; ok {
  6374. // permissionStr += newPermissionStr
  6375. // } else {
  6376. // getPermissionStr, err := company.GetExportPermissionName(v.CompanyId, cv.ProductId)
  6377. // if err != nil {
  6378. // br.Msg = "导出失败"
  6379. // br.ErrMsg = "获取客户权限信息失败,Err:" + err.Error()
  6380. // return
  6381. // }
  6382. // permissionMap[permissionKey] = getPermissionStr
  6383. // permissionStr += getPermissionStr
  6384. // }
  6385. // } else {
  6386. // industryName = industryName + "\n" + "权益:" + cv.IndustryName
  6387. // sellerName = sellerName + "\n" + "权益:" + cv.SellerName
  6388. // startDateStr := cv.StartDate.Format("2006/01/02")
  6389. // endDateStr := cv.EndDate.Format("2006/01/02")
  6390. //
  6391. // timeLimt = timeLimt + "\n" + "权益:" + startDateStr + "~" + endDateStr
  6392. // createTime = createTime + "\n" + "权益:" + cv.CreateTime
  6393. // source = source + "\n" + "权益:" + cv.Source
  6394. //
  6395. // sub := cv.EndDate.Sub(time.Now())
  6396. // if sub < 0 {
  6397. // sub = 0
  6398. // }
  6399. // expireDay = "\n" + "权益:" + fmt.Sprintf("%v", int(sub.Hours()/24))
  6400. //
  6401. // permissionKey := strconv.Itoa(v.CompanyId) + "_" + strconv.Itoa(cv.ProductId)
  6402. // if permissionStr != "" {
  6403. // permissionStr = permissionStr + "\n" + "权益:"
  6404. // } else {
  6405. // permissionStr = "权益:"
  6406. // }
  6407. // if newPermissionStr, ok := permissionMap[permissionKey]; ok {
  6408. // permissionStr += newPermissionStr
  6409. // } else {
  6410. // getPermissionStr, err := company.GetExportPermissionName(v.CompanyId, cv.ProductId)
  6411. // if err != nil {
  6412. // br.Msg = "导出失败"
  6413. // br.ErrMsg = "获取客户权限信息失败,Err:" + err.Error()
  6414. // return
  6415. // }
  6416. // permissionMap[permissionKey] = getPermissionStr
  6417. // permissionStr += getPermissionStr
  6418. // }
  6419. // }
  6420. // }
  6421. //
  6422. // dataRow := sheel.AddRow()
  6423. // dataRow.SetHeight(20)
  6424. // dataRow.AddCell().SetString(companyName)
  6425. // dataRow.AddCell().SetString(companyType)
  6426. // dataRow.AddCell().SetString(v.IndustryName)
  6427. // dataRow.AddCell().SetString(v.SellerName)
  6428. // dataRow.AddCell().SetString(v.Status)
  6429. // dataRow.AddCell().SetString(timeLimt)
  6430. // dataRow.AddCell().SetString(expireDay)
  6431. // dataRow.AddCell().SetString(v.CreatedTime)
  6432. // dataRow.AddCell().SetString(v.Source)
  6433. // dataRow.AddCell().SetString(permissionStr)
  6434. // }
  6435. // err = xlsxFile.Save(downLoadnFilePath)
  6436. // if err != nil {
  6437. // br.Msg = "保存文件失败"
  6438. // br.ErrMsg = "保存文件失败"
  6439. // return
  6440. // }
  6441. // randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
  6442. // downloadFileName := "客户列表_" + randStr + ".xlsx"
  6443. // this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  6444. // defer func() {
  6445. // os.Remove(downLoadnFilePath)
  6446. // }()
  6447. // br.Ret = 200
  6448. // br.Success = true
  6449. // br.Msg = "导出成功"
  6450. //}
  6451. // @Title 导出
  6452. // @Description 导出接口
  6453. // @Param Status query string true "状态:”试用','永续','冻结','流失','正式'"
  6454. // @Param CompanyType query string true "客户类型:传空字符串或者不传为全部,'ficc','权益'"
  6455. // @Param IndustryId query int true "行业id,0为全部"
  6456. // @Param AdminId query string true "销售id,多个用英文逗号隔开,空字符串为全部"
  6457. // @Param ChartPermissionIds query string false "阅读权限品种ID,多个用英文逗号分开,空字符串为全部"
  6458. // @Param ContractPermissionIds query string false "已购品种ID,多个用英文逗号分开,空字符串为全部"
  6459. // @Param StartDate query string true "开始时间"
  6460. // @Param EndDate query string true "结束时间"
  6461. // @Param KeyWord query string true "搜索关键词"
  6462. // @Param Address query string true "地址 , 多个用英文逗号分开 "
  6463. // @Param Province query string true "省 , 多个用英文逗号分开 "
  6464. // @Param City query string true "市 , 多个用英文逗号分开 "
  6465. // @Param PackageType query int true "套餐类型,0:无,1:大套餐,2:小套餐"
  6466. // @Success Ret=200 移动成功
  6467. // @router /user/export [get]
  6468. func (this *CompanyController) CompanyUserExport() {
  6469. br := new(models.BaseResponse).Init()
  6470. defer func() {
  6471. this.Data["json"] = br
  6472. this.ServeJSON()
  6473. }()
  6474. sysUser := this.SysUser
  6475. if sysUser == nil {
  6476. br.Msg = "请登录"
  6477. br.ErrMsg = "请登录,SysUser Is Empty"
  6478. br.Ret = 408
  6479. return
  6480. }
  6481. roleTypeCode := sysUser.RoleTypeCode
  6482. status := this.GetString("Status")
  6483. companyType := this.GetString("CompanyType")
  6484. industryId, _ := this.GetInt("IndustryId")
  6485. adminId := this.GetString("AdminId")
  6486. chartPermissionIds := this.GetString("ChartPermissionIds")
  6487. contractPermissionIds := this.GetString("ContractPermissionIds")
  6488. startDate := this.GetString("StartDate")
  6489. endDate := this.GetString("EndDate")
  6490. createStartDate := this.GetString("CreateStartDate")
  6491. createEndDate := this.GetString("CreateEndDate")
  6492. keyWord := this.GetString("KeyWord")
  6493. address := this.GetString("Address")
  6494. province := this.GetString("Province")
  6495. city := this.GetString("City")
  6496. // 套餐类型
  6497. packageType, _ := this.GetInt("PackageType")
  6498. var condition string
  6499. var pars []interface{}
  6500. if status != "" && status != "全部" {
  6501. condition += ` AND b.status=? `
  6502. pars = append(pars, status)
  6503. }
  6504. if companyType != "" {
  6505. condition += ` AND b.product_name=? `
  6506. pars = append(pars, companyType)
  6507. }
  6508. if industryId > 0 {
  6509. condition += ` AND b.industry_id=? `
  6510. pars = append(pars, industryId)
  6511. }
  6512. if adminId != "" {
  6513. condition += ` AND b.seller_id IN (` + adminId + `) `
  6514. }
  6515. if startDate != "" {
  6516. condition += ` AND b.start_date>=? `
  6517. pars = append(pars, startDate)
  6518. }
  6519. if endDate != "" {
  6520. condition += ` AND b.end_date<=? `
  6521. pars = append(pars, endDate)
  6522. }
  6523. if createStartDate != "" {
  6524. condition += ` AND a.created_time>=? `
  6525. pars = append(pars, createStartDate)
  6526. }
  6527. if createEndDate != "" {
  6528. condition += ` AND a.created_time<=? `
  6529. pars = append(pars, createEndDate)
  6530. }
  6531. if keyWord != "" {
  6532. condition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR c.mobile LIKE '%` + keyWord + `%' OR c.email LIKE '%` + keyWord + `%') `
  6533. }
  6534. // 阅读权限/已购品种筛选
  6535. cond, emp, e := services.FilterReadAndContractAuth(chartPermissionIds, contractPermissionIds, condition)
  6536. if e != nil {
  6537. br.Msg = "获取失败"
  6538. br.ErrMsg = "FilterReadAndContractAuth err: " + e.Error()
  6539. return
  6540. }
  6541. if emp {
  6542. condition += ` AND 1 = 2`
  6543. } else {
  6544. condition = cond
  6545. }
  6546. if address != "" {
  6547. var addressSql string
  6548. slice := strings.Split(address, ",")
  6549. for _, v := range slice {
  6550. addressSql += "'" + v + "'" + ","
  6551. }
  6552. addressSql = strings.TrimRight(addressSql, ",")
  6553. condition += ` AND a.address IN (` + addressSql + `) `
  6554. }
  6555. if province != "" {
  6556. var provinceSql string
  6557. slice := strings.Split(province, ",")
  6558. for _, v := range slice {
  6559. provinceSql += "'" + v + "'" + ","
  6560. }
  6561. provinceSql = strings.TrimRight(provinceSql, ",")
  6562. condition += ` AND a.province IN (` + provinceSql + `) `
  6563. }
  6564. if city != "" {
  6565. var citySql string
  6566. slice := strings.Split(city, ",")
  6567. for _, v := range slice {
  6568. citySql += "'" + v + "'" + ","
  6569. }
  6570. citySql = strings.TrimRight(citySql, ",")
  6571. condition += ` AND a.city IN (` + citySql + `) `
  6572. }
  6573. //套餐类型
  6574. if packageType > 0 {
  6575. condition += ` AND b.package_type=? `
  6576. pars = append(pars, packageType)
  6577. }
  6578. //权限控制
  6579. {
  6580. if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER ||
  6581. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER {
  6582. if status != utils.COMPANY_STATUS_LOSE && status != utils.COMPANY_STATUS_FOREVER {
  6583. condition += ` AND b.seller_id=? `
  6584. pars = append(pars, sysUser.AdminId)
  6585. }
  6586. }
  6587. if sysUser.Authority == 1 {
  6588. condition += ` AND b.department_id=? `
  6589. pars = append(pars, sysUser.DepartmentId)
  6590. }
  6591. if sysUser.Authority == 2 {
  6592. condition += ` AND b.group_id=? `
  6593. pars = append(pars, sysUser.GroupId)
  6594. }
  6595. }
  6596. var statusCond string
  6597. var statusPars []interface{}
  6598. // 根据当前用户角色
  6599. productId := services.GetProductId(roleTypeCode)
  6600. if productId > 0 {
  6601. condition += ` AND b.product_id = ? `
  6602. pars = append(pars, productId)
  6603. statusCond += ` AND b.product_id = ? `
  6604. statusPars = append(statusPars, productId)
  6605. }
  6606. companyIds, err := company.GetExportCompanyIds(condition, pars)
  6607. if err != nil {
  6608. br.Msg = "导出失败"
  6609. br.ErrMsg = "导出失败,Err:" + err.Error()
  6610. return
  6611. }
  6612. dir, err := os.Executable()
  6613. exPath := filepath.Dir(dir)
  6614. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  6615. xlsxFile := xlsx.NewFile()
  6616. if err != nil {
  6617. br.Msg = "生成文件失败"
  6618. br.ErrMsg = "生成文件失败"
  6619. return
  6620. }
  6621. style := xlsx.NewStyle()
  6622. alignment := xlsx.Alignment{
  6623. Horizontal: "center",
  6624. Vertical: "center",
  6625. WrapText: true,
  6626. }
  6627. style.Alignment = alignment
  6628. style.ApplyAlignment = true
  6629. sheel, err := xlsxFile.AddSheet("联系人数据")
  6630. if err != nil {
  6631. br.Msg = "新增Sheet失败"
  6632. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  6633. return
  6634. }
  6635. sheel.SetColWidth(7, 7, 10)
  6636. sheel.SetColWidth(8, 10, 16)
  6637. sheel.SetColWidth(9, 11, 20)
  6638. sheel.SetColWidth(12, 12, 35)
  6639. sheel.SetColWidth(13, 13, 15)
  6640. sheel.SetColWidth(14, 14, 80)
  6641. titleRow := sheel.AddRow()
  6642. titleRow.AddCell().SetValue("联系人")
  6643. titleRow.AddCell().SetValue("是否关注公众号")
  6644. titleRow.AddCell().SetValue("手机号")
  6645. titleRow.AddCell().SetValue("邮箱")
  6646. //titleRow.AddCell().SetValue("职位")
  6647. titleRow.AddCell().SetValue("是否决策人")
  6648. //titleRow.AddCell().SetValue("客户部门")
  6649. titleRow.AddCell().SetValue("客户名称")
  6650. titleRow.AddCell().SetValue("客户状态")
  6651. //titleRow.AddCell().SetValue("社会信用码")
  6652. //titleRow.AddCell().SetValue("所属区域")
  6653. //titleRow.AddCell().SetValue("客户类型")
  6654. //industryCell := titleRow.AddCell()
  6655. //industryCell.SetStyle(style)
  6656. //industryCell.Value = "所属行业"
  6657. //
  6658. //sellerCell := titleRow.AddCell()
  6659. //sellerCell.SetStyle(style)
  6660. //sellerCell.Value = "所属销售"
  6661. //
  6662. //statusCell := titleRow.AddCell()
  6663. //statusCell.SetStyle(style)
  6664. //statusCell.Value = "客户状态"
  6665. //
  6666. //timeLimtCell := titleRow.AddCell()
  6667. //timeLimtCell.SetStyle(style)
  6668. //timeLimtCell.Value = "服务期限"
  6669. //
  6670. //createTimeCell := titleRow.AddCell()
  6671. //createTimeCell.SetStyle(style)
  6672. //createTimeCell.Value = "创建时间"
  6673. //
  6674. //sourceCell := titleRow.AddCell()
  6675. //sourceCell.SetStyle(style)
  6676. //sourceCell.Value = "客户来源"
  6677. //permissionStyle := xlsx.NewStyle()
  6678. //permissionAlignment := xlsx.Alignment{
  6679. // Horizontal: "center",
  6680. // Vertical: "center",
  6681. // WrapText: true,
  6682. //}
  6683. //
  6684. //permissionStyle.Alignment = permissionAlignment
  6685. //permissionStyle.ApplyAlignment = true
  6686. //permissionCell := titleRow.AddCell()
  6687. //permissionCell.SetStyle(permissionStyle)
  6688. //permissionCell.Value = "阅读权限"
  6689. users := make([]*company.ExportUser, 0)
  6690. if companyIds != "" {
  6691. companyIds = strings.Trim(companyIds, ",")
  6692. if productId > 0 {
  6693. users, err = company.GetExportUserByProductId(companyIds, productId)
  6694. if err != nil {
  6695. br.Msg = "导出失败"
  6696. br.ErrMsg = "获取联系人信息失败,Err:" + err.Error()
  6697. return
  6698. }
  6699. } else {
  6700. users, err = company.GetExportUser(companyIds)
  6701. if err != nil {
  6702. br.Msg = "导出失败"
  6703. br.ErrMsg = "获取联系人信息失败,Err:" + err.Error()
  6704. return
  6705. }
  6706. }
  6707. // 获取客户状态
  6708. companyIntIds := make([]int, 0)
  6709. companyIdArr := strings.Split(companyIds, ",")
  6710. for _, c := range companyIdArr {
  6711. id, e := strconv.Atoi(c)
  6712. if e != nil {
  6713. br.Msg = "导出失败"
  6714. br.ErrMsg = "客户ID有误"
  6715. return
  6716. }
  6717. companyIntIds = append(companyIntIds, id)
  6718. }
  6719. if len(companyIntIds) > 0 {
  6720. statusCond += fmt.Sprintf(` AND a.company_id IN (%s) `, utils.GetOrmInReplace(len(companyIntIds)))
  6721. statusPars = append(statusPars, companyIntIds)
  6722. }
  6723. statusMap := make(map[int]string)
  6724. nameMap := make(map[int]string)
  6725. companyStatusList, e := company.GetExportUserCompanyStatus(statusCond, statusPars)
  6726. if e != nil {
  6727. br.Msg = "导出失败"
  6728. br.ErrMsg = "获取客户状态失败, Err: " + e.Error()
  6729. return
  6730. }
  6731. for _, s := range companyStatusList {
  6732. statusMap[s.CompanyId] = s.CompanyStatus
  6733. nameMap[s.CompanyId] = s.CompanyName
  6734. }
  6735. //cpMap := make(map[int][]*company.ExportCompanyProduct)
  6736. //permissionMap := make(map[string]string)
  6737. for _, v := range users {
  6738. dataRow := sheel.AddRow()
  6739. dataRow.SetHeight(20)
  6740. dataRow.AddCell().SetString(v.RealName)
  6741. if v.IsSubscribe == 1 {
  6742. dataRow.AddCell().SetString("是") // 是否关注公众号
  6743. } else {
  6744. dataRow.AddCell().SetString("")
  6745. }
  6746. dataRow.AddCell().SetString(v.Mobile)
  6747. dataRow.AddCell().SetString(v.Email)
  6748. //dataRow.AddCell().SetString(v.Position)
  6749. if v.IsMaker == 1 {
  6750. dataRow.AddCell().SetString("是")
  6751. } else {
  6752. dataRow.AddCell().SetString("否")
  6753. }
  6754. //dataRow.AddCell().SetString(v.DepartmentName)
  6755. //cpList := make([]*company.ExportCompanyProduct, 1)
  6756. //if cps, ok := cpMap[v.CompanyId]; ok {
  6757. // cpList = cps
  6758. //} else {
  6759. // companyProduct, err := company.GetExportCompanyProduct(v.CompanyId)
  6760. // if err != nil {
  6761. // br.Msg = "导出失败"
  6762. // br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  6763. // return
  6764. // }
  6765. // cpMap[v.CompanyId] = companyProduct
  6766. // cpList = companyProduct
  6767. //}
  6768. //productList, err := company.GetExportCompanyProduct(v.CompanyId)
  6769. //if err!=nil {
  6770. // fmt.Println("导出失败,Err:"+err.Error())
  6771. // return
  6772. //}
  6773. //var companyName, companyType, industryName, sellerName, status, timeLimt, createTime, source, permissionStr, creditCode, regionType string
  6774. //for ck, cv := range cpList {
  6775. // companyName = cv.CompanyName
  6776. // creditCode = cv.CreditCode
  6777. // regionType = cv.RegionType
  6778. // if ck >= 1 {
  6779. // companyType = companyType + "/" + cv.ProductName
  6780. // status = status + "/" + cv.Status
  6781. // } else {
  6782. // companyType = cv.ProductName
  6783. // status = cv.Status
  6784. // }
  6785. // if cv.ProductId == 1 {
  6786. // industryName = "ficc:" + cv.IndustryName
  6787. // sellerName = "ficc:" + cv.SellerName
  6788. // startDateStr := cv.StartDate.Format("2006/01/02")
  6789. // endDateStr := cv.EndDate.Format("2006/01/02")
  6790. // if startDateStr != "0001/01/01" {
  6791. // timeLimt = "ficc:" + startDateStr + "~" + endDateStr
  6792. // } else {
  6793. // timeLimt = ""
  6794. // }
  6795. // createTime = "ficc:" + cv.CreateTime
  6796. // source = "ficc:" + cv.Source
  6797. // permissionKey := strconv.Itoa(v.CompanyId) + "_" + strconv.Itoa(cv.ProductId)
  6798. //
  6799. // permissionStr = "ficc:"
  6800. // if newPermissionStr, ok := permissionMap[permissionKey]; ok {
  6801. // permissionStr += newPermissionStr
  6802. // } else {
  6803. // getPermissionStr, err := company.GetExportPermissionName(v.CompanyId, cv.ProductId)
  6804. // if err != nil {
  6805. // br.Msg = "导出失败"
  6806. // br.ErrMsg = "获取客户权限信息失败,Err:" + err.Error()
  6807. // return
  6808. // }
  6809. // permissionMap[permissionKey] = getPermissionStr
  6810. // permissionStr += getPermissionStr
  6811. // }
  6812. // if cv.Status == utils.COMPANY_STATUS_LOSE {
  6813. // permissionStr = ""
  6814. // }
  6815. // } else {
  6816. // industryName = industryName + "\n" + "权益:" + cv.IndustryName
  6817. // sellerName = sellerName + "\n" + "权益:" + cv.SellerName
  6818. // startDateStr := cv.StartDate.Format("2006/01/02")
  6819. // endDateStr := cv.EndDate.Format("2006/01/02")
  6820. //
  6821. // if startDateStr != "0001/01/01" {
  6822. // timeLimt = timeLimt + "\n" + "权益:" + startDateStr + "~" + endDateStr
  6823. // } else {
  6824. // timeLimt = timeLimt + ""
  6825. // }
  6826. // createTime = createTime + "\n" + "权益:" + cv.CreateTime
  6827. // source = source + "\n" + "权益:" + cv.Source
  6828. //
  6829. // permissionKey := strconv.Itoa(v.CompanyId) + "_" + strconv.Itoa(cv.ProductId)
  6830. // if permissionStr != "" {
  6831. // permissionStr = permissionStr + "\n" + "权益:"
  6832. // } else {
  6833. // permissionStr = "权益:"
  6834. // }
  6835. // if newPermissionStr, ok := permissionMap[permissionKey]; ok {
  6836. // permissionStr += newPermissionStr
  6837. // } else {
  6838. // getPermissionStr, err := company.GetExportPermissionName(v.CompanyId, cv.ProductId)
  6839. // if err != nil {
  6840. // br.Msg = "导出失败"
  6841. // br.ErrMsg = "获取客户权限信息失败,Err:" + err.Error()
  6842. // return
  6843. // }
  6844. // permissionMap[permissionKey] = getPermissionStr
  6845. // permissionStr += getPermissionStr
  6846. // }
  6847. // if cv.Status == utils.COMPANY_STATUS_LOSE {
  6848. // permissionStr = permissionStr + ""
  6849. // }
  6850. // }
  6851. //}
  6852. // 2023-0420这是谁写的循环查,顺手优化了一下,手动狗头-_-~
  6853. //companyInfo, err := company.GetCompanyById(v.CompanyId)
  6854. //if err != nil {
  6855. // br.Msg = "导出失败"
  6856. // br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  6857. // return
  6858. //}
  6859. dataRow.AddCell().SetString(nameMap[v.CompanyId])
  6860. dataRow.AddCell().SetString(statusMap[v.CompanyId]) // 客户状态
  6861. //dataRow.AddCell().SetString(creditCode)
  6862. //dataRow.AddCell().SetString(regionType)
  6863. //
  6864. //dataRow.AddCell().SetString(companyType)
  6865. //industryValueCell := dataRow.AddCell()
  6866. //industryValueCell.SetStyle(style)
  6867. //industryValueCell.SetString(industryName)
  6868. //
  6869. //sellerValueCell := dataRow.AddCell()
  6870. //sellerValueCell.SetStyle(style)
  6871. //sellerValueCell.SetString(sellerName)
  6872. //
  6873. //statusValueCell := dataRow.AddCell()
  6874. //statusValueCell.SetStyle(style)
  6875. //statusValueCell.SetValue(status)
  6876. //
  6877. //timeLimitValueCell := dataRow.AddCell()
  6878. //timeLimitValueCell.SetStyle(style)
  6879. //timeLimitValueCell.SetValue(timeLimt)
  6880. //
  6881. //createTimeValueCell := dataRow.AddCell()
  6882. //createTimeValueCell.SetStyle(style)
  6883. //createTimeValueCell.SetValue(createTime)
  6884. //
  6885. //sourceValueCell := dataRow.AddCell()
  6886. //sourceValueCell.SetStyle(style)
  6887. //sourceValueCell.SetValue(source)
  6888. //
  6889. //permissionStrValueCell := dataRow.AddCell()
  6890. //permissionStrValueCell.SetStyle(style)
  6891. //permissionStrValueCell.SetValue(permissionStr)
  6892. }
  6893. }
  6894. err = xlsxFile.Save(downLoadnFilePath)
  6895. if err != nil {
  6896. br.Msg = "保存文件失败"
  6897. br.ErrMsg = "保存文件失败"
  6898. return
  6899. }
  6900. randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
  6901. downloadFileName := "联系人列表" + randStr + ".xlsx"
  6902. this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  6903. defer func() {
  6904. os.Remove(downLoadnFilePath)
  6905. }()
  6906. br.Ret = 200
  6907. br.Success = true
  6908. br.Msg = "导出成功"
  6909. }
  6910. //func (this *CompanyController) CompanyUserExportOld() {
  6911. // br := new(models.BaseResponse).Init()
  6912. // defer func() {
  6913. // this.Data["json"] = br
  6914. // this.ServeJSON()
  6915. // }()
  6916. // sysUser := this.SysUser
  6917. // if sysUser == nil {
  6918. // br.Msg = "请登录"
  6919. // br.ErrMsg = "请登录,SysUser Is Empty"
  6920. // br.Ret = 408
  6921. // return
  6922. // }
  6923. // roleTypeCode := sysUser.RoleTypeCode
  6924. // status := this.GetString("Status")
  6925. // companyType := this.GetString("CompanyType")
  6926. // industryId, _ := this.GetInt("IndustryId")
  6927. // adminId := this.GetString("AdminId")
  6928. //
  6929. // chartPermissionIds := this.GetString("ChartPermissionIds")
  6930. // startDate := this.GetString("StartDate")
  6931. // endDate := this.GetString("EndDate")
  6932. // keyWord := this.GetString("KeyWord")
  6933. //
  6934. // var condition string
  6935. // var pars []interface{}
  6936. //
  6937. // if status != "" && status != "全部" {
  6938. // condition += ` AND b.status=? `
  6939. // pars = append(pars, status)
  6940. // }
  6941. // if companyType != "" {
  6942. // condition += ` AND b.product_name=? `
  6943. // pars = append(pars, companyType)
  6944. // }
  6945. //
  6946. // if industryId > 0 {
  6947. // condition += ` AND b.industry_id=? `
  6948. // pars = append(pars, industryId)
  6949. // }
  6950. //
  6951. // if adminId != "" {
  6952. // condition += ` AND b.seller_id IN (` + adminId + `) `
  6953. // }
  6954. //
  6955. // if startDate != "" {
  6956. // condition += ` AND b.start_date>=? `
  6957. // pars = append(pars, startDate)
  6958. // }
  6959. //
  6960. // if endDate != "" {
  6961. // condition += ` AND b.end_date>=? `
  6962. // pars = append(pars, endDate)
  6963. // }
  6964. //
  6965. // if keyWord != "" {
  6966. // condition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR c.mobile LIKE '%` + keyWord + `%' OR c.email LIKE '%` + keyWord + `%') `
  6967. // }
  6968. //
  6969. // if chartPermissionIds != "" {
  6970. // companyIdStr, err := company.GetCompanyIdStr(chartPermissionIds)
  6971. // if err != nil {
  6972. // br.Msg = "获取失败"
  6973. // br.ErrMsg = "根据权限获取公司ID失败,Err:" + err.Error()
  6974. // return
  6975. // }
  6976. // if companyIdStr != "" {
  6977. // condition += ` AND a.company_id IN (` + companyIdStr + `) `
  6978. // }
  6979. // }
  6980. //
  6981. // //权限控制
  6982. // {
  6983. // if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER ||
  6984. // roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER {
  6985. // if status != utils.COMPANY_STATUS_LOSE && status != utils.COMPANY_STATUS_FOREVER {
  6986. // condition += ` AND b.seller_id=? `
  6987. // pars = append(pars, sysUser.AdminId)
  6988. // }
  6989. // }
  6990. // if sysUser.Authority == 1 {
  6991. // condition += ` AND b.department_id=? `
  6992. // pars = append(pars, sysUser.DepartmentId)
  6993. // }
  6994. //
  6995. // if sysUser.Authority == 2 {
  6996. // condition += ` AND b.group_id=? `
  6997. // pars = append(pars, sysUser.GroupId)
  6998. // }
  6999. // }
  7000. // companyIds, err := company.GetExportCompanyIds(condition, pars)
  7001. // if err != nil {
  7002. // br.Msg = "导出失败"
  7003. // br.ErrMsg = "导出失败,Err:" + err.Error()
  7004. // return
  7005. // }
  7006. //
  7007. // dir, err := os.Executable()
  7008. // exPath := filepath.Dir(dir)
  7009. //
  7010. // downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  7011. // xlsxFile := xlsx.NewFile()
  7012. // if err != nil {
  7013. // br.Msg = "生成文件失败"
  7014. // br.ErrMsg = "生成文件失败"
  7015. // return
  7016. // }
  7017. // style := xlsx.NewStyle()
  7018. // alignment := xlsx.Alignment{
  7019. // Horizontal: "center",
  7020. // Vertical: "center",
  7021. // WrapText: true,
  7022. // }
  7023. //
  7024. // style.Alignment = alignment
  7025. // style.ApplyAlignment = true
  7026. //
  7027. // sheel, err := xlsxFile.AddSheet("联系人数据")
  7028. // if err != nil {
  7029. // br.Msg = "新增Sheet失败"
  7030. // br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  7031. // return
  7032. // }
  7033. //
  7034. // sheel.SetColWidth(7, 7, 10)
  7035. // sheel.SetColWidth(8, 10, 16)
  7036. // sheel.SetColWidth(9, 11, 20)
  7037. // sheel.SetColWidth(12, 12, 35)
  7038. // sheel.SetColWidth(13, 13, 15)
  7039. // sheel.SetColWidth(14, 14, 80)
  7040. // titleRow := sheel.AddRow()
  7041. // titleRow.AddCell().SetValue("联系人")
  7042. // titleRow.AddCell().SetValue("手机号")
  7043. // titleRow.AddCell().SetValue("邮箱")
  7044. // titleRow.AddCell().SetValue("职位")
  7045. // titleRow.AddCell().SetValue("是否决策人")
  7046. // titleRow.AddCell().SetValue("客户部门")
  7047. // titleRow.AddCell().SetValue("客户名称")
  7048. // titleRow.AddCell().SetValue("社会信用码")
  7049. // titleRow.AddCell().SetValue("所属区域")
  7050. // titleRow.AddCell().SetValue("客户类型")
  7051. //
  7052. // industryCell := titleRow.AddCell()
  7053. // industryCell.SetStyle(style)
  7054. // industryCell.Value = "所属行业"
  7055. //
  7056. // sellerCell := titleRow.AddCell()
  7057. // sellerCell.SetStyle(style)
  7058. // sellerCell.Value = "所属销售"
  7059. //
  7060. // statusCell := titleRow.AddCell()
  7061. // statusCell.SetStyle(style)
  7062. // statusCell.Value = "客户状态"
  7063. //
  7064. // timeLimtCell := titleRow.AddCell()
  7065. // timeLimtCell.SetStyle(style)
  7066. // timeLimtCell.Value = "服务期限"
  7067. //
  7068. // createTimeCell := titleRow.AddCell()
  7069. // createTimeCell.SetStyle(style)
  7070. // createTimeCell.Value = "创建时间"
  7071. //
  7072. // sourceCell := titleRow.AddCell()
  7073. // sourceCell.SetStyle(style)
  7074. // sourceCell.Value = "客户来源"
  7075. //
  7076. // permissionStyle := xlsx.NewStyle()
  7077. // permissionAlignment := xlsx.Alignment{
  7078. // Horizontal: "center",
  7079. // Vertical: "center",
  7080. // WrapText: true,
  7081. // }
  7082. //
  7083. // permissionStyle.Alignment = permissionAlignment
  7084. // permissionStyle.ApplyAlignment = true
  7085. //
  7086. // permissionCell := titleRow.AddCell()
  7087. // permissionCell.SetStyle(permissionStyle)
  7088. // permissionCell.Value = "阅读权限"
  7089. //
  7090. // if companyIds != "" {
  7091. // companyIds = strings.Trim(companyIds, ",")
  7092. // users, err := company.GetExportUser(companyIds)
  7093. // if err != nil {
  7094. // br.Msg = "导出失败"
  7095. // br.ErrMsg = "获取联系人信息失败,Err:" + err.Error()
  7096. // return
  7097. // }
  7098. // cpMap := make(map[int][]*company.ExportCompanyProduct)
  7099. // permissionMap := make(map[string]string)
  7100. // for _, v := range users {
  7101. // dataRow := sheel.AddRow()
  7102. // dataRow.SetHeight(20)
  7103. // dataRow.AddCell().SetString(v.RealName)
  7104. // dataRow.AddCell().SetString(v.Mobile)
  7105. // dataRow.AddCell().SetString(v.Email)
  7106. // dataRow.AddCell().SetString(v.Position)
  7107. // if v.IsMaker == 1 {
  7108. // dataRow.AddCell().SetString("是")
  7109. // } else {
  7110. // dataRow.AddCell().SetString("否")
  7111. // }
  7112. // dataRow.AddCell().SetString(v.DepartmentName)
  7113. // cpList := make([]*company.ExportCompanyProduct, 1)
  7114. // if cps, ok := cpMap[v.CompanyId]; ok {
  7115. // cpList = cps
  7116. // } else {
  7117. // companyProduct, err := company.GetExportCompanyProduct(v.CompanyId)
  7118. // if err != nil {
  7119. // br.Msg = "导出失败"
  7120. // br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  7121. // return
  7122. // }
  7123. // cpMap[v.CompanyId] = companyProduct
  7124. // cpList = companyProduct
  7125. // }
  7126. // //productList, err := company.GetExportCompanyProduct(v.CompanyId)
  7127. // //if err!=nil {
  7128. // // fmt.Println("导出失败,Err:"+err.Error())
  7129. // // return
  7130. // //}
  7131. // var companyName, companyType, industryName, sellerName, status, timeLimt, createTime, source, permissionStr, creditCode, regionType string
  7132. //
  7133. // for ck, cv := range cpList {
  7134. // companyName = cv.CompanyName
  7135. // creditCode = cv.CreditCode
  7136. // regionType = cv.RegionType
  7137. // if ck >= 1 {
  7138. // companyType = companyType + "/" + cv.ProductName
  7139. // status = status + "/" + cv.Status
  7140. // } else {
  7141. // companyType = cv.ProductName
  7142. // status = cv.Status
  7143. // }
  7144. // if cv.ProductId == 1 {
  7145. // industryName = "ficc:" + cv.IndustryName
  7146. // sellerName = "ficc:" + cv.SellerName
  7147. // startDateStr := cv.StartDate.Format("2006/01/02")
  7148. // endDateStr := cv.EndDate.Format("2006/01/02")
  7149. // if startDateStr != "0001/01/01" {
  7150. // timeLimt = "ficc:" + startDateStr + "~" + endDateStr
  7151. // } else {
  7152. // timeLimt = ""
  7153. // }
  7154. // createTime = "ficc:" + cv.CreateTime
  7155. // source = "ficc:" + cv.Source
  7156. // permissionKey := strconv.Itoa(v.CompanyId) + "_" + strconv.Itoa(cv.ProductId)
  7157. //
  7158. // permissionStr = "ficc:"
  7159. // if newPermissionStr, ok := permissionMap[permissionKey]; ok {
  7160. // permissionStr += newPermissionStr
  7161. // } else {
  7162. // getPermissionStr, err := company.GetExportPermissionName(v.CompanyId, cv.ProductId)
  7163. // if err != nil {
  7164. // br.Msg = "导出失败"
  7165. // br.ErrMsg = "获取客户权限信息失败,Err:" + err.Error()
  7166. // return
  7167. // }
  7168. // permissionMap[permissionKey] = getPermissionStr
  7169. // permissionStr += getPermissionStr
  7170. // }
  7171. // if cv.Status == utils.COMPANY_STATUS_LOSE {
  7172. // permissionStr = ""
  7173. // }
  7174. // } else {
  7175. // industryName = industryName + "\n" + "权益:" + cv.IndustryName
  7176. // sellerName = sellerName + "\n" + "权益:" + cv.SellerName
  7177. // startDateStr := cv.StartDate.Format("2006/01/02")
  7178. // endDateStr := cv.EndDate.Format("2006/01/02")
  7179. //
  7180. // if startDateStr != "0001/01/01" {
  7181. // timeLimt = timeLimt + "\n" + "权益:" + startDateStr + "~" + endDateStr
  7182. // } else {
  7183. // timeLimt = timeLimt + ""
  7184. // }
  7185. // createTime = createTime + "\n" + "权益:" + cv.CreateTime
  7186. // source = source + "\n" + "权益:" + cv.Source
  7187. //
  7188. // permissionKey := strconv.Itoa(v.CompanyId) + "_" + strconv.Itoa(cv.ProductId)
  7189. // if permissionStr != "" {
  7190. // permissionStr = permissionStr + "\n" + "权益:"
  7191. // } else {
  7192. // permissionStr = "权益:"
  7193. // }
  7194. // if newPermissionStr, ok := permissionMap[permissionKey]; ok {
  7195. // permissionStr += newPermissionStr
  7196. // } else {
  7197. // getPermissionStr, err := company.GetExportPermissionName(v.CompanyId, cv.ProductId)
  7198. // if err != nil {
  7199. // br.Msg = "导出失败"
  7200. // br.ErrMsg = "获取客户权限信息失败,Err:" + err.Error()
  7201. // return
  7202. // }
  7203. // permissionMap[permissionKey] = getPermissionStr
  7204. // permissionStr += getPermissionStr
  7205. // }
  7206. // if cv.Status == utils.COMPANY_STATUS_LOSE {
  7207. // permissionStr = permissionStr + ""
  7208. // }
  7209. // }
  7210. // }
  7211. // dataRow.AddCell().SetString(companyName)
  7212. // dataRow.AddCell().SetString(creditCode)
  7213. // dataRow.AddCell().SetString(regionType)
  7214. //
  7215. // dataRow.AddCell().SetString(companyType)
  7216. // industryValueCell := dataRow.AddCell()
  7217. // industryValueCell.SetStyle(style)
  7218. // industryValueCell.SetString(industryName)
  7219. //
  7220. // sellerValueCell := dataRow.AddCell()
  7221. // sellerValueCell.SetStyle(style)
  7222. // sellerValueCell.SetString(sellerName)
  7223. //
  7224. // statusValueCell := dataRow.AddCell()
  7225. // statusValueCell.SetStyle(style)
  7226. // statusValueCell.SetValue(status)
  7227. //
  7228. // timeLimitValueCell := dataRow.AddCell()
  7229. // timeLimitValueCell.SetStyle(style)
  7230. // timeLimitValueCell.SetValue(timeLimt)
  7231. //
  7232. // createTimeValueCell := dataRow.AddCell()
  7233. // createTimeValueCell.SetStyle(style)
  7234. // createTimeValueCell.SetValue(createTime)
  7235. //
  7236. // sourceValueCell := dataRow.AddCell()
  7237. // sourceValueCell.SetStyle(style)
  7238. // sourceValueCell.SetValue(source)
  7239. //
  7240. // permissionStrValueCell := dataRow.AddCell()
  7241. // permissionStrValueCell.SetStyle(style)
  7242. // permissionStrValueCell.SetValue(permissionStr)
  7243. // }
  7244. // }
  7245. // err = xlsxFile.Save(downLoadnFilePath)
  7246. // if err != nil {
  7247. // br.Msg = "保存文件失败"
  7248. // br.ErrMsg = "保存文件失败"
  7249. // return
  7250. // }
  7251. // randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
  7252. // downloadFileName := "联系人列表" + randStr + ".xlsx"
  7253. // this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  7254. // defer func() {
  7255. // os.Remove(downLoadnFilePath)
  7256. // }()
  7257. // br.Ret = 200
  7258. // br.Success = true
  7259. // br.Msg = "导出成功"
  7260. //}
  7261. // @Title 冻结客户
  7262. // @Description 冻结客户接口
  7263. // @Param request body company.CompanyFreezeReq true "type json string"
  7264. // @Success Ret=200 冻结成功
  7265. // @router /freeze [post]
  7266. func (this *CompanyController) Freeze() {
  7267. br := new(models.BaseResponse).Init()
  7268. defer func() {
  7269. this.Data["json"] = br
  7270. this.ServeJSON()
  7271. }()
  7272. sysUser := this.SysUser
  7273. if sysUser == nil {
  7274. br.Msg = "请登录"
  7275. br.ErrMsg = "请登录,SysUser Is Empty"
  7276. br.Ret = 408
  7277. return
  7278. }
  7279. var req company.CompanyFreezeReq
  7280. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  7281. if err != nil {
  7282. br.Msg = "参数解析异常!"
  7283. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  7284. return
  7285. }
  7286. if req.CompanyId <= 0 {
  7287. br.Msg = "参数错误!"
  7288. br.ErrMsg = "客户id小于等于0"
  7289. return
  7290. }
  7291. productId := 0
  7292. productName := ""
  7293. if req.CompanyType == utils.COMPANY_CLASSIFY_FICC {
  7294. productId = 1
  7295. productName = "ficc"
  7296. } else if req.CompanyType == utils.COMPANY_CLASSIFY_RAI {
  7297. productId = 2
  7298. productName = "权益"
  7299. } else {
  7300. productId = 3
  7301. productName = "佣金客户"
  7302. }
  7303. if req.CompanyId <= 0 {
  7304. br.Msg = "参数异常!"
  7305. br.ErrMsg = "CompanyId:" + strconv.Itoa(req.CompanyId)
  7306. return
  7307. }
  7308. cp, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, productId)
  7309. if err != nil {
  7310. br.Msg = "查询该客户产品异常!"
  7311. br.ErrMsg = "查询该客户产品异常,err:" + err.Error()
  7312. return
  7313. }
  7314. if cp.Status != utils.COMPANY_STATUS_TRY_OUT {
  7315. br.Msg = "客户状态为:" + cp.Status + ";不可冻结"
  7316. br.ErrMsg = "客户状态为:" + cp.Status + ";不可冻结"
  7317. return
  7318. }
  7319. //查询客户的产品权限
  7320. companyReportPermissionList, err := company.GetCompanyReportPermission(req.CompanyId, productId)
  7321. if err != nil {
  7322. br.Msg = "查询客户的产品权限异常"
  7323. br.ErrMsg = "查询客户的产品权限异常:" + err.Error()
  7324. return
  7325. }
  7326. err = company.CompanyFreeze(req.CompanyId, productId, req.Remark)
  7327. if err != nil {
  7328. br.Msg = "冻结失败!"
  7329. br.ErrMsg = "冻结失败,Err:" + err.Error()
  7330. return
  7331. }
  7332. //新增操作记录
  7333. {
  7334. approveContent := req.Remark
  7335. remark := "冻结客户"
  7336. operation := "freeze"
  7337. services.AddCompanyOperationRecord(req.CompanyId, cp.SellerId, sysUser.AdminId, productId, sysUser.AdminId, cp.CompanyName,
  7338. productName, sysUser.RealName, remark, operation, approveContent, sysUser.RealName, "", "冻结")
  7339. //新增产品权限冻结操作日志
  7340. for _, companyReportPermission := range companyReportPermissionList {
  7341. record := company_report_permission_log.CompanyReportPermissionLog{
  7342. CompanyReportPermissionId: companyReportPermission.CompanyReportPermissionId,
  7343. CompanyId: companyReportPermission.CompanyId,
  7344. ProductId: productId,
  7345. ProductName: companyReportPermission.ProductName,
  7346. SysUserId: sysUser.AdminId,
  7347. SysUserName: sysUser.RealName,
  7348. Remark: "冻结客户",
  7349. Operation: "freeze",
  7350. Status: companyReportPermission.Status,
  7351. CreateTime: time.Now(),
  7352. }
  7353. _, err = company_report_permission_log.AddCompanyReportPermissionLog(&record)
  7354. }
  7355. }
  7356. br.Ret = 200
  7357. br.Success = true
  7358. br.Msg = "领取成功"
  7359. }
  7360. // @Title 获取客户权限
  7361. // @Description 获取客户权限接口
  7362. // @Param CompanyId query int true "用户id"
  7363. // @Success 200 {object} company.CompanyPermissionResp
  7364. // @router /getCompanyPermission [get]
  7365. func (this *CompanyController) PermissionList() {
  7366. br := new(models.BaseResponse).Init()
  7367. defer func() {
  7368. this.Data["json"] = br
  7369. this.ServeJSON()
  7370. }()
  7371. sysUser := this.SysUser
  7372. if sysUser == nil {
  7373. br.Msg = "请登录"
  7374. br.ErrMsg = "请登录,SysUser Is Empty"
  7375. br.Ret = 408
  7376. return
  7377. }
  7378. companyId, _ := this.GetInt("CompanyId")
  7379. if companyId <= 0 {
  7380. br.Msg = "参数错误"
  7381. br.ErrMsg = "客户参数小于等于0"
  7382. return
  7383. }
  7384. //返回基础参数
  7385. resp := new(company.CompanyPermissionResp)
  7386. //客户类型map
  7387. classifyMap := make(map[string]int)
  7388. classifyMap["ficc"] = 1
  7389. classifyMap["权益"] = 2
  7390. roleTypeCode := sysUser.RoleTypeCode
  7391. var companySlice []string
  7392. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN ||
  7393. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN ||
  7394. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER ||
  7395. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP ||
  7396. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_TEAM ||
  7397. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_DEPARTMENT ||
  7398. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_RESEARCHR {
  7399. companySlice = append(companySlice, "ficc")
  7400. } else if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN ||
  7401. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN ||
  7402. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER ||
  7403. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP ||
  7404. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_DEPARTMENT ||
  7405. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_RESEARCHR {
  7406. companySlice = append(companySlice, "权益")
  7407. }
  7408. for _, companyType := range companySlice {
  7409. //子权限切片集合
  7410. //var permissionClassifyArr []string
  7411. var permissionProductId int
  7412. if companyType == "ficc" {
  7413. permissionProductId = utils.COMPANY_PRODUCT_FICC_ID
  7414. } else {
  7415. permissionProductId = utils.COMPANY_PRODUCT_RAI_ID
  7416. }
  7417. //子权限切片集合
  7418. permissionClassifyArr, err := models.GetPermissionFirstByProductId(permissionProductId)
  7419. if err != nil {
  7420. br.Msg = "获取失败"
  7421. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  7422. return
  7423. }
  7424. //遍历获取
  7425. for _, v := range permissionClassifyArr {
  7426. checkList := make([]int, 0)
  7427. plist := new(company.PermissionLookList)
  7428. plist.Items = make([]*company.PermissionLookItem, 0)
  7429. items, err := company.GetPermissionLookItemsByParentId(classifyMap[companyType], v.ChartPermissionId)
  7430. if err != nil {
  7431. br.Msg = "获取失败"
  7432. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  7433. return
  7434. }
  7435. mapPermissionCheck := make(map[string]int)
  7436. for i, n := range items {
  7437. item := items[i]
  7438. count, err := company.GetCompanyPermissionCheck(companyId, n.ChartPermissionId)
  7439. if err != nil {
  7440. br.Msg = "获取失败"
  7441. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  7442. return
  7443. }
  7444. //合并主观客观勾选的权限
  7445. if count > 0 && mapPermissionCheck[n.PermissionName] == 0 {
  7446. checkList = append(checkList, n.ChartPermissionId)
  7447. mapPermissionCheck[n.PermissionName] = n.ChartPermissionId
  7448. }
  7449. permission, err := company.GetCompanyPermissionCheckItem(companyId, n.ChartPermissionId)
  7450. if err != nil && err.Error() != utils.ErrNoRow() {
  7451. br.Msg = "获取失败"
  7452. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  7453. return
  7454. }
  7455. if permission != nil && permission.ChartPermissionId > 0 {
  7456. items[i].StartDate = permission.StartDate
  7457. items[i].EndDate = permission.EndDate
  7458. items[i].Status = permission.Status
  7459. //判断主观、客观
  7460. if items[i].PermissionType == 1 {
  7461. items[i].PermissionTypeName = "主观"
  7462. } else if items[i].PermissionType == 2 {
  7463. items[i].PermissionTypeName = "客观"
  7464. }
  7465. }
  7466. endDateTime, _ := time.Parse(utils.FormatDate, item.EndDate)
  7467. endDateTime = endDateTime.AddDate(0, 0, 1)
  7468. sub := endDateTime.Sub(time.Now())
  7469. if sub < 0 {
  7470. sub = 0
  7471. }
  7472. expireDay := fmt.Sprintf("%v", int(sub.Hours()/24))
  7473. items[i].ExpireDay = expireDay
  7474. items[i].ClassifyName = v.PermissionName
  7475. //if n.PermissionType == 1 {
  7476. // items[i].PermissionTypeName = "主观"
  7477. //} else if n.PermissionType == 2 {
  7478. // items[i].PermissionTypeName = "客观"
  7479. //}
  7480. }
  7481. //合并主观客观
  7482. mapPermissionName := make(map[string]int)
  7483. for _, v := range items {
  7484. if mapPermissionName[v.PermissionName] == 0 {
  7485. //plist.Items = append(plist.Items, v)
  7486. //mapPermissionName[v.PermissionName] = v.ChartPermissionId
  7487. // CRM8.8-只有客观的时候回显
  7488. if mapPermissionCheck[v.PermissionName] == 0 || (mapPermissionCheck[v.PermissionName] > 0 && v.ChartPermissionId == mapPermissionCheck[v.PermissionName]) {
  7489. plist.Items = append(plist.Items, v)
  7490. mapPermissionName[v.PermissionName] = v.ChartPermissionId
  7491. }
  7492. }
  7493. }
  7494. plist.ClassifyName = v.PermissionName
  7495. plist.CheckList = checkList
  7496. if companyType == "ficc" {
  7497. resp.FiccPermissionList = append(resp.FiccPermissionList, plist)
  7498. } else {
  7499. resp.PermissionList = append(resp.PermissionList, plist)
  7500. }
  7501. }
  7502. }
  7503. br.Ret = 200
  7504. br.Success = true
  7505. br.Msg = "获取成功"
  7506. br.Data = resp
  7507. }
  7508. // @Title 获取客户来源列表
  7509. // @Description 获取客户来源列表
  7510. // @Success 200 {object} models.CompanySourceListResp
  7511. // @router /getCompanySourceList [get]
  7512. func (this *CompanyController) CompanySourceList() {
  7513. br := new(models.BaseResponse).Init()
  7514. defer func() {
  7515. this.Data["json"] = br
  7516. this.ServeJSON()
  7517. }()
  7518. sysUser := this.SysUser
  7519. if sysUser == nil {
  7520. br.Msg = "请登录"
  7521. br.ErrMsg = "请登录,SysUser Is Empty"
  7522. br.Ret = 408
  7523. return
  7524. }
  7525. list, err := models.GetAllCompanySourceList()
  7526. if err != nil {
  7527. br.Msg = "查询失败"
  7528. br.ErrMsg = "查询异常:" + err.Error()
  7529. return
  7530. }
  7531. br.Ret = 200
  7532. br.Success = true
  7533. br.Msg = "获取成功"
  7534. br.Data = models.CompanySourceListResp{
  7535. List: list,
  7536. }
  7537. }
  7538. // @Title 获取客户的合同列表
  7539. // @Description 获取客户合同列表接口
  7540. // @Param CompanyId query int true "用户id"
  7541. // @Param CompanyType query string false "用户类型:可取范围:ficc,权益"
  7542. // @Param Status query int true "合同审核结果,枚举值:`0`,`1`; 0:待审核,1:审核通过"
  7543. // @Success 200 {object} company.CompanyPermissionResp
  7544. // @router /getCompanyContract [get]
  7545. func (this *CompanyController) ContractList() {
  7546. br := new(models.BaseResponse).Init()
  7547. defer func() {
  7548. this.Data["json"] = br
  7549. this.ServeJSON()
  7550. }()
  7551. sysUser := this.SysUser
  7552. if sysUser == nil {
  7553. br.Msg = "请登录"
  7554. br.ErrMsg = "请登录,SysUser Is Empty"
  7555. br.Ret = 408
  7556. return
  7557. }
  7558. companyId, _ := this.GetInt("CompanyId")
  7559. if companyId <= 0 {
  7560. br.Msg = "参数错误"
  7561. br.ErrMsg = "客户参数小于等于0"
  7562. return
  7563. }
  7564. //合同状态
  7565. status, _ := this.GetInt("Status")
  7566. //产品类型
  7567. companyType := this.GetString("CompanyType")
  7568. var condition string
  7569. var pars []interface{}
  7570. //产品类型
  7571. if companyType == "" {
  7572. productId := services.GetProductId(sysUser.RoleTypeCode)
  7573. if productId != 0 {
  7574. condition += " AND product_id = ?"
  7575. pars = append(pars, productId)
  7576. }
  7577. } else {
  7578. if companyType == "ficc" {
  7579. condition += " AND product_id = ?"
  7580. pars = append(pars, 1)
  7581. } else {
  7582. condition += " AND product_id = ?"
  7583. pars = append(pars, 2)
  7584. }
  7585. }
  7586. if status != 0 {
  7587. condition += " AND status = ?"
  7588. pars = append(pars, status)
  7589. }
  7590. list, err := company.GetCompanyContractListByCompanyId(companyId, condition, pars)
  7591. if err != nil {
  7592. br.Msg = "查询失败"
  7593. br.ErrMsg = "查询异常:" + err.Error()
  7594. return
  7595. }
  7596. br.Ret = 200
  7597. br.Success = true
  7598. br.Msg = "获取成功"
  7599. br.Data = list
  7600. }
  7601. // @Title 获取客户所属销售
  7602. // @Description 根据客户id获取客户所属销售
  7603. // @Param CompanyId query int true "客户id"
  7604. // @Success 200 {object} response.CompanySellerListResp
  7605. // @router /getCompanySellerList [get]
  7606. func (this *CompanyUserController) GetCompanySellerList() {
  7607. br := new(models.BaseResponse).Init()
  7608. defer func() {
  7609. this.Data["json"] = br
  7610. this.ServeJSON()
  7611. }()
  7612. sysUser := this.SysUser
  7613. if sysUser == nil {
  7614. br.Msg = "请登录"
  7615. br.ErrMsg = "请登录,SysUser Is Empty"
  7616. br.Ret = 408
  7617. return
  7618. }
  7619. companyId, _ := this.GetInt("CompanyId")
  7620. //item := make([]*company.CompanyItem, 0)
  7621. list, err := company.GetCompanySellerByCompanyId(companyId)
  7622. if err != nil && err.Error() != utils.ErrNoRow() {
  7623. br.Msg = "获取失败"
  7624. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  7625. return
  7626. }
  7627. resp := response.CompanySellerListResp{
  7628. List: list,
  7629. }
  7630. //resp.List = list
  7631. br.Ret = 200
  7632. br.Success = true
  7633. br.Msg = "获取成功"
  7634. br.Data = resp
  7635. }
  7636. // GetTryOutCompanyList
  7637. // @Title 获取销售今日待办数据
  7638. // @Description 获取销售今日待办接口
  7639. // @Param CompanyName query string false "客户名称"
  7640. // @Param ReasonStatus query int false "续约情况说明状态:-1:未填写,0:全部,1:已填写"
  7641. // @Param PageSize query int true "每页数据条数"
  7642. // @Param CurrentIndex query int true "当前页页码,从1开始"
  7643. // @Success 200 {object} response.TryOutCompanyListResp
  7644. // @router /getTryOutCompanyList [get]
  7645. func (this *CompanyController) GetTryOutCompanyList() {
  7646. br := new(models.BaseResponse).Init()
  7647. defer func() {
  7648. this.Data["json"] = br
  7649. this.ServeJSON()
  7650. }()
  7651. sysUser := this.SysUser
  7652. if sysUser == nil {
  7653. br.Msg = "请登录"
  7654. br.ErrMsg = "请登录,SysUser Is Empty"
  7655. br.Ret = 408
  7656. return
  7657. }
  7658. companyName := this.GetString("CompanyName")
  7659. reasonStatus, _ := this.GetInt("ReasonStatus", 0)
  7660. pageSize, _ := this.GetInt("PageSize")
  7661. currentIndex, _ := this.GetInt("CurrentIndex")
  7662. productId := services.GetProductId(sysUser.RoleTypeCode)
  7663. var startSize int
  7664. if pageSize <= 0 {
  7665. pageSize = utils.PageSize20
  7666. }
  7667. if currentIndex <= 0 {
  7668. currentIndex = 1
  7669. }
  7670. startSize = paging.StartIndex(currentIndex, pageSize)
  7671. var condition string
  7672. var pars []interface{}
  7673. //sellerId, productId int, tryOutTime time.Time, tryOutReason string
  7674. var tryOutTime, lastDescriptionTime time.Time
  7675. if productId == 1 {
  7676. //ficc
  7677. interval := cache.GetIntervalFromCrmConfig("try_out_time_intervals")
  7678. tryOutTime = time.Now().AddDate(0, 0, -interval)
  7679. interval = cache.GetIntervalFromCrmConfig("last_description_time_intervals")
  7680. lastDescriptionTime = time.Now().AddDate(0, 0, -interval)
  7681. } else {
  7682. //权益
  7683. interval := cache.GetIntervalFromCrmConfig("rai_try_out_time_intervals")
  7684. tryOutTime = time.Now().AddDate(0, 0, -interval)
  7685. interval = cache.GetIntervalFromCrmConfig("rai_last_description_time_intervals")
  7686. lastDescriptionTime = time.Now().AddDate(0, 0, -interval)
  7687. }
  7688. if productId > 0 {
  7689. condition += ` and product_id=? `
  7690. pars = append(pars, productId)
  7691. }
  7692. //客户名称模糊搜索
  7693. if companyName != "" {
  7694. condition += ` and b.company_name like "%` + companyName + `%" `
  7695. }
  7696. //续约情况说明(-1:未填写,0:全部,1:已填写)
  7697. switch reasonStatus {
  7698. case -1:
  7699. condition += ` and seller_id=? and try_out_time <=? and (last_description_time <=? OR last_description_time IS NULL) and (renewal_intention is NULL or renewal_reason is NULL or renewal_intention = 0) and (freeze_time='' OR freeze_time IS NULL) `
  7700. pars = append(pars, sysUser.AdminId, tryOutTime, lastDescriptionTime)
  7701. case 1:
  7702. condition += ` and seller_id=? and try_out_time <= ? and (renewal_intention is NULL or renewal_reason is NULL or renewal_intention = 0) and (freeze_time='' OR freeze_time IS NULL) `
  7703. pars = append(pars, sysUser.AdminId, tryOutTime)
  7704. default:
  7705. condition += ` and seller_id=? and (try_out_time <= ? or last_description_time <= ?) and (renewal_intention is NULL or renewal_reason is NULL or renewal_intention = 0) and (freeze_time='' OR freeze_time IS NULL) `
  7706. pars = append(pars, sysUser.AdminId, tryOutTime, lastDescriptionTime)
  7707. }
  7708. total := 0
  7709. list := make([]*company.TryOutCompanyList, 0)
  7710. ignoreStrs := []string{utils.ROLE_TYPE_CODE_FICC_SELLER, utils.ROLE_TYPE_CODE_RAI_SELLER, utils.ROLE_TYPE_CODE_FICC_GROUP, utils.ROLE_TYPE_CODE_FICC_TEAM, utils.ROLE_TYPE_CODE_RAI_GROUP}
  7711. if strings.Contains(strings.Join(ignoreStrs, ","), sysUser.RoleTypeCode) {
  7712. //排除已经签署续约合同的
  7713. notSql := ``
  7714. if productId > 0 {
  7715. notSql = fmt.Sprint(` and product_id = `, productId)
  7716. }
  7717. condition += `and a.company_id not in (select company_id from company_contract where contract_type ="续约合同" and start_date >now() and status = 1 ` + notSql + `) `
  7718. tmpTotal, err := company.GetTryOutCompanyCount(condition, pars)
  7719. if err != nil {
  7720. br.Msg = "获取失败"
  7721. br.ErrMsg = "获取总数失败失败,Err:" + err.Error()
  7722. return
  7723. }
  7724. tmpList, err := company.GetTryOutCompanyList(condition, pars, startSize, pageSize)
  7725. if err != nil {
  7726. br.Msg = "获取失败"
  7727. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  7728. return
  7729. }
  7730. total = tmpTotal
  7731. list = tmpList
  7732. }
  7733. if len(list) > 0 {
  7734. for k, item := range list {
  7735. endTime, _ := time.Parse(utils.FormatDate, item.EndDate)
  7736. endTime = endTime.AddDate(0, 0, 1)
  7737. sub := endTime.Sub(time.Now())
  7738. if sub < 0 {
  7739. sub = 0
  7740. }
  7741. list[k].ExpireDays = int(sub.Hours() / 24)
  7742. }
  7743. }
  7744. page := paging.GetPaging(currentIndex, pageSize, total)
  7745. resp := response.TryOutCompanyListResp{
  7746. List: list,
  7747. Paging: page,
  7748. }
  7749. br.Ret = 200
  7750. br.Success = true
  7751. br.Msg = "获取成功"
  7752. br.Data = resp
  7753. }
  7754. // EditTryOutCompanyReason
  7755. // @Title 编辑续约说明情况
  7756. // @Description 编辑续约说明情况接口
  7757. // @Param request body company.RenewalReasonReq true "type json string"
  7758. // @Success 200 编辑成功
  7759. // @router /editTryOutCompanyReason [post]
  7760. func (this *CompanyController) EditTryOutCompanyReason() {
  7761. br := new(models.BaseResponse).Init()
  7762. defer func() {
  7763. this.Data["json"] = br
  7764. this.ServeJSON()
  7765. }()
  7766. sysUser := this.SysUser
  7767. if sysUser == nil {
  7768. br.Msg = "请登录"
  7769. br.ErrMsg = "请登录,SysUser Is Empty"
  7770. br.Ret = 408
  7771. return
  7772. }
  7773. var req company.RenewalReasonReq
  7774. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  7775. if err != nil {
  7776. br.Msg = "参数解析异常!"
  7777. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  7778. return
  7779. }
  7780. if req.CompanyId <= 0 {
  7781. br.Msg = "参数缺失"
  7782. br.ErrMsg = "参数缺失,客户编号未传!"
  7783. return
  7784. }
  7785. if req.ProductId <= 0 {
  7786. br.Msg = "参数缺失"
  7787. br.ErrMsg = "参数缺失,产品编号未传!"
  7788. return
  7789. }
  7790. if req.Remark == "" {
  7791. br.Msg = "参数缺失"
  7792. br.ErrMsg = "参数缺失,续约情况说明未传!"
  7793. return
  7794. }
  7795. /*if req.RenewalTodo == "" && req.Renew == 0 {
  7796. br.Msg = "参数缺失"
  7797. br.ErrMsg = "参数缺失,待办事项说明未传!"
  7798. return
  7799. }*/
  7800. companyProduct, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, req.ProductId)
  7801. if err != nil {
  7802. br.Msg = "查询客户异常"
  7803. br.ErrMsg = "查询客户异常,Err:" + err.Error()
  7804. return
  7805. }
  7806. if companyProduct.SellerId != sysUser.AdminId {
  7807. br.Msg = "客户异常,没有该客户的操作权限"
  7808. br.ErrMsg = "客户异常,没有该客户的操作权限"
  7809. return
  7810. }
  7811. renewalReason := company.CompanyRenewalReason{
  7812. CompanyRenewalReasonId: 0,
  7813. CompanyId: companyProduct.CompanyId,
  7814. ProductId: companyProduct.ProductId,
  7815. ProductName: companyProduct.ProductName,
  7816. CompanyName: companyProduct.CompanyName,
  7817. TryOutTime: companyProduct.TryOutTime,
  7818. RenewalReason: req.Remark,
  7819. RenewalTodo: req.RenewalTodo,
  7820. LastDescriptionTime: companyProduct.LastDescriptionTime,
  7821. EndDays: companyProduct.ContractEndDate,
  7822. ExpirationTimeExceeded: 0,
  7823. RenewalIntention: req.Renew,
  7824. CreateTime: time.Now(),
  7825. }
  7826. endTime, err := company.GetTryOutTimeFromOperationRecord(renewalReason.CompanyId)
  7827. if err != nil {
  7828. br.Msg = "查询该客户转试用时间异常!"
  7829. br.ErrMsg = "查询该客户转试用时间异常,err:" + err.Error()
  7830. return
  7831. }
  7832. endDateTime, err := time.Parse(utils.FormatDateTime, *endTime)
  7833. if err != nil {
  7834. br.Msg = "时间格式化异常!"
  7835. br.ErrMsg = "时间格式化异常,err:" + err.Error()
  7836. return
  7837. }
  7838. endDate := endDateTime.Format(utils.FormatDate)
  7839. endDateTime, _ = time.Parse(utils.FormatDate, endDate)
  7840. sub := time.Now().Sub(endDateTime)
  7841. renewalReason.ExpirationTimeExceeded = int(sub.Hours() / 24)
  7842. var newId int64
  7843. newId, err = company.AddRenewalReason(&renewalReason)
  7844. if err != nil {
  7845. br.Msg = "新增续约情况说明操作异常!"
  7846. br.ErrMsg = "新增续约情况说明操作异常,err:" + err.Error()
  7847. return
  7848. }
  7849. companyProduct.RenewalIntention = req.Renew
  7850. err = company.EditTryOutCompanyReason(companyProduct, req.Remark, req.RenewalTodo)
  7851. if err != nil {
  7852. br.Msg = "更新客户未续约异常!"
  7853. br.ErrMsg = "更新客户未续约异常,err:" + err.Error()
  7854. return
  7855. }
  7856. if req.Renew == 1 {
  7857. productName := ""
  7858. if req.ProductId == 1 {
  7859. productName = "ficc"
  7860. } else if req.ProductId == 2 {
  7861. productName = "权益"
  7862. } else {
  7863. productName = "佣金客户"
  7864. }
  7865. cp, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, req.ProductId)
  7866. if err != nil {
  7867. br.Msg = "查询该客户产品异常!"
  7868. br.ErrMsg = "查询该客户产品异常,err:" + err.Error()
  7869. return
  7870. }
  7871. if cp.Status != utils.COMPANY_STATUS_TRY_OUT {
  7872. br.Msg = "客户状态为:" + cp.Status + ";不可冻结"
  7873. br.ErrMsg = "客户状态为:" + cp.Status + ";不可冻结"
  7874. return
  7875. }
  7876. //查询客户的产品权限
  7877. companyReportPermissionList, err := company.GetCompanyReportPermission(req.CompanyId, req.ProductId)
  7878. if err != nil {
  7879. br.Msg = "查询客户的产品权限异常"
  7880. br.ErrMsg = "查询客户的产品权限异常:" + err.Error()
  7881. return
  7882. }
  7883. err = company.CompanyFreeze(req.CompanyId, req.ProductId, req.Remark)
  7884. if err != nil {
  7885. br.Msg = "冻结失败!"
  7886. br.ErrMsg = "冻结失败,Err:" + err.Error()
  7887. return
  7888. }
  7889. //新增操作记录
  7890. go func() {
  7891. time.Sleep(time.Second)
  7892. approveContent := req.Remark
  7893. remark := "冻结客户"
  7894. operation := "freeze"
  7895. _ = services.AddCompanyOperationRecord(req.CompanyId, cp.SellerId, sysUser.AdminId, req.ProductId, sysUser.AdminId, cp.CompanyName,
  7896. productName, "超级管理员", remark, operation, approveContent, sysUser.RealName, "", "冻结")
  7897. //新增产品权限冻结操作日志
  7898. for _, companyReportPermission := range companyReportPermissionList {
  7899. record := company_report_permission_log.CompanyReportPermissionLog{
  7900. CompanyReportPermissionId: companyReportPermission.CompanyReportPermissionId,
  7901. CompanyId: companyReportPermission.CompanyId,
  7902. ProductId: req.ProductId,
  7903. ProductName: companyReportPermission.ProductName,
  7904. SysUserId: sysUser.AdminId,
  7905. SysUserName: "超级管理员",
  7906. Remark: "冻结客户",
  7907. Operation: "freeze",
  7908. Status: companyReportPermission.Status,
  7909. CreateTime: time.Now(),
  7910. }
  7911. _, err = company_report_permission_log.AddCompanyReportPermissionLog(&record)
  7912. }
  7913. }()
  7914. }
  7915. approveContent := req.Remark
  7916. approveContentExtra := req.RenewalTodo
  7917. remark := "新增续约说明"
  7918. operation := "edit_renewal_reason"
  7919. _ = services.AddCompanyOperationRecordMore(req.CompanyId, companyProduct.SellerId, sysUser.AdminId, companyProduct.ProductId, sysUser.AdminId, companyProduct.CompanyName,
  7920. companyProduct.ProductName, sysUser.RealName, remark, operation, approveContent, approveContentExtra, sysUser.RealName, "", companyProduct.Status)
  7921. items, err := company.ReadCompanyOperationRecord(req.CompanyId)
  7922. if err != nil {
  7923. br.Msg = "编辑失败"
  7924. br.ErrMsg = "编辑失败,Err:" + err.Error()
  7925. return
  7926. }
  7927. if len(items) > 0 {
  7928. record := new(company.CompanyOperationRecord)
  7929. record.Id = items[0].Id
  7930. record.ApproveContent = req.Remark
  7931. record.ApproveContentExtra = req.RenewalTodo
  7932. _, err = company.UpdateCompanyOperationRecord(record)
  7933. if err != nil {
  7934. br.Msg = "编辑失败"
  7935. br.ErrMsg = "编辑失败,Err:" + err.Error()
  7936. return
  7937. }
  7938. } else {
  7939. br.Msg = "编辑失败"
  7940. br.ErrMsg = "编辑失败,未查询到转试用记录"
  7941. return
  7942. }
  7943. if req.ProductId == utils.COMPANY_PRODUCT_RAI_ID {
  7944. //权益客户新增历史备注总表
  7945. itemRecord := new(company.CompanyHistoryRemark)
  7946. itemRecord.CompanyId = req.CompanyId
  7947. itemRecord.Content = req.Remark
  7948. itemRecord.SysAdminId = sysUser.AdminId
  7949. itemRecord.SysAdminName = sysUser.RealName
  7950. itemRecord.CreateTime = time.Now().Local()
  7951. itemRecord.ModifyTime = time.Now().Local()
  7952. itemRecord.ShowTime = time.Now().Local()
  7953. itemRecord.ProductId = 2
  7954. itemRecord.TableName = "company_renewal_reason"
  7955. itemRecord.TableId = int(newId)
  7956. go services.AddCompanyHistoryRemark(itemRecord)
  7957. }
  7958. br.Ret = 200
  7959. br.Success = true
  7960. br.Msg = "编辑成功"
  7961. }
  7962. // AddTryOutCompanyReason
  7963. // @Title 新增续约说明情况
  7964. // @Description 新增续约说明情况接口
  7965. // @Param request body company.RenewalReasonReq true "type json string"
  7966. // @Success 200 编辑成功
  7967. // @router /addTryOutCompanyReason [post]
  7968. func (this *CompanyController) AddTryOutCompanyReason() {
  7969. br := new(models.BaseResponse).Init()
  7970. defer func() {
  7971. this.Data["json"] = br
  7972. this.ServeJSON()
  7973. }()
  7974. sysUser := this.SysUser
  7975. if sysUser == nil {
  7976. br.Msg = "请登录"
  7977. br.ErrMsg = "请登录,SysUser Is Empty"
  7978. br.Ret = 408
  7979. return
  7980. }
  7981. var req company.RenewalReasonReq
  7982. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  7983. if err != nil {
  7984. br.Msg = "参数解析异常!"
  7985. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  7986. return
  7987. }
  7988. if req.CompanyId <= 0 {
  7989. br.Msg = "参数缺失"
  7990. br.ErrMsg = "参数缺失,客户编号未传!"
  7991. return
  7992. }
  7993. if req.ProductId <= 0 {
  7994. br.Msg = "参数缺失"
  7995. br.ErrMsg = "参数缺失,产品编号未传!"
  7996. return
  7997. }
  7998. if req.Remark == "" {
  7999. br.Msg = "参数缺失"
  8000. br.ErrMsg = "参数缺失,续约情况说明未传!"
  8001. return
  8002. }
  8003. if req.RenewalTodo == "" && req.Renew == 0 {
  8004. br.Msg = "参数缺失"
  8005. br.ErrMsg = "参数缺失,待办事项说明未传!"
  8006. return
  8007. }
  8008. companyProduct, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, req.ProductId)
  8009. if err != nil {
  8010. br.Msg = "查询客户异常"
  8011. br.ErrMsg = "查询客户异常,Err:" + err.Error()
  8012. return
  8013. }
  8014. if companyProduct.SellerId != sysUser.AdminId {
  8015. br.Msg = "客户异常,没有该客户的操作权限"
  8016. br.ErrMsg = "客户异常,没有该客户的操作权限"
  8017. return
  8018. }
  8019. renewalReason := company.CompanyRenewalReason{
  8020. CompanyRenewalReasonId: 0,
  8021. CompanyId: companyProduct.CompanyId,
  8022. ProductId: companyProduct.ProductId,
  8023. ProductName: companyProduct.ProductName,
  8024. CompanyName: companyProduct.CompanyName,
  8025. TryOutTime: companyProduct.TryOutTime,
  8026. RenewalReason: req.Remark,
  8027. RenewalTodo: req.RenewalTodo,
  8028. LastDescriptionTime: companyProduct.LastDescriptionTime,
  8029. EndDays: companyProduct.ContractEndDate,
  8030. ExpirationTimeExceeded: 0,
  8031. RenewalIntention: req.Renew,
  8032. CreateTime: time.Now(),
  8033. }
  8034. endTime, err := company.GetTryOutTimeFromOperationRecord(renewalReason.CompanyId)
  8035. if err != nil {
  8036. br.Msg = "查询该客户转试用时间异常!"
  8037. br.ErrMsg = "查询该客户转试用时间异常,err:" + err.Error()
  8038. return
  8039. }
  8040. endDateTime, err := time.Parse(utils.FormatDateTime, *endTime)
  8041. if err != nil {
  8042. br.Msg = "时间格式化异常!"
  8043. br.ErrMsg = "时间格式化异常,err:" + err.Error()
  8044. return
  8045. }
  8046. endDate := endDateTime.Format(utils.FormatDate)
  8047. endDateTime, _ = time.Parse(utils.FormatDate, endDate)
  8048. sub := time.Now().Sub(endDateTime)
  8049. renewalReason.ExpirationTimeExceeded = int(sub.Hours() / 24)
  8050. var newId int64
  8051. newId, err = company.AddRenewalReason(&renewalReason)
  8052. if err != nil {
  8053. br.Msg = "新增续约情况说明操作异常!"
  8054. br.ErrMsg = "新增续约情况说明操作异常,err:" + err.Error()
  8055. return
  8056. }
  8057. companyProduct.RenewalIntention = req.Renew
  8058. err = company.EditTryOutCompanyReason(companyProduct, req.Remark, req.RenewalTodo)
  8059. if err != nil {
  8060. br.Msg = "更新客户续约情况说明异常!"
  8061. br.ErrMsg = "更新客户续约情况说明异常,err:" + err.Error()
  8062. return
  8063. }
  8064. if req.Renew == 1 {
  8065. productName := ""
  8066. if req.ProductId == 1 {
  8067. productName = "ficc"
  8068. } else if req.ProductId == 2 {
  8069. productName = "权益"
  8070. } else {
  8071. productName = "佣金客户"
  8072. }
  8073. cp, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, req.ProductId)
  8074. if err != nil {
  8075. br.Msg = "查询该客户产品异常!"
  8076. br.ErrMsg = "查询该客户产品异常,err:" + err.Error()
  8077. return
  8078. }
  8079. if cp.Status != utils.COMPANY_STATUS_TRY_OUT {
  8080. br.Msg = "客户状态为:" + cp.Status + ";不可冻结"
  8081. br.ErrMsg = "客户状态为:" + cp.Status + ";不可冻结"
  8082. return
  8083. }
  8084. //查询客户的产品权限
  8085. companyReportPermissionList, err := company.GetCompanyReportPermission(req.CompanyId, req.ProductId)
  8086. if err != nil {
  8087. br.Msg = "查询客户的产品权限异常"
  8088. br.ErrMsg = "查询客户的产品权限异常:" + err.Error()
  8089. return
  8090. }
  8091. err = company.CompanyFreeze(req.CompanyId, req.ProductId, req.Remark)
  8092. if err != nil {
  8093. br.Msg = "冻结失败!"
  8094. br.ErrMsg = "冻结失败,Err:" + err.Error()
  8095. return
  8096. }
  8097. //新增操作记录
  8098. go func() {
  8099. time.Sleep(time.Second)
  8100. approveContent := req.Remark
  8101. remark := "冻结客户"
  8102. operation := "freeze"
  8103. _ = services.AddCompanyOperationRecord(req.CompanyId, cp.SellerId, sysUser.AdminId, req.ProductId, sysUser.AdminId, cp.CompanyName,
  8104. productName, "超级管理员", remark, operation, approveContent, sysUser.RealName, "", "冻结")
  8105. //新增产品权限冻结操作日志
  8106. for _, companyReportPermission := range companyReportPermissionList {
  8107. record := company_report_permission_log.CompanyReportPermissionLog{
  8108. CompanyReportPermissionId: companyReportPermission.CompanyReportPermissionId,
  8109. CompanyId: companyReportPermission.CompanyId,
  8110. ProductId: req.ProductId,
  8111. ProductName: companyReportPermission.ProductName,
  8112. SysUserId: sysUser.AdminId,
  8113. SysUserName: "超级管理员",
  8114. Remark: "冻结客户",
  8115. Operation: "freeze",
  8116. Status: companyReportPermission.Status,
  8117. CreateTime: time.Now(),
  8118. }
  8119. _, err = company_report_permission_log.AddCompanyReportPermissionLog(&record)
  8120. }
  8121. }()
  8122. }
  8123. {
  8124. approveContent := req.Remark
  8125. approveContentExtra := req.RenewalTodo
  8126. remark := "新增续约说明"
  8127. operation := "add_renewal_reason"
  8128. _ = services.AddCompanyOperationRecordMore(req.CompanyId, companyProduct.SellerId, sysUser.AdminId, companyProduct.ProductId, sysUser.AdminId, companyProduct.CompanyName,
  8129. companyProduct.ProductName, sysUser.RealName, remark, operation, approveContent, approveContentExtra, sysUser.RealName, "", companyProduct.Status)
  8130. }
  8131. if req.ProductId == utils.COMPANY_PRODUCT_RAI_ID {
  8132. //权益客户新增历史备注总表
  8133. itemRecord := new(company.CompanyHistoryRemark)
  8134. itemRecord.CompanyId = req.CompanyId
  8135. itemRecord.Content = req.Remark
  8136. itemRecord.SysAdminId = sysUser.AdminId
  8137. itemRecord.SysAdminName = sysUser.RealName
  8138. itemRecord.CreateTime = time.Now().Local()
  8139. itemRecord.ModifyTime = time.Now().Local()
  8140. itemRecord.ShowTime = time.Now().Local()
  8141. itemRecord.ProductId = 2
  8142. itemRecord.TableName = "company_renewal_reason"
  8143. itemRecord.TableId = int(newId)
  8144. go services.AddCompanyHistoryRemark(itemRecord)
  8145. }
  8146. br.Ret = 200
  8147. br.Success = true
  8148. br.Msg = "编辑成功"
  8149. }
  8150. // RenewReasonList 客户未续约说明历史列表
  8151. // @Title 客户未续约说明历史列表
  8152. // @Description 客户未续约说明历史列表
  8153. // @Param CompanyId query string true "客户id"
  8154. // @Param ProductId query string true "产品id"
  8155. // @Success 200 {object} response.RenewReasonItemResp
  8156. // @router /renewReasonList [get]
  8157. func (this *CompanyController) RenewReasonList() {
  8158. br := new(models.BaseResponse).Init()
  8159. defer func() {
  8160. this.Data["json"] = br
  8161. this.ServeJSON()
  8162. }()
  8163. sysUser := this.SysUser
  8164. if sysUser == nil {
  8165. br.Msg = "请登录"
  8166. br.ErrMsg = "请登录,SysUser Is Empty"
  8167. br.Ret = 408
  8168. return
  8169. }
  8170. CompanyId := this.GetString("CompanyId")
  8171. ProductId := this.GetString("ProductId")
  8172. if CompanyId == "" {
  8173. br.Msg = "请输入客户ID"
  8174. return
  8175. }
  8176. if ProductId != "1" && ProductId != "2" {
  8177. br.Msg = "请输入正确的产品ID"
  8178. return
  8179. }
  8180. renewalReason, err := models.GetMoreRenewalReason(CompanyId, ProductId)
  8181. if err != nil {
  8182. br.Msg = "获取失败"
  8183. br.ErrMsg = "获取失败,Err:" + err.Error()
  8184. return
  8185. }
  8186. resp := make([]response.RenewReasonItemResp, len(renewalReason))
  8187. for i, reason := range renewalReason {
  8188. createDate := reason.CreateTime.Format("2006.01.02 15:04:05")
  8189. resp[i].RenewalReason = reason.RenewalReason
  8190. resp[i].RenewalTodo = reason.RenewalTodo
  8191. resp[i].CreateTime = createDate
  8192. }
  8193. br.Ret = 200
  8194. br.Success = true
  8195. br.Msg = "获取成功"
  8196. br.Data = resp
  8197. }
  8198. // AddRenewalReason
  8199. // @Title 转试用按钮新增续约说明情况
  8200. // @Description 转试用按钮新增续约说明情况
  8201. // @Param request body company.TryOutReq true "type json string"
  8202. // @Success 200 编辑成功
  8203. // @router /addRenewalReason [post]
  8204. func (this *CompanyController) AddRenewalReason() {
  8205. br := new(models.BaseResponse).Init()
  8206. defer func() {
  8207. this.Data["json"] = br
  8208. this.ServeJSON()
  8209. }()
  8210. sysUser := this.SysUser
  8211. if sysUser == nil {
  8212. br.Msg = "请登录"
  8213. br.ErrMsg = "请登录,SysUser Is Empty"
  8214. br.Ret = 408
  8215. return
  8216. }
  8217. var req company.TryOutReq
  8218. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  8219. if err != nil {
  8220. br.Msg = "参数解析异常!"
  8221. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  8222. return
  8223. }
  8224. if req.CompanyId <= 0 {
  8225. br.Msg = "参数缺失"
  8226. br.ErrMsg = "参数缺失,客户编号未传!"
  8227. return
  8228. }
  8229. if req.ProductId <= 0 {
  8230. br.Msg = "参数缺失"
  8231. br.ErrMsg = "参数缺失,产品编号未传!"
  8232. return
  8233. }
  8234. if req.OperationId <= 0 {
  8235. br.Msg = "参数缺失"
  8236. br.ErrMsg = "参数缺失,操作记录表编号未传!"
  8237. return
  8238. }
  8239. if req.Remark == "" {
  8240. br.Msg = "参数缺失"
  8241. br.ErrMsg = "参数缺失,续约情况说明未传!"
  8242. return
  8243. }
  8244. if req.RenewalTodo == "" && req.Renew == 0 {
  8245. br.Msg = "参数缺失"
  8246. br.ErrMsg = "参数缺失,待办事项说明未传!"
  8247. return
  8248. }
  8249. companyProduct, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, req.ProductId)
  8250. if err != nil {
  8251. br.Msg = "查询客户异常"
  8252. br.ErrMsg = "查询客户异常,Err:" + err.Error()
  8253. return
  8254. }
  8255. if companyProduct.SellerId != sysUser.AdminId {
  8256. br.Msg = "客户异常,没有该客户的操作权限"
  8257. br.ErrMsg = "客户异常,没有该客户的操作权限"
  8258. return
  8259. }
  8260. renewalReason := company.CompanyRenewalReason{
  8261. CompanyRenewalReasonId: 0,
  8262. CompanyId: companyProduct.CompanyId,
  8263. ProductId: companyProduct.ProductId,
  8264. ProductName: companyProduct.ProductName,
  8265. CompanyName: companyProduct.CompanyName,
  8266. TryOutTime: companyProduct.TryOutTime,
  8267. RenewalReason: req.Remark,
  8268. RenewalTodo: req.RenewalTodo,
  8269. LastDescriptionTime: companyProduct.LastDescriptionTime,
  8270. EndDays: companyProduct.ContractEndDate,
  8271. ExpirationTimeExceeded: 0,
  8272. RenewalIntention: req.Renew,
  8273. CreateTime: time.Now(),
  8274. }
  8275. endTime, err := company.GetTryOutTimeFromOperationRecord(renewalReason.CompanyId)
  8276. if err != nil {
  8277. br.Msg = "查询该客户转试用时间异常!"
  8278. br.ErrMsg = "查询该客户转试用时间异常,err:" + err.Error()
  8279. return
  8280. }
  8281. endDateTime, err := time.Parse(utils.FormatDateTime, *endTime)
  8282. if err != nil {
  8283. br.Msg = "时间格式化异常!"
  8284. br.ErrMsg = "时间格式化异常,err:" + err.Error()
  8285. return
  8286. }
  8287. endDate := endDateTime.Format(utils.FormatDate)
  8288. endDateTime, _ = time.Parse(utils.FormatDate, endDate)
  8289. sub := time.Now().Sub(endDateTime)
  8290. renewalReason.ExpirationTimeExceeded = int(sub.Hours() / 24)
  8291. var newId int64
  8292. newId, err = company.AddRenewalReason(&renewalReason)
  8293. if err != nil {
  8294. br.Msg = "新增续约情况说明操作异常!"
  8295. br.ErrMsg = "新增续约情况说明操作异常,err:" + err.Error()
  8296. return
  8297. }
  8298. companyProduct.RenewalIntention = req.Renew
  8299. err = company.EditTryOutCompanyReason(companyProduct, req.Remark, req.RenewalTodo)
  8300. if err != nil {
  8301. br.Msg = "更新客户续约情况说明异常!"
  8302. br.ErrMsg = "更新客户续约情况说明异常,err:" + err.Error()
  8303. return
  8304. }
  8305. if req.Renew == 1 {
  8306. productName := ""
  8307. if req.ProductId == 1 {
  8308. productName = "ficc"
  8309. } else if req.ProductId == 2 {
  8310. productName = "权益"
  8311. } else {
  8312. productName = "佣金客户"
  8313. }
  8314. cp, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, req.ProductId)
  8315. if err != nil {
  8316. br.Msg = "查询该客户产品异常!"
  8317. br.ErrMsg = "查询该客户产品异常,err:" + err.Error()
  8318. return
  8319. }
  8320. if cp.Status != utils.COMPANY_STATUS_TRY_OUT {
  8321. br.Msg = "客户状态为:" + cp.Status + ";不可冻结"
  8322. br.ErrMsg = "客户状态为:" + cp.Status + ";不可冻结"
  8323. return
  8324. }
  8325. //查询客户的产品权限
  8326. companyReportPermissionList, err := company.GetCompanyReportPermission(req.CompanyId, req.ProductId)
  8327. if err != nil {
  8328. br.Msg = "查询客户的产品权限异常"
  8329. br.ErrMsg = "查询客户的产品权限异常:" + err.Error()
  8330. return
  8331. }
  8332. err = company.CompanyFreeze(req.CompanyId, req.ProductId, req.Remark)
  8333. if err != nil {
  8334. br.Msg = "冻结失败!"
  8335. br.ErrMsg = "冻结失败,Err:" + err.Error()
  8336. return
  8337. }
  8338. //新增操作记录
  8339. go func() {
  8340. time.Sleep(time.Second)
  8341. approveContent := req.Remark
  8342. remark := "冻结客户"
  8343. operation := "freeze"
  8344. _ = services.AddCompanyOperationRecord(req.CompanyId, cp.SellerId, sysUser.AdminId, req.ProductId, sysUser.AdminId, cp.CompanyName,
  8345. productName, "超级管理员", remark, operation, approveContent, sysUser.RealName, "", "冻结")
  8346. //新增产品权限冻结操作日志
  8347. for _, companyReportPermission := range companyReportPermissionList {
  8348. record := company_report_permission_log.CompanyReportPermissionLog{
  8349. CompanyReportPermissionId: companyReportPermission.CompanyReportPermissionId,
  8350. CompanyId: companyReportPermission.CompanyId,
  8351. ProductId: req.ProductId,
  8352. ProductName: companyReportPermission.ProductName,
  8353. SysUserId: sysUser.AdminId,
  8354. SysUserName: "超级管理员",
  8355. Remark: "冻结客户",
  8356. Operation: "freeze",
  8357. Status: companyReportPermission.Status,
  8358. CreateTime: time.Now(),
  8359. }
  8360. _, err = company_report_permission_log.AddCompanyReportPermissionLog(&record)
  8361. }
  8362. }()
  8363. }
  8364. {
  8365. approveContent := req.Remark
  8366. approveContentExtra := req.RenewalTodo
  8367. remark := "新增续约说明"
  8368. operation := "add_try_out_reason"
  8369. _ = services.AddCompanyOperationRecordMore(req.CompanyId, companyProduct.SellerId, sysUser.AdminId, companyProduct.ProductId, sysUser.AdminId, companyProduct.CompanyName,
  8370. companyProduct.ProductName, sysUser.RealName, remark, operation, approveContent, approveContentExtra, sysUser.RealName, "", companyProduct.Status)
  8371. record := new(company.CompanyOperationRecord)
  8372. record.Id = req.OperationId
  8373. record.ApproveContent = req.Remark
  8374. record.ApproveContentExtra = req.RenewalTodo
  8375. _, err = company.UpdateCompanyOperationRecord(record)
  8376. if err != nil {
  8377. br.Msg = "编辑失败"
  8378. br.ErrMsg = "编辑失败,Err:" + err.Error()
  8379. return
  8380. }
  8381. }
  8382. if req.ProductId == utils.COMPANY_PRODUCT_RAI_ID {
  8383. //权益客户新增历史备注总表
  8384. itemRecord := new(company.CompanyHistoryRemark)
  8385. itemRecord.CompanyId = req.CompanyId
  8386. itemRecord.Content = req.Remark
  8387. itemRecord.SysAdminId = sysUser.AdminId
  8388. itemRecord.SysAdminName = sysUser.RealName
  8389. itemRecord.CreateTime = time.Now().Local()
  8390. itemRecord.ModifyTime = time.Now().Local()
  8391. itemRecord.ShowTime = time.Now().Local()
  8392. itemRecord.ProductId = 2
  8393. itemRecord.TableName = "company_renewal_reason"
  8394. itemRecord.TableId = int(newId)
  8395. go services.AddCompanyHistoryRemark(itemRecord)
  8396. }
  8397. br.Ret = 200
  8398. br.Success = true
  8399. br.Msg = "编辑成功"
  8400. }
  8401. // AddRemark
  8402. // @Title 新增备注
  8403. // @Description 新增备注
  8404. // @Param request body company.RemarkReq true "type json string"
  8405. // @Success 200 编辑成功
  8406. // @router /remark/add [post]
  8407. func (this *CompanyController) AddRemark() {
  8408. br := new(models.BaseResponse).Init()
  8409. defer func() {
  8410. this.Data["json"] = br
  8411. this.ServeJSON()
  8412. }()
  8413. sysUser := this.SysUser
  8414. if sysUser == nil {
  8415. br.Msg = "请登录"
  8416. br.ErrMsg = "请登录,SysUser Is Empty"
  8417. br.Ret = 408
  8418. return
  8419. }
  8420. var req company.RemarkReq
  8421. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  8422. if err != nil {
  8423. br.Msg = "参数解析异常!"
  8424. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  8425. return
  8426. }
  8427. if req.CompanyId <= 0 {
  8428. br.Msg = "参数缺失"
  8429. br.ErrMsg = "参数缺失,客户编号未传!"
  8430. return
  8431. }
  8432. if req.Remark == "" {
  8433. br.Msg = "参数缺失"
  8434. br.ErrMsg = "参数缺失,备注说明未传!"
  8435. return
  8436. }
  8437. var productId int
  8438. //var productName string
  8439. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_TEAM || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
  8440. productId = 1
  8441. //productName = "ficc"
  8442. } else if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_DEPARTMENT {
  8443. productId = 2
  8444. //productName = "权益"
  8445. } else {
  8446. br.Msg = "角色类型错误"
  8447. br.ErrMsg = "角色类型错误,该角色不能添加备注!"
  8448. return
  8449. }
  8450. companyProduct, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, productId)
  8451. if err != nil {
  8452. br.Msg = "查询客户异常"
  8453. br.ErrMsg = "查询客户异常,Err:" + err.Error()
  8454. }
  8455. if companyProduct.SellerId != sysUser.AdminId {
  8456. br.Msg = "客户异常,没有该客户的操作权限"
  8457. br.ErrMsg = "客户异常,没有该客户的操作权限"
  8458. return
  8459. }
  8460. remark := company.CompanyProductRemark{
  8461. CompanyId: companyProduct.CompanyId,
  8462. ProductId: companyProduct.ProductId,
  8463. ProductName: companyProduct.ProductName,
  8464. Remark: req.Remark,
  8465. CreateTime: time.Now(),
  8466. SysUserId: sysUser.AdminId,
  8467. SysRealName: sysUser.RealName,
  8468. }
  8469. var newId int64
  8470. newId, err = company.AddCompanyRemark(&remark)
  8471. {
  8472. approveContent := req.Remark
  8473. remark := "新增备注"
  8474. operation := "add_remark"
  8475. services.AddCompanyOperationRecord(req.CompanyId, companyProduct.SellerId, sysUser.AdminId, companyProduct.ProductId, sysUser.AdminId, companyProduct.CompanyName,
  8476. companyProduct.ProductName, sysUser.RealName, remark, operation, approveContent, sysUser.RealName, "", companyProduct.Status)
  8477. }
  8478. if err != nil {
  8479. br.Msg = "编辑失败"
  8480. br.ErrMsg = "编辑失败,Err:" + err.Error()
  8481. }
  8482. //如果是权益的写入历史备注表
  8483. if productId == utils.COMPANY_PRODUCT_RAI_ID {
  8484. //权益客户新增历史备注总表
  8485. itemRecord := new(company.CompanyHistoryRemark)
  8486. itemRecord.CompanyId = req.CompanyId
  8487. itemRecord.Content = req.Remark
  8488. itemRecord.SysAdminId = sysUser.AdminId
  8489. itemRecord.SysAdminName = sysUser.RealName
  8490. itemRecord.CreateTime = time.Now().Local()
  8491. itemRecord.ModifyTime = time.Now().Local()
  8492. itemRecord.ShowTime = time.Now().Local()
  8493. itemRecord.ProductId = 2
  8494. itemRecord.TableName = "company_product_remark"
  8495. itemRecord.TableId = int(newId)
  8496. go services.AddCompanyHistoryRemark(itemRecord)
  8497. }
  8498. br.Ret = 200
  8499. br.Success = true
  8500. br.Msg = "编辑成功"
  8501. }
  8502. // RemarkList 备注列表
  8503. // @Title 备注列表
  8504. // @Description 备注列表
  8505. // @Param CompanyId query string true "客户id"
  8506. // @Success 200 {object} company.RemarkResp
  8507. // @router /remark [get]
  8508. func (this *CompanyController) RemarkList() {
  8509. br := new(models.BaseResponse).Init()
  8510. defer func() {
  8511. this.Data["json"] = br
  8512. this.ServeJSON()
  8513. }()
  8514. sysUser := this.SysUser
  8515. if sysUser == nil {
  8516. br.Msg = "请登录"
  8517. br.ErrMsg = "请登录,SysUser Is Empty"
  8518. br.Ret = 408
  8519. return
  8520. }
  8521. companyId := this.GetString("CompanyId")
  8522. var remarkList []*company.CompanyProductRemark
  8523. var err error
  8524. groupFicc := []string{
  8525. utils.ROLE_TYPE_CODE_FICC_SELLER, utils.ROLE_TYPE_CODE_FICC_TEAM, utils.ROLE_TYPE_CODE_FICC_GROUP,
  8526. utils.ROLE_TYPE_CODE_FICC_DEPARTMENT, utils.ROLE_TYPE_CODE_FICC_ADMIN,
  8527. }
  8528. groupRai := []string{
  8529. utils.ROLE_TYPE_CODE_RAI_SELLER, utils.ROLE_TYPE_CODE_RAI_GROUP, utils.ROLE_TYPE_CODE_RAI_GROUP,
  8530. utils.ROLE_TYPE_CODE_RAI_DEPARTMENT, utils.ROLE_TYPE_CODE_RAI_ADMIN,
  8531. }
  8532. if utils.InArrayByStr(groupFicc, sysUser.RoleTypeCode) {
  8533. remarkList, err = company.GetRemarkList(companyId, "1")
  8534. if err != nil {
  8535. br.Msg = "获取失败"
  8536. br.ErrMsg = "获取失败,Err:" + err.Error()
  8537. return
  8538. }
  8539. }
  8540. if utils.InArrayByStr(groupRai, sysUser.RoleTypeCode) {
  8541. remarkList, err = company.GetRemarkList(companyId, "2")
  8542. if err != nil {
  8543. br.Msg = "获取失败"
  8544. br.ErrMsg = "获取失败,Err:" + err.Error()
  8545. return
  8546. }
  8547. }
  8548. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  8549. remarkList, err = company.GetRemarkListByCompanyId(companyId)
  8550. if err != nil {
  8551. br.Msg = "获取失败"
  8552. br.ErrMsg = "获取失败,Err:" + err.Error()
  8553. return
  8554. }
  8555. }
  8556. resp := make([]company.RemarkResp, len(remarkList))
  8557. for i, remark := range remarkList {
  8558. createDate := remark.CreateTime.Format(utils.FormatDateTime)
  8559. resp[i].RemarkId = remark.CompanyProductRemarkId
  8560. resp[i].Remark = remark.Remark
  8561. resp[i].ProductName = remark.ProductName
  8562. resp[i].CreateTime = createDate
  8563. // 仅自己添加的可删除
  8564. if remark.SysUserId == sysUser.AdminId {
  8565. resp[i].ButtonDel = true
  8566. }
  8567. }
  8568. br.Ret = 200
  8569. br.Success = true
  8570. br.Msg = "获取成功"
  8571. br.Data = resp
  8572. }
  8573. // RoadShowList 客户列表的路演详情列表
  8574. // @Title 路演详情列表
  8575. // @Description 路演详情列表
  8576. // @Param CompanyId query string true "客户id"
  8577. // @Success 200 {object} company.RoadShowListResp
  8578. // @router /roadShowList [get]
  8579. func (this *CompanyController) RoadShowList() {
  8580. br := new(models.BaseResponse).Init()
  8581. defer func() {
  8582. this.Data["json"] = br
  8583. this.ServeJSON()
  8584. }()
  8585. sysUser := this.SysUser
  8586. if sysUser == nil {
  8587. br.Msg = "请登录"
  8588. br.ErrMsg = "请登录,SysUser Is Empty"
  8589. br.Ret = 408
  8590. return
  8591. }
  8592. companyId := this.GetString("CompanyId")
  8593. companyIdInt, _ := strconv.Atoi(companyId)
  8594. if companyIdInt <= 0 {
  8595. br.Msg = "参数错误"
  8596. return
  8597. }
  8598. var englishCompany int
  8599. if companyIdInt > utils.EnCompanyIdStep {
  8600. companyIdInt = companyIdInt - utils.EnCompanyIdStep
  8601. englishCompany = 1
  8602. }
  8603. var err error
  8604. roadShowList, err := company.GetRoadShowList(companyIdInt, englishCompany)
  8605. if err != nil {
  8606. br.Msg = "获取失败"
  8607. br.ErrMsg = "获取失败,Err:" + err.Error()
  8608. return
  8609. }
  8610. //calendarIdSlice := make([]string, 0)
  8611. //for _, v := range roadShowList {
  8612. // calendarIdSlice = append(calendarIdSlice, strconv.Itoa(v.RsCalendarId))
  8613. //}
  8614. //calendarIdStr := strings.Join(calendarIdSlice, ",")
  8615. //researcherList, _ := company.GetRoadShowResearchers(calendarIdStr)
  8616. //roadShowTotalMap := make(map[int]int)
  8617. //for _, roadShowTotal := range researcherList {
  8618. // roadShowTotalMap[roadShowTotal.CompanyId] = roadShowTotal.Total
  8619. //}
  8620. resp := make([]company.RoadShowListResp, len(roadShowList))
  8621. for i, calendar := range roadShowList {
  8622. resp[i].SysUserRealName = calendar.SysUserRealName
  8623. resp[i].RoadshowType = calendar.RoadshowType
  8624. //线上为平台,线下为省市
  8625. if calendar.RoadshowType == "线上" {
  8626. resp[i].RoadshowPlatform = calendar.RoadshowPlatform
  8627. } else {
  8628. resp[i].RoadshowPlatform = calendar.Province + calendar.City
  8629. }
  8630. researchers, err := company.GetRoadShowResearchers(calendar.RsCalendarId)
  8631. if err != nil && err.Error() != utils.ErrNoRow() {
  8632. br.Msg = "获取研究员信息失败"
  8633. br.ErrMsg = "获取研究员信息失败,Err:" + err.Error()
  8634. return
  8635. }
  8636. var researcherList []string
  8637. for _, researcher := range researchers {
  8638. researcherList = append(researcherList, *researcher)
  8639. }
  8640. researcher := strings.Join(researcherList, ",")
  8641. resp[i].Researchers = researcher
  8642. resp[i].RoadShowTime = calendar.EndDate.Format("2006.01.02")
  8643. }
  8644. br.Ret = 200
  8645. br.Success = true
  8646. br.Msg = "获取成功"
  8647. br.Data = resp
  8648. }
  8649. // CustomerAreaStatistics
  8650. // @Title 客户区域统计
  8651. // @Description 获取客户区域统计接口
  8652. // @Param Date query string true "日期"
  8653. // @Param ProductId query Int true "产品Id"
  8654. // @Success 200 {object} statistic_report.CompanyRenewRecordResp
  8655. // @router /customerAreaStatistics [get]
  8656. func (this *CompanyController) CustomerAreaStatistics() {
  8657. br := new(models.BaseResponse).Init()
  8658. defer func() {
  8659. this.Data["json"] = br
  8660. this.ServeJSON()
  8661. }()
  8662. sysUser := this.SysUser
  8663. if sysUser == nil {
  8664. br.Msg = "请登录"
  8665. br.ErrMsg = "请登录,SysUser Is Empty"
  8666. br.Ret = 408
  8667. return
  8668. }
  8669. date := this.GetString("Date")
  8670. productId, _ := this.GetInt("ProductId", 1)
  8671. //获取列表
  8672. companyAreaDataMapList, _, err := statistic_report.GetAreaDateData(date, productId)
  8673. if err != nil {
  8674. br.Msg = "数据异常"
  8675. br.ErrMsg = "数据异常,Err:" + err.Error()
  8676. return
  8677. }
  8678. //获取省市数据
  8679. areaMap := make(map[string]string)
  8680. provinceMap := make(map[string][]string, 0)
  8681. list, err := statisticModels.GetAllCompanyArea()
  8682. for _, item := range list {
  8683. areaMap[item.City] = item.Province
  8684. }
  8685. for c, p := range areaMap {
  8686. citySlice := make([]string, 0)
  8687. citySlice = provinceMap[p]
  8688. citySlice = append(citySlice, c)
  8689. provinceMap[p] = citySlice
  8690. }
  8691. //数据处理
  8692. groupReportRecordList := make([]statistic_report.GroupCityRecord, 0)
  8693. resp := statistic_report.CustomerAreaStatisticsResp{
  8694. List: groupReportRecordList,
  8695. IsAdmin: false,
  8696. }
  8697. //除ficc管理员和超管之外的角色进入此页面时,正式客户数量>0时可点击,点击查看正式客户列表详情;
  8698. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  8699. resp.IsAdmin = true
  8700. }
  8701. startDateIndexList := make(map[int]string) //开始时间间隔map
  8702. endDateIndexList := make(map[int]string) //结束时间间隔map
  8703. tmpAllTryOutNumMap := make(map[int]int)
  8704. tmpAllFormalNumMap := make(map[int]int)
  8705. tmpAllActiveNumMap := make(map[int]int)
  8706. tmpAllAllActiveNumMap := make(map[int]int)
  8707. tmpAllNoIncrementalActiveNumMap := make(map[int]int)
  8708. tmpAllTryStagePushMap := make(map[int]int)
  8709. tmpAllTryStageFollowMap := make(map[int]int)
  8710. tmpAllTryStageReadyMap := make(map[int]int)
  8711. tmpAllTryStageInitMap := make(map[int]int)
  8712. for province, cityList := range provinceMap {
  8713. tmpGroupCityReportRecord := make([]statistic_report.CityRecord, 0)
  8714. tmpGroupCompanyReportRecordNumList := make([]statistic_report.CompanyAreaNum, 0)
  8715. tmpGroupTryOutNumMap := make(map[int]int)
  8716. tmpGroupFormalNumMap := make(map[int]int)
  8717. tmpGroupFormalCompanyIdsMap := make(map[int]string) //正式客户id
  8718. tmpGroupActiveNumMap := make(map[int]int)
  8719. tmpGroupAllActiveNumMap := make(map[int]int)
  8720. tmpGroupNoIncrementalActiveNumMap := make(map[int]int)
  8721. // 其他类型客户ID
  8722. tmpGroupTryOutCompanyIdsMap := make(map[int]string) //试用客户ID
  8723. tmpGroupPushCompanyIdsMap := make(map[int]string) //试用(推进)客户ID
  8724. tmpGroupFollowCompanyIdsMap := make(map[int]string) //试用(跟踪)客户ID
  8725. tmpGroupReadyCompanyIdsMap := make(map[int]string) //试用(预备)客户ID
  8726. tmpGroupInitCompanyIdsMap := make(map[int]string) //试用(未分类)客户ID
  8727. tmpGroupTryStagePushMap := make(map[int]int)
  8728. tmpGroupTryStageFollowMap := make(map[int]int)
  8729. tmpGroupTryStageReadyMap := make(map[int]int)
  8730. tmpGroupTryStageInitMap := make(map[int]int)
  8731. for _, city := range cityList {
  8732. //城市数据
  8733. //每个城市的数据
  8734. tmpCompanyReportRecordNumList := make([]statistic_report.CompanyAreaNum, 0)
  8735. for index, adminData := range companyAreaDataMapList {
  8736. startDateIndexList[index] = adminData.StartDate
  8737. endDateIndexList[index] = adminData.EndDate
  8738. var tmpTryOutNum, tmpFormalNum, tmpActiveStatus, tmpAllActiveStatus, tmpNoIncrementalActiveStatus int
  8739. var tmpTryStagePushNum, tmpTryStageFollowNum, tmpTryStageReadyNum, tmpTryStageInitNum int
  8740. var tmpFormalCompanyIds string //正式客户id集合
  8741. var tmpTryOutCompanyIds string //试用客户ID集合
  8742. var tmpPushCompanyIds string //试用(推进)客户ID集合
  8743. var tmpFollowCompanyIds string //试用(跟踪)客户ID集合
  8744. var tmpReadyCompanyIds string //试用(预备)客户ID集合
  8745. var tmpInitCompanyIds string //试用(未分类)客户ID集合
  8746. if num, ok := adminData.TryOutMap[city]; ok {
  8747. tmpTryOutNum = num
  8748. }
  8749. if num, ok := adminData.FormalMap[city]; ok {
  8750. tmpFormalNum = num
  8751. }
  8752. if companyIds, ok := adminData.FormalIdMap[city]; ok {
  8753. tmpFormalCompanyIds = companyIds
  8754. }
  8755. if companyIds, ok := adminData.TryOutIdMap[city]; ok {
  8756. tmpTryOutCompanyIds = companyIds
  8757. }
  8758. if companyIds, ok := adminData.TryStagePushIdsMap[city]; ok {
  8759. tmpPushCompanyIds = companyIds
  8760. }
  8761. if companyIds, ok := adminData.TryStageFollowIdsMap[city]; ok {
  8762. tmpFollowCompanyIds = companyIds
  8763. }
  8764. if companyIds, ok := adminData.TryStageReadyIdsMap[city]; ok {
  8765. tmpReadyCompanyIds = companyIds
  8766. }
  8767. if companyIds, ok := adminData.TryStageInitIdsMap[city]; ok {
  8768. tmpInitCompanyIds = companyIds
  8769. }
  8770. if num, ok := adminData.ActiveMap[city]; ok {
  8771. tmpActiveStatus = num
  8772. }
  8773. if num, ok := adminData.AllActiveMap[city]; ok {
  8774. tmpAllActiveStatus = num
  8775. }
  8776. if num, ok := adminData.NoIncrementalActiveMap[city]; ok {
  8777. tmpNoIncrementalActiveStatus = num
  8778. }
  8779. // 每个用户的试用标签统计 推进-跟踪-预备-未分类
  8780. if num, ok := adminData.TryStagePushNum[city]; ok {
  8781. tmpTryStagePushNum = num
  8782. }
  8783. if num, ok := adminData.TryStageFollowNum[city]; ok {
  8784. tmpTryStageFollowNum = num
  8785. }
  8786. if num, ok := adminData.TryStageReadyNum[city]; ok {
  8787. tmpTryStageReadyNum = num
  8788. }
  8789. if num, ok := adminData.TryStageInitNum[city]; ok {
  8790. tmpTryStageInitNum = num
  8791. }
  8792. tmpAdminRsReportRecordNum := statistic_report.CompanyAreaNum{
  8793. TryOutNum: tmpTryOutNum,
  8794. FormalNum: tmpFormalNum,
  8795. FormalIds: tmpFormalCompanyIds,
  8796. ActiveNum: tmpActiveStatus,
  8797. AllActiveNum: tmpAllActiveStatus,
  8798. NoIncrementalActiveNum: tmpNoIncrementalActiveStatus,
  8799. StartDate: adminData.StartDate,
  8800. EndDate: adminData.EndDate,
  8801. TryStagePushNum: tmpTryStagePushNum,
  8802. TryStageFollowNum: tmpTryStageFollowNum,
  8803. TryStageReadyNum: tmpTryStageReadyNum,
  8804. TryStageInitNum: tmpTryStageInitNum,
  8805. TotalNum: tmpTryOutNum + tmpFormalNum,
  8806. }
  8807. tmpCompanyReportRecordNumList = append(tmpCompanyReportRecordNumList, tmpAdminRsReportRecordNum)
  8808. //组内数据汇总
  8809. tmpGroupTryOutNumMap[index] += tmpTryOutNum
  8810. tmpGroupFormalNumMap[index] += tmpFormalNum
  8811. // 正式客户id
  8812. if tmpFormalCompanyIds != `` {
  8813. tmpGroupFormalCompanyIds, ok := tmpGroupFormalCompanyIdsMap[index]
  8814. if ok {
  8815. tmpGroupFormalCompanyIdsMap[index] = tmpGroupFormalCompanyIds + "," + tmpFormalCompanyIds
  8816. } else {
  8817. tmpGroupFormalCompanyIdsMap[index] = tmpFormalCompanyIds
  8818. }
  8819. }
  8820. tmpGroupActiveNumMap[index] += tmpActiveStatus
  8821. tmpGroupAllActiveNumMap[index] += tmpActiveStatus
  8822. tmpGroupNoIncrementalActiveNumMap[index] += tmpActiveStatus
  8823. tmpGroupTryStagePushMap[index] += tmpTryStagePushNum
  8824. tmpGroupTryStageFollowMap[index] += tmpTryStageFollowNum
  8825. tmpGroupTryStageReadyMap[index] += tmpTryStageReadyNum
  8826. tmpGroupTryStageInitMap[index] += tmpTryStageInitNum
  8827. // 其他客户IDs
  8828. if tmpTryOutCompanyIds != `` {
  8829. a, ok := tmpGroupTryOutCompanyIdsMap[index]
  8830. if ok {
  8831. tmpGroupTryOutCompanyIdsMap[index] = a + "," + tmpTryOutCompanyIds
  8832. } else {
  8833. tmpGroupTryOutCompanyIdsMap[index] = tmpTryOutCompanyIds
  8834. }
  8835. }
  8836. if tmpPushCompanyIds != `` {
  8837. a, ok := tmpGroupPushCompanyIdsMap[index]
  8838. if ok {
  8839. tmpGroupPushCompanyIdsMap[index] = a + "," + tmpPushCompanyIds
  8840. } else {
  8841. tmpGroupPushCompanyIdsMap[index] = tmpPushCompanyIds
  8842. }
  8843. }
  8844. if tmpFollowCompanyIds != `` {
  8845. a, ok := tmpGroupFollowCompanyIdsMap[index]
  8846. if ok {
  8847. tmpGroupFollowCompanyIdsMap[index] = a + "," + tmpFollowCompanyIds
  8848. } else {
  8849. tmpGroupFollowCompanyIdsMap[index] = tmpFollowCompanyIds
  8850. }
  8851. }
  8852. if tmpReadyCompanyIds != `` {
  8853. a, ok := tmpGroupReadyCompanyIdsMap[index]
  8854. if ok {
  8855. tmpGroupReadyCompanyIdsMap[index] = a + "," + tmpReadyCompanyIds
  8856. } else {
  8857. tmpGroupReadyCompanyIdsMap[index] = tmpReadyCompanyIds
  8858. }
  8859. }
  8860. if tmpInitCompanyIds != `` {
  8861. a, ok := tmpGroupInitCompanyIdsMap[index]
  8862. if ok {
  8863. tmpGroupInitCompanyIdsMap[index] = a + "," + tmpInitCompanyIds
  8864. } else {
  8865. tmpGroupInitCompanyIdsMap[index] = tmpInitCompanyIds
  8866. }
  8867. }
  8868. //总数据汇总
  8869. tmpAllTryOutNumMap[index] += tmpTryOutNum
  8870. tmpAllFormalNumMap[index] += tmpFormalNum
  8871. tmpAllActiveNumMap[index] += tmpActiveStatus
  8872. tmpAllAllActiveNumMap[index] += tmpAllActiveStatus
  8873. tmpAllNoIncrementalActiveNumMap[index] += tmpNoIncrementalActiveStatus
  8874. // 总数据试用标签数据汇总
  8875. tmpAllTryStagePushMap[index] += tmpTryStagePushNum
  8876. tmpAllTryStageFollowMap[index] += tmpTryStageFollowNum
  8877. tmpAllTryStageReadyMap[index] += tmpTryStageReadyNum
  8878. tmpAllTryStageInitMap[index] += tmpTryStageInitNum
  8879. }
  8880. tmpAdminReportRecord := statistic_report.CityRecord{
  8881. Name: city,
  8882. CompanyAreaNumNumList: tmpCompanyReportRecordNumList,
  8883. }
  8884. tmpGroupCityReportRecord = append(tmpGroupCityReportRecord, tmpAdminReportRecord)
  8885. }
  8886. for i := 0; i < len(tmpGroupActiveNumMap); i++ {
  8887. tmpGroupCompanyReportRecordNum := statistic_report.CompanyAreaNum{
  8888. TryOutNum: tmpGroupTryOutNumMap[i],
  8889. FormalNum: tmpGroupFormalNumMap[i],
  8890. FormalIds: tmpGroupFormalCompanyIdsMap[i],
  8891. ActiveNum: tmpGroupActiveNumMap[i],
  8892. AllActiveNum: tmpGroupAllActiveNumMap[i],
  8893. NoIncrementalActiveNum: tmpGroupNoIncrementalActiveNumMap[i],
  8894. StartDate: startDateIndexList[i],
  8895. EndDate: endDateIndexList[i],
  8896. TryStagePushNum: tmpGroupTryStagePushMap[i],
  8897. TryStageFollowNum: tmpGroupTryStageFollowMap[i],
  8898. TryStageReadyNum: tmpGroupTryStageReadyMap[i],
  8899. TryStageInitNum: tmpGroupTryStageInitMap[i],
  8900. TotalNum: tmpGroupTryOutNumMap[i] + tmpGroupFormalNumMap[i],
  8901. TryOutIds: tmpGroupTryOutCompanyIdsMap[i],
  8902. TryStagePushIds: tmpGroupPushCompanyIdsMap[i],
  8903. TryStageFollowIds: tmpGroupFollowCompanyIdsMap[i],
  8904. TryStageReadyIds: tmpGroupReadyCompanyIdsMap[i],
  8905. TryStageInitIds: tmpGroupInitCompanyIdsMap[i],
  8906. }
  8907. tmpGroupCompanyReportRecordNumList = append(tmpGroupCompanyReportRecordNumList, tmpGroupCompanyReportRecordNum)
  8908. }
  8909. groupReportRecord := statistic_report.GroupCityRecord{
  8910. Item: tmpGroupCityReportRecord,
  8911. Name: province,
  8912. CompanyAreaNumNumList: tmpGroupCompanyReportRecordNumList,
  8913. }
  8914. groupReportRecordList = append(groupReportRecordList, groupReportRecord)
  8915. }
  8916. resp.List = groupReportRecordList
  8917. br.Ret = 200
  8918. br.Success = true
  8919. br.Msg = "获取成功"
  8920. br.Data = resp
  8921. }
  8922. // CompanyTryOutDayList
  8923. // @Title 客户累计试用详情接口
  8924. // @Description 客户累计试用详情接口
  8925. // @Param CompanyId query int true "客户id"
  8926. // @Param ProductId query int true "产品id"
  8927. // @Success 200 {object} company.CompanyTryOutDayListResp
  8928. // @router /company/tryOutDayList [get]
  8929. func (this *CompanyTodoController) CompanyTryOutDayList() {
  8930. br := new(models.BaseResponse).Init()
  8931. defer func() {
  8932. this.Data["json"] = br
  8933. this.ServeJSON()
  8934. }()
  8935. companyId, _ := this.GetInt("CompanyId")
  8936. if companyId <= 0 {
  8937. br.Msg = "请选择客户"
  8938. return
  8939. }
  8940. productId, _ := this.GetInt("ProductId")
  8941. if productId <= 0 {
  8942. br.Msg = "请选择类型"
  8943. return
  8944. }
  8945. pageSize, _ := this.GetInt("PageSize")
  8946. currentIndex, _ := this.GetInt("CurrentIndex")
  8947. var startSize int
  8948. if pageSize <= 0 {
  8949. pageSize = utils.PageSize20
  8950. }
  8951. if currentIndex <= 0 {
  8952. currentIndex = 1
  8953. }
  8954. startSize = paging.StartIndex(currentIndex, pageSize)
  8955. // 获取任务信息
  8956. total, err := company.GetCompanyProductTryOutUpdateLogTotal(companyId, productId)
  8957. if err != nil {
  8958. br.Msg = "获取任务信息失败"
  8959. br.ErrMsg = "获取任务信息失败,err:" + err.Error()
  8960. return
  8961. }
  8962. // 获取任务信息
  8963. list, err := company.GetCompanyProductTryOutUpdateLogList(companyId, productId, startSize, pageSize)
  8964. if err != nil {
  8965. br.Msg = "获取任务信息失败"
  8966. br.ErrMsg = "获取任务信息失败,err:" + err.Error()
  8967. return
  8968. }
  8969. //var list []*company_todo.CompanyTodoListItem
  8970. //for _, v := range todos {
  8971. // temp := &company_todo.CompanyTodoListItem{
  8972. // CompanyTodo: v,
  8973. // }
  8974. // temp.EndTimeStr = temp.EndTime.Format(utils.FormatDate)
  8975. // if temp.EndTimeStr == "0001-01-01" {
  8976. // temp.EndTimeStr = ""
  8977. // }
  8978. // list = append(list, temp)
  8979. //}
  8980. if len(list) <= 0 {
  8981. list = make([]*company.CompanyProductTryOutUpdateLog, 0)
  8982. }
  8983. page := paging.GetPaging(currentIndex, pageSize, total)
  8984. resp := company.CompanyTryOutDayListResp{
  8985. Paging: page,
  8986. List: list,
  8987. }
  8988. br.Ret = 200
  8989. br.Success = true
  8990. br.Msg = "获取成功"
  8991. br.Data = resp
  8992. }
  8993. // @Title 获取流水信息接口
  8994. // @Description 获取流水信息接口
  8995. // @Param CompanyId query int true "客户id"
  8996. // @Success 200 {object} company.CygxActivityPointsBillListResp
  8997. // @router /company/activity/points/bill [get]
  8998. func (this *CompanyTodoController) CompanyActivityPointsBill() {
  8999. br := new(models.BaseResponse).Init()
  9000. defer func() {
  9001. this.Data["json"] = br
  9002. this.ServeJSON()
  9003. }()
  9004. companyId, _ := this.GetInt("CompanyId")
  9005. if companyId <= 0 {
  9006. br.Msg = "请选择客户"
  9007. return
  9008. }
  9009. // 获取流水信息
  9010. list, err := cygx.CygxActivityPointsBillByCompanyId(companyId)
  9011. if err != nil {
  9012. br.Msg = "获取任务信息失败"
  9013. br.ErrMsg = "获取任务信息失败,err:" + err.Error()
  9014. return
  9015. }
  9016. if len(list) <= 0 {
  9017. list = make([]*cygx.CygxActivityPointsBillResp, 0)
  9018. }
  9019. resp := cygx.CygxActivityPointsBillListResp{
  9020. List: list,
  9021. }
  9022. br.Ret = 200
  9023. br.Success = true
  9024. br.Msg = "获取成功"
  9025. br.Data = resp
  9026. }
  9027. // DelRemark
  9028. // @Title 删除备注
  9029. // @Description 删除备注
  9030. // @Param request body company.RemarkDelReq true "type json string"
  9031. // @Success 200 操作成功
  9032. // @router /remark/del [post]
  9033. func (this *CompanyController) DelRemark() {
  9034. br := new(models.BaseResponse).Init()
  9035. defer func() {
  9036. if br.ErrMsg == "" {
  9037. br.IsSendEmail = false
  9038. }
  9039. this.Data["json"] = br
  9040. this.ServeJSON()
  9041. }()
  9042. sysUser := this.SysUser
  9043. if sysUser == nil {
  9044. br.Msg = "请登录"
  9045. br.ErrMsg = "请登录,SysUser Is Empty"
  9046. br.Ret = 408
  9047. return
  9048. }
  9049. var req company.RemarkDelReq
  9050. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  9051. if err != nil {
  9052. br.Msg = "参数解析异常!"
  9053. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  9054. return
  9055. }
  9056. if req.RemarkId <= 0 {
  9057. br.Msg = "参数有误"
  9058. br.ErrMsg = "参数有误, 备注ID有误"
  9059. return
  9060. }
  9061. item, e := company.GetCompanyRemarkById(req.RemarkId)
  9062. if e != nil {
  9063. if e.Error() == utils.ErrNoRow() {
  9064. br.Msg = "备注已被删除, 请刷新页面"
  9065. return
  9066. }
  9067. br.Msg = "备注信息有误"
  9068. br.ErrMsg = "获取客户备注失败, Err: " + e.Error()
  9069. return
  9070. }
  9071. if item.SysUserId != sysUser.AdminId {
  9072. br.Msg = "仅备注添加人可删除"
  9073. return
  9074. }
  9075. product, e := company.GetCompanyProductByCompanyIdAndProductId(item.CompanyId, item.ProductId)
  9076. if e != nil {
  9077. br.Msg = "操作失败"
  9078. br.ErrMsg = "获取客户产品信息失败, Err: " + e.Error()
  9079. return
  9080. }
  9081. if e := company.DelCompanyRemark(req.RemarkId); e != nil {
  9082. br.Msg = "操作失败"
  9083. br.ErrMsg = "删除客户备注失败, Err: " + e.Error()
  9084. return
  9085. }
  9086. content := fmt.Sprintf("%s%s", "删除备注: ", item.Remark)
  9087. _ = services.AddCompanyOperationRecord(product.CompanyId, product.SellerId, sysUser.AdminId, product.ProductId, sysUser.AdminId, product.CompanyName, product.ProductName, sysUser.RealName, "删除备注", "del_remark", content, sysUser.RealName, "", product.Status)
  9088. if item.ProductId == utils.COMPANY_PRODUCT_RAI_ID {
  9089. go services.DelCompanyHistoryRemark("company_product_remark", req.RemarkId) // 删除
  9090. }
  9091. br.Ret = 200
  9092. br.Success = true
  9093. br.Msg = "操作成功"
  9094. }
  9095. // @Title 获取流水信息接口
  9096. // @Description 获取流水信息接口
  9097. // @Param CompanyId query int true "客户id"
  9098. // @Success 200 {object} company.CygxActivityPointsBillListResp
  9099. // @router /company/activity/special/points/bill [get]
  9100. func (this *CompanyTodoController) CompanyActivitySpecialPointsBill() {
  9101. br := new(models.BaseResponse).Init()
  9102. defer func() {
  9103. this.Data["json"] = br
  9104. this.ServeJSON()
  9105. }()
  9106. companyId, _ := this.GetInt("CompanyId")
  9107. if companyId <= 0 {
  9108. br.Msg = "请选择客户"
  9109. return
  9110. }
  9111. // 获取流水信息
  9112. var condition string
  9113. var pars []interface{}
  9114. condition += ` AND company_id = ? `
  9115. pars = append(pars, companyId)
  9116. //查询当年的数据
  9117. //condition += ` AND b.create_time >= ? `
  9118. //pars = append(pars, time.Now().Format(utils.FormatYearDate)+"-01-01")
  9119. list, err := cygx.GetCygxActivitySpecialTripBillDetailListAll(condition, pars)
  9120. if err != nil {
  9121. br.Msg = "获取任务信息失败"
  9122. br.ErrMsg = "获取任务信息失败,err:" + err.Error()
  9123. return
  9124. }
  9125. //userType, tripRemaining, mapChartName, err := cygxService.GetChartPermissionSpecialSurplusByCompany(companyId)
  9126. //if err != nil {
  9127. // br.Msg = "获取专项调研剩余次数失败"
  9128. // br.ErrMsg = "获取专项调研剩余次数失败,err:" + err.Error()
  9129. // return
  9130. //}
  9131. //chartMap := map[int]string{utils.YI_YAO_ID: utils.YI_YAO_NAME, utils.XIAO_FEI_ID: utils.XIAO_FEI_NAME, utils.KE_JI_ID: utils.KE_JI_NAME, utils.ZHI_ZAO_ID: utils.ZHI_ZAO_NAME}
  9132. resp := new(cygx.CygxActivitySpecialPointsBillResp)
  9133. //lastTripRemaining := 0
  9134. for _, v := range list {
  9135. item := cygx.CygxActivitySpecialPointsBillRespItem{
  9136. Id: v.Id,
  9137. CreateTime: v.CreateTime.Format(utils.FormatDateTime),
  9138. CompanyId: v.CompanyId,
  9139. CompanyName: v.CompanyName,
  9140. RealName: v.RealName,
  9141. BillDetailed: v.BillDetailed,
  9142. ActivityName: v.ResearchTheme,
  9143. ChartPermissionId: v.ChartPermissionId,
  9144. ChartPermissionName: v.ChartPermissionName,
  9145. Total: v.Total,
  9146. }
  9147. if v.ActivityId == 0 {
  9148. item.Content = v.Content
  9149. } else {
  9150. if v.DoType == 1 && v.Way != 4 && v.Way != 3 {
  9151. item.Content = item.ActivityName + "--报名"
  9152. } else if v.DoType == 2 && v.Way != 4 && v.Way != 3 {
  9153. item.Content = item.ActivityName + "--取消报名"
  9154. } else if v.Way == 4 {
  9155. item.Content = item.ActivityName + "--活动取消"
  9156. }
  9157. }
  9158. //if userType == 2 {
  9159. // if i== 0 {
  9160. // item.Total += strconv.Itoa(tripRemaining) + "次"
  9161. // } else {
  9162. // item.Total += strconv.Itoa(tripRemaining-list[i-1].BillDetailed) + "次"
  9163. // }
  9164. // //if v.BillDetailed < 4 {
  9165. // // item.Total += strconv.Itoa(lastTripRemaining-list[i-1].BillDetailed) + "次"
  9166. // //} else {
  9167. // // item.Total += strconv.Itoa(lastTripRemaining) + "次"
  9168. // //}
  9169. //} else {
  9170. // for k, num := range mapChartName {
  9171. // if i== 0 {
  9172. // item.Total += k + strconv.Itoa(num) + "次+"
  9173. // } else {
  9174. // if list[i-1].ActivityId == 0 {
  9175. // item.Total += k + strconv.Itoa(num) + "次+"
  9176. // } else {
  9177. // item.Total += k + strconv.Itoa(num-list[i-1].BillDetailed) + "次+"
  9178. // }
  9179. // }
  9180. // //if num > 0 {
  9181. // // if i== 0{
  9182. // // item.Total += k + strconv.Itoa(num) + "次+"
  9183. // // } else {
  9184. // // item.Total += k + strconv.Itoa(num-v.BillDetailed) + "次+"
  9185. // // }
  9186. // //}
  9187. // }
  9188. // item.Total = strings.TrimRight(item.Total, "+")
  9189. //}
  9190. resp.List = append(resp.List, &item)
  9191. }
  9192. br.Ret = 200
  9193. br.Success = true
  9194. br.Msg = "获取成功"
  9195. br.Data = resp
  9196. }