common.php 241 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652
  1. <?php
  2. /**
  3. *
  4. * @param unknown_type $user_id 查看人
  5. * @param unknown_type $podcast_id 主播
  6. * @param unknown_type $to_user_id 被查看的人
  7. * @return Ambigous <mixed, multitype:number unknown mixed >
  8. */
  9. function getuserinfo($user_id,$podcast_id,$to_user_id,$request_data){
  10. $root = array();
  11. $root['show_tipoff'] = 0;//举报按钮 1:显示;0:不显示
  12. $root['show_admin'] = 0;//管理按钮 1,2:显示;0:不显示 (1 管理员:举报,禁言,取消; 2 主播:设置为管理员/取消管理员,管理员列表,禁言,取消)
  13. $root['has_focus'] = 0;//0:未关注;1:已关注
  14. $root['has_admin'] = 0;//0:非管理员;1:是管理员
  15. $root['is_forbid'] = 0;//0:未被禁言;1:被禁言
  16. if ($to_user_id == 0)
  17. $to_user_id = $user_id;
  18. $room_id = intval($request_data['room_id']);
  19. if($room_id){
  20. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/VideoRedisService.php');
  21. $video_redis = new VideoRedisService();
  22. $video_info = $video_redis->getRow_db($room_id,array('id','group_id'));
  23. $forbid_info = $video_redis->has_forbid_msg($video_info['group_id'],$to_user_id);//判断某个用户是否被禁言(被禁言返回:true; 未被禁言返回:false)
  24. if($forbid_info && intval($forbid_info)>NOW_TIME){
  25. $root['is_forbid'] = 1;
  26. }else{
  27. $video_redis->unset_forbid_msg($video_info['group_id'],$to_user_id);
  28. }
  29. }
  30. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/UserFollwRedisService.php');
  31. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/UserRedisService.php');
  32. $user_redis = new UserRedisService();
  33. $m_config = load_auto_cache("m_config");//初始化手机端配置
  34. //$userfollw_redis = new UserFollwRedisService($to_user_id);
  35. //$fans_count = $userfollw_redis->follower_count();
  36. //$focus_count = $userfollw_redis->follow_count();
  37. //查看自己
  38. if ($to_user_id == $user_id){
  39. $fields = array('id','fans_count','focus_count', 'is_agree','video_count','is_authentication','authentication_type','authentication_name','nick_name','signature','sex','province','city','head_image','ticket','no_ticket','refund_ticket','use_diamonds','diamonds','user_level','v_type','v_explain','v_icon','is_remind','birthday','emotional_state','job','family_id','family_chieftain','society_id','society_chieftain','society_settlement_type','is_robot','room_title','luck_num','coin','is_nospeaking', 'weibo_count');
  40. // if (OPEN_GAME_MODULE == 1) {
  41. // $fields[] = 'coin';
  42. // }
  43. $fields = array_merge($fields,array('is_vip','vip_expire_time'));
  44. if(defined('OPEN_VIP')){
  45. $open_vip = intval(OPEN_VIP);
  46. }
  47. $userinfo = $user_redis->getRow_db($to_user_id,$fields);
  48. $userinfo['signature'] = htmlspecialchars_decode($userinfo['signature']);
  49. $userinfo['nick_name'] = htmlspecialchars_decode($userinfo['nick_name']);
  50. $userinfo['signature'] = emoji_decode($userinfo['signature']);
  51. $userinfo['nick_name'] = emoji_decode($userinfo['nick_name']);
  52. $userinfo['user_id'] = $to_user_id;
  53. $userinfo['refund_ticket'] = intval(floor($userinfo['refund_ticket']));
  54. if(defined("robot_gifts") && robot_gifts ==1){
  55. $userinfo['ticket'] = intval(floor($userinfo['ticket']+$userinfo['no_ticket']));
  56. }else{
  57. $userinfo['ticket'] = intval(floor($userinfo['ticket']));
  58. }
  59. $userinfo['use_diamonds'] = intval(floor($userinfo['use_diamonds']));
  60. $userinfo['diamonds'] = intval(floor($userinfo['diamonds']));
  61. if($userinfo['is_authentication'] ==2){
  62. if($userinfo['v_explain']==''){
  63. $userinfo['v_explain'] = trim($userinfo['authentication_type']);
  64. }
  65. }
  66. if($userinfo['signature']==''||$userinfo['signature']==false){
  67. $userinfo['signature'] = 'TA好像忘记签名了';
  68. }
  69. /*
  70. $sql = "select id as user_id,is_agree,video_count,is_authentication,nick_name,signature,sex,province,city,focus_count,head_image,fans_count,ticket,use_diamonds,diamonds,user_level,v_type,v_explain,v_icon,is_remind from ".DB_PREFIX."user where id = '".$to_user_id."'";
  71. $userinfo = $GLOBALS['db']->getRow($sql,true,true);
  72. */
  73. if($userinfo['is_nospeaking'] === false) {
  74. $userinfo['is_nospeaking'] = 0;
  75. }
  76. if($userinfo['coin'] === false) {
  77. $userinfo['coin'] = 0;
  78. }
  79. if($userinfo['birthday']==false)
  80. $userinfo['birthday'] = '';
  81. if($userinfo['room_title'] === false) {
  82. $userinfo['room_title'] = '';
  83. }
  84. if($userinfo['luck_num'] == false) {
  85. $userinfo['luck_num'] = '';
  86. }
  87. if($userinfo['family_id']==false)
  88. $userinfo['family_id'] = 0;
  89. if($userinfo['family_chieftain']==false)
  90. $userinfo['family_chieftain'] = 0;
  91. if($userinfo['society_id']==false)
  92. $userinfo['society_id'] = 0;
  93. if($userinfo['society_chieftain']==false)
  94. $userinfo['society_chieftain'] = 0;
  95. if($userinfo['society_settlement_type']==false)
  96. $userinfo['society_settlement_type'] = 0;
  97. if($userinfo['emotional_state'] === false){
  98. $userinfo['emotional_state'] = '';
  99. }
  100. if ($userinfo['is_robot'] === false){
  101. $userinfo['is_robot'] = 0;
  102. }
  103. if($userinfo['job'] === false){
  104. $userinfo['job'] = '';
  105. }
  106. if($userinfo['alipay_user_id'] === false){
  107. $userinfo['alipay_user_id'] = '';
  108. }
  109. if($userinfo['alipay_name'] === false){
  110. $userinfo['alipay_name'] = '';
  111. }
  112. if($userinfo['alipay_authent_token'] === false){
  113. $userinfo['alipay_authent_token'] = '';
  114. }
  115. if($userinfo['id'] === false){
  116. $userinfo['id'] = $user_id;
  117. }
  118. if($userinfo['fans_count'] === false){
  119. $userinfo['fans_count'] = 0;
  120. }
  121. if($userinfo['focus_count'] === false){
  122. $userinfo['focus_count'] = 0;
  123. }
  124. if($userinfo['is_agree'] === false){
  125. $userinfo['is_agree'] = 0;
  126. }
  127. if($userinfo['is_remind'] === false){
  128. $userinfo['is_remind'] = 0;
  129. }
  130. if($userinfo['video_count'] === false){
  131. $userinfo['video_count'] = 0;
  132. }
  133. if($userinfo['is_authentication'] === false){
  134. $userinfo['is_authentication'] = 0;
  135. }
  136. if($userinfo['authentication_type'] === false) {
  137. $userinfo['authentication_type'] = 0;
  138. }
  139. if($userinfo['sex'] === false){
  140. $userinfo['sex'] = 0;
  141. }
  142. if($userinfo['province'] === false){
  143. $userinfo['province'] = '';
  144. }
  145. if($userinfo['city'] === false){
  146. $userinfo['city'] = '';
  147. }
  148. if($userinfo['head_image'] === false){
  149. $userinfo['head_image'] = '';
  150. }
  151. if($userinfo['use_diamonds'] === false){
  152. $userinfo['use_diamonds'] = 0;
  153. }
  154. if($userinfo['user_level'] === false){
  155. $userinfo['user_level'] = 1;
  156. }
  157. if($userinfo['v_type'] === false){
  158. $userinfo['v_type'] = 0;
  159. }
  160. if($userinfo['v_explain'] === false){
  161. $userinfo['v_explain'] = '';
  162. }
  163. if($userinfo['v_icon'] === false){
  164. $userinfo['v_icon'] = '';
  165. }
  166. $userinfo['open_vip'] = 0;
  167. if($open_vip){
  168. $userinfo['open_vip'] = $open_vip;
  169. }
  170. if($userinfo['is_vip'] === false){
  171. $userinfo['is_vip'] = 0;
  172. }
  173. if (!$userinfo['weibo_count']) {
  174. $userinfo['weibo_count'] = 0;
  175. }
  176. $userinfo['moments'] = $userinfo['weibo_count'];
  177. if (defined('OPEN_DIAMOND_GAME_MODULE') && OPEN_DIAMOND_GAME_MODULE == 1) {
  178. $userinfo['coin'] = $userinfo['use_diamonds'];
  179. }
  180. $vip_expire_time = intval($userinfo['vip_expire_time']);
  181. if($vip_expire_time>0){
  182. $userinfo['vip_expire_time'] = to_date( $vip_expire_time,'Y-m-d H:i');
  183. if($vip_expire_time < NOW_TIME){
  184. $userinfo['is_vip'] = 0;
  185. $userinfo['vip_expire_time'] = '已过期';
  186. $sql = "update ".DB_PREFIX."user set is_vip = 0 where id = ".$user_id;
  187. $GLOBALS['db']->query($sql);
  188. user_deal_to_reids(array($user_id));
  189. }else{
  190. if(intval($userinfo['is_vip'])==0){
  191. $userinfo['vip_expire_time'] = '未开通';
  192. }
  193. }
  194. }else{
  195. $userinfo['vip_expire_time'] = '未开通';
  196. if(intval($userinfo['is_vip'])==1){
  197. $userinfo['vip_expire_time'] = '永久';
  198. }
  199. }
  200. //未开启家族不显示
  201. if (!defined('OPEN_FAMILY_MODULE')||OPEN_FAMILY_MODULE!=1) {
  202. unset($userinfo['family_id']);
  203. unset($userinfo['family_chieftain']);
  204. }
  205. //未开启公会不显示
  206. if (!defined('OPEN_SOCIETY_MODULE')||OPEN_SOCIETY_MODULE!=1) {
  207. unset($userinfo['society_id']);
  208. unset($userinfo['society_chieftain']);
  209. unset($userinfo['society_settlement_type']);
  210. }
  211. $root['user'] = $userinfo;
  212. $root['user']['useable_ticket'] =intval($userinfo['ticket']-$userinfo['refund_ticket']);
  213. //直播间显示主播实际可提现印票(客户定制,标准版保留此功能)
  214. if(0){
  215. $root['user']['ticket'] = $root['user']['useable_ticket'];
  216. }
  217. $root['user']['head_image'] = get_spec_image($userinfo['head_image']);
  218. $root['user']['is_robot'] = intval($userinfo['is_robot']);
  219. //$root['user']['focus_count'] = $focus_count;
  220. //$root['user']['fans_count'] = $fans_count;
  221. $u_user_mobile = $user_redis->getRow_db($user_id,array('mobile'));
  222. //新增字段 测试数据
  223. if ((OPEN_PAI_MODULE==1||SHOPPING_GOODS==1)&&$u_user_mobile['mobile']!='13888888888'&&$u_user_mobile['mobile']!='13999999999') {
  224. $root['user']['show_user_order'] = intval(SHOW_USER_ORDER);
  225. if (SHOW_USER_ORDER==1) {
  226. $sql = "select count(*) from ".DB_PREFIX."goods_order where order_type='shop' and order_status in (1,2,3) and (pid = 0 OR is_p=1 ) and viewer_id = ".$user_id;
  227. $root['user']['user_order'] = intval($GLOBALS['db']->getOne($sql,true,true));
  228. }else{
  229. $root['user']['user_order']=0;
  230. }
  231. $root['user']['show_user_pai'] = intval(SHOW_USER_PAI);
  232. if (SHOW_USER_PAI==1) {
  233. $sql = "select count(*) from ".DB_PREFIX."goods_order where order_type<>'shop' and order_status in (1,2,3) and viewer_id =".$user_id;
  234. $root['user']['user_pai'] =intval($GLOBALS['db']->getOne($sql,true,true));
  235. }else{
  236. $root['user']['user_pai']=0;
  237. }
  238. /*$root['user']['show_podcast_order'] = 0;
  239. $root['user']['podcast_order'] = 0;
  240. $root['user']['show_podcast_pai'] = 0;
  241. $root['user']['podcast_pai'] = 0;
  242. $root['user']['show_podcast_goods'] = 0;
  243. $root['user']['podcast_goods'] = 0;*/
  244. $root['user']['show_podcast_order'] = intval(SHOW_PODCAST_ORDER);
  245. if (SHOW_PODCAST_ORDER==1) {
  246. $sql = "select count(*) from ".DB_PREFIX."goods_order where podcast_id = ".$user_id;
  247. $root['user']['podcast_order'] = intval($GLOBALS['db']->getOne($sql,true,true));
  248. }
  249. $root['user']['show_podcast_pai'] = intval(SHOW_PODCAST_PAI);
  250. if (SHOW_PODCAST_PAI==1) {
  251. $sql = "select count(*) from ".DB_PREFIX."pai_goods where podcast_id = ".$user_id." and is_delete=0 and status in (0,1,4) and order_status in (1,2,3)";
  252. $root['user']['podcast_pai'] = intval($GLOBALS['db']->getOne($sql,true,true));
  253. }
  254. $root['user']['show_podcast_goods'] = intval(SHOW_PODCAST_GOODS);
  255. if (SHOW_PODCAST_GOODS==1) {
  256. //商品
  257. //$sql = "select is_shop from ".DB_PREFIX."user where id = ".$user_id." ";
  258. $sql = "select count(*) from ".DB_PREFIX."user_goods as ug,".DB_PREFIX."goods as gs where gs.id=ug.goods_id and ug.user_id= ".$user_id." and gs.is_effect=1 and gs.inventory > 0";
  259. if(OPEN_GOODS == 1){
  260. $root['user']['podcast_goods'] = intval(good_number($user_id));
  261. }else{
  262. $root['user']['podcast_goods'] = intval($GLOBALS['db']->getOne($sql,true,true));
  263. }
  264. }
  265. $root['user']['show_shopping_cart'] = intval(SHOP_SHOPPING_CART);
  266. if(SHOP_SHOPPING_CART == 1){
  267. $sql = "select count(*) from ".DB_PREFIX."shopping_cart where user_id = ".$user_id." and is_effect=1";
  268. $root['user']['shopping_cart'] = intval($GLOBALS['db']->getOne($sql,true,true));
  269. }
  270. $root['user']['open_podcast_goods'] = intval(OPEN_PODCAST_GOODS);
  271. if(OPEN_PODCAST_GOODS == 1){
  272. $sql = "select count(*) from ".DB_PREFIX."podcast_goods where user_id = ".$user_id." and is_effect=1";
  273. $root['user']['shop_goods'] = intval($GLOBALS['db']->getOne($sql,true,true));
  274. }
  275. $shopping_goods = $GLOBALS['db']->getRow("SELECT * FROM ".DB_PREFIX."plugin WHERE class='shop' and is_effect=1");
  276. $pai = $GLOBALS['db']->getRow("SELECT * FROM ".DB_PREFIX."plugin WHERE class='pai' and is_effect=1");
  277. $podcast_goods = $GLOBALS['db']->getRow("SELECT * FROM ".DB_PREFIX."plugin WHERE class='podcast_goods' and is_effect=1");
  278. if(!$shopping_goods){
  279. $root['user']['shopping_goods']= 0;
  280. $root['user']['show_shopping_cart'] = 0;
  281. $root['user']['show_user_order']= 0;
  282. $root['user']['show_podcast_order'] = 0;
  283. }
  284. if(!$pai){
  285. $root['user']['show_user_pai'] = 0;
  286. $root['user']['show_podcast_pai'] = 0;
  287. }
  288. if(!$pai && !$shopping_goods){
  289. $root['user']['show_podcast_goods'] = 0;
  290. }
  291. if(!$podcast_goods){
  292. $root['user']['open_podcast_goods'] = 0;
  293. }
  294. }else{
  295. $root['user']['show_user_order'] = 0;
  296. $root['user']['user_order']=0;
  297. $root['user']['show_user_pai'] = 0;
  298. $root['user']['user_pai']=0;
  299. $root['user']['show_podcast_order'] = 0;
  300. $root['user']['show_podcast_pai'] = 0;
  301. $root['user']['show_podcast_goods'] = 0;
  302. $root['user']['podcast_goods'] = 0;
  303. $root['user']['show_shopping_cart'] = 0;
  304. $root['user']['shopping_cart'] = 0;
  305. $root['user']['open_podcast_goods'] = 0;
  306. }
  307. $root['user']['show_svideo'] = defined("OPEN_SVIDEO_MODULE") && OPEN_SVIDEO_MODULE == 1 ? 1 : 0;
  308. $root['user']['show_svideo_favor'] = defined("OPEN_SVIDEO_MODULE") && OPEN_SVIDEO_MODULE == 1 ? 1 : 0;
  309. if ($root['user']['show_svideo'])
  310. {
  311. $sql = "select count(*) from ".DB_PREFIX."weibo where user_id = ".$user_id." and status=1";
  312. $root['user']['svideo_count'] = intval($GLOBALS['db']->getOne($sql,true,true));
  313. }
  314. else
  315. {
  316. $root['user']['svideo_count'] = 0;
  317. }
  318. if ($podcast_id == $user_id){
  319. $root['show_admin'] = 0;//主播查看 主播:设置为管理员/取消管理员,管理员列表,禁言,取消
  320. /*if (OPEN_PAI_MODULE==1) {
  321. $root['user']['show_podcast_order'] = SHOW_PODCAST_ORDER;
  322. if (SHOW_PODCAST_ORDER==1) {
  323. $sql = "select count(*) from ".DB_PREFIX."goods_order where podcast_id = ".$user_id;
  324. $root['user']['podcast_order'] = intval($GLOBALS['db']->getOne($sql,true,true));
  325. }
  326. $root['user']['show_podcast_pai'] = SHOW_PODCAST_PAI;
  327. if (SHOW_PODCAST_PAI==1) {
  328. $sql = "select count(*) from ".DB_PREFIX."pai_goods where podcast_id = ".$user_id." and is_delete=0";
  329. $root['user']['podcast_pai'] = intval($GLOBALS['db']->getOne($sql,true,true));
  330. }
  331. $root['user']['show_podcast_goods'] = SHOW_PODCAST_GOODS;
  332. if (SHOW_PODCAST_GOODS==1) {
  333. //商品暂无
  334. $root['user']['podcast_goods'] = 0;
  335. }
  336. }*/
  337. }
  338. //H5链接
  339. $h5_url = array(
  340. 'url_my_grades' => SITE_DOMAIN.APP_ROOT.'/wap/index.php?ctl=user_center&act=grade',
  341. 'url_about_we' => SITE_DOMAIN.APP_ROOT.'/wap/index.php?ctl=settings&act=article_cate',
  342. 'url_help_feedback' => SITE_DOMAIN.APP_ROOT.'/wap/index.php?ctl=settings&act=help',
  343. 'url_auction_record' => SITE_DOMAIN.APP_ROOT.'/wap/index.php?ctl=pai_user&act=pailogs',
  344. 'url_user_order' => SITE_DOMAIN.APP_ROOT.'/wap/index.php?ctl=shop&act=shop_order&page=1', //商城h5订单链接(观众)
  345. 'url_user_pai' => SITE_DOMAIN.APP_ROOT.'/wap/index.php?ctl=pai_user&act=goods',
  346. 'url_podcast_order' => '', // 星级订单(暂无)
  347. 'url_podcast_pai' => SITE_DOMAIN.APP_ROOT.'/wap/index.php?ctl=pai_podcast&act=goods',
  348. 'url_podcast_goods' => SITE_DOMAIN.APP_ROOT.'/wap/index.php?ctl=shop&act=podcasr_goods_management&state=1&page=1', //商城h5链接(主播)
  349. 'url_auction_agreement' => SITE_DOMAIN.APP_ROOT.'/wap/index.php?ctl=settings&act=article_show&cate_id=18', //竞拍协议
  350. 'url_pai_income' => SITE_DOMAIN.APP_ROOT.'/wap/index.php?ctl=user_center&act=income', //竞拍收益h5
  351. 'url_goods_income' => SITE_DOMAIN.APP_ROOT.'/wap/index.php?ctl=user_center&act=goods_income_details', //商品收益h5
  352. 'url_user_goods' =>'', //进入第三方商城h5链接(观众)
  353. 'url_shopping_cart' => SITE_DOMAIN.APP_ROOT.'/wap/index.php?ctl=shop&act=shop_shopping_cart&page=1' //购物车
  354. );
  355. if (defined('OPEN_EDU_MODULE') && OPEN_EDU_MODULE == 1 && $userinfo['authentication_type'] == '机构') {
  356. $store_url = $GLOBALS['db']->getOne("select store_url from " . DB_PREFIX . "edu_org where user_id = " . $user_id);
  357. $h5_url['url_user_store'] = $store_url;
  358. }
  359. if((defined('PAI_REAL_BTN') && PAI_REAL_BTN == 1) && (defined('PAI_VIRTUAL_BTN') && PAI_VIRTUAL_BTN == 0)){
  360. $h5_url['url_user_pai'] = SITE_DOMAIN.APP_ROOT.'/wap/index.php?ctl=pai_user&act=goods&is_true=1';
  361. $h5_url['url_podcast_pai'] = SITE_DOMAIN.APP_ROOT.'/wap/index.php?ctl=pai_podcast&act=goods&is_true=1';
  362. }
  363. $root['h5_url']= $h5_url;
  364. }else{
  365. $fields = array('id','fans_count','focus_count','is_agree','video_count','is_authentication','nick_name','signature','sex','province','city','head_image','ticket','no_ticket','use_diamonds','user_level','v_type','v_explain','v_icon','is_remind','birthday','emotional_state','job','family_id','family_chieftain','is_robot','room_title','luck_num', 'weibo_count');
  366. $fields = array_merge($fields,array('is_vip','vip_expire_time'));
  367. $userinfo = $user_redis->getRow_db($to_user_id,$fields);
  368. $userinfo['user_id'] = $to_user_id;
  369. $userinfo['signature'] = htmlspecialchars_decode($userinfo['signature']);
  370. $userinfo['nick_name'] = htmlspecialchars_decode($userinfo['nick_name']);
  371. $userinfo['signature'] = emoji_decode($userinfo['signature']);
  372. $userinfo['nick_name'] = emoji_decode($userinfo['nick_name']);
  373. if(defined("robot_gifts") && robot_gifts ==1){
  374. $userinfo['ticket'] = intval(floor($userinfo['ticket']+$userinfo['no_ticket']));
  375. }else{
  376. $userinfo['ticket'] = intval(floor($userinfo['ticket']));
  377. }
  378. //===================slf add by 20160927 ============
  379. if($userinfo['signature']==''||$userinfo['signature']==false){
  380. $userinfo['signature'] = 'TA好像忘记签名了';
  381. }
  382. //===================================================
  383. /*
  384. $sql = "select id as user_id,video_count,is_authentication,nick_name,signature,sex,province,city,focus_count,head_image,fans_count,ticket,use_diamonds,user_level,v_type,v_explain,v_icon,emotional_state,job,city,birthday from ".DB_PREFIX."user where id = '".$to_user_id."'";
  385. $userinfo = $GLOBALS['db']->getRow($sql,true,true);
  386. */
  387. if($userinfo['birthday']==false)
  388. $userinfo['birthday'] = '';
  389. if($userinfo['room_title'] === false) {
  390. $userinfo['room_title'] = '';
  391. }
  392. if($userinfo['luck_num'] === false) {
  393. $userinfo['luck_num'] = '';
  394. }
  395. if($userinfo['emotional_state'] === false){
  396. $userinfo['emotional_state'] = '';
  397. }
  398. if($userinfo['family_id']==false)
  399. $userinfo['family_id'] = 0;
  400. if($userinfo['family_chieftain']==false)
  401. $userinfo['family_chieftain'] = 0;
  402. if ($userinfo['is_robot'] === false){
  403. $userinfo['is_robot'] = 0;
  404. }
  405. if($userinfo['job'] === false){
  406. $userinfo['job'] = '';
  407. }
  408. if($userinfo['id'] === false){
  409. $userinfo['id'] = $user_id;
  410. }
  411. if($userinfo['fans_count'] === false){
  412. $userinfo['fans_count'] = 0;
  413. }
  414. if($userinfo['focus_count'] === false){
  415. $userinfo['focus_count'] = 0;
  416. }
  417. if($userinfo['is_agree'] === false){
  418. $userinfo['is_agree'] = 0;
  419. }
  420. if($userinfo['is_remind'] === false){
  421. $userinfo['is_remind'] = 0;
  422. }
  423. if($userinfo['video_count'] === false){
  424. $userinfo['video_count'] = 0;
  425. }
  426. if($userinfo['is_authentication'] === false){
  427. $userinfo['is_authentication'] = 0;
  428. }
  429. if($userinfo['sex'] === false){
  430. $userinfo['sex'] = 0;
  431. }
  432. if($userinfo['province'] === false){
  433. $userinfo['province'] = '';
  434. }
  435. if($userinfo['city'] === false){
  436. $userinfo['city'] = '';
  437. }
  438. if($userinfo['head_image'] === false){
  439. $userinfo['head_image'] = '';
  440. }
  441. if($userinfo['use_diamonds'] === false){
  442. $userinfo['use_diamonds'] = 0;
  443. }
  444. if($userinfo['user_level'] === false){
  445. $userinfo['user_level'] = 1;
  446. }
  447. if($userinfo['v_type'] === false){
  448. $userinfo['v_type'] = 0;
  449. }
  450. if($userinfo['v_explain'] === false){
  451. $userinfo['v_explain'] = '';
  452. }
  453. if($userinfo['v_icon'] === false){
  454. $userinfo['v_icon'] = '';
  455. }
  456. if($userinfo['is_vip'] === false){
  457. $userinfo['is_vip'] = 0;
  458. }
  459. if ($userinfo['weibo_count'] === false) {
  460. $userinfo['weibo_count'] = 0;
  461. }
  462. $userinfo['moments'] = $userinfo['weibo_count'];
  463. $vip_expire_time = intval($userinfo['vip_expire_time']);
  464. if($vip_expire_time>0){
  465. $userinfo['vip_expire_time'] = to_date( $vip_expire_time,'Y-m-d H:i');
  466. if($vip_expire_time < NOW_TIME){
  467. $userinfo['is_vip'] = 0;
  468. $userinfo['vip_expire_time'] = '已过期';
  469. $sql = "update ".DB_PREFIX."user set is_vip = 0 where id = ".$to_user_id;
  470. $GLOBALS['db']->query($sql);
  471. user_deal_to_reids(array($to_user_id));
  472. }else{
  473. if(intval($userinfo['is_vip'])==0){
  474. $userinfo['vip_expire_time'] = '未开通';
  475. }
  476. }
  477. }else{
  478. $userinfo['vip_expire_time'] = '未开通';
  479. if(intval($userinfo['is_vip'])==1){
  480. $userinfo['vip_expire_time'] = '永久';
  481. }
  482. }
  483. $root['user'] = $userinfo;
  484. $root['user']['head_image'] = get_spec_image($userinfo['head_image']);
  485. //被查看的用户:个人主页地址
  486. //$root['user']['home_url'] = SITE_DOMAIN.APP_ROOT.'/index.php?isapp=1&c=home&podcast_id='.$to_user_id;
  487. //$root['user']['focus_count'] = $focus_count;
  488. //$root['user']['fans_count'] = $fans_count;
  489. if ($podcast_id > 0){
  490. //主播查看
  491. if ($podcast_id == $user_id){
  492. $root['show_admin'] = 2;//主播查看 主播:设置为管理员/取消管理员,管理员列表,禁言,取消
  493. $sql = "select id from ".DB_PREFIX."user_admin where podcast_id = ".$user_id." and user_id = ".$to_user_id;
  494. //$root['sql'] = $sql;
  495. if ($GLOBALS['db']->getOne($sql,true,true) > 1){
  496. $root['has_admin'] = 1;//0:非管理员;1:是管理员
  497. }else{
  498. $root['has_admin'] = 0;
  499. }
  500. }else{
  501. $sql = "select count(id) as num from ".DB_PREFIX."user_admin where podcast_id = '".$podcast_id."' and user_id = ".$user_id;
  502. if ($GLOBALS['db']->getOne($sql,true,true) > 0){
  503. $root['show_admin'] = 1;
  504. $root['has_admin'] = 1;//0:非管理员;1:是管理员
  505. //$root['sql'] = $sql;
  506. }
  507. }
  508. //管理员查看:主播; 不能:禁言 主播
  509. if ($root['show_admin'] == 1 && $podcast_id == $to_user_id){
  510. $root['show_admin'] = 0;
  511. }
  512. if ($root['show_admin'] > 0)
  513. $root['show_tipoff'] = 0;
  514. else
  515. $root['show_tipoff'] = 1;
  516. }
  517. //关注
  518. //fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/UserFollwRedisService.php');
  519. $userfollw_redis = new UserFollwRedisService($user_id);
  520. if ($userfollw_redis->is_following($to_user_id)){
  521. $root['has_focus'] = 1;//0:未关注;1:已关注
  522. }
  523. /*
  524. //关注
  525. $sql = "select count(id) as num from ".DB_PREFIX."focus where podcast_id = ".$to_user_id." and user_id = ".$user_id;
  526. if ($GLOBALS['db']->getOne($sql,true,true) > 0){
  527. $root['has_focus'] = 1;//0:未关注;1:已关注
  528. }*/
  529. }
  530. if ($podcast_id == 0){
  531. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/VideoContributionRedisService.php');
  532. $video_con = new VideoContributionRedisService();
  533. $con_list = $video_con->get_podcast_contribute($to_user_id,0,3,1);
  534. //印票贡献前3名
  535. $root['cuser_list'] = $con_list;
  536. foreach($root['cuser_list'] as $k => $v)
  537. {
  538. $root['cuser_list'][$k]['nick_name'] = emoji_decode($v['nick_name']);
  539. }
  540. //拖黑
  541. $sql = "select count(id) as num from ".DB_PREFIX."black where black_user_id = ".$to_user_id." and user_id = ".$user_id;
  542. if ($GLOBALS['db']->getOne($sql,true,true) > 0){
  543. $root['has_black'] = 1;//0:未拖黑;1:已拖黑
  544. }else{
  545. $root['has_black'] = 0;//0:未拖黑;1:已拖黑 $podcast_id == 0 时有效
  546. }
  547. $item = array();
  548. if ($root['user']['birthday'] == 0)
  549. $item['年龄'] = '你猜';
  550. else{
  551. $item['年龄'] = ceil((NOW_TIME - $root['user']['birthday']) / 31536000)."岁";
  552. }
  553. $item['情感状态'] = $root['user']['emotional_state'];
  554. $item['家乡'] = $root['user']['province']." ".$root['user']['city'];
  555. $item['职业'] = $root['user']['job'];
  556. //如果有靓号,显示的用户ID为靓号luck_num
  557. if (intval($root['user']['luck_num']) > 0){
  558. $item[$m_config['short_name'].'号'] = $userinfo['luck_num'];
  559. }else{
  560. $item[$m_config['short_name'].'号'] = $root['user']['user_id'];
  561. }
  562. // $item[$m_config['short_name'].'号'] = $root['user']['user_id'];
  563. $item['个性签名'] = $root['user']['signature'];
  564. //清空空值
  565. foreach ( $item as $k => $v )
  566. {
  567. if (trim($v) == ''){
  568. unset($item[$k]);
  569. }else{
  570. $item[$k] = htmlspecialchars_decode($v);
  571. }
  572. }
  573. $root['user']['item'] = $item;
  574. }else{
  575. //印票贡献第一名
  576. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/VideoContributionRedisService.php');
  577. $video_con = new VideoContributionRedisService();
  578. $con_root = $video_con->get_podcast_contribute($to_user_id,0,1,1);
  579. if ($con_root[0]){
  580. $root['cuser'] = $con_root[0];
  581. }
  582. }
  583. if(!$GLOBALS['db']->getOne("select id from ".DB_PREFIX."video where live_in = 1 and user_id=".$user_id,true,true)){
  584. $video = $GLOBALS['db']->getRow("select id as room_id,group_id,live_in,user_id,video_type,head_image,create_type,live_image from ".DB_PREFIX."video where user_id=".$to_user_id." and live_in in (1,3) and room_type = 3 order by sort_num desc,sort desc",true,true);
  585. if(intval($video['room_id'])){
  586. $video['head_image'] = get_spec_image($video['head_image']);
  587. $video['live_image'] = get_spec_image($video['live_image']);
  588. if (defined('OPEN_EDU_MODULE') && OPEN_EDU_MODULE == 1) {
  589. $video['is_verify'] = intval($GLOBALS['db']->getOne("select is_verify from " . DB_PREFIX . "edu_video_info where video_id = " . $video['room_id']));
  590. }
  591. if (empty($video['group_id']) && defined('CHILD_ROOM') && CHILD_ROOM) {
  592. fanwe_require(APP_ROOT_PATH.'mapi/lib/ChildRoom.class.php');
  593. $child_room = new child_room();
  594. $parent_id = $child_room->parent_id($video['room_id']);
  595. $video['group_id'] = $GLOBALS['db']->getOne("SELECT group_id FROM " . DB_PREFIX . "video WHERE id =" . $parent_id);
  596. }
  597. $root['video'] = $video;
  598. }
  599. }
  600. return $root;
  601. }
  602. /**
  603. * 设置关注/取消关注
  604. * @param unknown_type $user_id 关注用户ID
  605. * @param unknown_type $to_user_id 被关注的用户ID
  606. * $force_remove: 强制取消关注操作
  607. * @return multitype:number string
  608. */
  609. function redis_set_follow($user_id,$to_user_id,$force_remove = false,$room_id=0){
  610. $root = array();
  611. $root['status'] = 1;
  612. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/UserFollwRedisService.php');
  613. $user_follw_redis = new UserFollwRedisService($user_id);
  614. if ($user_follw_redis->is_following($to_user_id) || $force_remove){
  615. //已关注,取消关注操作
  616. //if ($user_redis->is_following($to_user_id)){
  617. //取消关注;
  618. $user_follw_redis->unfollow($to_user_id,$room_id);
  619. /*
  620. $user_redis->follow_count();//关注数 减少1
  621. $user2_redis = new UserNodeService($to_user_id);
  622. $user2_redis->follower_count();//粉丝数 减少1
  623. */
  624. //}
  625. }else{
  626. //未关注,添加关注操作
  627. $m_config = load_auto_cache("m_config");//初始化手机端配置
  628. $follow_max=$m_config['follow_max'];
  629. if ($user_follw_redis->follow_count() >= $follow_max){
  630. $root['error'] = '关注用户不能超过'.$follow_max.'个';
  631. $root['status'] = 0;
  632. return $root;
  633. }else{
  634. //关注操作
  635. $user_follw_redis->follow($to_user_id,$room_id);
  636. /*
  637. $user_redis->follow_count();//关注数 减少1
  638. $user2_redis = new UserNodeService($to_user_id);
  639. $user2_redis->follower_count();//粉丝数 减少1
  640. */
  641. //若在黑名单,解除拉黑
  642. set_black($user_id,$to_user_id,true);
  643. }
  644. }
  645. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/UserRedisService.php');
  646. $user_redis = new UserRedisService();
  647. $user_data = array();
  648. $user_data['fans_count'] = $user_follw_redis->follower_count();//粉丝数
  649. $user_data['focus_count'] = $user_follw_redis->follow_count();//关注数
  650. $user_redis->update_db($user_id, $user_data);
  651. $sql = "update ".DB_PREFIX."user set fans_count = ".$user_data['fans_count'].",focus_count = ".$user_data['focus_count']." where id = ".$user_id;
  652. $GLOBALS['db']->query($sql);
  653. $user2_follw_redis = new UserFollwRedisService($to_user_id);
  654. $user_data = array();
  655. $user_data['fans_count'] = $user2_follw_redis->follower_count();//粉丝数
  656. $user_data['focus_count'] = $user2_follw_redis->follow_count();//关注数
  657. $user_redis->update_db($to_user_id, $user_data);
  658. $sql = "update ".DB_PREFIX."user set fans_count = ".$user_data['fans_count'].",focus_count = ".$user_data['focus_count']." where id = ".$to_user_id;
  659. $GLOBALS['db']->query($sql);
  660. if ($user_follw_redis->is_following($to_user_id)){
  661. $root['has_focus'] = 1;//0:未关注;1:已关注
  662. }else{
  663. $root['has_focus'] = 0;
  664. }
  665. $root['fans_count'] = $user2_follw_redis->follower_count();
  666. $root['focus_count'] = $user_follw_redis->follow_count();//关注数
  667. return $root;
  668. }
  669. /**
  670. * 结束直播
  671. * @param unknown_type $video(id,user_id,group_id,watch_number,begin_time,end_time,room_type)
  672. * @param string $video_vid
  673. * @param string $is_aborted 1:被服务器异常终止结束(主要是心跳超时)
  674. */
  675. function do_end_video($video,$video_vid,$is_aborted = 0,$cate_id = 0){
  676. $user_id = $video['user_id'];
  677. $room_id = $video['id'];
  678. $group_id = $video['group_id'];
  679. //$watch_number = $video['watch_number'];
  680. $video_vid = strim($video_vid);
  681. if ($video_vid == 'null') $video_vid = '';
  682. /*if ($video_vid == '')
  683. $is_del_vod = 1;
  684. else
  685. $is_del_vod = 0;*/
  686. $is_del_vod = 1;
  687. $m_config = load_auto_cache("m_config");
  688. $short_video_time = $m_config['short_video_time']?$m_config['short_video_time']:300;
  689. //私有聊天或小于5分钟的视频,不保存 is_delete = IF(room_type =1 or ((".NOW_TIME." - begin_time) <300),1,is_delete)
  690. $sql = "update ".DB_PREFIX."video set live_in = 0,online_status=1,is_aborted = '".$is_aborted."',end_time = ".NOW_TIME.",end_date = '".to_date(NOW_TIME,'Y-m-d')."',video_vid = '".$video_vid."',is_del_vod = ".$is_del_vod.",is_delete = IF(room_type =1 or ((".NOW_TIME." - begin_time) <".$short_video_time."),1,is_delete) where (live_in =1 or live_in = 2 or live_in = 0) and id = ".$room_id;
  691. $GLOBALS['db']->query($sql);
  692. if($GLOBALS['db']->affected_rows()){
  693. if ($cate_id > 0){
  694. $sql = "update ".DB_PREFIX."video_cate a set a.num = (select count(*) from ".DB_PREFIX."video b where b.cate_id = a.id and b.live_in in (1,3)";
  695. if((defined('OPEN_ROOM_HIDE')&&OPEN_ROOM_HIDE==1)&&intval($m_config['open_room_hide'])==1){
  696. $sql.= " and b.province <> '火星' and b.province <>''";
  697. }
  698. $sql.=") where a.id = ".$cate_id;
  699. $GLOBALS['db']->query($sql);
  700. }
  701. //直播结束,连麦也打上结束标识
  702. $sql = 'update '.DB_PREFIX."video_lianmai set stop_time ='".NOW_TIME."' where stop_time = 0 and video_id =".$room_id;
  703. $GLOBALS['db']->query($sql);
  704. //开启公会功能ljz
  705. if(defined('OPEN_SOCIETY_MODULE') && intval(OPEN_SOCIETY_MODULE)==1){
  706. $video_id = intval($video['id']);
  707. $m_config = load_auto_cache("m_config");//初始化手机端配置
  708. $user_info = $GLOBALS['db']->getRow("select society_id,society_settlement_type from ".DB_PREFIX."user where id=".$user_id);
  709. //获取公会审核状态
  710. $society_status = $GLOBALS['db']->getOne("select status from ".DB_PREFIX."society where id=".$user_info['society_id']);
  711. //判断是否有公会
  712. if($user_info['society_id'] > 0 && $society_status == 1){
  713. //判断模式
  714. if($m_config['society_pattern'] == 0){//关闭公会模式
  715. platform_receipts($user_id,$m_config,$video,$video_id);
  716. }elseif ($m_config['society_pattern'] == 1){//有抽成模式
  717. society_lv_jf($m_config,$user_id,$video_id,$video,$user_info);
  718. }elseif ($m_config['society_pattern'] == 2){//无抽成模式
  719. society_receipts($video);
  720. }
  721. }else{
  722. platform_receipts($user_id,$m_config,$video,$video_id);
  723. }
  724. }
  725. //开启家族功能
  726. if(defined('OPEN_FAMILY_MODULE') && intval(OPEN_FAMILY_MODULE)==1 && intval(OPEN_SOCIETY_MODULE)==0){
  727. family_receipts1($room_id,$user_id,$video);
  728. }
  729. //开启公会功能,直播结束后将受益写入公会收益表
  730. /* if(OPEN_SOCIETY_MODULE == 1){
  731. society_receipts($video);
  732. } */
  733. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/BaseRedisService.php');
  734. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/VideoRedisService.php');
  735. $video_redis = new VideoRedisService();
  736. //直播结束时,将redis中计算的数据,同步一份到mysql;
  737. $fields = array('room_type','video_type','share_count','like_count','fans_count', 'sort_num', 'vote_number', 'robot_num','watch_number', 'virtual_watch_number', 'max_watch_number', 'channelid','prop_table');
  738. $video_data = $video_redis->getRow_db($room_id, $fields);
  739. $GLOBALS['db']->autoExecute(DB_PREFIX . "video", $video_data, "UPDATE", "id=" . $room_id);
  740. if ($video_data['room_type'] == 1){
  741. $drop_video = true;
  742. if (defined('OPEN_EDU_MODULE') && OPEN_EDU_MODULE == 1) {
  743. // 教育众筹和约课不删除视频
  744. $sql = "select deal_id,booking_class_id from " . DB_PREFIX . "edu_video_info where video_id = " . $room_id;
  745. $edu_video_info = $GLOBALS['db']->getRow($sql);
  746. if ($edu_video_info && ($edu_video_info['deal_id'] > 0 || $edu_video_info['booking_class_id'] > 0)) {
  747. $sql = "update " . DB_PREFIX . "video set is_delete = IF(((" . NOW_TIME . " - begin_time) <" . $short_video_time . "),1,0) where id = " . $room_id;
  748. $GLOBALS['db']->query($sql);
  749. $drop_video = false;
  750. }
  751. }
  752. //私密直播,
  753. if($drop_video) {
  754. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/VideoPrivateRedisService.php');
  755. $video_private_redis = new VideoPrivateRedisService();
  756. $video_private_redis->drop_video($room_id);
  757. }
  758. }
  759. $parent_id = 0;
  760. if (defined('CHILD_ROOM') && CHILD_ROOM == 1) {
  761. fanwe_require(APP_ROOT_PATH . 'mapi/lib/ChildRoom.class.php');
  762. $child_room = new child_room();
  763. $parent_id = $child_room->parent_id($room_id);
  764. if ($parent_id != $room_id) {
  765. $p_video_data = $video_redis->getRow_db($parent_id, $fields);
  766. $video_data['max_watch_number'] = $p_video_data['max_watch_number'];
  767. }
  768. }
  769. if ($video_data['video_type'] ==1 && $parent_id == $room_id){
  770. //0:腾讯云互动直播;1:腾讯云直播
  771. fanwe_require(APP_ROOT_PATH.'mapi/lib/core/video_factory.php');
  772. $video_factory = new VideoFactory();
  773. $video_factory->StopLVBChannel($video_data['channelid']);
  774. }
  775. //获取直播间,红包 发放记录,主要用于,直播结束后,处理还未被领取的红包
  776. $red_list = $video_redis->get_reds($room_id);
  777. if (count($red_list) > 0){
  778. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/VideoRedRedisService.php');
  779. $videoRed_redis = new VideoRedRedisService();
  780. foreach ($red_list as $red_id) {
  781. if ($videoRed_redis->red_exists($red_id)){
  782. $prop_table = $video_data['prop_table'];
  783. if($prop_table!=''){
  784. $sql = "SELECT from_user_id FROM " .$prop_table. " WHERE id=".$red_id;
  785. $from_user_id = $GLOBALS['db']->getOne($sql, true, true);
  786. }
  787. do{
  788. $money = $videoRed_redis->pop_red($red_id);
  789. if ($money > 0){
  790. //随机获得一机器人
  791. $robot_keys = $videoRed_redis->redis->srandmember($videoRed_redis->user_robot_db,1);
  792. $robot_id = intval($robot_keys[0]);
  793. //如果是私密直播间,红包退回发送者
  794. if ($video_data['room_type']==1){
  795. if(intval($from_user_id)){
  796. $robot_id = $from_user_id;
  797. }
  798. }
  799. allot_red_to_user($red_id,$robot_id,$money);
  800. }
  801. }while($money > 0);
  802. }
  803. }
  804. }
  805. if (OPEN_PAI_MODULE==1&&intval($video['pai_id'])>0) {
  806. //关闭竞拍
  807. $data=array();
  808. $data['podcast_id']=$video['user_id'];
  809. $data['pai_id']=$video['pai_id'];
  810. $data['video_id']=$room_id;
  811. $rs = FanweServiceCall("pai_podcast","stop_pai",$data);
  812. }
  813. if((defined('LIVE_END_TO_SCENE')&&LIVE_END_TO_SCENE==1) && intval($video['is_live_pay'])==1){
  814. //按时付费直播结束后转按场付费
  815. change_pay_type($video);
  816. }
  817. //将mysql数据,同步一份到redis中
  818. sync_video_to_redis($room_id,'*',false);
  819. if ($group_id != ''){
  820. //广播:直播结束
  821. $ext = array();
  822. $ext['type'] = 7; //0:普通消息;1:礼物;2:弹幕消息;3:主播退出;4:禁言;5:观众进入房间;6:观众退出房间;7:直播结束
  823. $ext['room_id'] = $room_id;//直播ID 也是room_id;只有与当前房间相同时,收到消息才响应
  824. $ext['show_num'] = $video_data['max_watch_number'];//观看人数
  825. $ext['fonts_color'] = '';//字体颜色
  826. $ext['desc'] = '直播结束';//弹幕消息;
  827. $ext['desc2'] = '直播结束';//弹幕消息;
  828. //消息发送者
  829. //$sender = array();
  830. //$ext['sender'] = $sender;
  831. #构造高级接口所需参数
  832. $msg_content = array();
  833. //创建array 所需元素
  834. $msg_content_elem = array(
  835. 'MsgType' => 'TIMCustomElem', //自定义类型
  836. 'MsgContent' => array(
  837. 'Data' => json_encode($ext),
  838. 'Desc' => '',
  839. // 'Ext' => $ext,
  840. // 'Sound' => '',
  841. )
  842. );
  843. //将创建的元素$msg_content_elem, 加入array $msg_content
  844. array_push($msg_content, $msg_content_elem);
  845. //发送广播:直播结束
  846. fanwe_require(APP_ROOT_PATH.'system/tim/TimApi.php');
  847. $api = createTimAPI();
  848. $ret = $api->group_send_group_msg2($user_id, $group_id, $msg_content);
  849. if (defined('CHILD_ROOM') && CHILD_ROOM == 1) {
  850. fanwe_require(APP_ROOT_PATH . 'mapi/lib/ChildRoom.class.php');
  851. $child_room = new child_room();
  852. $child_ids = $child_room->child_id($room_id);
  853. foreach ($child_ids as $child_id) {
  854. $ext['room_id'] = $child_id;
  855. $ret = $api->group_send_group_msg2($user_id, $group_id, array(
  856. array(
  857. 'MsgType' => 'TIMCustomElem', //自定义类型
  858. 'MsgContent' => array(
  859. 'Data' => json_encode($ext),
  860. 'Desc' => '',
  861. )
  862. )
  863. ));
  864. }
  865. }
  866. //=========================================================
  867. //广播:直播结束
  868. $ext = array();
  869. $ext['type'] = 18; //18:直播结束(全体推送的,用于更新用户列表状态)
  870. $ext['room_id'] = $room_id;//直播ID 也是room_id;只有与当前房间相同时,收到消息才响应
  871. //18:直播结束(全体推送的,用于更新用户列表状态)
  872. $api->group_send_group_system_notification($m_config['on_line_group_id'],json_encode($ext),null);
  873. //=========================================================
  874. return $ret;
  875. }else{
  876. return true;
  877. }
  878. }else{
  879. return false;
  880. }
  881. }
  882. /**
  883. * 直播结束 后相关数据处理(在后台定时执行)
  884. *
  885. *$video id,user_id,group_id,room_type,begin_time,end_time,video_vid,is_delete,is_del_vod
  886. *
  887. * 1、处理 fanwe_video_viewer 异常数据;没有begin_time时间的,用fanwe_video.begin_time代替; 没有end_time 用fanwe_video.end_time代替
  888. * 2、统计用户在线时长,fanwe_video_viewer
  889. * 3、移除fanwe_video_viewer,fanwe_video_contribution,fanwe_video_monitor,fanwe_video_share,fanwe_video,fanwe_video_lianmai数据到历史表中
  890. * @param unknown_type $video(id,user_id,watch_number,vote_number,group_id,room_type,begin_time,end_time)
  891. */
  892. function do_end_video_2(&$video_redis,&$api,$video_id){
  893. $pInTrans = $GLOBALS['db']->StartTrans();
  894. try
  895. {
  896. $sql = "update ".DB_PREFIX."video set live_in = -1 where live_in = 0 and id = ".$video_id;
  897. //echo $sql."<br>";
  898. $GLOBALS['db']->query($sql);
  899. if($GLOBALS['db']->affected_rows()){
  900. $sql = "select * from ".DB_PREFIX."video where id = ".$video_id;
  901. //$video = $video_redis->getRow_db($video_id);
  902. $video = $GLOBALS['db']->getRow($sql);
  903. $group_id = $video['group_id'];
  904. $begin_time = $video['begin_time'];
  905. $end_time = $video['end_time'];
  906. $user_id = $video['user_id'];
  907. $is_del_vod = $video['is_del_vod'];
  908. $is_delete = $video['is_delete'];
  909. $room_type = $video['room_type'];//房间类型 : 1私有群(Private),0公开群(Public),2聊天室(ChatRoom),3互动直播聊天室(AVChatRoom)
  910. /*
  911. //处理fanwe_video_viewer 异常数据
  912. $sql = "update ".DB_PREFIX."video_viewer set is_exception = 1, begin_time = '".$begin_time."' where begin_time = 0 and group_id = '".$group_id."'";
  913. $GLOBALS['db']->query($sql);
  914. //echo $sql."<br>";
  915. $sql = "update ".DB_PREFIX."video_viewer set is_exception = 1,end_time = '".$end_time."' where end_time = 0 and group_id = '".$group_id."'";
  916. $GLOBALS['db']->query($sql);
  917. //echo $sql."<br>";
  918. //fanwe_video_viewer
  919. //统计用户在线时长
  920. $sql = "update ".DB_PREFIX."user u,
  921. (select user_id, sum(end_time - begin_time) as time_len from ".DB_PREFIX."video_viewer where group_id = '".$group_id."' group by user_id) t
  922. set u.online_time = u.online_time + t.time_len
  923. where t.user_id = u.id";
  924. $GLOBALS['db']->query($sql);
  925. //echo $sql."<br>";
  926. //将本次直播观众移到历史表中
  927. $sql = "insert into ".DB_PREFIX."video_viewer_history(video_id,group_id,user_id,begin_time,end_time,is_robot,is_exception) select ".$video_id." as video_id,group_id,user_id,begin_time,end_time,is_robot,is_exception from ".DB_PREFIX."video_viewer where group_id='".$group_id."'";
  928. $GLOBALS['db']->query($sql);
  929. //echo $sql."<br>";
  930. $sql= "delete from ".DB_PREFIX."video_viewer where group_id='".$group_id."'";
  931. $GLOBALS['db']->query($sql);
  932. ///echo $sql."<br>";
  933. //将本次直播贡献排行移到历史表中
  934. $sql = "insert into ".DB_PREFIX."video_contribution_history(video_id,user_id,num) select video_id,user_id,num from ".DB_PREFIX."video_contribution where video_id='".$video_id."'";
  935. $GLOBALS['db']->query($sql);
  936. //echo $sql."<br>";
  937. $sql= "delete from ".DB_PREFIX."video_contribution where video_id='".$video_id."'";
  938. $GLOBALS['db']->query($sql);
  939. //echo $sql."<br>";
  940. */
  941. //将本次直播 心跳监听 移到历史表中
  942. $sql = "insert into ".DB_PREFIX."video_monitor_history(video_id,user_id,vote_number,watch_number,lianmai_num,monitor_time,statistic_time,appCPURate,sysCPURate,sendKBps,recvKBps,sendLossRate,fps,device) select video_id,user_id,vote_number,watch_number,lianmai_num,monitor_time,statistic_time,appCPURate,sysCPURate,sendKBps,recvKBps,sendLossRate,fps,device from ".DB_PREFIX."video_monitor where video_id='".$video_id."'";
  943. $GLOBALS['db']->query($sql);
  944. //echo $sql."<br>";
  945. $sql= "delete from ".DB_PREFIX."video_monitor where video_id='".$video_id."'";
  946. $GLOBALS['db']->query($sql);
  947. //echo $sql."<br>";
  948. //将本次直播 用户分享记录 移到历史表中
  949. $sql = "insert into ".DB_PREFIX."video_share_history(video_id,user_id,type,create_time) select video_id,user_id,type,create_time from ".DB_PREFIX."video_share where video_id='".$video_id."'";
  950. $GLOBALS['db']->query($sql);
  951. //echo $sql."<br>";
  952. $sql= "delete from ".DB_PREFIX."video_share where video_id='".$video_id."'";
  953. $GLOBALS['db']->query($sql);
  954. //echo $sql."<br>";
  955. //修正异常连麦结束数据
  956. $sql = 'update '.DB_PREFIX."video_lianmai set stop_time ='".$end_time."' where stop_time = 0 and video_id ='".$video_id."'";
  957. $GLOBALS['db']->query($sql);
  958. //将本次直播 用户连麦记录 移到历史表中
  959. $sql = "insert into ".DB_PREFIX."video_lianmai_history(video_id,user_id,start_time,stop_time) select video_id,user_id,start_time,stop_time from ".DB_PREFIX."video_lianmai where video_id='".$video_id."'";
  960. $GLOBALS['db']->query($sql);
  961. //echo $sql."<br>";
  962. $sql= "delete from ".DB_PREFIX."video_lianmai where video_id='".$video_id."'";
  963. $GLOBALS['db']->query($sql);
  964. /*
  965. //将本次直播 礼物记录 移到历史表中
  966. $sql = "insert into ".DB_PREFIX."video_prop_history(id,prop_id,prop_name,total_score,total_diamonds,use_diamonds,total_ticket,from_user_id,to_user_id,create_time,num,video_id,group_id,is_red_envelope,create_date,ActionStatus,ErrorInfo,ErrorCode) select id,prop_id,prop_name,total_score,total_diamonds,use_diamonds,total_ticket,from_user_id,to_user_id,create_time,num,video_id,group_id,is_red_envelope,create_date,ActionStatus,ErrorInfo,ErrorCode from ".DB_PREFIX."video_prop where video_id='".$video_id."'";
  967. $GLOBALS['db']->query($sql);
  968. //echo $sql."<br>";
  969. $sql= "delete from ".DB_PREFIX."video_prop where video_id='".$video_id."'";
  970. $GLOBALS['db']->query($sql);
  971. //echo $sql."<br>";
  972. //将本次直播 红包记录 移到历史表中
  973. $sql = "insert into ".DB_PREFIX."video_red_envelope_history(id,video_id,video_prop_id,user_id,nick_name,diamonds,sex,head_image,create_time) select id,video_id,video_prop_id,user_id,nick_name,diamonds,sex,head_image,create_time from ".DB_PREFIX."video_red_envelope where video_id='".$video_id."'";
  974. $GLOBALS['db']->query($sql);
  975. //echo $sql."<br>";
  976. $sql= "delete from ".DB_PREFIX."video_red_envelope where video_id='".$video_id."'";
  977. $GLOBALS['db']->query($sql);
  978. //echo $sql."<br>";
  979. */
  980. /* fanwe_video_private 放在redis中处理
  981. if ($room_type == 1){
  982. //将本次私聊直播 被护肩 的用户 移到历史表中
  983. $sql = "insert into ".DB_PREFIX."video_private_history(video_id,user_id) select video_id,user_id from ".DB_PREFIX."video_private where video_id='".$video_id."'";
  984. $GLOBALS['db']->query($sql);
  985. //echo $sql."<br>";
  986. $sql= "delete from ".DB_PREFIX."video_private where video_id='".$video_id."'";
  987. $GLOBALS['db']->query($sql);
  988. }
  989. */
  990. //echo $sql."<br>";
  991. /*
  992. //把fanwe_video 也移历史表中 end_date = ".to_date(NOW_TIME,'Y-m-d')
  993. $fields = "id,title,user_id,live_in,end_date,watch_number,virtual_watch_number,vote_number,cate_id,province,city,create_time,begin_time,end_time,group_id,destroy_group_status,long_polling_key,is_hot,is_new,max_watch_number,room_type,is_del_vod,video_vid,monitor_time,is_delete,robot_num,robot_time,channelid,is_aborted,tipoff_count";
  994. $sql = "insert into ".DB_PREFIX."video_history(".$fields.") select ".$fields." from ".DB_PREFIX."video where id='".$video_id."'";
  995. $GLOBALS['db']->query($sql);
  996. //echo $sql."<br>";
  997. */
  998. $video['live_in'] = 0;//改成:直播结束 live_in 0:结束;1:正在直播;2:创建中;3:回看
  999. $end_time = intval($video['end_time']);
  1000. if($end_time==0) $end_time = to_timespan($video['monitor_time']);
  1001. $video['len_time'] =$video['len_time'] + ($end_time - $video['begin_time']);
  1002. $GLOBALS['db']->autoExecute(DB_PREFIX."video_history", $video,"INSERT");
  1003. $sql= "delete from ".DB_PREFIX."video where id='".$video_id."'";
  1004. $GLOBALS['db']->query($sql);
  1005. //将付费直播记录移到历史表
  1006. if(intval($video['is_live_pay'])==1){
  1007. syn_live_pay_to_history($video_id,$video['user_id']);
  1008. }
  1009. //echo $sql."<br>";
  1010. /*
  1011. //删除禁言数据
  1012. $sql = "delete from ".DB_PREFIX."video_forbid_send_msg where group_id='".$group_id."'";
  1013. $GLOBALS['db']->query($sql);
  1014. */
  1015. //video_count
  1016. //$sql = "select id,title,begin_time,max_watch_number from ".DB_PREFIX."video_history where is_delete = 0 and is_del_vod = 0 and user_id = '".$to_user_id."' order by ".$sort_field." limit ".$limit;
  1017. $sql = "select count(*) as num from ".DB_PREFIX."video_history where is_delete = 0 and is_del_vod = 0 and user_id = '".$user_id."'";
  1018. $video_count = $GLOBALS['db']->getOne($sql);
  1019. $sql = "update ".DB_PREFIX."user set video_count = ".$video_count." where id = ".$user_id;
  1020. $GLOBALS['db']->query($sql);
  1021. //将直播间,用户领取的红包记录,同步一份到mysql
  1022. syn_red_to_mysql($video_id);
  1023. $GLOBALS['db']->Commit($pInTrans);
  1024. $pInTrans = false;
  1025. $data = array();
  1026. /*改成在 删除视频时 解散群组
  1027. //如果是删除状态,则解散群组
  1028. if ($is_delete == 1 && $video['destroy_group_status'] == 1){
  1029. if ($video['group_id'] != ''){
  1030. $ret = $api->group_destroy_group($video['group_id']);
  1031. $data['destroy_group_status'] = $ret['ErrorCode'];
  1032. $video_redis->del_video_group_db($video['group_id']);//只有在:解散 聊天组时,才删除
  1033. }else{
  1034. $data['destroy_group_status'] = 0;
  1035. }
  1036. }
  1037. $video_redis->update_db($video_id, $data);
  1038. */
  1039. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/UserRedisService.php');
  1040. $user_redis = new UserRedisService();
  1041. $user_data = array();
  1042. $user_data['video_count'] = $video_count;
  1043. $user_redis->update_db($user_id, $user_data);
  1044. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/VideoRedisService.php');
  1045. $video_redis = new VideoRedisService();
  1046. $data = [
  1047. 'game_log_id' => 0,
  1048. 'banker_id' => 0,
  1049. 'banker_status' => 0,
  1050. "banker_log_id" => 0,
  1051. "banker_name" => '',
  1052. "banker_img" => '',
  1053. 'coin' => 0,
  1054. ];
  1055. $video_redis->update_db($video_id, $data);
  1056. if ($is_del_vod == 0 && $is_delete == 1){
  1057. $m_config = load_auto_cache("m_config");
  1058. $del_short_video = $m_config['del_short_video']?$m_config['del_short_video']:1;
  1059. if ($del_short_video){
  1060. return del_vodset($video,true);//直播删除短视频
  1061. }else{
  1062. return $video_id;
  1063. }
  1064. }else{
  1065. return $video_id;
  1066. }
  1067. }else{
  1068. $GLOBALS['db']->Rollback($pInTrans);
  1069. return 0;
  1070. }
  1071. }catch(Exception $e){
  1072. //异常回滚
  1073. $GLOBALS['db']->Rollback($pInTrans);
  1074. return 0;
  1075. }
  1076. }
  1077. /**
  1078. * 设置 黑名单/取消 黑名单
  1079. * @param unknown_type $user_id 关注用户ID
  1080. * @param unknown_type $to_user_id 被关注的用户ID
  1081. * $force_remove: 强制取消黑名单
  1082. * @return multitype:number string
  1083. */
  1084. function set_black($user_id,$to_user_id,$force_remove = false){
  1085. $root = array();
  1086. $root['status'] = 1;
  1087. //
  1088. $pInTrans = $GLOBALS['db']->StartTrans();
  1089. try
  1090. {
  1091. $sql = "select id from ".DB_PREFIX."black where black_user_id = ".$to_user_id." and user_id = ".$user_id;
  1092. $black_id = $GLOBALS['db']->getOne($sql);
  1093. if ($black_id > 0 || $force_remove){
  1094. if ($black_id > 0){
  1095. //echo "black_a_id:".$black_id;
  1096. fanwe_require(APP_ROOT_PATH.'system/tim/TimApi.php');
  1097. $api = createTimAPI();
  1098. $ret = $api->sns_black_delete((string)$user_id, (string)$to_user_id);
  1099. if ($ret['ActionStatus'] == 'OK'){
  1100. //取消黑名单操作;
  1101. $sql = "delete from ".DB_PREFIX."black where id = ".$black_id;
  1102. $GLOBALS['db']->query($sql);
  1103. }else{
  1104. $root['status'] = 0;
  1105. $root['error'] = $ret['ErrorCode'].$ret['ErrorInfo'];
  1106. }
  1107. }
  1108. }else{
  1109. //echo "black_b_id:".$black_id;
  1110. fanwe_require(APP_ROOT_PATH.'system/tim/TimApi.php');
  1111. $api = createTimAPI();
  1112. $ret = $api->sns_black_import((string)$user_id, (string)$to_user_id);
  1113. //print_r($ret);
  1114. if ($ret['ActionStatus'] == 'OK'){
  1115. //未关注,需要关注操作;
  1116. $black = array();
  1117. $black['black_user_id'] = $to_user_id;
  1118. $black['user_id'] = $user_id;
  1119. $black['create_time'] = NOW_TIME;
  1120. $GLOBALS['db']->autoExecute(DB_PREFIX."black", $black,"INSERT");
  1121. //取消关注
  1122. //set_follow($user_id,$to_user_id,true);
  1123. redis_set_follow($user_id,$to_user_id,true);
  1124. }else{
  1125. $root['status'] = 0;
  1126. $root['error'] = $ret['ErrorCode'].$ret['ErrorInfo'];
  1127. }
  1128. }
  1129. $sql = "select count(id) as num from ".DB_PREFIX."black where black_user_id = ".$to_user_id." and user_id = ".$user_id;
  1130. //$root['sql'] = $sql;
  1131. if ($GLOBALS['db']->getOne($sql) > 0){
  1132. $root['has_black'] = 1;//0:未黑名单;1:黑名单
  1133. }else{
  1134. $root['has_black'] = 0;
  1135. }
  1136. if ($root['status'] == 1){
  1137. $GLOBALS['db']->Commit($pInTrans);
  1138. }else{
  1139. $GLOBALS['db']->Rollback($pInTrans);
  1140. }
  1141. }catch(Exception $e){
  1142. //异常回滚
  1143. $root['error'] = $e->getMessage();
  1144. $root['status'] = 0;
  1145. $GLOBALS['db']->Rollback($pInTrans);
  1146. }
  1147. return $root;
  1148. }
  1149. /**
  1150. * 获得点播资料
  1151. * @param unknown_type $video_vid
  1152. * @return multitype:multitype: number string
  1153. * https://www.qcloud.com/doc/api/257/2331
  1154. */
  1155. function get_vodset($video_vid){
  1156. $root = array();
  1157. $root['status'] = 1;
  1158. //$root['vodset'] = array();
  1159. //var_dump($video_vid);
  1160. $video_vid = htmlspecialchars_decode($video_vid);
  1161. //var_dump($video_vid);
  1162. $video_vid = str_replace("&quot;", "", $video_vid);
  1163. $video_vid = str_replace("[", "", $video_vid);
  1164. $video_vid = str_replace("]", "", $video_vid);
  1165. $video_vid = str_replace('"', '', $video_vid);
  1166. $video_vid = explode(",",$video_vid);
  1167. //var_dump($video_vid2);
  1168. //$video_vid3 = json_decode($video_vid);
  1169. //var_dump($video_vid3);
  1170. //print_r($video_vid);
  1171. //exit;
  1172. if (count($video_vid) > 0){
  1173. fanwe_require(APP_ROOT_PATH.'system/QcloudApi/QcloudApi.php');
  1174. $m_config = load_auto_cache("m_config");
  1175. $config = array('SecretId' => $m_config['qcloud_secret_id'],
  1176. 'SecretKey' => $m_config['qcloud_secret_key'],
  1177. 'RequestMethod' => 'GET',
  1178. 'DefaultRegion' => 'gz');
  1179. //print_r($config);exit;
  1180. $service = QcloudApi::load(QcloudApi::MODULE_VOD, $config);
  1181. foreach ( $video_vid as $k => $v )
  1182. {
  1183. $package = array('vid' => $v);
  1184. $ret = $service->DescribeRecordPlayInfo($package);
  1185. //var_dump($package);
  1186. //var_dump($ret);
  1187. //exit;
  1188. if ($ret === false) {
  1189. $error = $service->getError();
  1190. $root['status'] = 0;
  1191. $root['error'] = $v.";".$error->getCode() .";".$error->getMessage();
  1192. }else{
  1193. $root['vodset'][] = $ret;
  1194. /*
  1195. //code错误码, 0: 成功, 其他值: 失败; message: 错误信息;
  1196. if ($ret['code'] == 0){
  1197. foreach ( $ret['fileSet'] as $k => $v )
  1198. {
  1199. }
  1200. }
  1201. */
  1202. }
  1203. }
  1204. }else{
  1205. $root['status'] = 0;
  1206. $root['error'] = '无效的直播录制文件';
  1207. }
  1208. return $root;
  1209. }
  1210. /**
  1211. * 删除录制视频
  1212. * @param unknown_type $room_id
  1213. */
  1214. function del_vodset($video,$is_del_group=false){
  1215. if(! is_array($video)){
  1216. $video = array('id' => $video);
  1217. }
  1218. $room_id = $video['id'];
  1219. $root = array();
  1220. $root['status'] = 1;
  1221. $root['room_id'] = $room_id;
  1222. fanwe_require(APP_ROOT_PATH.'mapi/lib/core/video_factory.php');
  1223. $video_factory = new VideoFactory();
  1224. if($video['video_type'] == 1 && $video['channelid'] && strpos($video['channelid'],'_')){
  1225. $root['delvodset'] = $video_factory->DeleteVodFiles($video['channelid'], $video['begin_time']);
  1226. } else {
  1227. $filename = $room_id;
  1228. if($video['video_type'] == 1){
  1229. $filename = 'live'.$room_id;
  1230. }
  1231. $root['delvodset'] = $video_factory->DeleteVodFilesByFileName($filename);
  1232. }
  1233. //$sql = "select id as room_id,video_vid,is_del_vod,group2_id,group2_status from ".DB_PREFIX."video_history where id = ".$room_id;
  1234. //$video = $GLOBALS['db']->getRow($sql);
  1235. $isdelall = true;
  1236. foreach ( $root['delvodset'] as $k => $v ){
  1237. if ($v != 1 && isset($v['code']) && $v['code'] != 0){
  1238. $isdelall = false;
  1239. $root['error'] = $root['error'].";key:".$k.";code:".$v['code'].";message:".$v['message'];
  1240. }
  1241. }
  1242. if ($isdelall){
  1243. $sql = "update ".DB_PREFIX."video_history set is_del_vod = 1 where id = ".$room_id;
  1244. $GLOBALS['db']->query($sql);
  1245. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/BaseRedisService.php');
  1246. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/VideoRedisService.php');
  1247. $video_redis = new VideoRedisService();
  1248. $data = array();
  1249. $data['is_del_vod'] = 1;
  1250. $video_redis->update_db($room_id, $data);
  1251. //解散聊天组
  1252. if($is_del_group){
  1253. $sql = "select destroy_group_status,group_id from ".DB_PREFIX."video_history where id = ".$room_id;
  1254. $video_data = $GLOBALS['db']->getRow($sql);
  1255. //如果是删除状态,则解散群组
  1256. if ($video_data['destroy_group_status'] == 1){
  1257. if ($video_data['group_id'] != ''){
  1258. fanwe_require(APP_ROOT_PATH.'system/tim/TimApi.php');
  1259. $api = createTimAPI();
  1260. $ret = $api->group_destroy_group($video_data['group_id']);
  1261. $destroy_group_status = $ret['ErrorCode'];
  1262. }else{
  1263. $destroy_group_status = 0;
  1264. }
  1265. $sql = "update ".DB_PREFIX."video_history set destroy_group_status = ".$destroy_group_status." where id = ".$room_id;
  1266. $GLOBALS['db']->query($sql);
  1267. $data = array();
  1268. $data['destroy_group_status'] = $destroy_group_status;
  1269. $video_redis->update_db($room_id, $data);
  1270. }
  1271. }
  1272. //将直播间,用户领取的红包记录,同步一份到mysql
  1273. syn_red_to_mysql($room_id);
  1274. $sql = "select destroy_group_status,is_del_vod from ".DB_PREFIX."video_history where id = ".$room_id;
  1275. $video_data = $GLOBALS['db']->getRow($sql);
  1276. if ($video_data['destroy_group_status'] ==0 && $video_data['is_del_vod'] == 1){
  1277. $video_redis->del_db($room_id);//清空redis上视频相关数量【fanwe_video,禁言,点赞,观众列表,group_id与 video_id对应数据】
  1278. }
  1279. }
  1280. //print_r($root);
  1281. return $root;
  1282. }
  1283. //防盗连接sign = md5(【腾讯号 + 用户ID + 房间号】)
  1284. function check_sign($sign, $sign_version, $tim_sdkappid, $user_id, $room_id) {
  1285. //防盗连接问题 sign = md5(【腾讯号 + 用户ID + 房间号】)
  1286. if ($sign_version == '1.0'){
  1287. $sign2 = md5($tim_sdkappid.$user_id.$room_id);
  1288. }else{
  1289. $sign2 = md5($tim_sdkappid.$user_id.$room_id);
  1290. }
  1291. return (($sign == $sign2) && $sign != '');
  1292. }
  1293. //获取直播信息2
  1294. function get_video_info2($room_id, $user_id, $type, $param,$require_type=0) {
  1295. $has_scroll = strim($param['has_scroll']);//1: 自动会多返回一个podcast2(room_id,head_image)参数,用于上下滚动切换时,预加载使用; 当预加载直播失效时,自动返回下一个有效的直播房间
  1296. $private_key = strim($param['private_key']);//私密直播key
  1297. $is_vod = intval($param['is_vod']);//0:观看直播;1:点播
  1298. $sex = intval($param['sex']);//性别 0:全部, 1-男,2-女,默认为:0
  1299. $cate_id = intval($param['cate_id']);//话题id,默认为:0
  1300. $city = strim($param['city']);//城市(空为:热门),默认为:空
  1301. $type = intval($param['type']);
  1302. if ($city == '热门' || $city == 'null'){
  1303. $city = '';
  1304. }
  1305. $require_type=intval($require_type);//1:PC端;0:app端
  1306. $root = array();
  1307. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/VideoRedisService.php');
  1308. $video_redis = new VideoRedisService();
  1309. if ($room_id > 0){
  1310. //获得当前用户和主播的手机资料
  1311. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/UserRedisService.php');
  1312. $user_redis = new UserRedisService();
  1313. $u_user_mobile = $user_redis->getRow_db($user_id,array('mobile','is_effect'));
  1314. if($u_user_mobile['is_effect'] == 0){
  1315. $root = array();
  1316. $root['error'] = "无效帐户";
  1317. $root['status'] = 0;
  1318. if(!$require_type){
  1319. ajax_return($root);
  1320. }
  1321. }
  1322. //累计观看次数;累计观看次数明显大于其它用户观看次数时,及有可能是盗连接用户,需要禁用它
  1323. $sql = "update ".DB_PREFIX."user set view_count = view_count + 1 where id = ".$user_id;
  1324. $GLOBALS['db']->query($sql);
  1325. $fields = array('id','channelid', 'create_type','head_image','cate_id','title','thumb_head_image','xpoint','ypoint','sort_num','push_rtmp','play_url','play_mp4','play_flv','play_rtmp','play_hls','room_type','user_id','live_in','monitor_time', 'max_watch_number','online_status', 'video_vid','is_del_vod','is_delete','video_type','group_id','room_type','private_key','share_type','province','city','pai_id','begin_time', 'create_time','live_pay_time','is_live_pay','live_pay_type','live_fee','live_is_mention','room_title','pay_room_id');
  1326. if (OPEN_GAME_MODULE == 1) {
  1327. $fields[] = 'game_log_id';
  1328. }
  1329. if (OPEN_BM == 1) {
  1330. $fields[] = 'is_bm';
  1331. $fields[] = 'is_push';
  1332. }
  1333. $m_config = load_auto_cache("m_config");//手机端配置
  1334. $root = $video_redis->getRow_db($room_id,$fields);
  1335. if ($root['pay_room_id'] === false){
  1336. $root['pay_room_id'] = 0;
  1337. }
  1338. $monitor_overtime = $m_config['monitor_overtime'];
  1339. if ($monitor_overtime <= 0) $monitor_overtime = 40;
  1340. if ($root['live_in'] == 1 && $root['monitor_time'] > 0 && $root['monitor_time'] < NOW_TIME - $monitor_overtime){
  1341. //心跳超时
  1342. crontab_do_end_video();
  1343. $root = $video_redis->getRow_db($room_id,$fields);
  1344. }
  1345. //兼容IM推送失败列表不刷新,存在已关闭的直播显示问题
  1346. if(intval($root['live_in'])==0&&$is_vod==0){
  1347. $root = array();
  1348. $root['error'] = "直播已被关闭!";
  1349. $root['status'] = 0;
  1350. if($require_type == 1){
  1351. return $root;
  1352. }else{
  1353. ajax_return($root);
  1354. }
  1355. }
  1356. $root['head_image'] = get_spec_image($root['head_image']);
  1357. $root['thumb_head_image'] = get_spec_image($root['thumb_head_image']);
  1358. //非百魅模式
  1359. if (OPEN_BM == 1&&!$root['is_bm']) {
  1360. $root['is_push']=1;
  1361. }
  1362. $root['open_daily_task'] = 0; //每日任务
  1363. if (defined('OPEN_MISSION') && OPEN_MISSION == 1 && $m_config['mission_switch']) {
  1364. require_once APP_ROOT_PATH . 'mapi/lib/core/Model.class.php';
  1365. Model::$lib = APP_ROOT_PATH . 'mapi/lib/';
  1366. if (sizeof(Model::build('mission')->getMissionList($user_id)) > 0) {
  1367. $root['open_daily_task'] = 1;
  1368. }
  1369. }
  1370. //-------------------------------------
  1371. //sdk_type 0:使用腾讯SDK、1:使用金山SDK
  1372. //映射关系类型 腾讯云直播, 金山云,星域,方维云 ,阿里云
  1373. //video_type 1 2 3 4 5
  1374. //sdk_type 0 1 - - -
  1375. $root['sdk_type'] = get_sdk_info(intval($m_config['video_type']));
  1376. $p_user_mobile = $user_redis->getRow_db($root['user_id'],array('mobile'));
  1377. $dev_type = strim($_REQUEST['sdk_type']);
  1378. $sdk_version_name = strim($_REQUEST['sdk_version_name']);
  1379. /*$is_refuse = 1;
  1380. if($p_user_mobile['mobile']=='13999999999'&&($u_user_mobile['mobile']=='13888888888'||$u_user_mobile['mobile']=='13999999999')) $is_refuse = 0;
  1381. if($p_user_mobile['mobile']=='13888888888'&&($u_user_mobile['mobile']=='13888888888'||$u_user_mobile['mobile']=='13999999999')) $is_refuse = 0;
  1382. if($m_config['ios_check_version'] != ''&&$is_refuse){
  1383. $root = array();
  1384. $root['error'] = "直播间".$room_id."达到人数上限,无法进入!";
  1385. $root['status'] = 0;
  1386. ajax_return($root);
  1387. }
  1388. if ($root['pay_room_id'] === false){
  1389. $root['pay_room_id'] = 0;
  1390. }*/
  1391. $filter_false = array(
  1392. 'create_type' => 0,
  1393. 'video_vid' => '',
  1394. 'is_del_vod' => 0,
  1395. 'is_delete' => 0,
  1396. 'private_key' => '',
  1397. 'group_id' => '',
  1398. 'video_type' => 0,
  1399. 'pai_id' => 0,
  1400. 'max_watch_number' => 0,
  1401. 'head_image' => '',
  1402. 'thumb_head_image' => '',
  1403. 'xpoint' => 0,
  1404. 'ypoint' => 0,
  1405. 'sort_num' => 0,
  1406. 'play_flv' => '',
  1407. 'play_rtmp' => '',
  1408. 'play_hls' => '',
  1409. 'play_mp4' => '',
  1410. 'play_url' => '',
  1411. 'push_rtmp' => '',
  1412. 'cate_id' => 0,
  1413. 'title' => '',
  1414. 'is_live_pay' => 0,
  1415. 'live_pay_type' => 0,
  1416. 'live_pay_time' => '',
  1417. 'live_fee' => 0,
  1418. 'live_is_mention' => 0,
  1419. 'pay_room_id' => 0
  1420. );
  1421. if (OPEN_GAME_MODULE == 1) {
  1422. $filter_false['game_log_id'] = 0;
  1423. }
  1424. filter_false($root, $filter_false);
  1425. //限制主播PC端发起直播,APP端重复登录
  1426. $dev_type = strim($_REQUEST['sdk_type']);
  1427. if($root['user_id']==$user_id&&$root['create_type']==1&&$is_vod!=1&&($dev_type == 'ios' || $dev_type == 'android')){
  1428. $root['error'] = "PC端发起的直播,APP不能重复登录";
  1429. $root['status'] = 0;
  1430. ajax_return($root);
  1431. }
  1432. //vip
  1433. if($user_id!=$root['user_id'] &&(defined('OPEN_VIP')&&OPEN_VIP==1)&&intval($m_config['open_vip'])==1){
  1434. $sql = "select id,is_vip,vip_expire_time from ".DB_PREFIX."user where id = ".$user_id;
  1435. $user = $GLOBALS['db']->getRow($sql,true,true);
  1436. $vip_expire_time = intval($user['vip_expire_time']);
  1437. $is_vip = intval($user['is_vip']);
  1438. if($is_vip!=1 || ($is_vip == 1 && $vip_expire_time>0 && $vip_expire_time<NOW_TIME)){
  1439. $root['error'] = "非VIP会员或VIP会员已过期,请先购买。";
  1440. $root['status'] = 0;
  1441. $root['is_vip'] = 0;
  1442. $root['play_url'] = '';
  1443. $root['is_live_pay'] = 0;
  1444. if($require_type==1){
  1445. return $root;
  1446. }else{
  1447. ajax_return($root);
  1448. }
  1449. }
  1450. }else{
  1451. $is_vip = 1;
  1452. }
  1453. //付费直播
  1454. /*
  1455. * 'live_pay_time','live_pay_type','live_fee','live_is_mention'
  1456. */
  1457. /*$live_pay_info= $GLOBALS['db']->getAll("SELECT id,class FROM ".DB_PREFIX."plugin WHERE is_effect=1 and type = 1");
  1458. $live_pay = array();
  1459. if($live_pay_info){
  1460. foreach($live_pay_info as $k=>$v){
  1461. $live_pay[$v['class']] = $v['id'];
  1462. }
  1463. }*/
  1464. $group_id = $root['group_id'];
  1465. $p_user_id = $root['user_id'];
  1466. $is_order = 0;
  1467. if (defined('ORDER_ZC') && ORDER_ZC == 1) {
  1468. $is_order = is_ordered($room_id,$user_id);
  1469. }
  1470. //付费直播
  1471. if(intval(OPEN_LIVE_PAY)==1 && !$is_order){
  1472. $result = get_pay_video_info($root);
  1473. if($result['status']==0&&$root['user_id']!=$user_id){ //去掉这个参数; 0腾讯云互动直播,1腾讯云直播 &&intval($m_config['video_type'])==1
  1474. $root_result = array();
  1475. $root_result = $result;
  1476. $root_result['status'] = 1;
  1477. if(intval($m_config['is_only_play_video'])){
  1478. $root_result['is_only_play_voice'] = 0;
  1479. }else{
  1480. $root_result['is_only_play_voice'] = 1;
  1481. }
  1482. $sign = strim($param['sign']);//防盗连接问题 sign = md5(【腾讯号 + 用户ID + 房间号】)
  1483. $sign_version = strim($param['sign_version']);//1.0
  1484. $tim_sdkappid = $m_config['tim_sdkappid'];
  1485. //只有签名对,才返回:视频预览地址 防盗连接
  1486. if (check_sign($sign,$sign_version,$m_config['tim_sdkappid'],$user_id,$room_id)){
  1487. $key = "preview:video:{$room_id}:{$user_id}";
  1488. $preview_num = intval($GLOBALS['cache']->get($key, true));
  1489. $preview_num = $preview_num + 1;
  1490. $GLOBALS['cache']->set($key, $preview_num, 600, true);
  1491. $preview_play_url = '';
  1492. if ($preview_num > 2){
  1493. $root_result['is_only_play_voice'] = 1;//超过2次预览后,只显示声音
  1494. }
  1495. //视频预览地址,后面添加较验
  1496. $preview_play_url = $root['play_url'];
  1497. //直播状态,默认播放flv格式;
  1498. if (($root['live_in'] == 1 || $root['live_in'] == 2) && $preview_play_url == ''){
  1499. $preview_play_url = $root['play_flv'];
  1500. }
  1501. if ($root['live_in'] == 3 && $preview_play_url == '' ){
  1502. $file_info = load_auto_cache('video_file', array(
  1503. 'id' => $root['room_id'],
  1504. 'video_type' => $root['video_type'],
  1505. 'channelid' => $root['channelid'],
  1506. 'begin_time' => $root['begin_time'],
  1507. 'create_time' => $root['create_time'],
  1508. ));
  1509. if($file_info['play_url']){
  1510. $preview_play_url = $file_info['play_url'];
  1511. }
  1512. }
  1513. }else{
  1514. }
  1515. if(intval($m_config['countdown'])==0){
  1516. $preview_play_url = '';
  1517. }
  1518. $root_result['id'] = $room_id;
  1519. $root_result['room_id'] = $room_id;
  1520. $root_result['group_id'] = $group_id;
  1521. $root_result['user_id'] = $p_user_id;
  1522. $root_result['countdown'] = intval($m_config['countdown']);//(秒) 付费直播间预览倒计时,默认为10,0为关闭倒计时预览
  1523. $root_result['preview_play_url'] = $preview_play_url?$preview_play_url:'';
  1524. $root_result['online_status'] = $root['online_status'];
  1525. if (($root['live_in'] == 3 || $root['live_in'] == 0) && $is_vod == 1){
  1526. $root_result['has_video_control'] = 1;//点播时,视频控制操作
  1527. }
  1528. if($require_type==1){
  1529. $root_result['status'] = 0;
  1530. return $root_result;
  1531. }else{
  1532. ajax_return($root_result);
  1533. }
  1534. }else{
  1535. $is_live_pay = intval($result['is_live_pay']);
  1536. $live_pay_type = intval($result['live_pay_type']);
  1537. $live_fee = intval($result['live_fee']);
  1538. $is_pay_over = intval($result['is_pay_over']);
  1539. if((defined('PUBLIC_PAY')&&PUBLIC_PAY==1)&&$m_config['switch_public_pay']==1&&$m_config['public_pay']>0){
  1540. $is_live_pay = 1;
  1541. }
  1542. }
  1543. }
  1544. /* 非主播的 $is_live_pay 都要==0?修改 20170203
  1545. * 写错了?$root['user_id']==$user_id ?
  1546. * 主播 进入自己直播间 都不需要付费 $root['user_id']==$user_id !!!
  1547. * */
  1548. /*if($root['user_id']==$user_id&&$is_live_pay==1){
  1549. $is_live_pay = 0;
  1550. }*/
  1551. //直播间标题
  1552. //非主播,不下发推流地址
  1553. if ($root['user_id'] != $user_id){
  1554. $root['push_rtmp'] = '';
  1555. }
  1556. //直播状态,默认播放flv格式;
  1557. if (($root['live_in'] == 1 || $root['live_in'] == 2) && $root['play_url'] == ''){
  1558. $root['play_url'] = $root['play_flv'];
  1559. }
  1560. if ($root['room_type'] == 1 && $root['user_id'] != $user_id){
  1561. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/VideoPrivateRedisService.php');
  1562. $video_private_redis = new VideoPrivateRedisService();
  1563. if ($private_key != '' && $private_key != 'null'){
  1564. if ($private_key == $root['private_key']){
  1565. //检查用户是否被踢除,被踢除后,不能再加入;除非再次邀请
  1566. if ($video_private_redis->check_user_drop($room_id, $user_id)){
  1567. $root['error'] = "您已经被踢出,不能再加入";
  1568. $root['status'] = 0;
  1569. if($require_type==1){
  1570. return $root;
  1571. }else{
  1572. ajax_return($root);
  1573. }
  1574. }else{
  1575. //将用户加入私密直播,可重复操作
  1576. $video_private_redis->push_user($room_id, $user_id);
  1577. }
  1578. }else{
  1579. $root['error'] = "无效的私密钥匙:".$private_key;
  1580. $root['status'] = 0;
  1581. if($require_type=1){
  1582. return $root;
  1583. }else{
  1584. ajax_return($root);
  1585. }
  1586. }
  1587. }else{
  1588. //私聊,判断用户是否在被邀请的名单中,被踢除后,也不能重新加入
  1589. if (OPEN_BM == 1) {
  1590. $is_bm=$root['is_bm'];
  1591. }else{
  1592. $is_bm=false;
  1593. }
  1594. if ($video_private_redis->check_user_push($room_id, $user_id) == false&&!$is_bm){
  1595. $root['error'] = "私聊群,用户不在邀请名单中";
  1596. $root['status'] = 0;
  1597. if($require_type==1){
  1598. return $root;
  1599. }else{
  1600. ajax_return($root);
  1601. }
  1602. }
  1603. }
  1604. }
  1605. if ($root){//$has_scroll == 1 &&
  1606. $param = array(
  1607. 'sex'=>$sex,
  1608. 'city'=>$city,
  1609. 'cate_id'=>$cate_id,
  1610. 'is_vod'=>$is_vod,
  1611. 'video_type'=>$root['video_type'],
  1612. 'sort_num'=>$root['sort_num']
  1613. );
  1614. $root['room_id'] = $room_id;
  1615. //$video_list = get_rand_video($type,2,$user_id);
  1616. $video_list = get_rand_video($room_id,$user_id,$type,$param);
  1617. $video_previous = $video_list[0];
  1618. if (!$video_previous){
  1619. $video_previous = $root;
  1620. }
  1621. $video_next = $video_list[1];
  1622. if (!$video_next){
  1623. $video_next = $root;
  1624. }
  1625. }
  1626. }
  1627. if ($root['id']){
  1628. $root['init_version'] = intval($m_config['init_version']);//手机端配置版本号
  1629. //获得当前用户资料
  1630. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/UserRedisService.php');
  1631. $user_redis = new UserRedisService();
  1632. $user_info = $user_redis->getRow_db($user_id,array('id','user_level','is_robot','is_authentication','luck_num','mobile'));
  1633. //live_in 0:结束;1:正在直播;2:创建中;3:回看
  1634. if (($root['live_in'] == 1 && $is_vod == 0) || ($user_id == $root['user_id'] && $is_vod == 0) || (($root['live_in'] == 3 || $root['live_in'] == 0) && $is_vod == 1)){
  1635. //'video_vid','is_del_vod','is_delete','video_type','play_url','group_id','room_type','private_key'
  1636. $root['room_id'] = $room_id;
  1637. $root['podcast'] = getuserinfo($user_id,$root['user_id'],$root['user_id']);
  1638. $root['podcast']['user']['nick_name'] = emoji_decode($root['podcast']['user']['nick_name']);
  1639. $root['luck_num'] = $root['podcast']['user']['luck_num'];
  1640. if(empty($root['room_title'])){
  1641. $root['room_title']=$root['podcast']['user']['room_title'];
  1642. }
  1643. if ($video_previous){
  1644. $podcast_previous = array();
  1645. $podcast_previous['room_id'] = $video_previous['room_id'];
  1646. $video_previous['thumb_head_image'] = $video_previous['thumb_head_image']!=''?$video_previous['thumb_head_image']:$video_previous['head_image'];
  1647. $podcast_previous['head_image'] = get_spec_image($video_previous['thumb_head_image']);
  1648. $root['podcast_previous'] = $podcast_previous;
  1649. }
  1650. if ($video_next){
  1651. $podcast_next = array();
  1652. $podcast_next['room_id'] = $video_next['room_id'];
  1653. $video_next['thumb_head_image'] = $video_next['thumb_head_image']!=''?$video_next['thumb_head_image']:$video_next['head_image'];
  1654. $podcast_next['head_image'] = get_spec_image($video_next['thumb_head_image']);
  1655. $root['podcast_next'] = $podcast_next;
  1656. }
  1657. $user_level = intval($user_info['user_level']);
  1658. if ($user_level == 0) $user_level = 1;
  1659. $sort_num = $user_level*$user_redis->gz_level_weight;
  1660. if($user_info['is_robot']==0){
  1661. $sort_num+= $user_redis->gz_real_weight;
  1662. }
  1663. if($user_info['is_authentication']==2){
  1664. $sort_num+= $user_redis->gz_rz_weight;
  1665. }
  1666. //观众列表的排序权重
  1667. $root['sort_num'] = $sort_num;
  1668. //live_in 0:结束;1:正在直播;2:创建中;3:回看
  1669. if (($root['live_in'] == 3 || $root['live_in'] == 0) && $is_vod == 1){
  1670. //录制地址不能为空,且录制文件没有被删除
  1671. if ($root['is_del_vod'] == 0){
  1672. $file_info = load_auto_cache('video_file', array(
  1673. 'id' => $root['room_id'],
  1674. 'video_type' => $root['video_type'],
  1675. 'channelid' => $root['channelid'],
  1676. 'begin_time' => $root['begin_time'],
  1677. 'create_time' => $root['create_time'],
  1678. ));
  1679. if($file_info['play_url']){
  1680. $root['play_url'] = $file_info['play_url'];
  1681. }else{
  1682. $root['play_url'] = get_spec_image($root['play_url']);
  1683. }
  1684. $root['urls'] = $file_info['urls'];
  1685. }
  1686. if($root['user_id'] == $user_id){
  1687. $root['is_live_pay'] = 0;
  1688. }
  1689. //$root['video_type'] = 1;
  1690. //$root['play_url'] = 'rtmp://2811.liveplay.myqcloud.com/live/2811_b540dc105a3311e6a2cba4dcbef5e35a';
  1691. //http://2811.liveplay.myqcloud.com/live/2811_b540dc105a3311e6a2cba4dcbef5e35a.flv
  1692. $root['has_video_control'] = 1;//点播时,视频控制操作
  1693. $root['has_lianmai'] = 0;//1:显示连麦按钮;0:不显示连麦按钮
  1694. }else{
  1695. if (($root['video_type'] == 1 && $m_config['qcloud_security_key'] == '')|| $root['video_type'] == 2 || $root['video_type'] == 5){
  1696. //非直播码方式,不让连麦
  1697. $root['has_lianmai'] = 0;//1:显示连麦按钮;0:不显示连麦按钮
  1698. }else{
  1699. //会员允许等级
  1700. if ($m_config['has_lianmai_lv'] <= $user_level){
  1701. $root['has_lianmai'] = 1;//1:显示连麦按钮;0:不显示连麦按钮
  1702. }else{
  1703. $root['has_lianmai'] = 0;//1:显示连麦按钮;0:不显示连麦按钮
  1704. }
  1705. }
  1706. }
  1707. //$root['video_type'] = 0;//0:腾讯云互动直播;1:腾讯云直播
  1708. //$root['play_url'] = '';//video_type=1;1:腾讯云直播播放地址(rmtp,flv)
  1709. if ($user_id != $root['user_id']){
  1710. //非主播,不返回:推流地址
  1711. $root['push_url'] = '';//video_type=1;1:腾讯云直播推流地址
  1712. }
  1713. //print_r($root['podcast']);exit;
  1714. //印票贡献榜 http://ilvb.fanwe.net/index.php?ctl=user&act=contribution&user_id=1
  1715. //$root['cont_url'] = SITE_DOMAIN.APP_ROOT.'/index.php?ctl=user&act=contribution&user_id='.$root['user_id'];
  1716. $share = array();
  1717. $share['share_title'] = strim($m_config['share_title']);//'你丑你先睡,我美我直播!';
  1718. $share['share_imageUrl'] = $root['podcast']['user']['head_image'];
  1719. $share['share_key'] = $root['room_id'];
  1720. $share['share_url'] = SITE_DOMAIN.APP_ROOT.'/wap/index.php?ctl=share&act=live&user_id='.$root['user_id'].'&video_id='.$root['room_id'].'&share_id='.$user_id;
  1721. $share['share_content'] = $share['share_title'].$root['podcast']['user']['nick_name'].'正在直播,快来一起看~';
  1722. $root['share'] = $share;
  1723. $root['status'] = 1;
  1724. //$sql = "select count(*) from ".DB_PREFIX."video_viewer where group_id = '".$root['group_id']."'";
  1725. //$sql = "select count(*) from ".DB_PREFIX."user";
  1726. //当前房间人数 = 当前实时观看人数(实际,不含虚拟人数,不包含机器人) + 当前虚拟观看人数 + 机器人
  1727. //$root['viewer_num'] = $root['watch_number'] + $root['virtual_watch_number'] + $root['robot_num'];
  1728. //观众列表
  1729. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/VideoViewerRedisService.php');
  1730. $video_viewer_redis = new VideoViewerRedisService();
  1731. $viewer = $video_viewer_redis->get_viewer_list2($room_id,1,10);
  1732. $root['viewer'] = $viewer;
  1733. $root['viewer_num'] = $viewer['watch_number'];
  1734. //$root['viewer_num'] = $video_redis->get_video_watch_num($room_id);
  1735. if ($root['room_type'] == 1){
  1736. $root['is_private'] = 1;
  1737. if ($root['is_bm'] == 1) {
  1738. $root['is_private'] = 0;
  1739. }
  1740. /*
  1741. $sql = "select user_id from ".DB_PREFIX."user_admin where podcast_id = ".$root['user_id'];
  1742. $user_admin_list = $GLOBALS['db']->getAll($sql,true,true);
  1743. $user_admin_list = array_column($user_admin_list,'user_id');
  1744. //主播自己或管理员 // || $root['podcast']['show_admin'] == 2
  1745. if (in_array($user_id,$user_admin_list) || ($user_id == $root['user_id'])){
  1746. $private_share = "复制整段信息,打开[".strim($m_config['app_name'])."]可直接看直播,".$root['podcast']['user']['nick_name']."正在".$root['city']."直播";
  1747. $private_share = $private_share.base64_decode("8J+UkQ==").$root['private_key'].base64_decode("8J+UkQ==")."还没安装".strim($m_config['app_name'])."?点此安装,".SITE_DOMAIN."/appdown.php";
  1748. $root['private_share'] = $private_share;//print_r($root['podcast'],1);
  1749. }
  1750. */
  1751. $sql = "select id from ".DB_PREFIX."user_admin where podcast_id = ".$root['user_id']." and user_id=".$user_id;
  1752. $user_admin_id = intval($GLOBALS['db']->getOne($sql,true,true));
  1753. //主播自己或管理员 // || $root['podcast']['show_admin'] == 2
  1754. if ($user_admin_id > 0 || ($user_id == $root['user_id'])){
  1755. $private_share = "复制整段信息,打开[".strim($m_config['app_name'])."]可直接看直播,".$root['podcast']['user']['nick_name']."正在".$root['city']."直播";
  1756. $private_share = $private_share.base64_decode("8J+UkQ==").$root['private_key'].base64_decode("8J+UkQ==")."还没安装".strim($m_config['app_name'])."?点此安装,".SITE_DOMAIN_DOWNLOAD."/appdown.php";
  1757. $root['private_share'] = $private_share;//print_r($root['podcast'],1);
  1758. }
  1759. if ($root['is_bm'] == 1) {
  1760. }else{
  1761. $root['private_key'] = '';
  1762. }
  1763. }else{
  1764. $root['is_private'] = 0;
  1765. }
  1766. //进入房间提示 1、提示进入房间 0、 不提示
  1767. $join_room_remind_limit = intval($m_config['join_room_remind_limit']);
  1768. $root['join_room_prompt'] = 1;
  1769. if($join_room_remind_limit>0&&$root['viewer_num']>$join_room_remind_limit){
  1770. $root['join_room_prompt'] = 0;//
  1771. }
  1772. $root['is_live_pay'] = intval($is_live_pay);//
  1773. $root['live_pay_type'] = intval($live_pay_type);//
  1774. $root['live_fee'] = intval($live_fee);//
  1775. $root['is_pay_over'] = intval($is_pay_over);//
  1776. $root['is_vip'] = intval($is_vip);//是否VIP会员
  1777. //进入房间人数上限 join_room_limit
  1778. $join_room_limit = intval($m_config['join_room_limit']);
  1779. if($join_room_limit>0&&$root['viewer_num']>=$join_room_limit&&$root['user_id']!=$user_id){
  1780. $root = array();
  1781. $root['error'] = "直播间达到人数上限,无法进入!";
  1782. $root['status'] = 0;
  1783. }
  1784. $root['video_title'] = '直播Live';
  1785. if($root['live_in']==3&&intval($root['is_gather'])!=1){
  1786. $root['video_title'] = '精彩回放';
  1787. }else if($root['live_in']==3&&intval($root['is_gather'])==1){
  1788. $root['video_title'] = '直播Live';
  1789. }
  1790. }else{
  1791. if ($is_vod == 0){
  1792. $show_num = $root['max_watch_number'];//观看人数
  1793. $podcast_id = $root['user_id'];
  1794. $live_in = $root['live_in'];
  1795. $root = array();
  1796. //关注
  1797. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/UserFollwRedisService.php');
  1798. $userfollw_redis = new UserFollwRedisService($user_id);
  1799. if ($userfollw_redis->is_following($podcast_id)){
  1800. $root['has_focus'] = 1;//0:未关注;1:已关注
  1801. }else{
  1802. $root['has_focus'] = 0;
  1803. }
  1804. $root['live_in'] = $live_in;
  1805. $root['show_num'] = $show_num;
  1806. $root['status'] = 2;//提示直播结束;
  1807. //=========================================================
  1808. //广播:直播结束
  1809. //发送广播:直播结束
  1810. fanwe_require(APP_ROOT_PATH.'system/tim/TimApi.php');
  1811. $api = createTimAPI();
  1812. $ext = array();
  1813. $ext['type'] = 18; //18:直播结束(全体推送的,用于更新用户列表状态)
  1814. $ext['room_id'] = $room_id;//直播ID 也是room_id;只有与当前房间相同时,收到消息才响应
  1815. //18:直播结束(全体推送的,用于更新用户列表状态)
  1816. $api->group_send_group_system_notification($m_config['on_line_group_id'],json_encode($ext),null);
  1817. //=========================================================
  1818. //$video_redis->update_db($room_id,array('live_in'=>1));
  1819. //较验数据
  1820. crontab_do_end_video();
  1821. crontab_do_end_video_2();
  1822. //
  1823. }else{
  1824. $root = array();
  1825. $root['error'] = "直播已结束".$room_id;
  1826. $root['status'] = 0;
  1827. }
  1828. }
  1829. }else{
  1830. $root = array();
  1831. $root['error'] = "未发现有效的直播房间".$room_id;
  1832. $root['status'] = 0;
  1833. }
  1834. return $root;
  1835. }
  1836. //检查主播是否直播中
  1837. function is_live($data, $live_list)
  1838. {
  1839. foreach ($data as $k => $v) {
  1840. foreach ($live_list as $kk => $vv) {
  1841. if ($vv['user_id'] == $v['user_id']) {
  1842. $data[$k]['live_in'] = $vv['live_in'];
  1843. $data[$k]['video_url'] = get_video_url($vv['room_id'], $vv['live_in']);
  1844. break;
  1845. }
  1846. }
  1847. if(empty($data[$k]['video_url']))
  1848. {
  1849. $data[$k]['video_url'] = url('live#show', array('podcast_id' => $v['user_id']));
  1850. }
  1851. $data[$k]['user_level_ico'] = get_spec_image("./public/images/rank/rank_" . $v['user_level'] . ".png");
  1852. }
  1853. return $data;
  1854. }
  1855. //获取直播列表
  1856. function get_live()
  1857. {
  1858. $sql = "SELECT v.id AS room_id, v.sort_num, v.group_id, v.user_id, v.city, v.title, v.cate_id, v.live_in, v.video_type, v.room_type,
  1859. (v.robot_num + v.virtual_watch_number + v.watch_number) as watch_number, v.head_image,v.thumb_head_image, v.xpoint,v.ypoint,v.live_image,
  1860. u.v_type, u.v_icon, u.nick_name,u.user_level FROM " . DB_PREFIX . "video v
  1861. LEFT JOIN " . DB_PREFIX . "user u ON u.id = v.user_id where v.live_in in (1,3) order by v.live_in, v.sort_num desc,v.sort desc";
  1862. $live_list = $GLOBALS['db']->getAll($sql, true, true);
  1863. return $live_list;
  1864. }
  1865. /**
  1866. * //随机从type类型的直播列表中,取$num个直播ID; type: 0:热门;1:最新;2:关注
  1867. * 不会列出私聊房间
  1868. * @param int $type
  1869. * @param int $num
  1870. * @param string $user_id 当$type=2时生效;
  1871. */
  1872. /*function get_rand_video($type,$num,$user_id){
  1873. if ($type == 1){
  1874. //1:最新 半小时内
  1875. $sql = "select id as room_id,user_id,group_id,live_in,watch_number,robot_num,virtual_watch_number,room_type from ".DB_PREFIX."video WHERE room_type = 3 and live_in = 1 and is_new = 1 and begin_time > ".(NOW_TIME - 1800)." order by rand() LIMIT ".$num;
  1876. }else if ($type == 2){
  1877. //2:关注
  1878. $sql = "select v.id as room_id,v.user_id,v.group_id,v.live_in,v.watch_number,v.robot_num,v.virtual_watch_number,v.room_type from ".DB_PREFIX."video v "
  1879. ."LEFT JOIN ".DB_PREFIX."focus f on f.podcast_id = v.user_id "
  1880. ."WHERE v.room_type = 3 and v.live_in = 1 and f.user_id = '".$user_id."' order by rand() LIMIT ".$num;
  1881. }else{
  1882. //热门
  1883. $sql = "select id as room_id,user_id,group_id,live_in,watch_number,robot_num,virtual_watch_number,room_type from ".DB_PREFIX."video WHERE room_type = 3 and live_in = 1 and is_hot = 1 order by rand() LIMIT ".$num;
  1884. }
  1885. //随机获得2个(一个当前使用的,一个上下滚动时备用);
  1886. $video_list = $GLOBALS['db']->getAll($sql);
  1887. return $video_list;
  1888. }*/
  1889. function get_rand_video($room_id,$user_id,$type,$param, $num = 2){
  1890. /*
  1891. $type = intval($_REQUEST['type']);//type: 0:热门;1:最新;2:关注 [当room_id=0时有效,随机返回一个type类型下的直播]
  1892. $param = array(
  1893. 'sex'=>$sex,
  1894. 'city'=>$city,
  1895. 'cate_id'=>$cate_id,
  1896. 'type'=>$type,
  1897. 'room_id'=>$room_id,
  1898. 'is_vod'=>$is_vod,
  1899. 'video_type'=>$root['video_type'],
  1900. 'sort_num'=>$root['sort_num']
  1901. );
  1902. */
  1903. $ret_list = array();
  1904. $is_vod = intval($param['is_vod']);
  1905. if ($is_vod == 0){
  1906. if ($type == 2){
  1907. //关注
  1908. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/UserFollwRedisService.php');
  1909. $userfollw_redis = new UserFollwRedisService($user_id);
  1910. $user_list = $userfollw_redis->following();
  1911. //私密直播 video_private,私密直播结束后, 本表会清空
  1912. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/VideoPrivateRedisService.php');
  1913. $video_private_redis = new VideoPrivateRedisService();
  1914. $private_list = $video_private_redis->get_video_list($user_id);
  1915. if(sizeof($private_list) || sizeof($user_list)){
  1916. $list_all = load_auto_cache("select_video",array('has_private'=>1));
  1917. foreach($list_all as $k=>$v){
  1918. if (($v['live_in'] == 1) && ($v['room_id'] != $room_id) && (($v['room_type'] == 1 && in_array($v['room_id'], $private_list)) || ($v['room_type'] == 3 && in_array($v['user_id'], $user_list)))) {
  1919. $list[] = $v;
  1920. }
  1921. }
  1922. }
  1923. }else{
  1924. $list_all = load_auto_cache("select_video",array('sex_type'=>intval($param['sex']),'area_type'=>$param['city'],'cate_id'=>intval($param['cate_id']),'has_private'=>0));
  1925. foreach($list_all as $k=>$v){
  1926. if (($v['live_in'] == 1) && ($v['room_id'] != $room_id)&&$v['user_id']!=$user_id) {
  1927. $list[] = $v;
  1928. }
  1929. }
  1930. }
  1931. if (count($list) <= $num){
  1932. $ret_list = $list;
  1933. }else{
  1934. foreach(array_rand($list, $num) as $key){
  1935. $ret_list[] = $list[$key];
  1936. }
  1937. }
  1938. }
  1939. return $ret_list;
  1940. }
  1941. /*
  1942. function get_rand_video($room_id,$num,$param){
  1943. $list = array();
  1944. $type = $param['type'];
  1945. $sql = "SELECT v.id, v.group_id, v.user_id, v.city, v.title, v.cate_id, v.live_in, v.video_type, v.room_type,
  1946. (v.robot_num + v.virtual_watch_number + v.watch_number) as watch_number
  1947. FROM ".DB_PREFIX."video v where v.live_in=1 and v.id<>".$room_id;
  1948. if ($param['cate_name']) {
  1949. $cate_name = $param['cate_name'];
  1950. $sql .= " and v.room_type=3 and v.title='" . $cate_name . "' ";
  1951. $sql.= " order by rand() LIMIT ".$num;
  1952. $list = $GLOBALS['db']->getAll($sql);
  1953. } elseif ($type == 0) {
  1954. $sex = intval($param['sex']);
  1955. $city = strim($param['city']);
  1956. if($city=='热门' || $city=='null'){
  1957. $city = '';
  1958. }
  1959. if ($sex == 1 || $sex == 2){
  1960. $sql .= ' and v.sex = '.$sex;
  1961. }
  1962. if ($city != ''){
  1963. $sql .= " and v.province = '".$city."'";
  1964. }
  1965. $sql.=" and v.room_type=3 ";
  1966. $sql.= " order by rand() LIMIT ".$num;
  1967. $list = $GLOBALS['db']->getAll($sql);
  1968. }elseif ($type == 1) {
  1969. $sql .= " and v.room_type=3 ";
  1970. $sql.= " order by rand() LIMIT ".$num;
  1971. $list = $GLOBALS['db']->getAll($sql);
  1972. } elseif ($type == 2) {
  1973. $user_id = intval($GLOBALS['user_info']['id']);//登录用户id
  1974. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/UserFollwRedisService.php');
  1975. $userfollw_redis = new UserFollwRedisService($user_id);
  1976. $user_list = $userfollw_redis->following();
  1977. //私密直播 video_private,私密直播结束后, 本表会清空
  1978. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/VideoPrivateRedisService.php');
  1979. $video_private_redis = new VideoPrivateRedisService();
  1980. $private_list = $video_private_redis->get_video_list($user_id);
  1981. if(sizeof($private_list) || sizeof($user_list)){
  1982. $sql.=" and v.room_type in (1,3) order by rand() ";
  1983. $list_all = $GLOBALS['db']->getAll($sql);
  1984. $count = 0;
  1985. foreach($list_all as $k=>$v){
  1986. if($count==$num){
  1987. break;
  1988. }
  1989. if (($v['room_type'] == 1 && in_array($v['id'], $private_list)) || ($v['room_type'] == 3 && in_array($v['user_id'], $user_list))) {
  1990. $list[] = $v;
  1991. $count ++;
  1992. }
  1993. }
  1994. }
  1995. }
  1996. return $list;
  1997. }
  1998. */
  1999. //格式化时间单位(多少时间前)
  2000. function format_show_date($time){
  2001. $t=NOW_TIME-$time;
  2002. $f=array(
  2003. '31536000'=>'年',
  2004. '2592000'=>'个月',
  2005. '604800'=>'星期',
  2006. '86400'=>'天',
  2007. '3600'=>'小时',
  2008. '60'=>'分钟',
  2009. '1'=>'秒'
  2010. );
  2011. foreach ($f as $k=>$v) {
  2012. if (0 !=$c=floor($t/(int)$k)) {
  2013. return $c.$v.'前';
  2014. }
  2015. }
  2016. }
  2017. //获得回放视频的时长(多少小时/多少分钟)
  2018. function get_time_len($begin_time,$end_time){
  2019. $time =$end_time - $begin_time;
  2020. $palyback = '';
  2021. if($time/3600>1){
  2022. $palyback.=intval($time/3600).'小时';
  2023. $time = $time%3600;
  2024. }
  2025. if($time/60>1){
  2026. $palyback.=intval($time/60).'分钟';
  2027. }
  2028. return $palyback;
  2029. }
  2030. //格式化时间长度单位 (小时/分钟)
  2031. function get_live_time_len($time){
  2032. $total_time_format = '';
  2033. if($time/3600>=1){
  2034. $total_time_format.=intval($time/3600).'小时';
  2035. $time = $time%3600;
  2036. }
  2037. if($time/60>=1){
  2038. $total_time_format.=intval($time/60).'分钟';
  2039. }
  2040. return $total_time_format;
  2041. }
  2042. //格式化时间长度单位(天/小时/分钟)2017-8-9 10:40:18新增
  2043. function get_live_time_len2($time){
  2044. $total_time_format = '';
  2045. if($time/86400>=1){
  2046. $total_time_format.=intval($time/86400).'天';
  2047. $time = $time%86400;
  2048. }
  2049. if($time/3600>=1){
  2050. $total_time_format.=intval($time/3600).'小时';
  2051. $time = $time%3600;
  2052. }
  2053. if($time/60>=1){
  2054. $total_time_format.=intval($time/60).'分钟';
  2055. }
  2056. return $total_time_format;
  2057. }
  2058. function crontab_do_check_pc_video()
  2059. {
  2060. $ret_array = array();
  2061. $m_config = load_auto_cache("m_config");
  2062. $monitor_overtime = $m_config['monitor_overtime'];
  2063. if ($monitor_overtime <= 0) $monitor_overtime = 40;
  2064. $ret_array = array();
  2065. //监听主播掉线(30秒一次监听,如果超过180秒未收到心跳消息,则说明:主播掉线 了
  2066. $t = to_date(NOW_TIME - $monitor_overtime, 'Y-m-d H:i:s');
  2067. $sql = "select id,user_id,watch_number,vote_number,group_id,room_type,video_type,begin_time,end_time,channelid,video_vid,live_in,cate_id,pai_id from " . DB_PREFIX . "video where live_in = 2 and create_type = 1 and monitor_time > '" . $t . "'";
  2068. $list = $GLOBALS['db']->getAll($sql, true, true);
  2069. fanwe_require(APP_ROOT_PATH . 'mapi/lib/redis/VideoRedisService.php');
  2070. $video_redis = new VideoRedisService();
  2071. foreach ($list as $v) {
  2072. fanwe_require(APP_ROOT_PATH . 'mapi/lib/core/video_factory.php');
  2073. $video_factory = new VideoFactory();
  2074. if ($v['channelid']) {
  2075. $channel_info = $video_factory->Query($v['channelid']);
  2076. $ret_array[] = $channel_info;
  2077. // 正在直播,继续监听
  2078. if ($channel_info['status'] == 1) {
  2079. $data = array('live_in' => 1, 'begin_time' => NOW_TIME);
  2080. $GLOBALS['db']->autoExecute(DB_PREFIX . "video", $data, 'UPDATE', " id=" . $v['id']);
  2081. if ($GLOBALS['db']->affected_rows()) {
  2082. $room_id = $v['id'];
  2083. $sql = "select user_id,room_type,title,city,cate_id from " . DB_PREFIX . "video where id = " . $room_id;
  2084. $video = $GLOBALS['db']->getRow($sql);
  2085. $video_redis->video_online($room_id, $v['group_id']);
  2086. //将mysql数据,同步一份到redis中
  2087. sync_video_to_redis($room_id, '*', false);
  2088. if ($video['cate_id'] > 0) {
  2089. $sql = "update " . DB_PREFIX . "video_cate a set a.num = (select count(*) from " . DB_PREFIX . "video b where b.cate_id = a.id and b.live_in in (1,3)) where a.id = " . $video['cate_id'];
  2090. $GLOBALS['db']->query($sql);
  2091. }
  2092. if ($video['room_type'] == 3) {
  2093. crontab_robot($room_id);
  2094. }
  2095. fanwe_require(APP_ROOT_PATH . 'mapi/lib/redis/UserRedisService.php');
  2096. $user_redis = new UserRedisService();
  2097. $user_data = $user_redis->getRow_db($v['user_id'], array('id', 'nick_name', 'head_image'));
  2098. $pushdata = array(
  2099. 'user_id' => $v['user_id'], //'主播ID',
  2100. 'nick_name' => $user_data['nick_name'],//'主播昵称',
  2101. 'create_time' => NOW_TIME, //'创建时间',
  2102. 'cate_title' => $video['title'],// '直播主题',
  2103. 'room_id' => $room_id,// '房间ID',
  2104. 'city' => $video['city'],// '直播城市地址',
  2105. 'head_image' => get_spec_image($user_data['head_image']),
  2106. 'status' => 0,//'推送状态(0:未推送,1:推送中;2:已推送)'
  2107. );
  2108. $m_config = load_auto_cache("m_config");
  2109. if (intval($m_config['service_push'])) {
  2110. $pushdata['pust_type'] = 1; //'推送状态(0:粉丝推送,1:全服推送)';
  2111. } else {
  2112. $pushdata['pust_type'] = 0; //'推送状态(0:粉丝推送,1:全服推送)';
  2113. }
  2114. $GLOBALS['db']->autoExecute(DB_PREFIX . "push_anchor", $pushdata, 'INSERT');
  2115. }
  2116. }
  2117. }
  2118. }
  2119. return $ret_array;
  2120. }
  2121. function crontab_do_check_upload_video($create_type = 1)
  2122. {
  2123. $create_type = intval($create_type)?intval($create_type):0;
  2124. $ret_array = array();
  2125. $sql = "select id,video_vid,live_in,group_id from " . DB_PREFIX . "video_history where live_in = 2 and create_type = " .$create_type;
  2126. $list = $GLOBALS['db']->getAll($sql, true, true);
  2127. if($list){
  2128. fanwe_require(APP_ROOT_PATH . 'mapi/lib/redis/VideoRedisService.php');
  2129. fanwe_require(APP_ROOT_PATH . 'mapi/lib/core/video_factory.php');
  2130. $video_redis = new VideoRedisService();
  2131. $video_factory = new VideoFactory();
  2132. foreach ($list as $v) {
  2133. // 用户上传的视频轮询取得播放地址
  2134. $ret = $video_factory->DescribeVodPlayUrls($v['video_vid']);
  2135. if(empty($ret['urls'])){
  2136. continue;
  2137. }
  2138. $play_url = array_shift($ret['urls']);
  2139. $data = array('live_in' => 0, 'is_del_vod' => 0, 'play_url' => $play_url, 'end_time' => NOW_TIME);
  2140. $GLOBALS['db']->autoExecute(DB_PREFIX . "video_history", $data, 'UPDATE', " id=" . $v['id']);
  2141. $video_redis->update_db($v['id'], $data);
  2142. $video_redis->video_online($v['id'], $v['group_id']);
  2143. $ret_array[] = $data;
  2144. }
  2145. }
  2146. return $ret_array;
  2147. }
  2148. function crontab_do_end_video(){
  2149. try {
  2150. $m_config = load_auto_cache("m_config");
  2151. $monitor_overtime = $m_config['monitor_overtime'];
  2152. if ($monitor_overtime <= 0) $monitor_overtime = 40;
  2153. $ret_array = array();
  2154. //监听主播掉线(30秒一次监听,如果超过180秒未收到心跳消息,则说明:主播掉线 了
  2155. $t = to_date(NOW_TIME - $monitor_overtime,'Y-m-d H:i:s');
  2156. $sql = "select id,user_id,watch_number,vote_number,group_id,room_type,video_type,begin_time,end_time,channelid,video_vid,live_in,cate_id,pai_id from ".DB_PREFIX."video where (live_in = 1 or live_in = 2) and monitor_time < '".$t."'";
  2157. if (OPEN_BM == 1) {
  2158. $t1 = to_date(NOW_TIME - 43200,'Y-m-d H:i:s');
  2159. $sql = "select id,user_id,watch_number,vote_number,group_id,room_type,video_type,begin_time,end_time,channelid,video_vid,live_in,cate_id,pai_id from ".DB_PREFIX."video where (live_in = 1 or live_in = 2) and (is_bm=0 and monitor_time < '".$t."') or (is_bm=1 and monitor_time < '".$t1."') ";
  2160. }
  2161. $list = $GLOBALS['db']->getAll($sql,true,true);
  2162. foreach ( $list as $k => $v )
  2163. {
  2164. if($v['video_type'] > 0){
  2165. //0:腾讯云互动直播;1:腾讯云直播;2:方维云直播
  2166. fanwe_require(APP_ROOT_PATH.'mapi/lib/core/video_factory.php');
  2167. $video_factory = new VideoFactory();
  2168. $channel_info = $video_factory->Query($v['channelid']);
  2169. // 正在直播,继续监听
  2170. if($channel_info['status'] == 1){
  2171. continue;
  2172. }
  2173. }
  2174. //子房间过滤
  2175. if(defined('CHILD_ROOM') && CHILD_ROOM == 1){
  2176. $parent_id = $GLOBALS['db']->getOne("SELECT parent_id FROM " . DB_PREFIX . "child_room WHERE child_id = {$v['id']} and is_delete = 0");
  2177. if($parent_id){
  2178. if($GLOBALS['db']->getOne("select live_in from fanwe_video where id = " . $parent_id)) {
  2179. continue;
  2180. }
  2181. }
  2182. }
  2183. //结束直播
  2184. if ($v['live_in'] == 1){
  2185. $cate_id = $v['cate_id'];
  2186. }else{
  2187. $cate_id = 0;
  2188. }
  2189. $system_user_id =$m_config['tim_identifier'];//系统消息
  2190. $ext = array();
  2191. $ext['type'] = 17;
  2192. $ext['desc'] = '网络不佳,已结束直播';
  2193. $ext['room_id'] = $v['id'];
  2194. #构造高级接口所需参数
  2195. $msg_content = array();
  2196. //创建array 所需元素
  2197. $msg_content_elem = array(
  2198. 'MsgType' => 'TIMCustomElem', //自定义类型
  2199. 'MsgContent' => array(
  2200. 'Data' => json_encode($ext),
  2201. 'Desc' => '',
  2202. // 'Ext' => $ext,
  2203. // 'Sound' => '',
  2204. )
  2205. );
  2206. //将创建的元素$msg_content_elem, 加入array $msg_content
  2207. array_push($msg_content, $msg_content_elem);
  2208. fanwe_require(APP_ROOT_PATH.'system/tim/TimApi.php');
  2209. $api = createTimAPI();
  2210. $group_info = $api->group_get_group_member_info($v['group_id'],0,0);
  2211. if($group_info['MemberList']){
  2212. $to = array_column($group_info['MemberList'],"Member_Account");
  2213. }
  2214. $exceed = 500; //一次最多发送500条
  2215. if(sizeof($to)>$exceed){
  2216. $num = ceil(sizeof($to)/$exceed);
  2217. for($i=0;$i<$num;$i++){
  2218. $to_account = array_slice($to,$i*$exceed,$exceed);
  2219. $api->openim_batchsendmsg($system_user_id, $msg_content,$to_account);
  2220. }
  2221. }else{
  2222. $api->openim_batchsendmsg($system_user_id, $msg_content,$to);
  2223. }
  2224. $ret = do_end_video($v,$v['video_vid'],1,$cate_id);
  2225. $ret['func']='do_end_video';
  2226. $ret_array[]=$ret;
  2227. }
  2228. /*
  2229. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/VideoRedisService.php');
  2230. $video_redis = new VideoRedisService();
  2231. $list = $video_redis->get_off_video_monitor_time($monitor_overtime);
  2232. foreach ( $list as $k => $v )
  2233. {
  2234. $video_data = $video_redis->getRow_db($v);
  2235. $ret_array[]=redis_do_end_video($video_redis,$video_data,$video_data['video_vid'],1,$video_data['cate_id']);
  2236. }
  2237. */
  2238. return $ret_array;
  2239. } catch (Exception $e) {
  2240. return $e->getMessage();
  2241. }
  2242. }
  2243. function crontab_do_end_video_2(){
  2244. try {
  2245. $ret_array = array();
  2246. // 结束直播5分钟后,
  2247. $sql = "select id,is_del_vod,video_type,channelid,begin_time,create_time,end_time,user_id,vote_number,destroy_group_status,group_id from ".DB_PREFIX."video where end_time < ".(NOW_TIME - 300)." and live_in = 0 limit 10";
  2248. $list = $GLOBALS['db']->getAll($sql);
  2249. if ($list){
  2250. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/VideoRedisService.php');
  2251. $video_redis = new VideoRedisService();
  2252. fanwe_require(APP_ROOT_PATH.'system/tim/TimApi.php');
  2253. $api = createTimAPI();
  2254. foreach ( $list as $k => $v )
  2255. {
  2256. //1:表示已经清空了,录制视频;0:未做清空操作
  2257. if ($v['is_del_vod'] == 1){
  2258. fanwe_require(APP_ROOT_PATH.'mapi/lib/core/video_factory.php');
  2259. $video_factory = new VideoFactory();
  2260. /*if($v['video_type'] > 0 && $v['channelid']&& strpos($v['channelid'],'_')){
  2261. $ret = $video_factory->GetVodRecordFiles($v['channelid'], $v['create_time']);
  2262. } else {
  2263. $fileName = $v['id'];
  2264. if($v['video_type'] == 1){
  2265. $fileName = 'live'.$v['id'] ;
  2266. }
  2267. $ret = $video_factory->DescribeVodPlayInfo($fileName);
  2268. }*/
  2269. $ret = get_vodset_by_video_id($v['id']);
  2270. /*if ($ret['totalCount'] > 0){*/
  2271. if ($ret['total_count'] > 0){
  2272. //视频存在
  2273. $sql = "update ".DB_PREFIX."video set is_del_vod = 0 where id = ".$v['id'];
  2274. $GLOBALS['db']->query($sql);
  2275. $v['is_del_vod'] = 0;
  2276. $data = array();
  2277. $data['is_del_vod'] = 0;
  2278. $video_redis->update_db($v['id'], $data);
  2279. }
  2280. }
  2281. //直播结束 后相关数据处理(在后台定时执行)
  2282. //1、解散群组
  2283. if ($v['destroy_group_status'] == 1 && $v['is_del_vod'] == 1){
  2284. if ($v['group_id'] != ''){
  2285. fanwe_require(APP_ROOT_PATH.'system/tim/TimApi.php');
  2286. $api = createTimAPI();
  2287. $ret = $api->group_destroy_group($v['group_id']);
  2288. //删除:观众列表
  2289. $video_redis->del_viewer($v['id']);
  2290. $sql = "update ".DB_PREFIX."video set destroy_group_status = '".$ret['ErrorCode']."' where id = ".$v['id'];
  2291. $GLOBALS['db']->query($sql);
  2292. }else{
  2293. $sql = "update ".DB_PREFIX."video set destroy_group_status = 0 where id = ".$v['id'];
  2294. $GLOBALS['db']->query($sql);
  2295. }
  2296. }
  2297. //2、结束 旁边直播
  2298. /*
  2299. *旁边直播,在客户端做结束操作;如果客户端异常退出而没有结束时,腾讯云在10分钟后也会自动结束并清空
  2300. if ($v['channelid']){
  2301. //停止直播
  2302. fanwe_require(APP_ROOT_PATH.'system/QcloudApi/QcloudApi.php');
  2303. $m_config = load_auto_cache("m_config");
  2304. $config = array('SecretId' => $m_config['qcloud_secret_id'],
  2305. 'SecretKey' => $m_config['qcloud_secret_key'],
  2306. 'RequestMethod' => 'GET',
  2307. 'DefaultRegion' => 'gz');
  2308. $service = QcloudApi::load(QcloudApi::MODULE_LIVE, $config);
  2309. $package = array('channelIds.1' => $v['channelid']);
  2310. $a = $service->StopLVBChannel($package);
  2311. $stop_channel = 0;
  2312. if ($a === false) {
  2313. $error = $service->getError();
  2314. $stop_channel = $error->getCode();
  2315. }else{
  2316. $stop_channel = 1;
  2317. }
  2318. $sql = "update ".DB_PREFIX."video set stop_channel = '".$stop_channel."' where id = ".$v['id'];
  2319. $GLOBALS['db']->query($sql);
  2320. }
  2321. */
  2322. $ret = do_end_video_2($video_redis,$api,$v['id']);
  2323. $ret['func']='do_end_video_2';
  2324. $ret_array[]=$ret;
  2325. }
  2326. }
  2327. return $ret_array;
  2328. } catch (Exception $e) {
  2329. return $e->getMessage();
  2330. }
  2331. }
  2332. /**
  2333. * 添加机器人,每隔几秒随机添加几个人
  2334. */
  2335. function crontab_robot($video_id=0){
  2336. if ($video_id == 0){
  2337. $sql = "SELECT id,group_id,robot_num,max_robot_num FROM ".DB_PREFIX."video where robot_num < max_robot_num and live_in in (1,3) and room_type = 3 and robot_time < ".(NOW_TIME - rand(20,30));
  2338. }else{
  2339. $sql = "SELECT id,group_id,robot_num,max_robot_num FROM ".DB_PREFIX."video where robot_num < max_robot_num and live_in in (1,3) and room_type = 3 and id = ".$video_id;
  2340. }
  2341. $list = $GLOBALS['db']->getAll($sql,true,true);
  2342. if (count($list) > 0){
  2343. $m_config = load_auto_cache("m_config");//初始化手机端配置
  2344. $max_num = $m_config['robot_num'];
  2345. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/BaseRedisService.php');
  2346. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/VideoViewerRedisService.php');
  2347. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/VideoRedisService.php');
  2348. $video_redis = new VideoRedisService();
  2349. $video_viewer = new VideoViewerRedisService();
  2350. }
  2351. foreach ( $list as $k => $v )
  2352. {
  2353. //添加机器人
  2354. $robot_num = $v['robot_num'];
  2355. $max_robot_num = $v['max_robot_num']?$v['max_robot_num']:$max_num;
  2356. $video_id = $v['id'];
  2357. if($robot_num<$max_robot_num){
  2358. $rand_num = rand(6,10);
  2359. $robot_keys = $video_viewer->redis->srandmember($video_viewer->user_robot_db,$rand_num);
  2360. $user_array = array();
  2361. foreach($robot_keys as $user_id){
  2362. $user_array[$user_id]['user_level'] = $video_viewer->redis->hGet($video_viewer->user_db.$user_id,'user_level');
  2363. }
  2364. //新入群成员列表
  2365. foreach ( $robot_keys as $k=>$user_id ){
  2366. $begin_time = get_gmtime() ;
  2367. if($video_viewer->redis->zScore($video_viewer->video_viewer_level_db.$video_id, $user_id) === false){
  2368. //实际观众数统计:累计观众列表和; [score 为负数是:机器人; 正数是:真实观众] $user_array[$user_id]['user_level']
  2369. $video_viewer->redis->zAdd($video_viewer->video_viewer_level_db.$video_id, -1,$user_id);
  2370. $video_viewer->redis->hIncrBy($video_viewer->video_db.$video_id,'robot_num',1);
  2371. $video_viewer->redis->hIncrBy($video_viewer->video_db.$video_id,'max_watch_number',1);
  2372. //记录直播间的机器人头像 去除:直播间机器人独立列表 score 为负数是:机器人
  2373. //$video_redis->add_robot($video_id, $user_id);
  2374. }
  2375. }
  2376. $video = $video_redis->getRow_db($video_id,array('robot_num'));
  2377. $robot_num = intval($video['robot_num']);
  2378. if ($robot_num > 0){
  2379. $sql = "update ".DB_PREFIX."video set robot_num = ".$robot_num.",robot_time=".NOW_TIME." where id = ".$video_id;
  2380. $GLOBALS['db']->query($sql);
  2381. }
  2382. }
  2383. }
  2384. }
  2385. //获取一个新的房间号,同时记录分配给那个系统使用;
  2386. function get_max_room_id($sysid=0){
  2387. $sql = "insert into ".DB_PREFIX."room_id (id,sysid) values(0,$sysid)";
  2388. $GLOBALS['db']->query($sql);
  2389. $room_id = $GLOBALS['db']->insert_id();
  2390. return $room_id;
  2391. }
  2392. /**
  2393. * IP地址查询接口(API)
  2394. */
  2395. function get_ip_info(){
  2396. //http://www.hi-docs.com/Article/detail-Mzk=.html
  2397. fanwe_require(APP_ROOT_PATH .'mapi/lib/core/transport.php');
  2398. $trans = new transport();
  2399. //$url = 'http://ip.taobao.com/service/getIpInfo.php?ip='.CLIENT_IP;
  2400. //$url = 'http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=json&ip='.CLIENT_IP;
  2401. $url = 'http://ip.ws.126.net/ipquery?ip='.CLIENT_IP;
  2402. $req = $trans->request($url,array(),'GET');
  2403. //$req = json_decode($req['body'],true);
  2404. $req['body'] = mb_convert_encoding($req['body'], 'utf-8', 'gbk');
  2405. $b = substr($req['body'],strpos($req['body'],"{"),strpos($req['body'],"}"));
  2406. $req['city']= substr($b,strpos($b,"{city:")+7,strpos($b,"\",")-7);
  2407. $req['city'] = str_replace("市","",$req['city']);
  2408. $req['province']= substr($b,strpos($b,"province:")+10,-4);
  2409. $req['province'] = str_replace("省","",$req['province']);
  2410. /*
  2411. {
  2412. ret: 1,
  2413. start: -1,
  2414. end: -1,
  2415. country: "美国",
  2416. province: "加利福尼亚",
  2417. city: "Zenia",
  2418. district: "",
  2419. isp: "",
  2420. type: "",
  2421. desc: ""
  2422. }*/
  2423. $info = array();
  2424. $info['ip'] = CLIENT_IP;
  2425. $info['country'] = $req['country'];
  2426. $info['province'] = $req['province'];
  2427. $info['city'] = $req['city'];
  2428. $info['district'] = $req['district'];
  2429. return $info;
  2430. }
  2431. function get_ip_infos(){
  2432. fanwe_require(APP_ROOT_PATH .'mapi/lib/core/transport.php');
  2433. $trans = new transport();
  2434. $url = "https://dm-81.data.aliyun.com/rest/160601/ip/getIpInfo.json?ip=".CLIENT_IP;
  2435. $date =array();
  2436. $date['AppKey'] = '23489658';
  2437. $date['AppKeyAppSecret'] = '71d175d90329b580f989268f957f152a';
  2438. $req = $trans->request($url,$date,'GET');
  2439. return $req;
  2440. /*$req = json_decode($req['body'],true);
  2441. $info = array();
  2442. $info['ip'] = CLIENT_IP;
  2443. $info['country'] = $req['country'];
  2444. $info['province'] = $req['province'];
  2445. $info['city'] = $req['city'];
  2446. $info['district'] = $req['district'];
  2447. return $info;*/
  2448. }
  2449. /**
  2450. * 距离计算(API)
  2451. */
  2452. function get_distance_order($from, $to){
  2453. // http://lbs.qq.com/webservice_v1/guide-distance.html
  2454. $m_config = load_auto_cache("m_config");
  2455. // test
  2456. if(!isset($m_config["qcloud_app_key"])){
  2457. $m_config["qcloud_app_key"] = "UNDBZ-KYNLX-LDS4K-ZBARP-VT37E-I2FCL";
  2458. }
  2459. $url = 'http://apis.map.qq.com/ws/distance/v1/?'.http_build_query(array(
  2460. "mode" => "walking",
  2461. "from" => $from,
  2462. "to" => implode(';', $to),
  2463. "output" => "json",
  2464. "key" => $m_config["qcloud_app_key"],
  2465. ));
  2466. fanwe_require(APP_ROOT_PATH .'mapi/lib/core/transport.php');
  2467. $trans = new transport();
  2468. $response = $trans->request($url,array(),'GET');
  2469. $data = json_decode($response['body'],true);
  2470. if($data['status'] != 0){
  2471. return array();
  2472. }
  2473. return $data['result']['elements'];
  2474. }
  2475. /**
  2476. * 格式化时间
  2477. */
  2478. function date_time_format(&$date_time){
  2479. $time=strtotime($date_time);
  2480. $ri=date('Y年m月d日 ',$time);
  2481. $zhou=date('N',$time);
  2482. if ($zhou==1) {
  2483. $zhou=" 周一 ";
  2484. }elseif ($zhou==2) {
  2485. $zhou=" 周二 ";
  2486. }if ($zhou==3) {
  2487. $zhou=" 周三 ";
  2488. }if ($zhou==4) {
  2489. $zhou=" 周四 ";
  2490. }if ($zhou==5) {
  2491. $zhou=" 周五 ";
  2492. }if ($zhou==6) {
  2493. $zhou=" 周六 ";
  2494. }if ($zhou==7) {
  2495. $zhou=" 周日 ";
  2496. }
  2497. $fen=date(' H时i分',$time);
  2498. $date_time=$ri.$zhou.$fen;
  2499. }
  2500. /*
  2501. * 在线人数进行整理
  2502. */
  2503. function deal_online_cate_num(){
  2504. }
  2505. /**
  2506. * 通过 房间号 获取视频播放信息列表;注:在手机端开启录制时,要以房间号作为文件名;
  2507. * https://www.qcloud.com/doc/api/257/1373
  2508. * @param unknown_type $video_id
  2509. * @return Ambigous <multitype:number NULL unknown , number, string, unknown>
  2510. */
  2511. function get_vodset_by_video_id($video_id) {
  2512. $root = array();
  2513. $root['status'] = 1;
  2514. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/VideoRedisService.php');
  2515. $video_redis = new VideoRedisService();
  2516. $video = $video_redis->getRow_db($video_id,array('id','channelid','begin_time','video_type'));
  2517. $fileName = $video_id.'_'.to_date($video['begin_time'],'Y-m-d-H');//互动直播 例如:2018376_2017-01-12-18-03-19
  2518. if($video['video_type']==1 && $video['channelid']){
  2519. $fileName = 'live'.$video_id.'_'.to_date($video['begin_time'],'Y-m-d-H');//云直播&频道托管 例如:live2018376_2017-01-12-18-03-19
  2520. if(strpos($video['channelid'],'_')){
  2521. $fileName = $video['channelid'];//云直播&直播码 例如:2811_311359b479_dd55c664b4acf27c5138
  2522. }
  2523. }
  2524. $ret = get_vodset_by_filename($fileName);
  2525. //兼容 云直播&直播码接入&点播前缀有live
  2526. if ($ret['status'] != 1){
  2527. if($video['video_type']==1 && $video['channelid']&&strpos($video['channelid'],'_')){
  2528. $fileName = 'live'.$video['channelid'];//例如:live6311_311359b479_dd55c664b4acf27c5138
  2529. }
  2530. $ret = get_vodset_by_filename($fileName);
  2531. }
  2532. $root['total_count'] = 0;
  2533. if ($ret['status'] == 1){
  2534. $root['vodset'][] = $ret['ret'];
  2535. $root['total_count'] = $ret['ret']['totalCount'];
  2536. }else{
  2537. $root['status'] = 0;
  2538. $root['error'] = $ret['error'];
  2539. }
  2540. return $root;
  2541. }
  2542. /**
  2543. * 通过 房间号 获取视频播fileIds列表
  2544. * https://www.qcloud.com/doc/api/257/1373
  2545. * @param unknown_type $video_id
  2546. */
  2547. function get_vod_fileIds($video_id) {
  2548. $fileName = $video_id.'_';
  2549. $ret = get_vodset_by_filename($fileName);
  2550. $fileIds = array();
  2551. foreach ( $ret['fileSet'] as $k2 => $v2 )
  2552. {
  2553. $fileIds[] = $v2['fileId'];
  2554. }
  2555. return $fileIds;
  2556. }
  2557. /**
  2558. * 通过 视频名称(前缀匹配) 获取视频播放信息列表
  2559. * https://www.qcloud.com/doc/api/257/1373
  2560. * @param unknown_type $fileName
  2561. * @param unknown_type $page
  2562. * @return multitype:number string unknown
  2563. */
  2564. function get_vodset_by_filename($fileName,$page =1,$page_size=20) {
  2565. $root = array();
  2566. $root['status'] = 1;
  2567. fanwe_require(APP_ROOT_PATH.'system/QcloudApi/QcloudApi.php');
  2568. $m_config = load_auto_cache("m_config");
  2569. $config = array('SecretId' => $m_config['qcloud_secret_id'],
  2570. 'SecretKey' => $m_config['qcloud_secret_key'],
  2571. 'RequestMethod' => 'GET',
  2572. 'DefaultRegion' => 'gz');
  2573. $service = QcloudApi::load(QcloudApi::MODULE_VOD, $config);
  2574. if ($page == 0){
  2575. $page = 1;
  2576. }
  2577. $package = array('fileName' => $fileName,'pageNo'=>$page,'pageSize'=>$page_size);
  2578. $ret = $service->DescribeVodPlayInfo($package);
  2579. if ($ret === false) {
  2580. $error = $service->getError();
  2581. $root['status'] = 0;
  2582. $root['code'] = $error->getCode();
  2583. $root['error'] = "fileName:".$fileName.";code:".$error->getCode() .";msg:".$error->getMessage();
  2584. }else{
  2585. $root['ret'] = $ret;
  2586. }
  2587. $root['package'] = $ret;
  2588. return $root;
  2589. }
  2590. /**
  2591. * 每隔N秒,将在线直播redis计算的数据同步到mysql中
  2592. */
  2593. function crontab_deal_num($s=5){
  2594. $is_ok = $GLOBALS['cache']->set_lock('crontab_deal_num',$s);
  2595. if($is_ok) {
  2596. $sql = "SELECT id FROM " . DB_PREFIX . "video";
  2597. $list = $GLOBALS['db']->getAll($sql, true, true);
  2598. if (count($list) > 0) {
  2599. fanwe_require(APP_ROOT_PATH . 'mapi/lib/redis/VideoRedisService.php');
  2600. $video_redis = new VideoRedisService();
  2601. foreach ($list as $k => $v) {
  2602. $video_id = $v['id'];
  2603. //计算权重
  2604. $video_redis->syn_sort_num($video_id);
  2605. $fields = array('share_count','like_count','fans_count', 'sort_num', 'vote_number', 'robot_num','watch_number', 'virtual_watch_number', 'max_watch_number');
  2606. $video = $video_redis->getRow_db($video_id, $fields);
  2607. $GLOBALS['db']->autoExecute(DB_PREFIX . "video", $video, "UPDATE", "id=" . $video_id);
  2608. }
  2609. }
  2610. }
  2611. }
  2612. /**
  2613. * 把数据库中的fanwe_video同步到redis上去
  2614. * @param int $video_id
  2615. * @param string $fields 需要同步的字段 * 表示所有
  2616. * @param bool $exinclude_calc;true 不含redis中的计算字段array('share_count','like_count','fans_count', 'sort_num', 'vote_number', 'robot_num','watch_number', 'virtual_watch_number', 'max_watch_number')
  2617. */
  2618. function sync_video_to_redis($video_id, $fields = '*', $exinclude_calc=true){
  2619. if ($fields == '') $fields = '*';
  2620. $sql = "select ".$fields." from ".DB_PREFIX."video where id = ".$video_id;
  2621. $video = $GLOBALS['db']->getRow($sql);
  2622. if ($video == false){
  2623. $sql = "select ".$fields." from ".DB_PREFIX."video_history where id = ".$video_id;
  2624. $video = $GLOBALS['db']->getRow($sql);
  2625. }
  2626. if ($exinclude_calc){
  2627. $calc_fields = array('share_count','like_count','fans_count', 'sort_num', 'vote_number', 'robot_num','watch_number', 'virtual_watch_number', 'max_watch_number');
  2628. foreach ($video as $k => $v) {
  2629. if (in_array($k, $calc_fields)){
  2630. unset($video[$k]);
  2631. }
  2632. }
  2633. }
  2634. if ($fields == '*' && isset($video['vote_number'])){
  2635. unset($video['vote_number']);
  2636. }
  2637. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/VideoRedisService.php');
  2638. $video_redis = new VideoRedisService();
  2639. $video_redis->update_db($video_id, $video);
  2640. }
  2641. /**
  2642. * 将发送礼物记录移到mysql数据库中
  2643. * $num:一次插入多少条数据; -1取出所有记录;
  2644. *
  2645. * 本函数实际上已经失效;发送礼物记录,发送时直接记录在fanwe_video_prop_ym表中了; 此时用来处理旧的redis中数据,同步到mysql中
  2646. */
  2647. function sync_video_prop_to_mysql($num=-1){
  2648. $is_ok = $GLOBALS['cache']->set_lock('sync_video_prop_to_mysql',500);
  2649. if($is_ok) {
  2650. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/VideoGiftRedisService.php');
  2651. $videoGift_redis = new VideoGiftRedisService();
  2652. //$list = $videoGift_redis->getAll($num);
  2653. if ($num == -1) $num = 10000;
  2654. $list = $videoGift_redis->getAll($num);
  2655. if (count($list) == 0)
  2656. $list = $videoGift_redis->getAll(-1);
  2657. foreach($list as $k=>$v){
  2658. $video_prop = json_decode($v,true);
  2659. $video_prop['create_y'] = to_date($video_prop['create_time'],'Y');
  2660. $video_prop['create_m'] = to_date($video_prop['create_time'],'m');
  2661. $video_prop['create_ym'] = to_date($video_prop['create_time'],'Ym');
  2662. $video_prop['create_d'] = to_date($video_prop['create_time'],'d');
  2663. $video_prop['create_w'] = to_date($video_prop['create_time'],'W');
  2664. //没做批量插入,主要是考虑支持重复执行
  2665. $GLOBALS['db']->autoExecute(DB_PREFIX."video_prop", $video_prop,"INSERT",'','SILENT');
  2666. if($GLOBALS['db']->affected_rows()){
  2667. $videoGift_redis->del_db($k);
  2668. }else{
  2669. $sql = "select id from ".DB_PREFIX."video_prop where id = ".$k;
  2670. if ($GLOBALS['db']->getOne($sql) > 0){
  2671. $videoGift_redis->del_db($k);
  2672. }
  2673. }
  2674. }
  2675. $GLOBALS['cache']->del_lock('sync_video_prop_to_mysql');
  2676. }
  2677. }
  2678. /**
  2679. * 删除指定文件[前缀搜索]
  2680. * @param unknown_type $fileName
  2681. * @return multitype:unknown
  2682. */
  2683. function del_all_vod($fileName){
  2684. //$fileName = '_';
  2685. $ret = get_vodset_by_filename($fileName,1,80);
  2686. //print_r($ret);
  2687. //$fileIds = array();
  2688. fanwe_require(APP_ROOT_PATH.'system/QcloudApi/QcloudApi.php');
  2689. $m_config = load_auto_cache("m_config");
  2690. $config = array('SecretId' => $m_config['qcloud_secret_id'],
  2691. 'SecretKey' => $m_config['qcloud_secret_key'],
  2692. 'RequestMethod' => 'GET',
  2693. 'DefaultRegion' => 'gz');
  2694. $service = QcloudApi::load(QcloudApi::MODULE_VOD, $config);
  2695. foreach ( $ret['ret']['fileSet'] as $k2 => $v2 )
  2696. {
  2697. $package = array('fileId' => $v2['fileId'],'priority'=>0);
  2698. $ret2 = $service->DeleteVodFile($package);
  2699. $ret[$v2['fileId']] = $ret2;
  2700. }
  2701. //print_r($fileIds);
  2702. return $ret;
  2703. }
  2704. /**
  2705. * 历史直播:上架/下架
  2706. * 上架: 将fanwe_video_history 表数据,移到fanwe_video 后,删除fanwe_video_history记录
  2707. * 下架: 将fanwe_video 表数据,移到fanwe_video_history 后,删除fanwe_video记录
  2708. * @param unknown_type $video_id
  2709. * @param unknown_type $status; 0:上架;1:下架;
  2710. */
  2711. function video_status($video_id,$status){
  2712. $pInTrans = $GLOBALS['db']->StartTrans();
  2713. try
  2714. {
  2715. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/BaseRedisService.php');
  2716. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/VideoRedisService.php');
  2717. $video_redis = new VideoRedisService();
  2718. if($status == 0){
  2719. //历史直播:上架
  2720. $sql = "update ".DB_PREFIX."video_history set live_in = 3 where live_in = 0 and id = ".$video_id;
  2721. $GLOBALS['db']->query($sql);
  2722. if($GLOBALS['db']->affected_rows()){
  2723. $sql = "select * from ".DB_PREFIX."video_history where id = ".$video_id;
  2724. $video = $GLOBALS['db']->getRow($sql);
  2725. $GLOBALS['db']->autoExecute(DB_PREFIX."video", $video,"INSERT");
  2726. //修改话题
  2727. if ($video['cate_id'] > 0){
  2728. $sql = "update ".DB_PREFIX."video_cate a set a.num = (select count(*) from ".DB_PREFIX."video b where b.cate_id = a.id and b.live_in in (1,3)";
  2729. $m_config = load_auto_cache("m_config");//初始化手机端配置
  2730. if((defined('OPEN_ROOM_HIDE')&&OPEN_ROOM_HIDE==1)&&intval($m_config['open_room_hide'])==1){
  2731. $sql.= " and b.province <> '火星' and b.province <>''";
  2732. }
  2733. $sql.=") where a.id = ".$video['cate_id'];
  2734. $GLOBALS['db']->query($sql);
  2735. }
  2736. $user_id = intval($video['user_id']);
  2737. $sql = "select sex,ticket,refund_ticket,user_level,fans_count from ".DB_PREFIX."user where id = ".$user_id;
  2738. $user = $GLOBALS['db']->getRow($sql,true,true);
  2739. $m_config = load_auto_cache("m_config");
  2740. //sort_init(初始排序权重) = (用户可提现印票:fanwe_user.ticket - fanwe_user.refund_ticket) * 保留印票权重+ 直播/回看[回看是:0; 直播:9000000000 直播,需要排在最上面 ]+ fanwe_user.user_level * 等级权重+ fanwe_user.fans_count * 当前有的关注数权重
  2741. $sort_init = (intval($user['ticket']) - intval($user['refund_ticket'])) * floatval($m_config['ticke_weight']);
  2742. $sort_init += intval($user['user_level']) * floatval($m_config['level_weight']);
  2743. $sort_init += intval($user['fans_count']) * floatval($m_config['focus_weight']);
  2744. $sql = "update ".DB_PREFIX."video set sort_init = ".$sort_init.",watch_number=0,robot_num=0 where id = ".$video_id;
  2745. $GLOBALS['db']->query($sql);
  2746. $sql = "delete from ".DB_PREFIX."video_history WHERE id=".$video_id;
  2747. $GLOBALS['db']->query($sql);
  2748. //将mysql数据,同步一份到redis中
  2749. sync_video_to_redis($video_id,'*',false);
  2750. //付费记录从历史表移到原记录表中
  2751. if(intval($video['is_live_pay'])==1){
  2752. syn_history_to_live_pay($video_id);
  2753. }
  2754. $video_redis->video_online($video_id, $video['group_id']);
  2755. }
  2756. }else{
  2757. //回看直播:下架
  2758. $sql = "update ".DB_PREFIX."video set live_in = 0 where live_in = 3 and id = ".$video_id;
  2759. $GLOBALS['db']->query($sql);
  2760. if($GLOBALS['db']->affected_rows()){
  2761. //下架后,将redis数据,同步一份到mysql
  2762. $fields = array('share_count','like_count','fans_count', 'sort_num', 'vote_number', 'robot_num','watch_number', 'virtual_watch_number', 'max_watch_number','user_id');
  2763. $video = $video_redis->getRow_db($video_id, $fields);
  2764. $GLOBALS['db']->autoExecute(DB_PREFIX . "video", $video, "UPDATE", "id=" . $video_id);
  2765. //将数据历史表中
  2766. $sql = "select * from ".DB_PREFIX."video where id = ".$video_id;
  2767. $video = $GLOBALS['db']->getRow($sql);
  2768. $GLOBALS['db']->autoExecute(DB_PREFIX."video_history", $video,"INSERT");
  2769. //修改话题
  2770. if ($video['cate_id'] > 0){
  2771. $sql = "update ".DB_PREFIX."video_cate a set a.num = (select count(*) from ".DB_PREFIX."video b where b.cate_id = a.id and b.live_in in (1,3)";
  2772. $m_config = load_auto_cache("m_config");//初始化手机端配置
  2773. if((defined('OPEN_ROOM_HIDE')&&OPEN_ROOM_HIDE==1)&&intval($m_config['open_room_hide'])==1){
  2774. $sql.= " and b.province <> '火星' and b.province <>''";
  2775. }
  2776. $sql.=") where a.id = ".$video['cate_id'];
  2777. $GLOBALS['db']->query($sql);
  2778. }
  2779. //将mysql数据,同步一份到redis中
  2780. sync_video_to_redis($video_id,'*',false);
  2781. //付费直播记录移到历史表
  2782. if(intval($video['is_live_pay'])==1){
  2783. syn_live_pay_to_history($video_id,$video['user_id']);
  2784. }
  2785. $sql = "delete from ".DB_PREFIX."video WHERE id=".$video_id;
  2786. $GLOBALS['db']->query($sql);
  2787. }
  2788. }
  2789. $sql = "select count(*) as num from ".DB_PREFIX."video_history where is_delete = 0 and is_del_vod = 0 and user_id = '".$user_id."'";
  2790. $video_count = $GLOBALS['db']->getOne($sql);
  2791. $sql = "update ".DB_PREFIX."user set video_count = ".$video_count." where id = ".$user_id;
  2792. $GLOBALS['db']->query($sql);
  2793. //提交事务,不等 消息推送,防止锁太久
  2794. $GLOBALS['db']->Commit($pInTrans);
  2795. $pInTrans = false;//防止,下面异常时,还调用:Rollback
  2796. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/UserRedisService.php');
  2797. $user_redis = new UserRedisService();
  2798. $user_data = array();
  2799. $user_data['video_count'] = $video_count;
  2800. $user_redis->update_db($user_id, $user_data);
  2801. return true;
  2802. }catch(Exception $e){
  2803. //异常回滚
  2804. $GLOBALS['db']->Rollback($pInTrans);
  2805. return true;
  2806. }
  2807. }
  2808. /**
  2809. * 查询直播频道详情
  2810. * https://www.qcloud.com/doc/api/258/4717
  2811. * @param unknown_type $channelId
  2812. * @return
  2813. */
  2814. function describe_lvb_channel($channelId){
  2815. fanwe_require(APP_ROOT_PATH.'system/QcloudApi/QcloudApi.php');
  2816. $m_config = load_auto_cache("m_config");
  2817. $config = array('SecretId' => $m_config['qcloud_secret_id'],
  2818. 'SecretKey' => $m_config['qcloud_secret_key'],
  2819. 'RequestMethod' => 'GET',
  2820. 'DefaultRegion' => 'gz');
  2821. $service = QcloudApi::load(QcloudApi::MODULE_LIVE, $config);
  2822. $package = array('channelId' => $channelId);
  2823. $ret = $service->DescribeLVBChannel($package);
  2824. return $ret;
  2825. }
  2826. /**
  2827. * 给用户分配红包
  2828. * @param unknown_type $user_prop_id
  2829. * @param unknown_type $user_id
  2830. * @param unknown_type $money
  2831. */
  2832. function allot_red_to_user($user_prop_id, $user_id, $money){
  2833. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/VideoRedRedisService.php');
  2834. $videoRed_redis = new VideoRedRedisService();
  2835. $videoRed_redis->add_user_winning($user_prop_id, $user_id, $money);
  2836. //增加:用户钻石
  2837. $sql = "update ".DB_PREFIX."user set diamonds = diamonds + ".$money." where id = ".$user_id;
  2838. $GLOBALS['db']->query($sql);
  2839. user_deal_to_reids(array($user_id));
  2840. }
  2841. /**
  2842. * 将直播房间中的,红包领取记录,同步一份到mysql中
  2843. * 正常在:直播结束时调用一次,删除直播(视频)时调用一次
  2844. * @param unknown_type $video_id
  2845. */
  2846. function syn_red_to_mysql($video_id){
  2847. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/VideoRedisService.php');
  2848. $video_redis = new VideoRedisService();
  2849. //直播结束后,将redis中,领取红包记录保存一份到mysql中
  2850. $red_list = $video_redis->get_reds($video_id);
  2851. if (count($red_list) > 0){
  2852. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/VideoRedRedisService.php');
  2853. $videoRed_redis = new VideoRedRedisService();
  2854. $pInTrans = $GLOBALS['db']->StartTrans();
  2855. try
  2856. {
  2857. foreach ($red_list as $red_id) {
  2858. $user_list = $videoRed_redis->get_winnings($red_id);
  2859. foreach ($user_list as $k=>$v) {
  2860. $user_id = intval($v['user_id']);
  2861. $sql = "select id from ".DB_PREFIX."video_red where video_id =".$video_id." and video_prop_id = ".$red_id." and user_id =".$user_id;
  2862. $id = $GLOBALS['db']->getOne($sql);
  2863. $video_red = array();
  2864. $video_red['video_id'] = $video_id;
  2865. $video_red['video_prop_id'] = $red_id;
  2866. $video_red['user_id'] = $user_id;
  2867. $video_red['diamonds'] = $v['diamonds'];
  2868. if ($id > 0){
  2869. $GLOBALS['db']->autoExecute(DB_PREFIX."video_red", $video_red, "UPDATE","id=".$id);
  2870. }else{
  2871. $GLOBALS['db']->autoExecute(DB_PREFIX."video_red", $video_red, "INSERT");
  2872. }
  2873. }
  2874. }
  2875. $GLOBALS['db']->Commit($pInTrans);
  2876. }catch(Exception $e){
  2877. //异常回滚
  2878. $GLOBALS['db']->Rollback($pInTrans);
  2879. }
  2880. }
  2881. }
  2882. function filter_false(&$data, $default = array()){
  2883. foreach($default as $key => $value)
  2884. {
  2885. if($data[$key] == false){
  2886. $data[$key] = $value;
  2887. }
  2888. }
  2889. }
  2890. function get_video_url($room_id, $live_in)
  2891. {
  2892. if ($live_in == 3 || $live_in == 0) {
  2893. return url('live#show', array('room_id' => $room_id, 'is_vod' => 1));
  2894. } else {
  2895. return url('live#show', array('room_id' => $room_id));
  2896. }
  2897. }
  2898. function get_live_image($v)
  2899. {
  2900. return get_spec_image(empty($v['live_image']) ? $v['head_image'] : $v['live_image'], 285, 160, 1);
  2901. }
  2902. function getPropTablename($video_id){
  2903. $video_id = intval($video_id);
  2904. // $table = DB_PREFIX . 'video';
  2905. // $res = $GLOBALS['db']->getRow("SELECT `prop_table` FROM $table WHERE `id`=$video_id;");
  2906. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/VideoRedisService.php');
  2907. $video_redis = new VideoRedisService();
  2908. $video = $video_redis->getRow_db($video_id,array('prop_table'));
  2909. return $video ? $video['prop_table'] : $video;
  2910. }
  2911. function createPropTable($time = NOW_TIME)
  2912. {
  2913. //获取上个月自增ID
  2914. $prev_m = date("Ym",strtotime("-1 month"));
  2915. $prev_table = DB_PREFIX . 'video_prop_' . $prev_m;
  2916. $result = $GLOBALS['db']->getRow("SHOW TABLES LIKE'$prev_table'");
  2917. if(empty($result)) {
  2918. $prev_table = DB_PREFIX . 'video_prop';
  2919. }
  2920. $increment_id = $GLOBALS['db']->getOne("SELECT MAX(id) from ".$prev_table);
  2921. $increment_id = intval($increment_id)?intval($increment_id):1;
  2922. $table = DB_PREFIX . 'video_prop_'.to_date($time,'Ym');
  2923. $res = $GLOBALS['db']->getRow("SHOW TABLES LIKE'$table'");
  2924. if (!$res) {
  2925. // 创建新表
  2926. // 表结构
  2927. // -- Table structure for `%DB_PREFIX%video_prop`
  2928. $sql= "CREATE TABLE `$table` (
  2929. `id` int(11) NOT NULL AUTO_INCREMENT,
  2930. `prop_id` int(10) NOT NULL DEFAULT '0' COMMENT '礼物id',
  2931. `prop_name` varchar(255) NOT NULL COMMENT '道具名',
  2932. `total_score` int(11) NOT NULL COMMENT '积分(from_user_id可获得的积分)合计',
  2933. `total_diamonds` int(11) NOT NULL COMMENT '钻石(from_user_id减少的钻石)合计',
  2934. `total_ticket` int(11) NOT NULL DEFAULT '0' COMMENT '印票(to_user_id增加的印票)合计;is_red_envelope=1时,为主播获得的:钻石 数量',
  2935. `from_user_id` int(10) NOT NULL DEFAULT '0' COMMENT '送',
  2936. `to_user_id` int(10) NOT NULL DEFAULT '0' COMMENT '收',
  2937. `create_time` int(10) NOT NULL COMMENT '时间',
  2938. `create_date` date NOT NULL COMMENT '日期字段,按日期归档;要不然数据量太大了;不好维护',
  2939. `create_d` tinyint(2) NOT NULL COMMENT '日',
  2940. `create_w` tinyint(2) NOT NULL COMMENT '周',
  2941. `num` int(10) NOT NULL COMMENT '送的数量',
  2942. `video_id` int(10) NOT NULL DEFAULT '0' COMMENT '直播ID',
  2943. `group_id` varchar(20) NOT NULL COMMENT '群组ID',
  2944. `is_red_envelope` tinyint(1) NOT NULL DEFAULT '0' COMMENT '1:红包',
  2945. `msg` varchar(255) NOT NULL COMMENT '弹幕内容',
  2946. `ActionStatus` varchar(10) NOT NULL COMMENT '消息发送,请求处理的结果,OK表示处理成功,FAIL表示失败。',
  2947. `ErrorInfo` varchar(255) NOT NULL COMMENT '消息发送,错误信息',
  2948. `ErrorCode` int(10) NOT NULL COMMENT '错误码',
  2949. `create_ym` varchar(12) NOT NULL COMMENT '年月 如:201610',
  2950. `from_ip` varchar(255) NOT NULL COMMENT '送礼物人IP',
  2951. `is_private` int(4) default 0 COMMENT '判断是否为私信送礼 1表示私信 2表示不是私信',
  2952. `is_award` tinyint(1) NOT NULL COMMENT '是否为可中奖礼物 1为 是、0为否',
  2953. PRIMARY KEY (`id`),
  2954. KEY `idx_ecs_video_prop_cc_1` (`create_ym`,`create_d`,`from_user_id`,`total_diamonds`),
  2955. KEY `from_user_id` (`from_user_id`,`total_diamonds`) USING BTREE,
  2956. KEY `idx_ecs_video_prop_cc_2` (`create_ym`,`from_user_id`,`total_diamonds`),
  2957. KEY `to_user_id` (`is_red_envelope`,`to_user_id`,`total_ticket`) USING BTREE,
  2958. KEY `idx_ecs_video_prop_cc_3` (`create_ym`,`create_d`,`is_red_envelope`,`to_user_id`,`total_ticket`) USING BTREE,
  2959. KEY `idx_ecs_video_prop_cc_4` (`create_ym`,`is_red_envelope`,`to_user_id`,`total_ticket`) USING BTREE
  2960. ) ENGINE=InnoDB AUTO_INCREMENT={$increment_id} DEFAULT CHARSET=utf8 COMMENT='送礼物表'";
  2961. $res = $GLOBALS['db']->query($sql);
  2962. }
  2963. /*$res = 1;
  2964. $table = DB_PREFIX . 'video_prop';*/
  2965. return $res ? $table : false;
  2966. }
  2967. /**
  2968. * 取前50条观众列表,IM推送到客户端
  2969. * @param unknown_type $video_id
  2970. * @param unknown_type $group_id
  2971. * @return mixed
  2972. */
  2973. function push_viewer($video_id,$group_id,$page_size=50){
  2974. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/VideoViewerRedisService.php');
  2975. $video_viewer_redis = new VideoViewerRedisService();
  2976. $viewer = $video_viewer_redis->get_viewer_list2($video_id,1,$page_size);
  2977. for($i=count($viewer['list'])-1;$i>=0;$i--)
  2978. {
  2979. if ($viewer['list'][$i]['user_id']==0)
  2980. {
  2981. array_splice($viewer['list'],$i,1);
  2982. }
  2983. }
  2984. fanwe_require(APP_ROOT_PATH .'mapi/lib/core/shorturl.php');
  2985. $user_list = array();
  2986. $viewer['list_fields'] = array('user_id','user_level','head_image','v_icon','is_robot','is_authentication');
  2987. $short = shorturl::SHORTURL;// 'http://t.cn/';
  2988. foreach($viewer['list'] as $k=>$v){
  2989. $head_image = $v['head_image'];
  2990. $v_icon = $v['v_icon'];
  2991. $is_robot = intval($v['is_robot']);
  2992. $is_authentication = intval($v['is_authentication']);
  2993. if (!empty($head_image)){
  2994. $head_image = shorturl::getShort($head_image);
  2995. if (empty($head_image)){
  2996. $head_image = $v['head_image'];
  2997. }else{
  2998. $head_image = str_replace($short, '', $head_image);
  2999. }
  3000. }
  3001. if (!empty($v_icon)){
  3002. $v_icon = shorturl::getShort($v_icon);
  3003. if (empty($v_icon)){
  3004. $v_icon = $v['v_icon'];
  3005. }else{
  3006. $v_icon = str_replace($short, '', $v_icon);
  3007. }
  3008. }
  3009. $user2 = array((string)$v['user_id'],(string)$v['user_level'],$head_image,$v_icon,$is_robot,$is_authentication);
  3010. $user_list[] = $user2;
  3011. }
  3012. unset($viewer['list']);
  3013. $viewer['short_url'] = $short;//如果head_image,v_icon不是http://开头则需要加上short_url
  3014. $viewer['list_data'] = $user_list;
  3015. $viewer['time'] = NOW_TIME;
  3016. $ext = array();
  3017. $ext['type'] = 42; //42 通用数据格式
  3018. $ext['data_type'] = 0 ;//直播间观众列表
  3019. $ext['data'] = $viewer;
  3020. $msg_content = json_encode($ext);
  3021. fanwe_require(APP_ROOT_PATH.'system/tim/TimApi.php');
  3022. $api = createTimAPI();
  3023. $ret = $api->group_send_group_system_notification($group_id, $msg_content);
  3024. return $ret;
  3025. }
  3026. /**
  3027. * 回播定时推送观众列表
  3028. * @param unknown_type $video_id
  3029. * @param unknown_type $page_size
  3030. * @param unknown_type $s
  3031. * @return multitype:mixed
  3032. */
  3033. function crontab_viewer($video_id,$page_size=50,$s=50){
  3034. $ret = array();
  3035. $is_ok = $GLOBALS['cache']->set_lock('crontab_viewer_num',$s);
  3036. if($is_ok) {
  3037. if ($video_id == 0){
  3038. $sql = "SELECT id,group_id,watch_number FROM ".DB_PREFIX."video where live_in = 3 and watch_number > 0";
  3039. }else{
  3040. $sql = "SELECT id,group_id,watch_number FROM ".DB_PREFIX."video where id = ".$video_id;
  3041. }
  3042. //设置直播间观众列表返回数量
  3043. $m_config = load_auto_cache("m_config");
  3044. $page_size = intval($m_config['view_page_size'])>0?intval($m_config['view_page_size']):50;
  3045. $list = $GLOBALS['db']->getAll($sql,true,true);
  3046. if (count($list) > 0) {
  3047. foreach ( $list as $k => $v )
  3048. {
  3049. $ret[] = push_viewer($v['id'],$v['group_id'],$page_size);
  3050. }
  3051. }
  3052. $GLOBALS['cache']->del_lock('crontab_viewer_num');
  3053. }
  3054. return $ret;
  3055. }
  3056. function filter_all_false($default = array()){
  3057. if(is_array($default)){
  3058. foreach($default as $key => $value)
  3059. {
  3060. if(is_array($value)){
  3061. $value = filter_all_false($value);
  3062. }else{
  3063. if($value===false){
  3064. $value=get_type($value);
  3065. }
  3066. }
  3067. $default[$key] = $value;
  3068. }
  3069. }else{
  3070. if($default===false){
  3071. $default=get_type($default);
  3072. }
  3073. }
  3074. return $default;
  3075. }
  3076. /*
  3077. 判断变量的类型
  3078. */
  3079. function get_type($date=''){
  3080. switch (gettype($date))
  3081. {
  3082. case 'integer':
  3083. return 0;
  3084. break;
  3085. break;
  3086. case 'string':
  3087. return '';
  3088. break;
  3089. case 'array':
  3090. return array();
  3091. break;
  3092. case 'boolean':
  3093. return '0';
  3094. break;
  3095. /* case 'double':
  3096. return 0.00;
  3097. break;
  3098. case 'object':
  3099. return object();
  3100. break;
  3101. case 'resource':
  3102. return 'resource';
  3103. break;
  3104. case 'NULL':
  3105. return 'NULL';
  3106. break;
  3107. case 'object':
  3108. return 'object';
  3109. break;*/
  3110. default:
  3111. return '0';
  3112. }
  3113. }
  3114. /*
  3115. * 视频合并
  3116. * @param string $channel_id 直播码
  3117. * @param string $new_file_name 新的文件名
  3118. */
  3119. function Com_ConcatVideo($channel_id,$new_file_name){
  3120. fanwe_require(APP_ROOT_PATH . 'mapi/lib/core/video_factory.php');
  3121. $video_factory = new VideoFactory();
  3122. $ret = $video_factory->ConcatVideo($channel_id,$new_file_name);
  3123. return $ret;
  3124. }
  3125. //使用的sdk版本 0默认腾讯云、1金山
  3126. //映射关系类型 腾讯云直播, 金山云,星域,方维云 ,阿里云
  3127. //video_type 1 2 3 4 5
  3128. //sdk_type 0 1 1 1 1
  3129. function get_sdk_info($video_type){
  3130. switch($video_type){
  3131. case 1:
  3132. return $sdk_type = 0;
  3133. break;
  3134. default;
  3135. return $sdk_type = 1;
  3136. break;
  3137. }
  3138. }
  3139. //------付费相关------
  3140. /**
  3141. * 按时付费直播结束后转按场付费
  3142. * @param $video
  3143. */
  3144. function change_pay_type($video){
  3145. if(intval($video['live_pay_type'])!=1){
  3146. $sql = "update ".DB_PREFIX."video set live_pay_type = 1 where id = ".$video['id'];
  3147. $GLOBALS['db']->query($sql);
  3148. }
  3149. }
  3150. /**
  3151. * 是否付费过
  3152. */
  3153. function get_pay_video_info($video_info){
  3154. $root = array('status'=>1,'error'=>'');
  3155. //初始化参数
  3156. $live_pay_time = strim($video_info['live_pay_time']);
  3157. $live_pay_type = intval($video_info['live_pay_type']);
  3158. $live_fee = intval($video_info['live_fee']);
  3159. $live_is_mention = intval($video_info['live_is_mention']);
  3160. $is_live_pay = intval($video_info['is_live_pay']);
  3161. $user_id = intval($GLOBALS['user_info']['id']);//用户ID
  3162. $video_user_id = intval($video_info['user_id']);//主播ID
  3163. $live_in = intval($video_info['live_in']);//直播间ID
  3164. $room_id = intval($video_info['id']);//直播间ID
  3165. $is_pay_over = 0; //是否付费 1 已付费;0未付费
  3166. $new_room_id = 0;
  3167. if(intval($video_info['pay_room_id'])>0){
  3168. $room_id = $video_info['pay_room_id'];
  3169. $new_room_id = $video_info['id'];
  3170. }
  3171. //非付费直播间 或者 直播不正常 或者 直播不存在 跳过
  3172. if($is_live_pay==1&&$live_fee>0&&$live_in!=0&&$room_id>0){
  3173. if(!$GLOBALS['user_info']){
  3174. $root['error'] = "用户未登陆,请先登录.";
  3175. $root['status'] = 0;
  3176. $root['user_login_status'] = 0;//有这个参数: user_login_status = 0 时,表示服务端未登陆、要求登陆,操作
  3177. }else{
  3178. //默认提醒
  3179. if($room_id > 0){
  3180. //获取付费记录信息
  3181. $sql = "select id,pay_time_next,total_time,total_diamonds,live_pay_type from ".DB_PREFIX."live_pay_log where from_user_id = ".$user_id." and to_user_id = ".$video_user_id." and video_id=".$room_id;
  3182. $live_pay_log_info = $GLOBALS['db']->getRow($sql);
  3183. //不可提醒
  3184. $now_time = NOW_TIME;
  3185. $root['status'] = 0;
  3186. if(intval($live_pay_log_info['id'])>0&&($live_pay_log_info['live_pay_type']==1||($live_pay_log_info['pay_time_next']>$now_time&&$live_pay_log_info['live_pay_type']==0))){
  3187. $is_pay_over = 1;
  3188. $root['status'] = 1;
  3189. }
  3190. }
  3191. }
  3192. }
  3193. $root['is_live_pay'] = $is_live_pay;
  3194. $root['live_pay_type'] = $live_pay_type;
  3195. $root['live_fee'] = $live_fee;
  3196. $root['is_pay_over'] = $is_pay_over;
  3197. return $root;
  3198. }
  3199. /**
  3200. * 将付费直播记录移到历史表
  3201. * 正常在:直播结束时调用一次,删除直播(视频)时调用一次
  3202. * @param unknown_type $video_id
  3203. */
  3204. function syn_live_pay_to_history($video_id,$user_id){
  3205. if($video_id>0){
  3206. $sql = "select MAX(id) from ".DB_PREFIX."live_pay_log_history";
  3207. $live_pay_log_history_mid = $GLOBALS['db']->getOne($sql);
  3208. $sql = "select MAX(id) from ".DB_PREFIX."live_pay_log";
  3209. $live_pay_mid = $GLOBALS['db']->getOne($sql);
  3210. if($live_pay_log_history_mid>$live_pay_mid){
  3211. $video_max = $live_pay_log_history_mid+1;
  3212. $sql="alter table ".DB_PREFIX."live_pay_log AUTO_INCREMENT=".$video_max;
  3213. $GLOBALS['db']->query($sql);
  3214. }
  3215. //将本次直播付费记录 移到历史表中
  3216. $fields = 'id,total_time,total_ticket,total_diamonds,from_user_id,to_user_id,create_time,create_date,create_ym,create_d,create_w,live_fee,live_pay_time,live_pay_date,video_id,group_id,pay_time_end,pay_time_next,live_is_mention_time,live_is_mention_pay,live_pay_type,new_room_id,total_score,uesddiamonds_to_score,ticket_to_rate';
  3217. $sql = "insert into ".DB_PREFIX."live_pay_log_history(".$fields.") select ".$fields." from ".DB_PREFIX."live_pay_log where video_id='".$video_id."' and to_user_id=".$user_id;
  3218. $GLOBALS['db']->query($sql);
  3219. $sql= "delete from ".DB_PREFIX."live_pay_log where video_id='".$video_id."' and to_user_id=".$user_id;
  3220. $GLOBALS['db']->query($sql);
  3221. }
  3222. }
  3223. /**
  3224. * 将付费直播从历史表移到原记录表中
  3225. * 正常在:直播结束时调用一次,删除直播(视频)时调用一次
  3226. * @param unknown_type $video_id
  3227. */
  3228. function syn_history_to_live_pay($video_id){
  3229. if($video_id>0){
  3230. //将本次直播付费记录 从历史表移到原记录表中
  3231. $fields = 'total_time,total_ticket,total_diamonds,from_user_id,to_user_id,create_time,create_date,create_ym,create_d,create_w,live_fee,live_pay_time,live_pay_date,video_id,group_id,pay_time_end,pay_time_next,live_is_mention_time,live_is_mention_pay,live_pay_type,new_room_id,total_score,uesddiamonds_to_score,ticket_to_rate';
  3232. $sql = "insert into ".DB_PREFIX."live_pay_log(".$fields.") select ".$fields." from ".DB_PREFIX."live_pay_log_history where video_id='".$video_id."'";
  3233. $GLOBALS['db']->query($sql);
  3234. $sql= "delete from ".DB_PREFIX."live_pay_log_history where video_id='".$video_id."'";
  3235. $GLOBALS['db']->query($sql);
  3236. }
  3237. }
  3238. //----------------竞拍相关------------------
  3239. /**
  3240. * 根据竞拍ID 获得 竞拍参与表
  3241. */
  3242. function get_pailog_table($paiid = 0){
  3243. $idx = intval($paiid/10);
  3244. return DB_PREFIX."pai_log_".$idx;
  3245. }
  3246. /**
  3247. * $goods pai_goods 的信息
  3248. * $type=0 竞拍的人回调, $type=1 主播的回调
  3249. */
  3250. function format_pai_goods(&$goods,$type=0){
  3251. if($goods['imgs']!=''){
  3252. $goods['imgs'] = json_decode($goods['imgs'],1);
  3253. //$goods['img']=$goods['imgs']['0'];
  3254. $goods['img']=get_spec_image($goods['imgs']['0']);
  3255. if($goods['imgs']==""){
  3256. $goods['imgs'] = array();
  3257. }else{
  3258. foreach($goods['imgs'] as $k=>$v){
  3259. //$goods['imgs'][$k]=get_domain().APP_ROOT.$v;
  3260. $goods['imgs'][$k]=get_spec_image($v);
  3261. }
  3262. }
  3263. }
  3264. else{
  3265. $goods['imgs'] = array();
  3266. }
  3267. if($goods['status']==0){
  3268. if(PAI_YANCHI_MODULE == 0){
  3269. $goods['pai_left_time'] = $goods['pai_time'] * 3600 + $goods['create_time'] + $goods['now_yanshi'] * $goods['pai_yanshi'] * 60 - NOW_TIME;
  3270. }else{
  3271. $goods['pai_left_time'] = $goods['end_time'] - NOW_TIME;
  3272. }
  3273. if($goods['pai_left_time'] < 0){
  3274. $goods['pai_left_time'] = 0;
  3275. }
  3276. }
  3277. else{
  3278. $goods['pai_left_time'] = 0;
  3279. }
  3280. if(isset($goods['user_pai_info']['consignee_district']) && $goods['user_pai_info']['consignee_district']!=""){
  3281. $goods['user_pai_info']['consignee_district'] = json_decode($goods['user_pai_info']['consignee_district'],1);
  3282. if($goods['user_pai_info']['consignee_district']==""){
  3283. $goods['user_pai_info']['consignee_district'] = array();
  3284. }
  3285. }
  3286. else{
  3287. $goods['user_pai_info']['consignee_district'] = array();
  3288. }
  3289. if($goods['district']!=''){
  3290. $goods['district'] = json_decode($goods['district'],1);
  3291. if($goods['district']==""){
  3292. $goods['district'] = array();
  3293. }
  3294. }
  3295. else{
  3296. $goods['district'] = array();
  3297. }
  3298. if($goods['last_pai_diamonds']==0){
  3299. $goods['last_pai_diamonds']=$goods['qp_diamonds'];
  3300. }
  3301. if($goods['is_true']==0){
  3302. //虚拟
  3303. if ($type==1) {
  3304. if ($goods['order_status']==1) {
  3305. $goods['info_status']=1;
  3306. $goods['button_status']=0;
  3307. $goods['expire_time']=strtotime($goods['order_time']) - 8*3600 + MAX_PAI_PAY_TIME - NOW_TIME;
  3308. }elseif ($goods['order_status']==2) {
  3309. $goods['info_status']=2;
  3310. $goods['button_status']=2;
  3311. $date_time=strtotime($goods['date_time']) - 8*3600;
  3312. if ($date_time-NOW_TIME>0) {
  3313. //约会倒计时
  3314. $goods['expire_time']=$date_time - NOW_TIME;
  3315. $goods['info_status_type']=0;
  3316. }else{
  3317. //约会确认倒计时
  3318. $goods['expire_time']=$date_time + MAX_PODCAST_CONFIRM_TIME - NOW_TIME;
  3319. $goods['info_status_type']=1;
  3320. }
  3321. }elseif ($goods['order_status']==3) {
  3322. $goods['info_status']=3;
  3323. $goods['button_status']=0;
  3324. $goods['expire_time']=0;
  3325. }elseif ($goods['order_status']==4) {
  3326. $goods['info_status']=4;
  3327. $goods['button_status']=0;
  3328. $goods['expire_time']=0;
  3329. }elseif ($goods['order_status']==5) {
  3330. $goods['info_status']=5;
  3331. $goods['button_status']=5;
  3332. $goods['expire_time']=0;//strtotime($goods['order_status_time']) + 16*3600 - NOW_TIME;
  3333. }elseif ($goods['order_status']==6) {
  3334. $goods['info_status']=6;
  3335. $goods['button_status']=0;
  3336. $goods['expire_time']=0;
  3337. }elseif ($goods['order_status']==7) {
  3338. $goods['info_status']=7;
  3339. $goods['button_status']=0;
  3340. $goods['expire_time']=0;
  3341. }else{
  3342. $goods['info_status']=0;
  3343. $goods['button_status']=0;
  3344. $goods['expire_time']=0;
  3345. }
  3346. }else{
  3347. if ($goods['order_status']==1) {
  3348. $goods['info_status']=1;
  3349. $goods['button_status']=1;
  3350. $goods['expire_time']=strtotime($goods['order_time']) - 8*3600 + MAX_PAI_PAY_TIME - NOW_TIME;
  3351. }elseif ($goods['order_status']==2) {
  3352. $goods['info_status']=2;
  3353. $goods['button_status']=0;
  3354. $date_time=strtotime($goods['date_time']) - 8*3600;
  3355. if ($date_time>NOW_TIME) {
  3356. //约会倒计时
  3357. $goods['expire_time']=$date_time - NOW_TIME;
  3358. $goods['info_status_type']=0;
  3359. }else{
  3360. //主播未确认7天,倒计时
  3361. $goods['expire_time']=$date_time + MAX_PODCAST_CONFIRM_TIME - NOW_TIME;
  3362. $goods['info_status_type']=1;
  3363. }
  3364. }elseif ($goods['order_status']==3) {
  3365. $goods['info_status']=3;
  3366. $goods['button_status']=3;
  3367. //买家未确认7天,倒计时
  3368. $goods['expire_time']=intval($goods['order_status_time']) + MAX_USER_CONFIRM_TIME - NOW_TIME;
  3369. }elseif ($goods['order_status']==4) {
  3370. $goods['info_status']=4;
  3371. $goods['button_status']=4;
  3372. $goods['expire_time']=0;
  3373. }elseif ($goods['order_status']==5) {
  3374. $goods['info_status']=5;
  3375. $goods['button_status']=0;
  3376. $goods['expire_time']=0;
  3377. }elseif ($goods['order_status']==6) {
  3378. $goods['info_status']=6;
  3379. $goods['button_status']=0;
  3380. $goods['expire_time']=0;
  3381. }elseif ($goods['order_status']==7) {
  3382. $goods['info_status']=7;
  3383. $goods['button_status']=0;
  3384. $goods['expire_time']=0;
  3385. }else{
  3386. $goods['info_status']=0;
  3387. $goods['button_status']=0;
  3388. $goods['expire_time']=0;
  3389. }
  3390. }
  3391. }else{
  3392. //实物
  3393. if ($type==1) {
  3394. if ($goods['order_status']==1) {
  3395. $goods['info_status']=1;
  3396. $goods['button_status']=0;
  3397. $goods['expire_time']=strtotime($goods['order_time']) - 8*3600 + MAX_PAI_PAY_TIME - NOW_TIME;
  3398. }elseif ($goods['order_status']==2) {
  3399. $goods['info_status']=2;
  3400. $goods['button_status']=2;
  3401. $goods['expire_time']=strtotime($goods['pay_time']) - 8*3600 + MAX_PODCAST_CONFIRM_VIRTUAL_TIME - NOW_TIME;
  3402. }elseif ($goods['order_status']==3) {
  3403. $goods['info_status']=3;
  3404. $goods['button_status']=0;
  3405. $goods['expire_time']=intval($goods['order_status_time']) + MAX_USER_CONFIRM_VIRTUAL_TIME - NOW_TIME;
  3406. }elseif ($goods['order_status']==4) {
  3407. $goods['info_status']=4;
  3408. $goods['button_status']=0;
  3409. $goods['expire_time']=0;
  3410. }elseif ($goods['order_status']==5) {
  3411. $goods['info_status']=5;
  3412. $goods['button_status']=5;
  3413. $goods['expire_time']=0;//strtotime($goods['order_status_time']) + 16*3600 - NOW_TIME;
  3414. }elseif ($goods['order_status']==6) {
  3415. $goods['info_status']=6;
  3416. $goods['button_status']=0;
  3417. $goods['expire_time']=0;
  3418. }elseif ($goods['order_status']==7) {
  3419. $goods['info_status']=7;
  3420. $goods['button_status']=0;
  3421. $goods['expire_time']=0;
  3422. }else{
  3423. $goods['info_status']=0;
  3424. $goods['button_status']=0;
  3425. $goods['expire_time']=0;
  3426. }
  3427. }else{
  3428. if ($goods['order_status']==1) {
  3429. $goods['info_status']=1;
  3430. $goods['button_status']=1;
  3431. $goods['expire_time']=strtotime($goods['order_time']) - 8*3600 + MAX_PAI_PAY_TIME - NOW_TIME;
  3432. }elseif ($goods['order_status']==2) {
  3433. $goods['info_status']=2;
  3434. $goods['button_status']=0;
  3435. $goods['expire_time']=strtotime($goods['pay_time']) - 8*3600 + MAX_PODCAST_CONFIRM_VIRTUAL_TIME - NOW_TIME;
  3436. }elseif ($goods['order_status']==3) {
  3437. $goods['info_status']=3;
  3438. $goods['button_status']=3;
  3439. //买家未确认7天,倒计时
  3440. $goods['expire_time']=intval($goods['order_status_time']) + MAX_USER_CONFIRM_VIRTUAL_TIME - NOW_TIME;
  3441. }elseif ($goods['order_status']==4) {
  3442. $goods['info_status']=4;
  3443. $goods['button_status']=4;
  3444. $goods['expire_time']=0;
  3445. }elseif ($goods['order_status']==5) {
  3446. $goods['info_status']=5;
  3447. $goods['button_status']=0;
  3448. $goods['expire_time']=0;
  3449. }elseif ($goods['order_status']==6) {
  3450. $goods['info_status']=6;
  3451. $goods['button_status']=0;
  3452. $goods['expire_time']=0;
  3453. }elseif ($goods['order_status']==7) {
  3454. $goods['info_status']=7;
  3455. $goods['button_status']=0;
  3456. $goods['expire_time']=0;
  3457. }else{
  3458. $goods['info_status']=0;
  3459. $goods['button_status']=0;
  3460. $goods['expire_time']=0;
  3461. }
  3462. }
  3463. }
  3464. $goods['expire_date_time']=strtotime($goods['date_time']) - 8*3600 - NOW_TIME;
  3465. if ($goods['expire_date_time']<0) {
  3466. $goods['expire_date_time']=0;
  3467. }
  3468. if($goods['date_time']!=''){
  3469. date_time_format($goods['date_time']);
  3470. }
  3471. if($goods['order_status_time']!=''){
  3472. $goods['order_status_time']=to_date($goods['order_status_time'],'Y-m-d H:i:s');
  3473. }
  3474. if($goods['order_status']==2){
  3475. $goods['order_status_time']=0;
  3476. }
  3477. if($goods['pay_time']=='0000-00-00 00:00:00'){
  3478. $goods['pay_time']=0;
  3479. }
  3480. if ($goods['order_status']==4) {
  3481. $goods['final_time']=$goods['order_status_time'];
  3482. $goods['order_status_time']=0;
  3483. }
  3484. $goods['pai_logs_url']=SITE_DOMAIN.APP_ROOT.'/wap/index.php?ctl=pai_user&act=pailogs&id='.$goods['id'];
  3485. }
  3486. /**
  3487. * 格式化出价记录
  3488. */
  3489. function format_pai_logs(&$list,$status){
  3490. foreach($list as $k=>$v){
  3491. $str_len = mb_strlen($list[$k]['user_name'],'utf-8');
  3492. if ($str_len>2) {
  3493. $firstStr = mb_substr($list[$k]['user_name'], 0, 1, 'utf-8');
  3494. $lastStr = mb_substr($list[$k]['user_name'], -1, 1, 'utf-8');
  3495. $list[$k]['user_name']=$firstStr.'**'.$lastStr;
  3496. }
  3497. if($status==0 || $status==1){
  3498. if($k==0){
  3499. $list[$k]['pai_status'] = "领先";
  3500. }
  3501. else{
  3502. $list[$k]['pai_status'] = "出局";
  3503. }
  3504. }elseif($status==2){
  3505. $list[$k]['pai_status'] = "流拍";
  3506. }elseif($status==3){
  3507. if($k==0){
  3508. $list[$k]['pai_status'] = "失败";
  3509. }
  3510. else{
  3511. $list[$k]['pai_status'] = "出局";
  3512. }
  3513. }elseif($status==4){
  3514. if($k==0){
  3515. $list[$k]['pai_status'] = "成功";
  3516. }
  3517. else{
  3518. $list[$k]['pai_status'] = "出局";
  3519. }
  3520. }
  3521. //出价
  3522. //$list[$k]['pai_diamonds'] = $v['pai_sort'] * $v['jj_diamonds']+$v['qp_diamonds'];
  3523. $list[$k]['pai_date_format'] = to_date($v['pai_time'],"m.d H:i:s");
  3524. if($v['status'] == 0){
  3525. $list[$k]['status_format'] = "未支付";
  3526. }
  3527. elseif($v['status'] ==1){
  3528. $list[$k]['status_format'] = "已支付";
  3529. }
  3530. elseif($v['status'] ==2){
  3531. $list[$k]['status_format'] = "已流拍";
  3532. }
  3533. }
  3534. }
  3535. /*
  3536. * 排查订单支付超时
  3537. * 批量 查询 pai_join ,当 pai_status=1 , order_time+15*60<now_time,
  3538. * 则关闭 订单 order_status=6,扣去保证金,更新 goods_order;
  3539. * 同时查询下一名支付用户
  3540. * (1)若没有,则修改 pai_goods 的状态 status=2 表示流拍 ,同时推送消息,拍卖失败
  3541. * (2)若有下一名,则新增下单,同时更新 pai_join,pai_goods (pai_status =2 同时金额较高的)
  3542. */
  3543. function deal_payment_timeout(){
  3544. $pai_join_list=$GLOBALS['db']->getAll("select * from ".DB_PREFIX."pai_join where pai_status=1 and order_time-1+".MAX_PAI_PAY_TIME." <".NOW_TIME);
  3545. foreach($pai_join_list as $k=>$v){
  3546. $auth='';
  3547. if (isset($_REQUEST['auth'])) {
  3548. $auth=$_REQUEST['auth'];
  3549. }
  3550. $info = $GLOBALS['db']->getRow("SELECT * FROM ".DB_PREFIX."pai_goods WHERE id=".intval($v['pai_id']));
  3551. $bz_diamonds = intval($info['bz_diamonds']);//保证金
  3552. $podcast_id = intval($info['podcast_id']);//主播ID
  3553. $id= intval($info['id']);//商品ID
  3554. $name = strim($info['name']);
  3555. $time = NOW_TIME;
  3556. if($v['user_id'] == $info['last_user_id']){
  3557. //关闭订单 (扣去保证金?)
  3558. $sql = "update ".DB_PREFIX."goods_order set order_status = 6 ,order_status_time=".NOW_TIME." where id=".intval($v['order_id']) ;
  3559. $GLOBALS['db']->query($sql);
  3560. $sql = "update ".DB_PREFIX."pai_join set order_status = 6 ,pai_status=3 where id=".intval($v['id']) ;
  3561. $GLOBALS['db']->query($sql);
  3562. //保证金退还主播
  3563. $sql = "update ".DB_PREFIX."user set diamonds = diamonds + ".$bz_diamonds." where id = ".$podcast_id;
  3564. $GLOBALS['db']->query($sql);
  3565. fanwe_require(APP_ROOT_PATH.'/mapi/lib/redis/BaseRedisService.php');
  3566. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/UserRedisService.php');
  3567. $user_redis = new UserRedisService();
  3568. user_deal_to_reids(array($podcast_id));
  3569. $account_diamonds = $user_redis->getOne_db($podcast_id,'diamonds');//查询主播钻石
  3570. //会员账户 钻石变更日志表
  3571. $diamonds_log_data = array(
  3572. 'pai_id' => $id,
  3573. 'user_id' => $podcast_id,
  3574. 'diamonds'=> $bz_diamonds,//变更数额
  3575. 'account_diamonds'=>$account_diamonds,//账户余额
  3576. 'memo' =>'竞拍'.$name.',买家超时付款,主播获得保证金',//备注
  3577. 'create_time' => $time,
  3578. 'create_date' => to_date($time,'Y-m-d H:i:s'),
  3579. 'create_time_ymd' => to_date($time,'Y-m-d'),
  3580. 'create_time_y' => to_date($time,'Y'),
  3581. 'create_time_m' => to_date($time,'m'),
  3582. 'create_time_d' => to_date($time,'d'),
  3583. 'type' =>1,
  3584. );
  3585. $GLOBALS['db']->autoExecute(DB_PREFIX."user_diamonds_log",$diamonds_log_data);
  3586. //写入用户日志
  3587. $data = array();
  3588. $data['diamonds'] = $bz_diamonds;
  3589. $param['type'] = 8;//类型 0表示充值 1表示提现 2赠送道具 3 兑换印票 4表示保证金操作 5表示竞拍模块消费 6表示竞拍模块收益 8竞拍记录
  3590. $log_msg = '竞拍'.$info['name'].',买家超时付款,主播获得保证金';//备注
  3591. account_log_com($data,$podcast_id,$log_msg,$param);
  3592. //消息发送
  3593. $user_ids=array();
  3594. $user_ids[]=intval($v['user_id']);
  3595. $content="您参与的竞拍:‘".$info['name']."’ 付款超时,扣除您缴纳的保证金!";
  3596. FanweServiceCall("message","send",array("send_type"=>'no_pay',"user_ids"=>$user_ids,"content"=>$content));
  3597. //主播收到保证金消息发送
  3598. $user_ids=array();
  3599. $user_ids[]=$podcast_id;
  3600. $content= "竞拍用户超时未付款,已把保证金转入你账户。";
  3601. FanweServiceCall("message","send",array("send_type"=>'no_pay',"user_id"=>$user_ids,"content"=>$content));
  3602. }else{
  3603. //更改订单状态
  3604. $sql = "update ".DB_PREFIX."goods_order set order_status = 6 ,order_status_time=".NOW_TIME." where id=".intval($v['order_id']) ;
  3605. $GLOBALS['db']->query($sql);
  3606. $sql = "update ".DB_PREFIX."pai_join set order_status = 6 ,pai_status=3 where id=".intval($v['id']) ;
  3607. $GLOBALS['db']->query($sql);
  3608. //消息发送
  3609. $user_ids=array();
  3610. $user_ids[]=intval($v['user_id']);
  3611. $content="您参与的竞拍:‘".$info['name']."’ 付款超时!";
  3612. FanweServiceCall("message","send",array("send_type"=>'no_pay',"user_ids"=>$user_ids,"content"=>$content));
  3613. }
  3614. $next_pai_join=$GLOBALS['db']->getRow("select * from ".DB_PREFIX."pai_join where pai_status=2 and pai_diamonds >0 and pai_id=".intval($v['pai_id'])." ORDER BY pai_diamonds DESC ");
  3615. if ($next_pai_join) {
  3616. //中拍创建订单
  3617. $data=array();
  3618. $data['pai_id']=intval($v['pai_id']);
  3619. $data['user_id']=intval($next_pai_join['user_id']);
  3620. $data['auth']=$auth;
  3621. $result=deal_pai_do_order($data);
  3622. if (count($result)>0) {
  3623. $pai_goods_info=$GLOBALS['db']->getRow("select * from ".DB_PREFIX."pai_goods where id=".intval($v['pai_id'])." ");
  3624. $video_info=$GLOBALS['db']->getRow("select * from ".DB_PREFIX."video where user_id=".intval($pai_goods_info['podcast_id'])." and live_in=1");
  3625. $user_list=$GLOBALS['db']->getAll("select user_id,pai_status,order_id,order_status,pai_diamonds,order_time from ".DB_PREFIX."pai_join where pai_id=".intval($v['pai_id'])." and pai_diamonds >0 ORDER BY pai_diamonds DESC limit 0,3");
  3626. //房间内推送
  3627. $ext = array();
  3628. $ext['type'] = 26;
  3629. $ext['room_id'] = intval($video_info['id']);
  3630. $ext['pai_id'] = $data['pai_id'];
  3631. $ext['post_id'] = intval($pai_goods_info['podcast_id']);
  3632. $ext['desc'] = '';
  3633. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/BaseRedisService.php');
  3634. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/UserFollwRedisService.php');
  3635. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/UserRedisService.php');
  3636. $user_redis = new UserRedisService();
  3637. $fields = array('head_image','user_level','v_type','v_icon','nick_name');
  3638. //-------------------------
  3639. $ext['buyer']=array();
  3640. foreach($user_list as $k1=>$v1){
  3641. $buyer_data=array();
  3642. if (intval($v1['user_id'])>0) {
  3643. $buyer_data=$user_redis->getRow_db(intval($v1['user_id']),$fields);
  3644. $buyer_data['user_id'] = intval($v1['user_id']);
  3645. $buyer_data['type']=intval($v1['pai_status']);
  3646. $buyer_data['head_image'] = get_spec_image($buyer_data['head_image']);
  3647. $buyer_data['nick_name'] = emoji_decode($buyer_data['nick_name']);
  3648. if ($buyer_data['type']==1) {
  3649. $buyer_data['left_time']=$v1['order_time']+MAX_PAI_PAY_TIME-NOW_TIME;
  3650. $order_sn=$GLOBALS['db']->getOne("select order_sn from ".DB_PREFIX."goods_order where id=".intval($v1['order_id'])." ");
  3651. //$buyer_data['pay_url']=SITE_DOMAIN.APP_ROOT.'/wap/index.php?ctl=pai_user&act=order&order_sn='.$order_sn;
  3652. $buyer_data['goods_name']=$pai_goods_info['name'];
  3653. $buyer_data['order_sn']=$order_sn;
  3654. if ($pai_goods_info['imgs']!='') {
  3655. $pai_goods_info['imgs']=json_decode($pai_goods_info['imgs']);
  3656. foreach($pai_goods_info['imgs'] as $k2=>$v2){
  3657. /*if ($auth!='') {
  3658. $buyer_data['goods_icon']=$auth.$v2;
  3659. }else{
  3660. $buyer_data['goods_icon']=get_domain().APP_ROOT.$v2;
  3661. }*/
  3662. $buyer_data['goods_icon']=get_spec_image($v2);
  3663. break;
  3664. }
  3665. }else{
  3666. $buyer_data['goods_icon']="";
  3667. }
  3668. //$ext['desc'] = '恭喜用户'.$buyer_data['nick_name'].'出价'.intval($v1['pai_diamonds']).'成功拍得'.$pai_goods_info['name'];
  3669. $ext['desc'] = '出价'.intval($v1['pai_diamonds']).'成功拍得'.$pai_goods_info['name'];
  3670. $ext['user'] = $buyer_data;
  3671. }else{
  3672. $buyer_data['left_time']=0;
  3673. }
  3674. $buyer_data['pai_diamonds']=intval($v1['pai_diamonds']);
  3675. }
  3676. $ext['buyer'][]=$buyer_data;
  3677. }
  3678. //-------------------------
  3679. #构造高级接口所需参数
  3680. $tim_data=array();
  3681. $tim_data['ext']=$ext;
  3682. $tim_data['podcast_id']=strim($pai_goods_info['podcast_id']);
  3683. $tim_data['group_id']=strim($video_info['group_id']);
  3684. get_tim_api($tim_data);
  3685. /*
  3686. $msg_content = array();
  3687. //创建array 所需元素
  3688. $msg_content_elem = array(
  3689. 'MsgType' => 'TIMCustomElem', //自定义类型
  3690. 'MsgContent' => array(
  3691. 'Data' => json_encode($ext),
  3692. 'Desc' => '',
  3693. )
  3694. );
  3695. //将创建的元素$msg_content_elem, 加入array $msg_content
  3696. array_push($msg_content, $msg_content_elem);
  3697. fanwe_require(APP_ROOT_PATH.'system/tim/TimApi.php');
  3698. $api = createTimAPI();
  3699. $ret = $api->group_send_group_msg2(intval($pai_goods_info['podcast_id']), intval($video_info['group_id']), $msg_content);
  3700. */
  3701. }
  3702. }else{
  3703. //流拍
  3704. $sql = "update ".DB_PREFIX."pai_goods set status = 2 ,order_status = 6 where id = ".intval($v['pai_id']);
  3705. $GLOBALS['db']->query($sql);
  3706. $pai_goods_info=$GLOBALS['db']->getRow("select * from ".DB_PREFIX."pai_goods where id=".intval($v['pai_id'])." ");
  3707. $sql = "update ".DB_PREFIX."video set pai_id = 0 where user_id=".intval($pai_goods_info['podcast_id'])." ";
  3708. $GLOBALS['db']->query($sql);
  3709. $sql = "update ".DB_PREFIX."goods set inventory=inventory+1 where id=".$info['goods_id']."";
  3710. $GLOBALS['db']->query($sql);//商品流拍,减去的库存增加回去
  3711. $video_info=$GLOBALS['db']->getRow("select * from ".DB_PREFIX."video where user_id=".intval($pai_goods_info['podcast_id'])." and live_in=1");
  3712. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/BaseRedisService.php');
  3713. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/VideoRedisService.php');
  3714. $video_redis = new VideoRedisService();
  3715. $video_data=array();
  3716. $video_data['pai_id']=0;
  3717. $re = $video_redis->update_db(intval($video_info['id']),$video_data);
  3718. //退回保证金
  3719. $pai_id=intval($v['pai_id']);
  3720. $time=NOW_TIME;
  3721. $user_list = $GLOBALS['db']->getAll("SELECT id,user_id,bz_diamonds,status,pai_status FROM ".DB_PREFIX."pai_join WHERE pai_id=".$pai_id);
  3722. $user_ids=array();
  3723. foreach ( $user_list as $k1 => $v1 )
  3724. {
  3725. $user_ids[]=$v1['user_id'];
  3726. //退还保证金 bz_diamonds 不为超时即退保证金
  3727. if(intval($v1['status'])==0 && intval($v1['pai_status'])==3 && $v1['user_id'] == $info['last_user_id']){
  3728. $sql = "update ".DB_PREFIX."pai_join set status = 2 where id=".intval($v1['id'])." ";
  3729. $GLOBALS['db']->query($sql);
  3730. }else{
  3731. fanwe_require(APP_ROOT_PATH.'/mapi/lib/redis/BaseRedisService.php');
  3732. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/UserRedisService.php');
  3733. $user_redis = new UserRedisService();
  3734. //$user_redis->lock_diamonds(intval($v1['user_id']),intval($v1['bz_diamonds']));
  3735. //$account_diamonds = $user_redis->getOne_db(intval($v1['user_id']),'use_diamonds');
  3736. $sql = "update ".DB_PREFIX."user set diamonds = diamonds + ".intval($v1['bz_diamonds'])." where id = ".intval($v1['user_id']);
  3737. $GLOBALS['db']->query($sql);
  3738. user_deal_to_reids(array(intval($v1['user_id'])));
  3739. $account_diamonds = $user_redis->getOne_db(intval($v1['user_id']), 'diamonds');
  3740. $sql = "update ".DB_PREFIX."pai_join set status = 1 where id=".intval($v1['id'])." ";
  3741. $GLOBALS['db']->query($sql);
  3742. //会员账户 钻石变更日志表
  3743. $diamonds_log_data = array(
  3744. 'pai_id' => $pai_id,
  3745. 'user_id' => intval($v1['user_id']),
  3746. 'diamonds'=>intval($v1['bz_diamonds']),//变更数额
  3747. 'account_diamonds'=>$account_diamonds,//账户余额
  3748. 'memo' =>$pai_goods_info['name'].'退还保证金',//备注
  3749. 'create_time' => $time,
  3750. 'create_date' => to_date($time,'Y-m-d H:i:s'),
  3751. 'create_time_ymd' => to_date($time,'Y-m-d'),
  3752. 'create_time_y' => to_date($time,'Y'),
  3753. 'create_time_m' => to_date($time,'m'),
  3754. 'create_time_d' => to_date($time,'d'),
  3755. 'type' =>1,//1 提交保证金
  3756. );
  3757. $GLOBALS['db']->autoExecute(DB_PREFIX."user_diamonds_log",$diamonds_log_data);
  3758. //写入用户日志
  3759. $data = array();
  3760. $data['diamonds'] = intval($v1['bz_diamonds']);
  3761. $param['type'] = 8;//类型 0表示充值 1表示提现 2赠送道具 3 兑换印票 4表示保证金操作 5表示竞拍模块消费 6表示竞拍模块收益 8竞拍记录
  3762. $log_msg = $pai_goods_info['name'].'退还保证金';//备注
  3763. account_log_com($data,intval($v1['user_id']),$log_msg,$param);
  3764. }
  3765. }
  3766. //流拍房间内推送
  3767. $ext = array();
  3768. $ext['type'] = 27;
  3769. $ext['room_id'] = intval($video_info['id']);
  3770. $ext['pai_id'] = intval($v['pai_id']);
  3771. $ext['post_id'] = intval($pai_goods_info['podcast_id']);
  3772. $ext['out_type'] = 1;
  3773. $ext['desc'] = "很遗憾,".$pai_goods_info['name']."竞拍流拍";
  3774. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/BaseRedisService.php');
  3775. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/UserFollwRedisService.php');
  3776. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/UserRedisService.php');
  3777. $user_redis = new UserRedisService();
  3778. $fields = array('head_image','user_level','v_type','v_icon','nick_name');
  3779. $ext['user'] = $user_redis->getRow_db(intval($info['podcast_id']),$fields);
  3780. $ext['user']['user_id'] = intval($info['podcast_id']);
  3781. $ext['user']['head_image'] = get_spec_image($ext['user']['head_image']);
  3782. $ext['user']['nick_name'] = emoji_decode($ext['user']['nick_name']);
  3783. //-------------------------
  3784. $user_list_out=$GLOBALS['db']->getAll("select user_id,pai_status,order_id,order_status,pai_diamonds,order_time from ".DB_PREFIX."pai_join where pai_id=".intval($v['pai_id'])." and pai_diamonds >0 ORDER BY pai_diamonds DESC limit 0,3");
  3785. $ext['buyer']=array();
  3786. foreach($user_list_out as $k1=>$v1){
  3787. $buyer_data=array();
  3788. if (intval($v1['user_id'])>0) {
  3789. $buyer_data=$user_redis->getRow_db(intval($v1['user_id']),$fields);
  3790. $buyer_data['user_id'] = intval($v1['user_id']);
  3791. $buyer_data['type']=intval($v1['pai_status']);
  3792. $buyer_data['head_image'] = get_spec_image($buyer_data['head_image']);
  3793. $buyer_data['nick_name'] = emoji_decode($buyer_data['nick_name']);
  3794. if ($buyer_data['type']==1) {
  3795. $buyer_data['left_time']=$v1['order_time']+MAX_PAI_PAY_TIME-NOW_TIME;
  3796. //$order_sn=$GLOBALS['db']->getOne("select order_sn from ".DB_PREFIX."goods_order where id=".intval($v1['order_id'])." ");
  3797. //$buyer_data['pay_url']=SITE_DOMAIN.APP_ROOT.'/wap/index.php?ctl=pai_user&act=order&order_sn='.$order_sn;
  3798. }else{
  3799. $buyer_data['left_time']=0;
  3800. }
  3801. $buyer_data['pai_diamonds']=intval($v1['pai_diamonds']);
  3802. }
  3803. $ext['buyer'][]=$buyer_data;
  3804. }
  3805. //-----------------------
  3806. #构造高级接口所需参数
  3807. $tim_data=array();
  3808. $tim_data['ext']=$ext;
  3809. $tim_data['podcast_id']=strim($pai_goods_info['podcast_id']);
  3810. $tim_data['group_id']=strim($video_info['group_id']);
  3811. get_tim_api($tim_data);
  3812. /*
  3813. $msg_content = array();
  3814. //创建array 所需元素
  3815. $msg_content_elem = array(
  3816. 'MsgType' => 'TIMCustomElem', //自定义类型
  3817. 'MsgContent' => array(
  3818. 'Data' => json_encode($ext),
  3819. 'Desc' => '',
  3820. )
  3821. );
  3822. //将创建的元素$msg_content_elem, 加入array $msg_content
  3823. array_push($msg_content, $msg_content_elem);
  3824. fanwe_require(APP_ROOT_PATH.'system/tim/TimApi.php');
  3825. $api = createTimAPI();
  3826. $ret = $api->group_send_group_msg2(intval($pai_goods_info['podcast_id']), intval($video_info['group_id']), $msg_content);
  3827. */
  3828. }
  3829. }
  3830. }
  3831. /*查看拍卖超时,并结束拍卖,进入支付,或者 流拍状态
  3832. * pai_goods 当status=0,create_time+pai_time+now_yanshi*pai_yanshi <now_time
  3833. * (1) last_user_id 为空,则表示无人竞拍,则修改状态 当status=2,同时推送消息 表示流拍
  3834. * (2)last_user_id 不为空 ,第一名 进行下单,更新 pai_join 中 pai_status=1 ,第二名和第三名 pai_status=2,同时推送消息 竞拍成功
  3835. */
  3836. function deal_pai_timeout(){
  3837. if(PAI_YANCHI_MODULE == 0){
  3838. $pai_list=$GLOBALS['db']->getAll("select * from ".DB_PREFIX."pai_goods where status=0 and is_delete=0 and create_time+pai_time*3600+now_yanshi*pai_yanshi*60-1-1 <".NOW_TIME);
  3839. }else{
  3840. $pai_list=$GLOBALS['db']->getAll("select * from ".DB_PREFIX."pai_goods where status=0 and is_delete=0 and end_time-1 <".NOW_TIME);
  3841. }
  3842. foreach($pai_list as $k=>$v){
  3843. $auth='';
  3844. if (isset($_REQUEST['auth'])) {
  3845. $auth=$_REQUEST['auth'];
  3846. }
  3847. //中拍
  3848. $data=array();
  3849. $data['pai_id']=intval($v['id']);
  3850. $data['user_id']=intval($v['last_user_id']);
  3851. $data['auth']=$auth;
  3852. if (intval($v['last_user_id'])>0) {
  3853. $sql = "update ".DB_PREFIX."pai_goods set status = 1 where id = ".intval($v['id'])." and status=0 ";
  3854. $GLOBALS['db']->query($sql);
  3855. $result=deal_pai_do_order($data);
  3856. if (count($result)>0) {
  3857. //更新排队状态
  3858. $user_list=$GLOBALS['db']->getAll("select user_id from ".DB_PREFIX."pai_join where pai_id=".intval($v['id'])." and pai_diamonds >0 ORDER BY pai_diamonds DESC limit 1,2");
  3859. $user_array=array();
  3860. foreach($user_list as $k2=>$v2){
  3861. $user_array[]=intval($v2['user_id']);
  3862. }
  3863. $sql = "update ".DB_PREFIX."pai_join set pai_status = 2 where pai_id= ".$data['pai_id']." and user_id in (".implode(",",$user_array).") ";
  3864. $GLOBALS['db']->query($sql);
  3865. //发送排队消息
  3866. if(count($user_array)>0){
  3867. $content="您参与的竞拍:‘".$v['name']."’ 正在结算排队中!";
  3868. FanweServiceCall("message","send",array("send_type"=>'tip_towait',"user_ids"=>$user_array,"content"=>$content));
  3869. }
  3870. $video_info=$GLOBALS['db']->getRow("select * from ".DB_PREFIX."video where user_id=".intval($v['podcast_id'])." and live_in=1");
  3871. //房间内推送
  3872. $ext = array();
  3873. $ext['type'] = 25;
  3874. $ext['room_id'] = intval($video_info['id']);
  3875. $ext['pai_id'] = $data['pai_id'];
  3876. $ext['post_id'] = intval($v['podcast_id']);
  3877. $ext['desc'] = '';
  3878. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/BaseRedisService.php');
  3879. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/UserFollwRedisService.php');
  3880. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/UserRedisService.php');
  3881. $user_redis = new UserRedisService();
  3882. $fields = array('head_image','user_level','v_type','v_icon','nick_name');
  3883. //-------------------------
  3884. $ext['buyer']=array();
  3885. $user_list_all=$GLOBALS['db']->getAll("select user_id,pai_status,order_id,order_status,pai_diamonds,order_time from ".DB_PREFIX."pai_join where pai_id=".intval($v['id'])." and pai_diamonds >0 ORDER BY pai_diamonds DESC limit 0,3");
  3886. foreach($user_list_all as $k1=>$v1){
  3887. $buyer_data=array();
  3888. if (intval($v1['user_id'])>0) {
  3889. $buyer_data=$user_redis->getRow_db(intval($v1['user_id']),$fields);
  3890. $buyer_data['user_id'] = intval($v1['user_id']);
  3891. $buyer_data['type']=intval($v1['pai_status']);
  3892. $buyer_data['head_image'] = get_spec_image($buyer_data['head_image']);
  3893. $buyer_data['nick_name'] = emoji_decode($buyer_data['nick_name']);
  3894. $buyer_data['user_name'] = emoji_decode($buyer_data['user_name']);
  3895. if ($buyer_data['type']==1) {
  3896. $buyer_data['left_time']=$v1['order_time']+MAX_PAI_PAY_TIME-NOW_TIME;
  3897. $order_sn=$GLOBALS['db']->getOne("select order_sn from ".DB_PREFIX."goods_order where id=".intval($v1['order_id'])." ");
  3898. //$buyer_data['pay_url']=SITE_DOMAIN.APP_ROOT.'/wap/index.php?ctl=pai_user&act=order&order_sn='.$order_sn;
  3899. $buyer_data['goods_name']=$v['name'];
  3900. $buyer_data['order_sn']=$order_sn;
  3901. if ($v['imgs']!='') {
  3902. $v['imgs']=json_decode($v['imgs']);
  3903. foreach($v['imgs'] as $k2=>$v2){
  3904. /*if ($auth!='') {
  3905. $buyer_data['goods_icon']=$auth.$v2;
  3906. }else{
  3907. $buyer_data['goods_icon']=get_domain().APP_ROOT.$v2;
  3908. }*/
  3909. $buyer_data['goods_icon']=get_spec_image($v2);
  3910. break;
  3911. }
  3912. }else{
  3913. $buyer_data['goods_icon']="";
  3914. }
  3915. //$ext['desc'] = '恭喜用户'.$buyer_data['nick_name'].'出价'.intval($v1['pai_diamonds']).'成功拍得'.$v['name'];
  3916. $ext['desc'] = '出价'.intval($v1['pai_diamonds']).'成功拍得'.$v['name'];
  3917. $ext['user'] = $buyer_data;
  3918. }else{
  3919. $buyer_data['left_time']=0;
  3920. }
  3921. $buyer_data['pai_diamonds']=intval($v1['pai_diamonds']);
  3922. }
  3923. $ext['buyer'][]=$buyer_data;
  3924. }
  3925. //-------------------------
  3926. #构造高级接口所需参数
  3927. $tim_data=array();
  3928. $tim_data['ext']=$ext;
  3929. $tim_data['podcast_id']=strim($v['podcast_id']);
  3930. $tim_data['group_id']=strim($video_info['group_id']);
  3931. get_tim_api($tim_data);
  3932. /*
  3933. $msg_content = array();
  3934. //创建array 所需元素
  3935. $msg_content_elem = array(
  3936. 'MsgType' => 'TIMCustomElem', //自定义类型
  3937. 'MsgContent' => array(
  3938. 'Data' => json_encode($ext),
  3939. 'Desc' => '',
  3940. )
  3941. );
  3942. //将创建的元素$msg_content_elem, 加入array $msg_content
  3943. array_push($msg_content, $msg_content_elem);
  3944. fanwe_require(APP_ROOT_PATH.'system/tim/TimApi.php');
  3945. $api = createTimAPI();
  3946. $ret = $api->group_send_group_msg2(intval($v['podcast_id']), intval($video_info['group_id']), $msg_content);
  3947. */
  3948. }
  3949. }else{
  3950. //流拍
  3951. $sql = "update ".DB_PREFIX."pai_goods set status = 2 where id = ".intval($v['id'])." and status=0 ";
  3952. $GLOBALS['db']->query($sql);
  3953. $sql = "update ".DB_PREFIX."video set pai_id = 0 where user_id=".intval($v['podcast_id'])." ";
  3954. $GLOBALS['db']->query($sql);
  3955. $pai_goods_info=$GLOBALS['db']->getRow("select * from ".DB_PREFIX."pai_goods where id=".intval($v['id'])." ");
  3956. $sql = "update ".DB_PREFIX."goods set inventory=inventory+1 where id=".$pai_goods_info['goods_id']."";
  3957. $GLOBALS['db']->query($sql);//流拍,减去的库存增加回去
  3958. //退回保证金
  3959. $pai_id=intval($v['id']);
  3960. $time=NOW_TIME;
  3961. $user_list = $GLOBALS['db']->getAll("SELECT id,user_id,bz_diamonds,status,pai_status FROM ".DB_PREFIX."pai_join WHERE pai_id=".$pai_id);
  3962. $user_ids=array();
  3963. foreach ( $user_list as $k1 => $v1 )
  3964. {
  3965. $user_ids[]=$v1['user_id'];
  3966. //退还保证金 bz_diamonds 不为超时即退保证金
  3967. if (intval($v1['status'])==0&&intval($v1['pai_status'])!=3) {
  3968. fanwe_require(APP_ROOT_PATH.'/mapi/lib/redis/BaseRedisService.php');
  3969. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/UserRedisService.php');
  3970. $user_redis = new UserRedisService();
  3971. $sql = "update ".DB_PREFIX."user set diamonds = diamonds + ".intval($v1['bz_diamonds'])." where id = ".intval($v1['user_id']);
  3972. $GLOBALS['db']->query($sql);
  3973. user_deal_to_reids(array(intval($v1['user_id'])));
  3974. $account_diamonds = $user_redis->getOne_db(intval($v1['user_id']), 'diamonds');
  3975. $sql = "update ".DB_PREFIX."pai_join set status = 1 where id=".intval($v1['id'])." ";
  3976. $GLOBALS['db']->query($sql);
  3977. //会员账户 钻石变更日志表
  3978. $diamonds_log_data = array(
  3979. 'pai_id' => $pai_id,
  3980. 'user_id' => intval($v1['user_id']),
  3981. 'diamonds'=>intval($v1['bz_diamonds']),//变更数额
  3982. 'account_diamonds'=>$account_diamonds,//账户余额
  3983. 'memo' =>$pai_goods_info['name'].'退还保证金',//备注
  3984. 'create_time' => $time,
  3985. 'create_date' => to_date($time,'Y-m-d H:i:s'),
  3986. 'create_time_ymd' => to_date($time,'Y-m-d'),
  3987. 'create_time_y' => to_date($time,'Y'),
  3988. 'create_time_m' => to_date($time,'m'),
  3989. 'create_time_d' => to_date($time,'d'),
  3990. 'type' =>1,//1 提交保证金
  3991. );
  3992. $GLOBALS['db']->autoExecute(DB_PREFIX."user_diamonds_log",$diamonds_log_data);
  3993. //写入用户日志
  3994. $data = array();
  3995. $data['diamonds'] = intval($v1['bz_diamonds']);
  3996. $param['type'] = 8;//类型 0表示充值 1表示提现 2赠送道具 3 兑换印票 4表示保证金操作 5表示竞拍模块消费 6表示竞拍模块收益 8竞拍记录
  3997. $log_msg = $pai_goods_info['name'].'退还保证金';//备注
  3998. account_log_com($data,intval($v1['user_id']),$log_msg,$param);
  3999. }else if(intval($v1['status'])==0&&intval($v1['pai_status'])==3){
  4000. $sql = "update ".DB_PREFIX."pai_join set status = 2 where id=".intval($v1['id'])." ";
  4001. $GLOBALS['db']->query($sql);
  4002. }
  4003. }
  4004. $video_info=$GLOBALS['db']->getRow("select * from ".DB_PREFIX."video where user_id=".intval($v['podcast_id'])." and live_in=1");
  4005. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/BaseRedisService.php');
  4006. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/VideoRedisService.php');
  4007. $video_redis = new VideoRedisService();
  4008. $video_data=array();
  4009. $video_data['pai_id']=0;
  4010. $re = $video_redis->update_db(intval($video_info['id']),$video_data);
  4011. //流拍房间内推送
  4012. $ext = array();
  4013. $ext['type'] = 27;
  4014. $ext['room_id'] = intval($video_info['id']);
  4015. $ext['pai_id'] = $data['pai_id'];
  4016. $ext['post_id'] = intval($v['podcast_id']);
  4017. $ext['out_type'] = 0;
  4018. $ext['desc'] = "很遗憾,".$v['name']."竞拍流拍";
  4019. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/BaseRedisService.php');
  4020. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/UserFollwRedisService.php');
  4021. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/UserRedisService.php');
  4022. $user_redis = new UserRedisService();
  4023. $fields = array('head_image','user_level','v_type','v_icon','nick_name');
  4024. $ext['user'] = $user_redis->getRow_db(intval($v['podcast_id']),$fields);
  4025. $ext['user']['user_id'] = intval($v['podcast_id']);
  4026. $ext['user']['head_image'] = get_spec_image($ext['user']['head_image']);
  4027. $ext['user']['nick_name'] = emoji_decode($ext['user']['nick_name']);
  4028. #构造高级接口所需参数
  4029. $tim_data=array();
  4030. $tim_data['ext']=$ext;
  4031. $tim_data['podcast_id']=strim($v['podcast_id']);
  4032. $tim_data['group_id']=strim($video_info['group_id']);
  4033. get_tim_api($tim_data);
  4034. /*
  4035. $msg_content = array();
  4036. //创建array 所需元素
  4037. $msg_content_elem = array(
  4038. 'MsgType' => 'TIMCustomElem', //自定义类型
  4039. 'MsgContent' => array(
  4040. 'Data' => json_encode($ext),
  4041. 'Desc' => '',
  4042. )
  4043. );
  4044. //将创建的元素$msg_content_elem, 加入array $msg_content
  4045. array_push($msg_content, $msg_content_elem);
  4046. fanwe_require(APP_ROOT_PATH.'system/tim/TimApi.php');
  4047. $api = createTimAPI();
  4048. $ret = $api->group_send_group_msg2(intval($v['podcast_id']), intval($video_info['group_id']), $msg_content);
  4049. */
  4050. }
  4051. }
  4052. }
  4053. /*
  4054. * 拍卖订单 下单
  4055. * $data = array("pai_id"=>$pai_id,"user_id"=>$user_id);
  4056. */
  4057. function deal_pai_do_order($data){
  4058. return FanweServiceCall("pai_podcast","create_order",$data);
  4059. }
  4060. /*
  4061. * 拍卖订单 状态修改(暂行)
  4062. * 查询所有status位2.3的订单
  4063. * 2超时,未发货 超过约会时间,进入5,退款流程
  4064. * 3超时,未收货 超过时间7天自动更新确认
  4065. *
  4066. *
  4067. */
  4068. function deal_pai_order_status(){
  4069. $order_list=$GLOBALS['db']->getAll("select * from ".DB_PREFIX."goods_order where order_source='local' and order_type='pai' and order_status=3 and refund_platform=0 and order_status_time-1+".MAX_PODCAST_CONFIRM_TIME." <".NOW_TIME);
  4070. if ($order_list) {
  4071. //$sql = "UPDATE ".DB_PREFIX."goods_order SET order_status=7 ,order_status_time=".NOW_TIME." WHERE order_source='local' and order_type='pai' and order_status=3 and order_status_time+".MAX_USER_CONFIRM_TIME." <".NOW_TIME;
  4072. //$GLOBALS['db']->query($sql);
  4073. foreach($order_list as $k=>$v){
  4074. $sql = "UPDATE ".DB_PREFIX."goods_order SET order_status=7 ,order_status_time=".NOW_TIME." WHERE id=".intval($v['id']);
  4075. $GLOBALS['db']->query($sql);
  4076. $to_podcast_id=intval($v['podcast_id']);
  4077. $podcast_ticket=intval($v['podcast_ticket']);
  4078. $pai_id=intval($v['pai_id']);
  4079. $user_id=intval($v['viewer_id']);
  4080. $sql = "update ".DB_PREFIX."pai_goods set order_status = 7 where id=".$pai_id." ";
  4081. $GLOBALS['db']->query($sql);
  4082. $sql = "update ".DB_PREFIX."pai_join set order_status = 7 where user_id=".$user_id." and pai_id=".$pai_id." ";
  4083. $GLOBALS['db']->query($sql);
  4084. $pai_info=$GLOBALS['db']->getRow("select * from ".DB_PREFIX."pai_goods where id=".$pai_id);
  4085. //主播获得竞拍收益
  4086. fanwe_require(APP_ROOT_PATH.'/mapi/lib/redis/BaseRedisService.php');
  4087. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/UserRedisService.php');
  4088. $user_redis = new UserRedisService();
  4089. $sql = "update ".DB_PREFIX."user set ticket = ticket + ".$podcast_ticket." where id = ".$to_podcast_id;
  4090. $GLOBALS['db']->query($sql);
  4091. user_deal_to_reids(array($to_podcast_id));
  4092. //写入用户日志
  4093. $data = array();
  4094. $data['ticket'] = $podcast_ticket;
  4095. $param['type'] = 8;//类型 0表示充值 1表示提现 2赠送道具 3 兑换印票 4表示保证金操作 5表示竞拍模块消费 6表示竞拍模块收益 8竞拍记录
  4096. $log_msg = $pai_info['name'].'竞拍收益';//备注
  4097. account_log_com($data,intval($to_podcast_id),$log_msg,$param);
  4098. //分销功能 计算抽成
  4099. if(defined('OPEN_DISTRIBUTION')&&OPEN_DISTRIBUTION==1){
  4100. $total_ticket=$podcast_ticket;
  4101. $m_config = load_auto_cache("m_config");//初始化手机端配置
  4102. $table = DB_PREFIX.'distribution_log';
  4103. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/UserRedisService.php');
  4104. $user_redis = new UserRedisService();
  4105. $to_user_id = $user_redis->getOne_db($user_id,'p_user_id');//用户总的:印票数
  4106. $ticket = 0;
  4107. $result = 0;
  4108. if(intval($to_user_id)>0&&intval($m_config['distribution'])==1&&$user_id>0){
  4109. $ticket = round($m_config['distribution_rate']*0.01*$total_ticket,1);
  4110. $sql = "select id from ".$table." where to_user_id = ".$to_user_id." and from_user_id = ".$user_id;
  4111. $distribution = $GLOBALS['db']->getOne($sql);
  4112. $distribution_id = $distribution['id'];
  4113. if(intval($distribution_id)>0){
  4114. $sql = "update ".$table." set ticket = ticket + ".$ticket." where id = ".$distribution_id;
  4115. $GLOBALS['db']->query($sql);
  4116. if($GLOBALS['db']->affected_rows()) $result = 1;
  4117. }else{
  4118. //插入:分销日志
  4119. $video_prop = array();
  4120. $video_prop['from_user_id'] = $user_id;
  4121. $video_prop['to_user_id'] = $to_user_id;
  4122. $video_prop['create_date'] = "'".to_date(NOW_TIME,'Y-m-d')."'";
  4123. $video_prop['ticket'] = $ticket;
  4124. $video_prop['create_time'] = NOW_TIME;
  4125. $video_prop['create_ym'] = to_date($video_prop['create_time'],'Ym');
  4126. $video_prop['create_d'] = to_date($video_prop['create_time'],'d');
  4127. $video_prop['create_w'] = to_date($video_prop['create_time'],'W');
  4128. //将日志写入mysql表中
  4129. $field_arr = array('from_user_id', 'to_user_id','create_date','ticket', 'create_time','create_ym','create_d','create_w');
  4130. $fields = implode(",",$field_arr);
  4131. $valus = implode(",",$video_prop);
  4132. $sql = "insert into ".$table."(".$fields.") VALUES (".$valus.")";
  4133. $GLOBALS['db']->query($sql);
  4134. $result = $GLOBALS['db']->insert_id();
  4135. }
  4136. if(intval($result)>0){
  4137. $sql = "update ".DB_PREFIX."user set ticket = ticket + ".$ticket." where id = ".$to_user_id;
  4138. $GLOBALS['db']->query($sql);
  4139. }
  4140. }
  4141. }
  4142. $user_ids=array();
  4143. $user_ids[]=$to_podcast_id;
  4144. $user_ids[]=intval($v['viewer_id']);
  4145. $info = $GLOBALS['db']->getRow("SELECT pg.* FROM ".DB_PREFIX."pai_goods as pg WHERE pg.id=".$pai_id);
  4146. $content="竞拍:‘".$info['name']."’ 已自动确认完成!";
  4147. $rs=FanweServiceCall("message","send",array("send_type"=>'viewer_to_over_tryst',"user_ids"=>$user_ids,"content"=>$content));
  4148. }
  4149. }
  4150. $order_list_2=$GLOBALS['db']->getAll("select * from ".DB_PREFIX."goods_order where order_source='local' and order_type='pai' and order_status=2 and refund_platform=0 and order_status_time-1+".MAX_USER_CONFIRM_TIME." <".NOW_TIME);
  4151. if ($order_list_2) {
  4152. //未确认自动退款
  4153. /*
  4154. foreach($order_list_2 as $k=>$v){
  4155. $sql = "UPDATE ".DB_PREFIX."goods_order SET order_status=5 ,order_status_time=".NOW_TIME." ,refund_buyer_status=1 WHERE id=".intval($v['id']);
  4156. $GLOBALS['db']->query($sql);
  4157. $pai_id=intval($v['pai_id']);
  4158. $user_id=intval($v['viewer_id']);
  4159. $sql = "update ".DB_PREFIX."pai_goods set order_status = 5 where id=".$pai_id." ";
  4160. $GLOBALS['db']->query($sql);
  4161. $sql = "update ".DB_PREFIX."pai_join set order_status = 5 where user_id=".$user_id." and pai_id=".$pai_id." ";
  4162. $GLOBALS['db']->query($sql);
  4163. $user_ids=array();
  4164. $user_ids[]=intval($v['podcast_id']);
  4165. $user_ids[]=intval($v['viewer_id']);
  4166. $info = $GLOBALS['db']->getRow("SELECT pg.* FROM ".DB_PREFIX."pai_goods as pg WHERE pg.id=".$pai_id);
  4167. $content="竞拍:‘".$info['name']."’ 进入退款流程!";
  4168. $rs=FanweServiceCall("message","send",array("send_type"=>'to_refund',"user_ids"=>$user_ids,"content"=>$content));
  4169. }
  4170. */
  4171. //未确认自动确认
  4172. foreach($order_list_2 as $k=>$v){
  4173. $sql = "UPDATE ".DB_PREFIX."goods_order SET order_status=3 ,order_status_time=".NOW_TIME." ,refund_buyer_status=1 WHERE id=".intval($v['id']);
  4174. $GLOBALS['db']->query($sql);
  4175. $pai_id=intval($v['pai_id']);
  4176. $user_id=intval($v['viewer_id']);
  4177. $sql = "update ".DB_PREFIX."pai_goods set order_status = 3 where id=".$pai_id." ";
  4178. $GLOBALS['db']->query($sql);
  4179. $sql = "update ".DB_PREFIX."pai_join set order_status = 3 where user_id=".$user_id." and pai_id=".$pai_id." ";
  4180. $GLOBALS['db']->query($sql);
  4181. $user_ids=array();
  4182. $user_ids[]=intval($v['viewer_id']);
  4183. $info = $GLOBALS['db']->getRow("SELECT pg.* FROM ".DB_PREFIX."pai_goods as pg WHERE pg.id=".$pai_id);
  4184. $content="主播‘".$info['podcast_name']."’已确认完成‘".$info['name']."’";
  4185. $rs=FanweServiceCall("message","send",array("send_type"=>'podcast_to_over_tryst',"user_ids"=>$user_ids,"content"=>$content));
  4186. }
  4187. }
  4188. $order_list_3=$GLOBALS['db']->getAll("select * from ".DB_PREFIX."goods_order where order_source='local' and order_type='shop' and order_status=1 and refund_platform=0 and create_time-1+".MAX_PAI_PAY_TIME." <".NOW_TIME);
  4189. if($order_list_3){
  4190. foreach($order_list_3 as $key =>$value){
  4191. if($value['is_p'] == 0){
  4192. $sql = "UPDATE ".DB_PREFIX."goods SET inventory=inventory+".intval($value['number'])." WHERE id=".intval($value['goods_id']);
  4193. $GLOBALS['db']->query($sql);//增加库存
  4194. }
  4195. $sql = "UPDATE ".DB_PREFIX."goods_order SET order_status=6 ,order_status_time=".NOW_TIME." WHERE id=".intval($value['id']);
  4196. $GLOBALS['db']->query($sql);
  4197. $user_ids=array();
  4198. $user_ids[]=intval($value['viewer_id']);
  4199. $info = $GLOBALS['db']->getRow("SELECT * FROM ".DB_PREFIX."goods WHERE id=".intval($value['goods_id']));
  4200. $content="您购买的商品".$info['name']."超时未付款,已自动取消订单.";
  4201. $rs=FanweServiceCall("message","send",array("send_type"=>'podcast_to_over_tryst',"user_ids"=>$user_ids,"content"=>$content));
  4202. }
  4203. }
  4204. }
  4205. //-------------家族收益处理-------------
  4206. /**
  4207. * @ param int $user_id 主播ID
  4208. * @ param int $family_id 家族ID
  4209. * @ param float $family_income 家族收益
  4210. * @ param int $video_id 直播ID
  4211. */
  4212. function family_receipts($user_id,$family_id,$family_income,$video_id=0){
  4213. $sql = "select f.id as family_id,fj.id as join_id,f.status as family_status,f.user_id from ".DB_PREFIX."family_join as fj left join ".DB_PREFIX."family as f on f.id = fj.family_id where fj.status =1 and fj.user_id = ".$user_id." and fj.family_id =".$family_id;
  4214. $family_info = $GLOBALS['db']->getRow($sql);
  4215. if($family_info['join_id']>0&&$family_info['family_status']==1&&$family_info['family_id']>0){
  4216. if($family_income) {
  4217. //增加:家族收益
  4218. $sql = "update " . DB_PREFIX . "family set contribution = contribution + " . $family_income . " where id = " . $family_id;
  4219. $GLOBALS['db']->query($sql);
  4220. //将家族收益汇入家族长
  4221. $sql = "update " . DB_PREFIX . "user set ticket = ticket + " . $family_income . " where id = " . $family_info['user_id'];
  4222. $status = $GLOBALS['db']->query($sql);
  4223. user_deal_to_reids(array($family_info['user_id']));
  4224. $m_config = load_auto_cache("m_config");//初始化手机端配置
  4225. if(intval($m_config['family_profit_platform'])==0){
  4226. $sql = "update " . DB_PREFIX . "user set refund_ticket = refund_ticket + " . $family_income . " where id = " . $user_id . " and ticket > refund_ticket + " . $family_income;
  4227. $GLOBALS['db']->query($sql);
  4228. user_deal_to_reids(array($user_id));
  4229. if($status) {
  4230. //写入用户日志
  4231. $data = array();
  4232. $data['ticket'] = intval($family_income);
  4233. $data['video_id'] = intval($video_id) > 0 ? $video_id : 0;
  4234. $param['type'] = 4;//类型 0表示充值 1表示提现 2赠送道具 3 兑换印票 4 扣除家族收益
  4235. $log_msg = '扣除家族收益' . $data['ticket'] . '印票';
  4236. account_log_com($data, $user_id, $log_msg, $param);
  4237. }
  4238. }
  4239. if($status){
  4240. $log_msg = '收取家族收益'.$data['ticket'].'印票';
  4241. account_log_com($data,$family_info['user_id'],$log_msg,$param);
  4242. }
  4243. return true;
  4244. }
  4245. return false;
  4246. }else{
  4247. return false;
  4248. }
  4249. }
  4250. //-------------商城相关-------------
  4251. //第三方商城接口
  4252. function third_interface($user_id,$url,$args=array()){
  4253. fanwe_require(APP_ROOT_PATH.'system/saas/SAASAPIClient.php');
  4254. $appid = FANWE_APP_ID_YM;
  4255. $appsecret = FANWE_AES_KEY_YM;
  4256. $client = new SAASAPIClient($appid, $appsecret);
  4257. $user_info = $GLOBALS['db']->getRow("SELECT id,mobile,apns_code,device_type FROM " . DB_PREFIX . "user WHERE id=".$user_id);
  4258. // 设置头部参数
  4259. $head_args = array();
  4260. $head_args['userId']=$user_info['id'];
  4261. $head_args['mobile']=$user_info['mobile'];
  4262. /*$client_args = array();
  4263. $client_args['ios_uuid']='';
  4264. $client_args['android_imei']='';
  4265. if ($user_info['device_type']==1) {
  4266. $client_args['android_imei']=$user_info['apns_code'];
  4267. }elseif ($user_info['device_type']==2) {
  4268. $client_args['ios_uuid']=$user_info['apns_code'];
  4269. }
  4270. $client_args['app_terminal']=$user_info['device_type'];
  4271. $client_args['app_channel']='';
  4272. $head_args['client']=$client_args;*/
  4273. // 设置请求参数(根据不同业务需要设置)
  4274. $args =array_merge($head_args,$args);
  4275. $ret = $client->invoke($url, $args);
  4276. return $ret;
  4277. }
  4278. //o2o商城
  4279. function third_o2o_mall($url,$args=array()){
  4280. fanwe_require(APP_ROOT_PATH.'system/saas/SAASAPIClient.php');
  4281. $appid = FANWE_APP_ID_YM;
  4282. $appsecret = FANWE_AES_KEY_YM;
  4283. $client = new SAASAPIClient($appid, $appsecret);
  4284. $ret = $client->invoke($url,$args);
  4285. return $ret;
  4286. }
  4287. //第三方商城接口----竞拍商品数量
  4288. function good_number($user_id)
  4289. {
  4290. $ret=third_interface($user_id,'http://gw1.yimile.cc/V1/Commodity.json?action=GetUserDistributionCommodityQuantity');
  4291. $data=array();
  4292. if($ret['code'] == 0){
  4293. $data=$ret['data'];
  4294. return $data['commodityQuantity'];
  4295. }else{
  4296. return 0;
  4297. }
  4298. }
  4299. //h5链接
  4300. function go_h5($user_id,$url,$args=array(),$type=0)
  4301. {
  4302. $user_info = $GLOBALS['db']->getRow("SELECT id,mobile,apns_code,device_type FROM " . DB_PREFIX . "user WHERE id=".$user_id);
  4303. // 设置头部参数
  4304. $head_args = array();
  4305. $head_args['userId']=$user_info['id'];
  4306. $head_args['mobile']=$user_info['mobile'];
  4307. // 设置请求参数(根据不同业务需要设置)
  4308. $args =array_merge($head_args,$args);
  4309. fanwe_require(APP_ROOT_PATH.'system/saas/SAASAPIClient.php');
  4310. $appid = FANWE_APP_ID_YM;
  4311. $appsecret = FANWE_AES_KEY_YM;
  4312. $client = new SAASAPIClient($appid, $appsecret);
  4313. if($type == 0){
  4314. $url = $url.'?_saas_params='.base64_encode(json_encode($client->makeRequestParameters($args)));
  4315. }else{
  4316. $url = $url.'&_saas_params='.base64_encode(json_encode($client->makeRequestParameters($args)));
  4317. }
  4318. return $url;
  4319. }
  4320. //第三方商城--竟拍管理订单详情接口
  4321. function auction_order_detail($order_sn){
  4322. $root =array();
  4323. $user_id = intval($GLOBALS['user_info']['id']);
  4324. if ($user_id == 0) {
  4325. $root['status'] = 10007;
  4326. $root['error'] = "请先登录";
  4327. api_ajax_return($root);
  4328. }
  4329. $head_args['orderNo']=$order_sn;
  4330. $ret=third_interface($user_id,'http://gw1.yimile.cc/V1/Order.json?action=AuctionOrderDetail',$head_args);
  4331. if($ret['code'] == 0){
  4332. $root['status']=1;
  4333. if($ret['data']['orderInfo']['consignDate'] != ''){
  4334. $root['time'] = $ret['data']['orderInfo']['consignDate'];
  4335. }else{
  4336. $root['time'] = 0;
  4337. }
  4338. $express = array();
  4339. if($ret['data']['express'] != ''){
  4340. $express['express_no'] = $ret['data']['express']['expressNo'];
  4341. $express['express_detail'] = $ret['data']['express']['expressDetail'];
  4342. $express['express_time'] = $ret['data']['express']['expressTime'];
  4343. }
  4344. $root['express'] = $express;
  4345. $shopinfo = array();
  4346. if($ret['data']['shopInfo'] != ''){
  4347. $shopinfo['shop_id'] = $ret['data']['shopInfo']['shopId'];
  4348. $shopinfo['shop_name'] = $ret['data']['shopInfo']['shopName'];
  4349. $shopinfo['shop_qq'] = $ret['data']['shopInfo']['shopQQ'];
  4350. }
  4351. $root['shopinfo'] = $shopinfo;
  4352. }else{
  4353. $root['error']="获取失败";
  4354. }
  4355. return $root;
  4356. }
  4357. //第三方商城----竟拍保证金获取用户地址
  4358. function get_user_addressdetail($user_id){
  4359. // 调用服务
  4360. $ret=third_interface($user_id,'http://gw1.yimile.cc/V1/User.json?action=GetUserAddressDetail');
  4361. $taxe =array();
  4362. if($ret['code'] == 0){
  4363. $taxe['id'] = $ret['data']['userAddressId'];
  4364. $taxe['user_id'] = $user_id;
  4365. $taxe['consignee'] = $ret['data']['consignee'];
  4366. $taxe['consignee_mobile'] = $ret['data']['mobile'];
  4367. if($ret['data']['regionAddress'] != ''){
  4368. $sheng = explode("省",$ret['data']['regionAddress']);
  4369. if($sheng[1] == ''){
  4370. $shi = explode("市",$sheng[0]);
  4371. $qu = explode("区",$shi[1]);
  4372. }else{
  4373. $shi = explode("市",$sheng[1]);
  4374. $qu = explode("区",$shi[1]);
  4375. }
  4376. if($sheng[1] == ''){
  4377. $taxe['consignee_district'] = array('province'=>'','city'=>$shi[0].'市','area'=>$qu[0].'区');
  4378. }else{
  4379. $taxe['consignee_district'] = array('province'=>$sheng[0].'省','city'=>$shi[0].'市','area'=>$qu[0].'区');
  4380. }
  4381. }else{
  4382. $taxe['consignee_district'] = array('province'=>'','city'=>'','area'=>'');
  4383. }
  4384. $taxe['consignee_address'] = $ret['data']['address'];
  4385. $taxe['is_default'] = 0;
  4386. $taxe['create_time'] = 0;
  4387. }
  4388. return $taxe;
  4389. }
  4390. //第三方商城--竟拍订单提交
  4391. function create_auction_order($user_id,$goods_id,$nick_name,$zbuser_id,$zbmobile){
  4392. $root =array();
  4393. $head_args['commodityId'] = $goods_id;
  4394. $head_args['nickName'] = $nick_name;
  4395. $head_args['zbUserId'] = $zbuser_id;
  4396. $head_args['zbMobile'] = $zbmobile;
  4397. $ret=third_interface($user_id,'http://gw1.yimile.cc/V1/Order.json?action=CreateAuctionOrder',$head_args);
  4398. if($ret['code'] == 0){
  4399. $root['status']=1;
  4400. $root['orderNo'] = $ret['data']['orderNo'];
  4401. $root['totalPayPrice'] = $ret['data']['totalPayPrice'];
  4402. }else{
  4403. $root['error']="获取失败";
  4404. }
  4405. return $root;
  4406. }
  4407. function family_receipts1($video_id,$user_id,$video){
  4408. $video_id = intval($video_id);
  4409. $user_id = intval($user_id);
  4410. if($video_id==0||$user_id==0){
  4411. return ;
  4412. }
  4413. $family_id = $GLOBALS['db']->getOne("select family_id from ".DB_PREFIX."user where id = ".$user_id, true, true);
  4414. if($family_id > 0)
  4415. {
  4416. $m_config = load_auto_cache("m_config");//初始化手机端配置
  4417. $family_income = 0;
  4418. //判断是否扣除过
  4419. $user_log_id = $GLOBALS['db']->getOne("select id from ".DB_PREFIX."user_log where user_id = ".$user_id." and video_id=".intval($video_id));
  4420. if($m_config['profit_ratio']>0&&intval($user_log_id)==0){
  4421. $family_income = intval(intval($video['vote_number'])*0.01*$m_config['profit_ratio']);
  4422. $result = family_receipts($user_id,$family_id,$family_income,$video_id);
  4423. if($result){
  4424. $video['vote_number'] = $video['vote_number']-$family_income;
  4425. }
  4426. }
  4427. $family_score = $family_income;
  4428. //合并贡献收益 判断,用户当前等级积分
  4429. $cte = floatval($m_config['contribution_to_experience']);
  4430. if ($cte > 0){
  4431. $family_score += $family_income * $cte;
  4432. }
  4433. $video_time = (NOW_TIME - $video["begin_time"]);
  4434. //合并直播时长 判断,用户当前等级积分
  4435. $vte = floatval($m_config['videotime_to_experience']);
  4436. if ($vte > 0){
  4437. $family_score += $video_time * $vte;
  4438. }
  4439. $sql = "update ".DB_PREFIX."family set video_time = video_time + ".$video_time.",score = score + ".$family_score." where status=1 and id = " . $family_id;
  4440. $GLOBALS['db']->query($sql);
  4441. $family_info = $GLOBALS['db']->getRow("SELECT id as family_id,family_level,video_time,score FROM " . DB_PREFIX . "family WHERE id=" . $family_id . " and status=1", true, true);
  4442. family_level_syn($family_info);
  4443. }
  4444. }
  4445. //-------------公会无抽成模式---------------
  4446. /**
  4447. * @param $video 直播结束相关信息
  4448. * @return bool
  4449. */
  4450. function society_receipts($video){
  4451. if (intval($video['vote_number']) <= 0){
  4452. return false;
  4453. }
  4454. //公会的收益
  4455. $society_income = intval($video['vote_number']);
  4456. $user_info = $GLOBALS['db']->getRow("select society_id,society_settlement_type,society_chieftain from ".DB_PREFIX."user where id=".$video['user_id']);
  4457. $society_info = $GLOBALS['db']->getRow("select user_id,status from ".DB_PREFIX."society where id=".$user_info['society_id']);
  4458. //判断是否扣除过
  4459. $user_log_id = $GLOBALS['db']->getOne("select id from ".DB_PREFIX."user_log where type=10 and user_id = ".$video['user_id']." and video_id=".intval($video['id']));
  4460. if ($user_info['society_id'] > 0 && $society_info['status'] == 1 && intval($user_log_id) == 0 ){
  4461. //主播的收益加到公会中
  4462. $pInTrans = $GLOBALS['db']->StartTrans();
  4463. try
  4464. {
  4465. //收益添加到公会收益中
  4466. $GLOBALS['db']->query("update ".DB_PREFIX."society set chairman_earnings=chairman_earnings+".$society_income." where id=".$user_info['society_id']);
  4467. if($user_info['society_chieftain'] == 0){//排除会长
  4468. //将用户上交的公会的印票计入已提现
  4469. $sql = "update ".DB_PREFIX."user set refund_ticket = refund_ticket + ".$society_income.",society_ticket=society_ticket+".$society_income." where id = ".$video['user_id']." and ticket >=" .$society_income;
  4470. $status = $GLOBALS['db']->query($sql);
  4471. user_deal_to_reids(array($video['user_id']));
  4472. }else{
  4473. $status = true;
  4474. }
  4475. if ($status){
  4476. if($user_info['society_chieftain'] == 0){//排除会长
  4477. //将收益汇入公会长
  4478. $sql_chieftain = "update ".DB_PREFIX."user set ticket = ticket + ".$society_income." where id = ".$society_info['user_id'];
  4479. $GLOBALS['db']->query($sql_chieftain);
  4480. user_deal_to_reids(array($society_info['user_id']));
  4481. //写入会长日志
  4482. earnings_log($society_income, $user_info['society_id'], $video['user_id'], 10, '获取收益:公会成员'.$video['user_id'].'贡献'.$society_income.'印票', $society_info['user_id'],$video['id']);
  4483. }
  4484. if($user_info['society_chieftain']){
  4485. $contribution_id = $society_info['user_id'];
  4486. }else{
  4487. $contribution_id = 0;
  4488. }
  4489. //写入用户日志
  4490. earnings_log($society_income, $user_info['society_id'], $contribution_id, 10, '直播获取收益'.$society_income.'印票', $video['user_id'],$video['id']);
  4491. //公会等级积分的写入
  4492. society_level_syn($society_income, $video["begin_time"], $user_info['society_id']);
  4493. $m_config = load_auto_cache("m_config");//初始化手机端配置
  4494. //记录到公会主播收益表
  4495. $society_data = array();
  4496. $society_earning_id = $GLOBALS['db']->getOne('select id from '.DB_PREFIX."society_earning where video_id=".$video['id']);//是否已经记录过
  4497. if (!$society_earning_id && $user_info['society_id']>0){//收益还未记录且主播是公会成员
  4498. $society_data['video_id'] = $video['id'];
  4499. $society_data['user_id'] = $video['user_id'];
  4500. $society_data['vote_number'] = $video['vote_number'];
  4501. $society_data['begin_time'] = $video['begin_time'];
  4502. $society_data['end_time'] = $video['end_time'] ? $video['end_time'] : NOW_TIME;
  4503. $society_data['timelen'] = $society_data['end_time'] - $society_data['begin_time'];
  4504. $society_data['society_id'] = $user_info['society_id'];
  4505. $society_data['end_date'] = to_date($society_data['end_time'],'Y-m-d');
  4506. $society_data['end_Y'] = to_date($society_data['end_time'],'Y');
  4507. $society_data['end_m'] = to_date($society_data['end_time'],'m');
  4508. $society_data['end_d'] = to_date($society_data['end_time'],'d');
  4509. $society_data['end_w'] = to_date($society_data['end_time'],'W');
  4510. $society_data['society_settlement_type'] = $m_config['society_pattern'];
  4511. $society_data['society_number'] = $society_income;
  4512. $GLOBALS['db']->autoExecute(DB_PREFIX . "society_earning", $society_data);
  4513. }
  4514. }
  4515. //提交事务
  4516. $GLOBALS['db']->Commit($pInTrans);
  4517. }catch(Exception $e){
  4518. //异常回滚
  4519. $GLOBALS['db']->Rollback($pInTrans);
  4520. //写入用户日志
  4521. earnings_log($society_income, $user_info['society_id'], $contribution_id, 10, '直播获取收益'.$society_income.'印票,失败', $video['user_id'],$video['id']);
  4522. //写入会长日志
  4523. earnings_log($society_income, $user_info['society_id'], $video['user_id'], 10, '获取收益:公会成员'.$video['user_id'].'贡献'.$society_income.'印票,失败', $society_info['user_id'],$video['id']);
  4524. }
  4525. //-----事务结束-----
  4526. }
  4527. return;
  4528. }
  4529. //-------------平台收益,针对无公会人员-------------
  4530. /**
  4531. * @ param int $user_id 主播ID
  4532. * @ param float $m_config 配置信息
  4533. * @ param int $video 直播信息
  4534. * @ param int $video_id 直播ID
  4535. */
  4536. function platform_receipts($user_id,$m_config,$video,$video_id=0){
  4537. $society_income = 0;
  4538. $user_log_id = $GLOBALS['db']->getOne("select id from ".DB_PREFIX."user_log where type<>7 and user_id = ".$user_id." and video_id=".intval($video_id));
  4539. if($m_config['society_platform_earnings']>=0 && intval($user_log_id)==0 && $m_config['society_platform_earnings']<100 && $video['vote_number']>0){
  4540. //写入用户日志
  4541. earnings_log($video['vote_number'], 0, 0, 11, '直播获取收益' . intval($video['vote_number']) . '印票', $user_id,$video_id);
  4542. if($m_config['society_platform_earnings']==0){//平台不抽成
  4543. return true;
  4544. }
  4545. $society_income = intval(intval($video['vote_number'])*0.01*$m_config['society_platform_earnings']);
  4546. //增加收益更新到用户上
  4547. //$sql = "update " . DB_PREFIX . "user set ticket = ticket + ".$video['vote_number'].",refund_ticket = refund_ticket + " . $society_income . " where id = " .$user_id. " and ticket > refund_ticket + " . $society_income;
  4548. $sql = "update " . DB_PREFIX . "user set refund_ticket = refund_ticket + " . $society_income . " where id = " .$user_id. " and ticket > refund_ticket + " . $society_income;
  4549. $status = $GLOBALS['db']->query($sql);
  4550. user_deal_to_reids(array($user_id));
  4551. if($status) {
  4552. //写入用户日志
  4553. earnings_log($society_income, 0, 0, 11, '扣除平台收益' . $society_income . '印票', $user_id);
  4554. return true;
  4555. }else{
  4556. return false;
  4557. }
  4558. }
  4559. }
  4560. //-------------公会有抽成模式,会长收益-------------
  4561. /**
  4562. * @ param int $user_id 主播ID
  4563. * @ param int $society_id 公会ID
  4564. * @ param float $society_income 直播结束所得收益
  4565. * @ param int $video_id 直播ID
  4566. */
  4567. function society_receipts1($user_id,$society_id,$society_income,$vote_number,$video_id=0){
  4568. $sql = "select s.id as society_id,sa.id as apply_id,s.status as society_status,s.user_id from ".DB_PREFIX."society_apply as sa left join ".DB_PREFIX."society as s on s.id = sa.society_id where sa.status in(1,3) and sa.user_id = ".$user_id." and sa.society_id =".$society_id;
  4569. $society_info = $GLOBALS['db']->getRow($sql);
  4570. $society_chieftain = $GLOBALS['db']->getOne("select society_chieftain from ".DB_PREFIX."user where id=".$user_id);
  4571. if($society_info['apply_id']>0 && $society_info['society_status']==1 && $society_info['society_id']>0){
  4572. if($society_income) {
  4573. if($society_chieftain == 0){//排除会长自己
  4574. //增加:公会收益
  4575. $sql = "update " . DB_PREFIX . "society set contribution = contribution + " . $society_income . " where id = " . $society_id;
  4576. $GLOBALS['db']->query($sql);
  4577. //将公会收益汇给会长
  4578. $sql = "update " . DB_PREFIX . "user set ticket = ticket + " . $society_income . " where id = " . $society_info['user_id'];
  4579. $status = $GLOBALS['db']->query($sql);
  4580. user_deal_to_reids(array($society_info['user_id']));
  4581. }else{
  4582. //增加:公会收益
  4583. $sql = "update " . DB_PREFIX . "society set contribution = contribution + " . $vote_number . " where id = " . $society_id;
  4584. $GLOBALS['db']->query($sql);
  4585. }
  4586. if($society_chieftain){
  4587. $contribution_id = $user_id;
  4588. }else{
  4589. $contribution_id = 0;
  4590. }
  4591. //收益情况写入用户日志
  4592. earnings_log($vote_number, $society_id, $contribution_id, 8, '直播获取收益' . $vote_number . '印票', $user_id, $video_id);
  4593. $m_config = load_auto_cache("m_config");//初始化手机端配置
  4594. if(intval($m_config['society_profit_platform'])==0 && $society_chieftain == 0){//判断会长抽成是否由平台支付,0否1是
  4595. $sql = "update " . DB_PREFIX . "user set refund_ticket = refund_ticket + " . $society_income . " where id = " . $user_id . " and ticket > refund_ticket + " . $society_income;
  4596. $GLOBALS['db']->query($sql);
  4597. user_deal_to_reids(array($user_id));
  4598. //写入用户日志
  4599. earnings_log($society_income, $society_id, 0, 8, '扣除公会长抽成' . $society_income . '印票', $user_id, $video_id);
  4600. }
  4601. if($society_chieftain == 0){
  4602. //写入公会长日志
  4603. earnings_log($society_income, $society_id, $user_id, 8, '获取公会成员'.$user_id.':'.$society_income.'印票', $society_info['user_id'], $video_id);
  4604. }
  4605. return true;
  4606. }
  4607. return false;
  4608. }else{
  4609. return false;
  4610. }
  4611. }
  4612. //-------------公会等级积分-------------
  4613. /**
  4614. * @ param int $m_config 配置信息
  4615. * @ param int $user_id 用户ID
  4616. * @ param int $video_id 直播ID
  4617. * @ param array $video 直播信息
  4618. * @ param array $user_info 包含成员的 公会ID和会长标识
  4619. */
  4620. function society_lv_jf($m_config,$user_id,$video_id,$video,$user_info){
  4621. $society_income = 0;
  4622. //判断是否扣除过
  4623. $user_log_id = $GLOBALS['db']->getOne("select id from ".DB_PREFIX."user_log where type=8 and user_id = ".$user_id." and video_id=".intval($video_id));
  4624. if($m_config['society_profit_ratio']>=0 && intval($user_log_id)==0 && $m_config['society_profit_ratio'] < 100){
  4625. if($m_config['society_profit_ratio'] == 0){
  4626. //写入用户日志
  4627. earnings_log($video['vote_number'], $user_info['society_id'], 0, 8, '直播获取收益' . intval($video['vote_number']) . '印票', $user_id, $video_id);
  4628. return true;
  4629. }
  4630. $society_income = intval(intval($video['vote_number'])*0.01*$m_config['society_profit_ratio']);
  4631. $result = society_receipts1($user_id,$user_info['society_id'],$society_income,$video['vote_number'],$video_id);
  4632. if($result){
  4633. //公会等级积分的写入
  4634. $society_score = intval($video['vote_number']);
  4635. society_level_syn($video['vote_number'], $video['begin_time'], $user_info['society_id']);
  4636. //记录到公会主播收益表
  4637. $society_data = array();
  4638. $society_earning_id = $GLOBALS['db']->getOne('select id from '.DB_PREFIX."society_earning where video_id=".$video['id']);//是否已经记录过
  4639. if (!$society_earning_id && $user_info['society_id']>0){//收益还未记录且主播是公会成员
  4640. $society_data['video_id'] = $video['id'];
  4641. $society_data['user_id'] = $video['user_id'];
  4642. $society_data['vote_number'] = $video['vote_number'];
  4643. $society_data['begin_time'] = $video['begin_time'];
  4644. $society_data['end_time'] = $video['end_time'] ? $video['end_time'] : NOW_TIME;
  4645. $society_data['timelen'] = $society_data['end_time'] - $society_data['begin_time'];
  4646. $society_data['society_id'] = $user_info['society_id'];
  4647. $society_data['end_date'] = to_date($society_data['end_time'],'Y-m-d');
  4648. $society_data['end_Y'] = to_date($society_data['end_time'],'Y');
  4649. $society_data['end_m'] = to_date($society_data['end_time'],'m');
  4650. $society_data['end_d'] = to_date($society_data['end_time'],'d');
  4651. $society_data['end_w'] = to_date($society_data['end_time'],'W');
  4652. $society_data['society_settlement_type'] = $m_config['society_pattern'];
  4653. $society_chieftain = $GLOBALS['db']->getOne("select society_chieftain from ".DB_PREFIX."user where id=$user_id");
  4654. if($society_chieftain){
  4655. $society_data['society_number'] = $society_score;
  4656. }else{
  4657. $society_data['society_number'] = $society_income;
  4658. }
  4659. $GLOBALS['db']->autoExecute(DB_PREFIX . "society_earning", $society_data);
  4660. }
  4661. }
  4662. }
  4663. }
  4664. //-------------公会等级积分写入-------------
  4665. /**
  4666. * @ param int $society_income 直播结束所得收益
  4667. * @ param number $begin_time 直播时长
  4668. * @ param int $society_id 公会ID
  4669. */
  4670. function society_level_syn($society_income,$begin_time,$society_id)
  4671. {
  4672. $m_config = load_auto_cache("m_config");//初始化手机端配置
  4673. $society_score = 0;
  4674. //合并贡献收益 判断,用户当前等级积分
  4675. $cte = intval($m_config['society_lv_contribution']);
  4676. if ($cte > 0 && $cte < 100 ){
  4677. $society_score += $society_income * $cte * 0.01;
  4678. }
  4679. if($begin_time > 0){//区分私信送礼物
  4680. $video_time = (NOW_TIME - $begin_time);
  4681. //合并直播时长 判断,用户当前等级积分
  4682. $vte = intval($m_config['society_lv_videotime']);
  4683. if ($vte > 0 && $vte < 100 ){
  4684. $society_score += $video_time * $vte * 0.01;
  4685. }
  4686. }
  4687. if($cte > 0 || ($begin_time > 0 && $vte > 0)){
  4688. //积分写入
  4689. $GLOBALS['db']->query("update ".DB_PREFIX."society set score=score+".intval($society_score)." where id=".$society_id);
  4690. $society_info = $GLOBALS['db']->getRow("SELECT id as society_id,society_level,score FROM " . DB_PREFIX . "society WHERE id=" . $society_id . " and status=1", true, true);
  4691. //society_level_syn($society_info);
  4692. $society_score = $society_info['score'];
  4693. $society_level_info = load_auto_cache("society_level");
  4694. $society_level = null;
  4695. foreach($society_level_info as $v) {
  4696. // 两层关系即可
  4697. unset($society_level['next_level']);
  4698. $v['next_level'] = $society_level;
  4699. $society_level = $v;
  4700. if ($v['score'] <= intval($society_score)) {
  4701. break;
  4702. }
  4703. }
  4704. if($society_level)
  4705. {
  4706. $GLOBALS['db']->query("update ".DB_PREFIX."society set society_level = ".$society_level['level']." where id = ".$society_info['society_id']);
  4707. }
  4708. return $society_level;
  4709. }
  4710. }
  4711. //判断用户是否参与众筹
  4712. function is_ordered($room_id,$user_id){
  4713. $is_order = 0;
  4714. $deal_id = $GLOBALS['db']->getOne("select deal_id from " . DB_PREFIX . "edu_video_info where video_id= " . $room_id );
  4715. if($deal_id){
  4716. $deal_order_count = $GLOBALS['db']->getOne("select count(*) from " . DB_PREFIX . "edu_deal_order where deal_id= " . $deal_id . " and order_status=1 and is_refund=0 and user_id =".$user_id);
  4717. if($deal_order_count > 0){
  4718. $is_order = 1;
  4719. }
  4720. }
  4721. return $is_order;
  4722. }
  4723. /**
  4724. * 返回用户等级信息,当前经验和下一级所需经验
  4725. * @param $user_id
  4726. * @return mixed
  4727. */
  4728. function get_level_up_grade($user_id){
  4729. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/UserRedisService.php');
  4730. $user_redis = new UserRedisService();
  4731. $user_data = $user_redis->getRow_db($user_id,array('id','score','online_time','user_level'));
  4732. user_leverl_syn($user_data);
  4733. $level=$GLOBALS['db']->getRow("select ul.level as user_level, ul.score as l_score from ".DB_PREFIX."user_level as ul where ul.level=".intval($user_data['user_level']));
  4734. $m_config = load_auto_cache("m_config");
  4735. $level['u_score'] = $user_data['score']+floor($user_data['online_time']*floatval($m_config['onlinetime_to_experience']));
  4736. $level['up_score'] = $GLOBALS['db']->getOne("select score from ".DB_PREFIX."user_level where level=".intval($user_data['user_level']+1));
  4737. if(intval($level['up_score'])<=0){
  4738. $l_up_score = $GLOBALS['db']->getOne("select score from ".DB_PREFIX."user_level where level>".intval($user_data['user_level']+1));
  4739. if($l_up_score['score']>0){
  4740. $level['up_score'] =$l_up_score['score'];
  4741. }else{
  4742. $level['up_score'] ='满级';
  4743. }
  4744. }
  4745. $level['u_score'] = intval($level['u_score']);
  4746. $level['up_score'] = intval($level['up_score']);
  4747. return $level;
  4748. }
  4749. /**
  4750. * //暮橙定制: IM推送用户等级和经验信息
  4751. * @param $user_id
  4752. * @return bool
  4753. */
  4754. function push_level_info($user_id){
  4755. $m_config = load_auto_cache("m_config");
  4756. $system_user_id =$m_config['tim_identifier'];//系统消息
  4757. $level = get_level_up_grade($user_id);
  4758. $level_info = array();
  4759. $level_info['user_level'] = $level['user_level'];
  4760. if($level['up_score']=='满级'){
  4761. $level_info['score_msg'] = "升级还需0".$m_config['ticket_name'];
  4762. }else {
  4763. $score = $level['up_score'] - $level['u_score'];
  4764. $level_info['score_msg'] = "升级还需".$score.$m_config['ticket_name'];
  4765. }
  4766. $ext2 = array();
  4767. $ext2['type'] = 61; //上海暮橙定制: 用户送礼给主播,系统返回推送用户等级和升级经验信息
  4768. $ext2['level_info'] = $level_info;
  4769. $msg_content2 = array();
  4770. //创建array 所需元素
  4771. $msg_content_elem2 = array(
  4772. 'MsgType' => 'TIMCustomElem', //自定义类型
  4773. 'MsgContent' => array(
  4774. 'Data' => json_encode($ext2),
  4775. 'Desc' => ''
  4776. )
  4777. );
  4778. //将创建的元素$msg_content_elem, 加入array $msg_content
  4779. array_push($msg_content2, $msg_content_elem2);
  4780. fanwe_require(APP_ROOT_PATH.'system/tim/TimApi.php');
  4781. $api = createTimAPI();
  4782. $ret2 = $api->openim_send_msg2($system_user_id, (string)$user_id, $msg_content2);
  4783. if($ret2['ActionStatus'] != 'OK') {
  4784. //二次处理
  4785. $ret2 = $api->openim_send_msg2($system_user_id, (string)$user_id, $msg_content2);
  4786. }
  4787. if($ret2['ActionStatus'] == 'OK'){
  4788. return true;
  4789. }else{
  4790. return false;
  4791. }
  4792. }
  4793. /**
  4794. * //公会收益日志
  4795. * @param int $ticket 印票数
  4796. * @param int $type 类型
  4797. * @param string $log 日志内容
  4798. * @param int $user_id 用户id
  4799. * @param int $society_id 公会id
  4800. * @param int $contribution_id 会长抽取收益的成员id
  4801. * @param int $video_id 直播间id
  4802. * */
  4803. function earnings_log($ticket,$society_id,$contribution_id,$type,$log,$user_id,$video_id=0){
  4804. $data = array();
  4805. $data['ticket'] = $ticket;
  4806. $data['society_id'] = $society_id;
  4807. $data['contribution_id'] = $contribution_id;//会长记录
  4808. $data['video_id'] = $video_id;
  4809. $param['type'] = $type;//类型 0表示充值 1表示提现 2赠送道具 3 兑换印票 4 分享获得印票 5 登录赠送积分 6 观看付费直播 7游戏收益8扣除公会收益9分销收益10公会长收益11平台收益 12公会操作13私信收入
  4810. $log_msg = $log;
  4811. account_log_com($data,$user_id, $log_msg, $param);
  4812. }
  4813. /**
  4814. * 获取程序执行时间
  4815. * @param int $type 0:初次执行时间 1:最终执行时间
  4816. */
  4817. function get_runtime($pram,$type=0){
  4818. //get_runtime(array(__FILE__,__LINE__,__METHOD__),1);
  4819. if($type==0){
  4820. global $get_runtime_t1;
  4821. $get_runtime_t1 = microtime(true);
  4822. log_file('文件名:'.$pram[0].',行数:'.$pram[1].',方法:'.$pram[2].',首次执行时间'.$get_runtime_t1.'秒','run_time');
  4823. }else{
  4824. $get_runtime_t1 = $GLOBALS['get_runtime_t1'];
  4825. $get_runtime_t2 = microtime(true);
  4826. log_file('文件名:'.$pram[0].',行数:'.$pram[1].',方法:'.$pram[2].',最后执行时间'.$get_runtime_t2.'秒','run_time');
  4827. log_file('文件名:'.$pram[0].',行数:'.$pram[1].',方法:'.$pram[2].',耗时'.floatval($get_runtime_t2-$get_runtime_t1).'秒','run_time');
  4828. }
  4829. }
  4830. ?>