123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- <?php
- namespace App\Http\Controllers;
- use Illuminate\Http\Request;
- use Dingo\Api\Routing\Helpers;
- use Laravel\Lumen\Routing\Controller as BaseController;
- class Controller extends BaseController
- {
- use Helpers;
- public function success($data=[],$msg="ok"){
- $this->parseNull($data);
- $result = [
- "code"=>200,
- "msg"=>$msg,
- "data"=>$data,
- ];
- return response()->json($result,200);
- }
- public function success_list($data,$msg="ok" ,$total=0,$re=[],$res="all"){
- $this->parseNull($data);
- $result = [
- "code"=>200,
- "message"=>$msg,
- "data"=>[
- 'size'=>15,
- 'total'=>$total,
- "$res"=>$re,
- 'list'=>$data
- ],
- ];
- return response()->json($result,200);
- }
- //失败返回
- public function error($code="422",$data="",$msg="fail"){
- $result = [
- "code"=>$code,
- "message"=>$msg,
- "msg"=>$msg,
- "data"=>$data
- ];
- return response()->json($result,200);
- }
- //失败返回
- public function errormsg($code="422",$data="",$msg="fail"){
- $result = [
- "code"=>$code,
- "msg"=>$msg,
- "data"=>$data
- ];
- return response()->json($result,200);
- }
- public function new_error($code="422",$msg="fail"){
- $result = [
- "code"=>$code,
- "message"=>$msg,
- ];
- return response()->json($result,200);
- }
- //如果返回的数据中有 null 则那其值修改为空 (安卓和IOS 对null型的数据不友好,会报错)
- private function parseNull(&$data){
- if(is_array($data)){
- foreach($data as &$v){
- $this->parseNull($v);
- }
- }else{
- if(is_null($data)){
- $data = "";
- }
- }
- }
- }
|