xiaogang 4 years ago
parent
commit
6d4f3f64e6
1 changed files with 16 additions and 0 deletions
  1. 16 0
      app/Services/DynamicService.php

+ 16 - 0
app/Services/DynamicService.php

xqd xqd
@@ -11,6 +11,7 @@ use App\Models\DynamicModel;
 use App\Models\DynamicZanModel;
 use App\Models\User;
 use App\Models\UserReportModel;
+use App\Models\UserVipLimit;
 use Illuminate\Support\Facades\DB;
 use PHPUnit\Util\Exception;
 use function PHPUnit\Framework\isEmpty;
@@ -31,6 +32,21 @@ class DynamicService
      * 发布动态
      */
     public function release(DynamicParam $dynamicParam){
+        $user = auth('api')->user();
+        //判断会员特权和普通用户
+        if($user->is_vip==0){
+            throw new Exception("开通VIP即可发布动态");
+        }else{
+            $limit = UserVipLimit::query()->where('user_id',$user->id)->first();
+            if($limit->dynamic>=5){
+                throw new Exception("每天只能发布5条");
+            }else{
+                //增加记录
+                UserVipLimit::query()->where('user_id',$user->id)->increment('dynamic',1);
+            }
+        }
+
+
         //如果设置了标签   新标签则添加  否则就热度加1
         $tag_ins = '';
         //throw new Exception(json_encode($dynamicParam->tag));