| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682 |
- <?php
- // +----------------------------------------------------------------------
- // | FANWE 直播系统
- // +----------------------------------------------------------------------
- // | Copyright (c) 2011 http://www.fanwe.com All rights reserved.
- // +----------------------------------------------------------------------
- // | Author: 云淡风轻(1956838968@qq.com)
- // +----------------------------------------------------------------------
- class dealModule
- {
- /**
- * 送礼物
- */
- public function pop_prop(){
- $root = array();
- 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']);
- $prop_id = intval($_REQUEST['prop_id']);//礼物id
- $num = intval($_REQUEST['num']);//礼物数量
- $is_plus = intval($_REQUEST['is_plus']);//1显示连续;
- $video_id = strim($_REQUEST['room_id']);//直播ID 也是room_id
- $from=strim($_REQUEST['from']);//判断发送来源 pc或者app
- $is_coins = intval($_REQUEST['is_coins']);//0是钻石,1是游戏币
- $child_id = isset($_REQUEST['child_id'])?intval($_REQUEST['child_id']):$video_id;//子房间
- fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/VideoRedisService.php');
- $video_redis = new VideoRedisService();
- $group = $video_redis->getRow_db($video_id,array('group_id'));
- //子房间模块
- if(defined('CHILD_ROOM') && CHILD_ROOM == 1){
- fanwe_require(APP_ROOT_PATH.'mapi/lib/ChildRoom.class.php');
- $child_room = new child_room();
- $video_id = $child_room->child_pop_prop($user_id,$video_id);
- }
- //
- //$sql = "select id,user_id,group_id from ".DB_PREFIX."video where id = ".$video_id;
- //$video = $GLOBALS['db']->getRow($sql);
- $video = $video_redis->getRow_db($video_id,array('id','user_id','group_id','prop_table','room_type'));
- if($group){
- $group_id = strim($group['group_id']);//群组ID
- }else{
- $group_id = strim($video['group_id']);//群组ID
- }
- $podcast_id = intval($video['user_id']);//送给谁,有群组ID(group_id),除了红包外其它的都是送给:群主
- $room_type = intval($video['room_type']);//直播间类型 房间类型 : 1私有群(Private),0公开群(Public),2聊天室(ChatRoom),3互动直播聊天室(AVChatRoom)
- //子房间
- if(defined('CHILD_ROOM') && CHILD_ROOM == 1){
- fanwe_require(APP_ROOT_PATH.'mapi/lib/ChildRoom.class.php');
- $child_room = new child_room();
- $parent_id = $child_room->parent_id($video_id);
- $p_video = $video_redis->getRow_db($parent_id, array('id', 'user_id', 'group_id', 'prop_table'));
- if(empty($group_id)){
- $group_id = $p_video['group_id'];
- }
- }
- $is_nospeaking = $GLOBALS['db']->getOne("SELECT is_nospeaking FROM ".DB_PREFIX."user WHERE id=".$user_id,true,true);
- if($is_nospeaking){
- $root['status'] = 0;
- $root['error'] = "被im全局禁言,不能发礼物";
- ajax_return($root);
- }
- if($user_id == $podcast_id){
- $root['error'] = "不能发礼物给自己";
- $root['status'] = 0;
- ajax_return($root);
- }
- //检查测试账号不能发礼物给真实主播
- $sql = "select mobile from ".DB_PREFIX."user where id = '".$podcast_id."'";
- $podcast_mobile = $GLOBALS['db']->getOne($sql);
- if(($GLOBALS['user_info']['mobile'] == '13888888888'&&$podcast_mobile!='13999999999')||$GLOBALS['user_info']['mobile'] == '13999999999'&&$podcast_mobile!='13888888888'){
- $root['error'] = "测试账号不能发礼物给真实主播";
- $root['status'] = 0;
- ajax_return($root);
- }
- //以后需要从缓存中读取
- //$sql = "select id,name,score,diamonds,icon,ticket,is_much,sort,is_red_envelope,is_animated from ".DB_PREFIX."prop where id = '".$prop_id."'";
- //$prop = $GLOBALS['db']->getRow($sql);
- $prop = load_auto_cache("prop_id",array('id'=>$prop_id));
- if ($num <= 0){
- $num = 1;
- }
- if($is_coins == 0){
- $total_diamonds = $num * $prop['diamonds'];
- }else{
- $total_diamonds = $num * $prop['coins'];
- }
- $total_score = $num * $prop['score'];
- $total_ticket = intval($num * $prop['ticket']);
- $robot_diamonds = intval($prop['robot_diamonds']);
- fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/UserRedisService.php');
- $user_redis = new UserRedisService();
- $root = $this->pack_prop($video['prop_table'],$video_redis,$total_diamonds,$total_score,$total_ticket,$num,$prop,$is_plus,$video_id,$user_id,$prop_id,$podcast_id,$group_id,$room_type,$from,$robot_diamonds,$is_coins,$child_id);
- }
- ajax_return($root);
- }
- /**
- * 邀请码分销
- * @param $user_id
- * @param $total_ticket
- * @param $prop_id
- */
- private function check_invite($user_id, $total_ticket, $prop_id)
- {
- if (!defined('OPEN_INVITE_CODE') || OPEN_INVITE_CODE != 1) {
- return;
- }
- $m_config = load_auto_cache('m_config');
- if ($m_config['invite_ratio'] <= 0 || $m_config['invite_ratio'] > 1) {
- return;
- }
- $ratio = round($total_ticket * $m_config['invite_ratio'], 2);
- if ($ratio <= 0) {
- return;
- }
- $invite_by_user_id = $GLOBALS['db']->getOne("select invite_by_user_id from fanwe_user_invite where user_id = {$user_id}");
- if ($invite_by_user_id <= 0) {
- return;
- }
- $invite_user = $GLOBALS['db']->getRow("select is_effect,is_authentication from " . DB_PREFIX . "user where id = {$invite_by_user_id}");
- if (!$invite_user['is_effect'] && $invite_user['is_authentication'] == 2) {
- return;
- }
- $GLOBALS['db']->query("update " . DB_PREFIX . "user set ticket = ticket + " . $ratio . " where id = " . $invite_by_user_id);
- $GLOBALS['db']->autoExecute(DB_PREFIX . "invite_distribution_log", array(
- 'from_user_id' => $user_id,
- 'to_user_id' => $invite_by_user_id,
- 'create_date' => "'".to_date(NOW_TIME,'Y-m-d')."'",
- 'prop_id' => $prop_id,
- 'ticket' => $ratio,
- 'create_time' => NOW_TIME,
- 'create_ym' => to_date(NOW_TIME, 'Ym'),
- 'create_d' => to_date(NOW_TIME, 'd'),
- 'create_w' => to_date(NOW_TIME, 'W'),
- ));
- user_deal_to_reids(array($invite_by_user_id));
- }
- /**
- * 送礼物封装
- */
- public function pack_prop($table,$video_redis,$total_diamonds,$total_score,$total_ticket,$num,$prop,$is_plus,$video_id,$user_id,$prop_id,$podcast_id,$group_id,$room_type,$from,$robot_diamonds,$is_coins,$child_id=''){
- $pInTrans = $GLOBALS['db']->StartTrans();
- try
- {
- $m_config = load_auto_cache("m_config");//初始化手机端配置
- fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/UserRedisService.php');
- $user_redis = new UserRedisService();
- //免费礼物
- if($total_diamonds==0&&$total_score==0&&$total_ticket==0){
- $type = 1;
- //普通会员收到的提示内容;
- $desc = "我送了".$num."个".$prop['name'];
- //礼物接收人(主播)收到的提示内容
- $desc2 = $desc;
- $ext = array();
- $ext['type'] = $type; //0:普通消息;1:礼物;2:弹幕消息;3:主播退出;4:禁言;5:观众进入房间;6:观众退出房间;7:直播结束; 8:红包
- $ext['num'] = $num;
- $ext['is_plus'] = $is_plus;//1:数量连续叠加显示;0:不叠加;这个值是从客户端上传过来的
- $ext['is_much'] = $prop['is_much'];//1:可以连续发送多个;用于小金额礼物
- $ext['room_id'] = $video_id;//直播ID 也是room_id;只有与当前房间相同时,收到消息才响应
- $ext['is_animated'] = $prop['is_animated'];//1:动画;0:未动画
- //消息发送者
- $sender = array();
- $user_info = $user_redis->getRow_db($user_id,array('nick_name','head_image','user_level','v_icon'));
- $sender['user_id'] = $user_id;//发送人昵称
- $sender['nick_name'] = emoji_decode($user_info['nick_name']);//发送人昵称
- $sender['head_image'] = get_spec_image($user_info['head_image']);//发送人头像
- $sender['user_level'] = $user_info['user_level'];//用户等级
- $sender['v_icon'] = $user_info['v_icon'];//认证图标
- $ext['sender'] = $sender;
- if ($type == 1){
- $ext['prop_id'] = $prop_id; //礼物id
- $ext['icon'] = get_spec_image($prop['icon']);//图片,是否要: 大中小格式?
- $ext['total_ticket'] = intval($user_redis->getOne_db($podcast_id,'ticket'));//用户总的:印票数
- $ext['to_user_id'] = $podcast_id;//礼物接收人(主播)
- $ext['fonts_color'] = '';//字体颜色
- $ext['desc'] = $desc;//普通群员收到的提示内容;
- $ext['desc2'] = $desc2;//礼物接收人(主播)收到的提示内容;
- $ext['anim_type'] = $prop['anim_type'];//大型道具类型;
- $ext['top_title'] = $sender['nick_name']."送了".$prop['name'];//大型道具类型,标题;
- $ext['anim_cfg'] = $prop['anim_cfg'];
- }
- #构造高级接口所需参数
- $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);
- if (isset($_REQUEST['is_debug'])){
- $root['error'] = '';
- $root['status'] = 1;
- }else{
- fanwe_require(APP_ROOT_PATH.'system/tim/TimApi.php');
- $api = createTimAPI();
- $ret = $api->group_send_group_msg2($user_id, $group_id, $msg_content);
- if ($ret['ActionStatus'] == 'FAIL' && $ret['ErrorCode'] == 10002){
- //10002 系统错误,请再次尝试或联系技术客服。
- log_err_file(array(__FILE__,__LINE__,__METHOD__,$ret));
- $ret = $api->group_send_group_msg2($user_id, $group_id, $msg_content);
- }
- //$videoGift_redis->update_db($user_prop_id, $ret);
- if ($ret['ActionStatus'] == 'FAIL'){
- $root['error'] = $ret['ErrorInfo'].":".$ret['ErrorCode'];
- $root['status'] = 0;
- }else{
- $root['error'] = '';
- $root['status'] = 1;
- }
- }
- }else{
- //私密直播间送红包不加经验
- if ($prop['is_red_envelope'] ==1&&$room_type==1){
- $total_score = 0;
- }
- if($is_coins == 0){
- //减少用户钻石
- $sql = "update ".DB_PREFIX."user set diamonds = diamonds - ".$total_diamonds.", use_diamonds = use_diamonds + ".$total_diamonds.", score = score + ".$total_score." where id = '".$user_id."' and diamonds >= ".$total_diamonds;
- }else{
- //减少用户游戏币
- $sql = "update ".DB_PREFIX."user set coin = coin - ".$total_diamonds.", score = score + ".$total_score." where id = '".$user_id."' and coin >= ".$total_diamonds;
- }
-
- $GLOBALS['db']->query($sql);
- if($GLOBALS['db']->affected_rows()){
- if($is_coins){
- fanwe_require(APP_ROOT_PATH . 'mapi/lib/core/Model.class.php');
- Model::$lib = dirname(__FILE__);
- $user_model = Model::build('user');
- $account_diamonds = $user_model->coin($user_id);
- Model::build('coin_log')->addLog($user_id, -1, -$total_diamonds, $account_diamonds, '送礼物消费游戏币');
- }
- //记录:钻石 减少日志
- if ($total_ticket > 0){
- if ($prop['is_red_envelope'] == 1){
- //主播增加:钻石 数量
- //$user_redis->lock_diamonds($podcast_id,$total_ticket);
- $sql = "update ".DB_PREFIX."user set diamonds = diamonds + ".$total_ticket." where id = ".$podcast_id;
- $GLOBALS['db']->query($sql);
- }else{
- $m_config = load_auto_cache("m_config");//初始化手机端配置
- if(intval(OPEN_REWARD_GIFT)){
- if(file_exists(APP_ROOT_PATH.'mapi/lib/core/award_function.php')) {
- fanwe_require(APP_ROOT_PATH . 'mapi/lib/core/award_function.php');
- $list_award = get_award_info();
- }
- }
- if(defined("robot_gifts") && robot_gifts ==1){
- $roboter = $GLOBALS['db']->getOne("select roboter from ".DB_PREFIX."user where roboter=1 and id=".$user_id);//查询是否特殊权限用户
- if($roboter){
- //增加:不可提现印票
- $sql = "update ".DB_PREFIX."user set no_ticket = no_ticket + ".$total_ticket." where id = ".$podcast_id;
- $GLOBALS['db']->query($sql);
- }else{
- //增加:用户印票
- $sql = "update ".DB_PREFIX."user set ticket = ticket + ".$total_ticket." where id = ".$podcast_id;
- $GLOBALS['db']->query($sql);
- }
- }else{
- //增加:用户印票
- $sql = "update ".DB_PREFIX."user set ticket = ticket + ".$total_ticket." where id = ".$podcast_id;
- $GLOBALS['db']->query($sql);
- }
- }
- // 邀请码分销
- $this->check_invite($user_id, $total_ticket, $prop_id);
- /*
- * 记录在redis中
- //当前直播获得印票数
- $sql = "update ".DB_PREFIX."video set vote_number = vote_number + ".$total_ticket." where id =".$video_id;
- $GLOBALS['db']->query($sql);
- */
- }
- //=========数据库更新成功后,处理redis数据==========
- //插入:送礼物表 修改礼物直接写入 mysql @by slf
- $video_prop = array();
- $video_prop['prop_id'] = $prop_id;
- $video_prop['prop_name'] = "'".$prop['name']."'";
- $video_prop['is_red_envelope'] = $prop['is_red_envelope'];
- $video_prop['total_score'] = $total_score;
- $video_prop['total_diamonds'] = $total_diamonds;
- $video_prop['total_ticket'] = intval($total_ticket);//is_red_envelope=1时,为主播获得的:钻石 数量
- $video_prop['from_user_id'] = $user_id;
- $video_prop['to_user_id'] = $podcast_id;
- $video_prop['create_time'] = NOW_TIME;
- $video_prop['create_date'] = "'".to_date(NOW_TIME,'Y-m-d')."'";
- $video_prop['num'] = $num;
- $video_prop['video_id'] = $video_id;
- $video_prop['group_id'] = "'".$group_id."'";
- $video_prop['create_ym'] = to_date($video_prop['create_time'],'Ym');
- $video_prop['create_d'] = to_date($video_prop['create_time'],'d');
- $video_prop['create_w'] = to_date($video_prop['create_time'],'W');
- $video_prop['from_ip'] = "'".get_client_ip()."'";
- $video_prop['is_coin'] = 0;
- if($is_coins == 1){
- $video_prop['is_coin'] = 1;
- }
- $table_info = $GLOBALS['db']->getRow("Describe ".$table." from_ip",true,true);
- if(!$table_info){
- $GLOBALS['db']->query("ALTER TABLE ".$table." ADD COLUMN `from_ip` varchar(255) NOT NULL COMMENT '送礼物人IP'");
- }
- $table_version = $GLOBALS['db']->getRow("Describe ".$table." is_coin",true,true);
- if(!$table_version){
- $GLOBALS['db']->query("ALTER TABLE ".$table." ADD COLUMN `is_coin` varchar(255) NOT NULL COMMENT '双币礼物,0是钻石,1是游戏币'");
- }
- if(intval(OPEN_REWARD_GIFT)&&intval($list_award['is_open_award'])==1){
- $table_version_is_award = $GLOBALS['db']->getRow("Describe ".$table." is_award",true,true);
- if(!$table_version_is_award){
- $GLOBALS['db']->query("ALTER TABLE ".$table." ADD COLUMN `is_award` varchar(255) NOT NULL COMMENT '是否为可中奖礼物 1为 是、0为否'");
- }
- }
- //将礼物写入mysql表中
- $field_arr = array('prop_id','prop_name','is_red_envelope', 'total_score', 'total_diamonds', 'total_ticket','from_user_id', 'to_user_id', 'create_time','create_date','num','video_id','group_id','create_ym','create_d','create_w','from_ip','is_coin');
- if(intval(OPEN_REWARD_GIFT)&&intval($list_award['is_open_award'])==1){
- $field_arr[] = 'is_award';
- $video_prop['is_award'] = intval($prop['is_award']);
- }
- $fields = implode(",",$field_arr);
- $valus = implode(",",$video_prop);
- fanwe_require (APP_ROOT_PATH.'mapi/lib/core/common.php');
- //$table = createPropTable();
- $sql = "insert into ".$table." (".$fields.") VALUES (".$valus.")";
- $GLOBALS['db']->query($sql);
- $user_prop_id = $GLOBALS['db']->insert_id();
- //写入总表
- if(file_exists(APP_ROOT_PATH.'mapi/lib/core/award_function.php')){
- fanwe_require(APP_ROOT_PATH.'mapi/lib/core/award_function.php');
- $table_all = createPropAllTable();
- $table_version = $GLOBALS['db']->getRow("Describe ".$table_all." is_coin",true,true);
- if(!$table_version){
- $GLOBALS['db']->query("ALTER TABLE ".$table_all." ADD COLUMN `is_coin` varchar(255) NOT NULL COMMENT '双币礼物,0是钻石,1是游戏币'");
- }
- $sql = "insert into ".$table_all." (".$fields.") VALUES (".$valus.")";
- $GLOBALS['db']->query($sql);
- $award_res = array('status'=>0,'is_award'=>0);
- if(intval(OPEN_REWARD_GIFT)&&intval($prop['is_award'])==1&&intval($list_award['is_open_award'])==1){
- //礼物中奖逻辑处理
- $award_info = array();
- $award_info['video_id'] = $video_id;
- $award_info['group_id'] = $group_id;
- $award_info['from_ip'] = "'".get_client_ip()."'";
- $award_info['user_id'] = $user_id;
- $award_result = gift_award($award_info,$prop);
- if($award_result['status']){
- $award_res = $award_result;// 是否中奖
- }
- }
- }
- //提交事务,不等 消息推送,防止锁太久
- $GLOBALS['db']->Commit($pInTrans);
- $pInTrans = false;//防止,下面异常时,还调用:Rollback
- //子房间
- if(defined('CHILD_ROOM') && CHILD_ROOM == 1){
- fanwe_require(APP_ROOT_PATH.'mapi/lib/ChildRoom.class.php');
- $child_room = new child_room();
- $child_room->child_room_prop($child_id,$video_id,$video_prop,$fields,$user_id,$total_ticket);
- }
- if ($prop['is_red_envelope'] == 0 && $total_ticket > 0){
- //贡献榜
- fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/VideoContributionRedisService.php');
- $videoCont_redis = new VideoContributionRedisService();
- $videoCont_redis->insert_db($user_id, $podcast_id, $video_id, $total_ticket);
- }
- //分销功能 计算抽成
- if(defined('OPEN_DISTRIBUTION')&&OPEN_DISTRIBUTION==1&&$prop['is_red_envelope'] == 0&&$total_ticket>0){
- $this->distribution_calculate($user_id,$total_ticket);
- }
- if ($prop['is_red_envelope'] == 0&&$total_ticket>0) {
- $this->distribution($podcast_id, $video_id, $total_ticket);
- }
- user_deal_to_reids(array($user_id,$podcast_id));
- //更新用户等级
- $user_info = $user_redis->getRow_db($user_id,array('id','score','online_time','user_level'));
- user_leverl_syn($user_info);
- /*
- $sql = "select diamonds,use_diamonds,score,ticket,user_level,refund_ticket from ".DB_PREFIX."user where id = ".$user_id;
- $user_data = $GLOBALS['db']->getRow($sql);
- $user_redis->update_db($user_id, $user_data);
- $sql = "select diamonds,use_diamonds,score,ticket,user_level,refund_ticket from ".DB_PREFIX."user where id = ".$podcast_id;
- $user_data = $GLOBALS['db']->getRow($sql);
- $user_redis->update_db($podcast_id, $user_data);
- */
- //=================发送:礼物=================================
- $type = 1;
- //普通会员收到的提示内容;
- if ($prop['is_red_envelope'] == 1){
- $desc = '我给大家送了一个红包';
- $type = 8;
- }else{
- $desc = "我送了".$num."个".$prop['name'];
- }
- //礼物接收人(主播)收到的提示内容
- $desc2 = $desc;
- $ext = array();
- $ext['type'] = $type; //0:普通消息;1:礼物;2:弹幕消息;3:主播退出;4:禁言;5:观众进入房间;6:观众退出房间;7:直播结束; 8:红包
- $ext['num'] = $num;
- $ext['is_plus'] = $is_plus;//1:数量连续叠加显示;0:不叠加;这个值是从客户端上传过来的
- $ext['is_much'] = $prop['is_much'];//1:可以连续发送多个;用于小金额礼物
- $ext['room_id'] = $video_id;//直播ID 也是room_id;只有与当前房间相同时,收到消息才响应
- $ext['award'] = $award_res;//
- if($prop['is_much']) {
- // 计算连发次数,兼容 PC 端
- $key = "user:prop:{$user_id}:{$video_id}:{$prop_id}";
- $user_prop = $GLOBALS['cache']->get($key, true);
- if($user_prop && $user_prop['time'] > NOW_TIME){
- $plus_num = $user_prop['num'] + 1;
- if($from=='pc' && $plus_num > 1){
- $is_plus=1;
- }
- } else {
- $plus_num = 1;
- }
- $ext['plus_num'] = $plus_num;
- // app 上传 is_plus 视为连发
- $GLOBALS['cache']->set($key, array('time' => NOW_TIME + 5, 'num' => $plus_num), 5, true);
- //APP
- $key = "user:prop:{'app'}{$user_id}:{$video_id}:{$prop_id}";
- $app_user_prop = $GLOBALS['cache']->get($key, true);
- if($app_user_prop && $is_plus==1){
- $app_plus_num = $app_user_prop['num'] + 1;
- } else {
- $app_plus_num = 1;
- }
- $ext['app_plus_num'] = $app_plus_num;
- // app 上传 is_plus 视为连发
- $GLOBALS['cache']->set($key, array('num' => $app_plus_num), 86400, true);
- }else{
- $ext['app_plus_num'] = 1;
- }
- $ext['is_animated'] = $prop['is_animated'];//1:动画;0:未动画
- //消息发送者
- $sender = array();
- $user_info = $user_redis->getRow_db($user_id,array('nick_name','head_image','user_level','v_icon'));
- $sender['user_id'] = $user_id;//发送人昵称
- $sender['nick_name'] = emoji_decode($user_info['nick_name']);//发送人昵称
- $sender['head_image'] = get_spec_image($user_info['head_image']);//发送人头像
- $sender['user_level'] = $user_info['user_level'];//用户等级
- $sender['v_icon'] = $user_info['v_icon'];//认证图标
- $ext['sender'] = $sender;
- if ($type == 1){
- $ext['prop_id'] = $prop_id; //礼物id
- //$ext['animated_url'] = $prop['animated_url'];//动画播放url
- $ext['icon'] = get_spec_image($prop['icon']);//图片,是否要: 大中小格式?
- //$ext['is_red_envelope'] = $prop['is_red_envelope'];//是否是:红包;1:红包
- $ext['user_prop_id'] = $user_prop_id; //红包时用到,抢红包的id
- //$ext['show_num'] = $show_num;//显示连续送的礼物数量;
- $fields = array('ticket','no_ticket','refund_ticket');
- $user_info = $user_redis->getRow_db($podcast_id,$fields);//用户总的:印票数
- $ext['total_ticket'] =$user_info['ticket']+$user_info['no_ticket'];//用户总的:印票数
- //直播间显示主播实际可提现印票(客户定制,标准版保留此功能)
- if(0){
- $ext['total_ticket'] = $ext['total_ticket'] - intval($user_info['refund_ticket']);
- }
- $ext['to_user_id'] = $podcast_id;//礼物接收人(主播)
- $ext['fonts_color'] = '';//字体颜色
- $ext['desc'] = $desc;//普通群员收到的提示内容;
- $ext['desc2'] = $desc2;//礼物接收人(主播)收到的提示内容;
- $ext['anim_type'] = $prop['anim_type'];//大型道具类型;
- $ext['top_title'] = $sender['nick_name']."送了".$prop['name'];//大型道具类型,标题;
- /*
- if ($ext['is_animated'] == 1){
- //要缓存getAllCached
- $sql = "select id,url,play_count,delay_time,duration,show_user,type from ".DB_PREFIX."prop_animated where prop_id = ".$prop_id." order by sort desc";
- $anim_list = $GLOBALS['db']->getAll($sql);
- $ext['anim_cfg'] = $anim_list;
- //$ext['sql'] = $sql;
- }else{
- $ext['anim_cfg'] = array();
- }
- */
- $ext['anim_cfg'] = $prop['anim_cfg'];
- }else{
- $ext['prop_id'] = $prop_id; //礼物id
- //$ext['animated_url'] = $prop['animated_url'];//动画播放url
- $ext['icon'] = get_spec_image($prop['icon']);//图片,是否要: 大中小格式?
- //$ext['is_red_envelope'] = $prop['is_red_envelope'];//是否是:红包;1:红包
- $ext['user_prop_id'] = $user_prop_id; //红包时用到,抢红包的id
- //$ext['show_num'] = $show_num;//显示连续送的礼物数量;
- $ext['total_ticket'] = intval($user_redis->getOne_db($podcast_id,'ticket'));//用户总的:印票数
- $ext['to_user_id'] = $podcast_id;//礼物接收人(主播)
- $ext['to_diamonds'] = $total_ticket;//礼物接收人(主播),获得的:钻石 数量
- $ext['fonts_color'] = '';//字体颜色
- $ext['desc'] = $desc;//普通群员收到的提示内容;
- $ext['desc2'] = $desc2;//礼物接收人(主播)收到的提示内容;
- $allot_diamonds = 0;
- if ($prop['is_red_envelope'] ==1&&$room_type==1){
- }else{
- if ($robot_diamonds > 0){
- //优先分配给:观众列表中的机器人
- $robot_list = $video_redis->get_robot($video_id);
- $robot_num = count($robot_list);
- if ($robot_num > 0){
- //给一半以上的机器 人分配
- $robot_num = mt_rand(ceil($robot_num/2), $robot_num);
- //可分配的钻石小于机器人数1.3倍时,减少分配人数
- if ($robot_num * 1.3 > $robot_diamonds) $robot_num = ceil($robot_diamonds/2);
- $diamonds_list = $this->red_rand_list2($robot_diamonds,$robot_num);
- while(count($diamonds_list) > 0){
- $money = $diamonds_list[0];
- array_splice($diamonds_list,0,1);
- $robot_num = count($robot_list) - 1;
- $r = mt_rand(0, $robot_num);
- $robot_userid = $robot_list[$r];
- array_splice($robot_list,$r,1);
- //实际分配的
- $allot_diamonds = $allot_diamonds + $money;
- allot_red_to_user($user_prop_id,$robot_userid,$money);
- };
- }
- }
- }
- //生成一个随机红包队列(观众可抢钻石=diamonds-ticket-robot_diamods)
- $money_list = $this->red_rand_list($total_diamonds - $total_ticket-$allot_diamonds);
- fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/VideoRedRedisService.php');
- $videoRed_redis = new VideoRedRedisService();
- $videoRed_redis->push_red($user_prop_id, $money_list);
- //记录直播间发的:红包 记录; 主要用于,直播结束后,处理还未被领取的红包
- $video_redis->add_red($video_id, $user_prop_id);
- }
- #构造高级接口所需参数
- $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);
- if (isset($_REQUEST['is_debug'])){
- $root['error'] = '';
- $root['status'] = 1;
- }else{
- fanwe_require(APP_ROOT_PATH.'system/tim/TimApi.php');
- $api = createTimAPI();
- $ret = $api->group_send_group_msg2($user_id, $group_id, $msg_content);
- if ($ret['ActionStatus'] == 'FAIL' && $ret['ErrorCode'] == 10002){
- //10002 系统错误,请再次尝试或联系技术客服。
- log_err_file(array(__FILE__,__LINE__,__METHOD__,$ret));
- $ret = $api->group_send_group_msg2($user_id, $group_id, $msg_content);
- }
- $GLOBALS['db']->autoExecute($table, $ret,'UPDATE','id='.$user_prop_id);
- //$videoGift_redis->update_db($user_prop_id, $ret);
- if ($ret['ActionStatus'] == 'FAIL'){
- $root['error'] = $ret['ErrorInfo'].":".$ret['ErrorCode'];
- $root['status'] = 0;
- }else{
- if (defined('PROP_NOTIFY') && PROP_NOTIFY == 1 && $type==1 && $prop['anim_type']!='') //判断开关是否开启,是否为大型礼物
- {
- $m_config = load_auto_cache('m_config');
- $root['is_notify'] = intval($m_config['is_prop_notify']); //判断后台是否开启这个功能
- if ($root['is_notify'])
- {
- //获取房间类型
- $sql1 = "SELECT room_type FROM ".DB_PREFIX."video WHERE id=".$video_id;
- $room_type = $GLOBALS['db']->getOne($sql1,true,true);
- $sql2 = "SELECT live_in FROM ".DB_PREFIX."video WHERE id=".$video_id;
- $live_type = $GLOBALS['db']->getOne($sql2,true,true);
- if($room_type!=1 && $live_type!=3) //判定房间是否为私有房间或回播的房间
- {
- fanwe_require(APP_ROOT_PATH.'mapi/lib/core/prop_notify.php');
- $root[] = propNotify($sender,$ext,$prop); //执行全服通告
- }
- }
- $root['is_notify'] = intval($m_config['is_prop_notify']);
- }
-
- $root['error'] = '';
- $root['status'] = 1;
- }
- }
- }else{
- $GLOBALS['db']->Rollback($pInTrans);
- $root['error'] = $is_coins ? "用户游戏币不足" : "用户".$m_config['diamonds_name']."不足";
- $root['status'] = 0;
- }
- }
- }catch(Exception $e){
- //异常回滚
- $root['error'] = $e->getMessage();
- $root['status'] = 0;
- $GLOBALS['db']->Rollback($pInTrans);
- }
- 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,2);
- }
- return $root;
- }
- /**
- * 弹幕消息接口
- */
- public function pop_msg()
- {
- $root = array();
- 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']);
- $room_id = strim($_REQUEST['room_id']);//直播ID 也是room_id
- $msg = strim($_REQUEST['msg']);//消息内容8J+UkQ==
- //$to_user_id = intval($_REQUEST['to_user_id']);//群主ID
- $is_nospeaking = $GLOBALS['db']->getOne("SELECT is_nospeaking FROM " . DB_PREFIX . "user WHERE id=" . $user_id,
- true, true);
- if ($is_nospeaking) {
- $root['status'] = 0;
- $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($room_id, array('id', 'user_id', 'group_id', 'prop_table'));
- fanwe_require(APP_ROOT_PATH . 'mapi/lib/redis/UserRedisService.php');
- $user_redis = new UserRedisService();
- $group_id = strim($video['group_id']);//群组ID
- $podcast_id = intval($video['user_id']);//送给谁,有群组ID(group_id),除了红包外其它的都是送给:群主
- //子房间
- if(defined('CHILD_ROOM') && CHILD_ROOM == 1){
- fanwe_require(APP_ROOT_PATH.'mapi/lib/ChildRoom.class.php');
- $child_room = new child_room();
- $parent_id = $child_room->parent_id($room_id);
- $p_video = $video_redis->getRow_db($parent_id, array('id', 'user_id', 'group_id', 'prop_table'));
- if(empty($group_id)){
- $group_id = $p_video['group_id'];
- }
- }
- $m_config = load_auto_cache("m_config");//初始化手机端配置
- $is_podcast = false;
- //主播,自己发送 弹幕 消息,不扣钻石
- if ($podcast_id == $user_id) {
- $ext = array();
- $ext['type'] = 2; //0:普通消息;1:礼物;2:弹幕消息;3:主播退出;4:禁言;5:观众进入房间;6:观众退出房间;7:直播结束
- $ext['room_id'] = $room_id;//直播ID 也是room_id;只有与当前房间相同时,收到消息才响应
- $ext['num'] = 1;
- $ext['prop_id'] = 0; //礼物id
- //s$ext['animated_url'] = '';//动画播放url
- $ext['icon'] = '';//图片,是否要: 大中小格式?
- //$ext['is_red_envelope'] = 0;//是否是:红包;1:红包
- $ext['user_prop_id'] = 0; //红包时用到,抢红包的id
- //$ext['show_num'] = 1;//显示连续送的礼物数量;
- $fields = array('ticket','no_ticket','refund_ticket');
- $user_info = $user_redis->getRow_db($podcast_id,$fields);//用户总的:印票数
- $ext['total_ticket'] = intval($user_info['ticket'])+ intval($user_info['no_ticket']);//用户总的:印票数
- //直播间显示主播实际可提现印票(客户定制,标准版保留此功能)
- if(0){
- $ext['total_ticket'] = $ext['total_ticket'] - intval($user_info['refund_ticket']);
- }
- $ext['to_user_id'] = 0;//礼物接收人(主播)
- $ext['fonts_color'] = '';//字体颜色
- $ext['desc'] = $msg;//弹幕消息;
- $ext['desc2'] = $msg;//弹幕消息;
- //消息发送者
- $sender = array();
- $user_info = $user_redis->getRow_db($user_id, array('nick_name', 'head_image', 'user_level', 'v_icon'));
- $sender['user_id'] = $user_id;//发送人昵称
- $sender['nick_name'] = emoji_decode($user_info['nick_name']);//发送人昵称
- $sender['head_image'] = get_spec_image($user_info['head_image']);//发送人头像
- $sender['user_level'] = $user_info['user_level'];//用户等级
- $sender['v_icon'] = $user_info['v_icon'];//认证图标
- $ext['sender'] = $sender;
- #构造高级接口所需参数
- $msg_content = array();
- //创建array 所需元素
- $msg_content_elem = array(
- 'MsgType' => 'TIMCustomElem', //自定义类型
- 'MsgContent' => array(
- 'Data' => json_encode($ext),
- 'Desc' => '',
- // 'Ext' => $ext,
- // 'Sound' => '',
- )
- );
- if (intval($m_config['has_dirty_words']) == 1) {
- //文档内容,用来过滤脏字
- $msg_text_elem = array(
- 'MsgType' => 'TIMTextElem', //
- 'MsgContent' => array(
- 'Text' => $msg,
- )
- );
- array_push($msg_content, $msg_text_elem, $msg_content_elem);
- } else {
- //将创建的元素$msg_content_elem, 加入array $msg_content
- array_push($msg_content, $msg_content_elem);
- }
- if (isset($_REQUEST['is_debug'])) {
- $root['error'] = '';
- $root['status'] = 1;
- } else {
- fanwe_require(APP_ROOT_PATH . 'system/tim/TimApi.php');
- $api = createTimAPI();
- $ret = $api->group_send_group_msg2($user_id, $group_id, $msg_content);
- }
- if ($ret['ActionStatus'] == 'FAIL') {
- log_err_file(array(__FILE__, __LINE__, __METHOD__, $ret));
- if ($ret['ErrorCode'] == 80001) {
- $root['error'] = '该词已被禁用';
- } else {
- $root['error'] = $ret['ErrorInfo'] . ":" . $ret['ErrorCode'];
- }
- $root['status'] = 0;
- } else {
- $root['error'] = '';
- $root['status'] = 0;//app端通过这个判断是否扣除钻石,1为扣除
- }
- } else {
- //$sql = "select id from ".DB_PREFIX."video_forbid_send_msg where group_id='".$group_id."' and user_id = ".$user_id;
- //$has_forbid = $GLOBALS['db']->getOne($sql,true,true) > 0;
- $has_forbid = $video_redis->has_forbid_msg2($group_id, $user_id);
- if ($has_forbid) {
- $root['error'] = "被禁言,不能发送消息";
- $root['status'] = 0;
- } else {
- //file_put_contents(APP_ROOT_PATH.'mapi/lib/msg.txt', $msg);
- //$msg2 = unserialize(file_get_contents(APP_ROOT_PATH.'mapi/lib/msg2.txt'));
- //$msg =$msg .'【'.base64_decode("8J+UkQ==").'】';
- //子房间收益归主房间主播
- $p_id = $podcast_id;
- if(defined('CHILD_ROOM') && CHILD_ROOM == 1){
- fanwe_require(APP_ROOT_PATH.'mapi/lib/ChildRoom.class.php');
- $child_room = new child_room();
- $parent_id = $child_room->parent_id($room_id);
- $p_video = $video_redis->getRow_db($parent_id, array('id', 'user_id', 'group_id', 'prop_table'));
- $p_id = $p_video['user_id'];
- }
- $total_diamonds = 1;
- $total_score = 1;
- $total_ticket = 1;
- $pInTrans = $GLOBALS['db']->StartTrans();
- try {
- $sql = "update " . DB_PREFIX . "user set diamonds = diamonds - " . $total_diamonds . ",use_diamonds = use_diamonds + " . $total_diamonds . ", score = score + " . $total_score . " where id = '" . $user_id . "' and diamonds >= " . $total_diamonds;
- $GLOBALS['db']->query($sql);
- if ($GLOBALS['db']->affected_rows()) {
- if ($total_ticket > 0) {
- if(defined("robot_gifts") && robot_gifts ==1){
- $roboter = $GLOBALS['db']->getOne("select roboter from ".DB_PREFIX."user where roboter=1 and id=".$user_id);//查询是否特殊权限用户
- if($roboter){
- //增加:不可提现印票
- $sql = "update ".DB_PREFIX."user set no_ticket = no_ticket + ".$total_ticket." where id = ".$p_id;
- $GLOBALS['db']->query($sql);
- }else{
- //增加:用户印票
- $sql = "update ".DB_PREFIX."user set ticket = ticket + ".$total_ticket." where id = ".$p_id;
- $GLOBALS['db']->query($sql);
- }
- }else{
- //增加:用户印票
- $sql = "update " . DB_PREFIX . "user set ticket = ticket + " . $total_ticket . " where id = " . $p_id;
- $GLOBALS['db']->query($sql);
- }
- /*
- //当前直播获得印票数
- $sql = "update ".DB_PREFIX."video set vote_number = vote_number + ".$total_ticket." where id =".$room_id;
- $GLOBALS['db']->query($sql);
- */
- //记录:用户印票增加日志
- }
- $video_prop = array();
- $video_prop['prop_id'] = 0;
- $video_prop['prop_name'] = "'" . '弹幕' . "'";
- $video_prop['is_red_envelope'] = 0;
- $video_prop['total_score'] = $total_score;
- $video_prop['total_diamonds'] = $total_diamonds;
- $video_prop['total_ticket'] = intval($total_ticket);
- $video_prop['from_user_id'] = $user_id;
- $video_prop['to_user_id'] = $podcast_id;
- $video_prop['create_time'] = NOW_TIME;
- $video_prop['create_date'] = "'" . to_date(NOW_TIME, 'Y-m-d') . "'";
- $video_prop['num'] = 1;
- $video_prop['video_id'] = $room_id;
- $video_prop['group_id'] = "'" . $group_id . "'";
- $video_prop['msg'] = "'" . $msg . "'";
- $video_prop['create_ym'] = to_date($video_prop['create_time'], 'Ym');
- $video_prop['create_d'] = to_date($video_prop['create_time'], 'd');
- $video_prop['create_w'] = to_date($video_prop['create_time'], 'W');
- $video_prop['from_ip'] = "'".get_client_ip()."'";
- //将礼物写入mysql表中
- $field_arr = array(
- 'prop_id',
- 'prop_name',
- 'is_red_envelope',
- 'total_score',
- 'total_diamonds',
- 'total_ticket',
- 'from_user_id',
- 'to_user_id',
- 'create_time',
- 'create_date',
- 'num',
- 'video_id',
- 'group_id',
- 'msg',
- 'create_ym',
- 'create_d',
- 'create_w',
- 'from_ip'
- );
- $fields = implode(",", $field_arr);
- $valus = implode(",", $video_prop);
- $table = $video['prop_table'];
- $table_info = $GLOBALS['db']->getRow("Describe ".$table." from_ip",true,true);
- if(!$table_info){
- $GLOBALS['db']->query("ALTER TABLE ".$table." ADD COLUMN `from_ip` varchar(255) NOT NULL COMMENT '送礼物人IP'");
- }
- $sql = "insert into " . $table . "(" . $fields . ") VALUES (" . $valus . ")";
- $GLOBALS['db']->query($sql);
- $user_prop_id = $GLOBALS['db']->insert_id();
- //写入总表
- if(file_exists(APP_ROOT_PATH.'mapi/lib/core/award_function.php')){
- fanwe_require(APP_ROOT_PATH.'mapi/lib/core/award_function.php');
- $table_all = createPropAllTable();
- $sql = "insert into ".$table_all." (".$fields.") VALUES (".$valus.")";
- $GLOBALS['db']->query($sql);
- }
- //提交事务,不等 消息推送,防止锁太久
- $GLOBALS['db']->Commit($pInTrans);
- $pInTrans = false;//防止,下面异常时,还调用:Rollback
- //子房间
- if(defined('CHILD_ROOM') && CHILD_ROOM == 1){
- fanwe_require(APP_ROOT_PATH.'mapi/lib/ChildRoom.class.php');
- $child_room = new child_room();
- $child_room->child_room_pop_msg($room_id,$video_prop,$fields,$user_id,$total_ticket);
- }
- if ($total_ticket > 0) {
- fanwe_require(APP_ROOT_PATH . 'mapi/lib/redis/VideoContributionRedisService.php');
- $videoCont_redis = new VideoContributionRedisService();
- $videoCont_redis->insert_db($user_id, $podcast_id, $room_id, $total_ticket);
- }
- user_deal_to_reids(array($user_id, $podcast_id));
- //更新用户等级
- $user_info = $user_redis->getRow_db($user_id,
- array('id', 'score', 'online_time', 'user_level'));
- user_leverl_syn($user_info);
- //分销功能 计算抽成
- if (defined('OPEN_DISTRIBUTION') && OPEN_DISTRIBUTION == 1 && $total_ticket > 0) {
- $this->distribution_calculate($user_id, $total_ticket);
- }
- $this->distribution($podcast_id, $room_id, $total_ticket);
- //发送:礼物
- $ext = array();
- $ext['type'] = 2; //0:普通消息;1:礼物;2:弹幕消息;3:主播退出;4:禁言;5:观众进入房间;6:观众退出房间;7:直播结束
- $ext['room_id'] = $room_id;//直播ID 也是room_id;只有与当前房间相同时,收到消息才响应
- $ext['num'] = 1;
- $ext['prop_id'] = 0; //礼物id
- //s$ext['animated_url'] = '';//动画播放url
- $ext['icon'] = '';//图片,是否要: 大中小格式?
- //$ext['is_red_envelope'] = 0;//是否是:红包;1:红包
- $ext['user_prop_id'] = $user_prop_id; //红包时用到,抢红包的id
- //$ext['show_num'] = 1;//显示连续送的礼物数量;
- $fields = array('ticket','no_ticket');
- $user_info = $user_redis->getRow_db($podcast_id,$fields);//用户总的:印票数
- $ext['total_ticket'] =$user_info['ticket']+$user_info['no_ticket'];//用户总的:印票数
- // $ext['total_ticket'] = intval($user_redis->getOne_db($podcast_id, 'ticket'));//用户总的:印票数
- $ext['to_user_id'] = 0;//礼物接收人(主播)
- $ext['fonts_color'] = '';//字体颜色
- $ext['desc'] = $msg;//弹幕消息;
- $ext['desc2'] = $msg;//弹幕消息;
- //消息发送者
- $sender = array();
- $user_info = $user_redis->getRow_db($user_id,
- array('nick_name', 'head_image', 'user_level'));
- $sender['user_id'] = $user_id;//发送人昵称
- $sender['nick_name'] = emoji_decode($user_info['nick_name']);//发送人昵称
- $sender['head_image'] = get_spec_image($user_info['head_image']);//发送人头像
- $sender['user_level'] = $user_info['user_level'];//用户等级
- $ext['sender'] = $sender;
- #构造高级接口所需参数
- $msg_content = array();
- //创建array 所需元素
- $msg_content_elem = array(
- 'MsgType' => 'TIMCustomElem', //自定义类型
- 'MsgContent' => array(
- 'Data' => json_encode($ext),
- 'Desc' => '',
- )
- );
- if (intval($m_config['has_dirty_words']) == 1) {
- //文档内容,用来过滤脏字
- $msg_text_elem = array(
- 'MsgType' => 'TIMTextElem', //
- 'MsgContent' => array(
- 'Text' => $msg,
- )
- );
- array_push($msg_content, $msg_text_elem, $msg_content_elem);
- } else {
- //将创建的元素$msg_content_elem, 加入array $msg_content
- array_push($msg_content, $msg_content_elem);
- }
- if (isset($_REQUEST['is_debug'])) {
- $root['error'] = '';
- $root['status'] = 1;
- } else {
- fanwe_require(APP_ROOT_PATH . 'system/tim/TimApi.php');
- $api = createTimAPI();
- $ret = $api->group_send_group_msg2($user_id, $group_id, $msg_content);
- if ($ret['ActionStatus'] == 'FAIL' && $ret['ErrorCode'] == 10002) {
- //10002 系统错误,请再次尝试或联系技术客服。
- log_err_file(array(__FILE__, __LINE__, __METHOD__, $ret));
- $ret = $api->group_send_group_msg2($user_id, $group_id, $msg_content);
- }
- $GLOBALS['db']->autoExecute($table, $ret, 'UPDATE', 'id=' . $user_prop_id);
- //$videoGift_redis->update_db($user_prop_id, $ret);
- if ($ret['ActionStatus'] == 'FAIL') {
- if ($ret['ErrorCode'] == 80001) {
- $root['error'] = '该词已被禁用';
- } else {
- $root['error'] = $ret['ErrorInfo'] . ":" . $ret['ErrorCode'];
- }
- $root['status'] = 0;
- } else {
- $root['error'] = '';
- $root['status'] = 1;
- }
- }
- } else {
- $GLOBALS['db']->Rollback($pInTrans);
- $root['error'] = "用户".$m_config['diamonds_name']."不足";
- $root['status'] = 0;
- }
- } catch (Exception $e) {
- //异常回滚
- $root['error'] = $e->getMessage();
- $root['status'] = 0;
- $GLOBALS['db']->Rollback($pInTrans);
- }
- }
- }
- }
- ajax_return($root);
- }
- /**
- * 预生成好,红包随机队列
- * @param unknown_type $total_diamonds
- *
- * 0 1
- * 1 20
- * 2 3
- *
- */
- function red_rand_list($total_diamonds)
- {
- $list = array();
- while ($total_diamonds > 0) {
- $diamonds = mt_rand(1, 20);//随机取:1至20中的一个数字
- if ($total_diamonds >= $diamonds) {
- $total_diamonds = $total_diamonds - $diamonds;
- $list[] = $diamonds;
- } else {
- if ($total_diamonds >= 1) {
- $diamonds = 1;
- $total_diamonds = $total_diamonds - $diamonds;
- $list[] = $diamonds;
- }
- }
- }
- return $list;
- }
- /**
- * 把$total_diamonds 生成指定数量$num的,随机列表数
- * @param unknown_type $total_diamonds
- * @param unknown_type $num
- * @return multitype:number
- */
- function red_rand_list2($total_diamonds, $num)
- {
- $list = array();
- if ($num > $total_diamonds) {
- $num = $total_diamonds;
- }
- //先生成一批为:1 的
- for ($x = 0; $x < $num; $x++) {
- $list[] = 1;
- $total_diamonds = $total_diamonds - 1;
- }
- while ($total_diamonds > 0) {
- foreach ($list as $k => $v) {
- $diamonds = mt_rand(1, 19);//随机取:1至20中的一个数字
- if ($total_diamonds >= $diamonds) {
- $total_diamonds = $total_diamonds - $diamonds;
- } else {
- if ($total_diamonds >= 1) {
- $diamonds = 1;
- $total_diamonds = $total_diamonds - $diamonds;
- }
- }
- $list[$k] = $v + $diamonds;
- if ($total_diamonds == 0) {
- break;
- }
- }
- };
- return $list;
- }
- /**
- * 抢红包
- */
- public function red_envelope()
- {
- $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']);
- $user_prop_id = intval($_REQUEST['user_prop_id']);//红包id
- $m_config = load_auto_cache("m_config");//初始化手机端配置
- //============================redis================================================
- fanwe_require(APP_ROOT_PATH . 'mapi/lib/redis/VideoRedRedisService.php');
- $videoRed_redis = new VideoRedRedisService();
- //判断该用户没有抢过;
- $ret = $videoRed_redis->get_user_winning($user_prop_id, $user_id);
- if ($ret == false) {
- //判断是否还有可以抢的红包
- if ($videoRed_redis->red_exists($user_prop_id)) {
- $money = $videoRed_redis->pop_red($user_prop_id);
- if ($money > 0) {
- allot_red_to_user($user_prop_id, $user_id, $money);
- $root['diamonds'] = $money;
- $root['error'] = "恭喜您抢到" . $money . "个".$m_config['diamonds_name'];
- } else {
- $root['status'] = 0;
- $root['error'] = "手慢了,未捡到";
- }
- } else {
- $root['status'] = 0;
- $root['error'] = "手慢了,未捡到!";
- }
- } else {
- $root['diamonds'] = $ret;
- $root['error'] = "恭喜您抢到" . $ret . "个".$m_config['diamonds_name'];
- }
- }
- ajax_return($root);
- }
- /**
- * 抢红包---》看看大家的手气
- */
- public function user_red_envelope()
- {
- $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_prop_id = intval($_REQUEST['user_prop_id']);//红包id
- fanwe_require(APP_ROOT_PATH . 'mapi/lib/redis/VideoRedRedisService.php');
- $videoRed_redis = new VideoRedRedisService();
- $list = $videoRed_redis->get_winnings($user_prop_id);
- foreach ($list as $k => $v) {
- $list[$k]['nick_name'] = emoji_decode($v['nick_name']);
- }
- $root['status'] = 1;
- $root['list'] = $list;
- }
- ajax_return($root);
- }
- /**
- * 送礼物给某人
- */
- public function send_prop()
- {
- $root = array();
- if (!$GLOBALS['user_info']) {
- $root['error'] = "用户未登陆,请先登陆." . print_r($_COOKIE, 1);
- $root['status'] = 0;
- $root['user_login_status'] = 0;//有这个参数: user_login_status = 0 时,表示服务端未登陆、要求登陆,操作
- } else {
- $user_id = intval($GLOBALS['user_info']['id']);
- $prop_id = intval($_REQUEST['prop_id']);//礼物id
- $num = intval($_REQUEST['num']);//礼物数量
- $to_user_id = strim($_REQUEST['to_user_id']);//送给谁
- $is_nospeaking = $GLOBALS['db']->getOne("SELECT is_nospeaking FROM " . DB_PREFIX . "user WHERE id=" . $user_id,
- true, true);
- if ($is_nospeaking) {
- $root['status'] = 0;
- $root['error'] = "被im全局禁言,不能发礼物";
- ajax_return($root);
- }
- if ($user_id == $to_user_id) {
- $root['error'] = "不能发礼物给自己";
- $root['status'] = 0;
- ajax_return($root);
- }
- $m_config = load_auto_cache("m_config");//初始化手机端配置
- //检查测试账号不能发礼物给真实主播
- $sql = "select mobile from " . DB_PREFIX . "user where id = '" . $to_user_id . "'";
- $podcast_mobile = $GLOBALS['db']->getOne($sql);
- if (($GLOBALS['user_info']['mobile'] == '13888888888' && $podcast_mobile != '13999999999') || $GLOBALS['user_info']['mobile'] == '13999999999' && $podcast_mobile != '13888888888') {
- $root['error'] = "测试账号不能发礼物给真实主播";
- $root['status'] = 0;
- ajax_return($root);
- }
- $prop = load_auto_cache("prop_id", array('id' => $prop_id));
- if ($num <= 0) {
- $num = 1;
- }
- $total_diamonds = $num * $prop['diamonds'];
- $total_score = $num * $prop['score'];
- $total_ticket = intval($num * $prop['ticket']);
- fanwe_require(APP_ROOT_PATH . 'mapi/lib/redis/UserRedisService.php');
- $user_redis = new UserRedisService();
- $pInTrans = $GLOBALS['db']->StartTrans();
- try {
- //免费礼物
- if ($total_diamonds == 0 && $total_score == 0 && $total_ticket == 0) {
- $m_config = load_auto_cache("m_config");//初始化手机端配置
- $root['to_msg'] = "收到一个" . $prop['name'] . ",获得" . $total_ticket . $m_config['ticket_name'] . ",可以去个人主页>我的收益 查看哦";
- $to_diamonds = 0;
- $to_ticket = intval($total_ticket);
- $root['from_msg'] = "送给你一个" . $prop['name'];
- $root['from_score'] = "你的经验值+" . $total_score;
- $root['to_ticket'] = intval($to_ticket);
- $root['to_diamonds'] = $to_diamonds;//可获得的:钻石数;只有红包时,才有
- $root['to_user_id'] = $to_user_id;
- $root['prop_icon'] = $prop['icon'];
- $root['status'] = 1;
- $root['prop_id'] = $prop_id;
- $root['total_ticket'] = intval($user_redis->getOne_db($to_user_id, 'ticket'));//用户总的:印票数
- } else {
- //私聊送红包礼物没有经验
- if ($prop['is_red_envelope'] == 1) {
- $total_score = 0;
- }
- $sql = "update " . DB_PREFIX . "user set diamonds = diamonds - " . $total_diamonds . ", use_diamonds = use_diamonds + " . $total_diamonds . ", score = score + " . $total_score . " where id = '" . $user_id . "' and diamonds >= " . $total_diamonds;
- $GLOBALS['db']->query($sql);
- if ($GLOBALS['db']->affected_rows()) {
- //将红包的钻石,直接加给被送用户
- if ($prop['is_red_envelope'] == 1) {
- //$desc = '我给大家送了一个红包';
- //$user_redis->lock_diamonds($to_user_id,$total_diamonds);
- $sql = "update " . DB_PREFIX . "user set diamonds = diamonds + " . $total_diamonds . " where id = " . $to_user_id;
- $GLOBALS['db']->query($sql);
- $root['to_msg'] = "收到一个" . $prop['name'] . ",获得" . $total_diamonds .$m_config['diamonds_name'].",可以去个人主页 查看哦";
- $to_diamonds = $total_diamonds;//用户添加的:钻石 数;
- $to_ticket = 0;
- } else {
- $m_config = load_auto_cache("m_config");//初始化手机端配置
- $society_info = $GLOBALS['db']->getRow("select society_id,society_chieftain from " . DB_PREFIX . "user where id = " . $to_user_id);
- if(defined('OPEN_SOCIETY_MODULE') && OPEN_SOCIETY_MODULE){
- if($m_config['society_pattern'] == 2){
- //收益归公会长所有
- if($society_info['society_id']){
- $this->soceity_rake($to_user_id, $total_ticket ,$user_id);
- }else{
- $sql = "update " . DB_PREFIX . "user set ticket = ticket + " . $total_ticket . " where id = " . $to_user_id;
- $GLOBALS['db']->query($sql);
-
- //写入用户日志
- earnings_log($total_ticket, $society_info['society_id'], 0, 13, '私信获取收益:'.$total_ticket.'印票', $to_user_id);
- }
-
- }elseif($m_config['society_pattern'] == 1){
- //有公会需要增加公会等级积分
- if($society_info['society_id']){
- society_level_syn($total_ticket, 0, $society_info['society_id']);
- }
- $sql = "update " . DB_PREFIX . "user set ticket = ticket + " . $total_ticket . " where id = " . $to_user_id;
- $GLOBALS['db']->query($sql);
-
- if($society_info['society_chieftain']){
- $GLOBALS['db']->query("update ".DB_PREFIX."society set contribution = contribution + $total_ticket where id=".$society_info['society_id']);
- //写入会长日志
- earnings_log($total_ticket, $society_info['society_id'], $user_id, 13, '私信获取收益:'.$total_ticket.'印票', $to_user_id);
- }else{
- //写入用户日志
- earnings_log($total_ticket, $society_info['society_id'], 0, 13, '私信获取收益:'.$total_ticket.'印票', $to_user_id);
- }
- }else{
- $sql = "update " . DB_PREFIX . "user set ticket = ticket + " . $total_ticket . " where id = " . $to_user_id;
- $GLOBALS['db']->query($sql);
-
- //写入用户日志
- earnings_log($total_ticket, $society_info['society_id'], 0, 13, '私信获取收益:'.$total_ticket.'印票', $to_user_id);
- }
- }else{
- $sql = "update " . DB_PREFIX . "user set ticket = ticket + " . $total_ticket . " where id = " . $to_user_id;
- $GLOBALS['db']->query($sql);
-
- //写入用户日志
- earnings_log($total_ticket, $society_info['society_id'], 0, 13, '私信获取收益:'.$total_ticket.'印票', $to_user_id);
- }
-
- $root['to_msg'] = "收到一个" . $prop['name'] . ",获得" . $total_ticket . $m_config['ticket_name'] . ",可以去个人主页>我的收益 查看哦";
- $to_diamonds = 0;
- $to_ticket = intval($total_ticket);
- }
- $this->check_invite($user_id, $total_ticket, $prop_id);
- //插入:送礼物表
- $video_prop = array();
- $video_prop['prop_id'] = $prop_id;
- $video_prop['prop_name'] = "'" . $prop['name'] . "'";
- $video_prop['is_red_envelope'] = $prop['is_red_envelope'];
- $video_prop['total_score'] = $total_score;
- $video_prop['total_diamonds'] = $total_diamonds;
- if ($prop['is_red_envelope'] == 1) {
- $video_prop['total_ticket'] = intval($total_diamonds);
- } else {
- $video_prop['total_ticket'] = intval($total_ticket);
- }
- $video_prop['from_user_id'] = $user_id;
- $video_prop['to_user_id'] = $to_user_id;
- $video_prop['create_time'] = NOW_TIME;
- $video_prop['create_date'] = "'".to_date(NOW_TIME,'Y-m-d')."'";
- $video_prop['num'] = $num;
- $video_prop['create_ym'] = to_date($video_prop['create_time'], 'Ym');
- $video_prop['create_d'] = to_date($video_prop['create_time'], 'd');
- $video_prop['create_w'] = to_date($video_prop['create_time'], 'W');
- $video_prop['from_ip'] = "'".get_client_ip()."'";
- $video_prop['is_private'] = 1;
- //将礼物写入mysql表中
- $field_arr = array(
- 'prop_id',
- 'prop_name',
- 'is_red_envelope',
- 'total_score',
- 'total_diamonds',
- 'total_ticket',
- 'from_user_id',
- 'to_user_id',
- 'create_time',
- 'create_date',
- 'num',
- 'create_ym',
- 'create_d',
- 'create_w',
- 'from_ip',
- 'is_private'
- );
- if(intval(OPEN_REWARD_GIFT)){
- if(file_exists(APP_ROOT_PATH.'mapi/lib/core/award_function.php')) {
- fanwe_require(APP_ROOT_PATH . 'mapi/lib/core/award_function.php');
- $list_award = get_award_info();
- }
- }
- if(intval(OPEN_REWARD_GIFT)&&intval($list_award['is_open_award'])==1){
- $field_arr[] = 'is_award';
- $video_prop['is_award'] = intval($prop['is_award']);
- }
- $fields = implode(",", $field_arr);
- $valus = implode(",", $video_prop);
- $table = createPropTable();
- $table_info = $GLOBALS['db']->getRow("Describe ".$table." from_ip",true,true);
- if(!$table_info){
- $GLOBALS['db']->query("ALTER TABLE ".$table." ADD COLUMN `from_ip` varchar(255) NOT NULL COMMENT '送礼物人IP'");
- }
- $sql = "insert into " . $table . "(" . $fields . ") VALUES (" . $valus . ")";
- $GLOBALS['db']->query($sql);
- $user_prop_id = $GLOBALS['db']->insert_id();
- //写入总表
- if(file_exists(APP_ROOT_PATH.'mapi/lib/core/award_function.php')){
- fanwe_require(APP_ROOT_PATH.'mapi/lib/core/award_function.php');
- $table_all = createPropAllTable();
- $sql = "insert into ".$table_all." (".$fields.") VALUES (".$valus.")";
- $GLOBALS['db']->query($sql);
- }
- //提交事务
- $GLOBALS['db']->Commit($pInTrans);
- $pInTrans = false;
- if ($prop['is_red_envelope'] == 0) {
- fanwe_require(APP_ROOT_PATH . 'mapi/lib/redis/VideoContributionRedisService.php');
- $videoCont_redis = new VideoContributionRedisService();
- $videoCont_redis->insert_db($user_id, $to_user_id, 0, $total_ticket);
- }
- //分销功能 计算抽成
- if (defined('OPEN_DISTRIBUTION') && OPEN_DISTRIBUTION == 1 && $prop['is_red_envelope'] == 0 && $total_ticket > 0) {
- $this->distribution_calculate($user_id, $total_ticket);
- }
- $this->distribution($to_user_id, 0, $total_ticket);
- user_deal_to_reids(array($user_id, $to_user_id));
- //更新用户等级
- $user_info = $user_redis->getRow_db($user_id,
- array('id', 'score', 'online_time', 'user_level'));
- user_leverl_syn($user_info);
- $root['from_msg'] = "送给你一个" . $prop['name'];
- $root['from_score'] = "你的经验值+" . $total_score;
- $root['to_ticket'] = intval($to_ticket);
- $root['to_diamonds'] = $to_diamonds;//可获得的:钻石数;只有红包时,才有
- $root['to_user_id'] = $to_user_id;
- $root['prop_icon'] = $prop['icon'];
- $root['status'] = 1;
- $root['prop_id'] = $prop_id;
- $root['total_ticket'] = intval($user_redis->getOne_db($to_user_id, 'ticket'));//用户总的:印票数
- } else {
- $GLOBALS['db']->Rollback($pInTrans);
- $root['error'] = "用户".$m_config['diamonds_name']."不足";
- $root['status'] = 0;
- }
- }
- //减少用户钻石
- } catch (Exception $e) {
- //异常回滚
- $root['error'] = $e->getMessage();
- $root['status'] = 0;
- $GLOBALS['db']->Rollback($pInTrans);
- }
- }
- ajax_return($root);
- }
- /**
- * 游戏分销
- * @param $podcast_id
- * @param $video_id
- * @param $total_ticket
- */
- private function distribution($podcast_id, $video_id, $total_ticket)
- {
- require_once APP_ROOT_PATH . 'mapi/lib/core/Model.class.php';
- Model::$lib = dirname(__FILE__);
- if (defined('GAME_DISTRIBUTION') && GAME_DISTRIBUTION) {
- Model::build('game_distribution')->addLog($podcast_id, $video_id, 0, $total_ticket, '直播礼物分销',1);
- }
- if (defined('WEIXIN_DISTRIBUTION') && WEIXIN_DISTRIBUTION) {
- Model::build('weixin_distribution_log')->addLog($podcast_id, $total_ticket, '直播礼物分销(微信)',1);
- }
- }
- /**
- * 分销抽成
- * @param $user_id
- * @param $total_ticket
- */
- private function distribution_calculate($user_id, $total_ticket)
- {
- $root = array();
- $m_config = load_auto_cache("m_config");//初始化手机端配置
- $table = DB_PREFIX . 'distribution_log';
- fanwe_require(APP_ROOT_PATH . 'mapi/lib/redis/UserRedisService.php');
- $user_redis = new UserRedisService();
- $to_user_id = $user_redis->getOne_db($user_id, 'p_user_id');//用户总的:印票数
- $ticket = 0;
- $result = 0;
- if (intval($to_user_id) > 0 && intval($m_config['distribution']) == 1 && $user_id > 0 && $total_ticket > 0) {
- $ticket = round($m_config['distribution_rate'] * 0.01 * $total_ticket, 2);
- $sql = "select id from " . $table . " where to_user_id = " . $to_user_id . " and from_user_id = " . $user_id;
- $distribution_id = $GLOBALS['db']->getOne($sql);
- if (intval($distribution_id) > 0) {
- $sql = "update " . $table . " set ticket = ticket + " . $ticket . " where id = " . $distribution_id;
- $GLOBALS['db']->query($sql);
- $result = 1;
- } else {
- //插入:分销日志
- $video_prop = array();
- $video_prop['from_user_id'] = $user_id;
- $video_prop['to_user_id'] = $to_user_id;
- $video_prop['create_date'] = "'" . to_date(NOW_TIME, 'Y-m-d') . "'";
- $video_prop['ticket'] = $ticket;
- $video_prop['create_time'] = NOW_TIME;
- $video_prop['create_ym'] = to_date($video_prop['create_time'], 'Ym');
- $video_prop['create_d'] = to_date($video_prop['create_time'], 'd');
- $video_prop['create_w'] = to_date($video_prop['create_time'], 'W');
- //将日志写入mysql表中
- $field_arr = array(
- 'from_user_id',
- 'to_user_id',
- 'create_date',
- 'ticket',
- 'create_time',
- 'create_ym',
- 'create_d',
- 'create_w'
- );
- $fields = implode(",", $field_arr);
- $valus = implode(",", $video_prop);
- $sql = "insert into " . $table . "(" . $fields . ") VALUES (" . $valus . ")";
- $GLOBALS['db']->query($sql);
- $result = $GLOBALS['db']->insert_id();
- }
- if (intval($result) > 0) {
- $sql = "update " . DB_PREFIX . "user set ticket = ticket + " . $ticket . " where id = " . $to_user_id;
- $GLOBALS['db']->query($sql);
- }
- }
- }
-
- //-------------无抽成模式,所得私信收益归公会长所有---------------
- /**
- * @param int $to_user_id 被送礼物用户ID
- * @param int $total_ticket 获得的收益
- * @param int $user_id 用户id
- */
- public function soceity_rake($to_user_id,$total_ticket,$user_id){
- //判断是否有公会
- $user_info = $GLOBALS['db']->getRow("select society_id,society_chieftain from ".DB_PREFIX."user where id=".$to_user_id);
- $society_info = $GLOBALS['db']->getRow("select user_id,status from ".DB_PREFIX."society where id=".$user_info['society_id']);
- if($user_info['society_id'] > 0 && $society_info['status'] == 1){
- //主播的收益加到公会中
- $pInTrans = $GLOBALS['db']->StartTrans();
- try
- {
- //加入公会收益
- $sql = "update ".DB_PREFIX."society set chairman_earnings=chairman_earnings+".$total_ticket." where user_id=".$society_info['user_id'];
- $GLOBALS['db']->query($sql);
-
- //排除公会长
- if(!$user_info['society_chieftain']){
- //将用户上交的公会的印票计入已提现
- $sql = "update ".DB_PREFIX."user set ticket = ticket + ".$total_ticket.",refund_ticket = refund_ticket + ".$total_ticket.",society_ticket=society_ticket+".$total_ticket." where id = ".$to_user_id." and ticket >=refund_ticket";
- $status = $GLOBALS['db']->query($sql);
-
- //将收益汇入公会长
- $sql_chieftain = "update ".DB_PREFIX."user set ticket = ticket + ".$total_ticket." where id = ".$society_info['user_id'];
- $GLOBALS['db']->query($sql_chieftain);
- user_deal_to_reids(array($society_info['user_id']));
-
- //写入用户日志
- earnings_log($total_ticket, $user_info['society_id'], 0, 10, '私信获取收益:'.$total_ticket.'印票', $to_user_id);
- //写入会长日志
- earnings_log($total_ticket, $user_info['society_id'], $to_user_id, 10, '主播'.$to_user_id.'私信获取收益,产生公会收益'.$total_ticket.'印票', $society_info['user_id']);
-
- }else{
- $sql = "update ".DB_PREFIX."user set ticket = ticket + ".$total_ticket.",society_ticket=society_ticket+".$total_ticket." where id = ".$to_user_id." and ticket >=refund_ticket";
- $status = $GLOBALS['db']->query($sql);
- //写入用户日志
- earnings_log($total_ticket, $user_info['society_id'], $user_id, 10, '私信获取收益:'.$total_ticket.'印票', $society_info['user_id']);
- }
-
- //公会等级积分的写入
- society_level_syn($total_ticket, 0, $user_info['society_id']);
- //提交事务
- $GLOBALS['db']->Commit($pInTrans);
- }catch(Exception $e){
- //异常回滚
- $GLOBALS['db']->Rollback($pInTrans);
- //写入会长日志
- earnings_log($total_ticket, $user_info['society_id'], 0, 10, '公会成员'.$to_user_id.'贡献收益,'.$total_ticket.'印票'.'失败', $society_info['user_id']);
- }
- //-----事务结束-----
- }
- return ;
- }
- }
|