company.go 319 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730
  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. companyProduct.SellerIdInit = seller.AdminId
  2856. companyProduct.SellerNameInit = seller.RealName
  2857. companyProductId, err := company.AddCompanyProduct(companyProduct)
  2858. if err != nil {
  2859. br.Msg = "新增失败"
  2860. br.ErrMsg = "新增客户产品失败,err:" + err.Error()
  2861. return
  2862. }
  2863. companyReportPermissionList, err := services.AddCompanyPermission(int(companyId), seller.AdminId, productId, productName, seller.RealName, req.PermissionIds, startDate, endDate)
  2864. if err != nil {
  2865. br.Msg = "新增失败"
  2866. br.ErrMsg = "新增客户设置权限失败,err:" + err.Error()
  2867. return
  2868. }
  2869. {
  2870. record := new(company.CompanyOperationRecord)
  2871. record.CompanyId = int(companyId)
  2872. record.CompanyName = req.CompanyName
  2873. record.SellerId = seller.AdminId
  2874. record.SysUserId = seller.AdminId
  2875. record.SysRealName = seller.RealName
  2876. record.Remark = "新增客户"
  2877. record.Operation = "add"
  2878. record.CreateTime = time.Now()
  2879. record.ProductId = productId
  2880. record.ProductName = productName
  2881. record.Status = req.Status
  2882. _, err = company.AddCompanyOperationRecord(record)
  2883. if err != nil {
  2884. go alarm_msg.SendAlarmMsg("URI:"+this.Ctx.Input.URI()+"<br/> "+";<br/> Body:"+err.Error(), 3)
  2885. //go utils.SendEmail(utils.APPNAME+"失败提醒"+utils.RunMode, "URI:"+this.Ctx.Input.URI()+"<br/> "+";<br/> Body:"+err.Error(), utils.EmailSendToUsers)
  2886. }
  2887. }
  2888. //新增客户日志
  2889. {
  2890. companyLog := new(company.CompanyLog)
  2891. companyLog.CompanyId = int(companyId)
  2892. companyLog.CompanyName = req.CompanyName
  2893. companyLog.CreditCode = req.CreditCode
  2894. companyLog.CompanyCode = companyCode
  2895. companyLog.Sort = item.Sort
  2896. companyLog.IsFeeCustomer = item.IsFeeCustomer
  2897. companyLog.Country = item.Country
  2898. companyLog.Address = item.Address
  2899. companyLog.City = item.City
  2900. companyLog.Province = item.Province
  2901. companyLog.Enabled = item.Enabled
  2902. companyLog.CreatedTime = item.CreatedTime
  2903. companyLog.LastUpdatedTime = item.LastUpdatedTime
  2904. companyLog.Seller = item.Seller
  2905. companyLog.SellsId = item.SellsId
  2906. companyLog.CompanyBelong = item.CompanyBelong
  2907. companyLog.StartDate = item.StartDate
  2908. companyLog.EndDate = item.EndDate
  2909. companyLog.FirstStartDate = item.FirstStartDate
  2910. companyLog.FirstEndDate = item.FirstEndDate
  2911. companyLog.DateType = item.DateType
  2912. companyLog.AdminId = this.SysUser.AdminId
  2913. companyLog.LogType = "add"
  2914. companyLog.LogCreateTime = time.Now()
  2915. go company.AddCompanyLog(companyLog)
  2916. }
  2917. //新增客户产品日志
  2918. {
  2919. productLog := new(company.CompanyProductLog)
  2920. productLog.CompanyProductId = int(companyProductId)
  2921. productLog.CompanyId = companyProduct.CompanyId
  2922. productLog.ProductId = companyProduct.ProductId
  2923. productLog.ProductName = companyProduct.ProductName
  2924. productLog.CompanyName = companyProduct.CompanyName
  2925. productLog.CompanyName = companyProduct.CompanyName
  2926. productLog.Source = companyProduct.Source
  2927. productLog.Reasons = companyProduct.Reasons
  2928. productLog.Status = companyProduct.Status
  2929. productLog.IndustryId = companyProduct.IndustryId
  2930. productLog.IndustryName = companyProduct.IndustryName
  2931. productLog.SellerId = companyProduct.SellerId
  2932. productLog.SellerName = companyProduct.SellerName
  2933. productLog.GroupId = companyProduct.GroupId
  2934. productLog.DepartmentId = companyProduct.DepartmentId
  2935. productLog.IsSuspend = companyProduct.IsSuspend
  2936. productLog.SuspendTime = companyProduct.SuspendTime
  2937. productLog.ApproveStatus = companyProduct.ApproveStatus
  2938. productLog.FreezeTime = companyProduct.FreezeTime
  2939. productLog.Remark = companyProduct.Remark
  2940. productLog.StartDate = companyProduct.StartDate
  2941. productLog.EndDate = companyProduct.EndDate
  2942. productLog.CreateTime = companyProduct.CreateTime
  2943. productLog.ModifyTime = companyProduct.ModifyTime
  2944. productLog.LoseReason = companyProduct.LoseReason
  2945. productLog.LossTime = companyProduct.LossTime
  2946. productLog.LogType = "add"
  2947. productLog.LogCreateTime = time.Now()
  2948. productLog.AdminId = this.SysUser.AdminId
  2949. productLog.Scale = companyProduct.Scale
  2950. go company.AddCompanyProductLog(productLog)
  2951. }
  2952. //新增客户产品状态变更日志
  2953. {
  2954. companyProductUpdateLog := &company.CompanyProductUpdateLog{
  2955. Id: 0,
  2956. CompanyId: companyProduct.CompanyId,
  2957. ProductId: companyProduct.ProductId,
  2958. Status: "试用",
  2959. Source: "add",
  2960. SellerId: companyProduct.SellerId,
  2961. SellerName: companyProduct.SellerName,
  2962. StartDate: startDateTime,
  2963. EndDate: endDateTime,
  2964. RealEndDate: startDateTime,
  2965. CreateTime: time.Now(),
  2966. }
  2967. go company.AddCompanyProductUpdateLog(companyProductUpdateLog)
  2968. companyProductTryOutUpdateLog := &company.CompanyProductTryOutUpdateLog{
  2969. Id: 0,
  2970. CompanyId: companyProduct.CompanyId,
  2971. ProductId: companyProduct.ProductId,
  2972. Source: "add",
  2973. SellerId: companyProduct.SellerId,
  2974. SellerName: companyProduct.SellerName,
  2975. StartDate: startDateTime,
  2976. EndDate: endDateTime,
  2977. RealEndDate: startDateTime,
  2978. IsStop: 0,
  2979. CreateTime: time.Now(),
  2980. }
  2981. go company.AddCompanyProductTryOutUpdateLog(companyProductTryOutUpdateLog, companyReportPermissionList)
  2982. }
  2983. resp := new(company.CompanyAddResp)
  2984. resp.CompanyId = int(companyId)
  2985. br.Ret = 200
  2986. br.Success = true
  2987. br.Msg = "新增成功"
  2988. br.Data = resp
  2989. }
  2990. // Detail
  2991. // @Title 获取客户详情
  2992. // @Description 获取客户详情接口
  2993. // @Param CompanyId query int true "客户id"
  2994. // @Success 200 {object} company.CompanyDetailResp
  2995. // @router /detail [get]
  2996. func (this *CompanyController) Detail() {
  2997. br := new(models.BaseResponse).Init()
  2998. defer func() {
  2999. this.Data["json"] = br
  3000. this.ServeJSON()
  3001. }()
  3002. sysUser := this.SysUser
  3003. if sysUser == nil {
  3004. br.Msg = "请登录"
  3005. br.ErrMsg = "请登录,SysUser Is Empty"
  3006. br.Ret = 408
  3007. return
  3008. }
  3009. companyId, _ := this.GetInt("CompanyId")
  3010. if companyId <= 0 {
  3011. br.Msg = "参数错误"
  3012. br.ErrMsg = "客户参数小于等于0"
  3013. return
  3014. }
  3015. // CRM8.8-是否为编辑页的客户详情
  3016. isEdit, _ := this.GetBool("IsEdit")
  3017. productId := services.GetProductId(sysUser.RoleTypeCode)
  3018. item, err := company.GetCompanyDetailById(companyId)
  3019. if err != nil {
  3020. br.Msg = "获取信息失败"
  3021. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  3022. return
  3023. }
  3024. shareSellerId := 0
  3025. shareGroupId := 0
  3026. var productItem *company.CompanyProduct
  3027. if productId > 0 {
  3028. var e error
  3029. productItem, e = company.GetCompanyProductByCompanyIdAndProductId(companyId, productId)
  3030. if e != nil && e.Error() != utils.ErrNoRow() {
  3031. br.Msg = "客户信息有误"
  3032. br.ErrMsg = "获取客户信息失败, Err: " + e.Error()
  3033. return
  3034. }
  3035. if productItem != nil {
  3036. shareSellerId = productItem.ShareSellerId
  3037. shareGroupId = productItem.ShareGroupId
  3038. }
  3039. }
  3040. var productName string
  3041. if productId == 1 {
  3042. productName = utils.COMPANY_PRODUCT_FICC_NAME
  3043. } else if productId == 2 {
  3044. productName = utils.COMPANY_PRODUCT_RAI_NAME
  3045. } else {
  3046. productName = "admin"
  3047. }
  3048. resp := new(company.CompanyDetailResp)
  3049. resp.ProductName = productName
  3050. //获取客户产品
  3051. productList, err := company.GetCompanyProductsByCompanyId(companyId)
  3052. if err != nil {
  3053. br.Msg = "获取信息失败"
  3054. br.ErrMsg = "获取产品信息失败,Err:" + err.Error()
  3055. return
  3056. }
  3057. roleTypeCode := sysUser.RoleTypeCode
  3058. itemLen := len(productList)
  3059. btnDetailItem := new(company.ButtonDetailPermission)
  3060. // 客户权限校验
  3061. {
  3062. // 如果不是超管、ficc管理员、权益管理员,那么需要额外校验下权限
  3063. if !utils.InArrayByStr([]string{utils.ROLE_TYPE_CODE_ADMIN, utils.ROLE_TYPE_CODE_FICC_ADMIN, utils.ROLE_TYPE_CODE_RAI_ADMIN}, sysUser.RoleTypeCode) {
  3064. var isOk bool //是否有权限
  3065. var companyHasProduct bool // 客户当前是否有该产品权限
  3066. for _, productInfo := range productList {
  3067. // 只校验拥有的品种权限:ficc或者权益
  3068. if productInfo.ProductId == productId {
  3069. companyHasProduct = true
  3070. // 自己的客户有权限看
  3071. if productInfo.SellerId == sysUser.AdminId {
  3072. isOk = true
  3073. break
  3074. }
  3075. // 流失客户都有权限看
  3076. if productInfo.Status == utils.COMPANY_STATUS_LOSE || productInfo.Status == utils.COMPANY_STATUS_CLOSE {
  3077. isOk = true
  3078. break
  3079. }
  3080. // 分享的客户 也有权限
  3081. if productItem.IsShare == 1 && productItem.ShareSellerId == sysUser.AdminId {
  3082. isOk = true
  3083. break
  3084. }
  3085. // 分享的客户的组长 也有权限
  3086. if productItem.IsShare == 1 && productItem.ShareGroupId == sysUser.GroupId {
  3087. isOk = true
  3088. break
  3089. }
  3090. // 如果是组长,且该客户属于本组客户
  3091. if sysUser.Authority == 4 && productInfo.GroupId > 0 && productInfo.GroupId == sysUser.GroupId && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_TEAM {
  3092. isOk = true
  3093. break
  3094. }
  3095. // 如果是ficc主管或者权益主管
  3096. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  3097. // 获取顶级分组Id
  3098. var sysUserGroupPid, productGroupPid int
  3099. // 当前账号的顶级分组id
  3100. {
  3101. sysUserGroupIdpid, err := company.GetParentIdFromGroup(sysUser.GroupId)
  3102. if err != nil && err.Error() != utils.NotEmpty() {
  3103. break
  3104. }
  3105. if sysUserGroupIdpid == nil || *sysUserGroupIdpid == 0 {
  3106. sysUserGroupPid = sysUser.GroupId
  3107. } else {
  3108. sysUserGroupPid = *sysUserGroupIdpid
  3109. }
  3110. }
  3111. // 当前客户的顶级分组id
  3112. {
  3113. groupIdpid, err := company.GetParentIdFromGroup(productInfo.GroupId)
  3114. if err != nil && err.Error() != utils.NotEmpty() {
  3115. break
  3116. }
  3117. if groupIdpid == nil || *groupIdpid == 0 {
  3118. productGroupPid = productInfo.GroupId
  3119. } else {
  3120. productGroupPid = *groupIdpid
  3121. }
  3122. }
  3123. // 如果客户的顶级分组和当前账号分组id一致
  3124. if sysUserGroupPid == productGroupPid {
  3125. isOk = true
  3126. break
  3127. }
  3128. }
  3129. }
  3130. }
  3131. // 客户当前是否有该产品的权限,如果没有的话,说明是在领取客户,允许访问
  3132. if !companyHasProduct {
  3133. isOk = true
  3134. }
  3135. if !isOk {
  3136. br.Msg = "无访问权限"
  3137. return
  3138. }
  3139. }
  3140. }
  3141. //产品权限map
  3142. statusMap := make(map[int]string)
  3143. for i := 0; i < itemLen; i++ {
  3144. item := productList[i]
  3145. //添加产品权限map
  3146. statusMap[item.ProductId] = item.Status
  3147. if i == 0 {
  3148. if item.ProductId == 1 {
  3149. resp.CreateAuth = 1
  3150. } else {
  3151. resp.CreateAuth = 2
  3152. }
  3153. }
  3154. if item.ProductId == 1 {
  3155. if strings.Contains(sysUser.RoleTypeCode, "ficc") {
  3156. if item.Status == utils.COMPANY_STATUS_FREEZE || item.Status == utils.COMPANY_STATUS_LOSE {
  3157. btnDetailItem.BtnHistoryList = true
  3158. } else {
  3159. if item.SellerId == sysUser.AdminId || shareSellerId == sysUser.AdminId || shareGroupId == sysUser.GroupId {
  3160. btnDetailItem.BtnHistoryList = true
  3161. }
  3162. if sysUser.Authority > 0 {
  3163. if item.GroupId == sysUser.GroupId {
  3164. btnDetailItem.BtnHistoryList = true
  3165. }
  3166. if item.DepartmentId == sysUser.DepartmentId {
  3167. btnDetailItem.BtnHistoryList = true
  3168. }
  3169. }
  3170. }
  3171. }
  3172. // 编辑回显
  3173. allPermissions, e := company.GetPermissionLookItemsByProductId(utils.COMPANY_PRODUCT_FICC_ID)
  3174. if e != nil {
  3175. br.Msg = "获取失败"
  3176. br.ErrMsg = "获取权限信息失败,Err:" + e.Error()
  3177. return
  3178. }
  3179. permissionMap := make(map[int][]*company.PermissionLookItem, 0)
  3180. permissionCheckMap := make(map[int][]int, 0)
  3181. for _, v := range allPermissions {
  3182. if v.ParentId > 0 {
  3183. permissionMap[v.ParentId] = append(permissionMap[v.ParentId], v)
  3184. if v.IsPublic == 1 {
  3185. permissionCheckMap[v.ParentId] = append(permissionCheckMap[v.ParentId], v.ChartPermissionId)
  3186. }
  3187. }
  3188. }
  3189. for _, v := range allPermissions {
  3190. if v.ParentId == 0 {
  3191. checkList := make([]int, 0)
  3192. plist := new(company.PermissionLookList)
  3193. plist.Items = make([]*company.PermissionLookItem, 0)
  3194. plist.ItemsType = make([]*company.PermissionSetItemType, 0)
  3195. items, ok := permissionMap[v.ChartPermissionId]
  3196. if ok {
  3197. for itemK, n := range items {
  3198. permission, err := company.GetCompanyPermissionCheckItem(companyId, n.ChartPermissionId)
  3199. if err != nil && err.Error() != utils.ErrNoRow() {
  3200. br.Msg = "获取失败"
  3201. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  3202. return
  3203. }
  3204. if permission != nil && permission.ChartPermissionId > 0 {
  3205. checkList = append(checkList, n.ChartPermissionId)
  3206. items[itemK].StartDate = permission.StartDate
  3207. items[itemK].EndDate = permission.EndDate
  3208. items[itemK].Status = permission.Status
  3209. endDateTime, _ := time.Parse(utils.FormatDate, permission.EndDate)
  3210. endDateTime = endDateTime.AddDate(0, 0, 1)
  3211. sub := endDateTime.Sub(time.Now())
  3212. if sub < 0 {
  3213. sub = 0
  3214. }
  3215. expireDay := fmt.Sprintf("%v", int(sub.Hours()/24))
  3216. items[itemK].ExpireDay = expireDay
  3217. }
  3218. }
  3219. plist.Items = items
  3220. }
  3221. plist.ClassifyName = v.PermissionName
  3222. plist.CheckList = checkList
  3223. item.PermissionList = append(item.PermissionList, plist)
  3224. }
  3225. }
  3226. resp.FiccItem = item
  3227. if resp.FiccItem.Status == utils.COMPANY_STATUS_FOREVER {
  3228. resp.FiccItem.Status = utils.COMPANY_STATUS_X_CLASS_TRY_OUT
  3229. }
  3230. if (roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER ||
  3231. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP || roleTypeCode == utils.ROLE_TYPE_CODE_FICC_DEPARTMENT) &&
  3232. item.Status == utils.COMPANY_STATUS_TRY_OUT && item.ApproveStatus != "待审批" {
  3233. resp.IsButtonShow = 1
  3234. }
  3235. } else {
  3236. if strings.Contains(sysUser.RoleTypeCode, "rai") {
  3237. if item.Status == utils.COMPANY_STATUS_FREEZE || item.Status == utils.COMPANY_STATUS_LOSE {
  3238. btnDetailItem.BtnHistoryList = true
  3239. } else {
  3240. if item.SellerId == sysUser.AdminId || item.ShareSellerId == sysUser.AdminId || shareGroupId == sysUser.GroupId {
  3241. btnDetailItem.BtnHistoryList = true
  3242. }
  3243. if sysUser.Authority > 0 {
  3244. if item.GroupId == sysUser.GroupId {
  3245. btnDetailItem.BtnHistoryList = true
  3246. }
  3247. if item.DepartmentId == sysUser.DepartmentId {
  3248. btnDetailItem.BtnHistoryList = true
  3249. }
  3250. }
  3251. }
  3252. }
  3253. // CRM8.8-权益权限列表调用较多、统一进行调整
  3254. plist, e := services.RaiCompanyPermissionAndCheckList(companyId, isEdit, []string{"调研"})
  3255. if e != nil {
  3256. br.Msg = "获取客户权益权限列表信息失败"
  3257. br.ErrMsg = "获取客户权益权限列表信息失败,Err:" + e.Error()
  3258. return
  3259. }
  3260. // cygx8.2专项产业调研展示
  3261. item.SpecialSurplus, err = cygxService.GetSpecialSurplusByCompanyNew(companyId)
  3262. if err != nil {
  3263. br.Msg = "获取失败"
  3264. br.ErrMsg = "获取专项调研信息失败,Err:" + err.Error()
  3265. return
  3266. }
  3267. //研选服务点数
  3268. item.Points = cygxService.GetCygxActivityPointsCompanyByCompanyId(companyId)
  3269. item.PermissionList = append(item.PermissionList, plist)
  3270. resp.RaiItem = item
  3271. if resp.RaiItem.Status == utils.COMPANY_STATUS_FOREVER {
  3272. resp.RaiItem.Status = utils.COMPANY_STATUS_X_CLASS_TRY_OUT
  3273. }
  3274. if (roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER ||
  3275. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP ||
  3276. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_DEPARTMENT) &&
  3277. item.Status == utils.COMPANY_STATUS_TRY_OUT && item.ApproveStatus != "待审批" {
  3278. resp.IsButtonShow = 1
  3279. }
  3280. }
  3281. 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, "")
  3282. //if itemLen > 1 {
  3283. // btnDetailItem.BtnEdit = false
  3284. // btnDetailItem.BtnDelete = false
  3285. //} else {
  3286. // btnDetailItem.BtnEdit = btnItem.BtnEdit
  3287. // btnDetailItem.BtnDelete = btnItem.BtnDelete
  3288. //}
  3289. switch item.ProductId {
  3290. case 1:
  3291. btnDetailItem.FiccEdit = btnItem.BtnEdit
  3292. btnDetailItem.FiccDelete = btnItem.BtnDelete
  3293. case 2:
  3294. btnDetailItem.RaiEdit = btnItem.BtnEdit
  3295. btnDetailItem.RaiDelete = btnItem.BtnDelete
  3296. }
  3297. if !btnDetailItem.BtnEdit {
  3298. btnDetailItem.BtnEdit = btnItem.BtnEdit
  3299. }
  3300. if !btnDetailItem.BtnDelete {
  3301. btnDetailItem.BtnDelete = btnItem.BtnDelete
  3302. }
  3303. //联系人操作权限
  3304. if resp.IsContractButtonShow == false {
  3305. resp.IsContractButtonShow = services.CheckCompanyUserButton(sysUser.RoleTypeCode, item.SellerId, sysUser.AdminId, item.ProductId, shareSellerId, item.Status)
  3306. }
  3307. //校验当前操作员是否具给联系人开通个人研选的权限
  3308. if resp.IsUserYanXuanButtonShow == false {
  3309. resp.IsUserYanXuanButtonShow, err = services.CheckCompanyUserYanXuanButton(sysUser.RoleTypeCode, sysUser.Mobile)
  3310. if err != nil {
  3311. br.Msg = "获取失败"
  3312. br.ErrMsg = "获取专项调研信息失败,Err:" + err.Error()
  3313. return
  3314. }
  3315. }
  3316. }
  3317. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN ||
  3318. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN ||
  3319. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  3320. resp.IsButtonShow = 1
  3321. btnDetailItem.BtnHistoryList = true
  3322. }
  3323. //ficc权限
  3324. if ficcStatus, ok := statusMap[1]; ok {
  3325. if ficcStatus == utils.COMPANY_STATUS_TRY_OUT {
  3326. if raiStatus, ok := statusMap[2]; ok {
  3327. //另一个权限也是 试用 、冻结、流失
  3328. if raiStatus == utils.COMPANY_STATUS_TRY_OUT || raiStatus == utils.COMPANY_STATUS_FREEZE || raiStatus == utils.COMPANY_STATUS_LOSE {
  3329. //那么超管、部门管理员、销售可以编辑
  3330. if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER || roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3331. btnDetailItem.BaseInfoEdit = true
  3332. }
  3333. }
  3334. //权益是永续时,超管可编辑基础信息
  3335. if raiStatus == utils.COMPANY_STATUS_FOREVER {
  3336. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3337. btnDetailItem.BaseInfoEdit = true
  3338. }
  3339. }
  3340. } else {
  3341. //权限未开,有编辑基础信息权限
  3342. btnDetailItem.BaseInfoEdit = true
  3343. }
  3344. }
  3345. if ficcStatus == utils.COMPANY_STATUS_FOREVER {
  3346. if raiStatus, ok := statusMap[2]; ok {
  3347. //另一个权限也是 永续 、冻结、流失
  3348. if raiStatus == utils.COMPANY_STATUS_TRY_OUT || raiStatus == utils.COMPANY_STATUS_FOREVER || raiStatus == utils.COMPANY_STATUS_FREEZE || raiStatus == utils.COMPANY_STATUS_LOSE {
  3349. //超管可编辑基础信息
  3350. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3351. btnDetailItem.BaseInfoEdit = true
  3352. }
  3353. }
  3354. } else {
  3355. //权限未开,有编辑基础信息权限
  3356. btnDetailItem.BaseInfoEdit = true
  3357. }
  3358. }
  3359. }
  3360. //权益销售
  3361. if raiStatus, ok := statusMap[2]; ok {
  3362. if raiStatus == utils.COMPANY_STATUS_TRY_OUT {
  3363. if ficcStatus, ok := statusMap[1]; ok {
  3364. //另一个权限也是 试用 、冻结、流失
  3365. if ficcStatus == utils.COMPANY_STATUS_TRY_OUT || ficcStatus == utils.COMPANY_STATUS_FREEZE || ficcStatus == utils.COMPANY_STATUS_LOSE {
  3366. //那么超管、部门管理员、销售可以编辑
  3367. if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER || roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3368. btnDetailItem.BaseInfoEdit = true
  3369. }
  3370. }
  3371. //ficc是永续时,超管可编辑基础信息
  3372. if ficcStatus == utils.COMPANY_STATUS_FOREVER {
  3373. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3374. btnDetailItem.BaseInfoEdit = true
  3375. }
  3376. }
  3377. } else {
  3378. //权限未开,有编辑基础信息权限
  3379. btnDetailItem.BaseInfoEdit = true
  3380. }
  3381. }
  3382. if raiStatus == utils.COMPANY_STATUS_FOREVER {
  3383. if ficcStatus, ok := statusMap[1]; ok {
  3384. //另一个权限也是 试用、永续 、冻结、流失
  3385. if ficcStatus == utils.COMPANY_STATUS_TRY_OUT || ficcStatus == utils.COMPANY_STATUS_FOREVER || ficcStatus == utils.COMPANY_STATUS_FREEZE || ficcStatus == utils.COMPANY_STATUS_LOSE {
  3386. //超管可编辑基础信息
  3387. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3388. btnDetailItem.BaseInfoEdit = true
  3389. }
  3390. }
  3391. } else {
  3392. //权限未开,有编辑基础信息权限
  3393. btnDetailItem.BaseInfoEdit = true
  3394. }
  3395. }
  3396. }
  3397. // 白嫖客户标记
  3398. scroungeList, err := company.GetScroungeCompany()
  3399. if err != nil {
  3400. br.Msg = "获取失败"
  3401. br.ErrMsg = "获取白嫖客户信息失败,Err:" + err.Error()
  3402. return
  3403. }
  3404. scroungeMap := make(map[int]int)
  3405. for _, v := range scroungeList {
  3406. scroungeMap[v.CompanyId] = 1
  3407. }
  3408. if _, ok := scroungeMap[item.CompanyId]; ok {
  3409. item.IsScrounge = 1
  3410. }
  3411. resp.Item = item
  3412. resp.BtnItem = btnDetailItem
  3413. br.Ret = 200
  3414. br.Success = true
  3415. br.Msg = "获取成功"
  3416. br.Data = resp
  3417. }
  3418. // DetailByCreditCode
  3419. // @Title 根据社会信用码获取客户详情
  3420. // @Description 根据社会信用码获取客户详情接口
  3421. // @Param CreditCode query string true "客户社会信用码"
  3422. // @Success 200 {object} company.CompanyDetailResp
  3423. // @router /detail_by_credit_code [get]
  3424. func (this *CompanyController) DetailByCreditCode() {
  3425. br := new(models.BaseResponse).Init()
  3426. defer func() {
  3427. this.Data["json"] = br
  3428. this.ServeJSON()
  3429. }()
  3430. sysUser := this.SysUser
  3431. if sysUser == nil {
  3432. br.Msg = "请登录"
  3433. br.ErrMsg = "请登录,SysUser Is Empty"
  3434. br.Ret = 408
  3435. return
  3436. }
  3437. resp := new(company.CompanyDetailResp)
  3438. creditCode := this.GetString("CreditCode")
  3439. if creditCode == "" {
  3440. br.Msg = "参数错误"
  3441. br.ErrMsg = "社会信用码必传"
  3442. return
  3443. }
  3444. item, err := company.GetCompanyDetailByCreditCode(creditCode)
  3445. if err != nil {
  3446. br.Ret = 200
  3447. br.Success = true
  3448. br.Msg = "获取成功"
  3449. br.Data = resp
  3450. return
  3451. }
  3452. companyId := item.CompanyId
  3453. var productName string
  3454. productId := services.GetProductId(sysUser.RoleTypeCode)
  3455. if productId == 1 {
  3456. productName = utils.COMPANY_PRODUCT_FICC_NAME
  3457. } else if productId == 2 {
  3458. productName = utils.COMPANY_PRODUCT_RAI_NAME
  3459. } else {
  3460. productName = "admin"
  3461. }
  3462. resp.ProductName = productName
  3463. //获取客户产品
  3464. productList, err := company.GetCompanyProductsByCompanyId(companyId)
  3465. if err != nil {
  3466. br.Msg = "获取信息失败"
  3467. br.ErrMsg = "获取产品信息失败,Err:" + err.Error()
  3468. return
  3469. }
  3470. roleTypeCode := sysUser.RoleTypeCode
  3471. itemLen := len(productList)
  3472. btnDetailItem := new(company.ButtonDetailPermission)
  3473. //产品权限map
  3474. statusMap := make(map[int]string)
  3475. for i := 0; i < itemLen; i++ {
  3476. item := productList[i]
  3477. //添加产品权限map
  3478. statusMap[item.ProductId] = item.Status
  3479. if i == 0 {
  3480. if item.ProductId == 1 {
  3481. resp.CreateAuth = 1
  3482. } else {
  3483. resp.CreateAuth = 2
  3484. }
  3485. }
  3486. if item.ProductId == 1 {
  3487. if strings.Contains(sysUser.RoleTypeCode, "ficc") {
  3488. if item.Status == utils.COMPANY_STATUS_FREEZE || item.Status == utils.COMPANY_STATUS_LOSE {
  3489. btnDetailItem.BtnHistoryList = true
  3490. } else {
  3491. if item.SellerId == sysUser.AdminId {
  3492. btnDetailItem.BtnHistoryList = true
  3493. }
  3494. if sysUser.Authority > 0 {
  3495. if item.GroupId == sysUser.GroupId {
  3496. btnDetailItem.BtnHistoryList = true
  3497. }
  3498. if item.DepartmentId == sysUser.DepartmentId {
  3499. btnDetailItem.BtnHistoryList = true
  3500. }
  3501. }
  3502. }
  3503. }
  3504. //子权限切片集合
  3505. allFiccPermissions, permissionMap, e := services.GetBasePermissionLookItem(utils.COMPANY_PRODUCT_FICC_ID)
  3506. if e != nil {
  3507. br.Msg = "查询基础权限失败"
  3508. br.ErrMsg = "查询基础权限失败,Err:" + e.Error()
  3509. return
  3510. }
  3511. //遍历获取
  3512. for _, v := range allFiccPermissions {
  3513. if v.ParentId == 0 {
  3514. checkList := make([]int, 0)
  3515. plist := new(company.PermissionLookList)
  3516. plist.Items = make([]*company.PermissionLookItem, 0)
  3517. items, ok1 := permissionMap[v.ChartPermissionId]
  3518. if ok1 {
  3519. for itemK, n := range items {
  3520. permission, e := company.GetCompanyPermissionCheckItem(companyId, n.ChartPermissionId)
  3521. if e != nil && e.Error() != utils.ErrNoRow() {
  3522. br.Msg = "获取失败"
  3523. br.ErrMsg = "获取权限信息失败,Err:" + e.Error()
  3524. return
  3525. }
  3526. if permission != nil && permission.ChartPermissionId > 0 {
  3527. checkList = append(checkList, n.ChartPermissionId)
  3528. items[itemK].StartDate = permission.StartDate
  3529. items[itemK].EndDate = permission.EndDate
  3530. items[itemK].Status = permission.Status
  3531. endDateTime, _ := time.Parse(utils.FormatDate, permission.EndDate)
  3532. endDateTime = endDateTime.AddDate(0, 0, 1)
  3533. sub := endDateTime.Sub(time.Now())
  3534. if sub < 0 {
  3535. sub = 0
  3536. }
  3537. expireDay := fmt.Sprintf("%v", int(sub.Hours()/24))
  3538. items[itemK].ExpireDay = expireDay
  3539. }
  3540. }
  3541. plist.Items = items
  3542. }
  3543. plist.ClassifyName = v.PermissionName
  3544. plist.CheckList = checkList
  3545. item.PermissionList = append(item.PermissionList, plist)
  3546. }
  3547. }
  3548. resp.FiccItem = item
  3549. if (roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER ||
  3550. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP || roleTypeCode == utils.ROLE_TYPE_CODE_FICC_DEPARTMENT) &&
  3551. item.Status == utils.COMPANY_STATUS_TRY_OUT && item.ApproveStatus != "待审批" {
  3552. resp.IsButtonShow = 1
  3553. }
  3554. } else {
  3555. if strings.Contains(sysUser.RoleTypeCode, "rai") {
  3556. if item.Status == utils.COMPANY_STATUS_FREEZE || item.Status == utils.COMPANY_STATUS_LOSE {
  3557. btnDetailItem.BtnHistoryList = true
  3558. } else {
  3559. if item.SellerId == sysUser.AdminId {
  3560. btnDetailItem.BtnHistoryList = true
  3561. }
  3562. if sysUser.Authority > 0 {
  3563. if item.GroupId == sysUser.GroupId {
  3564. btnDetailItem.BtnHistoryList = true
  3565. }
  3566. if item.DepartmentId == sysUser.DepartmentId {
  3567. btnDetailItem.BtnHistoryList = true
  3568. }
  3569. }
  3570. }
  3571. }
  3572. classifyName := "权益"
  3573. checkList := make([]int, 0)
  3574. plist := new(company.PermissionLookList)
  3575. items, err := company.GetPermissionLookItems(item.ProductId, classifyName)
  3576. if err != nil {
  3577. br.Msg = "获取失败"
  3578. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  3579. return
  3580. }
  3581. for itemK, n := range items {
  3582. permission, err := company.GetCompanyPermissionCheckItem(companyId, n.ChartPermissionId)
  3583. if err != nil && err.Error() != utils.ErrNoRow() {
  3584. br.Msg = "获取失败"
  3585. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  3586. return
  3587. }
  3588. if permission != nil && permission.ChartPermissionId > 0 {
  3589. checkList = append(checkList, n.ChartPermissionId)
  3590. items[itemK].StartDate = permission.StartDate
  3591. items[itemK].EndDate = permission.EndDate
  3592. items[itemK].Status = permission.Status
  3593. endDateTime, _ := time.Parse(utils.FormatDate, permission.EndDate)
  3594. endDateTime = endDateTime.AddDate(0, 0, 1)
  3595. sub := endDateTime.Sub(time.Now())
  3596. if sub < 0 {
  3597. sub = 0
  3598. }
  3599. expireDay := fmt.Sprintf("%v", int(sub.Hours()/24))
  3600. items[itemK].ExpireDay = expireDay
  3601. }
  3602. //count, err := company.GetCompanyPermissionCheck(companyId, n.ChartPermissionId)
  3603. //if err != nil {
  3604. // br.Msg = "获取失败"
  3605. // br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  3606. // return
  3607. //}
  3608. //if count > 0 {
  3609. // checkList = append(checkList, n.ChartPermissionId)
  3610. //}
  3611. }
  3612. item.SpecialSurplus, err = cygxService.GetSpecialSurplusByCompanyNew(companyId)
  3613. if err != nil {
  3614. br.Msg = "获取失败"
  3615. br.ErrMsg = "获取专项调研信息失败,Err:" + err.Error()
  3616. return
  3617. }
  3618. plist.Items = items
  3619. plist.ClassifyName = classifyName
  3620. plist.CheckList = checkList
  3621. item.PermissionList = append(item.PermissionList, plist)
  3622. resp.RaiItem = item
  3623. if (roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER ||
  3624. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP ||
  3625. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_DEPARTMENT) &&
  3626. item.Status == utils.COMPANY_STATUS_TRY_OUT && item.ApproveStatus != "待审批" {
  3627. resp.IsButtonShow = 1
  3628. }
  3629. }
  3630. btnItem := services.GetCompanyPermissionButton(roleTypeCode, item.Status, strconv.Itoa(item.SellerId), strconv.Itoa(item.GroupId),
  3631. item.GroupId, sysUser.GroupId, item.SellerId, sysUser.AdminId, sysUser.Authority, item.ProductId, item.ShareSellerId, "")
  3632. //if itemLen > 1 {
  3633. // btnDetailItem.BtnEdit = false
  3634. // btnDetailItem.BtnDelete = false
  3635. //} else {
  3636. // btnDetailItem.BtnEdit = btnItem.BtnEdit
  3637. // btnDetailItem.BtnDelete = btnItem.BtnDelete
  3638. //}
  3639. switch item.ProductId {
  3640. case 1:
  3641. btnDetailItem.FiccEdit = btnItem.BtnEdit
  3642. btnDetailItem.FiccDelete = btnItem.BtnDelete
  3643. case 2:
  3644. btnDetailItem.RaiEdit = btnItem.BtnEdit
  3645. btnDetailItem.RaiDelete = btnItem.BtnDelete
  3646. }
  3647. if !btnDetailItem.BtnEdit {
  3648. btnDetailItem.BtnEdit = btnItem.BtnEdit
  3649. }
  3650. if !btnDetailItem.BtnDelete {
  3651. btnDetailItem.BtnDelete = btnItem.BtnDelete
  3652. }
  3653. //联系人操作权限
  3654. if resp.IsContractButtonShow == false {
  3655. resp.IsContractButtonShow = services.CheckCompanyUserButton(sysUser.RoleTypeCode, item.SellerId, sysUser.AdminId, item.ProductId, item.ShareSellerId, item.Status)
  3656. }
  3657. }
  3658. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN ||
  3659. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN ||
  3660. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  3661. resp.IsButtonShow = 1
  3662. btnDetailItem.BtnHistoryList = true
  3663. }
  3664. //ficc权限
  3665. if ficcStatus, ok := statusMap[1]; ok {
  3666. if ficcStatus == utils.COMPANY_STATUS_TRY_OUT {
  3667. if raiStatus, ok := statusMap[2]; ok {
  3668. //另一个权限也是 试用 、冻结、流失
  3669. if raiStatus == utils.COMPANY_STATUS_TRY_OUT || raiStatus == utils.COMPANY_STATUS_FREEZE || raiStatus == utils.COMPANY_STATUS_LOSE {
  3670. //那么超管、部门管理员、销售可以编辑
  3671. if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER || roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3672. btnDetailItem.BaseInfoEdit = true
  3673. }
  3674. }
  3675. //权益是永续时,超管可编辑基础信息
  3676. if raiStatus == utils.COMPANY_STATUS_FOREVER {
  3677. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3678. btnDetailItem.BaseInfoEdit = true
  3679. }
  3680. }
  3681. } else {
  3682. //权限未开,有编辑基础信息权限
  3683. btnDetailItem.BaseInfoEdit = true
  3684. }
  3685. }
  3686. if ficcStatus == utils.COMPANY_STATUS_FOREVER {
  3687. if raiStatus, ok := statusMap[2]; ok {
  3688. //另一个权限也是 永续 、冻结、流失
  3689. if raiStatus == utils.COMPANY_STATUS_TRY_OUT || raiStatus == utils.COMPANY_STATUS_FOREVER || raiStatus == utils.COMPANY_STATUS_FREEZE || raiStatus == utils.COMPANY_STATUS_LOSE {
  3690. //超管可编辑基础信息
  3691. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3692. btnDetailItem.BaseInfoEdit = true
  3693. }
  3694. }
  3695. } else {
  3696. //权限未开,有编辑基础信息权限
  3697. btnDetailItem.BaseInfoEdit = true
  3698. }
  3699. }
  3700. }
  3701. //权益销售
  3702. if raiStatus, ok := statusMap[2]; ok {
  3703. if raiStatus == utils.COMPANY_STATUS_TRY_OUT {
  3704. if ficcStatus, ok := statusMap[1]; ok {
  3705. //另一个权限也是 试用 、冻结、流失
  3706. if ficcStatus == utils.COMPANY_STATUS_TRY_OUT || ficcStatus == utils.COMPANY_STATUS_FREEZE || ficcStatus == utils.COMPANY_STATUS_LOSE {
  3707. //那么超管、部门管理员、销售可以编辑
  3708. if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER || roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3709. btnDetailItem.BaseInfoEdit = true
  3710. }
  3711. }
  3712. //ficc是永续时,超管可编辑基础信息
  3713. if ficcStatus == utils.COMPANY_STATUS_FOREVER {
  3714. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3715. btnDetailItem.BaseInfoEdit = true
  3716. }
  3717. }
  3718. } else {
  3719. //权限未开,有编辑基础信息权限
  3720. btnDetailItem.BaseInfoEdit = true
  3721. }
  3722. }
  3723. if raiStatus == utils.COMPANY_STATUS_FOREVER {
  3724. if ficcStatus, ok := statusMap[1]; ok {
  3725. //另一个权限也是 试用、永续 、冻结、流失
  3726. if ficcStatus == utils.COMPANY_STATUS_TRY_OUT || ficcStatus == utils.COMPANY_STATUS_FOREVER || ficcStatus == utils.COMPANY_STATUS_FREEZE || ficcStatus == utils.COMPANY_STATUS_LOSE {
  3727. //超管可编辑基础信息
  3728. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3729. btnDetailItem.BaseInfoEdit = true
  3730. }
  3731. }
  3732. } else {
  3733. //权限未开,有编辑基础信息权限
  3734. btnDetailItem.BaseInfoEdit = true
  3735. }
  3736. }
  3737. }
  3738. resp.Item = item
  3739. resp.BtnItem = btnDetailItem
  3740. br.Ret = 200
  3741. br.Success = true
  3742. br.Msg = "获取成功"
  3743. br.Data = resp
  3744. }
  3745. // @Title 编辑客户
  3746. // @Description 编辑客户接口
  3747. // @Param request body company.CompanyEditReq true "type json string"
  3748. // @Success Ret=200 保存成功
  3749. // @router /edit [post]
  3750. func (this *CompanyController) Edit() {
  3751. br := new(models.BaseResponse).Init()
  3752. defer func() {
  3753. this.Data["json"] = br
  3754. this.ServeJSON()
  3755. }()
  3756. sysUser := this.SysUser
  3757. if sysUser == nil {
  3758. br.Msg = "请登录"
  3759. br.ErrMsg = "请登录,SysUser Is Empty"
  3760. br.Ret = 408
  3761. return
  3762. }
  3763. //roleTypeCode := sysUser.RoleTypeCode
  3764. var req company.CompanyEditReq
  3765. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  3766. if err != nil {
  3767. br.Msg = "参数解析异常!"
  3768. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  3769. return
  3770. }
  3771. if req.CompanyId <= 0 {
  3772. br.Msg = "参数异常!"
  3773. br.ErrMsg = "CompanyId:" + strconv.Itoa(req.CompanyId)
  3774. return
  3775. }
  3776. if req.CompanyName == "" {
  3777. br.Msg = "请填写客户名称"
  3778. return
  3779. }
  3780. if req.CreditCode == "" {
  3781. br.Msg = "请填写社会统一信用码"
  3782. return
  3783. }
  3784. //移除空格
  3785. req.CreditCode = utils.TrimStr(req.CreditCode)
  3786. productId := services.GetProductId(sysUser.RoleTypeCode) //产品权限id
  3787. for _, v := range req.Products {
  3788. //X类试用,转为永续
  3789. if v.Status == utils.COMPANY_STATUS_X_CLASS_TRY_OUT {
  3790. v.Status = utils.COMPANY_STATUS_FOREVER
  3791. }
  3792. if productId == utils.COMPANY_PRODUCT_RAI_ID {
  3793. //查询客户的产品权限
  3794. companyReportPermissionListOld, err := company.GetCompanyReportPermission(req.CompanyId, productId)
  3795. if err != nil {
  3796. br.Msg = "查询客户的产品权限异常"
  3797. br.ErrMsg = "查询客户的产品权限异常:" + err.Error()
  3798. return
  3799. }
  3800. permissionArr := strings.Split(v.PermissionIds, ",")
  3801. //如果所选行业不属于研选订阅跟研选扣点包,那就是非研选试用客户
  3802. var isNoResearch bool
  3803. for _, v := range permissionArr {
  3804. if v != strconv.Itoa(utils.CHART_PERMISSION_ID_YANXUAN) && v != strconv.Itoa(utils.YAN_XUAN_KOU_DIAN_BAO_ID) {
  3805. isNoResearch = true
  3806. continue
  3807. }
  3808. }
  3809. if isNoResearch && len(companyReportPermissionListOld) != len(permissionArr) {
  3810. tryOutCountRai, err := company.GetRaiCompanyTryOutCountNoResearch(sysUser.AdminId)
  3811. if err != nil {
  3812. br.Msg = "判断试用客户量失败"
  3813. br.ErrMsg = "判断试用客户量失败,Err:" + err.Error()
  3814. return
  3815. }
  3816. if tryOutCountRai >= utils.COMPANY_STATUS_TRY_OUT_COUNT_RAI {
  3817. br.Msg = "非研选试用客户最多40家"
  3818. return
  3819. }
  3820. }
  3821. }
  3822. if v.IndustryId <= 0 {
  3823. br.Msg = "请选择行业"
  3824. br.IsSendEmail = false
  3825. return
  3826. }
  3827. //获取客户产品信息
  3828. productItem, err := company.GetCompanyProductById(v.CompanyProductId)
  3829. if err != nil {
  3830. br.Msg = "数据获取失败!"
  3831. br.ErrMsg = "数据获取失败,Err:" + err.Error()
  3832. return
  3833. }
  3834. if productItem == nil {
  3835. br.Msg = "客户信息不存在!"
  3836. return
  3837. }
  3838. // 如果本身是有权限归属的,同时传入的参数不是当前账号权限的,那么过滤该次循环,进入下次循环
  3839. if productId > 0 && productItem.ProductId != productId {
  3840. continue
  3841. }
  3842. if v.Status == "" {
  3843. br.Msg = "客户状态不可为空"
  3844. return
  3845. }
  3846. //if v.Reasons == "" {
  3847. // br.Msg = "请填写新增理由"
  3848. // return
  3849. //}
  3850. if v.PermissionIds == "" {
  3851. br.Msg = "请选择权限"
  3852. return
  3853. }
  3854. var startDate, endDate string
  3855. startDate = productItem.StartDate
  3856. endDate = productItem.EndDate
  3857. if startDate == "" || endDate == "" {
  3858. br.Msg = "数据错误"
  3859. br.Msg = "数据错误,开始或结束日期为空:startDate:" + startDate + "endDate:" + endDate
  3860. return
  3861. }
  3862. //判断客户是否已经存在
  3863. companyNameIsExist, err := company.GetCompanyCountByCompanyNameAndCompanyId(req.CompanyId, req.CompanyName)
  3864. if err != nil {
  3865. br.Msg = "判断客户是否存在失败"
  3866. br.ErrMsg = "判断客户是否存在失败,Err:" + err.Error()
  3867. return
  3868. }
  3869. if companyNameIsExist > 0 {
  3870. br.Msg = "客户已存在,请重新输入客户名称"
  3871. return
  3872. }
  3873. //判断客户是否已经存在
  3874. companyCreditCodeIsExist, err := company.GetCompanyCountByCreditCodeAndCompanyId(req.CompanyId, req.CreditCode)
  3875. if err != nil {
  3876. br.Msg = "判断客户是否存在失败"
  3877. br.ErrMsg = "判断客户是否存在失败,Err:" + err.Error()
  3878. return
  3879. }
  3880. if companyCreditCodeIsExist > 0 {
  3881. br.Msg = "客户已存在,请重新输入统一社会信用代码"
  3882. return
  3883. }
  3884. seller, err := system.GetSysAdminById(v.SellsId)
  3885. if err != nil {
  3886. br.Msg = "获取销售信息失败"
  3887. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  3888. return
  3889. }
  3890. if seller == nil {
  3891. br.Msg = "所属销售不存在"
  3892. return
  3893. }
  3894. //tryOutCount, err := company.GetCompanyTryOutCount(utils.COMPANY_STATUS_TRY_OUT, seller.AdminId)
  3895. //if err != nil {
  3896. // br.Msg = "判断试用客户量失败"
  3897. // br.ErrMsg = "判断试用客户量失败,Err:" + err.Error()
  3898. // return
  3899. //}
  3900. //if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_FICC_DEPARTMENT ||
  3901. // roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER || roleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
  3902. // if tryOutCount >= utils.COMPANY_STATUS_TRY_OUT_COUNT && v.SellsId == sysUser.AdminId {
  3903. // br.Msg = "您的试用客户总数,已超过上限,不可继续新增"
  3904. // return
  3905. // }
  3906. //}
  3907. industry, err := company.GetCompanyIndustryById(v.IndustryId)
  3908. if err != nil {
  3909. br.Msg = "获取行业信息失败"
  3910. br.ErrMsg = "获取行业信息失败,Err:" + err.Error()
  3911. return
  3912. }
  3913. companyProduct := new(company.CompanyProduct)
  3914. companyProduct.ProductId = productItem.ProductId
  3915. companyProduct.CompanyId = req.CompanyId
  3916. companyProduct.CompanyName = req.CompanyName
  3917. companyProduct.Source = v.Source
  3918. companyProduct.Reasons = v.Reasons
  3919. companyProduct.Status = v.Status
  3920. companyProduct.StartDate = startDate
  3921. companyProduct.EndDate = endDate
  3922. companyProduct.IndustryId = v.IndustryId
  3923. companyProduct.IndustryName = industry.IndustryName
  3924. companyProduct.SellerId = seller.AdminId
  3925. companyProduct.SellerName = seller.RealName
  3926. companyProduct.GroupId = seller.GroupId
  3927. companyProduct.DepartmentId = seller.DepartmentId
  3928. companyProduct.IsSuspend = 0
  3929. companyProduct.ModifyTime = time.Now()
  3930. companyProduct.CompanyProductId = v.CompanyProductId
  3931. companyProduct.Scale = v.Scale
  3932. err = company.ModifyCompanyProduct(companyProduct)
  3933. if err != nil {
  3934. br.Msg = "修改客户信息失败"
  3935. br.ErrMsg = "修改客户产品信息失败,Err:" + err.Error()
  3936. return
  3937. }
  3938. // CRM8.8-下面的需求取消, 编辑的时候根据选择开通对应权限
  3939. // 如果是权益客户,编辑的时候开通主观客观权限
  3940. //if v.CompanyType == utils.COMPANY_CLASSIFY_RAI {
  3941. // permissionStr, err := company.GetPermissionIdById(v.PermissionIds)
  3942. // if err != nil {
  3943. // br.Msg = "修改失败"
  3944. // br.ErrMsg = "获取主观客观权限信息失败,Err:" + err.Error()
  3945. // return
  3946. // }
  3947. // v.PermissionIds = permissionStr
  3948. //}
  3949. //处理权限
  3950. companyReportPermissionList, err := services.AddCompanyPermission(req.CompanyId, seller.AdminId, productItem.ProductId, productItem.ProductName, seller.RealName, v.PermissionIds, startDate, endDate)
  3951. if err != nil {
  3952. br.Msg = "修改失败"
  3953. br.ErrMsg = "新增客户设置权限失败,err:" + err.Error()
  3954. return
  3955. }
  3956. //新增操作记录
  3957. {
  3958. record := new(company.CompanyOperationRecord)
  3959. record.CompanyId = req.CompanyId
  3960. record.CompanyName = req.CompanyName
  3961. record.SellerId = companyProduct.SellerId
  3962. record.SysUserId = this.SysUser.AdminId
  3963. record.SysRealName = this.SysUser.RealName
  3964. record.Remark = "编辑客户"
  3965. record.Operation = "edit"
  3966. record.CreateTime = time.Now()
  3967. record.ProductId = productItem.ProductId
  3968. record.ProductName = productItem.ProductName
  3969. record.Status = productItem.Status
  3970. _, err = company.AddCompanyOperationRecord(record)
  3971. if err != nil {
  3972. go alarm_msg.SendAlarmMsg("URI:"+this.Ctx.Input.URI()+"<br/> "+";<br/> Body:"+err.Error(), 3)
  3973. //go utils.SendEmail(utils.APPNAME+"失败提醒"+utils.RunMode, "URI:"+this.Ctx.Input.URI()+"<br/> "+";<br/> Body:"+err.Error(), utils.EmailSendToUsers)
  3974. }
  3975. }
  3976. //新增客户产品日志
  3977. {
  3978. productLog := new(company.CompanyProductLog)
  3979. productLog.CompanyProductId = v.CompanyProductId
  3980. productLog.CompanyId = companyProduct.CompanyId
  3981. productLog.ProductId = companyProduct.ProductId
  3982. productLog.ProductName = companyProduct.ProductName
  3983. productLog.CompanyName = companyProduct.CompanyName
  3984. productLog.CompanyName = companyProduct.CompanyName
  3985. productLog.Source = companyProduct.Source
  3986. productLog.Reasons = companyProduct.Reasons
  3987. productLog.Status = companyProduct.Status
  3988. productLog.IndustryId = companyProduct.IndustryId
  3989. productLog.IndustryName = companyProduct.IndustryName
  3990. productLog.SellerId = companyProduct.SellerId
  3991. productLog.SellerName = companyProduct.SellerName
  3992. productLog.GroupId = companyProduct.GroupId
  3993. productLog.DepartmentId = companyProduct.DepartmentId
  3994. productLog.IsSuspend = companyProduct.IsSuspend
  3995. productLog.SuspendTime = companyProduct.SuspendTime
  3996. productLog.ApproveStatus = companyProduct.ApproveStatus
  3997. productLog.FreezeTime = companyProduct.FreezeTime
  3998. productLog.Remark = companyProduct.Remark
  3999. productLog.StartDate = companyProduct.StartDate
  4000. productLog.EndDate = companyProduct.EndDate
  4001. productLog.CreateTime = companyProduct.CreateTime
  4002. productLog.ModifyTime = companyProduct.ModifyTime
  4003. productLog.LoseReason = companyProduct.LoseReason
  4004. productLog.LossTime = companyProduct.LossTime
  4005. productLog.LogType = "modify"
  4006. productLog.LogCreateTime = time.Now()
  4007. productLog.AdminId = this.SysUser.AdminId
  4008. productLog.Scale = companyProduct.Scale
  4009. go company.AddCompanyProductLog(productLog)
  4010. }
  4011. //新增客户产品状态变更日志
  4012. {
  4013. startDateTime, _ := time.ParseInLocation(utils.FormatDate, startDate, time.Local)
  4014. endDateTime, _ := time.ParseInLocation(utils.FormatDate, endDate, time.Local)
  4015. companyProductUpdateLog := &company.CompanyProductUpdateLog{
  4016. Id: 0,
  4017. CompanyId: req.CompanyId,
  4018. ProductId: productId,
  4019. Status: "试用",
  4020. Source: "edit",
  4021. SellerId: seller.AdminId,
  4022. SellerName: seller.RealName,
  4023. StartDate: startDateTime,
  4024. EndDate: endDateTime,
  4025. RealEndDate: startDateTime,
  4026. CreateTime: time.Now(),
  4027. }
  4028. go company.AddCompanyProductUpdateLog(companyProductUpdateLog)
  4029. // 添加试用记录
  4030. companyProductTryOutUpdateLog := &company.CompanyProductTryOutUpdateLog{
  4031. Id: 0,
  4032. CompanyId: req.CompanyId,
  4033. ProductId: productId,
  4034. Source: "edit",
  4035. SellerId: seller.AdminId,
  4036. SellerName: seller.RealName,
  4037. StartDate: startDateTime,
  4038. EndDate: endDateTime,
  4039. RealEndDate: startDateTime,
  4040. IsStop: 0,
  4041. CreateTime: time.Now(),
  4042. }
  4043. go company.AddCompanyProductTryOutUpdateLog(companyProductTryOutUpdateLog, companyReportPermissionList)
  4044. }
  4045. }
  4046. companyItem := new(company.Company)
  4047. companyItem.CompanyId = req.CompanyId
  4048. companyItem.CompanyName = req.CompanyName
  4049. companyItem.CreditCode = req.CreditCode
  4050. companyItem.Province = req.Province
  4051. companyItem.City = req.City
  4052. companyItem.Address = req.Province + req.City
  4053. companyItem.LastUpdatedTime = time.Now()
  4054. companyItem.Enabled = 1
  4055. companyItem.Nation = req.Nation
  4056. err = company.ModifyCompany(companyItem)
  4057. if err != nil {
  4058. br.Msg = "修改客户信息失败"
  4059. br.ErrMsg = "修改客户信息失败,Err:" + err.Error()
  4060. return
  4061. }
  4062. //新增客户日志
  4063. {
  4064. companyLog := new(company.CompanyLog)
  4065. companyLog.CompanyId = req.CompanyId
  4066. companyLog.CompanyName = req.CompanyName
  4067. companyLog.CreditCode = req.CreditCode
  4068. companyLog.Address = companyItem.Address
  4069. companyLog.City = companyItem.City
  4070. companyLog.Province = companyItem.Province
  4071. companyLog.LastUpdatedTime = companyItem.LastUpdatedTime
  4072. companyLog.AdminId = this.SysUser.AdminId
  4073. companyLog.LogType = "modify"
  4074. companyLog.LogCreateTime = time.Now()
  4075. go company.AddCompanyLog(companyLog)
  4076. }
  4077. br.Ret = 200
  4078. br.Success = true
  4079. br.Msg = "保存成功"
  4080. }
  4081. // @Title 编辑补充客户信息接口
  4082. // @Description 编辑补充客户信息接口
  4083. // @Param request body company.CompanyInfoEditReq true "type json string"
  4084. // @Success Ret=200 保存成功
  4085. // @router /company_info/edit [post]
  4086. func (this *CompanyController) EditCompanyInfo() {
  4087. br := new(models.BaseResponse).Init()
  4088. defer func() {
  4089. this.Data["json"] = br
  4090. this.ServeJSON()
  4091. }()
  4092. sysUser := this.SysUser
  4093. if sysUser == nil {
  4094. br.Msg = "请登录"
  4095. br.ErrMsg = "请登录,SysUser Is Empty"
  4096. br.Ret = 408
  4097. return
  4098. }
  4099. var req company.CompanyInfoEditReq
  4100. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  4101. if err != nil {
  4102. br.Msg = "参数解析异常!"
  4103. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  4104. return
  4105. }
  4106. if req.CompanyId <= 0 {
  4107. br.Msg = "参数异常!"
  4108. br.ErrMsg = "CompanyId:" + strconv.Itoa(req.CompanyId)
  4109. return
  4110. }
  4111. if req.CompanyName == "" {
  4112. br.Msg = "请填写客户名称"
  4113. return
  4114. }
  4115. if req.CreditCode == "" {
  4116. br.Msg = "请填写社会统一信用码"
  4117. return
  4118. }
  4119. //if req.Province == "" {
  4120. // br.Msg = "请选择省份"
  4121. // return
  4122. //}
  4123. //if req.City == "" {
  4124. // br.Msg = "请选择市区"
  4125. // return
  4126. //}
  4127. //if req.IndustryId <= 0 {
  4128. // br.Msg = "请选择所属行业"
  4129. // return
  4130. //}
  4131. //if req.IndustryName == "" {
  4132. // br.Msg = "请选择所属行业"
  4133. // return
  4134. //}
  4135. //if req.Source == "" {
  4136. // br.Msg = "请选择来源"
  4137. // return
  4138. //}
  4139. //移除空格
  4140. req.CreditCode = utils.TrimStr(req.CreditCode)
  4141. //获取产品权限
  4142. productId := services.GetProductId(sysUser.RoleTypeCode)
  4143. if productId <= 0 {
  4144. br.Msg = "当前账号不允许修改客户信息"
  4145. return
  4146. }
  4147. companyNameIsExist, err := company.GetCompanyCountByCompanyNameAndCompanyId(req.CompanyId, req.CompanyName)
  4148. if err != nil {
  4149. br.Msg = "判断客户是否存在失败"
  4150. br.ErrMsg = "判断客户是否存在失败,Err:" + err.Error()
  4151. return
  4152. }
  4153. if companyNameIsExist > 0 {
  4154. br.Msg = "客户已存在,请重新输入客户名称"
  4155. return
  4156. }
  4157. //判断客户是否已经存在
  4158. companyCreditCodeIsExist, err := company.GetCompanyCountByCreditCodeAndCompanyId(req.CompanyId, req.CreditCode)
  4159. if err != nil {
  4160. br.Msg = "判断客户是否存在失败"
  4161. br.ErrMsg = "判断客户是否存在失败,Err:" + err.Error()
  4162. return
  4163. }
  4164. if companyCreditCodeIsExist > 0 {
  4165. br.Msg = "客户已存在,统一社会信用代码"
  4166. return
  4167. }
  4168. //查询该客户
  4169. companyItem, err := company.GetCompanyById(req.CompanyId)
  4170. if err != nil {
  4171. br.Msg = "查找客户失败"
  4172. br.ErrMsg = "查找客户失败,Err:" + err.Error()
  4173. return
  4174. }
  4175. //待更新字段
  4176. updateCol := make([]string, 0)
  4177. companyItem.CompanyName = req.CompanyName
  4178. companyItem.CreditCode = req.CreditCode
  4179. companyItem.Enabled = 1
  4180. companyItem.LastUpdatedTime = time.Now()
  4181. updateCol = append(updateCol, "CompanyName", "CreditCode", "Enabled", "LastUpdatedTime")
  4182. if req.Province != "" && req.City != "" {
  4183. companyItem.Province = req.Province
  4184. companyItem.City = req.City
  4185. companyItem.Address = req.Province + req.City
  4186. updateCol = append(updateCol, "Province", "City", "Address")
  4187. }
  4188. err = companyItem.Update(updateCol)
  4189. if err != nil {
  4190. br.Msg = "修改客户信息失败"
  4191. br.ErrMsg = "修改客户信息失败,Err:" + err.Error()
  4192. return
  4193. }
  4194. //查询并更新客户产品信息
  4195. companyProduct, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, productId)
  4196. if err != nil {
  4197. if err.Error() != utils.ErrNoRow() {
  4198. br.Msg = "查询客户产品信息失败"
  4199. br.ErrMsg = "查询客户产品信息失败,Err:" + err.Error()
  4200. return
  4201. }
  4202. } else {
  4203. if companyProduct != nil {
  4204. //客户产品待更新字段
  4205. updateCompanyProductCol := make([]string, 0)
  4206. //产品信息(来源、行业)
  4207. if req.IndustryId != 0 && req.IndustryId != companyProduct.IndustryId {
  4208. companyProduct.IndustryId = req.IndustryId
  4209. companyProduct.IndustryName = req.IndustryName
  4210. updateCompanyProductCol = append(updateCompanyProductCol, "IndustryId", "IndustryName")
  4211. }
  4212. if req.Source != "" && req.Source != companyProduct.Source {
  4213. companyProduct.Source = req.Source
  4214. updateCompanyProductCol = append(updateCompanyProductCol, "Source")
  4215. }
  4216. //更新客户产品信息
  4217. if len(updateCompanyProductCol) > 0 {
  4218. err = companyProduct.Update(updateCompanyProductCol)
  4219. if err != nil {
  4220. br.Msg = "修改客户信息失败"
  4221. br.ErrMsg = "修改客户信息失败,Err:" + err.Error()
  4222. return
  4223. }
  4224. }
  4225. }
  4226. }
  4227. //新增客户日志
  4228. {
  4229. companyLog := new(company.CompanyLog)
  4230. companyLog.CompanyId = req.CompanyId
  4231. companyLog.CompanyName = req.CompanyName
  4232. companyLog.CreditCode = req.CreditCode
  4233. companyLog.Address = companyItem.Address
  4234. companyLog.City = companyItem.City
  4235. companyLog.Province = companyItem.Province
  4236. companyLog.LastUpdatedTime = companyItem.LastUpdatedTime
  4237. companyLog.AdminId = this.SysUser.AdminId
  4238. companyLog.LogType = "modify"
  4239. companyLog.LogCreateTime = time.Now()
  4240. go company.AddCompanyLog(companyLog)
  4241. }
  4242. br.Ret = 200
  4243. br.Success = true
  4244. br.Msg = "保存成功"
  4245. }
  4246. // @Title 客户模糊检索(新增/编辑客户页面试用)
  4247. // @Description 客户模糊检索接口(新增/编辑客户页面试用)
  4248. // @Param KeyWord query string true "搜索关键词"
  4249. // @Success 200 {object} company.CompanyFuzzySearchReq
  4250. // @router /fuzzy/search [get]
  4251. func (this *CompanyController) FuzzySearch() {
  4252. br := new(models.BaseResponse).Init()
  4253. defer func() {
  4254. this.Data["json"] = br
  4255. this.ServeJSON()
  4256. }()
  4257. keyWord := this.GetString("KeyWord")
  4258. list, err := company.GetCompanyFuzzySearch(keyWord)
  4259. if err != nil {
  4260. br.Msg = "获取信息失败"
  4261. br.ErrMsg = "获取信息失败,err:" + err.Error()
  4262. return
  4263. }
  4264. resp := new(company.CompanyFuzzySearchReq)
  4265. resp.List = list
  4266. br.Ret = 200
  4267. br.Success = true
  4268. br.Msg = "获取成功"
  4269. br.Data = resp
  4270. }
  4271. // @Title 删除客户
  4272. // @Description 删除客户接口
  4273. // @Param request body company.DeletePptReq true "type json string"
  4274. // @Success Ret=200 保存成功
  4275. // @router /delete [post]
  4276. func (this *CompanyController) Delete() {
  4277. br := new(models.BaseResponse).Init()
  4278. defer func() {
  4279. this.Data["json"] = br
  4280. this.ServeJSON()
  4281. }()
  4282. sysUser := this.SysUser
  4283. if sysUser == nil {
  4284. br.Msg = "请登录"
  4285. br.ErrMsg = "请登录,SysUser Is Empty"
  4286. br.Ret = 408
  4287. return
  4288. }
  4289. var req company.DeletePptReq
  4290. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  4291. if err != nil {
  4292. br.Msg = "参数解析异常!"
  4293. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  4294. return
  4295. }
  4296. if req.CompanyId <= 0 {
  4297. br.Msg = "参数错误"
  4298. br.ErrMsg = "客户ID小于等于0"
  4299. return
  4300. }
  4301. roleTypeCode := this.SysUser.RoleTypeCode
  4302. productId := services.GetProductId(roleTypeCode)
  4303. productItems, err := company.GetCompanyProductsByCompanyId(req.CompanyId)
  4304. if err != nil {
  4305. br.Msg = "删除失败"
  4306. br.ErrMsg = "获取客户产品信息失败,Err:" + err.Error()
  4307. return
  4308. }
  4309. // 备份信息
  4310. companyDeleteBakInfo := services.CompanyDeleteBakInfo{
  4311. CompanyId: req.CompanyId,
  4312. CompanyName: "",
  4313. CompanyInfo: &company.Company{},
  4314. CompanyProductInfo: make([]*company.CompanyProduct, 0),
  4315. CompanyPermissionInfo: make([]*company.CompanyReportPermission, 0),
  4316. UserSellerRelationInfo: make([]*models.UserSellerRelation, 0),
  4317. UserRecordInfo: make([]*models.UserRecord, 0),
  4318. UserInfo: make([]*models.WxUser, 0),
  4319. CompanyChartPermissionInfo: make([]*company_user.ChartClassifyPermission, 0),
  4320. OpUserId: this.SysUser.AdminId,
  4321. OpUserName: this.SysUser.RealName,
  4322. }
  4323. if productId == 0 {
  4324. for _, v := range productItems {
  4325. //永续,试用,流失,关闭
  4326. 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 {
  4327. br.Msg = "该客户" + v.ProductName + "属性为" + v.Status + ",暂不可删除"
  4328. br.ErrMsg = "该客户" + v.ProductName + "属性为" + v.Status + ",暂不可删除"
  4329. return
  4330. }
  4331. companyProductList, companyReportPermissionList, err := company.DeleteCompanyProductById(v.CompanyId, v.ProductId, v.CompanyProductId)
  4332. if err != nil {
  4333. br.Msg = "删除失败"
  4334. br.ErrMsg = "删除失败,Err:" + err.Error()
  4335. return
  4336. }
  4337. companyDeleteBakInfo.CompanyProductInfo = append(companyDeleteBakInfo.CompanyProductInfo, companyProductList...)
  4338. companyDeleteBakInfo.CompanyPermissionInfo = append(companyDeleteBakInfo.CompanyPermissionInfo, companyReportPermissionList...)
  4339. //新增操作记录
  4340. {
  4341. record := new(company.CompanyOperationRecord)
  4342. record.CompanyId = req.CompanyId
  4343. record.CompanyName = v.CompanyName
  4344. record.SellerId = v.SellerId
  4345. record.SysUserId = this.SysUser.AdminId
  4346. record.SysRealName = this.SysUser.RealName
  4347. record.Remark = "删除客户"
  4348. record.Operation = "delete"
  4349. record.CreateTime = time.Now()
  4350. record.ProductId = v.ProductId
  4351. record.ProductName = v.ProductName
  4352. _, err = company.AddCompanyOperationRecord(record)
  4353. if err != nil {
  4354. go alarm_msg.SendAlarmMsg("URI:"+this.Ctx.Input.URI()+"<br/> "+";<br/> Body:"+err.Error(), 3)
  4355. //go utils.SendEmail(utils.APPNAME+"失败提醒"+utils.RunMode, "URI:"+this.Ctx.Input.URI()+"<br/> "+";<br/> Body:"+err.Error(), utils.EmailSendToUsers)
  4356. }
  4357. }
  4358. //删除对应产品的联系人
  4359. userSellerRelationList, userRecordList, wxUserList, chartClassifyPermission, _ := services.DeleteCompanyWxUserByProductId(v.CompanyId, v.ProductId)
  4360. //备份信息
  4361. {
  4362. if companyProductList != nil {
  4363. companyDeleteBakInfo.CompanyProductInfo = append(companyDeleteBakInfo.CompanyProductInfo, companyProductList...)
  4364. }
  4365. if companyReportPermissionList != nil {
  4366. companyDeleteBakInfo.CompanyPermissionInfo = append(companyDeleteBakInfo.CompanyPermissionInfo, companyReportPermissionList...)
  4367. }
  4368. if userSellerRelationList != nil {
  4369. companyDeleteBakInfo.UserSellerRelationInfo = append(companyDeleteBakInfo.UserSellerRelationInfo, userSellerRelationList...)
  4370. }
  4371. if userRecordList != nil {
  4372. companyDeleteBakInfo.UserRecordInfo = append(companyDeleteBakInfo.UserRecordInfo, userRecordList...)
  4373. }
  4374. if wxUserList != nil {
  4375. companyDeleteBakInfo.UserInfo = append(companyDeleteBakInfo.UserInfo, wxUserList...)
  4376. }
  4377. if chartClassifyPermission != nil {
  4378. companyDeleteBakInfo.CompanyChartPermissionInfo = append(companyDeleteBakInfo.CompanyChartPermissionInfo, chartClassifyPermission...)
  4379. }
  4380. companyDeleteBakInfo.CompanyName = v.CompanyName
  4381. }
  4382. }
  4383. } else {
  4384. productObj, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, productId)
  4385. if err != nil {
  4386. br.ErrMsg = "获取客户产品信息失败,Err:" + err.Error()
  4387. br.Msg = "删除失败"
  4388. return
  4389. }
  4390. //永续,试用,流失,关闭
  4391. 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 {
  4392. br.Msg = "该客户" + productObj.ProductName + "属性为" + productObj.Status + ",暂不可删除"
  4393. br.ErrMsg = "该客户" + productObj.ProductName + "属性为" + productObj.Status + ",暂不可删除"
  4394. return
  4395. }
  4396. companyProductList, companyReportPermissionList, err := company.DeleteCompanyProductById(productObj.CompanyId, productObj.ProductId, productObj.CompanyProductId)
  4397. if err != nil {
  4398. br.Msg = "删除失败"
  4399. br.ErrMsg = "删除失败,Err:" + err.Error()
  4400. return
  4401. }
  4402. //新增操作记录
  4403. {
  4404. record := new(company.CompanyOperationRecord)
  4405. record.CompanyId = req.CompanyId
  4406. record.CompanyName = productObj.CompanyName
  4407. record.SellerId = productObj.SellerId
  4408. record.SysUserId = this.SysUser.AdminId
  4409. record.SysRealName = this.SysUser.RealName
  4410. record.Remark = "删除客户"
  4411. record.Operation = "delete"
  4412. record.CreateTime = time.Now()
  4413. record.ProductId = productObj.ProductId
  4414. record.ProductName = productObj.ProductName
  4415. _, err = company.AddCompanyOperationRecord(record)
  4416. if err != nil {
  4417. go alarm_msg.SendAlarmMsg("URI:"+this.Ctx.Input.URI()+"<br/> "+";<br/> Body:"+err.Error(), 3)
  4418. //go utils.SendEmail(utils.APPNAME+"失败提醒"+utils.RunMode, "URI:"+this.Ctx.Input.URI()+"<br/> "+";<br/> Body:"+err.Error(), utils.EmailSendToUsers)
  4419. }
  4420. }
  4421. //删除对应产品的联系人
  4422. userSellerRelationList, userRecordList, wxUserList, chartClassifyPermission, _ := services.DeleteCompanyWxUserByProductId(productObj.CompanyId, productId)
  4423. //备份信息
  4424. {
  4425. if companyProductList != nil {
  4426. companyDeleteBakInfo.CompanyProductInfo = append(companyDeleteBakInfo.CompanyProductInfo, companyProductList...)
  4427. }
  4428. if companyReportPermissionList != nil {
  4429. companyDeleteBakInfo.CompanyPermissionInfo = append(companyDeleteBakInfo.CompanyPermissionInfo, companyReportPermissionList...)
  4430. }
  4431. if userSellerRelationList != nil {
  4432. companyDeleteBakInfo.UserSellerRelationInfo = append(companyDeleteBakInfo.UserSellerRelationInfo, userSellerRelationList...)
  4433. }
  4434. if userRecordList != nil {
  4435. companyDeleteBakInfo.UserRecordInfo = append(companyDeleteBakInfo.UserRecordInfo, userRecordList...)
  4436. }
  4437. if wxUserList != nil {
  4438. companyDeleteBakInfo.UserInfo = append(companyDeleteBakInfo.UserInfo, wxUserList...)
  4439. }
  4440. if chartClassifyPermission != nil {
  4441. companyDeleteBakInfo.CompanyChartPermissionInfo = append(companyDeleteBakInfo.CompanyChartPermissionInfo, chartClassifyPermission...)
  4442. }
  4443. companyDeleteBakInfo.CompanyName = productObj.CompanyName
  4444. }
  4445. }
  4446. productItemsNew, err := company.GetCompanyProductsByCompanyId(req.CompanyId)
  4447. if err != nil {
  4448. br.Msg = "删除失败"
  4449. br.ErrMsg = "获取客户产品信息失败,Err:" + err.Error()
  4450. return
  4451. }
  4452. if len(productItemsNew) == 0 {
  4453. //删除之前查询的数据信息
  4454. {
  4455. companyProductLists, companyReportPermissions, wxUsers, userSellerRelations, companyContracts, companyContractPermissions, companyInfo, _ := services.GetBeforeDeleteCompanyInfo(req.CompanyId)
  4456. //companyDeleteBakInfo
  4457. if companyProductLists != nil {
  4458. companyDeleteBakInfo.CompanyProductInfo = append(companyDeleteBakInfo.CompanyProductInfo, companyProductLists...)
  4459. }
  4460. if companyReportPermissions != nil {
  4461. companyDeleteBakInfo.CompanyPermissionInfo = append(companyDeleteBakInfo.CompanyPermissionInfo, companyReportPermissions...)
  4462. }
  4463. if wxUsers != nil {
  4464. companyDeleteBakInfo.UserInfo = append(companyDeleteBakInfo.UserInfo, wxUsers...)
  4465. }
  4466. if userSellerRelations != nil {
  4467. companyDeleteBakInfo.UserSellerRelationInfo = append(companyDeleteBakInfo.UserSellerRelationInfo, userSellerRelations...)
  4468. }
  4469. if companyContracts != nil {
  4470. companyDeleteBakInfo.CompanyContract = append(companyDeleteBakInfo.CompanyContract, companyContracts...)
  4471. }
  4472. if companyContractPermissions != nil {
  4473. companyDeleteBakInfo.CompanyContractPermission = append(companyDeleteBakInfo.CompanyContractPermission, companyContractPermissions...)
  4474. }
  4475. if companyInfo != nil {
  4476. companyDeleteBakInfo.CompanyName = companyInfo.CompanyName
  4477. companyDeleteBakInfo.CompanyInfo = companyInfo
  4478. }
  4479. }
  4480. err = company.DeleteCompanyById(req.CompanyId)
  4481. if err != nil {
  4482. br.Msg = "删除失败"
  4483. br.ErrMsg = "删除失败,Err:" + err.Error()
  4484. return
  4485. }
  4486. for _, v := range productItems {
  4487. //新增操作记录
  4488. {
  4489. record := new(company.CompanyOperationRecord)
  4490. record.CompanyId = req.CompanyId
  4491. record.CompanyName = v.CompanyName
  4492. record.SellerId = v.SellerId
  4493. record.SysUserId = this.SysUser.AdminId
  4494. record.SysRealName = this.SysUser.RealName
  4495. record.Remark = "删除客户"
  4496. record.Operation = "delete"
  4497. record.CreateTime = time.Now()
  4498. record.ProductId = v.ProductId
  4499. record.ProductName = v.ProductName
  4500. _, err = company.AddCompanyOperationRecord(record)
  4501. if err != nil {
  4502. go alarm_msg.SendAlarmMsg("URI:"+this.Ctx.Input.URI()+"<br/> "+";<br/> Body:"+err.Error(), 3)
  4503. //go utils.SendEmail(utils.APPNAME+"失败提醒"+utils.RunMode, "URI:"+this.Ctx.Input.URI()+"<br/> "+";<br/> Body:"+err.Error(), utils.EmailSendToUsers)
  4504. }
  4505. }
  4506. }
  4507. }
  4508. //数据备份入库
  4509. {
  4510. companyInfoJsonByte, _ := json.Marshal(companyDeleteBakInfo.CompanyInfo)
  4511. companyProductInfoJsonByte, _ := json.Marshal(companyDeleteBakInfo.CompanyProductInfo)
  4512. companyPermissionInfoJsonByte, _ := json.Marshal(companyDeleteBakInfo.CompanyPermissionInfo)
  4513. userSellerRelationInfoJsonByte, _ := json.Marshal(companyDeleteBakInfo.UserSellerRelationInfo)
  4514. userRecordInfoJsonByte, _ := json.Marshal(companyDeleteBakInfo.UserRecordInfo)
  4515. userInfoJsonByte, _ := json.Marshal(companyDeleteBakInfo.UserInfo)
  4516. companyChartPermissionInfoJsonByte, _ := json.Marshal(companyDeleteBakInfo.CompanyChartPermissionInfo)
  4517. companyContractByte, _ := json.Marshal(companyDeleteBakInfo.CompanyContract)
  4518. companyContractPermissionJsonByte, _ := json.Marshal(companyDeleteBakInfo.CompanyContractPermission)
  4519. companyDeleteBak := &company.CompanyDeleteBak{
  4520. //DeleteBakId: 0,
  4521. CompanyId: companyDeleteBakInfo.CompanyId,
  4522. CompanyName: companyDeleteBakInfo.CompanyName,
  4523. CompanyInfo: string(companyInfoJsonByte),
  4524. CompanyProductInfo: string(companyProductInfoJsonByte),
  4525. CompanyPermissionInfo: string(companyPermissionInfoJsonByte),
  4526. UserSellerRelationInfo: string(userSellerRelationInfoJsonByte),
  4527. UserRecordInfo: string(userRecordInfoJsonByte),
  4528. UserInfo: string(userInfoJsonByte),
  4529. CompanyChartPermissionInfo: string(companyChartPermissionInfoJsonByte),
  4530. CompanyContractInfo: string(companyContractByte),
  4531. CompanyContractPermissionInfo: string(companyContractPermissionJsonByte),
  4532. OpUserId: this.SysUser.AdminId,
  4533. OpUserName: this.SysUser.RealName,
  4534. CreateTime: time.Now(),
  4535. }
  4536. _ = company.AddCompanyDeleteBak(companyDeleteBak)
  4537. }
  4538. br.Ret = 200
  4539. br.Success = true
  4540. br.Msg = "删除成功"
  4541. }
  4542. // @Title 领取客户列表
  4543. // @Description 领取客户列表接口
  4544. // @Param PageSize query int true "每页数据条数"
  4545. // @Param CurrentIndex query int true "当前页页码,从1开始"
  4546. // @Param StartDate query string true "开始时间"
  4547. // @Param EndDate query string true "结束时间"
  4548. // @Param KeyWord query string true "搜索关键词"
  4549. // @Success 200 {object} company.CompanyReceiveListResp
  4550. // @router /receive/list [get]
  4551. func (this *CompanyController) ReceiveList() {
  4552. br := new(models.BaseResponse).Init()
  4553. defer func() {
  4554. this.Data["json"] = br
  4555. this.ServeJSON()
  4556. }()
  4557. sysUser := this.SysUser
  4558. if sysUser == nil {
  4559. br.Msg = "请登录"
  4560. br.ErrMsg = "请登录,SysUser Is Empty"
  4561. br.Ret = 408
  4562. return
  4563. }
  4564. var productId, recevieProductId int
  4565. roleTypeCode := sysUser.RoleTypeCode
  4566. productId = services.GetProductId(roleTypeCode)
  4567. if productId == 1 {
  4568. recevieProductId = 2
  4569. } else if productId == 2 {
  4570. recevieProductId = 1
  4571. }
  4572. if productId == 0 {
  4573. br.Msg = "参数错误"
  4574. br.ErrMsg = "客户类型为:" + roleTypeCode
  4575. return
  4576. }
  4577. pageSize, _ := this.GetInt("PageSize")
  4578. currentIndex, _ := this.GetInt("CurrentIndex")
  4579. adminId := this.GetString("AdminId")
  4580. startDate := this.GetString("StartDate")
  4581. endDate := this.GetString("EndDate")
  4582. keyWord := this.GetString("KeyWord")
  4583. var startSize int
  4584. if pageSize <= 0 {
  4585. pageSize = utils.PageSize20
  4586. }
  4587. if currentIndex <= 0 {
  4588. currentIndex = 1
  4589. }
  4590. startSize = paging.StartIndex(currentIndex, pageSize)
  4591. var condition string
  4592. var pars []interface{}
  4593. if adminId != "" {
  4594. condition += ` AND c.seller_id IN (` + adminId + `) `
  4595. }
  4596. if startDate != "" {
  4597. condition += ` AND c.start_date>=? `
  4598. pars = append(pars, startDate)
  4599. }
  4600. if endDate != "" {
  4601. condition += ` AND c.end_date>=? `
  4602. pars = append(pars, endDate)
  4603. }
  4604. if keyWord != "" {
  4605. condition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR b.mobile LIKE '%` + keyWord + `%' OR b.email LIKE '%` + keyWord + `%') `
  4606. }
  4607. total, err := company.GetCompanyReceiveListCount(condition, pars, productId, recevieProductId)
  4608. if err != nil {
  4609. br.Msg = "获取失败"
  4610. br.ErrMsg = "获取数据总数失败,Err:" + err.Error()
  4611. return
  4612. }
  4613. list, err := company.GetCompanyReceiveList(condition, pars, productId, recevieProductId, startSize, pageSize)
  4614. if err != nil {
  4615. br.Msg = "获取失败"
  4616. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  4617. return
  4618. }
  4619. lenList := len(list)
  4620. for i := 0; i < lenList; i++ {
  4621. item := list[i]
  4622. var expireDay string
  4623. if item.Status != "" {
  4624. status := item.Status
  4625. if item.EndDate != "" {
  4626. if status == utils.COMPANY_STATUS_FOREVER { //永续
  4627. expireDay = "-"
  4628. } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用/正式
  4629. endDateTime, _ := time.Parse(utils.FormatDate, item.EndDate)
  4630. sub := endDateTime.Sub(time.Now())
  4631. expireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
  4632. } else if status == utils.COMPANY_STATUS_LOSE { //流失
  4633. expireDay = "-"
  4634. } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  4635. if item.StartDate != "" && item.EndDate != "" {
  4636. endDateTime, _ := time.Parse(utils.FormatDate, item.EndDate)
  4637. sub := endDateTime.Sub(time.Now())
  4638. expireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
  4639. } else {
  4640. expireDay = "-"
  4641. }
  4642. } else {
  4643. expireDay = "-"
  4644. }
  4645. }
  4646. }
  4647. list[i].ExpireDay = expireDay
  4648. }
  4649. page := paging.GetPaging(currentIndex, pageSize, total)
  4650. resp := new(company.CompanyReceiveListResp)
  4651. resp.List = list
  4652. resp.Paging = page
  4653. br.Ret = 200
  4654. br.Success = true
  4655. br.Msg = "获取成功"
  4656. br.Data = resp
  4657. }
  4658. // @Title 领取客户
  4659. // @Description 领取客户接口
  4660. // @Param request body company.CompanyReceiveReq true "type json string"
  4661. // @Success Ret=200 领取成功
  4662. // @router /receive [post]
  4663. func (this *CompanyController) Receive() {
  4664. br := new(models.BaseResponse).Init()
  4665. defer func() {
  4666. this.Data["json"] = br
  4667. this.ServeJSON()
  4668. }()
  4669. sysUser := this.SysUser
  4670. if sysUser == nil {
  4671. br.Msg = "请登录"
  4672. br.ErrMsg = "请登录,SysUser Is Empty"
  4673. br.Ret = 408
  4674. return
  4675. }
  4676. var req company.CompanyReceiveReq
  4677. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  4678. if err != nil {
  4679. br.Msg = "参数解析异常!"
  4680. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  4681. return
  4682. }
  4683. if req.CompanyId <= 0 {
  4684. br.Msg = "参数异常!"
  4685. br.ErrMsg = "CompanyId:" + strconv.Itoa(req.CompanyId)
  4686. return
  4687. }
  4688. //权益主观客观权限一块开
  4689. if req.PermissionIds != "" {
  4690. permissionStr, err := company.GetPermissionIdById(req.PermissionIds)
  4691. if err != nil {
  4692. br.Msg = "获取信息失败"
  4693. br.ErrMsg = "获取主观客观权限信息失败,Err:" + err.Error()
  4694. return
  4695. }
  4696. req.PermissionIds = permissionStr
  4697. }
  4698. roleTypeCode := sysUser.RoleTypeCode
  4699. productId := services.GetProductId(roleTypeCode)
  4700. if productId == 0 {
  4701. br.Msg = "参数错误"
  4702. br.ErrMsg = "客户类型为:" + roleTypeCode
  4703. return
  4704. }
  4705. sellsId := 0
  4706. if req.SellsId <= 0 {
  4707. sellsId = sysUser.AdminId
  4708. } else {
  4709. sellsId = req.SellsId
  4710. }
  4711. seller, err := system.GetSysAdminById(sellsId)
  4712. if err != nil {
  4713. br.Msg = "获取销售信息失败"
  4714. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  4715. return
  4716. }
  4717. companyDetail, err := company.GetCompanyDetailById(req.CompanyId)
  4718. if err != nil {
  4719. br.Msg = "获取客户信息失败"
  4720. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  4721. return
  4722. }
  4723. cp, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, productId)
  4724. if err != nil && err.Error() != utils.ErrNoRow() {
  4725. br.Msg = "获取客户信息失败"
  4726. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  4727. return
  4728. }
  4729. productName := ""
  4730. var status string
  4731. if productId == 1 {
  4732. productName = utils.COMPANY_PRODUCT_FICC_NAME
  4733. } else {
  4734. productName = utils.COMPANY_PRODUCT_RAI_NAME
  4735. }
  4736. if productId == utils.COMPANY_PRODUCT_RAI_ID {
  4737. //查询客户的产品权限
  4738. companyReportPermissionListOld, err := company.GetCompanyReportPermission(req.CompanyId, productId)
  4739. if err != nil {
  4740. br.Msg = "查询客户的产品权限异常"
  4741. br.ErrMsg = "查询客户的产品权限异常:" + err.Error()
  4742. return
  4743. }
  4744. var isNoResearch bool
  4745. for _, v := range companyReportPermissionListOld {
  4746. if v.ChartPermissionId != utils.CHART_PERMISSION_ID_YANXUAN && v.ChartPermissionId != utils.YAN_XUAN_KOU_DIAN_BAO_ID {
  4747. isNoResearch = true
  4748. continue
  4749. }
  4750. }
  4751. //如果所选行业不属于研选订阅跟研选扣点包,那就是非研选试用客户
  4752. if isNoResearch {
  4753. tryOutCountRai, err := company.GetRaiCompanyTryOutCountNoResearch(req.SellsId)
  4754. if err != nil {
  4755. br.Msg = "判断试用客户量失败"
  4756. br.ErrMsg = "判断试用客户量失败,Err:" + err.Error()
  4757. return
  4758. }
  4759. if tryOutCountRai >= utils.COMPANY_STATUS_TRY_OUT_COUNT_RAI {
  4760. br.Msg = "非研选试用客户最多40家"
  4761. return
  4762. }
  4763. }
  4764. }
  4765. if cp != nil {
  4766. if cp.Status != utils.COMPANY_STATUS_LOSE {
  4767. br.Msg = "客户状态为:" + cp.Status + ";不可领取"
  4768. br.ErrMsg = "客户状态为:" + cp.Status + ";不可领取"
  4769. return
  4770. }
  4771. if cp.SellerId == sysUser.AdminId {
  4772. br.Msg = "已为自己客户,不可重复领取"
  4773. br.ErrMsg = "已为自己客户,不可领取:company_id:" + strconv.Itoa(cp.CompanyId)
  4774. return
  4775. }
  4776. //转移 销售
  4777. companyReportPermissionList, startDate, endDate, err := company.MoveSeller(req.CompanyId, productId, seller.AdminId, seller.GroupId, seller.DepartmentId, seller.RealName)
  4778. if err != nil {
  4779. br.Msg = "领取失败"
  4780. br.ErrMsg = "领取失败,Err:" + err.Error()
  4781. return
  4782. }
  4783. //新增客户产品状态变更日志
  4784. {
  4785. companyProductUpdateLog := &company.CompanyProductUpdateLog{
  4786. Id: 0,
  4787. CompanyId: req.CompanyId,
  4788. ProductId: productId,
  4789. Status: "试用",
  4790. Source: "receive",
  4791. SellerId: seller.AdminId,
  4792. SellerName: seller.RealName,
  4793. StartDate: startDate,
  4794. EndDate: endDate,
  4795. RealEndDate: startDate,
  4796. CreateTime: time.Now(),
  4797. }
  4798. go company.AddCompanyProductUpdateLog(companyProductUpdateLog)
  4799. companyProductTryOutUpdateLog := &company.CompanyProductTryOutUpdateLog{
  4800. Id: 0,
  4801. CompanyId: req.CompanyId,
  4802. ProductId: productId,
  4803. Source: "receive",
  4804. SellerId: seller.AdminId,
  4805. SellerName: seller.RealName,
  4806. StartDate: startDate,
  4807. EndDate: endDate,
  4808. RealEndDate: startDate,
  4809. IsStop: 0,
  4810. CreateTime: time.Now(),
  4811. }
  4812. go company.AddCompanyProductTryOutUpdateLog(companyProductTryOutUpdateLog, companyReportPermissionList)
  4813. }
  4814. //流失转试用,企业下面的用户自动添加产业关注
  4815. //{
  4816. // go cygxService.AddUserFllowCompanyLossToTryOut(req.CompanyId)
  4817. //}
  4818. } else {
  4819. //跨部门领取
  4820. var startDateTime, endDateTime time.Time
  4821. if req.Status == utils.COMPANY_STATUS_TRY_OUT {
  4822. startDateTime = time.Now()
  4823. endDateTime = time.Now().AddDate(0, 2, 0)
  4824. } else if req.Status == utils.COMPANY_STATUS_FOREVER {
  4825. startDateTime = time.Now()
  4826. endDateTime = time.Now().AddDate(100, 0, 0)
  4827. } else {
  4828. br.Msg = "无效的客户状态,请重新选择"
  4829. return
  4830. }
  4831. var startDate, endDate string
  4832. startDate = startDateTime.Format(utils.FormatDate)
  4833. endDate = endDateTime.Format(utils.FormatDate)
  4834. if req.PermissionIds == "" {
  4835. br.Msg = "请选择权限!"
  4836. return
  4837. }
  4838. industry, err := company.GetCompanyIndustryById(req.IndustryId)
  4839. if err != nil {
  4840. br.Msg = "获取行业信息失败"
  4841. br.ErrMsg = "获取行业信息失败,Err:" + err.Error()
  4842. return
  4843. }
  4844. if industry == nil {
  4845. br.Msg = "行业信息不存在"
  4846. return
  4847. }
  4848. status = req.Status
  4849. companyProduct := new(company.CompanyProduct)
  4850. companyProduct.CompanyId = req.CompanyId
  4851. companyProduct.ProductId = productId
  4852. companyProduct.ProductName = productName
  4853. companyProduct.CompanyName = companyDetail.CompanyName
  4854. companyProduct.Source = req.Source
  4855. companyProduct.Reasons = req.Reasons
  4856. companyProduct.Status = status
  4857. companyProduct.StartDate = startDate
  4858. companyProduct.EndDate = endDate
  4859. companyProduct.IndustryId = req.IndustryId
  4860. companyProduct.IndustryName = industry.IndustryName
  4861. companyProduct.SellerId = seller.AdminId
  4862. companyProduct.SellerName = seller.RealName
  4863. companyProduct.GroupId = seller.GroupId
  4864. companyProduct.DepartmentId = seller.DepartmentId
  4865. companyProduct.IsSuspend = 0
  4866. companyProduct.CreateTime = time.Now()
  4867. companyProduct.ModifyTime = time.Now()
  4868. companyProduct.CompanyType = req.CompanyType
  4869. companyProduct.OpenCode = services.GenerateOpenCompanyProductCode(req.CompanyId, productId)
  4870. companyProduct.TodoStatus = "无任务"
  4871. companyProduct.TryStage = 1
  4872. companyProduct.SellerIdInit = seller.AdminId
  4873. companyProduct.SellerNameInit = seller.RealName
  4874. _, err = company.AddCompanyProduct(companyProduct)
  4875. if err != nil {
  4876. br.Msg = "新增失败"
  4877. br.ErrMsg = "新增客户产品失败,err:" + err.Error()
  4878. return
  4879. }
  4880. companyReportPermissionList, err := services.AddCompanyPermission(req.CompanyId, seller.AdminId, productId, productName, seller.RealName, req.PermissionIds, startDate, endDate)
  4881. if err != nil {
  4882. br.Msg = "新增失败"
  4883. br.ErrMsg = "新增客户设置权限失败,err:" + err.Error()
  4884. return
  4885. }
  4886. //新增客户产品日志
  4887. {
  4888. go services.AddCompanyProductLog(companyProduct, this.SysUser.AdminId, "add")
  4889. }
  4890. //新增客户产品状态变更日志
  4891. {
  4892. companyProductUpdateLog := &company.CompanyProductUpdateLog{
  4893. Id: 0,
  4894. CompanyId: companyProduct.CompanyId,
  4895. ProductId: companyProduct.ProductId,
  4896. Status: "试用",
  4897. SellerId: seller.AdminId,
  4898. SellerName: seller.RealName,
  4899. Source: "add",
  4900. StartDate: startDateTime,
  4901. EndDate: endDateTime,
  4902. RealEndDate: startDateTime,
  4903. CreateTime: time.Now(),
  4904. }
  4905. go company.AddCompanyProductUpdateLog(companyProductUpdateLog)
  4906. companyProductTryOutUpdateLog := &company.CompanyProductTryOutUpdateLog{
  4907. Id: 0,
  4908. CompanyId: companyProduct.CompanyId,
  4909. ProductId: companyProduct.ProductId,
  4910. SellerId: seller.AdminId,
  4911. SellerName: seller.RealName,
  4912. Source: "add",
  4913. StartDate: startDateTime,
  4914. EndDate: endDateTime,
  4915. RealEndDate: startDateTime,
  4916. IsStop: 0,
  4917. CreateTime: time.Now(),
  4918. }
  4919. go company.AddCompanyProductTryOutUpdateLog(companyProductTryOutUpdateLog, companyReportPermissionList)
  4920. }
  4921. //查询当前客户的所有产品的列表数据,并找出非当前产品的销售去发送模板消息
  4922. companyProductList, err := company.GetCompanyProductsByCompanyId(req.CompanyId)
  4923. for _, companyProduct := range companyProductList {
  4924. //如果是当前领取的产品,那么就退出当前循环,进入下一循环
  4925. if companyProduct.ProductId == productId {
  4926. continue
  4927. }
  4928. //查询其他部门销售的信息
  4929. admin, tmpErr := system.GetSysAdminById(companyProduct.SellerId)
  4930. if tmpErr != nil {
  4931. continue
  4932. }
  4933. //发送模板消息给另一个部门的销售
  4934. go services.SendCompanyReceiveWxTemplateMsg(companyDetail.CompanyName, productName, sysUser.RealName, admin.Mobile)
  4935. }
  4936. }
  4937. //新增操作记录
  4938. {
  4939. remark := "领取客户"
  4940. operation := "receive"
  4941. services.AddCompanyOperationRecord(req.CompanyId, seller.AdminId, sysUser.AdminId, productId, sysUser.AdminId, companyDetail.CompanyName,
  4942. productName, sysUser.RealName, remark, operation, "", sysUser.RealName, "", status)
  4943. }
  4944. br.Ret = 200
  4945. br.Success = true
  4946. br.Msg = "领取成功"
  4947. }
  4948. // @Title 移动销售
  4949. // @Description 移动销售接口
  4950. // @Param request body company.MoveSellerReq true "type json string"
  4951. // @Success Ret=200 移动成功
  4952. // @router /move/seller [post]
  4953. func (this *CompanyController) MoveSeller() {
  4954. br := new(models.BaseResponse).Init()
  4955. defer func() {
  4956. this.Data["json"] = br
  4957. this.ServeJSON()
  4958. }()
  4959. sysUser := this.SysUser
  4960. if sysUser == nil {
  4961. br.Msg = "请登录"
  4962. br.ErrMsg = "请登录,SysUser Is Empty"
  4963. br.Ret = 408
  4964. return
  4965. }
  4966. var req company.MoveSellerReq
  4967. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  4968. if err != nil {
  4969. br.Msg = "参数解析异常!"
  4970. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  4971. return
  4972. }
  4973. if req.CompanyId <= 0 {
  4974. br.Msg = "参数异常!"
  4975. br.ErrMsg = "CompanyId:" + strconv.Itoa(req.CompanyId)
  4976. return
  4977. }
  4978. if req.SellsId <= 0 {
  4979. br.Msg = "参数异常!"
  4980. br.ErrMsg = "SellsId:" + strconv.Itoa(req.SellsId)
  4981. return
  4982. }
  4983. seller, err := system.GetSysAdminById(req.SellsId)
  4984. if err != nil {
  4985. br.Msg = "获取销售信息失败"
  4986. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  4987. return
  4988. }
  4989. roleTypeCode := sysUser.RoleTypeCode
  4990. productId := services.GetProductId(roleTypeCode)
  4991. if productId == 0 {
  4992. if req.CompanyType == utils.COMPANY_CLASSIFY_FICC {
  4993. productId = 1
  4994. } else if req.CompanyType == utils.COMPANY_CLASSIFY_RAI {
  4995. productId = 2
  4996. }
  4997. }
  4998. if productId == 0 {
  4999. br.Msg = "无效的客户类型"
  5000. br.ErrMsg = "无效的客户类型"
  5001. return
  5002. }
  5003. if productId == utils.COMPANY_PRODUCT_RAI_ID {
  5004. //查询客户的产品权限
  5005. companyReportPermissionListOld, err := company.GetCompanyReportPermission(req.CompanyId, productId)
  5006. if err != nil {
  5007. br.Msg = "查询客户的产品权限异常"
  5008. br.ErrMsg = "查询客户的产品权限异常:" + err.Error()
  5009. return
  5010. }
  5011. var isNoResearch bool
  5012. for _, v := range companyReportPermissionListOld {
  5013. if v.ChartPermissionId != utils.CHART_PERMISSION_ID_YANXUAN && v.ChartPermissionId != utils.YAN_XUAN_KOU_DIAN_BAO_ID {
  5014. isNoResearch = true
  5015. continue
  5016. }
  5017. }
  5018. //如果所选行业不属于研选订阅跟研选扣点包,那就是非研选试用客户
  5019. if isNoResearch {
  5020. tryOutCountRai, err := company.GetRaiCompanyTryOutCountNoResearch(req.SellsId)
  5021. if err != nil {
  5022. br.Msg = "判断试用客户量失败"
  5023. br.ErrMsg = "判断试用客户量失败,Err:" + err.Error()
  5024. return
  5025. }
  5026. if tryOutCountRai >= utils.COMPANY_STATUS_TRY_OUT_COUNT_RAI {
  5027. br.Msg = seller.RealName + "的非研选试用客户已超过40家"
  5028. return
  5029. }
  5030. }
  5031. }
  5032. cp, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, productId)
  5033. if err != nil && err.Error() != utils.ErrNoRow() {
  5034. if err.Error() == utils.ErrNoRow() {
  5035. br.Msg = "客户信息不存在"
  5036. br.ErrMsg = "客户信息不存在,Err:" + err.Error()
  5037. return
  5038. }
  5039. br.Msg = "获取客户信息失败"
  5040. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  5041. return
  5042. }
  5043. if cp == nil {
  5044. br.Msg = "客户信息不存在,请刷新页面"
  5045. br.ErrMsg = "客户信息不存在"
  5046. return
  5047. }
  5048. err = company.MoveCompanySeller(req.CompanyId, productId, req.SellsId, seller.GroupId, seller.DepartmentId, seller.RealName)
  5049. if err != nil {
  5050. br.Msg = "移动失败"
  5051. br.ErrMsg = "移动失败,Err:" + err.Error()
  5052. return
  5053. }
  5054. //新增操作记录
  5055. {
  5056. remark := "移动到:" + seller.RealName
  5057. operation := "move_seller"
  5058. services.AddCompanyOperationRecord(req.CompanyId, seller.AdminId, sysUser.AdminId, productId, sysUser.AdminId, cp.CompanyName,
  5059. cp.ProductName, sysUser.RealName, remark, operation, "", sysUser.RealName, "", cp.Status)
  5060. }
  5061. {
  5062. services.UpdateCompanyContractSellerMove(req.CompanyId, productId) //益客户移动所属销售之后,更新所关联的销售信息
  5063. }
  5064. //变更销售员与联系人关系
  5065. _ = models.UpdateUserSellerRelationByCompanyId(req.CompanyId, productId, seller.AdminId, seller.RealName)
  5066. br.Ret = 200
  5067. br.Success = true
  5068. br.Msg = "移动成功"
  5069. }
  5070. // @Title 修改试用客户标签
  5071. // @Description 修改试用客户标签接口
  5072. // @Param request body company.UpdateTryStageReq true "type json string"
  5073. // @Success Ret=200 设置成功
  5074. // @router /update/tryStage [post]
  5075. func (this *CompanyController) UpdateTryStage() {
  5076. br := new(models.BaseResponse).Init()
  5077. defer func() {
  5078. this.Data["json"] = br
  5079. this.ServeJSON()
  5080. }()
  5081. sysUser := this.SysUser
  5082. if sysUser == nil {
  5083. br.Msg = "请登录"
  5084. br.ErrMsg = "请登录,SysUser Is Empty"
  5085. br.Ret = 408
  5086. return
  5087. }
  5088. var req company.UpdateTryStageReq
  5089. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  5090. if err != nil {
  5091. br.Msg = "参数解析异常!"
  5092. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  5093. return
  5094. }
  5095. if req.CompanyId <= 0 {
  5096. br.Msg = "参数异常!"
  5097. br.ErrMsg = "CompanyId:" + strconv.Itoa(req.CompanyId)
  5098. return
  5099. }
  5100. if req.ProductId <= 0 {
  5101. br.Msg = "参数异常!"
  5102. br.ErrMsg = "ProductId:" + strconv.Itoa(req.ProductId)
  5103. return
  5104. }
  5105. if req.TryStage <= 0 {
  5106. br.Msg = "参数异常!"
  5107. br.ErrMsg = "TryStage:" + strconv.Itoa(req.TryStage)
  5108. return
  5109. }
  5110. cp, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, req.ProductId)
  5111. if err != nil && err.Error() != utils.ErrNoRow() {
  5112. if err.Error() == utils.ErrNoRow() {
  5113. br.Msg = "客户信息不存在"
  5114. br.ErrMsg = "客户信息不存在,Err:" + err.Error()
  5115. return
  5116. }
  5117. br.Msg = "获取客户信息失败"
  5118. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  5119. return
  5120. }
  5121. fmt.Println(cp)
  5122. if cp == nil {
  5123. br.Msg = "客户信息不存在,请刷新页面"
  5124. br.ErrMsg = "客户信息不存在"
  5125. return
  5126. }
  5127. if cp.Status != "试用" {
  5128. br.Msg = "客户不是试用状态,不允许修改"
  5129. br.ErrMsg = "客户不是试用状态,不允许修改"
  5130. return
  5131. }
  5132. if cp.SellerId != sysUser.AdminId {
  5133. br.Msg = "无修改权限"
  5134. br.ErrMsg = "无修改权限"
  5135. return
  5136. }
  5137. if cp.TryStage == req.TryStage {
  5138. br.Msg = "与原标签一致,无需修改"
  5139. br.ErrMsg = "与原标签一致,无需修改"
  5140. return
  5141. }
  5142. err = company.UpdateCompanyTryStage(req.CompanyId, req.ProductId, req.TryStage)
  5143. if err != nil {
  5144. br.Msg = "设置失败"
  5145. br.ErrMsg = "设置失败,Err:" + err.Error()
  5146. return
  5147. }
  5148. //新增操作记录
  5149. {
  5150. stage := ""
  5151. tryStageAllMap := map[int]string{
  5152. 1: "未分类",
  5153. 2: "推进",
  5154. 3: "跟踪",
  5155. 4: "预备",
  5156. }
  5157. if v, ok := tryStageAllMap[req.TryStage]; ok {
  5158. stage = v
  5159. }
  5160. remark := "修改试用客户子标签:" + stage
  5161. operation := "UpdateTryStage"
  5162. services.AddCompanyOperationRecord(req.CompanyId, cp.SellerId, sysUser.AdminId, req.ProductId, sysUser.AdminId, cp.CompanyName,
  5163. cp.ProductName, sysUser.RealName, remark, operation, "", sysUser.RealName, "", cp.Status)
  5164. }
  5165. br.Ret = 200
  5166. br.Success = true
  5167. br.Msg = "设置成功"
  5168. }
  5169. // @Title 暂停/启用
  5170. // @Description 暂停/启用接口
  5171. // @Param request body company.SuspendReq true "type json string"
  5172. // @Success Ret=200 移动成功
  5173. // @router /suspend [post]
  5174. func (this *CompanyController) Suspend() {
  5175. br := new(models.BaseResponse).Init()
  5176. defer func() {
  5177. this.Data["json"] = br
  5178. this.ServeJSON()
  5179. }()
  5180. sysUser := this.SysUser
  5181. if sysUser == nil {
  5182. br.Msg = "请登录"
  5183. br.ErrMsg = "请登录,SysUser Is Empty"
  5184. br.Ret = 408
  5185. return
  5186. }
  5187. var req company.SuspendReq
  5188. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  5189. if err != nil {
  5190. br.Msg = "参数解析异常!"
  5191. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  5192. return
  5193. }
  5194. if req.CompanyId <= 0 {
  5195. br.Msg = "参数异常!"
  5196. br.ErrMsg = "CompanyId:" + strconv.Itoa(req.CompanyId)
  5197. return
  5198. }
  5199. roleTypeCode := sysUser.RoleTypeCode
  5200. productId := services.GetProductId(roleTypeCode)
  5201. if productId == 0 {
  5202. br.Msg = "参数错误"
  5203. br.ErrMsg = "角色类型为:" + roleTypeCode
  5204. return
  5205. }
  5206. cp, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, productId)
  5207. if err != nil {
  5208. br.Msg = "获取数据异常!"
  5209. br.ErrMsg = "获取数据异常:" + err.Error()
  5210. return
  5211. }
  5212. suspendStatus := ""
  5213. suspend := 0
  5214. if cp.IsSuspend == 1 {
  5215. suspendStatus = "启用"
  5216. suspend = 0
  5217. } else {
  5218. suspendStatus = "暂停"
  5219. suspend = 1
  5220. }
  5221. if cp.Status != utils.COMPANY_STATUS_TRY_OUT {
  5222. br.Msg = "客户状态为:" + cp.Status + ",不允许进行" + suspendStatus + "操作"
  5223. br.ErrMsg = "客户状态为:" + cp.Status + ",不允许进行" + suspendStatus + "操作"
  5224. return
  5225. }
  5226. err = company.SuspendCompanyProductById(req.CompanyId, productId, suspend)
  5227. if err != nil {
  5228. br.Msg = suspendStatus + "失败"
  5229. br.ErrMsg = suspendStatus + "失败 Err:" + err.Error()
  5230. return
  5231. }
  5232. //新增操作记录
  5233. {
  5234. remark := suspendStatus
  5235. operation := "is_suspend"
  5236. services.AddCompanyOperationRecord(req.CompanyId, cp.SellerId, sysUser.AdminId, productId, sysUser.AdminId, cp.CompanyName,
  5237. cp.ProductName, sysUser.RealName, remark, operation, "", sysUser.RealName, "", cp.Status)
  5238. }
  5239. br.Ret = 200
  5240. br.Success = true
  5241. br.Msg = suspendStatus + "成功"
  5242. }
  5243. // @Title 检测客户名称或社会信用码
  5244. // @Description 检测客户名称或社会信用码接口(新增/编辑客户页面使用)
  5245. // @Param CompanyName query string true "客户名称"
  5246. // @Param CreditCode query string true "社会统一信用码"
  5247. // @Success 200 {object} company.CheckCompanyInfoResp
  5248. // @router /check/companyInfo [get]
  5249. func (this *CompanyController) CheckCompanyInfo() {
  5250. br := new(models.BaseResponse).Init()
  5251. defer func() {
  5252. this.Data["json"] = br
  5253. this.ServeJSON()
  5254. }()
  5255. sysUser := this.SysUser
  5256. if sysUser == nil {
  5257. br.Msg = "请登录"
  5258. br.ErrMsg = "请登录,SysUser Is Empty"
  5259. br.Ret = 408
  5260. return
  5261. }
  5262. roleTypeCode := sysUser.RoleTypeCode
  5263. productId := services.GetProductId(roleTypeCode)
  5264. companyName := this.GetString("CompanyName")
  5265. creditCode := this.GetString("CreditCode")
  5266. var status, comanyId int
  5267. var productName string
  5268. if productId == 0 {
  5269. productId = 1
  5270. checkProductId := 2
  5271. if companyName != "" {
  5272. nameItem, err := company.CheckCompanyProductByName(companyName, productId)
  5273. if err != nil && err.Error() != utils.ErrNoRow() {
  5274. br.Msg = "校验客户名称是否存在失败"
  5275. br.ErrMsg = "校验客户名称是否存在失败,Err:" + err.Error()
  5276. return
  5277. }
  5278. if nameItem != nil && nameItem.CompanyId > 0 {
  5279. br.Msg = "客户名称已存在,请重新填写"
  5280. br.ErrMsg = "客户名称已存在,请重新填写"
  5281. br.Ret = 405
  5282. return
  5283. }
  5284. nameCheckItem, err := company.CheckCompanyProductByName(companyName, checkProductId)
  5285. if err != nil && err.Error() != utils.ErrNoRow() {
  5286. br.Msg = "校验客户名称是否存在失败"
  5287. br.ErrMsg = "校验客户名称是否存在失败,Err:" + err.Error() + " productId:" + strconv.Itoa(productId) + ";checkProductId:" + strconv.Itoa(checkProductId)
  5288. return
  5289. }
  5290. if nameCheckItem != nil && nameCheckItem.CompanyId > 0 {
  5291. status = 1
  5292. productName = nameCheckItem.ProductName
  5293. comanyId = nameCheckItem.CompanyId
  5294. goto Loop
  5295. }
  5296. }
  5297. if creditCode != "" {
  5298. codeItem, err := company.CheckCompanyProductByCreditCode(creditCode, productId)
  5299. if err != nil && err.Error() != utils.ErrNoRow() {
  5300. br.Msg = "校验社会信用码是否存在失败"
  5301. br.ErrMsg = "校验社会信用码是否存在失败,Err:" + err.Error()
  5302. return
  5303. }
  5304. if codeItem != nil && codeItem.CompanyId > 0 {
  5305. br.Msg = "社会信用码已存在,请重新填写"
  5306. br.ErrMsg = "社会信用码已存在,请重新填写"
  5307. br.Ret = 405
  5308. return
  5309. }
  5310. codeCheckItem, err := company.CheckCompanyProductByCreditCode(creditCode, checkProductId)
  5311. if err != nil && err.Error() != utils.ErrNoRow() {
  5312. br.Msg = "校验社会信用码是否存在失败"
  5313. br.ErrMsg = "校验社会信用码是否存在失败,Err:" + err.Error() + " productId:" + strconv.Itoa(productId) + ";checkProductId:" + strconv.Itoa(checkProductId)
  5314. return
  5315. }
  5316. if codeCheckItem != nil && codeCheckItem.CompanyId > 0 {
  5317. status = 1
  5318. productName = codeCheckItem.ProductName
  5319. comanyId = codeCheckItem.CompanyId
  5320. goto Loop
  5321. }
  5322. }
  5323. productId = 2
  5324. checkProductId = 1
  5325. if companyName != "" {
  5326. nameItem, err := company.CheckCompanyProductByName(companyName, productId)
  5327. if err != nil && err.Error() != utils.ErrNoRow() {
  5328. br.Msg = "校验客户名称是否存在失败"
  5329. br.ErrMsg = "校验客户名称是否存在失败,Err:" + err.Error()
  5330. return
  5331. }
  5332. if nameItem != nil && nameItem.CompanyId > 0 {
  5333. br.Msg = "客户名称已存在,请重新填写"
  5334. br.ErrMsg = "客户名称已存在,请重新填写"
  5335. br.Ret = 405
  5336. return
  5337. }
  5338. nameCheckItem, err := company.CheckCompanyProductByName(companyName, checkProductId)
  5339. if err != nil && err.Error() != utils.ErrNoRow() {
  5340. br.Msg = "校验客户名称是否存在失败"
  5341. br.ErrMsg = "校验客户名称是否存在失败,Err:" + err.Error() + " productId:" + strconv.Itoa(productId) + ";checkProductId:" + strconv.Itoa(checkProductId)
  5342. return
  5343. }
  5344. if nameCheckItem != nil && nameCheckItem.CompanyId > 0 {
  5345. status = 1
  5346. productName = nameCheckItem.ProductName
  5347. comanyId = nameCheckItem.CompanyId
  5348. goto Loop
  5349. }
  5350. }
  5351. if creditCode != "" {
  5352. codeItem, err := company.CheckCompanyProductByCreditCode(creditCode, productId)
  5353. if err != nil && err.Error() != utils.ErrNoRow() {
  5354. br.Msg = "校验社会信用码是否存在失败"
  5355. br.ErrMsg = "校验社会信用码是否存在失败,Err:" + err.Error()
  5356. return
  5357. }
  5358. if codeItem != nil && codeItem.CompanyId > 0 {
  5359. br.Msg = "社会信用码已存在,请重新填写"
  5360. br.ErrMsg = "社会信用码已存在,请重新填写"
  5361. br.Ret = 405
  5362. return
  5363. }
  5364. codeCheckItem, err := company.CheckCompanyProductByCreditCode(creditCode, checkProductId)
  5365. if err != nil && err.Error() != utils.ErrNoRow() {
  5366. br.Msg = "校验社会信用码是否存在失败"
  5367. br.ErrMsg = "校验社会信用码是否存在失败,Err:" + err.Error() + " productId:" + strconv.Itoa(productId) + ";checkProductId:" + strconv.Itoa(checkProductId)
  5368. return
  5369. }
  5370. if codeCheckItem != nil && codeCheckItem.CompanyId > 0 {
  5371. status = 1
  5372. productName = codeCheckItem.ProductName
  5373. comanyId = codeCheckItem.CompanyId
  5374. goto Loop
  5375. }
  5376. }
  5377. } else {
  5378. checkProductId := 0
  5379. if productId == 1 {
  5380. checkProductId = 2
  5381. } else if productId == 2 {
  5382. checkProductId = 1
  5383. }
  5384. if companyName != "" {
  5385. nameItem, err := company.CheckCompanyProductByName(companyName, productId)
  5386. if err != nil && err.Error() != utils.ErrNoRow() {
  5387. br.Msg = "校验客户名称是否存在失败"
  5388. br.ErrMsg = "校验客户名称是否存在失败,Err:" + err.Error()
  5389. return
  5390. }
  5391. if nameItem != nil && nameItem.ProductName != "" {
  5392. br.Msg = "客户名称已存在,请重新填写"
  5393. br.ErrMsg = "客户名称已存在,请重新填写"
  5394. br.Ret = 405
  5395. return
  5396. }
  5397. nameCheckoutItem, err := company.CheckCompanyProductByName(companyName, checkProductId)
  5398. if err != nil && err.Error() != utils.ErrNoRow() {
  5399. br.Msg = "校验客户名称是否存在失败"
  5400. br.ErrMsg = "校验客户名称是否存在失败,Err:" + err.Error() + " productId:" + strconv.Itoa(productId) + ";checkProductId:" + strconv.Itoa(checkProductId)
  5401. return
  5402. }
  5403. if nameCheckoutItem != nil && nameCheckoutItem.CompanyId > 0 {
  5404. status = 1
  5405. productName = nameCheckoutItem.ProductName
  5406. comanyId = nameCheckoutItem.CompanyId
  5407. goto Loop
  5408. }
  5409. }
  5410. if creditCode != "" {
  5411. codeItem, err := company.CheckCompanyProductByCreditCode(creditCode, productId)
  5412. if err != nil && err.Error() != utils.ErrNoRow() {
  5413. br.Msg = "校验社会信用码是否存在失败"
  5414. br.ErrMsg = "校验社会信用码是否存在失败,Err:" + err.Error()
  5415. return
  5416. }
  5417. if codeItem != nil && codeItem.CompanyId > 0 {
  5418. br.Msg = "社会信用码已存在,请重新填写"
  5419. br.ErrMsg = "社会信用码已存在,请重新填写"
  5420. br.Ret = 405
  5421. return
  5422. }
  5423. codeCheckItem, err := company.CheckCompanyProductByCreditCode(creditCode, checkProductId)
  5424. if err != nil && err.Error() != utils.ErrNoRow() {
  5425. br.Msg = "校验社会信用码是否存在失败"
  5426. br.ErrMsg = "校验社会信用码是否存在失败,Err:" + err.Error() + " productId:" + strconv.Itoa(productId) + ";checkProductId:" + strconv.Itoa(checkProductId)
  5427. return
  5428. }
  5429. if codeCheckItem != nil && codeCheckItem.CompanyId > 0 {
  5430. status = 1
  5431. productName = codeCheckItem.ProductName
  5432. comanyId = codeCheckItem.CompanyId
  5433. goto Loop
  5434. }
  5435. }
  5436. }
  5437. Loop:
  5438. resp := new(company.CheckCompanyInfoResp)
  5439. resp.Status = status
  5440. resp.ProductName = productName
  5441. resp.CompanyId = comanyId
  5442. br.Ret = 200
  5443. br.Success = true
  5444. br.Msg = "获取成功"
  5445. br.Data = resp
  5446. }
  5447. // @Title 客户导出
  5448. // @Description 客户导出接口
  5449. // @Param Status query string true "状态:'试用','永续','冻结','流失','正式'"
  5450. // @Param CompanyType query string true "客户类型:传空字符串或者不传为全部,'ficc','权益'"
  5451. // @Param IndustryId query int true "行业id,0为全部"
  5452. // @Param AdminId query string true "销售id,多个用英文逗号隔开,空字符串为全部"
  5453. // @Param ChartPermissionIds query string false "阅读权限品种ID,多个用英文逗号分开,空字符串为全部"
  5454. // @Param ContractPermissionIds query string false "已购品种ID,多个用英文逗号分开,空字符串为全部"
  5455. // @Param StartDate query string true "开始时间"
  5456. // @Param EndDate query string true "结束时间"
  5457. // @Param CreateStartDate query string true "创建开始时间"
  5458. // @Param CreateEndDate query string true "创建结束时间"
  5459. // @Param KeyWord query string true "搜索关键词"
  5460. // @Param Address query string true "地址 , 多个用英文逗号分开 "
  5461. // @Param Province query string true "省 , 多个用英文逗号分开 "
  5462. // @Param City query string true "市 , 多个用英文逗号分开 "
  5463. // @Param PackageType query int true "套餐类型,0:无,1:大套餐,2:小套餐"
  5464. // @Success 200 {object} company.CompanyListResp
  5465. // @router /export [get]
  5466. func (this *CompanyController) Export() {
  5467. br := new(models.BaseResponse).Init()
  5468. defer func() {
  5469. this.Data["json"] = br
  5470. this.ServeJSON()
  5471. }()
  5472. sysUser := this.SysUser
  5473. if sysUser == nil {
  5474. br.Msg = "请登录"
  5475. br.ErrMsg = "请登录,SysUser Is Empty"
  5476. br.Ret = 408
  5477. return
  5478. }
  5479. roleTypeCode := sysUser.RoleTypeCode
  5480. status := this.GetString("Status")
  5481. companyType := this.GetString("CompanyType")
  5482. industryId, _ := this.GetInt("IndustryId")
  5483. adminId := this.GetString("AdminId")
  5484. chartPermissionIds := this.GetString("ChartPermissionIds")
  5485. contractPermissionIds := this.GetString("ContractPermissionIds")
  5486. startDate := this.GetString("StartDate")
  5487. endDate := this.GetString("EndDate")
  5488. createStartDate := this.GetString("CreateStartDate")
  5489. createEndDate := this.GetString("CreateEndDate")
  5490. keyWord := this.GetString("KeyWord")
  5491. keyWord = strings.Trim(keyWord, " ")
  5492. address := this.GetString("Address")
  5493. province := this.GetString("Province")
  5494. city := this.GetString("City")
  5495. // 套餐类型
  5496. packageType, _ := this.GetInt("PackageType")
  5497. resp := new(company.CompanyListResp)
  5498. statusItems := make([]*company.CompanyStatus, 0)
  5499. var statusArr = [...]string{"全部", "试用", "正式", "冻结", "流失", "永续"}
  5500. var condition string
  5501. var pars []interface{}
  5502. //状态分类查询条件
  5503. var permissionCondition string
  5504. var permissionPars []interface{}
  5505. if companyType != "" {
  5506. condition += ` AND b.product_name=? `
  5507. pars = append(pars, companyType)
  5508. }
  5509. if industryId > 0 {
  5510. condition += ` AND b.industry_id=? `
  5511. pars = append(pars, industryId)
  5512. }
  5513. if adminId != "" {
  5514. condition += ` AND b.seller_id IN (` + adminId + `) `
  5515. }
  5516. if startDate != "" {
  5517. condition += ` AND b.start_date>=? `
  5518. pars = append(pars, startDate)
  5519. }
  5520. if endDate != "" {
  5521. condition += ` AND b.end_date<=? `
  5522. pars = append(pars, endDate)
  5523. }
  5524. if createStartDate != "" {
  5525. condition += ` AND a.created_time>=? `
  5526. pars = append(pars, createStartDate)
  5527. }
  5528. if createEndDate != "" {
  5529. condition += ` AND a.created_time<=? `
  5530. pars = append(pars, createEndDate)
  5531. }
  5532. if address != "" {
  5533. var addressSql string
  5534. slice := strings.Split(address, ",")
  5535. for _, v := range slice {
  5536. addressSql += "'" + v + "'" + ","
  5537. }
  5538. addressSql = strings.TrimRight(addressSql, ",")
  5539. condition += ` AND a.address IN (` + addressSql + `) `
  5540. }
  5541. if province != "" {
  5542. var provinceSql string
  5543. slice := strings.Split(province, ",")
  5544. for _, v := range slice {
  5545. provinceSql += "'" + v + "'" + ","
  5546. }
  5547. provinceSql = strings.TrimRight(provinceSql, ",")
  5548. condition += ` AND a.province IN (` + provinceSql + `) `
  5549. }
  5550. if city != "" {
  5551. var citySql string
  5552. slice := strings.Split(city, ",")
  5553. for _, v := range slice {
  5554. citySql += "'" + v + "'" + ","
  5555. }
  5556. citySql = strings.TrimRight(citySql, ",")
  5557. condition += ` AND a.city IN (` + citySql + `) `
  5558. }
  5559. if keyWord != "" {
  5560. companyIdStr, err := company.GetCompanyIdByKeyWord(keyWord)
  5561. if err != nil {
  5562. br.Msg = "获取客户信息失败"
  5563. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  5564. return
  5565. }
  5566. if companyIdStr != "" {
  5567. condition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.company_id IN(` + companyIdStr + `)) `
  5568. } else {
  5569. condition += ` AND (a.company_name LIKE '%` + keyWord + `%' ) `
  5570. }
  5571. }
  5572. //if chartPermissionIds != "" && chartPermissionIds != "1" {
  5573. // companyIdStr, err := company.GetCompanyListCompanyIdByPermissionIdStr(chartPermissionIds)
  5574. // if err != nil {
  5575. // br.Msg = "获取失败"
  5576. // br.ErrMsg = "根据权限获取公司ID失败,Err:" + err.Error()
  5577. // return
  5578. // }
  5579. // if companyIdStr != "" {
  5580. // condition += ` AND a.company_id IN (` + companyIdStr + `) `
  5581. // } else {
  5582. // for _, v := range statusArr {
  5583. // statusCount := new(company.CompanyStatus)
  5584. // if v == "全部" {
  5585. // statusCount.Status = "全部"
  5586. // statusCount.Count = 0
  5587. // } else {
  5588. // statusCount.Status = v
  5589. // statusCount.Count = 0
  5590. // }
  5591. // statusItems = append(statusItems, statusCount)
  5592. // }
  5593. // items := make([]*company.CompanyListItem, 0)
  5594. // resp.List = items
  5595. // resp.StatusCount = statusItems
  5596. // br.Msg = "获取成功"
  5597. // br.Ret = 200
  5598. // br.Data = resp
  5599. // return
  5600. // }
  5601. //}
  5602. // 阅读权限/已购品种筛选
  5603. cond, emp, e := services.FilterReadAndContractAuth(chartPermissionIds, contractPermissionIds, condition)
  5604. if e != nil {
  5605. br.Msg = "获取失败"
  5606. br.ErrMsg = "FilterReadAndContractAuth err: " + e.Error()
  5607. return
  5608. }
  5609. if emp {
  5610. for _, v := range statusArr {
  5611. statusCount := new(company.CompanyStatus)
  5612. if v == "全部" {
  5613. statusCount.Status = "全部"
  5614. statusCount.Count = 0
  5615. } else {
  5616. statusCount.Status = v
  5617. statusCount.Count = 0
  5618. }
  5619. statusItems = append(statusItems, statusCount)
  5620. }
  5621. items := make([]*company.CompanyListItem, 0)
  5622. resp.List = items
  5623. resp.StatusCount = statusItems
  5624. br.Msg = "获取成功"
  5625. br.Ret = 200
  5626. br.Data = resp
  5627. return
  5628. }
  5629. condition = cond
  5630. //套餐类型
  5631. if packageType > 0 {
  5632. condition += ` AND b.package_type=? `
  5633. pars = append(pars, packageType)
  5634. }
  5635. permissionCondition = condition
  5636. permissionPars = pars
  5637. productId := services.GetProductId(roleTypeCode)
  5638. //权限控制
  5639. {
  5640. //如果不是超级管理员
  5641. if roleTypeCode != utils.ROLE_TYPE_CODE_ADMIN {
  5642. //如果是部门管理员
  5643. if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  5644. condition += ` AND b.product_id=? `
  5645. pars = append(pars, productId)
  5646. permissionCondition += ` AND b.product_id=? `
  5647. permissionPars = append(permissionPars, productId)
  5648. } else {
  5649. condition += ` AND b.product_id=? `
  5650. pars = append(pars, productId)
  5651. permissionCondition += ` AND b.product_id=? `
  5652. permissionPars = append(permissionPars, productId)
  5653. if status == "全部" {
  5654. ////如果是筛选了流失客户状态
  5655. if sysUser.Authority <= 0 {
  5656. condition += ` AND (b.seller_id=? OR status='流失') `
  5657. pars = append(pars, sysUser.AdminId)
  5658. permissionCondition += ` AND b.seller_id=? `
  5659. permissionPars = append(permissionPars, sysUser.AdminId)
  5660. } else {
  5661. if sysUser.Authority == 1 {
  5662. condition += ` AND (b.department_id=? OR status='流失')`
  5663. pars = append(pars, sysUser.DepartmentId)
  5664. permissionCondition += ` AND b.department_id=? `
  5665. permissionPars = append(permissionPars, sysUser.DepartmentId)
  5666. }
  5667. if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  5668. if status != utils.COMPANY_STATUS_LOSE {
  5669. condition += ` AND (b.group_id=? OR status='流失') `
  5670. pars = append(pars, sysUser.GroupId)
  5671. }
  5672. permissionCondition += ` AND b.group_id=? `
  5673. permissionPars = append(permissionPars, sysUser.GroupId)
  5674. }
  5675. if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
  5676. pid, err := company.GetParentIdFromGroup(sysUser.GroupId)
  5677. if err != nil {
  5678. br.Msg = "获取失败"
  5679. br.ErrMsg = "查询父级id异常" + err.Error()
  5680. return
  5681. }
  5682. var ids []*string
  5683. if pid != nil && *pid != 0 {
  5684. ids, err = company.GetGroupIdsByParentId(*pid)
  5685. if err != nil {
  5686. fmt.Println(err.Error())
  5687. }
  5688. } else {
  5689. ids, err = company.GetGroupIdsByParentId(sysUser.GroupId)
  5690. if err != nil {
  5691. fmt.Println(err.Error())
  5692. }
  5693. }
  5694. var idSlice []string
  5695. var sid string
  5696. for _, id := range ids {
  5697. idSlice = append(idSlice, *id)
  5698. }
  5699. //加入父级groupId
  5700. if *pid > 0 {
  5701. idSlice = append(idSlice, strconv.Itoa(*pid))
  5702. } else {
  5703. idSlice = append(idSlice, strconv.Itoa(sysUser.GroupId))
  5704. }
  5705. sid = strings.Join(idSlice, ",")
  5706. if len(sid) > 0 {
  5707. if status != utils.COMPANY_STATUS_LOSE {
  5708. condition += ` AND (b.group_id IN (` + sid + `) OR status='流失') `
  5709. //pars = append(pars, sysUser.GroupId)
  5710. }
  5711. permissionCondition += ` AND b.group_id IN (` + sid + `) `
  5712. } else {
  5713. if status != utils.COMPANY_STATUS_LOSE {
  5714. condition += ` AND (b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) OR status='流失') `
  5715. //pars = append(pars, sysUser.GroupId)
  5716. }
  5717. permissionCondition += ` AND b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) `
  5718. }
  5719. }
  5720. }
  5721. } else {
  5722. ////如果没有筛选了流失客户状态
  5723. if sysUser.Authority <= 0 {
  5724. condition += ` AND b.seller_id=? `
  5725. pars = append(pars, sysUser.AdminId)
  5726. permissionCondition += ` AND b.seller_id=? `
  5727. permissionPars = append(permissionPars, sysUser.AdminId)
  5728. } else {
  5729. if sysUser.Authority == 1 {
  5730. condition += ` AND b.department_id=?`
  5731. pars = append(pars, sysUser.DepartmentId)
  5732. permissionCondition += ` AND b.department_id=? `
  5733. permissionPars = append(permissionPars, sysUser.DepartmentId)
  5734. }
  5735. if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  5736. if status != utils.COMPANY_STATUS_LOSE {
  5737. condition += ` AND b.group_id=? `
  5738. pars = append(pars, sysUser.GroupId)
  5739. }
  5740. permissionCondition += ` AND b.group_id=? `
  5741. permissionPars = append(permissionPars, sysUser.GroupId)
  5742. }
  5743. if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
  5744. pid, err := company.GetParentIdFromGroup(sysUser.GroupId)
  5745. if err != nil {
  5746. br.Msg = "获取失败"
  5747. br.ErrMsg = "查询父级id异常" + err.Error()
  5748. return
  5749. }
  5750. var ids []*string
  5751. if pid != nil && *pid != 0 {
  5752. ids, err = company.GetGroupIdsByParentId(*pid)
  5753. if err != nil {
  5754. fmt.Println(err.Error())
  5755. }
  5756. } else {
  5757. ids, err = company.GetGroupIdsByParentId(sysUser.GroupId)
  5758. if err != nil {
  5759. fmt.Println(err.Error())
  5760. }
  5761. }
  5762. var idSlice []string
  5763. var sid string
  5764. for _, id := range ids {
  5765. idSlice = append(idSlice, *id)
  5766. }
  5767. //加入父级groupId
  5768. if *pid > 0 {
  5769. idSlice = append(idSlice, strconv.Itoa(*pid))
  5770. } else {
  5771. idSlice = append(idSlice, strconv.Itoa(sysUser.GroupId))
  5772. }
  5773. sid = strings.Join(idSlice, ",")
  5774. if len(sid) > 0 {
  5775. if status != utils.COMPANY_STATUS_LOSE {
  5776. condition += ` AND (b.group_id IN (` + sid + `) OR status='流失') `
  5777. //pars = append(pars, sysUser.GroupId)
  5778. }
  5779. permissionCondition += ` AND b.group_id IN (` + sid + `) `
  5780. } else {
  5781. if status != utils.COMPANY_STATUS_LOSE {
  5782. condition += ` AND (b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) OR status='流失') `
  5783. //pars = append(pars, sysUser.GroupId)
  5784. }
  5785. permissionCondition += ` AND b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) `
  5786. }
  5787. }
  5788. if sysUser.Authority == 4 {
  5789. if status != utils.COMPANY_STATUS_LOSE {
  5790. condition += ` AND b.group_id =? `
  5791. pars = append(pars, sysUser.GroupId)
  5792. }
  5793. permissionCondition += ` AND b.group_id=? `
  5794. permissionPars = append(permissionPars, sysUser.GroupId)
  5795. }
  5796. }
  5797. }
  5798. }
  5799. }
  5800. }
  5801. //状态控制
  5802. if status != "" && status != "全部" && status != utils.COMPANY_STATUS_LOSE {
  5803. condition += ` AND b.status=? `
  5804. pars = append(pars, status)
  5805. }
  5806. dir, err := os.Executable()
  5807. exPath := filepath.Dir(dir)
  5808. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  5809. xlsxFile := xlsx.NewFile()
  5810. if err != nil {
  5811. br.Msg = "生成文件失败"
  5812. br.ErrMsg = "生成文件失败"
  5813. return
  5814. }
  5815. style := xlsx.NewStyle()
  5816. alignment := xlsx.Alignment{
  5817. Horizontal: "center",
  5818. Vertical: "center",
  5819. WrapText: true,
  5820. }
  5821. style.Alignment = alignment
  5822. style.ApplyAlignment = true
  5823. sheel, err := xlsxFile.AddSheet("客户数据")
  5824. if err != nil {
  5825. br.Msg = "新增Sheet失败"
  5826. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  5827. return
  5828. }
  5829. titleArr := []string{"客户名称", "客户地址", "客户类型", "所属行业", "所属销售", "客户状态", "服务期限", "到期天数", "创建时间", "权限详情"}
  5830. titleLen := len(titleArr)
  5831. titleRow := sheel.AddRow()
  5832. remarkRow := sheel.AddRow() // 备注行
  5833. // 填充空白至Z列
  5834. emptyColNum := 0
  5835. for i := 0; i < 26; i++ {
  5836. remarkRow.AddCell().SetValue("")
  5837. if i >= titleLen {
  5838. emptyColNum += 1
  5839. titleRow.AddCell().SetValue("")
  5840. continue
  5841. }
  5842. titleRow.AddCell().SetValue(titleArr[i])
  5843. }
  5844. // AA列开始为品种权限
  5845. ficcPermissions := make([]int, 0) // 用于后续判断试用暂停客户是否需要暂停这部分权限
  5846. raiPermissions := make([]int, 0)
  5847. permissions, e := models.GetChartPermissionList()
  5848. if e != nil {
  5849. br.Msg = "获取失败"
  5850. br.ErrMsg = "获取品种数据失败,Err:" + err.Error()
  5851. return
  5852. }
  5853. raiArr := []string{"医药", "消费", "科技", "智造"}
  5854. for _, p := range permissions {
  5855. if p.ProductId == 1 {
  5856. ficcPermissions = append(ficcPermissions, p.ChartPermissionId)
  5857. }
  5858. if p.ProductId == 2 {
  5859. raiPermissions = append(raiPermissions, p.ChartPermissionId)
  5860. }
  5861. if utils.InArrayByStr(raiArr, p.PermissionName) {
  5862. titleRow.AddCell().SetValue(p.Remark)
  5863. continue
  5864. }
  5865. titleRow.AddCell().SetValue(p.PermissionName)
  5866. }
  5867. // 第二行, 在品种权限开始列加一行标红备注
  5868. styleRed := xlsx.NewStyle()
  5869. styleRed.Font.Color = "ff0000"
  5870. remarkCell := remarkRow.AddCell()
  5871. remarkCell.SetStyle(styleRed)
  5872. remarkCell.SetString(`第一位数字表示是否已购买该品种,1表示已购,0表示未购;第二位数字表示是否有阅读权限,1表示有权限,0表示没有`)
  5873. list, err := company.GetCompanyListExport(condition, pars)
  5874. if err != nil {
  5875. br.Msg = "获取失败"
  5876. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  5877. return
  5878. }
  5879. companyIds := make([]int, 0)
  5880. for _, c := range list {
  5881. companyIds = append(companyIds, c.CompanyId)
  5882. }
  5883. // 获取客户对应的阅读和合同权限集合
  5884. contractPermissionMap := make(map[int][]int)
  5885. contractPermissions, e := company.GetContractPermissionIdsByCompanyIds(companyIds)
  5886. if e != nil {
  5887. br.Msg = "获取失败"
  5888. br.ErrMsg = "获取已购权限失败, Err: " + e.Error()
  5889. return
  5890. }
  5891. for _, p := range contractPermissions {
  5892. ids := make([]int, 0)
  5893. if p.ChartPermissionIds != "" {
  5894. idArr := strings.Split(p.ChartPermissionIds, ",")
  5895. for _, i := range idArr {
  5896. id, _ := strconv.Atoi(i)
  5897. ids = append(ids, id)
  5898. }
  5899. }
  5900. contractPermissionMap[p.CompanyId] = ids
  5901. }
  5902. reportPermissionMap := make(map[int][]int)
  5903. reportPermissions, e := company.GetReportPermissionIdsByCompanyIds(companyIds)
  5904. if e != nil {
  5905. br.Msg = "获取失败"
  5906. br.ErrMsg = "获取阅读权限失败, Err: " + e.Error()
  5907. return
  5908. }
  5909. for _, p := range reportPermissions {
  5910. ids := make([]int, 0)
  5911. if p.ChartPermissionIds != "" {
  5912. idArr := strings.Split(p.ChartPermissionIds, ",")
  5913. for _, i := range idArr {
  5914. id, _ := strconv.Atoi(i)
  5915. ids = append(ids, id)
  5916. }
  5917. }
  5918. reportPermissionMap[p.CompanyId] = ids
  5919. }
  5920. cpMap := make(map[int][]*company.ExportCompanyProduct)
  5921. permissionMap := make(map[string]string)
  5922. for _, v := range list {
  5923. cpList := make([]*company.ExportCompanyProduct, 1)
  5924. if cps, ok := cpMap[v.CompanyId]; ok {
  5925. cpList = cps
  5926. } else {
  5927. companyProduct, err := company.GetExportCompanyProduct(v.CompanyId)
  5928. if err != nil {
  5929. br.Msg = "导出失败"
  5930. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  5931. return
  5932. }
  5933. cpMap[v.CompanyId] = companyProduct
  5934. cpList = companyProduct
  5935. }
  5936. var companyName, companyType, industryName, sellerName, status, timeLimt, createTime, source, permissionStr, expireDay string
  5937. isFiccSuspend := 0
  5938. isRaiSuspend := 0
  5939. for ck, cv := range cpList {
  5940. companyName = cv.CompanyName
  5941. if ck >= 1 {
  5942. companyType = companyType + "/" + cv.ProductName
  5943. status = status + "/" + cv.Status
  5944. } else {
  5945. companyType = cv.ProductName
  5946. status = cv.Status
  5947. }
  5948. if cv.ProductId == 1 {
  5949. industryName = "ficc:" + cv.IndustryName
  5950. sellerName = "ficc:" + cv.SellerName
  5951. startDateStr := cv.StartDate.Format("2006/01/02")
  5952. endDateStr := cv.EndDate.Format("2006/01/02")
  5953. timeLimt = "ficc:" + startDateStr + "~" + endDateStr
  5954. createTime = "ficc:" + cv.CreateTime
  5955. source = "ficc:" + cv.Source
  5956. sub := cv.EndDate.Sub(time.Now())
  5957. if sub < 0 {
  5958. sub = 0
  5959. }
  5960. expireDay = "ficc:" + fmt.Sprintf("%v", int(sub.Hours()/24))
  5961. permissionKey := strconv.Itoa(v.CompanyId) + "_" + strconv.Itoa(cv.ProductId)
  5962. permissionStr = "ficc:"
  5963. if newPermissionStr, ok := permissionMap[permissionKey]; ok {
  5964. permissionStr += newPermissionStr
  5965. } else {
  5966. getPermissionStr, err := company.GetExportPermissionName(v.CompanyId, cv.ProductId)
  5967. if err != nil {
  5968. br.Msg = "导出失败"
  5969. br.ErrMsg = "获取客户权限信息失败,Err:" + err.Error()
  5970. return
  5971. }
  5972. permissionMap[permissionKey] = getPermissionStr
  5973. permissionStr += getPermissionStr
  5974. }
  5975. isFiccSuspend = cv.IsSuspend
  5976. } else {
  5977. industryName = industryName + "\n" + "权益:" + cv.IndustryName
  5978. sellerName = sellerName + "\n" + "权益:" + cv.SellerName
  5979. startDateStr := cv.StartDate.Format("2006/01/02")
  5980. endDateStr := cv.EndDate.Format("2006/01/02")
  5981. timeLimt = timeLimt + "\n" + "权益:" + startDateStr + "~" + endDateStr
  5982. createTime = createTime + "\n" + "权益:" + cv.CreateTime
  5983. source = source + "\n" + "权益:" + cv.Source
  5984. sub := cv.EndDate.Sub(time.Now())
  5985. if sub < 0 {
  5986. sub = 0
  5987. }
  5988. expireDay = "\n" + "权益:" + fmt.Sprintf("%v", int(sub.Hours()/24))
  5989. permissionKey := strconv.Itoa(v.CompanyId) + "_" + strconv.Itoa(cv.ProductId)
  5990. if permissionStr != "" {
  5991. permissionStr = permissionStr + "\n" + "权益:"
  5992. } else {
  5993. permissionStr = "权益:"
  5994. }
  5995. if newPermissionStr, ok := permissionMap[permissionKey]; ok {
  5996. permissionStr += newPermissionStr
  5997. } else {
  5998. getPermissionStr, err := company.GetExportPermissionName(v.CompanyId, cv.ProductId)
  5999. if err != nil {
  6000. br.Msg = "导出失败"
  6001. br.ErrMsg = "获取客户权限信息失败,Err:" + err.Error()
  6002. return
  6003. }
  6004. permissionMap[permissionKey] = getPermissionStr
  6005. permissionStr += getPermissionStr
  6006. }
  6007. isRaiSuspend = cv.IsSuspend
  6008. }
  6009. }
  6010. dataRow := sheel.AddRow()
  6011. dataRow.SetHeight(20)
  6012. dataRow.AddCell().SetString(companyName)
  6013. dataRow.AddCell().SetString(v.Address)
  6014. dataRow.AddCell().SetString(companyType)
  6015. dataRow.AddCell().SetString(v.IndustryName)
  6016. dataRow.AddCell().SetString(v.SellerName)
  6017. dataRow.AddCell().SetString(v.Status)
  6018. dataRow.AddCell().SetString(timeLimt)
  6019. dataRow.AddCell().SetString(expireDay)
  6020. dataRow.AddCell().SetString(v.CreatedTime)
  6021. //dataRow.AddCell().SetString(v.Source)
  6022. dataRow.AddCell().SetString(permissionStr)
  6023. // 填充空白至Z列, AA列开始为权限
  6024. for i := 0; i < emptyColNum; i++ {
  6025. dataRow.AddCell().SetString("")
  6026. }
  6027. cpIds := contractPermissionMap[v.CompanyId]
  6028. rpIds := reportPermissionMap[v.CompanyId]
  6029. for _, p := range permissions {
  6030. // 数字含义:11-表示已购且有阅读权限, 01-表示未购买但有阅读权限
  6031. first := 0
  6032. if utils.InArrayByInt(cpIds, p.ChartPermissionId) {
  6033. first = 1
  6034. }
  6035. second := 0
  6036. if utils.InArrayByInt(rpIds, p.ChartPermissionId) {
  6037. second = 1
  6038. // 如果客户是试用暂停, 即使有这部分权限, 也标记为0
  6039. if isFiccSuspend == 1 && utils.InArrayByInt(ficcPermissions, p.ChartPermissionId) {
  6040. second = 0
  6041. }
  6042. if isRaiSuspend == 1 && utils.InArrayByInt(raiPermissions, p.ChartPermissionId) {
  6043. second = 0
  6044. }
  6045. }
  6046. dataRow.AddCell().SetString(fmt.Sprintf("%d%d", first, second))
  6047. }
  6048. }
  6049. err = xlsxFile.Save(downLoadnFilePath)
  6050. if err != nil {
  6051. br.Msg = "保存文件失败"
  6052. br.ErrMsg = "保存文件失败"
  6053. return
  6054. }
  6055. randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
  6056. downloadFileName := "客户列表_" + randStr + ".xlsx"
  6057. this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  6058. defer func() {
  6059. os.Remove(downLoadnFilePath)
  6060. }()
  6061. br.Ret = 200
  6062. br.Success = true
  6063. br.Msg = "导出成功"
  6064. }
  6065. //func (this *CompanyController) ExportOld() {
  6066. // br := new(models.BaseResponse).Init()
  6067. // defer func() {
  6068. // this.Data["json"] = br
  6069. // this.ServeJSON()
  6070. // }()
  6071. // sysUser := this.SysUser
  6072. // if sysUser == nil {
  6073. // br.Msg = "请登录"
  6074. // br.ErrMsg = "请登录,SysUser Is Empty"
  6075. // br.Ret = 408
  6076. // return
  6077. // }
  6078. // roleTypeCode := sysUser.RoleTypeCode
  6079. //
  6080. // status := this.GetString("Status")
  6081. // companyType := this.GetString("CompanyType")
  6082. // industryId, _ := this.GetInt("IndustryId")
  6083. // adminId := this.GetString("AdminId")
  6084. //
  6085. // chartPermissionIds := this.GetString("ChartPermissionIds")
  6086. // startDate := this.GetString("StartDate")
  6087. // endDate := this.GetString("EndDate")
  6088. // createStartDate := this.GetString("CreateStartDate")
  6089. // createEndDate := this.GetString("CreateEndDate")
  6090. // keyWord := this.GetString("KeyWord")
  6091. // keyWord = strings.Trim(keyWord, " ")
  6092. //
  6093. // resp := new(company.CompanyListResp)
  6094. // statusItems := make([]*company.CompanyStatus, 0)
  6095. // var statusArr = [...]string{"全部", "试用", "正式", "冻结", "流失", "永续"}
  6096. //
  6097. // var condition string
  6098. // var pars []interface{}
  6099. //
  6100. // var lossCondition string
  6101. // var lossPars []interface{}
  6102. //
  6103. // var permissionCondition string
  6104. // var permissionPars []interface{}
  6105. //
  6106. // if status != "" && status != "全部" {
  6107. // condition += ` AND b.status=? `
  6108. // pars = append(pars, status)
  6109. //
  6110. // //permissionCondition += ` AND b.status=? `
  6111. // //permissionPars = append(permissionPars, status)
  6112. // }
  6113. // if companyType != "" {
  6114. // condition += ` AND b.product_name=? `
  6115. // pars = append(pars, companyType)
  6116. //
  6117. // lossCondition += ` AND b.product_name=? `
  6118. // lossPars = append(lossPars, companyType)
  6119. //
  6120. // permissionCondition += ` AND b.product_name=? `
  6121. // permissionPars = append(permissionPars, companyType)
  6122. // }
  6123. //
  6124. // if industryId > 0 {
  6125. // condition += ` AND b.industry_id=? `
  6126. // pars = append(pars, industryId)
  6127. //
  6128. // lossCondition += ` AND b.industry_id=? `
  6129. // lossPars = append(lossPars, industryId)
  6130. //
  6131. // permissionCondition += ` AND b.industry_id=? `
  6132. // permissionPars = append(permissionPars, industryId)
  6133. // }
  6134. //
  6135. // if adminId != "" {
  6136. // condition += ` AND b.seller_id IN (` + adminId + `) `
  6137. //
  6138. // lossCondition += ` AND b.seller_id IN (` + adminId + `) `
  6139. //
  6140. // permissionCondition += ` AND b.seller_id IN (` + adminId + `) `
  6141. // }
  6142. //
  6143. // if startDate != "" {
  6144. // condition += ` AND b.start_date>=? `
  6145. // pars = append(pars, startDate)
  6146. //
  6147. // lossCondition += ` AND b.start_date>=? `
  6148. // lossPars = append(lossPars, startDate)
  6149. //
  6150. // permissionCondition += ` AND b.start_date>=? `
  6151. // permissionPars = append(permissionPars, startDate)
  6152. // }
  6153. //
  6154. // if endDate != "" {
  6155. // condition += ` AND b.end_date<=? `
  6156. // pars = append(pars, endDate)
  6157. //
  6158. // lossCondition += ` AND b.end_date<=? `
  6159. // lossPars = append(lossPars, endDate)
  6160. //
  6161. // permissionCondition += ` AND b.end_date<=? `
  6162. // permissionPars = append(permissionPars, endDate)
  6163. // }
  6164. //
  6165. // if createStartDate != "" {
  6166. // condition += ` AND a.created_time>=? `
  6167. // pars = append(pars, createStartDate)
  6168. //
  6169. // lossCondition += ` AND a.created_time>=? `
  6170. // lossPars = append(lossPars, createStartDate)
  6171. //
  6172. // permissionCondition += ` AND a.created_time>=? `
  6173. // permissionPars = append(permissionPars, createStartDate)
  6174. // }
  6175. //
  6176. // if createEndDate != "" {
  6177. // condition += ` AND a.created_time<=? `
  6178. // pars = append(pars, createEndDate)
  6179. //
  6180. // lossCondition += ` AND a.created_time<=? `
  6181. // lossPars = append(lossPars, createEndDate)
  6182. //
  6183. // permissionCondition += ` AND a.created_time<=? `
  6184. // permissionPars = append(permissionPars, createEndDate)
  6185. // }
  6186. //
  6187. // if keyWord != "" {
  6188. // companyIdStr, err := company.GetCompanyIdByKeyWord(keyWord)
  6189. // if err != nil {
  6190. // return
  6191. // }
  6192. // if companyIdStr != "" {
  6193. // condition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.company_id IN(` + companyIdStr + `)) `
  6194. // lossCondition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.company_id IN(` + companyIdStr + `)) `
  6195. //
  6196. // permissionCondition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.company_id IN(` + companyIdStr + `)) `
  6197. // } else {
  6198. // condition += ` AND (a.company_name LIKE '%` + keyWord + `%' ) `
  6199. // lossCondition += ` AND (a.company_name LIKE '%` + keyWord + `%' ) `
  6200. //
  6201. // permissionCondition += ` AND (a.company_name LIKE '%` + keyWord + `%' ) `
  6202. // }
  6203. // }
  6204. //
  6205. // if chartPermissionIds != "" && chartPermissionIds != "1" {
  6206. // //chartPermissionArr := strings.Split(chartPermissionIds, ",")
  6207. // //chartPermissionCount := len(chartPermissionArr)
  6208. // companyIdStr, err := company.GetCompanyListCompanyIdByPermissionIdStr(chartPermissionIds)
  6209. // if err != nil {
  6210. // br.Msg = "获取失败"
  6211. // br.ErrMsg = "根据权限获取公司ID失败,Err:" + err.Error()
  6212. // return
  6213. // }
  6214. // //var companyIdArr []string
  6215. // //for _, v := range companyIdList {
  6216. // // companyIdArr = append(companyIdArr, strconv.Itoa(v.CompanyId))
  6217. // //}
  6218. // //companyIdStr := strings.Join(companyIdArr, ",")
  6219. //
  6220. // if companyIdStr != "" {
  6221. // condition += ` AND a.company_id IN (` + companyIdStr + `) `
  6222. // lossCondition += ` AND a.company_id IN (` + companyIdStr + `) `
  6223. // permissionCondition += ` AND a.company_id IN (` + companyIdStr + `) `
  6224. // } else {
  6225. // for _, v := range statusArr {
  6226. // statusCount := new(company.CompanyStatus)
  6227. // if v == "全部" {
  6228. // statusCount.Status = "全部"
  6229. // statusCount.Count = 0
  6230. // } else {
  6231. // statusCount.Status = v
  6232. // statusCount.Count = 0
  6233. // }
  6234. // statusItems = append(statusItems, statusCount)
  6235. // }
  6236. // items := make([]*company.CompanyListItem, 0)
  6237. // resp.List = items
  6238. // resp.StatusCount = statusItems
  6239. // br.Msg = "获取成功"
  6240. // br.Ret = 200
  6241. // br.Data = resp
  6242. // return
  6243. // }
  6244. // }
  6245. //
  6246. // //权限控制
  6247. // {
  6248. // if roleTypeCode != utils.ROLE_TYPE_CODE_ADMIN {
  6249. // if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN {
  6250. // condition += ` AND b.product_id=? `
  6251. // pars = append(pars, 1)
  6252. //
  6253. // permissionCondition += ` AND b.product_id=? `
  6254. // permissionPars = append(permissionPars, 1)
  6255. // } else if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  6256. // condition += ` AND b.product_id=? `
  6257. // pars = append(pars, 2)
  6258. //
  6259. // permissionCondition += ` AND b.product_id=? `
  6260. // permissionPars = append(permissionPars, 2)
  6261. // } else {
  6262. // if sysUser.Authority <= 0 {
  6263. // if status != utils.COMPANY_STATUS_LOSE {
  6264. // condition += ` AND b.seller_id=? `
  6265. // pars = append(pars, sysUser.AdminId)
  6266. // }
  6267. //
  6268. // permissionCondition += ` AND b.seller_id=? `
  6269. // permissionPars = append(permissionPars, sysUser.AdminId)
  6270. // } else {
  6271. // if sysUser.Authority == 1 {
  6272. // if status != utils.COMPANY_STATUS_LOSE {
  6273. // condition += ` AND b.department_id=? `
  6274. // pars = append(pars, sysUser.DepartmentId)
  6275. // }
  6276. // permissionCondition += ` AND b.department_id=? `
  6277. // permissionPars = append(permissionPars, sysUser.DepartmentId)
  6278. // }
  6279. //
  6280. // if sysUser.Authority == 2 {
  6281. // if status != utils.COMPANY_STATUS_LOSE {
  6282. // condition += ` AND b.group_id=? `
  6283. // pars = append(pars, sysUser.GroupId)
  6284. // }
  6285. // permissionCondition += ` AND b.group_id=? `
  6286. // permissionPars = append(permissionPars, sysUser.GroupId)
  6287. // }
  6288. // }
  6289. // }
  6290. // }
  6291. // }
  6292. //
  6293. // dir, err := os.Executable()
  6294. // exPath := filepath.Dir(dir)
  6295. // downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  6296. // xlsxFile := xlsx.NewFile()
  6297. // if err != nil {
  6298. // br.Msg = "生成文件失败"
  6299. // br.ErrMsg = "生成文件失败"
  6300. // return
  6301. // }
  6302. // style := xlsx.NewStyle()
  6303. // alignment := xlsx.Alignment{
  6304. // Horizontal: "center",
  6305. // Vertical: "center",
  6306. // WrapText: true,
  6307. // }
  6308. //
  6309. // style.Alignment = alignment
  6310. // style.ApplyAlignment = true
  6311. //
  6312. // sheel, err := xlsxFile.AddSheet("客户数据")
  6313. // if err != nil {
  6314. // br.Msg = "新增Sheet失败"
  6315. // br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  6316. // return
  6317. // }
  6318. // titleRow := sheel.AddRow()
  6319. // titleRow.AddCell().SetValue("客户名称")
  6320. // titleRow.AddCell().SetValue("客户类型")
  6321. // titleRow.AddCell().SetValue("所属行业")
  6322. // titleRow.AddCell().SetValue("所属销售")
  6323. // titleRow.AddCell().SetValue("客户状态")
  6324. // titleRow.AddCell().SetValue("服务期限")
  6325. // titleRow.AddCell().SetValue("到期天数")
  6326. // titleRow.AddCell().SetValue("创建时间")
  6327. // titleRow.AddCell().SetValue("客户来源")
  6328. // titleRow.AddCell().SetValue("阅读权限")
  6329. //
  6330. // list, err := company.GetCompanyListExport(condition, pars)
  6331. // if err != nil {
  6332. // br.Msg = "获取失败"
  6333. // br.ErrMsg = "获取数据失败,Err:" + err.Error()
  6334. // return
  6335. // }
  6336. // cpMap := make(map[int][]*company.ExportCompanyProduct)
  6337. // permissionMap := make(map[string]string)
  6338. // for _, v := range list {
  6339. // cpList := make([]*company.ExportCompanyProduct, 1)
  6340. // if cps, ok := cpMap[v.CompanyId]; ok {
  6341. // cpList = cps
  6342. // } else {
  6343. // companyProduct, err := company.GetExportCompanyProduct(v.CompanyId)
  6344. // if err != nil {
  6345. // br.Msg = "导出失败"
  6346. // br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  6347. // return
  6348. // }
  6349. // cpMap[v.CompanyId] = companyProduct
  6350. // cpList = companyProduct
  6351. // }
  6352. // var companyName, companyType, industryName, sellerName, status, timeLimt, createTime, source, permissionStr, expireDay string
  6353. //
  6354. // for ck, cv := range cpList {
  6355. // companyName = cv.CompanyName
  6356. // if ck >= 1 {
  6357. // companyType = companyType + "/" + cv.ProductName
  6358. // status = status + "/" + cv.Status
  6359. // } else {
  6360. // companyType = cv.ProductName
  6361. // status = cv.Status
  6362. // }
  6363. // if cv.ProductId == 1 {
  6364. // industryName = "ficc:" + cv.IndustryName
  6365. // sellerName = "ficc:" + cv.SellerName
  6366. // startDateStr := cv.StartDate.Format("2006/01/02")
  6367. // endDateStr := cv.EndDate.Format("2006/01/02")
  6368. // timeLimt = "ficc:" + startDateStr + "~" + endDateStr
  6369. // createTime = "ficc:" + cv.CreateTime
  6370. // source = "ficc:" + cv.Source
  6371. // sub := cv.EndDate.Sub(time.Now())
  6372. // if sub < 0 {
  6373. // sub = 0
  6374. // }
  6375. // expireDay = "ficc:" + fmt.Sprintf("%v", int(sub.Hours()/24))
  6376. //
  6377. // permissionKey := strconv.Itoa(v.CompanyId) + "_" + strconv.Itoa(cv.ProductId)
  6378. //
  6379. // permissionStr = "ficc:"
  6380. // if newPermissionStr, ok := permissionMap[permissionKey]; ok {
  6381. // permissionStr += newPermissionStr
  6382. // } else {
  6383. // getPermissionStr, err := company.GetExportPermissionName(v.CompanyId, cv.ProductId)
  6384. // if err != nil {
  6385. // br.Msg = "导出失败"
  6386. // br.ErrMsg = "获取客户权限信息失败,Err:" + err.Error()
  6387. // return
  6388. // }
  6389. // permissionMap[permissionKey] = getPermissionStr
  6390. // permissionStr += getPermissionStr
  6391. // }
  6392. // } else {
  6393. // industryName = industryName + "\n" + "权益:" + cv.IndustryName
  6394. // sellerName = sellerName + "\n" + "权益:" + cv.SellerName
  6395. // startDateStr := cv.StartDate.Format("2006/01/02")
  6396. // endDateStr := cv.EndDate.Format("2006/01/02")
  6397. //
  6398. // timeLimt = timeLimt + "\n" + "权益:" + startDateStr + "~" + endDateStr
  6399. // createTime = createTime + "\n" + "权益:" + cv.CreateTime
  6400. // source = source + "\n" + "权益:" + cv.Source
  6401. //
  6402. // sub := cv.EndDate.Sub(time.Now())
  6403. // if sub < 0 {
  6404. // sub = 0
  6405. // }
  6406. // expireDay = "\n" + "权益:" + fmt.Sprintf("%v", int(sub.Hours()/24))
  6407. //
  6408. // permissionKey := strconv.Itoa(v.CompanyId) + "_" + strconv.Itoa(cv.ProductId)
  6409. // if permissionStr != "" {
  6410. // permissionStr = permissionStr + "\n" + "权益:"
  6411. // } else {
  6412. // permissionStr = "权益:"
  6413. // }
  6414. // if newPermissionStr, ok := permissionMap[permissionKey]; ok {
  6415. // permissionStr += newPermissionStr
  6416. // } else {
  6417. // getPermissionStr, err := company.GetExportPermissionName(v.CompanyId, cv.ProductId)
  6418. // if err != nil {
  6419. // br.Msg = "导出失败"
  6420. // br.ErrMsg = "获取客户权限信息失败,Err:" + err.Error()
  6421. // return
  6422. // }
  6423. // permissionMap[permissionKey] = getPermissionStr
  6424. // permissionStr += getPermissionStr
  6425. // }
  6426. // }
  6427. // }
  6428. //
  6429. // dataRow := sheel.AddRow()
  6430. // dataRow.SetHeight(20)
  6431. // dataRow.AddCell().SetString(companyName)
  6432. // dataRow.AddCell().SetString(companyType)
  6433. // dataRow.AddCell().SetString(v.IndustryName)
  6434. // dataRow.AddCell().SetString(v.SellerName)
  6435. // dataRow.AddCell().SetString(v.Status)
  6436. // dataRow.AddCell().SetString(timeLimt)
  6437. // dataRow.AddCell().SetString(expireDay)
  6438. // dataRow.AddCell().SetString(v.CreatedTime)
  6439. // dataRow.AddCell().SetString(v.Source)
  6440. // dataRow.AddCell().SetString(permissionStr)
  6441. // }
  6442. // err = xlsxFile.Save(downLoadnFilePath)
  6443. // if err != nil {
  6444. // br.Msg = "保存文件失败"
  6445. // br.ErrMsg = "保存文件失败"
  6446. // return
  6447. // }
  6448. // randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
  6449. // downloadFileName := "客户列表_" + randStr + ".xlsx"
  6450. // this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  6451. // defer func() {
  6452. // os.Remove(downLoadnFilePath)
  6453. // }()
  6454. // br.Ret = 200
  6455. // br.Success = true
  6456. // br.Msg = "导出成功"
  6457. //}
  6458. // @Title 导出
  6459. // @Description 导出接口
  6460. // @Param Status query string true "状态:”试用','永续','冻结','流失','正式'"
  6461. // @Param CompanyType query string true "客户类型:传空字符串或者不传为全部,'ficc','权益'"
  6462. // @Param IndustryId query int true "行业id,0为全部"
  6463. // @Param AdminId query string true "销售id,多个用英文逗号隔开,空字符串为全部"
  6464. // @Param ChartPermissionIds query string false "阅读权限品种ID,多个用英文逗号分开,空字符串为全部"
  6465. // @Param ContractPermissionIds query string false "已购品种ID,多个用英文逗号分开,空字符串为全部"
  6466. // @Param StartDate query string true "开始时间"
  6467. // @Param EndDate query string true "结束时间"
  6468. // @Param KeyWord query string true "搜索关键词"
  6469. // @Param Address query string true "地址 , 多个用英文逗号分开 "
  6470. // @Param Province query string true "省 , 多个用英文逗号分开 "
  6471. // @Param City query string true "市 , 多个用英文逗号分开 "
  6472. // @Param PackageType query int true "套餐类型,0:无,1:大套餐,2:小套餐"
  6473. // @Success Ret=200 移动成功
  6474. // @router /user/export [get]
  6475. func (this *CompanyController) CompanyUserExport() {
  6476. br := new(models.BaseResponse).Init()
  6477. defer func() {
  6478. this.Data["json"] = br
  6479. this.ServeJSON()
  6480. }()
  6481. sysUser := this.SysUser
  6482. if sysUser == nil {
  6483. br.Msg = "请登录"
  6484. br.ErrMsg = "请登录,SysUser Is Empty"
  6485. br.Ret = 408
  6486. return
  6487. }
  6488. roleTypeCode := sysUser.RoleTypeCode
  6489. status := this.GetString("Status")
  6490. companyType := this.GetString("CompanyType")
  6491. industryId, _ := this.GetInt("IndustryId")
  6492. adminId := this.GetString("AdminId")
  6493. chartPermissionIds := this.GetString("ChartPermissionIds")
  6494. contractPermissionIds := this.GetString("ContractPermissionIds")
  6495. startDate := this.GetString("StartDate")
  6496. endDate := this.GetString("EndDate")
  6497. createStartDate := this.GetString("CreateStartDate")
  6498. createEndDate := this.GetString("CreateEndDate")
  6499. keyWord := this.GetString("KeyWord")
  6500. address := this.GetString("Address")
  6501. province := this.GetString("Province")
  6502. city := this.GetString("City")
  6503. // 套餐类型
  6504. packageType, _ := this.GetInt("PackageType")
  6505. var condition string
  6506. var pars []interface{}
  6507. if status != "" && status != "全部" {
  6508. condition += ` AND b.status=? `
  6509. pars = append(pars, status)
  6510. }
  6511. if companyType != "" {
  6512. condition += ` AND b.product_name=? `
  6513. pars = append(pars, companyType)
  6514. }
  6515. if industryId > 0 {
  6516. condition += ` AND b.industry_id=? `
  6517. pars = append(pars, industryId)
  6518. }
  6519. if adminId != "" {
  6520. condition += ` AND b.seller_id IN (` + adminId + `) `
  6521. }
  6522. if startDate != "" {
  6523. condition += ` AND b.start_date>=? `
  6524. pars = append(pars, startDate)
  6525. }
  6526. if endDate != "" {
  6527. condition += ` AND b.end_date<=? `
  6528. pars = append(pars, endDate)
  6529. }
  6530. if createStartDate != "" {
  6531. condition += ` AND a.created_time>=? `
  6532. pars = append(pars, createStartDate)
  6533. }
  6534. if createEndDate != "" {
  6535. condition += ` AND a.created_time<=? `
  6536. pars = append(pars, createEndDate)
  6537. }
  6538. if keyWord != "" {
  6539. condition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR c.mobile LIKE '%` + keyWord + `%' OR c.email LIKE '%` + keyWord + `%') `
  6540. }
  6541. // 阅读权限/已购品种筛选
  6542. cond, emp, e := services.FilterReadAndContractAuth(chartPermissionIds, contractPermissionIds, condition)
  6543. if e != nil {
  6544. br.Msg = "获取失败"
  6545. br.ErrMsg = "FilterReadAndContractAuth err: " + e.Error()
  6546. return
  6547. }
  6548. if emp {
  6549. condition += ` AND 1 = 2`
  6550. } else {
  6551. condition = cond
  6552. }
  6553. if address != "" {
  6554. var addressSql string
  6555. slice := strings.Split(address, ",")
  6556. for _, v := range slice {
  6557. addressSql += "'" + v + "'" + ","
  6558. }
  6559. addressSql = strings.TrimRight(addressSql, ",")
  6560. condition += ` AND a.address IN (` + addressSql + `) `
  6561. }
  6562. if province != "" {
  6563. var provinceSql string
  6564. slice := strings.Split(province, ",")
  6565. for _, v := range slice {
  6566. provinceSql += "'" + v + "'" + ","
  6567. }
  6568. provinceSql = strings.TrimRight(provinceSql, ",")
  6569. condition += ` AND a.province IN (` + provinceSql + `) `
  6570. }
  6571. if city != "" {
  6572. var citySql string
  6573. slice := strings.Split(city, ",")
  6574. for _, v := range slice {
  6575. citySql += "'" + v + "'" + ","
  6576. }
  6577. citySql = strings.TrimRight(citySql, ",")
  6578. condition += ` AND a.city IN (` + citySql + `) `
  6579. }
  6580. //套餐类型
  6581. if packageType > 0 {
  6582. condition += ` AND b.package_type=? `
  6583. pars = append(pars, packageType)
  6584. }
  6585. //权限控制
  6586. {
  6587. if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER ||
  6588. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER {
  6589. if status != utils.COMPANY_STATUS_LOSE && status != utils.COMPANY_STATUS_FOREVER {
  6590. condition += ` AND b.seller_id=? `
  6591. pars = append(pars, sysUser.AdminId)
  6592. }
  6593. }
  6594. if sysUser.Authority == 1 {
  6595. condition += ` AND b.department_id=? `
  6596. pars = append(pars, sysUser.DepartmentId)
  6597. }
  6598. if sysUser.Authority == 2 {
  6599. condition += ` AND b.group_id=? `
  6600. pars = append(pars, sysUser.GroupId)
  6601. }
  6602. }
  6603. var statusCond string
  6604. var statusPars []interface{}
  6605. // 根据当前用户角色
  6606. productId := services.GetProductId(roleTypeCode)
  6607. if productId > 0 {
  6608. condition += ` AND b.product_id = ? `
  6609. pars = append(pars, productId)
  6610. statusCond += ` AND b.product_id = ? `
  6611. statusPars = append(statusPars, productId)
  6612. }
  6613. companyIds, err := company.GetExportCompanyIds(condition, pars)
  6614. if err != nil {
  6615. br.Msg = "导出失败"
  6616. br.ErrMsg = "导出失败,Err:" + err.Error()
  6617. return
  6618. }
  6619. dir, err := os.Executable()
  6620. exPath := filepath.Dir(dir)
  6621. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  6622. xlsxFile := xlsx.NewFile()
  6623. if err != nil {
  6624. br.Msg = "生成文件失败"
  6625. br.ErrMsg = "生成文件失败"
  6626. return
  6627. }
  6628. style := xlsx.NewStyle()
  6629. alignment := xlsx.Alignment{
  6630. Horizontal: "center",
  6631. Vertical: "center",
  6632. WrapText: true,
  6633. }
  6634. style.Alignment = alignment
  6635. style.ApplyAlignment = true
  6636. sheel, err := xlsxFile.AddSheet("联系人数据")
  6637. if err != nil {
  6638. br.Msg = "新增Sheet失败"
  6639. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  6640. return
  6641. }
  6642. sheel.SetColWidth(7, 7, 10)
  6643. sheel.SetColWidth(8, 10, 16)
  6644. sheel.SetColWidth(9, 11, 20)
  6645. sheel.SetColWidth(12, 12, 35)
  6646. sheel.SetColWidth(13, 13, 15)
  6647. sheel.SetColWidth(14, 14, 80)
  6648. titleRow := sheel.AddRow()
  6649. titleRow.AddCell().SetValue("联系人")
  6650. titleRow.AddCell().SetValue("是否关注公众号")
  6651. titleRow.AddCell().SetValue("手机号")
  6652. titleRow.AddCell().SetValue("邮箱")
  6653. //titleRow.AddCell().SetValue("职位")
  6654. titleRow.AddCell().SetValue("是否决策人")
  6655. //titleRow.AddCell().SetValue("客户部门")
  6656. titleRow.AddCell().SetValue("客户名称")
  6657. titleRow.AddCell().SetValue("客户状态")
  6658. //titleRow.AddCell().SetValue("社会信用码")
  6659. //titleRow.AddCell().SetValue("所属区域")
  6660. //titleRow.AddCell().SetValue("客户类型")
  6661. //industryCell := titleRow.AddCell()
  6662. //industryCell.SetStyle(style)
  6663. //industryCell.Value = "所属行业"
  6664. //
  6665. //sellerCell := titleRow.AddCell()
  6666. //sellerCell.SetStyle(style)
  6667. //sellerCell.Value = "所属销售"
  6668. //
  6669. //statusCell := titleRow.AddCell()
  6670. //statusCell.SetStyle(style)
  6671. //statusCell.Value = "客户状态"
  6672. //
  6673. //timeLimtCell := titleRow.AddCell()
  6674. //timeLimtCell.SetStyle(style)
  6675. //timeLimtCell.Value = "服务期限"
  6676. //
  6677. //createTimeCell := titleRow.AddCell()
  6678. //createTimeCell.SetStyle(style)
  6679. //createTimeCell.Value = "创建时间"
  6680. //
  6681. //sourceCell := titleRow.AddCell()
  6682. //sourceCell.SetStyle(style)
  6683. //sourceCell.Value = "客户来源"
  6684. //permissionStyle := xlsx.NewStyle()
  6685. //permissionAlignment := xlsx.Alignment{
  6686. // Horizontal: "center",
  6687. // Vertical: "center",
  6688. // WrapText: true,
  6689. //}
  6690. //
  6691. //permissionStyle.Alignment = permissionAlignment
  6692. //permissionStyle.ApplyAlignment = true
  6693. //permissionCell := titleRow.AddCell()
  6694. //permissionCell.SetStyle(permissionStyle)
  6695. //permissionCell.Value = "阅读权限"
  6696. users := make([]*company.ExportUser, 0)
  6697. if companyIds != "" {
  6698. companyIds = strings.Trim(companyIds, ",")
  6699. if productId > 0 {
  6700. users, err = company.GetExportUserByProductId(companyIds, productId)
  6701. if err != nil {
  6702. br.Msg = "导出失败"
  6703. br.ErrMsg = "获取联系人信息失败,Err:" + err.Error()
  6704. return
  6705. }
  6706. } else {
  6707. users, err = company.GetExportUser(companyIds)
  6708. if err != nil {
  6709. br.Msg = "导出失败"
  6710. br.ErrMsg = "获取联系人信息失败,Err:" + err.Error()
  6711. return
  6712. }
  6713. }
  6714. // 获取客户状态
  6715. companyIntIds := make([]int, 0)
  6716. companyIdArr := strings.Split(companyIds, ",")
  6717. for _, c := range companyIdArr {
  6718. id, e := strconv.Atoi(c)
  6719. if e != nil {
  6720. br.Msg = "导出失败"
  6721. br.ErrMsg = "客户ID有误"
  6722. return
  6723. }
  6724. companyIntIds = append(companyIntIds, id)
  6725. }
  6726. if len(companyIntIds) > 0 {
  6727. statusCond += fmt.Sprintf(` AND a.company_id IN (%s) `, utils.GetOrmInReplace(len(companyIntIds)))
  6728. statusPars = append(statusPars, companyIntIds)
  6729. }
  6730. statusMap := make(map[int]string)
  6731. nameMap := make(map[int]string)
  6732. companyStatusList, e := company.GetExportUserCompanyStatus(statusCond, statusPars)
  6733. if e != nil {
  6734. br.Msg = "导出失败"
  6735. br.ErrMsg = "获取客户状态失败, Err: " + e.Error()
  6736. return
  6737. }
  6738. for _, s := range companyStatusList {
  6739. statusMap[s.CompanyId] = s.CompanyStatus
  6740. nameMap[s.CompanyId] = s.CompanyName
  6741. }
  6742. //cpMap := make(map[int][]*company.ExportCompanyProduct)
  6743. //permissionMap := make(map[string]string)
  6744. for _, v := range users {
  6745. dataRow := sheel.AddRow()
  6746. dataRow.SetHeight(20)
  6747. dataRow.AddCell().SetString(v.RealName)
  6748. if v.IsSubscribe == 1 {
  6749. dataRow.AddCell().SetString("是") // 是否关注公众号
  6750. } else {
  6751. dataRow.AddCell().SetString("")
  6752. }
  6753. dataRow.AddCell().SetString(v.Mobile)
  6754. dataRow.AddCell().SetString(v.Email)
  6755. //dataRow.AddCell().SetString(v.Position)
  6756. if v.IsMaker == 1 {
  6757. dataRow.AddCell().SetString("是")
  6758. } else {
  6759. dataRow.AddCell().SetString("否")
  6760. }
  6761. //dataRow.AddCell().SetString(v.DepartmentName)
  6762. //cpList := make([]*company.ExportCompanyProduct, 1)
  6763. //if cps, ok := cpMap[v.CompanyId]; ok {
  6764. // cpList = cps
  6765. //} else {
  6766. // companyProduct, err := company.GetExportCompanyProduct(v.CompanyId)
  6767. // if err != nil {
  6768. // br.Msg = "导出失败"
  6769. // br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  6770. // return
  6771. // }
  6772. // cpMap[v.CompanyId] = companyProduct
  6773. // cpList = companyProduct
  6774. //}
  6775. //productList, err := company.GetExportCompanyProduct(v.CompanyId)
  6776. //if err!=nil {
  6777. // fmt.Println("导出失败,Err:"+err.Error())
  6778. // return
  6779. //}
  6780. //var companyName, companyType, industryName, sellerName, status, timeLimt, createTime, source, permissionStr, creditCode, regionType string
  6781. //for ck, cv := range cpList {
  6782. // companyName = cv.CompanyName
  6783. // creditCode = cv.CreditCode
  6784. // regionType = cv.RegionType
  6785. // if ck >= 1 {
  6786. // companyType = companyType + "/" + cv.ProductName
  6787. // status = status + "/" + cv.Status
  6788. // } else {
  6789. // companyType = cv.ProductName
  6790. // status = cv.Status
  6791. // }
  6792. // if cv.ProductId == 1 {
  6793. // industryName = "ficc:" + cv.IndustryName
  6794. // sellerName = "ficc:" + cv.SellerName
  6795. // startDateStr := cv.StartDate.Format("2006/01/02")
  6796. // endDateStr := cv.EndDate.Format("2006/01/02")
  6797. // if startDateStr != "0001/01/01" {
  6798. // timeLimt = "ficc:" + startDateStr + "~" + endDateStr
  6799. // } else {
  6800. // timeLimt = ""
  6801. // }
  6802. // createTime = "ficc:" + cv.CreateTime
  6803. // source = "ficc:" + cv.Source
  6804. // permissionKey := strconv.Itoa(v.CompanyId) + "_" + strconv.Itoa(cv.ProductId)
  6805. //
  6806. // permissionStr = "ficc:"
  6807. // if newPermissionStr, ok := permissionMap[permissionKey]; ok {
  6808. // permissionStr += newPermissionStr
  6809. // } else {
  6810. // getPermissionStr, err := company.GetExportPermissionName(v.CompanyId, cv.ProductId)
  6811. // if err != nil {
  6812. // br.Msg = "导出失败"
  6813. // br.ErrMsg = "获取客户权限信息失败,Err:" + err.Error()
  6814. // return
  6815. // }
  6816. // permissionMap[permissionKey] = getPermissionStr
  6817. // permissionStr += getPermissionStr
  6818. // }
  6819. // if cv.Status == utils.COMPANY_STATUS_LOSE {
  6820. // permissionStr = ""
  6821. // }
  6822. // } else {
  6823. // industryName = industryName + "\n" + "权益:" + cv.IndustryName
  6824. // sellerName = sellerName + "\n" + "权益:" + cv.SellerName
  6825. // startDateStr := cv.StartDate.Format("2006/01/02")
  6826. // endDateStr := cv.EndDate.Format("2006/01/02")
  6827. //
  6828. // if startDateStr != "0001/01/01" {
  6829. // timeLimt = timeLimt + "\n" + "权益:" + startDateStr + "~" + endDateStr
  6830. // } else {
  6831. // timeLimt = timeLimt + ""
  6832. // }
  6833. // createTime = createTime + "\n" + "权益:" + cv.CreateTime
  6834. // source = source + "\n" + "权益:" + cv.Source
  6835. //
  6836. // permissionKey := strconv.Itoa(v.CompanyId) + "_" + strconv.Itoa(cv.ProductId)
  6837. // if permissionStr != "" {
  6838. // permissionStr = permissionStr + "\n" + "权益:"
  6839. // } else {
  6840. // permissionStr = "权益:"
  6841. // }
  6842. // if newPermissionStr, ok := permissionMap[permissionKey]; ok {
  6843. // permissionStr += newPermissionStr
  6844. // } else {
  6845. // getPermissionStr, err := company.GetExportPermissionName(v.CompanyId, cv.ProductId)
  6846. // if err != nil {
  6847. // br.Msg = "导出失败"
  6848. // br.ErrMsg = "获取客户权限信息失败,Err:" + err.Error()
  6849. // return
  6850. // }
  6851. // permissionMap[permissionKey] = getPermissionStr
  6852. // permissionStr += getPermissionStr
  6853. // }
  6854. // if cv.Status == utils.COMPANY_STATUS_LOSE {
  6855. // permissionStr = permissionStr + ""
  6856. // }
  6857. // }
  6858. //}
  6859. // 2023-0420这是谁写的循环查,顺手优化了一下,手动狗头-_-~
  6860. //companyInfo, err := company.GetCompanyById(v.CompanyId)
  6861. //if err != nil {
  6862. // br.Msg = "导出失败"
  6863. // br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  6864. // return
  6865. //}
  6866. dataRow.AddCell().SetString(nameMap[v.CompanyId])
  6867. dataRow.AddCell().SetString(statusMap[v.CompanyId]) // 客户状态
  6868. //dataRow.AddCell().SetString(creditCode)
  6869. //dataRow.AddCell().SetString(regionType)
  6870. //
  6871. //dataRow.AddCell().SetString(companyType)
  6872. //industryValueCell := dataRow.AddCell()
  6873. //industryValueCell.SetStyle(style)
  6874. //industryValueCell.SetString(industryName)
  6875. //
  6876. //sellerValueCell := dataRow.AddCell()
  6877. //sellerValueCell.SetStyle(style)
  6878. //sellerValueCell.SetString(sellerName)
  6879. //
  6880. //statusValueCell := dataRow.AddCell()
  6881. //statusValueCell.SetStyle(style)
  6882. //statusValueCell.SetValue(status)
  6883. //
  6884. //timeLimitValueCell := dataRow.AddCell()
  6885. //timeLimitValueCell.SetStyle(style)
  6886. //timeLimitValueCell.SetValue(timeLimt)
  6887. //
  6888. //createTimeValueCell := dataRow.AddCell()
  6889. //createTimeValueCell.SetStyle(style)
  6890. //createTimeValueCell.SetValue(createTime)
  6891. //
  6892. //sourceValueCell := dataRow.AddCell()
  6893. //sourceValueCell.SetStyle(style)
  6894. //sourceValueCell.SetValue(source)
  6895. //
  6896. //permissionStrValueCell := dataRow.AddCell()
  6897. //permissionStrValueCell.SetStyle(style)
  6898. //permissionStrValueCell.SetValue(permissionStr)
  6899. }
  6900. }
  6901. err = xlsxFile.Save(downLoadnFilePath)
  6902. if err != nil {
  6903. br.Msg = "保存文件失败"
  6904. br.ErrMsg = "保存文件失败"
  6905. return
  6906. }
  6907. randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
  6908. downloadFileName := "联系人列表" + randStr + ".xlsx"
  6909. this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  6910. defer func() {
  6911. os.Remove(downLoadnFilePath)
  6912. }()
  6913. br.Ret = 200
  6914. br.Success = true
  6915. br.Msg = "导出成功"
  6916. }
  6917. //func (this *CompanyController) CompanyUserExportOld() {
  6918. // br := new(models.BaseResponse).Init()
  6919. // defer func() {
  6920. // this.Data["json"] = br
  6921. // this.ServeJSON()
  6922. // }()
  6923. // sysUser := this.SysUser
  6924. // if sysUser == nil {
  6925. // br.Msg = "请登录"
  6926. // br.ErrMsg = "请登录,SysUser Is Empty"
  6927. // br.Ret = 408
  6928. // return
  6929. // }
  6930. // roleTypeCode := sysUser.RoleTypeCode
  6931. // status := this.GetString("Status")
  6932. // companyType := this.GetString("CompanyType")
  6933. // industryId, _ := this.GetInt("IndustryId")
  6934. // adminId := this.GetString("AdminId")
  6935. //
  6936. // chartPermissionIds := this.GetString("ChartPermissionIds")
  6937. // startDate := this.GetString("StartDate")
  6938. // endDate := this.GetString("EndDate")
  6939. // keyWord := this.GetString("KeyWord")
  6940. //
  6941. // var condition string
  6942. // var pars []interface{}
  6943. //
  6944. // if status != "" && status != "全部" {
  6945. // condition += ` AND b.status=? `
  6946. // pars = append(pars, status)
  6947. // }
  6948. // if companyType != "" {
  6949. // condition += ` AND b.product_name=? `
  6950. // pars = append(pars, companyType)
  6951. // }
  6952. //
  6953. // if industryId > 0 {
  6954. // condition += ` AND b.industry_id=? `
  6955. // pars = append(pars, industryId)
  6956. // }
  6957. //
  6958. // if adminId != "" {
  6959. // condition += ` AND b.seller_id IN (` + adminId + `) `
  6960. // }
  6961. //
  6962. // if startDate != "" {
  6963. // condition += ` AND b.start_date>=? `
  6964. // pars = append(pars, startDate)
  6965. // }
  6966. //
  6967. // if endDate != "" {
  6968. // condition += ` AND b.end_date>=? `
  6969. // pars = append(pars, endDate)
  6970. // }
  6971. //
  6972. // if keyWord != "" {
  6973. // condition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR c.mobile LIKE '%` + keyWord + `%' OR c.email LIKE '%` + keyWord + `%') `
  6974. // }
  6975. //
  6976. // if chartPermissionIds != "" {
  6977. // companyIdStr, err := company.GetCompanyIdStr(chartPermissionIds)
  6978. // if err != nil {
  6979. // br.Msg = "获取失败"
  6980. // br.ErrMsg = "根据权限获取公司ID失败,Err:" + err.Error()
  6981. // return
  6982. // }
  6983. // if companyIdStr != "" {
  6984. // condition += ` AND a.company_id IN (` + companyIdStr + `) `
  6985. // }
  6986. // }
  6987. //
  6988. // //权限控制
  6989. // {
  6990. // if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER ||
  6991. // roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER {
  6992. // if status != utils.COMPANY_STATUS_LOSE && status != utils.COMPANY_STATUS_FOREVER {
  6993. // condition += ` AND b.seller_id=? `
  6994. // pars = append(pars, sysUser.AdminId)
  6995. // }
  6996. // }
  6997. // if sysUser.Authority == 1 {
  6998. // condition += ` AND b.department_id=? `
  6999. // pars = append(pars, sysUser.DepartmentId)
  7000. // }
  7001. //
  7002. // if sysUser.Authority == 2 {
  7003. // condition += ` AND b.group_id=? `
  7004. // pars = append(pars, sysUser.GroupId)
  7005. // }
  7006. // }
  7007. // companyIds, err := company.GetExportCompanyIds(condition, pars)
  7008. // if err != nil {
  7009. // br.Msg = "导出失败"
  7010. // br.ErrMsg = "导出失败,Err:" + err.Error()
  7011. // return
  7012. // }
  7013. //
  7014. // dir, err := os.Executable()
  7015. // exPath := filepath.Dir(dir)
  7016. //
  7017. // downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  7018. // xlsxFile := xlsx.NewFile()
  7019. // if err != nil {
  7020. // br.Msg = "生成文件失败"
  7021. // br.ErrMsg = "生成文件失败"
  7022. // return
  7023. // }
  7024. // style := xlsx.NewStyle()
  7025. // alignment := xlsx.Alignment{
  7026. // Horizontal: "center",
  7027. // Vertical: "center",
  7028. // WrapText: true,
  7029. // }
  7030. //
  7031. // style.Alignment = alignment
  7032. // style.ApplyAlignment = true
  7033. //
  7034. // sheel, err := xlsxFile.AddSheet("联系人数据")
  7035. // if err != nil {
  7036. // br.Msg = "新增Sheet失败"
  7037. // br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  7038. // return
  7039. // }
  7040. //
  7041. // sheel.SetColWidth(7, 7, 10)
  7042. // sheel.SetColWidth(8, 10, 16)
  7043. // sheel.SetColWidth(9, 11, 20)
  7044. // sheel.SetColWidth(12, 12, 35)
  7045. // sheel.SetColWidth(13, 13, 15)
  7046. // sheel.SetColWidth(14, 14, 80)
  7047. // titleRow := sheel.AddRow()
  7048. // titleRow.AddCell().SetValue("联系人")
  7049. // titleRow.AddCell().SetValue("手机号")
  7050. // titleRow.AddCell().SetValue("邮箱")
  7051. // titleRow.AddCell().SetValue("职位")
  7052. // titleRow.AddCell().SetValue("是否决策人")
  7053. // titleRow.AddCell().SetValue("客户部门")
  7054. // titleRow.AddCell().SetValue("客户名称")
  7055. // titleRow.AddCell().SetValue("社会信用码")
  7056. // titleRow.AddCell().SetValue("所属区域")
  7057. // titleRow.AddCell().SetValue("客户类型")
  7058. //
  7059. // industryCell := titleRow.AddCell()
  7060. // industryCell.SetStyle(style)
  7061. // industryCell.Value = "所属行业"
  7062. //
  7063. // sellerCell := titleRow.AddCell()
  7064. // sellerCell.SetStyle(style)
  7065. // sellerCell.Value = "所属销售"
  7066. //
  7067. // statusCell := titleRow.AddCell()
  7068. // statusCell.SetStyle(style)
  7069. // statusCell.Value = "客户状态"
  7070. //
  7071. // timeLimtCell := titleRow.AddCell()
  7072. // timeLimtCell.SetStyle(style)
  7073. // timeLimtCell.Value = "服务期限"
  7074. //
  7075. // createTimeCell := titleRow.AddCell()
  7076. // createTimeCell.SetStyle(style)
  7077. // createTimeCell.Value = "创建时间"
  7078. //
  7079. // sourceCell := titleRow.AddCell()
  7080. // sourceCell.SetStyle(style)
  7081. // sourceCell.Value = "客户来源"
  7082. //
  7083. // permissionStyle := xlsx.NewStyle()
  7084. // permissionAlignment := xlsx.Alignment{
  7085. // Horizontal: "center",
  7086. // Vertical: "center",
  7087. // WrapText: true,
  7088. // }
  7089. //
  7090. // permissionStyle.Alignment = permissionAlignment
  7091. // permissionStyle.ApplyAlignment = true
  7092. //
  7093. // permissionCell := titleRow.AddCell()
  7094. // permissionCell.SetStyle(permissionStyle)
  7095. // permissionCell.Value = "阅读权限"
  7096. //
  7097. // if companyIds != "" {
  7098. // companyIds = strings.Trim(companyIds, ",")
  7099. // users, err := company.GetExportUser(companyIds)
  7100. // if err != nil {
  7101. // br.Msg = "导出失败"
  7102. // br.ErrMsg = "获取联系人信息失败,Err:" + err.Error()
  7103. // return
  7104. // }
  7105. // cpMap := make(map[int][]*company.ExportCompanyProduct)
  7106. // permissionMap := make(map[string]string)
  7107. // for _, v := range users {
  7108. // dataRow := sheel.AddRow()
  7109. // dataRow.SetHeight(20)
  7110. // dataRow.AddCell().SetString(v.RealName)
  7111. // dataRow.AddCell().SetString(v.Mobile)
  7112. // dataRow.AddCell().SetString(v.Email)
  7113. // dataRow.AddCell().SetString(v.Position)
  7114. // if v.IsMaker == 1 {
  7115. // dataRow.AddCell().SetString("是")
  7116. // } else {
  7117. // dataRow.AddCell().SetString("否")
  7118. // }
  7119. // dataRow.AddCell().SetString(v.DepartmentName)
  7120. // cpList := make([]*company.ExportCompanyProduct, 1)
  7121. // if cps, ok := cpMap[v.CompanyId]; ok {
  7122. // cpList = cps
  7123. // } else {
  7124. // companyProduct, err := company.GetExportCompanyProduct(v.CompanyId)
  7125. // if err != nil {
  7126. // br.Msg = "导出失败"
  7127. // br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  7128. // return
  7129. // }
  7130. // cpMap[v.CompanyId] = companyProduct
  7131. // cpList = companyProduct
  7132. // }
  7133. // //productList, err := company.GetExportCompanyProduct(v.CompanyId)
  7134. // //if err!=nil {
  7135. // // fmt.Println("导出失败,Err:"+err.Error())
  7136. // // return
  7137. // //}
  7138. // var companyName, companyType, industryName, sellerName, status, timeLimt, createTime, source, permissionStr, creditCode, regionType string
  7139. //
  7140. // for ck, cv := range cpList {
  7141. // companyName = cv.CompanyName
  7142. // creditCode = cv.CreditCode
  7143. // regionType = cv.RegionType
  7144. // if ck >= 1 {
  7145. // companyType = companyType + "/" + cv.ProductName
  7146. // status = status + "/" + cv.Status
  7147. // } else {
  7148. // companyType = cv.ProductName
  7149. // status = cv.Status
  7150. // }
  7151. // if cv.ProductId == 1 {
  7152. // industryName = "ficc:" + cv.IndustryName
  7153. // sellerName = "ficc:" + cv.SellerName
  7154. // startDateStr := cv.StartDate.Format("2006/01/02")
  7155. // endDateStr := cv.EndDate.Format("2006/01/02")
  7156. // if startDateStr != "0001/01/01" {
  7157. // timeLimt = "ficc:" + startDateStr + "~" + endDateStr
  7158. // } else {
  7159. // timeLimt = ""
  7160. // }
  7161. // createTime = "ficc:" + cv.CreateTime
  7162. // source = "ficc:" + cv.Source
  7163. // permissionKey := strconv.Itoa(v.CompanyId) + "_" + strconv.Itoa(cv.ProductId)
  7164. //
  7165. // permissionStr = "ficc:"
  7166. // if newPermissionStr, ok := permissionMap[permissionKey]; ok {
  7167. // permissionStr += newPermissionStr
  7168. // } else {
  7169. // getPermissionStr, err := company.GetExportPermissionName(v.CompanyId, cv.ProductId)
  7170. // if err != nil {
  7171. // br.Msg = "导出失败"
  7172. // br.ErrMsg = "获取客户权限信息失败,Err:" + err.Error()
  7173. // return
  7174. // }
  7175. // permissionMap[permissionKey] = getPermissionStr
  7176. // permissionStr += getPermissionStr
  7177. // }
  7178. // if cv.Status == utils.COMPANY_STATUS_LOSE {
  7179. // permissionStr = ""
  7180. // }
  7181. // } else {
  7182. // industryName = industryName + "\n" + "权益:" + cv.IndustryName
  7183. // sellerName = sellerName + "\n" + "权益:" + cv.SellerName
  7184. // startDateStr := cv.StartDate.Format("2006/01/02")
  7185. // endDateStr := cv.EndDate.Format("2006/01/02")
  7186. //
  7187. // if startDateStr != "0001/01/01" {
  7188. // timeLimt = timeLimt + "\n" + "权益:" + startDateStr + "~" + endDateStr
  7189. // } else {
  7190. // timeLimt = timeLimt + ""
  7191. // }
  7192. // createTime = createTime + "\n" + "权益:" + cv.CreateTime
  7193. // source = source + "\n" + "权益:" + cv.Source
  7194. //
  7195. // permissionKey := strconv.Itoa(v.CompanyId) + "_" + strconv.Itoa(cv.ProductId)
  7196. // if permissionStr != "" {
  7197. // permissionStr = permissionStr + "\n" + "权益:"
  7198. // } else {
  7199. // permissionStr = "权益:"
  7200. // }
  7201. // if newPermissionStr, ok := permissionMap[permissionKey]; ok {
  7202. // permissionStr += newPermissionStr
  7203. // } else {
  7204. // getPermissionStr, err := company.GetExportPermissionName(v.CompanyId, cv.ProductId)
  7205. // if err != nil {
  7206. // br.Msg = "导出失败"
  7207. // br.ErrMsg = "获取客户权限信息失败,Err:" + err.Error()
  7208. // return
  7209. // }
  7210. // permissionMap[permissionKey] = getPermissionStr
  7211. // permissionStr += getPermissionStr
  7212. // }
  7213. // if cv.Status == utils.COMPANY_STATUS_LOSE {
  7214. // permissionStr = permissionStr + ""
  7215. // }
  7216. // }
  7217. // }
  7218. // dataRow.AddCell().SetString(companyName)
  7219. // dataRow.AddCell().SetString(creditCode)
  7220. // dataRow.AddCell().SetString(regionType)
  7221. //
  7222. // dataRow.AddCell().SetString(companyType)
  7223. // industryValueCell := dataRow.AddCell()
  7224. // industryValueCell.SetStyle(style)
  7225. // industryValueCell.SetString(industryName)
  7226. //
  7227. // sellerValueCell := dataRow.AddCell()
  7228. // sellerValueCell.SetStyle(style)
  7229. // sellerValueCell.SetString(sellerName)
  7230. //
  7231. // statusValueCell := dataRow.AddCell()
  7232. // statusValueCell.SetStyle(style)
  7233. // statusValueCell.SetValue(status)
  7234. //
  7235. // timeLimitValueCell := dataRow.AddCell()
  7236. // timeLimitValueCell.SetStyle(style)
  7237. // timeLimitValueCell.SetValue(timeLimt)
  7238. //
  7239. // createTimeValueCell := dataRow.AddCell()
  7240. // createTimeValueCell.SetStyle(style)
  7241. // createTimeValueCell.SetValue(createTime)
  7242. //
  7243. // sourceValueCell := dataRow.AddCell()
  7244. // sourceValueCell.SetStyle(style)
  7245. // sourceValueCell.SetValue(source)
  7246. //
  7247. // permissionStrValueCell := dataRow.AddCell()
  7248. // permissionStrValueCell.SetStyle(style)
  7249. // permissionStrValueCell.SetValue(permissionStr)
  7250. // }
  7251. // }
  7252. // err = xlsxFile.Save(downLoadnFilePath)
  7253. // if err != nil {
  7254. // br.Msg = "保存文件失败"
  7255. // br.ErrMsg = "保存文件失败"
  7256. // return
  7257. // }
  7258. // randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
  7259. // downloadFileName := "联系人列表" + randStr + ".xlsx"
  7260. // this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  7261. // defer func() {
  7262. // os.Remove(downLoadnFilePath)
  7263. // }()
  7264. // br.Ret = 200
  7265. // br.Success = true
  7266. // br.Msg = "导出成功"
  7267. //}
  7268. // @Title 冻结客户
  7269. // @Description 冻结客户接口
  7270. // @Param request body company.CompanyFreezeReq true "type json string"
  7271. // @Success Ret=200 冻结成功
  7272. // @router /freeze [post]
  7273. func (this *CompanyController) Freeze() {
  7274. br := new(models.BaseResponse).Init()
  7275. defer func() {
  7276. this.Data["json"] = br
  7277. this.ServeJSON()
  7278. }()
  7279. sysUser := this.SysUser
  7280. if sysUser == nil {
  7281. br.Msg = "请登录"
  7282. br.ErrMsg = "请登录,SysUser Is Empty"
  7283. br.Ret = 408
  7284. return
  7285. }
  7286. var req company.CompanyFreezeReq
  7287. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  7288. if err != nil {
  7289. br.Msg = "参数解析异常!"
  7290. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  7291. return
  7292. }
  7293. if req.CompanyId <= 0 {
  7294. br.Msg = "参数错误!"
  7295. br.ErrMsg = "客户id小于等于0"
  7296. return
  7297. }
  7298. productId := 0
  7299. productName := ""
  7300. if req.CompanyType == utils.COMPANY_CLASSIFY_FICC {
  7301. productId = 1
  7302. productName = "ficc"
  7303. } else if req.CompanyType == utils.COMPANY_CLASSIFY_RAI {
  7304. productId = 2
  7305. productName = "权益"
  7306. } else {
  7307. productId = 3
  7308. productName = "佣金客户"
  7309. }
  7310. if req.CompanyId <= 0 {
  7311. br.Msg = "参数异常!"
  7312. br.ErrMsg = "CompanyId:" + strconv.Itoa(req.CompanyId)
  7313. return
  7314. }
  7315. cp, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, productId)
  7316. if err != nil {
  7317. br.Msg = "查询该客户产品异常!"
  7318. br.ErrMsg = "查询该客户产品异常,err:" + err.Error()
  7319. return
  7320. }
  7321. if cp.Status != utils.COMPANY_STATUS_TRY_OUT {
  7322. br.Msg = "客户状态为:" + cp.Status + ";不可冻结"
  7323. br.ErrMsg = "客户状态为:" + cp.Status + ";不可冻结"
  7324. return
  7325. }
  7326. //查询客户的产品权限
  7327. companyReportPermissionList, err := company.GetCompanyReportPermission(req.CompanyId, productId)
  7328. if err != nil {
  7329. br.Msg = "查询客户的产品权限异常"
  7330. br.ErrMsg = "查询客户的产品权限异常:" + err.Error()
  7331. return
  7332. }
  7333. err = company.CompanyFreeze(req.CompanyId, productId, req.Remark)
  7334. if err != nil {
  7335. br.Msg = "冻结失败!"
  7336. br.ErrMsg = "冻结失败,Err:" + err.Error()
  7337. return
  7338. }
  7339. //新增操作记录
  7340. {
  7341. approveContent := req.Remark
  7342. remark := "冻结客户"
  7343. operation := "freeze"
  7344. services.AddCompanyOperationRecord(req.CompanyId, cp.SellerId, sysUser.AdminId, productId, sysUser.AdminId, cp.CompanyName,
  7345. productName, sysUser.RealName, remark, operation, approveContent, sysUser.RealName, "", "冻结")
  7346. //新增产品权限冻结操作日志
  7347. for _, companyReportPermission := range companyReportPermissionList {
  7348. record := company_report_permission_log.CompanyReportPermissionLog{
  7349. CompanyReportPermissionId: companyReportPermission.CompanyReportPermissionId,
  7350. CompanyId: companyReportPermission.CompanyId,
  7351. ProductId: productId,
  7352. ProductName: companyReportPermission.ProductName,
  7353. SysUserId: sysUser.AdminId,
  7354. SysUserName: sysUser.RealName,
  7355. Remark: "冻结客户",
  7356. Operation: "freeze",
  7357. Status: companyReportPermission.Status,
  7358. CreateTime: time.Now(),
  7359. }
  7360. _, err = company_report_permission_log.AddCompanyReportPermissionLog(&record)
  7361. }
  7362. }
  7363. br.Ret = 200
  7364. br.Success = true
  7365. br.Msg = "领取成功"
  7366. }
  7367. // @Title 获取客户权限
  7368. // @Description 获取客户权限接口
  7369. // @Param CompanyId query int true "用户id"
  7370. // @Success 200 {object} company.CompanyPermissionResp
  7371. // @router /getCompanyPermission [get]
  7372. func (this *CompanyController) PermissionList() {
  7373. br := new(models.BaseResponse).Init()
  7374. defer func() {
  7375. this.Data["json"] = br
  7376. this.ServeJSON()
  7377. }()
  7378. sysUser := this.SysUser
  7379. if sysUser == nil {
  7380. br.Msg = "请登录"
  7381. br.ErrMsg = "请登录,SysUser Is Empty"
  7382. br.Ret = 408
  7383. return
  7384. }
  7385. companyId, _ := this.GetInt("CompanyId")
  7386. if companyId <= 0 {
  7387. br.Msg = "参数错误"
  7388. br.ErrMsg = "客户参数小于等于0"
  7389. return
  7390. }
  7391. //返回基础参数
  7392. resp := new(company.CompanyPermissionResp)
  7393. //客户类型map
  7394. classifyMap := make(map[string]int)
  7395. classifyMap["ficc"] = 1
  7396. classifyMap["权益"] = 2
  7397. roleTypeCode := sysUser.RoleTypeCode
  7398. var companySlice []string
  7399. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN ||
  7400. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN ||
  7401. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER ||
  7402. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP ||
  7403. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_TEAM ||
  7404. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_DEPARTMENT ||
  7405. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_RESEARCHR {
  7406. companySlice = append(companySlice, "ficc")
  7407. } else if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN ||
  7408. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN ||
  7409. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER ||
  7410. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP ||
  7411. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_DEPARTMENT ||
  7412. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_RESEARCHR {
  7413. companySlice = append(companySlice, "权益")
  7414. }
  7415. for _, companyType := range companySlice {
  7416. //子权限切片集合
  7417. //var permissionClassifyArr []string
  7418. var permissionProductId int
  7419. if companyType == "ficc" {
  7420. permissionProductId = utils.COMPANY_PRODUCT_FICC_ID
  7421. } else {
  7422. permissionProductId = utils.COMPANY_PRODUCT_RAI_ID
  7423. }
  7424. //子权限切片集合
  7425. permissionClassifyArr, err := models.GetPermissionFirstByProductId(permissionProductId)
  7426. if err != nil {
  7427. br.Msg = "获取失败"
  7428. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  7429. return
  7430. }
  7431. //遍历获取
  7432. for _, v := range permissionClassifyArr {
  7433. checkList := make([]int, 0)
  7434. plist := new(company.PermissionLookList)
  7435. plist.Items = make([]*company.PermissionLookItem, 0)
  7436. items, err := company.GetPermissionLookItemsByParentId(classifyMap[companyType], v.ChartPermissionId)
  7437. if err != nil {
  7438. br.Msg = "获取失败"
  7439. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  7440. return
  7441. }
  7442. mapPermissionCheck := make(map[string]int)
  7443. for i, n := range items {
  7444. item := items[i]
  7445. count, err := company.GetCompanyPermissionCheck(companyId, n.ChartPermissionId)
  7446. if err != nil {
  7447. br.Msg = "获取失败"
  7448. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  7449. return
  7450. }
  7451. //合并主观客观勾选的权限
  7452. if count > 0 && mapPermissionCheck[n.PermissionName] == 0 {
  7453. checkList = append(checkList, n.ChartPermissionId)
  7454. mapPermissionCheck[n.PermissionName] = n.ChartPermissionId
  7455. }
  7456. permission, err := company.GetCompanyPermissionCheckItem(companyId, n.ChartPermissionId)
  7457. if err != nil && err.Error() != utils.ErrNoRow() {
  7458. br.Msg = "获取失败"
  7459. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  7460. return
  7461. }
  7462. if permission != nil && permission.ChartPermissionId > 0 {
  7463. items[i].StartDate = permission.StartDate
  7464. items[i].EndDate = permission.EndDate
  7465. items[i].Status = permission.Status
  7466. //判断主观、客观
  7467. if items[i].PermissionType == 1 {
  7468. items[i].PermissionTypeName = "主观"
  7469. } else if items[i].PermissionType == 2 {
  7470. items[i].PermissionTypeName = "客观"
  7471. }
  7472. }
  7473. endDateTime, _ := time.Parse(utils.FormatDate, item.EndDate)
  7474. endDateTime = endDateTime.AddDate(0, 0, 1)
  7475. sub := endDateTime.Sub(time.Now())
  7476. if sub < 0 {
  7477. sub = 0
  7478. }
  7479. expireDay := fmt.Sprintf("%v", int(sub.Hours()/24))
  7480. items[i].ExpireDay = expireDay
  7481. items[i].ClassifyName = v.PermissionName
  7482. //if n.PermissionType == 1 {
  7483. // items[i].PermissionTypeName = "主观"
  7484. //} else if n.PermissionType == 2 {
  7485. // items[i].PermissionTypeName = "客观"
  7486. //}
  7487. }
  7488. //合并主观客观
  7489. mapPermissionName := make(map[string]int)
  7490. for _, v := range items {
  7491. if mapPermissionName[v.PermissionName] == 0 {
  7492. //plist.Items = append(plist.Items, v)
  7493. //mapPermissionName[v.PermissionName] = v.ChartPermissionId
  7494. // CRM8.8-只有客观的时候回显
  7495. if mapPermissionCheck[v.PermissionName] == 0 || (mapPermissionCheck[v.PermissionName] > 0 && v.ChartPermissionId == mapPermissionCheck[v.PermissionName]) {
  7496. plist.Items = append(plist.Items, v)
  7497. mapPermissionName[v.PermissionName] = v.ChartPermissionId
  7498. }
  7499. }
  7500. }
  7501. plist.ClassifyName = v.PermissionName
  7502. plist.CheckList = checkList
  7503. if companyType == "ficc" {
  7504. resp.FiccPermissionList = append(resp.FiccPermissionList, plist)
  7505. } else {
  7506. resp.PermissionList = append(resp.PermissionList, plist)
  7507. }
  7508. }
  7509. }
  7510. br.Ret = 200
  7511. br.Success = true
  7512. br.Msg = "获取成功"
  7513. br.Data = resp
  7514. }
  7515. // @Title 获取客户来源列表
  7516. // @Description 获取客户来源列表
  7517. // @Success 200 {object} models.CompanySourceListResp
  7518. // @router /getCompanySourceList [get]
  7519. func (this *CompanyController) CompanySourceList() {
  7520. br := new(models.BaseResponse).Init()
  7521. defer func() {
  7522. this.Data["json"] = br
  7523. this.ServeJSON()
  7524. }()
  7525. sysUser := this.SysUser
  7526. if sysUser == nil {
  7527. br.Msg = "请登录"
  7528. br.ErrMsg = "请登录,SysUser Is Empty"
  7529. br.Ret = 408
  7530. return
  7531. }
  7532. list, err := models.GetAllCompanySourceList()
  7533. if err != nil {
  7534. br.Msg = "查询失败"
  7535. br.ErrMsg = "查询异常:" + err.Error()
  7536. return
  7537. }
  7538. br.Ret = 200
  7539. br.Success = true
  7540. br.Msg = "获取成功"
  7541. br.Data = models.CompanySourceListResp{
  7542. List: list,
  7543. }
  7544. }
  7545. // @Title 获取客户的合同列表
  7546. // @Description 获取客户合同列表接口
  7547. // @Param CompanyId query int true "用户id"
  7548. // @Param CompanyType query string false "用户类型:可取范围:ficc,权益"
  7549. // @Param Status query int true "合同审核结果,枚举值:`0`,`1`; 0:待审核,1:审核通过"
  7550. // @Success 200 {object} company.CompanyPermissionResp
  7551. // @router /getCompanyContract [get]
  7552. func (this *CompanyController) ContractList() {
  7553. br := new(models.BaseResponse).Init()
  7554. defer func() {
  7555. this.Data["json"] = br
  7556. this.ServeJSON()
  7557. }()
  7558. sysUser := this.SysUser
  7559. if sysUser == nil {
  7560. br.Msg = "请登录"
  7561. br.ErrMsg = "请登录,SysUser Is Empty"
  7562. br.Ret = 408
  7563. return
  7564. }
  7565. companyId, _ := this.GetInt("CompanyId")
  7566. if companyId <= 0 {
  7567. br.Msg = "参数错误"
  7568. br.ErrMsg = "客户参数小于等于0"
  7569. return
  7570. }
  7571. //合同状态
  7572. status, _ := this.GetInt("Status")
  7573. //产品类型
  7574. companyType := this.GetString("CompanyType")
  7575. var condition string
  7576. var pars []interface{}
  7577. //产品类型
  7578. if companyType == "" {
  7579. productId := services.GetProductId(sysUser.RoleTypeCode)
  7580. if productId != 0 {
  7581. condition += " AND product_id = ?"
  7582. pars = append(pars, productId)
  7583. }
  7584. } else {
  7585. if companyType == "ficc" {
  7586. condition += " AND product_id = ?"
  7587. pars = append(pars, 1)
  7588. } else {
  7589. condition += " AND product_id = ?"
  7590. pars = append(pars, 2)
  7591. }
  7592. }
  7593. if status != 0 {
  7594. condition += " AND status = ?"
  7595. pars = append(pars, status)
  7596. }
  7597. list, err := company.GetCompanyContractListByCompanyId(companyId, condition, pars)
  7598. if err != nil {
  7599. br.Msg = "查询失败"
  7600. br.ErrMsg = "查询异常:" + err.Error()
  7601. return
  7602. }
  7603. br.Ret = 200
  7604. br.Success = true
  7605. br.Msg = "获取成功"
  7606. br.Data = list
  7607. }
  7608. // @Title 获取客户所属销售
  7609. // @Description 根据客户id获取客户所属销售
  7610. // @Param CompanyId query int true "客户id"
  7611. // @Success 200 {object} response.CompanySellerListResp
  7612. // @router /getCompanySellerList [get]
  7613. func (this *CompanyUserController) GetCompanySellerList() {
  7614. br := new(models.BaseResponse).Init()
  7615. defer func() {
  7616. this.Data["json"] = br
  7617. this.ServeJSON()
  7618. }()
  7619. sysUser := this.SysUser
  7620. if sysUser == nil {
  7621. br.Msg = "请登录"
  7622. br.ErrMsg = "请登录,SysUser Is Empty"
  7623. br.Ret = 408
  7624. return
  7625. }
  7626. companyId, _ := this.GetInt("CompanyId")
  7627. //item := make([]*company.CompanyItem, 0)
  7628. list, err := company.GetCompanySellerByCompanyId(companyId)
  7629. if err != nil && err.Error() != utils.ErrNoRow() {
  7630. br.Msg = "获取失败"
  7631. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  7632. return
  7633. }
  7634. resp := response.CompanySellerListResp{
  7635. List: list,
  7636. }
  7637. //resp.List = list
  7638. br.Ret = 200
  7639. br.Success = true
  7640. br.Msg = "获取成功"
  7641. br.Data = resp
  7642. }
  7643. // GetTryOutCompanyList
  7644. // @Title 获取销售今日待办数据
  7645. // @Description 获取销售今日待办接口
  7646. // @Param CompanyName query string false "客户名称"
  7647. // @Param ReasonStatus query int false "续约情况说明状态:-1:未填写,0:全部,1:已填写"
  7648. // @Param PageSize query int true "每页数据条数"
  7649. // @Param CurrentIndex query int true "当前页页码,从1开始"
  7650. // @Success 200 {object} response.TryOutCompanyListResp
  7651. // @router /getTryOutCompanyList [get]
  7652. func (this *CompanyController) GetTryOutCompanyList() {
  7653. br := new(models.BaseResponse).Init()
  7654. defer func() {
  7655. this.Data["json"] = br
  7656. this.ServeJSON()
  7657. }()
  7658. sysUser := this.SysUser
  7659. if sysUser == nil {
  7660. br.Msg = "请登录"
  7661. br.ErrMsg = "请登录,SysUser Is Empty"
  7662. br.Ret = 408
  7663. return
  7664. }
  7665. companyName := this.GetString("CompanyName")
  7666. reasonStatus, _ := this.GetInt("ReasonStatus", 0)
  7667. pageSize, _ := this.GetInt("PageSize")
  7668. currentIndex, _ := this.GetInt("CurrentIndex")
  7669. productId := services.GetProductId(sysUser.RoleTypeCode)
  7670. var startSize int
  7671. if pageSize <= 0 {
  7672. pageSize = utils.PageSize20
  7673. }
  7674. if currentIndex <= 0 {
  7675. currentIndex = 1
  7676. }
  7677. startSize = paging.StartIndex(currentIndex, pageSize)
  7678. var condition string
  7679. var pars []interface{}
  7680. //sellerId, productId int, tryOutTime time.Time, tryOutReason string
  7681. var tryOutTime, lastDescriptionTime time.Time
  7682. if productId == 1 {
  7683. //ficc
  7684. interval := cache.GetIntervalFromCrmConfig("try_out_time_intervals")
  7685. tryOutTime = time.Now().AddDate(0, 0, -interval)
  7686. interval = cache.GetIntervalFromCrmConfig("last_description_time_intervals")
  7687. lastDescriptionTime = time.Now().AddDate(0, 0, -interval)
  7688. } else {
  7689. //权益
  7690. interval := cache.GetIntervalFromCrmConfig("rai_try_out_time_intervals")
  7691. tryOutTime = time.Now().AddDate(0, 0, -interval)
  7692. interval = cache.GetIntervalFromCrmConfig("rai_last_description_time_intervals")
  7693. lastDescriptionTime = time.Now().AddDate(0, 0, -interval)
  7694. }
  7695. if productId > 0 {
  7696. condition += ` and product_id=? `
  7697. pars = append(pars, productId)
  7698. }
  7699. //客户名称模糊搜索
  7700. if companyName != "" {
  7701. condition += ` and b.company_name like "%` + companyName + `%" `
  7702. }
  7703. //续约情况说明(-1:未填写,0:全部,1:已填写)
  7704. switch reasonStatus {
  7705. case -1:
  7706. 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) `
  7707. pars = append(pars, sysUser.AdminId, tryOutTime, lastDescriptionTime)
  7708. case 1:
  7709. 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) `
  7710. pars = append(pars, sysUser.AdminId, tryOutTime)
  7711. default:
  7712. 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) `
  7713. pars = append(pars, sysUser.AdminId, tryOutTime, lastDescriptionTime)
  7714. }
  7715. total := 0
  7716. list := make([]*company.TryOutCompanyList, 0)
  7717. 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}
  7718. if strings.Contains(strings.Join(ignoreStrs, ","), sysUser.RoleTypeCode) {
  7719. //排除已经签署续约合同的
  7720. notSql := ``
  7721. if productId > 0 {
  7722. notSql = fmt.Sprint(` and product_id = `, productId)
  7723. }
  7724. condition += `and a.company_id not in (select company_id from company_contract where contract_type ="续约合同" and start_date >now() and status = 1 ` + notSql + `) `
  7725. tmpTotal, err := company.GetTryOutCompanyCount(condition, pars)
  7726. if err != nil {
  7727. br.Msg = "获取失败"
  7728. br.ErrMsg = "获取总数失败失败,Err:" + err.Error()
  7729. return
  7730. }
  7731. tmpList, err := company.GetTryOutCompanyList(condition, pars, startSize, pageSize)
  7732. if err != nil {
  7733. br.Msg = "获取失败"
  7734. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  7735. return
  7736. }
  7737. total = tmpTotal
  7738. list = tmpList
  7739. }
  7740. if len(list) > 0 {
  7741. for k, item := range list {
  7742. endTime, _ := time.Parse(utils.FormatDate, item.EndDate)
  7743. endTime = endTime.AddDate(0, 0, 1)
  7744. sub := endTime.Sub(time.Now())
  7745. if sub < 0 {
  7746. sub = 0
  7747. }
  7748. list[k].ExpireDays = int(sub.Hours() / 24)
  7749. }
  7750. }
  7751. page := paging.GetPaging(currentIndex, pageSize, total)
  7752. resp := response.TryOutCompanyListResp{
  7753. List: list,
  7754. Paging: page,
  7755. }
  7756. br.Ret = 200
  7757. br.Success = true
  7758. br.Msg = "获取成功"
  7759. br.Data = resp
  7760. }
  7761. // EditTryOutCompanyReason
  7762. // @Title 编辑续约说明情况
  7763. // @Description 编辑续约说明情况接口
  7764. // @Param request body company.RenewalReasonReq true "type json string"
  7765. // @Success 200 编辑成功
  7766. // @router /editTryOutCompanyReason [post]
  7767. func (this *CompanyController) EditTryOutCompanyReason() {
  7768. br := new(models.BaseResponse).Init()
  7769. defer func() {
  7770. this.Data["json"] = br
  7771. this.ServeJSON()
  7772. }()
  7773. sysUser := this.SysUser
  7774. if sysUser == nil {
  7775. br.Msg = "请登录"
  7776. br.ErrMsg = "请登录,SysUser Is Empty"
  7777. br.Ret = 408
  7778. return
  7779. }
  7780. var req company.RenewalReasonReq
  7781. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  7782. if err != nil {
  7783. br.Msg = "参数解析异常!"
  7784. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  7785. return
  7786. }
  7787. if req.CompanyId <= 0 {
  7788. br.Msg = "参数缺失"
  7789. br.ErrMsg = "参数缺失,客户编号未传!"
  7790. return
  7791. }
  7792. if req.ProductId <= 0 {
  7793. br.Msg = "参数缺失"
  7794. br.ErrMsg = "参数缺失,产品编号未传!"
  7795. return
  7796. }
  7797. if req.Remark == "" {
  7798. br.Msg = "参数缺失"
  7799. br.ErrMsg = "参数缺失,续约情况说明未传!"
  7800. return
  7801. }
  7802. /*if req.RenewalTodo == "" && req.Renew == 0 {
  7803. br.Msg = "参数缺失"
  7804. br.ErrMsg = "参数缺失,待办事项说明未传!"
  7805. return
  7806. }*/
  7807. companyProduct, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, req.ProductId)
  7808. if err != nil {
  7809. br.Msg = "查询客户异常"
  7810. br.ErrMsg = "查询客户异常,Err:" + err.Error()
  7811. return
  7812. }
  7813. if companyProduct.SellerId != sysUser.AdminId {
  7814. br.Msg = "客户异常,没有该客户的操作权限"
  7815. br.ErrMsg = "客户异常,没有该客户的操作权限"
  7816. return
  7817. }
  7818. renewalReason := company.CompanyRenewalReason{
  7819. CompanyRenewalReasonId: 0,
  7820. CompanyId: companyProduct.CompanyId,
  7821. ProductId: companyProduct.ProductId,
  7822. ProductName: companyProduct.ProductName,
  7823. CompanyName: companyProduct.CompanyName,
  7824. TryOutTime: companyProduct.TryOutTime,
  7825. RenewalReason: req.Remark,
  7826. RenewalTodo: req.RenewalTodo,
  7827. LastDescriptionTime: companyProduct.LastDescriptionTime,
  7828. EndDays: companyProduct.ContractEndDate,
  7829. ExpirationTimeExceeded: 0,
  7830. RenewalIntention: req.Renew,
  7831. CreateTime: time.Now(),
  7832. }
  7833. endTime, err := company.GetTryOutTimeFromOperationRecord(renewalReason.CompanyId)
  7834. if err != nil {
  7835. br.Msg = "查询该客户转试用时间异常!"
  7836. br.ErrMsg = "查询该客户转试用时间异常,err:" + err.Error()
  7837. return
  7838. }
  7839. endDateTime, err := time.Parse(utils.FormatDateTime, *endTime)
  7840. if err != nil {
  7841. br.Msg = "时间格式化异常!"
  7842. br.ErrMsg = "时间格式化异常,err:" + err.Error()
  7843. return
  7844. }
  7845. endDate := endDateTime.Format(utils.FormatDate)
  7846. endDateTime, _ = time.Parse(utils.FormatDate, endDate)
  7847. sub := time.Now().Sub(endDateTime)
  7848. renewalReason.ExpirationTimeExceeded = int(sub.Hours() / 24)
  7849. var newId int64
  7850. newId, err = company.AddRenewalReason(&renewalReason)
  7851. if err != nil {
  7852. br.Msg = "新增续约情况说明操作异常!"
  7853. br.ErrMsg = "新增续约情况说明操作异常,err:" + err.Error()
  7854. return
  7855. }
  7856. companyProduct.RenewalIntention = req.Renew
  7857. err = company.EditTryOutCompanyReason(companyProduct, req.Remark, req.RenewalTodo)
  7858. if err != nil {
  7859. br.Msg = "更新客户未续约异常!"
  7860. br.ErrMsg = "更新客户未续约异常,err:" + err.Error()
  7861. return
  7862. }
  7863. if req.Renew == 1 {
  7864. productName := ""
  7865. if req.ProductId == 1 {
  7866. productName = "ficc"
  7867. } else if req.ProductId == 2 {
  7868. productName = "权益"
  7869. } else {
  7870. productName = "佣金客户"
  7871. }
  7872. cp, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, req.ProductId)
  7873. if err != nil {
  7874. br.Msg = "查询该客户产品异常!"
  7875. br.ErrMsg = "查询该客户产品异常,err:" + err.Error()
  7876. return
  7877. }
  7878. if cp.Status != utils.COMPANY_STATUS_TRY_OUT {
  7879. br.Msg = "客户状态为:" + cp.Status + ";不可冻结"
  7880. br.ErrMsg = "客户状态为:" + cp.Status + ";不可冻结"
  7881. return
  7882. }
  7883. //查询客户的产品权限
  7884. companyReportPermissionList, err := company.GetCompanyReportPermission(req.CompanyId, req.ProductId)
  7885. if err != nil {
  7886. br.Msg = "查询客户的产品权限异常"
  7887. br.ErrMsg = "查询客户的产品权限异常:" + err.Error()
  7888. return
  7889. }
  7890. err = company.CompanyFreeze(req.CompanyId, req.ProductId, req.Remark)
  7891. if err != nil {
  7892. br.Msg = "冻结失败!"
  7893. br.ErrMsg = "冻结失败,Err:" + err.Error()
  7894. return
  7895. }
  7896. //新增操作记录
  7897. go func() {
  7898. time.Sleep(time.Second)
  7899. approveContent := req.Remark
  7900. remark := "冻结客户"
  7901. operation := "freeze"
  7902. _ = services.AddCompanyOperationRecord(req.CompanyId, cp.SellerId, sysUser.AdminId, req.ProductId, sysUser.AdminId, cp.CompanyName,
  7903. productName, "超级管理员", remark, operation, approveContent, sysUser.RealName, "", "冻结")
  7904. //新增产品权限冻结操作日志
  7905. for _, companyReportPermission := range companyReportPermissionList {
  7906. record := company_report_permission_log.CompanyReportPermissionLog{
  7907. CompanyReportPermissionId: companyReportPermission.CompanyReportPermissionId,
  7908. CompanyId: companyReportPermission.CompanyId,
  7909. ProductId: req.ProductId,
  7910. ProductName: companyReportPermission.ProductName,
  7911. SysUserId: sysUser.AdminId,
  7912. SysUserName: "超级管理员",
  7913. Remark: "冻结客户",
  7914. Operation: "freeze",
  7915. Status: companyReportPermission.Status,
  7916. CreateTime: time.Now(),
  7917. }
  7918. _, err = company_report_permission_log.AddCompanyReportPermissionLog(&record)
  7919. }
  7920. }()
  7921. }
  7922. approveContent := req.Remark
  7923. approveContentExtra := req.RenewalTodo
  7924. remark := "新增续约说明"
  7925. operation := "edit_renewal_reason"
  7926. _ = services.AddCompanyOperationRecordMore(req.CompanyId, companyProduct.SellerId, sysUser.AdminId, companyProduct.ProductId, sysUser.AdminId, companyProduct.CompanyName,
  7927. companyProduct.ProductName, sysUser.RealName, remark, operation, approveContent, approveContentExtra, sysUser.RealName, "", companyProduct.Status)
  7928. items, err := company.ReadCompanyOperationRecord(req.CompanyId)
  7929. if err != nil {
  7930. br.Msg = "编辑失败"
  7931. br.ErrMsg = "编辑失败,Err:" + err.Error()
  7932. return
  7933. }
  7934. if len(items) > 0 {
  7935. record := new(company.CompanyOperationRecord)
  7936. record.Id = items[0].Id
  7937. record.ApproveContent = req.Remark
  7938. record.ApproveContentExtra = req.RenewalTodo
  7939. _, err = company.UpdateCompanyOperationRecord(record)
  7940. if err != nil {
  7941. br.Msg = "编辑失败"
  7942. br.ErrMsg = "编辑失败,Err:" + err.Error()
  7943. return
  7944. }
  7945. } else {
  7946. br.Msg = "编辑失败"
  7947. br.ErrMsg = "编辑失败,未查询到转试用记录"
  7948. return
  7949. }
  7950. if req.ProductId == utils.COMPANY_PRODUCT_RAI_ID {
  7951. //权益客户新增历史备注总表
  7952. itemRecord := new(company.CompanyHistoryRemark)
  7953. itemRecord.CompanyId = req.CompanyId
  7954. itemRecord.Content = req.Remark
  7955. itemRecord.SysAdminId = sysUser.AdminId
  7956. itemRecord.SysAdminName = sysUser.RealName
  7957. itemRecord.CreateTime = time.Now().Local()
  7958. itemRecord.ModifyTime = time.Now().Local()
  7959. itemRecord.ShowTime = time.Now().Local()
  7960. itemRecord.ProductId = 2
  7961. itemRecord.TableName = "company_renewal_reason"
  7962. itemRecord.TableId = int(newId)
  7963. go services.AddCompanyHistoryRemark(itemRecord)
  7964. }
  7965. br.Ret = 200
  7966. br.Success = true
  7967. br.Msg = "编辑成功"
  7968. }
  7969. // AddTryOutCompanyReason
  7970. // @Title 新增续约说明情况
  7971. // @Description 新增续约说明情况接口
  7972. // @Param request body company.RenewalReasonReq true "type json string"
  7973. // @Success 200 编辑成功
  7974. // @router /addTryOutCompanyReason [post]
  7975. func (this *CompanyController) AddTryOutCompanyReason() {
  7976. br := new(models.BaseResponse).Init()
  7977. defer func() {
  7978. this.Data["json"] = br
  7979. this.ServeJSON()
  7980. }()
  7981. sysUser := this.SysUser
  7982. if sysUser == nil {
  7983. br.Msg = "请登录"
  7984. br.ErrMsg = "请登录,SysUser Is Empty"
  7985. br.Ret = 408
  7986. return
  7987. }
  7988. var req company.RenewalReasonReq
  7989. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  7990. if err != nil {
  7991. br.Msg = "参数解析异常!"
  7992. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  7993. return
  7994. }
  7995. if req.CompanyId <= 0 {
  7996. br.Msg = "参数缺失"
  7997. br.ErrMsg = "参数缺失,客户编号未传!"
  7998. return
  7999. }
  8000. if req.ProductId <= 0 {
  8001. br.Msg = "参数缺失"
  8002. br.ErrMsg = "参数缺失,产品编号未传!"
  8003. return
  8004. }
  8005. if req.Remark == "" {
  8006. br.Msg = "参数缺失"
  8007. br.ErrMsg = "参数缺失,续约情况说明未传!"
  8008. return
  8009. }
  8010. if req.RenewalTodo == "" && req.Renew == 0 {
  8011. br.Msg = "参数缺失"
  8012. br.ErrMsg = "参数缺失,待办事项说明未传!"
  8013. return
  8014. }
  8015. companyProduct, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, req.ProductId)
  8016. if err != nil {
  8017. br.Msg = "查询客户异常"
  8018. br.ErrMsg = "查询客户异常,Err:" + err.Error()
  8019. return
  8020. }
  8021. if companyProduct.SellerId != sysUser.AdminId {
  8022. br.Msg = "客户异常,没有该客户的操作权限"
  8023. br.ErrMsg = "客户异常,没有该客户的操作权限"
  8024. return
  8025. }
  8026. renewalReason := company.CompanyRenewalReason{
  8027. CompanyRenewalReasonId: 0,
  8028. CompanyId: companyProduct.CompanyId,
  8029. ProductId: companyProduct.ProductId,
  8030. ProductName: companyProduct.ProductName,
  8031. CompanyName: companyProduct.CompanyName,
  8032. TryOutTime: companyProduct.TryOutTime,
  8033. RenewalReason: req.Remark,
  8034. RenewalTodo: req.RenewalTodo,
  8035. LastDescriptionTime: companyProduct.LastDescriptionTime,
  8036. EndDays: companyProduct.ContractEndDate,
  8037. ExpirationTimeExceeded: 0,
  8038. RenewalIntention: req.Renew,
  8039. CreateTime: time.Now(),
  8040. }
  8041. endTime, err := company.GetTryOutTimeFromOperationRecord(renewalReason.CompanyId)
  8042. if err != nil {
  8043. br.Msg = "查询该客户转试用时间异常!"
  8044. br.ErrMsg = "查询该客户转试用时间异常,err:" + err.Error()
  8045. return
  8046. }
  8047. endDateTime, err := time.Parse(utils.FormatDateTime, *endTime)
  8048. if err != nil {
  8049. br.Msg = "时间格式化异常!"
  8050. br.ErrMsg = "时间格式化异常,err:" + err.Error()
  8051. return
  8052. }
  8053. endDate := endDateTime.Format(utils.FormatDate)
  8054. endDateTime, _ = time.Parse(utils.FormatDate, endDate)
  8055. sub := time.Now().Sub(endDateTime)
  8056. renewalReason.ExpirationTimeExceeded = int(sub.Hours() / 24)
  8057. var newId int64
  8058. newId, err = company.AddRenewalReason(&renewalReason)
  8059. if err != nil {
  8060. br.Msg = "新增续约情况说明操作异常!"
  8061. br.ErrMsg = "新增续约情况说明操作异常,err:" + err.Error()
  8062. return
  8063. }
  8064. companyProduct.RenewalIntention = req.Renew
  8065. err = company.EditTryOutCompanyReason(companyProduct, req.Remark, req.RenewalTodo)
  8066. if err != nil {
  8067. br.Msg = "更新客户续约情况说明异常!"
  8068. br.ErrMsg = "更新客户续约情况说明异常,err:" + err.Error()
  8069. return
  8070. }
  8071. if req.Renew == 1 {
  8072. productName := ""
  8073. if req.ProductId == 1 {
  8074. productName = "ficc"
  8075. } else if req.ProductId == 2 {
  8076. productName = "权益"
  8077. } else {
  8078. productName = "佣金客户"
  8079. }
  8080. cp, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, req.ProductId)
  8081. if err != nil {
  8082. br.Msg = "查询该客户产品异常!"
  8083. br.ErrMsg = "查询该客户产品异常,err:" + err.Error()
  8084. return
  8085. }
  8086. if cp.Status != utils.COMPANY_STATUS_TRY_OUT {
  8087. br.Msg = "客户状态为:" + cp.Status + ";不可冻结"
  8088. br.ErrMsg = "客户状态为:" + cp.Status + ";不可冻结"
  8089. return
  8090. }
  8091. //查询客户的产品权限
  8092. companyReportPermissionList, err := company.GetCompanyReportPermission(req.CompanyId, req.ProductId)
  8093. if err != nil {
  8094. br.Msg = "查询客户的产品权限异常"
  8095. br.ErrMsg = "查询客户的产品权限异常:" + err.Error()
  8096. return
  8097. }
  8098. err = company.CompanyFreeze(req.CompanyId, req.ProductId, req.Remark)
  8099. if err != nil {
  8100. br.Msg = "冻结失败!"
  8101. br.ErrMsg = "冻结失败,Err:" + err.Error()
  8102. return
  8103. }
  8104. //新增操作记录
  8105. go func() {
  8106. time.Sleep(time.Second)
  8107. approveContent := req.Remark
  8108. remark := "冻结客户"
  8109. operation := "freeze"
  8110. _ = services.AddCompanyOperationRecord(req.CompanyId, cp.SellerId, sysUser.AdminId, req.ProductId, sysUser.AdminId, cp.CompanyName,
  8111. productName, "超级管理员", remark, operation, approveContent, sysUser.RealName, "", "冻结")
  8112. //新增产品权限冻结操作日志
  8113. for _, companyReportPermission := range companyReportPermissionList {
  8114. record := company_report_permission_log.CompanyReportPermissionLog{
  8115. CompanyReportPermissionId: companyReportPermission.CompanyReportPermissionId,
  8116. CompanyId: companyReportPermission.CompanyId,
  8117. ProductId: req.ProductId,
  8118. ProductName: companyReportPermission.ProductName,
  8119. SysUserId: sysUser.AdminId,
  8120. SysUserName: "超级管理员",
  8121. Remark: "冻结客户",
  8122. Operation: "freeze",
  8123. Status: companyReportPermission.Status,
  8124. CreateTime: time.Now(),
  8125. }
  8126. _, err = company_report_permission_log.AddCompanyReportPermissionLog(&record)
  8127. }
  8128. }()
  8129. }
  8130. {
  8131. approveContent := req.Remark
  8132. approveContentExtra := req.RenewalTodo
  8133. remark := "新增续约说明"
  8134. operation := "add_renewal_reason"
  8135. _ = services.AddCompanyOperationRecordMore(req.CompanyId, companyProduct.SellerId, sysUser.AdminId, companyProduct.ProductId, sysUser.AdminId, companyProduct.CompanyName,
  8136. companyProduct.ProductName, sysUser.RealName, remark, operation, approveContent, approveContentExtra, sysUser.RealName, "", companyProduct.Status)
  8137. }
  8138. if req.ProductId == utils.COMPANY_PRODUCT_RAI_ID {
  8139. //权益客户新增历史备注总表
  8140. itemRecord := new(company.CompanyHistoryRemark)
  8141. itemRecord.CompanyId = req.CompanyId
  8142. itemRecord.Content = req.Remark
  8143. itemRecord.SysAdminId = sysUser.AdminId
  8144. itemRecord.SysAdminName = sysUser.RealName
  8145. itemRecord.CreateTime = time.Now().Local()
  8146. itemRecord.ModifyTime = time.Now().Local()
  8147. itemRecord.ShowTime = time.Now().Local()
  8148. itemRecord.ProductId = 2
  8149. itemRecord.TableName = "company_renewal_reason"
  8150. itemRecord.TableId = int(newId)
  8151. go services.AddCompanyHistoryRemark(itemRecord)
  8152. }
  8153. br.Ret = 200
  8154. br.Success = true
  8155. br.Msg = "编辑成功"
  8156. }
  8157. // RenewReasonList 客户未续约说明历史列表
  8158. // @Title 客户未续约说明历史列表
  8159. // @Description 客户未续约说明历史列表
  8160. // @Param CompanyId query string true "客户id"
  8161. // @Param ProductId query string true "产品id"
  8162. // @Success 200 {object} response.RenewReasonItemResp
  8163. // @router /renewReasonList [get]
  8164. func (this *CompanyController) RenewReasonList() {
  8165. br := new(models.BaseResponse).Init()
  8166. defer func() {
  8167. this.Data["json"] = br
  8168. this.ServeJSON()
  8169. }()
  8170. sysUser := this.SysUser
  8171. if sysUser == nil {
  8172. br.Msg = "请登录"
  8173. br.ErrMsg = "请登录,SysUser Is Empty"
  8174. br.Ret = 408
  8175. return
  8176. }
  8177. CompanyId := this.GetString("CompanyId")
  8178. ProductId := this.GetString("ProductId")
  8179. if CompanyId == "" {
  8180. br.Msg = "请输入客户ID"
  8181. return
  8182. }
  8183. if ProductId != "1" && ProductId != "2" {
  8184. br.Msg = "请输入正确的产品ID"
  8185. return
  8186. }
  8187. renewalReason, err := models.GetMoreRenewalReason(CompanyId, ProductId)
  8188. if err != nil {
  8189. br.Msg = "获取失败"
  8190. br.ErrMsg = "获取失败,Err:" + err.Error()
  8191. return
  8192. }
  8193. resp := make([]response.RenewReasonItemResp, len(renewalReason))
  8194. for i, reason := range renewalReason {
  8195. createDate := reason.CreateTime.Format("2006.01.02 15:04:05")
  8196. resp[i].RenewalReason = reason.RenewalReason
  8197. resp[i].RenewalTodo = reason.RenewalTodo
  8198. resp[i].CreateTime = createDate
  8199. }
  8200. br.Ret = 200
  8201. br.Success = true
  8202. br.Msg = "获取成功"
  8203. br.Data = resp
  8204. }
  8205. // AddRenewalReason
  8206. // @Title 转试用按钮新增续约说明情况
  8207. // @Description 转试用按钮新增续约说明情况
  8208. // @Param request body company.TryOutReq true "type json string"
  8209. // @Success 200 编辑成功
  8210. // @router /addRenewalReason [post]
  8211. func (this *CompanyController) AddRenewalReason() {
  8212. br := new(models.BaseResponse).Init()
  8213. defer func() {
  8214. this.Data["json"] = br
  8215. this.ServeJSON()
  8216. }()
  8217. sysUser := this.SysUser
  8218. if sysUser == nil {
  8219. br.Msg = "请登录"
  8220. br.ErrMsg = "请登录,SysUser Is Empty"
  8221. br.Ret = 408
  8222. return
  8223. }
  8224. var req company.TryOutReq
  8225. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  8226. if err != nil {
  8227. br.Msg = "参数解析异常!"
  8228. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  8229. return
  8230. }
  8231. if req.CompanyId <= 0 {
  8232. br.Msg = "参数缺失"
  8233. br.ErrMsg = "参数缺失,客户编号未传!"
  8234. return
  8235. }
  8236. if req.ProductId <= 0 {
  8237. br.Msg = "参数缺失"
  8238. br.ErrMsg = "参数缺失,产品编号未传!"
  8239. return
  8240. }
  8241. if req.OperationId <= 0 {
  8242. br.Msg = "参数缺失"
  8243. br.ErrMsg = "参数缺失,操作记录表编号未传!"
  8244. return
  8245. }
  8246. if req.Remark == "" {
  8247. br.Msg = "参数缺失"
  8248. br.ErrMsg = "参数缺失,续约情况说明未传!"
  8249. return
  8250. }
  8251. if req.RenewalTodo == "" && req.Renew == 0 {
  8252. br.Msg = "参数缺失"
  8253. br.ErrMsg = "参数缺失,待办事项说明未传!"
  8254. return
  8255. }
  8256. companyProduct, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, req.ProductId)
  8257. if err != nil {
  8258. br.Msg = "查询客户异常"
  8259. br.ErrMsg = "查询客户异常,Err:" + err.Error()
  8260. return
  8261. }
  8262. if companyProduct.SellerId != sysUser.AdminId {
  8263. br.Msg = "客户异常,没有该客户的操作权限"
  8264. br.ErrMsg = "客户异常,没有该客户的操作权限"
  8265. return
  8266. }
  8267. renewalReason := company.CompanyRenewalReason{
  8268. CompanyRenewalReasonId: 0,
  8269. CompanyId: companyProduct.CompanyId,
  8270. ProductId: companyProduct.ProductId,
  8271. ProductName: companyProduct.ProductName,
  8272. CompanyName: companyProduct.CompanyName,
  8273. TryOutTime: companyProduct.TryOutTime,
  8274. RenewalReason: req.Remark,
  8275. RenewalTodo: req.RenewalTodo,
  8276. LastDescriptionTime: companyProduct.LastDescriptionTime,
  8277. EndDays: companyProduct.ContractEndDate,
  8278. ExpirationTimeExceeded: 0,
  8279. RenewalIntention: req.Renew,
  8280. CreateTime: time.Now(),
  8281. }
  8282. endTime, err := company.GetTryOutTimeFromOperationRecord(renewalReason.CompanyId)
  8283. if err != nil {
  8284. br.Msg = "查询该客户转试用时间异常!"
  8285. br.ErrMsg = "查询该客户转试用时间异常,err:" + err.Error()
  8286. return
  8287. }
  8288. endDateTime, err := time.Parse(utils.FormatDateTime, *endTime)
  8289. if err != nil {
  8290. br.Msg = "时间格式化异常!"
  8291. br.ErrMsg = "时间格式化异常,err:" + err.Error()
  8292. return
  8293. }
  8294. endDate := endDateTime.Format(utils.FormatDate)
  8295. endDateTime, _ = time.Parse(utils.FormatDate, endDate)
  8296. sub := time.Now().Sub(endDateTime)
  8297. renewalReason.ExpirationTimeExceeded = int(sub.Hours() / 24)
  8298. var newId int64
  8299. newId, err = company.AddRenewalReason(&renewalReason)
  8300. if err != nil {
  8301. br.Msg = "新增续约情况说明操作异常!"
  8302. br.ErrMsg = "新增续约情况说明操作异常,err:" + err.Error()
  8303. return
  8304. }
  8305. companyProduct.RenewalIntention = req.Renew
  8306. err = company.EditTryOutCompanyReason(companyProduct, req.Remark, req.RenewalTodo)
  8307. if err != nil {
  8308. br.Msg = "更新客户续约情况说明异常!"
  8309. br.ErrMsg = "更新客户续约情况说明异常,err:" + err.Error()
  8310. return
  8311. }
  8312. if req.Renew == 1 {
  8313. productName := ""
  8314. if req.ProductId == 1 {
  8315. productName = "ficc"
  8316. } else if req.ProductId == 2 {
  8317. productName = "权益"
  8318. } else {
  8319. productName = "佣金客户"
  8320. }
  8321. cp, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, req.ProductId)
  8322. if err != nil {
  8323. br.Msg = "查询该客户产品异常!"
  8324. br.ErrMsg = "查询该客户产品异常,err:" + err.Error()
  8325. return
  8326. }
  8327. if cp.Status != utils.COMPANY_STATUS_TRY_OUT {
  8328. br.Msg = "客户状态为:" + cp.Status + ";不可冻结"
  8329. br.ErrMsg = "客户状态为:" + cp.Status + ";不可冻结"
  8330. return
  8331. }
  8332. //查询客户的产品权限
  8333. companyReportPermissionList, err := company.GetCompanyReportPermission(req.CompanyId, req.ProductId)
  8334. if err != nil {
  8335. br.Msg = "查询客户的产品权限异常"
  8336. br.ErrMsg = "查询客户的产品权限异常:" + err.Error()
  8337. return
  8338. }
  8339. err = company.CompanyFreeze(req.CompanyId, req.ProductId, req.Remark)
  8340. if err != nil {
  8341. br.Msg = "冻结失败!"
  8342. br.ErrMsg = "冻结失败,Err:" + err.Error()
  8343. return
  8344. }
  8345. //新增操作记录
  8346. go func() {
  8347. time.Sleep(time.Second)
  8348. approveContent := req.Remark
  8349. remark := "冻结客户"
  8350. operation := "freeze"
  8351. _ = services.AddCompanyOperationRecord(req.CompanyId, cp.SellerId, sysUser.AdminId, req.ProductId, sysUser.AdminId, cp.CompanyName,
  8352. productName, "超级管理员", remark, operation, approveContent, sysUser.RealName, "", "冻结")
  8353. //新增产品权限冻结操作日志
  8354. for _, companyReportPermission := range companyReportPermissionList {
  8355. record := company_report_permission_log.CompanyReportPermissionLog{
  8356. CompanyReportPermissionId: companyReportPermission.CompanyReportPermissionId,
  8357. CompanyId: companyReportPermission.CompanyId,
  8358. ProductId: req.ProductId,
  8359. ProductName: companyReportPermission.ProductName,
  8360. SysUserId: sysUser.AdminId,
  8361. SysUserName: "超级管理员",
  8362. Remark: "冻结客户",
  8363. Operation: "freeze",
  8364. Status: companyReportPermission.Status,
  8365. CreateTime: time.Now(),
  8366. }
  8367. _, err = company_report_permission_log.AddCompanyReportPermissionLog(&record)
  8368. }
  8369. }()
  8370. }
  8371. {
  8372. approveContent := req.Remark
  8373. approveContentExtra := req.RenewalTodo
  8374. remark := "新增续约说明"
  8375. operation := "add_try_out_reason"
  8376. _ = services.AddCompanyOperationRecordMore(req.CompanyId, companyProduct.SellerId, sysUser.AdminId, companyProduct.ProductId, sysUser.AdminId, companyProduct.CompanyName,
  8377. companyProduct.ProductName, sysUser.RealName, remark, operation, approveContent, approveContentExtra, sysUser.RealName, "", companyProduct.Status)
  8378. record := new(company.CompanyOperationRecord)
  8379. record.Id = req.OperationId
  8380. record.ApproveContent = req.Remark
  8381. record.ApproveContentExtra = req.RenewalTodo
  8382. _, err = company.UpdateCompanyOperationRecord(record)
  8383. if err != nil {
  8384. br.Msg = "编辑失败"
  8385. br.ErrMsg = "编辑失败,Err:" + err.Error()
  8386. return
  8387. }
  8388. }
  8389. if req.ProductId == utils.COMPANY_PRODUCT_RAI_ID {
  8390. //权益客户新增历史备注总表
  8391. itemRecord := new(company.CompanyHistoryRemark)
  8392. itemRecord.CompanyId = req.CompanyId
  8393. itemRecord.Content = req.Remark
  8394. itemRecord.SysAdminId = sysUser.AdminId
  8395. itemRecord.SysAdminName = sysUser.RealName
  8396. itemRecord.CreateTime = time.Now().Local()
  8397. itemRecord.ModifyTime = time.Now().Local()
  8398. itemRecord.ShowTime = time.Now().Local()
  8399. itemRecord.ProductId = 2
  8400. itemRecord.TableName = "company_renewal_reason"
  8401. itemRecord.TableId = int(newId)
  8402. go services.AddCompanyHistoryRemark(itemRecord)
  8403. }
  8404. br.Ret = 200
  8405. br.Success = true
  8406. br.Msg = "编辑成功"
  8407. }
  8408. // AddRemark
  8409. // @Title 新增备注
  8410. // @Description 新增备注
  8411. // @Param request body company.RemarkReq true "type json string"
  8412. // @Success 200 编辑成功
  8413. // @router /remark/add [post]
  8414. func (this *CompanyController) AddRemark() {
  8415. br := new(models.BaseResponse).Init()
  8416. defer func() {
  8417. this.Data["json"] = br
  8418. this.ServeJSON()
  8419. }()
  8420. sysUser := this.SysUser
  8421. if sysUser == nil {
  8422. br.Msg = "请登录"
  8423. br.ErrMsg = "请登录,SysUser Is Empty"
  8424. br.Ret = 408
  8425. return
  8426. }
  8427. var req company.RemarkReq
  8428. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  8429. if err != nil {
  8430. br.Msg = "参数解析异常!"
  8431. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  8432. return
  8433. }
  8434. if req.CompanyId <= 0 {
  8435. br.Msg = "参数缺失"
  8436. br.ErrMsg = "参数缺失,客户编号未传!"
  8437. return
  8438. }
  8439. if req.Remark == "" {
  8440. br.Msg = "参数缺失"
  8441. br.ErrMsg = "参数缺失,备注说明未传!"
  8442. return
  8443. }
  8444. var productId int
  8445. //var productName string
  8446. 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 {
  8447. productId = 1
  8448. //productName = "ficc"
  8449. } 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 {
  8450. productId = 2
  8451. //productName = "权益"
  8452. } else {
  8453. br.Msg = "角色类型错误"
  8454. br.ErrMsg = "角色类型错误,该角色不能添加备注!"
  8455. return
  8456. }
  8457. companyProduct, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, productId)
  8458. if err != nil {
  8459. br.Msg = "查询客户异常"
  8460. br.ErrMsg = "查询客户异常,Err:" + err.Error()
  8461. }
  8462. if companyProduct.SellerId != sysUser.AdminId {
  8463. br.Msg = "客户异常,没有该客户的操作权限"
  8464. br.ErrMsg = "客户异常,没有该客户的操作权限"
  8465. return
  8466. }
  8467. remark := company.CompanyProductRemark{
  8468. CompanyId: companyProduct.CompanyId,
  8469. ProductId: companyProduct.ProductId,
  8470. ProductName: companyProduct.ProductName,
  8471. Remark: req.Remark,
  8472. CreateTime: time.Now(),
  8473. SysUserId: sysUser.AdminId,
  8474. SysRealName: sysUser.RealName,
  8475. }
  8476. var newId int64
  8477. newId, err = company.AddCompanyRemark(&remark)
  8478. {
  8479. approveContent := req.Remark
  8480. remark := "新增备注"
  8481. operation := "add_remark"
  8482. services.AddCompanyOperationRecord(req.CompanyId, companyProduct.SellerId, sysUser.AdminId, companyProduct.ProductId, sysUser.AdminId, companyProduct.CompanyName,
  8483. companyProduct.ProductName, sysUser.RealName, remark, operation, approveContent, sysUser.RealName, "", companyProduct.Status)
  8484. }
  8485. if err != nil {
  8486. br.Msg = "编辑失败"
  8487. br.ErrMsg = "编辑失败,Err:" + err.Error()
  8488. }
  8489. //如果是权益的写入历史备注表
  8490. if productId == utils.COMPANY_PRODUCT_RAI_ID {
  8491. //权益客户新增历史备注总表
  8492. itemRecord := new(company.CompanyHistoryRemark)
  8493. itemRecord.CompanyId = req.CompanyId
  8494. itemRecord.Content = req.Remark
  8495. itemRecord.SysAdminId = sysUser.AdminId
  8496. itemRecord.SysAdminName = sysUser.RealName
  8497. itemRecord.CreateTime = time.Now().Local()
  8498. itemRecord.ModifyTime = time.Now().Local()
  8499. itemRecord.ShowTime = time.Now().Local()
  8500. itemRecord.ProductId = 2
  8501. itemRecord.TableName = "company_product_remark"
  8502. itemRecord.TableId = int(newId)
  8503. go services.AddCompanyHistoryRemark(itemRecord)
  8504. }
  8505. br.Ret = 200
  8506. br.Success = true
  8507. br.Msg = "编辑成功"
  8508. }
  8509. // RemarkList 备注列表
  8510. // @Title 备注列表
  8511. // @Description 备注列表
  8512. // @Param CompanyId query string true "客户id"
  8513. // @Success 200 {object} company.RemarkResp
  8514. // @router /remark [get]
  8515. func (this *CompanyController) RemarkList() {
  8516. br := new(models.BaseResponse).Init()
  8517. defer func() {
  8518. this.Data["json"] = br
  8519. this.ServeJSON()
  8520. }()
  8521. sysUser := this.SysUser
  8522. if sysUser == nil {
  8523. br.Msg = "请登录"
  8524. br.ErrMsg = "请登录,SysUser Is Empty"
  8525. br.Ret = 408
  8526. return
  8527. }
  8528. companyId := this.GetString("CompanyId")
  8529. var remarkList []*company.CompanyProductRemark
  8530. var err error
  8531. groupFicc := []string{
  8532. utils.ROLE_TYPE_CODE_FICC_SELLER, utils.ROLE_TYPE_CODE_FICC_TEAM, utils.ROLE_TYPE_CODE_FICC_GROUP,
  8533. utils.ROLE_TYPE_CODE_FICC_DEPARTMENT, utils.ROLE_TYPE_CODE_FICC_ADMIN,
  8534. }
  8535. groupRai := []string{
  8536. utils.ROLE_TYPE_CODE_RAI_SELLER, utils.ROLE_TYPE_CODE_RAI_GROUP, utils.ROLE_TYPE_CODE_RAI_GROUP,
  8537. utils.ROLE_TYPE_CODE_RAI_DEPARTMENT, utils.ROLE_TYPE_CODE_RAI_ADMIN,
  8538. }
  8539. if utils.InArrayByStr(groupFicc, sysUser.RoleTypeCode) {
  8540. remarkList, err = company.GetRemarkList(companyId, "1")
  8541. if err != nil {
  8542. br.Msg = "获取失败"
  8543. br.ErrMsg = "获取失败,Err:" + err.Error()
  8544. return
  8545. }
  8546. }
  8547. if utils.InArrayByStr(groupRai, sysUser.RoleTypeCode) {
  8548. remarkList, err = company.GetRemarkList(companyId, "2")
  8549. if err != nil {
  8550. br.Msg = "获取失败"
  8551. br.ErrMsg = "获取失败,Err:" + err.Error()
  8552. return
  8553. }
  8554. }
  8555. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  8556. remarkList, err = company.GetRemarkListByCompanyId(companyId)
  8557. if err != nil {
  8558. br.Msg = "获取失败"
  8559. br.ErrMsg = "获取失败,Err:" + err.Error()
  8560. return
  8561. }
  8562. }
  8563. resp := make([]company.RemarkResp, len(remarkList))
  8564. for i, remark := range remarkList {
  8565. createDate := remark.CreateTime.Format(utils.FormatDateTime)
  8566. resp[i].RemarkId = remark.CompanyProductRemarkId
  8567. resp[i].Remark = remark.Remark
  8568. resp[i].ProductName = remark.ProductName
  8569. resp[i].CreateTime = createDate
  8570. // 仅自己添加的可删除
  8571. if remark.SysUserId == sysUser.AdminId {
  8572. resp[i].ButtonDel = true
  8573. }
  8574. }
  8575. br.Ret = 200
  8576. br.Success = true
  8577. br.Msg = "获取成功"
  8578. br.Data = resp
  8579. }
  8580. // RoadShowList 客户列表的路演详情列表
  8581. // @Title 路演详情列表
  8582. // @Description 路演详情列表
  8583. // @Param CompanyId query string true "客户id"
  8584. // @Success 200 {object} company.RoadShowListResp
  8585. // @router /roadShowList [get]
  8586. func (this *CompanyController) RoadShowList() {
  8587. br := new(models.BaseResponse).Init()
  8588. defer func() {
  8589. this.Data["json"] = br
  8590. this.ServeJSON()
  8591. }()
  8592. sysUser := this.SysUser
  8593. if sysUser == nil {
  8594. br.Msg = "请登录"
  8595. br.ErrMsg = "请登录,SysUser Is Empty"
  8596. br.Ret = 408
  8597. return
  8598. }
  8599. companyId := this.GetString("CompanyId")
  8600. companyIdInt, _ := strconv.Atoi(companyId)
  8601. if companyIdInt <= 0 {
  8602. br.Msg = "参数错误"
  8603. return
  8604. }
  8605. var englishCompany int
  8606. if companyIdInt > utils.EnCompanyIdStep {
  8607. companyIdInt = companyIdInt - utils.EnCompanyIdStep
  8608. englishCompany = 1
  8609. }
  8610. var err error
  8611. roadShowList, err := company.GetRoadShowList(companyIdInt, englishCompany)
  8612. if err != nil {
  8613. br.Msg = "获取失败"
  8614. br.ErrMsg = "获取失败,Err:" + err.Error()
  8615. return
  8616. }
  8617. //calendarIdSlice := make([]string, 0)
  8618. //for _, v := range roadShowList {
  8619. // calendarIdSlice = append(calendarIdSlice, strconv.Itoa(v.RsCalendarId))
  8620. //}
  8621. //calendarIdStr := strings.Join(calendarIdSlice, ",")
  8622. //researcherList, _ := company.GetRoadShowResearchers(calendarIdStr)
  8623. //roadShowTotalMap := make(map[int]int)
  8624. //for _, roadShowTotal := range researcherList {
  8625. // roadShowTotalMap[roadShowTotal.CompanyId] = roadShowTotal.Total
  8626. //}
  8627. resp := make([]company.RoadShowListResp, len(roadShowList))
  8628. for i, calendar := range roadShowList {
  8629. resp[i].SysUserRealName = calendar.SysUserRealName
  8630. resp[i].RoadshowType = calendar.RoadshowType
  8631. //线上为平台,线下为省市
  8632. if calendar.RoadshowType == "线上" {
  8633. resp[i].RoadshowPlatform = calendar.RoadshowPlatform
  8634. } else {
  8635. resp[i].RoadshowPlatform = calendar.Province + calendar.City
  8636. }
  8637. researchers, err := company.GetRoadShowResearchers(calendar.RsCalendarId)
  8638. if err != nil && err.Error() != utils.ErrNoRow() {
  8639. br.Msg = "获取研究员信息失败"
  8640. br.ErrMsg = "获取研究员信息失败,Err:" + err.Error()
  8641. return
  8642. }
  8643. var researcherList []string
  8644. for _, researcher := range researchers {
  8645. researcherList = append(researcherList, *researcher)
  8646. }
  8647. researcher := strings.Join(researcherList, ",")
  8648. resp[i].Researchers = researcher
  8649. resp[i].RoadShowTime = calendar.EndDate.Format("2006.01.02")
  8650. }
  8651. br.Ret = 200
  8652. br.Success = true
  8653. br.Msg = "获取成功"
  8654. br.Data = resp
  8655. }
  8656. // CustomerAreaStatistics
  8657. // @Title 客户区域统计
  8658. // @Description 获取客户区域统计接口
  8659. // @Param Date query string true "日期"
  8660. // @Param ProductId query Int true "产品Id"
  8661. // @Success 200 {object} statistic_report.CompanyRenewRecordResp
  8662. // @router /customerAreaStatistics [get]
  8663. func (this *CompanyController) CustomerAreaStatistics() {
  8664. br := new(models.BaseResponse).Init()
  8665. defer func() {
  8666. this.Data["json"] = br
  8667. this.ServeJSON()
  8668. }()
  8669. sysUser := this.SysUser
  8670. if sysUser == nil {
  8671. br.Msg = "请登录"
  8672. br.ErrMsg = "请登录,SysUser Is Empty"
  8673. br.Ret = 408
  8674. return
  8675. }
  8676. date := this.GetString("Date")
  8677. productId, _ := this.GetInt("ProductId", 1)
  8678. //获取列表
  8679. companyAreaDataMapList, _, err := statistic_report.GetAreaDateData(date, productId)
  8680. if err != nil {
  8681. br.Msg = "数据异常"
  8682. br.ErrMsg = "数据异常,Err:" + err.Error()
  8683. return
  8684. }
  8685. //获取省市数据
  8686. areaMap := make(map[string]string)
  8687. provinceMap := make(map[string][]string, 0)
  8688. list, err := statisticModels.GetAllCompanyArea()
  8689. for _, item := range list {
  8690. areaMap[item.City] = item.Province
  8691. }
  8692. for c, p := range areaMap {
  8693. citySlice := make([]string, 0)
  8694. citySlice = provinceMap[p]
  8695. citySlice = append(citySlice, c)
  8696. provinceMap[p] = citySlice
  8697. }
  8698. //数据处理
  8699. groupReportRecordList := make([]statistic_report.GroupCityRecord, 0)
  8700. resp := statistic_report.CustomerAreaStatisticsResp{
  8701. List: groupReportRecordList,
  8702. IsAdmin: false,
  8703. }
  8704. //除ficc管理员和超管之外的角色进入此页面时,正式客户数量>0时可点击,点击查看正式客户列表详情;
  8705. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  8706. resp.IsAdmin = true
  8707. }
  8708. startDateIndexList := make(map[int]string) //开始时间间隔map
  8709. endDateIndexList := make(map[int]string) //结束时间间隔map
  8710. tmpAllTryOutNumMap := make(map[int]int)
  8711. tmpAllFormalNumMap := make(map[int]int)
  8712. tmpAllActiveNumMap := make(map[int]int)
  8713. tmpAllAllActiveNumMap := make(map[int]int)
  8714. tmpAllNoIncrementalActiveNumMap := make(map[int]int)
  8715. tmpAllTryStagePushMap := make(map[int]int)
  8716. tmpAllTryStageFollowMap := make(map[int]int)
  8717. tmpAllTryStageReadyMap := make(map[int]int)
  8718. tmpAllTryStageInitMap := make(map[int]int)
  8719. for province, cityList := range provinceMap {
  8720. tmpGroupCityReportRecord := make([]statistic_report.CityRecord, 0)
  8721. tmpGroupCompanyReportRecordNumList := make([]statistic_report.CompanyAreaNum, 0)
  8722. tmpGroupTryOutNumMap := make(map[int]int)
  8723. tmpGroupFormalNumMap := make(map[int]int)
  8724. tmpGroupFormalCompanyIdsMap := make(map[int]string) //正式客户id
  8725. tmpGroupActiveNumMap := make(map[int]int)
  8726. tmpGroupAllActiveNumMap := make(map[int]int)
  8727. tmpGroupNoIncrementalActiveNumMap := make(map[int]int)
  8728. // 其他类型客户ID
  8729. tmpGroupTryOutCompanyIdsMap := make(map[int]string) //试用客户ID
  8730. tmpGroupPushCompanyIdsMap := make(map[int]string) //试用(推进)客户ID
  8731. tmpGroupFollowCompanyIdsMap := make(map[int]string) //试用(跟踪)客户ID
  8732. tmpGroupReadyCompanyIdsMap := make(map[int]string) //试用(预备)客户ID
  8733. tmpGroupInitCompanyIdsMap := make(map[int]string) //试用(未分类)客户ID
  8734. tmpGroupTryStagePushMap := make(map[int]int)
  8735. tmpGroupTryStageFollowMap := make(map[int]int)
  8736. tmpGroupTryStageReadyMap := make(map[int]int)
  8737. tmpGroupTryStageInitMap := make(map[int]int)
  8738. for _, city := range cityList {
  8739. //城市数据
  8740. //每个城市的数据
  8741. tmpCompanyReportRecordNumList := make([]statistic_report.CompanyAreaNum, 0)
  8742. for index, adminData := range companyAreaDataMapList {
  8743. startDateIndexList[index] = adminData.StartDate
  8744. endDateIndexList[index] = adminData.EndDate
  8745. var tmpTryOutNum, tmpFormalNum, tmpActiveStatus, tmpAllActiveStatus, tmpNoIncrementalActiveStatus int
  8746. var tmpTryStagePushNum, tmpTryStageFollowNum, tmpTryStageReadyNum, tmpTryStageInitNum int
  8747. var tmpFormalCompanyIds string //正式客户id集合
  8748. var tmpTryOutCompanyIds string //试用客户ID集合
  8749. var tmpPushCompanyIds string //试用(推进)客户ID集合
  8750. var tmpFollowCompanyIds string //试用(跟踪)客户ID集合
  8751. var tmpReadyCompanyIds string //试用(预备)客户ID集合
  8752. var tmpInitCompanyIds string //试用(未分类)客户ID集合
  8753. if num, ok := adminData.TryOutMap[city]; ok {
  8754. tmpTryOutNum = num
  8755. }
  8756. if num, ok := adminData.FormalMap[city]; ok {
  8757. tmpFormalNum = num
  8758. }
  8759. if companyIds, ok := adminData.FormalIdMap[city]; ok {
  8760. tmpFormalCompanyIds = companyIds
  8761. }
  8762. if companyIds, ok := adminData.TryOutIdMap[city]; ok {
  8763. tmpTryOutCompanyIds = companyIds
  8764. }
  8765. if companyIds, ok := adminData.TryStagePushIdsMap[city]; ok {
  8766. tmpPushCompanyIds = companyIds
  8767. }
  8768. if companyIds, ok := adminData.TryStageFollowIdsMap[city]; ok {
  8769. tmpFollowCompanyIds = companyIds
  8770. }
  8771. if companyIds, ok := adminData.TryStageReadyIdsMap[city]; ok {
  8772. tmpReadyCompanyIds = companyIds
  8773. }
  8774. if companyIds, ok := adminData.TryStageInitIdsMap[city]; ok {
  8775. tmpInitCompanyIds = companyIds
  8776. }
  8777. if num, ok := adminData.ActiveMap[city]; ok {
  8778. tmpActiveStatus = num
  8779. }
  8780. if num, ok := adminData.AllActiveMap[city]; ok {
  8781. tmpAllActiveStatus = num
  8782. }
  8783. if num, ok := adminData.NoIncrementalActiveMap[city]; ok {
  8784. tmpNoIncrementalActiveStatus = num
  8785. }
  8786. // 每个用户的试用标签统计 推进-跟踪-预备-未分类
  8787. if num, ok := adminData.TryStagePushNum[city]; ok {
  8788. tmpTryStagePushNum = num
  8789. }
  8790. if num, ok := adminData.TryStageFollowNum[city]; ok {
  8791. tmpTryStageFollowNum = num
  8792. }
  8793. if num, ok := adminData.TryStageReadyNum[city]; ok {
  8794. tmpTryStageReadyNum = num
  8795. }
  8796. if num, ok := adminData.TryStageInitNum[city]; ok {
  8797. tmpTryStageInitNum = num
  8798. }
  8799. tmpAdminRsReportRecordNum := statistic_report.CompanyAreaNum{
  8800. TryOutNum: tmpTryOutNum,
  8801. FormalNum: tmpFormalNum,
  8802. FormalIds: tmpFormalCompanyIds,
  8803. ActiveNum: tmpActiveStatus,
  8804. AllActiveNum: tmpAllActiveStatus,
  8805. NoIncrementalActiveNum: tmpNoIncrementalActiveStatus,
  8806. StartDate: adminData.StartDate,
  8807. EndDate: adminData.EndDate,
  8808. TryStagePushNum: tmpTryStagePushNum,
  8809. TryStageFollowNum: tmpTryStageFollowNum,
  8810. TryStageReadyNum: tmpTryStageReadyNum,
  8811. TryStageInitNum: tmpTryStageInitNum,
  8812. TotalNum: tmpTryOutNum + tmpFormalNum,
  8813. }
  8814. tmpCompanyReportRecordNumList = append(tmpCompanyReportRecordNumList, tmpAdminRsReportRecordNum)
  8815. //组内数据汇总
  8816. tmpGroupTryOutNumMap[index] += tmpTryOutNum
  8817. tmpGroupFormalNumMap[index] += tmpFormalNum
  8818. // 正式客户id
  8819. if tmpFormalCompanyIds != `` {
  8820. tmpGroupFormalCompanyIds, ok := tmpGroupFormalCompanyIdsMap[index]
  8821. if ok {
  8822. tmpGroupFormalCompanyIdsMap[index] = tmpGroupFormalCompanyIds + "," + tmpFormalCompanyIds
  8823. } else {
  8824. tmpGroupFormalCompanyIdsMap[index] = tmpFormalCompanyIds
  8825. }
  8826. }
  8827. tmpGroupActiveNumMap[index] += tmpActiveStatus
  8828. tmpGroupAllActiveNumMap[index] += tmpActiveStatus
  8829. tmpGroupNoIncrementalActiveNumMap[index] += tmpActiveStatus
  8830. tmpGroupTryStagePushMap[index] += tmpTryStagePushNum
  8831. tmpGroupTryStageFollowMap[index] += tmpTryStageFollowNum
  8832. tmpGroupTryStageReadyMap[index] += tmpTryStageReadyNum
  8833. tmpGroupTryStageInitMap[index] += tmpTryStageInitNum
  8834. // 其他客户IDs
  8835. if tmpTryOutCompanyIds != `` {
  8836. a, ok := tmpGroupTryOutCompanyIdsMap[index]
  8837. if ok {
  8838. tmpGroupTryOutCompanyIdsMap[index] = a + "," + tmpTryOutCompanyIds
  8839. } else {
  8840. tmpGroupTryOutCompanyIdsMap[index] = tmpTryOutCompanyIds
  8841. }
  8842. }
  8843. if tmpPushCompanyIds != `` {
  8844. a, ok := tmpGroupPushCompanyIdsMap[index]
  8845. if ok {
  8846. tmpGroupPushCompanyIdsMap[index] = a + "," + tmpPushCompanyIds
  8847. } else {
  8848. tmpGroupPushCompanyIdsMap[index] = tmpPushCompanyIds
  8849. }
  8850. }
  8851. if tmpFollowCompanyIds != `` {
  8852. a, ok := tmpGroupFollowCompanyIdsMap[index]
  8853. if ok {
  8854. tmpGroupFollowCompanyIdsMap[index] = a + "," + tmpFollowCompanyIds
  8855. } else {
  8856. tmpGroupFollowCompanyIdsMap[index] = tmpFollowCompanyIds
  8857. }
  8858. }
  8859. if tmpReadyCompanyIds != `` {
  8860. a, ok := tmpGroupReadyCompanyIdsMap[index]
  8861. if ok {
  8862. tmpGroupReadyCompanyIdsMap[index] = a + "," + tmpReadyCompanyIds
  8863. } else {
  8864. tmpGroupReadyCompanyIdsMap[index] = tmpReadyCompanyIds
  8865. }
  8866. }
  8867. if tmpInitCompanyIds != `` {
  8868. a, ok := tmpGroupInitCompanyIdsMap[index]
  8869. if ok {
  8870. tmpGroupInitCompanyIdsMap[index] = a + "," + tmpInitCompanyIds
  8871. } else {
  8872. tmpGroupInitCompanyIdsMap[index] = tmpInitCompanyIds
  8873. }
  8874. }
  8875. //总数据汇总
  8876. tmpAllTryOutNumMap[index] += tmpTryOutNum
  8877. tmpAllFormalNumMap[index] += tmpFormalNum
  8878. tmpAllActiveNumMap[index] += tmpActiveStatus
  8879. tmpAllAllActiveNumMap[index] += tmpAllActiveStatus
  8880. tmpAllNoIncrementalActiveNumMap[index] += tmpNoIncrementalActiveStatus
  8881. // 总数据试用标签数据汇总
  8882. tmpAllTryStagePushMap[index] += tmpTryStagePushNum
  8883. tmpAllTryStageFollowMap[index] += tmpTryStageFollowNum
  8884. tmpAllTryStageReadyMap[index] += tmpTryStageReadyNum
  8885. tmpAllTryStageInitMap[index] += tmpTryStageInitNum
  8886. }
  8887. tmpAdminReportRecord := statistic_report.CityRecord{
  8888. Name: city,
  8889. CompanyAreaNumNumList: tmpCompanyReportRecordNumList,
  8890. }
  8891. tmpGroupCityReportRecord = append(tmpGroupCityReportRecord, tmpAdminReportRecord)
  8892. }
  8893. for i := 0; i < len(tmpGroupActiveNumMap); i++ {
  8894. tmpGroupCompanyReportRecordNum := statistic_report.CompanyAreaNum{
  8895. TryOutNum: tmpGroupTryOutNumMap[i],
  8896. FormalNum: tmpGroupFormalNumMap[i],
  8897. FormalIds: tmpGroupFormalCompanyIdsMap[i],
  8898. ActiveNum: tmpGroupActiveNumMap[i],
  8899. AllActiveNum: tmpGroupAllActiveNumMap[i],
  8900. NoIncrementalActiveNum: tmpGroupNoIncrementalActiveNumMap[i],
  8901. StartDate: startDateIndexList[i],
  8902. EndDate: endDateIndexList[i],
  8903. TryStagePushNum: tmpGroupTryStagePushMap[i],
  8904. TryStageFollowNum: tmpGroupTryStageFollowMap[i],
  8905. TryStageReadyNum: tmpGroupTryStageReadyMap[i],
  8906. TryStageInitNum: tmpGroupTryStageInitMap[i],
  8907. TotalNum: tmpGroupTryOutNumMap[i] + tmpGroupFormalNumMap[i],
  8908. TryOutIds: tmpGroupTryOutCompanyIdsMap[i],
  8909. TryStagePushIds: tmpGroupPushCompanyIdsMap[i],
  8910. TryStageFollowIds: tmpGroupFollowCompanyIdsMap[i],
  8911. TryStageReadyIds: tmpGroupReadyCompanyIdsMap[i],
  8912. TryStageInitIds: tmpGroupInitCompanyIdsMap[i],
  8913. }
  8914. tmpGroupCompanyReportRecordNumList = append(tmpGroupCompanyReportRecordNumList, tmpGroupCompanyReportRecordNum)
  8915. }
  8916. groupReportRecord := statistic_report.GroupCityRecord{
  8917. Item: tmpGroupCityReportRecord,
  8918. Name: province,
  8919. CompanyAreaNumNumList: tmpGroupCompanyReportRecordNumList,
  8920. }
  8921. groupReportRecordList = append(groupReportRecordList, groupReportRecord)
  8922. }
  8923. resp.List = groupReportRecordList
  8924. br.Ret = 200
  8925. br.Success = true
  8926. br.Msg = "获取成功"
  8927. br.Data = resp
  8928. }
  8929. // CompanyTryOutDayList
  8930. // @Title 客户累计试用详情接口
  8931. // @Description 客户累计试用详情接口
  8932. // @Param CompanyId query int true "客户id"
  8933. // @Param ProductId query int true "产品id"
  8934. // @Success 200 {object} company.CompanyTryOutDayListResp
  8935. // @router /company/tryOutDayList [get]
  8936. func (this *CompanyTodoController) CompanyTryOutDayList() {
  8937. br := new(models.BaseResponse).Init()
  8938. defer func() {
  8939. this.Data["json"] = br
  8940. this.ServeJSON()
  8941. }()
  8942. companyId, _ := this.GetInt("CompanyId")
  8943. if companyId <= 0 {
  8944. br.Msg = "请选择客户"
  8945. return
  8946. }
  8947. productId, _ := this.GetInt("ProductId")
  8948. if productId <= 0 {
  8949. br.Msg = "请选择类型"
  8950. return
  8951. }
  8952. pageSize, _ := this.GetInt("PageSize")
  8953. currentIndex, _ := this.GetInt("CurrentIndex")
  8954. var startSize int
  8955. if pageSize <= 0 {
  8956. pageSize = utils.PageSize20
  8957. }
  8958. if currentIndex <= 0 {
  8959. currentIndex = 1
  8960. }
  8961. startSize = paging.StartIndex(currentIndex, pageSize)
  8962. // 获取任务信息
  8963. total, err := company.GetCompanyProductTryOutUpdateLogTotal(companyId, productId)
  8964. if err != nil {
  8965. br.Msg = "获取任务信息失败"
  8966. br.ErrMsg = "获取任务信息失败,err:" + err.Error()
  8967. return
  8968. }
  8969. // 获取任务信息
  8970. list, err := company.GetCompanyProductTryOutUpdateLogList(companyId, productId, startSize, pageSize)
  8971. if err != nil {
  8972. br.Msg = "获取任务信息失败"
  8973. br.ErrMsg = "获取任务信息失败,err:" + err.Error()
  8974. return
  8975. }
  8976. //var list []*company_todo.CompanyTodoListItem
  8977. //for _, v := range todos {
  8978. // temp := &company_todo.CompanyTodoListItem{
  8979. // CompanyTodo: v,
  8980. // }
  8981. // temp.EndTimeStr = temp.EndTime.Format(utils.FormatDate)
  8982. // if temp.EndTimeStr == "0001-01-01" {
  8983. // temp.EndTimeStr = ""
  8984. // }
  8985. // list = append(list, temp)
  8986. //}
  8987. if len(list) <= 0 {
  8988. list = make([]*company.CompanyProductTryOutUpdateLog, 0)
  8989. }
  8990. page := paging.GetPaging(currentIndex, pageSize, total)
  8991. resp := company.CompanyTryOutDayListResp{
  8992. Paging: page,
  8993. List: list,
  8994. }
  8995. br.Ret = 200
  8996. br.Success = true
  8997. br.Msg = "获取成功"
  8998. br.Data = resp
  8999. }
  9000. // @Title 获取流水信息接口
  9001. // @Description 获取流水信息接口
  9002. // @Param CompanyId query int true "客户id"
  9003. // @Success 200 {object} company.CygxActivityPointsBillListResp
  9004. // @router /company/activity/points/bill [get]
  9005. func (this *CompanyTodoController) CompanyActivityPointsBill() {
  9006. br := new(models.BaseResponse).Init()
  9007. defer func() {
  9008. this.Data["json"] = br
  9009. this.ServeJSON()
  9010. }()
  9011. companyId, _ := this.GetInt("CompanyId")
  9012. if companyId <= 0 {
  9013. br.Msg = "请选择客户"
  9014. return
  9015. }
  9016. // 获取流水信息
  9017. list, err := cygx.CygxActivityPointsBillByCompanyId(companyId)
  9018. if err != nil {
  9019. br.Msg = "获取任务信息失败"
  9020. br.ErrMsg = "获取任务信息失败,err:" + err.Error()
  9021. return
  9022. }
  9023. if len(list) <= 0 {
  9024. list = make([]*cygx.CygxActivityPointsBillResp, 0)
  9025. }
  9026. resp := cygx.CygxActivityPointsBillListResp{
  9027. List: list,
  9028. }
  9029. br.Ret = 200
  9030. br.Success = true
  9031. br.Msg = "获取成功"
  9032. br.Data = resp
  9033. }
  9034. // DelRemark
  9035. // @Title 删除备注
  9036. // @Description 删除备注
  9037. // @Param request body company.RemarkDelReq true "type json string"
  9038. // @Success 200 操作成功
  9039. // @router /remark/del [post]
  9040. func (this *CompanyController) DelRemark() {
  9041. br := new(models.BaseResponse).Init()
  9042. defer func() {
  9043. if br.ErrMsg == "" {
  9044. br.IsSendEmail = false
  9045. }
  9046. this.Data["json"] = br
  9047. this.ServeJSON()
  9048. }()
  9049. sysUser := this.SysUser
  9050. if sysUser == nil {
  9051. br.Msg = "请登录"
  9052. br.ErrMsg = "请登录,SysUser Is Empty"
  9053. br.Ret = 408
  9054. return
  9055. }
  9056. var req company.RemarkDelReq
  9057. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  9058. if err != nil {
  9059. br.Msg = "参数解析异常!"
  9060. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  9061. return
  9062. }
  9063. if req.RemarkId <= 0 {
  9064. br.Msg = "参数有误"
  9065. br.ErrMsg = "参数有误, 备注ID有误"
  9066. return
  9067. }
  9068. item, e := company.GetCompanyRemarkById(req.RemarkId)
  9069. if e != nil {
  9070. if e.Error() == utils.ErrNoRow() {
  9071. br.Msg = "备注已被删除, 请刷新页面"
  9072. return
  9073. }
  9074. br.Msg = "备注信息有误"
  9075. br.ErrMsg = "获取客户备注失败, Err: " + e.Error()
  9076. return
  9077. }
  9078. if item.SysUserId != sysUser.AdminId {
  9079. br.Msg = "仅备注添加人可删除"
  9080. return
  9081. }
  9082. product, e := company.GetCompanyProductByCompanyIdAndProductId(item.CompanyId, item.ProductId)
  9083. if e != nil {
  9084. br.Msg = "操作失败"
  9085. br.ErrMsg = "获取客户产品信息失败, Err: " + e.Error()
  9086. return
  9087. }
  9088. if e := company.DelCompanyRemark(req.RemarkId); e != nil {
  9089. br.Msg = "操作失败"
  9090. br.ErrMsg = "删除客户备注失败, Err: " + e.Error()
  9091. return
  9092. }
  9093. content := fmt.Sprintf("%s%s", "删除备注: ", item.Remark)
  9094. _ = 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)
  9095. if item.ProductId == utils.COMPANY_PRODUCT_RAI_ID {
  9096. go services.DelCompanyHistoryRemark("company_product_remark", req.RemarkId) // 删除
  9097. }
  9098. br.Ret = 200
  9099. br.Success = true
  9100. br.Msg = "操作成功"
  9101. }
  9102. // @Title 获取流水信息接口
  9103. // @Description 获取流水信息接口
  9104. // @Param CompanyId query int true "客户id"
  9105. // @Success 200 {object} company.CygxActivityPointsBillListResp
  9106. // @router /company/activity/special/points/bill [get]
  9107. func (this *CompanyTodoController) CompanyActivitySpecialPointsBill() {
  9108. br := new(models.BaseResponse).Init()
  9109. defer func() {
  9110. this.Data["json"] = br
  9111. this.ServeJSON()
  9112. }()
  9113. companyId, _ := this.GetInt("CompanyId")
  9114. if companyId <= 0 {
  9115. br.Msg = "请选择客户"
  9116. return
  9117. }
  9118. // 获取流水信息
  9119. var condition string
  9120. var pars []interface{}
  9121. condition += ` AND company_id = ? `
  9122. pars = append(pars, companyId)
  9123. //查询当年的数据
  9124. //condition += ` AND b.create_time >= ? `
  9125. //pars = append(pars, time.Now().Format(utils.FormatYearDate)+"-01-01")
  9126. list, err := cygx.GetCygxActivitySpecialTripBillDetailListAll(condition, pars)
  9127. if err != nil {
  9128. br.Msg = "获取任务信息失败"
  9129. br.ErrMsg = "获取任务信息失败,err:" + err.Error()
  9130. return
  9131. }
  9132. //userType, tripRemaining, mapChartName, err := cygxService.GetChartPermissionSpecialSurplusByCompany(companyId)
  9133. //if err != nil {
  9134. // br.Msg = "获取专项调研剩余次数失败"
  9135. // br.ErrMsg = "获取专项调研剩余次数失败,err:" + err.Error()
  9136. // return
  9137. //}
  9138. //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}
  9139. resp := new(cygx.CygxActivitySpecialPointsBillResp)
  9140. //lastTripRemaining := 0
  9141. for _, v := range list {
  9142. item := cygx.CygxActivitySpecialPointsBillRespItem{
  9143. Id: v.Id,
  9144. CreateTime: v.CreateTime.Format(utils.FormatDateTime),
  9145. CompanyId: v.CompanyId,
  9146. CompanyName: v.CompanyName,
  9147. RealName: v.RealName,
  9148. BillDetailed: v.BillDetailed,
  9149. ActivityName: v.ResearchTheme,
  9150. ChartPermissionId: v.ChartPermissionId,
  9151. ChartPermissionName: v.ChartPermissionName,
  9152. Total: v.Total,
  9153. }
  9154. if v.ActivityId == 0 {
  9155. item.Content = v.Content
  9156. } else {
  9157. if v.DoType == 1 && v.Way != 4 && v.Way != 3 {
  9158. item.Content = item.ActivityName + "--报名"
  9159. } else if v.DoType == 2 && v.Way != 4 && v.Way != 3 {
  9160. item.Content = item.ActivityName + "--取消报名"
  9161. } else if v.Way == 4 {
  9162. item.Content = item.ActivityName + "--活动取消"
  9163. }
  9164. }
  9165. //if userType == 2 {
  9166. // if i== 0 {
  9167. // item.Total += strconv.Itoa(tripRemaining) + "次"
  9168. // } else {
  9169. // item.Total += strconv.Itoa(tripRemaining-list[i-1].BillDetailed) + "次"
  9170. // }
  9171. // //if v.BillDetailed < 4 {
  9172. // // item.Total += strconv.Itoa(lastTripRemaining-list[i-1].BillDetailed) + "次"
  9173. // //} else {
  9174. // // item.Total += strconv.Itoa(lastTripRemaining) + "次"
  9175. // //}
  9176. //} else {
  9177. // for k, num := range mapChartName {
  9178. // if i== 0 {
  9179. // item.Total += k + strconv.Itoa(num) + "次+"
  9180. // } else {
  9181. // if list[i-1].ActivityId == 0 {
  9182. // item.Total += k + strconv.Itoa(num) + "次+"
  9183. // } else {
  9184. // item.Total += k + strconv.Itoa(num-list[i-1].BillDetailed) + "次+"
  9185. // }
  9186. // }
  9187. // //if num > 0 {
  9188. // // if i== 0{
  9189. // // item.Total += k + strconv.Itoa(num) + "次+"
  9190. // // } else {
  9191. // // item.Total += k + strconv.Itoa(num-v.BillDetailed) + "次+"
  9192. // // }
  9193. // //}
  9194. // }
  9195. // item.Total = strings.TrimRight(item.Total, "+")
  9196. //}
  9197. resp.List = append(resp.List, &item)
  9198. }
  9199. br.Ret = 200
  9200. br.Success = true
  9201. br.Msg = "获取成功"
  9202. br.Data = resp
  9203. }