company.go 311 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505
  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 = ? OR (b.share_seller_id = ? AND b.is_share = 1)) `
  752. pars = append(pars, sysUser.AdminId, 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. list[i].BtnItem = btnItem
  1257. if item.FreezeStartDate != "" && item.FreezeEndDate != "" && item.Status == utils.COMPANY_STATUS_FREEZE {
  1258. freezeEndDate, _ := time.Parse(utils.FormatDate, item.FreezeEndDate)
  1259. if time.Now().Before(freezeEndDate) {
  1260. expireDays := freezeEndDate.Sub(time.Now()).Hours() / 24
  1261. list[i].FreezeExpireDays = int(expireDays) + 1
  1262. }
  1263. }
  1264. btnItem.BtnServiceRecord = btnServiceRecordMap[list[i].CompanyId]
  1265. // 签约未签约按钮回显展示
  1266. btnCompanyStatusItem := new(company.CompanyStatusButton)
  1267. btnCompanyStatusItem = services.GetLsitCompanyStatusButton(list[i].CompanyType, list[i].Status, list[i].SigningStatus)
  1268. list[i].CompanyStatusButton = btnCompanyStatusItem
  1269. //productIdArr := strings.Split(item.ProductIds, "/")
  1270. //// 套餐类型
  1271. //packageTypeArr := strings.Split(item.PackageTypes, "/")
  1272. //viewTotalArr := strings.Split(item.ViewTotals, "/") //总阅读次数
  1273. //lastViewTimeArr := strings.Split(item.LastViewTimes, "/") //最近阅读时间
  1274. //if len(productIdArr) > 1 {
  1275. // if len(packageTypeArr) == 1 {
  1276. // item.PackageTypes = item.PackageTypes + "/" + item.PackageTypes
  1277. // packageTypeArr = strings.Split(item.PackageTypes, "/")
  1278. // }
  1279. // //阅读次数
  1280. // if len(viewTotalArr) == 1 {
  1281. // item.ViewTotals = item.ViewTotals + "/" + item.ViewTotals
  1282. // viewTotalArr = strings.Split(item.ViewTotals, "/") //总阅读次数
  1283. // }
  1284. //
  1285. // if len(lastViewTimeArr) == 1 {
  1286. // item.LastViewTimes = item.LastViewTimes + "/" + item.LastViewTimes
  1287. // lastViewTimeArr = strings.Split(item.LastViewTimes, "/") //最近阅读时间
  1288. // }
  1289. //}
  1290. //for i, tmpProductId := range productIdArr {
  1291. // packageTypeInt, _ := strconv.Atoi(packageTypeArr[i])
  1292. // viewTotalInt, _ := strconv.Atoi(viewTotalArr[i])
  1293. // lastViewTime := lastViewTimeArr[i]
  1294. // //ficc
  1295. // if tmpProductId == "1" {
  1296. // //套餐类型
  1297. // item.FiccPackageType = packageTypeInt
  1298. //
  1299. // //总阅读次数
  1300. // item.FiccView = viewTotalInt
  1301. //
  1302. // //最近一次阅读时间
  1303. // item.FiccLastViewTime = lastViewTime
  1304. // }
  1305. // //权益
  1306. // if tmpProductId == "2" {
  1307. // //总阅读次数
  1308. // item.RaiView = viewTotalInt
  1309. //
  1310. // //最近一次阅读时间
  1311. // item.RaiLastViewTime = lastViewTime
  1312. // }
  1313. //}
  1314. ficcKey := fmt.Sprint(item.CompanyId, "_", 1)
  1315. //ficc
  1316. if tmpCompanyProduct, ok := companyProductMap[ficcKey]; ok {
  1317. //套餐类型
  1318. item.FiccPackageType = tmpCompanyProduct.PackageType
  1319. //总试用天数
  1320. item.FiccTryOutDay = tmpCompanyProduct.TryOutDayTotal
  1321. //总阅读次数
  1322. item.FiccView = tmpCompanyProduct.ViewTotal
  1323. if !tmpCompanyProduct.LastViewTime.IsZero() {
  1324. //最近一次阅读时间
  1325. item.FiccLastViewTime = tmpCompanyProduct.LastViewTime.Format(utils.FormatDateTime)
  1326. }
  1327. }
  1328. //权益
  1329. raiKey := fmt.Sprint(item.CompanyId, "_", 2)
  1330. if tmpCompanyProduct, ok := companyProductMap[raiKey]; ok {
  1331. //总阅读次数
  1332. item.RaiView = tmpCompanyProduct.ViewTotal
  1333. //总试用天数
  1334. item.RaiTryOutDay = tmpCompanyProduct.TryOutDayTotal
  1335. if !tmpCompanyProduct.LastViewTime.IsZero() {
  1336. //最近一次阅读时间
  1337. item.RaiLastViewTime = tmpCompanyProduct.LastViewTime.Format(utils.FormatDateTime)
  1338. }
  1339. }
  1340. //最近阅读时间
  1341. //if viewTime, ok := companyFiccViewTimeMap[item.CompanyId]; ok {
  1342. // item.FiccLastViewTime = viewTime.Format(utils.FormatDateTime)
  1343. //}
  1344. //
  1345. //if viewTime, ok := companyRaiViewTimeMap[item.CompanyId]; ok {
  1346. // item.RaiLastViewTime = viewTime.Format(utils.FormatDateTime)
  1347. //}
  1348. // 试用客户子标签
  1349. if strings.Contains(item.Status, "试用") {
  1350. statusSlice := strings.Split(item.Status, "/")
  1351. stageItemSlice := strings.Split(item.TryStageStr, "/")
  1352. productIdSlice := strings.Split(item.ProductIds, "/")
  1353. for sk, sv := range statusSlice {
  1354. if sv != "试用" {
  1355. continue
  1356. }
  1357. tryItem := new(company.TryStageSliceItem)
  1358. if len(productIdSlice) < (sk+1) || len(stageItemSlice) < (sk+1) {
  1359. continue
  1360. }
  1361. key := fmt.Sprint(item.CompanyId, "_", productIdSlice[sk])
  1362. if pro, ok := companyProductMap[key]; ok {
  1363. tryItem.ProductId, _ = strconv.Atoi(productIdSlice[sk])
  1364. if pro.SellerId == sysUser.AdminId { //产品销售ID和登录ID相等
  1365. tryItem.HasPermission = true
  1366. }
  1367. tryItem.TryStage, _ = strconv.Atoi(stageItemSlice[sk])
  1368. list[i].TryStageSlice = append(list[i].TryStageSlice, tryItem)
  1369. }
  1370. }
  1371. }
  1372. // To-Do任务状态为未完成的对应任务的截止日期-当前日期;
  1373. if strings.Contains(item.TodoStatuss, "未完成") {
  1374. if strings.Contains(item.TodoEndTimeStr, "/") {
  1375. edtSlice := strings.Split(item.TodoEndTimeStr, "/")
  1376. item.TodoEndTime, _ = time.ParseInLocation(utils.FormatDateTime, edtSlice[0], time.Local)
  1377. } else {
  1378. item.TodoEndTime, _ = time.ParseInLocation(utils.FormatDateTime, item.TodoEndTimeStr, time.Local)
  1379. }
  1380. tmpEndTime := item.TodoEndTime.Format(utils.FormatDate)
  1381. if tmpEndTime == "0001-01-01" {
  1382. tmpEndTime = ""
  1383. }
  1384. if tmpEndTime != "" {
  1385. dlTime1 := time.Date(time.Now().Year(), time.Now().Month(), time.Now().Day(), 0, 0, 0, 0, time.Local)
  1386. dlTime2 := time.Date(item.TodoEndTime.Year(), item.TodoEndTime.Month(), item.TodoEndTime.Day(), 0, 0, 0, 0, time.Local)
  1387. dldays := int(dlTime2.Sub(dlTime1).Hours() / 24)
  1388. list[i].Deadline = strconv.Itoa(dldays)
  1389. }
  1390. }
  1391. }
  1392. statusCount, err := company.GetCompanyStatusCount(permissionCondition, permissionPars)
  1393. if err != nil {
  1394. br.Msg = "获取失败"
  1395. br.ErrMsg = "获取状态数量失败,Err:" + err.Error()
  1396. return
  1397. }
  1398. statusMap := make(map[string]int, 0)
  1399. var totalCount int
  1400. for _, sv := range statusCount {
  1401. sv.Status = strings.Replace(sv.Status, utils.COMPANY_STATUS_FOREVER, utils.COMPANY_STATUS_X_CLASS_TRY_OUT, -1) // 永续客户类型,映射成 X类试用
  1402. totalCount = totalCount + sv.Count
  1403. statusMap[sv.Status] = sv.Count
  1404. }
  1405. // 统计试用客户的子标签数量,只在试用状态页面统计
  1406. var tryStageCountResp []*company.CompanyTryStageCount
  1407. if status == "试用" {
  1408. tryStageCount, err := company.GetCompanyTryStageCount(permissionCondition, permissionPars)
  1409. if err != nil {
  1410. br.Msg = "获取失败"
  1411. br.ErrMsg = "获取试用状态标签数量失败,Err:" + err.Error()
  1412. return
  1413. }
  1414. tryStageMap := make(map[int]int)
  1415. for _, v := range tryStageCount {
  1416. tryStageMap[0] += v.Count
  1417. tryStageMap[v.TryStage] = v.Count
  1418. }
  1419. tryStageAllMap := map[int]string{
  1420. 0: "全部",
  1421. 2: "推进",
  1422. 3: "跟踪",
  1423. 4: "预备",
  1424. 1: "未分类",
  1425. }
  1426. for k, v := range tryStageAllMap {
  1427. item := new(company.CompanyTryStageCount)
  1428. item.TryStageStr = v
  1429. item.TryStage = k
  1430. if count, ok := tryStageMap[k]; ok {
  1431. item.Count = count
  1432. }
  1433. tryStageCountResp = append(tryStageCountResp, item)
  1434. }
  1435. }
  1436. //
  1437. ////试用-活跃
  1438. //{
  1439. // tmpPermissionCondition := permissionCondition
  1440. // tmpPermissionPars := permissionPars
  1441. // tmpPermissionCondition += ` and b.view_total>=? `
  1442. // tmpPermissionPars = append(tmpPermissionPars, statistic_report.ActiveViewNum)
  1443. //
  1444. // tryOutActiveCount, err := company.GetCompanyTryOutStatusCount(tmpPermissionCondition, tmpPermissionPars)
  1445. // if err != nil {
  1446. // br.Msg = "获取失败"
  1447. // br.ErrMsg = "获取状态数量失败,Err:" + err.Error()
  1448. // return
  1449. // }
  1450. // statusMap["试用-活跃"] = tryOutActiveCount.Count
  1451. //}
  1452. //
  1453. ////试用-非活跃
  1454. //{
  1455. // tmpPermissionCondition := permissionCondition
  1456. // tmpPermissionPars := permissionPars
  1457. // tmpPermissionCondition += ` and b.view_total <? `
  1458. // tmpPermissionPars = append(tmpPermissionPars, statistic_report.ActiveViewNum)
  1459. //
  1460. // tryOutActiveCount, err := company.GetCompanyTryOutStatusCount(tmpPermissionCondition, tmpPermissionPars)
  1461. // if err != nil {
  1462. // br.Msg = "获取失败"
  1463. // br.ErrMsg = "获取状态数量失败,Err:" + err.Error()
  1464. // return
  1465. // }
  1466. // statusMap["试用-非活跃"] = tryOutActiveCount.Count
  1467. //}
  1468. lossItem, err := company.GetCompanyStatusLoseCount(lossCondition, lossPars)
  1469. if err != nil {
  1470. br.Msg = "获取失败"
  1471. br.ErrMsg = "获取流失状态数量失败,Err:" + err.Error()
  1472. return
  1473. }
  1474. totalCount = totalCount + lossItem.Count
  1475. for _, v := range statusArr {
  1476. s := new(company.CompanyStatus)
  1477. if v == "全部" {
  1478. s.Status = "全部"
  1479. s.Count = totalCount
  1480. } else if v == utils.COMPANY_STATUS_LOSE {
  1481. s.Status = v
  1482. s.Count = lossItem.Count
  1483. } else {
  1484. s.Status = v
  1485. if val, ok := statusMap[v]; ok {
  1486. s.Count = val
  1487. }
  1488. }
  1489. statusItems = append(statusItems, s)
  1490. }
  1491. sysUserList, err := system.GetAdminList()
  1492. if err != nil {
  1493. br.Msg = "获取失败"
  1494. br.ErrMsg = "获取admin列表失败, Err:" + err.Error()
  1495. return
  1496. }
  1497. adminMap := make(map[int]*system.Admin, 0)
  1498. for _, v := range sysUserList {
  1499. adminMap[v.AdminId] = v
  1500. }
  1501. companyLists := make([]*company.CompanyListItem, 0)
  1502. //查询阅读次数
  1503. if list == nil {
  1504. companyLists = make([]*company.CompanyListItem, 0)
  1505. } else {
  1506. for _, v := range list {
  1507. //viewTotal:=GetviewTotal(v.CompanyId)
  1508. //活跃(客户状态)
  1509. //if v.IsShare != 1 {
  1510. // if v.BtnItem.BtnModifySeller == true {
  1511. // v.BtnItem.BtnModifySeller = false
  1512. // }
  1513. //}
  1514. //productIdSlice := strings.Split(v.ProductIds, "/")
  1515. //statusSlice := strings.Split(v.Status, "/")
  1516. //for productIndex, tmpProductId := range productIdSlice {
  1517. // tmpStatusIndex := 0
  1518. // if len(statusSlice) > 1 {
  1519. // tmpStatusIndex = productIndex
  1520. // }
  1521. // tmpProductStatus := statusSlice[tmpStatusIndex]
  1522. // if strings.Contains(tmpProductStatus, "试用") {
  1523. // activeType := "非活跃"
  1524. // viewNum := v.FiccView
  1525. // if tmpProductId == "2" {
  1526. // viewNum = v.RaiView
  1527. // }
  1528. // if viewNum >= statistic_report.ActiveViewNum {
  1529. // activeType = "活跃"
  1530. // }
  1531. // statusSlice[tmpStatusIndex] = fmt.Sprint(tmpProductStatus, "(", activeType, ")")
  1532. //
  1533. // tmpStatus = strings.Join(statusSlice, "/")
  1534. // }
  1535. //}
  1536. //ficcViewTotal, ok := companyFiccViewTotal[v.CompanyId]
  1537. //if !ok {
  1538. // ficcViewTotal = 0
  1539. //}
  1540. //raiViewTotal, ok := companyRaiViewTotal[v.CompanyId]
  1541. //if !ok {
  1542. // raiViewTotal = 0
  1543. //}
  1544. // 是否存在进行中的任务
  1545. var todoStatus bool
  1546. if _, ok := companyTodoMap[fmt.Sprint(v.CompanyId)]; ok {
  1547. todoStatus = true
  1548. }
  1549. //是否支持确认完成待办任务
  1550. var canConfirm bool
  1551. var hiddenConfirm bool //是否隐藏确定完成按钮
  1552. var hiddenCreate bool //是否隐藏新增/编辑按钮
  1553. hiddenConfirm = true
  1554. hiddenCreate = true
  1555. for _, vProductId := range []int{1, 2} {
  1556. ficcKey := fmt.Sprint(v.CompanyId, "_", vProductId)
  1557. //ficc
  1558. if tmpCompanyProduct, ok := companyProductMap[ficcKey]; ok {
  1559. if tmpCompanyProduct.Status != utils.COMPANY_STATUS_LOSE && tmpCompanyProduct.Status != utils.COMPANY_STATUS_CLOSE { //非流失或关闭
  1560. hiddenCreate = false
  1561. switch this.SysUser.RoleTypeCode {
  1562. 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:
  1563. //部门管理员、ficc主管、权益组长
  1564. hiddenConfirm = false //不展示
  1565. if todoStatus { //有任务,需要展示
  1566. canConfirm = true
  1567. }
  1568. case utils.ROLE_TYPE_CODE_FICC_TEAM: //ficc组长
  1569. if todoStatus { //有任务,需要展示
  1570. canConfirm = true
  1571. }
  1572. if v.SellerId != this.SysUser.AdminId { //不是自己的客户
  1573. hiddenConfirm = false //展示
  1574. }
  1575. case utils.ROLE_TYPE_CODE_RAI_SELLER: //权益销售
  1576. if v.SellerId == this.SysUser.AdminId { //是自己的客户
  1577. has := services.CheckRaiApprovePermission(sysUser.AdminId) //这些个权益销售是有权限的
  1578. if has {
  1579. if todoStatus { //有任务,需要展示
  1580. canConfirm = true
  1581. }
  1582. hiddenConfirm = false //展示
  1583. }
  1584. }
  1585. }
  1586. }
  1587. }
  1588. }
  1589. todoButtonColor := `green`
  1590. //'无任务','未完成','已完成'
  1591. if strings.Contains(v.TodoStatuss, "未完成") {
  1592. todoButtonColor = "red"
  1593. } else if strings.Contains(v.TodoStatuss, "已完成") {
  1594. todoButtonColor = "green"
  1595. } else if strings.Contains(v.TodoStatuss, "无任务") {
  1596. todoButtonColor = "gray"
  1597. }
  1598. //if str
  1599. companyList := &company.CompanyListItem{
  1600. CompanyId: v.CompanyId,
  1601. CompanyName: v.CompanyName,
  1602. CreditCode: v.CreditCode,
  1603. CompanyCode: v.CompanyCode,
  1604. StartDate: v.StartDate,
  1605. EndDate: v.EndDate,
  1606. LoseReason: v.LoseReason,
  1607. RenewalReason: v.RenewalReason,
  1608. FreezeReason: v.FreezeReason,
  1609. LossTime: v.LossTime,
  1610. Status: v.StatusStr,
  1611. CompanyType: v.CompanyType,
  1612. ApproveStatus: v.ApproveStatus,
  1613. SellerName: v.SellerName,
  1614. SellerId: v.SellerId,
  1615. SellerIds: v.SellerIds,
  1616. ExpireDay: v.ExpireDay,
  1617. FreezeTime: v.FreezeTime,
  1618. GroupId: v.GroupId,
  1619. GroupIds: v.GroupIds,
  1620. DepartmentId: v.DepartmentId,
  1621. IndustryName: v.IndustryName,
  1622. IsSuspend: v.IsSuspend,
  1623. CreatedTime: v.CreatedTime,
  1624. Source: v.Source,
  1625. Province: v.Province,
  1626. City: v.City,
  1627. Address: v.Address,
  1628. Reasons: v.Reasons,
  1629. FreezeStartDate: v.FreezeStartDate,
  1630. FreezeEndDate: v.FreezeEndDate,
  1631. FreezeExpireDays: v.FreezeExpireDays,
  1632. BtnItem: v.BtnItem,
  1633. ProductId: v.ProductId,
  1634. FormalTime: v.FormalTime,
  1635. IsShared: v.IsShared,
  1636. RegionType: v.RegionType,
  1637. FiccPackageType: v.FiccPackageType,
  1638. FiccLastViewTime: v.FiccLastViewTime,
  1639. RaiLastViewTime: v.RaiLastViewTime,
  1640. //FiccView: viewTotal[0],
  1641. //RaiView: viewTotal[1],
  1642. //FiccView: ficcViewTotal,
  1643. //RaiView: raiViewTotal,
  1644. FiccView: v.FiccView,
  1645. RaiView: v.RaiView,
  1646. FiccTryOutDay: v.FiccTryOutDay,
  1647. RaiTryOutDay: v.RaiTryOutDay,
  1648. AllViewTotal: v.AllViewTotal,
  1649. RoadShowTotal: v.RoadShowTotal,
  1650. TodoStatus: todoStatus,
  1651. CanConfirm: canConfirm,
  1652. HiddenConfirm: hiddenConfirm,
  1653. HiddenCreate: hiddenCreate,
  1654. TodoButtonColor: todoButtonColor,
  1655. TryStageSlice: v.TryStageSlice,
  1656. Deadline: v.Deadline,
  1657. WeekViewActive: v.WeekViewActive,
  1658. IsShare: v.IsShare,
  1659. CloseTime: v.CloseTime,
  1660. CloseReason: v.CloseReason,
  1661. IsSigning: v.IsSigning,
  1662. CompanyStatusButton: v.CompanyStatusButton,
  1663. ShareSellerId: v.ShareSellerId,
  1664. ShareSellerIds: v.ShareSellerIds,
  1665. }
  1666. if v.ShareSellerIds != "" {
  1667. shareSellerIds := strings.Split(v.ShareSellerIds, ",")
  1668. for _, idStr := range shareSellerIds {
  1669. shareSellerId, e := strconv.Atoi(idStr)
  1670. if e != nil {
  1671. err = e
  1672. return
  1673. }
  1674. shareSeller := adminMap[shareSellerId]
  1675. if shareSeller != nil {
  1676. companyList.ShareSeller += shareSeller.RealName + "(" + shareSeller.GroupName + ")" + "/"
  1677. }
  1678. }
  1679. companyList.ShareSeller = strings.TrimRight(companyList.ShareSeller, "/")
  1680. }
  1681. companyLists = append(companyLists, companyList)
  1682. }
  1683. }
  1684. if companyLists == nil {
  1685. companyLists = make([]*company.CompanyListItem, 0)
  1686. }
  1687. // 白嫖客户标记
  1688. scroungeList, err := company.GetScroungeCompany()
  1689. if err != nil {
  1690. br.Msg = "获取失败"
  1691. br.ErrMsg = "获取白嫖客户信息失败,Err:" + err.Error()
  1692. return
  1693. }
  1694. scroungeMap := make(map[int]int)
  1695. for _, v := range scroungeList {
  1696. scroungeMap[v.CompanyId] = 1
  1697. }
  1698. for i, v := range companyLists {
  1699. if _, ok := scroungeMap[v.CompanyId]; ok {
  1700. companyLists[i].IsScrounge = 1
  1701. }
  1702. }
  1703. page = paging.GetPaging(currentIndex, pageSize, total)
  1704. resp.List = companyLists
  1705. resp.StatusCount = statusItems
  1706. resp.TryStageCount = tryStageCountResp
  1707. resp.Paging = page
  1708. resp.AddCompanyBtn = receiveEnabled
  1709. br.Ret = 200
  1710. br.Success = true
  1711. br.Msg = "获取成功"
  1712. br.Data = resp
  1713. }
  1714. //func (this *CompanyController) ListOld() {
  1715. // br := new(models.BaseResponse).Init()
  1716. // defer func() {
  1717. // this.Data["json"] = br
  1718. // this.ServeJSON()
  1719. // }()
  1720. // sysUser := this.SysUser
  1721. // if sysUser == nil {
  1722. // br.Msg = "请登录"
  1723. // br.ErrMsg = "请登录,SysUser Is Empty"
  1724. // br.Ret = 408
  1725. // return
  1726. // }
  1727. // roleTypeCode := sysUser.RoleTypeCode
  1728. //
  1729. // pageSize, _ := this.GetInt("PageSize")
  1730. // currentIndex, _ := this.GetInt("CurrentIndex")
  1731. // status := this.GetString("Status")
  1732. // companyType := this.GetString("CompanyType")
  1733. // industryId, _ := this.GetInt("IndustryId")
  1734. // adminId := this.GetString("AdminId")
  1735. //
  1736. // chartPermissionIds := this.GetString("ChartPermissionIds")
  1737. // startDate := this.GetString("StartDate")
  1738. // endDate := this.GetString("EndDate")
  1739. // createStartDate := this.GetString("CreateStartDate")
  1740. // createEndDate := this.GetString("CreateEndDate")
  1741. // keyWord := this.GetString("KeyWord")
  1742. // keyWord = strings.Trim(keyWord, " ")
  1743. // keyWord = strings.Replace(keyWord, "'", "", -1)
  1744. //
  1745. // //排序参数
  1746. // sortParam := this.GetString("SortParam")
  1747. // sortType := this.GetString("SortType")
  1748. //
  1749. // var total int
  1750. // page := paging.GetPaging(currentIndex, pageSize, total)
  1751. // resp := new(company.CompanyListResp)
  1752. // statusItems := make([]*company.CompanyStatus, 0)
  1753. // var statusArr = [...]string{"全部", "试用", "正式", "冻结", "流失", "永续"}
  1754. //
  1755. // var startSize int
  1756. // if pageSize <= 0 {
  1757. // pageSize = utils.PageSize20
  1758. // }
  1759. // if currentIndex <= 0 {
  1760. // currentIndex = 1
  1761. // }
  1762. // startSize = paging.StartIndex(currentIndex, pageSize)
  1763. // var condition string
  1764. // var pars []interface{}
  1765. //
  1766. // //流失
  1767. // var lossCondition string
  1768. // var lossPars []interface{}
  1769. // //冻结
  1770. // var freezeCondition string
  1771. // var freezePars []interface{}
  1772. //
  1773. // //永续
  1774. // var forverCondition string
  1775. // var forverPars []interface{}
  1776. //
  1777. // var permissionCondition string
  1778. // var permissionPars []interface{}
  1779. //
  1780. // if status != "" && status != "全部" {
  1781. // condition += ` AND b.status=? `
  1782. // pars = append(pars, status)
  1783. //
  1784. // //permissionCondition += ` AND b.status=? `
  1785. // //permissionPars = append(permissionPars, status)
  1786. // }
  1787. // if companyType != "" {
  1788. // condition += ` AND b.product_name=? `
  1789. // pars = append(pars, companyType)
  1790. //
  1791. // lossCondition += ` AND b.product_name=? `
  1792. // lossPars = append(lossPars, companyType)
  1793. //
  1794. // freezeCondition += ` AND b.product_name=? `
  1795. // freezePars = append(freezePars, companyType)
  1796. //
  1797. // forverCondition += ` AND b.product_name=? `
  1798. // forverPars = append(forverPars, companyType)
  1799. //
  1800. // permissionCondition += ` AND b.product_name=? `
  1801. // permissionPars = append(permissionPars, companyType)
  1802. // }
  1803. //
  1804. // if industryId > 0 {
  1805. // condition += ` AND b.industry_id=? `
  1806. // pars = append(pars, industryId)
  1807. //
  1808. // lossCondition += ` AND b.industry_id=? `
  1809. // lossPars = append(lossPars, industryId)
  1810. //
  1811. // freezeCondition += ` AND b.industry_id=? `
  1812. // freezePars = append(freezePars, industryId)
  1813. //
  1814. // forverCondition += ` AND b.industry_id=? `
  1815. // forverPars = append(forverPars, industryId)
  1816. //
  1817. // permissionCondition += ` AND b.industry_id=? `
  1818. // permissionPars = append(permissionPars, industryId)
  1819. // }
  1820. //
  1821. // if adminId != "" {
  1822. // condition += ` AND b.seller_id IN (` + adminId + `) `
  1823. //
  1824. // lossCondition += ` AND b.seller_id IN (` + adminId + `) `
  1825. //
  1826. // freezeCondition += ` AND b.seller_id IN (` + adminId + `) `
  1827. //
  1828. // forverCondition += ` AND b.seller_id IN (` + adminId + `) `
  1829. //
  1830. // permissionCondition += ` AND b.seller_id IN (` + adminId + `) `
  1831. // }
  1832. //
  1833. // if startDate != "" {
  1834. // condition += ` AND b.start_date>=? `
  1835. // pars = append(pars, startDate)
  1836. //
  1837. // lossCondition += ` AND b.start_date>=? `
  1838. // lossPars = append(lossPars, startDate)
  1839. //
  1840. // freezeCondition += ` AND b.start_date>=? `
  1841. // freezePars = append(freezePars, startDate)
  1842. //
  1843. // forverCondition += ` AND b.start_date>=? `
  1844. // forverPars = append(forverPars, startDate)
  1845. //
  1846. // permissionCondition += ` AND b.start_date>=? `
  1847. // permissionPars = append(permissionPars, startDate)
  1848. // }
  1849. //
  1850. // if endDate != "" {
  1851. // condition += ` AND b.end_date<=? `
  1852. // pars = append(pars, endDate)
  1853. //
  1854. // lossCondition += ` AND b.end_date<=? `
  1855. // lossPars = append(lossPars, endDate)
  1856. //
  1857. // freezeCondition += ` AND b.end_date<=? `
  1858. // freezePars = append(freezePars, endDate)
  1859. //
  1860. // forverCondition += ` AND b.end_date<=? `
  1861. // forverPars = append(forverPars, endDate)
  1862. //
  1863. // permissionCondition += ` AND b.end_date<=? `
  1864. // permissionPars = append(permissionPars, endDate)
  1865. // }
  1866. //
  1867. // if createStartDate != "" {
  1868. // condition += ` AND a.created_time>=? `
  1869. // pars = append(pars, createStartDate)
  1870. //
  1871. // lossCondition += ` AND a.created_time>=? `
  1872. // lossPars = append(lossPars, createStartDate)
  1873. //
  1874. // freezeCondition += ` AND a.created_time>=? `
  1875. // freezePars = append(freezePars, createStartDate)
  1876. //
  1877. // forverCondition += ` AND a.created_time>=? `
  1878. // forverPars = append(forverPars, createStartDate)
  1879. //
  1880. // permissionCondition += ` AND a.created_time>=? `
  1881. // permissionPars = append(permissionPars, createStartDate)
  1882. // }
  1883. //
  1884. // if createEndDate != "" {
  1885. // condition += ` AND a.created_time<=? `
  1886. // pars = append(pars, createEndDate)
  1887. //
  1888. // lossCondition += ` AND a.created_time<=? `
  1889. // lossPars = append(lossPars, createEndDate)
  1890. //
  1891. // freezeCondition += ` AND a.created_time<=? `
  1892. // freezePars = append(freezePars, createEndDate)
  1893. //
  1894. // forverCondition += ` AND a.created_time<=? `
  1895. // forverPars = append(forverPars, createEndDate)
  1896. //
  1897. // permissionCondition += ` AND a.created_time<=? `
  1898. // permissionPars = append(permissionPars, createEndDate)
  1899. // }
  1900. //
  1901. // if keyWord != "" {
  1902. // companyIdStr, err := company.GetCompanyIdByKeyWord(keyWord)
  1903. // if err != nil {
  1904. // br.Msg = "获取客户信息失败"
  1905. // br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  1906. // return
  1907. // }
  1908. // if companyIdStr != "" {
  1909. // condition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.company_id IN(` + companyIdStr + `)) `
  1910. // lossCondition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.company_id IN(` + companyIdStr + `)) `
  1911. // freezeCondition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.company_id IN(` + companyIdStr + `)) `
  1912. // forverCondition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.company_id IN(` + companyIdStr + `)) `
  1913. //
  1914. // permissionCondition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.company_id IN(` + companyIdStr + `)) `
  1915. // } else {
  1916. // condition += ` AND (a.company_name LIKE '%` + keyWord + `%' ) `
  1917. // lossCondition += ` AND (a.company_name LIKE '%` + keyWord + `%' ) `
  1918. // freezeCondition += ` AND (a.company_name LIKE '%` + keyWord + `%' ) `
  1919. // forverCondition += ` AND (a.company_name LIKE '%` + keyWord + `%' ) `
  1920. //
  1921. // permissionCondition += ` AND (a.company_name LIKE '%` + keyWord + `%' ) `
  1922. // }
  1923. // }
  1924. // if chartPermissionIds != "" && chartPermissionIds != "1" {
  1925. // //chartPermissionArr := strings.Split(chartPermissionIds, ",")
  1926. // //chartPermissionCount := len(chartPermissionArr)
  1927. // companyIdStr, err := company.GetCompanyListCompanyIdByPermissionIdStr(chartPermissionIds)
  1928. // if err != nil {
  1929. // br.Msg = "获取失败"
  1930. // br.ErrMsg = "根据权限获取公司ID失败,Err:" + err.Error()
  1931. // return
  1932. // }
  1933. // //var companyIdArr []string
  1934. // //for _, v := range companyIdList {
  1935. // // companyIdArr = append(companyIdArr, strconv.Itoa(v.CompanyId))
  1936. // //}
  1937. // //companyIdStr := strings.Join(companyIdArr, ",")
  1938. // if companyIdStr != "" {
  1939. // condition += ` AND a.company_id IN (` + companyIdStr + `) `
  1940. // lossCondition += ` AND a.company_id IN (` + companyIdStr + `) `
  1941. // freezeCondition += ` AND a.company_id IN (` + companyIdStr + `) `
  1942. // forverCondition += ` AND a.company_id IN (` + companyIdStr + `) `
  1943. // permissionCondition += ` AND a.company_id IN (` + companyIdStr + `) `
  1944. // } else {
  1945. // for _, v := range statusArr {
  1946. // statusCount := new(company.CompanyStatus)
  1947. // if v == "全部" {
  1948. // statusCount.Status = "全部"
  1949. // statusCount.Count = 0
  1950. // } else {
  1951. // statusCount.Status = v
  1952. // statusCount.Count = 0
  1953. // }
  1954. // statusItems = append(statusItems, statusCount)
  1955. // }
  1956. // items := make([]*company.CompanyListItem, 0)
  1957. // resp.List = items
  1958. // resp.Paging = page
  1959. // resp.StatusCount = statusItems
  1960. // br.Msg = "获取成功"
  1961. // br.Ret = 200
  1962. // br.Data = resp
  1963. // return
  1964. // }
  1965. // }
  1966. // //权限控制
  1967. // {
  1968. // fmt.Println(roleTypeCode)
  1969. // if roleTypeCode != utils.ROLE_TYPE_CODE_ADMIN {
  1970. // if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN {
  1971. // condition += ` AND b.product_id=? `
  1972. // pars = append(pars, 1)
  1973. //
  1974. // permissionCondition += ` AND b.product_id=? `
  1975. // permissionPars = append(permissionPars, 1)
  1976. // } else if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  1977. // condition += ` AND b.product_id=? `
  1978. // pars = append(pars, 2)
  1979. //
  1980. // permissionCondition += ` AND b.product_id=? `
  1981. // permissionPars = append(permissionPars, 2)
  1982. // } else {
  1983. // if sysUser.Authority <= 0 {
  1984. // if status == utils.COMPANY_STATUS_TRY_OUT || status == utils.COMPANY_STATUS_FORMAL || status == "全部" {
  1985. // if status == "全部" {
  1986. // condition += ` AND (b.seller_id=? OR status='流失' OR status='永续') `
  1987. // pars = append(pars, sysUser.AdminId)
  1988. // } else {
  1989. // condition += ` AND b.seller_id=? `
  1990. // pars = append(pars, sysUser.AdminId)
  1991. // }
  1992. // }
  1993. // permissionCondition += ` AND b.seller_id=? `
  1994. // permissionPars = append(permissionPars, sysUser.AdminId)
  1995. // } else {
  1996. // if sysUser.Authority == 1 {
  1997. // if status == utils.COMPANY_STATUS_TRY_OUT || status == utils.COMPANY_STATUS_FORMAL || status == "全部" {
  1998. // condition += ` AND b.department_id=? `
  1999. // pars = append(pars, sysUser.DepartmentId)
  2000. //
  2001. // permissionCondition += ` AND b.department_id=? `
  2002. // permissionPars = append(permissionPars, sysUser.DepartmentId)
  2003. // } else {
  2004. // permissionCondition += ` AND b.department_id=? `
  2005. // permissionPars = append(permissionPars, sysUser.DepartmentId)
  2006. // }
  2007. // }
  2008. //
  2009. // if sysUser.Authority == 2 {
  2010. // if status == utils.COMPANY_STATUS_TRY_OUT || status == utils.COMPANY_STATUS_FORMAL || status == "全部" {
  2011. // condition += ` AND b.group_id=? `
  2012. // pars = append(pars, sysUser.GroupId)
  2013. //
  2014. // permissionCondition += ` AND b.group_id=? `
  2015. // permissionPars = append(permissionPars, sysUser.GroupId)
  2016. // } else {
  2017. // permissionCondition += ` AND b.group_id=? `
  2018. // permissionPars = append(permissionPars, sysUser.GroupId)
  2019. // }
  2020. // }
  2021. // }
  2022. // }
  2023. // }
  2024. //
  2025. // //if status == utils.COMPANY_STATUS_FREEZE {
  2026. // // condition += ` AND b.seller_id=? `
  2027. // // pars = append(pars, sysUser.AdminId)
  2028. // //
  2029. // // //permissionCondition += ` AND b.seller_id=? `
  2030. // // //permissionPars = append(permissionPars, sysUser.AdminId)
  2031. // //}
  2032. // //if status == "全部" || status == utils.COMPANY_STATUS_FREEZE {
  2033. // // freezeCondition += ` AND b.seller_id=? `
  2034. // // freezePars = append(freezePars, sysUser.AdminId)
  2035. // //}
  2036. // if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  2037. // //freezeCondition += ` AND b.seller_id=? `
  2038. // //freezePars = append(freezePars, sysUser.AdminId)
  2039. // } else if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN {
  2040. // permissionCondition += ` AND b.product_id=? `
  2041. // permissionPars = append(permissionPars, 1)
  2042. // } else if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  2043. // permissionCondition += ` AND b.product_id=? `
  2044. // permissionPars = append(permissionPars, 2)
  2045. // } else {
  2046. // if status == utils.COMPANY_STATUS_FREEZE {
  2047. // condition += ` AND b.seller_id=? `
  2048. // pars = append(pars, sysUser.AdminId)
  2049. // }
  2050. //
  2051. // freezeCondition += ` AND b.seller_id=? `
  2052. // freezePars = append(freezePars, sysUser.AdminId)
  2053. // }
  2054. // }
  2055. //
  2056. // total, err := company.GetCompanyListCount(condition, pars)
  2057. // if err != nil {
  2058. // br.Msg = "获取失败"
  2059. // br.ErrMsg = "获取数据总数失败,Err:" + err.Error()
  2060. // return
  2061. // }
  2062. //
  2063. // sortStr := ``
  2064. // if sortParam != "" && sortType != "" {
  2065. // if sortParam == "endDate" {
  2066. // sortStr = " ORDER BY b.end_date "
  2067. // } else if sortParam == "createTime" {
  2068. // sortStr = " ORDER BY a.created_time "
  2069. // } else {
  2070. // br.Msg = "获取失败"
  2071. // br.ErrMsg = "排序字段传入数据异常:" + sortParam
  2072. // return
  2073. // }
  2074. //
  2075. // if sortType == "asc" {
  2076. // sortStr += " ASC "
  2077. // } else if sortType == "desc" {
  2078. // sortStr += " DESC "
  2079. // } else {
  2080. // br.Msg = "获取失败"
  2081. // br.ErrMsg = "排序类型传入数据异常:" + sortType
  2082. // return
  2083. // }
  2084. // }
  2085. //
  2086. // list, err := company.GetCompanyList(condition, status, sortStr, pars, startSize, pageSize)
  2087. // if err != nil {
  2088. // br.Msg = "获取失败"
  2089. // br.ErrMsg = "获取数据失败,Err:" + err.Error()
  2090. // return
  2091. // }
  2092. //
  2093. //
  2094. // //企业用户数组切片
  2095. // companyIdSlice := make([]string, 0)
  2096. // for _, v := range list {
  2097. // companyIdSlice = append(companyIdSlice, strconv.Itoa(v.CompanyId))
  2098. // }
  2099. //
  2100. // //企业用户产品开通数
  2101. // companyIdStr := strings.Join(companyIdSlice, ",")
  2102. // companyProductTotalList, _ := company.GetCountProductByCompanyIds(companyIdStr)
  2103. // companyProductTotalMap := make(map[int]*company.CompanyProductTotalSlice)
  2104. // for _, companyProductTotal := range companyProductTotalList {
  2105. // companyProductTotalMap[companyProductTotal.CompanyId] = companyProductTotal
  2106. // }
  2107. // lenList := len(list)
  2108. // for i := 0; i < lenList; i++ {
  2109. // item := list[i]
  2110. //
  2111. // //校验该客户是否存在多个产品,如果是,那么代表是共享客户
  2112. // if companyProductTotal, ok := companyProductTotalMap[int(item.CompanyId)]; ok {
  2113. // if companyProductTotal.Total > 1 {
  2114. // list[i].IsShared = true
  2115. // }
  2116. // }
  2117. //
  2118. // var expireDay string
  2119. // itemStatus := item.Status
  2120. // if itemStatus != "" {
  2121. // if !strings.Contains(item.Status, "/") {
  2122. // if itemStatus == utils.COMPANY_STATUS_FOREVER { //永续
  2123. // expireDay = "-"
  2124. // } else if itemStatus == utils.COMPANY_STATUS_TRY_OUT || itemStatus == utils.COMPANY_STATUS_FORMAL { //试用/正式
  2125. // if item.StartDate != "" && item.EndDate != "" {
  2126. // endDateTime, _ := time.Parse(utils.FormatDate, item.EndDate)
  2127. // endDateTime = endDateTime.AddDate(0, 0, 1)
  2128. // sub := endDateTime.Sub(time.Now())
  2129. // if sub < 0 {
  2130. // sub = 0
  2131. // }
  2132. // expireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
  2133. // } else {
  2134. // expireDay = "-"
  2135. // }
  2136. // } else if itemStatus == utils.COMPANY_STATUS_LOSE {
  2137. // expireDay = "-"
  2138. // } else if itemStatus == utils.COMPANY_STATUS_FREEZE {
  2139. // if item.StartDate != "" && item.EndDate != "" {
  2140. // endDateTime, _ := time.Parse(utils.FormatDate, item.EndDate)
  2141. // endDateTime = endDateTime.AddDate(0, 0, 0)
  2142. // sub := endDateTime.Sub(time.Now())
  2143. // if sub < 0 {
  2144. // sub = 0
  2145. // }
  2146. // expireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
  2147. // } else {
  2148. // expireDay = "-"
  2149. // }
  2150. // } else {
  2151. // expireDay = "-"
  2152. // }
  2153. // } else {
  2154. // statusArr := strings.Split(item.Status, "/")
  2155. // ficcStatus := statusArr[0]
  2156. // raiStatus := statusArr[1]
  2157. // var ficcEndDate, tryEndDate string
  2158. // var ficcExpireDay, tryExpireDay string
  2159. // if item.EndDate != "" {
  2160. // endDateArr := strings.Split(item.EndDate, "/")
  2161. // if len(endDateArr) == 1 {
  2162. // ficcEndDate = endDateArr[0]
  2163. // } else if len(endDateArr) > 1 {
  2164. // ficcEndDate = endDateArr[0]
  2165. // tryEndDate = endDateArr[1]
  2166. // }
  2167. // if ficcStatus == utils.COMPANY_STATUS_FOREVER { //永续
  2168. // ficcExpireDay = "-"
  2169. // } else if ficcStatus == utils.COMPANY_STATUS_TRY_OUT || ficcStatus == utils.COMPANY_STATUS_FORMAL { //试用/正式
  2170. // if ficcEndDate != "" {
  2171. // endDateTime, _ := time.Parse(utils.FormatDate, ficcEndDate)
  2172. // endDateTime = endDateTime.AddDate(0, 0, 1)
  2173. // sub := endDateTime.Sub(time.Now())
  2174. // if sub < 0 {
  2175. // sub = 0
  2176. // }
  2177. // ficcExpireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
  2178. // } else {
  2179. // ficcExpireDay = "-"
  2180. // }
  2181. // } else if ficcStatus == utils.COMPANY_STATUS_LOSE { //流失
  2182. // ficcExpireDay = "-"
  2183. // } else if ficcStatus == utils.COMPANY_STATUS_FREEZE { //冻结
  2184. // if item.StartDate != "" && item.EndDate != "" {
  2185. // endDateTime, _ := time.Parse(utils.FormatDate, ficcEndDate)
  2186. // endDateTime = endDateTime.AddDate(0, 0, 0)
  2187. // sub := endDateTime.Sub(time.Now())
  2188. // if sub < 0 {
  2189. // sub = 0
  2190. // }
  2191. // ficcExpireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
  2192. // } else {
  2193. // ficcExpireDay = "-"
  2194. // }
  2195. // } else {
  2196. // ficcExpireDay = "-"
  2197. // }
  2198. //
  2199. // if raiStatus == utils.COMPANY_STATUS_FOREVER { //永续
  2200. // tryExpireDay = "-"
  2201. // } else if raiStatus == utils.COMPANY_STATUS_TRY_OUT || raiStatus == utils.COMPANY_STATUS_FORMAL { //试用/正式
  2202. // if tryEndDate != "" {
  2203. // endDateTime, _ := time.Parse(utils.FormatDate, tryEndDate)
  2204. // endDateTime = endDateTime.AddDate(0, 0, 1)
  2205. // sub := endDateTime.Sub(time.Now())
  2206. // if sub < 0 {
  2207. // sub = 0
  2208. // }
  2209. // tryExpireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
  2210. // } else {
  2211. // tryExpireDay = "-"
  2212. // }
  2213. // } else if raiStatus == utils.COMPANY_STATUS_LOSE { //流失
  2214. // tryExpireDay = "-"
  2215. // } else if raiStatus == utils.COMPANY_STATUS_FREEZE { //冻结
  2216. // if item.StartDate != "" && item.EndDate != "" {
  2217. // endDateTime, _ := time.Parse(utils.FormatDate, tryEndDate)
  2218. // endDateTime = endDateTime.AddDate(0, 0, 0)
  2219. // sub := endDateTime.Sub(time.Now())
  2220. // if sub < 0 {
  2221. // sub = 0
  2222. // }
  2223. // tryExpireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
  2224. // } else {
  2225. // tryExpireDay = "-"
  2226. // }
  2227. // } else {
  2228. // tryExpireDay = "-"
  2229. // }
  2230. // }
  2231. // expireDay = ficcExpireDay + "/" + tryExpireDay
  2232. // }
  2233. // }
  2234. // list[i].ExpireDay = expireDay
  2235. //
  2236. // //按钮显示控制
  2237. // btnItem := new(company.ButtonPermission)
  2238. // if item.CompanyId != 1 {
  2239. // *btnItem = services.GetCompanyPermissionButton(roleTypeCode, itemStatus, item.GroupIds, item.GroupIds, item.GroupId, sysUser.GroupId, item.SellerId, sysUser.AdminId, sysUser.Authority, item.ProductId)
  2240. // }
  2241. // list[i].BtnItem = btnItem
  2242. // if item.FreezeStartDate != "" && item.FreezeEndDate != "" && item.Status == utils.COMPANY_STATUS_FREEZE {
  2243. // freezeEndDate, _ := time.Parse(utils.FormatDate, item.FreezeEndDate)
  2244. // if time.Now().Before(freezeEndDate) {
  2245. // expireDays := freezeEndDate.Sub(time.Now()).Hours() / 24
  2246. // list[i].FreezeExpireDays = int(expireDays) + 1
  2247. // }
  2248. // }
  2249. // }
  2250. //
  2251. // statusCount, err := company.GetCompanyStatusCount(permissionCondition, permissionPars)
  2252. // if err != nil {
  2253. // br.Msg = "获取失败"
  2254. // br.ErrMsg = "获取状态数量失败,Err:" + err.Error()
  2255. // return
  2256. // }
  2257. //
  2258. // statusMap := make(map[string]int, 0)
  2259. // var totalCount int
  2260. // for _, sv := range statusCount {
  2261. // totalCount = totalCount + sv.Count
  2262. // statusMap[sv.Status] = sv.Count
  2263. // }
  2264. //
  2265. // lossItem, err := company.GetCompanyStatusLoseCount(lossCondition, lossPars)
  2266. // if err != nil {
  2267. // br.Msg = "获取失败"
  2268. // br.ErrMsg = "获取流失状态数量失败,Err:" + err.Error()
  2269. // return
  2270. // }
  2271. // totalCount = totalCount + lossItem.Count
  2272. //
  2273. // freezeItem, err := company.GetCompanyStatusFreezeCount(freezeCondition, freezePars)
  2274. // if err != nil {
  2275. // br.Msg = "获取失败"
  2276. // br.ErrMsg = "获取冻结状态数量失败,Err:" + err.Error()
  2277. // return
  2278. // }
  2279. // statusMap["冻结"] = freezeItem.Count
  2280. // totalCount = totalCount + freezeItem.Count
  2281. //
  2282. // forverItem, err := company.GetCompanyStatusForverCount(forverCondition, forverPars)
  2283. // if err != nil {
  2284. // br.Msg = "获取失败"
  2285. // br.ErrMsg = "获取永续状态数量失败,Err:" + err.Error()
  2286. // return
  2287. // }
  2288. // totalCount = totalCount + forverItem.Count
  2289. //
  2290. // for _, v := range statusArr {
  2291. // statusCount := new(company.CompanyStatus)
  2292. // if v == "全部" {
  2293. // statusCount.Status = "全部"
  2294. // statusCount.Count = totalCount
  2295. // } else if v == utils.COMPANY_STATUS_LOSE {
  2296. // statusCount.Status = v
  2297. // statusCount.Count = lossItem.Count
  2298. // } else if v == utils.COMPANY_STATUS_FOREVER {
  2299. // statusCount.Status = v
  2300. // statusCount.Count = forverItem.Count
  2301. // //} else if v == utils.COMPANY_STATUS_FREEZE {
  2302. // // statusCount.Status = v
  2303. // // statusCount.Count = freezeItem.Count
  2304. // //}
  2305. // } else {
  2306. // statusCount.Status = v
  2307. // if val, ok := statusMap[v]; ok {
  2308. // statusCount.Count = val
  2309. // }
  2310. // }
  2311. // statusItems = append(statusItems, statusCount)
  2312. // }
  2313. //
  2314. // companyLists := make([]*company.CompanyListItem, 0)
  2315. // //查询阅读次数
  2316. // if list == nil {
  2317. // companyLists = make([]*company.CompanyListItem, 0)
  2318. // } else {
  2319. // for _, v := range list {
  2320. // viewTotal := GetviewTotal(v.CompanyId)
  2321. // companyList := &company.CompanyListItem{
  2322. // CompanyId: v.CompanyId,
  2323. // CompanyName: v.CompanyName,
  2324. // CreditCode: v.CreditCode,
  2325. // CompanyCode: v.CompanyCode,
  2326. // StartDate: v.StartDate,
  2327. // EndDate: v.EndDate,
  2328. // LoseReason: v.LoseReason,
  2329. // RenewalReason: v.RenewalReason,
  2330. // FreezeReason: v.FreezeReason,
  2331. // LossTime: v.LossTime,
  2332. // Status: v.Status,
  2333. // CompanyType: v.CompanyType,
  2334. // ApproveStatus: v.ApproveStatus,
  2335. // SellerName: v.SellerName,
  2336. // SellerId: v.SellerId,
  2337. // SellerIds: v.SellerIds,
  2338. // ExpireDay: v.ExpireDay,
  2339. // FreezeTime: v.FreezeTime,
  2340. // GroupId: v.GroupId,
  2341. // GroupIds: v.GroupIds,
  2342. // DepartmentId: v.DepartmentId,
  2343. // IndustryName: v.IndustryName,
  2344. // IsSuspend: v.IsSuspend,
  2345. // CreatedTime: v.CreatedTime,
  2346. // Source: v.Source,
  2347. // Province: v.Province,
  2348. // City: v.City,
  2349. // Address: v.Address,
  2350. // Reasons: v.Reasons,
  2351. // FreezeStartDate: v.FreezeStartDate,
  2352. // FreezeEndDate: v.FreezeEndDate,
  2353. // FreezeExpireDays: v.FreezeExpireDays,
  2354. // BtnItem: v.BtnItem,
  2355. // ProductId: v.ProductId,
  2356. // FormalTime: v.FormalTime,
  2357. // IsShared: v.IsShared,
  2358. // RegionType: v.RegionType,
  2359. // FiccView: viewTotal[0],
  2360. // RaiView: viewTotal[1],
  2361. // }
  2362. // companyLists = append(companyLists, companyList)
  2363. // }
  2364. // }
  2365. // if companyLists == nil {
  2366. // companyLists = make([]*company.CompanyListItem, 0)
  2367. // }
  2368. // page = paging.GetPaging(currentIndex, pageSize, total)
  2369. // resp.List = companyLists
  2370. // resp.StatusCount = statusItems
  2371. // resp.Paging = page
  2372. // br.Ret = 200
  2373. // br.Success = true
  2374. // br.Msg = "获取成功"
  2375. // br.Data = resp
  2376. //}
  2377. func GetviewTotal(companyId int) (view []int) {
  2378. list, err := company.GetCompanyUserListById(companyId)
  2379. if err != nil {
  2380. fmt.Println("GetCompanyUserList err:", err.Error())
  2381. return
  2382. }
  2383. //获取企业客户信息
  2384. companyInfo, err := company.GetCompanyById(companyId)
  2385. if err != nil {
  2386. fmt.Println("GetCompanyById err:", err.Error())
  2387. return
  2388. }
  2389. var ficcViewTotal, cygxViewTotal int
  2390. lenList := len(list)
  2391. if lenList > 0 {
  2392. userIdSlice := make([]string, 0)
  2393. mobilesSlice := make([]string, 0)
  2394. emailsSlice := make([]string, 0)
  2395. for _, v := range list {
  2396. userIdSlice = append(userIdSlice, strconv.Itoa(int(v.UserId)))
  2397. if v.Mobile != "" {
  2398. mobilesSlice = append(mobilesSlice, v.Mobile)
  2399. } else if v.Email != "" {
  2400. emailsSlice = append(emailsSlice, v.Email)
  2401. }
  2402. }
  2403. //用户浏览数据
  2404. mobileStr := strings.Join(mobilesSlice, "','")
  2405. mobileStr = "'" + mobileStr + "'"
  2406. emailStr := strings.Join(emailsSlice, "','")
  2407. emailStr = "'" + emailStr + "'"
  2408. //报告统计删除晨报部分统计加入每日资讯 2021-4-9
  2409. //手机号
  2410. userViewMobileTotalMap := make(map[string]*models.UserViewMobileTotalSlice)
  2411. userReportViewMobileTotalMap := make(map[string]*models.ReportViewMobileRecord)
  2412. userAdvisoryViewMobileTotalMap := make(map[string]*advisory.UserViewMobileTotalSlice)
  2413. userCygxArticleHistoryRecordViewMobileTotalMap := make(map[string]*models.UserViewMobileTotalSlice)
  2414. if len(mobilesSlice) > 0 {
  2415. //权益数据
  2416. rightsItems, err := company.GetRightsReportListByMobile(mobileStr)
  2417. if err != nil {
  2418. fmt.Println("GetRightsReportListByMobile err:", err.Error())
  2419. return
  2420. }
  2421. cygxViewTotal = len(rightsItems)
  2422. //FICC数据
  2423. ficcItems, err := company.GetFiccReportListByMobile(mobileStr)
  2424. if err != nil {
  2425. fmt.Println("GetFiccReportListByMobile err:", err.Error())
  2426. return
  2427. }
  2428. ficcViewTotal = len(ficcItems)
  2429. }
  2430. //邮箱
  2431. userViewEmailTotalMap := make(map[string]*models.UserViewEmailTotalSlice)
  2432. userReportViewEmailTotalMap := make(map[string]*models.ReportViewEmailRecord)
  2433. userAdvisoryViewEmailTotalMap := make(map[string]*advisory.UserViewEmailTotalSlice)
  2434. userCygxViewEmailTotalMap := make(map[string]*models.UserViewEmailTotalSlice)
  2435. if len(emailsSlice) > 0 {
  2436. //FICC数据
  2437. ficcItems, err := company.GetFiccReportListByEmail(emailStr)
  2438. if err != nil {
  2439. fmt.Println("GetFiccReportListByEmail err:", err.Error())
  2440. return
  2441. }
  2442. ficcViewTotal += len(ficcItems)
  2443. //权益数据
  2444. rightsItems, err := company.GetRightsReportListByEmail(emailStr)
  2445. if err != nil {
  2446. fmt.Println("GetViewReportListByMobile err:", err.Error())
  2447. return
  2448. }
  2449. cygxViewTotal += len(rightsItems)
  2450. }
  2451. for i := 0; i < lenList; i++ {
  2452. item := list[i]
  2453. //企业名称
  2454. list[i].CompanyName = companyInfo.CompanyName
  2455. //手机号用户累计浏览次数
  2456. if userView, ok := userViewMobileTotalMap[item.Mobile]; ok {
  2457. list[i].ViewTotal += userView.Total
  2458. }
  2459. //邮箱用户累计浏览次数
  2460. if userView, ok := userViewEmailTotalMap[item.Email]; ok {
  2461. //总共浏览的报表数据需要调整为(手机号用户浏览晨报数+邮箱号用户浏览晨报数)
  2462. list[i].ViewTotal += userView.Total
  2463. }
  2464. if item.OpenId != "" {
  2465. list[i].IsRegister = true
  2466. } else {
  2467. if item.RegisterPlatform == 2 {
  2468. if item.Mobile != "" || item.Email != "" {
  2469. list[i].IsRegister = true
  2470. }
  2471. } else if item.RegisterTime != "" {
  2472. list[i].IsRegister = true
  2473. } else {
  2474. list[i].IsRegister = false
  2475. }
  2476. }
  2477. //如果存在手机号用户日评数据,那么需要做处理
  2478. if reportView, ok := userReportViewMobileTotalMap[item.Mobile]; ok {
  2479. //对日评数据做校验,日评时间晚于晨报时间,那么将最近一次浏览时间替换
  2480. if reportView.LastViewTime.After(list[i].LastViewTime) {
  2481. list[i].LastViewTime = reportView.LastViewTime
  2482. list[i].LastViewTimeStr = reportView.LastViewTime.Format(utils.FormatDateTime)
  2483. }
  2484. //总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数)
  2485. list[i].ViewTotal += reportView.ViewTotal
  2486. }
  2487. //如果存在手机号用户日评数据,那么需要做处理
  2488. if reportView, ok := userReportViewEmailTotalMap[item.Email]; ok {
  2489. //对日评数据做校验,日评时间晚于晨报时间,那么将最近一次浏览时间替换
  2490. if reportView.LastViewTime.After(list[i].LastViewTime) {
  2491. list[i].LastViewTime = reportView.LastViewTime
  2492. list[i].LastViewTimeStr = reportView.LastViewTime.Format(utils.FormatDateTime)
  2493. }
  2494. //总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数)
  2495. list[i].ViewTotal += reportView.ViewTotal
  2496. }
  2497. //如果存在手机号用户每日资讯,那么需要做处理
  2498. if advisoryView, ok := userAdvisoryViewMobileTotalMap[item.Mobile]; ok {
  2499. //fmt.Println("蝴蝶眨几次眼睛")
  2500. //对每日资讯数据做校验,每日资讯时间晚日评报时间,那么将最近一次浏览时间替换
  2501. if advisoryView.CreatedTime.After(list[i].LastViewTime) {
  2502. list[i].LastViewTime = advisoryView.CreatedTime
  2503. list[i].LastViewTimeStr = advisoryView.CreatedTime.Format(utils.FormatDateTime)
  2504. }
  2505. //总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数+每日资讯数)
  2506. list[i].ViewTotal += advisoryView.Total
  2507. }
  2508. //如果存在邮箱号用户每日资讯,那么需要做处理
  2509. if advisoryView, ok := userAdvisoryViewEmailTotalMap[item.Email]; ok {
  2510. //对每日资讯数据做校验,每日资讯时间晚日评报时间,那么将最近一次浏览时间替换
  2511. if advisoryView.CreatedTime.After(list[i].LastViewTime) {
  2512. list[i].LastViewTime = advisoryView.CreatedTime
  2513. list[i].LastViewTimeStr = advisoryView.CreatedTime.Format(utils.FormatDateTime)
  2514. }
  2515. //总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数+每日资讯数)
  2516. list[i].ViewTotal += advisoryView.Total
  2517. }
  2518. ficcViewTotal += list[i].ViewTotal
  2519. //如果存在手机号用户查研观向,那么需要做处理
  2520. if cygxView, ok := userCygxArticleHistoryRecordViewMobileTotalMap[item.Mobile]; ok {
  2521. //对每日资讯数据做校验,每日资讯时间晚日评报时间,那么将最近一次浏览时间替换
  2522. if cygxView.CreatedTime.After(list[i].LastViewTime) {
  2523. list[i].LastViewTime = cygxView.CreatedTime
  2524. list[i].LastViewTimeStr = cygxView.CreatedTime.Format(utils.FormatDateTime)
  2525. }
  2526. //总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数+每日资讯数+查研观向)
  2527. cygxViewTotal += cygxView.Total
  2528. list[i].ViewTotal += cygxView.Total
  2529. }
  2530. //如果存在邮箱号用户查研观向,那么需要做处理
  2531. if cygxView, ok := userCygxViewEmailTotalMap[item.Email]; ok {
  2532. //对每日资讯数据做校验,每日资讯时间晚日评报时间,那么将最近一次浏览时间替换
  2533. if cygxView.CreatedTime.After(list[i].LastViewTime) {
  2534. list[i].LastViewTime = cygxView.CreatedTime
  2535. list[i].LastViewTimeStr = cygxView.CreatedTime.Format(utils.FormatDateTime)
  2536. }
  2537. //总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数+每日资讯数+查研观向)
  2538. cygxViewTotal += cygxView.Total
  2539. //list[i].ViewTotal += cygxView.Total
  2540. }
  2541. /*if reportView, ok := userReportViewTotalMap[int(item.UserId)]; ok {
  2542. //对日评数据做校验,日评时间晚于晨报时间,那么将最近一次浏览时间替换
  2543. if reportView.LastViewTime.After(list[i].LastViewTime) {
  2544. list[i].LastViewTime = reportView.LastViewTime
  2545. list[i].LastViewTimeStr = reportView.LastViewTime.Format(utils.FormatDateTime)
  2546. }
  2547. //总共浏览的报表数据需要调整为(浏览晨报数+浏览日评数)
  2548. list[i].ViewTotal += reportView.ViewTotal
  2549. }*/
  2550. }
  2551. }
  2552. view = append(view, ficcViewTotal)
  2553. view = append(view, cygxViewTotal)
  2554. return
  2555. }
  2556. // @Title 新增客户
  2557. // @Description 新增客户接口
  2558. // @Param request body company.CompanyAddReq true "type json string"
  2559. // @Success 200 {object} company.CompanyAddResp
  2560. // @router /add [post]
  2561. func (this *CompanyController) Add() {
  2562. br := new(models.BaseResponse).Init()
  2563. defer func() {
  2564. this.Data["json"] = br
  2565. this.ServeJSON()
  2566. }()
  2567. sysUser := this.SysUser
  2568. if sysUser == nil {
  2569. br.Msg = "请登录"
  2570. br.ErrMsg = "请登录,SysUser Is Empty"
  2571. br.Ret = 408
  2572. return
  2573. }
  2574. roleTypeCode := sysUser.RoleTypeCode
  2575. var req company.CompanyAddReq
  2576. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  2577. if err != nil {
  2578. br.Msg = "参数解析异常!"
  2579. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2580. return
  2581. }
  2582. if req.CompanyName == "" {
  2583. br.Msg = "请填写客户名称"
  2584. return
  2585. }
  2586. if req.CreditCode == "" {
  2587. br.Msg = "请填写社会统一信用码"
  2588. return
  2589. }
  2590. if req.Status == "" {
  2591. br.Msg = "客户状态不可为空"
  2592. return
  2593. }
  2594. //移除空格
  2595. req.CreditCode = utils.TrimStr(req.CreditCode)
  2596. var startDateTime, endDateTime time.Time
  2597. if req.Status == utils.COMPANY_STATUS_TRY_OUT {
  2598. startDateTime = time.Now()
  2599. endDateTime = time.Now().AddDate(0, 2, 0)
  2600. } else if req.Status == utils.COMPANY_STATUS_FOREVER {
  2601. startDateTime = time.Now()
  2602. endDateTime = time.Now().AddDate(100, 0, 0)
  2603. } else {
  2604. br.Msg = "无效的客户状态,请重新选择"
  2605. return
  2606. }
  2607. var startDate, endDate string
  2608. startDate = startDateTime.Format(utils.FormatDate)
  2609. endDate = endDateTime.Format(utils.FormatDate)
  2610. if req.CompanyType == "" {
  2611. br.Msg = "请选择客户类型"
  2612. return
  2613. }
  2614. var productId int
  2615. var productName string
  2616. if req.CompanyType == utils.COMPANY_PRODUCT_FICC_NAME {
  2617. productId = utils.COMPANY_PRODUCT_FICC_ID
  2618. productName = utils.COMPANY_PRODUCT_FICC_NAME
  2619. } else if req.CompanyType == utils.COMPANY_PRODUCT_RAI_NAME {
  2620. productId = utils.COMPANY_PRODUCT_RAI_ID
  2621. productName = utils.COMPANY_PRODUCT_RAI_NAME
  2622. } else {
  2623. br.Msg = "无效的客户类型,请重新选择"
  2624. return
  2625. }
  2626. if req.IndustryId <= 0 {
  2627. br.Msg = "请选择行业"
  2628. return
  2629. }
  2630. if req.SellsId <= 0 {
  2631. br.Msg = "请选择所属销售"
  2632. return
  2633. }
  2634. //if req.Reasons == "" {
  2635. // br.Msg = "请填写新增理由"
  2636. // return
  2637. //}
  2638. if req.PermissionIds == "" {
  2639. br.Msg = "请选择权限"
  2640. return
  2641. } else {
  2642. permissionStr, err := company.GetPermissionIdById(req.PermissionIds)
  2643. if err != nil {
  2644. br.Msg = "获取信息失败"
  2645. br.ErrMsg = "获取主观客观权限信息失败,Err:" + err.Error()
  2646. return
  2647. }
  2648. req.PermissionIds = permissionStr
  2649. }
  2650. industry, err := company.GetCompanyIndustryById(req.IndustryId)
  2651. if err != nil {
  2652. br.Msg = "获取行业信息失败"
  2653. br.ErrMsg = "获取行业信息失败,Err:" + err.Error()
  2654. return
  2655. }
  2656. if industry == nil {
  2657. br.Msg = "行业信息不存在"
  2658. return
  2659. }
  2660. //判断客户是否已经存在
  2661. companyNameIsExist, err := company.GetCompanyCountByCompanyName(req.CompanyName)
  2662. if err != nil {
  2663. br.Msg = "判断客户是否存在失败"
  2664. br.ErrMsg = "判断客户是否存在失败,Err:" + err.Error()
  2665. return
  2666. }
  2667. if companyNameIsExist > 0 {
  2668. br.Msg = "客户已存在,请重新输入客户名称"
  2669. return
  2670. }
  2671. //判断客户是否已经存在
  2672. companyCreditCodeIsExist, err := company.GetCompanyCountByCreditCode(req.CreditCode)
  2673. if err != nil {
  2674. br.Msg = "判断客户是否存在失败"
  2675. br.ErrMsg = "判断客户是否存在失败,Err:" + err.Error()
  2676. return
  2677. }
  2678. if companyCreditCodeIsExist > 0 {
  2679. br.Msg = "客户已存在,统一社会信用代码"
  2680. return
  2681. }
  2682. seller, err := system.GetSysAdminById(req.SellsId)
  2683. if err != nil {
  2684. br.Msg = "获取销售信息失败"
  2685. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  2686. return
  2687. }
  2688. tryOutCount, err := company.GetCompanyTryOutCount(utils.COMPANY_STATUS_TRY_OUT, seller.AdminId)
  2689. if err != nil {
  2690. br.Msg = "判断试用客户量失败"
  2691. br.ErrMsg = "判断试用客户量失败,Err:" + err.Error()
  2692. return
  2693. }
  2694. /*
  2695. ROLE_TYPE_CODE_ADMIN = "admin" //管理员
  2696. ROLE_TYPE_CODE_FICC_ADMIN = "ficc_admin" //ficc管理员
  2697. ROLE_TYPE_CODE_FICC_SELLER = "ficc_seller" //ficc销售
  2698. ROLE_TYPE_CODE_RAI_ADMIN = "rai_admin" //权益管理员
  2699. ROLE_TYPE_CODE_RAI_SELLER = "rai_seller" //权益销售
  2700. ROLE_TYPE_CODE_FICC_GROUP = "ficc_group" //ficc组长
  2701. ROLE_TYPE_CODE_RAI_GROUP = "rai_group" //ficc组长
  2702. ROLE_TYPE_CODE_FICC_DEPARTMENT = "ficc_department" //ficc部门经理
  2703. ROLE_TYPE_CODE_RAI_DEPARTMENT = "rai_department" //权益部门经理
  2704. ROLE_TYPE_CODE_FICC_RESEARCHR = "ficc_researcher" //ficc研究员
  2705. ROLE_TYPE_CODE_RAI_RESEARCHR = "rai_researcher" //权益研究员
  2706. */
  2707. if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_FICC_DEPARTMENT ||
  2708. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER || roleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
  2709. if tryOutCount >= utils.COMPANY_STATUS_TRY_OUT_COUNT {
  2710. br.Msg = "您的试用客户总数,已超过上限,不可继续新增"
  2711. return
  2712. }
  2713. }
  2714. // 每个权益销售手中的试用客户最多30个
  2715. if productId == utils.COMPANY_PRODUCT_RAI_ID && tryOutCount >= utils.COMPANY_STATUS_TRY_OUT_COUNT_RAI {
  2716. br.Msg = "您的试用客户总数,已超过上限,不可继续新增"
  2717. return
  2718. }
  2719. if seller == nil {
  2720. br.Msg = "所属销售不存在"
  2721. return
  2722. }
  2723. companyCode, err := company.GetCompanyCode()
  2724. if err != nil {
  2725. br.Msg = "获取客户编码信息失败"
  2726. br.ErrMsg = "获取客户编码信息失败,Err:" + err.Error()
  2727. return
  2728. }
  2729. item := new(company.Company)
  2730. item.CompanyName = req.CompanyName
  2731. item.CreditCode = req.CreditCode
  2732. item.CompanyCode = companyCode
  2733. item.Province = req.Province
  2734. item.City = req.City
  2735. item.Address = req.Province + req.City
  2736. item.StartDate = time.Now().Format(utils.FormatDate)
  2737. if req.Status == utils.COMPANY_STATUS_FOREVER {
  2738. item.EndDate = time.Now().AddDate(100, 0, 0).Format(utils.FormatDate)
  2739. item.CompanyType = 5
  2740. }
  2741. if req.Status == utils.COMPANY_STATUS_TRY_OUT {
  2742. item.EndDate = time.Now().AddDate(0, 2, 0).Format(utils.FormatDate)
  2743. item.CompanyType = 2
  2744. }
  2745. item.FirstStartDate = item.StartDate
  2746. item.FirstEndDate = item.EndDate
  2747. item.CreatedTime = time.Now()
  2748. item.LastUpdatedTime = time.Now()
  2749. item.Enabled = 1
  2750. item.RegionType = req.RegionType
  2751. item.Remark = req.Reasons
  2752. item.Nation = req.Nation
  2753. item.OverseasStatus = "试用"
  2754. item.ResetBtn = 1
  2755. companyId, err := company.AddCompany(item)
  2756. if err != nil {
  2757. br.Msg = "新增失败"
  2758. br.ErrMsg = "新增失败,err:" + err.Error()
  2759. return
  2760. }
  2761. item.CompanyId = int(companyId)
  2762. //生成第三方code编号
  2763. item.OpenCompanyCode = services.GenerateOpenCompanyCode(int(companyId))
  2764. item.Update([]string{"OpenCompanyCode"})
  2765. if req.UserId > 0 {
  2766. //修改联系人
  2767. err = company.ModifyCompanyUserCompanyId(req.UserId, int(companyId))
  2768. if err != nil {
  2769. br.Msg = "新增失败"
  2770. br.ErrMsg = "新增失败,ModifyCompanyUserCompanyId err:" + err.Error()
  2771. return
  2772. }
  2773. //获取联系人详情
  2774. userInfo, err := models.GetWxUserByUserId(req.UserId)
  2775. if err != nil {
  2776. br.Msg = "获取联系人异常!"
  2777. br.ErrMsg = "获取联系人异常,Err:" + err.Error()
  2778. return
  2779. }
  2780. //添加该联系人 与 当前销售的关系
  2781. models.AddUserSellerRelation(int64(req.UserId), int(companyId), seller.AdminId, productId, seller.RealName, userInfo.Mobile, userInfo.Email)
  2782. }
  2783. companyProduct := new(company.CompanyProduct)
  2784. companyProduct.CompanyId = int(companyId)
  2785. companyProduct.ProductId = productId
  2786. companyProduct.ProductName = productName
  2787. companyProduct.CompanyName = req.CompanyName
  2788. companyProduct.Source = req.Source
  2789. companyProduct.Reasons = req.Reasons
  2790. companyProduct.Status = req.Status
  2791. companyProduct.StartDate = startDate
  2792. companyProduct.EndDate = endDate
  2793. companyProduct.IndustryId = req.IndustryId
  2794. companyProduct.IndustryName = industry.IndustryName
  2795. companyProduct.SellerId = seller.AdminId
  2796. companyProduct.SellerName = seller.RealName
  2797. companyProduct.GroupId = seller.GroupId
  2798. companyProduct.DepartmentId = seller.DepartmentId
  2799. companyProduct.IsSuspend = 0
  2800. companyProduct.CreateTime = time.Now()
  2801. companyProduct.ModifyTime = time.Now()
  2802. companyProduct.CompanyType = req.CompanyType
  2803. companyProduct.Scale = req.Scale
  2804. companyProduct.OpenCode = services.GenerateOpenCompanyProductCode(int(companyId), productId)
  2805. companyProduct.TodoStatus = "无任务"
  2806. companyProduct.TryStage = 1
  2807. companyProduct.OverseasLabel = 1
  2808. if seller.Mobile == "13065778668" {
  2809. if req.RegionType == "海外" {
  2810. companyProduct.IsOverseas = 0
  2811. } else {
  2812. companyProduct.IsOverseas = 1
  2813. }
  2814. }
  2815. if productId == utils.COMPANY_PRODUCT_RAI_ID && req.Status == utils.COMPANY_STATUS_FOREVER { // 权益的永续客户给一个状态初始化的记录
  2816. companyProduct.InitStatus = req.Status
  2817. }
  2818. companyProductId, err := company.AddCompanyProduct(companyProduct)
  2819. if err != nil {
  2820. br.Msg = "新增失败"
  2821. br.ErrMsg = "新增客户产品失败,err:" + err.Error()
  2822. return
  2823. }
  2824. companyReportPermissionList, err := services.AddCompanyPermission(int(companyId), seller.AdminId, productId, productName, seller.RealName, req.PermissionIds, startDate, endDate)
  2825. if err != nil {
  2826. br.Msg = "新增失败"
  2827. br.ErrMsg = "新增客户设置权限失败,err:" + err.Error()
  2828. return
  2829. }
  2830. {
  2831. record := new(company.CompanyOperationRecord)
  2832. record.CompanyId = int(companyId)
  2833. record.CompanyName = req.CompanyName
  2834. record.SellerId = seller.AdminId
  2835. record.SysUserId = seller.AdminId
  2836. record.SysRealName = seller.RealName
  2837. record.Remark = "新增客户"
  2838. record.Operation = "add"
  2839. record.CreateTime = time.Now()
  2840. record.ProductId = productId
  2841. record.ProductName = productName
  2842. record.Status = req.Status
  2843. _, err = company.AddCompanyOperationRecord(record)
  2844. if err != nil {
  2845. go alarm_msg.SendAlarmMsg("URI:"+this.Ctx.Input.URI()+"<br/> "+";<br/> Body:"+err.Error(), 3)
  2846. //go utils.SendEmail(utils.APPNAME+"失败提醒"+utils.RunMode, "URI:"+this.Ctx.Input.URI()+"<br/> "+";<br/> Body:"+err.Error(), utils.EmailSendToUsers)
  2847. }
  2848. }
  2849. //新增客户日志
  2850. {
  2851. companyLog := new(company.CompanyLog)
  2852. companyLog.CompanyId = int(companyId)
  2853. companyLog.CompanyName = req.CompanyName
  2854. companyLog.CreditCode = req.CreditCode
  2855. companyLog.CompanyCode = companyCode
  2856. companyLog.Sort = item.Sort
  2857. companyLog.IsFeeCustomer = item.IsFeeCustomer
  2858. companyLog.Country = item.Country
  2859. companyLog.Address = item.Address
  2860. companyLog.City = item.City
  2861. companyLog.Province = item.Province
  2862. companyLog.Enabled = item.Enabled
  2863. companyLog.CreatedTime = item.CreatedTime
  2864. companyLog.LastUpdatedTime = item.LastUpdatedTime
  2865. companyLog.Seller = item.Seller
  2866. companyLog.SellsId = item.SellsId
  2867. companyLog.CompanyBelong = item.CompanyBelong
  2868. companyLog.StartDate = item.StartDate
  2869. companyLog.EndDate = item.EndDate
  2870. companyLog.FirstStartDate = item.FirstStartDate
  2871. companyLog.FirstEndDate = item.FirstEndDate
  2872. companyLog.DateType = item.DateType
  2873. companyLog.AdminId = this.SysUser.AdminId
  2874. companyLog.LogType = "add"
  2875. companyLog.LogCreateTime = time.Now()
  2876. go company.AddCompanyLog(companyLog)
  2877. }
  2878. //新增客户产品日志
  2879. {
  2880. productLog := new(company.CompanyProductLog)
  2881. productLog.CompanyProductId = int(companyProductId)
  2882. productLog.CompanyId = companyProduct.CompanyId
  2883. productLog.ProductId = companyProduct.ProductId
  2884. productLog.ProductName = companyProduct.ProductName
  2885. productLog.CompanyName = companyProduct.CompanyName
  2886. productLog.CompanyName = companyProduct.CompanyName
  2887. productLog.Source = companyProduct.Source
  2888. productLog.Reasons = companyProduct.Reasons
  2889. productLog.Status = companyProduct.Status
  2890. productLog.IndustryId = companyProduct.IndustryId
  2891. productLog.IndustryName = companyProduct.IndustryName
  2892. productLog.SellerId = companyProduct.SellerId
  2893. productLog.SellerName = companyProduct.SellerName
  2894. productLog.GroupId = companyProduct.GroupId
  2895. productLog.DepartmentId = companyProduct.DepartmentId
  2896. productLog.IsSuspend = companyProduct.IsSuspend
  2897. productLog.SuspendTime = companyProduct.SuspendTime
  2898. productLog.ApproveStatus = companyProduct.ApproveStatus
  2899. productLog.FreezeTime = companyProduct.FreezeTime
  2900. productLog.Remark = companyProduct.Remark
  2901. productLog.StartDate = companyProduct.StartDate
  2902. productLog.EndDate = companyProduct.EndDate
  2903. productLog.CreateTime = companyProduct.CreateTime
  2904. productLog.ModifyTime = companyProduct.ModifyTime
  2905. productLog.LoseReason = companyProduct.LoseReason
  2906. productLog.LossTime = companyProduct.LossTime
  2907. productLog.LogType = "add"
  2908. productLog.LogCreateTime = time.Now()
  2909. productLog.AdminId = this.SysUser.AdminId
  2910. productLog.Scale = companyProduct.Scale
  2911. go company.AddCompanyProductLog(productLog)
  2912. }
  2913. //新增客户产品状态变更日志
  2914. {
  2915. companyProductUpdateLog := &company.CompanyProductUpdateLog{
  2916. Id: 0,
  2917. CompanyId: companyProduct.CompanyId,
  2918. ProductId: companyProduct.ProductId,
  2919. Status: "试用",
  2920. Source: "add",
  2921. SellerId: companyProduct.SellerId,
  2922. SellerName: companyProduct.SellerName,
  2923. StartDate: startDateTime,
  2924. EndDate: endDateTime,
  2925. RealEndDate: startDateTime,
  2926. CreateTime: time.Now(),
  2927. }
  2928. go company.AddCompanyProductUpdateLog(companyProductUpdateLog)
  2929. companyProductTryOutUpdateLog := &company.CompanyProductTryOutUpdateLog{
  2930. Id: 0,
  2931. CompanyId: companyProduct.CompanyId,
  2932. ProductId: companyProduct.ProductId,
  2933. Source: "add",
  2934. SellerId: companyProduct.SellerId,
  2935. SellerName: companyProduct.SellerName,
  2936. StartDate: startDateTime,
  2937. EndDate: endDateTime,
  2938. RealEndDate: startDateTime,
  2939. IsStop: 0,
  2940. CreateTime: time.Now(),
  2941. }
  2942. go company.AddCompanyProductTryOutUpdateLog(companyProductTryOutUpdateLog, companyReportPermissionList)
  2943. }
  2944. resp := new(company.CompanyAddResp)
  2945. resp.CompanyId = int(companyId)
  2946. br.Ret = 200
  2947. br.Success = true
  2948. br.Msg = "新增成功"
  2949. br.Data = resp
  2950. }
  2951. // Detail
  2952. // @Title 获取客户详情
  2953. // @Description 获取客户详情接口
  2954. // @Param CompanyId query int true "客户id"
  2955. // @Success 200 {object} company.CompanyDetailResp
  2956. // @router /detail [get]
  2957. func (this *CompanyController) Detail() {
  2958. br := new(models.BaseResponse).Init()
  2959. defer func() {
  2960. this.Data["json"] = br
  2961. this.ServeJSON()
  2962. }()
  2963. sysUser := this.SysUser
  2964. if sysUser == nil {
  2965. br.Msg = "请登录"
  2966. br.ErrMsg = "请登录,SysUser Is Empty"
  2967. br.Ret = 408
  2968. return
  2969. }
  2970. companyId, _ := this.GetInt("CompanyId")
  2971. if companyId <= 0 {
  2972. br.Msg = "参数错误"
  2973. br.ErrMsg = "客户参数小于等于0"
  2974. return
  2975. }
  2976. // CRM8.8-是否为编辑页的客户详情
  2977. isEdit, _ := this.GetBool("IsEdit")
  2978. productId := services.GetProductId(sysUser.RoleTypeCode)
  2979. item, err := company.GetCompanyDetailById(companyId)
  2980. if err != nil {
  2981. br.Msg = "获取信息失败"
  2982. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  2983. return
  2984. }
  2985. shareSellerId := 0
  2986. var productItem *company.CompanyProduct
  2987. if productId > 0 {
  2988. var e error
  2989. productItem, e = company.GetCompanyProductByCompanyIdAndProductId(companyId, productId)
  2990. if e != nil && e.Error() != utils.ErrNoRow() {
  2991. br.Msg = "客户信息有误"
  2992. br.ErrMsg = "获取客户信息失败, Err: " + e.Error()
  2993. return
  2994. }
  2995. if productItem != nil {
  2996. shareSellerId = productItem.ShareSellerId
  2997. }
  2998. }
  2999. var productName string
  3000. if productId == 1 {
  3001. productName = utils.COMPANY_PRODUCT_FICC_NAME
  3002. } else if productId == 2 {
  3003. productName = utils.COMPANY_PRODUCT_RAI_NAME
  3004. } else {
  3005. productName = "admin"
  3006. }
  3007. resp := new(company.CompanyDetailResp)
  3008. resp.ProductName = productName
  3009. //获取客户产品
  3010. productList, err := company.GetCompanyProductsByCompanyId(companyId)
  3011. if err != nil {
  3012. br.Msg = "获取信息失败"
  3013. br.ErrMsg = "获取产品信息失败,Err:" + err.Error()
  3014. return
  3015. }
  3016. roleTypeCode := sysUser.RoleTypeCode
  3017. itemLen := len(productList)
  3018. btnDetailItem := new(company.ButtonDetailPermission)
  3019. // 客户权限校验
  3020. {
  3021. // 如果不是超管、ficc管理员、权益管理员,那么需要额外校验下权限
  3022. if !utils.InArrayByStr([]string{utils.ROLE_TYPE_CODE_ADMIN, utils.ROLE_TYPE_CODE_FICC_ADMIN, utils.ROLE_TYPE_CODE_RAI_ADMIN}, sysUser.RoleTypeCode) {
  3023. var isOk bool //是否有权限
  3024. var companyHasProduct bool // 客户当前是否有该产品权限
  3025. for _, productInfo := range productList {
  3026. // 只校验拥有的品种权限:ficc或者权益
  3027. if productInfo.ProductId == productId {
  3028. companyHasProduct = true
  3029. // 自己的客户有权限看
  3030. if productInfo.SellerId == sysUser.AdminId {
  3031. isOk = true
  3032. break
  3033. }
  3034. // 流失客户都有权限看
  3035. if productInfo.Status == utils.COMPANY_STATUS_LOSE || productInfo.Status == utils.COMPANY_STATUS_CLOSE {
  3036. isOk = true
  3037. break
  3038. }
  3039. // 分享的客户 也有权限
  3040. if productItem.IsShare == 1 && productItem.ShareSellerId == sysUser.AdminId {
  3041. isOk = true
  3042. break
  3043. }
  3044. // 如果是组长,且该客户属于本组客户
  3045. if sysUser.Authority == 4 && productInfo.GroupId > 0 && productInfo.GroupId == sysUser.GroupId && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_TEAM {
  3046. isOk = true
  3047. break
  3048. }
  3049. // 如果是ficc主管或者权益主管
  3050. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  3051. // 获取顶级分组Id
  3052. var sysUserGroupPid, productGroupPid int
  3053. // 当前账号的顶级分组id
  3054. {
  3055. sysUserGroupIdpid, err := company.GetParentIdFromGroup(sysUser.GroupId)
  3056. if err != nil && err.Error() != utils.NotEmpty() {
  3057. break
  3058. }
  3059. if sysUserGroupIdpid == nil || *sysUserGroupIdpid == 0 {
  3060. sysUserGroupPid = sysUser.GroupId
  3061. } else {
  3062. sysUserGroupPid = *sysUserGroupIdpid
  3063. }
  3064. }
  3065. // 当前客户的顶级分组id
  3066. {
  3067. groupIdpid, err := company.GetParentIdFromGroup(productInfo.GroupId)
  3068. if err != nil && err.Error() != utils.NotEmpty() {
  3069. break
  3070. }
  3071. if groupIdpid == nil || *groupIdpid == 0 {
  3072. productGroupPid = productInfo.GroupId
  3073. } else {
  3074. productGroupPid = *groupIdpid
  3075. }
  3076. }
  3077. // 如果客户的顶级分组和当前账号分组id一致
  3078. if sysUserGroupPid == productGroupPid {
  3079. isOk = true
  3080. break
  3081. }
  3082. }
  3083. }
  3084. }
  3085. // 客户当前是否有该产品的权限,如果没有的话,说明是在领取客户,允许访问
  3086. if !companyHasProduct {
  3087. isOk = true
  3088. }
  3089. if !isOk {
  3090. br.Msg = "无访问权限"
  3091. return
  3092. }
  3093. }
  3094. }
  3095. //产品权限map
  3096. statusMap := make(map[int]string)
  3097. for i := 0; i < itemLen; i++ {
  3098. item := productList[i]
  3099. //添加产品权限map
  3100. statusMap[item.ProductId] = item.Status
  3101. if i == 0 {
  3102. if item.ProductId == 1 {
  3103. resp.CreateAuth = 1
  3104. } else {
  3105. resp.CreateAuth = 2
  3106. }
  3107. }
  3108. if item.ProductId == 1 {
  3109. if strings.Contains(sysUser.RoleTypeCode, "ficc") {
  3110. if item.Status == utils.COMPANY_STATUS_FREEZE || item.Status == utils.COMPANY_STATUS_LOSE {
  3111. btnDetailItem.BtnHistoryList = true
  3112. } else {
  3113. if item.SellerId == sysUser.AdminId || shareSellerId == sysUser.AdminId {
  3114. btnDetailItem.BtnHistoryList = true
  3115. }
  3116. if sysUser.Authority > 0 {
  3117. if item.GroupId == sysUser.GroupId {
  3118. btnDetailItem.BtnHistoryList = true
  3119. }
  3120. if item.DepartmentId == sysUser.DepartmentId {
  3121. btnDetailItem.BtnHistoryList = true
  3122. }
  3123. }
  3124. }
  3125. }
  3126. // 编辑回显
  3127. allPermissions, e := company.GetPermissionLookItemsByProductId(utils.COMPANY_PRODUCT_FICC_ID)
  3128. if e != nil {
  3129. br.Msg = "获取失败"
  3130. br.ErrMsg = "获取权限信息失败,Err:" + e.Error()
  3131. return
  3132. }
  3133. permissionMap := make(map[int][]*company.PermissionLookItem, 0)
  3134. permissionCheckMap := make(map[int][]int, 0)
  3135. for _, v := range allPermissions {
  3136. if v.ParentId > 0 {
  3137. permissionMap[v.ParentId] = append(permissionMap[v.ParentId], v)
  3138. if v.IsPublic == 1 {
  3139. permissionCheckMap[v.ParentId] = append(permissionCheckMap[v.ParentId], v.ChartPermissionId)
  3140. }
  3141. }
  3142. }
  3143. for _, v := range allPermissions {
  3144. if v.ParentId == 0 {
  3145. checkList := make([]int, 0)
  3146. plist := new(company.PermissionLookList)
  3147. plist.Items = make([]*company.PermissionLookItem, 0)
  3148. plist.ItemsType = make([]*company.PermissionSetItemType, 0)
  3149. items, ok := permissionMap[v.ChartPermissionId]
  3150. if ok {
  3151. for itemK, n := range items {
  3152. permission, err := company.GetCompanyPermissionCheckItem(companyId, n.ChartPermissionId)
  3153. if err != nil && err.Error() != utils.ErrNoRow() {
  3154. br.Msg = "获取失败"
  3155. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  3156. return
  3157. }
  3158. if permission != nil && permission.ChartPermissionId > 0 {
  3159. checkList = append(checkList, n.ChartPermissionId)
  3160. items[itemK].StartDate = permission.StartDate
  3161. items[itemK].EndDate = permission.EndDate
  3162. items[itemK].Status = permission.Status
  3163. endDateTime, _ := time.Parse(utils.FormatDate, permission.EndDate)
  3164. endDateTime = endDateTime.AddDate(0, 0, 1)
  3165. sub := endDateTime.Sub(time.Now())
  3166. if sub < 0 {
  3167. sub = 0
  3168. }
  3169. expireDay := fmt.Sprintf("%v", int(sub.Hours()/24))
  3170. items[itemK].ExpireDay = expireDay
  3171. }
  3172. }
  3173. plist.Items = items
  3174. }
  3175. plist.ClassifyName = v.PermissionName
  3176. plist.CheckList = checkList
  3177. item.PermissionList = append(item.PermissionList, plist)
  3178. }
  3179. }
  3180. resp.FiccItem = item
  3181. if resp.FiccItem.Status == utils.COMPANY_STATUS_FOREVER {
  3182. resp.FiccItem.Status = utils.COMPANY_STATUS_X_CLASS_TRY_OUT
  3183. }
  3184. if (roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER ||
  3185. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP || roleTypeCode == utils.ROLE_TYPE_CODE_FICC_DEPARTMENT) &&
  3186. item.Status == utils.COMPANY_STATUS_TRY_OUT && item.ApproveStatus != "待审批" {
  3187. resp.IsButtonShow = 1
  3188. }
  3189. } else {
  3190. if strings.Contains(sysUser.RoleTypeCode, "rai") {
  3191. if item.Status == utils.COMPANY_STATUS_FREEZE || item.Status == utils.COMPANY_STATUS_LOSE {
  3192. btnDetailItem.BtnHistoryList = true
  3193. } else {
  3194. if item.SellerId == sysUser.AdminId || item.ShareSellerId == sysUser.AdminId {
  3195. btnDetailItem.BtnHistoryList = true
  3196. }
  3197. if sysUser.Authority > 0 {
  3198. if item.GroupId == sysUser.GroupId {
  3199. btnDetailItem.BtnHistoryList = true
  3200. }
  3201. if item.DepartmentId == sysUser.DepartmentId {
  3202. btnDetailItem.BtnHistoryList = true
  3203. }
  3204. }
  3205. }
  3206. }
  3207. // CRM8.8-权益权限列表调用较多、统一进行调整
  3208. plist, e := services.RaiCompanyPermissionAndCheckList(companyId, isEdit, []string{"调研"})
  3209. if e != nil {
  3210. br.Msg = "获取客户权益权限列表信息失败"
  3211. br.ErrMsg = "获取客户权益权限列表信息失败,Err:" + e.Error()
  3212. return
  3213. }
  3214. // cygx8.2专项产业调研展示
  3215. item.SpecialSurplus, err = cygxService.GetSpecialSurplusByCompanyNew(companyId)
  3216. if err != nil {
  3217. br.Msg = "获取失败"
  3218. br.ErrMsg = "获取专项调研信息失败,Err:" + err.Error()
  3219. return
  3220. }
  3221. //研选服务点数
  3222. item.Points = cygxService.GetCygxActivityPointsCompanyByCompanyId(companyId)
  3223. item.PermissionList = append(item.PermissionList, plist)
  3224. resp.RaiItem = item
  3225. if resp.RaiItem.Status == utils.COMPANY_STATUS_FOREVER {
  3226. resp.RaiItem.Status = utils.COMPANY_STATUS_X_CLASS_TRY_OUT
  3227. }
  3228. if (roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER ||
  3229. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP ||
  3230. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_DEPARTMENT) &&
  3231. item.Status == utils.COMPANY_STATUS_TRY_OUT && item.ApproveStatus != "待审批" {
  3232. resp.IsButtonShow = 1
  3233. }
  3234. }
  3235. 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, "")
  3236. //if itemLen > 1 {
  3237. // btnDetailItem.BtnEdit = false
  3238. // btnDetailItem.BtnDelete = false
  3239. //} else {
  3240. // btnDetailItem.BtnEdit = btnItem.BtnEdit
  3241. // btnDetailItem.BtnDelete = btnItem.BtnDelete
  3242. //}
  3243. switch item.ProductId {
  3244. case 1:
  3245. btnDetailItem.FiccEdit = btnItem.BtnEdit
  3246. btnDetailItem.FiccDelete = btnItem.BtnDelete
  3247. case 2:
  3248. btnDetailItem.RaiEdit = btnItem.BtnEdit
  3249. btnDetailItem.RaiDelete = btnItem.BtnDelete
  3250. }
  3251. if !btnDetailItem.BtnEdit {
  3252. btnDetailItem.BtnEdit = btnItem.BtnEdit
  3253. }
  3254. if !btnDetailItem.BtnDelete {
  3255. btnDetailItem.BtnDelete = btnItem.BtnDelete
  3256. }
  3257. //联系人操作权限
  3258. if resp.IsContractButtonShow == false {
  3259. resp.IsContractButtonShow = services.CheckCompanyUserButton(sysUser.RoleTypeCode, item.SellerId, sysUser.AdminId, item.ProductId, shareSellerId, item.Status)
  3260. }
  3261. //校验当前操作员是否具给联系人开通个人研选的权限
  3262. if resp.IsUserYanXuanButtonShow == false {
  3263. resp.IsUserYanXuanButtonShow, err = services.CheckCompanyUserYanXuanButton(sysUser.RoleTypeCode, sysUser.Mobile)
  3264. if err != nil {
  3265. br.Msg = "获取失败"
  3266. br.ErrMsg = "获取专项调研信息失败,Err:" + err.Error()
  3267. return
  3268. }
  3269. }
  3270. }
  3271. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN ||
  3272. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN ||
  3273. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  3274. resp.IsButtonShow = 1
  3275. btnDetailItem.BtnHistoryList = true
  3276. }
  3277. //ficc权限
  3278. if ficcStatus, ok := statusMap[1]; ok {
  3279. if ficcStatus == utils.COMPANY_STATUS_TRY_OUT {
  3280. if raiStatus, ok := statusMap[2]; ok {
  3281. //另一个权限也是 试用 、冻结、流失
  3282. if raiStatus == utils.COMPANY_STATUS_TRY_OUT || raiStatus == utils.COMPANY_STATUS_FREEZE || raiStatus == utils.COMPANY_STATUS_LOSE {
  3283. //那么超管、部门管理员、销售可以编辑
  3284. if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER || roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3285. btnDetailItem.BaseInfoEdit = true
  3286. }
  3287. }
  3288. //权益是永续时,超管可编辑基础信息
  3289. if raiStatus == utils.COMPANY_STATUS_FOREVER {
  3290. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3291. btnDetailItem.BaseInfoEdit = true
  3292. }
  3293. }
  3294. } else {
  3295. //权限未开,有编辑基础信息权限
  3296. btnDetailItem.BaseInfoEdit = true
  3297. }
  3298. }
  3299. if ficcStatus == utils.COMPANY_STATUS_FOREVER {
  3300. if raiStatus, ok := statusMap[2]; ok {
  3301. //另一个权限也是 永续 、冻结、流失
  3302. if raiStatus == utils.COMPANY_STATUS_TRY_OUT || raiStatus == utils.COMPANY_STATUS_FOREVER || raiStatus == utils.COMPANY_STATUS_FREEZE || raiStatus == utils.COMPANY_STATUS_LOSE {
  3303. //超管可编辑基础信息
  3304. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3305. btnDetailItem.BaseInfoEdit = true
  3306. }
  3307. }
  3308. } else {
  3309. //权限未开,有编辑基础信息权限
  3310. btnDetailItem.BaseInfoEdit = true
  3311. }
  3312. }
  3313. }
  3314. //权益销售
  3315. if raiStatus, ok := statusMap[2]; ok {
  3316. if raiStatus == utils.COMPANY_STATUS_TRY_OUT {
  3317. if ficcStatus, ok := statusMap[1]; ok {
  3318. //另一个权限也是 试用 、冻结、流失
  3319. if ficcStatus == utils.COMPANY_STATUS_TRY_OUT || ficcStatus == utils.COMPANY_STATUS_FREEZE || ficcStatus == utils.COMPANY_STATUS_LOSE {
  3320. //那么超管、部门管理员、销售可以编辑
  3321. if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER || roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3322. btnDetailItem.BaseInfoEdit = true
  3323. }
  3324. }
  3325. //ficc是永续时,超管可编辑基础信息
  3326. if ficcStatus == utils.COMPANY_STATUS_FOREVER {
  3327. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3328. btnDetailItem.BaseInfoEdit = true
  3329. }
  3330. }
  3331. } else {
  3332. //权限未开,有编辑基础信息权限
  3333. btnDetailItem.BaseInfoEdit = true
  3334. }
  3335. }
  3336. if raiStatus == utils.COMPANY_STATUS_FOREVER {
  3337. if ficcStatus, ok := statusMap[1]; ok {
  3338. //另一个权限也是 试用、永续 、冻结、流失
  3339. if ficcStatus == utils.COMPANY_STATUS_TRY_OUT || ficcStatus == utils.COMPANY_STATUS_FOREVER || ficcStatus == utils.COMPANY_STATUS_FREEZE || ficcStatus == utils.COMPANY_STATUS_LOSE {
  3340. //超管可编辑基础信息
  3341. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3342. btnDetailItem.BaseInfoEdit = true
  3343. }
  3344. }
  3345. } else {
  3346. //权限未开,有编辑基础信息权限
  3347. btnDetailItem.BaseInfoEdit = true
  3348. }
  3349. }
  3350. }
  3351. // 白嫖客户标记
  3352. scroungeList, err := company.GetScroungeCompany()
  3353. if err != nil {
  3354. br.Msg = "获取失败"
  3355. br.ErrMsg = "获取白嫖客户信息失败,Err:" + err.Error()
  3356. return
  3357. }
  3358. scroungeMap := make(map[int]int)
  3359. for _, v := range scroungeList {
  3360. scroungeMap[v.CompanyId] = 1
  3361. }
  3362. if _, ok := scroungeMap[item.CompanyId]; ok {
  3363. item.IsScrounge = 1
  3364. }
  3365. resp.Item = item
  3366. resp.BtnItem = btnDetailItem
  3367. br.Ret = 200
  3368. br.Success = true
  3369. br.Msg = "获取成功"
  3370. br.Data = resp
  3371. }
  3372. // DetailByCreditCode
  3373. // @Title 根据社会信用码获取客户详情
  3374. // @Description 根据社会信用码获取客户详情接口
  3375. // @Param CreditCode query string true "客户社会信用码"
  3376. // @Success 200 {object} company.CompanyDetailResp
  3377. // @router /detail_by_credit_code [get]
  3378. func (this *CompanyController) DetailByCreditCode() {
  3379. br := new(models.BaseResponse).Init()
  3380. defer func() {
  3381. this.Data["json"] = br
  3382. this.ServeJSON()
  3383. }()
  3384. sysUser := this.SysUser
  3385. if sysUser == nil {
  3386. br.Msg = "请登录"
  3387. br.ErrMsg = "请登录,SysUser Is Empty"
  3388. br.Ret = 408
  3389. return
  3390. }
  3391. resp := new(company.CompanyDetailResp)
  3392. creditCode := this.GetString("CreditCode")
  3393. if creditCode == "" {
  3394. br.Msg = "参数错误"
  3395. br.ErrMsg = "社会信用码必传"
  3396. return
  3397. }
  3398. item, err := company.GetCompanyDetailByCreditCode(creditCode)
  3399. if err != nil {
  3400. br.Ret = 200
  3401. br.Success = true
  3402. br.Msg = "获取成功"
  3403. br.Data = resp
  3404. return
  3405. }
  3406. companyId := item.CompanyId
  3407. var productName string
  3408. productId := services.GetProductId(sysUser.RoleTypeCode)
  3409. if productId == 1 {
  3410. productName = utils.COMPANY_PRODUCT_FICC_NAME
  3411. } else if productId == 2 {
  3412. productName = utils.COMPANY_PRODUCT_RAI_NAME
  3413. } else {
  3414. productName = "admin"
  3415. }
  3416. resp.ProductName = productName
  3417. //获取客户产品
  3418. productList, err := company.GetCompanyProductsByCompanyId(companyId)
  3419. if err != nil {
  3420. br.Msg = "获取信息失败"
  3421. br.ErrMsg = "获取产品信息失败,Err:" + err.Error()
  3422. return
  3423. }
  3424. roleTypeCode := sysUser.RoleTypeCode
  3425. itemLen := len(productList)
  3426. btnDetailItem := new(company.ButtonDetailPermission)
  3427. //产品权限map
  3428. statusMap := make(map[int]string)
  3429. for i := 0; i < itemLen; i++ {
  3430. item := productList[i]
  3431. //添加产品权限map
  3432. statusMap[item.ProductId] = item.Status
  3433. if i == 0 {
  3434. if item.ProductId == 1 {
  3435. resp.CreateAuth = 1
  3436. } else {
  3437. resp.CreateAuth = 2
  3438. }
  3439. }
  3440. if item.ProductId == 1 {
  3441. if strings.Contains(sysUser.RoleTypeCode, "ficc") {
  3442. if item.Status == utils.COMPANY_STATUS_FREEZE || item.Status == utils.COMPANY_STATUS_LOSE {
  3443. btnDetailItem.BtnHistoryList = true
  3444. } else {
  3445. if item.SellerId == sysUser.AdminId {
  3446. btnDetailItem.BtnHistoryList = true
  3447. }
  3448. if sysUser.Authority > 0 {
  3449. if item.GroupId == sysUser.GroupId {
  3450. btnDetailItem.BtnHistoryList = true
  3451. }
  3452. if item.DepartmentId == sysUser.DepartmentId {
  3453. btnDetailItem.BtnHistoryList = true
  3454. }
  3455. }
  3456. }
  3457. }
  3458. //子权限切片集合
  3459. allFiccPermissions, permissionMap, e := services.GetBasePermissionLookItem(utils.COMPANY_PRODUCT_FICC_ID)
  3460. if e != nil {
  3461. br.Msg = "查询基础权限失败"
  3462. br.ErrMsg = "查询基础权限失败,Err:" + e.Error()
  3463. return
  3464. }
  3465. //遍历获取
  3466. for _, v := range allFiccPermissions {
  3467. if v.ParentId == 0 {
  3468. checkList := make([]int, 0)
  3469. plist := new(company.PermissionLookList)
  3470. plist.Items = make([]*company.PermissionLookItem, 0)
  3471. items, ok1 := permissionMap[v.ChartPermissionId]
  3472. if ok1 {
  3473. for itemK, n := range items {
  3474. permission, e := company.GetCompanyPermissionCheckItem(companyId, n.ChartPermissionId)
  3475. if e != nil && e.Error() != utils.ErrNoRow() {
  3476. br.Msg = "获取失败"
  3477. br.ErrMsg = "获取权限信息失败,Err:" + e.Error()
  3478. return
  3479. }
  3480. if permission != nil && permission.ChartPermissionId > 0 {
  3481. checkList = append(checkList, n.ChartPermissionId)
  3482. items[itemK].StartDate = permission.StartDate
  3483. items[itemK].EndDate = permission.EndDate
  3484. items[itemK].Status = permission.Status
  3485. endDateTime, _ := time.Parse(utils.FormatDate, permission.EndDate)
  3486. endDateTime = endDateTime.AddDate(0, 0, 1)
  3487. sub := endDateTime.Sub(time.Now())
  3488. if sub < 0 {
  3489. sub = 0
  3490. }
  3491. expireDay := fmt.Sprintf("%v", int(sub.Hours()/24))
  3492. items[itemK].ExpireDay = expireDay
  3493. }
  3494. }
  3495. plist.Items = items
  3496. }
  3497. plist.ClassifyName = v.PermissionName
  3498. plist.CheckList = checkList
  3499. item.PermissionList = append(item.PermissionList, plist)
  3500. }
  3501. }
  3502. resp.FiccItem = item
  3503. if (roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER ||
  3504. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP || roleTypeCode == utils.ROLE_TYPE_CODE_FICC_DEPARTMENT) &&
  3505. item.Status == utils.COMPANY_STATUS_TRY_OUT && item.ApproveStatus != "待审批" {
  3506. resp.IsButtonShow = 1
  3507. }
  3508. } else {
  3509. if strings.Contains(sysUser.RoleTypeCode, "rai") {
  3510. if item.Status == utils.COMPANY_STATUS_FREEZE || item.Status == utils.COMPANY_STATUS_LOSE {
  3511. btnDetailItem.BtnHistoryList = true
  3512. } else {
  3513. if item.SellerId == sysUser.AdminId {
  3514. btnDetailItem.BtnHistoryList = true
  3515. }
  3516. if sysUser.Authority > 0 {
  3517. if item.GroupId == sysUser.GroupId {
  3518. btnDetailItem.BtnHistoryList = true
  3519. }
  3520. if item.DepartmentId == sysUser.DepartmentId {
  3521. btnDetailItem.BtnHistoryList = true
  3522. }
  3523. }
  3524. }
  3525. }
  3526. classifyName := "权益"
  3527. checkList := make([]int, 0)
  3528. plist := new(company.PermissionLookList)
  3529. items, err := company.GetPermissionLookItems(item.ProductId, classifyName)
  3530. if err != nil {
  3531. br.Msg = "获取失败"
  3532. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  3533. return
  3534. }
  3535. for itemK, n := range items {
  3536. permission, err := company.GetCompanyPermissionCheckItem(companyId, n.ChartPermissionId)
  3537. if err != nil && err.Error() != utils.ErrNoRow() {
  3538. br.Msg = "获取失败"
  3539. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  3540. return
  3541. }
  3542. if permission != nil && permission.ChartPermissionId > 0 {
  3543. checkList = append(checkList, n.ChartPermissionId)
  3544. items[itemK].StartDate = permission.StartDate
  3545. items[itemK].EndDate = permission.EndDate
  3546. items[itemK].Status = permission.Status
  3547. endDateTime, _ := time.Parse(utils.FormatDate, permission.EndDate)
  3548. endDateTime = endDateTime.AddDate(0, 0, 1)
  3549. sub := endDateTime.Sub(time.Now())
  3550. if sub < 0 {
  3551. sub = 0
  3552. }
  3553. expireDay := fmt.Sprintf("%v", int(sub.Hours()/24))
  3554. items[itemK].ExpireDay = expireDay
  3555. }
  3556. //count, err := company.GetCompanyPermissionCheck(companyId, n.ChartPermissionId)
  3557. //if err != nil {
  3558. // br.Msg = "获取失败"
  3559. // br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  3560. // return
  3561. //}
  3562. //if count > 0 {
  3563. // checkList = append(checkList, n.ChartPermissionId)
  3564. //}
  3565. }
  3566. item.SpecialSurplus, err = cygxService.GetSpecialSurplusByCompanyNew(companyId)
  3567. if err != nil {
  3568. br.Msg = "获取失败"
  3569. br.ErrMsg = "获取专项调研信息失败,Err:" + err.Error()
  3570. return
  3571. }
  3572. plist.Items = items
  3573. plist.ClassifyName = classifyName
  3574. plist.CheckList = checkList
  3575. item.PermissionList = append(item.PermissionList, plist)
  3576. resp.RaiItem = item
  3577. if (roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER ||
  3578. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP ||
  3579. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_DEPARTMENT) &&
  3580. item.Status == utils.COMPANY_STATUS_TRY_OUT && item.ApproveStatus != "待审批" {
  3581. resp.IsButtonShow = 1
  3582. }
  3583. }
  3584. btnItem := services.GetCompanyPermissionButton(roleTypeCode, item.Status, strconv.Itoa(item.SellerId), strconv.Itoa(item.GroupId),
  3585. item.GroupId, sysUser.GroupId, item.SellerId, sysUser.AdminId, sysUser.Authority, item.ProductId, item.ShareSellerId, "")
  3586. //if itemLen > 1 {
  3587. // btnDetailItem.BtnEdit = false
  3588. // btnDetailItem.BtnDelete = false
  3589. //} else {
  3590. // btnDetailItem.BtnEdit = btnItem.BtnEdit
  3591. // btnDetailItem.BtnDelete = btnItem.BtnDelete
  3592. //}
  3593. switch item.ProductId {
  3594. case 1:
  3595. btnDetailItem.FiccEdit = btnItem.BtnEdit
  3596. btnDetailItem.FiccDelete = btnItem.BtnDelete
  3597. case 2:
  3598. btnDetailItem.RaiEdit = btnItem.BtnEdit
  3599. btnDetailItem.RaiDelete = btnItem.BtnDelete
  3600. }
  3601. if !btnDetailItem.BtnEdit {
  3602. btnDetailItem.BtnEdit = btnItem.BtnEdit
  3603. }
  3604. if !btnDetailItem.BtnDelete {
  3605. btnDetailItem.BtnDelete = btnItem.BtnDelete
  3606. }
  3607. //联系人操作权限
  3608. if resp.IsContractButtonShow == false {
  3609. resp.IsContractButtonShow = services.CheckCompanyUserButton(sysUser.RoleTypeCode, item.SellerId, sysUser.AdminId, item.ProductId, item.ShareSellerId, item.Status)
  3610. }
  3611. }
  3612. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN ||
  3613. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN ||
  3614. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  3615. resp.IsButtonShow = 1
  3616. btnDetailItem.BtnHistoryList = true
  3617. }
  3618. //ficc权限
  3619. if ficcStatus, ok := statusMap[1]; ok {
  3620. if ficcStatus == utils.COMPANY_STATUS_TRY_OUT {
  3621. if raiStatus, ok := statusMap[2]; ok {
  3622. //另一个权限也是 试用 、冻结、流失
  3623. if raiStatus == utils.COMPANY_STATUS_TRY_OUT || raiStatus == utils.COMPANY_STATUS_FREEZE || raiStatus == utils.COMPANY_STATUS_LOSE {
  3624. //那么超管、部门管理员、销售可以编辑
  3625. if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER || roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3626. btnDetailItem.BaseInfoEdit = true
  3627. }
  3628. }
  3629. //权益是永续时,超管可编辑基础信息
  3630. if raiStatus == utils.COMPANY_STATUS_FOREVER {
  3631. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3632. btnDetailItem.BaseInfoEdit = true
  3633. }
  3634. }
  3635. } else {
  3636. //权限未开,有编辑基础信息权限
  3637. btnDetailItem.BaseInfoEdit = true
  3638. }
  3639. }
  3640. if ficcStatus == utils.COMPANY_STATUS_FOREVER {
  3641. if raiStatus, ok := statusMap[2]; ok {
  3642. //另一个权限也是 永续 、冻结、流失
  3643. if raiStatus == utils.COMPANY_STATUS_TRY_OUT || raiStatus == utils.COMPANY_STATUS_FOREVER || raiStatus == utils.COMPANY_STATUS_FREEZE || raiStatus == utils.COMPANY_STATUS_LOSE {
  3644. //超管可编辑基础信息
  3645. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3646. btnDetailItem.BaseInfoEdit = true
  3647. }
  3648. }
  3649. } else {
  3650. //权限未开,有编辑基础信息权限
  3651. btnDetailItem.BaseInfoEdit = true
  3652. }
  3653. }
  3654. }
  3655. //权益销售
  3656. if raiStatus, ok := statusMap[2]; ok {
  3657. if raiStatus == utils.COMPANY_STATUS_TRY_OUT {
  3658. if ficcStatus, ok := statusMap[1]; ok {
  3659. //另一个权限也是 试用 、冻结、流失
  3660. if ficcStatus == utils.COMPANY_STATUS_TRY_OUT || ficcStatus == utils.COMPANY_STATUS_FREEZE || ficcStatus == utils.COMPANY_STATUS_LOSE {
  3661. //那么超管、部门管理员、销售可以编辑
  3662. if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER || roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3663. btnDetailItem.BaseInfoEdit = true
  3664. }
  3665. }
  3666. //ficc是永续时,超管可编辑基础信息
  3667. if ficcStatus == utils.COMPANY_STATUS_FOREVER {
  3668. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3669. btnDetailItem.BaseInfoEdit = true
  3670. }
  3671. }
  3672. } else {
  3673. //权限未开,有编辑基础信息权限
  3674. btnDetailItem.BaseInfoEdit = true
  3675. }
  3676. }
  3677. if raiStatus == utils.COMPANY_STATUS_FOREVER {
  3678. if ficcStatus, ok := statusMap[1]; ok {
  3679. //另一个权限也是 试用、永续 、冻结、流失
  3680. if ficcStatus == utils.COMPANY_STATUS_TRY_OUT || ficcStatus == utils.COMPANY_STATUS_FOREVER || ficcStatus == utils.COMPANY_STATUS_FREEZE || ficcStatus == utils.COMPANY_STATUS_LOSE {
  3681. //超管可编辑基础信息
  3682. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  3683. btnDetailItem.BaseInfoEdit = true
  3684. }
  3685. }
  3686. } else {
  3687. //权限未开,有编辑基础信息权限
  3688. btnDetailItem.BaseInfoEdit = true
  3689. }
  3690. }
  3691. }
  3692. resp.Item = item
  3693. resp.BtnItem = btnDetailItem
  3694. br.Ret = 200
  3695. br.Success = true
  3696. br.Msg = "获取成功"
  3697. br.Data = resp
  3698. }
  3699. // @Title 编辑客户
  3700. // @Description 编辑客户接口
  3701. // @Param request body company.CompanyEditReq true "type json string"
  3702. // @Success Ret=200 保存成功
  3703. // @router /edit [post]
  3704. func (this *CompanyController) Edit() {
  3705. br := new(models.BaseResponse).Init()
  3706. defer func() {
  3707. this.Data["json"] = br
  3708. this.ServeJSON()
  3709. }()
  3710. sysUser := this.SysUser
  3711. if sysUser == nil {
  3712. br.Msg = "请登录"
  3713. br.ErrMsg = "请登录,SysUser Is Empty"
  3714. br.Ret = 408
  3715. return
  3716. }
  3717. //roleTypeCode := sysUser.RoleTypeCode
  3718. var req company.CompanyEditReq
  3719. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  3720. if err != nil {
  3721. br.Msg = "参数解析异常!"
  3722. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  3723. return
  3724. }
  3725. if req.CompanyId <= 0 {
  3726. br.Msg = "参数异常!"
  3727. br.ErrMsg = "CompanyId:" + strconv.Itoa(req.CompanyId)
  3728. return
  3729. }
  3730. if req.CompanyName == "" {
  3731. br.Msg = "请填写客户名称"
  3732. return
  3733. }
  3734. if req.CreditCode == "" {
  3735. br.Msg = "请填写社会统一信用码"
  3736. return
  3737. }
  3738. //移除空格
  3739. req.CreditCode = utils.TrimStr(req.CreditCode)
  3740. productId := services.GetProductId(sysUser.RoleTypeCode) //产品权限id
  3741. for _, v := range req.Products {
  3742. if v.IndustryId <= 0 {
  3743. br.Msg = "请选择行业"
  3744. br.IsSendEmail = false
  3745. return
  3746. }
  3747. //获取客户产品信息
  3748. productItem, err := company.GetCompanyProductById(v.CompanyProductId)
  3749. if err != nil {
  3750. br.Msg = "数据获取失败!"
  3751. br.ErrMsg = "数据获取失败,Err:" + err.Error()
  3752. return
  3753. }
  3754. if productItem == nil {
  3755. br.Msg = "客户信息不存在!"
  3756. return
  3757. }
  3758. // 如果本身是有权限归属的,同时传入的参数不是当前账号权限的,那么过滤该次循环,进入下次循环
  3759. if productId > 0 && productItem.ProductId != productId {
  3760. continue
  3761. }
  3762. if v.Status == "" {
  3763. br.Msg = "客户状态不可为空"
  3764. return
  3765. }
  3766. //if v.Reasons == "" {
  3767. // br.Msg = "请填写新增理由"
  3768. // return
  3769. //}
  3770. if v.PermissionIds == "" {
  3771. br.Msg = "请选择权限"
  3772. return
  3773. }
  3774. var startDate, endDate string
  3775. startDate = productItem.StartDate
  3776. endDate = productItem.EndDate
  3777. if startDate == "" || endDate == "" {
  3778. br.Msg = "数据错误"
  3779. br.Msg = "数据错误,开始或结束日期为空:startDate:" + startDate + "endDate:" + endDate
  3780. return
  3781. }
  3782. //判断客户是否已经存在
  3783. companyNameIsExist, err := company.GetCompanyCountByCompanyNameAndCompanyId(req.CompanyId, req.CompanyName)
  3784. if err != nil {
  3785. br.Msg = "判断客户是否存在失败"
  3786. br.ErrMsg = "判断客户是否存在失败,Err:" + err.Error()
  3787. return
  3788. }
  3789. if companyNameIsExist > 0 {
  3790. br.Msg = "客户已存在,请重新输入客户名称"
  3791. return
  3792. }
  3793. //判断客户是否已经存在
  3794. companyCreditCodeIsExist, err := company.GetCompanyCountByCreditCodeAndCompanyId(req.CompanyId, req.CreditCode)
  3795. if err != nil {
  3796. br.Msg = "判断客户是否存在失败"
  3797. br.ErrMsg = "判断客户是否存在失败,Err:" + err.Error()
  3798. return
  3799. }
  3800. if companyCreditCodeIsExist > 0 {
  3801. br.Msg = "客户已存在,请重新输入统一社会信用代码"
  3802. return
  3803. }
  3804. seller, err := system.GetSysAdminById(v.SellsId)
  3805. if err != nil {
  3806. br.Msg = "获取销售信息失败"
  3807. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  3808. return
  3809. }
  3810. if seller == nil {
  3811. br.Msg = "所属销售不存在"
  3812. return
  3813. }
  3814. //tryOutCount, err := company.GetCompanyTryOutCount(utils.COMPANY_STATUS_TRY_OUT, seller.AdminId)
  3815. //if err != nil {
  3816. // br.Msg = "判断试用客户量失败"
  3817. // br.ErrMsg = "判断试用客户量失败,Err:" + err.Error()
  3818. // return
  3819. //}
  3820. //if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_FICC_DEPARTMENT ||
  3821. // roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER || roleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
  3822. // if tryOutCount >= utils.COMPANY_STATUS_TRY_OUT_COUNT && v.SellsId == sysUser.AdminId {
  3823. // br.Msg = "您的试用客户总数,已超过上限,不可继续新增"
  3824. // return
  3825. // }
  3826. //}
  3827. industry, err := company.GetCompanyIndustryById(v.IndustryId)
  3828. if err != nil {
  3829. br.Msg = "获取行业信息失败"
  3830. br.ErrMsg = "获取行业信息失败,Err:" + err.Error()
  3831. return
  3832. }
  3833. companyProduct := new(company.CompanyProduct)
  3834. companyProduct.ProductId = productItem.ProductId
  3835. companyProduct.CompanyId = req.CompanyId
  3836. companyProduct.CompanyName = req.CompanyName
  3837. companyProduct.Source = v.Source
  3838. companyProduct.Reasons = v.Reasons
  3839. companyProduct.Status = v.Status
  3840. companyProduct.StartDate = startDate
  3841. companyProduct.EndDate = endDate
  3842. companyProduct.IndustryId = v.IndustryId
  3843. companyProduct.IndustryName = industry.IndustryName
  3844. companyProduct.SellerId = seller.AdminId
  3845. companyProduct.SellerName = seller.RealName
  3846. companyProduct.GroupId = seller.GroupId
  3847. companyProduct.DepartmentId = seller.DepartmentId
  3848. companyProduct.IsSuspend = 0
  3849. companyProduct.ModifyTime = time.Now()
  3850. companyProduct.CompanyProductId = v.CompanyProductId
  3851. companyProduct.Scale = v.Scale
  3852. err = company.ModifyCompanyProduct(companyProduct)
  3853. if err != nil {
  3854. br.Msg = "修改客户信息失败"
  3855. br.ErrMsg = "修改客户产品信息失败,Err:" + err.Error()
  3856. return
  3857. }
  3858. // CRM8.8-下面的需求取消, 编辑的时候根据选择开通对应权限
  3859. // 如果是权益客户,编辑的时候开通主观客观权限
  3860. //if v.CompanyType == utils.COMPANY_CLASSIFY_RAI {
  3861. // permissionStr, err := company.GetPermissionIdById(v.PermissionIds)
  3862. // if err != nil {
  3863. // br.Msg = "修改失败"
  3864. // br.ErrMsg = "获取主观客观权限信息失败,Err:" + err.Error()
  3865. // return
  3866. // }
  3867. // v.PermissionIds = permissionStr
  3868. //}
  3869. //处理权限
  3870. companyReportPermissionList, err := services.AddCompanyPermission(req.CompanyId, seller.AdminId, productItem.ProductId, productItem.ProductName, seller.RealName, v.PermissionIds, startDate, endDate)
  3871. if err != nil {
  3872. br.Msg = "修改失败"
  3873. br.ErrMsg = "新增客户设置权限失败,err:" + err.Error()
  3874. return
  3875. }
  3876. //新增操作记录
  3877. {
  3878. record := new(company.CompanyOperationRecord)
  3879. record.CompanyId = req.CompanyId
  3880. record.CompanyName = req.CompanyName
  3881. record.SellerId = companyProduct.SellerId
  3882. record.SysUserId = this.SysUser.AdminId
  3883. record.SysRealName = this.SysUser.RealName
  3884. record.Remark = "编辑客户"
  3885. record.Operation = "edit"
  3886. record.CreateTime = time.Now()
  3887. record.ProductId = productItem.ProductId
  3888. record.ProductName = productItem.ProductName
  3889. record.Status = productItem.Status
  3890. _, err = company.AddCompanyOperationRecord(record)
  3891. if err != nil {
  3892. go alarm_msg.SendAlarmMsg("URI:"+this.Ctx.Input.URI()+"<br/> "+";<br/> Body:"+err.Error(), 3)
  3893. //go utils.SendEmail(utils.APPNAME+"失败提醒"+utils.RunMode, "URI:"+this.Ctx.Input.URI()+"<br/> "+";<br/> Body:"+err.Error(), utils.EmailSendToUsers)
  3894. }
  3895. }
  3896. //新增客户产品日志
  3897. {
  3898. productLog := new(company.CompanyProductLog)
  3899. productLog.CompanyProductId = v.CompanyProductId
  3900. productLog.CompanyId = companyProduct.CompanyId
  3901. productLog.ProductId = companyProduct.ProductId
  3902. productLog.ProductName = companyProduct.ProductName
  3903. productLog.CompanyName = companyProduct.CompanyName
  3904. productLog.CompanyName = companyProduct.CompanyName
  3905. productLog.Source = companyProduct.Source
  3906. productLog.Reasons = companyProduct.Reasons
  3907. productLog.Status = companyProduct.Status
  3908. productLog.IndustryId = companyProduct.IndustryId
  3909. productLog.IndustryName = companyProduct.IndustryName
  3910. productLog.SellerId = companyProduct.SellerId
  3911. productLog.SellerName = companyProduct.SellerName
  3912. productLog.GroupId = companyProduct.GroupId
  3913. productLog.DepartmentId = companyProduct.DepartmentId
  3914. productLog.IsSuspend = companyProduct.IsSuspend
  3915. productLog.SuspendTime = companyProduct.SuspendTime
  3916. productLog.ApproveStatus = companyProduct.ApproveStatus
  3917. productLog.FreezeTime = companyProduct.FreezeTime
  3918. productLog.Remark = companyProduct.Remark
  3919. productLog.StartDate = companyProduct.StartDate
  3920. productLog.EndDate = companyProduct.EndDate
  3921. productLog.CreateTime = companyProduct.CreateTime
  3922. productLog.ModifyTime = companyProduct.ModifyTime
  3923. productLog.LoseReason = companyProduct.LoseReason
  3924. productLog.LossTime = companyProduct.LossTime
  3925. productLog.LogType = "modify"
  3926. productLog.LogCreateTime = time.Now()
  3927. productLog.AdminId = this.SysUser.AdminId
  3928. productLog.Scale = companyProduct.Scale
  3929. go company.AddCompanyProductLog(productLog)
  3930. }
  3931. //新增客户产品状态变更日志
  3932. {
  3933. startDateTime, _ := time.ParseInLocation(utils.FormatDate, startDate, time.Local)
  3934. endDateTime, _ := time.ParseInLocation(utils.FormatDate, endDate, time.Local)
  3935. companyProductUpdateLog := &company.CompanyProductUpdateLog{
  3936. Id: 0,
  3937. CompanyId: req.CompanyId,
  3938. ProductId: productId,
  3939. Status: "试用",
  3940. Source: "edit",
  3941. SellerId: seller.AdminId,
  3942. SellerName: seller.RealName,
  3943. StartDate: startDateTime,
  3944. EndDate: endDateTime,
  3945. RealEndDate: startDateTime,
  3946. CreateTime: time.Now(),
  3947. }
  3948. go company.AddCompanyProductUpdateLog(companyProductUpdateLog)
  3949. // 添加试用记录
  3950. companyProductTryOutUpdateLog := &company.CompanyProductTryOutUpdateLog{
  3951. Id: 0,
  3952. CompanyId: req.CompanyId,
  3953. ProductId: productId,
  3954. Source: "edit",
  3955. SellerId: seller.AdminId,
  3956. SellerName: seller.RealName,
  3957. StartDate: startDateTime,
  3958. EndDate: endDateTime,
  3959. RealEndDate: startDateTime,
  3960. IsStop: 0,
  3961. CreateTime: time.Now(),
  3962. }
  3963. go company.AddCompanyProductTryOutUpdateLog(companyProductTryOutUpdateLog, companyReportPermissionList)
  3964. }
  3965. }
  3966. companyItem := new(company.Company)
  3967. companyItem.CompanyId = req.CompanyId
  3968. companyItem.CompanyName = req.CompanyName
  3969. companyItem.CreditCode = req.CreditCode
  3970. companyItem.Province = req.Province
  3971. companyItem.City = req.City
  3972. companyItem.Address = req.Province + req.City
  3973. companyItem.LastUpdatedTime = time.Now()
  3974. companyItem.Enabled = 1
  3975. companyItem.Nation = req.Nation
  3976. err = company.ModifyCompany(companyItem)
  3977. if err != nil {
  3978. br.Msg = "修改客户信息失败"
  3979. br.ErrMsg = "修改客户信息失败,Err:" + err.Error()
  3980. return
  3981. }
  3982. //新增客户日志
  3983. {
  3984. companyLog := new(company.CompanyLog)
  3985. companyLog.CompanyId = req.CompanyId
  3986. companyLog.CompanyName = req.CompanyName
  3987. companyLog.CreditCode = req.CreditCode
  3988. companyLog.Address = companyItem.Address
  3989. companyLog.City = companyItem.City
  3990. companyLog.Province = companyItem.Province
  3991. companyLog.LastUpdatedTime = companyItem.LastUpdatedTime
  3992. companyLog.AdminId = this.SysUser.AdminId
  3993. companyLog.LogType = "modify"
  3994. companyLog.LogCreateTime = time.Now()
  3995. go company.AddCompanyLog(companyLog)
  3996. }
  3997. br.Ret = 200
  3998. br.Success = true
  3999. br.Msg = "保存成功"
  4000. }
  4001. // @Title 编辑补充客户信息接口
  4002. // @Description 编辑补充客户信息接口
  4003. // @Param request body company.CompanyInfoEditReq true "type json string"
  4004. // @Success Ret=200 保存成功
  4005. // @router /company_info/edit [post]
  4006. func (this *CompanyController) EditCompanyInfo() {
  4007. br := new(models.BaseResponse).Init()
  4008. defer func() {
  4009. this.Data["json"] = br
  4010. this.ServeJSON()
  4011. }()
  4012. sysUser := this.SysUser
  4013. if sysUser == nil {
  4014. br.Msg = "请登录"
  4015. br.ErrMsg = "请登录,SysUser Is Empty"
  4016. br.Ret = 408
  4017. return
  4018. }
  4019. var req company.CompanyInfoEditReq
  4020. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  4021. if err != nil {
  4022. br.Msg = "参数解析异常!"
  4023. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  4024. return
  4025. }
  4026. if req.CompanyId <= 0 {
  4027. br.Msg = "参数异常!"
  4028. br.ErrMsg = "CompanyId:" + strconv.Itoa(req.CompanyId)
  4029. return
  4030. }
  4031. if req.CompanyName == "" {
  4032. br.Msg = "请填写客户名称"
  4033. return
  4034. }
  4035. if req.CreditCode == "" {
  4036. br.Msg = "请填写社会统一信用码"
  4037. return
  4038. }
  4039. //if req.Province == "" {
  4040. // br.Msg = "请选择省份"
  4041. // return
  4042. //}
  4043. //if req.City == "" {
  4044. // br.Msg = "请选择市区"
  4045. // return
  4046. //}
  4047. //if req.IndustryId <= 0 {
  4048. // br.Msg = "请选择所属行业"
  4049. // return
  4050. //}
  4051. //if req.IndustryName == "" {
  4052. // br.Msg = "请选择所属行业"
  4053. // return
  4054. //}
  4055. //if req.Source == "" {
  4056. // br.Msg = "请选择来源"
  4057. // return
  4058. //}
  4059. //移除空格
  4060. req.CreditCode = utils.TrimStr(req.CreditCode)
  4061. //获取产品权限
  4062. productId := services.GetProductId(sysUser.RoleTypeCode)
  4063. if productId <= 0 {
  4064. br.Msg = "当前账号不允许修改客户信息"
  4065. return
  4066. }
  4067. companyNameIsExist, err := company.GetCompanyCountByCompanyNameAndCompanyId(req.CompanyId, req.CompanyName)
  4068. if err != nil {
  4069. br.Msg = "判断客户是否存在失败"
  4070. br.ErrMsg = "判断客户是否存在失败,Err:" + err.Error()
  4071. return
  4072. }
  4073. if companyNameIsExist > 0 {
  4074. br.Msg = "客户已存在,请重新输入客户名称"
  4075. return
  4076. }
  4077. //判断客户是否已经存在
  4078. companyCreditCodeIsExist, err := company.GetCompanyCountByCreditCodeAndCompanyId(req.CompanyId, req.CreditCode)
  4079. if err != nil {
  4080. br.Msg = "判断客户是否存在失败"
  4081. br.ErrMsg = "判断客户是否存在失败,Err:" + err.Error()
  4082. return
  4083. }
  4084. if companyCreditCodeIsExist > 0 {
  4085. br.Msg = "客户已存在,统一社会信用代码"
  4086. return
  4087. }
  4088. //查询该客户
  4089. companyItem, err := company.GetCompanyById(req.CompanyId)
  4090. if err != nil {
  4091. br.Msg = "查找客户失败"
  4092. br.ErrMsg = "查找客户失败,Err:" + err.Error()
  4093. return
  4094. }
  4095. //待更新字段
  4096. updateCol := make([]string, 0)
  4097. companyItem.CompanyName = req.CompanyName
  4098. companyItem.CreditCode = req.CreditCode
  4099. companyItem.Enabled = 1
  4100. companyItem.LastUpdatedTime = time.Now()
  4101. updateCol = append(updateCol, "CompanyName", "CreditCode", "Enabled", "LastUpdatedTime")
  4102. if req.Province != "" && req.City != "" {
  4103. companyItem.Province = req.Province
  4104. companyItem.City = req.City
  4105. companyItem.Address = req.Province + req.City
  4106. updateCol = append(updateCol, "Province", "City", "Address")
  4107. }
  4108. err = companyItem.Update(updateCol)
  4109. if err != nil {
  4110. br.Msg = "修改客户信息失败"
  4111. br.ErrMsg = "修改客户信息失败,Err:" + err.Error()
  4112. return
  4113. }
  4114. //查询并更新客户产品信息
  4115. companyProduct, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, productId)
  4116. if err != nil {
  4117. if err.Error() != utils.ErrNoRow() {
  4118. br.Msg = "查询客户产品信息失败"
  4119. br.ErrMsg = "查询客户产品信息失败,Err:" + err.Error()
  4120. return
  4121. }
  4122. } else {
  4123. if companyProduct != nil {
  4124. //客户产品待更新字段
  4125. updateCompanyProductCol := make([]string, 0)
  4126. //产品信息(来源、行业)
  4127. if req.IndustryId != 0 && req.IndustryId != companyProduct.IndustryId {
  4128. companyProduct.IndustryId = req.IndustryId
  4129. companyProduct.IndustryName = req.IndustryName
  4130. updateCompanyProductCol = append(updateCompanyProductCol, "IndustryId", "IndustryName")
  4131. }
  4132. if req.Source != "" && req.Source != companyProduct.Source {
  4133. companyProduct.Source = req.Source
  4134. updateCompanyProductCol = append(updateCompanyProductCol, "Source")
  4135. }
  4136. //更新客户产品信息
  4137. if len(updateCompanyProductCol) > 0 {
  4138. err = companyProduct.Update(updateCompanyProductCol)
  4139. if err != nil {
  4140. br.Msg = "修改客户信息失败"
  4141. br.ErrMsg = "修改客户信息失败,Err:" + err.Error()
  4142. return
  4143. }
  4144. }
  4145. }
  4146. }
  4147. //新增客户日志
  4148. {
  4149. companyLog := new(company.CompanyLog)
  4150. companyLog.CompanyId = req.CompanyId
  4151. companyLog.CompanyName = req.CompanyName
  4152. companyLog.CreditCode = req.CreditCode
  4153. companyLog.Address = companyItem.Address
  4154. companyLog.City = companyItem.City
  4155. companyLog.Province = companyItem.Province
  4156. companyLog.LastUpdatedTime = companyItem.LastUpdatedTime
  4157. companyLog.AdminId = this.SysUser.AdminId
  4158. companyLog.LogType = "modify"
  4159. companyLog.LogCreateTime = time.Now()
  4160. go company.AddCompanyLog(companyLog)
  4161. }
  4162. br.Ret = 200
  4163. br.Success = true
  4164. br.Msg = "保存成功"
  4165. }
  4166. // @Title 客户模糊检索(新增/编辑客户页面试用)
  4167. // @Description 客户模糊检索接口(新增/编辑客户页面试用)
  4168. // @Param KeyWord query string true "搜索关键词"
  4169. // @Success 200 {object} company.CompanyFuzzySearchReq
  4170. // @router /fuzzy/search [get]
  4171. func (this *CompanyController) FuzzySearch() {
  4172. br := new(models.BaseResponse).Init()
  4173. defer func() {
  4174. this.Data["json"] = br
  4175. this.ServeJSON()
  4176. }()
  4177. keyWord := this.GetString("KeyWord")
  4178. list, err := company.GetCompanyFuzzySearch(keyWord)
  4179. if err != nil {
  4180. br.Msg = "获取信息失败"
  4181. br.ErrMsg = "获取信息失败,err:" + err.Error()
  4182. return
  4183. }
  4184. resp := new(company.CompanyFuzzySearchReq)
  4185. resp.List = list
  4186. br.Ret = 200
  4187. br.Success = true
  4188. br.Msg = "获取成功"
  4189. br.Data = resp
  4190. }
  4191. // @Title 删除客户
  4192. // @Description 删除客户接口
  4193. // @Param request body company.DeletePptReq true "type json string"
  4194. // @Success Ret=200 保存成功
  4195. // @router /delete [post]
  4196. func (this *CompanyController) Delete() {
  4197. br := new(models.BaseResponse).Init()
  4198. defer func() {
  4199. this.Data["json"] = br
  4200. this.ServeJSON()
  4201. }()
  4202. sysUser := this.SysUser
  4203. if sysUser == nil {
  4204. br.Msg = "请登录"
  4205. br.ErrMsg = "请登录,SysUser Is Empty"
  4206. br.Ret = 408
  4207. return
  4208. }
  4209. var req company.DeletePptReq
  4210. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  4211. if err != nil {
  4212. br.Msg = "参数解析异常!"
  4213. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  4214. return
  4215. }
  4216. if req.CompanyId <= 0 {
  4217. br.Msg = "参数错误"
  4218. br.ErrMsg = "客户ID小于等于0"
  4219. return
  4220. }
  4221. roleTypeCode := this.SysUser.RoleTypeCode
  4222. productId := services.GetProductId(roleTypeCode)
  4223. productItems, err := company.GetCompanyProductsByCompanyId(req.CompanyId)
  4224. if err != nil {
  4225. br.Msg = "删除失败"
  4226. br.ErrMsg = "获取客户产品信息失败,Err:" + err.Error()
  4227. return
  4228. }
  4229. // 备份信息
  4230. companyDeleteBakInfo := services.CompanyDeleteBakInfo{
  4231. CompanyId: req.CompanyId,
  4232. CompanyName: "",
  4233. CompanyInfo: &company.Company{},
  4234. CompanyProductInfo: make([]*company.CompanyProduct, 0),
  4235. CompanyPermissionInfo: make([]*company.CompanyReportPermission, 0),
  4236. UserSellerRelationInfo: make([]*models.UserSellerRelation, 0),
  4237. UserRecordInfo: make([]*models.UserRecord, 0),
  4238. UserInfo: make([]*models.WxUser, 0),
  4239. CompanyChartPermissionInfo: make([]*company_user.ChartClassifyPermission, 0),
  4240. OpUserId: this.SysUser.AdminId,
  4241. OpUserName: this.SysUser.RealName,
  4242. }
  4243. if productId == 0 {
  4244. for _, v := range productItems {
  4245. //永续,试用,流失,关闭
  4246. 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 {
  4247. br.Msg = "该客户" + v.ProductName + "属性为" + v.Status + ",暂不可删除"
  4248. br.ErrMsg = "该客户" + v.ProductName + "属性为" + v.Status + ",暂不可删除"
  4249. return
  4250. }
  4251. companyProductList, companyReportPermissionList, err := company.DeleteCompanyProductById(v.CompanyId, v.ProductId, v.CompanyProductId)
  4252. if err != nil {
  4253. br.Msg = "删除失败"
  4254. br.ErrMsg = "删除失败,Err:" + err.Error()
  4255. return
  4256. }
  4257. companyDeleteBakInfo.CompanyProductInfo = append(companyDeleteBakInfo.CompanyProductInfo, companyProductList...)
  4258. companyDeleteBakInfo.CompanyPermissionInfo = append(companyDeleteBakInfo.CompanyPermissionInfo, companyReportPermissionList...)
  4259. //新增操作记录
  4260. {
  4261. record := new(company.CompanyOperationRecord)
  4262. record.CompanyId = req.CompanyId
  4263. record.CompanyName = v.CompanyName
  4264. record.SellerId = v.SellerId
  4265. record.SysUserId = this.SysUser.AdminId
  4266. record.SysRealName = this.SysUser.RealName
  4267. record.Remark = "删除客户"
  4268. record.Operation = "delete"
  4269. record.CreateTime = time.Now()
  4270. record.ProductId = v.ProductId
  4271. record.ProductName = v.ProductName
  4272. _, err = company.AddCompanyOperationRecord(record)
  4273. if err != nil {
  4274. go alarm_msg.SendAlarmMsg("URI:"+this.Ctx.Input.URI()+"<br/> "+";<br/> Body:"+err.Error(), 3)
  4275. //go utils.SendEmail(utils.APPNAME+"失败提醒"+utils.RunMode, "URI:"+this.Ctx.Input.URI()+"<br/> "+";<br/> Body:"+err.Error(), utils.EmailSendToUsers)
  4276. }
  4277. }
  4278. //删除对应产品的联系人
  4279. userSellerRelationList, userRecordList, wxUserList, chartClassifyPermission, _ := services.DeleteCompanyWxUserByProductId(v.CompanyId, v.ProductId)
  4280. //备份信息
  4281. {
  4282. if companyProductList != nil {
  4283. companyDeleteBakInfo.CompanyProductInfo = append(companyDeleteBakInfo.CompanyProductInfo, companyProductList...)
  4284. }
  4285. if companyReportPermissionList != nil {
  4286. companyDeleteBakInfo.CompanyPermissionInfo = append(companyDeleteBakInfo.CompanyPermissionInfo, companyReportPermissionList...)
  4287. }
  4288. if userSellerRelationList != nil {
  4289. companyDeleteBakInfo.UserSellerRelationInfo = append(companyDeleteBakInfo.UserSellerRelationInfo, userSellerRelationList...)
  4290. }
  4291. if userRecordList != nil {
  4292. companyDeleteBakInfo.UserRecordInfo = append(companyDeleteBakInfo.UserRecordInfo, userRecordList...)
  4293. }
  4294. if wxUserList != nil {
  4295. companyDeleteBakInfo.UserInfo = append(companyDeleteBakInfo.UserInfo, wxUserList...)
  4296. }
  4297. if chartClassifyPermission != nil {
  4298. companyDeleteBakInfo.CompanyChartPermissionInfo = append(companyDeleteBakInfo.CompanyChartPermissionInfo, chartClassifyPermission...)
  4299. }
  4300. companyDeleteBakInfo.CompanyName = v.CompanyName
  4301. }
  4302. }
  4303. } else {
  4304. productObj, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, productId)
  4305. if err != nil {
  4306. br.ErrMsg = "获取客户产品信息失败,Err:" + err.Error()
  4307. br.Msg = "删除失败"
  4308. return
  4309. }
  4310. //永续,试用,流失,关闭
  4311. 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 {
  4312. br.Msg = "该客户" + productObj.ProductName + "属性为" + productObj.Status + ",暂不可删除"
  4313. br.ErrMsg = "该客户" + productObj.ProductName + "属性为" + productObj.Status + ",暂不可删除"
  4314. return
  4315. }
  4316. companyProductList, companyReportPermissionList, err := company.DeleteCompanyProductById(productObj.CompanyId, productObj.ProductId, productObj.CompanyProductId)
  4317. if err != nil {
  4318. br.Msg = "删除失败"
  4319. br.ErrMsg = "删除失败,Err:" + err.Error()
  4320. return
  4321. }
  4322. //新增操作记录
  4323. {
  4324. record := new(company.CompanyOperationRecord)
  4325. record.CompanyId = req.CompanyId
  4326. record.CompanyName = productObj.CompanyName
  4327. record.SellerId = productObj.SellerId
  4328. record.SysUserId = this.SysUser.AdminId
  4329. record.SysRealName = this.SysUser.RealName
  4330. record.Remark = "删除客户"
  4331. record.Operation = "delete"
  4332. record.CreateTime = time.Now()
  4333. record.ProductId = productObj.ProductId
  4334. record.ProductName = productObj.ProductName
  4335. _, err = company.AddCompanyOperationRecord(record)
  4336. if err != nil {
  4337. go alarm_msg.SendAlarmMsg("URI:"+this.Ctx.Input.URI()+"<br/> "+";<br/> Body:"+err.Error(), 3)
  4338. //go utils.SendEmail(utils.APPNAME+"失败提醒"+utils.RunMode, "URI:"+this.Ctx.Input.URI()+"<br/> "+";<br/> Body:"+err.Error(), utils.EmailSendToUsers)
  4339. }
  4340. }
  4341. //删除对应产品的联系人
  4342. userSellerRelationList, userRecordList, wxUserList, chartClassifyPermission, _ := services.DeleteCompanyWxUserByProductId(productObj.CompanyId, productId)
  4343. //备份信息
  4344. {
  4345. if companyProductList != nil {
  4346. companyDeleteBakInfo.CompanyProductInfo = append(companyDeleteBakInfo.CompanyProductInfo, companyProductList...)
  4347. }
  4348. if companyReportPermissionList != nil {
  4349. companyDeleteBakInfo.CompanyPermissionInfo = append(companyDeleteBakInfo.CompanyPermissionInfo, companyReportPermissionList...)
  4350. }
  4351. if userSellerRelationList != nil {
  4352. companyDeleteBakInfo.UserSellerRelationInfo = append(companyDeleteBakInfo.UserSellerRelationInfo, userSellerRelationList...)
  4353. }
  4354. if userRecordList != nil {
  4355. companyDeleteBakInfo.UserRecordInfo = append(companyDeleteBakInfo.UserRecordInfo, userRecordList...)
  4356. }
  4357. if wxUserList != nil {
  4358. companyDeleteBakInfo.UserInfo = append(companyDeleteBakInfo.UserInfo, wxUserList...)
  4359. }
  4360. if chartClassifyPermission != nil {
  4361. companyDeleteBakInfo.CompanyChartPermissionInfo = append(companyDeleteBakInfo.CompanyChartPermissionInfo, chartClassifyPermission...)
  4362. }
  4363. companyDeleteBakInfo.CompanyName = productObj.CompanyName
  4364. }
  4365. }
  4366. productItemsNew, err := company.GetCompanyProductsByCompanyId(req.CompanyId)
  4367. if err != nil {
  4368. br.Msg = "删除失败"
  4369. br.ErrMsg = "获取客户产品信息失败,Err:" + err.Error()
  4370. return
  4371. }
  4372. if len(productItemsNew) == 0 {
  4373. //删除之前查询的数据信息
  4374. {
  4375. companyProductLists, companyReportPermissions, wxUsers, userSellerRelations, companyContracts, companyContractPermissions, companyInfo, _ := services.GetBeforeDeleteCompanyInfo(req.CompanyId)
  4376. //companyDeleteBakInfo
  4377. if companyProductLists != nil {
  4378. companyDeleteBakInfo.CompanyProductInfo = append(companyDeleteBakInfo.CompanyProductInfo, companyProductLists...)
  4379. }
  4380. if companyReportPermissions != nil {
  4381. companyDeleteBakInfo.CompanyPermissionInfo = append(companyDeleteBakInfo.CompanyPermissionInfo, companyReportPermissions...)
  4382. }
  4383. if wxUsers != nil {
  4384. companyDeleteBakInfo.UserInfo = append(companyDeleteBakInfo.UserInfo, wxUsers...)
  4385. }
  4386. if userSellerRelations != nil {
  4387. companyDeleteBakInfo.UserSellerRelationInfo = append(companyDeleteBakInfo.UserSellerRelationInfo, userSellerRelations...)
  4388. }
  4389. if companyContracts != nil {
  4390. companyDeleteBakInfo.CompanyContract = append(companyDeleteBakInfo.CompanyContract, companyContracts...)
  4391. }
  4392. if companyContractPermissions != nil {
  4393. companyDeleteBakInfo.CompanyContractPermission = append(companyDeleteBakInfo.CompanyContractPermission, companyContractPermissions...)
  4394. }
  4395. if companyInfo != nil {
  4396. companyDeleteBakInfo.CompanyName = companyInfo.CompanyName
  4397. companyDeleteBakInfo.CompanyInfo = companyInfo
  4398. }
  4399. }
  4400. err = company.DeleteCompanyById(req.CompanyId)
  4401. if err != nil {
  4402. br.Msg = "删除失败"
  4403. br.ErrMsg = "删除失败,Err:" + err.Error()
  4404. return
  4405. }
  4406. for _, v := range productItems {
  4407. //新增操作记录
  4408. {
  4409. record := new(company.CompanyOperationRecord)
  4410. record.CompanyId = req.CompanyId
  4411. record.CompanyName = v.CompanyName
  4412. record.SellerId = v.SellerId
  4413. record.SysUserId = this.SysUser.AdminId
  4414. record.SysRealName = this.SysUser.RealName
  4415. record.Remark = "删除客户"
  4416. record.Operation = "delete"
  4417. record.CreateTime = time.Now()
  4418. record.ProductId = v.ProductId
  4419. record.ProductName = v.ProductName
  4420. _, err = company.AddCompanyOperationRecord(record)
  4421. if err != nil {
  4422. go alarm_msg.SendAlarmMsg("URI:"+this.Ctx.Input.URI()+"<br/> "+";<br/> Body:"+err.Error(), 3)
  4423. //go utils.SendEmail(utils.APPNAME+"失败提醒"+utils.RunMode, "URI:"+this.Ctx.Input.URI()+"<br/> "+";<br/> Body:"+err.Error(), utils.EmailSendToUsers)
  4424. }
  4425. }
  4426. }
  4427. }
  4428. //数据备份入库
  4429. {
  4430. companyInfoJsonByte, _ := json.Marshal(companyDeleteBakInfo.CompanyInfo)
  4431. companyProductInfoJsonByte, _ := json.Marshal(companyDeleteBakInfo.CompanyProductInfo)
  4432. companyPermissionInfoJsonByte, _ := json.Marshal(companyDeleteBakInfo.CompanyPermissionInfo)
  4433. userSellerRelationInfoJsonByte, _ := json.Marshal(companyDeleteBakInfo.UserSellerRelationInfo)
  4434. userRecordInfoJsonByte, _ := json.Marshal(companyDeleteBakInfo.UserRecordInfo)
  4435. userInfoJsonByte, _ := json.Marshal(companyDeleteBakInfo.UserInfo)
  4436. companyChartPermissionInfoJsonByte, _ := json.Marshal(companyDeleteBakInfo.CompanyChartPermissionInfo)
  4437. companyContractByte, _ := json.Marshal(companyDeleteBakInfo.CompanyContract)
  4438. companyContractPermissionJsonByte, _ := json.Marshal(companyDeleteBakInfo.CompanyContractPermission)
  4439. companyDeleteBak := &company.CompanyDeleteBak{
  4440. //DeleteBakId: 0,
  4441. CompanyId: companyDeleteBakInfo.CompanyId,
  4442. CompanyName: companyDeleteBakInfo.CompanyName,
  4443. CompanyInfo: string(companyInfoJsonByte),
  4444. CompanyProductInfo: string(companyProductInfoJsonByte),
  4445. CompanyPermissionInfo: string(companyPermissionInfoJsonByte),
  4446. UserSellerRelationInfo: string(userSellerRelationInfoJsonByte),
  4447. UserRecordInfo: string(userRecordInfoJsonByte),
  4448. UserInfo: string(userInfoJsonByte),
  4449. CompanyChartPermissionInfo: string(companyChartPermissionInfoJsonByte),
  4450. CompanyContractInfo: string(companyContractByte),
  4451. CompanyContractPermissionInfo: string(companyContractPermissionJsonByte),
  4452. OpUserId: this.SysUser.AdminId,
  4453. OpUserName: this.SysUser.RealName,
  4454. CreateTime: time.Now(),
  4455. }
  4456. _ = company.AddCompanyDeleteBak(companyDeleteBak)
  4457. }
  4458. br.Ret = 200
  4459. br.Success = true
  4460. br.Msg = "删除成功"
  4461. }
  4462. // @Title 领取客户列表
  4463. // @Description 领取客户列表接口
  4464. // @Param PageSize query int true "每页数据条数"
  4465. // @Param CurrentIndex query int true "当前页页码,从1开始"
  4466. // @Param StartDate query string true "开始时间"
  4467. // @Param EndDate query string true "结束时间"
  4468. // @Param KeyWord query string true "搜索关键词"
  4469. // @Success 200 {object} company.CompanyReceiveListResp
  4470. // @router /receive/list [get]
  4471. func (this *CompanyController) ReceiveList() {
  4472. br := new(models.BaseResponse).Init()
  4473. defer func() {
  4474. this.Data["json"] = br
  4475. this.ServeJSON()
  4476. }()
  4477. sysUser := this.SysUser
  4478. if sysUser == nil {
  4479. br.Msg = "请登录"
  4480. br.ErrMsg = "请登录,SysUser Is Empty"
  4481. br.Ret = 408
  4482. return
  4483. }
  4484. var productId, recevieProductId int
  4485. roleTypeCode := sysUser.RoleTypeCode
  4486. productId = services.GetProductId(roleTypeCode)
  4487. if productId == 1 {
  4488. recevieProductId = 2
  4489. } else if productId == 2 {
  4490. recevieProductId = 1
  4491. }
  4492. if productId == 0 {
  4493. br.Msg = "参数错误"
  4494. br.ErrMsg = "客户类型为:" + roleTypeCode
  4495. return
  4496. }
  4497. pageSize, _ := this.GetInt("PageSize")
  4498. currentIndex, _ := this.GetInt("CurrentIndex")
  4499. adminId := this.GetString("AdminId")
  4500. startDate := this.GetString("StartDate")
  4501. endDate := this.GetString("EndDate")
  4502. keyWord := this.GetString("KeyWord")
  4503. var startSize int
  4504. if pageSize <= 0 {
  4505. pageSize = utils.PageSize20
  4506. }
  4507. if currentIndex <= 0 {
  4508. currentIndex = 1
  4509. }
  4510. startSize = paging.StartIndex(currentIndex, pageSize)
  4511. var condition string
  4512. var pars []interface{}
  4513. if adminId != "" {
  4514. condition += ` AND c.seller_id IN (` + adminId + `) `
  4515. }
  4516. if startDate != "" {
  4517. condition += ` AND c.start_date>=? `
  4518. pars = append(pars, startDate)
  4519. }
  4520. if endDate != "" {
  4521. condition += ` AND c.end_date>=? `
  4522. pars = append(pars, endDate)
  4523. }
  4524. if keyWord != "" {
  4525. condition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR b.mobile LIKE '%` + keyWord + `%' OR b.email LIKE '%` + keyWord + `%') `
  4526. }
  4527. total, err := company.GetCompanyReceiveListCount(condition, pars, productId, recevieProductId)
  4528. if err != nil {
  4529. br.Msg = "获取失败"
  4530. br.ErrMsg = "获取数据总数失败,Err:" + err.Error()
  4531. return
  4532. }
  4533. list, err := company.GetCompanyReceiveList(condition, pars, productId, recevieProductId, startSize, pageSize)
  4534. if err != nil {
  4535. br.Msg = "获取失败"
  4536. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  4537. return
  4538. }
  4539. lenList := len(list)
  4540. for i := 0; i < lenList; i++ {
  4541. item := list[i]
  4542. var expireDay string
  4543. if item.Status != "" {
  4544. status := item.Status
  4545. if item.EndDate != "" {
  4546. if status == utils.COMPANY_STATUS_FOREVER { //永续
  4547. expireDay = "-"
  4548. } else if status == utils.COMPANY_STATUS_TRY_OUT { //试用/正式
  4549. endDateTime, _ := time.Parse(utils.FormatDate, item.EndDate)
  4550. sub := endDateTime.Sub(time.Now())
  4551. expireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
  4552. } else if status == utils.COMPANY_STATUS_LOSE { //流失
  4553. expireDay = "-"
  4554. } else if status == utils.COMPANY_STATUS_FREEZE { //冻结
  4555. if item.StartDate != "" && item.EndDate != "" {
  4556. endDateTime, _ := time.Parse(utils.FormatDate, item.EndDate)
  4557. sub := endDateTime.Sub(time.Now())
  4558. expireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
  4559. } else {
  4560. expireDay = "-"
  4561. }
  4562. } else {
  4563. expireDay = "-"
  4564. }
  4565. }
  4566. }
  4567. list[i].ExpireDay = expireDay
  4568. }
  4569. page := paging.GetPaging(currentIndex, pageSize, total)
  4570. resp := new(company.CompanyReceiveListResp)
  4571. resp.List = list
  4572. resp.Paging = page
  4573. br.Ret = 200
  4574. br.Success = true
  4575. br.Msg = "获取成功"
  4576. br.Data = resp
  4577. }
  4578. // @Title 领取客户
  4579. // @Description 领取客户接口
  4580. // @Param request body company.CompanyReceiveReq true "type json string"
  4581. // @Success Ret=200 领取成功
  4582. // @router /receive [post]
  4583. func (this *CompanyController) Receive() {
  4584. br := new(models.BaseResponse).Init()
  4585. defer func() {
  4586. this.Data["json"] = br
  4587. this.ServeJSON()
  4588. }()
  4589. sysUser := this.SysUser
  4590. if sysUser == nil {
  4591. br.Msg = "请登录"
  4592. br.ErrMsg = "请登录,SysUser Is Empty"
  4593. br.Ret = 408
  4594. return
  4595. }
  4596. var req company.CompanyReceiveReq
  4597. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  4598. if err != nil {
  4599. br.Msg = "参数解析异常!"
  4600. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  4601. return
  4602. }
  4603. if req.CompanyId <= 0 {
  4604. br.Msg = "参数异常!"
  4605. br.ErrMsg = "CompanyId:" + strconv.Itoa(req.CompanyId)
  4606. return
  4607. }
  4608. //权益主观客观权限一块开
  4609. if req.PermissionIds != "" {
  4610. permissionStr, err := company.GetPermissionIdById(req.PermissionIds)
  4611. if err != nil {
  4612. br.Msg = "获取信息失败"
  4613. br.ErrMsg = "获取主观客观权限信息失败,Err:" + err.Error()
  4614. return
  4615. }
  4616. req.PermissionIds = permissionStr
  4617. }
  4618. roleTypeCode := sysUser.RoleTypeCode
  4619. productId := services.GetProductId(roleTypeCode)
  4620. if productId == 0 {
  4621. br.Msg = "参数错误"
  4622. br.ErrMsg = "客户类型为:" + roleTypeCode
  4623. return
  4624. }
  4625. sellsId := 0
  4626. if req.SellsId <= 0 {
  4627. sellsId = sysUser.AdminId
  4628. } else {
  4629. sellsId = req.SellsId
  4630. }
  4631. seller, err := system.GetSysAdminById(sellsId)
  4632. if err != nil {
  4633. br.Msg = "获取销售信息失败"
  4634. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  4635. return
  4636. }
  4637. companyDetail, err := company.GetCompanyDetailById(req.CompanyId)
  4638. if err != nil {
  4639. br.Msg = "获取客户信息失败"
  4640. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  4641. return
  4642. }
  4643. cp, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, productId)
  4644. if err != nil && err.Error() != utils.ErrNoRow() {
  4645. br.Msg = "获取客户信息失败"
  4646. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  4647. return
  4648. }
  4649. productName := ""
  4650. var status string
  4651. if productId == 1 {
  4652. productName = utils.COMPANY_PRODUCT_FICC_NAME
  4653. } else {
  4654. productName = utils.COMPANY_PRODUCT_RAI_NAME
  4655. }
  4656. if cp != nil {
  4657. if cp.Status != utils.COMPANY_STATUS_LOSE {
  4658. br.Msg = "客户状态为:" + cp.Status + ";不可领取"
  4659. br.ErrMsg = "客户状态为:" + cp.Status + ";不可领取"
  4660. return
  4661. }
  4662. if cp.SellerId == sysUser.AdminId {
  4663. br.Msg = "已为自己客户,不可重复领取"
  4664. br.ErrMsg = "已为自己客户,不可领取:company_id:" + strconv.Itoa(cp.CompanyId)
  4665. return
  4666. }
  4667. //转移 销售
  4668. companyReportPermissionList, startDate, endDate, err := company.MoveSeller(req.CompanyId, productId, seller.AdminId, seller.GroupId, seller.DepartmentId, seller.RealName)
  4669. if err != nil {
  4670. br.Msg = "领取失败"
  4671. br.ErrMsg = "领取失败,Err:" + err.Error()
  4672. return
  4673. }
  4674. //新增客户产品状态变更日志
  4675. {
  4676. companyProductUpdateLog := &company.CompanyProductUpdateLog{
  4677. Id: 0,
  4678. CompanyId: req.CompanyId,
  4679. ProductId: productId,
  4680. Status: "试用",
  4681. Source: "receive",
  4682. SellerId: seller.AdminId,
  4683. SellerName: seller.RealName,
  4684. StartDate: startDate,
  4685. EndDate: endDate,
  4686. RealEndDate: startDate,
  4687. CreateTime: time.Now(),
  4688. }
  4689. go company.AddCompanyProductUpdateLog(companyProductUpdateLog)
  4690. companyProductTryOutUpdateLog := &company.CompanyProductTryOutUpdateLog{
  4691. Id: 0,
  4692. CompanyId: req.CompanyId,
  4693. ProductId: productId,
  4694. Source: "receive",
  4695. SellerId: seller.AdminId,
  4696. SellerName: seller.RealName,
  4697. StartDate: startDate,
  4698. EndDate: endDate,
  4699. RealEndDate: startDate,
  4700. IsStop: 0,
  4701. CreateTime: time.Now(),
  4702. }
  4703. go company.AddCompanyProductTryOutUpdateLog(companyProductTryOutUpdateLog, companyReportPermissionList)
  4704. }
  4705. //流失转试用,企业下面的用户自动添加产业关注
  4706. {
  4707. go cygxService.AddUserFllowCompanyLossToTryOut(req.CompanyId)
  4708. }
  4709. } else {
  4710. //跨部门领取
  4711. var startDateTime, endDateTime time.Time
  4712. if req.Status == utils.COMPANY_STATUS_TRY_OUT {
  4713. startDateTime = time.Now()
  4714. endDateTime = time.Now().AddDate(0, 2, 0)
  4715. } else if req.Status == utils.COMPANY_STATUS_FOREVER {
  4716. startDateTime = time.Now()
  4717. endDateTime = time.Now().AddDate(100, 0, 0)
  4718. } else {
  4719. br.Msg = "无效的客户状态,请重新选择"
  4720. return
  4721. }
  4722. var startDate, endDate string
  4723. startDate = startDateTime.Format(utils.FormatDate)
  4724. endDate = endDateTime.Format(utils.FormatDate)
  4725. if req.PermissionIds == "" {
  4726. br.Msg = "请选择权限!"
  4727. return
  4728. }
  4729. industry, err := company.GetCompanyIndustryById(req.IndustryId)
  4730. if err != nil {
  4731. br.Msg = "获取行业信息失败"
  4732. br.ErrMsg = "获取行业信息失败,Err:" + err.Error()
  4733. return
  4734. }
  4735. if industry == nil {
  4736. br.Msg = "行业信息不存在"
  4737. return
  4738. }
  4739. status = req.Status
  4740. companyProduct := new(company.CompanyProduct)
  4741. companyProduct.CompanyId = req.CompanyId
  4742. companyProduct.ProductId = productId
  4743. companyProduct.ProductName = productName
  4744. companyProduct.CompanyName = companyDetail.CompanyName
  4745. companyProduct.Source = req.Source
  4746. companyProduct.Reasons = req.Reasons
  4747. companyProduct.Status = status
  4748. companyProduct.StartDate = startDate
  4749. companyProduct.EndDate = endDate
  4750. companyProduct.IndustryId = req.IndustryId
  4751. companyProduct.IndustryName = industry.IndustryName
  4752. companyProduct.SellerId = seller.AdminId
  4753. companyProduct.SellerName = seller.RealName
  4754. companyProduct.GroupId = seller.GroupId
  4755. companyProduct.DepartmentId = seller.DepartmentId
  4756. companyProduct.IsSuspend = 0
  4757. companyProduct.CreateTime = time.Now()
  4758. companyProduct.ModifyTime = time.Now()
  4759. companyProduct.CompanyType = req.CompanyType
  4760. companyProduct.OpenCode = services.GenerateOpenCompanyProductCode(req.CompanyId, productId)
  4761. companyProduct.TodoStatus = "无任务"
  4762. companyProduct.TryStage = 1
  4763. _, err = company.AddCompanyProduct(companyProduct)
  4764. if err != nil {
  4765. br.Msg = "新增失败"
  4766. br.ErrMsg = "新增客户产品失败,err:" + err.Error()
  4767. return
  4768. }
  4769. companyReportPermissionList, err := services.AddCompanyPermission(req.CompanyId, seller.AdminId, productId, productName, seller.RealName, req.PermissionIds, startDate, endDate)
  4770. if err != nil {
  4771. br.Msg = "新增失败"
  4772. br.ErrMsg = "新增客户设置权限失败,err:" + err.Error()
  4773. return
  4774. }
  4775. //新增客户产品日志
  4776. {
  4777. go services.AddCompanyProductLog(companyProduct, this.SysUser.AdminId, "add")
  4778. }
  4779. //新增客户产品状态变更日志
  4780. {
  4781. companyProductUpdateLog := &company.CompanyProductUpdateLog{
  4782. Id: 0,
  4783. CompanyId: companyProduct.CompanyId,
  4784. ProductId: companyProduct.ProductId,
  4785. Status: "试用",
  4786. SellerId: seller.AdminId,
  4787. SellerName: seller.RealName,
  4788. Source: "add",
  4789. StartDate: startDateTime,
  4790. EndDate: endDateTime,
  4791. RealEndDate: startDateTime,
  4792. CreateTime: time.Now(),
  4793. }
  4794. go company.AddCompanyProductUpdateLog(companyProductUpdateLog)
  4795. companyProductTryOutUpdateLog := &company.CompanyProductTryOutUpdateLog{
  4796. Id: 0,
  4797. CompanyId: companyProduct.CompanyId,
  4798. ProductId: companyProduct.ProductId,
  4799. SellerId: seller.AdminId,
  4800. SellerName: seller.RealName,
  4801. Source: "add",
  4802. StartDate: startDateTime,
  4803. EndDate: endDateTime,
  4804. RealEndDate: startDateTime,
  4805. IsStop: 0,
  4806. CreateTime: time.Now(),
  4807. }
  4808. go company.AddCompanyProductTryOutUpdateLog(companyProductTryOutUpdateLog, companyReportPermissionList)
  4809. }
  4810. //查询当前客户的所有产品的列表数据,并找出非当前产品的销售去发送模板消息
  4811. companyProductList, err := company.GetCompanyProductsByCompanyId(req.CompanyId)
  4812. for _, companyProduct := range companyProductList {
  4813. //如果是当前领取的产品,那么就退出当前循环,进入下一循环
  4814. if companyProduct.ProductId == productId {
  4815. continue
  4816. }
  4817. //查询其他部门销售的信息
  4818. admin, tmpErr := system.GetSysAdminById(companyProduct.SellerId)
  4819. if tmpErr != nil {
  4820. continue
  4821. }
  4822. //发送模板消息给另一个部门的销售
  4823. go services.SendCompanyReceiveWxTemplateMsg(companyDetail.CompanyName, productName, sysUser.RealName, admin.Mobile)
  4824. }
  4825. }
  4826. //新增操作记录
  4827. {
  4828. remark := "领取客户"
  4829. operation := "receive"
  4830. services.AddCompanyOperationRecord(req.CompanyId, seller.AdminId, sysUser.AdminId, productId, sysUser.AdminId, companyDetail.CompanyName,
  4831. productName, sysUser.RealName, remark, operation, "", sysUser.RealName, "", status)
  4832. }
  4833. br.Ret = 200
  4834. br.Success = true
  4835. br.Msg = "领取成功"
  4836. }
  4837. // @Title 移动销售
  4838. // @Description 移动销售接口
  4839. // @Param request body company.MoveSellerReq true "type json string"
  4840. // @Success Ret=200 移动成功
  4841. // @router /move/seller [post]
  4842. func (this *CompanyController) MoveSeller() {
  4843. br := new(models.BaseResponse).Init()
  4844. defer func() {
  4845. this.Data["json"] = br
  4846. this.ServeJSON()
  4847. }()
  4848. sysUser := this.SysUser
  4849. if sysUser == nil {
  4850. br.Msg = "请登录"
  4851. br.ErrMsg = "请登录,SysUser Is Empty"
  4852. br.Ret = 408
  4853. return
  4854. }
  4855. var req company.MoveSellerReq
  4856. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  4857. if err != nil {
  4858. br.Msg = "参数解析异常!"
  4859. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  4860. return
  4861. }
  4862. if req.CompanyId <= 0 {
  4863. br.Msg = "参数异常!"
  4864. br.ErrMsg = "CompanyId:" + strconv.Itoa(req.CompanyId)
  4865. return
  4866. }
  4867. if req.SellsId <= 0 {
  4868. br.Msg = "参数异常!"
  4869. br.ErrMsg = "SellsId:" + strconv.Itoa(req.SellsId)
  4870. return
  4871. }
  4872. seller, err := system.GetSysAdminById(req.SellsId)
  4873. if err != nil {
  4874. br.Msg = "获取销售信息失败"
  4875. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  4876. return
  4877. }
  4878. roleTypeCode := sysUser.RoleTypeCode
  4879. productId := services.GetProductId(roleTypeCode)
  4880. if productId == 0 {
  4881. if req.CompanyType == utils.COMPANY_CLASSIFY_FICC {
  4882. productId = 1
  4883. } else if req.CompanyType == utils.COMPANY_CLASSIFY_RAI {
  4884. productId = 2
  4885. }
  4886. }
  4887. if productId == 0 {
  4888. br.Msg = "无效的客户类型"
  4889. br.ErrMsg = "无效的客户类型"
  4890. return
  4891. }
  4892. cp, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, productId)
  4893. if err != nil && err.Error() != utils.ErrNoRow() {
  4894. if err.Error() == utils.ErrNoRow() {
  4895. br.Msg = "客户信息不存在"
  4896. br.ErrMsg = "客户信息不存在,Err:" + err.Error()
  4897. return
  4898. }
  4899. br.Msg = "获取客户信息失败"
  4900. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  4901. return
  4902. }
  4903. fmt.Println(cp)
  4904. if cp == nil {
  4905. br.Msg = "客户信息不存在,请刷新页面"
  4906. br.ErrMsg = "客户信息不存在"
  4907. return
  4908. }
  4909. err = company.MoveCompanySeller(req.CompanyId, productId, req.SellsId, seller.GroupId, seller.DepartmentId, seller.RealName)
  4910. if err != nil {
  4911. br.Msg = "移动失败"
  4912. br.ErrMsg = "移动失败,Err:" + err.Error()
  4913. return
  4914. }
  4915. //新增操作记录
  4916. {
  4917. remark := "移动到:" + seller.RealName
  4918. operation := "move_seller"
  4919. services.AddCompanyOperationRecord(req.CompanyId, seller.AdminId, sysUser.AdminId, productId, sysUser.AdminId, cp.CompanyName,
  4920. cp.ProductName, sysUser.RealName, remark, operation, "", sysUser.RealName, "", cp.Status)
  4921. }
  4922. //变更销售员与联系人关系
  4923. _ = models.UpdateUserSellerRelationByCompanyId(req.CompanyId, productId, seller.AdminId, seller.RealName)
  4924. br.Ret = 200
  4925. br.Success = true
  4926. br.Msg = "移动成功"
  4927. }
  4928. // @Title 修改试用客户标签
  4929. // @Description 修改试用客户标签接口
  4930. // @Param request body company.UpdateTryStageReq true "type json string"
  4931. // @Success Ret=200 设置成功
  4932. // @router /update/tryStage [post]
  4933. func (this *CompanyController) UpdateTryStage() {
  4934. br := new(models.BaseResponse).Init()
  4935. defer func() {
  4936. this.Data["json"] = br
  4937. this.ServeJSON()
  4938. }()
  4939. sysUser := this.SysUser
  4940. if sysUser == nil {
  4941. br.Msg = "请登录"
  4942. br.ErrMsg = "请登录,SysUser Is Empty"
  4943. br.Ret = 408
  4944. return
  4945. }
  4946. var req company.UpdateTryStageReq
  4947. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  4948. if err != nil {
  4949. br.Msg = "参数解析异常!"
  4950. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  4951. return
  4952. }
  4953. if req.CompanyId <= 0 {
  4954. br.Msg = "参数异常!"
  4955. br.ErrMsg = "CompanyId:" + strconv.Itoa(req.CompanyId)
  4956. return
  4957. }
  4958. if req.ProductId <= 0 {
  4959. br.Msg = "参数异常!"
  4960. br.ErrMsg = "ProductId:" + strconv.Itoa(req.ProductId)
  4961. return
  4962. }
  4963. if req.TryStage <= 0 {
  4964. br.Msg = "参数异常!"
  4965. br.ErrMsg = "TryStage:" + strconv.Itoa(req.TryStage)
  4966. return
  4967. }
  4968. cp, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, req.ProductId)
  4969. if err != nil && err.Error() != utils.ErrNoRow() {
  4970. if err.Error() == utils.ErrNoRow() {
  4971. br.Msg = "客户信息不存在"
  4972. br.ErrMsg = "客户信息不存在,Err:" + err.Error()
  4973. return
  4974. }
  4975. br.Msg = "获取客户信息失败"
  4976. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  4977. return
  4978. }
  4979. fmt.Println(cp)
  4980. if cp == nil {
  4981. br.Msg = "客户信息不存在,请刷新页面"
  4982. br.ErrMsg = "客户信息不存在"
  4983. return
  4984. }
  4985. if cp.Status != "试用" {
  4986. br.Msg = "客户不是试用状态,不允许修改"
  4987. br.ErrMsg = "客户不是试用状态,不允许修改"
  4988. return
  4989. }
  4990. if cp.SellerId != sysUser.AdminId {
  4991. br.Msg = "无修改权限"
  4992. br.ErrMsg = "无修改权限"
  4993. return
  4994. }
  4995. if cp.TryStage == req.TryStage {
  4996. br.Msg = "与原标签一致,无需修改"
  4997. br.ErrMsg = "与原标签一致,无需修改"
  4998. return
  4999. }
  5000. err = company.UpdateCompanyTryStage(req.CompanyId, req.ProductId, req.TryStage)
  5001. if err != nil {
  5002. br.Msg = "设置失败"
  5003. br.ErrMsg = "设置失败,Err:" + err.Error()
  5004. return
  5005. }
  5006. //新增操作记录
  5007. {
  5008. stage := ""
  5009. tryStageAllMap := map[int]string{
  5010. 1: "未分类",
  5011. 2: "推进",
  5012. 3: "跟踪",
  5013. 4: "预备",
  5014. }
  5015. if v, ok := tryStageAllMap[req.TryStage]; ok {
  5016. stage = v
  5017. }
  5018. remark := "修改试用客户子标签:" + stage
  5019. operation := "UpdateTryStage"
  5020. services.AddCompanyOperationRecord(req.CompanyId, cp.SellerId, sysUser.AdminId, req.ProductId, sysUser.AdminId, cp.CompanyName,
  5021. cp.ProductName, sysUser.RealName, remark, operation, "", sysUser.RealName, "", cp.Status)
  5022. }
  5023. br.Ret = 200
  5024. br.Success = true
  5025. br.Msg = "设置成功"
  5026. }
  5027. // @Title 暂停/启用
  5028. // @Description 暂停/启用接口
  5029. // @Param request body company.SuspendReq true "type json string"
  5030. // @Success Ret=200 移动成功
  5031. // @router /suspend [post]
  5032. func (this *CompanyController) Suspend() {
  5033. br := new(models.BaseResponse).Init()
  5034. defer func() {
  5035. this.Data["json"] = br
  5036. this.ServeJSON()
  5037. }()
  5038. sysUser := this.SysUser
  5039. if sysUser == nil {
  5040. br.Msg = "请登录"
  5041. br.ErrMsg = "请登录,SysUser Is Empty"
  5042. br.Ret = 408
  5043. return
  5044. }
  5045. var req company.SuspendReq
  5046. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  5047. if err != nil {
  5048. br.Msg = "参数解析异常!"
  5049. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  5050. return
  5051. }
  5052. if req.CompanyId <= 0 {
  5053. br.Msg = "参数异常!"
  5054. br.ErrMsg = "CompanyId:" + strconv.Itoa(req.CompanyId)
  5055. return
  5056. }
  5057. roleTypeCode := sysUser.RoleTypeCode
  5058. productId := services.GetProductId(roleTypeCode)
  5059. if productId == 0 {
  5060. br.Msg = "参数错误"
  5061. br.ErrMsg = "角色类型为:" + roleTypeCode
  5062. return
  5063. }
  5064. cp, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, productId)
  5065. if err != nil {
  5066. br.Msg = "获取数据异常!"
  5067. br.ErrMsg = "获取数据异常:" + err.Error()
  5068. return
  5069. }
  5070. suspendStatus := ""
  5071. suspend := 0
  5072. if cp.IsSuspend == 1 {
  5073. suspendStatus = "启用"
  5074. suspend = 0
  5075. } else {
  5076. suspendStatus = "暂停"
  5077. suspend = 1
  5078. }
  5079. if cp.Status != utils.COMPANY_STATUS_TRY_OUT {
  5080. br.Msg = "客户状态为:" + cp.Status + ",不允许进行" + suspendStatus + "操作"
  5081. br.ErrMsg = "客户状态为:" + cp.Status + ",不允许进行" + suspendStatus + "操作"
  5082. return
  5083. }
  5084. err = company.SuspendCompanyProductById(req.CompanyId, productId, suspend)
  5085. if err != nil {
  5086. br.Msg = suspendStatus + "失败"
  5087. br.ErrMsg = suspendStatus + "失败 Err:" + err.Error()
  5088. return
  5089. }
  5090. //新增操作记录
  5091. {
  5092. remark := suspendStatus
  5093. operation := "is_suspend"
  5094. services.AddCompanyOperationRecord(req.CompanyId, cp.SellerId, sysUser.AdminId, productId, sysUser.AdminId, cp.CompanyName,
  5095. cp.ProductName, sysUser.RealName, remark, operation, "", sysUser.RealName, "", cp.Status)
  5096. }
  5097. br.Ret = 200
  5098. br.Success = true
  5099. br.Msg = suspendStatus + "成功"
  5100. }
  5101. // @Title 检测客户名称或社会信用码
  5102. // @Description 检测客户名称或社会信用码接口(新增/编辑客户页面使用)
  5103. // @Param CompanyName query string true "客户名称"
  5104. // @Param CreditCode query string true "社会统一信用码"
  5105. // @Success 200 {object} company.CheckCompanyInfoResp
  5106. // @router /check/companyInfo [get]
  5107. func (this *CompanyController) CheckCompanyInfo() {
  5108. br := new(models.BaseResponse).Init()
  5109. defer func() {
  5110. this.Data["json"] = br
  5111. this.ServeJSON()
  5112. }()
  5113. sysUser := this.SysUser
  5114. if sysUser == nil {
  5115. br.Msg = "请登录"
  5116. br.ErrMsg = "请登录,SysUser Is Empty"
  5117. br.Ret = 408
  5118. return
  5119. }
  5120. roleTypeCode := sysUser.RoleTypeCode
  5121. productId := services.GetProductId(roleTypeCode)
  5122. companyName := this.GetString("CompanyName")
  5123. creditCode := this.GetString("CreditCode")
  5124. var status, comanyId int
  5125. var productName string
  5126. if productId == 0 {
  5127. productId = 1
  5128. checkProductId := 2
  5129. if companyName != "" {
  5130. nameItem, err := company.CheckCompanyProductByName(companyName, productId)
  5131. if err != nil && err.Error() != utils.ErrNoRow() {
  5132. br.Msg = "校验客户名称是否存在失败"
  5133. br.ErrMsg = "校验客户名称是否存在失败,Err:" + err.Error()
  5134. return
  5135. }
  5136. if nameItem != nil && nameItem.CompanyId > 0 {
  5137. br.Msg = "客户名称已存在,请重新填写"
  5138. br.ErrMsg = "客户名称已存在,请重新填写"
  5139. br.Ret = 405
  5140. return
  5141. }
  5142. nameCheckItem, err := company.CheckCompanyProductByName(companyName, checkProductId)
  5143. if err != nil && err.Error() != utils.ErrNoRow() {
  5144. br.Msg = "校验客户名称是否存在失败"
  5145. br.ErrMsg = "校验客户名称是否存在失败,Err:" + err.Error() + " productId:" + strconv.Itoa(productId) + ";checkProductId:" + strconv.Itoa(checkProductId)
  5146. return
  5147. }
  5148. if nameCheckItem != nil && nameCheckItem.CompanyId > 0 {
  5149. status = 1
  5150. productName = nameCheckItem.ProductName
  5151. comanyId = nameCheckItem.CompanyId
  5152. goto Loop
  5153. }
  5154. }
  5155. if creditCode != "" {
  5156. codeItem, err := company.CheckCompanyProductByCreditCode(creditCode, productId)
  5157. if err != nil && err.Error() != utils.ErrNoRow() {
  5158. br.Msg = "校验社会信用码是否存在失败"
  5159. br.ErrMsg = "校验社会信用码是否存在失败,Err:" + err.Error()
  5160. return
  5161. }
  5162. if codeItem != nil && codeItem.CompanyId > 0 {
  5163. br.Msg = "社会信用码已存在,请重新填写"
  5164. br.ErrMsg = "社会信用码已存在,请重新填写"
  5165. br.Ret = 405
  5166. return
  5167. }
  5168. codeCheckItem, err := company.CheckCompanyProductByCreditCode(creditCode, checkProductId)
  5169. if err != nil && err.Error() != utils.ErrNoRow() {
  5170. br.Msg = "校验社会信用码是否存在失败"
  5171. br.ErrMsg = "校验社会信用码是否存在失败,Err:" + err.Error() + " productId:" + strconv.Itoa(productId) + ";checkProductId:" + strconv.Itoa(checkProductId)
  5172. return
  5173. }
  5174. if codeCheckItem != nil && codeCheckItem.CompanyId > 0 {
  5175. status = 1
  5176. productName = codeCheckItem.ProductName
  5177. comanyId = codeCheckItem.CompanyId
  5178. goto Loop
  5179. }
  5180. }
  5181. productId = 2
  5182. checkProductId = 1
  5183. if companyName != "" {
  5184. nameItem, err := company.CheckCompanyProductByName(companyName, productId)
  5185. if err != nil && err.Error() != utils.ErrNoRow() {
  5186. br.Msg = "校验客户名称是否存在失败"
  5187. br.ErrMsg = "校验客户名称是否存在失败,Err:" + err.Error()
  5188. return
  5189. }
  5190. if nameItem != nil && nameItem.CompanyId > 0 {
  5191. br.Msg = "客户名称已存在,请重新填写"
  5192. br.ErrMsg = "客户名称已存在,请重新填写"
  5193. br.Ret = 405
  5194. return
  5195. }
  5196. nameCheckItem, err := company.CheckCompanyProductByName(companyName, checkProductId)
  5197. if err != nil && err.Error() != utils.ErrNoRow() {
  5198. br.Msg = "校验客户名称是否存在失败"
  5199. br.ErrMsg = "校验客户名称是否存在失败,Err:" + err.Error() + " productId:" + strconv.Itoa(productId) + ";checkProductId:" + strconv.Itoa(checkProductId)
  5200. return
  5201. }
  5202. if nameCheckItem != nil && nameCheckItem.CompanyId > 0 {
  5203. status = 1
  5204. productName = nameCheckItem.ProductName
  5205. comanyId = nameCheckItem.CompanyId
  5206. goto Loop
  5207. }
  5208. }
  5209. if creditCode != "" {
  5210. codeItem, err := company.CheckCompanyProductByCreditCode(creditCode, productId)
  5211. if err != nil && err.Error() != utils.ErrNoRow() {
  5212. br.Msg = "校验社会信用码是否存在失败"
  5213. br.ErrMsg = "校验社会信用码是否存在失败,Err:" + err.Error()
  5214. return
  5215. }
  5216. if codeItem != nil && codeItem.CompanyId > 0 {
  5217. br.Msg = "社会信用码已存在,请重新填写"
  5218. br.ErrMsg = "社会信用码已存在,请重新填写"
  5219. br.Ret = 405
  5220. return
  5221. }
  5222. codeCheckItem, err := company.CheckCompanyProductByCreditCode(creditCode, checkProductId)
  5223. if err != nil && err.Error() != utils.ErrNoRow() {
  5224. br.Msg = "校验社会信用码是否存在失败"
  5225. br.ErrMsg = "校验社会信用码是否存在失败,Err:" + err.Error() + " productId:" + strconv.Itoa(productId) + ";checkProductId:" + strconv.Itoa(checkProductId)
  5226. return
  5227. }
  5228. if codeCheckItem != nil && codeCheckItem.CompanyId > 0 {
  5229. status = 1
  5230. productName = codeCheckItem.ProductName
  5231. comanyId = codeCheckItem.CompanyId
  5232. goto Loop
  5233. }
  5234. }
  5235. } else {
  5236. checkProductId := 0
  5237. if productId == 1 {
  5238. checkProductId = 2
  5239. } else if productId == 2 {
  5240. checkProductId = 1
  5241. }
  5242. if companyName != "" {
  5243. nameItem, err := company.CheckCompanyProductByName(companyName, productId)
  5244. if err != nil && err.Error() != utils.ErrNoRow() {
  5245. br.Msg = "校验客户名称是否存在失败"
  5246. br.ErrMsg = "校验客户名称是否存在失败,Err:" + err.Error()
  5247. return
  5248. }
  5249. if nameItem != nil && nameItem.ProductName != "" {
  5250. br.Msg = "客户名称已存在,请重新填写"
  5251. br.ErrMsg = "客户名称已存在,请重新填写"
  5252. br.Ret = 405
  5253. return
  5254. }
  5255. nameCheckoutItem, err := company.CheckCompanyProductByName(companyName, checkProductId)
  5256. if err != nil && err.Error() != utils.ErrNoRow() {
  5257. br.Msg = "校验客户名称是否存在失败"
  5258. br.ErrMsg = "校验客户名称是否存在失败,Err:" + err.Error() + " productId:" + strconv.Itoa(productId) + ";checkProductId:" + strconv.Itoa(checkProductId)
  5259. return
  5260. }
  5261. if nameCheckoutItem != nil && nameCheckoutItem.CompanyId > 0 {
  5262. status = 1
  5263. productName = nameCheckoutItem.ProductName
  5264. comanyId = nameCheckoutItem.CompanyId
  5265. goto Loop
  5266. }
  5267. }
  5268. if creditCode != "" {
  5269. codeItem, err := company.CheckCompanyProductByCreditCode(creditCode, productId)
  5270. if err != nil && err.Error() != utils.ErrNoRow() {
  5271. br.Msg = "校验社会信用码是否存在失败"
  5272. br.ErrMsg = "校验社会信用码是否存在失败,Err:" + err.Error()
  5273. return
  5274. }
  5275. if codeItem != nil && codeItem.CompanyId > 0 {
  5276. br.Msg = "社会信用码已存在,请重新填写"
  5277. br.ErrMsg = "社会信用码已存在,请重新填写"
  5278. br.Ret = 405
  5279. return
  5280. }
  5281. codeCheckItem, err := company.CheckCompanyProductByCreditCode(creditCode, checkProductId)
  5282. if err != nil && err.Error() != utils.ErrNoRow() {
  5283. br.Msg = "校验社会信用码是否存在失败"
  5284. br.ErrMsg = "校验社会信用码是否存在失败,Err:" + err.Error() + " productId:" + strconv.Itoa(productId) + ";checkProductId:" + strconv.Itoa(checkProductId)
  5285. return
  5286. }
  5287. if codeCheckItem != nil && codeCheckItem.CompanyId > 0 {
  5288. status = 1
  5289. productName = codeCheckItem.ProductName
  5290. comanyId = codeCheckItem.CompanyId
  5291. goto Loop
  5292. }
  5293. }
  5294. }
  5295. Loop:
  5296. resp := new(company.CheckCompanyInfoResp)
  5297. resp.Status = status
  5298. resp.ProductName = productName
  5299. resp.CompanyId = comanyId
  5300. br.Ret = 200
  5301. br.Success = true
  5302. br.Msg = "获取成功"
  5303. br.Data = resp
  5304. }
  5305. // @Title 客户导出
  5306. // @Description 客户导出接口
  5307. // @Param Status query string true "状态:'试用','永续','冻结','流失','正式'"
  5308. // @Param CompanyType query string true "客户类型:传空字符串或者不传为全部,'ficc','权益'"
  5309. // @Param IndustryId query int true "行业id,0为全部"
  5310. // @Param AdminId query string true "销售id,多个用英文逗号隔开,空字符串为全部"
  5311. // @Param ChartPermissionIds query string false "阅读权限品种ID,多个用英文逗号分开,空字符串为全部"
  5312. // @Param ContractPermissionIds query string false "已购品种ID,多个用英文逗号分开,空字符串为全部"
  5313. // @Param StartDate query string true "开始时间"
  5314. // @Param EndDate query string true "结束时间"
  5315. // @Param CreateStartDate query string true "创建开始时间"
  5316. // @Param CreateEndDate query string true "创建结束时间"
  5317. // @Param KeyWord query string true "搜索关键词"
  5318. // @Param Address query string true "地址 , 多个用英文逗号分开 "
  5319. // @Param Province query string true "省 , 多个用英文逗号分开 "
  5320. // @Param City query string true "市 , 多个用英文逗号分开 "
  5321. // @Param PackageType query int true "套餐类型,0:无,1:大套餐,2:小套餐"
  5322. // @Success 200 {object} company.CompanyListResp
  5323. // @router /export [get]
  5324. func (this *CompanyController) Export() {
  5325. br := new(models.BaseResponse).Init()
  5326. defer func() {
  5327. this.Data["json"] = br
  5328. this.ServeJSON()
  5329. }()
  5330. sysUser := this.SysUser
  5331. if sysUser == nil {
  5332. br.Msg = "请登录"
  5333. br.ErrMsg = "请登录,SysUser Is Empty"
  5334. br.Ret = 408
  5335. return
  5336. }
  5337. roleTypeCode := sysUser.RoleTypeCode
  5338. status := this.GetString("Status")
  5339. companyType := this.GetString("CompanyType")
  5340. industryId, _ := this.GetInt("IndustryId")
  5341. adminId := this.GetString("AdminId")
  5342. chartPermissionIds := this.GetString("ChartPermissionIds")
  5343. contractPermissionIds := this.GetString("ContractPermissionIds")
  5344. startDate := this.GetString("StartDate")
  5345. endDate := this.GetString("EndDate")
  5346. createStartDate := this.GetString("CreateStartDate")
  5347. createEndDate := this.GetString("CreateEndDate")
  5348. keyWord := this.GetString("KeyWord")
  5349. keyWord = strings.Trim(keyWord, " ")
  5350. address := this.GetString("Address")
  5351. province := this.GetString("Province")
  5352. city := this.GetString("City")
  5353. // 套餐类型
  5354. packageType, _ := this.GetInt("PackageType")
  5355. resp := new(company.CompanyListResp)
  5356. statusItems := make([]*company.CompanyStatus, 0)
  5357. var statusArr = [...]string{"全部", "试用", "正式", "冻结", "流失", "永续"}
  5358. var condition string
  5359. var pars []interface{}
  5360. //状态分类查询条件
  5361. var permissionCondition string
  5362. var permissionPars []interface{}
  5363. if companyType != "" {
  5364. condition += ` AND b.product_name=? `
  5365. pars = append(pars, companyType)
  5366. }
  5367. if industryId > 0 {
  5368. condition += ` AND b.industry_id=? `
  5369. pars = append(pars, industryId)
  5370. }
  5371. if adminId != "" {
  5372. condition += ` AND b.seller_id IN (` + adminId + `) `
  5373. }
  5374. if startDate != "" {
  5375. condition += ` AND b.start_date>=? `
  5376. pars = append(pars, startDate)
  5377. }
  5378. if endDate != "" {
  5379. condition += ` AND b.end_date<=? `
  5380. pars = append(pars, endDate)
  5381. }
  5382. if createStartDate != "" {
  5383. condition += ` AND a.created_time>=? `
  5384. pars = append(pars, createStartDate)
  5385. }
  5386. if createEndDate != "" {
  5387. condition += ` AND a.created_time<=? `
  5388. pars = append(pars, createEndDate)
  5389. }
  5390. if address != "" {
  5391. var addressSql string
  5392. slice := strings.Split(address, ",")
  5393. for _, v := range slice {
  5394. addressSql += "'" + v + "'" + ","
  5395. }
  5396. addressSql = strings.TrimRight(addressSql, ",")
  5397. condition += ` AND a.address IN (` + addressSql + `) `
  5398. }
  5399. if province != "" {
  5400. var provinceSql string
  5401. slice := strings.Split(province, ",")
  5402. for _, v := range slice {
  5403. provinceSql += "'" + v + "'" + ","
  5404. }
  5405. provinceSql = strings.TrimRight(provinceSql, ",")
  5406. condition += ` AND a.province IN (` + provinceSql + `) `
  5407. }
  5408. if city != "" {
  5409. var citySql string
  5410. slice := strings.Split(city, ",")
  5411. for _, v := range slice {
  5412. citySql += "'" + v + "'" + ","
  5413. }
  5414. citySql = strings.TrimRight(citySql, ",")
  5415. condition += ` AND a.city IN (` + citySql + `) `
  5416. }
  5417. if keyWord != "" {
  5418. companyIdStr, err := company.GetCompanyIdByKeyWord(keyWord)
  5419. if err != nil {
  5420. br.Msg = "获取客户信息失败"
  5421. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  5422. return
  5423. }
  5424. if companyIdStr != "" {
  5425. condition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.company_id IN(` + companyIdStr + `)) `
  5426. } else {
  5427. condition += ` AND (a.company_name LIKE '%` + keyWord + `%' ) `
  5428. }
  5429. }
  5430. //if chartPermissionIds != "" && chartPermissionIds != "1" {
  5431. // companyIdStr, err := company.GetCompanyListCompanyIdByPermissionIdStr(chartPermissionIds)
  5432. // if err != nil {
  5433. // br.Msg = "获取失败"
  5434. // br.ErrMsg = "根据权限获取公司ID失败,Err:" + err.Error()
  5435. // return
  5436. // }
  5437. // if companyIdStr != "" {
  5438. // condition += ` AND a.company_id IN (` + companyIdStr + `) `
  5439. // } else {
  5440. // for _, v := range statusArr {
  5441. // statusCount := new(company.CompanyStatus)
  5442. // if v == "全部" {
  5443. // statusCount.Status = "全部"
  5444. // statusCount.Count = 0
  5445. // } else {
  5446. // statusCount.Status = v
  5447. // statusCount.Count = 0
  5448. // }
  5449. // statusItems = append(statusItems, statusCount)
  5450. // }
  5451. // items := make([]*company.CompanyListItem, 0)
  5452. // resp.List = items
  5453. // resp.StatusCount = statusItems
  5454. // br.Msg = "获取成功"
  5455. // br.Ret = 200
  5456. // br.Data = resp
  5457. // return
  5458. // }
  5459. //}
  5460. // 阅读权限/已购品种筛选
  5461. cond, emp, e := services.FilterReadAndContractAuth(chartPermissionIds, contractPermissionIds, condition)
  5462. if e != nil {
  5463. br.Msg = "获取失败"
  5464. br.ErrMsg = "FilterReadAndContractAuth err: " + e.Error()
  5465. return
  5466. }
  5467. if emp {
  5468. for _, v := range statusArr {
  5469. statusCount := new(company.CompanyStatus)
  5470. if v == "全部" {
  5471. statusCount.Status = "全部"
  5472. statusCount.Count = 0
  5473. } else {
  5474. statusCount.Status = v
  5475. statusCount.Count = 0
  5476. }
  5477. statusItems = append(statusItems, statusCount)
  5478. }
  5479. items := make([]*company.CompanyListItem, 0)
  5480. resp.List = items
  5481. resp.StatusCount = statusItems
  5482. br.Msg = "获取成功"
  5483. br.Ret = 200
  5484. br.Data = resp
  5485. return
  5486. }
  5487. condition = cond
  5488. //套餐类型
  5489. if packageType > 0 {
  5490. condition += ` AND b.package_type=? `
  5491. pars = append(pars, packageType)
  5492. }
  5493. permissionCondition = condition
  5494. permissionPars = pars
  5495. productId := services.GetProductId(roleTypeCode)
  5496. //权限控制
  5497. {
  5498. //如果不是超级管理员
  5499. if roleTypeCode != utils.ROLE_TYPE_CODE_ADMIN {
  5500. //如果是部门管理员
  5501. if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  5502. condition += ` AND b.product_id=? `
  5503. pars = append(pars, productId)
  5504. permissionCondition += ` AND b.product_id=? `
  5505. permissionPars = append(permissionPars, productId)
  5506. } else {
  5507. condition += ` AND b.product_id=? `
  5508. pars = append(pars, productId)
  5509. permissionCondition += ` AND b.product_id=? `
  5510. permissionPars = append(permissionPars, productId)
  5511. if status == "全部" {
  5512. ////如果是筛选了流失客户状态
  5513. if sysUser.Authority <= 0 {
  5514. condition += ` AND (b.seller_id=? OR status='流失') `
  5515. pars = append(pars, sysUser.AdminId)
  5516. permissionCondition += ` AND b.seller_id=? `
  5517. permissionPars = append(permissionPars, sysUser.AdminId)
  5518. } else {
  5519. if sysUser.Authority == 1 {
  5520. condition += ` AND (b.department_id=? OR status='流失')`
  5521. pars = append(pars, sysUser.DepartmentId)
  5522. permissionCondition += ` AND b.department_id=? `
  5523. permissionPars = append(permissionPars, sysUser.DepartmentId)
  5524. }
  5525. if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  5526. if status != utils.COMPANY_STATUS_LOSE {
  5527. condition += ` AND (b.group_id=? OR status='流失') `
  5528. pars = append(pars, sysUser.GroupId)
  5529. }
  5530. permissionCondition += ` AND b.group_id=? `
  5531. permissionPars = append(permissionPars, sysUser.GroupId)
  5532. }
  5533. if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
  5534. pid, err := company.GetParentIdFromGroup(sysUser.GroupId)
  5535. if err != nil {
  5536. br.Msg = "获取失败"
  5537. br.ErrMsg = "查询父级id异常" + err.Error()
  5538. return
  5539. }
  5540. var ids []*string
  5541. if pid != nil && *pid != 0 {
  5542. ids, err = company.GetGroupIdsByParentId(*pid)
  5543. if err != nil {
  5544. fmt.Println(err.Error())
  5545. }
  5546. } else {
  5547. ids, err = company.GetGroupIdsByParentId(sysUser.GroupId)
  5548. if err != nil {
  5549. fmt.Println(err.Error())
  5550. }
  5551. }
  5552. var idSlice []string
  5553. var sid string
  5554. for _, id := range ids {
  5555. idSlice = append(idSlice, *id)
  5556. }
  5557. //加入父级groupId
  5558. if *pid > 0 {
  5559. idSlice = append(idSlice, strconv.Itoa(*pid))
  5560. } else {
  5561. idSlice = append(idSlice, strconv.Itoa(sysUser.GroupId))
  5562. }
  5563. sid = strings.Join(idSlice, ",")
  5564. if len(sid) > 0 {
  5565. if status != utils.COMPANY_STATUS_LOSE {
  5566. condition += ` AND (b.group_id IN (` + sid + `) OR status='流失') `
  5567. //pars = append(pars, sysUser.GroupId)
  5568. }
  5569. permissionCondition += ` AND b.group_id IN (` + sid + `) `
  5570. } else {
  5571. if status != utils.COMPANY_STATUS_LOSE {
  5572. condition += ` AND (b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) OR status='流失') `
  5573. //pars = append(pars, sysUser.GroupId)
  5574. }
  5575. permissionCondition += ` AND b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) `
  5576. }
  5577. }
  5578. }
  5579. } else {
  5580. ////如果没有筛选了流失客户状态
  5581. if sysUser.Authority <= 0 {
  5582. condition += ` AND b.seller_id=? `
  5583. pars = append(pars, sysUser.AdminId)
  5584. permissionCondition += ` AND b.seller_id=? `
  5585. permissionPars = append(permissionPars, sysUser.AdminId)
  5586. } else {
  5587. if sysUser.Authority == 1 {
  5588. condition += ` AND b.department_id=?`
  5589. pars = append(pars, sysUser.DepartmentId)
  5590. permissionCondition += ` AND b.department_id=? `
  5591. permissionPars = append(permissionPars, sysUser.DepartmentId)
  5592. }
  5593. if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  5594. if status != utils.COMPANY_STATUS_LOSE {
  5595. condition += ` AND b.group_id=? `
  5596. pars = append(pars, sysUser.GroupId)
  5597. }
  5598. permissionCondition += ` AND b.group_id=? `
  5599. permissionPars = append(permissionPars, sysUser.GroupId)
  5600. }
  5601. if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
  5602. pid, err := company.GetParentIdFromGroup(sysUser.GroupId)
  5603. if err != nil {
  5604. br.Msg = "获取失败"
  5605. br.ErrMsg = "查询父级id异常" + err.Error()
  5606. return
  5607. }
  5608. var ids []*string
  5609. if pid != nil && *pid != 0 {
  5610. ids, err = company.GetGroupIdsByParentId(*pid)
  5611. if err != nil {
  5612. fmt.Println(err.Error())
  5613. }
  5614. } else {
  5615. ids, err = company.GetGroupIdsByParentId(sysUser.GroupId)
  5616. if err != nil {
  5617. fmt.Println(err.Error())
  5618. }
  5619. }
  5620. var idSlice []string
  5621. var sid string
  5622. for _, id := range ids {
  5623. idSlice = append(idSlice, *id)
  5624. }
  5625. //加入父级groupId
  5626. if *pid > 0 {
  5627. idSlice = append(idSlice, strconv.Itoa(*pid))
  5628. } else {
  5629. idSlice = append(idSlice, strconv.Itoa(sysUser.GroupId))
  5630. }
  5631. sid = strings.Join(idSlice, ",")
  5632. if len(sid) > 0 {
  5633. if status != utils.COMPANY_STATUS_LOSE {
  5634. condition += ` AND (b.group_id IN (` + sid + `) OR status='流失') `
  5635. //pars = append(pars, sysUser.GroupId)
  5636. }
  5637. permissionCondition += ` AND b.group_id IN (` + sid + `) `
  5638. } else {
  5639. if status != utils.COMPANY_STATUS_LOSE {
  5640. condition += ` AND (b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) OR status='流失') `
  5641. //pars = append(pars, sysUser.GroupId)
  5642. }
  5643. permissionCondition += ` AND b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) `
  5644. }
  5645. }
  5646. if sysUser.Authority == 4 {
  5647. if status != utils.COMPANY_STATUS_LOSE {
  5648. condition += ` AND b.group_id =? `
  5649. pars = append(pars, sysUser.GroupId)
  5650. }
  5651. permissionCondition += ` AND b.group_id=? `
  5652. permissionPars = append(permissionPars, sysUser.GroupId)
  5653. }
  5654. }
  5655. }
  5656. }
  5657. }
  5658. }
  5659. //状态控制
  5660. if status != "" && status != "全部" && status != utils.COMPANY_STATUS_LOSE {
  5661. condition += ` AND b.status=? `
  5662. pars = append(pars, status)
  5663. }
  5664. dir, err := os.Executable()
  5665. exPath := filepath.Dir(dir)
  5666. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  5667. xlsxFile := xlsx.NewFile()
  5668. if err != nil {
  5669. br.Msg = "生成文件失败"
  5670. br.ErrMsg = "生成文件失败"
  5671. return
  5672. }
  5673. style := xlsx.NewStyle()
  5674. alignment := xlsx.Alignment{
  5675. Horizontal: "center",
  5676. Vertical: "center",
  5677. WrapText: true,
  5678. }
  5679. style.Alignment = alignment
  5680. style.ApplyAlignment = true
  5681. sheel, err := xlsxFile.AddSheet("客户数据")
  5682. if err != nil {
  5683. br.Msg = "新增Sheet失败"
  5684. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  5685. return
  5686. }
  5687. titleArr := []string{"客户名称", "客户地址", "客户类型", "所属行业", "所属销售", "客户状态", "服务期限", "到期天数", "创建时间", "权限详情"}
  5688. titleLen := len(titleArr)
  5689. titleRow := sheel.AddRow()
  5690. remarkRow := sheel.AddRow() // 备注行
  5691. // 填充空白至Z列
  5692. emptyColNum := 0
  5693. for i := 0; i < 26; i++ {
  5694. remarkRow.AddCell().SetValue("")
  5695. if i >= titleLen {
  5696. emptyColNum += 1
  5697. titleRow.AddCell().SetValue("")
  5698. continue
  5699. }
  5700. titleRow.AddCell().SetValue(titleArr[i])
  5701. }
  5702. // AA列开始为品种权限
  5703. ficcPermissions := make([]int, 0) // 用于后续判断试用暂停客户是否需要暂停这部分权限
  5704. raiPermissions := make([]int, 0)
  5705. permissions, e := models.GetChartPermissionList()
  5706. if e != nil {
  5707. br.Msg = "获取失败"
  5708. br.ErrMsg = "获取品种数据失败,Err:" + err.Error()
  5709. return
  5710. }
  5711. raiArr := []string{"医药", "消费", "科技", "智造"}
  5712. for _, p := range permissions {
  5713. if p.ProductId == 1 {
  5714. ficcPermissions = append(ficcPermissions, p.ChartPermissionId)
  5715. }
  5716. if p.ProductId == 2 {
  5717. raiPermissions = append(raiPermissions, p.ChartPermissionId)
  5718. }
  5719. if utils.InArrayByStr(raiArr, p.PermissionName) {
  5720. titleRow.AddCell().SetValue(p.Remark)
  5721. continue
  5722. }
  5723. titleRow.AddCell().SetValue(p.PermissionName)
  5724. }
  5725. // 第二行, 在品种权限开始列加一行标红备注
  5726. styleRed := xlsx.NewStyle()
  5727. styleRed.Font.Color = "ff0000"
  5728. remarkCell := remarkRow.AddCell()
  5729. remarkCell.SetStyle(styleRed)
  5730. remarkCell.SetString(`第一位数字表示是否已购买该品种,1表示已购,0表示未购;第二位数字表示是否有阅读权限,1表示有权限,0表示没有`)
  5731. list, err := company.GetCompanyListExport(condition, pars)
  5732. if err != nil {
  5733. br.Msg = "获取失败"
  5734. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  5735. return
  5736. }
  5737. companyIds := make([]int, 0)
  5738. for _, c := range list {
  5739. companyIds = append(companyIds, c.CompanyId)
  5740. }
  5741. // 获取客户对应的阅读和合同权限集合
  5742. contractPermissionMap := make(map[int][]int)
  5743. contractPermissions, e := company.GetContractPermissionIdsByCompanyIds(companyIds)
  5744. if e != nil {
  5745. br.Msg = "获取失败"
  5746. br.ErrMsg = "获取已购权限失败, Err: " + e.Error()
  5747. return
  5748. }
  5749. for _, p := range contractPermissions {
  5750. ids := make([]int, 0)
  5751. if p.ChartPermissionIds != "" {
  5752. idArr := strings.Split(p.ChartPermissionIds, ",")
  5753. for _, i := range idArr {
  5754. id, _ := strconv.Atoi(i)
  5755. ids = append(ids, id)
  5756. }
  5757. }
  5758. contractPermissionMap[p.CompanyId] = ids
  5759. }
  5760. reportPermissionMap := make(map[int][]int)
  5761. reportPermissions, e := company.GetReportPermissionIdsByCompanyIds(companyIds)
  5762. if e != nil {
  5763. br.Msg = "获取失败"
  5764. br.ErrMsg = "获取阅读权限失败, Err: " + e.Error()
  5765. return
  5766. }
  5767. for _, p := range reportPermissions {
  5768. ids := make([]int, 0)
  5769. if p.ChartPermissionIds != "" {
  5770. idArr := strings.Split(p.ChartPermissionIds, ",")
  5771. for _, i := range idArr {
  5772. id, _ := strconv.Atoi(i)
  5773. ids = append(ids, id)
  5774. }
  5775. }
  5776. reportPermissionMap[p.CompanyId] = ids
  5777. }
  5778. cpMap := make(map[int][]*company.ExportCompanyProduct)
  5779. permissionMap := make(map[string]string)
  5780. for _, v := range list {
  5781. cpList := make([]*company.ExportCompanyProduct, 1)
  5782. if cps, ok := cpMap[v.CompanyId]; ok {
  5783. cpList = cps
  5784. } else {
  5785. companyProduct, err := company.GetExportCompanyProduct(v.CompanyId)
  5786. if err != nil {
  5787. br.Msg = "导出失败"
  5788. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  5789. return
  5790. }
  5791. cpMap[v.CompanyId] = companyProduct
  5792. cpList = companyProduct
  5793. }
  5794. var companyName, companyType, industryName, sellerName, status, timeLimt, createTime, source, permissionStr, expireDay string
  5795. isFiccSuspend := 0
  5796. isRaiSuspend := 0
  5797. for ck, cv := range cpList {
  5798. companyName = cv.CompanyName
  5799. if ck >= 1 {
  5800. companyType = companyType + "/" + cv.ProductName
  5801. status = status + "/" + cv.Status
  5802. } else {
  5803. companyType = cv.ProductName
  5804. status = cv.Status
  5805. }
  5806. if cv.ProductId == 1 {
  5807. industryName = "ficc:" + cv.IndustryName
  5808. sellerName = "ficc:" + cv.SellerName
  5809. startDateStr := cv.StartDate.Format("2006/01/02")
  5810. endDateStr := cv.EndDate.Format("2006/01/02")
  5811. timeLimt = "ficc:" + startDateStr + "~" + endDateStr
  5812. createTime = "ficc:" + cv.CreateTime
  5813. source = "ficc:" + cv.Source
  5814. sub := cv.EndDate.Sub(time.Now())
  5815. if sub < 0 {
  5816. sub = 0
  5817. }
  5818. expireDay = "ficc:" + fmt.Sprintf("%v", int(sub.Hours()/24))
  5819. permissionKey := strconv.Itoa(v.CompanyId) + "_" + strconv.Itoa(cv.ProductId)
  5820. permissionStr = "ficc:"
  5821. if newPermissionStr, ok := permissionMap[permissionKey]; ok {
  5822. permissionStr += newPermissionStr
  5823. } else {
  5824. getPermissionStr, err := company.GetExportPermissionName(v.CompanyId, cv.ProductId)
  5825. if err != nil {
  5826. br.Msg = "导出失败"
  5827. br.ErrMsg = "获取客户权限信息失败,Err:" + err.Error()
  5828. return
  5829. }
  5830. permissionMap[permissionKey] = getPermissionStr
  5831. permissionStr += getPermissionStr
  5832. }
  5833. isFiccSuspend = cv.IsSuspend
  5834. } else {
  5835. industryName = industryName + "\n" + "权益:" + cv.IndustryName
  5836. sellerName = sellerName + "\n" + "权益:" + cv.SellerName
  5837. startDateStr := cv.StartDate.Format("2006/01/02")
  5838. endDateStr := cv.EndDate.Format("2006/01/02")
  5839. timeLimt = timeLimt + "\n" + "权益:" + startDateStr + "~" + endDateStr
  5840. createTime = createTime + "\n" + "权益:" + cv.CreateTime
  5841. source = source + "\n" + "权益:" + cv.Source
  5842. sub := cv.EndDate.Sub(time.Now())
  5843. if sub < 0 {
  5844. sub = 0
  5845. }
  5846. expireDay = "\n" + "权益:" + fmt.Sprintf("%v", int(sub.Hours()/24))
  5847. permissionKey := strconv.Itoa(v.CompanyId) + "_" + strconv.Itoa(cv.ProductId)
  5848. if permissionStr != "" {
  5849. permissionStr = permissionStr + "\n" + "权益:"
  5850. } else {
  5851. permissionStr = "权益:"
  5852. }
  5853. if newPermissionStr, ok := permissionMap[permissionKey]; ok {
  5854. permissionStr += newPermissionStr
  5855. } else {
  5856. getPermissionStr, err := company.GetExportPermissionName(v.CompanyId, cv.ProductId)
  5857. if err != nil {
  5858. br.Msg = "导出失败"
  5859. br.ErrMsg = "获取客户权限信息失败,Err:" + err.Error()
  5860. return
  5861. }
  5862. permissionMap[permissionKey] = getPermissionStr
  5863. permissionStr += getPermissionStr
  5864. }
  5865. isRaiSuspend = cv.IsSuspend
  5866. }
  5867. }
  5868. dataRow := sheel.AddRow()
  5869. dataRow.SetHeight(20)
  5870. dataRow.AddCell().SetString(companyName)
  5871. dataRow.AddCell().SetString(v.Address)
  5872. dataRow.AddCell().SetString(companyType)
  5873. dataRow.AddCell().SetString(v.IndustryName)
  5874. dataRow.AddCell().SetString(v.SellerName)
  5875. dataRow.AddCell().SetString(v.Status)
  5876. dataRow.AddCell().SetString(timeLimt)
  5877. dataRow.AddCell().SetString(expireDay)
  5878. dataRow.AddCell().SetString(v.CreatedTime)
  5879. //dataRow.AddCell().SetString(v.Source)
  5880. dataRow.AddCell().SetString(permissionStr)
  5881. // 填充空白至Z列, AA列开始为权限
  5882. for i := 0; i < emptyColNum; i++ {
  5883. dataRow.AddCell().SetString("")
  5884. }
  5885. cpIds := contractPermissionMap[v.CompanyId]
  5886. rpIds := reportPermissionMap[v.CompanyId]
  5887. for _, p := range permissions {
  5888. // 数字含义:11-表示已购且有阅读权限, 01-表示未购买但有阅读权限
  5889. first := 0
  5890. if utils.InArrayByInt(cpIds, p.ChartPermissionId) {
  5891. first = 1
  5892. }
  5893. second := 0
  5894. if utils.InArrayByInt(rpIds, p.ChartPermissionId) {
  5895. second = 1
  5896. // 如果客户是试用暂停, 即使有这部分权限, 也标记为0
  5897. if isFiccSuspend == 1 && utils.InArrayByInt(ficcPermissions, p.ChartPermissionId) {
  5898. second = 0
  5899. }
  5900. if isRaiSuspend == 1 && utils.InArrayByInt(raiPermissions, p.ChartPermissionId) {
  5901. second = 0
  5902. }
  5903. }
  5904. dataRow.AddCell().SetString(fmt.Sprintf("%d%d", first, second))
  5905. }
  5906. }
  5907. err = xlsxFile.Save(downLoadnFilePath)
  5908. if err != nil {
  5909. br.Msg = "保存文件失败"
  5910. br.ErrMsg = "保存文件失败"
  5911. return
  5912. }
  5913. randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
  5914. downloadFileName := "客户列表_" + randStr + ".xlsx"
  5915. this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  5916. defer func() {
  5917. os.Remove(downLoadnFilePath)
  5918. }()
  5919. br.Ret = 200
  5920. br.Success = true
  5921. br.Msg = "导出成功"
  5922. }
  5923. //func (this *CompanyController) ExportOld() {
  5924. // br := new(models.BaseResponse).Init()
  5925. // defer func() {
  5926. // this.Data["json"] = br
  5927. // this.ServeJSON()
  5928. // }()
  5929. // sysUser := this.SysUser
  5930. // if sysUser == nil {
  5931. // br.Msg = "请登录"
  5932. // br.ErrMsg = "请登录,SysUser Is Empty"
  5933. // br.Ret = 408
  5934. // return
  5935. // }
  5936. // roleTypeCode := sysUser.RoleTypeCode
  5937. //
  5938. // status := this.GetString("Status")
  5939. // companyType := this.GetString("CompanyType")
  5940. // industryId, _ := this.GetInt("IndustryId")
  5941. // adminId := this.GetString("AdminId")
  5942. //
  5943. // chartPermissionIds := this.GetString("ChartPermissionIds")
  5944. // startDate := this.GetString("StartDate")
  5945. // endDate := this.GetString("EndDate")
  5946. // createStartDate := this.GetString("CreateStartDate")
  5947. // createEndDate := this.GetString("CreateEndDate")
  5948. // keyWord := this.GetString("KeyWord")
  5949. // keyWord = strings.Trim(keyWord, " ")
  5950. //
  5951. // resp := new(company.CompanyListResp)
  5952. // statusItems := make([]*company.CompanyStatus, 0)
  5953. // var statusArr = [...]string{"全部", "试用", "正式", "冻结", "流失", "永续"}
  5954. //
  5955. // var condition string
  5956. // var pars []interface{}
  5957. //
  5958. // var lossCondition string
  5959. // var lossPars []interface{}
  5960. //
  5961. // var permissionCondition string
  5962. // var permissionPars []interface{}
  5963. //
  5964. // if status != "" && status != "全部" {
  5965. // condition += ` AND b.status=? `
  5966. // pars = append(pars, status)
  5967. //
  5968. // //permissionCondition += ` AND b.status=? `
  5969. // //permissionPars = append(permissionPars, status)
  5970. // }
  5971. // if companyType != "" {
  5972. // condition += ` AND b.product_name=? `
  5973. // pars = append(pars, companyType)
  5974. //
  5975. // lossCondition += ` AND b.product_name=? `
  5976. // lossPars = append(lossPars, companyType)
  5977. //
  5978. // permissionCondition += ` AND b.product_name=? `
  5979. // permissionPars = append(permissionPars, companyType)
  5980. // }
  5981. //
  5982. // if industryId > 0 {
  5983. // condition += ` AND b.industry_id=? `
  5984. // pars = append(pars, industryId)
  5985. //
  5986. // lossCondition += ` AND b.industry_id=? `
  5987. // lossPars = append(lossPars, industryId)
  5988. //
  5989. // permissionCondition += ` AND b.industry_id=? `
  5990. // permissionPars = append(permissionPars, industryId)
  5991. // }
  5992. //
  5993. // if adminId != "" {
  5994. // condition += ` AND b.seller_id IN (` + adminId + `) `
  5995. //
  5996. // lossCondition += ` AND b.seller_id IN (` + adminId + `) `
  5997. //
  5998. // permissionCondition += ` AND b.seller_id IN (` + adminId + `) `
  5999. // }
  6000. //
  6001. // if startDate != "" {
  6002. // condition += ` AND b.start_date>=? `
  6003. // pars = append(pars, startDate)
  6004. //
  6005. // lossCondition += ` AND b.start_date>=? `
  6006. // lossPars = append(lossPars, startDate)
  6007. //
  6008. // permissionCondition += ` AND b.start_date>=? `
  6009. // permissionPars = append(permissionPars, startDate)
  6010. // }
  6011. //
  6012. // if endDate != "" {
  6013. // condition += ` AND b.end_date<=? `
  6014. // pars = append(pars, endDate)
  6015. //
  6016. // lossCondition += ` AND b.end_date<=? `
  6017. // lossPars = append(lossPars, endDate)
  6018. //
  6019. // permissionCondition += ` AND b.end_date<=? `
  6020. // permissionPars = append(permissionPars, endDate)
  6021. // }
  6022. //
  6023. // if createStartDate != "" {
  6024. // condition += ` AND a.created_time>=? `
  6025. // pars = append(pars, createStartDate)
  6026. //
  6027. // lossCondition += ` AND a.created_time>=? `
  6028. // lossPars = append(lossPars, createStartDate)
  6029. //
  6030. // permissionCondition += ` AND a.created_time>=? `
  6031. // permissionPars = append(permissionPars, createStartDate)
  6032. // }
  6033. //
  6034. // if createEndDate != "" {
  6035. // condition += ` AND a.created_time<=? `
  6036. // pars = append(pars, createEndDate)
  6037. //
  6038. // lossCondition += ` AND a.created_time<=? `
  6039. // lossPars = append(lossPars, createEndDate)
  6040. //
  6041. // permissionCondition += ` AND a.created_time<=? `
  6042. // permissionPars = append(permissionPars, createEndDate)
  6043. // }
  6044. //
  6045. // if keyWord != "" {
  6046. // companyIdStr, err := company.GetCompanyIdByKeyWord(keyWord)
  6047. // if err != nil {
  6048. // return
  6049. // }
  6050. // if companyIdStr != "" {
  6051. // condition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.company_id IN(` + companyIdStr + `)) `
  6052. // lossCondition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.company_id IN(` + companyIdStr + `)) `
  6053. //
  6054. // permissionCondition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.company_id IN(` + companyIdStr + `)) `
  6055. // } else {
  6056. // condition += ` AND (a.company_name LIKE '%` + keyWord + `%' ) `
  6057. // lossCondition += ` AND (a.company_name LIKE '%` + keyWord + `%' ) `
  6058. //
  6059. // permissionCondition += ` AND (a.company_name LIKE '%` + keyWord + `%' ) `
  6060. // }
  6061. // }
  6062. //
  6063. // if chartPermissionIds != "" && chartPermissionIds != "1" {
  6064. // //chartPermissionArr := strings.Split(chartPermissionIds, ",")
  6065. // //chartPermissionCount := len(chartPermissionArr)
  6066. // companyIdStr, err := company.GetCompanyListCompanyIdByPermissionIdStr(chartPermissionIds)
  6067. // if err != nil {
  6068. // br.Msg = "获取失败"
  6069. // br.ErrMsg = "根据权限获取公司ID失败,Err:" + err.Error()
  6070. // return
  6071. // }
  6072. // //var companyIdArr []string
  6073. // //for _, v := range companyIdList {
  6074. // // companyIdArr = append(companyIdArr, strconv.Itoa(v.CompanyId))
  6075. // //}
  6076. // //companyIdStr := strings.Join(companyIdArr, ",")
  6077. //
  6078. // if companyIdStr != "" {
  6079. // condition += ` AND a.company_id IN (` + companyIdStr + `) `
  6080. // lossCondition += ` AND a.company_id IN (` + companyIdStr + `) `
  6081. // permissionCondition += ` AND a.company_id IN (` + companyIdStr + `) `
  6082. // } else {
  6083. // for _, v := range statusArr {
  6084. // statusCount := new(company.CompanyStatus)
  6085. // if v == "全部" {
  6086. // statusCount.Status = "全部"
  6087. // statusCount.Count = 0
  6088. // } else {
  6089. // statusCount.Status = v
  6090. // statusCount.Count = 0
  6091. // }
  6092. // statusItems = append(statusItems, statusCount)
  6093. // }
  6094. // items := make([]*company.CompanyListItem, 0)
  6095. // resp.List = items
  6096. // resp.StatusCount = statusItems
  6097. // br.Msg = "获取成功"
  6098. // br.Ret = 200
  6099. // br.Data = resp
  6100. // return
  6101. // }
  6102. // }
  6103. //
  6104. // //权限控制
  6105. // {
  6106. // if roleTypeCode != utils.ROLE_TYPE_CODE_ADMIN {
  6107. // if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN {
  6108. // condition += ` AND b.product_id=? `
  6109. // pars = append(pars, 1)
  6110. //
  6111. // permissionCondition += ` AND b.product_id=? `
  6112. // permissionPars = append(permissionPars, 1)
  6113. // } else if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  6114. // condition += ` AND b.product_id=? `
  6115. // pars = append(pars, 2)
  6116. //
  6117. // permissionCondition += ` AND b.product_id=? `
  6118. // permissionPars = append(permissionPars, 2)
  6119. // } else {
  6120. // if sysUser.Authority <= 0 {
  6121. // if status != utils.COMPANY_STATUS_LOSE {
  6122. // condition += ` AND b.seller_id=? `
  6123. // pars = append(pars, sysUser.AdminId)
  6124. // }
  6125. //
  6126. // permissionCondition += ` AND b.seller_id=? `
  6127. // permissionPars = append(permissionPars, sysUser.AdminId)
  6128. // } else {
  6129. // if sysUser.Authority == 1 {
  6130. // if status != utils.COMPANY_STATUS_LOSE {
  6131. // condition += ` AND b.department_id=? `
  6132. // pars = append(pars, sysUser.DepartmentId)
  6133. // }
  6134. // permissionCondition += ` AND b.department_id=? `
  6135. // permissionPars = append(permissionPars, sysUser.DepartmentId)
  6136. // }
  6137. //
  6138. // if sysUser.Authority == 2 {
  6139. // if status != utils.COMPANY_STATUS_LOSE {
  6140. // condition += ` AND b.group_id=? `
  6141. // pars = append(pars, sysUser.GroupId)
  6142. // }
  6143. // permissionCondition += ` AND b.group_id=? `
  6144. // permissionPars = append(permissionPars, sysUser.GroupId)
  6145. // }
  6146. // }
  6147. // }
  6148. // }
  6149. // }
  6150. //
  6151. // dir, err := os.Executable()
  6152. // exPath := filepath.Dir(dir)
  6153. // downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  6154. // xlsxFile := xlsx.NewFile()
  6155. // if err != nil {
  6156. // br.Msg = "生成文件失败"
  6157. // br.ErrMsg = "生成文件失败"
  6158. // return
  6159. // }
  6160. // style := xlsx.NewStyle()
  6161. // alignment := xlsx.Alignment{
  6162. // Horizontal: "center",
  6163. // Vertical: "center",
  6164. // WrapText: true,
  6165. // }
  6166. //
  6167. // style.Alignment = alignment
  6168. // style.ApplyAlignment = true
  6169. //
  6170. // sheel, err := xlsxFile.AddSheet("客户数据")
  6171. // if err != nil {
  6172. // br.Msg = "新增Sheet失败"
  6173. // br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  6174. // return
  6175. // }
  6176. // titleRow := sheel.AddRow()
  6177. // titleRow.AddCell().SetValue("客户名称")
  6178. // titleRow.AddCell().SetValue("客户类型")
  6179. // titleRow.AddCell().SetValue("所属行业")
  6180. // titleRow.AddCell().SetValue("所属销售")
  6181. // titleRow.AddCell().SetValue("客户状态")
  6182. // titleRow.AddCell().SetValue("服务期限")
  6183. // titleRow.AddCell().SetValue("到期天数")
  6184. // titleRow.AddCell().SetValue("创建时间")
  6185. // titleRow.AddCell().SetValue("客户来源")
  6186. // titleRow.AddCell().SetValue("阅读权限")
  6187. //
  6188. // list, err := company.GetCompanyListExport(condition, pars)
  6189. // if err != nil {
  6190. // br.Msg = "获取失败"
  6191. // br.ErrMsg = "获取数据失败,Err:" + err.Error()
  6192. // return
  6193. // }
  6194. // cpMap := make(map[int][]*company.ExportCompanyProduct)
  6195. // permissionMap := make(map[string]string)
  6196. // for _, v := range list {
  6197. // cpList := make([]*company.ExportCompanyProduct, 1)
  6198. // if cps, ok := cpMap[v.CompanyId]; ok {
  6199. // cpList = cps
  6200. // } else {
  6201. // companyProduct, err := company.GetExportCompanyProduct(v.CompanyId)
  6202. // if err != nil {
  6203. // br.Msg = "导出失败"
  6204. // br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  6205. // return
  6206. // }
  6207. // cpMap[v.CompanyId] = companyProduct
  6208. // cpList = companyProduct
  6209. // }
  6210. // var companyName, companyType, industryName, sellerName, status, timeLimt, createTime, source, permissionStr, expireDay string
  6211. //
  6212. // for ck, cv := range cpList {
  6213. // companyName = cv.CompanyName
  6214. // if ck >= 1 {
  6215. // companyType = companyType + "/" + cv.ProductName
  6216. // status = status + "/" + cv.Status
  6217. // } else {
  6218. // companyType = cv.ProductName
  6219. // status = cv.Status
  6220. // }
  6221. // if cv.ProductId == 1 {
  6222. // industryName = "ficc:" + cv.IndustryName
  6223. // sellerName = "ficc:" + cv.SellerName
  6224. // startDateStr := cv.StartDate.Format("2006/01/02")
  6225. // endDateStr := cv.EndDate.Format("2006/01/02")
  6226. // timeLimt = "ficc:" + startDateStr + "~" + endDateStr
  6227. // createTime = "ficc:" + cv.CreateTime
  6228. // source = "ficc:" + cv.Source
  6229. // sub := cv.EndDate.Sub(time.Now())
  6230. // if sub < 0 {
  6231. // sub = 0
  6232. // }
  6233. // expireDay = "ficc:" + fmt.Sprintf("%v", int(sub.Hours()/24))
  6234. //
  6235. // permissionKey := strconv.Itoa(v.CompanyId) + "_" + strconv.Itoa(cv.ProductId)
  6236. //
  6237. // permissionStr = "ficc:"
  6238. // if newPermissionStr, ok := permissionMap[permissionKey]; ok {
  6239. // permissionStr += newPermissionStr
  6240. // } else {
  6241. // getPermissionStr, err := company.GetExportPermissionName(v.CompanyId, cv.ProductId)
  6242. // if err != nil {
  6243. // br.Msg = "导出失败"
  6244. // br.ErrMsg = "获取客户权限信息失败,Err:" + err.Error()
  6245. // return
  6246. // }
  6247. // permissionMap[permissionKey] = getPermissionStr
  6248. // permissionStr += getPermissionStr
  6249. // }
  6250. // } else {
  6251. // industryName = industryName + "\n" + "权益:" + cv.IndustryName
  6252. // sellerName = sellerName + "\n" + "权益:" + cv.SellerName
  6253. // startDateStr := cv.StartDate.Format("2006/01/02")
  6254. // endDateStr := cv.EndDate.Format("2006/01/02")
  6255. //
  6256. // timeLimt = timeLimt + "\n" + "权益:" + startDateStr + "~" + endDateStr
  6257. // createTime = createTime + "\n" + "权益:" + cv.CreateTime
  6258. // source = source + "\n" + "权益:" + cv.Source
  6259. //
  6260. // sub := cv.EndDate.Sub(time.Now())
  6261. // if sub < 0 {
  6262. // sub = 0
  6263. // }
  6264. // expireDay = "\n" + "权益:" + fmt.Sprintf("%v", int(sub.Hours()/24))
  6265. //
  6266. // permissionKey := strconv.Itoa(v.CompanyId) + "_" + strconv.Itoa(cv.ProductId)
  6267. // if permissionStr != "" {
  6268. // permissionStr = permissionStr + "\n" + "权益:"
  6269. // } else {
  6270. // permissionStr = "权益:"
  6271. // }
  6272. // if newPermissionStr, ok := permissionMap[permissionKey]; ok {
  6273. // permissionStr += newPermissionStr
  6274. // } else {
  6275. // getPermissionStr, err := company.GetExportPermissionName(v.CompanyId, cv.ProductId)
  6276. // if err != nil {
  6277. // br.Msg = "导出失败"
  6278. // br.ErrMsg = "获取客户权限信息失败,Err:" + err.Error()
  6279. // return
  6280. // }
  6281. // permissionMap[permissionKey] = getPermissionStr
  6282. // permissionStr += getPermissionStr
  6283. // }
  6284. // }
  6285. // }
  6286. //
  6287. // dataRow := sheel.AddRow()
  6288. // dataRow.SetHeight(20)
  6289. // dataRow.AddCell().SetString(companyName)
  6290. // dataRow.AddCell().SetString(companyType)
  6291. // dataRow.AddCell().SetString(v.IndustryName)
  6292. // dataRow.AddCell().SetString(v.SellerName)
  6293. // dataRow.AddCell().SetString(v.Status)
  6294. // dataRow.AddCell().SetString(timeLimt)
  6295. // dataRow.AddCell().SetString(expireDay)
  6296. // dataRow.AddCell().SetString(v.CreatedTime)
  6297. // dataRow.AddCell().SetString(v.Source)
  6298. // dataRow.AddCell().SetString(permissionStr)
  6299. // }
  6300. // err = xlsxFile.Save(downLoadnFilePath)
  6301. // if err != nil {
  6302. // br.Msg = "保存文件失败"
  6303. // br.ErrMsg = "保存文件失败"
  6304. // return
  6305. // }
  6306. // randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
  6307. // downloadFileName := "客户列表_" + randStr + ".xlsx"
  6308. // this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  6309. // defer func() {
  6310. // os.Remove(downLoadnFilePath)
  6311. // }()
  6312. // br.Ret = 200
  6313. // br.Success = true
  6314. // br.Msg = "导出成功"
  6315. //}
  6316. // @Title 导出
  6317. // @Description 导出接口
  6318. // @Param Status query string true "状态:”试用','永续','冻结','流失','正式'"
  6319. // @Param CompanyType query string true "客户类型:传空字符串或者不传为全部,'ficc','权益'"
  6320. // @Param IndustryId query int true "行业id,0为全部"
  6321. // @Param AdminId query string true "销售id,多个用英文逗号隔开,空字符串为全部"
  6322. // @Param ChartPermissionIds query string false "阅读权限品种ID,多个用英文逗号分开,空字符串为全部"
  6323. // @Param ContractPermissionIds query string false "已购品种ID,多个用英文逗号分开,空字符串为全部"
  6324. // @Param StartDate query string true "开始时间"
  6325. // @Param EndDate query string true "结束时间"
  6326. // @Param KeyWord query string true "搜索关键词"
  6327. // @Param Address query string true "地址 , 多个用英文逗号分开 "
  6328. // @Param Province query string true "省 , 多个用英文逗号分开 "
  6329. // @Param City query string true "市 , 多个用英文逗号分开 "
  6330. // @Param PackageType query int true "套餐类型,0:无,1:大套餐,2:小套餐"
  6331. // @Success Ret=200 移动成功
  6332. // @router /user/export [get]
  6333. func (this *CompanyController) CompanyUserExport() {
  6334. br := new(models.BaseResponse).Init()
  6335. defer func() {
  6336. this.Data["json"] = br
  6337. this.ServeJSON()
  6338. }()
  6339. sysUser := this.SysUser
  6340. if sysUser == nil {
  6341. br.Msg = "请登录"
  6342. br.ErrMsg = "请登录,SysUser Is Empty"
  6343. br.Ret = 408
  6344. return
  6345. }
  6346. roleTypeCode := sysUser.RoleTypeCode
  6347. status := this.GetString("Status")
  6348. companyType := this.GetString("CompanyType")
  6349. industryId, _ := this.GetInt("IndustryId")
  6350. adminId := this.GetString("AdminId")
  6351. chartPermissionIds := this.GetString("ChartPermissionIds")
  6352. contractPermissionIds := this.GetString("ContractPermissionIds")
  6353. startDate := this.GetString("StartDate")
  6354. endDate := this.GetString("EndDate")
  6355. createStartDate := this.GetString("CreateStartDate")
  6356. createEndDate := this.GetString("CreateEndDate")
  6357. keyWord := this.GetString("KeyWord")
  6358. address := this.GetString("Address")
  6359. province := this.GetString("Province")
  6360. city := this.GetString("City")
  6361. // 套餐类型
  6362. packageType, _ := this.GetInt("PackageType")
  6363. var condition string
  6364. var pars []interface{}
  6365. if status != "" && status != "全部" {
  6366. condition += ` AND b.status=? `
  6367. pars = append(pars, status)
  6368. }
  6369. if companyType != "" {
  6370. condition += ` AND b.product_name=? `
  6371. pars = append(pars, companyType)
  6372. }
  6373. if industryId > 0 {
  6374. condition += ` AND b.industry_id=? `
  6375. pars = append(pars, industryId)
  6376. }
  6377. if adminId != "" {
  6378. condition += ` AND b.seller_id IN (` + adminId + `) `
  6379. }
  6380. if startDate != "" {
  6381. condition += ` AND b.start_date>=? `
  6382. pars = append(pars, startDate)
  6383. }
  6384. if endDate != "" {
  6385. condition += ` AND b.end_date<=? `
  6386. pars = append(pars, endDate)
  6387. }
  6388. if createStartDate != "" {
  6389. condition += ` AND a.created_time>=? `
  6390. pars = append(pars, createStartDate)
  6391. }
  6392. if createEndDate != "" {
  6393. condition += ` AND a.created_time<=? `
  6394. pars = append(pars, createEndDate)
  6395. }
  6396. if keyWord != "" {
  6397. condition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR c.mobile LIKE '%` + keyWord + `%' OR c.email LIKE '%` + keyWord + `%') `
  6398. }
  6399. // 阅读权限/已购品种筛选
  6400. cond, emp, e := services.FilterReadAndContractAuth(chartPermissionIds, contractPermissionIds, condition)
  6401. if e != nil {
  6402. br.Msg = "获取失败"
  6403. br.ErrMsg = "FilterReadAndContractAuth err: " + e.Error()
  6404. return
  6405. }
  6406. if emp {
  6407. condition += ` AND 1 = 2`
  6408. } else {
  6409. condition = cond
  6410. }
  6411. if address != "" {
  6412. var addressSql string
  6413. slice := strings.Split(address, ",")
  6414. for _, v := range slice {
  6415. addressSql += "'" + v + "'" + ","
  6416. }
  6417. addressSql = strings.TrimRight(addressSql, ",")
  6418. condition += ` AND a.address IN (` + addressSql + `) `
  6419. }
  6420. if province != "" {
  6421. var provinceSql string
  6422. slice := strings.Split(province, ",")
  6423. for _, v := range slice {
  6424. provinceSql += "'" + v + "'" + ","
  6425. }
  6426. provinceSql = strings.TrimRight(provinceSql, ",")
  6427. condition += ` AND a.province IN (` + provinceSql + `) `
  6428. }
  6429. if city != "" {
  6430. var citySql string
  6431. slice := strings.Split(city, ",")
  6432. for _, v := range slice {
  6433. citySql += "'" + v + "'" + ","
  6434. }
  6435. citySql = strings.TrimRight(citySql, ",")
  6436. condition += ` AND a.city IN (` + citySql + `) `
  6437. }
  6438. //套餐类型
  6439. if packageType > 0 {
  6440. condition += ` AND b.package_type=? `
  6441. pars = append(pars, packageType)
  6442. }
  6443. //权限控制
  6444. {
  6445. if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER ||
  6446. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER {
  6447. if status != utils.COMPANY_STATUS_LOSE && status != utils.COMPANY_STATUS_FOREVER {
  6448. condition += ` AND b.seller_id=? `
  6449. pars = append(pars, sysUser.AdminId)
  6450. }
  6451. }
  6452. if sysUser.Authority == 1 {
  6453. condition += ` AND b.department_id=? `
  6454. pars = append(pars, sysUser.DepartmentId)
  6455. }
  6456. if sysUser.Authority == 2 {
  6457. condition += ` AND b.group_id=? `
  6458. pars = append(pars, sysUser.GroupId)
  6459. }
  6460. }
  6461. var statusCond string
  6462. var statusPars []interface{}
  6463. // 根据当前用户角色
  6464. productId := services.GetProductId(roleTypeCode)
  6465. if productId > 0 {
  6466. condition += ` AND b.product_id = ? `
  6467. pars = append(pars, productId)
  6468. statusCond += ` AND b.product_id = ? `
  6469. statusPars = append(statusPars, productId)
  6470. }
  6471. companyIds, err := company.GetExportCompanyIds(condition, pars)
  6472. if err != nil {
  6473. br.Msg = "导出失败"
  6474. br.ErrMsg = "导出失败,Err:" + err.Error()
  6475. return
  6476. }
  6477. dir, err := os.Executable()
  6478. exPath := filepath.Dir(dir)
  6479. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  6480. xlsxFile := xlsx.NewFile()
  6481. if err != nil {
  6482. br.Msg = "生成文件失败"
  6483. br.ErrMsg = "生成文件失败"
  6484. return
  6485. }
  6486. style := xlsx.NewStyle()
  6487. alignment := xlsx.Alignment{
  6488. Horizontal: "center",
  6489. Vertical: "center",
  6490. WrapText: true,
  6491. }
  6492. style.Alignment = alignment
  6493. style.ApplyAlignment = true
  6494. sheel, err := xlsxFile.AddSheet("联系人数据")
  6495. if err != nil {
  6496. br.Msg = "新增Sheet失败"
  6497. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  6498. return
  6499. }
  6500. sheel.SetColWidth(7, 7, 10)
  6501. sheel.SetColWidth(8, 10, 16)
  6502. sheel.SetColWidth(9, 11, 20)
  6503. sheel.SetColWidth(12, 12, 35)
  6504. sheel.SetColWidth(13, 13, 15)
  6505. sheel.SetColWidth(14, 14, 80)
  6506. titleRow := sheel.AddRow()
  6507. titleRow.AddCell().SetValue("联系人")
  6508. titleRow.AddCell().SetValue("是否关注公众号")
  6509. titleRow.AddCell().SetValue("手机号")
  6510. titleRow.AddCell().SetValue("邮箱")
  6511. //titleRow.AddCell().SetValue("职位")
  6512. titleRow.AddCell().SetValue("是否决策人")
  6513. //titleRow.AddCell().SetValue("客户部门")
  6514. titleRow.AddCell().SetValue("客户名称")
  6515. titleRow.AddCell().SetValue("客户状态")
  6516. //titleRow.AddCell().SetValue("社会信用码")
  6517. //titleRow.AddCell().SetValue("所属区域")
  6518. //titleRow.AddCell().SetValue("客户类型")
  6519. //industryCell := titleRow.AddCell()
  6520. //industryCell.SetStyle(style)
  6521. //industryCell.Value = "所属行业"
  6522. //
  6523. //sellerCell := titleRow.AddCell()
  6524. //sellerCell.SetStyle(style)
  6525. //sellerCell.Value = "所属销售"
  6526. //
  6527. //statusCell := titleRow.AddCell()
  6528. //statusCell.SetStyle(style)
  6529. //statusCell.Value = "客户状态"
  6530. //
  6531. //timeLimtCell := titleRow.AddCell()
  6532. //timeLimtCell.SetStyle(style)
  6533. //timeLimtCell.Value = "服务期限"
  6534. //
  6535. //createTimeCell := titleRow.AddCell()
  6536. //createTimeCell.SetStyle(style)
  6537. //createTimeCell.Value = "创建时间"
  6538. //
  6539. //sourceCell := titleRow.AddCell()
  6540. //sourceCell.SetStyle(style)
  6541. //sourceCell.Value = "客户来源"
  6542. //permissionStyle := xlsx.NewStyle()
  6543. //permissionAlignment := xlsx.Alignment{
  6544. // Horizontal: "center",
  6545. // Vertical: "center",
  6546. // WrapText: true,
  6547. //}
  6548. //
  6549. //permissionStyle.Alignment = permissionAlignment
  6550. //permissionStyle.ApplyAlignment = true
  6551. //permissionCell := titleRow.AddCell()
  6552. //permissionCell.SetStyle(permissionStyle)
  6553. //permissionCell.Value = "阅读权限"
  6554. users := make([]*company.ExportUser, 0)
  6555. if companyIds != "" {
  6556. companyIds = strings.Trim(companyIds, ",")
  6557. if productId > 0 {
  6558. users, err = company.GetExportUserByProductId(companyIds, productId)
  6559. if err != nil {
  6560. br.Msg = "导出失败"
  6561. br.ErrMsg = "获取联系人信息失败,Err:" + err.Error()
  6562. return
  6563. }
  6564. } else {
  6565. users, err = company.GetExportUser(companyIds)
  6566. if err != nil {
  6567. br.Msg = "导出失败"
  6568. br.ErrMsg = "获取联系人信息失败,Err:" + err.Error()
  6569. return
  6570. }
  6571. }
  6572. // 获取客户状态
  6573. companyIntIds := make([]int, 0)
  6574. companyIdArr := strings.Split(companyIds, ",")
  6575. for _, c := range companyIdArr {
  6576. id, e := strconv.Atoi(c)
  6577. if e != nil {
  6578. br.Msg = "导出失败"
  6579. br.ErrMsg = "客户ID有误"
  6580. return
  6581. }
  6582. companyIntIds = append(companyIntIds, id)
  6583. }
  6584. if len(companyIntIds) > 0 {
  6585. statusCond += fmt.Sprintf(` AND a.company_id IN (%s) `, utils.GetOrmInReplace(len(companyIntIds)))
  6586. statusPars = append(statusPars, companyIntIds)
  6587. }
  6588. statusMap := make(map[int]string)
  6589. nameMap := make(map[int]string)
  6590. companyStatusList, e := company.GetExportUserCompanyStatus(statusCond, statusPars)
  6591. if e != nil {
  6592. br.Msg = "导出失败"
  6593. br.ErrMsg = "获取客户状态失败, Err: " + e.Error()
  6594. return
  6595. }
  6596. for _, s := range companyStatusList {
  6597. statusMap[s.CompanyId] = s.CompanyStatus
  6598. nameMap[s.CompanyId] = s.CompanyName
  6599. }
  6600. //cpMap := make(map[int][]*company.ExportCompanyProduct)
  6601. //permissionMap := make(map[string]string)
  6602. for _, v := range users {
  6603. dataRow := sheel.AddRow()
  6604. dataRow.SetHeight(20)
  6605. dataRow.AddCell().SetString(v.RealName)
  6606. if v.IsSubscribe == 1 {
  6607. dataRow.AddCell().SetString("是") // 是否关注公众号
  6608. } else {
  6609. dataRow.AddCell().SetString("")
  6610. }
  6611. dataRow.AddCell().SetString(v.Mobile)
  6612. dataRow.AddCell().SetString(v.Email)
  6613. //dataRow.AddCell().SetString(v.Position)
  6614. if v.IsMaker == 1 {
  6615. dataRow.AddCell().SetString("是")
  6616. } else {
  6617. dataRow.AddCell().SetString("否")
  6618. }
  6619. //dataRow.AddCell().SetString(v.DepartmentName)
  6620. //cpList := make([]*company.ExportCompanyProduct, 1)
  6621. //if cps, ok := cpMap[v.CompanyId]; ok {
  6622. // cpList = cps
  6623. //} else {
  6624. // companyProduct, err := company.GetExportCompanyProduct(v.CompanyId)
  6625. // if err != nil {
  6626. // br.Msg = "导出失败"
  6627. // br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  6628. // return
  6629. // }
  6630. // cpMap[v.CompanyId] = companyProduct
  6631. // cpList = companyProduct
  6632. //}
  6633. //productList, err := company.GetExportCompanyProduct(v.CompanyId)
  6634. //if err!=nil {
  6635. // fmt.Println("导出失败,Err:"+err.Error())
  6636. // return
  6637. //}
  6638. //var companyName, companyType, industryName, sellerName, status, timeLimt, createTime, source, permissionStr, creditCode, regionType string
  6639. //for ck, cv := range cpList {
  6640. // companyName = cv.CompanyName
  6641. // creditCode = cv.CreditCode
  6642. // regionType = cv.RegionType
  6643. // if ck >= 1 {
  6644. // companyType = companyType + "/" + cv.ProductName
  6645. // status = status + "/" + cv.Status
  6646. // } else {
  6647. // companyType = cv.ProductName
  6648. // status = cv.Status
  6649. // }
  6650. // if cv.ProductId == 1 {
  6651. // industryName = "ficc:" + cv.IndustryName
  6652. // sellerName = "ficc:" + cv.SellerName
  6653. // startDateStr := cv.StartDate.Format("2006/01/02")
  6654. // endDateStr := cv.EndDate.Format("2006/01/02")
  6655. // if startDateStr != "0001/01/01" {
  6656. // timeLimt = "ficc:" + startDateStr + "~" + endDateStr
  6657. // } else {
  6658. // timeLimt = ""
  6659. // }
  6660. // createTime = "ficc:" + cv.CreateTime
  6661. // source = "ficc:" + cv.Source
  6662. // permissionKey := strconv.Itoa(v.CompanyId) + "_" + strconv.Itoa(cv.ProductId)
  6663. //
  6664. // permissionStr = "ficc:"
  6665. // if newPermissionStr, ok := permissionMap[permissionKey]; ok {
  6666. // permissionStr += newPermissionStr
  6667. // } else {
  6668. // getPermissionStr, err := company.GetExportPermissionName(v.CompanyId, cv.ProductId)
  6669. // if err != nil {
  6670. // br.Msg = "导出失败"
  6671. // br.ErrMsg = "获取客户权限信息失败,Err:" + err.Error()
  6672. // return
  6673. // }
  6674. // permissionMap[permissionKey] = getPermissionStr
  6675. // permissionStr += getPermissionStr
  6676. // }
  6677. // if cv.Status == utils.COMPANY_STATUS_LOSE {
  6678. // permissionStr = ""
  6679. // }
  6680. // } else {
  6681. // industryName = industryName + "\n" + "权益:" + cv.IndustryName
  6682. // sellerName = sellerName + "\n" + "权益:" + cv.SellerName
  6683. // startDateStr := cv.StartDate.Format("2006/01/02")
  6684. // endDateStr := cv.EndDate.Format("2006/01/02")
  6685. //
  6686. // if startDateStr != "0001/01/01" {
  6687. // timeLimt = timeLimt + "\n" + "权益:" + startDateStr + "~" + endDateStr
  6688. // } else {
  6689. // timeLimt = timeLimt + ""
  6690. // }
  6691. // createTime = createTime + "\n" + "权益:" + cv.CreateTime
  6692. // source = source + "\n" + "权益:" + cv.Source
  6693. //
  6694. // permissionKey := strconv.Itoa(v.CompanyId) + "_" + strconv.Itoa(cv.ProductId)
  6695. // if permissionStr != "" {
  6696. // permissionStr = permissionStr + "\n" + "权益:"
  6697. // } else {
  6698. // permissionStr = "权益:"
  6699. // }
  6700. // if newPermissionStr, ok := permissionMap[permissionKey]; ok {
  6701. // permissionStr += newPermissionStr
  6702. // } else {
  6703. // getPermissionStr, err := company.GetExportPermissionName(v.CompanyId, cv.ProductId)
  6704. // if err != nil {
  6705. // br.Msg = "导出失败"
  6706. // br.ErrMsg = "获取客户权限信息失败,Err:" + err.Error()
  6707. // return
  6708. // }
  6709. // permissionMap[permissionKey] = getPermissionStr
  6710. // permissionStr += getPermissionStr
  6711. // }
  6712. // if cv.Status == utils.COMPANY_STATUS_LOSE {
  6713. // permissionStr = permissionStr + ""
  6714. // }
  6715. // }
  6716. //}
  6717. // 2023-0420这是谁写的循环查,顺手优化了一下,手动狗头-_-~
  6718. //companyInfo, err := company.GetCompanyById(v.CompanyId)
  6719. //if err != nil {
  6720. // br.Msg = "导出失败"
  6721. // br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  6722. // return
  6723. //}
  6724. dataRow.AddCell().SetString(nameMap[v.CompanyId])
  6725. dataRow.AddCell().SetString(statusMap[v.CompanyId]) // 客户状态
  6726. //dataRow.AddCell().SetString(creditCode)
  6727. //dataRow.AddCell().SetString(regionType)
  6728. //
  6729. //dataRow.AddCell().SetString(companyType)
  6730. //industryValueCell := dataRow.AddCell()
  6731. //industryValueCell.SetStyle(style)
  6732. //industryValueCell.SetString(industryName)
  6733. //
  6734. //sellerValueCell := dataRow.AddCell()
  6735. //sellerValueCell.SetStyle(style)
  6736. //sellerValueCell.SetString(sellerName)
  6737. //
  6738. //statusValueCell := dataRow.AddCell()
  6739. //statusValueCell.SetStyle(style)
  6740. //statusValueCell.SetValue(status)
  6741. //
  6742. //timeLimitValueCell := dataRow.AddCell()
  6743. //timeLimitValueCell.SetStyle(style)
  6744. //timeLimitValueCell.SetValue(timeLimt)
  6745. //
  6746. //createTimeValueCell := dataRow.AddCell()
  6747. //createTimeValueCell.SetStyle(style)
  6748. //createTimeValueCell.SetValue(createTime)
  6749. //
  6750. //sourceValueCell := dataRow.AddCell()
  6751. //sourceValueCell.SetStyle(style)
  6752. //sourceValueCell.SetValue(source)
  6753. //
  6754. //permissionStrValueCell := dataRow.AddCell()
  6755. //permissionStrValueCell.SetStyle(style)
  6756. //permissionStrValueCell.SetValue(permissionStr)
  6757. }
  6758. }
  6759. err = xlsxFile.Save(downLoadnFilePath)
  6760. if err != nil {
  6761. br.Msg = "保存文件失败"
  6762. br.ErrMsg = "保存文件失败"
  6763. return
  6764. }
  6765. randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
  6766. downloadFileName := "联系人列表" + randStr + ".xlsx"
  6767. this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  6768. defer func() {
  6769. os.Remove(downLoadnFilePath)
  6770. }()
  6771. br.Ret = 200
  6772. br.Success = true
  6773. br.Msg = "导出成功"
  6774. }
  6775. //func (this *CompanyController) CompanyUserExportOld() {
  6776. // br := new(models.BaseResponse).Init()
  6777. // defer func() {
  6778. // this.Data["json"] = br
  6779. // this.ServeJSON()
  6780. // }()
  6781. // sysUser := this.SysUser
  6782. // if sysUser == nil {
  6783. // br.Msg = "请登录"
  6784. // br.ErrMsg = "请登录,SysUser Is Empty"
  6785. // br.Ret = 408
  6786. // return
  6787. // }
  6788. // roleTypeCode := sysUser.RoleTypeCode
  6789. // status := this.GetString("Status")
  6790. // companyType := this.GetString("CompanyType")
  6791. // industryId, _ := this.GetInt("IndustryId")
  6792. // adminId := this.GetString("AdminId")
  6793. //
  6794. // chartPermissionIds := this.GetString("ChartPermissionIds")
  6795. // startDate := this.GetString("StartDate")
  6796. // endDate := this.GetString("EndDate")
  6797. // keyWord := this.GetString("KeyWord")
  6798. //
  6799. // var condition string
  6800. // var pars []interface{}
  6801. //
  6802. // if status != "" && status != "全部" {
  6803. // condition += ` AND b.status=? `
  6804. // pars = append(pars, status)
  6805. // }
  6806. // if companyType != "" {
  6807. // condition += ` AND b.product_name=? `
  6808. // pars = append(pars, companyType)
  6809. // }
  6810. //
  6811. // if industryId > 0 {
  6812. // condition += ` AND b.industry_id=? `
  6813. // pars = append(pars, industryId)
  6814. // }
  6815. //
  6816. // if adminId != "" {
  6817. // condition += ` AND b.seller_id IN (` + adminId + `) `
  6818. // }
  6819. //
  6820. // if startDate != "" {
  6821. // condition += ` AND b.start_date>=? `
  6822. // pars = append(pars, startDate)
  6823. // }
  6824. //
  6825. // if endDate != "" {
  6826. // condition += ` AND b.end_date>=? `
  6827. // pars = append(pars, endDate)
  6828. // }
  6829. //
  6830. // if keyWord != "" {
  6831. // condition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR c.mobile LIKE '%` + keyWord + `%' OR c.email LIKE '%` + keyWord + `%') `
  6832. // }
  6833. //
  6834. // if chartPermissionIds != "" {
  6835. // companyIdStr, err := company.GetCompanyIdStr(chartPermissionIds)
  6836. // if err != nil {
  6837. // br.Msg = "获取失败"
  6838. // br.ErrMsg = "根据权限获取公司ID失败,Err:" + err.Error()
  6839. // return
  6840. // }
  6841. // if companyIdStr != "" {
  6842. // condition += ` AND a.company_id IN (` + companyIdStr + `) `
  6843. // }
  6844. // }
  6845. //
  6846. // //权限控制
  6847. // {
  6848. // if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER ||
  6849. // roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER {
  6850. // if status != utils.COMPANY_STATUS_LOSE && status != utils.COMPANY_STATUS_FOREVER {
  6851. // condition += ` AND b.seller_id=? `
  6852. // pars = append(pars, sysUser.AdminId)
  6853. // }
  6854. // }
  6855. // if sysUser.Authority == 1 {
  6856. // condition += ` AND b.department_id=? `
  6857. // pars = append(pars, sysUser.DepartmentId)
  6858. // }
  6859. //
  6860. // if sysUser.Authority == 2 {
  6861. // condition += ` AND b.group_id=? `
  6862. // pars = append(pars, sysUser.GroupId)
  6863. // }
  6864. // }
  6865. // companyIds, err := company.GetExportCompanyIds(condition, pars)
  6866. // if err != nil {
  6867. // br.Msg = "导出失败"
  6868. // br.ErrMsg = "导出失败,Err:" + err.Error()
  6869. // return
  6870. // }
  6871. //
  6872. // dir, err := os.Executable()
  6873. // exPath := filepath.Dir(dir)
  6874. //
  6875. // downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  6876. // xlsxFile := xlsx.NewFile()
  6877. // if err != nil {
  6878. // br.Msg = "生成文件失败"
  6879. // br.ErrMsg = "生成文件失败"
  6880. // return
  6881. // }
  6882. // style := xlsx.NewStyle()
  6883. // alignment := xlsx.Alignment{
  6884. // Horizontal: "center",
  6885. // Vertical: "center",
  6886. // WrapText: true,
  6887. // }
  6888. //
  6889. // style.Alignment = alignment
  6890. // style.ApplyAlignment = true
  6891. //
  6892. // sheel, err := xlsxFile.AddSheet("联系人数据")
  6893. // if err != nil {
  6894. // br.Msg = "新增Sheet失败"
  6895. // br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  6896. // return
  6897. // }
  6898. //
  6899. // sheel.SetColWidth(7, 7, 10)
  6900. // sheel.SetColWidth(8, 10, 16)
  6901. // sheel.SetColWidth(9, 11, 20)
  6902. // sheel.SetColWidth(12, 12, 35)
  6903. // sheel.SetColWidth(13, 13, 15)
  6904. // sheel.SetColWidth(14, 14, 80)
  6905. // titleRow := sheel.AddRow()
  6906. // titleRow.AddCell().SetValue("联系人")
  6907. // titleRow.AddCell().SetValue("手机号")
  6908. // titleRow.AddCell().SetValue("邮箱")
  6909. // titleRow.AddCell().SetValue("职位")
  6910. // titleRow.AddCell().SetValue("是否决策人")
  6911. // titleRow.AddCell().SetValue("客户部门")
  6912. // titleRow.AddCell().SetValue("客户名称")
  6913. // titleRow.AddCell().SetValue("社会信用码")
  6914. // titleRow.AddCell().SetValue("所属区域")
  6915. // titleRow.AddCell().SetValue("客户类型")
  6916. //
  6917. // industryCell := titleRow.AddCell()
  6918. // industryCell.SetStyle(style)
  6919. // industryCell.Value = "所属行业"
  6920. //
  6921. // sellerCell := titleRow.AddCell()
  6922. // sellerCell.SetStyle(style)
  6923. // sellerCell.Value = "所属销售"
  6924. //
  6925. // statusCell := titleRow.AddCell()
  6926. // statusCell.SetStyle(style)
  6927. // statusCell.Value = "客户状态"
  6928. //
  6929. // timeLimtCell := titleRow.AddCell()
  6930. // timeLimtCell.SetStyle(style)
  6931. // timeLimtCell.Value = "服务期限"
  6932. //
  6933. // createTimeCell := titleRow.AddCell()
  6934. // createTimeCell.SetStyle(style)
  6935. // createTimeCell.Value = "创建时间"
  6936. //
  6937. // sourceCell := titleRow.AddCell()
  6938. // sourceCell.SetStyle(style)
  6939. // sourceCell.Value = "客户来源"
  6940. //
  6941. // permissionStyle := xlsx.NewStyle()
  6942. // permissionAlignment := xlsx.Alignment{
  6943. // Horizontal: "center",
  6944. // Vertical: "center",
  6945. // WrapText: true,
  6946. // }
  6947. //
  6948. // permissionStyle.Alignment = permissionAlignment
  6949. // permissionStyle.ApplyAlignment = true
  6950. //
  6951. // permissionCell := titleRow.AddCell()
  6952. // permissionCell.SetStyle(permissionStyle)
  6953. // permissionCell.Value = "阅读权限"
  6954. //
  6955. // if companyIds != "" {
  6956. // companyIds = strings.Trim(companyIds, ",")
  6957. // users, err := company.GetExportUser(companyIds)
  6958. // if err != nil {
  6959. // br.Msg = "导出失败"
  6960. // br.ErrMsg = "获取联系人信息失败,Err:" + err.Error()
  6961. // return
  6962. // }
  6963. // cpMap := make(map[int][]*company.ExportCompanyProduct)
  6964. // permissionMap := make(map[string]string)
  6965. // for _, v := range users {
  6966. // dataRow := sheel.AddRow()
  6967. // dataRow.SetHeight(20)
  6968. // dataRow.AddCell().SetString(v.RealName)
  6969. // dataRow.AddCell().SetString(v.Mobile)
  6970. // dataRow.AddCell().SetString(v.Email)
  6971. // dataRow.AddCell().SetString(v.Position)
  6972. // if v.IsMaker == 1 {
  6973. // dataRow.AddCell().SetString("是")
  6974. // } else {
  6975. // dataRow.AddCell().SetString("否")
  6976. // }
  6977. // dataRow.AddCell().SetString(v.DepartmentName)
  6978. // cpList := make([]*company.ExportCompanyProduct, 1)
  6979. // if cps, ok := cpMap[v.CompanyId]; ok {
  6980. // cpList = cps
  6981. // } else {
  6982. // companyProduct, err := company.GetExportCompanyProduct(v.CompanyId)
  6983. // if err != nil {
  6984. // br.Msg = "导出失败"
  6985. // br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  6986. // return
  6987. // }
  6988. // cpMap[v.CompanyId] = companyProduct
  6989. // cpList = companyProduct
  6990. // }
  6991. // //productList, err := company.GetExportCompanyProduct(v.CompanyId)
  6992. // //if err!=nil {
  6993. // // fmt.Println("导出失败,Err:"+err.Error())
  6994. // // return
  6995. // //}
  6996. // var companyName, companyType, industryName, sellerName, status, timeLimt, createTime, source, permissionStr, creditCode, regionType string
  6997. //
  6998. // for ck, cv := range cpList {
  6999. // companyName = cv.CompanyName
  7000. // creditCode = cv.CreditCode
  7001. // regionType = cv.RegionType
  7002. // if ck >= 1 {
  7003. // companyType = companyType + "/" + cv.ProductName
  7004. // status = status + "/" + cv.Status
  7005. // } else {
  7006. // companyType = cv.ProductName
  7007. // status = cv.Status
  7008. // }
  7009. // if cv.ProductId == 1 {
  7010. // industryName = "ficc:" + cv.IndustryName
  7011. // sellerName = "ficc:" + cv.SellerName
  7012. // startDateStr := cv.StartDate.Format("2006/01/02")
  7013. // endDateStr := cv.EndDate.Format("2006/01/02")
  7014. // if startDateStr != "0001/01/01" {
  7015. // timeLimt = "ficc:" + startDateStr + "~" + endDateStr
  7016. // } else {
  7017. // timeLimt = ""
  7018. // }
  7019. // createTime = "ficc:" + cv.CreateTime
  7020. // source = "ficc:" + cv.Source
  7021. // permissionKey := strconv.Itoa(v.CompanyId) + "_" + strconv.Itoa(cv.ProductId)
  7022. //
  7023. // permissionStr = "ficc:"
  7024. // if newPermissionStr, ok := permissionMap[permissionKey]; ok {
  7025. // permissionStr += newPermissionStr
  7026. // } else {
  7027. // getPermissionStr, err := company.GetExportPermissionName(v.CompanyId, cv.ProductId)
  7028. // if err != nil {
  7029. // br.Msg = "导出失败"
  7030. // br.ErrMsg = "获取客户权限信息失败,Err:" + err.Error()
  7031. // return
  7032. // }
  7033. // permissionMap[permissionKey] = getPermissionStr
  7034. // permissionStr += getPermissionStr
  7035. // }
  7036. // if cv.Status == utils.COMPANY_STATUS_LOSE {
  7037. // permissionStr = ""
  7038. // }
  7039. // } else {
  7040. // industryName = industryName + "\n" + "权益:" + cv.IndustryName
  7041. // sellerName = sellerName + "\n" + "权益:" + cv.SellerName
  7042. // startDateStr := cv.StartDate.Format("2006/01/02")
  7043. // endDateStr := cv.EndDate.Format("2006/01/02")
  7044. //
  7045. // if startDateStr != "0001/01/01" {
  7046. // timeLimt = timeLimt + "\n" + "权益:" + startDateStr + "~" + endDateStr
  7047. // } else {
  7048. // timeLimt = timeLimt + ""
  7049. // }
  7050. // createTime = createTime + "\n" + "权益:" + cv.CreateTime
  7051. // source = source + "\n" + "权益:" + cv.Source
  7052. //
  7053. // permissionKey := strconv.Itoa(v.CompanyId) + "_" + strconv.Itoa(cv.ProductId)
  7054. // if permissionStr != "" {
  7055. // permissionStr = permissionStr + "\n" + "权益:"
  7056. // } else {
  7057. // permissionStr = "权益:"
  7058. // }
  7059. // if newPermissionStr, ok := permissionMap[permissionKey]; ok {
  7060. // permissionStr += newPermissionStr
  7061. // } else {
  7062. // getPermissionStr, err := company.GetExportPermissionName(v.CompanyId, cv.ProductId)
  7063. // if err != nil {
  7064. // br.Msg = "导出失败"
  7065. // br.ErrMsg = "获取客户权限信息失败,Err:" + err.Error()
  7066. // return
  7067. // }
  7068. // permissionMap[permissionKey] = getPermissionStr
  7069. // permissionStr += getPermissionStr
  7070. // }
  7071. // if cv.Status == utils.COMPANY_STATUS_LOSE {
  7072. // permissionStr = permissionStr + ""
  7073. // }
  7074. // }
  7075. // }
  7076. // dataRow.AddCell().SetString(companyName)
  7077. // dataRow.AddCell().SetString(creditCode)
  7078. // dataRow.AddCell().SetString(regionType)
  7079. //
  7080. // dataRow.AddCell().SetString(companyType)
  7081. // industryValueCell := dataRow.AddCell()
  7082. // industryValueCell.SetStyle(style)
  7083. // industryValueCell.SetString(industryName)
  7084. //
  7085. // sellerValueCell := dataRow.AddCell()
  7086. // sellerValueCell.SetStyle(style)
  7087. // sellerValueCell.SetString(sellerName)
  7088. //
  7089. // statusValueCell := dataRow.AddCell()
  7090. // statusValueCell.SetStyle(style)
  7091. // statusValueCell.SetValue(status)
  7092. //
  7093. // timeLimitValueCell := dataRow.AddCell()
  7094. // timeLimitValueCell.SetStyle(style)
  7095. // timeLimitValueCell.SetValue(timeLimt)
  7096. //
  7097. // createTimeValueCell := dataRow.AddCell()
  7098. // createTimeValueCell.SetStyle(style)
  7099. // createTimeValueCell.SetValue(createTime)
  7100. //
  7101. // sourceValueCell := dataRow.AddCell()
  7102. // sourceValueCell.SetStyle(style)
  7103. // sourceValueCell.SetValue(source)
  7104. //
  7105. // permissionStrValueCell := dataRow.AddCell()
  7106. // permissionStrValueCell.SetStyle(style)
  7107. // permissionStrValueCell.SetValue(permissionStr)
  7108. // }
  7109. // }
  7110. // err = xlsxFile.Save(downLoadnFilePath)
  7111. // if err != nil {
  7112. // br.Msg = "保存文件失败"
  7113. // br.ErrMsg = "保存文件失败"
  7114. // return
  7115. // }
  7116. // randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
  7117. // downloadFileName := "联系人列表" + randStr + ".xlsx"
  7118. // this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  7119. // defer func() {
  7120. // os.Remove(downLoadnFilePath)
  7121. // }()
  7122. // br.Ret = 200
  7123. // br.Success = true
  7124. // br.Msg = "导出成功"
  7125. //}
  7126. // @Title 冻结客户
  7127. // @Description 冻结客户接口
  7128. // @Param request body company.CompanyFreezeReq true "type json string"
  7129. // @Success Ret=200 冻结成功
  7130. // @router /freeze [post]
  7131. func (this *CompanyController) Freeze() {
  7132. br := new(models.BaseResponse).Init()
  7133. defer func() {
  7134. this.Data["json"] = br
  7135. this.ServeJSON()
  7136. }()
  7137. sysUser := this.SysUser
  7138. if sysUser == nil {
  7139. br.Msg = "请登录"
  7140. br.ErrMsg = "请登录,SysUser Is Empty"
  7141. br.Ret = 408
  7142. return
  7143. }
  7144. var req company.CompanyFreezeReq
  7145. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  7146. if err != nil {
  7147. br.Msg = "参数解析异常!"
  7148. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  7149. return
  7150. }
  7151. if req.CompanyId <= 0 {
  7152. br.Msg = "参数错误!"
  7153. br.ErrMsg = "客户id小于等于0"
  7154. return
  7155. }
  7156. productId := 0
  7157. productName := ""
  7158. if req.CompanyType == utils.COMPANY_CLASSIFY_FICC {
  7159. productId = 1
  7160. productName = "ficc"
  7161. } else if req.CompanyType == utils.COMPANY_CLASSIFY_RAI {
  7162. productId = 2
  7163. productName = "权益"
  7164. } else {
  7165. productId = 3
  7166. productName = "佣金客户"
  7167. }
  7168. if req.CompanyId <= 0 {
  7169. br.Msg = "参数异常!"
  7170. br.ErrMsg = "CompanyId:" + strconv.Itoa(req.CompanyId)
  7171. return
  7172. }
  7173. cp, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, productId)
  7174. if err != nil {
  7175. br.Msg = "查询该客户产品异常!"
  7176. br.ErrMsg = "查询该客户产品异常,err:" + err.Error()
  7177. return
  7178. }
  7179. if cp.Status != utils.COMPANY_STATUS_TRY_OUT {
  7180. br.Msg = "客户状态为:" + cp.Status + ";不可冻结"
  7181. br.ErrMsg = "客户状态为:" + cp.Status + ";不可冻结"
  7182. return
  7183. }
  7184. //查询客户的产品权限
  7185. companyReportPermissionList, err := company.GetCompanyReportPermission(req.CompanyId, productId)
  7186. if err != nil {
  7187. br.Msg = "查询客户的产品权限异常"
  7188. br.ErrMsg = "查询客户的产品权限异常:" + err.Error()
  7189. return
  7190. }
  7191. err = company.CompanyFreeze(req.CompanyId, productId, req.Remark)
  7192. if err != nil {
  7193. br.Msg = "冻结失败!"
  7194. br.ErrMsg = "冻结失败,Err:" + err.Error()
  7195. return
  7196. }
  7197. //新增操作记录
  7198. {
  7199. approveContent := req.Remark
  7200. remark := "冻结客户"
  7201. operation := "freeze"
  7202. services.AddCompanyOperationRecord(req.CompanyId, cp.SellerId, sysUser.AdminId, productId, sysUser.AdminId, cp.CompanyName,
  7203. productName, sysUser.RealName, remark, operation, approveContent, sysUser.RealName, "", "冻结")
  7204. //新增产品权限冻结操作日志
  7205. for _, companyReportPermission := range companyReportPermissionList {
  7206. record := company_report_permission_log.CompanyReportPermissionLog{
  7207. CompanyReportPermissionId: companyReportPermission.CompanyReportPermissionId,
  7208. CompanyId: companyReportPermission.CompanyId,
  7209. ProductId: productId,
  7210. ProductName: companyReportPermission.ProductName,
  7211. SysUserId: sysUser.AdminId,
  7212. SysUserName: sysUser.RealName,
  7213. Remark: "冻结客户",
  7214. Operation: "freeze",
  7215. Status: companyReportPermission.Status,
  7216. CreateTime: time.Now(),
  7217. }
  7218. _, err = company_report_permission_log.AddCompanyReportPermissionLog(&record)
  7219. }
  7220. }
  7221. br.Ret = 200
  7222. br.Success = true
  7223. br.Msg = "领取成功"
  7224. }
  7225. // @Title 获取客户权限
  7226. // @Description 获取客户权限接口
  7227. // @Param CompanyId query int true "用户id"
  7228. // @Success 200 {object} company.CompanyPermissionResp
  7229. // @router /getCompanyPermission [get]
  7230. func (this *CompanyController) PermissionList() {
  7231. br := new(models.BaseResponse).Init()
  7232. defer func() {
  7233. this.Data["json"] = br
  7234. this.ServeJSON()
  7235. }()
  7236. sysUser := this.SysUser
  7237. if sysUser == nil {
  7238. br.Msg = "请登录"
  7239. br.ErrMsg = "请登录,SysUser Is Empty"
  7240. br.Ret = 408
  7241. return
  7242. }
  7243. companyId, _ := this.GetInt("CompanyId")
  7244. if companyId <= 0 {
  7245. br.Msg = "参数错误"
  7246. br.ErrMsg = "客户参数小于等于0"
  7247. return
  7248. }
  7249. //返回基础参数
  7250. resp := new(company.CompanyPermissionResp)
  7251. //客户类型map
  7252. classifyMap := make(map[string]int)
  7253. classifyMap["ficc"] = 1
  7254. classifyMap["权益"] = 2
  7255. roleTypeCode := sysUser.RoleTypeCode
  7256. var companySlice []string
  7257. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN ||
  7258. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN ||
  7259. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER ||
  7260. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP ||
  7261. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_TEAM ||
  7262. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_DEPARTMENT ||
  7263. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_RESEARCHR {
  7264. companySlice = append(companySlice, "ficc")
  7265. } else if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN ||
  7266. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN ||
  7267. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER ||
  7268. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP ||
  7269. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_DEPARTMENT ||
  7270. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_RESEARCHR {
  7271. companySlice = append(companySlice, "权益")
  7272. }
  7273. for _, companyType := range companySlice {
  7274. //子权限切片集合
  7275. //var permissionClassifyArr []string
  7276. var permissionProductId int
  7277. if companyType == "ficc" {
  7278. permissionProductId = utils.COMPANY_PRODUCT_FICC_ID
  7279. } else {
  7280. permissionProductId = utils.COMPANY_PRODUCT_RAI_ID
  7281. }
  7282. //子权限切片集合
  7283. permissionClassifyArr, err := models.GetPermissionFirstByProductId(permissionProductId)
  7284. if err != nil {
  7285. br.Msg = "获取失败"
  7286. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  7287. return
  7288. }
  7289. //遍历获取
  7290. for _, v := range permissionClassifyArr {
  7291. checkList := make([]int, 0)
  7292. plist := new(company.PermissionLookList)
  7293. plist.Items = make([]*company.PermissionLookItem, 0)
  7294. items, err := company.GetPermissionLookItemsByParentId(classifyMap[companyType], v.ChartPermissionId)
  7295. if err != nil {
  7296. br.Msg = "获取失败"
  7297. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  7298. return
  7299. }
  7300. mapPermissionCheck := make(map[string]int)
  7301. for i, n := range items {
  7302. item := items[i]
  7303. count, err := company.GetCompanyPermissionCheck(companyId, n.ChartPermissionId)
  7304. if err != nil {
  7305. br.Msg = "获取失败"
  7306. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  7307. return
  7308. }
  7309. //合并主观客观勾选的权限
  7310. if count > 0 && mapPermissionCheck[n.PermissionName] == 0 {
  7311. checkList = append(checkList, n.ChartPermissionId)
  7312. mapPermissionCheck[n.PermissionName] = n.ChartPermissionId
  7313. }
  7314. permission, err := company.GetCompanyPermissionCheckItem(companyId, n.ChartPermissionId)
  7315. if err != nil && err.Error() != utils.ErrNoRow() {
  7316. br.Msg = "获取失败"
  7317. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  7318. return
  7319. }
  7320. if permission != nil && permission.ChartPermissionId > 0 {
  7321. items[i].StartDate = permission.StartDate
  7322. items[i].EndDate = permission.EndDate
  7323. items[i].Status = permission.Status
  7324. //判断主观、客观
  7325. if items[i].PermissionType == 1 {
  7326. items[i].PermissionTypeName = "主观"
  7327. } else if items[i].PermissionType == 2 {
  7328. items[i].PermissionTypeName = "客观"
  7329. }
  7330. }
  7331. endDateTime, _ := time.Parse(utils.FormatDate, item.EndDate)
  7332. endDateTime = endDateTime.AddDate(0, 0, 1)
  7333. sub := endDateTime.Sub(time.Now())
  7334. if sub < 0 {
  7335. sub = 0
  7336. }
  7337. expireDay := fmt.Sprintf("%v", int(sub.Hours()/24))
  7338. items[i].ExpireDay = expireDay
  7339. items[i].ClassifyName = v.PermissionName
  7340. //if n.PermissionType == 1 {
  7341. // items[i].PermissionTypeName = "主观"
  7342. //} else if n.PermissionType == 2 {
  7343. // items[i].PermissionTypeName = "客观"
  7344. //}
  7345. }
  7346. //合并主观客观
  7347. mapPermissionName := make(map[string]int)
  7348. for _, v := range items {
  7349. if mapPermissionName[v.PermissionName] == 0 {
  7350. //plist.Items = append(plist.Items, v)
  7351. //mapPermissionName[v.PermissionName] = v.ChartPermissionId
  7352. // CRM8.8-只有客观的时候回显
  7353. if mapPermissionCheck[v.PermissionName] == 0 || (mapPermissionCheck[v.PermissionName] > 0 && v.ChartPermissionId == mapPermissionCheck[v.PermissionName]) {
  7354. plist.Items = append(plist.Items, v)
  7355. mapPermissionName[v.PermissionName] = v.ChartPermissionId
  7356. }
  7357. }
  7358. }
  7359. plist.ClassifyName = v.PermissionName
  7360. plist.CheckList = checkList
  7361. if companyType == "ficc" {
  7362. resp.FiccPermissionList = append(resp.FiccPermissionList, plist)
  7363. } else {
  7364. resp.PermissionList = append(resp.PermissionList, plist)
  7365. }
  7366. }
  7367. }
  7368. br.Ret = 200
  7369. br.Success = true
  7370. br.Msg = "获取成功"
  7371. br.Data = resp
  7372. }
  7373. // @Title 获取客户来源列表
  7374. // @Description 获取客户来源列表
  7375. // @Success 200 {object} models.CompanySourceListResp
  7376. // @router /getCompanySourceList [get]
  7377. func (this *CompanyController) CompanySourceList() {
  7378. br := new(models.BaseResponse).Init()
  7379. defer func() {
  7380. this.Data["json"] = br
  7381. this.ServeJSON()
  7382. }()
  7383. sysUser := this.SysUser
  7384. if sysUser == nil {
  7385. br.Msg = "请登录"
  7386. br.ErrMsg = "请登录,SysUser Is Empty"
  7387. br.Ret = 408
  7388. return
  7389. }
  7390. list, err := models.GetAllCompanySourceList()
  7391. if err != nil {
  7392. br.Msg = "查询失败"
  7393. br.ErrMsg = "查询异常:" + err.Error()
  7394. return
  7395. }
  7396. br.Ret = 200
  7397. br.Success = true
  7398. br.Msg = "获取成功"
  7399. br.Data = models.CompanySourceListResp{
  7400. List: list,
  7401. }
  7402. }
  7403. // @Title 获取客户的合同列表
  7404. // @Description 获取客户合同列表接口
  7405. // @Param CompanyId query int true "用户id"
  7406. // @Param CompanyType query string false "用户类型:可取范围:ficc,权益"
  7407. // @Param Status query int true "合同审核结果,枚举值:`0`,`1`; 0:待审核,1:审核通过"
  7408. // @Success 200 {object} company.CompanyPermissionResp
  7409. // @router /getCompanyContract [get]
  7410. func (this *CompanyController) ContractList() {
  7411. br := new(models.BaseResponse).Init()
  7412. defer func() {
  7413. this.Data["json"] = br
  7414. this.ServeJSON()
  7415. }()
  7416. sysUser := this.SysUser
  7417. if sysUser == nil {
  7418. br.Msg = "请登录"
  7419. br.ErrMsg = "请登录,SysUser Is Empty"
  7420. br.Ret = 408
  7421. return
  7422. }
  7423. companyId, _ := this.GetInt("CompanyId")
  7424. if companyId <= 0 {
  7425. br.Msg = "参数错误"
  7426. br.ErrMsg = "客户参数小于等于0"
  7427. return
  7428. }
  7429. //合同状态
  7430. status, _ := this.GetInt("Status")
  7431. //产品类型
  7432. companyType := this.GetString("CompanyType")
  7433. var condition string
  7434. var pars []interface{}
  7435. //产品类型
  7436. if companyType == "" {
  7437. productId := services.GetProductId(sysUser.RoleTypeCode)
  7438. if productId != 0 {
  7439. condition += " AND product_id = ?"
  7440. pars = append(pars, productId)
  7441. }
  7442. } else {
  7443. if companyType == "ficc" {
  7444. condition += " AND product_id = ?"
  7445. pars = append(pars, 1)
  7446. } else {
  7447. condition += " AND product_id = ?"
  7448. pars = append(pars, 2)
  7449. }
  7450. }
  7451. if status != 0 {
  7452. condition += " AND status = ?"
  7453. pars = append(pars, status)
  7454. }
  7455. list, err := company.GetCompanyContractListByCompanyId(companyId, condition, pars)
  7456. if err != nil {
  7457. br.Msg = "查询失败"
  7458. br.ErrMsg = "查询异常:" + err.Error()
  7459. return
  7460. }
  7461. br.Ret = 200
  7462. br.Success = true
  7463. br.Msg = "获取成功"
  7464. br.Data = list
  7465. }
  7466. // @Title 获取客户所属销售
  7467. // @Description 根据客户id获取客户所属销售
  7468. // @Param CompanyId query int true "客户id"
  7469. // @Success 200 {object} response.CompanySellerListResp
  7470. // @router /getCompanySellerList [get]
  7471. func (this *CompanyUserController) GetCompanySellerList() {
  7472. br := new(models.BaseResponse).Init()
  7473. defer func() {
  7474. this.Data["json"] = br
  7475. this.ServeJSON()
  7476. }()
  7477. sysUser := this.SysUser
  7478. if sysUser == nil {
  7479. br.Msg = "请登录"
  7480. br.ErrMsg = "请登录,SysUser Is Empty"
  7481. br.Ret = 408
  7482. return
  7483. }
  7484. companyId, _ := this.GetInt("CompanyId")
  7485. //item := make([]*company.CompanyItem, 0)
  7486. list, err := company.GetCompanySellerByCompanyId(companyId)
  7487. if err != nil && err.Error() != utils.ErrNoRow() {
  7488. br.Msg = "获取失败"
  7489. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  7490. return
  7491. }
  7492. resp := response.CompanySellerListResp{
  7493. List: list,
  7494. }
  7495. //resp.List = list
  7496. br.Ret = 200
  7497. br.Success = true
  7498. br.Msg = "获取成功"
  7499. br.Data = resp
  7500. }
  7501. // GetTryOutCompanyList
  7502. // @Title 获取销售今日待办数据
  7503. // @Description 获取销售今日待办接口
  7504. // @Param CompanyName query string false "客户名称"
  7505. // @Param ReasonStatus query int false "续约情况说明状态:-1:未填写,0:全部,1:已填写"
  7506. // @Param PageSize query int true "每页数据条数"
  7507. // @Param CurrentIndex query int true "当前页页码,从1开始"
  7508. // @Success 200 {object} response.TryOutCompanyListResp
  7509. // @router /getTryOutCompanyList [get]
  7510. func (this *CompanyController) GetTryOutCompanyList() {
  7511. br := new(models.BaseResponse).Init()
  7512. defer func() {
  7513. this.Data["json"] = br
  7514. this.ServeJSON()
  7515. }()
  7516. sysUser := this.SysUser
  7517. if sysUser == nil {
  7518. br.Msg = "请登录"
  7519. br.ErrMsg = "请登录,SysUser Is Empty"
  7520. br.Ret = 408
  7521. return
  7522. }
  7523. companyName := this.GetString("CompanyName")
  7524. reasonStatus, _ := this.GetInt("ReasonStatus", 0)
  7525. pageSize, _ := this.GetInt("PageSize")
  7526. currentIndex, _ := this.GetInt("CurrentIndex")
  7527. productId := services.GetProductId(sysUser.RoleTypeCode)
  7528. var startSize int
  7529. if pageSize <= 0 {
  7530. pageSize = utils.PageSize20
  7531. }
  7532. if currentIndex <= 0 {
  7533. currentIndex = 1
  7534. }
  7535. startSize = paging.StartIndex(currentIndex, pageSize)
  7536. var condition string
  7537. var pars []interface{}
  7538. //sellerId, productId int, tryOutTime time.Time, tryOutReason string
  7539. var tryOutTime, lastDescriptionTime time.Time
  7540. if productId == 1 {
  7541. //ficc
  7542. interval := cache.GetIntervalFromCrmConfig("try_out_time_intervals")
  7543. tryOutTime = time.Now().AddDate(0, 0, -interval)
  7544. interval = cache.GetIntervalFromCrmConfig("last_description_time_intervals")
  7545. lastDescriptionTime = time.Now().AddDate(0, 0, -interval)
  7546. } else {
  7547. //权益
  7548. interval := cache.GetIntervalFromCrmConfig("rai_try_out_time_intervals")
  7549. tryOutTime = time.Now().AddDate(0, 0, -interval)
  7550. interval = cache.GetIntervalFromCrmConfig("rai_last_description_time_intervals")
  7551. lastDescriptionTime = time.Now().AddDate(0, 0, -interval)
  7552. }
  7553. if productId > 0 {
  7554. condition += ` and product_id=? `
  7555. pars = append(pars, productId)
  7556. }
  7557. //客户名称模糊搜索
  7558. if companyName != "" {
  7559. condition += ` and b.company_name like "%` + companyName + `%" `
  7560. }
  7561. //续约情况说明(-1:未填写,0:全部,1:已填写)
  7562. switch reasonStatus {
  7563. case -1:
  7564. 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) `
  7565. pars = append(pars, sysUser.AdminId, tryOutTime, lastDescriptionTime)
  7566. case 1:
  7567. 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) `
  7568. pars = append(pars, sysUser.AdminId, tryOutTime)
  7569. default:
  7570. 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) `
  7571. pars = append(pars, sysUser.AdminId, tryOutTime, lastDescriptionTime)
  7572. }
  7573. total := 0
  7574. list := make([]*company.TryOutCompanyList, 0)
  7575. 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}
  7576. if strings.Contains(strings.Join(ignoreStrs, ","), sysUser.RoleTypeCode) {
  7577. //排除已经签署续约合同的
  7578. notSql := ``
  7579. if productId > 0 {
  7580. notSql = fmt.Sprint(` and product_id = `, productId)
  7581. }
  7582. condition += `and a.company_id not in (select company_id from company_contract where contract_type ="续约合同" and start_date >now() and status = 1 ` + notSql + `) `
  7583. tmpTotal, err := company.GetTryOutCompanyCount(condition, pars)
  7584. if err != nil {
  7585. br.Msg = "获取失败"
  7586. br.ErrMsg = "获取总数失败失败,Err:" + err.Error()
  7587. return
  7588. }
  7589. tmpList, err := company.GetTryOutCompanyList(condition, pars, startSize, pageSize)
  7590. if err != nil {
  7591. br.Msg = "获取失败"
  7592. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  7593. return
  7594. }
  7595. total = tmpTotal
  7596. list = tmpList
  7597. }
  7598. if len(list) > 0 {
  7599. for k, item := range list {
  7600. endTime, _ := time.Parse(utils.FormatDate, item.EndDate)
  7601. endTime = endTime.AddDate(0, 0, 1)
  7602. sub := endTime.Sub(time.Now())
  7603. if sub < 0 {
  7604. sub = 0
  7605. }
  7606. list[k].ExpireDays = int(sub.Hours() / 24)
  7607. }
  7608. }
  7609. page := paging.GetPaging(currentIndex, pageSize, total)
  7610. resp := response.TryOutCompanyListResp{
  7611. List: list,
  7612. Paging: page,
  7613. }
  7614. br.Ret = 200
  7615. br.Success = true
  7616. br.Msg = "获取成功"
  7617. br.Data = resp
  7618. }
  7619. // EditTryOutCompanyReason
  7620. // @Title 编辑续约说明情况
  7621. // @Description 编辑续约说明情况接口
  7622. // @Param request body company.RenewalReasonReq true "type json string"
  7623. // @Success 200 编辑成功
  7624. // @router /editTryOutCompanyReason [post]
  7625. func (this *CompanyController) EditTryOutCompanyReason() {
  7626. br := new(models.BaseResponse).Init()
  7627. defer func() {
  7628. this.Data["json"] = br
  7629. this.ServeJSON()
  7630. }()
  7631. sysUser := this.SysUser
  7632. if sysUser == nil {
  7633. br.Msg = "请登录"
  7634. br.ErrMsg = "请登录,SysUser Is Empty"
  7635. br.Ret = 408
  7636. return
  7637. }
  7638. var req company.RenewalReasonReq
  7639. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  7640. if err != nil {
  7641. br.Msg = "参数解析异常!"
  7642. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  7643. return
  7644. }
  7645. if req.CompanyId <= 0 {
  7646. br.Msg = "参数缺失"
  7647. br.ErrMsg = "参数缺失,客户编号未传!"
  7648. return
  7649. }
  7650. if req.ProductId <= 0 {
  7651. br.Msg = "参数缺失"
  7652. br.ErrMsg = "参数缺失,产品编号未传!"
  7653. return
  7654. }
  7655. if req.Remark == "" {
  7656. br.Msg = "参数缺失"
  7657. br.ErrMsg = "参数缺失,续约情况说明未传!"
  7658. return
  7659. }
  7660. /*if req.RenewalTodo == "" && req.Renew == 0 {
  7661. br.Msg = "参数缺失"
  7662. br.ErrMsg = "参数缺失,待办事项说明未传!"
  7663. return
  7664. }*/
  7665. companyProduct, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, req.ProductId)
  7666. if err != nil {
  7667. br.Msg = "查询客户异常"
  7668. br.ErrMsg = "查询客户异常,Err:" + err.Error()
  7669. return
  7670. }
  7671. if companyProduct.SellerId != sysUser.AdminId {
  7672. br.Msg = "客户异常,没有该客户的操作权限"
  7673. br.ErrMsg = "客户异常,没有该客户的操作权限"
  7674. return
  7675. }
  7676. renewalReason := company.CompanyRenewalReason{
  7677. CompanyRenewalReasonId: 0,
  7678. CompanyId: companyProduct.CompanyId,
  7679. ProductId: companyProduct.ProductId,
  7680. ProductName: companyProduct.ProductName,
  7681. CompanyName: companyProduct.CompanyName,
  7682. TryOutTime: companyProduct.TryOutTime,
  7683. RenewalReason: req.Remark,
  7684. RenewalTodo: req.RenewalTodo,
  7685. LastDescriptionTime: companyProduct.LastDescriptionTime,
  7686. EndDays: companyProduct.ContractEndDate,
  7687. ExpirationTimeExceeded: 0,
  7688. RenewalIntention: req.Renew,
  7689. CreateTime: time.Now(),
  7690. }
  7691. endTime, err := company.GetTryOutTimeFromOperationRecord(renewalReason.CompanyId)
  7692. if err != nil {
  7693. br.Msg = "查询该客户转试用时间异常!"
  7694. br.ErrMsg = "查询该客户转试用时间异常,err:" + err.Error()
  7695. return
  7696. }
  7697. endDateTime, err := time.Parse(utils.FormatDateTime, *endTime)
  7698. if err != nil {
  7699. br.Msg = "时间格式化异常!"
  7700. br.ErrMsg = "时间格式化异常,err:" + err.Error()
  7701. return
  7702. }
  7703. endDate := endDateTime.Format(utils.FormatDate)
  7704. endDateTime, _ = time.Parse(utils.FormatDate, endDate)
  7705. sub := time.Now().Sub(endDateTime)
  7706. renewalReason.ExpirationTimeExceeded = int(sub.Hours() / 24)
  7707. err = company.AddRenewalReason(&renewalReason)
  7708. if err != nil {
  7709. br.Msg = "新增续约情况说明操作异常!"
  7710. br.ErrMsg = "新增续约情况说明操作异常,err:" + err.Error()
  7711. return
  7712. }
  7713. companyProduct.RenewalIntention = req.Renew
  7714. err = company.EditTryOutCompanyReason(companyProduct, req.Remark, req.RenewalTodo)
  7715. if err != nil {
  7716. br.Msg = "更新客户未续约异常!"
  7717. br.ErrMsg = "更新客户未续约异常,err:" + err.Error()
  7718. return
  7719. }
  7720. if req.Renew == 1 {
  7721. productName := ""
  7722. if req.ProductId == 1 {
  7723. productName = "ficc"
  7724. } else if req.ProductId == 2 {
  7725. productName = "权益"
  7726. } else {
  7727. productName = "佣金客户"
  7728. }
  7729. cp, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, req.ProductId)
  7730. if err != nil {
  7731. br.Msg = "查询该客户产品异常!"
  7732. br.ErrMsg = "查询该客户产品异常,err:" + err.Error()
  7733. return
  7734. }
  7735. if cp.Status != utils.COMPANY_STATUS_TRY_OUT {
  7736. br.Msg = "客户状态为:" + cp.Status + ";不可冻结"
  7737. br.ErrMsg = "客户状态为:" + cp.Status + ";不可冻结"
  7738. return
  7739. }
  7740. //查询客户的产品权限
  7741. companyReportPermissionList, err := company.GetCompanyReportPermission(req.CompanyId, req.ProductId)
  7742. if err != nil {
  7743. br.Msg = "查询客户的产品权限异常"
  7744. br.ErrMsg = "查询客户的产品权限异常:" + err.Error()
  7745. return
  7746. }
  7747. err = company.CompanyFreeze(req.CompanyId, req.ProductId, req.Remark)
  7748. if err != nil {
  7749. br.Msg = "冻结失败!"
  7750. br.ErrMsg = "冻结失败,Err:" + err.Error()
  7751. return
  7752. }
  7753. //新增操作记录
  7754. go func() {
  7755. time.Sleep(time.Second)
  7756. approveContent := req.Remark
  7757. remark := "冻结客户"
  7758. operation := "freeze"
  7759. _ = services.AddCompanyOperationRecord(req.CompanyId, cp.SellerId, sysUser.AdminId, req.ProductId, sysUser.AdminId, cp.CompanyName,
  7760. productName, "超级管理员", remark, operation, approveContent, sysUser.RealName, "", "冻结")
  7761. //新增产品权限冻结操作日志
  7762. for _, companyReportPermission := range companyReportPermissionList {
  7763. record := company_report_permission_log.CompanyReportPermissionLog{
  7764. CompanyReportPermissionId: companyReportPermission.CompanyReportPermissionId,
  7765. CompanyId: companyReportPermission.CompanyId,
  7766. ProductId: req.ProductId,
  7767. ProductName: companyReportPermission.ProductName,
  7768. SysUserId: sysUser.AdminId,
  7769. SysUserName: "超级管理员",
  7770. Remark: "冻结客户",
  7771. Operation: "freeze",
  7772. Status: companyReportPermission.Status,
  7773. CreateTime: time.Now(),
  7774. }
  7775. _, err = company_report_permission_log.AddCompanyReportPermissionLog(&record)
  7776. }
  7777. }()
  7778. }
  7779. approveContent := req.Remark
  7780. approveContentExtra := req.RenewalTodo
  7781. remark := "新增续约说明"
  7782. operation := "edit_renewal_reason"
  7783. _ = services.AddCompanyOperationRecordMore(req.CompanyId, companyProduct.SellerId, sysUser.AdminId, companyProduct.ProductId, sysUser.AdminId, companyProduct.CompanyName,
  7784. companyProduct.ProductName, sysUser.RealName, remark, operation, approveContent, approveContentExtra, sysUser.RealName, "", companyProduct.Status)
  7785. items, err := company.ReadCompanyOperationRecord(req.CompanyId)
  7786. if err != nil {
  7787. br.Msg = "编辑失败"
  7788. br.ErrMsg = "编辑失败,Err:" + err.Error()
  7789. return
  7790. }
  7791. if len(items) > 0 {
  7792. record := new(company.CompanyOperationRecord)
  7793. record.Id = items[0].Id
  7794. record.ApproveContent = req.Remark
  7795. record.ApproveContentExtra = req.RenewalTodo
  7796. _, err = company.UpdateCompanyOperationRecord(record)
  7797. if err != nil {
  7798. br.Msg = "编辑失败"
  7799. br.ErrMsg = "编辑失败,Err:" + err.Error()
  7800. return
  7801. }
  7802. } else {
  7803. br.Msg = "编辑失败"
  7804. br.ErrMsg = "编辑失败,未查询到转试用记录"
  7805. return
  7806. }
  7807. br.Ret = 200
  7808. br.Success = true
  7809. br.Msg = "编辑成功"
  7810. }
  7811. // AddTryOutCompanyReason
  7812. // @Title 新增续约说明情况
  7813. // @Description 新增续约说明情况接口
  7814. // @Param request body company.RenewalReasonReq true "type json string"
  7815. // @Success 200 编辑成功
  7816. // @router /addTryOutCompanyReason [post]
  7817. func (this *CompanyController) AddTryOutCompanyReason() {
  7818. br := new(models.BaseResponse).Init()
  7819. defer func() {
  7820. this.Data["json"] = br
  7821. this.ServeJSON()
  7822. }()
  7823. sysUser := this.SysUser
  7824. if sysUser == nil {
  7825. br.Msg = "请登录"
  7826. br.ErrMsg = "请登录,SysUser Is Empty"
  7827. br.Ret = 408
  7828. return
  7829. }
  7830. var req company.RenewalReasonReq
  7831. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  7832. if err != nil {
  7833. br.Msg = "参数解析异常!"
  7834. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  7835. return
  7836. }
  7837. if req.CompanyId <= 0 {
  7838. br.Msg = "参数缺失"
  7839. br.ErrMsg = "参数缺失,客户编号未传!"
  7840. return
  7841. }
  7842. if req.ProductId <= 0 {
  7843. br.Msg = "参数缺失"
  7844. br.ErrMsg = "参数缺失,产品编号未传!"
  7845. return
  7846. }
  7847. if req.Remark == "" {
  7848. br.Msg = "参数缺失"
  7849. br.ErrMsg = "参数缺失,续约情况说明未传!"
  7850. return
  7851. }
  7852. if req.RenewalTodo == "" && req.Renew == 0 {
  7853. br.Msg = "参数缺失"
  7854. br.ErrMsg = "参数缺失,待办事项说明未传!"
  7855. return
  7856. }
  7857. companyProduct, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, req.ProductId)
  7858. if err != nil {
  7859. br.Msg = "查询客户异常"
  7860. br.ErrMsg = "查询客户异常,Err:" + err.Error()
  7861. return
  7862. }
  7863. if companyProduct.SellerId != sysUser.AdminId {
  7864. br.Msg = "客户异常,没有该客户的操作权限"
  7865. br.ErrMsg = "客户异常,没有该客户的操作权限"
  7866. return
  7867. }
  7868. renewalReason := company.CompanyRenewalReason{
  7869. CompanyRenewalReasonId: 0,
  7870. CompanyId: companyProduct.CompanyId,
  7871. ProductId: companyProduct.ProductId,
  7872. ProductName: companyProduct.ProductName,
  7873. CompanyName: companyProduct.CompanyName,
  7874. TryOutTime: companyProduct.TryOutTime,
  7875. RenewalReason: req.Remark,
  7876. RenewalTodo: req.RenewalTodo,
  7877. LastDescriptionTime: companyProduct.LastDescriptionTime,
  7878. EndDays: companyProduct.ContractEndDate,
  7879. ExpirationTimeExceeded: 0,
  7880. RenewalIntention: req.Renew,
  7881. CreateTime: time.Now(),
  7882. }
  7883. endTime, err := company.GetTryOutTimeFromOperationRecord(renewalReason.CompanyId)
  7884. if err != nil {
  7885. br.Msg = "查询该客户转试用时间异常!"
  7886. br.ErrMsg = "查询该客户转试用时间异常,err:" + err.Error()
  7887. return
  7888. }
  7889. endDateTime, err := time.Parse(utils.FormatDateTime, *endTime)
  7890. if err != nil {
  7891. br.Msg = "时间格式化异常!"
  7892. br.ErrMsg = "时间格式化异常,err:" + err.Error()
  7893. return
  7894. }
  7895. endDate := endDateTime.Format(utils.FormatDate)
  7896. endDateTime, _ = time.Parse(utils.FormatDate, endDate)
  7897. sub := time.Now().Sub(endDateTime)
  7898. renewalReason.ExpirationTimeExceeded = int(sub.Hours() / 24)
  7899. err = company.AddRenewalReason(&renewalReason)
  7900. if err != nil {
  7901. br.Msg = "新增续约情况说明操作异常!"
  7902. br.ErrMsg = "新增续约情况说明操作异常,err:" + err.Error()
  7903. return
  7904. }
  7905. companyProduct.RenewalIntention = req.Renew
  7906. err = company.EditTryOutCompanyReason(companyProduct, req.Remark, req.RenewalTodo)
  7907. if err != nil {
  7908. br.Msg = "更新客户续约情况说明异常!"
  7909. br.ErrMsg = "更新客户续约情况说明异常,err:" + err.Error()
  7910. return
  7911. }
  7912. if req.Renew == 1 {
  7913. productName := ""
  7914. if req.ProductId == 1 {
  7915. productName = "ficc"
  7916. } else if req.ProductId == 2 {
  7917. productName = "权益"
  7918. } else {
  7919. productName = "佣金客户"
  7920. }
  7921. cp, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, req.ProductId)
  7922. if err != nil {
  7923. br.Msg = "查询该客户产品异常!"
  7924. br.ErrMsg = "查询该客户产品异常,err:" + err.Error()
  7925. return
  7926. }
  7927. if cp.Status != utils.COMPANY_STATUS_TRY_OUT {
  7928. br.Msg = "客户状态为:" + cp.Status + ";不可冻结"
  7929. br.ErrMsg = "客户状态为:" + cp.Status + ";不可冻结"
  7930. return
  7931. }
  7932. //查询客户的产品权限
  7933. companyReportPermissionList, err := company.GetCompanyReportPermission(req.CompanyId, req.ProductId)
  7934. if err != nil {
  7935. br.Msg = "查询客户的产品权限异常"
  7936. br.ErrMsg = "查询客户的产品权限异常:" + err.Error()
  7937. return
  7938. }
  7939. err = company.CompanyFreeze(req.CompanyId, req.ProductId, req.Remark)
  7940. if err != nil {
  7941. br.Msg = "冻结失败!"
  7942. br.ErrMsg = "冻结失败,Err:" + err.Error()
  7943. return
  7944. }
  7945. //新增操作记录
  7946. go func() {
  7947. time.Sleep(time.Second)
  7948. approveContent := req.Remark
  7949. remark := "冻结客户"
  7950. operation := "freeze"
  7951. _ = services.AddCompanyOperationRecord(req.CompanyId, cp.SellerId, sysUser.AdminId, req.ProductId, sysUser.AdminId, cp.CompanyName,
  7952. productName, "超级管理员", remark, operation, approveContent, sysUser.RealName, "", "冻结")
  7953. //新增产品权限冻结操作日志
  7954. for _, companyReportPermission := range companyReportPermissionList {
  7955. record := company_report_permission_log.CompanyReportPermissionLog{
  7956. CompanyReportPermissionId: companyReportPermission.CompanyReportPermissionId,
  7957. CompanyId: companyReportPermission.CompanyId,
  7958. ProductId: req.ProductId,
  7959. ProductName: companyReportPermission.ProductName,
  7960. SysUserId: sysUser.AdminId,
  7961. SysUserName: "超级管理员",
  7962. Remark: "冻结客户",
  7963. Operation: "freeze",
  7964. Status: companyReportPermission.Status,
  7965. CreateTime: time.Now(),
  7966. }
  7967. _, err = company_report_permission_log.AddCompanyReportPermissionLog(&record)
  7968. }
  7969. }()
  7970. }
  7971. {
  7972. approveContent := req.Remark
  7973. approveContentExtra := req.RenewalTodo
  7974. remark := "新增续约说明"
  7975. operation := "add_renewal_reason"
  7976. _ = services.AddCompanyOperationRecordMore(req.CompanyId, companyProduct.SellerId, sysUser.AdminId, companyProduct.ProductId, sysUser.AdminId, companyProduct.CompanyName,
  7977. companyProduct.ProductName, sysUser.RealName, remark, operation, approveContent, approveContentExtra, sysUser.RealName, "", companyProduct.Status)
  7978. }
  7979. br.Ret = 200
  7980. br.Success = true
  7981. br.Msg = "编辑成功"
  7982. }
  7983. // RenewReasonList 客户未续约说明历史列表
  7984. // @Title 客户未续约说明历史列表
  7985. // @Description 客户未续约说明历史列表
  7986. // @Param CompanyId query string true "客户id"
  7987. // @Param ProductId query string true "产品id"
  7988. // @Success 200 {object} response.RenewReasonItemResp
  7989. // @router /renewReasonList [get]
  7990. func (this *CompanyController) RenewReasonList() {
  7991. br := new(models.BaseResponse).Init()
  7992. defer func() {
  7993. this.Data["json"] = br
  7994. this.ServeJSON()
  7995. }()
  7996. sysUser := this.SysUser
  7997. if sysUser == nil {
  7998. br.Msg = "请登录"
  7999. br.ErrMsg = "请登录,SysUser Is Empty"
  8000. br.Ret = 408
  8001. return
  8002. }
  8003. CompanyId := this.GetString("CompanyId")
  8004. ProductId := this.GetString("ProductId")
  8005. if CompanyId == "" {
  8006. br.Msg = "请输入客户ID"
  8007. return
  8008. }
  8009. if ProductId != "1" && ProductId != "2" {
  8010. br.Msg = "请输入正确的产品ID"
  8011. return
  8012. }
  8013. renewalReason, err := models.GetMoreRenewalReason(CompanyId, ProductId)
  8014. if err != nil {
  8015. br.Msg = "获取失败"
  8016. br.ErrMsg = "获取失败,Err:" + err.Error()
  8017. return
  8018. }
  8019. resp := make([]response.RenewReasonItemResp, len(renewalReason))
  8020. for i, reason := range renewalReason {
  8021. createDate := reason.CreateTime.Format("2006.01.02 15:04:05")
  8022. resp[i].RenewalReason = reason.RenewalReason
  8023. resp[i].RenewalTodo = reason.RenewalTodo
  8024. resp[i].CreateTime = createDate
  8025. }
  8026. br.Ret = 200
  8027. br.Success = true
  8028. br.Msg = "获取成功"
  8029. br.Data = resp
  8030. }
  8031. // AddRenewalReason
  8032. // @Title 转试用按钮新增续约说明情况
  8033. // @Description 转试用按钮新增续约说明情况
  8034. // @Param request body company.TryOutReq true "type json string"
  8035. // @Success 200 编辑成功
  8036. // @router /addRenewalReason [post]
  8037. func (this *CompanyController) AddRenewalReason() {
  8038. br := new(models.BaseResponse).Init()
  8039. defer func() {
  8040. this.Data["json"] = br
  8041. this.ServeJSON()
  8042. }()
  8043. sysUser := this.SysUser
  8044. if sysUser == nil {
  8045. br.Msg = "请登录"
  8046. br.ErrMsg = "请登录,SysUser Is Empty"
  8047. br.Ret = 408
  8048. return
  8049. }
  8050. var req company.TryOutReq
  8051. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  8052. if err != nil {
  8053. br.Msg = "参数解析异常!"
  8054. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  8055. return
  8056. }
  8057. if req.CompanyId <= 0 {
  8058. br.Msg = "参数缺失"
  8059. br.ErrMsg = "参数缺失,客户编号未传!"
  8060. return
  8061. }
  8062. if req.ProductId <= 0 {
  8063. br.Msg = "参数缺失"
  8064. br.ErrMsg = "参数缺失,产品编号未传!"
  8065. return
  8066. }
  8067. if req.OperationId <= 0 {
  8068. br.Msg = "参数缺失"
  8069. br.ErrMsg = "参数缺失,操作记录表编号未传!"
  8070. return
  8071. }
  8072. if req.Remark == "" {
  8073. br.Msg = "参数缺失"
  8074. br.ErrMsg = "参数缺失,续约情况说明未传!"
  8075. return
  8076. }
  8077. if req.RenewalTodo == "" && req.Renew == 0 {
  8078. br.Msg = "参数缺失"
  8079. br.ErrMsg = "参数缺失,待办事项说明未传!"
  8080. return
  8081. }
  8082. companyProduct, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, req.ProductId)
  8083. if err != nil {
  8084. br.Msg = "查询客户异常"
  8085. br.ErrMsg = "查询客户异常,Err:" + err.Error()
  8086. return
  8087. }
  8088. if companyProduct.SellerId != sysUser.AdminId {
  8089. br.Msg = "客户异常,没有该客户的操作权限"
  8090. br.ErrMsg = "客户异常,没有该客户的操作权限"
  8091. return
  8092. }
  8093. renewalReason := company.CompanyRenewalReason{
  8094. CompanyRenewalReasonId: 0,
  8095. CompanyId: companyProduct.CompanyId,
  8096. ProductId: companyProduct.ProductId,
  8097. ProductName: companyProduct.ProductName,
  8098. CompanyName: companyProduct.CompanyName,
  8099. TryOutTime: companyProduct.TryOutTime,
  8100. RenewalReason: req.Remark,
  8101. RenewalTodo: req.RenewalTodo,
  8102. LastDescriptionTime: companyProduct.LastDescriptionTime,
  8103. EndDays: companyProduct.ContractEndDate,
  8104. ExpirationTimeExceeded: 0,
  8105. RenewalIntention: req.Renew,
  8106. CreateTime: time.Now(),
  8107. }
  8108. endTime, err := company.GetTryOutTimeFromOperationRecord(renewalReason.CompanyId)
  8109. if err != nil {
  8110. br.Msg = "查询该客户转试用时间异常!"
  8111. br.ErrMsg = "查询该客户转试用时间异常,err:" + err.Error()
  8112. return
  8113. }
  8114. endDateTime, err := time.Parse(utils.FormatDateTime, *endTime)
  8115. if err != nil {
  8116. br.Msg = "时间格式化异常!"
  8117. br.ErrMsg = "时间格式化异常,err:" + err.Error()
  8118. return
  8119. }
  8120. endDate := endDateTime.Format(utils.FormatDate)
  8121. endDateTime, _ = time.Parse(utils.FormatDate, endDate)
  8122. sub := time.Now().Sub(endDateTime)
  8123. renewalReason.ExpirationTimeExceeded = int(sub.Hours() / 24)
  8124. err = company.AddRenewalReason(&renewalReason)
  8125. if err != nil {
  8126. br.Msg = "新增续约情况说明操作异常!"
  8127. br.ErrMsg = "新增续约情况说明操作异常,err:" + err.Error()
  8128. return
  8129. }
  8130. companyProduct.RenewalIntention = req.Renew
  8131. err = company.EditTryOutCompanyReason(companyProduct, req.Remark, req.RenewalTodo)
  8132. if err != nil {
  8133. br.Msg = "更新客户续约情况说明异常!"
  8134. br.ErrMsg = "更新客户续约情况说明异常,err:" + err.Error()
  8135. return
  8136. }
  8137. if req.Renew == 1 {
  8138. productName := ""
  8139. if req.ProductId == 1 {
  8140. productName = "ficc"
  8141. } else if req.ProductId == 2 {
  8142. productName = "权益"
  8143. } else {
  8144. productName = "佣金客户"
  8145. }
  8146. cp, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, req.ProductId)
  8147. if err != nil {
  8148. br.Msg = "查询该客户产品异常!"
  8149. br.ErrMsg = "查询该客户产品异常,err:" + err.Error()
  8150. return
  8151. }
  8152. if cp.Status != utils.COMPANY_STATUS_TRY_OUT {
  8153. br.Msg = "客户状态为:" + cp.Status + ";不可冻结"
  8154. br.ErrMsg = "客户状态为:" + cp.Status + ";不可冻结"
  8155. return
  8156. }
  8157. //查询客户的产品权限
  8158. companyReportPermissionList, err := company.GetCompanyReportPermission(req.CompanyId, req.ProductId)
  8159. if err != nil {
  8160. br.Msg = "查询客户的产品权限异常"
  8161. br.ErrMsg = "查询客户的产品权限异常:" + err.Error()
  8162. return
  8163. }
  8164. err = company.CompanyFreeze(req.CompanyId, req.ProductId, req.Remark)
  8165. if err != nil {
  8166. br.Msg = "冻结失败!"
  8167. br.ErrMsg = "冻结失败,Err:" + err.Error()
  8168. return
  8169. }
  8170. //新增操作记录
  8171. go func() {
  8172. time.Sleep(time.Second)
  8173. approveContent := req.Remark
  8174. remark := "冻结客户"
  8175. operation := "freeze"
  8176. _ = services.AddCompanyOperationRecord(req.CompanyId, cp.SellerId, sysUser.AdminId, req.ProductId, sysUser.AdminId, cp.CompanyName,
  8177. productName, "超级管理员", remark, operation, approveContent, sysUser.RealName, "", "冻结")
  8178. //新增产品权限冻结操作日志
  8179. for _, companyReportPermission := range companyReportPermissionList {
  8180. record := company_report_permission_log.CompanyReportPermissionLog{
  8181. CompanyReportPermissionId: companyReportPermission.CompanyReportPermissionId,
  8182. CompanyId: companyReportPermission.CompanyId,
  8183. ProductId: req.ProductId,
  8184. ProductName: companyReportPermission.ProductName,
  8185. SysUserId: sysUser.AdminId,
  8186. SysUserName: "超级管理员",
  8187. Remark: "冻结客户",
  8188. Operation: "freeze",
  8189. Status: companyReportPermission.Status,
  8190. CreateTime: time.Now(),
  8191. }
  8192. _, err = company_report_permission_log.AddCompanyReportPermissionLog(&record)
  8193. }
  8194. }()
  8195. }
  8196. {
  8197. approveContent := req.Remark
  8198. approveContentExtra := req.RenewalTodo
  8199. remark := "新增续约说明"
  8200. operation := "add_try_out_reason"
  8201. _ = services.AddCompanyOperationRecordMore(req.CompanyId, companyProduct.SellerId, sysUser.AdminId, companyProduct.ProductId, sysUser.AdminId, companyProduct.CompanyName,
  8202. companyProduct.ProductName, sysUser.RealName, remark, operation, approveContent, approveContentExtra, sysUser.RealName, "", companyProduct.Status)
  8203. record := new(company.CompanyOperationRecord)
  8204. record.Id = req.OperationId
  8205. record.ApproveContent = req.Remark
  8206. record.ApproveContentExtra = req.RenewalTodo
  8207. _, err = company.UpdateCompanyOperationRecord(record)
  8208. if err != nil {
  8209. br.Msg = "编辑失败"
  8210. br.ErrMsg = "编辑失败,Err:" + err.Error()
  8211. return
  8212. }
  8213. }
  8214. br.Ret = 200
  8215. br.Success = true
  8216. br.Msg = "编辑成功"
  8217. }
  8218. // AddRemark
  8219. // @Title 新增备注
  8220. // @Description 新增备注
  8221. // @Param request body company.RemarkReq true "type json string"
  8222. // @Success 200 编辑成功
  8223. // @router /remark/add [post]
  8224. func (this *CompanyController) AddRemark() {
  8225. br := new(models.BaseResponse).Init()
  8226. defer func() {
  8227. this.Data["json"] = br
  8228. this.ServeJSON()
  8229. }()
  8230. sysUser := this.SysUser
  8231. if sysUser == nil {
  8232. br.Msg = "请登录"
  8233. br.ErrMsg = "请登录,SysUser Is Empty"
  8234. br.Ret = 408
  8235. return
  8236. }
  8237. var req company.RemarkReq
  8238. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  8239. if err != nil {
  8240. br.Msg = "参数解析异常!"
  8241. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  8242. return
  8243. }
  8244. if req.CompanyId <= 0 {
  8245. br.Msg = "参数缺失"
  8246. br.ErrMsg = "参数缺失,客户编号未传!"
  8247. return
  8248. }
  8249. if req.Remark == "" {
  8250. br.Msg = "参数缺失"
  8251. br.ErrMsg = "参数缺失,备注说明未传!"
  8252. return
  8253. }
  8254. var productId int
  8255. //var productName string
  8256. 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 {
  8257. productId = 1
  8258. //productName = "ficc"
  8259. } 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 {
  8260. productId = 2
  8261. //productName = "权益"
  8262. } else {
  8263. br.Msg = "角色类型错误"
  8264. br.ErrMsg = "角色类型错误,该角色不能添加备注!"
  8265. return
  8266. }
  8267. companyProduct, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, productId)
  8268. if err != nil {
  8269. br.Msg = "查询客户异常"
  8270. br.ErrMsg = "查询客户异常,Err:" + err.Error()
  8271. }
  8272. if companyProduct.SellerId != sysUser.AdminId {
  8273. br.Msg = "客户异常,没有该客户的操作权限"
  8274. br.ErrMsg = "客户异常,没有该客户的操作权限"
  8275. return
  8276. }
  8277. remark := company.CompanyProductRemark{
  8278. CompanyId: companyProduct.CompanyId,
  8279. ProductId: companyProduct.ProductId,
  8280. ProductName: companyProduct.ProductName,
  8281. Remark: req.Remark,
  8282. CreateTime: time.Now(),
  8283. SysUserId: sysUser.AdminId,
  8284. SysRealName: sysUser.RealName,
  8285. }
  8286. err = company.AddCompanyRemark(&remark)
  8287. {
  8288. approveContent := req.Remark
  8289. remark := "新增备注"
  8290. operation := "add_remark"
  8291. services.AddCompanyOperationRecord(req.CompanyId, companyProduct.SellerId, sysUser.AdminId, companyProduct.ProductId, sysUser.AdminId, companyProduct.CompanyName,
  8292. companyProduct.ProductName, sysUser.RealName, remark, operation, approveContent, sysUser.RealName, "", companyProduct.Status)
  8293. }
  8294. if err != nil {
  8295. br.Msg = "编辑失败"
  8296. br.ErrMsg = "编辑失败,Err:" + err.Error()
  8297. }
  8298. br.Ret = 200
  8299. br.Success = true
  8300. br.Msg = "编辑成功"
  8301. }
  8302. // RemarkList 备注列表
  8303. // @Title 备注列表
  8304. // @Description 备注列表
  8305. // @Param CompanyId query string true "客户id"
  8306. // @Success 200 {object} company.RemarkResp
  8307. // @router /remark [get]
  8308. func (this *CompanyController) RemarkList() {
  8309. br := new(models.BaseResponse).Init()
  8310. defer func() {
  8311. this.Data["json"] = br
  8312. this.ServeJSON()
  8313. }()
  8314. sysUser := this.SysUser
  8315. if sysUser == nil {
  8316. br.Msg = "请登录"
  8317. br.ErrMsg = "请登录,SysUser Is Empty"
  8318. br.Ret = 408
  8319. return
  8320. }
  8321. companyId := this.GetString("CompanyId")
  8322. var remarkList []*company.CompanyProductRemark
  8323. var err error
  8324. groupFicc := []string{
  8325. utils.ROLE_TYPE_CODE_FICC_SELLER, utils.ROLE_TYPE_CODE_FICC_TEAM, utils.ROLE_TYPE_CODE_FICC_GROUP,
  8326. utils.ROLE_TYPE_CODE_FICC_DEPARTMENT, utils.ROLE_TYPE_CODE_FICC_ADMIN,
  8327. }
  8328. groupRai := []string{
  8329. utils.ROLE_TYPE_CODE_RAI_SELLER, utils.ROLE_TYPE_CODE_RAI_GROUP, utils.ROLE_TYPE_CODE_RAI_GROUP,
  8330. utils.ROLE_TYPE_CODE_RAI_DEPARTMENT, utils.ROLE_TYPE_CODE_RAI_ADMIN,
  8331. }
  8332. if utils.InArrayByStr(groupFicc, sysUser.RoleTypeCode) {
  8333. remarkList, err = company.GetRemarkList(companyId, "1")
  8334. if err != nil {
  8335. br.Msg = "获取失败"
  8336. br.ErrMsg = "获取失败,Err:" + err.Error()
  8337. return
  8338. }
  8339. }
  8340. if utils.InArrayByStr(groupRai, sysUser.RoleTypeCode) {
  8341. remarkList, err = company.GetRemarkList(companyId, "2")
  8342. if err != nil {
  8343. br.Msg = "获取失败"
  8344. br.ErrMsg = "获取失败,Err:" + err.Error()
  8345. return
  8346. }
  8347. }
  8348. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  8349. remarkList, err = company.GetRemarkListByCompanyId(companyId)
  8350. if err != nil {
  8351. br.Msg = "获取失败"
  8352. br.ErrMsg = "获取失败,Err:" + err.Error()
  8353. return
  8354. }
  8355. }
  8356. resp := make([]company.RemarkResp, len(remarkList))
  8357. for i, remark := range remarkList {
  8358. createDate := remark.CreateTime.Format(utils.FormatDateTime)
  8359. resp[i].RemarkId = remark.CompanyProductRemarkId
  8360. resp[i].Remark = remark.Remark
  8361. resp[i].ProductName = remark.ProductName
  8362. resp[i].CreateTime = createDate
  8363. // 仅自己添加的可删除
  8364. if remark.SysUserId == sysUser.AdminId {
  8365. resp[i].ButtonDel = true
  8366. }
  8367. }
  8368. br.Ret = 200
  8369. br.Success = true
  8370. br.Msg = "获取成功"
  8371. br.Data = resp
  8372. }
  8373. // RoadShowList 客户列表的路演详情列表
  8374. // @Title 路演详情列表
  8375. // @Description 路演详情列表
  8376. // @Param CompanyId query string true "客户id"
  8377. // @Success 200 {object} company.RoadShowListResp
  8378. // @router /roadShowList [get]
  8379. func (this *CompanyController) RoadShowList() {
  8380. br := new(models.BaseResponse).Init()
  8381. defer func() {
  8382. this.Data["json"] = br
  8383. this.ServeJSON()
  8384. }()
  8385. sysUser := this.SysUser
  8386. if sysUser == nil {
  8387. br.Msg = "请登录"
  8388. br.ErrMsg = "请登录,SysUser Is Empty"
  8389. br.Ret = 408
  8390. return
  8391. }
  8392. companyId := this.GetString("CompanyId")
  8393. companyIdInt, _ := strconv.Atoi(companyId)
  8394. if companyIdInt <= 0 {
  8395. br.Msg = "参数错误"
  8396. return
  8397. }
  8398. var englishCompany int
  8399. if companyIdInt > utils.EnCompanyIdStep {
  8400. companyIdInt = companyIdInt - utils.EnCompanyIdStep
  8401. englishCompany = 1
  8402. }
  8403. var err error
  8404. roadShowList, err := company.GetRoadShowList(companyIdInt, englishCompany)
  8405. if err != nil {
  8406. br.Msg = "获取失败"
  8407. br.ErrMsg = "获取失败,Err:" + err.Error()
  8408. return
  8409. }
  8410. //calendarIdSlice := make([]string, 0)
  8411. //for _, v := range roadShowList {
  8412. // calendarIdSlice = append(calendarIdSlice, strconv.Itoa(v.RsCalendarId))
  8413. //}
  8414. //calendarIdStr := strings.Join(calendarIdSlice, ",")
  8415. //researcherList, _ := company.GetRoadShowResearchers(calendarIdStr)
  8416. //roadShowTotalMap := make(map[int]int)
  8417. //for _, roadShowTotal := range researcherList {
  8418. // roadShowTotalMap[roadShowTotal.CompanyId] = roadShowTotal.Total
  8419. //}
  8420. resp := make([]company.RoadShowListResp, len(roadShowList))
  8421. for i, calendar := range roadShowList {
  8422. resp[i].SysUserRealName = calendar.SysUserRealName
  8423. resp[i].RoadshowType = calendar.RoadshowType
  8424. //线上为平台,线下为省市
  8425. if calendar.RoadshowType == "线上" {
  8426. resp[i].RoadshowPlatform = calendar.RoadshowPlatform
  8427. } else {
  8428. resp[i].RoadshowPlatform = calendar.Province + calendar.City
  8429. }
  8430. researchers, err := company.GetRoadShowResearchers(calendar.RsCalendarId)
  8431. if err != nil && err.Error() != utils.ErrNoRow() {
  8432. br.Msg = "获取研究员信息失败"
  8433. br.ErrMsg = "获取研究员信息失败,Err:" + err.Error()
  8434. return
  8435. }
  8436. var researcherList []string
  8437. for _, researcher := range researchers {
  8438. researcherList = append(researcherList, *researcher)
  8439. }
  8440. researcher := strings.Join(researcherList, ",")
  8441. resp[i].Researchers = researcher
  8442. resp[i].RoadShowTime = calendar.EndDate.Format("2006.01.02")
  8443. }
  8444. br.Ret = 200
  8445. br.Success = true
  8446. br.Msg = "获取成功"
  8447. br.Data = resp
  8448. }
  8449. // CustomerAreaStatistics
  8450. // @Title 客户区域统计
  8451. // @Description 获取客户区域统计接口
  8452. // @Param Date query string true "日期"
  8453. // @Param ProductId query Int true "产品Id"
  8454. // @Success 200 {object} statistic_report.CompanyRenewRecordResp
  8455. // @router /customerAreaStatistics [get]
  8456. func (this *CompanyController) CustomerAreaStatistics() {
  8457. br := new(models.BaseResponse).Init()
  8458. defer func() {
  8459. this.Data["json"] = br
  8460. this.ServeJSON()
  8461. }()
  8462. sysUser := this.SysUser
  8463. if sysUser == nil {
  8464. br.Msg = "请登录"
  8465. br.ErrMsg = "请登录,SysUser Is Empty"
  8466. br.Ret = 408
  8467. return
  8468. }
  8469. date := this.GetString("Date")
  8470. productId, _ := this.GetInt("ProductId", 1)
  8471. //获取列表
  8472. companyAreaDataMapList, _, err := statistic_report.GetAreaDateData(date, productId)
  8473. if err != nil {
  8474. br.Msg = "数据异常"
  8475. br.ErrMsg = "数据异常,Err:" + err.Error()
  8476. return
  8477. }
  8478. //获取省市数据
  8479. areaMap := make(map[string]string)
  8480. provinceMap := make(map[string][]string, 0)
  8481. list, err := statisticModels.GetAllCompanyArea()
  8482. for _, item := range list {
  8483. areaMap[item.City] = item.Province
  8484. }
  8485. for c, p := range areaMap {
  8486. citySlice := make([]string, 0)
  8487. citySlice = provinceMap[p]
  8488. citySlice = append(citySlice, c)
  8489. provinceMap[p] = citySlice
  8490. }
  8491. //数据处理
  8492. groupReportRecordList := make([]statistic_report.GroupCityRecord, 0)
  8493. resp := statistic_report.CustomerAreaStatisticsResp{
  8494. List: groupReportRecordList,
  8495. IsAdmin: false,
  8496. }
  8497. //除ficc管理员和超管之外的角色进入此页面时,正式客户数量>0时可点击,点击查看正式客户列表详情;
  8498. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  8499. resp.IsAdmin = true
  8500. }
  8501. startDateIndexList := make(map[int]string) //开始时间间隔map
  8502. endDateIndexList := make(map[int]string) //结束时间间隔map
  8503. tmpAllTryOutNumMap := make(map[int]int)
  8504. tmpAllFormalNumMap := make(map[int]int)
  8505. tmpAllActiveNumMap := make(map[int]int)
  8506. tmpAllAllActiveNumMap := make(map[int]int)
  8507. tmpAllNoIncrementalActiveNumMap := make(map[int]int)
  8508. tmpAllTryStagePushMap := make(map[int]int)
  8509. tmpAllTryStageFollowMap := make(map[int]int)
  8510. tmpAllTryStageReadyMap := make(map[int]int)
  8511. tmpAllTryStageInitMap := make(map[int]int)
  8512. for province, cityList := range provinceMap {
  8513. tmpGroupCityReportRecord := make([]statistic_report.CityRecord, 0)
  8514. tmpGroupCompanyReportRecordNumList := make([]statistic_report.CompanyAreaNum, 0)
  8515. tmpGroupTryOutNumMap := make(map[int]int)
  8516. tmpGroupFormalNumMap := make(map[int]int)
  8517. tmpGroupFormalCompanyIdsMap := make(map[int]string) //正式客户id
  8518. tmpGroupActiveNumMap := make(map[int]int)
  8519. tmpGroupAllActiveNumMap := make(map[int]int)
  8520. tmpGroupNoIncrementalActiveNumMap := make(map[int]int)
  8521. // 其他类型客户ID
  8522. tmpGroupTryOutCompanyIdsMap := make(map[int]string) //试用客户ID
  8523. tmpGroupPushCompanyIdsMap := make(map[int]string) //试用(推进)客户ID
  8524. tmpGroupFollowCompanyIdsMap := make(map[int]string) //试用(跟踪)客户ID
  8525. tmpGroupReadyCompanyIdsMap := make(map[int]string) //试用(预备)客户ID
  8526. tmpGroupInitCompanyIdsMap := make(map[int]string) //试用(未分类)客户ID
  8527. tmpGroupTryStagePushMap := make(map[int]int)
  8528. tmpGroupTryStageFollowMap := make(map[int]int)
  8529. tmpGroupTryStageReadyMap := make(map[int]int)
  8530. tmpGroupTryStageInitMap := make(map[int]int)
  8531. for _, city := range cityList {
  8532. //城市数据
  8533. //每个城市的数据
  8534. tmpCompanyReportRecordNumList := make([]statistic_report.CompanyAreaNum, 0)
  8535. for index, adminData := range companyAreaDataMapList {
  8536. startDateIndexList[index] = adminData.StartDate
  8537. endDateIndexList[index] = adminData.EndDate
  8538. var tmpTryOutNum, tmpFormalNum, tmpActiveStatus, tmpAllActiveStatus, tmpNoIncrementalActiveStatus int
  8539. var tmpTryStagePushNum, tmpTryStageFollowNum, tmpTryStageReadyNum, tmpTryStageInitNum int
  8540. var tmpFormalCompanyIds string //正式客户id集合
  8541. var tmpTryOutCompanyIds string //试用客户ID集合
  8542. var tmpPushCompanyIds string //试用(推进)客户ID集合
  8543. var tmpFollowCompanyIds string //试用(跟踪)客户ID集合
  8544. var tmpReadyCompanyIds string //试用(预备)客户ID集合
  8545. var tmpInitCompanyIds string //试用(未分类)客户ID集合
  8546. if num, ok := adminData.TryOutMap[city]; ok {
  8547. tmpTryOutNum = num
  8548. }
  8549. if num, ok := adminData.FormalMap[city]; ok {
  8550. tmpFormalNum = num
  8551. }
  8552. if companyIds, ok := adminData.FormalIdMap[city]; ok {
  8553. tmpFormalCompanyIds = companyIds
  8554. }
  8555. if companyIds, ok := adminData.TryOutIdMap[city]; ok {
  8556. tmpTryOutCompanyIds = companyIds
  8557. }
  8558. if companyIds, ok := adminData.TryStagePushIdsMap[city]; ok {
  8559. tmpPushCompanyIds = companyIds
  8560. }
  8561. if companyIds, ok := adminData.TryStageFollowIdsMap[city]; ok {
  8562. tmpFollowCompanyIds = companyIds
  8563. }
  8564. if companyIds, ok := adminData.TryStageReadyIdsMap[city]; ok {
  8565. tmpReadyCompanyIds = companyIds
  8566. }
  8567. if companyIds, ok := adminData.TryStageInitIdsMap[city]; ok {
  8568. tmpInitCompanyIds = companyIds
  8569. }
  8570. if num, ok := adminData.ActiveMap[city]; ok {
  8571. tmpActiveStatus = num
  8572. }
  8573. if num, ok := adminData.AllActiveMap[city]; ok {
  8574. tmpAllActiveStatus = num
  8575. }
  8576. if num, ok := adminData.NoIncrementalActiveMap[city]; ok {
  8577. tmpNoIncrementalActiveStatus = num
  8578. }
  8579. // 每个用户的试用标签统计 推进-跟踪-预备-未分类
  8580. if num, ok := adminData.TryStagePushNum[city]; ok {
  8581. tmpTryStagePushNum = num
  8582. }
  8583. if num, ok := adminData.TryStageFollowNum[city]; ok {
  8584. tmpTryStageFollowNum = num
  8585. }
  8586. if num, ok := adminData.TryStageReadyNum[city]; ok {
  8587. tmpTryStageReadyNum = num
  8588. }
  8589. if num, ok := adminData.TryStageInitNum[city]; ok {
  8590. tmpTryStageInitNum = num
  8591. }
  8592. tmpAdminRsReportRecordNum := statistic_report.CompanyAreaNum{
  8593. TryOutNum: tmpTryOutNum,
  8594. FormalNum: tmpFormalNum,
  8595. FormalIds: tmpFormalCompanyIds,
  8596. ActiveNum: tmpActiveStatus,
  8597. AllActiveNum: tmpAllActiveStatus,
  8598. NoIncrementalActiveNum: tmpNoIncrementalActiveStatus,
  8599. StartDate: adminData.StartDate,
  8600. EndDate: adminData.EndDate,
  8601. TryStagePushNum: tmpTryStagePushNum,
  8602. TryStageFollowNum: tmpTryStageFollowNum,
  8603. TryStageReadyNum: tmpTryStageReadyNum,
  8604. TryStageInitNum: tmpTryStageInitNum,
  8605. TotalNum: tmpTryOutNum + tmpFormalNum,
  8606. }
  8607. tmpCompanyReportRecordNumList = append(tmpCompanyReportRecordNumList, tmpAdminRsReportRecordNum)
  8608. //组内数据汇总
  8609. tmpGroupTryOutNumMap[index] += tmpTryOutNum
  8610. tmpGroupFormalNumMap[index] += tmpFormalNum
  8611. // 正式客户id
  8612. if tmpFormalCompanyIds != `` {
  8613. tmpGroupFormalCompanyIds, ok := tmpGroupFormalCompanyIdsMap[index]
  8614. if ok {
  8615. tmpGroupFormalCompanyIdsMap[index] = tmpGroupFormalCompanyIds + "," + tmpFormalCompanyIds
  8616. } else {
  8617. tmpGroupFormalCompanyIdsMap[index] = tmpFormalCompanyIds
  8618. }
  8619. }
  8620. tmpGroupActiveNumMap[index] += tmpActiveStatus
  8621. tmpGroupAllActiveNumMap[index] += tmpActiveStatus
  8622. tmpGroupNoIncrementalActiveNumMap[index] += tmpActiveStatus
  8623. tmpGroupTryStagePushMap[index] += tmpTryStagePushNum
  8624. tmpGroupTryStageFollowMap[index] += tmpTryStageFollowNum
  8625. tmpGroupTryStageReadyMap[index] += tmpTryStageReadyNum
  8626. tmpGroupTryStageInitMap[index] += tmpTryStageInitNum
  8627. // 其他客户IDs
  8628. if tmpTryOutCompanyIds != `` {
  8629. a, ok := tmpGroupTryOutCompanyIdsMap[index]
  8630. if ok {
  8631. tmpGroupTryOutCompanyIdsMap[index] = a + "," + tmpTryOutCompanyIds
  8632. } else {
  8633. tmpGroupTryOutCompanyIdsMap[index] = tmpTryOutCompanyIds
  8634. }
  8635. }
  8636. if tmpPushCompanyIds != `` {
  8637. a, ok := tmpGroupPushCompanyIdsMap[index]
  8638. if ok {
  8639. tmpGroupPushCompanyIdsMap[index] = a + "," + tmpPushCompanyIds
  8640. } else {
  8641. tmpGroupPushCompanyIdsMap[index] = tmpPushCompanyIds
  8642. }
  8643. }
  8644. if tmpFollowCompanyIds != `` {
  8645. a, ok := tmpGroupFollowCompanyIdsMap[index]
  8646. if ok {
  8647. tmpGroupFollowCompanyIdsMap[index] = a + "," + tmpFollowCompanyIds
  8648. } else {
  8649. tmpGroupFollowCompanyIdsMap[index] = tmpFollowCompanyIds
  8650. }
  8651. }
  8652. if tmpReadyCompanyIds != `` {
  8653. a, ok := tmpGroupReadyCompanyIdsMap[index]
  8654. if ok {
  8655. tmpGroupReadyCompanyIdsMap[index] = a + "," + tmpReadyCompanyIds
  8656. } else {
  8657. tmpGroupReadyCompanyIdsMap[index] = tmpReadyCompanyIds
  8658. }
  8659. }
  8660. if tmpInitCompanyIds != `` {
  8661. a, ok := tmpGroupInitCompanyIdsMap[index]
  8662. if ok {
  8663. tmpGroupInitCompanyIdsMap[index] = a + "," + tmpInitCompanyIds
  8664. } else {
  8665. tmpGroupInitCompanyIdsMap[index] = tmpInitCompanyIds
  8666. }
  8667. }
  8668. //总数据汇总
  8669. tmpAllTryOutNumMap[index] += tmpTryOutNum
  8670. tmpAllFormalNumMap[index] += tmpFormalNum
  8671. tmpAllActiveNumMap[index] += tmpActiveStatus
  8672. tmpAllAllActiveNumMap[index] += tmpAllActiveStatus
  8673. tmpAllNoIncrementalActiveNumMap[index] += tmpNoIncrementalActiveStatus
  8674. // 总数据试用标签数据汇总
  8675. tmpAllTryStagePushMap[index] += tmpTryStagePushNum
  8676. tmpAllTryStageFollowMap[index] += tmpTryStageFollowNum
  8677. tmpAllTryStageReadyMap[index] += tmpTryStageReadyNum
  8678. tmpAllTryStageInitMap[index] += tmpTryStageInitNum
  8679. }
  8680. tmpAdminReportRecord := statistic_report.CityRecord{
  8681. Name: city,
  8682. CompanyAreaNumNumList: tmpCompanyReportRecordNumList,
  8683. }
  8684. tmpGroupCityReportRecord = append(tmpGroupCityReportRecord, tmpAdminReportRecord)
  8685. }
  8686. for i := 0; i < len(tmpGroupActiveNumMap); i++ {
  8687. tmpGroupCompanyReportRecordNum := statistic_report.CompanyAreaNum{
  8688. TryOutNum: tmpGroupTryOutNumMap[i],
  8689. FormalNum: tmpGroupFormalNumMap[i],
  8690. FormalIds: tmpGroupFormalCompanyIdsMap[i],
  8691. ActiveNum: tmpGroupActiveNumMap[i],
  8692. AllActiveNum: tmpGroupAllActiveNumMap[i],
  8693. NoIncrementalActiveNum: tmpGroupNoIncrementalActiveNumMap[i],
  8694. StartDate: startDateIndexList[i],
  8695. EndDate: endDateIndexList[i],
  8696. TryStagePushNum: tmpGroupTryStagePushMap[i],
  8697. TryStageFollowNum: tmpGroupTryStageFollowMap[i],
  8698. TryStageReadyNum: tmpGroupTryStageReadyMap[i],
  8699. TryStageInitNum: tmpGroupTryStageInitMap[i],
  8700. TotalNum: tmpGroupTryOutNumMap[i] + tmpGroupFormalNumMap[i],
  8701. TryOutIds: tmpGroupTryOutCompanyIdsMap[i],
  8702. TryStagePushIds: tmpGroupPushCompanyIdsMap[i],
  8703. TryStageFollowIds: tmpGroupFollowCompanyIdsMap[i],
  8704. TryStageReadyIds: tmpGroupReadyCompanyIdsMap[i],
  8705. TryStageInitIds: tmpGroupInitCompanyIdsMap[i],
  8706. }
  8707. tmpGroupCompanyReportRecordNumList = append(tmpGroupCompanyReportRecordNumList, tmpGroupCompanyReportRecordNum)
  8708. }
  8709. groupReportRecord := statistic_report.GroupCityRecord{
  8710. Item: tmpGroupCityReportRecord,
  8711. Name: province,
  8712. CompanyAreaNumNumList: tmpGroupCompanyReportRecordNumList,
  8713. }
  8714. groupReportRecordList = append(groupReportRecordList, groupReportRecord)
  8715. }
  8716. resp.List = groupReportRecordList
  8717. br.Ret = 200
  8718. br.Success = true
  8719. br.Msg = "获取成功"
  8720. br.Data = resp
  8721. }
  8722. // CompanyTryOutDayList
  8723. // @Title 客户累计试用详情接口
  8724. // @Description 客户累计试用详情接口
  8725. // @Param CompanyId query int true "客户id"
  8726. // @Param ProductId query int true "产品id"
  8727. // @Success 200 {object} company.CompanyTryOutDayListResp
  8728. // @router /company/tryOutDayList [get]
  8729. func (this *CompanyTodoController) CompanyTryOutDayList() {
  8730. br := new(models.BaseResponse).Init()
  8731. defer func() {
  8732. this.Data["json"] = br
  8733. this.ServeJSON()
  8734. }()
  8735. companyId, _ := this.GetInt("CompanyId")
  8736. if companyId <= 0 {
  8737. br.Msg = "请选择客户"
  8738. return
  8739. }
  8740. productId, _ := this.GetInt("ProductId")
  8741. if productId <= 0 {
  8742. br.Msg = "请选择类型"
  8743. return
  8744. }
  8745. pageSize, _ := this.GetInt("PageSize")
  8746. currentIndex, _ := this.GetInt("CurrentIndex")
  8747. var startSize int
  8748. if pageSize <= 0 {
  8749. pageSize = utils.PageSize20
  8750. }
  8751. if currentIndex <= 0 {
  8752. currentIndex = 1
  8753. }
  8754. startSize = paging.StartIndex(currentIndex, pageSize)
  8755. // 获取任务信息
  8756. total, err := company.GetCompanyProductTryOutUpdateLogTotal(companyId, productId)
  8757. if err != nil {
  8758. br.Msg = "获取任务信息失败"
  8759. br.ErrMsg = "获取任务信息失败,err:" + err.Error()
  8760. return
  8761. }
  8762. // 获取任务信息
  8763. list, err := company.GetCompanyProductTryOutUpdateLogList(companyId, productId, startSize, pageSize)
  8764. if err != nil {
  8765. br.Msg = "获取任务信息失败"
  8766. br.ErrMsg = "获取任务信息失败,err:" + err.Error()
  8767. return
  8768. }
  8769. //var list []*company_todo.CompanyTodoListItem
  8770. //for _, v := range todos {
  8771. // temp := &company_todo.CompanyTodoListItem{
  8772. // CompanyTodo: v,
  8773. // }
  8774. // temp.EndTimeStr = temp.EndTime.Format(utils.FormatDate)
  8775. // if temp.EndTimeStr == "0001-01-01" {
  8776. // temp.EndTimeStr = ""
  8777. // }
  8778. // list = append(list, temp)
  8779. //}
  8780. if len(list) <= 0 {
  8781. list = make([]*company.CompanyProductTryOutUpdateLog, 0)
  8782. }
  8783. page := paging.GetPaging(currentIndex, pageSize, total)
  8784. resp := company.CompanyTryOutDayListResp{
  8785. Paging: page,
  8786. List: list,
  8787. }
  8788. br.Ret = 200
  8789. br.Success = true
  8790. br.Msg = "获取成功"
  8791. br.Data = resp
  8792. }
  8793. // @Title 获取流水信息接口
  8794. // @Description 获取流水信息接口
  8795. // @Param CompanyId query int true "客户id"
  8796. // @Success 200 {object} company.CygxActivityPointsBillListResp
  8797. // @router /company/activity/points/bill [get]
  8798. func (this *CompanyTodoController) CompanyActivityPointsBill() {
  8799. br := new(models.BaseResponse).Init()
  8800. defer func() {
  8801. this.Data["json"] = br
  8802. this.ServeJSON()
  8803. }()
  8804. companyId, _ := this.GetInt("CompanyId")
  8805. if companyId <= 0 {
  8806. br.Msg = "请选择客户"
  8807. return
  8808. }
  8809. // 获取流水信息
  8810. list, err := cygx.CygxActivityPointsBillByCompanyId(companyId)
  8811. if err != nil {
  8812. br.Msg = "获取任务信息失败"
  8813. br.ErrMsg = "获取任务信息失败,err:" + err.Error()
  8814. return
  8815. }
  8816. if len(list) <= 0 {
  8817. list = make([]*cygx.CygxActivityPointsBillResp, 0)
  8818. }
  8819. resp := cygx.CygxActivityPointsBillListResp{
  8820. List: list,
  8821. }
  8822. br.Ret = 200
  8823. br.Success = true
  8824. br.Msg = "获取成功"
  8825. br.Data = resp
  8826. }
  8827. // DelRemark
  8828. // @Title 删除备注
  8829. // @Description 删除备注
  8830. // @Param request body company.RemarkDelReq true "type json string"
  8831. // @Success 200 操作成功
  8832. // @router /remark/del [post]
  8833. func (this *CompanyController) DelRemark() {
  8834. br := new(models.BaseResponse).Init()
  8835. defer func() {
  8836. if br.ErrMsg == "" {
  8837. br.IsSendEmail = false
  8838. }
  8839. this.Data["json"] = br
  8840. this.ServeJSON()
  8841. }()
  8842. sysUser := this.SysUser
  8843. if sysUser == nil {
  8844. br.Msg = "请登录"
  8845. br.ErrMsg = "请登录,SysUser Is Empty"
  8846. br.Ret = 408
  8847. return
  8848. }
  8849. var req company.RemarkDelReq
  8850. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  8851. if err != nil {
  8852. br.Msg = "参数解析异常!"
  8853. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  8854. return
  8855. }
  8856. if req.RemarkId <= 0 {
  8857. br.Msg = "参数有误"
  8858. br.ErrMsg = "参数有误, 备注ID有误"
  8859. return
  8860. }
  8861. item, e := company.GetCompanyRemarkById(req.RemarkId)
  8862. if e != nil {
  8863. if e.Error() == utils.ErrNoRow() {
  8864. br.Msg = "备注已被删除, 请刷新页面"
  8865. return
  8866. }
  8867. br.Msg = "备注信息有误"
  8868. br.ErrMsg = "获取客户备注失败, Err: " + e.Error()
  8869. return
  8870. }
  8871. if item.SysUserId != sysUser.AdminId {
  8872. br.Msg = "仅备注添加人可删除"
  8873. return
  8874. }
  8875. product, e := company.GetCompanyProductByCompanyIdAndProductId(item.CompanyId, item.ProductId)
  8876. if e != nil {
  8877. br.Msg = "操作失败"
  8878. br.ErrMsg = "获取客户产品信息失败, Err: " + e.Error()
  8879. return
  8880. }
  8881. if e := company.DelCompanyRemark(req.RemarkId); e != nil {
  8882. br.Msg = "操作失败"
  8883. br.ErrMsg = "删除客户备注失败, Err: " + e.Error()
  8884. return
  8885. }
  8886. content := fmt.Sprintf("%s%s", "删除备注: ", item.Remark)
  8887. _ = 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)
  8888. br.Ret = 200
  8889. br.Success = true
  8890. br.Msg = "操作成功"
  8891. }
  8892. // @Title 获取流水信息接口
  8893. // @Description 获取流水信息接口
  8894. // @Param CompanyId query int true "客户id"
  8895. // @Success 200 {object} company.CygxActivityPointsBillListResp
  8896. // @router /company/activity/special/points/bill [get]
  8897. func (this *CompanyTodoController) CompanyActivitySpecialPointsBill() {
  8898. br := new(models.BaseResponse).Init()
  8899. defer func() {
  8900. this.Data["json"] = br
  8901. this.ServeJSON()
  8902. }()
  8903. companyId, _ := this.GetInt("CompanyId")
  8904. if companyId <= 0 {
  8905. br.Msg = "请选择客户"
  8906. return
  8907. }
  8908. // 获取流水信息
  8909. var condition string
  8910. var pars []interface{}
  8911. condition += ` AND company_id = ? `
  8912. pars = append(pars, companyId)
  8913. //查询当年的数据
  8914. //condition += ` AND b.create_time >= ? `
  8915. //pars = append(pars, time.Now().Format(utils.FormatYearDate)+"-01-01")
  8916. list, err := cygx.GetCygxActivitySpecialTripBillDetailListAll(condition, pars)
  8917. if err != nil {
  8918. br.Msg = "获取任务信息失败"
  8919. br.ErrMsg = "获取任务信息失败,err:" + err.Error()
  8920. return
  8921. }
  8922. //userType, tripRemaining, mapChartName, err := cygxService.GetChartPermissionSpecialSurplusByCompany(companyId)
  8923. //if err != nil {
  8924. // br.Msg = "获取专项调研剩余次数失败"
  8925. // br.ErrMsg = "获取专项调研剩余次数失败,err:" + err.Error()
  8926. // return
  8927. //}
  8928. //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}
  8929. resp := new(cygx.CygxActivitySpecialPointsBillResp)
  8930. //lastTripRemaining := 0
  8931. for _, v := range list {
  8932. item := cygx.CygxActivitySpecialPointsBillRespItem{
  8933. Id: v.Id,
  8934. CreateTime: v.CreateTime.Format(utils.FormatDateTime),
  8935. CompanyId: v.CompanyId,
  8936. CompanyName: v.CompanyName,
  8937. RealName: v.RealName,
  8938. BillDetailed: v.BillDetailed,
  8939. ActivityName: v.ResearchTheme,
  8940. ChartPermissionId: v.ChartPermissionId,
  8941. ChartPermissionName: v.ChartPermissionName,
  8942. Total: v.Total,
  8943. }
  8944. if v.ActivityId == 0 {
  8945. item.Content = v.Content
  8946. } else {
  8947. if v.DoType == 1 && v.Way != 4 && v.Way != 3 {
  8948. item.Content = item.ActivityName + "--报名"
  8949. } else if v.DoType == 2 && v.Way != 4 && v.Way != 3 {
  8950. item.Content = item.ActivityName + "--取消报名"
  8951. } else if v.Way == 4 {
  8952. item.Content = item.ActivityName + "--活动取消"
  8953. }
  8954. }
  8955. //if userType == 2 {
  8956. // if i== 0 {
  8957. // item.Total += strconv.Itoa(tripRemaining) + "次"
  8958. // } else {
  8959. // item.Total += strconv.Itoa(tripRemaining-list[i-1].BillDetailed) + "次"
  8960. // }
  8961. // //if v.BillDetailed < 4 {
  8962. // // item.Total += strconv.Itoa(lastTripRemaining-list[i-1].BillDetailed) + "次"
  8963. // //} else {
  8964. // // item.Total += strconv.Itoa(lastTripRemaining) + "次"
  8965. // //}
  8966. //} else {
  8967. // for k, num := range mapChartName {
  8968. // if i== 0 {
  8969. // item.Total += k + strconv.Itoa(num) + "次+"
  8970. // } else {
  8971. // if list[i-1].ActivityId == 0 {
  8972. // item.Total += k + strconv.Itoa(num) + "次+"
  8973. // } else {
  8974. // item.Total += k + strconv.Itoa(num-list[i-1].BillDetailed) + "次+"
  8975. // }
  8976. // }
  8977. // //if num > 0 {
  8978. // // if i== 0{
  8979. // // item.Total += k + strconv.Itoa(num) + "次+"
  8980. // // } else {
  8981. // // item.Total += k + strconv.Itoa(num-v.BillDetailed) + "次+"
  8982. // // }
  8983. // //}
  8984. // }
  8985. // item.Total = strings.TrimRight(item.Total, "+")
  8986. //}
  8987. resp.List = append(resp.List, &item)
  8988. }
  8989. br.Ret = 200
  8990. br.Success = true
  8991. br.Msg = "获取成功"
  8992. br.Data = resp
  8993. }