user.action.php 72 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | FANWE 直播系统
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2011 http://www.fanwe.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Author: 云淡风轻(1956838968@qq.com)
  8. // +----------------------------------------------------------------------
  9. class userCModule extends baseCModule
  10. {
  11. public function __construct()
  12. {
  13. parent::__construct();
  14. }
  15. public function usersig()
  16. {
  17. /**
  18. * 获取用户签名
  19. **/
  20. //$GLOBALS['user_info']['id'] = 320;
  21. $root = array();
  22. if(!$GLOBALS['user_info']){
  23. $root['error'] = "用户未登陆,请先登陆.";// es_session::id();
  24. //$root['es_session'] = es_session::id();
  25. //$root['user_info'] = json_encode(es_session::get("user_info"));
  26. $root['status'] = 0;
  27. $root['user_login_status'] = 0;//有这个参数: user_login_status = 0 时,表示服务端未登陆、要求登陆,操作
  28. }else{
  29. $identifier = $GLOBALS['user_info']['id'];// $_REQUEST['identifier'];
  30. $root = load_auto_cache("usersig", array("id"=>$identifier));
  31. /*
  32. $usersig = $GLOBALS['db']->getOne("select usersig from ".DB_PREFIX."user where id=".$identifier." and expiry_after >" .NOW_TIME);
  33. if(!$usersig){
  34. fanwe_require(APP_ROOT_PATH.'system/tim/TimApi.php');
  35. $api = createRestAPI();
  36. $private_pem_path = APP_ROOT_PATH."system/tim/ec_key.pem";
  37. $signature = get_signature();
  38. $ret = $api->generate_user_sig($identifier, '86400', $private_pem_path, $signature);
  39. $expiry_after = NOW_TIME + 86400;
  40. //echo "update ".DB_PREFIX."user set usersig = ".$ret[0].",expiry_after=".$expiry_after." where id = ".$identifier;exit;
  41. $GLOBALS['db']->query("update ".DB_PREFIX."user set usersig = '".$ret[0]."',expiry_after=".$expiry_after." where id = ".$identifier);
  42. }else{
  43. $ret[0] =$usersig;
  44. }
  45. if($ret == null || strstr($ret[0], "failed")){
  46. $root['error'] = "获取usrsig失败, 请确保TimRestApiConfig.json配置信息正确";
  47. $root['status'] = 0;
  48. }else{
  49. $root['usersig'] = $ret[0];
  50. $root['status'] = 1;
  51. }
  52. */
  53. }
  54. ajax_return($root);
  55. }
  56. /**
  57. * 获得用户公开信息;不传identifier时,则获得当前登陆用户的信息
  58. */
  59. public function userinfo(){
  60. $root = array();
  61. //$GLOBALS['user_info']['id'] = 292;
  62. if(!$GLOBALS['user_info']){
  63. $root['error'] = "用户未登陆,请先登陆.";
  64. $root['status'] = 0;
  65. $root['user_login_status'] = 0;//有这个参数: user_login_status = 0 时,表示服务端未登陆、要求登陆,操作
  66. }else{
  67. $user_id = intval($GLOBALS['user_info']['id']);
  68. $podcast_id = intval($_REQUEST['podcast_id']);//主播id,fanwe_user.id
  69. $to_user_id = intval($_REQUEST['to_user_id']);//需要查看的用户id
  70. if ($to_user_id == 0){
  71. $to_user_id = $user_id;
  72. }
  73. $root = getuserinfo($user_id,$podcast_id,$to_user_id);
  74. $m_config = load_auto_cache("m_config");//初始化手机端配置
  75. $root['init_version'] = intval($m_config['init_version']);//手机端配置版本号
  76. if($m_config['name_limit']==1){
  77. $user = $GLOBALS['db']->getRow("select nick_name from ".DB_PREFIX."user where id = ".$user_id);
  78. $nick_name=$user['nick_name'];
  79. //进入个人中心过滤铭感词汇
  80. $limit_sql =$GLOBALS['db']->getCol("SELECT name FROM ".DB_PREFIX."limit_name");
  81. if($GLOBALS['db']->getCol("SELECT name FROM ".DB_PREFIX."limit_name WHERE '$nick_name' like concat('%',name,'%')")){
  82. $nick_name=str_replace($limit_sql,'*',$nick_name);
  83. }
  84. //判断用户名如果被过滤后为空,格式则变更为: 账号+ID
  85. if($nick_name==''){
  86. $nick_name=('账号'.$user_id);
  87. }
  88. //更新数据库
  89. $sql = "update ".DB_PREFIX."user set nick_name = '$nick_name' where id=".$user_id;
  90. $GLOBALS['db']->query($sql);
  91. //更新redis
  92. user_deal_to_reids(array($user_id));
  93. }
  94. $root['status'] = 1;
  95. }
  96. ajax_return($root);
  97. }
  98. /**
  99. * 关注某个用户
  100. */
  101. public function follow(){
  102. $root = array('status'=>1,'error'=>'');
  103. //$GLOBALS['user_info']['id'] = 269;
  104. if(!$GLOBALS['user_info']){
  105. $root['error'] = "用户未登陆,请先登陆.";
  106. $root['status'] = 0;
  107. $root['user_login_status'] = 0;//有这个参数: user_login_status = 0 时,表示服务端未登陆、要求登陆,操作
  108. }else{
  109. //
  110. $user_id = intval($GLOBALS['user_info']['id']);//当前用户;
  111. $room_id = intval($_REQUEST['room_id']);//room_id 当前直播房间号,用来:计算权重的;
  112. $to_user_id = intval($_REQUEST['to_user_id']);//被关注或取消关注的用户
  113. $to_user_id = $GLOBALS['db']->getOne("select id from ".DB_PREFIX."user where id = ".$to_user_id,true,true);
  114. if(!intval($to_user_id)) {
  115. $root['error'] = "关注的用户不存在!";
  116. $root['status'] = 0;
  117. }else if($user_id!=$to_user_id){
  118. $root = redis_set_follow($user_id,$to_user_id,false,$room_id);
  119. clear_auto_cache("playback_list",array("user_id"=>$user_id));
  120. /*
  121. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/UserFollwRedisService.php');
  122. $user_redis = new UserFollwRedisService($user_id);
  123. //查看关注人数
  124. $follow_count = $user_redis->follow_count();
  125. //粉丝人数
  126. $follow_by_count = $user_redis->follower_count();
  127. //update_follow($user_id,$follow_count,$follow_by_count);
  128. //$root = set_follow($user_id,$to_user_id);
  129. //$root = redis_set_follow($user_id,$to_user_id);
  130. */
  131. }else{
  132. $root['error'] = "不能关注自己!";
  133. $root['status'] = 0;
  134. }
  135. }
  136. ajax_return($root);
  137. }
  138. /**
  139. * 禁言,只有:主群或群管理员才能设置
  140. */
  141. public function forbid_send_msg(){
  142. $root = array();
  143. $root['status'] = 0;
  144. //$GLOBALS['user_info']['id'] = 1;
  145. if(!$GLOBALS['user_info']){
  146. $root['error'] = "用户未登陆,请先登陆.";
  147. $root['status'] = 0;
  148. $root['user_login_status'] = 0;//有这个参数: user_login_status = 0 时,表示服务端未登陆、要求登陆,操作
  149. }else{
  150. $user_id = intval($GLOBALS['user_info']['id']);//
  151. $to_user_id = strim($_REQUEST['to_user_id']);//被禁言的用户id
  152. $group_id = strim($_REQUEST['group_id']);//群组ID
  153. $second = intval($_REQUEST['second']);//禁言时间,单位为秒; 为0时表示取消禁言
  154. $is_nospeaking = $GLOBALS['db']->getOne("select is_nospeaking from ".DB_PREFIX."user where id = ".$to_user_id,true,true);
  155. if(intval($is_nospeaking)==1){
  156. $root['error'] = "该用户已被im全局禁言.";
  157. ajax_return($root);
  158. }
  159. $second = 10000;
  160. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/VideoRedisService.php');
  161. $video_redis = new VideoRedisService();
  162. $video = $video_redis->getRow_db_ByGroupId($group_id,array('id','user_id'));
  163. //优化
  164. $forbid_info = $video_redis->has_forbid_msg($group_id,$to_user_id);//判断某个用户是否被禁言(被禁言返回:true; 未被禁言返回:false)
  165. if($forbid_info){
  166. $second = 0;
  167. }else{
  168. $second = 10000;
  169. }
  170. //$sql = "select id,user_id,group_id from ".DB_PREFIX."video where group_id = '".$group_id."'";
  171. //$video = $GLOBALS['db']->getRow($sql,true,true);
  172. $podcast_id = intval($video['user_id']);
  173. $room_id = intval($video['id']);
  174. //查看自己
  175. if ($to_user_id == $user_id){
  176. $root['error'] = "不能自己给自己禁言";
  177. }else{
  178. $allow = false;
  179. //主播查看
  180. if ($podcast_id == $user_id){
  181. $allow = true;//主播 有权限禁言
  182. }else{
  183. $sql = "select count(id) as num from ".DB_PREFIX."user_admin where podcast_id = ".$podcast_id." and user_id = ".$user_id;
  184. if ($GLOBALS['db']->getOne($sql,true,true) > 0){
  185. $allow = true;//管理员 有权限禁言按钮
  186. }
  187. }
  188. }
  189. if ($allow){
  190. $sql = "select is_robot,nick_name from ".DB_PREFIX."user where id = '".$to_user_id."'";
  191. $user = $GLOBALS['db']->getRow($sql,true,true);
  192. $nick_name = $user['nick_name'];
  193. if ($user['is_robot'] == 1){
  194. $root['status'] = 1;
  195. $msg = $nick_name. " 被禁言";
  196. $root['error'] = $msg;
  197. }else{
  198. fanwe_require(APP_ROOT_PATH.'system/tim/TimApi.php');
  199. $api = createTimAPI();
  200. //设置:禁言(second>0),取消禁言(second = 0)
  201. $ret = $api->group_forbid_send_msg($group_id,(string)$to_user_id,$second);
  202. if ($ret['ActionStatus'] == 'OK'){
  203. //$ret = $api->get_group_shutted_uin($group_id);
  204. if ($second > 0){
  205. /*
  206. $forbid_send_msg = array();
  207. $forbid_send_msg['group_id'] = $group_id;
  208. $forbid_send_msg['user_id'] = $to_user_id;
  209. $forbid_send_msg['shut_up_time'] = NOW_TIME + $second;
  210. $GLOBALS['db']->autoExecute(DB_PREFIX."video_forbid_send_msg", $forbid_send_msg,"INSERT");
  211. */
  212. $video_redis->set_forbid_msg($group_id,$to_user_id);
  213. $msg = $nick_name. " 被禁言";//.print_r($ret,1).';user_id:'.$user_id.";second:".$second.";group_id:".$group_id;
  214. }else{
  215. $msg = $nick_name. " 取消禁言";
  216. $video_redis->unset_forbid_msg($group_id,$to_user_id);
  217. //$sql = "delete from ".DB_PREFIX."video_forbid_send_msg where group_id='".$group_id."' and user_id = '".$to_user_id."'";
  218. //$GLOBALS['db']->query($sql);
  219. }
  220. $root['status'] = 1;
  221. }else{
  222. $root['status'] = 0;
  223. $root['error'] = $ret['ErrorInfo'].":".$ret['ErrorCode'];
  224. }
  225. }
  226. if ($root['status'] == 1){
  227. if (!$api){
  228. fanwe_require(APP_ROOT_PATH.'system/tim/TimApi.php');
  229. $api = createTimAPI();
  230. }
  231. //群播一个:禁言通知
  232. $ext = array();
  233. $ext['type'] = 4; //0:普通消息;1:礼物;2:弹幕消息;3:主播退出;4:禁言;5:观众进入房间;6:观众退出房间;7:直播结束
  234. $ext['room_id'] = $room_id;//直播ID 也是room_id;只有与当前房间相同时,收到消息才响应
  235. $ext['fonts_color'] = '';//字体颜色
  236. $ext['desc'] = $msg;//禁言通知消息;
  237. $ext['desc2'] = $msg;//禁言通知消息;
  238. //消息发送者
  239. $sender = array();
  240. $sender['user_id'] = $GLOBALS['user_info']['id'];//发送人昵称
  241. $sender['nick_name'] = $GLOBALS['user_info']['nick_name'];//发送人昵称
  242. $sender['head_image'] = $GLOBALS['user_info']['head_image'];//发送人头像
  243. $sender['user_level'] = $GLOBALS['user_info']['user_level'];//用户等级
  244. $ext['sender'] = $sender;
  245. #构造高级接口所需参数
  246. $msg_content = array();
  247. //创建array 所需元素
  248. $msg_content_elem = array(
  249. 'MsgType' => 'TIMCustomElem', //自定义类型
  250. 'MsgContent' => array(
  251. 'Data' => json_encode($ext),
  252. 'Desc' => '',
  253. // 'Ext' => $ext,
  254. // 'Sound' => '',
  255. )
  256. );
  257. //将创建的元素$msg_content_elem, 加入array $msg_content
  258. array_push($msg_content, $msg_content_elem);
  259. $ret = $api->group_send_group_msg2($GLOBALS['user_info']['id'], $group_id, $msg_content);
  260. }
  261. }else{
  262. $root['error'] = "无禁言权限";
  263. }
  264. }
  265. ajax_return($root);
  266. }
  267. /**
  268. * 设置/取消 管理员
  269. */
  270. public function set_admin(){
  271. $root = array();
  272. $root['status'] = 1;
  273. if(!$GLOBALS['user_info']){
  274. $root['error'] = "用户未登陆,请先登陆.";
  275. $root['status'] = 0;
  276. $root['user_login_status'] = 0;//有这个参数: user_login_status = 0 时,表示服务端未登陆、要求登陆,操作
  277. }else{
  278. //
  279. $user_id = intval($GLOBALS['user_info']['id']);
  280. $to_user_id = intval($_REQUEST['to_user_id']);//被关注或取消 管理员用户
  281. $room_id = strim($_REQUEST['room_id']);
  282. $sql = "select id from ".DB_PREFIX."user_admin where podcast_id = '".$user_id."' and user_id = ".$to_user_id;
  283. $user_admin_id = $GLOBALS['db']->getOne($sql);
  284. if ($user_admin_id > 0){
  285. //取消管理员操作;
  286. $sql = "delete from ".DB_PREFIX."user_admin where id = ".$user_admin_id;
  287. $GLOBALS['db']->query($sql);
  288. }else{
  289. $sql = "select count(id) as num from ".DB_PREFIX."user_admin where podcast_id = ".$GLOBALS['user_info']['id'];
  290. if ($GLOBALS['db']->getOne($sql) < 5){
  291. //设置管理员操作;
  292. $user_admin = array();
  293. $user_admin['podcast_id'] = $GLOBALS['user_info']['id'];
  294. $user_admin['user_id'] = $to_user_id;
  295. $user_admin['create_time'] = NOW_TIME;
  296. $GLOBALS['db']->autoExecute(DB_PREFIX."user_admin", $user_admin,"INSERT");
  297. }else{
  298. $root['error'] = "已经超过5位管理员,不能再设置新的管理员";
  299. $root['status'] = 0;
  300. }
  301. }
  302. $sql = "select id from ".DB_PREFIX."user_admin where podcast_id = '".$user_id."' and user_id = ".$to_user_id;
  303. if ($GLOBALS['db']->getOne($sql) > 0){
  304. $root['has_admin'] = 1;//0:非管理员;1:是管理员
  305. }else{
  306. $root['has_admin'] = 0;
  307. }
  308. if ($root['status'] ==1 && $room_id != ''){
  309. $sql = "select nick_name from ".DB_PREFIX."user where id = '".$to_user_id."'";
  310. if ($root['has_admin'] == 1){
  311. $msg = $GLOBALS['db']->getOne($sql). " 被设置为管理员";
  312. }else{
  313. $msg = $GLOBALS['db']->getOne($sql). " 管理员被取消";
  314. }
  315. fanwe_require(APP_ROOT_PATH.'system/tim/TimApi.php');
  316. $api = createTimAPI();
  317. //群播一个:直播消息
  318. $ext = array();
  319. $ext['type'] = 9; //0:普通消息;1:礼物;2:弹幕消息;3:主播退出;4:禁言;5:观众进入房间;6:观众退出房间;7:直播结束
  320. $ext['room_id'] = $room_id;//直播ID 也是room_id;只有与当前房间相同时,收到消息才响应
  321. $ext['fonts_color'] = '';//字体颜色
  322. $ext['desc'] = $msg;//禁言通知消息;
  323. $ext['desc2'] = $msg;//禁言通知消息;
  324. //消息发送者
  325. $sender = array();
  326. $sender['user_id'] = $GLOBALS['user_info']['id'];//发送人昵称
  327. $sender['nick_name'] = $GLOBALS['user_info']['nick_name'];//发送人昵称
  328. $sender['head_image'] = $GLOBALS['user_info']['head_image'];//发送人头像
  329. $sender['user_level'] = $GLOBALS['user_info']['user_level'];//用户等级
  330. $ext['sender'] = $sender;
  331. #构造高级接口所需参数
  332. $msg_content = array();
  333. //创建array 所需元素
  334. $msg_content_elem = array(
  335. 'MsgType' => 'TIMCustomElem', //自定义类型
  336. 'MsgContent' => array(
  337. 'Data' => json_encode($ext),
  338. 'Desc' => '',
  339. // 'Ext' => $ext,
  340. // 'Sound' => '',
  341. )
  342. );
  343. //将创建的元素$msg_content_elem, 加入array $msg_content
  344. array_push($msg_content, $msg_content_elem);
  345. $sql = "select group_id from ".DB_PREFIX."video where id = '".$room_id."'";
  346. $group_id = $GLOBALS['db']->getOne($sql);
  347. $ret = $api->group_send_group_msg2($GLOBALS['user_info']['id'], $group_id, $msg_content);
  348. if ($ret['ActionStatus'] == 'FAIL' && $ret['ErrorCode'] == 10002){
  349. //10002 系统错误,请再次尝试或联系技术客服。
  350. $ret = $api->group_send_group_msg2($GLOBALS['user_info']['id'], $group_id, $msg_content);
  351. }
  352. }
  353. }
  354. ajax_return($root);
  355. }
  356. /**
  357. * 举报用户
  358. */
  359. public function tipoff(){
  360. $root = array();
  361. $root['status'] = 1;
  362. if(!$GLOBALS['user_info']){
  363. $root['error'] = "用户未登陆,请先登陆.";
  364. $root['status'] = 0;
  365. $root['user_login_status'] = 0;//有这个参数: user_login_status = 0 时,表示服务端未登陆、要求登陆,操作
  366. }else{
  367. $to_user_id = intval($_REQUEST['to_user_id']);//被关注的举报用户ID
  368. $type = intval($_REQUEST['type']);
  369. $room_id = intval($_REQUEST['room_id']); //被举报的房间id
  370. $tipoff = array();
  371. $tipoff['from_user_id'] = $GLOBALS['user_info']['id'];
  372. $tipoff['to_user_id'] = $to_user_id;
  373. $tipoff['create_time'] = NOW_TIME;
  374. $tipoff['tipoff_type_id'] = $type;
  375. $tipoff['video_id'] = $room_id;
  376. $GLOBALS['db']->autoExecute(DB_PREFIX."tipoff", $tipoff,"INSERT");
  377. if ($room_id > 0){
  378. //累加举报次数
  379. $sql = "update ".DB_PREFIX."video set tipoff_count = tipoff_count + 1 where id =".$room_id;
  380. $GLOBALS['db']->query($sql);
  381. }
  382. }
  383. ajax_return($root);
  384. }
  385. /**
  386. * 主播管理员列表
  387. */
  388. public function user_admin(){
  389. $root = array();
  390. $root['status'] = 1;
  391. if(!$GLOBALS['user_info']){
  392. $root['error'] = "用户未登陆,请先登陆.";
  393. $root['status'] = 0;
  394. $root['user_login_status'] = 0;//有这个参数: user_login_status = 0 时,表示服务端未登陆、要求登陆,操作
  395. }else{
  396. $user_id = intval($GLOBALS['user_info']['id']);//用户ID
  397. $sql = "select ua.id, ua.user_id, u.nick_name,u.head_image,u.sex,u.user_level from ".DB_PREFIX."user_admin ua left join ".DB_PREFIX."user u on u.id = ua.user_id where ua.podcast_id = ".$user_id;
  398. $list = $GLOBALS['db']->getAll($sql);
  399. foreach($list as $k=>$v){
  400. $list[$k]['head_image'] = get_spec_image($v['head_image']);
  401. }
  402. $root['list'] = $list;
  403. $root['max_num'] = 5;
  404. $root['cur_num'] = count($list);
  405. $root['status'] = 1;
  406. }
  407. ajax_return($root);
  408. }
  409. /**
  410. * 关注的用户,最多不超过100个
  411. */
  412. public function user_follow(){
  413. $root = array();
  414. $root['status'] = 1;
  415. //$GLOBALS['user_info']['id'] = 278;
  416. if(!$GLOBALS['user_info']){
  417. $root['error'] = "用户未登陆,请先登陆.";
  418. $root['status'] = 0;
  419. $root['user_login_status'] = 0;//有这个参数: user_login_status = 0 时,表示服务端未登陆、要求登陆,操作
  420. }else{
  421. $user_id = intval($GLOBALS['user_info']['id']);//id
  422. $page = intval($_REQUEST['p']);//取第几页数据
  423. if($page==0){
  424. $page = 1;
  425. }
  426. if (isset($_REQUEST['to_user_id'])){
  427. $to_user_id = strim($_REQUEST['to_user_id']);//被查看的用户id
  428. }else{
  429. $to_user_id = $user_id;//id
  430. }
  431. $page_size = 20;
  432. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/UserFollwRedisService.php');
  433. $user_redis = new UserFollwRedisService($user_id);
  434. $list = $user_redis->get_follonging_user($to_user_id,$page,$page_size);
  435. foreach($list as $k=>$v){
  436. $list[$k]['signature'] = htmlspecialchars_decode($list[$k]['signature']);
  437. $list[$k]['nick_name'] = htmlspecialchars_decode($list[$k]['nick_name']);
  438. }
  439. $root['list'] = $list;
  440. $rs_count = $user_redis->following();
  441. if($page==0){
  442. $root['has_next'] = 0;
  443. }else{
  444. if (count($rs_count) >= $page_size)
  445. $root['has_next'] = 1;
  446. else
  447. $root['has_next'] = 0;
  448. }
  449. $root['page'] = $page;//
  450. }
  451. ajax_return($root);
  452. }
  453. /**
  454. * 粉丝列表,最多不超过100个
  455. */
  456. public function user_focus(){
  457. $root = array();
  458. $root['status'] = 1;
  459. //$GLOBALS['user_info']['id'] = 278;
  460. if(!$GLOBALS['user_info']){
  461. $root['error'] = "用户未登陆,请先登陆.";
  462. $root['status'] = 0;
  463. $root['user_login_status'] = 0;//有这个参数: user_login_status = 0 时,表示服务端未登陆、要求登陆,操作
  464. }else{
  465. $user_id = intval($GLOBALS['user_info']['id']);//id
  466. if (isset($_REQUEST['to_user_id'])){
  467. $to_user_id = strim($_REQUEST['to_user_id']);//被查看的用户id
  468. }else{
  469. $to_user_id = $user_id;
  470. }
  471. $page = intval($_REQUEST['p']);//取第几页数据
  472. if($page==0){
  473. $page = 1;
  474. }
  475. $page_size = 20;
  476. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/UserFollwRedisService.php');
  477. $user_redis = new UserFollwRedisService($user_id);
  478. $list = $user_redis->get_follonging_by_user($to_user_id,$page);
  479. $keys = $user_redis->following();
  480. foreach($list as $k=>$v){
  481. if($user_id>0){
  482. if (in_array($v['user_id'],$keys)){
  483. $list[$k]['follow_id'] = 1;
  484. }else{
  485. $list[$k]['follow_id'] = 0;
  486. }
  487. }else{
  488. $list[$k]['follow_id'] = 0;
  489. }
  490. $list[$k]['head_image'] = get_spec_image($v['head_image']);
  491. $list[$k]['nick_name'] = htmlspecialchars_decode($list[$k]['nick_name']);
  492. }
  493. $root['list'] = $list;
  494. if($page==0){
  495. $root['has_next'] = 0;
  496. }else{
  497. if (count($list) >= $page_size)
  498. $root['has_next'] = 1;
  499. else
  500. $root['has_next'] = 0;
  501. }
  502. $root['page'] = $page;//
  503. }
  504. ajax_return($root);
  505. }
  506. /**
  507. * 分享成功回调
  508. *
  509. * type: 分享类型(
  510. WEIXIN,WEIXIN_CIRCLE,QQ,QZONE,EMAIL,SMS,SINA
  511. 微信,微信朋友圈,qq,QQ空间,email,短信,新浪微博)
  512. room_id:房间号
  513. */
  514. public function share(){
  515. $root = array();
  516. $root['status'] = 1;
  517. if(!$GLOBALS['user_info']){
  518. $root['error'] = "用户未登陆,请先登陆.";
  519. $root['status'] = 0;
  520. $root['user_login_status'] = 0;//有这个参数: user_login_status = 0 时,表示服务端未登陆、要求登陆,操作
  521. }else{
  522. $user_id = intval($GLOBALS['user_info']['id']);//用户ID
  523. $type = strtolower(strim($_REQUEST['type']));//WEIXIN,WEIXIN_CIRCLE,QQ,QZONE,EMAIL,SMS,SINA
  524. $room_id = intval($_REQUEST['room_id']);//直播ID 也是room_id
  525. //分享加印票功能
  526. $m_config = load_auto_cache("m_config");//初始化手机端配置
  527. //每个房间每个类型可以分享一次,主播分享自己房间不获得
  528. if(defined('OPEN_SHARE_EXPERIENCE')&&OPEN_SHARE_EXPERIENCE==1&&intval($m_config['open_share_ticket'])){
  529. $sql = "select max(id) from ".DB_PREFIX."video_share where video_id = ".$room_id." and user_id =".$user_id." and type = '".$type."'";
  530. $exist_share_id = $GLOBALS['db']->getOne($sql);
  531. //获取主播ID
  532. $sql = "select user_id as from_user_id from ".DB_PREFIX."video where id =".$room_id;
  533. $video_user_info = $GLOBALS['db']->getRow($sql);
  534. $share_id = intval($exist_share_id);
  535. if($share_id==0){
  536. //分享表中无记录,查分享历史表
  537. $sql = "select id from ".DB_PREFIX."video_share_history where video_id = ".$room_id." and user_id =".$user_id." and type = '".$type."'";
  538. $share_id = intval($GLOBALS['db']->getOne($sql));
  539. }
  540. $now_time = NOW_TIME;
  541. $s_now_time = to_timespan(to_date($now_time,"Y-m-d 00:00:00"));
  542. $e_now_time = to_timespan(to_date($now_time,"Y-m-d 23:59:59"));
  543. if($share_id==0){
  544. $sql = "select max(id) from ".DB_PREFIX."video_share where user_id =".$user_id." and type = '".$type."' and create_time>".$s_now_time." and create_time<".$e_now_time;
  545. $video_t_share_id = $GLOBALS['db']->getOne($sql);
  546. $share_id = intval($video_t_share_id);
  547. if($share_id==0){
  548. //分享表中无记录,查分享历史表
  549. $sql = "select id from ".DB_PREFIX."video_share_history where user_id =".$user_id." and type = '".$type."' and create_time>".$s_now_time." and create_time<".$e_now_time;
  550. $share_id = intval($GLOBALS['db']->getOne($sql));
  551. }
  552. }
  553. //补充判断 app 端 上传 video_id 错误问题
  554. /*if($share_id==0){
  555. $sql = "select id,video_id,user_id from ".DB_PREFIX."video_share where '".strtotime(date('Y-m-d'))."' - create_time<3600*24 and user_id =".$user_id." and type = '".$type."'";
  556. $video_share_info = $GLOBALS['db']->getRow($sql);
  557. if(intval($video_share_info['id'])==0){
  558. $sql = "select id,video_id,user_id from ".DB_PREFIX."video_share_history where '".strtotime(date('Y-m-d'))."'-create_time<3600*24 and user_id =".$user_id." and type = '".$type."'";
  559. $video_share_info = $GLOBALS['db']->getRow($sql);
  560. };
  561. $share_id = intval($video_share_info['id']);
  562. }*/
  563. }
  564. //每个用户每个房间可以分享一次,增加分享次数
  565. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/VideoRedisService.php');
  566. $video_redis = new VideoRedisService();
  567. //$video_redis->incry($this->video_db.$room_id, 'share_count', 1);
  568. $video_redis->redis->hIncrBy($video_redis->video_db.$room_id,'share_count',1);
  569. $data = array();
  570. //写入分享表
  571. $video_monitor = array();
  572. $video_monitor['user_id'] = $user_id;
  573. $video_monitor['video_id'] = $room_id;
  574. $video_monitor['type'] = $type;
  575. $video_monitor['create_time'] = NOW_TIME;
  576. $GLOBALS['db']->autoExecute(DB_PREFIX."video_share", $video_monitor,"INSERT");
  577. $video_share_id = $GLOBALS['db']->insert_id();
  578. if(defined('OPEN_SHARE_EXPERIENCE')&&OPEN_SHARE_EXPERIENCE==1&&intval($m_config['open_share_ticket'])){
  579. //历史记录中也没有,可以增加
  580. if($share_id==0&&intval($m_config['share_ticket'])>0&&intval($video_user_info['from_user_id'])!=$user_id&&intval($video_share_id)>0){
  581. //根据open_share_ticket决定获得印票或钻石 1印票 2钻石
  582. if (intval($m_config['open_share_ticket'])==1){
  583. $sql = "update ".DB_PREFIX."user set ticket = ticket + ".intval($m_config['share_ticket'])." where id =".$user_id;
  584. $data['ticket'] =intval($m_config['share_ticket']);
  585. $ticket_name = '印票';
  586. }else{
  587. $sql = "update ".DB_PREFIX."user set diamonds = diamonds + ".intval($m_config['share_ticket'])." where id =".$user_id;
  588. $data['diamonds'] =intval($m_config['share_ticket']);
  589. $ticket_name = '钻石';
  590. }
  591. $GLOBALS['db']->query($sql);//增加用户印票或钻石
  592. user_deal_to_reids(array($user_id));//同步用户redis
  593. //请求返回信息
  594. $root['share_award'] =intval($m_config['share_ticket']);
  595. $root['share_award_type'] = $ticket_name;
  596. $root['share_award_info'] ='分享直播获得'.$ticket_name.intval($m_config['share_ticket']);
  597. //写入用户日志
  598. $data['log_admin_id'] = 0;
  599. $data['video_id'] = $room_id;
  600. $param['type'] = 4;//类型 0表示充值 1表示提现 2赠送道具 3 兑换印票 4 分享获得印票
  601. $log_msg ="通过".$type.'分享直播间'.$room_id.',获得'.intval($m_config['share_ticket']).$ticket_name;
  602. account_log_com($data,$user_id,$log_msg,$param);
  603. }
  604. }
  605. }
  606. ajax_return($root);
  607. }
  608. public function apns()
  609. {
  610. $root = array();
  611. $root['status'] = 1;
  612. //$GLOBALS['user_info']['id'] = 1;
  613. if(!$GLOBALS['user_info']){
  614. $root['error'] = "用户未登陆,请先登陆.";
  615. $root['status'] = 0;
  616. $root['user_login_status'] = 0;//有这个参数: user_login_status = 0 时,表示服务端未登陆、要求登陆,操作
  617. }else{
  618. $user_id = intval($GLOBALS['user_info']['id']);//用户ID
  619. $apns_code = addslashes($_REQUEST['apns_code']);
  620. //apns_code 友盟消息推送服务对设备的唯一标识。Android的device_token是44位字符串, iOS的device-token是64位
  621. //device_type 1:android; 2:ios
  622. if (strlen($apns_code) == 44){
  623. $device_type = 1;
  624. }else if (strlen($apns_code) == 64){
  625. $device_type = 2;
  626. }else{
  627. $device_type = 0;
  628. }
  629. $sql = 'update '.DB_PREFIX."user set apns_code ='".$apns_code."',device_type='".$device_type."' where id =".$user_id;
  630. $GLOBALS['db']->query($sql);
  631. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/UserRedisService.php');
  632. $user_redis = new UserRedisService();
  633. $data['apns_code'] = $apns_code;
  634. $data['device_type'] = $device_type;
  635. $user_redis->update_db($user_id,$data);
  636. }
  637. ajax_return($root);
  638. }
  639. public function user_home(){
  640. $root = array();
  641. //$GLOBALS['user_info']['id'] = 286;
  642. if(!$GLOBALS['user_info']){
  643. $root['error'] = "用户未登陆,请先登陆.";
  644. $root['status'] = 0;
  645. $root['user_login_status'] = 0;//有这个参数: user_login_status = 0 时,表示服务端未登陆、要求登陆,操作
  646. }else{
  647. $user_id = intval($GLOBALS['user_info']['id']);//用户ID
  648. $to_user_id = intval($_REQUEST['to_user_id']);//被查看的用户id
  649. if ($to_user_id == 0){
  650. $to_user_id = $user_id;
  651. }
  652. $root = getuserinfo($user_id,0,$to_user_id);
  653. $root['status'] = 1;
  654. }
  655. ajax_return($root);
  656. }
  657. //直播回看
  658. public function user_review(){
  659. $root = array();
  660. //$GLOBALS['user_info']['id'] = 1;
  661. $to_user_id = intval($_REQUEST['to_user_id']);//被查看的用户id
  662. if ($to_user_id == 0){
  663. $to_user_id = intval($GLOBALS['user_info']['id']);
  664. }
  665. $sort = intval($_REQUEST['sort']);//排序类型; 0:最新;1:最热
  666. $page = intval($_REQUEST['p']);//取第几页数据
  667. if($page==0)$page = 1;
  668. $page_size=10;
  669. $limit = (($page-1)*$page_size).",".$page_size;
  670. $sort_field = "vh.begin_time desc";
  671. if ($sort == 1){
  672. $sort_field = "vh.max_watch_number desc";
  673. }
  674. //video_count
  675. if($to_user_id ==intval($GLOBALS['user_info']['id'])){
  676. $sql = "select vh.id,vh.title,vh.begin_time,vh.max_watch_number,vh.video_vid,vh.video_type,vh.channelid,vh.create_time,u.id as user_id,u.head_image,u.nick_name from ".DB_PREFIX."video_history as vh left join ".DB_PREFIX."user as u on u.id= vh.user_id where vh.group_id!='' and vh.is_delete = 0 and vh.is_del_vod = 0 and vh.user_id = '".$to_user_id."' order by ".$sort_field." limit ".$limit;
  677. }else{
  678. $sql = "select vh.id,vh.title,vh.begin_time,vh.max_watch_number,vh.video_vid,vh.video_type,vh.channelid,vh.create_time,u.id as user_id,u.head_image,u.nick_name from ".DB_PREFIX."video_history as vh left join ".DB_PREFIX."user as u on u.id= vh.user_id where vh.group_id!='' and vh.is_delete = 0 and vh.is_del_vod = 0 and vh.is_live_pay = 0 and user_id = '".$to_user_id."' order by ".$sort_field." limit ".$limit;
  679. }
  680. $list = array();
  681. $list_arr = array();
  682. $list_info = $GLOBALS['db']->getAll($sql);
  683. foreach ( $list_info as $k => $v )
  684. {
  685. /*//判断视频存在
  686. fanwe_require(APP_ROOT_PATH . 'mapi/lib/core/video_factory.php');
  687. $video_factory = new VideoFactory();
  688. if($v['video_type'] == 1 && $v['channelid'])
  689. {
  690. if(strlen($v['channelid'])>20){
  691. $fileName = $v['channelid'];
  692. $ret = $video_factory->DescribeVodPlayInfo($fileName);
  693. }else{
  694. $ret = $video_factory->GetVodRecordFiles($v['channelid'], $v['create_time']);
  695. }
  696. }else{
  697. $fileName = $v['id'] . '_' . to_date($v['begin_time'],'Y-m-d-H');
  698. $ret = $video_factory->DescribeVodPlayInfo($fileName);
  699. }
  700. if($ret['codeDesc'] == 'Success'){
  701. $list_arr = $v;
  702. $list_arr['head_image'] = get_spec_image($v['head_image'],150,150);
  703. $list_arr['begin_time_format'] = format_show_date($v['begin_time']);
  704. if ($v['max_watch_number'] > 10000){
  705. $list_arr['watch_number_format'] = round($v['max_watch_number']/10000,2)."万";
  706. }else{
  707. $list_arr['watch_number_format'] = $v['max_watch_number'];
  708. }
  709. $list_arr['max_watch_number'] = $v['max_watch_number'];
  710. if($v['title'] == '')
  711. $list_arr['title'] = "....";
  712. $list[] = $list_arr;
  713. }else{
  714. //会误删
  715. $sql = "update ".DB_PREFIX."video_history set is_del_vod = 1 where id =".$v['id'];
  716. //$GLOBALS['db']->query($sql);
  717. }*/
  718. $list_arr = $v;
  719. $list_arr['head_image'] = get_spec_image($v['head_image'],150,150);
  720. $list_arr['begin_time_format'] = format_show_date($v['begin_time']);
  721. if ($v['max_watch_number'] > 10000){
  722. $list_arr['watch_number_format'] = round($v['max_watch_number']/10000,2)."万";
  723. }else{
  724. $list_arr['watch_number_format'] = $v['max_watch_number'];
  725. }
  726. $list_arr['max_watch_number'] = $v['max_watch_number'];
  727. if($v['title'] == '')
  728. $list_arr['title'] = "....";
  729. $list[] = $list_arr;
  730. }
  731. $root['list'] = $list;
  732. if($to_user_id ==intval($GLOBALS['user_info']['id'])){
  733. $sql = "select count(*) from ".DB_PREFIX."video_history as vh left join ".DB_PREFIX."user as u on u.id= vh.user_id where vh.group_id!='' and vh.is_delete = 0 and vh.is_del_vod = 0 and vh.user_id = '".$to_user_id."' order by ".$sort_field;
  734. }else{
  735. $sql = "select count(*) from ".DB_PREFIX."video_history as vh left join ".DB_PREFIX."user as u on u.id= vh.user_id where vh.group_id!='' and vh.is_delete = 0 and vh.is_del_vod = 0 and vh.is_live_pay = 0 and user_id = '".$to_user_id."' order by ".$sort_field;
  736. }
  737. $count = $GLOBALS['db']->getOne($sql);
  738. //$count = count($list);
  739. if ($count >= $page_size)
  740. $root['has_next'] = 1;
  741. else
  742. $root['has_next'] = 0;
  743. $root['count'] = $count;
  744. if($to_user_id ==intval($GLOBALS['user_info']['id'])&&$page==1){
  745. $sql = "update ".DB_PREFIX."user set video_count = ".$root['count']." where id = ".intval($GLOBALS['user_info']['id'])." and video_count!=".$root['count'];
  746. $GLOBALS['db']->query($sql);
  747. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/BaseRedisService.php');
  748. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/UserRedisService.php');
  749. $user_redis = new UserRedisService();
  750. $user_data = array();
  751. $user_data['video_count'] = $root['count'];
  752. $user_redis->update_db(intval($GLOBALS['user_info']['id']), $user_data);
  753. }
  754. $root['page'] = $page;
  755. $root['status'] = 1;
  756. ajax_return($root);
  757. }
  758. /**
  759. * 设置黑名单
  760. */
  761. public function set_black(){
  762. $root = array();
  763. //$GLOBALS['user_info']['id'] = 269;
  764. if(!$GLOBALS['user_info']){
  765. $root['error'] = "用户未登陆,请先登陆.";
  766. $root['status'] = 0;
  767. $root['user_login_status'] = 0;//有这个参数: user_login_status = 0 时,表示服务端未登陆、要求登陆,操作
  768. }else{
  769. //
  770. $user_id = intval($GLOBALS['user_info']['id']);//当前用户;
  771. $to_user_id = intval($_REQUEST['to_user_id']);//被关注或取消关注的用户
  772. if($user_id!=$to_user_id){
  773. $root = set_black($user_id,$to_user_id);
  774. }else{
  775. $root['error'] = "不能设置自己!";
  776. $root['status'] = 0;
  777. }
  778. }
  779. ajax_return($root);
  780. }
  781. /**
  782. * 搜索用户列表
  783. */
  784. public function search(){
  785. //$GLOBALS['user_info']['id'] = 269;
  786. $root = array();
  787. $root['status'] = 1;
  788. if(false){
  789. $root['error'] = "用户未登陆,请先登陆.";
  790. $root['status'] = 2;
  791. $root['user_login_status'] = 0;//有这个参数: user_login_status = 0 时,表示服务端未登陆、要求登陆,操作
  792. }else{
  793. //
  794. $user_id = intval($GLOBALS['user_info']['id']);//当前用户;
  795. $keyword = strim($_REQUEST['keyword']);//搜索关键字
  796. if ($keyword != ""){
  797. $page = intval($_REQUEST['p']);//取第几页数据
  798. if($page==0)$page = 1;
  799. $page_size=20;
  800. $limit = (($page-1)*$page_size).",".$page_size;
  801. if ($page == 1){
  802. if (intval($keyword) > 0){//如果搜索关键字为数字
  803. //搜索ID,昵称,靓号,不为机器人。
  804. $sql = "select u.id as user_id,u.nick_name,u.signature,u.sex,u.head_image,u.user_level,u.v_icon,u.fans_count from ".DB_PREFIX."user u where u.id = ".$keyword." and u.is_robot=0 limit 0,1
  805. union select u.id as user_id,u.nick_name,u.signature,u.sex,u.head_image,u.user_level,u.v_icon,u.fans_count from ".DB_PREFIX."user u where u.luck_num = ".$keyword." and u.is_robot=0 limit 0,1
  806. union select u.id as user_id,u.nick_name,u.signature,u.sex,u.head_image,u.user_level,u.v_icon,u.fans_count from ".DB_PREFIX."user u where u.nick_name = '".$keyword."' and u.is_robot=0 limit 20";
  807. }else{
  808. $sql = "select u.id as user_id,u.nick_name,u.signature,u.sex,u.head_image,u.user_level,u.v_icon,u.fans_count from ".DB_PREFIX."user u where u.nick_name = '".$keyword."' and u.is_robot=0 limit ".$limit;
  809. }
  810. }else{
  811. $sql = "select u.id as user_id,u.nick_name,u.signature,u.sex,u.head_image,u.user_level,u.v_icon,u.fans_count from ".DB_PREFIX."user u where u.nick_name = '".$keyword."' and u.is_robot=0 limit ".$limit;
  812. }
  813. //查询用户列表,修改成 从只读数据库中取,但不是高效做法;主并发时,可以加入阿里云的搜索服务
  814. $list = $GLOBALS['db']->getAll($sql,true,true);
  815. $keys =array();
  816. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/UserFollwRedisService.php');
  817. $user_redis = new UserFollwRedisService($user_id);
  818. $keys = $user_redis->following();
  819. foreach($list as $k=>$v){
  820. if(in_array($v['user_id'],$keys)){
  821. $list[$k]['follow_id'] = $v['user_id'];
  822. }else{
  823. $list[$k]['follow_id'] = 0;
  824. }
  825. $list[$k]['head_image'] = get_spec_image($v['head_image']);
  826. $list[$k]['signature'] = htmlspecialchars_decode($list[$k]['signature']);
  827. $list[$k]['nick_name'] = htmlspecialchars_decode($list[$k]['nick_name']);
  828. }
  829. $root['list'] = $list;
  830. if (count($list) == $page_size)
  831. $root['has_next'] = 1;
  832. else
  833. $root['has_next'] = 0;
  834. $root['page'] = $page;//
  835. }else{
  836. $root['has_next'] = 0;
  837. $root['list'] = array();
  838. $root['page'] = 0;//
  839. }
  840. }
  841. ajax_return($root);
  842. }
  843. /**
  844. * 批量导入未同步的用户到im
  845. */
  846. public function account_import(){
  847. $root = array();
  848. $root['status'] = 1;
  849. fanwe_require(APP_ROOT_PATH.'system/tim/TimApi.php');
  850. $api = createTimAPI();
  851. $sql = "select id,nick_name,head_image from ".DB_PREFIX."user where synchronize = 0 limit 10";
  852. $list = $GLOBALS['db']->getAll($sql);
  853. foreach ( $list as $k => $v )
  854. {
  855. $face_url = get_spec_image($v['head_image']);
  856. $ret = $api->account_import((string)$v['id'], $v['nick_name'], $face_url);
  857. if ($ret['ActionStatus'] == 'OK'){
  858. $sql = 'update '.DB_PREFIX."user set synchronize =1 where id =".$v['id'];
  859. $GLOBALS['db']->query($sql);
  860. }else{
  861. $root['ret'][$v['id']] = $ret;
  862. }
  863. //print_r($ret);
  864. }
  865. ajax_return($root);
  866. }
  867. //允许直播的话,未同意状态改为同意
  868. public function agree(){
  869. $user_id = intval($GLOBALS['user_info']['id']);
  870. if($user_id){
  871. $GLOBALS['db']->query("update ".DB_PREFIX."user set is_agree =1 where id=".$user_id." and is_agree = 0 ");
  872. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/UserRedisService.php');
  873. $user_redis = new UserRedisService();
  874. $data['is_agree'] = 1;
  875. $user_redis->update_db($user_id, $data);
  876. }
  877. $root['status'] =1;
  878. $root['error'] ='';
  879. ajax_return($root);
  880. }
  881. /**
  882. * 一次性取出,我关注的用户列表
  883. */
  884. public function my_follow(){
  885. $root = array();
  886. $root['status'] = 1;
  887. // $GLOBALS['user_info']['id'] = 290;
  888. if(!$GLOBALS['user_info']){
  889. $root['error'] = "用户未登陆,请先登陆.";
  890. $root['status'] = 0;
  891. $root['user_login_status'] = 0;//有这个参数: user_login_status = 0 时,表示服务端未登陆、要求登陆,操作
  892. }else{
  893. $user_id = intval($GLOBALS['user_info']['id']);//id
  894. // $sql = "select f.podcast_id as user_id from ".DB_PREFIX."focus f where f.user_id = ".$user_id;
  895. //
  896. // //$root['sql'] = $sql;
  897. //
  898. // $list = $GLOBALS['db']->getAll($sql);
  899. // $root['list'] = $list;
  900. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/UserFollwRedisService.php');
  901. $user_redis = new UserFollwRedisService($user_id);
  902. $root['list'] = $user_redis->get_follonging_user($user_id,1,1000);
  903. }
  904. ajax_return($root);
  905. }
  906. /**
  907. * 好友,相互关注的用户;用于私密直播时,添加的用户列表
  908. */
  909. public function friends(){
  910. $root = array();
  911. $root['status'] = 1;
  912. //$GLOBALS['user_info']['id'] = 278;
  913. if(!$GLOBALS['user_info']){
  914. $root['error'] = "用户未登陆,请先登陆.";
  915. $root['status'] = 0;
  916. $root['user_login_status'] = 0;//有这个参数: user_login_status = 0 时,表示服务端未登陆、要求登陆,操作
  917. }else{
  918. $user_id = intval($GLOBALS['user_info']['id']);//id
  919. $video_id = intval($_REQUEST['room_id']);
  920. $page = intval($_REQUEST['p']);//取第几页数据
  921. if($page==0){
  922. $page = 1;
  923. }
  924. $page_size=20;
  925. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/UserFollwRedisService.php');
  926. $user_redis = new UserFollwRedisService($user_id);
  927. $root = $user_redis->get_private_user($page,$page_size);
  928. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/VideoRedisService.php');
  929. $video_redis = new VideoRedisService();
  930. $video_data = $video_redis->getRow_db($video_id,array('group_id','user_id'));
  931. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/VideoViewerRedisService.php');
  932. $video_viewer_redis = new VideoViewerRedisService();
  933. $group_id = $video_data['group_id'];//聊天群id
  934. if($group_id) {
  935. $users = $video_viewer_redis->get_viewer_list($group_id, $page);
  936. if($users['list']){
  937. $user_ids = array_column($users['list'],'user_id');
  938. $friends = $root['list'];
  939. foreach($friends as $k=>$v){
  940. if(in_array($v['user_id'],$user_ids) || $v['user_id']==$video_data['user_id']){
  941. unset($friends[$k]);
  942. }
  943. }
  944. $root['list'] = array_values($friends);
  945. }
  946. }
  947. }
  948. ajax_return($root);
  949. }
  950. /**
  951. * 获得用户基本信息(比如:固化的信息比如:头像,性别,昵称,等级,签名等)
  952. */
  953. public function baseinfo(){
  954. $root = array();
  955. //$GLOBALS['user_info']['id'] = 292;
  956. if(!$GLOBALS['user_info']){
  957. $root['error'] = "用户未登陆,请先登陆.";
  958. $root['status'] = 0;
  959. $root['user_login_status'] = 0;//有这个参数: user_login_status = 0 时,表示服务端未登陆、要求登陆,操作
  960. }else{
  961. $user_id = intval($GLOBALS['user_info']['id']);
  962. $user_ids = strim($_REQUEST['user_ids']);//字符串类型的用户id 23,123,3455 以英文逗号分割的字符串 ,一次不能大于100个用户
  963. if ($user_ids == ''){
  964. $user_ids = $user_id;
  965. }
  966. //将选中的:私聊 数据添加到数据库中
  967. $user_list = explode(',',$user_ids);
  968. if (count($user_list) > 100){
  969. $root['status'] =0;
  970. $root['error'] ='一次不能大于100个用户';
  971. }else{
  972. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/UserRedisService.php');
  973. $user_redis = new UserRedisService();
  974. $list = $user_redis->get_m_user($user_list);
  975. /*
  976. $fields = array('id','is_agree','video_count','is_authentication','nick_name','signature','sex','province','city','head_image','ticket','use_diamonds','user_level','v_type','v_explain','v_icon','is_remind');
  977. foreach ( $user_list as $k => $v )
  978. {
  979. $userinfo = $user_redis->getRow_db($v,$fields);
  980. $userinfo['user_id'] = $v;
  981. $list[] = $userinfo;
  982. }
  983. $sql = "select id as user_id,is_agree,is_authentication,nick_name,signature,sex,province,city,head_image,user_level,v_type,v_explain,v_icon from ".DB_PREFIX."user where id in (".$user_ids.")";
  984. $list = $GLOBALS['db']->getAll($sql);
  985. foreach ( $list as $k => $v )
  986. {
  987. $list[$k]['head_image'] = get_abs_img_root($v['head_image']);
  988. }
  989. */
  990. $root['list'] = $list;
  991. $root['status'] = 1;
  992. }
  993. }
  994. ajax_return($root);
  995. }
  996. /**
  997. * app呼醒跟进入后台时调用【用来统计用户在线时长】
  998. */
  999. function state_change(){
  1000. $root = array();
  1001. $root['status'] = 1;
  1002. if(!$GLOBALS['user_info']){
  1003. $root['error'] = "用户未登陆,请先登陆.";
  1004. $root['status'] = 0;
  1005. $root['user_login_status'] = 0;//有这个参数: user_login_status = 0 时,表示服务端未登陆、要求登陆,操作
  1006. }else{
  1007. $user_id = intval($GLOBALS['user_info']['id']);
  1008. $action = strim($_REQUEST['action']);
  1009. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/UserRedisService.php');
  1010. $user_redis = new UserRedisService();
  1011. if (strtolower($action) == 'login'){
  1012. $data = array('is_online'=>1,'login_time'=>to_date(NOW_TIME));
  1013. $GLOBALS['db']->autoExecute(DB_PREFIX."user", $data,"UPDATE", 'id='.$user_id);
  1014. $user_redis->update_db($user_id, $data);
  1015. }else{
  1016. $data = array('is_online'=>0,'login_time'=>to_date(NOW_TIME),'logout_time'=>to_date(NOW_TIME));
  1017. $user = $user_redis->getRow_db($user_id, array('login_time','logout_time','online_time'));
  1018. $login_time = to_timespan($user['login_time']);
  1019. if ($login_time == 0){
  1020. $data['login_time'] = to_date(NOW_TIME);
  1021. }
  1022. //计算在线时长
  1023. $online = NOW_TIME - $login_time;
  1024. if ($online > 7200){
  1025. //异常数据,一次不可能超过8小时
  1026. $online = 0;
  1027. }
  1028. $data['online_time'] = $user['online_time'] + $online;
  1029. $GLOBALS['db']->autoExecute(DB_PREFIX."user", $data,"UPDATE", 'id='.$user_id);
  1030. if($GLOBALS['db']->affected_rows()){
  1031. $user_redis->update_db($user_id, $data);
  1032. //更新用户等级
  1033. $user_info = $user_redis->getRow_db($user_id,array('id','score','online_time','user_level'));
  1034. user_leverl_syn($user_info);
  1035. }
  1036. }
  1037. }
  1038. ajax_return($root);
  1039. }
  1040. //上传展示图片
  1041. public function do_publish_img(){
  1042. $root = array();
  1043. if(!$GLOBALS['user_info']){
  1044. $root['error'] = "用户未登陆,请先登陆.";
  1045. $root['status'] = 2;
  1046. api_ajax_return($root);
  1047. }
  1048. $list = json_decode($_REQUEST['data'],TRUE);
  1049. if(!is_array($list)){
  1050. $root['error'] = "请上传图片!";
  1051. $root['status'] = 0;
  1052. api_ajax_return($root);
  1053. }
  1054. $user_id = $GLOBALS['user_info']['id'];
  1055. $where = ' id = '.$user_id;
  1056. $imgs = $GLOBALS['db']->getOne("select show_image from ".DB_PREFIX."user where ".$where);
  1057. if($imgs==''){
  1058. $imgs_array = $list;
  1059. }else{
  1060. $imgs_array = unserialize($imgs);
  1061. if(is_array($list)){
  1062. $imgs_array = array_merge($imgs_array,$list);
  1063. }else{
  1064. array_push($imgs_array,$list);
  1065. }
  1066. }
  1067. $show_image = serialize($imgs_array);
  1068. $data['show_image'] = $show_image;
  1069. $res = $GLOBALS['db']->autoExecute(DB_PREFIX."user",$data,'UPDATE',$where);
  1070. if($res){
  1071. $root = array(
  1072. 'status'=>1,
  1073. 'error'=>'图片上传成功'
  1074. );
  1075. $root['show_image'] = array();
  1076. foreach($imgs_array as $k=>$v){
  1077. if($v){
  1078. $root['show_image'][] = array(
  1079. 'url'=>get_spec_image($v,100,100,1),
  1080. 'is_model'=>0,
  1081. 'orginal_url'=>get_spec_image($v)
  1082. );
  1083. }
  1084. }
  1085. }else{
  1086. $root = array(
  1087. 'status'=>0,
  1088. 'error'=>'图片上传失败'
  1089. );
  1090. }
  1091. api_ajax_return($root);
  1092. }
  1093. //删除展示图片
  1094. public function del_publish_img(){
  1095. if(!$GLOBALS['user_info']){
  1096. $root['error'] = "用户未登陆,请先登陆.";
  1097. $root['status'] = 2;
  1098. api_ajax_return($root);
  1099. }
  1100. $url = strim($_REQUEST['url']);
  1101. if(!$url){
  1102. $root['error'] = "删除信息提交失败!";
  1103. $root['status'] = 0;
  1104. api_ajax_return($root);
  1105. }
  1106. $oss_domain = $GLOBALS['distribution_cfg']['OSS_DOMAIN'].'/public/';
  1107. $url = str_replace($oss_domain, "./public/", $url);
  1108. $user_id = intval($GLOBALS['user_info']['id']);
  1109. $where = ' id = '.$user_id;
  1110. $imgs = $GLOBALS['db']->getOne("select show_image from ".DB_PREFIX."user where ".$where);
  1111. $imgs_array = unserialize($imgs);
  1112. $key = array_search($url,$imgs_array);
  1113. if($key!==false){
  1114. unset($imgs_array[$key]);
  1115. if(count($imgs_array)>0){
  1116. $show_image = serialize(array_values($imgs_array));
  1117. }else{
  1118. $show_image = '';
  1119. }
  1120. $data['show_image'] = $show_image;
  1121. $res = $GLOBALS['db']->autoExecute(DB_PREFIX."user",$data,'UPDATE',$where);
  1122. if($res){
  1123. $root = array(
  1124. 'status'=>1,
  1125. 'error'=>'图片删除成功!'
  1126. );
  1127. }else{
  1128. $root = array(
  1129. 'status'=>0,
  1130. 'error'=>'图片删除失败!'
  1131. );
  1132. }
  1133. }else{
  1134. $root = array(
  1135. 'status'=>0,
  1136. 'error'=>'图片不存在!'
  1137. );
  1138. }
  1139. api_ajax_return($root);
  1140. }
  1141. /**
  1142. * 获得用户公开信息;不传identifier时,则获得当前登陆用户的信息
  1143. */
  1144. public function weibo_userinfo(){
  1145. $root = array();
  1146. $to_user_id = intval($_REQUEST['to_user_id']);//被查看的用户ID
  1147. if(!$to_user_id){
  1148. if(!$GLOBALS['user_info']){
  1149. $root['error'] = "用户未登陆,请先登陆.";
  1150. $root['status'] = 0;
  1151. api_ajax_return($root);
  1152. }else{
  1153. $to_user_id = intval($GLOBALS['user_info']['id']);
  1154. }
  1155. }
  1156. if(!$GLOBALS['user_info']){
  1157. $user_id = 0;
  1158. }else{
  1159. $user_id = intval($GLOBALS['user_info']['id']);
  1160. }
  1161. if($user_id!==$to_user_id&&$user_id>0){
  1162. $sql = "select id from ".DB_PREFIX."black where black_user_id = ".$to_user_id." and user_id = ".$user_id;
  1163. $black_id = $GLOBALS['db']->getOne($sql);
  1164. if($black_id){
  1165. $root['error'] = "您与对方是拉黑关系,无法进行其他操作!";
  1166. $root['status'] = 0;
  1167. $root['is_black'] = 1;
  1168. api_ajax_return($root);
  1169. }
  1170. }
  1171. fanwe_require(APP_ROOT_PATH.'mapi/xr/core/common.php');
  1172. $page = intval($_REQUEST['page'])?intval($_REQUEST['page']):1;
  1173. $page_size =20;
  1174. $root = get_weibo_userinfo($to_user_id,$user_id,$page,$page_size,$this->image_pay_type);
  1175. $root['is_black'] = 0;
  1176. $root['status'] = 1;
  1177. ajax_return($root);
  1178. }
  1179. //我的微博动态
  1180. public function weibo_mine(){
  1181. if(!$GLOBALS['user_info']){
  1182. $root['error'] = "用户未登陆,请先登陆.";
  1183. $root['status'] = 0;
  1184. api_ajax_return($root);
  1185. }
  1186. // $to_user_id = intval($GLOBALS['user_info']['id']);
  1187. $user_id = intval($GLOBALS['user_info']['id']);
  1188. fanwe_require(APP_ROOT_PATH.'mapi/xr/core/common.php');
  1189. $page = intval($_REQUEST['page'])?intval($_REQUEST['page']):1;
  1190. $page_size =20;
  1191. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/UserFollwRedisService.php');
  1192. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/UserRedisService.php');
  1193. $root['list'] = $list = load_auto_cache("select_weibo_mine_list",array('page'=>$page,'page_size'=>$page_size,'user_id'=>$user_id));
  1194. if(count($list)==$page_size){
  1195. $root['has_next'] = 1;
  1196. }else{
  1197. $root['has_next'] = 0;
  1198. }
  1199. $root['page'] = $page;
  1200. $root['status'] = 1;
  1201. ajax_return($root);
  1202. }
  1203. //获取微信的状态
  1204. public function weixin_status(){
  1205. if(!$GLOBALS['user_info']){
  1206. $root['error'] = "用户未登陆,请先登陆.";
  1207. $root['status'] = 2;
  1208. api_ajax_return($root);
  1209. }
  1210. $user_id = $GLOBALS['user_info']['id'];
  1211. $weixin = $GLOBALS['db']->getRow("select weixin_price,weixin_account from ".DB_PREFIX."user where id = ".$user_id);
  1212. $weixin_price = $weixin['weixin_price'];
  1213. $weixin_account = $weixin['weixin_account'];
  1214. if(intval($weixin_price)>0){
  1215. $weixin_status = 1;
  1216. $root['weixin_account'] = $weixin_account;
  1217. $root['weixin_price'] = $weixin_price;
  1218. }else{
  1219. $root['weixin_account'] = '';
  1220. $root['weixin_price'] = 0;
  1221. $weixin_status = 0;
  1222. }
  1223. $root['weixin_status'] = $weixin_status;
  1224. $root['error'] = "";
  1225. $root['status'] = 1;
  1226. api_ajax_return($root);
  1227. }
  1228. //设置置顶
  1229. public function set_top(){
  1230. if(!$GLOBALS['user_info']){
  1231. $root['error'] = "用户未登陆,请先登陆.";
  1232. $root['status'] = 2;
  1233. api_ajax_return($root);
  1234. }
  1235. $weibo_id = $_REQUEST['weibo_id'];
  1236. if(!$weibo_id){
  1237. $root['error'] = "动态ID错误!";
  1238. $root['status'] = 2;
  1239. api_ajax_return($root);
  1240. }
  1241. $user_id = $GLOBALS['user_info']['id'];
  1242. $weibo_user_id = $GLOBALS['db']->getOne("select user_id from ".DB_PREFIX."weibo where id = ".$weibo_id);
  1243. if($weibo_user_id!=$user_id){
  1244. $root['error'] = "您没有权限进行该操作!";
  1245. $root['status'] = 0;
  1246. api_ajax_return($root);
  1247. }
  1248. $set_id = $GLOBALS['db']->getOne("select id from ".DB_PREFIX."weibo where user_id = ".$user_id." and is_top = 1");
  1249. $where = ' id = '.$weibo_id;
  1250. if($set_id){
  1251. if($weibo_id==$set_id){
  1252. $data['is_top'] = 0;
  1253. //$where = ' id = '.$weibo_id;
  1254. $res = $GLOBALS['db']->autoExecute(DB_PREFIX."weibo",$data,'UPDATE',$where);
  1255. }else{
  1256. $GLOBALS['db']->autoExecute(DB_PREFIX."weibo",array('is_top'=>0),'UPDATE',' user_id = '.$user_id.' and is_top = 1');
  1257. $data['is_top'] = 1;
  1258. //$where = ' id = '.$weibo_id;
  1259. $res = $GLOBALS['db']->autoExecute(DB_PREFIX."weibo",$data,'UPDATE',$where);
  1260. }
  1261. }else{
  1262. $data['is_top'] = 1;
  1263. $res = $GLOBALS['db']->autoExecute(DB_PREFIX."weibo",$data,'UPDATE',$where);
  1264. }
  1265. if($res){
  1266. $info = $data['is_top']?'置顶成功':'取消置顶成功';
  1267. $root = array(
  1268. 'status'=>1,
  1269. 'error'=>$info,
  1270. 'is_top'=>$data['is_top']
  1271. );
  1272. }else{
  1273. $root = array(
  1274. 'status'=>0,
  1275. 'error'=>'操作失败'
  1276. );
  1277. }
  1278. api_ajax_return($root);
  1279. }
  1280. //设置关注 或取消关注
  1281. public function set_focus(){
  1282. if(!$GLOBALS['user_info']){
  1283. $root['error'] = "用户未登陆,请先登陆.";
  1284. $root['status'] = 0;
  1285. api_ajax_return($root);
  1286. }
  1287. $to_user_id = intval($_REQUEST['to_user_id']);
  1288. if(!$to_user_id){
  1289. $root['error'] = "用户ID错误!";
  1290. $root['status'] = 0;
  1291. api_ajax_return($root);
  1292. }
  1293. $user_id = $GLOBALS['user_info']['id'];
  1294. $root = redis_set_follow($user_id,$to_user_id);
  1295. $root['status'] = 1;
  1296. $root['error'] = '';
  1297. api_ajax_return($root);
  1298. }
  1299. //取消动态
  1300. public function del_weibo(){
  1301. if(!$GLOBALS['user_info']){
  1302. $root['error'] = "用户未登陆,请先登陆.";
  1303. $root['status'] = 0;
  1304. api_ajax_return($root);
  1305. }
  1306. $weibo_id = $_REQUEST['weibo_id'];
  1307. if(!$weibo_id){
  1308. $root['error'] = "动态ID错误!";
  1309. $root['status'] = 0;
  1310. api_ajax_return($root);
  1311. }
  1312. $user_id = $GLOBALS['user_info']['id'];
  1313. $res = $GLOBALS['db']->query("delete from ".DB_PREFIX."weibo where id = ".$weibo_id." and user_id = ".$user_id);
  1314. if($res){
  1315. $root['status'] = 1;
  1316. $root['error'] = '';
  1317. }else{
  1318. $root['status'] = 0;
  1319. $root['error'] = '删除失败!';
  1320. }
  1321. api_ajax_return($root);
  1322. }
  1323. //删除评论
  1324. public function del_comment(){
  1325. if(!$GLOBALS['user_info']){
  1326. $root['error'] = "用户未登陆,请先登陆.";
  1327. $root['status'] = 0;
  1328. api_ajax_return($root);
  1329. }
  1330. $user_id =intval( $GLOBALS['user_info']['id']);
  1331. $comment_id = intval($_REQUEST['comment_id']);
  1332. $info = $GLOBALS['db']->getRow("select wc.user_id as comment_user_id,w.user_id as andmin_id,w.id as weibo_id from ".DB_PREFIX."weibo_comment as wc left join ".DB_PREFIX."weibo as w
  1333. on wc.weibo_id = w.id where wc.comment_id =".$comment_id);
  1334. if(!$info){
  1335. $root['error'] = "该评论不存在!.";
  1336. $root['status'] = 0;
  1337. api_ajax_return($root);
  1338. }
  1339. if($info['comment_user_id']==$user_id||$info['andmin_id']==$user_id){
  1340. $re = $GLOBALS['db']->query("delete from ".DB_PREFIX."weibo_comment where comment_id = ".$comment_id);
  1341. if($re){
  1342. $root['error'] = "删除成功.";
  1343. $root['status'] = 1;
  1344. $weibo_id = $info['weibo_id'];
  1345. $comment_count = $GLOBALS['db']->getOne("select count(*) from ".DB_PREFIX."weibo_comment where weibo_id = ".$weibo_id." and type = 1 and is_del = 0");
  1346. $root['comment_count'] = $comment_count;
  1347. $GLOBALS['db']->query("update ".DB_PREFIX."weibo set comment_count = $comment_count where id = ".$weibo_id);
  1348. }else{
  1349. $root['error'] = "删除失败.";
  1350. $root['status'] = 0;
  1351. }
  1352. api_ajax_return($root);
  1353. }else{
  1354. $root['error'] = "您没有删除该评论权限!.";
  1355. $root['status'] = 0;
  1356. api_ajax_return($root);
  1357. }
  1358. }
  1359. //发表评论
  1360. public function publish_comment(){
  1361. if(!$GLOBALS['user_info']){
  1362. $root['error'] = "用户未登陆,请先登陆.";
  1363. $root['status'] = 0;
  1364. api_ajax_return($root);
  1365. }
  1366. $weibo_id = intval($_REQUEST['weibo_id']);
  1367. if(!$weibo_id){
  1368. $root['error'] = "ID错误!";
  1369. $root['status'] = 0;
  1370. api_ajax_return($root);
  1371. }
  1372. $data['weibo_id'] = $weibo_id;
  1373. $weibo_user_id = $GLOBALS['db']->getOne("select user_id from ".DB_PREFIX."weibo where id = ".$weibo_id);
  1374. if(!$weibo_user_id){
  1375. $root['error'] = "小视屏不存在或已被删除!";
  1376. $root['status'] = 0;
  1377. api_ajax_return($root);
  1378. }
  1379. $data['weibo_user_id'] = $weibo_user_id;
  1380. $user_id =intval( $GLOBALS['user_info']['id']);
  1381. //$to_user_id = intval($_REQUEST['to_user_id']);
  1382. $type = intval($_REQUEST['type']);
  1383. $root['unlike'] =array();
  1384. $root['digg'] =array();
  1385. $root['comment'] =array();
  1386. if($type==1){
  1387. $to_comment_id = intval($_REQUEST['to_comment_id']);
  1388. if($to_comment_id){
  1389. $to_user_id = $GLOBALS['db']->getOne("select user_id from ".DB_PREFIX."weibo_comment where comment_id = ".$to_comment_id);
  1390. if(!$to_user_id){
  1391. $root['error'] = "被评论ID不存在!";
  1392. $root['status'] = 0;
  1393. api_ajax_return($root);
  1394. }
  1395. $data['to_comment_id'] = $to_comment_id;
  1396. $data['to_user_id'] = $to_user_id;
  1397. }
  1398. $content = strim($_REQUEST['content']);
  1399. if(!$content){
  1400. $root['error'] = "内容不能为空!";
  1401. $root['status'] = 0;
  1402. api_ajax_return($root);
  1403. }
  1404. $max_length = 255;
  1405. if(mb_strlen($content, 'utf-8') > $max_length) {
  1406. api_ajax_return(array('status' => 0, 'error' => "评论超过{$max_length}个字数限制"));
  1407. }
  1408. $data['user_id'] = $user_id;
  1409. $data['content'] = emoji_encode($content);
  1410. $data['type'] = $type;
  1411. $data['create_time'] = to_date(NOW_TIME);
  1412. $data['is_audit'] = 1;
  1413. $storey = $GLOBALS['db']->getOne("select count(*) from ".DB_PREFIX."weibo_comment where weibo_id = ".$weibo_id." and type = 1");
  1414. $data['storey'] = intval($storey);
  1415. $res = $GLOBALS['db']->autoExecute(DB_PREFIX."weibo_comment",$data,'INSERT');
  1416. $data['content'] = emoji_decode($content);
  1417. if($res){
  1418. $comment_id = $GLOBALS['db']->insert_id();
  1419. $root['comment'] = $data;
  1420. $root['comment']['comment_id'] = $comment_id;
  1421. $info = $GLOBALS['db']->getRow("select is_authentication,v_icon,nick_name,head_image from ".DB_PREFIX."user where id = $user_id");
  1422. $root['comment']['is_authentication'] = $info['is_authentication'];
  1423. $root['comment']['v_icon'] = $info['v_icon'];
  1424. $root['comment']['nick_name'] = emoji_decode($info['nick_name']);
  1425. $root['comment']['head_image'] = get_spec_image($info['head_image']);
  1426. $root['comment']['left_time'] = '刚刚';
  1427. $root['comment']['to_nick_name'] = '';
  1428. if($to_user_id){
  1429. $to_nick_name = $GLOBALS['db']->getOne("select nick_name from ".DB_PREFIX."user where id = $to_user_id");
  1430. $root['comment']['to_nick_name'] = emoji_decode($to_nick_name);
  1431. }
  1432. }
  1433. }else if($type == 3){
  1434. //点赞
  1435. $data['type'] = $type;
  1436. $data['user_id'] = $user_id;
  1437. $data['create_time'] = to_date(NOW_TIME);
  1438. $data['is_audit'] = 1;
  1439. //$data['to_user_id'] = $to_user_id;;
  1440. $sql = "select count(*) from ".DB_PREFIX."weibo_comment where weibo_id = ".$weibo_id." and type = 3 and user_id = ".$user_id;
  1441. $has_unlike = $GLOBALS['db']->getOne($sql);
  1442. if($has_unlike){
  1443. $sql = "delete from ".DB_PREFIX."weibo_comment where weibo_id = ".$weibo_id." and type = 3 and user_id = ".$user_id;
  1444. $res = $GLOBALS['db']->query($sql);
  1445. }else{
  1446. $res = $GLOBALS['db']->autoExecute(DB_PREFIX."weibo_comment",$data,'INSERT');
  1447. if($res){
  1448. if (defined('OPEN_SVIDEO_MODULE') && OPEN_SVIDEO_MODULE == 1) {
  1449. $sql = "delete from " . DB_PREFIX . "weibo_comment where weibo_id = " . $weibo_id . " and type = 2 and user_id = " . $user_id;
  1450. $GLOBALS['db']->query($sql);
  1451. }
  1452. $info = $GLOBALS['db']->getRow("select is_authentication,v_icon,nick_name,head_image from ".DB_PREFIX."user where id = $user_id");
  1453. $root['unlike'] = array(
  1454. 'user_id'=>$data['user_id'],
  1455. 'is_authentication'=>$info['is_authentication'],
  1456. 'v_icon' => $info['v_icon'],
  1457. 'nick_name'=>$info['nick_name'],
  1458. 'head_image'=>get_spec_image($info['head_image']),
  1459. );
  1460. }
  1461. }
  1462. }else{
  1463. //点赞
  1464. $data['type'] = $type;
  1465. $data['user_id'] = $user_id;
  1466. $data['create_time'] = to_date(NOW_TIME);
  1467. $data['is_audit'] = 1;
  1468. //$data['to_user_id'] = $to_user_id;;
  1469. $sql = "select count(*) from ".DB_PREFIX."weibo_comment where weibo_id = ".$weibo_id." and type = 2 and user_id = ".$user_id;
  1470. $has_digg = $GLOBALS['db']->getOne($sql);
  1471. if($has_digg){
  1472. $sql = "delete from ".DB_PREFIX."weibo_comment where weibo_id = ".$weibo_id." and type = 2 and user_id = ".$user_id;
  1473. $res = $GLOBALS['db']->query($sql);
  1474. }else{
  1475. $res = $GLOBALS['db']->autoExecute(DB_PREFIX."weibo_comment",$data,'INSERT');
  1476. if($res){
  1477. if (defined('OPEN_SVIDEO_MODULE') && OPEN_SVIDEO_MODULE == 1) {
  1478. $sql = "delete from " . DB_PREFIX . "weibo_comment where weibo_id = " . $weibo_id . " and type = 3 and user_id = " . $user_id;
  1479. $GLOBALS['db']->query($sql);
  1480. }
  1481. $info = $GLOBALS['db']->getRow("select is_authentication,v_icon,nick_name,head_image from ".DB_PREFIX."user where id = $user_id");
  1482. $root['digg'] = array(
  1483. 'user_id'=>$data['user_id'],
  1484. 'is_authentication'=>$info['is_authentication'],
  1485. 'v_icon' => $info['v_icon'],
  1486. 'nick_name'=>$info['nick_name'],
  1487. 'head_image'=>get_spec_image($info['head_image']),
  1488. );
  1489. }
  1490. }
  1491. }
  1492. if($res){
  1493. if($type==1){
  1494. $root['error'] = "评论发表成功!";
  1495. if($_REQUEST['test']=1){
  1496. $root['comment_id'] = $GLOBALS['db']->insert_id();
  1497. }
  1498. $root['status'] = 1;
  1499. $comment_count = $GLOBALS['db']->getOne("select count(*) from ".DB_PREFIX."weibo_comment where weibo_id = ".$weibo_id." and type = 1 and is_del = 0");
  1500. $root['comment_count'] = $comment_count;
  1501. $GLOBALS['db']->query("update ".DB_PREFIX."weibo set comment_count = $comment_count where id = ".$weibo_id);
  1502. }else if($type == 3) {
  1503. if (!$has_unlike) {
  1504. $root['error'] = "踩了一下!";
  1505. $root['has_unlike'] = 1;
  1506. } else {
  1507. $root['error'] = "取消踩一下!";
  1508. $root['has_unlike'] = 0;
  1509. $GLOBALS['db']->query("update " . DB_PREFIX . "weibo set unlike_count = unlike_count-1 where id = " . $weibo_id);
  1510. }
  1511. $sql = "select count(*) from " . DB_PREFIX . "weibo_comment where weibo_id = " . $weibo_id . " and type = 3 ";
  1512. $unlike_count = $GLOBALS['db']->getOne($sql);
  1513. $GLOBALS['db']->query("update " . DB_PREFIX . "weibo set unlike_count = " . intval($unlike_count) . " where id = " . $weibo_id);
  1514. if (defined('OPEN_SVIDEO_MODULE') && OPEN_SVIDEO_MODULE == 1) {
  1515. $sql = "select count(*) from " . DB_PREFIX . "weibo_comment where weibo_id = " . $weibo_id . " and type = 2 ";
  1516. $digg_count = $GLOBALS['db']->getOne($sql);
  1517. $GLOBALS['db']->query("update " . DB_PREFIX . "weibo set digg_count = " . intval($digg_count) . " where id = " . $weibo_id);
  1518. $root['has_digg'] = 0;
  1519. $root['digg_count'] = intval($digg_count);
  1520. }
  1521. $root['status'] = 1;
  1522. $root['unlike_count'] = intval($unlike_count);
  1523. }else{
  1524. if(!$has_digg){
  1525. $root['error'] = "点赞成功!";
  1526. $root['has_digg'] = 1;
  1527. }else{
  1528. $root['error'] = "取消点赞!";
  1529. $root['has_digg'] = 0;
  1530. $GLOBALS['db']->query("update ".DB_PREFIX."weibo set digg_count = digg_count-1 where id = ".$weibo_id);
  1531. }
  1532. if (defined('OPEN_SVIDEO_MODULE') && OPEN_SVIDEO_MODULE == 1) {
  1533. $sql = "select count(*) from " . DB_PREFIX . "weibo_comment where weibo_id = " . $weibo_id . " and type = 3 ";
  1534. $unlike_count = $GLOBALS['db']->getOne($sql);
  1535. $GLOBALS['db']->query("update " . DB_PREFIX . "weibo set unlike_count = " . intval($unlike_count) . " where id = " . $weibo_id);
  1536. $root['has_unlike'] = 0;
  1537. $root['unlike_count'] = intval($unlike_count);
  1538. }
  1539. $sql = "select count(*) from ".DB_PREFIX."weibo_comment where weibo_id = ".$weibo_id." and type = 2 ";
  1540. $digg_count = $GLOBALS['db']->getOne($sql);
  1541. $GLOBALS['db']->query("update ".DB_PREFIX."weibo set digg_count = ".intval($digg_count)." where id = ".$weibo_id);
  1542. $root['status'] = 1;
  1543. $root['digg_count'] = intval($digg_count);
  1544. }
  1545. }else{
  1546. $root['error'] = "操作失败!";
  1547. $root['status'] = 0;
  1548. }
  1549. api_ajax_return($root);
  1550. }
  1551. /**
  1552. * 举报用户 或动态
  1553. */
  1554. public function tipoff_weibo(){
  1555. $root = array();
  1556. $root['status'] = 1;
  1557. if(!$GLOBALS['user_info']){
  1558. $root['error'] = "用户未登陆,请先登陆.";
  1559. $root['status'] = 0;
  1560. $root['user_login_status'] = 0;//有这个参数: user_login_status = 0 时,表示服务端未登陆、要求登陆,操作
  1561. }else{
  1562. $to_user_id = intval($_REQUEST['to_user_id']);//被关注的举报用户ID
  1563. $type = intval($_REQUEST['type']);
  1564. $weibo_id = intval($_REQUEST['weibo_id']); //被举报的动态id
  1565. $from_user_id = intval($GLOBALS['user_info']['id']);
  1566. $where = 'from_user_id = '.$from_user_id;
  1567. if($to_user_id){
  1568. $where .= ' and to_user_id = '.$to_user_id;
  1569. }
  1570. if($weibo_id){
  1571. $where .= ' and weibo_id = '.$weibo_id;
  1572. }
  1573. $count = $GLOBALS['db']->getOne("select count(*) from ".DB_PREFIX."tipoff where $where");
  1574. if($count){
  1575. $root['error'] = "请不要重复举报!";
  1576. $root['status'] = 0;
  1577. ajax_return($root);
  1578. }
  1579. $tipoff = array();
  1580. $tipoff['from_user_id'] = $from_user_id;
  1581. $tipoff['to_user_id'] = $to_user_id;
  1582. $tipoff['create_time'] = NOW_TIME;
  1583. $tipoff['tipoff_type_id'] = $type;
  1584. $tipoff['weibo_id'] = $weibo_id;
  1585. $GLOBALS['db']->autoExecute(DB_PREFIX."tipoff", $tipoff,"INSERT");
  1586. if ($weibo_id > 0){
  1587. //累加举报次数
  1588. $sql = "update ".DB_PREFIX."weibo set tipoff_count = tipoff_count + 1 where id =".$weibo_id;
  1589. $GLOBALS['db']->query($sql);
  1590. }
  1591. if($from_user_id>0){
  1592. $sql = "update ".DB_PREFIX."user set tipoff_count = tipoff_count + 1 where id =".$weibo_id;
  1593. $GLOBALS['db']->query($sql);
  1594. }
  1595. }
  1596. $root['error'] = '举报成功,我们将在24小时内处理!';
  1597. ajax_return($root);
  1598. }
  1599. public function change_user_photo_img(){
  1600. if(!$GLOBALS['user_info']){
  1601. $root['error'] = "用户未登陆,请先登陆.";
  1602. $root['status'] = 0;
  1603. $root['user_login_status'] = 0;//有这个参数: user_login_status = 0 时,表示服务端未登陆、要求登陆,操作
  1604. api_ajax_return($root);
  1605. }
  1606. $user_id = $GLOBALS['user_info']['id'];
  1607. $photo_img = strim($_REQUEST['photo_img']);
  1608. if(!$photo_img){
  1609. $root['error'] = "请上传图片地址!";
  1610. $root['status'] = 0;
  1611. api_ajax_return($root);
  1612. }
  1613. $oss_domain = $GLOBALS['distribution_cfg']['OSS_DOMAIN'].'/public/';
  1614. $photo_img = str_replace($oss_domain, "./public/", $photo_img);
  1615. $data['weibo_photo_img'] = $photo_img;
  1616. $where = ' id = '.$user_id;
  1617. $res = $GLOBALS['db']->autoExecute(DB_PREFIX."user",$data,'UPDATE',$where);
  1618. if(!$res){
  1619. $root['error'] = "图片上传失败!";
  1620. $root['status'] = 0;
  1621. }else{
  1622. $root['error'] = "图片上传成功!";
  1623. $root['status'] = 1;
  1624. $root['user_id'] = $user_id;
  1625. $root['weibo_photo_img'] = get_spec_image($photo_img,320,180,1);
  1626. }
  1627. api_ajax_return($root);
  1628. }
  1629. //设置聊天价格
  1630. public function set_chat_price(){
  1631. if(!$GLOBALS['user_info']){
  1632. $root['error'] = "用户未登陆,请先登陆.";
  1633. $root['status'] = 0;
  1634. $root['user_login_status'] = 0;//有这个参数: user_login_status = 0 时,表示服务端未登陆、要求登陆,操作
  1635. api_ajax_return($root);
  1636. }
  1637. $user_id = $GLOBALS['user_info']['id'];
  1638. $price = floatval($_REQUEST['price']);
  1639. // if($price<=0){
  1640. // $root['error'] = "价格要大于0!";
  1641. // $root['status'] = 0;
  1642. // api_ajax_return($root);
  1643. // }
  1644. $re = $GLOBALS['db']->query("update ".DB_PREFIX."user set weibo_chat_price = ".$price." where id =".$user_id);
  1645. if($re){
  1646. $root['error'] = "设置成功!";
  1647. $root['status'] = 1;
  1648. }else{
  1649. $root['error'] = "设置失败!";
  1650. $root['status'] = 0;
  1651. }
  1652. api_ajax_return($root);
  1653. }
  1654. //我的购买
  1655. public function my_buy_weixin(){
  1656. if(!$GLOBALS['user_info']){
  1657. $root['error'] = "用户未登陆,请先登陆.";
  1658. $root['status'] = 0;
  1659. $root['user_login_status'] = 0;//有这个参数: user_login_status = 0 时,表示服务端未登陆、要求登陆,操作
  1660. api_ajax_return($root);
  1661. }
  1662. $page = intval($_REQUEST['page'])?intval($_REQUEST['page']):1;
  1663. $page_size= 20;
  1664. $limit = (($page-1) * $page_size) . "," . $page_size;
  1665. $user_id = $GLOBALS['user_info']['id'];
  1666. $type_cate_name = array(
  1667. 'weixin'=>'微信号',
  1668. 'reward'=>'打赏',
  1669. 'chat'=>'聊天',
  1670. 'goods'=>'商品',
  1671. 'red_photo'=>'红包',
  1672. 'photo'=>'写真',
  1673. );
  1674. $list = $GLOBALS['db']->getAll("select pn.id as notice_id,pn.memo,pn.user_id,pn.pay_time,pn.is_paid,pn.money,pn.type_cate,u.nick_name,u.head_image from ".DB_PREFIX."payment_notice as pn left join ".DB_PREFIX."user as u on pn.to_user_id = u.id where pn.user_id = ".$user_id." and type = 11 limit $limit");
  1675. foreach($list as $k=>$v){
  1676. if($v['head_image']){
  1677. $list[$k]['head_image'] = get_spec_image($v['head_image'],200,200,1);
  1678. }else{
  1679. $list[$k]['head_image'] = '';
  1680. }
  1681. $list[$k]['type_cate_name'] =$type_cate_name[$v['type_cate']]?$type_cate_name[$v['type_cate']]:'';
  1682. $list[$k]['pay_time'] = to_date($v['pay_time']);
  1683. }
  1684. $root['list'] = $list;
  1685. if(count($list)==$page_size){
  1686. $root['has_next'] = 1;
  1687. }else{
  1688. $root['has_next'] = 0;
  1689. }
  1690. $root['status'] = 1;
  1691. $root['error'] = ".";
  1692. $root['page'] = $page;
  1693. api_ajax_return($root);
  1694. }
  1695. public function my_buy_weixin_user(){
  1696. if(!$GLOBALS['user_info']){
  1697. $root['error'] = "用户未登陆,请先登陆.";
  1698. $root['status'] = 0;
  1699. $root['user_login_status'] = 0;//有这个参数: user_login_status = 0 时,表示服务端未登陆、要求登陆,操作
  1700. api_ajax_return($root);
  1701. }
  1702. $user_id = $GLOBALS['user_info']['id'];
  1703. $notice_id = intval($_REQUEST['notice_id']);
  1704. $sql = "select pn.id as notice_id, pn.memo,pn.user_id,pn.pay_time,pn.is_paid,pn.money,pn.type_cate,u.nick_name from ".DB_PREFIX."payment_notice as pn left join ".DB_PREFIX."user as u on pn.to_user_id = u.id where pn.user_id = $user_id and pn.id = $notice_id ";
  1705. $notice = $GLOBALS['db']->getRow($sql);
  1706. if(!$notice){
  1707. $root['error'] = "该订单不存在.";
  1708. $root['status'] = 0;
  1709. api_ajax_return($root);
  1710. }
  1711. $notice['pay_time'] = to_date($notice['pay_time']);
  1712. $root['info'] = $notice;
  1713. $root['status'] = 1;
  1714. $root['error'] = ".";
  1715. api_ajax_return($root);
  1716. }
  1717. //买家列表
  1718. public function my_buyer(){
  1719. if(!$GLOBALS['user_info']){
  1720. $root['error'] = "用户未登陆,请先登陆.";
  1721. $root['status'] = 0;
  1722. $root['user_login_status'] = 0;//有这个参数: user_login_status = 0 时,表示服务端未登陆、要求登陆,操作
  1723. api_ajax_return($root);
  1724. }
  1725. $page = intval($_REQUEST['page'])?intval($_REQUEST['page']):1;
  1726. $page_size= 20;
  1727. $limit = (($page-1) * $page_size) . "," . $page_size;
  1728. $user_id = $GLOBALS['user_info']['id'];
  1729. $type_cate_name = array(
  1730. 'weixin'=>'微信号',
  1731. 'reward'=>'打赏',
  1732. 'chat'=>'聊天',
  1733. 'goods'=>'商品',
  1734. 'red_photo'=>'红包',
  1735. 'photo'=>'写真',
  1736. );
  1737. $list = $GLOBALS['db']->getAll("select pn.id as notice_id,pn.memo,pn.user_id,pn.pay_time,pn.money,pn.type_cate,u.nick_name,u.head_image,pn.from_user_info from ".DB_PREFIX."payment_notice as pn left join ".DB_PREFIX."user as u on pn.user_id = u.id where pn.to_user_id = ".$user_id." and type = 11 and is_paid = 1 limit $limit");
  1738. foreach($list as $k=>$v){
  1739. if($v['head_image']){
  1740. $list[$k]['head_image'] = get_spec_image($v['head_image'],200,200,1);
  1741. }else{
  1742. $list[$k]['head_image'] = '';
  1743. }
  1744. $list[$k]['type_cate_name'] =$type_cate_name[$v['type_cate']]?$type_cate_name[$v['type_cate']]:'';
  1745. $list[$k]['pay_time'] = to_date($v['pay_time']);
  1746. }
  1747. $root['list'] = $list;
  1748. if(count($list)==$page_size){
  1749. $root['has_next'] = 1;
  1750. }else{
  1751. $root['has_next'] = 0;
  1752. }
  1753. $root['page'] = $page;
  1754. $root['status'] = 1;
  1755. $root['error'] = ".";
  1756. api_ajax_return($root);
  1757. }
  1758. public function my_buyer_user(){
  1759. if(!$GLOBALS['user_info']){
  1760. $root['error'] = "用户未登陆,请先登陆.";
  1761. $root['status'] = 0;
  1762. $root['user_login_status'] = 0;//有这个参数: user_login_status = 0 时,表示服务端未登陆、要求登陆,操作
  1763. api_ajax_return($root);
  1764. }
  1765. $user_id = $GLOBALS['user_info']['id'];
  1766. $notice_id = intval($_REQUEST['notice_id']);
  1767. $sql = "select pn.id as notice_id, pn.memo,pn.user_id,pn.pay_time,pn.is_paid,pn.money,pn.type_cate,u.nick_name,pn.from_user_info from ".DB_PREFIX."payment_notice as pn left join ".DB_PREFIX."user as u on pn.user_id = u.id where pn.to_user_id = $user_id and pn.id = $notice_id ";
  1768. $notice = $GLOBALS['db']->getRow($sql);
  1769. $notice['pay_time'] = to_date($notice['pay_time']);
  1770. if(!$notice){
  1771. $root['error'] = "该订单不存在.";
  1772. $root['status'] = 0;
  1773. api_ajax_return($root);
  1774. }
  1775. $root['info'] = $notice;
  1776. $root['status'] = 1;
  1777. $root['error'] = ".";
  1778. api_ajax_return($root);
  1779. }
  1780. }