| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474 |
- <?php
- // +----------------------------------------------------------------------
- // | FANWE 直播系统
- // +----------------------------------------------------------------------
- // | Copyright (c) 2011 http://www.fanwe.com All rights reserved.
- // +----------------------------------------------------------------------
- // | Author: 云淡风轻(1956838968@qq.com)
- // +----------------------------------------------------------------------
- class userModule extends baseModule
- {
- /**
- * 获取用户签名
- */
- public function usersig()
- {
- /**
- * 获取用户签名
- **/
-
- //$GLOBALS['user_info']['id'] = 320;
- $root = array();
-
-
- if(!$GLOBALS['user_info']){
- $root['error'] = "用户未登陆,请先登陆.";// es_session::id();
- //$root['es_session'] = es_session::id();
- //$root['user_info'] = json_encode(es_session::get("user_info"));
- $root['status'] = 0;
- $root['user_login_status'] = 0;//有这个参数: user_login_status = 0 时,表示服务端未登陆、要求登陆,操作
- }else{
-
- $identifier = $GLOBALS['user_info']['id'];// $_REQUEST['identifier'];
-
- $root = load_auto_cache("usersig", array("id"=>$identifier));
-
- /*
- $usersig = $GLOBALS['db']->getOne("select usersig from ".DB_PREFIX."user where id=".$identifier." and expiry_after >" .NOW_TIME);
- if(!$usersig){
- fanwe_require(APP_ROOT_PATH.'system/tim/TimApi.php');
- $api = createRestAPI();
-
- $private_pem_path = APP_ROOT_PATH."system/tim/ec_key.pem";
- $signature = get_signature();
-
- $ret = $api->generate_user_sig($identifier, '86400', $private_pem_path, $signature);
- $expiry_after = NOW_TIME + 86400;
- //echo "update ".DB_PREFIX."user set usersig = ".$ret[0].",expiry_after=".$expiry_after." where id = ".$identifier;exit;
- $GLOBALS['db']->query("update ".DB_PREFIX."user set usersig = '".$ret[0]."',expiry_after=".$expiry_after." where id = ".$identifier);
-
- }else{
- $ret[0] =$usersig;
- }
-
- if($ret == null || strstr($ret[0], "failed")){
- $root['error'] = "获取usrsig失败, 请确保TimRestApiConfig.json配置信息正确";
- $root['status'] = 0;
- }else{
- $root['usersig'] = $ret[0];
- $root['status'] = 1;
- }
- */
- }
- if(intval($_REQUEST['ajax_type'])&&intval(IS_DEBUG)){
- print_r($root);echo "<hr/>";
- }
- ajax_return($root);
- }
- /**
- * 获得用户公开信息;不传identifier时,则获得当前登陆用户的信息
- */
- public function userinfo(){
- $root = array();
- //$GLOBALS['user_info']['id'] = 292;
- if(!$GLOBALS['user_info']){
- $root['error'] = "用户未登陆,请先登陆.";
- $root['status'] = 0;
- $root['user_login_status'] = 0;//有这个参数: user_login_status = 0 时,表示服务端未登陆、要求登陆,操作
- }else{
- $user_id = intval($GLOBALS['user_info']['id']);
- $podcast_id = intval($_REQUEST['podcast_id']);//主播id,fanwe_user.id
- $to_user_id = intval($_REQUEST['to_user_id']);//需要查看的用户id
- if ($to_user_id == 0){
- $to_user_id = $user_id;
- }
- $root = getuserinfo($user_id,$podcast_id,$to_user_id,$_REQUEST);
- $m_config = load_auto_cache("m_config");//初始化手机端配置
- $root['init_version'] = intval($m_config['init_version']);//手机端配置版本号
-
- //公会ljz
- if($root['user']['society_id'] > 0){
- $root['user']['society_name'] = $GLOBALS['db']->getOne("select name from ".DB_PREFIX."society where id=".$root['user']['society_id']);
- }else{
- $root['user']['society_name'] = '';
- }
- if($m_config['name_limit']==1){
- $user = $GLOBALS['db']->getRow("select nick_name from ".DB_PREFIX."user where id = ".$user_id);
- $nick_name=$user['nick_name'];
- //进入个人中心过滤铭感词汇
- $limit_sql =$GLOBALS['db']->getCol("SELECT name FROM ".DB_PREFIX."limit_name");
- if($GLOBALS['db']->getCol("SELECT name FROM ".DB_PREFIX."limit_name WHERE '$nick_name' like concat('%',name,'%')")){
- $nick_name=str_replace($limit_sql,'*',$nick_name);
- }
- //判断用户名如果被过滤后为空,格式则变更为: 账号+ID
- if($nick_name==''){
- $nick_name=('账号'.$user_id);
- }
- //更新数据库
- $sql = "update ".DB_PREFIX."user set nick_name = '$nick_name' where id=".$user_id;
- $GLOBALS['db']->query($sql);
- //更新redis
- user_deal_to_reids(array($user_id));
- //二级分销
- if ((defined('DISTRIBUTION_SCAN')&&DISTRIBUTION_SCAN==1)) //二级分销按钮
- {
- $login_type = $GLOBALS['db']->getRow("select login_type from ".DB_PREFIX."user where id = ".$user_id); //获取登录用户类型
- if ($login_type['login_type']!='4') //若不是游客登录,才可进行二级分销
- {
- $root['distribution_btn'] = 1; //显示分销二维码和分享界面的按钮
- //分销转发的数据
- $share = array();
- $share['share_title'] = strim($m_config['share_title']);//'你丑你先睡,我美我直播!';
- $head_image = $GLOBALS['db']->getRow("select head_image from ".DB_PREFIX."user where id = ".$user_id);
- $share['share_imageUrl']=get_spec_image($head_image['head_image']);
- $share['share_url'] = SITE_DOMAIN.APP_ROOT.'/mapi/index.php?ctl=share_distribution&act=index&share_id='.$user_id; //分销分享的URL(二维码或者其他地方转发)
- $share['share_content'] = $user['nick_name'].'邀请您加入我们,一起来看直播~';
- $root['share'] = $share; //分销分享部分的数据
- $qr_code = $GLOBALS['db']->getRow("select qr_code from ".DB_PREFIX."user where id = ".$user_id);
- $root['qr_code'] = get_spec_image($qr_code['qr_code']);//分销二维码图片路径
- }
- }
- }
- $sdk_version_name = strim($_REQUEST['sdk_version_name']);
- $root['show_red'] = $m_config['ios_check_version'] && $m_config['ios_check_version'] == $sdk_version_name ? 0 : 1;
- $root['status'] = 1;
- //格式化数据(大于10000保留两位小数,否则不变)
- fanwe_require(APP_ROOT_PATH.'mapi/lib/core/num_format.php');
- $root['user']['n_fans_count'] = format_for_ten_thousand($root['user']['fans_count']);
- $root['user']['n_focus_count'] = format_for_ten_thousand($root['user']['focus_count']);
- $root['user']['n_use_diamonds'] = format_for_ten_thousand($root['user']['use_diamonds']);
- $root['user']['n_ticket'] = format_for_ten_thousand($root['user']['ticket']);
- $root['user']['n_video_count'] = format_for_ten_thousand($root['user']['video_count']);
- $root['user']['n_useable_ticket'] = format_for_ten_thousand($root['user']['useable_ticket']);
- $root['user']['n_diamonds'] = format_for_ten_thousand($root['user']['diamonds']);
- $root['user']['n_use_diamonds'] = format_for_ten_thousand($root['user']['use_diamonds']);
- $root['user']['n_show_user_order'] = format_for_ten_thousand($root['user']['show_user_order']);
- $root['user']['n_user_order'] = format_for_ten_thousand($root['user']['user_order']);
- $root['user']['n_show_user_pai'] = format_for_ten_thousand($root['user']['show_user_pai']);
- $root['user']['n_user_pai'] = format_for_ten_thousand($root['user']['user_pai']);
- $root['user']['n_show_podcast_order'] = format_for_ten_thousand($root['user']['show_podcast_order']);
- $root['user']['n_podcast_order'] = format_for_ten_thousand($root['user']['podcast_order']);
- $root['user']['n_show_shopping_cart'] = format_for_ten_thousand($root['user']['show_shopping_cart']);
- $root['user']['n_shopping_cart'] = format_for_ten_thousand($root['user']['shopping_cart']);
- $root['user']['n_podcast_goods'] = format_for_ten_thousand($root['user']['podcast_goods']);
- $root['user']['n_coin'] = format_for_ten_thousand($root['user']['coin']);
- $root['user']['n_podcast_pai'] = format_for_ten_thousand($root['user']['podcast_pai']);
- $root['user']['n_shop_goods'] = format_for_ten_thousand($root['user']['shop_goods']);
- $root['user']['n_svideo_count'] = format_for_ten_thousand($root['user']['svideo_count']);
- }
- ajax_return($root);
- }
- /**
- * 关注某个用户
- */
- public function follow(){
- $root = array('status'=>1,'error'=>'');
-
- //$GLOBALS['user_info']['id'] = 269;
- if(!$GLOBALS['user_info']){
- $root['error'] = "用户未登陆,请先登陆.";
- $root['status'] = 0;
- $root['user_login_status'] = 0;//有这个参数: user_login_status = 0 时,表示服务端未登陆、要求登陆,操作
- }else{
- //
- $user_level = $GLOBALS['db']->getOne("select user_level from ".DB_PREFIX."user where id = ".$GLOBALS['user_info']['id'],true,true);
- $m_config = load_auto_cache("m_config");//初始化手机端配置
- $show_follow_msg = intval($m_config['show_follow_msg']);//是否现发送关注提示信息 0:不显示; 1:显示
- $show_follow_msg_lv = intval($m_config['show_follow_msg_lv']);//关注提示显示的等级
- $user_id = intval($GLOBALS['user_info']['id']);//当前用户;
- $room_id = intval($_REQUEST['room_id']);//room_id 当前直播房间号,用来:计算权重的;
-
- $to_user_id = intval($_REQUEST['to_user_id']);//被关注或取消关注的用户
- $to_user_id = $GLOBALS['db']->getOne("select id from ".DB_PREFIX."user where id = ".$to_user_id,true,true);
- if(!intval($to_user_id)) {
- $root['error'] = "关注的用户不存在!";
- $root['status'] = 0;
- }else if($user_id!=$to_user_id){
- $root = redis_set_follow($user_id,$to_user_id,false,$room_id);
- clear_auto_cache("playback_list",array("user_id"=>$user_id));
- if($show_follow_msg && ($user_level>=$show_follow_msg_lv)){
- $root['follow_msg'] = emoji_decode($GLOBALS['user_info']['nick_name'])."关注了主播";
- }else {
- $root['follow_msg'] = '';
- }
- /*
- fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/UserFollwRedisService.php');
- $user_redis = new UserFollwRedisService($user_id);
- //查看关注人数
- $follow_count = $user_redis->follow_count();
- //粉丝人数
- $follow_by_count = $user_redis->follower_count();
- //update_follow($user_id,$follow_count,$follow_by_count);
-
- //$root = set_follow($user_id,$to_user_id);
- //$root = redis_set_follow($user_id,$to_user_id);
- */
- if (defined('OPEN_MISSION') && OPEN_MISSION && $root['has_focus']) {
- require_once APP_ROOT_PATH . 'mapi/lib/core/Model.class.php';
- Model::$lib = dirname(__FILE__);
- Model::build('mission')->incProgress($user_id,4);
- }
- }else{
- $root['error'] = "不能关注自己!";
- $root['status'] = 0;
- }
-
- }
- ajax_return($root);
- }
- /**
- * 禁言,只有:主群或群管理员才能设置
- */
- public function forbid_send_msg(){
- $root = array();
- $root['status'] = 0;
- $root['is_forbid'] = 0;
- //$GLOBALS['user_info']['id'] = 1;
-
- if(!$GLOBALS['user_info']){
- $root['error'] = "用户未登陆,请先登陆.";
- $root['status'] = 0;
- $root['user_login_status'] = 0;//有这个参数: user_login_status = 0 时,表示服务端未登陆、要求登陆,操作
- }else{
-
- $user_id = intval($GLOBALS['user_info']['id']);//
- $to_user_id = strim($_REQUEST['to_user_id']);//被禁言的用户id
- $group_id = strim($_REQUEST['group_id']);//群组ID
- $second = intval($_REQUEST['second']);//禁言时间,单位为秒; 为0时表示取消禁言
- $is_nospeaking = $GLOBALS['db']->getOne("select is_nospeaking from ".DB_PREFIX."user where id = ".$to_user_id,true,true);
- if(intval($is_nospeaking)==1){
- $root['error'] = "该用户已被im全局禁言.";
- ajax_return($root);
- }
-
- fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/VideoRedisService.php');
- $video_redis = new VideoRedisService();
- $video = $video_redis->getRow_db_ByGroupId($group_id,array('id','user_id'));
- // //优化
- // $forbid_info = $video_redis->has_forbid_msg($group_id,$to_user_id);//判断某个用户是否被禁言(被禁言返回:true; 未被禁言返回:false)
- // if($forbid_info && intval($forbid_info)>NOW_TIME){
- // $second = 0;
- // }else{
- // $second = 10000;
- // $video_redis->unset_forbid_msg($group_id,$to_user_id);
- // }
-
- //$sql = "select id,user_id,group_id from ".DB_PREFIX."video where group_id = '".$group_id."'";
- //$video = $GLOBALS['db']->getRow($sql,true,true);
- $podcast_id = intval($video['user_id']);
- $room_id = intval($video['id']);
-
-
- //查看自己
- if ($to_user_id == $user_id){
- $root['error'] = "不能自己给自己禁言";
- }else{
- $allow = false;
- //主播查看
- if ($podcast_id == $user_id){
- $allow = true;//主播 有权限禁言
- }else{
- $sql = "select count(id) as num from ".DB_PREFIX."user_admin where podcast_id = ".$podcast_id." and user_id = ".$user_id;
- if ($GLOBALS['db']->getOne($sql,true,true) > 0){
- $allow = true;//管理员 有权限禁言按钮
- }
- }
-
- }
- if ($allow){
- $sql = "select is_robot,nick_name from ".DB_PREFIX."user where id = '".$to_user_id."'";
- $user = $GLOBALS['db']->getRow($sql,true,true);
- $nick_name = $user['nick_name'];
- fanwe_require(APP_ROOT_PATH.'system/tim/TimApi.php');
- $api = createTimAPI();
- //设置:禁言(second>0),取消禁言(second = 0)
- if($user['is_robot'] != 1){
- $ret = $api->group_forbid_send_msg($group_id,(string)$to_user_id,$second);
- }
- if ($ret['ActionStatus'] == 'OK' || $user['is_robot'] == 1){
- //$ret = $api->get_group_shutted_uin($group_id);
- if ($second > 0){
- /*
- $forbid_send_msg = array();
- $forbid_send_msg['group_id'] = $group_id;
- $forbid_send_msg['user_id'] = $to_user_id;
- $forbid_send_msg['shut_up_time'] = NOW_TIME + $second;
- $GLOBALS['db']->autoExecute(DB_PREFIX."video_forbid_send_msg", $forbid_send_msg,"INSERT");
- */
- //禁言到期时间
- if($second>86400){//大于一天则永禁言
- $msg = emoji_decode($nick_name). " 被永久禁言";//.print_r($ret,1).';user_id:'.$user_id.";second:".$second.";group_id:".$group_id;
- $second = 99999999;
- }else{
- $msg = emoji_decode($nick_name). " 被禁言".get_live_time_len2($second);
- }
- $root['is_forbid'] = 1;
- $shutup_time = NOW_TIME+$second;
- $video_redis->set_forbid_msg($group_id,$to_user_id,$shutup_time);
- }else{
- $msg = emoji_decode($nick_name). " 取消禁言";
- $video_redis->unset_forbid_msg($group_id,$to_user_id);
- $root['is_forbid'] = 0;
- //$sql = "delete from ".DB_PREFIX."video_forbid_send_msg where group_id='".$group_id."' and user_id = '".$to_user_id."'";
- //$GLOBALS['db']->query($sql);
- }
- $root['status'] = 1;
- }else{
- $root['status'] = 0;
- $root['error'] = $ret['ErrorInfo'].":".$ret['ErrorCode'];
- }
- if ($root['status'] == 1){
- if (!$api){
- fanwe_require(APP_ROOT_PATH.'system/tim/TimApi.php');
- $api = createTimAPI();
- }
-
- //群播一个:禁言通知
- $ext = array();
- $ext['type'] = 4; //0:普通消息;1:礼物;2:弹幕消息;3:主播退出;4:禁言;5:观众进入房间;6:观众退出房间;7:直播结束
- $ext['room_id'] = $room_id;//直播ID 也是room_id;只有与当前房间相同时,收到消息才响应
- $ext['fonts_color'] = '';//字体颜色
- $ext['desc'] = $msg;//禁言通知消息;
- $ext['desc2'] = $msg;//禁言通知消息;
-
- //消息发送者
- $sender = array();
- $sender['user_id'] = $GLOBALS['user_info']['id'];//发送人昵称
- $sender['nick_name'] = emoji_decode($GLOBALS['user_info']['nick_name']);//发送人昵称
- $sender['head_image'] = $GLOBALS['user_info']['head_image'];//发送人头像
- $sender['user_level'] = $GLOBALS['user_info']['user_level'];//用户等级
-
- $ext['sender'] = $sender;
-
-
- #构造高级接口所需参数
- $msg_content = array();
- //创建array 所需元素
- $msg_content_elem = array(
- 'MsgType' => 'TIMCustomElem', //自定义类型
- 'MsgContent' => array(
- 'Data' => json_encode($ext),
- 'Desc' => '',
- // 'Ext' => $ext,
- // 'Sound' => '',
- )
- );
- //将创建的元素$msg_content_elem, 加入array $msg_content
- array_push($msg_content, $msg_content_elem);
-
- $ret = $api->group_send_group_msg2($GLOBALS['user_info']['id'], $group_id, $msg_content);
- }
-
-
- }else{
- $root['error'] = "无禁言权限";
- }
- }
- ajax_return($root);
-
- }
-
- /**
- * 设置/取消 管理员
- */
- public function set_admin(){
-
- $root = array();
- $root['status'] = 1;
-
- if(!$GLOBALS['user_info']){
- $root['error'] = "用户未登陆,请先登陆.";
- $root['status'] = 0;
- $root['user_login_status'] = 0;//有这个参数: user_login_status = 0 时,表示服务端未登陆、要求登陆,操作
- }else{
- //
- $user_id = intval($GLOBALS['user_info']['id']);
- $to_user_id = intval($_REQUEST['to_user_id']);//被关注或取消 管理员用户
-
- $room_id = strim($_REQUEST['room_id']);
-
-
- $sql = "select id from ".DB_PREFIX."user_admin where podcast_id = '".$user_id."' and user_id = ".$to_user_id;
- $user_admin_id = $GLOBALS['db']->getOne($sql);
- if ($user_admin_id > 0){
- //取消管理员操作;
- $sql = "delete from ".DB_PREFIX."user_admin where id = ".$user_admin_id;
- $GLOBALS['db']->query($sql);
-
- }else{
- $sql = "select count(id) as num from ".DB_PREFIX."user_admin where podcast_id = ".$GLOBALS['user_info']['id'];
- if ($GLOBALS['db']->getOne($sql) < 5){
- //设置管理员操作;
- $user_admin = array();
- $user_admin['podcast_id'] = $GLOBALS['user_info']['id'];
- $user_admin['user_id'] = $to_user_id;
- $user_admin['create_time'] = NOW_TIME;
- $GLOBALS['db']->autoExecute(DB_PREFIX."user_admin", $user_admin,"INSERT");
- }else{
- $root['error'] = "已经超过5位管理员,不能再设置新的管理员";
- $root['status'] = 0;
- }
- }
-
- $sql = "select id from ".DB_PREFIX."user_admin where podcast_id = '".$user_id."' and user_id = ".$to_user_id;
- if ($GLOBALS['db']->getOne($sql) > 0){
- $root['has_admin'] = 1;//0:非管理员;1:是管理员
- }else{
- $root['has_admin'] = 0;
- }
-
-
- if ($root['status'] ==1 && $room_id != ''){
-
- $sql = "select nick_name from ".DB_PREFIX."user where id = '".$to_user_id."'";
- if ($root['has_admin'] == 1){
- $msg = emoji_decode($GLOBALS['db']->getOne($sql)). " 被设置为管理员";
- }else{
- $msg = emoji_decode($GLOBALS['db']->getOne($sql)). " 管理员被取消";
- }
-
-
- fanwe_require(APP_ROOT_PATH.'system/tim/TimApi.php');
- $api = createTimAPI();
-
- //群播一个:直播消息
- $ext = array();
- $ext['type'] = 9; //0:普通消息;1:礼物;2:弹幕消息;3:主播退出;4:禁言;5:观众进入房间;6:观众退出房间;7:直播结束
- $ext['room_id'] = $room_id;//直播ID 也是room_id;只有与当前房间相同时,收到消息才响应
- $ext['fonts_color'] = '';//字体颜色
- $ext['desc'] = $msg;//禁言通知消息;
- $ext['desc2'] = $msg;//禁言通知消息;
-
- //消息发送者
- $sender = array();
- $sender['user_id'] = $GLOBALS['user_info']['id'];//发送人昵称
- $sender['nick_name'] = emoji_decode($GLOBALS['user_info']['nick_name']);//发送人昵称
- $sender['head_image'] = $GLOBALS['user_info']['head_image'];//发送人头像
- $sender['user_level'] = $GLOBALS['user_info']['user_level'];//用户等级
-
- $ext['sender'] = $sender;
-
-
- #构造高级接口所需参数
- $msg_content = array();
- //创建array 所需元素
- $msg_content_elem = array(
- 'MsgType' => 'TIMCustomElem', //自定义类型
- 'MsgContent' => array(
- 'Data' => json_encode($ext),
- 'Desc' => '',
- // 'Ext' => $ext,
- // 'Sound' => '',
- )
- );
- //将创建的元素$msg_content_elem, 加入array $msg_content
- array_push($msg_content, $msg_content_elem);
-
-
- $sql = "select group_id from ".DB_PREFIX."video where id = '".$room_id."'";
- $group_id = $GLOBALS['db']->getOne($sql);
-
- $ret = $api->group_send_group_msg2($GLOBALS['user_info']['id'], $group_id, $msg_content);
- if ($ret['ActionStatus'] == 'FAIL' && $ret['ErrorCode'] == 10002){
- //10002 系统错误,请再次尝试或联系技术客服。
- $ret = $api->group_send_group_msg2($GLOBALS['user_info']['id'], $group_id, $msg_content);
- }
-
- }
-
- }
-
- ajax_return($root);
- }
- /**
- * 举报用户
- */
- public function tipoff(){
-
- $root = array();
- $root['status'] = 1;
-
- if(!$GLOBALS['user_info']){
- $root['error'] = "用户未登陆,请先登陆.";
- $root['status'] = 0;
- $root['user_login_status'] = 0;//有这个参数: user_login_status = 0 时,表示服务端未登陆、要求登陆,操作
- }else{
-
- $to_user_id = intval($_REQUEST['to_user_id']);//被关注的举报用户ID
- $type = intval($_REQUEST['type']);
- $room_id = intval($_REQUEST['room_id']); //被举报的房间id
-
- $tipoff = array();
- $tipoff['from_user_id'] = $GLOBALS['user_info']['id'];
- $tipoff['to_user_id'] = $to_user_id;
- $tipoff['create_time'] = NOW_TIME;
- $tipoff['tipoff_type_id'] = $type;
- $tipoff['video_id'] = $room_id;
- $GLOBALS['db']->autoExecute(DB_PREFIX."tipoff", $tipoff,"INSERT");
-
- if ($room_id > 0){
- //累加举报次数
- $sql = "update ".DB_PREFIX."video set tipoff_count = tipoff_count + 1 where id =".$room_id;
- $GLOBALS['db']->query($sql);
- }
- }
- ajax_return($root);
- }
- /**
- * 主播管理员列表
- */
- public function user_admin(){
-
- $root = array();
- $root['status'] = 1;
-
- if(!$GLOBALS['user_info']){
- $root['error'] = "用户未登陆,请先登陆.";
- $root['status'] = 0;
- $root['user_login_status'] = 0;//有这个参数: user_login_status = 0 时,表示服务端未登陆、要求登陆,操作
- }else{
-
- $user_id = intval($GLOBALS['user_info']['id']);//用户ID
-
-
- $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;
- $list = $GLOBALS['db']->getAll($sql);
- foreach($list as $k=>$v){
- $list[$k]['head_image'] = get_spec_image($v['head_image']);
- $list[$k]['nick_name'] = emoji_decode($list[$k]['nick_name']);
- }
- $root['list'] = $list;
-
- $root['max_num'] = 5;
- $root['cur_num'] = count($list);
-
- $root['status'] = 1;
- }
-
- ajax_return($root);
- }
-
- /**
- * 关注的用户,最多不超过100个
- */
- public function user_follow(){
-
- $root = array();
- $root['status'] = 1;
- //$GLOBALS['user_info']['id'] = 278;
- if(!$GLOBALS['user_info']){
- $root['error'] = "用户未登陆,请先登陆.";
- $root['status'] = 0;
- $root['user_login_status'] = 0;//有这个参数: user_login_status = 0 时,表示服务端未登陆、要求登陆,操作
- }else{
-
- $user_id = intval($GLOBALS['user_info']['id']);//id
- $page = intval($_REQUEST['p']);//取第几页数据
- if($page==0){
- $page = 1;
- }
- if (isset($_REQUEST['to_user_id'])){
- $to_user_id = strim($_REQUEST['to_user_id']);//被查看的用户id
- }else{
- $to_user_id = $user_id;//id
- }
- $page_size = 20;
- fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/UserFollwRedisService.php');
- $user_redis = new UserFollwRedisService($user_id);
- $list = $user_redis->get_follonging_user($to_user_id,$page,$page_size);
- foreach($list as $k=>$v){
- $list[$k]['signature'] = htmlspecialchars_decode($list[$k]['signature']);
- $list[$k]['nick_name'] = htmlspecialchars_decode($list[$k]['nick_name']);
- $list[$k]['signature'] = emoji_decode($list[$k]['signature']);
- $list[$k]['nick_name'] = emoji_decode($list[$k]['nick_name']);
- }
- $root['list'] = $list;
- $rs_count = $user_redis->following();
- if($page==0){
- $root['has_next'] = 0;
- }else{
- if (count($rs_count) >= $page_size)
- $root['has_next'] = 1;
- else
- $root['has_next'] = 0;
- }
-
- $root['page'] = $page;//
-
- }
- ajax_return($root);
- }
- /**
- * 粉丝列表,最多不超过100个
- */
- public function user_focus(){
-
- $root = array();
- $root['status'] = 1;
- //$GLOBALS['user_info']['id'] = 278;
- if(!$GLOBALS['user_info']){
- $root['error'] = "用户未登陆,请先登陆.";
- $root['status'] = 0;
- $root['user_login_status'] = 0;//有这个参数: user_login_status = 0 时,表示服务端未登陆、要求登陆,操作
- }else{
- $user_id = intval($GLOBALS['user_info']['id']);//id
- if (isset($_REQUEST['to_user_id'])){
- $to_user_id = strim($_REQUEST['to_user_id']);//被查看的用户id
- }else{
- $to_user_id = $user_id;
- }
-
- $page = intval($_REQUEST['p']);//取第几页数据
- if($page==0){
- $page = 1;
- }
- $page_size = 20;
- fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/UserFollwRedisService.php');
- $user_redis = new UserFollwRedisService($user_id);
- $list = $user_redis->get_follonging_by_user($to_user_id,$page);
- $keys = $user_redis->following();
- foreach($list as $k=>$v){
- if($user_id>0){
- if (in_array($v['user_id'],$keys)){
- $list[$k]['follow_id'] = 1;
- }else{
- $list[$k]['follow_id'] = 0;
- }
- }else{
- $list[$k]['follow_id'] = 0;
- }
- $list[$k]['head_image'] = get_spec_image($v['head_image']);
- $list[$k]['nick_name'] = htmlspecialchars_decode($list[$k]['nick_name']);
- $list[$k]['signature'] = htmlspecialchars_decode($list[$k]['signature']);
- $list[$k]['nick_name'] = emoji_decode($list[$k]['nick_name']);
- $list[$k]['signature'] = emoji_decode($list[$k]['signature']);
- }
- $root['list'] = $list;
-
-
- if($page==0){
- $root['has_next'] = 0;
- }else{
- if (count($list) >= $page_size)
- $root['has_next'] = 1;
- else
- $root['has_next'] = 0;
- }
-
- $root['page'] = $page;//
-
- }
- ajax_return($root);
- }
- /**
- * 分享成功回调
- * type: 分享类型(WEIXIN,WEIXIN_CIRCLE,QQ,QZONE,EMAIL,SMS,SINA 微信,微信朋友圈,qq,QQ空间,email,短信,新浪微博)
- */
- public function share(){
-
- $root = array();
- $root['status'] = 1;
- if(!$GLOBALS['user_info']){
- $root['error'] = "用户未登陆,请先登陆.";
- $root['status'] = 0;
- $root['user_login_status'] = 0;//有这个参数: user_login_status = 0 时,表示服务端未登陆、要求登陆,操作
- }else{
- $user_id = intval($GLOBALS['user_info']['id']);//用户ID
- $type = strtolower(strim($_REQUEST['type']));//WEIXIN,WEIXIN_CIRCLE,QQ,QZONE,EMAIL,SMS,SINA
-
- $room_id = intval($_REQUEST['room_id']);//直播ID 也是room_id
-
- //分享加印票功能
- $m_config = load_auto_cache("m_config");//初始化手机端配置
- //每个房间每个类型可以分享一次,主播分享自己房间不获得
- if(defined('OPEN_SHARE_EXPERIENCE')&&OPEN_SHARE_EXPERIENCE==1&&intval($m_config['open_share_ticket'])){
-
- $sql = "select max(id) from ".DB_PREFIX."video_share where video_id = ".$room_id." and user_id =".$user_id." and type = '".$type."'";
- $exist_share_id = $GLOBALS['db']->getOne($sql);
- //获取主播ID
- $sql = "select user_id as from_user_id from ".DB_PREFIX."video where id =".$room_id;
- $video_user_info = $GLOBALS['db']->getRow($sql);
- $share_id = intval($exist_share_id);
- if($share_id==0){
- //分享表中无记录,查分享历史表
- $sql = "select id from ".DB_PREFIX."video_share_history where video_id = ".$room_id." and user_id =".$user_id." and type = '".$type."'";
- $share_id = intval($GLOBALS['db']->getOne($sql));
- }
- $now_time = NOW_TIME;
- $s_now_time = to_timespan(to_date($now_time,"Y-m-d 00:00:00"));
- $e_now_time = to_timespan(to_date($now_time,"Y-m-d 23:59:59"));
- if($share_id==0){
- $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;
- $video_t_share_id = $GLOBALS['db']->getOne($sql);
-
- $share_id = intval($video_t_share_id);
- if($share_id==0){
- //分享表中无记录,查分享历史表
- $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;
- $share_id = intval($GLOBALS['db']->getOne($sql));
- }
- }
- }
-
-
- //每个用户每个房间可以分享一次,增加分享次数
-
- fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/VideoRedisService.php');
- $video_redis = new VideoRedisService();
- //$video_redis->incry($this->video_db.$room_id, 'share_count', 1);
- $video_redis->redis->hIncrBy($video_redis->video_db.$room_id,'share_count',1);
- $data = array();
- //写入分享表
- $video_monitor = array();
- $video_monitor['user_id'] = $user_id;
- $video_monitor['video_id'] = $room_id;
- $video_monitor['type'] = $type;
- $video_monitor['create_time'] = NOW_TIME;
- $GLOBALS['db']->autoExecute(DB_PREFIX."video_share", $video_monitor,"INSERT");
-
- $video_share_id = $GLOBALS['db']->insert_id();
- if (defined('OPEN_MISSION') && OPEN_MISSION) {
- require_once APP_ROOT_PATH . 'mapi/lib/core/Model.class.php';
- Model::$lib = dirname(__FILE__);
- Model::build('mission')->incProgress($user_id,3);
- }
- if(defined('OPEN_SHARE_EXPERIENCE')&&OPEN_SHARE_EXPERIENCE==1&&intval($m_config['open_share_ticket'])){
- //历史记录中也没有,可以增加
- if($share_id==0&&intval($m_config['share_ticket'])>0&&intval($video_user_info['from_user_id'])!=$user_id&&intval($video_share_id)>0){
- //根据open_share_ticket决定获得印票或钻石 1印票 2钻石
- $ticket_name = $m_config['ticket_name'];
- if (intval($m_config['open_share_ticket'])==1){
- $sql = "update ".DB_PREFIX."user set ticket = ticket + ".intval($m_config['share_ticket'])." where id =".$user_id;
- $data['ticket'] =intval($m_config['share_ticket']);
- if($ticket_name==''){
- $ticket_name = '印票';
- }
- }else{
- $sql = "update ".DB_PREFIX."user set diamonds = diamonds + ".intval($m_config['share_ticket'])." where id =".$user_id;
- $data['diamonds'] =intval($m_config['share_ticket']);
- $ticket_name = '钻石';
- }
- $GLOBALS['db']->query($sql);//增加用户印票或钻石
- user_deal_to_reids(array($user_id));//同步用户redis
- //请求返回信息
- $root['share_award'] =intval($m_config['share_ticket']);
- $root['share_award_type'] = $ticket_name;
- $root['share_award_info'] ='分享直播获得'.$ticket_name.intval($m_config['share_ticket']);
- //写入用户日志
- $data['log_admin_id'] = 0;
- $data['video_id'] = $room_id;
- $param['type'] = 4;//类型 0表示充值 1表示提现 2赠送道具 3 兑换印票 4 分享获得印票
- $log_msg ="通过".$type.'分享直播间'.$room_id.',获得'.intval($m_config['share_ticket']).$ticket_name;
- account_log_com($data,$user_id,$log_msg,$param);
- }
- }
- }
-
- ajax_return($root);
- }
-
- /**
- * 更新设备号
- */
- public function apns()
- {
- $root = array();
- $root['status'] = 1;
- //$GLOBALS['user_info']['id'] = 1;
- if(!$GLOBALS['user_info']){
- $root['error'] = "用户未登陆,请先登陆.";
- $root['status'] = 0;
- $root['user_login_status'] = 0;//有这个参数: user_login_status = 0 时,表示服务端未登陆、要求登陆,操作
- }else{
- $user_id = intval($GLOBALS['user_info']['id']);//用户ID
- $apns_code = addslashes($_REQUEST['apns_code']);
- if(!$apns_code)
- {
- $root['error'] = "设备号为空,更新失败";
- $root['status'] = 0;
- ajax_return($root);
- }
-
- //apns_code 友盟消息推送服务对设备的唯一标识。Android的device_token是44位字符串, iOS的device-token是64位
- //device_type 1:android; 2:ios
- if (strlen($apns_code) == 44){
- $device_type = 1;
- }else if (strlen($apns_code) == 64){
- $device_type = 2;
- }else{
- $device_type = 0;
- }
-
- $sql = 'update '.DB_PREFIX."user set apns_code ='".$apns_code."',device_type='".$device_type."' where id =".$user_id;
- $GLOBALS['db']->query($sql);
-
- fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/UserRedisService.php');
- $user_redis = new UserRedisService();
- $data['apns_code'] = $apns_code;
- $data['device_type'] = $device_type;
- $user_redis->update_db($user_id,$data);
-
- }
-
- ajax_return($root);
- }
- /**
- * 查看个人主页
- */
- public function user_home(){
- $root = array();
-
- //$GLOBALS['user_info']['id'] = 286;
- if(!$GLOBALS['user_info']){
- $root['error'] = "用户未登陆,请先登陆.";
- $root['status'] = 0;
- $root['user_login_status'] = 0;//有这个参数: user_login_status = 0 时,表示服务端未登陆、要求登陆,操作
- }else{
- $user_id = intval($GLOBALS['user_info']['id']);//用户ID
-
- $to_user_id = intval($_REQUEST['to_user_id']);//被查看的用户id
- if ($to_user_id == 0){
- $to_user_id = $user_id;
- }
-
- $root = getuserinfo($user_id,0,$to_user_id);
- $root['status'] = 1;
- //格式化数据(大于10000保留两位小数,否则不变)
- fanwe_require(APP_ROOT_PATH.'mapi/lib/core/num_format.php');
- $root['user']['n_fans_count'] = format_for_ten_thousand($root['user']['fans_count']);
- $root['user']['n_focus_count'] = format_for_ten_thousand($root['user']['focus_count']);
- $root['user']['n_use_diamonds'] = format_for_ten_thousand($root['user']['use_diamonds']);
- $root['user']['n_ticket'] = format_for_ten_thousand($root['user']['ticket']);
- $root['user']['n_video_count'] = format_for_ten_thousand($root['user']['video_count']);
- $root['user']['n_useable_ticket'] = format_for_ten_thousand($root['user']['useable_ticket']);
- $root['user']['n_diamonds'] = format_for_ten_thousand($root['user']['diamonds']);
- $root['user']['n_use_diamonds'] = format_for_ten_thousand($root['user']['use_diamonds']);
- $root['user']['n_show_user_order'] = format_for_ten_thousand($root['user']['show_user_order']);
- $root['user']['n_user_order'] = format_for_ten_thousand($root['user']['user_order']);
- $root['user']['n_show_user_pai'] = format_for_ten_thousand($root['user']['show_user_pai']);
- $root['user']['n_user_pai'] = format_for_ten_thousand($root['user']['user_pai']);
- $root['user']['n_show_podcast_order'] = format_for_ten_thousand($root['user']['show_podcast_order']);
- $root['user']['n_podcast_order'] = format_for_ten_thousand($root['user']['podcast_order']);
- $root['user']['n_show_shopping_cart'] = format_for_ten_thousand($root['user']['show_shopping_cart']);
- $root['user']['n_shopping_cart'] = format_for_ten_thousand($root['user']['shopping_cart']);
- $root['user']['n_podcast_goods'] = format_for_ten_thousand($root['user']['podcast_goods']);
- $root['user']['n_coin'] = format_for_ten_thousand($root['user']['coin']);
- $root['user']['n_podcast_pai'] = format_for_ten_thousand($root['user']['podcast_pai']);
- $root['user']['n_shop_goods'] = format_for_ten_thousand($root['user']['shop_goods']);
- $root['user']['n_svideo_count'] = format_for_ten_thousand($root['user']['svideo_count']);
- if(!$root['user']['luck_num'])
- {
- $root['user']['luck_num'] = '';
- }
- }
-
- ajax_return($root);
-
- }
- /**
- * 直播回看
- */
- public function user_review(){
- $root = array();
-
- //$GLOBALS['user_info']['id'] = 1;
-
-
- $to_user_id = intval($_REQUEST['to_user_id']);//被查看的用户id
- if ($to_user_id == 0){
- $to_user_id = intval($GLOBALS['user_info']['id']);
- }
- $sort = intval($_REQUEST['sort']);//排序类型; 0:最新;1:最热
-
-
- $page = intval($_REQUEST['p']);//取第几页数据
- if($page==0)$page = 1;
- $page_size=10;
-
- $limit = (($page-1)*$page_size).",".$page_size;
- $sort_field = "vh.begin_time desc";
- if ($sort == 1){
- $sort_field = "vh.max_watch_number desc";
- }
-
- //video_count
- if($to_user_id ==intval($GLOBALS['user_info']['id'])){
- $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;
- }else{
- $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;
- }
- $list = array();
- $list_arr = array();
- $list_info = $GLOBALS['db']->getAll($sql);
- foreach ( $list_info as $k => $v )
- {
-
- /*//判断视频存在
- fanwe_require(APP_ROOT_PATH . 'mapi/lib/core/video_factory.php');
- $video_factory = new VideoFactory();
- if($v['video_type'] == 1 && $v['channelid'])
- {
- if(strlen($v['channelid'])>20){
- $fileName = $v['channelid'];
- $ret = $video_factory->DescribeVodPlayInfo($fileName);
- }else{
- $ret = $video_factory->GetVodRecordFiles($v['channelid'], $v['create_time']);
- }
- }else{
- $fileName = $v['id'] . '_' . to_date($v['begin_time'],'Y-m-d-H');
- $ret = $video_factory->DescribeVodPlayInfo($fileName);
- }
-
- if($ret['codeDesc'] == 'Success'){
- $list_arr = $v;
- $list_arr['head_image'] = get_spec_image($v['head_image'],150,150);
- $list_arr['begin_time_format'] = format_show_date($v['begin_time']);
- if ($v['max_watch_number'] > 10000){
- $list_arr['watch_number_format'] = round($v['max_watch_number']/10000,2)."万";
- }else{
- $list_arr['watch_number_format'] = $v['max_watch_number'];
- }
-
- $list_arr['max_watch_number'] = $v['max_watch_number'];
-
- if($v['title'] == '')
- $list_arr['title'] = "....";
-
- $list[] = $list_arr;
- }else{
- //会误删
- $sql = "update ".DB_PREFIX."video_history set is_del_vod = 1 where id =".$v['id'];
- //$GLOBALS['db']->query($sql);
- }*/
- $list_arr = $v;
- $list_arr['head_image'] = get_spec_image($v['head_image'],150,150);
- $list_arr['begin_time_format'] = format_show_date($v['begin_time']);
- if ($v['max_watch_number'] > 10000){
- $list_arr['watch_number_format'] = round($v['max_watch_number']/10000,2)."万";
- }else{
- $list_arr['watch_number_format'] = $v['max_watch_number'];
- }
-
- $list_arr['max_watch_number'] = $v['max_watch_number'];
- //20170930 Ios端逻辑处理添加 @slf
- $list_arr['live_in'] = 3;
- if($v['title'] == '')
- $list_arr['title'] = "....";
-
- $list[] = $list_arr;
-
- }
- $root['list'] = $list;
- if($to_user_id ==intval($GLOBALS['user_info']['id'])){
- $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;
- }else{
- $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;
- }
-
- $count = $GLOBALS['db']->getOne($sql);
- //$count = count($list);
- if ($count >= $page_size)
- $root['has_next'] = 1;
- else
- $root['has_next'] = 0;
- $root['count'] = $count;
- if($to_user_id ==intval($GLOBALS['user_info']['id'])&&$page==1){
-
- $sql = "update ".DB_PREFIX."user set video_count = ".$root['count']." where id = ".intval($GLOBALS['user_info']['id'])." and video_count!=".$root['count'];
- $GLOBALS['db']->query($sql);
-
- fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/BaseRedisService.php');
- fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/UserRedisService.php');
- $user_redis = new UserRedisService();
- $user_data = array();
- $user_data['video_count'] = $root['count'];
- $user_redis->update_db(intval($GLOBALS['user_info']['id']), $user_data);
- }
-
- $root['page'] = $page;
- $root['status'] = 1;
-
- ajax_return($root);
- }
-
- /**
- * 设置黑名单
- */
- public function set_black(){
- $root = array();
-
- //$GLOBALS['user_info']['id'] = 269;
- if(!$GLOBALS['user_info']){
- $root['error'] = "用户未登陆,请先登陆.";
- $root['status'] = 0;
- $root['user_login_status'] = 0;//有这个参数: user_login_status = 0 时,表示服务端未登陆、要求登陆,操作
- }else{
- //
- $user_id = intval($GLOBALS['user_info']['id']);//当前用户;
-
- $to_user_id = intval($_REQUEST['to_user_id']);//被关注或取消关注的用户
- if($user_id!=$to_user_id){
- $root = set_black($user_id,$to_user_id);
- }else{
- $root['error'] = "不能设置自己!";
- $root['status'] = 0;
- }
- }
- ajax_return($root);
- }
- /**
- * 搜索用户列表
- */
- public function search(){
-
- //$GLOBALS['user_info']['id'] = 269;
-
- $root = array();
- $root['status'] = 1;
- if(!$GLOBALS['user_info']){
- $root['error'] = "用户未登陆,请先登陆.";
- $root['status'] = 0;
- $root['user_login_status'] = 0;//有这个参数: user_login_status = 0 时,表示服务端未登陆、要求登陆,操作
- }else{
- //
- $user_id = intval($GLOBALS['user_info']['id']);//当前用户;
-
- $keyword = strim($_REQUEST['keyword']);//搜索关键字
- if ($keyword != ""){
- $page = intval($_REQUEST['p']);//取第几页数据
-
- if($page==0)$page = 1;
- $page_size=20;
- $limit = (($page-1)*$page_size).",".$page_size;
- $m_config = load_auto_cache("m_config");//初始化手机端配置
- if($m_config['search_change']==0){
- if ($page == 1){
- if (intval($keyword) > 0){//如果搜索关键字为数字
- //搜索ID,昵称,靓号,不为机器人。
- $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
- 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
- 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";
- }else{
- $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;
- }
- }else{
- $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;
- }
- }else{
- if ($page == 1){
- if (intval($keyword) > 0){//如果搜索关键字为数字
- //搜索ID,昵称,靓号,不为机器人。
- $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
- 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
- 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";
- }else{
- $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;
- }
- }else{
- $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;
- }
- }
- // if (intval($keyword) > 0){//如果搜索关键字为数字
- // //搜索ID,昵称,靓号,不为机器人。
- // //$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;
- // $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;
- // }else{
- // // $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;
- // $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;
- // }
-
- //$root['sql'] = $sql;
-
- //查询用户列表,修改成 从只读数据库中取,但不是高效做法;主并发时,可以加入阿里云的搜索服务
- //https://www.aliyun.com/product/opensearch?spm=5176.8142029.388261.62.tgDxhe
- $list = $GLOBALS['db']->getAll($sql,true,true);
- $keys =array();
- fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/UserFollwRedisService.php');
- $user_redis = new UserFollwRedisService($user_id);
- $keys = $user_redis->following();
- foreach($list as $k=>$v){
- if(in_array($v['user_id'],$keys)){
- $list[$k]['follow_id'] = $v['user_id'];
- }else{
- $list[$k]['follow_id'] = 0;
- }
- $list[$k]['head_image'] = get_spec_image($v['head_image']);
- $list[$k]['signature'] = htmlspecialchars_decode($list[$k]['signature']);
- $list[$k]['nick_name'] = htmlspecialchars_decode($list[$k]['nick_name']);
- $list[$k]['signature'] = emoji_decode($list[$k]['signature']);
- $list[$k]['nick_name'] = emoji_decode($list[$k]['nick_name']);
- }
- $root['list'] = $list;
- if (count($list) == $page_size)
- $root['has_next'] = 1;
- else
- $root['has_next'] = 0;
-
- $root['page'] = $page;//
- }else{
- $root['has_next'] = 0;
- $root['list'] = array();
- $root['page'] = 0;//
- }
- }
-
-
- ajax_return($root);
-
- }
-
- /**
- * 批量导入未同步的用户到im
- */
- public function account_import(){
- $root = array();
- $root['status'] = 1;
-
- fanwe_require(APP_ROOT_PATH.'system/tim/TimApi.php');
- $api = createTimAPI();
-
- $sql = "select id,nick_name,head_image from ".DB_PREFIX."user where synchronize = 0 limit 10";
-
- $list = $GLOBALS['db']->getAll($sql);
-
- foreach ( $list as $k => $v )
- {
- $face_url = get_spec_image($v['head_image']);
- $ret = $api->account_import((string)$v['id'], $v['nick_name'], $face_url);
- if ($ret['ActionStatus'] == 'OK'){
- $sql = 'update '.DB_PREFIX."user set synchronize =1 where id =".$v['id'];
- $GLOBALS['db']->query($sql);
- }else{
- $root['ret'][$v['id']] = $ret;
- }
- //print_r($ret);
- }
- ajax_return($root);
- }
- /**
- * 允许直播的话,未同意状态改为同意
- */
- public function agree(){
- $user_id = intval($GLOBALS['user_info']['id']);
- if($user_id){
- $GLOBALS['db']->query("update ".DB_PREFIX."user set is_agree =1 where id=".$user_id." and is_agree = 0 ");
-
- fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/UserRedisService.php');
- $user_redis = new UserRedisService();
- $data['is_agree'] = 1;
- $user_redis->update_db($user_id, $data);
- }
-
- $root['status'] =1;
- $root['error'] ='';
-
- ajax_return($root);
- }
- /**
- * 一次性取出,我关注的用户列表
- */
- public function my_follow(){
-
- $root = array();
- $root['status'] = 1;
- // $GLOBALS['user_info']['id'] = 290;
- if(!$GLOBALS['user_info']){
- $root['error'] = "用户未登陆,请先登陆.";
- $root['status'] = 0;
- $root['user_login_status'] = 0;//有这个参数: user_login_status = 0 时,表示服务端未登陆、要求登陆,操作
- }else{
-
- $user_id = intval($GLOBALS['user_info']['id']);//id
-
- // $sql = "select f.podcast_id as user_id from ".DB_PREFIX."focus f where f.user_id = ".$user_id;
- //
- // //$root['sql'] = $sql;
- //
- // $list = $GLOBALS['db']->getAll($sql);
- // $root['list'] = $list;
- fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/UserFollwRedisService.php');
- $user_redis = new UserFollwRedisService($user_id);
- $root['list'] = $user_redis->get_follonging_user($user_id,1,1000);
- if(!empty($root['list']))
- {
- for($i=0;$i<count($root['list']);$i++)
- {
- $root['list'][$i]['nick_name'] = emoji_decode($root['list'][$i]['nick_name']);
- $root['list'][$i]['signature'] = emoji_decode($root['list'][$i]['signature']);
- }
- }
-
- }
- ajax_return($root);
- }
-
- /**
- * 好友,相互关注的用户;用于私密直播时,添加的用户列表
- */
- public function friends(){
-
- $root = array();
- $root['status'] = 1;
- //$GLOBALS['user_info']['id'] = 278;
- if(!$GLOBALS['user_info']){
- $root['error'] = "用户未登陆,请先登陆.";
- $root['status'] = 0;
- $root['user_login_status'] = 0;//有这个参数: user_login_status = 0 时,表示服务端未登陆、要求登陆,操作
- }else{
-
- $user_id = intval($GLOBALS['user_info']['id']);//id
- $video_id = intval($_REQUEST['room_id']);
- $page = intval($_REQUEST['p']);//取第几页数据
-
- if($page==0){
- $page = 1;
- }
-
- $page_size=20;
- fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/UserFollwRedisService.php');
- $user_redis = new UserFollwRedisService($user_id);
- $root = $user_redis->get_private_user($page,$page_size);
- fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/VideoRedisService.php');
- $video_redis = new VideoRedisService();
- $video_data = $video_redis->getRow_db($video_id,array('group_id','user_id'));
- fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/VideoViewerRedisService.php');
- $video_viewer_redis = new VideoViewerRedisService();
- $group_id = $video_data['group_id'];//聊天群id
- if($group_id) {
- $users = $video_viewer_redis->get_viewer_list($group_id, $page);
- if($users['list']){
- $user_ids = array_column($users['list'],'user_id');
- $friends = $root['list'];
- foreach($friends as $k=>$v){
- if(in_array($v['user_id'],$user_ids) || $v['user_id']==$video_data['user_id']){
- unset($friends[$k]);
- }
- }
- $root['list'] = array_values($friends);
- }
- }
-
- }
- if(!empty($root['list']))
- {
- for($i=0;$i<count($root['list']);$i++)
- {
- $root['list'][$i]['nick_name'] = emoji_decode($root['list'][$i]['nick_name']);
- $root['list'][$i]['signature'] = emoji_decode($root['list'][$i]['signature']);
- }
- }
- ajax_return($root);
- }
-
- /**
- * 获得用户基本信息(比如:固化的信息比如:头像,性别,昵称,等级,签名等)
- */
- public function baseinfo(){
- $root = array();
-
- //$GLOBALS['user_info']['id'] = 292;
-
- if(!$GLOBALS['user_info']){
- $root['error'] = "用户未登陆,请先登陆.";
- $root['status'] = 0;
- $root['user_login_status'] = 0;//有这个参数: user_login_status = 0 时,表示服务端未登陆、要求登陆,操作
- }else{
- $user_id = intval($GLOBALS['user_info']['id']);
-
- $user_ids = strim($_REQUEST['user_ids']);//字符串类型的用户id 23,123,3455 以英文逗号分割的字符串 ,一次不能大于100个用户
-
-
- if ($user_ids == ''){
- $user_ids = $user_id;
- }
-
- //将选中的:私聊 数据添加到数据库中
- $user_list = explode(',',$user_ids);
-
- if (count($user_list) > 100){
- $root['status'] =0;
- $root['error'] ='一次不能大于100个用户';
-
- }else{
-
- fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/UserRedisService.php');
- $user_redis = new UserRedisService();
-
- $list = $user_redis->get_m_user($user_list);
- /*
-
- $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');
-
-
-
- foreach ( $user_list as $k => $v )
- {
- $userinfo = $user_redis->getRow_db($v,$fields);
- $userinfo['user_id'] = $v;
- $list[] = $userinfo;
- }
-
-
-
- $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.")";
-
- $list = $GLOBALS['db']->getAll($sql);
- foreach ( $list as $k => $v )
- {
- $list[$k]['head_image'] = get_abs_img_root($v['head_image']);
- }
- */
-
- $root['list'] = $list;
- if(!empty($root['list']))
- {
- for($i=0;$i<count($root['list']);$i++)
- {
- $root['list'][$i]['nick_name'] = emoji_decode($root['list'][$i]['nick_name']);
- }
- }
-
- $root['status'] = 1;
- }
- }
- ajax_return($root);
- }
-
- /**
- * app呼醒跟进入后台时调用【用来统计用户在线时长】
- */
- function state_change(){
- $root = array();
- $root['status'] = 1;
- if(!$GLOBALS['user_info']){
- $root['error'] = "用户未登陆,请先登陆.";
- $root['status'] = 0;
- $root['user_login_status'] = 0;//有这个参数: user_login_status = 0 时,表示服务端未登陆、要求登陆,操作
- }else{
- $user_id = intval($GLOBALS['user_info']['id']);
- $action = strim($_REQUEST['action']);
-
- fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/UserRedisService.php');
- $user_redis = new UserRedisService();
- if (strtolower($action) == 'login'){
- $data = array('is_online'=>1,'login_time'=>to_date(NOW_TIME));
- $GLOBALS['db']->autoExecute(DB_PREFIX."user", $data,"UPDATE", 'id='.$user_id);
- $user_redis->update_db($user_id, $data);
- }else{
- $data = array('is_online'=>0,'login_time'=>to_date(NOW_TIME),'logout_time'=>to_date(NOW_TIME));
-
- $user = $user_redis->getRow_db($user_id, array('login_time','logout_time','online_time'));
-
- $login_time = to_timespan($user['login_time']);
- if ($login_time == 0){
- $data['login_time'] = to_date(NOW_TIME);
- }
-
- //计算在线时长
- $online = NOW_TIME - $login_time;
-
- if ($online > 7200){
- //异常数据,一次不可能超过8小时
- $online = 0;
- }
-
- $data['online_time'] = $user['online_time'] + $online;
-
- $GLOBALS['db']->autoExecute(DB_PREFIX."user", $data,"UPDATE", 'id='.$user_id);
- if($GLOBALS['db']->affected_rows()){
- $user_redis->update_db($user_id, $data);
-
- //更新用户等级
- $user_info = $user_redis->getRow_db($user_id,array('id','score','online_time','user_level'));
- user_leverl_syn($user_info);
- }
- }
-
- }
- ajax_return($root);
-
- }
- }
|