|
@@ -2,15 +2,37 @@
|
|
|
|
|
|
namespace yckj\commons\model;
|
|
|
|
|
|
+use CatchException;
|
|
|
+use RuntimeException;
|
|
|
+use think\exception\HttpResponseException;
|
|
|
use think\Model;
|
|
|
+use think\Facade\Log;
|
|
|
|
|
|
-class Result extends Model
|
|
|
+/**
|
|
|
+ * 通用返回值,继承Model是为了方便 \think\Response 序列化对象,这并不是一个数据库对象
|
|
|
+ */
|
|
|
+class Result implements Model
|
|
|
{
|
|
|
protected int $code;
|
|
|
|
|
|
- protected string $msg;
|
|
|
-
|
|
|
protected mixed $data;
|
|
|
-
|
|
|
|
|
|
+ protected string $msg = '';
|
|
|
+
|
|
|
+ public function __construct(int $code, $data, $msg = '')
|
|
|
+ {
|
|
|
+ $this->$code = $code;
|
|
|
+ $this->$data = $data;
|
|
|
+ $this->msg = $msg;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static function of($data)
|
|
|
+ {
|
|
|
+ if(!is_null($data)) {
|
|
|
+ return new Result(0, $data, 'success');
|
|
|
+ }
|
|
|
+
|
|
|
+ Log::error('Unknown Null Error');
|
|
|
+ throw new CatchException('', 1000);
|
|
|
+ }
|
|
|
}
|