You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
2.2 KiB
69 lines
2.2 KiB
9 months ago
|
<?php
|
||
|
// +----------------------------------------------------------------------
|
||
|
// | 天诚科技 [ 刘海东 17600099397赋能开发者,助力企业发展 ]
|
||
|
// +----------------------------------------------------------------------
|
||
|
// | Copyright (c) 2016~2020 https://www.tczxkj.com All rights reserved.
|
||
|
// +----------------------------------------------------------------------
|
||
|
// | Licensed 该系统并不是自由软件,未经许可不能去掉相关版权
|
||
|
// +----------------------------------------------------------------------
|
||
|
// | Author:甘肃天诚志信电子商务有限公司 刘海东 联系电话维系17600099397
|
||
|
// +----------------------------------------------------------------------
|
||
|
|
||
|
|
||
|
namespace service;
|
||
|
|
||
|
|
||
|
class JsonService
|
||
|
{
|
||
|
private static $SUCCESSFUL_DEFAULT_MSG = 'ok';
|
||
|
|
||
|
private static $FAIL_DEFAULT_MSG = 'no';
|
||
|
|
||
|
public static function result($code, $msg = '', $data = [], $count = 0)
|
||
|
{
|
||
|
exit(json_encode(compact('code', 'msg', 'data', 'count')));
|
||
|
}
|
||
|
|
||
|
public static function successlayui($count = 0, $data = [], $msg = '')
|
||
|
{
|
||
|
if (is_array($count)) {
|
||
|
if (isset($count['data'])) $data = $count['data'];
|
||
|
if (isset($count['count'])) $count = $count['count'];
|
||
|
}
|
||
|
if (false == is_string($msg)) {
|
||
|
$data = $msg;
|
||
|
$msg = self::$SUCCESSFUL_DEFAULT_MSG;
|
||
|
}
|
||
|
return self::result(0, $msg, $data, $count);
|
||
|
}
|
||
|
|
||
|
public static function successful($msg = 'ok', $data = [], $status = 200)
|
||
|
{
|
||
|
if (false == is_string($msg)) {
|
||
|
$data = $msg;
|
||
|
$msg = self::$SUCCESSFUL_DEFAULT_MSG;
|
||
|
}
|
||
|
return self::result($status, $msg, $data);
|
||
|
}
|
||
|
|
||
|
public static function status($status, $msg, $result = [])
|
||
|
{
|
||
|
$status = strtoupper($status);
|
||
|
if (true == is_array($msg)) {
|
||
|
$result = $msg;
|
||
|
$msg = self::$SUCCESSFUL_DEFAULT_MSG;
|
||
|
}
|
||
|
return self::result(200, $msg, compact('status', 'result'));
|
||
|
}
|
||
|
|
||
|
public static function fail($msg, $data = [], $code = false)
|
||
|
{
|
||
|
if (true == is_array($msg)) {
|
||
|
$data = $msg;
|
||
|
$msg = self::$FAIL_DEFAULT_MSG;
|
||
|
}
|
||
|
return self::result($code ? $code : 400, $msg, $data);
|
||
|
}
|
||
|
|
||
|
}
|