company.go 308 KB

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