|
@@ -41,190 +41,6 @@ class Test
|
|
|
$redis->hDel("livebc_jewel_top3",$user_id);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 全麦/单独赠送礼物
|
|
|
- */
|
|
|
- public function giveGiftToYou() {
|
|
|
- // 接口防并发
|
|
|
- if (!$this->apiLimit(1, 1000)) {
|
|
|
- $this->error(__('Operation frequently'));
|
|
|
- }
|
|
|
|
|
|
- //
|
|
|
- $user_ids = $this->request->request("user_id");// 赠送对象
|
|
|
- $gift_id = $this->request->request("gift_id");// 礼物ID
|
|
|
- $party_id = $this->request->request("party_id",0);// 派对ID
|
|
|
- $number = $this->request->request("number");// 赠送数量
|
|
|
- $room_type = 1; // 房间类型
|
|
|
- $is_back = 0;// 是否背包赠送: 1=是,0=否
|
|
|
- if (!$user_ids || !$gift_id || !$number)
|
|
|
- {
|
|
|
- $this->error(__('Invalid parameters'));
|
|
|
- }
|
|
|
-
|
|
|
- //
|
|
|
- $user_id_arr = explode(',',$user_ids);
|
|
|
- $userCount = count($user_id_arr);
|
|
|
- $userauthid = $this->auth->id;
|
|
|
-
|
|
|
-
|
|
|
- // 获取礼物信息
|
|
|
- $giftInfo = Db::name('gift')->where('id',$gift_id)->find();
|
|
|
- if (!$giftInfo) {$this->error("请选择礼物!");}
|
|
|
- $giftValue = $giftInfo["value"] * $number;
|
|
|
- $giftCountValue = $giftInfo["value"] * $number * $userCount;
|
|
|
-
|
|
|
-
|
|
|
- // 判断当前用户余额
|
|
|
- $user_gold = model('wallet')->getWallet($userauthid,'gold');
|
|
|
- if($user_gold < $giftCountValue) {$this->error("您的金币余额不足!");}
|
|
|
-
|
|
|
-
|
|
|
- if($party_id){
|
|
|
- $partyInfo = \app\common\model\Party::field("user_id,platRate,guilderRate")->where(["id"=>$party_id])->find();
|
|
|
- if(!$partyInfo){
|
|
|
- $this->error('不存在的语聊间');
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- $returnData = [];
|
|
|
- Db::startTrans();
|
|
|
- try {
|
|
|
- $redis = new Redis();
|
|
|
- $redisconfig = config("redis");
|
|
|
- $redis->connect($redisconfig["host"], $redisconfig["port"], 86400 * 31);
|
|
|
-
|
|
|
- // 获取当天零点
|
|
|
- $day = date("Ymd");
|
|
|
- // 获取本周第一天
|
|
|
- $weekday = $this->firstOfWeek(date("Y-m-d H:i:s"));
|
|
|
- // 获取本月第一天
|
|
|
- $monthday = date("Ym01");
|
|
|
-
|
|
|
- $allVal = 0;
|
|
|
- $i = 0;
|
|
|
- foreach($user_id_arr as $user_id) {
|
|
|
-
|
|
|
- // 添加礼物赠送记录表
|
|
|
- $data = [];
|
|
|
- $data["user_id"] = $userauthid;
|
|
|
- $data["user_to_id"] = $user_id;
|
|
|
- $data["party_id"] = $party_id;
|
|
|
- $data["gift_id"] = $gift_id;
|
|
|
- $data["gift_give_type"] = 2;
|
|
|
- $data["gift_name"] = $giftInfo["name"];
|
|
|
- $data["gift_gif_image"] = $giftInfo["image"];
|
|
|
- $data["number"] = $number;
|
|
|
- $data["price"] = $giftInfo["value"];
|
|
|
- $data["value"] = $giftValue;
|
|
|
-
|
|
|
- $data["createtime"] = time();
|
|
|
- $log_id = Db::name('gift_user_party')->insertGetId($data);
|
|
|
- if(!$log_id){
|
|
|
- Db::rollback();
|
|
|
- $this->error('赠送失败');
|
|
|
- }
|
|
|
-
|
|
|
- if($giftValue > 0){
|
|
|
- // 扣除当前用户钻石余额
|
|
|
- $wallet_rs = model('wallet')->lockChangeAccountRemain($userauthid,'gold',-$giftValue,51,'赠送礼物:'.$giftInfo["name"],'gift_user_party',$log_id);
|
|
|
- if($wallet_rs['status'] === false){
|
|
|
- Db::rollback();
|
|
|
- $this->error($wallet_rs['msg']);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- // 添加赠送用户余额
|
|
|
- $money_to_gold = config('site.money_to_gold');
|
|
|
- $gift_plat_scale = config('site.gift_plat_scale');
|
|
|
- $giftmoney = bcdiv($giftValue,$money_to_gold,2);
|
|
|
- $money = bcdiv(bcmul($giftmoney,100 - $gift_plat_scale,2),100,2);
|
|
|
-
|
|
|
- $wallet_rs = model('wallet')->lockChangeAccountRemain($user_id,'money',$money,52,'获得礼物:'.$giftInfo["name"],'gift_user_party',$log_id);
|
|
|
- if($wallet_rs['status'] === false){
|
|
|
- Db::rollback();
|
|
|
- $this->error($wallet_rs['msg']);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- $res6 = true;
|
|
|
-
|
|
|
- if ($res6) {
|
|
|
- $i++;
|
|
|
- if($party_id > 0) {
|
|
|
- // 添加redis记录做财富排行榜日榜用
|
|
|
- $redis->zIncrBy($this->roomTypeArr[$room_type] . "_jewel_get_" . $party_id . ":" . $day . "d", $giftValue, $user_id);
|
|
|
- // 添加redis记录做财富排行榜周榜用
|
|
|
- $redis->zIncrBy($this->roomTypeArr[$room_type] . "_jewel_get_" . $party_id . ":" . $weekday . "w", $giftValue, $user_id);
|
|
|
- // 添加redis记录做财富排行榜月榜用
|
|
|
- $redis->zIncrBy($this->roomTypeArr[$room_type] . "_jewel_get_" . $party_id . ":" . $monthday . "m", $giftValue, $user_id);
|
|
|
- // 添加redis记录做贡献排行榜日榜用
|
|
|
- $redis->zIncrBy($this->roomTypeArr[$room_type] . "_jewel_to_" . $party_id . ":" . $day . "d", $giftValue, $userauthid);
|
|
|
- // 添加redis记录做贡献排行榜周榜用
|
|
|
- $redis->zIncrBy($this->roomTypeArr[$room_type] . "_jewel_to_" . $party_id . ":" . $weekday . "w", $giftValue, $userauthid);
|
|
|
- // 添加redis记录做贡献排行榜月榜用
|
|
|
- $redis->zIncrBy($this->roomTypeArr[$room_type] . "_jewel_to_" . $party_id . ":" . $monthday . "m", $giftValue, $userauthid);
|
|
|
-
|
|
|
- // tcp 更新用户魅力值
|
|
|
- $this->updateUserCharm($party_id, $user_id, $giftValue);
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- $allVal = $allVal + $giftValue;
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 获取用户魅力值
|
|
|
- $users = $redis->zRange("hourCharm_".$party_id,0,-1,true);
|
|
|
- $u = [];
|
|
|
- if($users) {
|
|
|
- foreach($users as $k => $v) $u[] = [
|
|
|
- "user_id"=>$k,
|
|
|
- "charm"=>$this->changeW($v)
|
|
|
- ];
|
|
|
- }
|
|
|
- $userCharm = $u;
|
|
|
- // tcp 更新房间热度
|
|
|
- $partyHot = $this->updatePartyHot($party_id, $allVal, $room_type);
|
|
|
-
|
|
|
- // 如果是派对,则添加派对热度值记录做榜单统计
|
|
|
- if($room_type == 1) {
|
|
|
- $data = [];
|
|
|
- $data["party_id"] = $party_id;
|
|
|
- $data["hot"] = $allVal;
|
|
|
- $data["createtime"] = time();
|
|
|
- \app\common\model\PartyHot::insert($data);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- // tcp 获取房间用户周前三名
|
|
|
- $partyUserTop = $this->getPartyUserTop($party_id, $room_type);
|
|
|
-
|
|
|
- if($i == $userCount) {
|
|
|
- $returnData["userCharm"] = $userCharm;
|
|
|
- $returnData["partyHot"] = $this->changeW($partyHot);
|
|
|
- $returnData["partyUserTop"] = $partyUserTop;
|
|
|
- $returnData["image"] = $giftInfo["image"];
|
|
|
- $returnData["gif_image"] = $giftInfo["special"];
|
|
|
-
|
|
|
- Db::commit();
|
|
|
- $this->success("赠送成功!",$returnData);
|
|
|
- } else {
|
|
|
- $this->success("赠送失败!");
|
|
|
- }
|
|
|
- } catch (ValidateException $e) {
|
|
|
- Db::rollback();
|
|
|
- $this->error($e->getMessage());
|
|
|
- } catch (PDOException $e) {
|
|
|
- Db::rollback();
|
|
|
- $this->error($e->getMessage());
|
|
|
- } catch (Exception $e) {
|
|
|
- Db::rollback();
|
|
|
- $this->error($e->getMessage());
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
}
|