~~~
<?php
namespace app\utils;
class Code
{
/**
* 自定义全局code码
*/
public static $arr = [
'10000' => 'success',
'40000' => '好友信息不存在',
'40001' => '不能添加自己为好友',
'40002' => '请三分钟后,再添加好友',
'40003' => '请不要重复添加好友',
'40004' => '发送好友请求失败',
'40005' => '添加好友失败'
];
/**
* service层 错误返回
* @param $code
* @return array
*/
public static function error($code){
$arr = [
'code' => $code,
'result' =>false
];
return $arr;
}
/**
* service层 成功返回
* @return array
*/
public static function success(){
$arr = [
'code' => 10000,
'result' =>true
];
return $arr;
}
public static function isSuccess($data){
if($data['code']==10000 && $data['result']==true){
return true;
}
return false;
}
/**
* 消息返回
* @param $code
* @return mixed
*/
public static function msg($code){
if(!isset(self::$arr[$code])){
return '未定义code码';
}
return self::$arr[$code];
}
}
~~~