user.action.php 57 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474
  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 userModule extends baseModule
  10. {
  11. /**
  12. * 获取用户签名
  13. */
  14. public function usersig()
  15. {
  16. /**
  17. * 获取用户签名
  18. **/
  19. //$GLOBALS['user_info']['id'] = 320;
  20. $root = array();
  21. if(!$GLOBALS['user_info']){
  22. $root['error'] = "用户未登陆,请先登陆.";// es_session::id();
  23. //$root['es_session'] = es_session::id();
  24. //$root['user_info'] = json_encode(es_session::get("user_info"));
  25. $root['status'] = 0;
  26. $root['user_login_status'] = 0;//有这个参数: user_login_status = 0 时,表示服务端未登陆、要求登陆,操作
  27. }else{
  28. $identifier = $GLOBALS['user_info']['id'];// $_REQUEST['identifier'];
  29. $root = load_auto_cache("usersig", array("id"=>$identifier));
  30. /*
  31. $usersig = $GLOBALS['db']->getOne("select usersig from ".DB_PREFIX."user where id=".$identifier." and expiry_after >" .NOW_TIME);
  32. if(!$usersig){
  33. fanwe_require(APP_ROOT_PATH.'system/tim/TimApi.php');
  34. $api = createRestAPI();
  35. $private_pem_path = APP_ROOT_PATH."system/tim/ec_key.pem";
  36. $signature = get_signature();
  37. $ret = $api->generate_user_sig($identifier, '86400', $private_pem_path, $signature);
  38. $expiry_after = NOW_TIME + 86400;
  39. //echo "update ".DB_PREFIX."user set usersig = ".$ret[0].",expiry_after=".$expiry_after." where id = ".$identifier;exit;
  40. $GLOBALS['db']->query("update ".DB_PREFIX."user set usersig = '".$ret[0]."',expiry_after=".$expiry_after." where id = ".$identifier);
  41. }else{
  42. $ret[0] =$usersig;
  43. }
  44. if($ret == null || strstr($ret[0], "failed")){
  45. $root['error'] = "获取usrsig失败, 请确保TimRestApiConfig.json配置信息正确";
  46. $root['status'] = 0;
  47. }else{
  48. $root['usersig'] = $ret[0];
  49. $root['status'] = 1;
  50. }
  51. */
  52. }
  53. if(intval($_REQUEST['ajax_type'])&&intval(IS_DEBUG)){
  54. print_r($root);echo "<hr/>";
  55. }
  56. ajax_return($root);
  57. }
  58. /**
  59. * 获得用户公开信息;不传identifier时,则获得当前登陆用户的信息
  60. */
  61. public function userinfo(){
  62. $root = array();
  63. //$GLOBALS['user_info']['id'] = 292;
  64. if(!$GLOBALS['user_info']){
  65. $root['error'] = "用户未登陆,请先登陆.";
  66. $root['status'] = 0;
  67. $root['user_login_status'] = 0;//有这个参数: user_login_status = 0 时,表示服务端未登陆、要求登陆,操作
  68. }else{
  69. $user_id = intval($GLOBALS['user_info']['id']);
  70. $podcast_id = intval($_REQUEST['podcast_id']);//主播id,fanwe_user.id
  71. $to_user_id = intval($_REQUEST['to_user_id']);//需要查看的用户id
  72. if ($to_user_id == 0){
  73. $to_user_id = $user_id;
  74. }
  75. $root = getuserinfo($user_id,$podcast_id,$to_user_id,$_REQUEST);
  76. $m_config = load_auto_cache("m_config");//初始化手机端配置
  77. $root['init_version'] = intval($m_config['init_version']);//手机端配置版本号
  78. //公会ljz
  79. if($root['user']['society_id'] > 0){
  80. $root['user']['society_name'] = $GLOBALS['db']->getOne("select name from ".DB_PREFIX."society where id=".$root['user']['society_id']);
  81. }else{
  82. $root['user']['society_name'] = '';
  83. }
  84. if($m_config['name_limit']==1){
  85. $user = $GLOBALS['db']->getRow("select nick_name from ".DB_PREFIX."user where id = ".$user_id);
  86. $nick_name=$user['nick_name'];
  87. //进入个人中心过滤铭感词汇
  88. $limit_sql =$GLOBALS['db']->getCol("SELECT name FROM ".DB_PREFIX."limit_name");
  89. if($GLOBALS['db']->getCol("SELECT name FROM ".DB_PREFIX."limit_name WHERE '$nick_name' like concat('%',name,'%')")){
  90. $nick_name=str_replace($limit_sql,'*',$nick_name);
  91. }
  92. //判断用户名如果被过滤后为空,格式则变更为: 账号+ID
  93. if($nick_name==''){
  94. $nick_name=('账号'.$user_id);
  95. }
  96. //更新数据库
  97. $sql = "update ".DB_PREFIX."user set nick_name = '$nick_name' where id=".$user_id;
  98. $GLOBALS['db']->query($sql);
  99. //更新redis
  100. user_deal_to_reids(array($user_id));
  101. //二级分销
  102. if ((defined('DISTRIBUTION_SCAN')&&DISTRIBUTION_SCAN==1)) //二级分销按钮
  103. {
  104. $login_type = $GLOBALS['db']->getRow("select login_type from ".DB_PREFIX."user where id = ".$user_id); //获取登录用户类型
  105. if ($login_type['login_type']!='4') //若不是游客登录,才可进行二级分销
  106. {
  107. $root['distribution_btn'] = 1; //显示分销二维码和分享界面的按钮
  108. //分销转发的数据
  109. $share = array();
  110. $share['share_title'] = strim($m_config['share_title']);//'你丑你先睡,我美我直播!';
  111. $head_image = $GLOBALS['db']->getRow("select head_image from ".DB_PREFIX."user where id = ".$user_id);
  112. $share['share_imageUrl']=get_spec_image($head_image['head_image']);
  113. $share['share_url'] = SITE_DOMAIN.APP_ROOT.'/mapi/index.php?ctl=share_distribution&act=index&share_id='.$user_id; //分销分享的URL(二维码或者其他地方转发)
  114. $share['share_content'] = $user['nick_name'].'邀请您加入我们,一起来看直播~';
  115. $root['share'] = $share; //分销分享部分的数据
  116. $qr_code = $GLOBALS['db']->getRow("select qr_code from ".DB_PREFIX."user where id = ".$user_id);
  117. $root['qr_code'] = get_spec_image($qr_code['qr_code']);//分销二维码图片路径
  118. }
  119. }
  120. }
  121. $sdk_version_name = strim($_REQUEST['sdk_version_name']);
  122. $root['show_red'] = $m_config['ios_check_version'] && $m_config['ios_check_version'] == $sdk_version_name ? 0 : 1;
  123. $root['status'] = 1;
  124. //格式化数据(大于10000保留两位小数,否则不变)
  125. fanwe_require(APP_ROOT_PATH.'mapi/lib/core/num_format.php');
  126. $root['user']['n_fans_count'] = format_for_ten_thousand($root['user']['fans_count']);
  127. $root['user']['n_focus_count'] = format_for_ten_thousand($root['user']['focus_count']);
  128. $root['user']['n_use_diamonds'] = format_for_ten_thousand($root['user']['use_diamonds']);
  129. $root['user']['n_ticket'] = format_for_ten_thousand($root['user']['ticket']);
  130. $root['user']['n_video_count'] = format_for_ten_thousand($root['user']['video_count']);
  131. $root['user']['n_useable_ticket'] = format_for_ten_thousand($root['user']['useable_ticket']);
  132. $root['user']['n_diamonds'] = format_for_ten_thousand($root['user']['diamonds']);
  133. $root['user']['n_use_diamonds'] = format_for_ten_thousand($root['user']['use_diamonds']);
  134. $root['user']['n_show_user_order'] = format_for_ten_thousand($root['user']['show_user_order']);
  135. $root['user']['n_user_order'] = format_for_ten_thousand($root['user']['user_order']);
  136. $root['user']['n_show_user_pai'] = format_for_ten_thousand($root['user']['show_user_pai']);
  137. $root['user']['n_user_pai'] = format_for_ten_thousand($root['user']['user_pai']);
  138. $root['user']['n_show_podcast_order'] = format_for_ten_thousand($root['user']['show_podcast_order']);
  139. $root['user']['n_podcast_order'] = format_for_ten_thousand($root['user']['podcast_order']);
  140. $root['user']['n_show_shopping_cart'] = format_for_ten_thousand($root['user']['show_shopping_cart']);
  141. $root['user']['n_shopping_cart'] = format_for_ten_thousand($root['user']['shopping_cart']);
  142. $root['user']['n_podcast_goods'] = format_for_ten_thousand($root['user']['podcast_goods']);
  143. $root['user']['n_coin'] = format_for_ten_thousand($root['user']['coin']);
  144. $root['user']['n_podcast_pai'] = format_for_ten_thousand($root['user']['podcast_pai']);
  145. $root['user']['n_shop_goods'] = format_for_ten_thousand($root['user']['shop_goods']);
  146. $root['user']['n_svideo_count'] = format_for_ten_thousand($root['user']['svideo_count']);
  147. }
  148. ajax_return($root);
  149. }
  150. /**
  151. * 关注某个用户
  152. */
  153. public function follow(){
  154. $root = array('status'=>1,'error'=>'');
  155. //$GLOBALS['user_info']['id'] = 269;
  156. if(!$GLOBALS['user_info']){
  157. $root['error'] = "用户未登陆,请先登陆.";
  158. $root['status'] = 0;
  159. $root['user_login_status'] = 0;//有这个参数: user_login_status = 0 时,表示服务端未登陆、要求登陆,操作
  160. }else{
  161. //
  162. $user_level = $GLOBALS['db']->getOne("select user_level from ".DB_PREFIX."user where id = ".$GLOBALS['user_info']['id'],true,true);
  163. $m_config = load_auto_cache("m_config");//初始化手机端配置
  164. $show_follow_msg = intval($m_config['show_follow_msg']);//是否现发送关注提示信息 0:不显示; 1:显示
  165. $show_follow_msg_lv = intval($m_config['show_follow_msg_lv']);//关注提示显示的等级
  166. $user_id = intval($GLOBALS['user_info']['id']);//当前用户;
  167. $room_id = intval($_REQUEST['room_id']);//room_id 当前直播房间号,用来:计算权重的;
  168. $to_user_id = intval($_REQUEST['to_user_id']);//被关注或取消关注的用户
  169. $to_user_id = $GLOBALS['db']->getOne("select id from ".DB_PREFIX."user where id = ".$to_user_id,true,true);
  170. if(!intval($to_user_id)) {
  171. $root['error'] = "关注的用户不存在!";
  172. $root['status'] = 0;
  173. }else if($user_id!=$to_user_id){
  174. $root = redis_set_follow($user_id,$to_user_id,false,$room_id);
  175. clear_auto_cache("playback_list",array("user_id"=>$user_id));
  176. if($show_follow_msg && ($user_level>=$show_follow_msg_lv)){
  177. $root['follow_msg'] = emoji_decode($GLOBALS['user_info']['nick_name'])."关注了主播";
  178. }else {
  179. $root['follow_msg'] = '';
  180. }
  181. /*
  182. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/UserFollwRedisService.php');
  183. $user_redis = new UserFollwRedisService($user_id);
  184. //查看关注人数
  185. $follow_count = $user_redis->follow_count();
  186. //粉丝人数
  187. $follow_by_count = $user_redis->follower_count();
  188. //update_follow($user_id,$follow_count,$follow_by_count);
  189. //$root = set_follow($user_id,$to_user_id);
  190. //$root = redis_set_follow($user_id,$to_user_id);
  191. */
  192. if (defined('OPEN_MISSION') && OPEN_MISSION && $root['has_focus']) {
  193. require_once APP_ROOT_PATH . 'mapi/lib/core/Model.class.php';
  194. Model::$lib = dirname(__FILE__);
  195. Model::build('mission')->incProgress($user_id,4);
  196. }
  197. }else{
  198. $root['error'] = "不能关注自己!";
  199. $root['status'] = 0;
  200. }
  201. }
  202. ajax_return($root);
  203. }
  204. /**
  205. * 禁言,只有:主群或群管理员才能设置
  206. */
  207. public function forbid_send_msg(){
  208. $root = array();
  209. $root['status'] = 0;
  210. $root['is_forbid'] = 0;
  211. //$GLOBALS['user_info']['id'] = 1;
  212. if(!$GLOBALS['user_info']){
  213. $root['error'] = "用户未登陆,请先登陆.";
  214. $root['status'] = 0;
  215. $root['user_login_status'] = 0;//有这个参数: user_login_status = 0 时,表示服务端未登陆、要求登陆,操作
  216. }else{
  217. $user_id = intval($GLOBALS['user_info']['id']);//
  218. $to_user_id = strim($_REQUEST['to_user_id']);//被禁言的用户id
  219. $group_id = strim($_REQUEST['group_id']);//群组ID
  220. $second = intval($_REQUEST['second']);//禁言时间,单位为秒; 为0时表示取消禁言
  221. $is_nospeaking = $GLOBALS['db']->getOne("select is_nospeaking from ".DB_PREFIX."user where id = ".$to_user_id,true,true);
  222. if(intval($is_nospeaking)==1){
  223. $root['error'] = "该用户已被im全局禁言.";
  224. ajax_return($root);
  225. }
  226. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/VideoRedisService.php');
  227. $video_redis = new VideoRedisService();
  228. $video = $video_redis->getRow_db_ByGroupId($group_id,array('id','user_id'));
  229. // //优化
  230. // $forbid_info = $video_redis->has_forbid_msg($group_id,$to_user_id);//判断某个用户是否被禁言(被禁言返回:true; 未被禁言返回:false)
  231. // if($forbid_info && intval($forbid_info)>NOW_TIME){
  232. // $second = 0;
  233. // }else{
  234. // $second = 10000;
  235. // $video_redis->unset_forbid_msg($group_id,$to_user_id);
  236. // }
  237. //$sql = "select id,user_id,group_id from ".DB_PREFIX."video where group_id = '".$group_id."'";
  238. //$video = $GLOBALS['db']->getRow($sql,true,true);
  239. $podcast_id = intval($video['user_id']);
  240. $room_id = intval($video['id']);
  241. //查看自己
  242. if ($to_user_id == $user_id){
  243. $root['error'] = "不能自己给自己禁言";
  244. }else{
  245. $allow = false;
  246. //主播查看
  247. if ($podcast_id == $user_id){
  248. $allow = true;//主播 有权限禁言
  249. }else{
  250. $sql = "select count(id) as num from ".DB_PREFIX."user_admin where podcast_id = ".$podcast_id." and user_id = ".$user_id;
  251. if ($GLOBALS['db']->getOne($sql,true,true) > 0){
  252. $allow = true;//管理员 有权限禁言按钮
  253. }
  254. }
  255. }
  256. if ($allow){
  257. $sql = "select is_robot,nick_name from ".DB_PREFIX."user where id = '".$to_user_id."'";
  258. $user = $GLOBALS['db']->getRow($sql,true,true);
  259. $nick_name = $user['nick_name'];
  260. fanwe_require(APP_ROOT_PATH.'system/tim/TimApi.php');
  261. $api = createTimAPI();
  262. //设置:禁言(second>0),取消禁言(second = 0)
  263. if($user['is_robot'] != 1){
  264. $ret = $api->group_forbid_send_msg($group_id,(string)$to_user_id,$second);
  265. }
  266. if ($ret['ActionStatus'] == 'OK' || $user['is_robot'] == 1){
  267. //$ret = $api->get_group_shutted_uin($group_id);
  268. if ($second > 0){
  269. /*
  270. $forbid_send_msg = array();
  271. $forbid_send_msg['group_id'] = $group_id;
  272. $forbid_send_msg['user_id'] = $to_user_id;
  273. $forbid_send_msg['shut_up_time'] = NOW_TIME + $second;
  274. $GLOBALS['db']->autoExecute(DB_PREFIX."video_forbid_send_msg", $forbid_send_msg,"INSERT");
  275. */
  276. //禁言到期时间
  277. if($second>86400){//大于一天则永禁言
  278. $msg = emoji_decode($nick_name). " 被永久禁言";//.print_r($ret,1).';user_id:'.$user_id.";second:".$second.";group_id:".$group_id;
  279. $second = 99999999;
  280. }else{
  281. $msg = emoji_decode($nick_name). " 被禁言".get_live_time_len2($second);
  282. }
  283. $root['is_forbid'] = 1;
  284. $shutup_time = NOW_TIME+$second;
  285. $video_redis->set_forbid_msg($group_id,$to_user_id,$shutup_time);
  286. }else{
  287. $msg = emoji_decode($nick_name). " 取消禁言";
  288. $video_redis->unset_forbid_msg($group_id,$to_user_id);
  289. $root['is_forbid'] = 0;
  290. //$sql = "delete from ".DB_PREFIX."video_forbid_send_msg where group_id='".$group_id."' and user_id = '".$to_user_id."'";
  291. //$GLOBALS['db']->query($sql);
  292. }
  293. $root['status'] = 1;
  294. }else{
  295. $root['status'] = 0;
  296. $root['error'] = $ret['ErrorInfo'].":".$ret['ErrorCode'];
  297. }
  298. if ($root['status'] == 1){
  299. if (!$api){
  300. fanwe_require(APP_ROOT_PATH.'system/tim/TimApi.php');
  301. $api = createTimAPI();
  302. }
  303. //群播一个:禁言通知
  304. $ext = array();
  305. $ext['type'] = 4; //0:普通消息;1:礼物;2:弹幕消息;3:主播退出;4:禁言;5:观众进入房间;6:观众退出房间;7:直播结束
  306. $ext['room_id'] = $room_id;//直播ID 也是room_id;只有与当前房间相同时,收到消息才响应
  307. $ext['fonts_color'] = '';//字体颜色
  308. $ext['desc'] = $msg;//禁言通知消息;
  309. $ext['desc2'] = $msg;//禁言通知消息;
  310. //消息发送者
  311. $sender = array();
  312. $sender['user_id'] = $GLOBALS['user_info']['id'];//发送人昵称
  313. $sender['nick_name'] = emoji_decode($GLOBALS['user_info']['nick_name']);//发送人昵称
  314. $sender['head_image'] = $GLOBALS['user_info']['head_image'];//发送人头像
  315. $sender['user_level'] = $GLOBALS['user_info']['user_level'];//用户等级
  316. $ext['sender'] = $sender;
  317. #构造高级接口所需参数
  318. $msg_content = array();
  319. //创建array 所需元素
  320. $msg_content_elem = array(
  321. 'MsgType' => 'TIMCustomElem', //自定义类型
  322. 'MsgContent' => array(
  323. 'Data' => json_encode($ext),
  324. 'Desc' => '',
  325. // 'Ext' => $ext,
  326. // 'Sound' => '',
  327. )
  328. );
  329. //将创建的元素$msg_content_elem, 加入array $msg_content
  330. array_push($msg_content, $msg_content_elem);
  331. $ret = $api->group_send_group_msg2($GLOBALS['user_info']['id'], $group_id, $msg_content);
  332. }
  333. }else{
  334. $root['error'] = "无禁言权限";
  335. }
  336. }
  337. ajax_return($root);
  338. }
  339. /**
  340. * 设置/取消 管理员
  341. */
  342. public function set_admin(){
  343. $root = array();
  344. $root['status'] = 1;
  345. if(!$GLOBALS['user_info']){
  346. $root['error'] = "用户未登陆,请先登陆.";
  347. $root['status'] = 0;
  348. $root['user_login_status'] = 0;//有这个参数: user_login_status = 0 时,表示服务端未登陆、要求登陆,操作
  349. }else{
  350. //
  351. $user_id = intval($GLOBALS['user_info']['id']);
  352. $to_user_id = intval($_REQUEST['to_user_id']);//被关注或取消 管理员用户
  353. $room_id = strim($_REQUEST['room_id']);
  354. $sql = "select id from ".DB_PREFIX."user_admin where podcast_id = '".$user_id."' and user_id = ".$to_user_id;
  355. $user_admin_id = $GLOBALS['db']->getOne($sql);
  356. if ($user_admin_id > 0){
  357. //取消管理员操作;
  358. $sql = "delete from ".DB_PREFIX."user_admin where id = ".$user_admin_id;
  359. $GLOBALS['db']->query($sql);
  360. }else{
  361. $sql = "select count(id) as num from ".DB_PREFIX."user_admin where podcast_id = ".$GLOBALS['user_info']['id'];
  362. if ($GLOBALS['db']->getOne($sql) < 5){
  363. //设置管理员操作;
  364. $user_admin = array();
  365. $user_admin['podcast_id'] = $GLOBALS['user_info']['id'];
  366. $user_admin['user_id'] = $to_user_id;
  367. $user_admin['create_time'] = NOW_TIME;
  368. $GLOBALS['db']->autoExecute(DB_PREFIX."user_admin", $user_admin,"INSERT");
  369. }else{
  370. $root['error'] = "已经超过5位管理员,不能再设置新的管理员";
  371. $root['status'] = 0;
  372. }
  373. }
  374. $sql = "select id from ".DB_PREFIX."user_admin where podcast_id = '".$user_id."' and user_id = ".$to_user_id;
  375. if ($GLOBALS['db']->getOne($sql) > 0){
  376. $root['has_admin'] = 1;//0:非管理员;1:是管理员
  377. }else{
  378. $root['has_admin'] = 0;
  379. }
  380. if ($root['status'] ==1 && $room_id != ''){
  381. $sql = "select nick_name from ".DB_PREFIX."user where id = '".$to_user_id."'";
  382. if ($root['has_admin'] == 1){
  383. $msg = emoji_decode($GLOBALS['db']->getOne($sql)). " 被设置为管理员";
  384. }else{
  385. $msg = emoji_decode($GLOBALS['db']->getOne($sql)). " 管理员被取消";
  386. }
  387. fanwe_require(APP_ROOT_PATH.'system/tim/TimApi.php');
  388. $api = createTimAPI();
  389. //群播一个:直播消息
  390. $ext = array();
  391. $ext['type'] = 9; //0:普通消息;1:礼物;2:弹幕消息;3:主播退出;4:禁言;5:观众进入房间;6:观众退出房间;7:直播结束
  392. $ext['room_id'] = $room_id;//直播ID 也是room_id;只有与当前房间相同时,收到消息才响应
  393. $ext['fonts_color'] = '';//字体颜色
  394. $ext['desc'] = $msg;//禁言通知消息;
  395. $ext['desc2'] = $msg;//禁言通知消息;
  396. //消息发送者
  397. $sender = array();
  398. $sender['user_id'] = $GLOBALS['user_info']['id'];//发送人昵称
  399. $sender['nick_name'] = emoji_decode($GLOBALS['user_info']['nick_name']);//发送人昵称
  400. $sender['head_image'] = $GLOBALS['user_info']['head_image'];//发送人头像
  401. $sender['user_level'] = $GLOBALS['user_info']['user_level'];//用户等级
  402. $ext['sender'] = $sender;
  403. #构造高级接口所需参数
  404. $msg_content = array();
  405. //创建array 所需元素
  406. $msg_content_elem = array(
  407. 'MsgType' => 'TIMCustomElem', //自定义类型
  408. 'MsgContent' => array(
  409. 'Data' => json_encode($ext),
  410. 'Desc' => '',
  411. // 'Ext' => $ext,
  412. // 'Sound' => '',
  413. )
  414. );
  415. //将创建的元素$msg_content_elem, 加入array $msg_content
  416. array_push($msg_content, $msg_content_elem);
  417. $sql = "select group_id from ".DB_PREFIX."video where id = '".$room_id."'";
  418. $group_id = $GLOBALS['db']->getOne($sql);
  419. $ret = $api->group_send_group_msg2($GLOBALS['user_info']['id'], $group_id, $msg_content);
  420. if ($ret['ActionStatus'] == 'FAIL' && $ret['ErrorCode'] == 10002){
  421. //10002 系统错误,请再次尝试或联系技术客服。
  422. $ret = $api->group_send_group_msg2($GLOBALS['user_info']['id'], $group_id, $msg_content);
  423. }
  424. }
  425. }
  426. ajax_return($root);
  427. }
  428. /**
  429. * 举报用户
  430. */
  431. public function tipoff(){
  432. $root = array();
  433. $root['status'] = 1;
  434. if(!$GLOBALS['user_info']){
  435. $root['error'] = "用户未登陆,请先登陆.";
  436. $root['status'] = 0;
  437. $root['user_login_status'] = 0;//有这个参数: user_login_status = 0 时,表示服务端未登陆、要求登陆,操作
  438. }else{
  439. $to_user_id = intval($_REQUEST['to_user_id']);//被关注的举报用户ID
  440. $type = intval($_REQUEST['type']);
  441. $room_id = intval($_REQUEST['room_id']); //被举报的房间id
  442. $tipoff = array();
  443. $tipoff['from_user_id'] = $GLOBALS['user_info']['id'];
  444. $tipoff['to_user_id'] = $to_user_id;
  445. $tipoff['create_time'] = NOW_TIME;
  446. $tipoff['tipoff_type_id'] = $type;
  447. $tipoff['video_id'] = $room_id;
  448. $GLOBALS['db']->autoExecute(DB_PREFIX."tipoff", $tipoff,"INSERT");
  449. if ($room_id > 0){
  450. //累加举报次数
  451. $sql = "update ".DB_PREFIX."video set tipoff_count = tipoff_count + 1 where id =".$room_id;
  452. $GLOBALS['db']->query($sql);
  453. }
  454. }
  455. ajax_return($root);
  456. }
  457. /**
  458. * 主播管理员列表
  459. */
  460. public function user_admin(){
  461. $root = array();
  462. $root['status'] = 1;
  463. if(!$GLOBALS['user_info']){
  464. $root['error'] = "用户未登陆,请先登陆.";
  465. $root['status'] = 0;
  466. $root['user_login_status'] = 0;//有这个参数: user_login_status = 0 时,表示服务端未登陆、要求登陆,操作
  467. }else{
  468. $user_id = intval($GLOBALS['user_info']['id']);//用户ID
  469. $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;
  470. $list = $GLOBALS['db']->getAll($sql);
  471. foreach($list as $k=>$v){
  472. $list[$k]['head_image'] = get_spec_image($v['head_image']);
  473. $list[$k]['nick_name'] = emoji_decode($list[$k]['nick_name']);
  474. }
  475. $root['list'] = $list;
  476. $root['max_num'] = 5;
  477. $root['cur_num'] = count($list);
  478. $root['status'] = 1;
  479. }
  480. ajax_return($root);
  481. }
  482. /**
  483. * 关注的用户,最多不超过100个
  484. */
  485. public function user_follow(){
  486. $root = array();
  487. $root['status'] = 1;
  488. //$GLOBALS['user_info']['id'] = 278;
  489. if(!$GLOBALS['user_info']){
  490. $root['error'] = "用户未登陆,请先登陆.";
  491. $root['status'] = 0;
  492. $root['user_login_status'] = 0;//有这个参数: user_login_status = 0 时,表示服务端未登陆、要求登陆,操作
  493. }else{
  494. $user_id = intval($GLOBALS['user_info']['id']);//id
  495. $page = intval($_REQUEST['p']);//取第几页数据
  496. if($page==0){
  497. $page = 1;
  498. }
  499. if (isset($_REQUEST['to_user_id'])){
  500. $to_user_id = strim($_REQUEST['to_user_id']);//被查看的用户id
  501. }else{
  502. $to_user_id = $user_id;//id
  503. }
  504. $page_size = 20;
  505. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/UserFollwRedisService.php');
  506. $user_redis = new UserFollwRedisService($user_id);
  507. $list = $user_redis->get_follonging_user($to_user_id,$page,$page_size);
  508. foreach($list as $k=>$v){
  509. $list[$k]['signature'] = htmlspecialchars_decode($list[$k]['signature']);
  510. $list[$k]['nick_name'] = htmlspecialchars_decode($list[$k]['nick_name']);
  511. $list[$k]['signature'] = emoji_decode($list[$k]['signature']);
  512. $list[$k]['nick_name'] = emoji_decode($list[$k]['nick_name']);
  513. }
  514. $root['list'] = $list;
  515. $rs_count = $user_redis->following();
  516. if($page==0){
  517. $root['has_next'] = 0;
  518. }else{
  519. if (count($rs_count) >= $page_size)
  520. $root['has_next'] = 1;
  521. else
  522. $root['has_next'] = 0;
  523. }
  524. $root['page'] = $page;//
  525. }
  526. ajax_return($root);
  527. }
  528. /**
  529. * 粉丝列表,最多不超过100个
  530. */
  531. public function user_focus(){
  532. $root = array();
  533. $root['status'] = 1;
  534. //$GLOBALS['user_info']['id'] = 278;
  535. if(!$GLOBALS['user_info']){
  536. $root['error'] = "用户未登陆,请先登陆.";
  537. $root['status'] = 0;
  538. $root['user_login_status'] = 0;//有这个参数: user_login_status = 0 时,表示服务端未登陆、要求登陆,操作
  539. }else{
  540. $user_id = intval($GLOBALS['user_info']['id']);//id
  541. if (isset($_REQUEST['to_user_id'])){
  542. $to_user_id = strim($_REQUEST['to_user_id']);//被查看的用户id
  543. }else{
  544. $to_user_id = $user_id;
  545. }
  546. $page = intval($_REQUEST['p']);//取第几页数据
  547. if($page==0){
  548. $page = 1;
  549. }
  550. $page_size = 20;
  551. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/UserFollwRedisService.php');
  552. $user_redis = new UserFollwRedisService($user_id);
  553. $list = $user_redis->get_follonging_by_user($to_user_id,$page);
  554. $keys = $user_redis->following();
  555. foreach($list as $k=>$v){
  556. if($user_id>0){
  557. if (in_array($v['user_id'],$keys)){
  558. $list[$k]['follow_id'] = 1;
  559. }else{
  560. $list[$k]['follow_id'] = 0;
  561. }
  562. }else{
  563. $list[$k]['follow_id'] = 0;
  564. }
  565. $list[$k]['head_image'] = get_spec_image($v['head_image']);
  566. $list[$k]['nick_name'] = htmlspecialchars_decode($list[$k]['nick_name']);
  567. $list[$k]['signature'] = htmlspecialchars_decode($list[$k]['signature']);
  568. $list[$k]['nick_name'] = emoji_decode($list[$k]['nick_name']);
  569. $list[$k]['signature'] = emoji_decode($list[$k]['signature']);
  570. }
  571. $root['list'] = $list;
  572. if($page==0){
  573. $root['has_next'] = 0;
  574. }else{
  575. if (count($list) >= $page_size)
  576. $root['has_next'] = 1;
  577. else
  578. $root['has_next'] = 0;
  579. }
  580. $root['page'] = $page;//
  581. }
  582. ajax_return($root);
  583. }
  584. /**
  585. * 分享成功回调
  586. * type: 分享类型(WEIXIN,WEIXIN_CIRCLE,QQ,QZONE,EMAIL,SMS,SINA 微信,微信朋友圈,qq,QQ空间,email,短信,新浪微博)
  587. */
  588. public function share(){
  589. $root = array();
  590. $root['status'] = 1;
  591. if(!$GLOBALS['user_info']){
  592. $root['error'] = "用户未登陆,请先登陆.";
  593. $root['status'] = 0;
  594. $root['user_login_status'] = 0;//有这个参数: user_login_status = 0 时,表示服务端未登陆、要求登陆,操作
  595. }else{
  596. $user_id = intval($GLOBALS['user_info']['id']);//用户ID
  597. $type = strtolower(strim($_REQUEST['type']));//WEIXIN,WEIXIN_CIRCLE,QQ,QZONE,EMAIL,SMS,SINA
  598. $room_id = intval($_REQUEST['room_id']);//直播ID 也是room_id
  599. //分享加印票功能
  600. $m_config = load_auto_cache("m_config");//初始化手机端配置
  601. //每个房间每个类型可以分享一次,主播分享自己房间不获得
  602. if(defined('OPEN_SHARE_EXPERIENCE')&&OPEN_SHARE_EXPERIENCE==1&&intval($m_config['open_share_ticket'])){
  603. $sql = "select max(id) from ".DB_PREFIX."video_share where video_id = ".$room_id." and user_id =".$user_id." and type = '".$type."'";
  604. $exist_share_id = $GLOBALS['db']->getOne($sql);
  605. //获取主播ID
  606. $sql = "select user_id as from_user_id from ".DB_PREFIX."video where id =".$room_id;
  607. $video_user_info = $GLOBALS['db']->getRow($sql);
  608. $share_id = intval($exist_share_id);
  609. if($share_id==0){
  610. //分享表中无记录,查分享历史表
  611. $sql = "select id from ".DB_PREFIX."video_share_history where video_id = ".$room_id." and user_id =".$user_id." and type = '".$type."'";
  612. $share_id = intval($GLOBALS['db']->getOne($sql));
  613. }
  614. $now_time = NOW_TIME;
  615. $s_now_time = to_timespan(to_date($now_time,"Y-m-d 00:00:00"));
  616. $e_now_time = to_timespan(to_date($now_time,"Y-m-d 23:59:59"));
  617. if($share_id==0){
  618. $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;
  619. $video_t_share_id = $GLOBALS['db']->getOne($sql);
  620. $share_id = intval($video_t_share_id);
  621. if($share_id==0){
  622. //分享表中无记录,查分享历史表
  623. $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;
  624. $share_id = intval($GLOBALS['db']->getOne($sql));
  625. }
  626. }
  627. }
  628. //每个用户每个房间可以分享一次,增加分享次数
  629. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/VideoRedisService.php');
  630. $video_redis = new VideoRedisService();
  631. //$video_redis->incry($this->video_db.$room_id, 'share_count', 1);
  632. $video_redis->redis->hIncrBy($video_redis->video_db.$room_id,'share_count',1);
  633. $data = array();
  634. //写入分享表
  635. $video_monitor = array();
  636. $video_monitor['user_id'] = $user_id;
  637. $video_monitor['video_id'] = $room_id;
  638. $video_monitor['type'] = $type;
  639. $video_monitor['create_time'] = NOW_TIME;
  640. $GLOBALS['db']->autoExecute(DB_PREFIX."video_share", $video_monitor,"INSERT");
  641. $video_share_id = $GLOBALS['db']->insert_id();
  642. if (defined('OPEN_MISSION') && OPEN_MISSION) {
  643. require_once APP_ROOT_PATH . 'mapi/lib/core/Model.class.php';
  644. Model::$lib = dirname(__FILE__);
  645. Model::build('mission')->incProgress($user_id,3);
  646. }
  647. if(defined('OPEN_SHARE_EXPERIENCE')&&OPEN_SHARE_EXPERIENCE==1&&intval($m_config['open_share_ticket'])){
  648. //历史记录中也没有,可以增加
  649. if($share_id==0&&intval($m_config['share_ticket'])>0&&intval($video_user_info['from_user_id'])!=$user_id&&intval($video_share_id)>0){
  650. //根据open_share_ticket决定获得印票或钻石 1印票 2钻石
  651. $ticket_name = $m_config['ticket_name'];
  652. if (intval($m_config['open_share_ticket'])==1){
  653. $sql = "update ".DB_PREFIX."user set ticket = ticket + ".intval($m_config['share_ticket'])." where id =".$user_id;
  654. $data['ticket'] =intval($m_config['share_ticket']);
  655. if($ticket_name==''){
  656. $ticket_name = '印票';
  657. }
  658. }else{
  659. $sql = "update ".DB_PREFIX."user set diamonds = diamonds + ".intval($m_config['share_ticket'])." where id =".$user_id;
  660. $data['diamonds'] =intval($m_config['share_ticket']);
  661. $ticket_name = '钻石';
  662. }
  663. $GLOBALS['db']->query($sql);//增加用户印票或钻石
  664. user_deal_to_reids(array($user_id));//同步用户redis
  665. //请求返回信息
  666. $root['share_award'] =intval($m_config['share_ticket']);
  667. $root['share_award_type'] = $ticket_name;
  668. $root['share_award_info'] ='分享直播获得'.$ticket_name.intval($m_config['share_ticket']);
  669. //写入用户日志
  670. $data['log_admin_id'] = 0;
  671. $data['video_id'] = $room_id;
  672. $param['type'] = 4;//类型 0表示充值 1表示提现 2赠送道具 3 兑换印票 4 分享获得印票
  673. $log_msg ="通过".$type.'分享直播间'.$room_id.',获得'.intval($m_config['share_ticket']).$ticket_name;
  674. account_log_com($data,$user_id,$log_msg,$param);
  675. }
  676. }
  677. }
  678. ajax_return($root);
  679. }
  680. /**
  681. * 更新设备号
  682. */
  683. public function apns()
  684. {
  685. $root = array();
  686. $root['status'] = 1;
  687. //$GLOBALS['user_info']['id'] = 1;
  688. if(!$GLOBALS['user_info']){
  689. $root['error'] = "用户未登陆,请先登陆.";
  690. $root['status'] = 0;
  691. $root['user_login_status'] = 0;//有这个参数: user_login_status = 0 时,表示服务端未登陆、要求登陆,操作
  692. }else{
  693. $user_id = intval($GLOBALS['user_info']['id']);//用户ID
  694. $apns_code = addslashes($_REQUEST['apns_code']);
  695. if(!$apns_code)
  696. {
  697. $root['error'] = "设备号为空,更新失败";
  698. $root['status'] = 0;
  699. ajax_return($root);
  700. }
  701. //apns_code 友盟消息推送服务对设备的唯一标识。Android的device_token是44位字符串, iOS的device-token是64位
  702. //device_type 1:android; 2:ios
  703. if (strlen($apns_code) == 44){
  704. $device_type = 1;
  705. }else if (strlen($apns_code) == 64){
  706. $device_type = 2;
  707. }else{
  708. $device_type = 0;
  709. }
  710. $sql = 'update '.DB_PREFIX."user set apns_code ='".$apns_code."',device_type='".$device_type."' where id =".$user_id;
  711. $GLOBALS['db']->query($sql);
  712. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/UserRedisService.php');
  713. $user_redis = new UserRedisService();
  714. $data['apns_code'] = $apns_code;
  715. $data['device_type'] = $device_type;
  716. $user_redis->update_db($user_id,$data);
  717. }
  718. ajax_return($root);
  719. }
  720. /**
  721. * 查看个人主页
  722. */
  723. public function user_home(){
  724. $root = array();
  725. //$GLOBALS['user_info']['id'] = 286;
  726. if(!$GLOBALS['user_info']){
  727. $root['error'] = "用户未登陆,请先登陆.";
  728. $root['status'] = 0;
  729. $root['user_login_status'] = 0;//有这个参数: user_login_status = 0 时,表示服务端未登陆、要求登陆,操作
  730. }else{
  731. $user_id = intval($GLOBALS['user_info']['id']);//用户ID
  732. $to_user_id = intval($_REQUEST['to_user_id']);//被查看的用户id
  733. if ($to_user_id == 0){
  734. $to_user_id = $user_id;
  735. }
  736. $root = getuserinfo($user_id,0,$to_user_id);
  737. $root['status'] = 1;
  738. //格式化数据(大于10000保留两位小数,否则不变)
  739. fanwe_require(APP_ROOT_PATH.'mapi/lib/core/num_format.php');
  740. $root['user']['n_fans_count'] = format_for_ten_thousand($root['user']['fans_count']);
  741. $root['user']['n_focus_count'] = format_for_ten_thousand($root['user']['focus_count']);
  742. $root['user']['n_use_diamonds'] = format_for_ten_thousand($root['user']['use_diamonds']);
  743. $root['user']['n_ticket'] = format_for_ten_thousand($root['user']['ticket']);
  744. $root['user']['n_video_count'] = format_for_ten_thousand($root['user']['video_count']);
  745. $root['user']['n_useable_ticket'] = format_for_ten_thousand($root['user']['useable_ticket']);
  746. $root['user']['n_diamonds'] = format_for_ten_thousand($root['user']['diamonds']);
  747. $root['user']['n_use_diamonds'] = format_for_ten_thousand($root['user']['use_diamonds']);
  748. $root['user']['n_show_user_order'] = format_for_ten_thousand($root['user']['show_user_order']);
  749. $root['user']['n_user_order'] = format_for_ten_thousand($root['user']['user_order']);
  750. $root['user']['n_show_user_pai'] = format_for_ten_thousand($root['user']['show_user_pai']);
  751. $root['user']['n_user_pai'] = format_for_ten_thousand($root['user']['user_pai']);
  752. $root['user']['n_show_podcast_order'] = format_for_ten_thousand($root['user']['show_podcast_order']);
  753. $root['user']['n_podcast_order'] = format_for_ten_thousand($root['user']['podcast_order']);
  754. $root['user']['n_show_shopping_cart'] = format_for_ten_thousand($root['user']['show_shopping_cart']);
  755. $root['user']['n_shopping_cart'] = format_for_ten_thousand($root['user']['shopping_cart']);
  756. $root['user']['n_podcast_goods'] = format_for_ten_thousand($root['user']['podcast_goods']);
  757. $root['user']['n_coin'] = format_for_ten_thousand($root['user']['coin']);
  758. $root['user']['n_podcast_pai'] = format_for_ten_thousand($root['user']['podcast_pai']);
  759. $root['user']['n_shop_goods'] = format_for_ten_thousand($root['user']['shop_goods']);
  760. $root['user']['n_svideo_count'] = format_for_ten_thousand($root['user']['svideo_count']);
  761. if(!$root['user']['luck_num'])
  762. {
  763. $root['user']['luck_num'] = '';
  764. }
  765. }
  766. ajax_return($root);
  767. }
  768. /**
  769. * 直播回看
  770. */
  771. public function user_review(){
  772. $root = array();
  773. //$GLOBALS['user_info']['id'] = 1;
  774. $to_user_id = intval($_REQUEST['to_user_id']);//被查看的用户id
  775. if ($to_user_id == 0){
  776. $to_user_id = intval($GLOBALS['user_info']['id']);
  777. }
  778. $sort = intval($_REQUEST['sort']);//排序类型; 0:最新;1:最热
  779. $page = intval($_REQUEST['p']);//取第几页数据
  780. if($page==0)$page = 1;
  781. $page_size=10;
  782. $limit = (($page-1)*$page_size).",".$page_size;
  783. $sort_field = "vh.begin_time desc";
  784. if ($sort == 1){
  785. $sort_field = "vh.max_watch_number desc";
  786. }
  787. //video_count
  788. if($to_user_id ==intval($GLOBALS['user_info']['id'])){
  789. $sql = "select vh.id,vh.id as room_id,vh.group_id,vh.live_in,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;
  790. }else{
  791. $sql = "select vh.id,vh.id as room_id,vh.group_id,vh.live_in,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;
  792. }
  793. $list = array();
  794. $list_arr = array();
  795. $list_info = $GLOBALS['db']->getAll($sql);
  796. foreach ( $list_info as $k => $v )
  797. {
  798. /*//判断视频存在
  799. fanwe_require(APP_ROOT_PATH . 'mapi/lib/core/video_factory.php');
  800. $video_factory = new VideoFactory();
  801. if($v['video_type'] == 1 && $v['channelid'])
  802. {
  803. if(strlen($v['channelid'])>20){
  804. $fileName = $v['channelid'];
  805. $ret = $video_factory->DescribeVodPlayInfo($fileName);
  806. }else{
  807. $ret = $video_factory->GetVodRecordFiles($v['channelid'], $v['create_time']);
  808. }
  809. }else{
  810. $fileName = $v['id'] . '_' . to_date($v['begin_time'],'Y-m-d-H');
  811. $ret = $video_factory->DescribeVodPlayInfo($fileName);
  812. }
  813. if($ret['codeDesc'] == 'Success'){
  814. $list_arr = $v;
  815. $list_arr['head_image'] = get_spec_image($v['head_image'],150,150);
  816. $list_arr['begin_time_format'] = format_show_date($v['begin_time']);
  817. if ($v['max_watch_number'] > 10000){
  818. $list_arr['watch_number_format'] = round($v['max_watch_number']/10000,2)."万";
  819. }else{
  820. $list_arr['watch_number_format'] = $v['max_watch_number'];
  821. }
  822. $list_arr['max_watch_number'] = $v['max_watch_number'];
  823. if($v['title'] == '')
  824. $list_arr['title'] = "....";
  825. $list[] = $list_arr;
  826. }else{
  827. //会误删
  828. $sql = "update ".DB_PREFIX."video_history set is_del_vod = 1 where id =".$v['id'];
  829. //$GLOBALS['db']->query($sql);
  830. }*/
  831. $list_arr = $v;
  832. $list_arr['head_image'] = get_spec_image($v['head_image'],150,150);
  833. $list_arr['begin_time_format'] = format_show_date($v['begin_time']);
  834. if ($v['max_watch_number'] > 10000){
  835. $list_arr['watch_number_format'] = round($v['max_watch_number']/10000,2)."万";
  836. }else{
  837. $list_arr['watch_number_format'] = $v['max_watch_number'];
  838. }
  839. $list_arr['max_watch_number'] = $v['max_watch_number'];
  840. //20170930 Ios端逻辑处理添加 @slf
  841. $list_arr['live_in'] = 3;
  842. if($v['title'] == '')
  843. $list_arr['title'] = "....";
  844. $list[] = $list_arr;
  845. }
  846. $root['list'] = $list;
  847. if($to_user_id ==intval($GLOBALS['user_info']['id'])){
  848. $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;
  849. }else{
  850. $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;
  851. }
  852. $count = $GLOBALS['db']->getOne($sql);
  853. //$count = count($list);
  854. if ($count >= $page_size)
  855. $root['has_next'] = 1;
  856. else
  857. $root['has_next'] = 0;
  858. $root['count'] = $count;
  859. if($to_user_id ==intval($GLOBALS['user_info']['id'])&&$page==1){
  860. $sql = "update ".DB_PREFIX."user set video_count = ".$root['count']." where id = ".intval($GLOBALS['user_info']['id'])." and video_count!=".$root['count'];
  861. $GLOBALS['db']->query($sql);
  862. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/BaseRedisService.php');
  863. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/UserRedisService.php');
  864. $user_redis = new UserRedisService();
  865. $user_data = array();
  866. $user_data['video_count'] = $root['count'];
  867. $user_redis->update_db(intval($GLOBALS['user_info']['id']), $user_data);
  868. }
  869. $root['page'] = $page;
  870. $root['status'] = 1;
  871. ajax_return($root);
  872. }
  873. /**
  874. * 设置黑名单
  875. */
  876. public function set_black(){
  877. $root = array();
  878. //$GLOBALS['user_info']['id'] = 269;
  879. if(!$GLOBALS['user_info']){
  880. $root['error'] = "用户未登陆,请先登陆.";
  881. $root['status'] = 0;
  882. $root['user_login_status'] = 0;//有这个参数: user_login_status = 0 时,表示服务端未登陆、要求登陆,操作
  883. }else{
  884. //
  885. $user_id = intval($GLOBALS['user_info']['id']);//当前用户;
  886. $to_user_id = intval($_REQUEST['to_user_id']);//被关注或取消关注的用户
  887. if($user_id!=$to_user_id){
  888. $root = set_black($user_id,$to_user_id);
  889. }else{
  890. $root['error'] = "不能设置自己!";
  891. $root['status'] = 0;
  892. }
  893. }
  894. ajax_return($root);
  895. }
  896. /**
  897. * 搜索用户列表
  898. */
  899. public function search(){
  900. //$GLOBALS['user_info']['id'] = 269;
  901. $root = array();
  902. $root['status'] = 1;
  903. if(!$GLOBALS['user_info']){
  904. $root['error'] = "用户未登陆,请先登陆.";
  905. $root['status'] = 0;
  906. $root['user_login_status'] = 0;//有这个参数: user_login_status = 0 时,表示服务端未登陆、要求登陆,操作
  907. }else{
  908. //
  909. $user_id = intval($GLOBALS['user_info']['id']);//当前用户;
  910. $keyword = strim($_REQUEST['keyword']);//搜索关键字
  911. if ($keyword != ""){
  912. $page = intval($_REQUEST['p']);//取第几页数据
  913. if($page==0)$page = 1;
  914. $page_size=20;
  915. $limit = (($page-1)*$page_size).",".$page_size;
  916. $m_config = load_auto_cache("m_config");//初始化手机端配置
  917. if($m_config['search_change']==0){
  918. if ($page == 1){
  919. if (intval($keyword) > 0){//如果搜索关键字为数字
  920. //搜索ID,昵称,靓号,不为机器人。
  921. $sql = "select u.id as user_id,u.nick_name,u.signature,u.sex,u.head_image,u.user_level,u.v_icon from ".DB_PREFIX."user u where u.id = ".$keyword." and u.is_robot=0 limit 0,1
  922. union select u.id as user_id,u.nick_name,u.signature,u.sex,u.head_image,u.user_level,u.v_icon from ".DB_PREFIX."user u where u.luck_num = ".$keyword." and u.is_robot=0 limit 0,1
  923. union select u.id as user_id,u.nick_name,u.signature,u.sex,u.head_image,u.user_level,u.v_icon from ".DB_PREFIX."user u where u.nick_name = '".$keyword."' and u.is_robot=0 limit 20";
  924. }else{
  925. $sql = "select u.id as user_id,u.nick_name,u.signature,u.sex,u.head_image,u.user_level,u.v_icon from ".DB_PREFIX."user u where u.nick_name = '".$keyword."' and u.is_robot=0 limit ".$limit;
  926. }
  927. }else{
  928. $sql = "select u.id as user_id,u.nick_name,u.signature,u.sex,u.head_image,u.user_level,u.v_icon from ".DB_PREFIX."user u where u.nick_name = '".$keyword."' and u.is_robot=0 limit ".$limit;
  929. }
  930. }else{
  931. if ($page == 1){
  932. if (intval($keyword) > 0){//如果搜索关键字为数字
  933. //搜索ID,昵称,靓号,不为机器人。
  934. $sql = "select u.id as user_id,u.nick_name,u.signature,u.sex,u.head_image,u.user_level,u.v_icon from ".DB_PREFIX."user u where u.id = ".$keyword." and u.is_robot=0 limit 0,1
  935. union select u.id as user_id,u.nick_name,u.signature,u.sex,u.head_image,u.user_level,u.v_icon from ".DB_PREFIX."user u where u.luck_num = ".$keyword." and u.is_robot=0 limit 0,1
  936. union select u.id as user_id,u.nick_name,u.signature,u.sex,u.head_image,u.user_level,u.v_icon from ".DB_PREFIX."user u where u.nick_name = '".$keyword."' and u.is_robot=0 limit 20";
  937. }else{
  938. $sql = "select u.id as user_id,u.nick_name,u.signature,u.sex,u.head_image,u.user_level,u.v_icon from ".DB_PREFIX."user u where u.nick_name like '%".$keyword."%' and u.is_robot=0 limit ".$limit;
  939. }
  940. }else{
  941. $sql = "select u.id as user_id,u.nick_name,u.signature,u.sex,u.head_image,u.user_level,u.v_icon from ".DB_PREFIX."user u where u.nick_name like '%".$keyword."%' and u.is_robot=0 limit ".$limit;
  942. }
  943. }
  944. // if (intval($keyword) > 0){//如果搜索关键字为数字
  945. // //搜索ID,昵称,靓号,不为机器人。
  946. // //$sql = "select u.id as user_id,u.nick_name,u.signature,u.sex,u.head_image,u.user_level,u.v_icon from ".DB_PREFIX."user u where (u.id = '".$keyword. "' or u.luck_num = '".$keyword. "' or u.nick_name = '".$keyword."') and u.is_robot=0 limit ".$limit;
  947. // $sql = "select u.id as user_id,u.nick_name,u.signature,u.sex,u.head_image,u.user_level,u.v_icon from ".DB_PREFIX."user u where u.nick_name = '".$keyword."' and u.is_robot=0 limit ".$limit;
  948. // }else{
  949. // // $sql = "select u.id as user_id,u.nick_name,u.signature,u.sex,u.head_image,u.user_level,u.v_icon from ".DB_PREFIX."user u where (u.id = '".$keyword. "' or u.nick_name = '".$keyword."') and u.is_robot=0 limit ".$limit;
  950. // $sql = "select u.id as user_id,u.nick_name,u.signature,u.sex,u.head_image,u.user_level,u.v_icon from ".DB_PREFIX."user u where u.nick_name = '".$keyword."' and u.is_robot=0 limit ".$limit;
  951. // }
  952. //$root['sql'] = $sql;
  953. //查询用户列表,修改成 从只读数据库中取,但不是高效做法;主并发时,可以加入阿里云的搜索服务
  954. //https://www.aliyun.com/product/opensearch?spm=5176.8142029.388261.62.tgDxhe
  955. $list = $GLOBALS['db']->getAll($sql,true,true);
  956. $keys =array();
  957. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/UserFollwRedisService.php');
  958. $user_redis = new UserFollwRedisService($user_id);
  959. $keys = $user_redis->following();
  960. foreach($list as $k=>$v){
  961. if(in_array($v['user_id'],$keys)){
  962. $list[$k]['follow_id'] = $v['user_id'];
  963. }else{
  964. $list[$k]['follow_id'] = 0;
  965. }
  966. $list[$k]['head_image'] = get_spec_image($v['head_image']);
  967. $list[$k]['signature'] = htmlspecialchars_decode($list[$k]['signature']);
  968. $list[$k]['nick_name'] = htmlspecialchars_decode($list[$k]['nick_name']);
  969. $list[$k]['signature'] = emoji_decode($list[$k]['signature']);
  970. $list[$k]['nick_name'] = emoji_decode($list[$k]['nick_name']);
  971. }
  972. $root['list'] = $list;
  973. if (count($list) == $page_size)
  974. $root['has_next'] = 1;
  975. else
  976. $root['has_next'] = 0;
  977. $root['page'] = $page;//
  978. }else{
  979. $root['has_next'] = 0;
  980. $root['list'] = array();
  981. $root['page'] = 0;//
  982. }
  983. }
  984. ajax_return($root);
  985. }
  986. /**
  987. * 批量导入未同步的用户到im
  988. */
  989. public function account_import(){
  990. $root = array();
  991. $root['status'] = 1;
  992. fanwe_require(APP_ROOT_PATH.'system/tim/TimApi.php');
  993. $api = createTimAPI();
  994. $sql = "select id,nick_name,head_image from ".DB_PREFIX."user where synchronize = 0 limit 10";
  995. $list = $GLOBALS['db']->getAll($sql);
  996. foreach ( $list as $k => $v )
  997. {
  998. $face_url = get_spec_image($v['head_image']);
  999. $ret = $api->account_import((string)$v['id'], $v['nick_name'], $face_url);
  1000. if ($ret['ActionStatus'] == 'OK'){
  1001. $sql = 'update '.DB_PREFIX."user set synchronize =1 where id =".$v['id'];
  1002. $GLOBALS['db']->query($sql);
  1003. }else{
  1004. $root['ret'][$v['id']] = $ret;
  1005. }
  1006. //print_r($ret);
  1007. }
  1008. ajax_return($root);
  1009. }
  1010. /**
  1011. * 允许直播的话,未同意状态改为同意
  1012. */
  1013. public function agree(){
  1014. $user_id = intval($GLOBALS['user_info']['id']);
  1015. if($user_id){
  1016. $GLOBALS['db']->query("update ".DB_PREFIX."user set is_agree =1 where id=".$user_id." and is_agree = 0 ");
  1017. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/UserRedisService.php');
  1018. $user_redis = new UserRedisService();
  1019. $data['is_agree'] = 1;
  1020. $user_redis->update_db($user_id, $data);
  1021. }
  1022. $root['status'] =1;
  1023. $root['error'] ='';
  1024. ajax_return($root);
  1025. }
  1026. /**
  1027. * 一次性取出,我关注的用户列表
  1028. */
  1029. public function my_follow(){
  1030. $root = array();
  1031. $root['status'] = 1;
  1032. // $GLOBALS['user_info']['id'] = 290;
  1033. if(!$GLOBALS['user_info']){
  1034. $root['error'] = "用户未登陆,请先登陆.";
  1035. $root['status'] = 0;
  1036. $root['user_login_status'] = 0;//有这个参数: user_login_status = 0 时,表示服务端未登陆、要求登陆,操作
  1037. }else{
  1038. $user_id = intval($GLOBALS['user_info']['id']);//id
  1039. // $sql = "select f.podcast_id as user_id from ".DB_PREFIX."focus f where f.user_id = ".$user_id;
  1040. //
  1041. // //$root['sql'] = $sql;
  1042. //
  1043. // $list = $GLOBALS['db']->getAll($sql);
  1044. // $root['list'] = $list;
  1045. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/UserFollwRedisService.php');
  1046. $user_redis = new UserFollwRedisService($user_id);
  1047. $root['list'] = $user_redis->get_follonging_user($user_id,1,1000);
  1048. if(!empty($root['list']))
  1049. {
  1050. for($i=0;$i<count($root['list']);$i++)
  1051. {
  1052. $root['list'][$i]['nick_name'] = emoji_decode($root['list'][$i]['nick_name']);
  1053. $root['list'][$i]['signature'] = emoji_decode($root['list'][$i]['signature']);
  1054. }
  1055. }
  1056. }
  1057. ajax_return($root);
  1058. }
  1059. /**
  1060. * 好友,相互关注的用户;用于私密直播时,添加的用户列表
  1061. */
  1062. public function friends(){
  1063. $root = array();
  1064. $root['status'] = 1;
  1065. //$GLOBALS['user_info']['id'] = 278;
  1066. if(!$GLOBALS['user_info']){
  1067. $root['error'] = "用户未登陆,请先登陆.";
  1068. $root['status'] = 0;
  1069. $root['user_login_status'] = 0;//有这个参数: user_login_status = 0 时,表示服务端未登陆、要求登陆,操作
  1070. }else{
  1071. $user_id = intval($GLOBALS['user_info']['id']);//id
  1072. $video_id = intval($_REQUEST['room_id']);
  1073. $page = intval($_REQUEST['p']);//取第几页数据
  1074. if($page==0){
  1075. $page = 1;
  1076. }
  1077. $page_size=20;
  1078. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/UserFollwRedisService.php');
  1079. $user_redis = new UserFollwRedisService($user_id);
  1080. $root = $user_redis->get_private_user($page,$page_size);
  1081. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/VideoRedisService.php');
  1082. $video_redis = new VideoRedisService();
  1083. $video_data = $video_redis->getRow_db($video_id,array('group_id','user_id'));
  1084. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/VideoViewerRedisService.php');
  1085. $video_viewer_redis = new VideoViewerRedisService();
  1086. $group_id = $video_data['group_id'];//聊天群id
  1087. if($group_id) {
  1088. $users = $video_viewer_redis->get_viewer_list($group_id, $page);
  1089. if($users['list']){
  1090. $user_ids = array_column($users['list'],'user_id');
  1091. $friends = $root['list'];
  1092. foreach($friends as $k=>$v){
  1093. if(in_array($v['user_id'],$user_ids) || $v['user_id']==$video_data['user_id']){
  1094. unset($friends[$k]);
  1095. }
  1096. }
  1097. $root['list'] = array_values($friends);
  1098. }
  1099. }
  1100. }
  1101. if(!empty($root['list']))
  1102. {
  1103. for($i=0;$i<count($root['list']);$i++)
  1104. {
  1105. $root['list'][$i]['nick_name'] = emoji_decode($root['list'][$i]['nick_name']);
  1106. $root['list'][$i]['signature'] = emoji_decode($root['list'][$i]['signature']);
  1107. }
  1108. }
  1109. ajax_return($root);
  1110. }
  1111. /**
  1112. * 获得用户基本信息(比如:固化的信息比如:头像,性别,昵称,等级,签名等)
  1113. */
  1114. public function baseinfo(){
  1115. $root = array();
  1116. //$GLOBALS['user_info']['id'] = 292;
  1117. if(!$GLOBALS['user_info']){
  1118. $root['error'] = "用户未登陆,请先登陆.";
  1119. $root['status'] = 0;
  1120. $root['user_login_status'] = 0;//有这个参数: user_login_status = 0 时,表示服务端未登陆、要求登陆,操作
  1121. }else{
  1122. $user_id = intval($GLOBALS['user_info']['id']);
  1123. $user_ids = strim($_REQUEST['user_ids']);//字符串类型的用户id 23,123,3455 以英文逗号分割的字符串 ,一次不能大于100个用户
  1124. if ($user_ids == ''){
  1125. $user_ids = $user_id;
  1126. }
  1127. //将选中的:私聊 数据添加到数据库中
  1128. $user_list = explode(',',$user_ids);
  1129. if (count($user_list) > 100){
  1130. $root['status'] =0;
  1131. $root['error'] ='一次不能大于100个用户';
  1132. }else{
  1133. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/UserRedisService.php');
  1134. $user_redis = new UserRedisService();
  1135. $list = $user_redis->get_m_user($user_list);
  1136. /*
  1137. $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');
  1138. foreach ( $user_list as $k => $v )
  1139. {
  1140. $userinfo = $user_redis->getRow_db($v,$fields);
  1141. $userinfo['user_id'] = $v;
  1142. $list[] = $userinfo;
  1143. }
  1144. $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.")";
  1145. $list = $GLOBALS['db']->getAll($sql);
  1146. foreach ( $list as $k => $v )
  1147. {
  1148. $list[$k]['head_image'] = get_abs_img_root($v['head_image']);
  1149. }
  1150. */
  1151. $root['list'] = $list;
  1152. if(!empty($root['list']))
  1153. {
  1154. for($i=0;$i<count($root['list']);$i++)
  1155. {
  1156. $root['list'][$i]['nick_name'] = emoji_decode($root['list'][$i]['nick_name']);
  1157. }
  1158. }
  1159. $root['status'] = 1;
  1160. }
  1161. }
  1162. ajax_return($root);
  1163. }
  1164. /**
  1165. * app呼醒跟进入后台时调用【用来统计用户在线时长】
  1166. */
  1167. function state_change(){
  1168. $root = array();
  1169. $root['status'] = 1;
  1170. if(!$GLOBALS['user_info']){
  1171. $root['error'] = "用户未登陆,请先登陆.";
  1172. $root['status'] = 0;
  1173. $root['user_login_status'] = 0;//有这个参数: user_login_status = 0 时,表示服务端未登陆、要求登陆,操作
  1174. }else{
  1175. $user_id = intval($GLOBALS['user_info']['id']);
  1176. $action = strim($_REQUEST['action']);
  1177. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/UserRedisService.php');
  1178. $user_redis = new UserRedisService();
  1179. if (strtolower($action) == 'login'){
  1180. $data = array('is_online'=>1,'login_time'=>to_date(NOW_TIME));
  1181. $GLOBALS['db']->autoExecute(DB_PREFIX."user", $data,"UPDATE", 'id='.$user_id);
  1182. $user_redis->update_db($user_id, $data);
  1183. }else{
  1184. $data = array('is_online'=>0,'login_time'=>to_date(NOW_TIME),'logout_time'=>to_date(NOW_TIME));
  1185. $user = $user_redis->getRow_db($user_id, array('login_time','logout_time','online_time'));
  1186. $login_time = to_timespan($user['login_time']);
  1187. if ($login_time == 0){
  1188. $data['login_time'] = to_date(NOW_TIME);
  1189. }
  1190. //计算在线时长
  1191. $online = NOW_TIME - $login_time;
  1192. if ($online > 7200){
  1193. //异常数据,一次不可能超过8小时
  1194. $online = 0;
  1195. }
  1196. $data['online_time'] = $user['online_time'] + $online;
  1197. $GLOBALS['db']->autoExecute(DB_PREFIX."user", $data,"UPDATE", 'id='.$user_id);
  1198. if($GLOBALS['db']->affected_rows()){
  1199. $user_redis->update_db($user_id, $data);
  1200. //更新用户等级
  1201. $user_info = $user_redis->getRow_db($user_id,array('id','score','online_time','user_level'));
  1202. user_leverl_syn($user_info);
  1203. }
  1204. }
  1205. }
  1206. ajax_return($root);
  1207. }
  1208. }