user.go 177 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333
  1. package cygx
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "github.com/rdlucklib/rdluck_tools/paging"
  6. "github.com/tealeg/xlsx"
  7. "hongze/hz_crm_api/controllers"
  8. "hongze/hz_crm_api/models"
  9. "hongze/hz_crm_api/models/company"
  10. "hongze/hz_crm_api/models/cygx"
  11. "hongze/hz_crm_api/services"
  12. cygxService "hongze/hz_crm_api/services/cygx"
  13. "hongze/hz_crm_api/utils"
  14. "os"
  15. "path/filepath"
  16. "sort"
  17. "strconv"
  18. "strings"
  19. "time"
  20. )
  21. // 权益用户管理
  22. type UserController struct {
  23. controllers.BaseAuthController
  24. }
  25. // List
  26. // @Title 用户列表
  27. // @Description 用户列表接口
  28. // @Param PageSize query int true "每页数据条数"
  29. // @Param CurrentIndex query int true "当前页页码,从1开始"
  30. // @Param Status query string true "状态:”试用','永续','冻结','流失','正式'"
  31. // @Param IsMaker query int false "是否决策人,1:是,0:否 ,2:全部'"
  32. // @Param IsRegister query int false "是否决策人,1:是,0:否 ,2:全部'"
  33. // @Param AdminId query string true "销售id,多个用英文逗号隔开,空字符串为全部"
  34. // @Param KeyWord query string true "搜索关键词"
  35. // @Param Label query string true "搜索用户标签"
  36. // @Param TryStage query int false "试用客户子标签:0全部、1未分类、2 推进、3 跟踪、4 预备。正式:套餐类型,0:无,1:大套餐,2:小套餐"
  37. // @Param SortType query string true "如何排序,是正序还是倒序,枚举值:`asc 正序`,`desc 倒叙`"
  38. // @Param IsSubscribeCygx query int true "是否关注了查研观向小助手公众号: -1-默认全部; 0-未关注; 1-已关注"
  39. // @Success 200 {object} cygx.CompanyUserListResp
  40. // @router /user/list [get]
  41. func (this *UserController) List() {
  42. br := new(models.BaseResponse).Init()
  43. defer func() {
  44. this.Data["json"] = br
  45. this.ServeJSON()
  46. }()
  47. sysUser := this.SysUser
  48. if sysUser == nil {
  49. br.Msg = "请登录"
  50. br.ErrMsg = "请登录,SysUser Is Empty"
  51. br.Ret = 408
  52. return
  53. }
  54. roleTypeCode := sysUser.RoleTypeCode
  55. pageSize, _ := this.GetInt("PageSize")
  56. currentIndex, _ := this.GetInt("CurrentIndex")
  57. isMaker, _ := this.GetInt("IsMaker")
  58. isRegister, _ := this.GetInt("IsRegister")
  59. status := this.GetString("Status")
  60. adminId := this.GetString("AdminId")
  61. keyWord := this.GetString("KeyWord")
  62. label := this.GetString("Label")
  63. tryStage, _ := this.GetInt("TryStage") //试用客户标签
  64. sortType := this.GetString("SortType") //试用客户标签
  65. // 套餐类型
  66. //packageType, _ := this.GetInt("PackageType")
  67. keyWord = strings.Trim(keyWord, " ")
  68. keyWord = strings.Replace(keyWord, "'", "", -1)
  69. isSubscribeCygx, _ := this.GetInt("IsSubscribeCygx", -1)
  70. if status == "X类试用" {
  71. status = "永续"
  72. }
  73. var total int
  74. page := paging.GetPaging(currentIndex, pageSize, total)
  75. //statusItems := make([]*company.CompanyStatus, 0)
  76. //var statusArr = [...]string{"全部", "试用", "正式", "冻结", "流失", "永续"}
  77. var startSize int
  78. if pageSize <= 0 {
  79. pageSize = utils.PageSize20
  80. }
  81. if currentIndex <= 0 {
  82. currentIndex = 1
  83. }
  84. startSize = paging.StartIndex(currentIndex, pageSize)
  85. var condition string
  86. var sqlOrder string
  87. var usercondition string
  88. var kwywordcondition string
  89. var pars []interface{}
  90. var parsUser []interface{}
  91. //流失
  92. var lossCondition string
  93. //var lossPars []interface{}
  94. //状态分类查询条件
  95. var permissionCondition string
  96. if adminId != "" {
  97. condition += ` AND b.seller_id IN (` + adminId + `) `
  98. }
  99. lossCondition = condition
  100. //lossPars = pars
  101. permissionCondition = condition
  102. //流失客户统计
  103. lossCondition += ` AND status='流失' `
  104. //productId := services.GetProductId(roleTypeCode)
  105. productId := 2
  106. //权限控制
  107. {
  108. //如果不是超级管理员或者财务
  109. if roleTypeCode != utils.ROLE_TYPE_CODE_ADMIN && roleTypeCode != utils.ROLE_TYPE_CODE_FINANCE {
  110. //如果是部门管理员
  111. if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  112. condition += ` AND b.product_id= '` + strconv.Itoa(productId) + `'`
  113. lossCondition += ` AND b.product_id= '` + strconv.Itoa(productId) + `'`
  114. permissionCondition += ` AND b.product_id= '` + strconv.Itoa(productId) + `'`
  115. } else {
  116. condition += ` AND b.product_id= '` + strconv.Itoa(productId) + `'`
  117. lossCondition += ` AND b.product_id= '` + strconv.Itoa(productId) + `'`
  118. permissionCondition += ` AND b.product_id= '` + strconv.Itoa(productId) + `'`
  119. if status == "全部" {
  120. ////如果是筛选了流失客户状态
  121. if sysUser.Authority <= 0 {
  122. condition += ` AND (b.seller_id= '` + strconv.Itoa(sysUser.AdminId) + `' OR status='流失') `
  123. permissionCondition += ` AND b.seller_id= ` + strconv.Itoa(sysUser.AdminId)
  124. } else {
  125. if sysUser.Authority == 1 {
  126. condition += ` AND (b.department_id=` + strconv.Itoa(sysUser.DepartmentId) + ` OR status='流失')`
  127. permissionCondition += ` AND b.department_id=` + strconv.Itoa(sysUser.DepartmentId)
  128. }
  129. if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  130. if status != utils.COMPANY_STATUS_LOSE {
  131. condition += ` AND (b.group_id=` + strconv.Itoa(sysUser.GroupId) + ` OR status='流失') `
  132. }
  133. permissionCondition += ` AND b.group_id=` + strconv.Itoa(sysUser.GroupId)
  134. }
  135. if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
  136. pid, err := company.GetParentIdFromGroup(sysUser.GroupId)
  137. if err != nil {
  138. br.Msg = "获取失败"
  139. br.ErrMsg = "查询父级id异常" + err.Error()
  140. return
  141. }
  142. var ids []*string
  143. if pid != nil {
  144. if *pid != 0 {
  145. //销售主管放在三级列表中
  146. ids, err = company.GetGroupIdsByParentId(*pid)
  147. if err != nil {
  148. fmt.Println(err.Error())
  149. }
  150. } else {
  151. //销售主管放在二级列表中
  152. ids, err = company.GetGroupIdsByParentId(sysUser.GroupId)
  153. if err != nil {
  154. fmt.Println(err.Error())
  155. }
  156. }
  157. }
  158. var idSlice []string
  159. var sid string
  160. for _, id := range ids {
  161. idSlice = append(idSlice, *id)
  162. }
  163. //加入父级groupId
  164. if *pid > 0 {
  165. idSlice = append(idSlice, strconv.Itoa(*pid))
  166. } else {
  167. idSlice = append(idSlice, strconv.Itoa(sysUser.GroupId))
  168. }
  169. sid = strings.Join(idSlice, ",")
  170. if len(sid) > 0 {
  171. if status != utils.COMPANY_STATUS_LOSE {
  172. condition += ` AND (b.group_id IN (` + sid + `) OR status='流失') `
  173. }
  174. permissionCondition += ` AND b.group_id IN (` + sid + `) `
  175. } else {
  176. if status != utils.COMPANY_STATUS_LOSE {
  177. condition += ` AND (b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) OR status='流失') `
  178. }
  179. permissionCondition += ` AND b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) `
  180. }
  181. }
  182. if sysUser.Authority == 4 {
  183. if status != utils.COMPANY_STATUS_LOSE {
  184. condition += ` AND (b.group_id =` + strconv.Itoa(sysUser.GroupId) + ` OR status='流失') `
  185. //pars = append(pars, sysUser.GroupId)
  186. }
  187. permissionCondition += ` AND b.group_id=` + strconv.Itoa(sysUser.GroupId)
  188. //permissionPars = append(permissionPars, sysUser.GroupId)
  189. }
  190. }
  191. } else {
  192. //如果没有筛选了流失客户状态,那么需要加客户归属条件加入到查询中去
  193. if sysUser.Authority <= 0 {
  194. if status != utils.COMPANY_STATUS_LOSE {
  195. condition += ` AND b.seller_id=` + strconv.Itoa(sysUser.AdminId)
  196. //pars = append(pars, sysUser.AdminId)
  197. }
  198. permissionCondition += ` AND b.seller_id=` + strconv.Itoa(sysUser.AdminId)
  199. //permissionPars = append(permissionPars, sysUser.AdminId)
  200. } else {
  201. if sysUser.Authority == 1 {
  202. if status != utils.COMPANY_STATUS_LOSE {
  203. condition += ` AND b.department_id=` + strconv.Itoa(sysUser.DepartmentId)
  204. //pars = append(pars, sysUser.DepartmentId)
  205. }
  206. permissionCondition += ` AND b.department_id=` + strconv.Itoa(sysUser.DepartmentId)
  207. //permissionPars = append(permissionPars, sysUser.DepartmentId)
  208. }
  209. if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  210. if status != utils.COMPANY_STATUS_LOSE {
  211. condition += ` AND b.group_id= ` + strconv.Itoa(sysUser.GroupId)
  212. //pars = append(pars, sysUser.GroupId)
  213. }
  214. permissionCondition += ` AND b.group_id=` + strconv.Itoa(sysUser.GroupId)
  215. //permissionPars = append(permissionPars, sysUser.GroupId)
  216. }
  217. if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
  218. pid, err := company.GetParentIdFromGroup(sysUser.GroupId)
  219. if err != nil {
  220. br.Msg = "获取失败"
  221. br.ErrMsg = "查询父级id异常" + err.Error()
  222. return
  223. }
  224. var ids []*string
  225. if pid != nil {
  226. if *pid != 0 {
  227. //销售主管放在三级列表中
  228. ids, err = company.GetGroupIdsByParentId(*pid)
  229. if err != nil {
  230. fmt.Println(err.Error())
  231. }
  232. } else {
  233. //销售主管放在二级列表中
  234. ids, err = company.GetGroupIdsByParentId(sysUser.GroupId)
  235. if err != nil {
  236. fmt.Println(err.Error())
  237. }
  238. }
  239. }
  240. var idSlice []string
  241. var sid string
  242. for _, id := range ids {
  243. idSlice = append(idSlice, *id)
  244. }
  245. //加入父级groupId
  246. if *pid > 0 {
  247. idSlice = append(idSlice, strconv.Itoa(*pid))
  248. } else {
  249. idSlice = append(idSlice, strconv.Itoa(sysUser.GroupId))
  250. }
  251. sid = strings.Join(idSlice, ",")
  252. if len(sid) > 0 {
  253. if status != utils.COMPANY_STATUS_LOSE {
  254. condition += ` AND (b.group_id IN (` + sid + `) OR status='流失') `
  255. //pars = append(pars, sysUser.GroupId)
  256. }
  257. permissionCondition += ` AND b.group_id IN (` + sid + `) `
  258. } else {
  259. if status != utils.COMPANY_STATUS_LOSE {
  260. condition += ` AND (b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) OR status='流失') `
  261. //pars = append(pars, sysUser.GroupId)
  262. }
  263. permissionCondition += ` AND b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) `
  264. }
  265. }
  266. if sysUser.Authority == 4 {
  267. if status != utils.COMPANY_STATUS_LOSE {
  268. condition += ` AND b.group_id =` + strconv.Itoa(sysUser.GroupId)
  269. //pars = append(pars, sysUser.GroupId)
  270. }
  271. permissionCondition += ` AND b.group_id=` + strconv.Itoa(sysUser.GroupId)
  272. //permissionPars = append(permissionPars, sysUser.GroupId)
  273. }
  274. }
  275. }
  276. }
  277. }
  278. }
  279. //状态控制
  280. if status != "" && status != "全部" {
  281. condition += ` AND b.status= '` + status + `'`
  282. usercondition += ` AND cp.status= '` + status + `'`
  283. } else {
  284. condition += ` AND b.status IN ('正式','试用','冻结','永续') `
  285. }
  286. // 试用客户标签
  287. if (status == "试用" || status == "永续") && tryStage > 0 {
  288. condition += ` AND b.try_stage= '` + strconv.Itoa(tryStage) + `'`
  289. usercondition += ` AND cp.try_stage= '` + strconv.Itoa(tryStage) + `'`
  290. }
  291. //套餐类型 权益客户除了大套餐就是小套餐
  292. if status == "正式" && tryStage > 0 {
  293. if tryStage == 1 {
  294. condition += ` AND b.package_type= '` + strconv.Itoa(tryStage) + `'`
  295. usercondition += ` AND cp.package_type= '` + strconv.Itoa(tryStage) + `'`
  296. } else {
  297. condition += ` AND b.package_type!= 1 `
  298. usercondition += ` AND cp.package_type != 1 `
  299. }
  300. }
  301. if isMaker != 2 {
  302. if isMaker == 1 {
  303. usercondition += ` AND u.is_maker = 1 `
  304. } else {
  305. //部分脏数据
  306. usercondition += ` AND u.is_maker != 1 `
  307. }
  308. //parsUser = append(parsUser, isMaker)
  309. }
  310. if isRegister != 2 {
  311. if isRegister == 1 {
  312. usercondition += ` AND u.register_time IS NOT NULL`
  313. } else {
  314. //部分脏数据
  315. usercondition += ` AND u.register_time IS NULL`
  316. }
  317. //parsUser = append(parsUser, isRegister)
  318. }
  319. kwywordcondition = condition
  320. if keyWord != "" {
  321. companyIdStr, err := company.GetCompanyIdByKeyWord(keyWord)
  322. if err != nil {
  323. br.Msg = "获取客户信息失败"
  324. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  325. return
  326. }
  327. if companyIdStr != "" {
  328. condition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.credit_code LIKE '%` + keyWord + `%' AND a.company_id IN(` + companyIdStr + `)) `
  329. } else {
  330. condition += ` AND (a.company_name LIKE '%` + keyWord + `%' OR a.credit_code LIKE '%` + keyWord + `%' ) `
  331. }
  332. }
  333. if label != "" {
  334. usercondition += ` AND u.user_label LIKE '%` + label + `%'`
  335. }
  336. //
  337. usercondition += ` AND cp.product_id = 2 AND sr.product_id = 2 `
  338. // 是否关注弘则研究公众号
  339. if isSubscribeCygx == 0 {
  340. usercondition += ` AND (u.cygx_subscribe = 0 OR ISNULL(u.cygx_subscribe)) `
  341. }
  342. if isSubscribeCygx == 1 {
  343. usercondition += ` AND u.cygx_subscribe = 1 `
  344. }
  345. condition += ` AND cp.product_id = 2 `
  346. total, err := cygx.GetCompanyListCount(usercondition, keyWord, kwywordcondition, condition, roleTypeCode, pars)
  347. if err != nil {
  348. br.Msg = "获取失败"
  349. br.ErrMsg = "获取数据总数失败,Err:" + err.Error()
  350. return
  351. }
  352. if sortType == "" {
  353. sqlOrder = ` GROUP by u.user_id ORDER BY c.created_time DESC, u.register_time DESC `
  354. } else {
  355. if sortType == "asc" {
  356. sqlOrder = ` GROUP by u.user_id ORDER BY u.interaction_num ASC , u.register_time DESC `
  357. } else {
  358. sqlOrder = ` GROUP by u.user_id ORDER BY u.interaction_num DESC , u.register_time DESC `
  359. }
  360. }
  361. list, err := cygx.GetCygxCompanyUserList(usercondition, keyWord, kwywordcondition, condition, roleTypeCode, sqlOrder, parsUser, startSize, pageSize)
  362. if err != nil {
  363. br.Msg = "获取失败"
  364. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  365. return
  366. }
  367. var isAdminRole bool
  368. //如果不是管理员身份或者研究员身份则需要添加可见范围处理
  369. if sysUser.Role == utils.ROLE_TYPE_CODE_ADMIN || sysUser.Role == utils.ROLE_TYPE_CODE_RESEARCHR {
  370. isAdminRole = true
  371. }
  372. var userIds string
  373. var userIdArr []int
  374. if list != nil {
  375. for k, v := range list {
  376. if v.RegisterTime != "" {
  377. list[k].IsRegister = true
  378. } else {
  379. list[k].IsRegister = false
  380. }
  381. if v.IsShowSeeNum > 0 {
  382. list[k].IsShowSee = true
  383. }
  384. if v.Status == "正式" {
  385. if v.PackageType == 1 {
  386. list[k].Status += "(大套餐)"
  387. } else {
  388. list[k].Status += "(小套餐)"
  389. }
  390. }
  391. if v.Status == "试用" {
  392. if v.TryStage == 1 {
  393. list[k].Status += "(未分类)"
  394. } else if v.TryStage == 2 {
  395. list[k].Status += "(推进)"
  396. } else if v.TryStage == 3 {
  397. list[k].Status += "(跟踪)"
  398. } else if v.TryStage == 4 {
  399. list[k].Status += "(预备)"
  400. }
  401. }
  402. if v.Status == "永续" {
  403. v.Status = "X类试用"
  404. }
  405. userIds += strconv.Itoa(int(v.UserId)) + ","
  406. userIdArr = append(userIdArr, int(v.UserId))
  407. if !isAdminRole {
  408. list[k].CompanyInteractionNum = v.CompanyInteractionNumSeller
  409. }
  410. }
  411. userIds = strings.TrimRight(userIds, ",")
  412. splitList, err := cygx.GetCygxCompanyUserListSplit(userIds)
  413. if err != nil && err.Error() != utils.ErrNoRow() {
  414. br.Msg = "获取失败"
  415. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  416. return
  417. }
  418. //用户备注
  419. userRemarksList, err := cygx.GetUserRemarksListByUserIds(userIds)
  420. if err != nil && err.Error() != utils.ErrNoRow() {
  421. br.Msg = "获取失败"
  422. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  423. return
  424. }
  425. mapUserRemarks := make(map[int]string)
  426. for _, v := range userRemarksList {
  427. if mapUserRemarks[v.UserId] == "" {
  428. mapUserRemarks[v.UserId] = v.Content
  429. }
  430. }
  431. UserRemindListMap := cygxService.GetCygxUserRemindListMap(userIdArr)
  432. for k, v := range list {
  433. for _, vsplit := range splitList {
  434. if vsplit.UserId == v.UserId {
  435. list[k].HistoryNum = vsplit.HistoryNum
  436. list[k].CountNum = vsplit.CountNum
  437. list[k].IndustryFllowNum = vsplit.IndustryFllowNum
  438. list[k].DepartmentFollowNum = vsplit.DepartmentFollowNum
  439. list[k].KeyWordNum = vsplit.KeyWordNum
  440. list[k].OnLineNum = vsplit.OnLineNum
  441. list[k].OfficeNum = vsplit.OfficeNum
  442. list[k].ChartNum = vsplit.ChartNum
  443. list[k].TripNum = vsplit.TripNum
  444. list[k].RoadshowVideoNum = vsplit.RoadshowVideoNum
  445. list[k].ActivityVideoNum = vsplit.ActivityVideoNum
  446. list[k].ActivityVoiceNum = vsplit.ActivityVoiceNum
  447. list[k].YanxuanspecialNum = vsplit.YanxuanspecialNum
  448. }
  449. }
  450. if mapUserRemarks[int(v.UserId)] != "" {
  451. list[k].Content = mapUserRemarks[int(v.UserId)]
  452. }
  453. list[k].IsRemind = UserRemindListMap[int(v.UserId)]
  454. }
  455. for k := range list {
  456. list[k].InteractionNum = list[k].HistoryNum + list[k].CountNum + list[k].IndustryFllowNum + list[k].DepartmentFollowNum + list[k].KeyWordNum + list[k].OnLineNum + list[k].OfficeNum + list[k].ChartNum + list[k].TripNum + list[k].RoadshowVideoNum + list[k].ActivityVideoNum + list[k].ActivityVoiceNum + list[k].YanxuanspecialNum
  457. }
  458. } else {
  459. list = make([]*cygx.CygxCompanyUser, 0)
  460. }
  461. page = paging.GetPaging(currentIndex, pageSize, total)
  462. resp := new(cygx.CompanyUserListResp)
  463. resp.List = list
  464. resp.Paging = page
  465. br.Ret = 200
  466. br.Success = true
  467. br.Msg = "获取成功"
  468. br.Data = resp
  469. }
  470. // @Title 新增备注接口
  471. // @Description 新增备注
  472. // @Param request body cygx.UserRemarAddReq true "type json string"
  473. // @Success 200 新增成功
  474. // @router /user/addRemarks [post]
  475. func (this *UserController) Add() {
  476. br := new(models.BaseResponse).Init()
  477. defer func() {
  478. this.Data["json"] = br
  479. this.ServeJSON()
  480. }()
  481. sysUser := this.SysUser
  482. if sysUser == nil {
  483. br.Msg = "请登录"
  484. br.ErrMsg = "请登录,SysUser Is Empty"
  485. br.Ret = 408
  486. return
  487. }
  488. var req cygx.UserRemarAddReq
  489. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  490. if err != nil {
  491. br.Msg = "参数解析异常!"
  492. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  493. return
  494. }
  495. if req.Content == "" {
  496. br.Msg = "请填写内容"
  497. return
  498. }
  499. item := new(cygx.UserRemarks)
  500. item.UserId = req.UserId
  501. item.AdminId = sysUser.AdminId
  502. item.Content = req.Content
  503. item.CreateTime = time.Now()
  504. err = cygx.AddUserRemarks(item)
  505. if err != nil {
  506. br.Msg = "新增失败."
  507. br.ErrMsg = "新增失败,Err:" + err.Error()
  508. return
  509. }
  510. br.Ret = 200
  511. br.Success = true
  512. br.Msg = "新增成功"
  513. }
  514. // @Title 备注列表
  515. // @Description 备注列表接口
  516. // @Param UserId query int true "用户id"
  517. // @Success 200 {object} cygx.UserRemarksListResp
  518. // @router /user/remark/list [get]
  519. func (this *UserController) RemarkList() {
  520. br := new(models.BaseResponse).Init()
  521. defer func() {
  522. this.Data["json"] = br
  523. this.ServeJSON()
  524. }()
  525. sysUser := this.SysUser
  526. if sysUser == nil {
  527. br.Msg = "请登录"
  528. br.ErrMsg = "请登录,SysUser Is Empty"
  529. br.Ret = 408
  530. return
  531. }
  532. userId, _ := this.GetInt("UserId")
  533. if userId < 1 {
  534. br.Msg = "用户不存在"
  535. return
  536. }
  537. list, err := cygx.GetUserRemarksList(userId)
  538. if err != nil && err.Error() != utils.ErrNoRow() {
  539. br.Msg = "获取信息失败"
  540. br.ErrMsg = "获取备注信息失败,Err:" + err.Error()
  541. return
  542. }
  543. resp := new(cygx.UserRemarksListResp)
  544. resp.List = list
  545. br.Ret = 200
  546. br.Success = true
  547. br.Msg = "获取成功"
  548. br.Data = resp
  549. }
  550. // @Title 互动详情table栏
  551. // @Description 互动详情table栏接口
  552. // @Param UserId query int true "用户id"
  553. // @Param ClassType query int true "列表类型,1:权益,2:研选,默认1"
  554. // @Success 200 {object} cygx.UserRemarksListResp
  555. // @router /user/table/list [get]
  556. func (this *UserController) TableList() {
  557. br := new(models.BaseResponse).Init()
  558. defer func() {
  559. this.Data["json"] = br
  560. this.ServeJSON()
  561. }()
  562. sysUser := this.SysUser
  563. if sysUser == nil {
  564. br.Msg = "请登录"
  565. br.ErrMsg = "请登录,SysUser Is Empty"
  566. br.Ret = 408
  567. return
  568. }
  569. userId, _ := this.GetInt("UserId")
  570. if userId < 1 {
  571. br.Msg = "用户不存在"
  572. return
  573. }
  574. classType, _ := this.GetInt("ClassType", 1)
  575. wxUser, err := models.GetWxUserByUserId(userId)
  576. if err != nil {
  577. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  578. br.Msg = "获取信息失败"
  579. return
  580. }
  581. comanyDetail, err := company.GetCompanyDetailById(wxUser.CompanyId)
  582. if err != nil {
  583. br.Msg = "获取信息失败"
  584. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  585. return
  586. }
  587. resp := new(cygx.CygxUserTableListRep)
  588. if classType == 1 {
  589. countDetail, err := cygx.GetUserInteractionTableCount(userId)
  590. if err != nil {
  591. br.Msg = "获取信息失败"
  592. br.ErrMsg = "获取各个阅读总数失败,Err:" + err.Error()
  593. return
  594. }
  595. List := []*cygx.CygxUserTableRep{{PermissionName: "报告阅读列表", Source: 1, TotalNum: countDetail.HistoryNum},
  596. {PermissionName: "活动互动记录", Source: 2, TotalNum: countDetail.OnLineNum + countDetail.OfficeNum},
  597. {PermissionName: "专项调研", Source: 8, TotalNum: countDetail.TripNum},
  598. {PermissionName: "收藏的报告", Source: 3, TotalNum: countDetail.CountNum},
  599. {PermissionName: "收藏的图表", Source: 4, TotalNum: countDetail.ChartNum},
  600. {PermissionName: "关注的产业", Source: 5, TotalNum: countDetail.IndustryFllowNum},
  601. {PermissionName: "搜索", Source: 7, TotalNum: countDetail.KeyWordNum},
  602. {PermissionName: "音视频播放", Source: 9, TotalNum: countDetail.RoadshowVideoNum + countDetail.ActivityVideoNum + countDetail.ActivityVoiceNum},
  603. {PermissionName: "首页标签点击", Source: 10, TotalNum: countDetail.TagNum}}
  604. resp.List = List
  605. } else {
  606. countDetail, err := cygx.GetUserInteractionTableCountByYanXuan(userId)
  607. if err != nil {
  608. br.Msg = "获取信息失败"
  609. br.ErrMsg = "获取各个阅读总数失败,Err:" + err.Error()
  610. return
  611. }
  612. List := []*cygx.CygxUserTableRep{{PermissionName: "报告阅读列表", Source: 1, TotalNum: countDetail.HistoryNum},
  613. {PermissionName: "活动互动记录", Source: 2, TotalNum: countDetail.OnLineNum + countDetail.OfficeNum},
  614. {PermissionName: "收藏的报告", Source: 3, TotalNum: countDetail.CountNum},
  615. {PermissionName: "关注的产业", Source: 5, TotalNum: countDetail.IndustryFllowNum},
  616. {PermissionName: "关注的作者", Source: 6, TotalNum: countDetail.DepartmentFollowNum},
  617. {PermissionName: "专栏文章阅读记录", Source: 11, TotalNum: countDetail.YanxuanSpecialNum},
  618. {PermissionName: "收藏的专栏文章", Source: 12, TotalNum: countDetail.YanxuanSpecialCollectNum},
  619. {PermissionName: "关注的专栏作者", Source: 13, TotalNum: countDetail.YanxuanSpecialFollowNum},
  620. {PermissionName: "搜索", Source: 7, TotalNum: 0}}
  621. resp.List = List
  622. }
  623. //阅读记录总数
  624. resp.UserName = wxUser.RealName
  625. resp.Mobile = wxUser.Mobile
  626. resp.ComapnyName = comanyDetail.CompanyName
  627. br.Ret = 200
  628. br.Success = true
  629. br.Msg = "获取成功"
  630. br.Data = resp
  631. }
  632. // @Title 互动详情
  633. // @Description 互动详情接口
  634. // @Param UserId query int true "用户id"
  635. // @Param Source query int true "来源"
  636. // @Param IdentityType query int true "身份类型,1:用户,2机构。默认1 (图表分页使用)"
  637. // @Param IsMeeting query string true "是否到会 1到会、2未到会"
  638. // @Param MeetType query string true "参会方式 1线上,2线下 默认为线上"
  639. // @Param PageSize query int true "每页数据条数"
  640. // @Param CurrentIndex query int true "当前页页码,从1开始"
  641. // @Param StartDate query string true "开始时间"
  642. // @Param EndDate query string true "结束时间"
  643. // @Param KeyWord query string true "搜索关键词"
  644. // @Param ClassType query int true "列表类型,1:权益,2:研选,默认1"
  645. // @Success 200 {object} cygx.UserInteractionListResp
  646. // @router /user/interaction/detail [get]
  647. func (this *UserController) TableDetail() {
  648. br := new(models.BaseResponse).Init()
  649. defer func() {
  650. this.Data["json"] = br
  651. this.ServeJSON()
  652. }()
  653. sysUser := this.SysUser
  654. if sysUser == nil {
  655. br.Msg = "请登录"
  656. br.ErrMsg = "请登录,SysUser Is Empty"
  657. br.Ret = 408
  658. return
  659. }
  660. pageSize, _ := this.GetInt("PageSize")
  661. currentIndex, _ := this.GetInt("CurrentIndex")
  662. var startSize int
  663. if pageSize <= 0 {
  664. pageSize = utils.PageSize20
  665. }
  666. if currentIndex <= 0 {
  667. currentIndex = 1
  668. }
  669. startSize = paging.StartIndex(currentIndex, pageSize)
  670. userId, _ := this.GetInt("UserId")
  671. isMeeting := this.GetString("IsMeeting")
  672. meetType := this.GetString("MeetType")
  673. startDate := this.GetString("StartDate")
  674. endDate := this.GetString("EndDate")
  675. keyWord := this.GetString("KeyWord")
  676. source, _ := this.GetInt("Source")
  677. identityType, _ := this.GetInt("IdentityType")
  678. classType, _ := this.GetInt("ClassType", 1)
  679. if userId < 1 {
  680. br.Msg = "用户不存在"
  681. return
  682. }
  683. // 1.标记用户表
  684. //操作权限校验
  685. var err error
  686. wxUser, err := models.GetWxUserByUserId(userId)
  687. if err != nil {
  688. br.Msg = "获取信息失败"
  689. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  690. return
  691. }
  692. mobile := wxUser.Mobile
  693. //var checkSource bool
  694. var MeetingNum int
  695. var NoMeetingNum int
  696. var list []*cygx.UserInteraction
  697. //listTable := []*cygx.CygxUserTableRep{{PermissionName: "报告阅读列表", Source: 1, TotalNum: 10},
  698. // {PermissionName: "活动互动记录", Source: 2, TotalNum: 10},
  699. // {PermissionName: "收藏的报告", Source: 3, TotalNum: 10},
  700. // {PermissionName: "收藏图表", Source: 4, TotalNum: 10},
  701. // {PermissionName: "关注的产业", Source: 5, TotalNum: 10},
  702. // {PermissionName: "关注的作者", Source: 6, TotalNum: 10},
  703. // {PermissionName: "搜索", Source: 7, TotalNum: 10},
  704. // {PermissionName: "专项调研", Source: 8, TotalNum: 10},
  705. // {PermissionName: "音视频播放", Source: 9, TotalNum: 10},
  706. // {PermissionName: "首页标签点击", Source: 10, TotalNum: 10}}
  707. //for _, v := range listTable {
  708. // if v.Source == source {
  709. // checkSource = true
  710. // }
  711. //}
  712. ////默认类型1
  713. //if !checkSource {
  714. // source = 1
  715. //}
  716. var total int
  717. var condition string
  718. var pars []interface{}
  719. if source == 1 {
  720. if startDate != "" {
  721. startDate += " 00:00:00"
  722. condition += ` AND r.create_time >= '` + startDate + `' `
  723. }
  724. if endDate != "" {
  725. endDate += " 23:59:59"
  726. condition += ` AND r.create_time <= '` + endDate + `' `
  727. }
  728. if wxUser.Mobile == "" {
  729. wxUser.Mobile = wxUser.Email
  730. }
  731. //total, err = cygx.GetCygxArticleHistoryCount(wxUser.Mobile, wxUser.Email, condition)
  732. //if err != nil {
  733. // br.Msg = "获取信息失败"
  734. // br.ErrMsg = "获取用户阅读记录总数失败,Err:" + err.Error()
  735. // return
  736. //}
  737. if classType == 1 {
  738. condition += " AND art.article_type_id = 0 "
  739. } else {
  740. condition += " AND art.article_type_id > 0 "
  741. }
  742. condition += " AND (r.mobile = '" + wxUser.Mobile + "' OR r.email = '" + wxUser.Mobile + "') "
  743. total, list, err = cygx.GetCygxArticleHistoryRecordByUserNew(condition, startSize, pageSize)
  744. if err != nil && err.Error() != utils.ErrNoRow() {
  745. br.Msg = "获取信息失败"
  746. br.ErrMsg = "获取用户阅读记录,Err:" + err.Error()
  747. return
  748. }
  749. var articleIds string
  750. var articleIdArr []int
  751. if len(list) > 0 {
  752. articleIds = ""
  753. mapAricleId := make(map[int]int)
  754. mapAricleIndustrialSubjectName := make(map[int]*cygx.ArticleIndustrialSubjectNameResp)
  755. for k, v := range list {
  756. if v.ArticleId >= utils.SummaryArticleId {
  757. list[k].ArticleType = 1
  758. } else {
  759. list[k].ArticleType = 2
  760. }
  761. if mapAricleId[v.ArticleId] == 0 {
  762. articleIds += strconv.Itoa(v.ArticleId) + ","
  763. mapAricleId[v.ArticleId] = v.ArticleId
  764. }
  765. list[k].RegisterPlatform = cygxService.GetArticleSourcePlatform(v.SourcePlatform)
  766. list[k].RegisterPlatformText = cygxService.GetArticleSourcePlatformText(v.RegisterPlatform)
  767. articleIdArr = append(articleIdArr, v.ArticleId)
  768. }
  769. articleIds = strings.TrimRight(articleIds, ",")
  770. listArticleIndustrialSubjectList, err := cygx.GetCygxArticleIndustrialSubjectName(articleIds)
  771. if err != nil && err.Error() != utils.ErrNoRow() {
  772. br.Msg = "获取信息失败"
  773. br.ErrMsg = "获取用户阅读记录,Err:" + err.Error()
  774. return
  775. }
  776. if len(listArticleIndustrialSubjectList) > 0 {
  777. for _, v := range listArticleIndustrialSubjectList {
  778. mapAricleIndustrialSubjectName[v.ArticleId] = v
  779. }
  780. for k, v := range list {
  781. if mapAricleIndustrialSubjectName[v.ArticleId] != nil {
  782. list[k].IndustryName = mapAricleIndustrialSubjectName[v.ArticleId].IndustryName // 产业
  783. list[k].SubjectNameStr = mapAricleIndustrialSubjectName[v.ArticleId].SubjectNameStr // 标的
  784. }
  785. }
  786. }
  787. //行业
  788. mapPerssionName := cygxService.GetCygxArticlePerssionNameListMap(articleIdArr)
  789. for k, v := range list {
  790. if v.SpecialType > 0 {
  791. list[k].PermissionName = utils.CHART_PERMISSION_NAME_MF_YANXUAN
  792. } else {
  793. list[k].PermissionName = mapPerssionName[v.ArticleId]
  794. }
  795. }
  796. }
  797. } else if source == 2 {
  798. if mobile != "" {
  799. condition = ` AND s.mobile = '` + mobile + `' `
  800. if classType == 1 {
  801. condition += " AND a.chart_permission_id != 31 "
  802. } else {
  803. condition += " AND a.chart_permission_id = 31 "
  804. }
  805. if isMeeting == "1" {
  806. condition += ` AND s.is_meeting = 1 `
  807. }
  808. if isMeeting == "2" {
  809. condition += ` AND s.is_meeting = 0 `
  810. }
  811. if meetType == "1" {
  812. condition += ` AND t.activity_type = 1 `
  813. }
  814. if meetType == "2" {
  815. condition += ` AND t.activity_type = 0 `
  816. }
  817. if startDate != "" {
  818. startDate += " 00:00:00"
  819. condition += ` AND a.activity_time >= '` + startDate + `' `
  820. }
  821. if endDate != "" {
  822. endDate += " 23:59:59"
  823. condition += ` AND a.activity_time <= '` + endDate + `' `
  824. }
  825. if keyWord != "" {
  826. condition += ` AND a.activity_name LIKE '%` + keyWord + `%' `
  827. }
  828. total, err = cygx.GetActivityMeetByUserCount(condition)
  829. if err != nil {
  830. br.Msg = "获取信息失败"
  831. br.ErrMsg = "获取参会总数失败,Err:" + err.Error()
  832. return
  833. }
  834. list, err = cygx.GetActivityMeetByUser(condition, startSize, pageSize)
  835. if err != nil && err.Error() != utils.ErrNoRow() {
  836. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  837. br.Msg = "获取参会人数列表失败"
  838. return
  839. }
  840. if len(list) > 0 {
  841. for k, v := range list {
  842. if v.ActivityType == 1 {
  843. if v.SignupType == "2" {
  844. list[k].InteractionType = "自主拨入"
  845. } else {
  846. list[k].InteractionType = "预约外呼"
  847. }
  848. if v.ReminderNum > 0 {
  849. list[k].InteractionType += "会议提醒"
  850. }
  851. }
  852. if v.IsMeeting == 0 {
  853. list[k].FirstMeetingTime = ""
  854. list[k].LastMeetingTime = ""
  855. }
  856. if v.FirstMeetingTime == "0000-00-00 00:00:00" {
  857. list[k].FirstMeetingTime = ""
  858. list[k].LastMeetingTime = ""
  859. }
  860. }
  861. }
  862. }
  863. } else if source == 3 {
  864. if classType == 1 {
  865. condition += " AND art.article_type_id = 0 "
  866. } else {
  867. condition += " AND art.article_type_id > 0 "
  868. }
  869. total, err = cygx.GetCygxArticleCollectCount(userId, condition)
  870. if err != nil {
  871. br.Msg = "获取信息失败"
  872. br.ErrMsg = "获取用户收藏记录总数失败,Err:" + err.Error()
  873. return
  874. }
  875. list, err = cygx.GetCygxArticleCollectByUser(userId, startSize, pageSize, condition)
  876. if err != nil && err.Error() != utils.ErrNoRow() {
  877. br.Msg = "获取信息失败"
  878. br.ErrMsg = "获取用户搜藏记录失败,Err:" + err.Error()
  879. return
  880. }
  881. if len(list) > 0 {
  882. for k, v := range list {
  883. if v.ArticleId >= utils.SummaryArticleId {
  884. list[k].ArticleType = 1
  885. } else {
  886. list[k].ArticleType = 2
  887. }
  888. }
  889. }
  890. } else if source == 4 {
  891. if identityType == 2 {
  892. condition += ` AND r.create_time < date_format(now(),'%Y-%m-%d') ` //过滤当天时间
  893. }
  894. condition += ` AND a.publish_status = 1 AND user_id = ` + strconv.Itoa(userId)
  895. var err error
  896. total, err = cygx.GetChartCountByUser(condition)
  897. if err != nil {
  898. br.Msg = "获取信息失败"
  899. br.ErrMsg = "获取总数失败,Err:" + err.Error()
  900. return
  901. }
  902. list, err = cygx.GetChartListCollectionWithCygx(condition, startSize, pageSize)
  903. if err != nil {
  904. br.Msg = "获取信息失败"
  905. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  906. return
  907. }
  908. for k, v := range list {
  909. if v.PtagName != "" {
  910. list[k].CtagNamePc = v.PtagName
  911. }
  912. if v.CtagName != "" {
  913. list[k].CtagNamePc += "," + v.CtagName
  914. }
  915. if v.PtagNameTwo != "" {
  916. list[k].CtagNamePc += "," + v.PtagNameTwo
  917. }
  918. if v.CtagNameTwo != "" {
  919. list[k].CtagNamePc += "," + v.CtagNameTwo
  920. }
  921. }
  922. } else if source == 5 {
  923. if classType == 1 {
  924. condition += " AND a.chart_permission_id = 31 "
  925. } else {
  926. condition += " AND a.chart_permission_id = 31 "
  927. }
  928. total, err = cygx.GetCygxIndustryFllowCount(userId, condition)
  929. if err != nil {
  930. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  931. br.Msg = "获取用户关注总数失败"
  932. return
  933. }
  934. list, err = cygx.GetCygxIndustryFllowByUser(userId, startSize, pageSize, condition)
  935. if err != nil && err.Error() != utils.ErrNoRow() {
  936. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  937. br.Msg = "获取用户关注总数失败"
  938. return
  939. }
  940. } else if source == 6 {
  941. total, err = cygx.GetCygArticleDepartmentFollowCount(userId)
  942. if err != nil {
  943. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  944. br.Msg = "获取关注作者总数失败"
  945. return
  946. }
  947. list, err = cygx.GetCygArticleDepartmentFollowByUser(userId, startSize, pageSize)
  948. if err != nil && err.Error() != utils.ErrNoRow() {
  949. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  950. br.Msg = "获取关注作者列表失败"
  951. return
  952. }
  953. if len(list) > 0 {
  954. for k, v := range list {
  955. var condition string
  956. var pars []interface{}
  957. condition += ` WHERE art.source = 1 AND art.is_summary = 1 AND art.department_id = ` + strconv.Itoa(v.DepartmentId)
  958. listArt, errList := cygx.GetSummaryManageList(condition, pars, 0, 20)
  959. if errList != nil && errList.Error() != utils.ErrNoRow() {
  960. br.Msg = "获取失败"
  961. br.ErrMsg = "获取失败,Err:" + errList.Error()
  962. return
  963. }
  964. if len(listArt) > 0 {
  965. mapIndustryName := make(map[string]string)
  966. mapSubjectName := make(map[string]string)
  967. var articleIdStr string
  968. for _, vArt := range listArt {
  969. if vArt.IndustryName != "" && mapIndustryName[vArt.IndustryName] == "" {
  970. list[k].IndustryName += vArt.IndustryName + "/"
  971. mapIndustryName[vArt.IndustryName] = vArt.IndustryName
  972. }
  973. articleIdStr += strconv.Itoa(vArt.ArticleId) + ","
  974. }
  975. list[k].IndustryName = strings.TrimRight(list[k].IndustryName, "/")
  976. articleIdStr = strings.TrimRight(articleIdStr, ",")
  977. listSubject, err := cygx.GetArticleSubjectList(articleIdStr)
  978. if err != nil {
  979. br.Msg = "获取失败"
  980. br.ErrMsg = "获取失败,Err:" + err.Error()
  981. return
  982. }
  983. if len(listSubject) > 0 {
  984. for _, vSub := range listSubject {
  985. if vSub.SubjectName != "" && mapSubjectName[vSub.SubjectName] == "" {
  986. list[k].SubjectNameStr += vSub.SubjectName + "/"
  987. mapSubjectName[vSub.SubjectName] = vSub.SubjectName
  988. }
  989. }
  990. list[k].SubjectNameStr = strings.TrimRight(list[k].SubjectNameStr, "/")
  991. }
  992. }
  993. }
  994. }
  995. } else if source == 7 {
  996. total, err = cygx.GetCygxSearchKeyWordCount(userId)
  997. if err != nil {
  998. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  999. br.Msg = "获取搜索记录失败"
  1000. return
  1001. }
  1002. list, err = cygx.GetCygxSearchKeyWordByUser(userId, startSize, pageSize)
  1003. if err != nil && err.Error() != utils.ErrNoRow() {
  1004. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  1005. br.Msg = "获取搜索记录列表失败"
  1006. return
  1007. }
  1008. } else if source == 8 {
  1009. condition += ` AND h.user_id = ? `
  1010. pars = append(pars, userId)
  1011. total, err = cygx.GetCygxActivitySpecialTripCount(condition, pars)
  1012. if err != nil {
  1013. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  1014. br.Msg = "获取搜索记录失败"
  1015. return
  1016. }
  1017. list, err = cygx.GetCygxActivitySpecialTripByUser(userId, startSize, pageSize)
  1018. if err != nil && err.Error() != utils.ErrNoRow() {
  1019. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  1020. br.Msg = "获取搜索记录列表失败"
  1021. return
  1022. }
  1023. } else if source == 9 {
  1024. total, err = cygx.GetCygxRoadshowCount(userId)
  1025. if err != nil {
  1026. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  1027. br.Msg = "获取搜索记录失败"
  1028. return
  1029. }
  1030. list, err = cygx.GetCygxRoadshowByUser(userId, startSize, pageSize)
  1031. if err != nil && err.Error() != utils.ErrNoRow() {
  1032. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  1033. br.Msg = "获取搜索记录列表失败"
  1034. return
  1035. }
  1036. } else if source == 10 { //标签点击记录
  1037. total, err = cygx.GetCygxTagHistoryCountByUserId(userId)
  1038. if err != nil {
  1039. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  1040. br.Msg = "获取搜索记录失败"
  1041. return
  1042. }
  1043. list, err = cygx.GetCygxTagHistoryByUserId(userId, startSize, pageSize)
  1044. if err != nil && err.Error() != utils.ErrNoRow() {
  1045. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  1046. br.Msg = "获取搜索记录列表失败"
  1047. return
  1048. }
  1049. } else if source == 11 { //专栏文章阅读记录
  1050. if startDate != "" {
  1051. startDate += " 00:00:00"
  1052. condition += ` AND r.create_time >= '` + startDate + `' `
  1053. }
  1054. if endDate != "" {
  1055. endDate += " 23:59:59"
  1056. condition += ` AND r.create_time <= '` + endDate + `' `
  1057. }
  1058. if wxUser.Mobile == "" {
  1059. wxUser.Mobile = wxUser.Email
  1060. }
  1061. condition += " AND (r.mobile = '" + wxUser.Mobile + "' OR r.email = '" + wxUser.Mobile + "') "
  1062. total, list, err = cygx.GetCygxYanxuaSspecialHistoryRecordByUser(condition, startSize, pageSize)
  1063. if err != nil && err.Error() != utils.ErrNoRow() {
  1064. br.Msg = "获取信息失败"
  1065. br.ErrMsg = "获取用户阅读记录,Err:" + err.Error()
  1066. return
  1067. }
  1068. if len(list) > 0 {
  1069. for k, v := range list {
  1070. list[k].RegisterPlatform = cygxService.GetArticleSourcePlatform(v.SourcePlatform)
  1071. list[k].RegisterPlatformText = cygxService.GetArticleSourcePlatformText(v.RegisterPlatform)
  1072. }
  1073. }
  1074. } else if source == 12 { //收藏的专栏文章
  1075. if startDate != "" {
  1076. startDate += " 00:00:00"
  1077. condition += ` AND r.create_time >= '` + startDate + `' `
  1078. }
  1079. if endDate != "" {
  1080. endDate += " 23:59:59"
  1081. condition += ` AND r.create_time <= '` + endDate + `' `
  1082. }
  1083. if wxUser.Mobile == "" {
  1084. wxUser.Mobile = wxUser.Email
  1085. }
  1086. condition += " AND (r.mobile = '" + wxUser.Mobile + "' OR r.email = '" + wxUser.Mobile + "') "
  1087. total, list, err = cygx.GetCygxYanxuanSpecialCollectByUser(condition, startSize, pageSize)
  1088. if err != nil && err.Error() != utils.ErrNoRow() {
  1089. br.Msg = "获取信息失败"
  1090. br.ErrMsg = "获取用户阅读记录,Err:" + err.Error()
  1091. return
  1092. }
  1093. if len(list) > 0 {
  1094. for k, v := range list {
  1095. list[k].RegisterPlatform = cygxService.GetArticleSourcePlatform(v.SourcePlatform)
  1096. list[k].RegisterPlatformText = cygxService.GetArticleSourcePlatformText(v.RegisterPlatform)
  1097. }
  1098. }
  1099. } else if source == 13 { //关注的专栏作者
  1100. if startDate != "" {
  1101. startDate += " 00:00:00"
  1102. condition += ` AND r.create_time >= '` + startDate + `' `
  1103. }
  1104. if endDate != "" {
  1105. endDate += " 23:59:59"
  1106. condition += ` AND r.create_time <= '` + endDate + `' `
  1107. }
  1108. if wxUser.Mobile == "" {
  1109. wxUser.Mobile = wxUser.Email
  1110. }
  1111. condition += " AND (r.mobile = '" + wxUser.Mobile + "' OR r.email = '" + wxUser.Mobile + "') "
  1112. total, list, err = cygx.GetCygxYanxuanSpecialAuthorByUser(condition, startSize, pageSize)
  1113. if err != nil && err.Error() != utils.ErrNoRow() {
  1114. br.Msg = "获取信息失败"
  1115. br.ErrMsg = "获取用户阅读记录,Err:" + err.Error()
  1116. return
  1117. }
  1118. }
  1119. page := paging.GetPaging(currentIndex, pageSize, total)
  1120. resp := new(cygx.UserInteractionListResp)
  1121. if len(list) == 0 {
  1122. list = make([]*cygx.UserInteraction, 0)
  1123. }
  1124. resp.MeetingNum = MeetingNum
  1125. resp.NoMeetingNum = NoMeetingNum
  1126. resp.List = list
  1127. resp.Paging = page
  1128. br.Ret = 200
  1129. br.Success = true
  1130. br.Msg = "获取成功"
  1131. br.Data = resp
  1132. }
  1133. // @Title 获取用户标签详情
  1134. // @Description 获取用户标签详情接口
  1135. // @Param UserId query int true "用户id"
  1136. // @Success 200 {object} cygx.UserLabel
  1137. // @router /user/label/detail [get]
  1138. func (this *UserController) LabelDetail() {
  1139. br := new(models.BaseResponse).Init()
  1140. defer func() {
  1141. this.Data["json"] = br
  1142. this.ServeJSON()
  1143. }()
  1144. sysUser := this.SysUser
  1145. if sysUser == nil {
  1146. br.Msg = "请登录"
  1147. br.ErrMsg = "请登录,SysUser Is Empty"
  1148. br.Ret = 408
  1149. return
  1150. }
  1151. userId, _ := this.GetInt("UserId")
  1152. if userId < 1 {
  1153. br.Msg = "用户不存在"
  1154. return
  1155. }
  1156. wxUser, err := models.GetWxUserByUserId(userId)
  1157. if err != nil {
  1158. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  1159. br.Msg = "获取信息失败"
  1160. return
  1161. }
  1162. if userId > 0 {
  1163. resp := new(cygx.UserLabel)
  1164. resp.Label = wxUser.UserLabel
  1165. br.Ret = 200
  1166. br.Success = true
  1167. br.Msg = "获取成功"
  1168. br.Data = resp
  1169. return
  1170. }
  1171. list, err := cygx.GetCygxCompanyUserListSplit(strconv.Itoa(userId))
  1172. if err != nil {
  1173. br.Msg = "获取失败"
  1174. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1175. return
  1176. }
  1177. mapLabels := make(map[string]string)
  1178. var labelsListStr []*cygx.UserLabel
  1179. mapActivityLabels := make(map[string]string)
  1180. for k := range list {
  1181. labels := list[k].Labels
  1182. labelsList := strings.Split(labels, ",")
  1183. for _, vL := range labelsList {
  1184. if mapLabels[vL] == "" && vL != "" {
  1185. mapLabels[vL] = vL
  1186. item := new(cygx.UserLabel)
  1187. item.Label = vL
  1188. labelsListStr = append(labelsListStr, item)
  1189. }
  1190. }
  1191. }
  1192. dateTime := time.Now().AddDate(0, -3, 0).Format(utils.FormatDate)
  1193. listArticlePv, err := cygx.GetArticlePvCount(wxUser.Mobile, wxUser.Email, dateTime)
  1194. if err != nil && err.Error() != utils.ErrNoRow() {
  1195. br.Msg = "获取失败"
  1196. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1197. return
  1198. }
  1199. var articleIds string
  1200. mapArticleIdLabelTotal := make(map[string]int)
  1201. mapArticleIdPv := make(map[int]int)
  1202. if len(listArticlePv) > 0 {
  1203. for _, v := range listArticlePv {
  1204. articleIds += strconv.Itoa(v.ArticleId) + ","
  1205. mapArticleIdPv[v.ArticleId] = v.Pv
  1206. }
  1207. articleIds = strings.TrimRight(articleIds, ",")
  1208. //产业、标的标签
  1209. listLabelName, err := cygx.GetArticleGroupyIndustryName(articleIds)
  1210. if err != nil && err.Error() != utils.ErrNoRow() {
  1211. br.Msg = "获取失败"
  1212. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1213. return
  1214. }
  1215. if len(listLabelName) > 0 {
  1216. for _, v := range listLabelName {
  1217. labelsIndustryList := strings.Split(v.IndustryName, "/")
  1218. labelsSubjectList := strings.Split(v.SubjectName, "/")
  1219. //添加产业统计
  1220. if len(labelsIndustryList) > 0 {
  1221. for _, vIn := range labelsIndustryList {
  1222. if mapActivityLabels[vIn] != "" {
  1223. mapArticleIdLabelTotal[vIn] += mapArticleIdPv[v.ArticleId]
  1224. } else {
  1225. mapArticleIdLabelTotal[vIn] = mapArticleIdPv[v.ArticleId]
  1226. mapActivityLabels[vIn] = vIn
  1227. }
  1228. }
  1229. }
  1230. if len(labelsSubjectList) > 0 {
  1231. //添加标的统计
  1232. for _, vIn := range labelsSubjectList {
  1233. if mapActivityLabels[vIn] != "" {
  1234. mapArticleIdLabelTotal[vIn] += mapArticleIdPv[v.ArticleId]
  1235. } else {
  1236. mapArticleIdLabelTotal[vIn] = mapArticleIdPv[v.ArticleId]
  1237. mapActivityLabels[vIn] = vIn
  1238. }
  1239. }
  1240. }
  1241. }
  1242. }
  1243. }
  1244. articleIds, err = cygx.GetCygxArticleCollectId(userId, dateTime)
  1245. if err != nil && err.Error() != utils.ErrNoRow() {
  1246. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  1247. br.Msg = "获取用户搜藏记录失败"
  1248. return
  1249. }
  1250. if articleIds != "" {
  1251. //产业、标的标签
  1252. listLabelName, err := cygx.GetArticleGroupyIndustryName(articleIds)
  1253. if err != nil && err.Error() != utils.ErrNoRow() {
  1254. br.Msg = "获取失败"
  1255. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1256. return
  1257. }
  1258. if len(listLabelName) > 0 {
  1259. for _, v := range listLabelName {
  1260. labelsIndustryList := strings.Split(v.IndustryName, "/")
  1261. labelsSubjectList := strings.Split(v.SubjectName, "/")
  1262. //添加产业统计
  1263. if len(labelsIndustryList) > 0 {
  1264. for _, vIn := range labelsIndustryList {
  1265. if mapActivityLabels[vIn] != "" {
  1266. mapArticleIdLabelTotal[vIn] += 1
  1267. } else {
  1268. mapArticleIdLabelTotal[vIn] = 1
  1269. mapActivityLabels[vIn] = vIn
  1270. }
  1271. }
  1272. }
  1273. if len(labelsSubjectList) > 0 {
  1274. //添加标的统计
  1275. for _, vIn := range labelsSubjectList {
  1276. if mapActivityLabels[vIn] != "" {
  1277. mapArticleIdLabelTotal[vIn] += 1
  1278. } else {
  1279. mapArticleIdLabelTotal[vIn] = 1
  1280. mapActivityLabels[vIn] = vIn
  1281. }
  1282. }
  1283. }
  1284. }
  1285. }
  1286. }
  1287. //活动标签计算
  1288. listActivityPv, err := cygx.GetActivitySignCount(wxUser.Mobile, dateTime)
  1289. if err != nil && err.Error() != utils.ErrNoRow() {
  1290. br.Msg = "获取失败"
  1291. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1292. return
  1293. }
  1294. if len(listActivityPv) > 0 {
  1295. for _, v := range listActivityPv {
  1296. labelsList := strings.Split(v.Label, "-")
  1297. for _, v2 := range labelsList {
  1298. labelsListSon := strings.Split(v2, "/")
  1299. for _, v3 := range labelsListSon {
  1300. if mapActivityLabels[v3] != "" {
  1301. mapArticleIdLabelTotal[v3] += 1
  1302. } else {
  1303. mapArticleIdLabelTotal[v3] = 1
  1304. mapActivityLabels[v3] = v3
  1305. }
  1306. }
  1307. }
  1308. }
  1309. }
  1310. //会议提醒部分标签
  1311. listActivityPvByReminder, err := cygx.GetActivityMeetingReminder(wxUser.Mobile, dateTime)
  1312. if err != nil && err.Error() != utils.ErrNoRow() {
  1313. br.Msg = "获取失败"
  1314. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1315. return
  1316. }
  1317. if len(listActivityPvByReminder) > 0 {
  1318. for _, v := range listActivityPvByReminder {
  1319. labelsList := strings.Split(v.Label, "-")
  1320. for _, v2 := range labelsList {
  1321. labelsListSon := strings.Split(v2, "/")
  1322. for _, v3 := range labelsListSon {
  1323. if mapActivityLabels[v3] != "" {
  1324. mapArticleIdLabelTotal[v3] += 1
  1325. } else {
  1326. mapArticleIdLabelTotal[v3] = 1
  1327. mapActivityLabels[v3] = v3
  1328. }
  1329. }
  1330. }
  1331. }
  1332. }
  1333. //对标签数量进行排序
  1334. type KvPair struct {
  1335. Key string
  1336. Val int
  1337. }
  1338. tmpList := make([]KvPair, 0)
  1339. for k, v := range mapArticleIdLabelTotal {
  1340. tmpList = append(tmpList, KvPair{Key: k, Val: v})
  1341. }
  1342. sort.Slice(tmpList, func(i, j int) bool {
  1343. return tmpList[i].Val > tmpList[j].Val // 降序
  1344. })
  1345. for _, v := range tmpList {
  1346. if v.Key != "" {
  1347. mapLabels[v.Key] = v.Key
  1348. item := new(cygx.UserLabel)
  1349. item.Label = v.Key
  1350. labelsListStr = append(labelsListStr, item)
  1351. }
  1352. }
  1353. var labelNew string
  1354. for _, v := range labelsListStr {
  1355. labelNew += v.Label + ","
  1356. }
  1357. labelNew = strings.TrimRight(labelNew, ",")
  1358. resp := new(cygx.UserLabel)
  1359. resp.Label = labelNew
  1360. br.Ret = 200
  1361. br.Success = true
  1362. br.Msg = "获取成功"
  1363. br.Data = resp
  1364. }
  1365. // @Title 状态搜索栏
  1366. // @Description 状态搜索栏接口
  1367. // @Success 200 {object} cygx.CygxUserTableStatusListRep
  1368. // @router /user/status/table [get]
  1369. func (this *UserController) StatusTable() {
  1370. br := new(models.BaseResponse).Init()
  1371. defer func() {
  1372. this.Data["json"] = br
  1373. this.ServeJSON()
  1374. }()
  1375. sysUser := this.SysUser
  1376. if sysUser == nil {
  1377. br.Msg = "请登录"
  1378. br.ErrMsg = "请登录,SysUser Is Empty"
  1379. br.Ret = 408
  1380. return
  1381. }
  1382. listType := []*cygx.CygxTryStageRep{{Name: "大套餐", TryStage: 1}, {Name: "小套餐", TryStage: 2}}
  1383. listStatus := []*cygx.CygxTryStageRep{{Name: "未分类", TryStage: 1}, {Name: "推进", TryStage: 2}, {Name: "跟踪", TryStage: 3}, {Name: "预备", TryStage: 4}}
  1384. List := []*cygx.CygxUserTableStatusRep{{Name: "正式", List: listType, TryStage: "正式"}, {Name: "试用", List: listStatus, TryStage: "试用"}, {Name: "冻结", List: []*cygx.CygxTryStageRep{}, TryStage: "冻结"}, {Name: "X类试用", List: []*cygx.CygxTryStageRep{}, TryStage: "X类试用"}}
  1385. resp := new(cygx.CygxUserTableStatusListRep)
  1386. resp.List = List
  1387. br.Ret = 200
  1388. br.Success = true
  1389. br.Msg = "获取成功"
  1390. br.Data = resp
  1391. }
  1392. // @Title 用户互动量
  1393. // @Description 状态搜索栏接口
  1394. // @Param UserId query int true "用户id"
  1395. // @Success 200 {object} cygx.CygxUserTableStatusListRep
  1396. // @router /user/interactionNum [get]
  1397. func (this *UserController) InteractionNum() {
  1398. br := new(models.BaseResponse).Init()
  1399. defer func() {
  1400. this.Data["json"] = br
  1401. this.ServeJSON()
  1402. }()
  1403. sysUser := this.SysUser
  1404. if sysUser == nil {
  1405. br.Msg = "请登录"
  1406. br.ErrMsg = "请登录,SysUser Is Empty"
  1407. br.Ret = 408
  1408. return
  1409. }
  1410. userId, _ := this.GetInt("UserId")
  1411. if userId < 1 {
  1412. br.Msg = "用户不存在"
  1413. return
  1414. }
  1415. wxUser, err := models.GetWxUserByUserId(userId)
  1416. if err != nil {
  1417. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  1418. br.Msg = "获取信息失败"
  1419. return
  1420. }
  1421. cp, err := company.GetCompanyProductByCompanyIdAndProductId(wxUser.CompanyId, 2)
  1422. if err != nil && err.Error() != utils.ErrNoRow() {
  1423. br.Msg = "获取客户信息失败"
  1424. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  1425. return
  1426. }
  1427. resp := new(cygx.CygxCygxInteractionNumRespListResp)
  1428. for i := 0; i < 4; i++ {
  1429. item := new(cygx.CygxInteractionNumResp)
  1430. if cp != nil && cp.Status == "正式" {
  1431. //阅读记录总数
  1432. var startDate, endDate string
  1433. item.DateTime = time.Now().AddDate(0, -i, 0).Format("2006.01")
  1434. startDate = utils.GetOneMonthFirstDay(time.Now().AddDate(0, -i, 0)).Format(utils.FormatDate)
  1435. endDate = utils.GetOneMonthLastDay(time.Now().AddDate(0, -i, 0)).Format(utils.FormatDate)
  1436. countDetail, err := cygx.GetCompanyInteractionTableCountBytime(wxUser.CompanyId, startDate, endDate)
  1437. if err != nil {
  1438. br.Msg = "获取信息失败"
  1439. br.ErrMsg = "获取各个阅读总数失败,Err:" + err.Error()
  1440. return
  1441. }
  1442. item.InteractionNum = countDetail.HistoryNum + countDetail.CountNum + countDetail.IndustryFllowNum + countDetail.DepartmentFollowNum + countDetail.KeyWordNum + countDetail.OnLineNum + countDetail.OfficeNum + countDetail.ChartNum
  1443. } else {
  1444. var weekStr string
  1445. switch i {
  1446. case 0:
  1447. weekStr = "本周("
  1448. case 1:
  1449. weekStr = "上周("
  1450. case 2:
  1451. weekStr = "上两周("
  1452. case 3:
  1453. weekStr = "上三周("
  1454. }
  1455. item.DateTime = weekStr + utils.GetNowWeekMonday().AddDate(0, 0, -i*7).Format("01.02") + "~" + utils.GetNowWeekMonday().AddDate(0, 0, -i*7+6).Format("01.02") + ")"
  1456. var startDate, endDate string
  1457. startDate = utils.GetNowWeekMonday().AddDate(0, 0, -i*7).Format(utils.FormatDate)
  1458. endDate = utils.GetNowWeekMonday().AddDate(0, 0, -i*7+6).Format(utils.FormatDate)
  1459. countDetail, err := cygx.GetCompanyInteractionTableCountBytime(wxUser.CompanyId, startDate, endDate)
  1460. if err != nil {
  1461. br.Msg = "获取信息失败"
  1462. br.ErrMsg = "获取各个阅读总数失败,Err:" + err.Error()
  1463. return
  1464. }
  1465. item.InteractionNum = countDetail.HistoryNum + countDetail.CountNum + countDetail.IndustryFllowNum + countDetail.DepartmentFollowNum + countDetail.KeyWordNum + countDetail.OnLineNum + countDetail.OfficeNum + countDetail.ChartNum + countDetail.TripNum + countDetail.RoadshowVideoNum + countDetail.ActivityVideoNum + countDetail.ActivityVoiceNum
  1466. }
  1467. resp.List = append(resp.List, item)
  1468. }
  1469. br.Ret = 200
  1470. br.Success = true
  1471. br.Msg = "获取成功"
  1472. br.Data = resp
  1473. }
  1474. // @Title 标签检索用户相关互动
  1475. // @Description 标签检索用户相关互动接口
  1476. // @Param UserId query int true "用户id"
  1477. // @Param KeyWord query string true "搜索关键词"
  1478. // @Param Source query int true "来源 1:报告阅读,2:报告收藏,3:相关活动,4:专项产业调研"
  1479. // @Success 200 {object} cygx.UserInteractionrelevantListResp
  1480. // @router /user/interaction/relevant [get]
  1481. func (this *UserController) InteractionRelevant() {
  1482. br := new(models.BaseResponse).Init()
  1483. defer func() {
  1484. this.Data["json"] = br
  1485. this.ServeJSON()
  1486. }()
  1487. sysUser := this.SysUser
  1488. if sysUser == nil {
  1489. br.Msg = "请登录"
  1490. br.ErrMsg = "请登录,SysUser Is Empty"
  1491. br.Ret = 408
  1492. return
  1493. }
  1494. userId, _ := this.GetInt("UserId")
  1495. source, _ := this.GetInt("Source")
  1496. keyWord := this.GetString("KeyWord")
  1497. if userId < 1 {
  1498. br.Msg = "用户不存在"
  1499. return
  1500. }
  1501. wxUser, err := models.GetWxUserByUserId(userId)
  1502. if err != nil {
  1503. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  1504. br.Msg = "获取信息失败"
  1505. return
  1506. }
  1507. managementIds, err := cygx.GetManagementIdsByName(keyWord)
  1508. if err != nil {
  1509. br.Msg = "获取信息失败"
  1510. br.ErrMsg = "获取产业信息失败,Err:" + err.Error()
  1511. return
  1512. }
  1513. subjectIds, err := cygx.GetIndustrialSubjectIdsByName(keyWord)
  1514. if err != nil {
  1515. br.Msg = "获取信息失败"
  1516. br.ErrMsg = "获取标的信息失败,Err:" + err.Error()
  1517. return
  1518. }
  1519. resp := new(cygx.UserInteractionrelevantListResp)
  1520. var condition string
  1521. if source == 1 || source == 2 {
  1522. var articleIds string
  1523. if managementIds != "" || subjectIds != "" {
  1524. var articleIdmanagement string
  1525. var articleIdsubject string
  1526. if managementIds != "" {
  1527. articleIdmanagement, err = cygx.GetArticleIdsByIndustrialManagementId(managementIds)
  1528. if err != nil {
  1529. br.Msg = "获取信息失败"
  1530. br.ErrMsg = "获取活动ID信息失败,Err:" + err.Error()
  1531. return
  1532. }
  1533. }
  1534. if subjectIds != "" {
  1535. articleIdsubject, err = cygx.GetArticleIdsBySubjectId(subjectIds)
  1536. if err != nil {
  1537. br.Msg = "获取信息失败"
  1538. br.ErrMsg = "获取活动ID信息失败,Err:" + err.Error()
  1539. return
  1540. }
  1541. }
  1542. if articleIdmanagement != "" && articleIdsubject != "" {
  1543. articleIds = articleIdmanagement + "," + articleIdsubject
  1544. } else if articleIdmanagement != "" && articleIdsubject == "" {
  1545. articleIds = articleIdmanagement
  1546. } else if articleIdmanagement == "" && articleIdsubject != "" {
  1547. articleIds = articleIdsubject
  1548. }
  1549. } else {
  1550. matchDetail, err := cygx.GetCygxReportMappingCygxDetailByName(keyWord)
  1551. if err != nil && err.Error() != utils.ErrNoRow() {
  1552. br.Msg = "获取信息失败"
  1553. br.ErrMsg = "GetCygxReportMappingCygxDetail,Err:" + err.Error()
  1554. return
  1555. }
  1556. if matchDetail != nil {
  1557. var condition string
  1558. var pars []interface{}
  1559. condition = ` AND id_cygx = ? `
  1560. pars = append(pars, matchDetail.Id)
  1561. listGroup, err := cygx.GetCygxReportMappingGroupList(condition, pars, 0, 999)
  1562. if err != nil && err.Error() != utils.ErrNoRow() {
  1563. br.Msg = "获取失败"
  1564. br.ErrMsg = "获取失败,Err:" + err.Error()
  1565. return
  1566. }
  1567. var categoryIds []int
  1568. for _, v := range listGroup {
  1569. categoryIds = append(categoryIds, v.CategoryIdCelue)
  1570. }
  1571. pars = make([]interface{}, 0)
  1572. condition = ` AND category_id IN (` + utils.GetOrmInReplace(len(categoryIds)) + `)`
  1573. pars = append(pars, categoryIds)
  1574. listArticle, err := cygx.GetArticlList(condition, pars, 0, 999)
  1575. if err != nil && err.Error() != utils.ErrNoRow() {
  1576. br.Msg = "获取失败"
  1577. br.ErrMsg = "获取失败,Err:" + err.Error()
  1578. return
  1579. }
  1580. for _, v := range listArticle {
  1581. articleIds += strconv.Itoa(v.ArticleId) + ","
  1582. }
  1583. articleIds = strings.TrimRight(articleIds, ",")
  1584. }
  1585. }
  1586. if articleIds != "" {
  1587. condition = ` AND r.article_id IN (` + articleIds + `)`
  1588. if source == 1 {
  1589. condition += ` AND r.stop_time > 4 `
  1590. resp.List, err = cygx.GetCygxArticleHistoryRecordByUser(wxUser.Mobile, wxUser.Email, condition, 0, 0)
  1591. } else {
  1592. resp.List, err = cygx.GetCygxArticleCollectByUser(userId, 0, 0, condition)
  1593. }
  1594. if err != nil && err.Error() != utils.ErrNoRow() {
  1595. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  1596. br.Msg = "获取用户阅读记录"
  1597. return
  1598. }
  1599. if len(resp.List) > 0 {
  1600. for k, v := range resp.List {
  1601. resp.List[k].RegisterPlatform = cygxService.GetArticleSourcePlatform(v.SourcePlatform)
  1602. resp.List[k].RegisterPlatformText = cygxService.GetArticleSourcePlatformText(v.RegisterPlatform)
  1603. if v.ArticleId >= utils.SummaryArticleId {
  1604. resp.List[k].ArticleType = 1
  1605. } else {
  1606. resp.List[k].ArticleType = 2
  1607. }
  1608. }
  1609. }
  1610. }
  1611. } else if source == 3 {
  1612. activityIdByLabel, err := cygx.GetactivityIdsByLabel(keyWord)
  1613. if err != nil {
  1614. br.Msg = "获取信息失败"
  1615. br.ErrMsg = "获取活动ID信息失败,Err:" + err.Error()
  1616. return
  1617. }
  1618. activityId := activityIdByLabel
  1619. if activityId != "" {
  1620. condition = ` AND s.is_meeting = 1 AND s.activity_id IN (` + activityId + `) AND s.mobile = ` + wxUser.Mobile
  1621. resp.List, err = cygx.GetActivityMeetByUser(condition, 0, 0)
  1622. if err != nil && err.Error() != utils.ErrNoRow() {
  1623. br.Msg = "获取信息失败"
  1624. br.ErrMsg = "获取用户搜藏记录失败,Err:" + err.Error()
  1625. return
  1626. }
  1627. }
  1628. } else if source == 4 {
  1629. activityIdByLabel, err := cygx.GetactivitySpecilIdsByLabel(keyWord)
  1630. if err != nil {
  1631. br.Msg = "获取信息失败"
  1632. br.ErrMsg = "获取活动ID信息失败,Err:" + err.Error()
  1633. return
  1634. }
  1635. activityId := activityIdByLabel
  1636. if activityId != "" {
  1637. condition = ` AND s.is_meeting = 1 AND s.activity_id IN (` + activityId + `) AND s.mobile = ` + wxUser.Mobile
  1638. resp.List, err = cygx.GetActivitySpecialMeetByUser(condition, 0, 0)
  1639. if err != nil && err.Error() != utils.ErrNoRow() {
  1640. br.Msg = "获取信息失败"
  1641. br.ErrMsg = "获取用户搜藏记录失败,Err:" + err.Error()
  1642. return
  1643. }
  1644. }
  1645. }
  1646. if len(resp.List) == 0 {
  1647. resp.List = make([]*cygx.UserInteraction, 0)
  1648. }
  1649. resp.IndustryName = keyWord
  1650. if managementIds != "" {
  1651. count, err := cygx.GetCygxIndustryFllowCountByUser(userId, managementIds)
  1652. if err != nil {
  1653. br.Msg = "获取信息失败"
  1654. br.ErrMsg = "获取用户是否关注失败,Err:" + err.Error()
  1655. return
  1656. }
  1657. if count > 0 {
  1658. resp.IsFllow = true
  1659. }
  1660. }
  1661. br.Ret = 200
  1662. br.Success = true
  1663. br.Msg = "获取成功"
  1664. br.Data = resp
  1665. }
  1666. // @Title 用户相关互动下载
  1667. // @Description 用户相关互动下载接口
  1668. // @Param UserId query int true "用户id"
  1669. // @Param Source query int true "来源 报告阅读列表: 1, 活动互动记录: 2"
  1670. // @Param IsMeeting query string true "是否到会 1到会、2未到会"
  1671. // @Param MeetType query string true "参会方式 1线上,2线下 默认为线上"
  1672. // @Param StartDate query string true "开始时间"
  1673. // @Param EndDate query string true "结束时间"
  1674. // @Param KeyWord query string true "搜索关键词"
  1675. // @Success 200 {object} cygx.CygxUserTableStatusListRep
  1676. // @router /user/export/interaction [get]
  1677. func (this *UserController) ExportInteraction() {
  1678. br := new(models.BaseResponse).Init()
  1679. defer func() {
  1680. this.Data["json"] = br
  1681. this.ServeJSON()
  1682. }()
  1683. sysUser := this.SysUser
  1684. if sysUser == nil {
  1685. br.Msg = "请登录"
  1686. br.ErrMsg = "请登录,SysUser Is Empty"
  1687. br.Ret = 408
  1688. return
  1689. }
  1690. userId, _ := this.GetInt("UserId")
  1691. isMeeting := this.GetString("IsMeeting")
  1692. meetType := this.GetString("MeetType")
  1693. startDate := this.GetString("StartDate")
  1694. endDate := this.GetString("EndDate")
  1695. keyWord := this.GetString("KeyWord")
  1696. source, _ := this.GetInt("Source")
  1697. if userId < 1 {
  1698. br.Msg = "用户不存在"
  1699. return
  1700. }
  1701. wxUser, err := models.GetWxUserByUserId(userId)
  1702. if err != nil {
  1703. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  1704. br.Msg = "获取信息失败"
  1705. return
  1706. }
  1707. mobile := wxUser.Mobile
  1708. var list []*cygx.UserInteraction
  1709. var condition string
  1710. var sheetName string
  1711. if source == 1 {
  1712. sheetName = "报告阅读列表"
  1713. if startDate != "" {
  1714. startDate += " 00:00:00"
  1715. condition += ` AND r.create_time >= '` + startDate + `' `
  1716. }
  1717. if endDate != "" {
  1718. endDate += " 23:59:59"
  1719. condition += ` AND r.create_time <= '` + endDate + `' `
  1720. }
  1721. if wxUser.Mobile == "" {
  1722. wxUser.Mobile = wxUser.Email
  1723. }
  1724. //total, err = cygx.GetCygxArticleHistoryCount(wxUser.Mobile, wxUser.Email, condition)
  1725. //if err != nil {
  1726. // br.Msg = "获取信息失败"
  1727. // br.ErrMsg = "获取用户阅读记录总数失败,Err:" + err.Error()
  1728. // return
  1729. //}
  1730. condition += " AND (r.mobile = '" + wxUser.Mobile + "' OR r.email = '" + wxUser.Mobile + "') "
  1731. _, list, err = cygx.GetCygxArticleHistoryRecordByUserNew(condition, 0, 9999)
  1732. if err != nil && err.Error() != utils.ErrNoRow() {
  1733. br.Msg = "获取信息失败"
  1734. br.ErrMsg = "获取用户阅读记录,Err:" + err.Error()
  1735. return
  1736. }
  1737. var articleIds []int
  1738. if len(list) > 0 {
  1739. for k, v := range list {
  1740. if v.ArticleId >= utils.SummaryArticleId {
  1741. list[k].ArticleType = 1
  1742. } else {
  1743. list[k].ArticleType = 2
  1744. }
  1745. if list[k].PermissionName == "" {
  1746. list[k].PermissionName = v.CategoryName
  1747. }
  1748. if v.SpecialType == 0 {
  1749. articleIds = append(articleIds, v.ArticleId)
  1750. }
  1751. }
  1752. mapIndustrialLabel := cygxService.GetArticleIndustrialLabelByArticleId(articleIds) // 关联产业
  1753. mapSubjectLabel := cygxService.GetArticleSubjectLabelByArticleId(articleIds) // 关联标的
  1754. for _, v := range list {
  1755. v.IndustryName = strings.Join(mapIndustrialLabel[v.ArticleId], "/")
  1756. v.SubjectNames = strings.Join(mapSubjectLabel[v.ArticleId], "/")
  1757. }
  1758. }
  1759. } else if source == 2 {
  1760. sheetName = "到会管理名单"
  1761. if mobile != "" {
  1762. condition = ` AND s.mobile = '` + mobile + `' `
  1763. if isMeeting == "1" {
  1764. condition += ` AND s.is_meeting = 1 `
  1765. }
  1766. if isMeeting == "2" {
  1767. condition += ` AND s.is_meeting = 0 `
  1768. }
  1769. if meetType == "1" {
  1770. condition += ` AND t.activity_type = 1 `
  1771. }
  1772. if meetType == "2" {
  1773. condition += ` AND t.activity_type = 0 `
  1774. }
  1775. if startDate != "" {
  1776. startDate += " 00:00:00"
  1777. condition += ` AND a.activity_time >= '` + startDate + `' `
  1778. }
  1779. if endDate != "" {
  1780. endDate += " 23:59:59"
  1781. condition += ` AND a.activity_time <= '` + endDate + `' `
  1782. }
  1783. if keyWord != "" {
  1784. condition += ` AND a.activity_name LIKE '%` + keyWord + `%' `
  1785. }
  1786. list, err = cygx.GetActivityMeetByUser(condition, 0, 0)
  1787. if err != nil && err.Error() != utils.ErrNoRow() {
  1788. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  1789. br.Msg = "获取参会人数列表失败"
  1790. return
  1791. }
  1792. if len(list) > 0 {
  1793. for k, v := range list {
  1794. if v.ActivityType == 1 {
  1795. if v.SignupType == "2" {
  1796. list[k].InteractionType = "自主拨入"
  1797. } else {
  1798. list[k].InteractionType = "预约外呼"
  1799. }
  1800. if v.ReminderNum > 0 {
  1801. list[k].InteractionType += ",会议提醒"
  1802. }
  1803. }
  1804. }
  1805. }
  1806. }
  1807. }
  1808. //创建excel
  1809. dir, err := os.Executable()
  1810. exPath := filepath.Dir(dir)
  1811. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  1812. xlsxFile := xlsx.NewFile()
  1813. if err != nil {
  1814. br.Msg = "生成文件失败"
  1815. br.ErrMsg = "生成文件失败"
  1816. return
  1817. }
  1818. style := xlsx.NewStyle()
  1819. alignment := xlsx.Alignment{
  1820. Horizontal: "center",
  1821. Vertical: "center",
  1822. WrapText: true,
  1823. }
  1824. style.Alignment = alignment
  1825. style.ApplyAlignment = true
  1826. sheet, err := xlsxFile.AddSheet(sheetName)
  1827. if err != nil {
  1828. br.Msg = "新增Sheet失败"
  1829. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  1830. return
  1831. }
  1832. if source == 1 {
  1833. //标头
  1834. rowTitle := sheet.AddRow()
  1835. cellA := rowTitle.AddCell()
  1836. cellA.Value = "报告标题"
  1837. cellB := rowTitle.AddCell()
  1838. cellB.Value = "所属行业"
  1839. cellC := rowTitle.AddCell()
  1840. cellC.Value = "所属产业"
  1841. cellD := rowTitle.AddCell()
  1842. cellD.Value = "关联标的"
  1843. cellE := rowTitle.AddCell()
  1844. cellE.Value = "发布时间"
  1845. cellF := rowTitle.AddCell()
  1846. cellF.Value = "阅读时间"
  1847. cellG := rowTitle.AddCell()
  1848. cellG.Value = "阅读时长"
  1849. for _, item := range list {
  1850. row := sheet.AddRow()
  1851. cellA := row.AddCell()
  1852. cellA.Value = item.Title
  1853. cellB := row.AddCell()
  1854. cellB.Value = item.PermissionName
  1855. cellC := row.AddCell()
  1856. cellC.Value = item.IndustryName
  1857. cellD := row.AddCell()
  1858. cellD.Value = item.SubjectNameStr
  1859. cellE := row.AddCell()
  1860. cellE.Value = item.PublishDate
  1861. cellF := row.AddCell()
  1862. cellF.Value = item.CreateTime
  1863. cellG := row.AddCell()
  1864. cellG.Value = item.StopTime
  1865. }
  1866. } else {
  1867. //标头
  1868. rowTitle := sheet.AddRow()
  1869. cellA := rowTitle.AddCell()
  1870. cellA.Value = "活动名称"
  1871. cellB := rowTitle.AddCell()
  1872. cellB.Value = "所属行业"
  1873. cellC := rowTitle.AddCell()
  1874. cellC.Value = "活动类型"
  1875. cellD := rowTitle.AddCell()
  1876. cellD.Value = "活动主题"
  1877. cellE := rowTitle.AddCell()
  1878. cellE.Value = "活动时间"
  1879. cellF := rowTitle.AddCell()
  1880. cellF.Value = "是否到会"
  1881. cellG := rowTitle.AddCell()
  1882. cellG.Value = "首次入会时间"
  1883. cellH := rowTitle.AddCell()
  1884. cellH.Value = "最后退出时间"
  1885. cellI := rowTitle.AddCell()
  1886. cellI.Value = "参与总时长"
  1887. cellJ := rowTitle.AddCell()
  1888. cellJ.Value = "参会方式"
  1889. cellK := rowTitle.AddCell()
  1890. cellK.Value = "参会权鉴"
  1891. cellL := rowTitle.AddCell()
  1892. cellL.Value = "参会状态"
  1893. for _, item := range list {
  1894. row := sheet.AddRow()
  1895. cellA := row.AddCell()
  1896. cellA.Value = item.ActivityName
  1897. cellB := row.AddCell()
  1898. cellB.Value = item.PermissionName
  1899. cellC := row.AddCell()
  1900. cellC.Value = item.ActivityTypeName
  1901. cellD := row.AddCell()
  1902. cellD.Value = item.Label
  1903. cellE := row.AddCell()
  1904. cellE.Value = item.ActivityTime
  1905. cellF := row.AddCell()
  1906. if item.IsMeeting == 1 {
  1907. cellF.Value = "到会"
  1908. } else {
  1909. cellF.Value = "未到会"
  1910. }
  1911. cellG := row.AddCell()
  1912. cellG.Value = item.FirstMeetingTime
  1913. cellH := row.AddCell()
  1914. cellH.Value = item.LastMeetingTime
  1915. cellI := row.AddCell()
  1916. cellI.Value = item.Duration
  1917. cellJ := row.AddCell()
  1918. cellJ.Value = item.LastMeetingTime
  1919. cellK := row.AddCell()
  1920. cellK.Value = item.MeetingTypeStr
  1921. cellL := row.AddCell()
  1922. cellL.Value = item.MeetingStatusStr
  1923. }
  1924. }
  1925. err = xlsxFile.Save(downLoadnFilePath)
  1926. if err != nil {
  1927. br.Msg = "保存文件失败"
  1928. br.ErrMsg = "保存文件失败"
  1929. return
  1930. }
  1931. randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
  1932. downloadFileName := wxUser.RealName + randStr + ".xlsx"
  1933. this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  1934. defer func() {
  1935. os.Remove(downLoadnFilePath)
  1936. }()
  1937. br.Ret = 200
  1938. br.Success = true
  1939. br.Msg = "获取成功"
  1940. }
  1941. // @Title 机构互动详情table栏
  1942. // @Description 互动详情table栏接口
  1943. // @Param CompanyId query int true "公司ID"
  1944. // @Param ClassType query int true "列表类型,1:权益,2:研选,默认1"
  1945. // @Success 200 {object} cygx.UserRemarksListResp
  1946. // @router /user/company/table/list [get]
  1947. func (this *UserController) CompanyTableList() {
  1948. br := new(models.BaseResponse).Init()
  1949. defer func() {
  1950. this.Data["json"] = br
  1951. this.ServeJSON()
  1952. }()
  1953. sysUser := this.SysUser
  1954. if sysUser == nil {
  1955. br.Msg = "请登录"
  1956. br.ErrMsg = "请登录,SysUser Is Empty"
  1957. br.Ret = 408
  1958. return
  1959. }
  1960. companyId, _ := this.GetInt("CompanyId")
  1961. classType, _ := this.GetInt("ClassType", 1)
  1962. if companyId < 1 {
  1963. br.Msg = "机构不存在"
  1964. return
  1965. }
  1966. comanyDetail, err := company.GetCompanyDetailById(companyId)
  1967. if err != nil {
  1968. br.Msg = "获取信息失败"
  1969. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1970. return
  1971. }
  1972. resp := new(cygx.CygxUserTableListRep)
  1973. var isAdminRole bool
  1974. //如果不是管理员身份或者研究员身份则需要添加可见范围处理
  1975. if sysUser.Role == utils.ROLE_TYPE_CODE_ADMIN || sysUser.Role == utils.ROLE_TYPE_CODE_RESEARCHR {
  1976. isAdminRole = true
  1977. }
  1978. var pars []interface{}
  1979. condition := ` AND r.company_id IN ( ` + strconv.Itoa(companyId) + ` ) AND r.create_time < '` + time.Now().Format(utils.FormatDate) + `' ` //过滤当天时间
  1980. //totalEs, _, err := services.SearcCygxArticleHistoryData(utils.IndexNameArticleHistory, "", "", "", strconv.Itoa(companyId), 0, 0)
  1981. //if err != nil {
  1982. // br.Msg = "获取信息失败"
  1983. // br.ErrMsg = "获取Es文章阅读数量失败,Err:" + err.Error()
  1984. // return
  1985. //}
  1986. conditionArtcile := condition //文章搜索条件
  1987. conditionActivityMeet := condition //活动到会搜索条件
  1988. conditionIndustryFllow := condition //产业关注搜索条件
  1989. conditionKeyWord := condition //关键词记录搜索条件
  1990. if classType == 1 {
  1991. conditionArtcile += " AND art.article_type_id = 0 "
  1992. conditionActivityMeet += " AND a.chart_permission_id != 31 "
  1993. conditionIndustryFllow += " AND m.chart_permission_id != 31 "
  1994. conditionKeyWord += " AND r.register_platform IN (1,2) "
  1995. } else {
  1996. conditionArtcile += " AND art.article_type_id > 0 "
  1997. conditionActivityMeet += " AND a.chart_permission_id = 31 "
  1998. conditionIndustryFllow += " AND m.chart_permission_id = 31 "
  1999. conditionKeyWord += " AND r.register_platform IN (5,6) "
  2000. }
  2001. var historyNum int //报告阅读列表
  2002. var activityNum int //活动互动记录
  2003. var triptotal int //专项调研
  2004. var articleCollect int //收藏的报告
  2005. var chartNum int //收藏图表
  2006. var industryFllowNum int //关注的产业
  2007. var departmentFollowNum int //关注的作者
  2008. var keyWordNum int //搜索
  2009. var roadshowTotal int //音视频播放
  2010. var tagNum int //首页标签点击
  2011. var yanxuanSpecialNum int //专栏文章阅读记录
  2012. var yanxuanSpecialCollectNum int //收藏的专栏文章
  2013. var yanxuanSpecialFollowNum int //关注的专栏作者
  2014. if isAdminRole {
  2015. historyNum, err = cygx.GetCygxArticleAndYanxuanRecordCount(conditionArtcile, pars)
  2016. if err != nil {
  2017. br.Msg = "获取信息失败"
  2018. br.ErrMsg = "获取用户阅读记录数量失败,Err:" + err.Error()
  2019. return
  2020. }
  2021. activityNum, err = cygx.GetActivityMeetByCompanyCount(conditionActivityMeet)
  2022. if err != nil {
  2023. br.Msg = "获取信息失败"
  2024. br.ErrMsg = "获取参会总数失败,Err:" + err.Error()
  2025. return
  2026. }
  2027. //获取用户收藏记录总数
  2028. articleCollect, err = cygx.GetCygxArticleCollectCountByCompany(conditionArtcile)
  2029. if err != nil {
  2030. br.Msg = "获取信息失败"
  2031. br.ErrMsg = "获取用户收藏记录总数失败,Err:" + err.Error()
  2032. return
  2033. }
  2034. //获取用户关注总数
  2035. industryFllowNum, err = cygx.GetCygxIndustryFllowCountByCompany(conditionIndustryFllow)
  2036. if err != nil {
  2037. br.Msg = "获取信息失败 "
  2038. br.ErrMsg = "获取用户关注总数失败,Err:" + err.Error()
  2039. return
  2040. }
  2041. //获取关注作者总数
  2042. departmentFollowNum, err = cygx.GetCygArticleDepartmentFollowCountByCompany(condition)
  2043. if err != nil {
  2044. br.Msg = "获取信息失败"
  2045. br.ErrMsg = "获取关注作者总数失败,Err:" + err.Error()
  2046. return
  2047. }
  2048. //获取搜索记录
  2049. keyWordNum, err = cygx.GetCygxSearchKeyWordCountBuCompany(conditionKeyWord)
  2050. if err != nil {
  2051. br.Msg = "获取信息失败"
  2052. br.ErrMsg = "获取搜索记录失败,Err:" + err.Error()
  2053. return
  2054. }
  2055. chartNum, err = cygx.GetChartCountByUserMobile(condition)
  2056. if err != nil {
  2057. br.Msg = "获取信息失败"
  2058. br.ErrMsg = "获取总数失败,Err:" + err.Error()
  2059. return
  2060. }
  2061. triptotal, err = cygx.GetCygxActivitySpecialTripCountByCompany(condition)
  2062. if err != nil {
  2063. br.Msg = "获取信息失败"
  2064. br.ErrMsg = "获取搜索记录失败,Err:" + err.Error()
  2065. return
  2066. }
  2067. roadshowTotal, err = cygx.GetCygxRoadshowCountByCompany(condition)
  2068. if err != nil {
  2069. br.Msg = "获取信息失败"
  2070. br.ErrMsg = "获取搜索记录失败,Err:" + err.Error()
  2071. return
  2072. }
  2073. tagNum, err = cygx.GetCygxTagHistoryCount(condition)
  2074. if err != nil {
  2075. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  2076. br.Msg = "获取搜索记录失败"
  2077. return
  2078. }
  2079. yanxuanSpecialNum, err = cygx.GetCygxYanxuanSpecialRecordCount(condition, pars)
  2080. if err != nil {
  2081. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  2082. br.Msg = "获取研选专栏阅读数量失败"
  2083. return
  2084. }
  2085. yanxuanSpecialCollectNum, err = cygx.GetCygxYanxuanSpecialCollectCount(condition, pars)
  2086. if err != nil {
  2087. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  2088. br.Msg = "获取收藏的专栏文章数量失败"
  2089. return
  2090. }
  2091. yanxuanSpecialFollowNum, err = cygx.GetCygxYanxuanSpecialFollowCount(condition, pars)
  2092. if err != nil {
  2093. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  2094. br.Msg = "获取关注的专栏作者数量失败"
  2095. return
  2096. }
  2097. } else {
  2098. historyNum, err = cygx.GetCygxArticleAndYanxuanRecordCountWeekly(conditionArtcile, pars)
  2099. if err != nil {
  2100. br.Msg = "获取信息失败"
  2101. br.ErrMsg = "获取用户阅读记录数量失败,Err:" + err.Error()
  2102. return
  2103. }
  2104. activityNum, err = cygx.GetActivityMeetByCompanyCountWeekly(conditionActivityMeet)
  2105. if err != nil {
  2106. br.Msg = "获取信息失败"
  2107. br.ErrMsg = "获取参会总数失败,Err:" + err.Error()
  2108. return
  2109. }
  2110. //获取用户收藏记录总数
  2111. articleCollect, err = cygx.GetCygxArticleCollectCountByCompanyWeekly(conditionArtcile)
  2112. if err != nil {
  2113. br.Msg = "获取信息失败"
  2114. br.ErrMsg = "获取用户收藏记录总数失败,Err:" + err.Error()
  2115. return
  2116. }
  2117. //获取用户关注总数
  2118. industryFllowNum, err = cygx.GetCygxIndustryFllowCountByCompanyWeekly(condition)
  2119. if err != nil {
  2120. br.Msg = "获取信息失败 "
  2121. br.ErrMsg = "获取用户关注总数失败,Err:" + err.Error()
  2122. return
  2123. }
  2124. //获取关注作者总数
  2125. departmentFollowNum, err = cygx.GetCygArticleDepartmentFollowCountByCompanyWeekly(condition)
  2126. if err != nil {
  2127. br.Msg = "获取信息失败"
  2128. br.ErrMsg = "获取关注作者总数失败,Err:" + err.Error()
  2129. return
  2130. }
  2131. //获取搜索记录
  2132. keyWordNum, err = cygx.GetCygxSearchKeyWordCountBuCompanyWeekly(conditionKeyWord)
  2133. if err != nil {
  2134. br.Msg = "获取信息失败"
  2135. br.ErrMsg = "获取搜索记录失败,Err:" + err.Error()
  2136. return
  2137. }
  2138. chartNum, err = cygx.GetChartCountByUserMobileWeekly(condition)
  2139. if err != nil {
  2140. br.Msg = "获取信息失败"
  2141. br.ErrMsg = "获取总数失败,Err:" + err.Error()
  2142. return
  2143. }
  2144. triptotal, err = cygx.GetCygxActivitySpecialTripCountByCompanyWeekly(condition)
  2145. if err != nil {
  2146. br.Msg = "获取信息失败"
  2147. br.ErrMsg = "获取搜索记录失败,Err:" + err.Error()
  2148. return
  2149. }
  2150. roadshowTotal, err = cygx.GetCygxRoadshowCountByCompanyWeekly(condition)
  2151. if err != nil {
  2152. br.Msg = "获取信息失败"
  2153. br.ErrMsg = "获取搜索记录失败,Err:" + err.Error()
  2154. return
  2155. }
  2156. tagNum, err = cygx.GetCygxTagHistoryCountWeekly(condition)
  2157. if err != nil {
  2158. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  2159. br.Msg = "获取搜索记录失败"
  2160. return
  2161. }
  2162. yanxuanSpecialNum, err = cygx.GetCygxYanxuanSpecialRecordCountWeekly(condition, pars)
  2163. if err != nil {
  2164. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  2165. br.Msg = "获取研选专栏阅读数量失败"
  2166. return
  2167. }
  2168. yanxuanSpecialCollectNum, err = cygx.GetCygxYanxuanSpecialCollectCountWeekly(condition, pars)
  2169. if err != nil {
  2170. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  2171. br.Msg = "获取收藏的专栏文章数量失败"
  2172. return
  2173. }
  2174. yanxuanSpecialFollowNum, err = cygx.GetCygxYanxuanSpecialFollowCountWeekly(condition, pars)
  2175. if err != nil {
  2176. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  2177. br.Msg = "获取关注的专栏作者数量失败"
  2178. return
  2179. }
  2180. }
  2181. if classType == 1 {
  2182. List := []*cygx.CygxUserTableRep{{PermissionName: "报告阅读列表", Source: 1, TotalNum: historyNum},
  2183. {PermissionName: "活动互动记录", Source: 2, TotalNum: activityNum},
  2184. {PermissionName: "专项调研", Source: 8, TotalNum: triptotal},
  2185. {PermissionName: "收藏的报告", Source: 3, TotalNum: articleCollect},
  2186. {PermissionName: "收藏图表", Source: 4, TotalNum: chartNum},
  2187. {PermissionName: "关注的产业", Source: 5, TotalNum: industryFllowNum},
  2188. {PermissionName: "搜索", Source: 7, TotalNum: keyWordNum},
  2189. {PermissionName: "音视频播放", Source: 9, TotalNum: roadshowTotal},
  2190. {PermissionName: "首页标签点击", Source: 10, TotalNum: tagNum}}
  2191. resp.List = List
  2192. } else {
  2193. List := []*cygx.CygxUserTableRep{{PermissionName: "报告阅读列表", Source: 1, TotalNum: historyNum},
  2194. {PermissionName: "活动互动记录", Source: 2, TotalNum: activityNum},
  2195. {PermissionName: "收藏的报告", Source: 3, TotalNum: articleCollect},
  2196. {PermissionName: "关注的产业", Source: 5, TotalNum: industryFllowNum},
  2197. {PermissionName: "关注的作者", Source: 6, TotalNum: departmentFollowNum},
  2198. {PermissionName: "专栏文章阅读记录", Source: 11, TotalNum: yanxuanSpecialNum},
  2199. {PermissionName: "收藏的专栏文章", Source: 12, TotalNum: yanxuanSpecialCollectNum},
  2200. {PermissionName: "关注的专栏作者", Source: 13, TotalNum: yanxuanSpecialFollowNum}}
  2201. resp.List = List
  2202. }
  2203. resp.ComapnyName = comanyDetail.CompanyName
  2204. br.Ret = 200
  2205. br.Success = true
  2206. br.Msg = "获取成功"
  2207. br.Data = resp
  2208. }
  2209. // @Title 机构互动详情
  2210. // @Description 机构互动详情接口
  2211. // @Param CompanyId query int true "公司ID"
  2212. // @Param Source query int true "来源"
  2213. // @Param IsMeeting query string false "是否到会 1到会、2未到会"
  2214. // @Param MeetType query string false "参会方式 1线上,2线下 默认为线上"
  2215. // @Param PageSize query int true "每页数据条数"
  2216. // @Param CurrentIndex query int true "当前页页码,从1开始"
  2217. // @Param StartDate query string false "开始时间"
  2218. // @Param EndDate query string false "结束时间"
  2219. // @Param KeyWord query string false "搜索关键词"
  2220. // @Param ActivityName query string false "活动名称"
  2221. // @Param ClassType query int true "列表类型,1:权益,2:研选,默认1"
  2222. // @Success 200 {object} cygx.UserInteractionListResp
  2223. // @router /user/company/interaction/detail [get]
  2224. func (this *UserController) CompanyTableDetail() {
  2225. br := new(models.BaseResponse).Init()
  2226. defer func() {
  2227. this.Data["json"] = br
  2228. this.ServeJSON()
  2229. }()
  2230. sysUser := this.SysUser
  2231. if sysUser == nil {
  2232. br.Msg = "请登录"
  2233. br.ErrMsg = "请登录,SysUser Is Empty"
  2234. br.Ret = 408
  2235. return
  2236. }
  2237. pageSize, _ := this.GetInt("PageSize")
  2238. currentIndex, _ := this.GetInt("CurrentIndex")
  2239. var startSize int
  2240. if pageSize <= 0 {
  2241. pageSize = utils.PageSize20
  2242. }
  2243. if currentIndex <= 0 {
  2244. currentIndex = 1
  2245. }
  2246. startSize = paging.StartIndex(currentIndex, pageSize)
  2247. companyId, _ := this.GetInt("CompanyId")
  2248. isMeeting := this.GetString("IsMeeting")
  2249. meetType := this.GetString("MeetType")
  2250. startDate := this.GetString("StartDate")
  2251. endDate := this.GetString("EndDate")
  2252. keyWord := this.GetString("KeyWord")
  2253. activityName := this.GetString("ActivityName")
  2254. source, _ := this.GetInt("Source")
  2255. classType, _ := this.GetInt("ClassType", 1)
  2256. if companyId < 1 {
  2257. br.Msg = "用户不存在"
  2258. return
  2259. }
  2260. fmt.Println("ClassType", classType)
  2261. // 1.标记用户表
  2262. //操作权限校验
  2263. resp := new(cygx.UserInteractionListResp)
  2264. var err error
  2265. var list []*cygx.UserInteraction
  2266. var total int
  2267. var condition string
  2268. var pars []interface{}
  2269. condition += ` AND r.company_id = ` + strconv.Itoa(companyId) + ` AND r.create_time < '` + time.Now().Format(utils.FormatDate) + `' `
  2270. if keyWord != "" {
  2271. //condition += ` AND r.mobile IN (SELECT mobile FROM wx_user WHERE mobile LIKE '%` + keyWord + `%' OR email LIKE '%` + keyWord + `%' OR real_name LIKE '%` + keyWord + `%')`
  2272. condition += ` AND ( r.mobile LIKE '%` + keyWord + `%' OR r.email LIKE '%` + keyWord + `%' OR r.real_name LIKE '%` + keyWord + `%')`
  2273. }
  2274. var isAdminRole bool
  2275. //如果不是管理员身份或者研究员身份则需要添加可见范围处理
  2276. if sysUser.Role == utils.ROLE_TYPE_CODE_ADMIN || sysUser.Role == utils.ROLE_TYPE_CODE_RESEARCHR {
  2277. isAdminRole = true
  2278. }
  2279. if source == 1 {
  2280. if startDate != "" {
  2281. startDate += " 00:00:00"
  2282. condition += ` AND r.create_time >= '` + startDate + `' `
  2283. }
  2284. if endDate != "" {
  2285. endDate += " 23:59:59"
  2286. condition += ` AND r.create_time <= '` + endDate + `' `
  2287. }
  2288. condition += " AND r.source = 'article' "
  2289. if classType == 1 {
  2290. condition += " AND art.article_type_id = 0 "
  2291. } else {
  2292. condition += " AND art.article_type_id > 0 "
  2293. }
  2294. condition += " ORDER BY r.create_time DESC "
  2295. var listRecord []*cygx.CygxArticleAndYanxuanRecordResp
  2296. if isAdminRole {
  2297. total, err = cygx.GetCygxArticleAndYanxuanRecordCount(condition, pars)
  2298. if err != nil {
  2299. br.Msg = "获取信息失败"
  2300. br.ErrMsg = "获取用户阅读记录数量失败,Err:" + err.Error()
  2301. return
  2302. }
  2303. listRecord, err = cygx.GetCygxArticleAndYanxuanRecordRespList(condition, pars, startSize, pageSize)
  2304. if err != nil && err.Error() != utils.ErrNoRow() {
  2305. br.Msg = "获取信息失败"
  2306. br.ErrMsg = "获取用户阅读记录,Err:" + err.Error()
  2307. return
  2308. }
  2309. } else {
  2310. total, err = cygx.GetCygxArticleAndYanxuanRecordCountWeekly(condition, pars)
  2311. if err != nil {
  2312. br.Msg = "获取信息失败"
  2313. br.ErrMsg = "获取用户阅读记录数量失败,Err:" + err.Error()
  2314. return
  2315. }
  2316. listRecord, err = cygx.GetCygxArticleAndYanxuanRecordRespListWeekly(condition, pars, startSize, pageSize)
  2317. if err != nil && err.Error() != utils.ErrNoRow() {
  2318. br.Msg = "获取信息失败"
  2319. br.ErrMsg = "获取用户阅读记录,Err:" + err.Error()
  2320. return
  2321. }
  2322. }
  2323. //处理查询信息回显
  2324. list, err = cygxService.HandleArticleAndYanxuanRecordList(listRecord)
  2325. if err != nil && err.Error() != utils.ErrNoRow() {
  2326. br.Msg = "获取信息失败"
  2327. br.ErrMsg = "获取用户阅读记录,Err:" + err.Error()
  2328. return
  2329. }
  2330. } else if source == 2 {
  2331. if isMeeting == "1" {
  2332. condition += ` AND r.is_meeting = 1 `
  2333. }
  2334. if isMeeting == "2" {
  2335. condition += ` AND r.is_meeting = 0 `
  2336. }
  2337. if meetType == "1" {
  2338. condition += ` AND t.activity_type = 1 `
  2339. }
  2340. if meetType == "2" {
  2341. condition += ` AND t.activity_type = 0 `
  2342. }
  2343. if startDate != "" {
  2344. startDate += " 00:00:00"
  2345. condition += ` AND a.activity_time >= '` + startDate + `' `
  2346. }
  2347. if endDate != "" {
  2348. endDate += " 23:59:59"
  2349. condition += ` AND a.activity_time <= '` + endDate + `' `
  2350. }
  2351. if activityName != "" {
  2352. condition += ` AND a.activity_name LIKE '%` + activityName + `%' `
  2353. }
  2354. if classType == 1 {
  2355. condition += " AND a.chart_permission_id != 31 "
  2356. } else {
  2357. condition += " AND a.chart_permission_id = 31 "
  2358. }
  2359. if isAdminRole {
  2360. total, err = cygx.GetActivityMeetByCompanyCount(condition)
  2361. if err != nil {
  2362. br.Msg = "获取信息失败"
  2363. br.ErrMsg = "获取参会总数失败,Err:" + err.Error()
  2364. return
  2365. }
  2366. list, err = cygx.GetActivityMeetByCompany(condition, startSize, pageSize)
  2367. if err != nil && err.Error() != utils.ErrNoRow() {
  2368. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  2369. br.Msg = "获取参会人数列表失败"
  2370. return
  2371. }
  2372. } else {
  2373. total, err = cygx.GetActivityMeetByCompanyCountWeekly(condition)
  2374. if err != nil {
  2375. br.Msg = "获取信息失败"
  2376. br.ErrMsg = "获取参会总数失败,Err:" + err.Error()
  2377. return
  2378. }
  2379. list, err = cygx.GetActivityMeetByCompanyWeekly(condition, startSize, pageSize)
  2380. if err != nil && err.Error() != utils.ErrNoRow() {
  2381. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  2382. br.Msg = "获取参会人数列表失败"
  2383. return
  2384. }
  2385. }
  2386. if len(list) > 0 {
  2387. for k, v := range list {
  2388. if v.ActivityType == 1 {
  2389. if v.SignupType == "2" {
  2390. list[k].InteractionType = "自主拨入"
  2391. } else {
  2392. list[k].InteractionType = "预约外呼"
  2393. }
  2394. if v.ReminderNum > 0 {
  2395. list[k].InteractionType += ",会议提醒"
  2396. }
  2397. }
  2398. if v.IsMeeting == 0 || v.FirstMeetingTime == "0000-00-00 00:00:00" {
  2399. list[k].FirstMeetingTime = ""
  2400. list[k].LastMeetingTime = ""
  2401. }
  2402. if v.FirstMeetingTime == "0000-00-00 00:00:00" {
  2403. list[k].FirstMeetingTime = ""
  2404. list[k].LastMeetingTime = ""
  2405. }
  2406. }
  2407. }
  2408. } else if source == 3 {
  2409. if classType == 1 {
  2410. condition += " AND art.article_type_id = 0 "
  2411. } else {
  2412. condition += " AND art.article_type_id > 0 "
  2413. }
  2414. if isAdminRole {
  2415. total, err = cygx.GetCygxArticleCollectCountByCompany(condition)
  2416. if err != nil {
  2417. br.Msg = "获取信息失败"
  2418. br.ErrMsg = "获取用户收藏记录总数失败,Err:" + err.Error()
  2419. return
  2420. }
  2421. list, err = cygx.GetCygxArticleCollectByCompany(startSize, pageSize, condition)
  2422. if err != nil && err.Error() != utils.ErrNoRow() {
  2423. br.Msg = "获取信息失败"
  2424. br.ErrMsg = "获取用户搜藏记录失败,Err:" + err.Error()
  2425. return
  2426. }
  2427. } else {
  2428. total, err = cygx.GetCygxArticleCollectCountByCompanyWeekly(condition)
  2429. if err != nil {
  2430. br.Msg = "获取信息失败"
  2431. br.ErrMsg = "获取用户收藏记录总数失败,Err:" + err.Error()
  2432. return
  2433. }
  2434. list, err = cygx.GetCygxArticleCollectByCompanyWeekly(startSize, pageSize, condition)
  2435. if err != nil && err.Error() != utils.ErrNoRow() {
  2436. br.Msg = "获取信息失败"
  2437. br.ErrMsg = "获取用户搜藏记录失败,Err:" + err.Error()
  2438. return
  2439. }
  2440. }
  2441. if len(list) > 0 {
  2442. for k, v := range list {
  2443. if v.ArticleId >= utils.SummaryArticleId {
  2444. list[k].ArticleType = 1
  2445. } else {
  2446. list[k].ArticleType = 2
  2447. }
  2448. }
  2449. }
  2450. } else if source == 4 {
  2451. if isAdminRole {
  2452. list, err = cygx.GetChartCollectList(condition)
  2453. if err != nil {
  2454. br.Msg = "获取信息失败"
  2455. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  2456. return
  2457. }
  2458. } else {
  2459. list, err = cygx.GetChartCollectListWeekly(condition)
  2460. if err != nil {
  2461. br.Msg = "获取信息失败"
  2462. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  2463. return
  2464. }
  2465. }
  2466. if len(list) > 0 {
  2467. for k, v := range list {
  2468. var err error
  2469. condition = ` AND a.publish_status = 1 AND r.company_id = ` + strconv.Itoa(companyId) + ` AND r.mobile = ` + v.Mobile + ` AND r.create_time < '` + time.Now().Format(utils.FormatDate) + `' ` //过滤当天时间
  2470. total, err = cygx.GetChartCountByUserMobile(condition)
  2471. if err != nil {
  2472. br.Msg = "获取信息失败"
  2473. br.ErrMsg = "获取总数失败,Err:" + err.Error()
  2474. return
  2475. }
  2476. listChart, err := cygx.GetChartListCollectionWithCygxByMobile(condition, 0, 18)
  2477. if err != nil {
  2478. br.Msg = "获取信息失败"
  2479. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  2480. return
  2481. }
  2482. for k, vChart := range listChart {
  2483. if vChart.PtagName != "" {
  2484. listChart[k].CtagNamePc = vChart.PtagName
  2485. }
  2486. if vChart.CtagName != "" {
  2487. listChart[k].CtagNamePc += "," + vChart.CtagName
  2488. }
  2489. if vChart.PtagNameTwo != "" {
  2490. listChart[k].CtagNamePc += "," + vChart.PtagNameTwo
  2491. }
  2492. if vChart.CtagNameTwo != "" {
  2493. listChart[k].CtagNamePc += "," + vChart.CtagNameTwo
  2494. }
  2495. }
  2496. pageChart := paging.GetPaging(currentIndex, 18, total)
  2497. list[k].ListChart = listChart
  2498. list[k].Paging = pageChart
  2499. list[k].IsEnd = pageChart.IsEnd
  2500. list[k].CurrentIndex = pageChart.CurrentIndex
  2501. }
  2502. }
  2503. } else if source == 5 {
  2504. if classType == 1 {
  2505. condition += " AND m.chart_permission_id != 31 "
  2506. } else {
  2507. condition += " AND m.chart_permission_id = 31 "
  2508. }
  2509. if isAdminRole {
  2510. total, err = cygx.GetCygxIndustryFllowCountByCompany(condition)
  2511. if err != nil {
  2512. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  2513. br.Msg = "获取用户关注总数失败"
  2514. return
  2515. }
  2516. list, err = cygx.GetCygxIndustryFllowByCompany(condition, startSize, pageSize)
  2517. if err != nil && err.Error() != utils.ErrNoRow() {
  2518. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  2519. br.Msg = "获取用户关注总数失败"
  2520. return
  2521. }
  2522. } else {
  2523. total, err = cygx.GetCygxIndustryFllowCountByCompanyWeekly(condition)
  2524. if err != nil {
  2525. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  2526. br.Msg = "获取用户关注总数失败"
  2527. return
  2528. }
  2529. if err != nil {
  2530. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  2531. br.Msg = "获取用户关注总数失败"
  2532. return
  2533. }
  2534. list, err = cygx.GetCygxIndustryFllowByCompanyWeekly(condition, startSize, pageSize)
  2535. if err != nil && err.Error() != utils.ErrNoRow() {
  2536. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  2537. br.Msg = "获取用户关注总数失败"
  2538. return
  2539. }
  2540. }
  2541. } else if source == 6 {
  2542. if isAdminRole {
  2543. total, err = cygx.GetCygArticleDepartmentFollowCountByCompany(condition)
  2544. if err != nil {
  2545. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  2546. br.Msg = "获取关注作者总数失败"
  2547. return
  2548. }
  2549. list, err = cygx.GetCygArticleDepartmentFollowByCompany(condition, startSize, pageSize)
  2550. if err != nil && err.Error() != utils.ErrNoRow() {
  2551. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  2552. br.Msg = "获取关注作者列表失败"
  2553. return
  2554. }
  2555. } else {
  2556. total, err = cygx.GetCygArticleDepartmentFollowCountByCompanyWeekly(condition)
  2557. if err != nil {
  2558. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  2559. br.Msg = "获取关注作者总数失败"
  2560. return
  2561. }
  2562. list, err = cygx.GetCygArticleDepartmentFollowByCompanyWeekly(condition, startSize, pageSize)
  2563. if err != nil && err.Error() != utils.ErrNoRow() {
  2564. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  2565. br.Msg = "获取关注作者列表失败"
  2566. return
  2567. }
  2568. }
  2569. if len(list) > 0 {
  2570. var departmentIds []int
  2571. for _, v := range list {
  2572. departmentIds = append(departmentIds, v.DepartmentId)
  2573. }
  2574. mapIndustrialLabel := cygxService.GetArticleIndustrialLabelByDepartmentId(departmentIds) // 关联产业
  2575. for _, v := range list {
  2576. v.SubjectNameStr = strings.Join(mapIndustrialLabel[v.DepartmentId], "/")
  2577. }
  2578. }
  2579. } else if source == 7 {
  2580. if classType == 1 {
  2581. condition += " AND r.register_platform IN (1,2) "
  2582. } else {
  2583. condition += " AND r.register_platform IN (5,6) "
  2584. }
  2585. if isAdminRole {
  2586. total, err = cygx.GetCygxSearchKeyWordCountBuCompany(condition)
  2587. if err != nil {
  2588. br.Msg = "获取信息失败"
  2589. br.ErrMsg = "获取搜索记录失败,Err:" + err.Error()
  2590. return
  2591. }
  2592. list, err = cygx.GetCygxSearchKeyWordByCompany(condition, startSize, pageSize)
  2593. if err != nil && err.Error() != utils.ErrNoRow() {
  2594. br.Msg = "获取信息失败"
  2595. br.ErrMsg = "获取搜索记录列表失败,Err:" + err.Error()
  2596. return
  2597. }
  2598. } else {
  2599. total, err = cygx.GetCygxSearchKeyWordCountBuCompanyWeekly(condition)
  2600. if err != nil {
  2601. br.Msg = "获取信息失败"
  2602. br.ErrMsg = "获取搜索记录失败,Err:" + err.Error()
  2603. return
  2604. }
  2605. list, err = cygx.GetCygxSearchKeyWordByCompanyWeekly(condition, startSize, pageSize)
  2606. if err != nil && err.Error() != utils.ErrNoRow() {
  2607. br.Msg = "获取信息失败"
  2608. br.ErrMsg = "获取搜索记录列表失败,Err:" + err.Error()
  2609. return
  2610. }
  2611. }
  2612. } else if source == 8 {
  2613. if isAdminRole {
  2614. total, err = cygx.GetCygxActivitySpecialTripCountByCompany(condition)
  2615. if err != nil {
  2616. br.Msg = "获取信息失败"
  2617. br.ErrMsg = "获取搜索记录失败,Err:" + err.Error()
  2618. return
  2619. }
  2620. list, err = cygx.CygxActivitySpecialTripByCompany(condition, startSize, pageSize)
  2621. if err != nil && err.Error() != utils.ErrNoRow() {
  2622. br.Msg = "获取信息失败"
  2623. br.ErrMsg = "获取搜索记录列表失败,Err:" + err.Error()
  2624. return
  2625. }
  2626. } else {
  2627. total, err = cygx.GetCygxActivitySpecialTripCountByCompanyWeekly(condition)
  2628. if err != nil {
  2629. br.Msg = "获取信息失败"
  2630. br.ErrMsg = "获取搜索记录失败,Err:" + err.Error()
  2631. return
  2632. }
  2633. list, err = cygx.CygxActivitySpecialTripByCompanyWeekly(condition, startSize, pageSize)
  2634. if err != nil && err.Error() != utils.ErrNoRow() {
  2635. br.Msg = "获取信息失败"
  2636. br.ErrMsg = "获取搜索记录列表失败,Err:" + err.Error()
  2637. return
  2638. }
  2639. }
  2640. } else if source == 9 {
  2641. if isAdminRole {
  2642. total, err = cygx.GetCygxRoadshowCountByCompany(condition)
  2643. if err != nil {
  2644. br.Msg = "获取信息失败"
  2645. br.ErrMsg = "获取搜索记录失败,Err:" + err.Error()
  2646. return
  2647. }
  2648. list, err = cygx.GetCygxRoadshowByCompany(condition, startSize, pageSize)
  2649. if err != nil && err.Error() != utils.ErrNoRow() {
  2650. br.Msg = "获取信息失败"
  2651. br.ErrMsg = "获取搜索记录列表失败,Err:" + err.Error()
  2652. return
  2653. }
  2654. } else {
  2655. total, err = cygx.GetCygxRoadshowCountByCompanyWeekly(condition)
  2656. if err != nil {
  2657. br.Msg = "获取信息失败"
  2658. br.ErrMsg = "获取搜索记录失败,Err:" + err.Error()
  2659. return
  2660. }
  2661. list, err = cygx.GetCygxRoadshowByCompanyWeekly(condition, startSize, pageSize)
  2662. if err != nil && err.Error() != utils.ErrNoRow() {
  2663. br.Msg = "获取信息失败"
  2664. br.ErrMsg = "获取搜索记录列表失败,Err:" + err.Error()
  2665. return
  2666. }
  2667. }
  2668. } else if source == 10 { //标签点击记录
  2669. if isAdminRole {
  2670. total, err = cygx.GetCygxTagHistoryCount(condition)
  2671. if err != nil {
  2672. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  2673. br.Msg = "获取搜索记录失败"
  2674. return
  2675. }
  2676. list, err = cygx.GetCygxTagHistoryListBycondition(condition, startSize, pageSize)
  2677. if err != nil && err.Error() != utils.ErrNoRow() {
  2678. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  2679. br.Msg = "获取搜索记录列表失败"
  2680. return
  2681. }
  2682. } else {
  2683. total, err = cygx.GetCygxTagHistoryCountWeekly(condition)
  2684. if err != nil {
  2685. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  2686. br.Msg = "获取搜索记录失败"
  2687. return
  2688. }
  2689. list, err = cygx.GetCygxTagHistoryListByconditionWeekly(condition, startSize, pageSize)
  2690. if err != nil && err.Error() != utils.ErrNoRow() {
  2691. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  2692. br.Msg = "获取搜索记录列表失败"
  2693. return
  2694. }
  2695. }
  2696. } else if source == 11 { //专栏文章阅读记录
  2697. if isAdminRole {
  2698. total, list, err = cygx.GetCygxYanxuaSspecialHistoryRecordByUser(condition, startSize, pageSize)
  2699. if err != nil && err.Error() != utils.ErrNoRow() {
  2700. br.Msg = "获取信息失败"
  2701. br.ErrMsg = "获取用户阅读记录,Err:" + err.Error()
  2702. return
  2703. }
  2704. } else {
  2705. total, list, err = cygx.GetCygxYanxuaSspecialHistoryRecordByUserWeekly(condition, startSize, pageSize)
  2706. if err != nil && err.Error() != utils.ErrNoRow() {
  2707. br.Msg = "获取信息失败"
  2708. br.ErrMsg = "获取用户阅读记录,Err:" + err.Error()
  2709. return
  2710. }
  2711. }
  2712. if len(list) > 0 {
  2713. for k, v := range list {
  2714. list[k].RegisterPlatform = cygxService.GetArticleSourcePlatform(v.SourcePlatform)
  2715. list[k].RegisterPlatformText = cygxService.GetArticleSourcePlatformText(v.RegisterPlatform)
  2716. }
  2717. }
  2718. } else if source == 12 { //收藏的专栏文章
  2719. if isAdminRole {
  2720. total, list, err = cygx.GetCygxYanxuanSpecialCollectByUser(condition, startSize, pageSize)
  2721. if err != nil && err.Error() != utils.ErrNoRow() {
  2722. br.Msg = "获取信息失败"
  2723. br.ErrMsg = "获取用户阅读记录,Err:" + err.Error()
  2724. return
  2725. }
  2726. } else {
  2727. total, list, err = cygx.GetCygxYanxuanSpecialCollectByUserWeekly(condition, startSize, pageSize)
  2728. if err != nil && err.Error() != utils.ErrNoRow() {
  2729. br.Msg = "获取信息失败"
  2730. br.ErrMsg = "获取用户阅读记录,Err:" + err.Error()
  2731. return
  2732. }
  2733. }
  2734. if len(list) > 0 {
  2735. for k, v := range list {
  2736. list[k].RegisterPlatform = cygxService.GetArticleSourcePlatform(v.SourcePlatform)
  2737. list[k].RegisterPlatformText = cygxService.GetArticleSourcePlatformText(v.RegisterPlatform)
  2738. }
  2739. }
  2740. } else if source == 13 { //关注的专栏作者
  2741. if isAdminRole {
  2742. total, list, err = cygx.GetCygxYanxuanSpecialAuthorByUser(condition, startSize, pageSize)
  2743. if err != nil && err.Error() != utils.ErrNoRow() {
  2744. br.Msg = "获取信息失败"
  2745. br.ErrMsg = "获取用户阅读记录,Err:" + err.Error()
  2746. return
  2747. }
  2748. } else {
  2749. total, list, err = cygx.GetCygxYanxuanSpecialAuthorByUserWeekly(condition, startSize, pageSize)
  2750. if err != nil && err.Error() != utils.ErrNoRow() {
  2751. br.Msg = "获取信息失败"
  2752. br.ErrMsg = "获取用户阅读记录,Err:" + err.Error()
  2753. return
  2754. }
  2755. }
  2756. if len(list) > 0 {
  2757. for k, v := range list {
  2758. list[k].RegisterPlatform = cygxService.GetArticleSourcePlatform(v.SourcePlatform)
  2759. list[k].RegisterPlatformText = cygxService.GetArticleSourcePlatformText(v.RegisterPlatform)
  2760. }
  2761. }
  2762. }
  2763. page := paging.GetPaging(currentIndex, pageSize, total)
  2764. if len(list) == 0 {
  2765. list = make([]*cygx.UserInteraction, 0)
  2766. }
  2767. resp.List = list
  2768. resp.Paging = page
  2769. br.Ret = 200
  2770. br.Success = true
  2771. br.Msg = "获取成功"
  2772. br.Data = resp
  2773. }
  2774. // @Title 机构相关互动下载
  2775. // @Description 机构相关互动下载接口
  2776. // @Param CompanyId query int true "公司id"
  2777. // @Param Source query int true "来源 报告阅读列表: 1, 活动互动记录: 2"
  2778. // @Param IsMeeting query string true "是否到会 1到会、2未到会"
  2779. // @Param MeetType query string true "参会方式 1线上,2线下 默认为线上"
  2780. // @Param StartDate query string true "开始时间"
  2781. // @Param EndDate query string true "结束时间"
  2782. // @Param KeyWord query string true "搜索关键词"
  2783. // @Param ActivityName query string true "活动名称"
  2784. // @Success 200 {object} cygx.CygxUserTableStatusListRep
  2785. // @router /user/company/export/interaction [get]
  2786. func (this *UserController) CompanyExportInteraction() {
  2787. br := new(models.BaseResponse).Init()
  2788. defer func() {
  2789. this.Data["json"] = br
  2790. this.ServeJSON()
  2791. }()
  2792. sysUser := this.SysUser
  2793. if sysUser == nil {
  2794. br.Msg = "请登录"
  2795. br.ErrMsg = "请登录,SysUser Is Empty"
  2796. br.Ret = 408
  2797. return
  2798. }
  2799. companyId, _ := this.GetInt("CompanyId")
  2800. isMeeting := this.GetString("IsMeeting")
  2801. meetType := this.GetString("MeetType")
  2802. startDate := this.GetString("StartDate")
  2803. endDate := this.GetString("EndDate")
  2804. keyWord := this.GetString("KeyWord")
  2805. activityName := this.GetString("ActivityName")
  2806. source, _ := this.GetInt("Source")
  2807. if companyId < 1 {
  2808. br.Msg = "用户不存在"
  2809. return
  2810. }
  2811. //获取企业客户信息
  2812. companyInfo, err := company.GetCompanyById(companyId)
  2813. if err != nil {
  2814. br.Msg = "获取信息失败"
  2815. br.ErrMsg = "GetCompanyById,Err:" + err.Error()
  2816. return
  2817. }
  2818. var isAdminRole bool
  2819. //如果不是管理员身份或者研究员身份则需要添加可见范围处理
  2820. if sysUser.Role == utils.ROLE_TYPE_CODE_ADMIN || sysUser.Role == utils.ROLE_TYPE_CODE_RESEARCHR {
  2821. isAdminRole = true
  2822. }
  2823. var pageSize = 9999
  2824. var list []*cygx.UserInteraction
  2825. var condition string
  2826. condition += ` AND r.company_id = ` + strconv.Itoa(companyId) + ` AND r.create_time < date_format(now(),'%Y-%m-%d') ` //过滤当天时间
  2827. if keyWord != "" {
  2828. //condition += ` AND r.user_id IN (SELECT user_id FROM wx_user WHERE mobile LIKE '%` + keyWord + `%' OR email LIKE '%` + keyWord + `%' OR real_name LIKE '%` + keyWord + `%')`
  2829. condition += ` AND ( r.mobile LIKE '%` + keyWord + `%' OR r.email LIKE '%` + keyWord + `%' OR r.real_name LIKE '%` + keyWord + `%')`
  2830. }
  2831. if source == 1 {
  2832. if startDate != "" {
  2833. startDate += " 00:00:00"
  2834. condition += ` AND r.create_time >= '` + startDate + `' `
  2835. }
  2836. if endDate != "" {
  2837. endDate += " 23:59:59"
  2838. condition += ` AND r.create_time <= '` + endDate + `' `
  2839. }
  2840. condition += ` ORDER BY r.create_time DESC `
  2841. var pars []interface{}
  2842. var listRecord []*cygx.CygxArticleAndYanxuanRecordResp
  2843. if isAdminRole {
  2844. listRecord, err = cygx.GetCygxArticleAndYanxuanRecordRespList(condition, pars, 0, pageSize)
  2845. if err != nil && err.Error() != utils.ErrNoRow() {
  2846. br.Msg = "获取信息失败"
  2847. br.ErrMsg = "获取用户阅读记录,Err:" + err.Error()
  2848. return
  2849. }
  2850. } else {
  2851. listRecord, err = cygx.GetCygxArticleAndYanxuanRecordRespListWeekly(condition, pars, 0, pageSize)
  2852. if err != nil && err.Error() != utils.ErrNoRow() {
  2853. br.Msg = "获取信息失败"
  2854. br.ErrMsg = "获取用户阅读记录,Err:" + err.Error()
  2855. return
  2856. }
  2857. }
  2858. //处理查询信息回显
  2859. list, err = cygxService.HandleArticleAndYanxuanRecordList(listRecord)
  2860. if err != nil && err.Error() != utils.ErrNoRow() {
  2861. br.Msg = "获取信息失败"
  2862. br.ErrMsg = "获取用户阅读记录,Err:" + err.Error()
  2863. return
  2864. }
  2865. if len(list) > 0 {
  2866. var articleIds string
  2867. mapAricleId := make(map[int]int)
  2868. mapAricleIndustrialSubjectName := make(map[int]*cygx.ArticleIndustrialSubjectNameResp)
  2869. for k, v := range list {
  2870. if v.ArticleId >= utils.SummaryArticleId {
  2871. list[k].ArticleType = 1
  2872. } else {
  2873. list[k].ArticleType = 2
  2874. }
  2875. if list[k].PermissionName == "" {
  2876. list[k].PermissionName = v.CategoryName
  2877. }
  2878. if mapAricleId[v.ArticleId] == 0 {
  2879. articleIds += strconv.Itoa(v.ArticleId) + ","
  2880. mapAricleId[v.ArticleId] = v.ArticleId
  2881. }
  2882. }
  2883. articleIds = strings.TrimRight(articleIds, ",")
  2884. if articleIds != "" {
  2885. listArticleIndustrialSubjectList, err := cygx.GetCygxArticleIndustrialSubjectName(articleIds)
  2886. if err != nil && err.Error() != utils.ErrNoRow() {
  2887. br.Msg = "获取信息失败"
  2888. br.ErrMsg = "获取用户阅读记录,Err:" + err.Error()
  2889. return
  2890. }
  2891. if len(listArticleIndustrialSubjectList) > 0 {
  2892. for _, v := range listArticleIndustrialSubjectList {
  2893. mapAricleIndustrialSubjectName[v.ArticleId] = v
  2894. }
  2895. for k, v := range list {
  2896. if mapAricleIndustrialSubjectName[v.ArticleId] != nil {
  2897. list[k].IndustryName = mapAricleIndustrialSubjectName[v.ArticleId].IndustryName
  2898. list[k].SubjectNameStr = mapAricleIndustrialSubjectName[v.ArticleId].SubjectNameStr
  2899. }
  2900. }
  2901. }
  2902. }
  2903. }
  2904. } else if source == 2 {
  2905. if isMeeting == "1" {
  2906. condition += ` AND r.is_meeting = 1 `
  2907. }
  2908. if isMeeting == "2" {
  2909. condition += ` AND r.is_meeting = 0 `
  2910. }
  2911. if meetType == "1" {
  2912. condition += ` AND t.activity_type = 1 `
  2913. }
  2914. if meetType == "2" {
  2915. condition += ` AND t.activity_type = 0 `
  2916. }
  2917. if startDate != "" {
  2918. startDate += " 00:00:00"
  2919. condition += ` AND a.activity_time >= '` + startDate + `' `
  2920. }
  2921. if endDate != "" {
  2922. endDate += " 23:59:59"
  2923. condition += ` AND a.activity_time <= '` + endDate + `' `
  2924. }
  2925. if activityName != "" {
  2926. condition += ` AND a.activity_name LIKE '%` + activityName + `%' `
  2927. }
  2928. if isAdminRole {
  2929. list, err = cygx.GetActivityMeetByCompany(condition, 0, pageSize)
  2930. if err != nil && err.Error() != utils.ErrNoRow() {
  2931. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  2932. br.Msg = "获取参会人数列表失败"
  2933. return
  2934. }
  2935. } else {
  2936. list, err = cygx.GetActivityMeetByCompanyWeekly(condition, 0, pageSize)
  2937. if err != nil && err.Error() != utils.ErrNoRow() {
  2938. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  2939. br.Msg = "获取参会人数列表失败"
  2940. return
  2941. }
  2942. }
  2943. if len(list) > 0 {
  2944. for k, v := range list {
  2945. if v.ActivityType == 1 {
  2946. if v.SignupType == "2" {
  2947. list[k].InteractionType = "自主拨入"
  2948. } else {
  2949. list[k].InteractionType = "预约外呼"
  2950. }
  2951. if v.ReminderNum > 0 {
  2952. list[k].InteractionType += ",会议提醒"
  2953. }
  2954. }
  2955. }
  2956. }
  2957. }
  2958. //创建excel
  2959. dir, err := os.Executable()
  2960. exPath := filepath.Dir(dir)
  2961. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  2962. xlsxFile := xlsx.NewFile()
  2963. if err != nil {
  2964. br.Msg = "生成文件失败"
  2965. br.ErrMsg = "生成文件失败"
  2966. return
  2967. }
  2968. style := xlsx.NewStyle()
  2969. alignment := xlsx.Alignment{
  2970. Horizontal: "center",
  2971. Vertical: "center",
  2972. WrapText: true,
  2973. }
  2974. style.Alignment = alignment
  2975. style.ApplyAlignment = true
  2976. sheet, err := xlsxFile.AddSheet("用户名单")
  2977. if err != nil {
  2978. br.Msg = "新增Sheet失败"
  2979. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  2980. return
  2981. }
  2982. var excelName string
  2983. if source == 1 {
  2984. excelName = "阅读记录"
  2985. //标头
  2986. rowTitle := sheet.AddRow()
  2987. cellA := rowTitle.AddCell()
  2988. cellA.Value = "姓名"
  2989. cellB := rowTitle.AddCell()
  2990. cellB.Value = "手机号"
  2991. cellC := rowTitle.AddCell()
  2992. cellC.Value = "报告标题"
  2993. cellD := rowTitle.AddCell()
  2994. cellD.Value = "所属行业"
  2995. cellE := rowTitle.AddCell()
  2996. cellE.Value = "所属产业"
  2997. cellF := rowTitle.AddCell()
  2998. cellF.Value = "关联标的"
  2999. cellG := rowTitle.AddCell()
  3000. cellG.Value = "发布时间"
  3001. cellH := rowTitle.AddCell()
  3002. cellH.Value = "阅读时间"
  3003. cellI := rowTitle.AddCell()
  3004. cellI.Value = "阅读时长"
  3005. for _, item := range list {
  3006. row := sheet.AddRow()
  3007. cellA := row.AddCell()
  3008. cellA.Value = item.RealName
  3009. cellB := row.AddCell()
  3010. cellB.Value = item.Mobile
  3011. cellC := row.AddCell()
  3012. cellC.Value = item.Title
  3013. cellD := row.AddCell()
  3014. cellD.Value = item.PermissionName
  3015. cellE := row.AddCell()
  3016. cellE.Value = item.IndustryName
  3017. cellF := row.AddCell()
  3018. cellF.Value = item.SubjectNameStr
  3019. cellG := row.AddCell()
  3020. cellG.Value = item.PublishDate
  3021. cellH := row.AddCell()
  3022. cellH.Value = item.CreateTime
  3023. cellI := row.AddCell()
  3024. cellI.Value = item.StopTime
  3025. }
  3026. } else {
  3027. excelName = "参会记录"
  3028. //标头
  3029. rowTitle := sheet.AddRow()
  3030. cellA := rowTitle.AddCell()
  3031. cellA.Value = "姓名"
  3032. cellB := rowTitle.AddCell()
  3033. cellB.Value = "手机号"
  3034. cellC := rowTitle.AddCell()
  3035. cellC.Value = "活动名称"
  3036. cellD := rowTitle.AddCell()
  3037. cellD.Value = "所属行业"
  3038. cellE := rowTitle.AddCell()
  3039. cellE.Value = "活动类型"
  3040. cellF := rowTitle.AddCell()
  3041. cellF.Value = "活动主题"
  3042. cellG := rowTitle.AddCell()
  3043. cellG.Value = "活动时间"
  3044. cellH := rowTitle.AddCell()
  3045. cellH.Value = "是否到会"
  3046. cellI := rowTitle.AddCell()
  3047. cellI.Value = "首次入会时间"
  3048. cellJ := rowTitle.AddCell()
  3049. cellJ.Value = "最后退出时间"
  3050. cellK := rowTitle.AddCell()
  3051. cellK.Value = "参与总时长"
  3052. cellL := rowTitle.AddCell()
  3053. cellL.Value = "参会方式"
  3054. cellM := rowTitle.AddCell()
  3055. cellM.Value = "参会权鉴"
  3056. cellN := rowTitle.AddCell()
  3057. cellN.Value = "参会状态"
  3058. for _, item := range list {
  3059. row := sheet.AddRow()
  3060. cellA := row.AddCell()
  3061. cellA.Value = item.RealName
  3062. cellB := row.AddCell()
  3063. cellB.Value = item.Mobile
  3064. cellC := row.AddCell()
  3065. cellC.Value = item.ActivityName
  3066. cellD := row.AddCell()
  3067. cellD.Value = item.PermissionName
  3068. cellE := row.AddCell()
  3069. cellE.Value = item.ActivityTypeName
  3070. cellF := row.AddCell()
  3071. cellF.Value = item.Label
  3072. cellG := row.AddCell()
  3073. cellG.Value = item.ActivityTime
  3074. cellH := row.AddCell()
  3075. if item.IsMeeting == 1 {
  3076. cellH.Value = "到会"
  3077. } else {
  3078. cellH.Value = "未到会"
  3079. }
  3080. cellI := row.AddCell()
  3081. cellI.Value = item.FirstMeetingTime
  3082. cellJ := row.AddCell()
  3083. cellJ.Value = item.LastMeetingTime
  3084. cellK := row.AddCell()
  3085. cellK.Value = item.Duration
  3086. cellL := row.AddCell()
  3087. cellL.Value = item.LastMeetingTime
  3088. cellM := row.AddCell()
  3089. cellM.Value = item.MeetingTypeStr
  3090. cellN := row.AddCell()
  3091. cellN.Value = item.MeetingStatusStr
  3092. }
  3093. }
  3094. err = xlsxFile.Save(downLoadnFilePath)
  3095. if err != nil {
  3096. br.Msg = "保存文件失败"
  3097. br.ErrMsg = "保存文件失败"
  3098. return
  3099. }
  3100. randStr := time.Now().Format(utils.FormatDate)
  3101. downloadFileName := excelName + companyInfo.CompanyName + randStr + ".xlsx"
  3102. this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  3103. defer func() {
  3104. os.Remove(downLoadnFilePath)
  3105. }()
  3106. br.Ret = 200
  3107. br.Success = true
  3108. br.Msg = "获取成功"
  3109. }
  3110. // @Title 全机构互动列表
  3111. // @Description 全机构互动列表接口
  3112. // @Param Source query int true "来源"
  3113. // @Param AdminId query string true "销售id,多个用英文逗号隔开,空字符串为全部"
  3114. // @Param IsMeeting query string false "是否到会 1到会、2未到会"
  3115. // @Param MeetType query string false "参会方式 1线上,2线下 默认为线上"
  3116. // @Param PageSize query int true "每页数据条数"
  3117. // @Param CurrentIndex query int true "当前页页码,从1开始"
  3118. // @Param StartDate query string false "开始时间"
  3119. // @Param EndDate query string false "结束时间"
  3120. // @Param KeyWord query string false "搜索关键词"
  3121. // @Param ActivityName query string false "活动名称"
  3122. // @Param ClassType query int true "列表类型,1:权益,2:研选,默认1"
  3123. // @Success 200 {object} cygx.UserInteractionListResp
  3124. // @router /user/company/list [get]
  3125. func (this *UserController) CompanyList() {
  3126. br := new(models.BaseResponse).Init()
  3127. defer func() {
  3128. this.Data["json"] = br
  3129. this.ServeJSON()
  3130. }()
  3131. sysUser := this.SysUser
  3132. if sysUser == nil {
  3133. br.Msg = "请登录"
  3134. br.ErrMsg = "请登录,SysUser Is Empty"
  3135. br.Ret = 408
  3136. return
  3137. }
  3138. roleTypeCode := sysUser.RoleTypeCode
  3139. pageSize, _ := this.GetInt("PageSize")
  3140. currentIndex, _ := this.GetInt("CurrentIndex")
  3141. adminId := this.GetString("AdminId")
  3142. keyWord := this.GetString("KeyWord")
  3143. isMeeting := this.GetString("IsMeeting")
  3144. meetType := this.GetString("MeetType")
  3145. startDate := this.GetString("StartDate")
  3146. endDate := this.GetString("EndDate")
  3147. activityName := this.GetString("ActivityName")
  3148. source, _ := this.GetInt("Source")
  3149. status := this.GetString("Status")
  3150. classType, _ := this.GetInt("ClassType", 1)
  3151. // 套餐类型
  3152. //packageType, _ := this.GetInt("PackageType")
  3153. keyWord = strings.Trim(keyWord, " ")
  3154. keyWord = strings.Replace(keyWord, "'", "", -1)
  3155. var total int
  3156. //statusItems := make([]*company.CompanyStatus, 0)
  3157. //var statusArr = [...]string{"全部", "试用", "正式", "冻结", "流失", "永续"}
  3158. var startSize int
  3159. if pageSize <= 0 {
  3160. pageSize = utils.PageSize20
  3161. }
  3162. if currentIndex <= 0 {
  3163. currentIndex = 1
  3164. }
  3165. startSize = paging.StartIndex(currentIndex, pageSize)
  3166. var condition string
  3167. resp := new(cygx.UserInteractionListResp)
  3168. var err error
  3169. var list []*cygx.UserInteraction
  3170. //流失
  3171. var lossCondition string
  3172. //var lossPars []interface{}
  3173. //状态分类查询条件
  3174. var permissionCondition string
  3175. if adminId != "" {
  3176. condition += ` AND b.seller_id IN (` + adminId + `) `
  3177. }
  3178. lossCondition = condition
  3179. //lossPars = pars
  3180. permissionCondition = condition
  3181. //流失客户统计
  3182. lossCondition += ` AND status='流失' `
  3183. //productId := services.GetProductId(roleTypeCode)
  3184. productId := 2
  3185. //权限控制
  3186. {
  3187. //如果不是超级管理员或者财务
  3188. if roleTypeCode != utils.ROLE_TYPE_CODE_ADMIN && roleTypeCode != utils.ROLE_TYPE_CODE_FINANCE {
  3189. //如果是部门管理员
  3190. if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  3191. condition += ` AND b.product_id= '` + strconv.Itoa(productId) + `'`
  3192. lossCondition += ` AND b.product_id= '` + strconv.Itoa(productId) + `'`
  3193. permissionCondition += ` AND b.product_id= '` + strconv.Itoa(productId) + `'`
  3194. } else {
  3195. condition += ` AND b.product_id= '` + strconv.Itoa(productId) + `'`
  3196. lossCondition += ` AND b.product_id= '` + strconv.Itoa(productId) + `'`
  3197. permissionCondition += ` AND b.product_id= '` + strconv.Itoa(productId) + `'`
  3198. if status == "全部" {
  3199. ////如果是筛选了流失客户状态
  3200. if sysUser.Authority <= 0 {
  3201. condition += ` AND (b.seller_id= '` + strconv.Itoa(sysUser.AdminId) + `' OR status='流失') `
  3202. permissionCondition += ` AND b.seller_id= ` + strconv.Itoa(sysUser.AdminId)
  3203. } else {
  3204. if sysUser.Authority == 1 {
  3205. condition += ` AND (b.department_id=` + strconv.Itoa(sysUser.DepartmentId) + ` OR status='流失')`
  3206. permissionCondition += ` AND b.department_id=` + strconv.Itoa(sysUser.DepartmentId)
  3207. }
  3208. if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  3209. if status != utils.COMPANY_STATUS_LOSE {
  3210. condition += ` AND (b.group_id=` + strconv.Itoa(sysUser.GroupId) + ` OR status='流失') `
  3211. }
  3212. permissionCondition += ` AND b.group_id=` + strconv.Itoa(sysUser.GroupId)
  3213. }
  3214. if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
  3215. pid, err := company.GetParentIdFromGroup(sysUser.GroupId)
  3216. if err != nil {
  3217. br.Msg = "获取失败"
  3218. br.ErrMsg = "查询父级id异常" + err.Error()
  3219. return
  3220. }
  3221. var ids []*string
  3222. if pid != nil {
  3223. if *pid != 0 {
  3224. //销售主管放在三级列表中
  3225. ids, err = company.GetGroupIdsByParentId(*pid)
  3226. if err != nil {
  3227. fmt.Println(err.Error())
  3228. }
  3229. } else {
  3230. //销售主管放在二级列表中
  3231. ids, err = company.GetGroupIdsByParentId(sysUser.GroupId)
  3232. if err != nil {
  3233. fmt.Println(err.Error())
  3234. }
  3235. }
  3236. }
  3237. var idSlice []string
  3238. var sid string
  3239. for _, id := range ids {
  3240. idSlice = append(idSlice, *id)
  3241. }
  3242. //加入父级groupId
  3243. if *pid > 0 {
  3244. idSlice = append(idSlice, strconv.Itoa(*pid))
  3245. } else {
  3246. idSlice = append(idSlice, strconv.Itoa(sysUser.GroupId))
  3247. }
  3248. sid = strings.Join(idSlice, ",")
  3249. if len(sid) > 0 {
  3250. if status != utils.COMPANY_STATUS_LOSE {
  3251. condition += ` AND (b.group_id IN (` + sid + `) OR status='流失') `
  3252. }
  3253. permissionCondition += ` AND b.group_id IN (` + sid + `) `
  3254. } else {
  3255. if status != utils.COMPANY_STATUS_LOSE {
  3256. condition += ` AND (b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) OR status='流失') `
  3257. }
  3258. permissionCondition += ` AND b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) `
  3259. }
  3260. }
  3261. if sysUser.Authority == 4 {
  3262. if status != utils.COMPANY_STATUS_LOSE {
  3263. condition += ` AND (b.group_id =` + strconv.Itoa(sysUser.GroupId) + ` OR status='流失') `
  3264. //pars = append(pars, sysUser.GroupId)
  3265. }
  3266. permissionCondition += ` AND b.group_id=` + strconv.Itoa(sysUser.GroupId)
  3267. //permissionPars = append(permissionPars, sysUser.GroupId)
  3268. }
  3269. }
  3270. } else {
  3271. //如果没有筛选了流失客户状态,那么需要加客户归属条件加入到查询中去
  3272. if sysUser.Authority <= 0 {
  3273. if status != utils.COMPANY_STATUS_LOSE {
  3274. condition += ` AND b.seller_id=` + strconv.Itoa(sysUser.AdminId)
  3275. //pars = append(pars, sysUser.AdminId)
  3276. }
  3277. permissionCondition += ` AND b.seller_id=` + strconv.Itoa(sysUser.AdminId)
  3278. //permissionPars = append(permissionPars, sysUser.AdminId)
  3279. } else {
  3280. if sysUser.Authority == 1 {
  3281. if status != utils.COMPANY_STATUS_LOSE {
  3282. condition += ` AND b.department_id=` + strconv.Itoa(sysUser.DepartmentId)
  3283. //pars = append(pars, sysUser.DepartmentId)
  3284. }
  3285. permissionCondition += ` AND b.department_id=` + strconv.Itoa(sysUser.DepartmentId)
  3286. //permissionPars = append(permissionPars, sysUser.DepartmentId)
  3287. }
  3288. if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  3289. if status != utils.COMPANY_STATUS_LOSE {
  3290. condition += ` AND b.group_id= ` + strconv.Itoa(sysUser.GroupId)
  3291. //pars = append(pars, sysUser.GroupId)
  3292. }
  3293. permissionCondition += ` AND b.group_id=` + strconv.Itoa(sysUser.GroupId)
  3294. //permissionPars = append(permissionPars, sysUser.GroupId)
  3295. }
  3296. if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
  3297. pid, err := company.GetParentIdFromGroup(sysUser.GroupId)
  3298. if err != nil {
  3299. br.Msg = "获取失败"
  3300. br.ErrMsg = "查询父级id异常" + err.Error()
  3301. return
  3302. }
  3303. var ids []*string
  3304. if pid != nil {
  3305. if *pid != 0 {
  3306. //销售主管放在三级列表中
  3307. ids, err = company.GetGroupIdsByParentId(*pid)
  3308. if err != nil {
  3309. fmt.Println(err.Error())
  3310. }
  3311. } else {
  3312. //销售主管放在二级列表中
  3313. ids, err = company.GetGroupIdsByParentId(sysUser.GroupId)
  3314. if err != nil {
  3315. fmt.Println(err.Error())
  3316. }
  3317. }
  3318. }
  3319. var idSlice []string
  3320. var sid string
  3321. for _, id := range ids {
  3322. idSlice = append(idSlice, *id)
  3323. }
  3324. //加入父级groupId
  3325. if *pid > 0 {
  3326. idSlice = append(idSlice, strconv.Itoa(*pid))
  3327. } else {
  3328. idSlice = append(idSlice, strconv.Itoa(sysUser.GroupId))
  3329. }
  3330. sid = strings.Join(idSlice, ",")
  3331. if len(sid) > 0 {
  3332. if status != utils.COMPANY_STATUS_LOSE {
  3333. condition += ` AND (b.group_id IN (` + sid + `) OR status='流失') `
  3334. //pars = append(pars, sysUser.GroupId)
  3335. }
  3336. permissionCondition += ` AND b.group_id IN (` + sid + `) `
  3337. } else {
  3338. if status != utils.COMPANY_STATUS_LOSE {
  3339. condition += ` AND (b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) OR status='流失') `
  3340. //pars = append(pars, sysUser.GroupId)
  3341. }
  3342. permissionCondition += ` AND b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) `
  3343. }
  3344. }
  3345. if sysUser.Authority == 4 {
  3346. if status != utils.COMPANY_STATUS_LOSE {
  3347. condition += ` AND b.group_id =` + strconv.Itoa(sysUser.GroupId)
  3348. //pars = append(pars, sysUser.GroupId)
  3349. }
  3350. permissionCondition += ` AND b.group_id=` + strconv.Itoa(sysUser.GroupId)
  3351. //permissionPars = append(permissionPars, sysUser.GroupId)
  3352. }
  3353. }
  3354. }
  3355. }
  3356. }
  3357. }
  3358. condition += ` AND b.status IN ('正式','试用','冻结') `
  3359. companyCondition := `SELECT a.company_id FROM company AS a INNER JOIN company_product AS b ON a.company_id=b.company_id WHERE a.enabled=1 `
  3360. companyIdsCondition := `SELECT GROUP_CONCAT( DISTINCT a.company_id SEPARATOR ',' ) AS company_ids FROM company AS a INNER JOIN company_product AS b ON a.company_id=b.company_id WHERE a.enabled=1 `
  3361. if condition != "" {
  3362. companyCondition += condition
  3363. }
  3364. companyIdsCondition += condition
  3365. var companyIds string
  3366. companyIds, err = cygx.GetCompanyIdsCondition(companyIdsCondition)
  3367. if err != nil {
  3368. br.Msg = "获取失败"
  3369. br.ErrMsg = "获取公司ID数据失败,Err:" + err.Error()
  3370. return
  3371. }
  3372. condition = ` AND r.company_id IN ( ` + companyIds + ` ) AND r.create_time < '` + time.Now().Format(utils.FormatDate) + `' ` // 过滤当天查询时间
  3373. if keyWord != "" {
  3374. condition += ` AND (r.mobile LIKE '%` + keyWord + `%' OR r.email LIKE '%` + keyWord + `%' OR r.real_name LIKE '%` + keyWord + `%'` + ` OR r.company_name LIKE '%` + keyWord + `%') `
  3375. }
  3376. var isAdminRole bool
  3377. //如果不是管理员身份或者研究员身份则需要添加可见范围处理
  3378. if sysUser.Role == utils.ROLE_TYPE_CODE_ADMIN || sysUser.Role == utils.ROLE_TYPE_CODE_RESEARCHR {
  3379. isAdminRole = true
  3380. }
  3381. if source == 1 {
  3382. if startDate != "" {
  3383. startDate += " 00:00:00"
  3384. condition += ` AND r.create_time >= '` + startDate + `' `
  3385. }
  3386. if endDate != "" {
  3387. endDate += " 23:59:59"
  3388. condition += ` AND r.create_time <= '` + endDate + `' `
  3389. }
  3390. if classType == 1 {
  3391. condition += " AND art.article_type_id = 0 "
  3392. } else {
  3393. condition += " AND art.article_type_id > 0 "
  3394. }
  3395. var pars []interface{}
  3396. condition += " ORDER BY r.create_time DESC "
  3397. var listRecord []*cygx.CygxArticleAndYanxuanRecordResp
  3398. if isAdminRole {
  3399. listRecord, err = cygx.GetCygxArticleAndYanxuanRecordRespList(condition, pars, startSize, pageSize)
  3400. if err != nil && err.Error() != utils.ErrNoRow() {
  3401. br.Msg = "获取信息失败"
  3402. br.ErrMsg = "获取用户阅读记录,Err:" + err.Error()
  3403. return
  3404. }
  3405. total, err = cygx.GetCygxArticleAndYanxuanRecordCount(condition, pars)
  3406. if err != nil {
  3407. br.Msg = "获取信息失败"
  3408. br.ErrMsg = "获取用户阅读记录数量失败,Err:" + err.Error()
  3409. return
  3410. }
  3411. } else {
  3412. listRecord, err = cygx.GetCygxArticleAndYanxuanRecordRespListWeekly(condition, pars, startSize, pageSize)
  3413. if err != nil && err.Error() != utils.ErrNoRow() {
  3414. br.Msg = "获取信息失败"
  3415. br.ErrMsg = "获取用户阅读记录,Err:" + err.Error()
  3416. return
  3417. }
  3418. total, err = cygx.GetCygxArticleAndYanxuanRecordCountWeekly(condition, pars)
  3419. if err != nil {
  3420. br.Msg = "获取信息失败"
  3421. br.ErrMsg = "获取用户阅读记录数量失败,Err:" + err.Error()
  3422. return
  3423. }
  3424. }
  3425. //处理查询信息回显
  3426. list, err = cygxService.HandleArticleAndYanxuanRecordList(listRecord)
  3427. if err != nil && err.Error() != utils.ErrNoRow() {
  3428. br.Msg = "获取信息失败"
  3429. br.ErrMsg = "获取用户阅读记录,Err:" + err.Error()
  3430. return
  3431. }
  3432. } else if source == 2 {
  3433. if isMeeting == "1" {
  3434. condition += ` AND r.is_meeting = 1 `
  3435. }
  3436. if isMeeting == "2" {
  3437. condition += ` AND r.is_meeting = 0 `
  3438. }
  3439. if meetType == "1" {
  3440. condition += ` AND t.activity_type = 1 `
  3441. }
  3442. if meetType == "2" {
  3443. condition += ` AND t.activity_type = 0 `
  3444. }
  3445. if startDate != "" {
  3446. startDate += " 00:00:00"
  3447. condition += ` AND a.activity_time >= '` + startDate + `' `
  3448. }
  3449. if endDate != "" {
  3450. endDate += " 23:59:59"
  3451. condition += ` AND a.activity_time <= '` + endDate + `' `
  3452. }
  3453. if activityName != "" {
  3454. condition += ` AND a.activity_name LIKE '%` + activityName + `%' `
  3455. }
  3456. if classType == 1 {
  3457. condition += " AND a.chart_permission_id != 31 "
  3458. } else {
  3459. condition += " AND a.chart_permission_id = 31 "
  3460. }
  3461. if isAdminRole {
  3462. total, err = cygx.GetActivityMeetByCompanyCount(condition)
  3463. if err != nil {
  3464. br.Msg = "获取信息失败"
  3465. br.ErrMsg = "获取参会总数失败,Err:" + err.Error()
  3466. return
  3467. }
  3468. list, err = cygx.GetActivityMeetByCompanyList(condition, startSize, pageSize)
  3469. if err != nil && err.Error() != utils.ErrNoRow() {
  3470. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  3471. br.Msg = "获取参会人数列表失败"
  3472. return
  3473. }
  3474. } else {
  3475. total, err = cygx.GetActivityMeetByCompanyCountWeekly(condition)
  3476. if err != nil {
  3477. br.Msg = "获取信息失败"
  3478. br.ErrMsg = "获取参会总数失败,Err:" + err.Error()
  3479. return
  3480. }
  3481. list, err = cygx.GetActivityMeetByCompanyWeekly(condition, startSize, pageSize)
  3482. if err != nil && err.Error() != utils.ErrNoRow() {
  3483. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  3484. br.Msg = "获取参会人数列表失败"
  3485. return
  3486. }
  3487. }
  3488. //根据公司ID获取对应销售
  3489. var sellerCompanyIds []int
  3490. for _, v := range list {
  3491. sellerCompanyIds = append(sellerCompanyIds, v.CompanyId)
  3492. }
  3493. sellNameMap := services.GetSellNameMapByCompanyIds(sellerCompanyIds)
  3494. if len(list) > 0 {
  3495. for k, v := range list {
  3496. if v.ActivityType == 1 {
  3497. if v.SignupType == "2" {
  3498. list[k].InteractionType = "自主拨入"
  3499. } else {
  3500. list[k].InteractionType = "预约外呼"
  3501. }
  3502. if v.ReminderNum > 0 {
  3503. list[k].InteractionType += ",会议提醒"
  3504. }
  3505. }
  3506. if v.IsMeeting == 0 {
  3507. list[k].FirstMeetingTime = ""
  3508. list[k].LastMeetingTime = ""
  3509. }
  3510. v.SellerName = sellNameMap[v.CompanyId]
  3511. }
  3512. }
  3513. } else if source == 3 {
  3514. if classType == 1 {
  3515. condition += " AND art.article_type_id = 0 "
  3516. } else {
  3517. condition += " AND art.article_type_id > 0 "
  3518. }
  3519. if isAdminRole {
  3520. total, err = cygx.GetCygxArticleCollectCountByCompany(condition)
  3521. if err != nil {
  3522. br.Msg = "获取信息失败"
  3523. br.ErrMsg = "获取用户收藏记录总数失败,Err:" + err.Error()
  3524. return
  3525. }
  3526. list, err = cygx.GetCygxArticleCollectByCompanyList(startSize, pageSize, condition)
  3527. if err != nil && err.Error() != utils.ErrNoRow() {
  3528. br.Msg = "获取信息失败"
  3529. br.ErrMsg = "获取用户搜藏记录失败,Err:" + err.Error()
  3530. return
  3531. }
  3532. } else {
  3533. total, err = cygx.GetCygxArticleCollectCountByCompanyWeekly(condition)
  3534. if err != nil {
  3535. br.Msg = "获取信息失败"
  3536. br.ErrMsg = "获取用户收藏记录总数失败,Err:" + err.Error()
  3537. return
  3538. }
  3539. list, err = cygx.GetCygxArticleCollectByCompanyWeekly(startSize, pageSize, condition)
  3540. if err != nil && err.Error() != utils.ErrNoRow() {
  3541. br.Msg = "获取信息失败"
  3542. br.ErrMsg = "获取用户搜藏记录失败,Err:" + err.Error()
  3543. return
  3544. }
  3545. }
  3546. //根据公司ID获取对应销售
  3547. var sellerCompanyIds []int
  3548. for _, v := range list {
  3549. sellerCompanyIds = append(sellerCompanyIds, v.CompanyId)
  3550. }
  3551. sellNameMap := services.GetSellNameMapByCompanyIds(sellerCompanyIds)
  3552. if len(list) > 0 {
  3553. for k, v := range list {
  3554. if v.ArticleId >= utils.SummaryArticleId {
  3555. list[k].ArticleType = 1
  3556. } else {
  3557. list[k].ArticleType = 2
  3558. }
  3559. v.SellerName = sellNameMap[v.CompanyId]
  3560. }
  3561. }
  3562. } else if source == 4 {
  3563. if isAdminRole {
  3564. total, err = cygx.GetChartCountByUserCount(condition)
  3565. if err != nil {
  3566. br.Msg = "获取信息失败"
  3567. br.ErrMsg = "获取总数失败,Err:" + err.Error()
  3568. return
  3569. }
  3570. //condition += ` AND r.company_id = ` + strconv.Itoa(companyId) + ` AND r.create_time < date_format(now(),'%Y-%m-%d')` //过滤当天时间
  3571. list, err = cygx.GetChartCollectBycompanyList(condition, startSize, pageSize)
  3572. if err != nil {
  3573. br.Msg = "获取信息失败"
  3574. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  3575. return
  3576. }
  3577. } else {
  3578. total, err = cygx.GetChartCountByUserMobileWeekly(condition)
  3579. if err != nil {
  3580. br.Msg = "获取信息失败"
  3581. br.ErrMsg = "获取总数失败,Err:" + err.Error()
  3582. return
  3583. }
  3584. //condition += ` AND r.company_id = ` + strconv.Itoa(companyId) + ` AND r.create_time < date_format(now(),'%Y-%m-%d')` //过滤当天时间
  3585. list, err = cygx.GetChartCollectBycompanyListWeekly(condition, startSize, pageSize)
  3586. if err != nil {
  3587. br.Msg = "获取信息失败"
  3588. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  3589. return
  3590. }
  3591. }
  3592. if len(list) > 0 {
  3593. for k, v := range list {
  3594. var err error
  3595. condition = ` AND a.publish_status = 1 AND r.mobile = ` + v.Mobile + ` AND r.create_time < date_format(now(),'%Y-%m-%d')` //过滤当天时间
  3596. totalUser, err := cygx.GetChartCountByUserMobile(condition)
  3597. if err != nil {
  3598. br.Msg = "获取信息失败"
  3599. br.ErrMsg = "获取总数失败,Err:" + err.Error()
  3600. return
  3601. }
  3602. listChart, err := cygx.GetChartListCollectionWithCygxByMobile(condition, 0, 18)
  3603. if err != nil {
  3604. br.Msg = "获取信息失败"
  3605. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  3606. return
  3607. }
  3608. for k, vChart := range listChart {
  3609. if vChart.PtagName != "" {
  3610. listChart[k].CtagNamePc = vChart.PtagName
  3611. }
  3612. if vChart.CtagName != "" {
  3613. listChart[k].CtagNamePc += "," + vChart.CtagName
  3614. }
  3615. if vChart.PtagNameTwo != "" {
  3616. listChart[k].CtagNamePc += "," + vChart.PtagNameTwo
  3617. }
  3618. if vChart.CtagNameTwo != "" {
  3619. listChart[k].CtagNamePc += "," + vChart.CtagNameTwo
  3620. }
  3621. }
  3622. pageChart := paging.GetPaging(currentIndex, pageSize, totalUser)
  3623. list[k].ListChart = listChart
  3624. list[k].Paging = pageChart
  3625. list[k].IsEnd = pageChart.IsEnd
  3626. list[k].CurrentIndex = pageChart.CurrentIndex
  3627. }
  3628. }
  3629. } else if source == 5 {
  3630. if classType == 1 {
  3631. condition += " AND m.chart_permission_id != 31 "
  3632. } else {
  3633. condition += " AND m.chart_permission_id = 31 "
  3634. }
  3635. if isAdminRole {
  3636. total, err = cygx.GetCygxIndustryFllowCountByCompany(condition)
  3637. if err != nil {
  3638. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  3639. br.Msg = "获取用户关注总数失败"
  3640. return
  3641. }
  3642. list, err = cygx.GetCygxIndustryFllowByCompanyList(condition, startSize, pageSize)
  3643. if err != nil && err.Error() != utils.ErrNoRow() {
  3644. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  3645. br.Msg = "获取用户关注总数失败"
  3646. return
  3647. }
  3648. } else {
  3649. total, err = cygx.GetCygxIndustryFllowCountByCompanyWeekly(condition)
  3650. if err != nil {
  3651. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  3652. br.Msg = "获取用户关注总数失败"
  3653. return
  3654. }
  3655. list, err = cygx.GetCygxIndustryFllowByCompanyWeekly(condition, startSize, pageSize)
  3656. if err != nil && err.Error() != utils.ErrNoRow() {
  3657. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  3658. br.Msg = "获取用户关注总数失败"
  3659. return
  3660. }
  3661. }
  3662. //根据公司ID获取对应销售
  3663. var sellerCompanyIds []int
  3664. for _, v := range list {
  3665. sellerCompanyIds = append(sellerCompanyIds, v.CompanyId)
  3666. }
  3667. sellNameMap := services.GetSellNameMapByCompanyIds(sellerCompanyIds)
  3668. for _, v := range list {
  3669. v.SellerName = sellNameMap[v.CompanyId]
  3670. }
  3671. } else if source == 6 {
  3672. if isAdminRole {
  3673. total, err = cygx.GetCygArticleDepartmentFollowCountByCompany(condition)
  3674. if err != nil {
  3675. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  3676. br.Msg = "获取关注作者总数失败"
  3677. return
  3678. }
  3679. list, err = cygx.GetCygArticleDepartmentFollowByCompanyList(condition, startSize, pageSize)
  3680. if err != nil && err.Error() != utils.ErrNoRow() {
  3681. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  3682. br.Msg = "获取关注作者列表失败"
  3683. return
  3684. }
  3685. } else {
  3686. total, err = cygx.GetCygArticleDepartmentFollowCountByCompanyWeekly(condition)
  3687. if err != nil {
  3688. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  3689. br.Msg = "获取关注作者总数失败"
  3690. return
  3691. }
  3692. list, err = cygx.GetCygArticleDepartmentFollowByCompanyWeekly(condition, startSize, pageSize)
  3693. if err != nil && err.Error() != utils.ErrNoRow() {
  3694. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  3695. br.Msg = "获取关注作者列表失败"
  3696. return
  3697. }
  3698. }
  3699. if len(list) > 0 {
  3700. //根据公司ID获取对应销售
  3701. var sellerCompanyIds []int
  3702. var departmentIds []int
  3703. for _, v := range list {
  3704. sellerCompanyIds = append(sellerCompanyIds, v.CompanyId)
  3705. departmentIds = append(departmentIds, v.DepartmentId)
  3706. }
  3707. sellNameMap := services.GetSellNameMapByCompanyIds(sellerCompanyIds)
  3708. mapIndustrialLabel := cygxService.GetArticleIndustrialLabelByDepartmentId(departmentIds) // 关联产业
  3709. for _, v := range list {
  3710. v.SellerName = sellNameMap[v.CompanyId]
  3711. v.SubjectNameStr = strings.Join(mapIndustrialLabel[v.DepartmentId], "/")
  3712. }
  3713. }
  3714. } else if source == 7 {
  3715. if classType == 1 {
  3716. condition += " AND r.register_platform IN (1,2) "
  3717. } else {
  3718. condition += " AND r.register_platform IN (5,6) "
  3719. }
  3720. if isAdminRole {
  3721. total, err = cygx.GetCygxSearchKeyWordCountBuCompany(condition)
  3722. if err != nil {
  3723. br.Msg = "获取信息失败"
  3724. br.ErrMsg = "获取搜索记录失败,Err:" + err.Error()
  3725. return
  3726. }
  3727. list, err = cygx.GetCygxSearchKeyWordByCompanyList(condition, startSize, pageSize)
  3728. if err != nil && err.Error() != utils.ErrNoRow() {
  3729. br.Msg = "获取信息失败"
  3730. br.ErrMsg = "获取搜索记录列表失败,Err:" + err.Error()
  3731. return
  3732. }
  3733. } else {
  3734. total, err = cygx.GetCygxSearchKeyWordCountBuCompanyWeekly(condition)
  3735. if err != nil {
  3736. br.Msg = "获取信息失败"
  3737. br.ErrMsg = "获取搜索记录失败,Err:" + err.Error()
  3738. return
  3739. }
  3740. list, err = cygx.GetCygxSearchKeyWordByCompanyWeekly(condition, startSize, pageSize)
  3741. if err != nil && err.Error() != utils.ErrNoRow() {
  3742. br.Msg = "获取信息失败"
  3743. br.ErrMsg = "获取搜索记录列表失败,Err:" + err.Error()
  3744. return
  3745. }
  3746. }
  3747. //根据公司ID获取对应销售
  3748. var sellerCompanyIds []int
  3749. for _, v := range list {
  3750. sellerCompanyIds = append(sellerCompanyIds, v.CompanyId)
  3751. }
  3752. sellNameMap := services.GetSellNameMapByCompanyIds(sellerCompanyIds)
  3753. for _, v := range list {
  3754. v.SellerName = sellNameMap[v.CompanyId]
  3755. }
  3756. } else if source == 8 {
  3757. if isAdminRole {
  3758. total, err = cygx.GetCygxActivitySpecialTripCountByCompany(condition)
  3759. if err != nil {
  3760. br.Msg = "获取信息失败"
  3761. br.ErrMsg = "获取搜索记录失败,Err:" + err.Error()
  3762. return
  3763. }
  3764. list, err = cygx.GetCygxActivitySpecialTripByCompanyList(condition, startSize, pageSize)
  3765. if err != nil && err.Error() != utils.ErrNoRow() {
  3766. br.Msg = "获取信息失败"
  3767. br.ErrMsg = "获取搜索记录列表失败,Err:" + err.Error()
  3768. return
  3769. }
  3770. } else {
  3771. total, err = cygx.GetCygxActivitySpecialTripCountByCompanyWeekly(condition)
  3772. if err != nil {
  3773. br.Msg = "获取信息失败"
  3774. br.ErrMsg = "获取搜索记录失败,Err:" + err.Error()
  3775. return
  3776. }
  3777. list, err = cygx.CygxActivitySpecialTripByCompanyWeekly(condition, startSize, pageSize)
  3778. if err != nil && err.Error() != utils.ErrNoRow() {
  3779. br.Msg = "获取信息失败"
  3780. br.ErrMsg = "获取搜索记录列表失败,Err:" + err.Error()
  3781. return
  3782. }
  3783. }
  3784. } else if source == 9 {
  3785. if isAdminRole {
  3786. total, err = cygx.GetCygxRoadshowCountByCompany(condition)
  3787. if err != nil {
  3788. br.Msg = "获取信息失败"
  3789. br.ErrMsg = "获取搜索记录失败,Err:" + err.Error()
  3790. return
  3791. }
  3792. list, err = cygx.GetCygxRoadshowByCompanyList(condition, startSize, pageSize)
  3793. if err != nil && err.Error() != utils.ErrNoRow() {
  3794. br.Msg = "获取信息失败"
  3795. br.ErrMsg = "获取搜索记录列表失败,Err:" + err.Error()
  3796. return
  3797. }
  3798. } else {
  3799. total, err = cygx.GetCygxRoadshowCountByCompanyWeekly(condition)
  3800. if err != nil {
  3801. br.Msg = "获取信息失败"
  3802. br.ErrMsg = "获取搜索记录失败,Err:" + err.Error()
  3803. return
  3804. }
  3805. list, err = cygx.GetCygxRoadshowByCompanyWeekly(condition, startSize, pageSize)
  3806. if err != nil && err.Error() != utils.ErrNoRow() {
  3807. br.Msg = "获取信息失败"
  3808. br.ErrMsg = "获取搜索记录列表失败,Err:" + err.Error()
  3809. return
  3810. }
  3811. }
  3812. //根据公司ID获取对应销售
  3813. var sellerCompanyIds []int
  3814. for _, v := range list {
  3815. sellerCompanyIds = append(sellerCompanyIds, v.CompanyId)
  3816. }
  3817. sellNameMap := services.GetSellNameMapByCompanyIds(sellerCompanyIds)
  3818. for _, v := range list {
  3819. v.SellerName = sellNameMap[v.CompanyId]
  3820. }
  3821. } else if source == 10 { //标签点击记录
  3822. if isAdminRole {
  3823. total, err = cygx.GetCygxTagHistoryCount(condition)
  3824. if err != nil {
  3825. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  3826. br.Msg = "获取搜索记录失败"
  3827. return
  3828. }
  3829. list, err = cygx.GetCygxTagHistoryListBycondition(condition, startSize, pageSize)
  3830. if err != nil && err.Error() != utils.ErrNoRow() {
  3831. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  3832. br.Msg = "获取搜索记录列表失败"
  3833. return
  3834. }
  3835. } else {
  3836. total, err = cygx.GetCygxTagHistoryCountWeekly(condition)
  3837. if err != nil {
  3838. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  3839. br.Msg = "获取搜索记录失败"
  3840. return
  3841. }
  3842. list, err = cygx.GetCygxTagHistoryListByconditionWeekly(condition, startSize, pageSize)
  3843. if err != nil && err.Error() != utils.ErrNoRow() {
  3844. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  3845. br.Msg = "获取搜索记录列表失败"
  3846. return
  3847. }
  3848. }
  3849. } else if source == 11 { //专栏文章阅读记录
  3850. if isAdminRole {
  3851. total, list, err = cygx.GetCygxYanxuaSspecialHistoryRecordByUser(condition, startSize, pageSize)
  3852. if err != nil && err.Error() != utils.ErrNoRow() {
  3853. br.Msg = "获取信息失败"
  3854. br.ErrMsg = "获取用户阅读记录,Err:" + err.Error()
  3855. return
  3856. }
  3857. } else {
  3858. total, list, err = cygx.GetCygxYanxuaSspecialHistoryRecordByUserWeekly(condition, startSize, pageSize)
  3859. if err != nil && err.Error() != utils.ErrNoRow() {
  3860. br.Msg = "获取信息失败"
  3861. br.ErrMsg = "获取用户阅读记录,Err:" + err.Error()
  3862. return
  3863. }
  3864. }
  3865. if len(list) > 0 {
  3866. for k, v := range list {
  3867. list[k].RegisterPlatform = cygxService.GetArticleSourcePlatform(v.SourcePlatform)
  3868. list[k].RegisterPlatformText = cygxService.GetArticleSourcePlatformText(v.RegisterPlatform)
  3869. }
  3870. }
  3871. } else if source == 12 { //收藏的专栏文章
  3872. if isAdminRole {
  3873. total, list, err = cygx.GetCygxYanxuanSpecialCollectByUser(condition, startSize, pageSize)
  3874. if err != nil && err.Error() != utils.ErrNoRow() {
  3875. br.Msg = "获取信息失败"
  3876. br.ErrMsg = "获取用户阅读记录,Err:" + err.Error()
  3877. return
  3878. }
  3879. } else {
  3880. total, list, err = cygx.GetCygxYanxuanSpecialCollectByUserWeekly(condition, startSize, pageSize)
  3881. if err != nil && err.Error() != utils.ErrNoRow() {
  3882. br.Msg = "获取信息失败"
  3883. br.ErrMsg = "获取用户阅读记录,Err:" + err.Error()
  3884. return
  3885. }
  3886. }
  3887. if len(list) > 0 {
  3888. for k, v := range list {
  3889. list[k].RegisterPlatform = cygxService.GetArticleSourcePlatform(v.SourcePlatform)
  3890. list[k].RegisterPlatformText = cygxService.GetArticleSourcePlatformText(v.RegisterPlatform)
  3891. }
  3892. }
  3893. } else if source == 13 { //关注的专栏作者
  3894. if isAdminRole {
  3895. total, list, err = cygx.GetCygxYanxuanSpecialAuthorByUser(condition, startSize, pageSize)
  3896. if err != nil && err.Error() != utils.ErrNoRow() {
  3897. br.Msg = "获取信息失败"
  3898. br.ErrMsg = "获取用户阅读记录,Err:" + err.Error()
  3899. return
  3900. }
  3901. } else {
  3902. total, list, err = cygx.GetCygxYanxuanSpecialAuthorByUserWeekly(condition, startSize, pageSize)
  3903. if err != nil && err.Error() != utils.ErrNoRow() {
  3904. br.Msg = "获取信息失败"
  3905. br.ErrMsg = "获取用户阅读记录,Err:" + err.Error()
  3906. return
  3907. }
  3908. }
  3909. if len(list) > 0 {
  3910. for k, v := range list {
  3911. list[k].RegisterPlatform = cygxService.GetArticleSourcePlatform(v.SourcePlatform)
  3912. list[k].RegisterPlatformText = cygxService.GetArticleSourcePlatformText(v.RegisterPlatform)
  3913. }
  3914. }
  3915. }
  3916. page := paging.GetPaging(currentIndex, pageSize, total)
  3917. if len(list) == 0 {
  3918. list = make([]*cygx.UserInteraction, 0)
  3919. }
  3920. resp.List = list
  3921. resp.Paging = page
  3922. br.Ret = 200
  3923. br.Success = true
  3924. br.Msg = "获取成功"
  3925. br.Data = resp
  3926. }
  3927. // @Title 机构列表相关互动下载
  3928. // @Description 机构相关互动下载接口
  3929. // @Param Source query int true "来源 报告阅读列表: 1, 活动互动记录: 2"
  3930. // @Param IsMeeting query string true "是否到会 1到会、2未到会"
  3931. // @Param MeetType query string true "参会方式 1线上,2线下 默认为线上"
  3932. // @Param StartDate query string true "开始时间"
  3933. // @Param EndDate query string true "结束时间"
  3934. // @Param KeyWord query string true "搜索关键词"
  3935. // @Param ActivityName query string true "活动名称"
  3936. // @Success 200 {object} cygx.CygxUserTableStatusListRep
  3937. // @router /user/companyList/export/interaction [get]
  3938. func (this *UserController) CompanyExportInteractionList() {
  3939. br := new(models.BaseResponse).Init()
  3940. defer func() {
  3941. this.Data["json"] = br
  3942. this.ServeJSON()
  3943. }()
  3944. sysUser := this.SysUser
  3945. if sysUser == nil {
  3946. br.Msg = "请登录"
  3947. br.ErrMsg = "请登录,SysUser Is Empty"
  3948. br.Ret = 408
  3949. return
  3950. }
  3951. roleTypeCode := sysUser.RoleTypeCode
  3952. adminId := this.GetString("AdminId")
  3953. keyWord := this.GetString("KeyWord")
  3954. isMeeting := this.GetString("IsMeeting")
  3955. meetType := this.GetString("MeetType")
  3956. startDate := this.GetString("StartDate")
  3957. endDate := this.GetString("EndDate")
  3958. activityName := this.GetString("ActivityName")
  3959. source, _ := this.GetInt("Source")
  3960. status := this.GetString("Status")
  3961. // 套餐类型
  3962. //packageType, _ := this.GetInt("PackageType")
  3963. keyWord = strings.Trim(keyWord, " ")
  3964. keyWord = strings.Replace(keyWord, "'", "", -1)
  3965. var list []*cygx.UserInteraction
  3966. var err error
  3967. var condition string
  3968. //流失
  3969. var lossCondition string
  3970. //var lossPars []interface{}
  3971. //状态分类查询条件
  3972. var permissionCondition string
  3973. if adminId != "" {
  3974. condition += ` AND b.seller_id IN (` + adminId + `) `
  3975. }
  3976. lossCondition = condition
  3977. //lossPars = pars
  3978. permissionCondition = condition
  3979. //流失客户统计
  3980. lossCondition += ` AND status='流失' `
  3981. //productId := services.GetProductId(roleTypeCode)
  3982. productId := 2
  3983. //权限控制
  3984. {
  3985. //如果不是超级管理员或者财务
  3986. if roleTypeCode != utils.ROLE_TYPE_CODE_ADMIN && roleTypeCode != utils.ROLE_TYPE_CODE_FINANCE {
  3987. //如果是部门管理员
  3988. if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  3989. condition += ` AND b.product_id= '` + strconv.Itoa(productId) + `'`
  3990. lossCondition += ` AND b.product_id= '` + strconv.Itoa(productId) + `'`
  3991. permissionCondition += ` AND b.product_id= '` + strconv.Itoa(productId) + `'`
  3992. } else {
  3993. condition += ` AND b.product_id= '` + strconv.Itoa(productId) + `'`
  3994. lossCondition += ` AND b.product_id= '` + strconv.Itoa(productId) + `'`
  3995. permissionCondition += ` AND b.product_id= '` + strconv.Itoa(productId) + `'`
  3996. if status == "全部" {
  3997. ////如果是筛选了流失客户状态
  3998. if sysUser.Authority <= 0 {
  3999. condition += ` AND (b.seller_id= '` + strconv.Itoa(sysUser.AdminId) + `' OR status='流失') `
  4000. permissionCondition += ` AND b.seller_id= ` + strconv.Itoa(sysUser.AdminId)
  4001. } else {
  4002. if sysUser.Authority == 1 {
  4003. condition += ` AND (b.department_id=` + strconv.Itoa(sysUser.DepartmentId) + ` OR status='流失')`
  4004. permissionCondition += ` AND b.department_id=` + strconv.Itoa(sysUser.DepartmentId)
  4005. }
  4006. if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  4007. if status != utils.COMPANY_STATUS_LOSE {
  4008. condition += ` AND (b.group_id=` + strconv.Itoa(sysUser.GroupId) + ` OR status='流失') `
  4009. }
  4010. permissionCondition += ` AND b.group_id=` + strconv.Itoa(sysUser.GroupId)
  4011. }
  4012. if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
  4013. pid, err := company.GetParentIdFromGroup(sysUser.GroupId)
  4014. if err != nil {
  4015. br.Msg = "获取失败"
  4016. br.ErrMsg = "查询父级id异常" + err.Error()
  4017. return
  4018. }
  4019. var ids []*string
  4020. if pid != nil {
  4021. if *pid != 0 {
  4022. //销售主管放在三级列表中
  4023. ids, err = company.GetGroupIdsByParentId(*pid)
  4024. if err != nil {
  4025. fmt.Println(err.Error())
  4026. }
  4027. } else {
  4028. //销售主管放在二级列表中
  4029. ids, err = company.GetGroupIdsByParentId(sysUser.GroupId)
  4030. if err != nil {
  4031. fmt.Println(err.Error())
  4032. }
  4033. }
  4034. }
  4035. var idSlice []string
  4036. var sid string
  4037. for _, id := range ids {
  4038. idSlice = append(idSlice, *id)
  4039. }
  4040. //加入父级groupId
  4041. if *pid > 0 {
  4042. idSlice = append(idSlice, strconv.Itoa(*pid))
  4043. } else {
  4044. idSlice = append(idSlice, strconv.Itoa(sysUser.GroupId))
  4045. }
  4046. sid = strings.Join(idSlice, ",")
  4047. if len(sid) > 0 {
  4048. if status != utils.COMPANY_STATUS_LOSE {
  4049. condition += ` AND (b.group_id IN (` + sid + `) OR status='流失') `
  4050. }
  4051. permissionCondition += ` AND b.group_id IN (` + sid + `) `
  4052. } else {
  4053. if status != utils.COMPANY_STATUS_LOSE {
  4054. condition += ` AND (b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) OR status='流失') `
  4055. }
  4056. permissionCondition += ` AND b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) `
  4057. }
  4058. }
  4059. if sysUser.Authority == 4 {
  4060. if status != utils.COMPANY_STATUS_LOSE {
  4061. condition += ` AND (b.group_id =` + strconv.Itoa(sysUser.GroupId) + ` OR status='流失') `
  4062. //pars = append(pars, sysUser.GroupId)
  4063. }
  4064. permissionCondition += ` AND b.group_id=` + strconv.Itoa(sysUser.GroupId)
  4065. //permissionPars = append(permissionPars, sysUser.GroupId)
  4066. }
  4067. }
  4068. } else {
  4069. //如果没有筛选了流失客户状态,那么需要加客户归属条件加入到查询中去
  4070. if sysUser.Authority <= 0 {
  4071. if status != utils.COMPANY_STATUS_LOSE {
  4072. condition += ` AND b.seller_id=` + strconv.Itoa(sysUser.AdminId)
  4073. //pars = append(pars, sysUser.AdminId)
  4074. }
  4075. permissionCondition += ` AND b.seller_id=` + strconv.Itoa(sysUser.AdminId)
  4076. //permissionPars = append(permissionPars, sysUser.AdminId)
  4077. } else {
  4078. if sysUser.Authority == 1 {
  4079. if status != utils.COMPANY_STATUS_LOSE {
  4080. condition += ` AND b.department_id=` + strconv.Itoa(sysUser.DepartmentId)
  4081. //pars = append(pars, sysUser.DepartmentId)
  4082. }
  4083. permissionCondition += ` AND b.department_id=` + strconv.Itoa(sysUser.DepartmentId)
  4084. //permissionPars = append(permissionPars, sysUser.DepartmentId)
  4085. }
  4086. if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  4087. if status != utils.COMPANY_STATUS_LOSE {
  4088. condition += ` AND b.group_id= ` + strconv.Itoa(sysUser.GroupId)
  4089. //pars = append(pars, sysUser.GroupId)
  4090. }
  4091. permissionCondition += ` AND b.group_id=` + strconv.Itoa(sysUser.GroupId)
  4092. //permissionPars = append(permissionPars, sysUser.GroupId)
  4093. }
  4094. if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
  4095. pid, err := company.GetParentIdFromGroup(sysUser.GroupId)
  4096. if err != nil {
  4097. br.Msg = "获取失败"
  4098. br.ErrMsg = "查询父级id异常" + err.Error()
  4099. return
  4100. }
  4101. var ids []*string
  4102. if pid != nil {
  4103. if *pid != 0 {
  4104. //销售主管放在三级列表中
  4105. ids, err = company.GetGroupIdsByParentId(*pid)
  4106. if err != nil {
  4107. fmt.Println(err.Error())
  4108. }
  4109. } else {
  4110. //销售主管放在二级列表中
  4111. ids, err = company.GetGroupIdsByParentId(sysUser.GroupId)
  4112. if err != nil {
  4113. fmt.Println(err.Error())
  4114. }
  4115. }
  4116. }
  4117. var idSlice []string
  4118. var sid string
  4119. for _, id := range ids {
  4120. idSlice = append(idSlice, *id)
  4121. }
  4122. //加入父级groupId
  4123. if *pid > 0 {
  4124. idSlice = append(idSlice, strconv.Itoa(*pid))
  4125. } else {
  4126. idSlice = append(idSlice, strconv.Itoa(sysUser.GroupId))
  4127. }
  4128. sid = strings.Join(idSlice, ",")
  4129. if len(sid) > 0 {
  4130. if status != utils.COMPANY_STATUS_LOSE {
  4131. condition += ` AND (b.group_id IN (` + sid + `) OR status='流失') `
  4132. //pars = append(pars, sysUser.GroupId)
  4133. }
  4134. permissionCondition += ` AND b.group_id IN (` + sid + `) `
  4135. } else {
  4136. if status != utils.COMPANY_STATUS_LOSE {
  4137. condition += ` AND (b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) OR status='流失') `
  4138. //pars = append(pars, sysUser.GroupId)
  4139. }
  4140. permissionCondition += ` AND b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) `
  4141. }
  4142. }
  4143. if sysUser.Authority == 4 {
  4144. if status != utils.COMPANY_STATUS_LOSE {
  4145. condition += ` AND b.group_id =` + strconv.Itoa(sysUser.GroupId)
  4146. //pars = append(pars, sysUser.GroupId)
  4147. }
  4148. permissionCondition += ` AND b.group_id=` + strconv.Itoa(sysUser.GroupId)
  4149. //permissionPars = append(permissionPars, sysUser.GroupId)
  4150. }
  4151. }
  4152. }
  4153. }
  4154. }
  4155. }
  4156. //condition += ` AND b.status IN ('正式','试用','冻结') `
  4157. //companyCondition := `SELECT a.company_id FROM company AS a INNER JOIN company_product AS b ON a.company_id=b.company_id WHERE a.enabled=1 `
  4158. //if condition != "" {
  4159. // companyCondition += condition
  4160. //}
  4161. condition += ` AND b.status IN ('正式','试用','冻结') `
  4162. companyCondition := `SELECT a.company_id FROM company AS a INNER JOIN company_product AS b ON a.company_id=b.company_id WHERE a.enabled=1 `
  4163. companyIdsCondition := `SELECT GROUP_CONCAT( DISTINCT a.company_id SEPARATOR ',' ) AS company_ids FROM company AS a INNER JOIN company_product AS b ON a.company_id=b.company_id WHERE a.enabled=1 `
  4164. if condition != "" {
  4165. companyCondition += condition
  4166. }
  4167. companyIdsCondition += condition
  4168. var companyIds string
  4169. companyIds, err = cygx.GetCompanyIdsCondition(companyIdsCondition)
  4170. companyIds, err = cygx.GetCompanyIdsCondition(companyIdsCondition)
  4171. if err != nil {
  4172. br.Msg = "获取失败"
  4173. br.ErrMsg = "获取公司ID数据失败,Err:" + err.Error()
  4174. return
  4175. }
  4176. condition = ` AND r.company_id IN ( ` + companyIds + ` )AND r.create_time < date_format(now(),'%Y-%m-%d') ` //过滤当天时间
  4177. if keyWord != "" {
  4178. condition += ` AND (r.mobile LIKE '%` + keyWord + `%' OR r.email LIKE '%` + keyWord + `%' OR r.real_name LIKE '%` + keyWord + `%'` + ` OR r.company_name LIKE '%` + keyWord + `%') `
  4179. }
  4180. var isAdminRole bool
  4181. var pageSize = 9999
  4182. //如果不是管理员身份或者研究员身份则需要添加可见范围处理
  4183. if sysUser.Role == utils.ROLE_TYPE_CODE_ADMIN || sysUser.Role == utils.ROLE_TYPE_CODE_RESEARCHR {
  4184. isAdminRole = true
  4185. }
  4186. if source == 1 {
  4187. if startDate != "" {
  4188. startDate += " 00:00:00"
  4189. condition += ` AND r.create_time >= '` + startDate + `' `
  4190. }
  4191. if endDate != "" {
  4192. endDate += " 23:59:59"
  4193. condition += ` AND r.create_time <= '` + endDate + `' `
  4194. }
  4195. condition += ` ORDER BY r.create_time DESC `
  4196. var pars []interface{}
  4197. var listRecord []*cygx.CygxArticleAndYanxuanRecordResp
  4198. if isAdminRole {
  4199. listRecord, err = cygx.GetCygxArticleAndYanxuanRecordRespList(condition, pars, 0, pageSize)
  4200. if err != nil && err.Error() != utils.ErrNoRow() {
  4201. br.Msg = "获取信息失败"
  4202. br.ErrMsg = "获取用户阅读记录,Err:" + err.Error()
  4203. return
  4204. }
  4205. } else {
  4206. listRecord, err = cygx.GetCygxArticleAndYanxuanRecordRespListWeekly(condition, pars, 0, pageSize)
  4207. if err != nil && err.Error() != utils.ErrNoRow() {
  4208. br.Msg = "获取信息失败"
  4209. br.ErrMsg = "获取用户阅读记录,Err:" + err.Error()
  4210. return
  4211. }
  4212. }
  4213. //处理查询信息回显
  4214. list, err = cygxService.HandleArticleAndYanxuanRecordList(listRecord)
  4215. if err != nil && err.Error() != utils.ErrNoRow() {
  4216. br.Msg = "获取信息失败"
  4217. br.ErrMsg = "获取用户阅读记录,Err:" + err.Error()
  4218. return
  4219. }
  4220. if len(list) > 0 {
  4221. var articleIds string
  4222. mapAricleId := make(map[int]int)
  4223. mapAricleIndustrialSubjectName := make(map[int]*cygx.ArticleIndustrialSubjectNameResp)
  4224. for k, v := range list {
  4225. if v.ArticleId >= utils.SummaryArticleId {
  4226. list[k].ArticleType = 1
  4227. } else {
  4228. list[k].ArticleType = 2
  4229. }
  4230. if list[k].PermissionName == "" {
  4231. list[k].PermissionName = v.CategoryName
  4232. }
  4233. if mapAricleId[v.ArticleId] == 0 {
  4234. articleIds += strconv.Itoa(v.ArticleId) + ","
  4235. mapAricleId[v.ArticleId] = v.ArticleId
  4236. }
  4237. }
  4238. articleIds = strings.TrimRight(articleIds, ",")
  4239. if articleIds != "" {
  4240. listArticleIndustrialSubjectList, err := cygx.GetCygxArticleIndustrialSubjectName(articleIds)
  4241. if err != nil && err.Error() != utils.ErrNoRow() {
  4242. br.Msg = "获取信息失败"
  4243. br.ErrMsg = "获取用户阅读记录,Err:" + err.Error()
  4244. return
  4245. }
  4246. if len(listArticleIndustrialSubjectList) > 0 {
  4247. for _, v := range listArticleIndustrialSubjectList {
  4248. mapAricleIndustrialSubjectName[v.ArticleId] = v
  4249. }
  4250. for k, v := range list {
  4251. if mapAricleIndustrialSubjectName[v.ArticleId] != nil {
  4252. fmt.Println(mapAricleIndustrialSubjectName[v.ArticleId].IndustryName)
  4253. list[k].IndustryName = mapAricleIndustrialSubjectName[v.ArticleId].IndustryName
  4254. list[k].SubjectNameStr = mapAricleIndustrialSubjectName[v.ArticleId].SubjectNameStr
  4255. }
  4256. }
  4257. }
  4258. }
  4259. }
  4260. } else if source == 2 {
  4261. if isMeeting == "1" {
  4262. condition += ` AND r.is_meeting = 1 `
  4263. }
  4264. if isMeeting == "2" {
  4265. condition += ` AND r.is_meeting = 0 `
  4266. }
  4267. if meetType == "1" {
  4268. condition += ` AND t.activity_type = 1 `
  4269. }
  4270. if meetType == "2" {
  4271. condition += ` AND t.activity_type = 0 `
  4272. }
  4273. if startDate != "" {
  4274. startDate += " 00:00:00"
  4275. condition += ` AND a.activity_time >= '` + startDate + `' `
  4276. }
  4277. if endDate != "" {
  4278. endDate += " 23:59:59"
  4279. condition += ` AND a.activity_time <= '` + endDate + `' `
  4280. }
  4281. if activityName != "" {
  4282. condition += ` AND a.activity_name LIKE '%` + activityName + `%' `
  4283. }
  4284. if isAdminRole {
  4285. list, err = cygx.GetActivityMeetByCompany(condition, 0, pageSize)
  4286. if err != nil && err.Error() != utils.ErrNoRow() {
  4287. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  4288. br.Msg = "获取参会人数列表失败"
  4289. return
  4290. }
  4291. } else {
  4292. list, err = cygx.GetActivityMeetByCompanyWeekly(condition, 0, pageSize)
  4293. if err != nil && err.Error() != utils.ErrNoRow() {
  4294. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  4295. br.Msg = "获取参会人数列表失败"
  4296. return
  4297. }
  4298. }
  4299. if len(list) > 0 {
  4300. for k, v := range list {
  4301. if v.ActivityType == 1 {
  4302. if v.SignupType == "2" {
  4303. list[k].InteractionType = "自主拨入"
  4304. } else {
  4305. list[k].InteractionType = "预约外呼"
  4306. }
  4307. if v.ReminderNum > 0 {
  4308. list[k].InteractionType += ",会议提醒"
  4309. }
  4310. }
  4311. }
  4312. }
  4313. }
  4314. //创建excel
  4315. dir, err := os.Executable()
  4316. exPath := filepath.Dir(dir)
  4317. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  4318. xlsxFile := xlsx.NewFile()
  4319. if err != nil {
  4320. br.Msg = "生成文件失败"
  4321. br.ErrMsg = "生成文件失败"
  4322. return
  4323. }
  4324. style := xlsx.NewStyle()
  4325. alignment := xlsx.Alignment{
  4326. Horizontal: "center",
  4327. Vertical: "center",
  4328. WrapText: true,
  4329. }
  4330. var excelName string
  4331. style.Alignment = alignment
  4332. style.ApplyAlignment = true
  4333. sheet, err := xlsxFile.AddSheet("到会管理名单")
  4334. if err != nil {
  4335. br.Msg = "新增Sheet失败"
  4336. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  4337. return
  4338. }
  4339. if source == 1 {
  4340. excelName = "客户阅读记录"
  4341. //标头
  4342. rowTitle := sheet.AddRow()
  4343. cellA := rowTitle.AddCell()
  4344. cellA.Value = "客户名称"
  4345. cellB := rowTitle.AddCell()
  4346. cellB.Value = "所属销售"
  4347. cellC := rowTitle.AddCell()
  4348. cellC.Value = "姓名"
  4349. cellD := rowTitle.AddCell()
  4350. cellD.Value = "手机号"
  4351. cellE := rowTitle.AddCell()
  4352. cellE.Value = "报告标题"
  4353. cellF := rowTitle.AddCell()
  4354. cellF.Value = "所属行业"
  4355. cellG := rowTitle.AddCell()
  4356. cellG.Value = "所属产业"
  4357. cellH := rowTitle.AddCell()
  4358. cellH.Value = "关联标的"
  4359. cellI := rowTitle.AddCell()
  4360. cellI.Value = "发布时间"
  4361. cellJ := rowTitle.AddCell()
  4362. cellJ.Value = "阅读时间"
  4363. cellK := rowTitle.AddCell()
  4364. cellK.Value = "阅读时长"
  4365. for _, item := range list {
  4366. row := sheet.AddRow()
  4367. cellA := row.AddCell()
  4368. cellA.Value = item.CompanyName
  4369. cellB := row.AddCell()
  4370. cellB.Value = item.SellerName
  4371. cellC := row.AddCell()
  4372. cellC.Value = item.RealName
  4373. cellD := row.AddCell()
  4374. cellD.Value = item.Mobile
  4375. cellE := row.AddCell()
  4376. cellE.Value = item.Title
  4377. cellF := row.AddCell()
  4378. cellF.Value = item.PermissionName
  4379. cellG := row.AddCell()
  4380. cellG.Value = item.IndustryName
  4381. cellH := row.AddCell()
  4382. cellH.Value = item.SubjectNameStr
  4383. cellI := row.AddCell()
  4384. cellI.Value = item.PublishDate
  4385. cellJ := row.AddCell()
  4386. cellJ.Value = item.CreateTime
  4387. cellK := row.AddCell()
  4388. cellK.Value = item.StopTime
  4389. }
  4390. } else {
  4391. excelName = "客户参会记录"
  4392. //标头
  4393. rowTitle := sheet.AddRow()
  4394. cellA := rowTitle.AddCell()
  4395. cellA.Value = "客户名称"
  4396. cellB := rowTitle.AddCell()
  4397. cellB.Value = "所属销售"
  4398. cellC := rowTitle.AddCell()
  4399. cellC.Value = "姓名"
  4400. cellD := rowTitle.AddCell()
  4401. cellD.Value = "手机号"
  4402. cellE := rowTitle.AddCell()
  4403. cellE.Value = "活动名称"
  4404. cellF := rowTitle.AddCell()
  4405. cellF.Value = "所属行业"
  4406. cellG := rowTitle.AddCell()
  4407. cellG.Value = "活动类型"
  4408. cellH := rowTitle.AddCell()
  4409. cellH.Value = "活动主题"
  4410. cellI := rowTitle.AddCell()
  4411. cellI.Value = "活动时间"
  4412. cellJ := rowTitle.AddCell()
  4413. cellJ.Value = "是否到会"
  4414. cellK := rowTitle.AddCell()
  4415. cellK.Value = "首次入会时间"
  4416. cellL := rowTitle.AddCell()
  4417. cellL.Value = "最后退出时间"
  4418. cellM := rowTitle.AddCell()
  4419. cellM.Value = "参与总时长"
  4420. cellN := rowTitle.AddCell()
  4421. cellN.Value = "参会方式"
  4422. cellO := rowTitle.AddCell()
  4423. cellO.Value = "参会权鉴"
  4424. cellP := rowTitle.AddCell()
  4425. cellP.Value = "参会状态"
  4426. for _, item := range list {
  4427. row := sheet.AddRow()
  4428. cellA := row.AddCell()
  4429. cellA.Value = item.CompanyName
  4430. cellB := row.AddCell()
  4431. cellB.Value = item.SellerName
  4432. cellC := row.AddCell()
  4433. cellC.Value = item.RealName
  4434. cellD := row.AddCell()
  4435. cellD.Value = item.Mobile
  4436. cellE := row.AddCell()
  4437. cellE.Value = item.ActivityName
  4438. cellF := row.AddCell()
  4439. cellF.Value = item.PermissionName
  4440. cellG := row.AddCell()
  4441. cellG.Value = item.ActivityTypeName
  4442. cellH := row.AddCell()
  4443. cellH.Value = item.Label
  4444. cellI := row.AddCell()
  4445. cellI.Value = item.ActivityTime
  4446. cellJ := row.AddCell()
  4447. if item.IsMeeting == 1 {
  4448. cellJ.Value = "到会"
  4449. } else {
  4450. cellJ.Value = "未到会"
  4451. }
  4452. cellK := row.AddCell()
  4453. cellK.Value = item.FirstMeetingTime
  4454. cellL := row.AddCell()
  4455. cellL.Value = item.LastMeetingTime
  4456. cellM := row.AddCell()
  4457. cellM.Value = item.Duration
  4458. cellN := row.AddCell()
  4459. cellN.Value = item.LastMeetingTime
  4460. cellO := row.AddCell()
  4461. cellO.Value = item.MeetingTypeStr
  4462. cellP := row.AddCell()
  4463. cellP.Value = item.MeetingStatusStr
  4464. }
  4465. }
  4466. err = xlsxFile.Save(downLoadnFilePath)
  4467. if err != nil {
  4468. br.Msg = "保存文件失败"
  4469. br.ErrMsg = "保存文件失败"
  4470. return
  4471. }
  4472. randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
  4473. downloadFileName := excelName + randStr + ".xlsx"
  4474. this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  4475. defer func() {
  4476. os.Remove(downLoadnFilePath)
  4477. }()
  4478. br.Ret = 200
  4479. br.Success = true
  4480. br.Msg = "获取成功"
  4481. }
  4482. // @Title 机构列表互动详情table栏
  4483. // @Description 机构列表互动详情table栏接口
  4484. // @Param ClassType query int true "列表类型,1:权益,2:研选,默认1"
  4485. // @Success 200 {object} cygx.CygxUserTableListRep
  4486. // @router /user/table/companyList [get]
  4487. func (this *UserController) TableCompanyList() {
  4488. br := new(models.BaseResponse).Init()
  4489. defer func() {
  4490. this.Data["json"] = br
  4491. this.ServeJSON()
  4492. }()
  4493. sysUser := this.SysUser
  4494. if sysUser == nil {
  4495. br.Msg = "请登录"
  4496. br.ErrMsg = "请登录,SysUser Is Empty"
  4497. br.Ret = 408
  4498. return
  4499. }
  4500. roleTypeCode := sysUser.RoleTypeCode
  4501. status := this.GetString("Status")
  4502. classType, _ := this.GetInt("ClassType", 1)
  4503. //流失
  4504. var lossCondition string
  4505. var condition string
  4506. //var lossPars []interface{}
  4507. //状态分类查询条件
  4508. var permissionCondition string
  4509. lossCondition = condition
  4510. //lossPars = pars
  4511. permissionCondition = condition
  4512. //流失客户统计
  4513. lossCondition += ` AND status='流失' `
  4514. //productId := services.GetProductId(roleTypeCode)
  4515. productId := 2
  4516. //权限控制
  4517. {
  4518. //如果不是超级管理员或者财务
  4519. if roleTypeCode != utils.ROLE_TYPE_CODE_ADMIN && roleTypeCode != utils.ROLE_TYPE_CODE_FINANCE {
  4520. //如果是部门管理员
  4521. if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  4522. condition += ` AND b.product_id= '` + strconv.Itoa(productId) + `'`
  4523. lossCondition += ` AND b.product_id= '` + strconv.Itoa(productId) + `'`
  4524. permissionCondition += ` AND b.product_id= '` + strconv.Itoa(productId) + `'`
  4525. } else {
  4526. condition += ` AND b.product_id= '` + strconv.Itoa(productId) + `'`
  4527. lossCondition += ` AND b.product_id= '` + strconv.Itoa(productId) + `'`
  4528. permissionCondition += ` AND b.product_id= '` + strconv.Itoa(productId) + `'`
  4529. if status == "全部" {
  4530. ////如果是筛选了流失客户状态
  4531. if sysUser.Authority <= 0 {
  4532. condition += ` AND (b.seller_id= '` + strconv.Itoa(sysUser.AdminId) + `' OR status='流失') `
  4533. permissionCondition += ` AND b.seller_id= ` + strconv.Itoa(sysUser.AdminId)
  4534. } else {
  4535. if sysUser.Authority == 1 {
  4536. condition += ` AND (b.department_id=` + strconv.Itoa(sysUser.DepartmentId) + ` OR status='流失')`
  4537. permissionCondition += ` AND b.department_id=` + strconv.Itoa(sysUser.DepartmentId)
  4538. }
  4539. if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  4540. if status != utils.COMPANY_STATUS_LOSE {
  4541. condition += ` AND (b.group_id=` + strconv.Itoa(sysUser.GroupId) + ` OR status='流失') `
  4542. }
  4543. permissionCondition += ` AND b.group_id=` + strconv.Itoa(sysUser.GroupId)
  4544. }
  4545. if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
  4546. pid, err := company.GetParentIdFromGroup(sysUser.GroupId)
  4547. if err != nil {
  4548. br.Msg = "获取失败"
  4549. br.ErrMsg = "查询父级id异常" + err.Error()
  4550. return
  4551. }
  4552. var ids []*string
  4553. if pid != nil {
  4554. if *pid != 0 {
  4555. //销售主管放在三级列表中
  4556. ids, err = company.GetGroupIdsByParentId(*pid)
  4557. if err != nil {
  4558. fmt.Println(err.Error())
  4559. }
  4560. } else {
  4561. //销售主管放在二级列表中
  4562. ids, err = company.GetGroupIdsByParentId(sysUser.GroupId)
  4563. if err != nil {
  4564. fmt.Println(err.Error())
  4565. }
  4566. }
  4567. }
  4568. var idSlice []string
  4569. var sid string
  4570. for _, id := range ids {
  4571. idSlice = append(idSlice, *id)
  4572. }
  4573. //加入父级groupId
  4574. if *pid > 0 {
  4575. idSlice = append(idSlice, strconv.Itoa(*pid))
  4576. } else {
  4577. idSlice = append(idSlice, strconv.Itoa(sysUser.GroupId))
  4578. }
  4579. sid = strings.Join(idSlice, ",")
  4580. if len(sid) > 0 {
  4581. if status != utils.COMPANY_STATUS_LOSE {
  4582. condition += ` AND (b.group_id IN (` + sid + `) OR status='流失') `
  4583. }
  4584. permissionCondition += ` AND b.group_id IN (` + sid + `) `
  4585. } else {
  4586. if status != utils.COMPANY_STATUS_LOSE {
  4587. condition += ` AND (b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) OR status='流失') `
  4588. }
  4589. permissionCondition += ` AND b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) `
  4590. }
  4591. }
  4592. if sysUser.Authority == 4 {
  4593. if status != utils.COMPANY_STATUS_LOSE {
  4594. condition += ` AND (b.group_id =` + strconv.Itoa(sysUser.GroupId) + ` OR status='流失') `
  4595. //pars = append(pars, sysUser.GroupId)
  4596. }
  4597. permissionCondition += ` AND b.group_id=` + strconv.Itoa(sysUser.GroupId)
  4598. //permissionPars = append(permissionPars, sysUser.GroupId)
  4599. }
  4600. }
  4601. } else {
  4602. //如果没有筛选了流失客户状态,那么需要加客户归属条件加入到查询中去
  4603. if sysUser.Authority <= 0 {
  4604. if status != utils.COMPANY_STATUS_LOSE {
  4605. condition += ` AND b.seller_id=` + strconv.Itoa(sysUser.AdminId)
  4606. //pars = append(pars, sysUser.AdminId)
  4607. }
  4608. permissionCondition += ` AND b.seller_id=` + strconv.Itoa(sysUser.AdminId)
  4609. //permissionPars = append(permissionPars, sysUser.AdminId)
  4610. } else {
  4611. if sysUser.Authority == 1 {
  4612. if status != utils.COMPANY_STATUS_LOSE {
  4613. condition += ` AND b.department_id=` + strconv.Itoa(sysUser.DepartmentId)
  4614. //pars = append(pars, sysUser.DepartmentId)
  4615. }
  4616. permissionCondition += ` AND b.department_id=` + strconv.Itoa(sysUser.DepartmentId)
  4617. //permissionPars = append(permissionPars, sysUser.DepartmentId)
  4618. }
  4619. if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  4620. if status != utils.COMPANY_STATUS_LOSE {
  4621. condition += ` AND b.group_id= ` + strconv.Itoa(sysUser.GroupId)
  4622. //pars = append(pars, sysUser.GroupId)
  4623. }
  4624. permissionCondition += ` AND b.group_id=` + strconv.Itoa(sysUser.GroupId)
  4625. //permissionPars = append(permissionPars, sysUser.GroupId)
  4626. }
  4627. if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
  4628. pid, err := company.GetParentIdFromGroup(sysUser.GroupId)
  4629. if err != nil {
  4630. br.Msg = "获取失败"
  4631. br.ErrMsg = "查询父级id异常" + err.Error()
  4632. return
  4633. }
  4634. var ids []*string
  4635. if pid != nil {
  4636. if *pid != 0 {
  4637. //销售主管放在三级列表中
  4638. ids, err = company.GetGroupIdsByParentId(*pid)
  4639. if err != nil {
  4640. fmt.Println(err.Error())
  4641. }
  4642. } else {
  4643. //销售主管放在二级列表中
  4644. ids, err = company.GetGroupIdsByParentId(sysUser.GroupId)
  4645. if err != nil {
  4646. fmt.Println(err.Error())
  4647. }
  4648. }
  4649. }
  4650. var idSlice []string
  4651. var sid string
  4652. for _, id := range ids {
  4653. idSlice = append(idSlice, *id)
  4654. }
  4655. //加入父级groupId
  4656. if *pid > 0 {
  4657. idSlice = append(idSlice, strconv.Itoa(*pid))
  4658. } else {
  4659. idSlice = append(idSlice, strconv.Itoa(sysUser.GroupId))
  4660. }
  4661. sid = strings.Join(idSlice, ",")
  4662. if len(sid) > 0 {
  4663. if status != utils.COMPANY_STATUS_LOSE {
  4664. condition += ` AND (b.group_id IN (` + sid + `) OR status='流失') `
  4665. //pars = append(pars, sysUser.GroupId)
  4666. }
  4667. permissionCondition += ` AND b.group_id IN (` + sid + `) `
  4668. } else {
  4669. if status != utils.COMPANY_STATUS_LOSE {
  4670. condition += ` AND (b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) OR status='流失') `
  4671. //pars = append(pars, sysUser.GroupId)
  4672. }
  4673. permissionCondition += ` AND b.group_id IN (` + strconv.Itoa(sysUser.GroupId) + `) `
  4674. }
  4675. }
  4676. if sysUser.Authority == 4 {
  4677. if status != utils.COMPANY_STATUS_LOSE {
  4678. condition += ` AND b.group_id =` + strconv.Itoa(sysUser.GroupId)
  4679. //pars = append(pars, sysUser.GroupId)
  4680. }
  4681. permissionCondition += ` AND b.group_id=` + strconv.Itoa(sysUser.GroupId)
  4682. //permissionPars = append(permissionPars, sysUser.GroupId)
  4683. }
  4684. }
  4685. }
  4686. }
  4687. }
  4688. }
  4689. condition += ` AND b.status IN ('正式','试用','冻结') `
  4690. companyCondition := ` AND a.enabled=1 `
  4691. if condition != "" {
  4692. companyCondition += condition
  4693. }
  4694. resp := new(cygx.CygxUserTableListRep)
  4695. var isAdminRole bool
  4696. //如果不是管理员身份或者研究员身份则需要添加可见范围处理
  4697. if sysUser.Role == utils.ROLE_TYPE_CODE_ADMIN || sysUser.Role == utils.ROLE_TYPE_CODE_RESEARCHR {
  4698. isAdminRole = true
  4699. }
  4700. var pars []interface{}
  4701. lsitCompany, err := company.GetCompanyProductListBycondition(condition, pars)
  4702. if err != nil {
  4703. br.Msg = "获取失败"
  4704. br.ErrMsg = "获取数据失败,GetCompanyProductListBycondition Err:" + err.Error()
  4705. return
  4706. }
  4707. var companyIds []string
  4708. for _, v := range lsitCompany {
  4709. companyIds = append(companyIds, strconv.Itoa(v.CompanyId))
  4710. }
  4711. condition = " AND r.company_id IN (" + strings.Join(companyIds, ",") + ")"
  4712. condition += ` AND r.create_time < date_format(now(),'%Y-%m-%d') ` //过滤当天时间
  4713. conditionArtcile := condition //文章搜索条件
  4714. conditionActivityMeet := condition //活动到会搜索条件
  4715. conditionIndustryFllow := condition //产业关注搜索条件
  4716. conditionKeyWord := condition //关键词记录搜索条件
  4717. if classType == 1 {
  4718. conditionArtcile += " AND art.article_type_id = 0 "
  4719. conditionActivityMeet += " AND a.chart_permission_id != 31 "
  4720. conditionIndustryFllow += " AND m.chart_permission_id != 31 "
  4721. conditionKeyWord += " AND r.register_platform IN (1,2) "
  4722. } else {
  4723. conditionArtcile += " AND art.article_type_id > 0 "
  4724. conditionActivityMeet += " AND a.chart_permission_id = 31 "
  4725. conditionIndustryFllow += " AND m.chart_permission_id = 31 "
  4726. conditionKeyWord += " AND r.register_platform IN (5,6) "
  4727. }
  4728. var historyNum int //报告阅读列表
  4729. var activityNum int //活动互动记录
  4730. var triptotal int //专项调研
  4731. var articleCollect int //收藏的报告
  4732. var chartNum int //收藏图表
  4733. var industryFllowNum int //关注的产业
  4734. var departmentFollowNum int //关注的作者
  4735. var keyWordNum int //搜索
  4736. var roadshowTotal int //音视频播放
  4737. var tagNum int //首页标签点击
  4738. var yanxuanSpecialNum int //专栏文章阅读记录
  4739. var yanxuanSpecialCollectNum int //收藏的专栏文章
  4740. var yanxuanSpecialFollowNum int //关注的专栏作者
  4741. if isAdminRole {
  4742. historyNum, err = cygx.GetCygxArticleAndYanxuanRecordCount(conditionArtcile, pars)
  4743. if err != nil {
  4744. br.Msg = "获取信息失败"
  4745. br.ErrMsg = "获取用户阅读记录数量失败,Err:" + err.Error()
  4746. return
  4747. }
  4748. //获取参会总数
  4749. activityNum, err = cygx.GetActivityMeetByCompanyCount(conditionActivityMeet)
  4750. if err != nil {
  4751. br.Msg = "获取信息失败"
  4752. br.ErrMsg = "获取参会总数失败,Err:" + err.Error()
  4753. return
  4754. }
  4755. //获取用户收藏记录总数
  4756. articleCollect, err = cygx.GetCygxArticleCollectCountByCompany(conditionArtcile)
  4757. if err != nil {
  4758. br.Msg = "获取信息失败"
  4759. br.ErrMsg = "获取用户收藏记录总数失败,Err:" + err.Error()
  4760. return
  4761. }
  4762. //获取用户关注总数
  4763. industryFllowNum, err = cygx.GetCygxIndustryFllowCountByCompany(conditionIndustryFllow)
  4764. if err != nil {
  4765. br.Msg = "获取信息失败 "
  4766. br.ErrMsg = "获取用户关注总数失败,Err:" + err.Error()
  4767. return
  4768. }
  4769. //获取关注作者总数
  4770. departmentFollowNum, err = cygx.GetCygArticleDepartmentFollowCountByCompany(condition)
  4771. if err != nil {
  4772. br.Msg = "获取信息失败"
  4773. br.ErrMsg = "获取关注作者总数失败,Err:" + err.Error()
  4774. return
  4775. }
  4776. //获取搜索记录
  4777. keyWordNum, err = cygx.GetCygxSearchKeyWordCountBuCompany(conditionKeyWord)
  4778. if err != nil {
  4779. br.Msg = "获取信息失败"
  4780. br.ErrMsg = "获取搜索记录失败,Err:" + err.Error()
  4781. return
  4782. }
  4783. chartNum, err = cygx.GetChartCountByUserMobile(condition)
  4784. if err != nil {
  4785. br.Msg = "获取信息失败"
  4786. br.ErrMsg = "获取总数失败,Err:" + err.Error()
  4787. return
  4788. }
  4789. triptotal, err = cygx.GetCygxActivitySpecialTripCountByCompany(condition)
  4790. if err != nil {
  4791. br.Msg = "获取信息失败"
  4792. br.ErrMsg = "获取搜索记录失败,Err:" + err.Error()
  4793. return
  4794. }
  4795. roadshowTotal, err = cygx.GetCygxRoadshowCountByCompany(condition)
  4796. if err != nil {
  4797. br.Msg = "获取信息失败"
  4798. br.ErrMsg = "获取搜索记录失败,Err:" + err.Error()
  4799. return
  4800. }
  4801. tagNum, err = cygx.GetCygxTagHistoryCount(condition)
  4802. if err != nil {
  4803. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  4804. br.Msg = "获取搜索记录失败"
  4805. return
  4806. }
  4807. yanxuanSpecialNum, err = cygx.GetCygxYanxuanSpecialRecordCount(condition, pars)
  4808. if err != nil {
  4809. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  4810. br.Msg = "获取研选专栏阅读数量失败"
  4811. return
  4812. }
  4813. yanxuanSpecialCollectNum, err = cygx.GetCygxYanxuanSpecialCollectCount(condition, pars)
  4814. if err != nil {
  4815. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  4816. br.Msg = "获取收藏的专栏文章数量失败"
  4817. return
  4818. }
  4819. yanxuanSpecialFollowNum, err = cygx.GetCygxYanxuanSpecialFollowCount(condition, pars)
  4820. if err != nil {
  4821. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  4822. br.Msg = "获取关注的专栏作者数量失败"
  4823. return
  4824. }
  4825. //List := []*cygx.CygxUserTableRep{{PermissionName: "报告阅读列表", Source: 1, TotalNum: historyNum},
  4826. // {PermissionName: "活动互动记录", Source: 2, TotalNum: activityNum},
  4827. // {PermissionName: "专项调研", Source: 8, TotalNum: triptotal},
  4828. // {PermissionName: "收藏的报告", Source: 3, TotalNum: articleCollect},
  4829. // {PermissionName: "收藏图表", Source: 4, TotalNum: chartNum},
  4830. // {PermissionName: "关注的产业", Source: 5, TotalNum: industryFllowNum},
  4831. // {PermissionName: "关注的作者", Source: 6, TotalNum: departmentFollowNum},
  4832. // {PermissionName: "搜索", Source: 7, TotalNum: keyWordNum},
  4833. // {PermissionName: "音视频播放", Source: 9, TotalNum: roadshowTotal},
  4834. // {PermissionName: "首页标签点击", Source: 10, TotalNum: tagNum}}
  4835. //resp.List = List
  4836. } else {
  4837. historyNum, err = cygx.GetCygxArticleAndYanxuanRecordCountWeekly(conditionArtcile, pars)
  4838. if err != nil {
  4839. br.Msg = "获取信息失败"
  4840. br.ErrMsg = "获取用户阅读记录数量失败,Err:" + err.Error()
  4841. return
  4842. }
  4843. //获取参会总数
  4844. activityNum, err = cygx.GetActivityMeetByCompanyCountWeekly(conditionActivityMeet)
  4845. if err != nil {
  4846. br.Msg = "获取信息失败"
  4847. br.ErrMsg = "获取参会总数失败,Err:" + err.Error()
  4848. return
  4849. }
  4850. //获取用户收藏记录总数
  4851. articleCollect, err = cygx.GetCygxArticleCollectCountByCompanyWeekly(conditionArtcile)
  4852. if err != nil {
  4853. br.Msg = "获取信息失败"
  4854. br.ErrMsg = "获取用户收藏记录总数失败,Err:" + err.Error()
  4855. return
  4856. }
  4857. //获取用户关注总数
  4858. industryFllowNum, err = cygx.GetCygxIndustryFllowCountByCompanyWeekly(conditionIndustryFllow)
  4859. if err != nil {
  4860. br.Msg = "获取信息失败 "
  4861. br.ErrMsg = "获取用户关注总数失败,Err:" + err.Error()
  4862. return
  4863. }
  4864. //获取关注作者总数
  4865. departmentFollowNum, err = cygx.GetCygArticleDepartmentFollowCountByCompanyWeekly(condition)
  4866. if err != nil {
  4867. br.Msg = "获取信息失败"
  4868. br.ErrMsg = "获取关注作者总数失败,Err:" + err.Error()
  4869. return
  4870. }
  4871. //获取搜索记录
  4872. keyWordNum, err = cygx.GetCygxSearchKeyWordCountBuCompanyWeekly(conditionKeyWord)
  4873. if err != nil {
  4874. br.Msg = "获取信息失败"
  4875. br.ErrMsg = "获取搜索记录失败,Err:" + err.Error()
  4876. return
  4877. }
  4878. chartNum, err = cygx.GetChartCountByUserMobileWeekly(condition)
  4879. if err != nil {
  4880. br.Msg = "获取信息失败"
  4881. br.ErrMsg = "获取总数失败,Err:" + err.Error()
  4882. return
  4883. }
  4884. triptotal, err = cygx.GetCygxActivitySpecialTripCountByCompanyWeekly(condition)
  4885. if err != nil {
  4886. br.Msg = "获取信息失败"
  4887. br.ErrMsg = "获取搜索记录失败,Err:" + err.Error()
  4888. return
  4889. }
  4890. roadshowTotal, err = cygx.GetCygxRoadshowCountByCompanyWeekly(condition)
  4891. if err != nil {
  4892. br.Msg = "获取信息失败"
  4893. br.ErrMsg = "获取搜索记录失败,Err:" + err.Error()
  4894. return
  4895. }
  4896. tagNum, err = cygx.GetCygxTagHistoryCountWeekly(condition)
  4897. if err != nil {
  4898. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  4899. br.Msg = "获取搜索记录失败"
  4900. return
  4901. }
  4902. yanxuanSpecialNum, err = cygx.GetCygxYanxuanSpecialRecordCountWeekly(condition, pars)
  4903. if err != nil {
  4904. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  4905. br.Msg = "获取研选专栏阅读数量失败"
  4906. return
  4907. }
  4908. yanxuanSpecialCollectNum, err = cygx.GetCygxYanxuanSpecialCollectCountWeekly(condition, pars)
  4909. if err != nil {
  4910. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  4911. br.Msg = "获取收藏的专栏文章数量失败"
  4912. return
  4913. }
  4914. yanxuanSpecialFollowNum, err = cygx.GetCygxYanxuanSpecialFollowCountWeekly(condition, pars)
  4915. if err != nil {
  4916. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  4917. br.Msg = "获取关注的专栏作者数量失败"
  4918. return
  4919. }
  4920. //List := []*cygx.CygxUserTableRep{{PermissionName: "报告阅读列表", Source: 1, TotalNum: historyNum},
  4921. // {PermissionName: "活动互动记录", Source: 2, TotalNum: activityNum},
  4922. // {PermissionName: "专项调研", Source: 8, TotalNum: triptotal},
  4923. // {PermissionName: "收藏的报告", Source: 3, TotalNum: articleCollect},
  4924. // {PermissionName: "收藏图表", Source: 4, TotalNum: chartNum},
  4925. // {PermissionName: "关注的产业", Source: 5, TotalNum: industryFllowNum},
  4926. // {PermissionName: "关注的作者", Source: 6, TotalNum: departmentFollowNum},
  4927. // {PermissionName: "搜索", Source: 7, TotalNum: keyWordNum},
  4928. // {PermissionName: "音视频播放", Source: 9, TotalNum: roadshowTotal},
  4929. // {PermissionName: "首页标签点击", Source: 10, TotalNum: tagNum}}
  4930. //resp.List = List
  4931. }
  4932. if classType == 1 {
  4933. List := []*cygx.CygxUserTableRep{{PermissionName: "报告阅读列表", Source: 1, TotalNum: historyNum},
  4934. {PermissionName: "活动互动记录", Source: 2, TotalNum: activityNum},
  4935. {PermissionName: "专项调研", Source: 8, TotalNum: triptotal},
  4936. {PermissionName: "收藏的报告", Source: 3, TotalNum: articleCollect},
  4937. {PermissionName: "收藏图表", Source: 4, TotalNum: chartNum},
  4938. {PermissionName: "关注的产业", Source: 5, TotalNum: industryFllowNum},
  4939. {PermissionName: "搜索", Source: 7, TotalNum: keyWordNum},
  4940. {PermissionName: "音视频播放", Source: 9, TotalNum: roadshowTotal},
  4941. {PermissionName: "首页标签点击", Source: 10, TotalNum: tagNum}}
  4942. resp.List = List
  4943. } else {
  4944. List := []*cygx.CygxUserTableRep{{PermissionName: "报告阅读列表", Source: 1, TotalNum: historyNum},
  4945. {PermissionName: "活动互动记录", Source: 2, TotalNum: activityNum},
  4946. {PermissionName: "收藏的报告", Source: 3, TotalNum: articleCollect},
  4947. {PermissionName: "关注的产业", Source: 5, TotalNum: industryFllowNum},
  4948. {PermissionName: "关注的作者", Source: 6, TotalNum: departmentFollowNum},
  4949. {PermissionName: "专栏文章阅读记录", Source: 11, TotalNum: yanxuanSpecialNum},
  4950. {PermissionName: "收藏的专栏文章", Source: 12, TotalNum: yanxuanSpecialCollectNum},
  4951. {PermissionName: "关注的专栏作者", Source: 13, TotalNum: yanxuanSpecialFollowNum}}
  4952. resp.List = List
  4953. }
  4954. br.Ret = 200
  4955. br.Success = true
  4956. br.Msg = "获取成功"
  4957. br.Data = resp
  4958. }
  4959. // @Title 添加/取消用户提醒
  4960. // @Description 添加/取消用户提醒
  4961. // @Param request body cygx.UserRemarAddReq true "type json string"
  4962. // @Success 200 新增成功
  4963. // @router /user/remind [post]
  4964. func (this *UserController) UserRemind() {
  4965. br := new(models.BaseResponse).Init()
  4966. defer func() {
  4967. this.Data["json"] = br
  4968. this.ServeJSON()
  4969. }()
  4970. sysUser := this.SysUser
  4971. if sysUser == nil {
  4972. br.Msg = "请登录"
  4973. br.ErrMsg = "请登录,SysUser Is Empty"
  4974. br.Ret = 408
  4975. return
  4976. }
  4977. var req cygx.UserRemarAddReq
  4978. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  4979. if err != nil {
  4980. br.Msg = "参数解析异常!"
  4981. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  4982. return
  4983. }
  4984. userId := req.UserId
  4985. sourceType := req.SourceType
  4986. doType := req.DoType
  4987. wxUser, err := cygx.GetUserAndCompanyNameList(userId)
  4988. if err != nil {
  4989. br.Msg = "设置互动提醒失败"
  4990. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  4991. return
  4992. }
  4993. if sourceType != 1 && sourceType != 2 {
  4994. br.Msg = "设置互动提醒失败"
  4995. br.ErrMsg = "设置互动提醒失败,sourceType:" + strconv.Itoa(sourceType)
  4996. return
  4997. }
  4998. if doType != 1 && doType != 2 {
  4999. br.Msg = "设置互动提醒失败"
  5000. br.ErrMsg = "设置互动提醒失败,doType:" + strconv.Itoa(doType)
  5001. return
  5002. }
  5003. count, err := cygx.GetCygxUserRemindCount(userId)
  5004. if err != nil {
  5005. br.Msg = "获取数据失败!"
  5006. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  5007. return
  5008. }
  5009. resp := new(cygx.CygxUserRemindResp)
  5010. if count <= 0 {
  5011. var items []*cygx.CygxUserRemind
  5012. if sourceType == 1 {
  5013. item := new(cygx.CygxUserRemind)
  5014. item.AdminId = sysUser.AdminId
  5015. item.AdminName = sysUser.RealName
  5016. item.UserId = userId
  5017. item.Mobile = wxUser.Mobile
  5018. item.Email = wxUser.Email
  5019. item.CompanyId = wxUser.CompanyId
  5020. item.CompanyName = wxUser.CompanyName
  5021. item.RealName = wxUser.RealName
  5022. item.CreateTime = time.Now()
  5023. item.ModifyTime = time.Now()
  5024. items = append(items, item)
  5025. } else {
  5026. //获取机构下所有的用户
  5027. listUser, err := models.GetWxUserListCompanyId(wxUser.CompanyId)
  5028. if err != nil {
  5029. br.Msg = "获取数据失败!"
  5030. br.ErrMsg = "获取数据失败,GetWxUserListCompanyId Err:" + err.Error()
  5031. return
  5032. }
  5033. //获取已经添加消息提醒的
  5034. listUserRemind, err := cygx.GetCygxUserRemindListByCompanyId(wxUser.CompanyId)
  5035. if err != nil {
  5036. br.Msg = "获取数据失败!"
  5037. br.ErrMsg = "获取数据失败,GetCygxUserRemindListByCompanyId Err:" + err.Error()
  5038. return
  5039. }
  5040. mapUserRemind := make(map[int]bool)
  5041. for _, v := range listUserRemind {
  5042. mapUserRemind[v.UserId] = true
  5043. }
  5044. for _, v := range listUser {
  5045. //如果已经添加了提醒的用户就不做添加处理
  5046. if mapUserRemind[v.UserId] {
  5047. continue
  5048. }
  5049. item := new(cygx.CygxUserRemind)
  5050. item.AdminId = sysUser.AdminId
  5051. item.AdminName = sysUser.RealName
  5052. item.UserId = v.UserId
  5053. item.Mobile = v.Mobile
  5054. item.Email = v.Email
  5055. item.CompanyId = v.CompanyId
  5056. item.CompanyName = v.CompanyName
  5057. item.RealName = v.RealName
  5058. item.CreateTime = time.Now()
  5059. item.ModifyTime = time.Now()
  5060. items = append(items, item)
  5061. }
  5062. }
  5063. //批量加入
  5064. err = cygx.AddCygxUserRemindMulti(items)
  5065. if err != nil {
  5066. br.Msg = "添加失败"
  5067. br.ErrMsg = "添加失败,Err:" + err.Error()
  5068. return
  5069. }
  5070. br.Msg = "收藏成功"
  5071. resp.Status = 1
  5072. } else {
  5073. if sourceType == 1 {
  5074. err = cygx.RemoveCygxUserRemind(userId) //取消个人提醒
  5075. } else {
  5076. err = cygx.RemoveCygxUserRemindByCompanyId(wxUser.CompanyId) //取消整个机构提醒
  5077. }
  5078. if err != nil {
  5079. br.Msg = "取消失败"
  5080. br.ErrMsg = "取消失败,Err:" + err.Error()
  5081. return
  5082. }
  5083. br.Msg = "已取消收藏"
  5084. resp.Status = 2
  5085. }
  5086. br.Ret = 200
  5087. br.Success = true
  5088. br.Data = resp
  5089. }