下面说下1对1直播系统源码中,直播场景赠送礼物的逻辑流程介绍:
用户在APP中,选择礼物 点击赠送按钮,请求接口
获取到请求的参数
1、检测用户信息
$checkToken=checkToken($uid,$token);
if($checkToken==700){
$rs['code'] = $checkToken;
$rs['msg'] = '您的登陆状态失效,请重新登陆!';
return $rs;
}
2、检测礼物信息
/* 礼物信息 */
$giftinfo=DI()->notorm->gift ->select("type,mark,giftname,gifticon,needcoin,swftype,swf,swftime")
->where('id=?',$giftid)
->fetchOne();
if(!$giftinfo){
/* 礼物信息不存在 */
return 1002;
}
3、计算总价
$total= $giftinfo['needcoin']*$giftcount;
$addtime=time();
$type='expend';
$action='sendgift';
/* 扣除用户余额 增加用户消费总额 */
$ifok =DI()->notorm->users
->where('id = ? and coin >=?', $uid,$total)
->update(array('coin' => new NotORM_Literal("coin - {$total}"),'consumption' => new NotORM_Literal("consumption + {$total}") ) );
if(!$ifok){
/* 余额不足 */
return 1001;
}
/* 增加主播 魅力值 累计魅力值 */
$istouid =DI()->notorm->users
->where('id = ?', $liveuid)
->update( array('votes' => new NotORM_Literal("votes + {$anthor_total}"),'votestotal' => new NotORM_Literal("votestotal + {$total}") ));
$stream2=explode('_',$stream);
$showid=$stream2[1];
4、生成用户消费记录
$insert=array("type"=>$type,"action"=>$action,"uid"=>$uid,"touid"=>$liveuid,"giftid"=>$giftid,"giftcount"=>$giftcount,"totalcoin"=>$total,"showid"=>$showid,"mark"=>$giftinfo['mark'],"addtime"=>$addtime );
DI()->notorm->users_coinrecord->insert($insert);
5、生成赠送礼物 唯一标识 安全处理
$gifttoken=md5(md5($action.$uid.$liveuid.$giftid.$giftcount.$total.$showid.$addtime.rand(100,999)));
6、将用户最新余额 等级 以及 赠送礼物标识 返回到APP 以处理礼物效果
$rs['info'][0]['gifttoken']=$result['gifttoken'];
$rs['info'][0]['level']=$result['level'];
$rs['info'][0]['coin']=$result['coin'];
return $rs;
以上就是在1对1直播系统源码中,直播场景当中用户消费实现方式,代码中详细介绍了检测用户信息、检测礼物信息、计算总价、生成用户消费记录、生成赠送礼物、将用户最新余额等级以及赠送礼物标识、返回到APP 以处理礼物效果处理过程的介绍。
声明:本篇文章为小编原创文章,转载请注明出处及作者。