|
@@ -129,3 +129,35 @@ function subtext($text, $length)
|
|
|
return $text;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+function success($data = [], $msg = "成功")
|
|
|
+{
|
|
|
+ $response = array(
|
|
|
+ 'code' => 0,
|
|
|
+ 'msg' => $msg,
|
|
|
+ 'data' => new stdClass()
|
|
|
+ );
|
|
|
+ if ($data) {
|
|
|
+ if (is_array($data)) {
|
|
|
+ //带有分页格式转换
|
|
|
+ if (isset($data['meta'])) {
|
|
|
+ // 更改元数据格式,全部包含在data下
|
|
|
+ $temp = array(
|
|
|
+ 'data' => array(
|
|
|
+ 'data' => $data['data'],
|
|
|
+ 'pagination' => $data['meta']['pagination']
|
|
|
+ )
|
|
|
+ );
|
|
|
+ $response = array_merge($response, $temp);
|
|
|
+ } elseif(isset($data['data'])) {
|
|
|
+ $response = $data;
|
|
|
+ }else{
|
|
|
+ $temp = array(
|
|
|
+ 'data' => $data
|
|
|
+ );
|
|
|
+ $response = array_merge($response, $temp);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return $response;
|
|
|
+}
|