user.go 143 KB

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