Browse Source

送礼物上限

lizhen_gitee 11 months ago
parent
commit
cb19f99503
1 changed files with 31 additions and 0 deletions
  1. 31 0
      application/api/controller/Gift.php

+ 31 - 0
application/api/controller/Gift.php

@@ -91,6 +91,13 @@ class Gift extends Api
             $this->error("不存在的用户");
         }
 
+        //送礼物上限
+        $limit_rs = $this->limit_gift($giftvalue);
+        if($limit_rs !== true){
+            $this->error($limit_rs);
+        }
+
+
         Db::startTrans();
 
         // 判断当前用户余额
@@ -153,6 +160,30 @@ class Gift extends Api
 
     }
 
+    //送礼物上限
+    public function limit_gift($giftvalue){
+        $limit_info = Db::name('gift_limit')->where('level',$this->auth->wealth_level)->find();
+        if(empty($limit_info)){
+            return true;
+        }
+
+        if($this->auth->wealth_value + $giftvalue > $limit_info['gift_total']){
+            return '您已经达到送礼物总上限';
+        }
+
+        $today = date('Y-m-d');
+        $starttime = strtotime($today);
+        $endtime   = $starttime + 86399;
+
+        $today_sum = Db::name('gift_user_typing')->where('user_id',$this->auth->id)->where('createtime','BETWEEN',[$starttime,$endtime])->sum('total_price');
+        if($today_sum + $giftvalue >= $limit_info['gift_total']){
+            return '您今天已经达到送礼物上限';
+        }
+
+        return true;
+
+    }
+