浏览代码

送礼物优化

lizhen_gitee 1 年之前
父节点
当前提交
1e09b48c2f
共有 1 个文件被更改,包括 22 次插入33 次删除
  1. 22 33
      application/api/controller/Party.php

+ 22 - 33
application/api/controller/Party.php

@@ -1626,26 +1626,34 @@ class Party extends Common
         $money_to_jewel = config('site.money_to_jewel') ?: 10; //余额兑换钻石
         $userModel = new \app\common\model\User();
 
-        $backGiftId = 0;
-        $boxgiftInfo = [];
         // 不可以赠送给自己
         //if(in_array($userauthid,$user_id_arr)) $this->error("不可以赠送给自己!");
+
+        $backGiftId = 0; //背包礼物表的 gift_id
+        $boxgiftInfo = [];
+
         if($is_back == 1) {
             // 获取背包礼物信息
             $giftInfo = \app\common\model\GiftBack::get($gift_id);
-            if(!$giftInfo) $this->error("背包礼物获取失败");
+            if(!$giftInfo){
+                $this->error("背包礼物获取失败");
+            }
             $backGiftId = $giftInfo->gift_id;
+
             // 随机获取一个礼物
             $allCount = $number*$userCount;
-            $giftbackList = \app\common\model\GiftBack::where(["name"=>$giftInfo->name,"user_id"=>$userauthid,'is_use'=>0])->limit($allCount)->select();
-            $giftInfo = isset($giftbackList[0])?$giftbackList[0]:[];
+            $giftbackList = \app\common\model\GiftBack::where(["gift_id"=>$backGiftId,"user_id"=>$userauthid,'is_use'=>0])->limit($allCount)->select();
+            $giftInfo = isset($giftbackList[0]) ? $giftbackList[0] : [];
             $giftcount = 0;
             $giftList = [];
-            if($giftbackList) foreach($giftbackList as $k => $v) {
-                $giftcount =  $giftcount + $v["number"];
-                $giftList[$k] = $v;
-                if($giftcount >= $allCount) {
-                    break;
+
+            if(!empty($giftbackList)) {
+                foreach($giftbackList as $k => $v) {
+                    $giftcount =  $giftcount + $v["number"];
+                    $giftList[$k] = $v;
+                    if($giftcount >= $allCount) {
+                        break;
+                    }
                 }
             }
 
@@ -1655,11 +1663,10 @@ class Party extends Common
         } else {
 
             // 获取礼物信息
-            $giftModel = new \app\common\model\Gift();
-            $where = [];
-            $where["id"] = $gift_id;
-            $giftInfo = $giftModel->where($where)->find();
-            if (!$giftInfo) $this->error("请选择礼物!");
+            $giftInfo = Db::name('gift')->where('id',$gift_id)->find();
+            if (!$giftInfo) {
+                $this->error("请选择礼物!");
+            }
             $giftValue = $giftInfo["value"] * $number;
             $giftCountValue = $giftInfo["value"] * $number * $userCount;
             $getValue = $giftValue;
@@ -1679,21 +1686,6 @@ class Party extends Common
 
         $hotValue = $getValue;
 
-        //$getValue = round($getValue * ($soundCoinRate/100));
-
-        // 转换统计
-        /*$progetValue = $hotValue - $getValue;
-        if($progetValue >0) {
-            $data = [];
-            $data["user_id"] = $user_ids;
-            $data["party_id"] = $party_id?$party_id:0;
-            $data["gift_value"] = $hotValue;
-            $data["plat_value"] = $hotValue - $getValue;
-            $data["createtime"] = time();
-            \app\common\model\UserChangeLog::insert($data);
-        }*/
-
-
         // 转换声币后 再进行抽点设置
         $partyInfo = null;
         if(!$party_id) {
@@ -1723,9 +1715,6 @@ class Party extends Common
             if($redisconfig['redis_selectdb'] > 0){
                 $redis->select($redisconfig['redis_selectdb']);
             }
-            // 事务处理余额与记录信息
-            $userjewellogModel = new \app\common\model\UserJewelLog();
-            //$usersoundcoinlogModel = new \app\common\model\UserSoundcoinLog();
 
             // 获取当天零点
             $day = date("Ymd");