12345678910111213141516171819202122 |
- <?php
- namespace app\controller;
- use think\response\Json;
- trait ResponseJson
- {
- public function JsonSucess($data=null,$code=1): Json
- {
- return $this->JsonResponse($code,config("ResponseCode.".$code),$data);
- }
- public function JsonError($message = null,$code=0): Json
- {
- if ($message==null){$message=config("ResponseCode.".$code);}
- return $this->JsonResponse($code,$message);
- }
- public function JsonResponse($code,$message,$data=[]): Json
- {
- return json(["code"=>$code,"data"=>$data,"message"=>$message]);
- }
- }
|