1对1直播系统源码中,直播场景主要的消费方式—赠送礼物介绍

下面说下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 以处理礼物效果处理过程的介绍。
声明:本篇文章为小编原创文章,转载请注明出处及作者。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值