ResponseJson.php 503 B

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