ResponseJson.php 572 B

12345678910111213141516171819202122
  1. <?php
  2. namespace app\controller;
  3. use think\response\Json;
  4. trait ResponseJson
  5. {
  6. public function JsonSucess($data=null,$code=1): Json
  7. {
  8. return $this->JsonResponse($code,config("ResponseCode.".$code),$data);
  9. }
  10. public function JsonError($message = null,$code=0): Json
  11. {
  12. if ($message==null){$message=config("ResponseCode.".$code);}
  13. return $this->JsonResponse($code,$message);
  14. }
  15. public function JsonResponse($code,$message,$data=[]): Json
  16. {
  17. return json(["code"=>$code,"data"=>$data,"message"=>$message]);
  18. }
  19. }