wesmiler 1 giorno fa
parent
commit
5ebf8ac00b

+ 2 - 1
app/Http/Controllers/Api/v1/PostRecordController.php

@@ -65,7 +65,8 @@ class PostRecordController extends webApp
             if ($result = PostRecordService::make()->submit($this->userId, $params)) {
                 return showJson(PostRecordService::make()->getError(), true, $result);
             } else {
-                return showJson(PostRecordService::make()->getError(), false);
+                $errorCode = PostRecordService::make()->getErrorCode();
+                return showJson(PostRecordService::make()->getError(), false,'',$errorCode);
             }
         }  catch (\Exception $exception) {
             $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];

+ 6 - 0
app/Services/Api/PostRecordService.php

@@ -136,6 +136,12 @@ class PostRecordService extends BaseService
             return false;
         }
 
+        if($userId<=0){
+            $this->error = '请先登录';
+            $this->errorCode = 403;
+            return false;
+        }
+
         $cacheKey = "caches:members:comment_{$userId}_{$sourceId}";
         if(RedisService::get($cacheKey.'_lock')){
             $this->error = '请不要频繁提交';

+ 11 - 0
app/Services/BaseService.php

@@ -27,6 +27,8 @@ class BaseService
     // 错误信息
     protected $error = '1003';
 
+    protected $errorCode = 0;
+
     protected $errorData = [];
     // 静态对象
     protected static $instance = null;
@@ -62,6 +64,15 @@ class BaseService
     }
 
     /**
+     * 错误码
+     * @return int
+     */
+    public function getErrorCode()
+    {
+        return $this->errorCode;
+    }
+
+    /**
      * 获取数据列表
      * @return array
      * @since 2020/11/11