company.go 306 KB

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