48 lines
1.2 KiB
PHP
48 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Response;
|
|
|
|
use App\Jobs\AddErrorLog;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
trait ResponseJson
|
|
{
|
|
public function failure($msg='服务器休息,请稍后再试', $data=[], $jsonp=false)
|
|
{
|
|
return $this->jsonResponse(1, $msg, $data);
|
|
}
|
|
|
|
public function success($msg, $data=[], $cookie = null, $jsonp = false)
|
|
{
|
|
if (request()->debug) {
|
|
return view('welcome');
|
|
}
|
|
//增加数据为空值返回统一处理
|
|
// if(empty($data)){
|
|
// return $this->jsonResponse(1, '数据为空', null);
|
|
// }
|
|
return $this->jsonResponse(0, $msg, $data);
|
|
}
|
|
|
|
public function authFail($msg="未授权登录", $data=[])
|
|
{
|
|
return $this->jsonResponse(2, $msg, $data);
|
|
}
|
|
|
|
public function banFail($msg="已封号,请联系客服", $data=[])
|
|
{
|
|
return $this->jsonResponse(4, $msg, $data);
|
|
}
|
|
|
|
private function jsonResponse($code, $msg, $data=[])
|
|
{
|
|
$result = [
|
|
'code'=>$code,
|
|
'message'=>$msg,
|
|
'data'=>$data,
|
|
];
|
|
return Response()->json($result);
|
|
}
|
|
}
|