BaseLogic.php
1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
namespace App\Http\Logic\Bside;
use App\Enums\Common\Code;
use App\Exceptions\BsideGlobalException;
/**
* @notes: 逻辑层基类 控制器调用 统一返回 统一抛出异常
*/
class BaseLogic
{
protected $requestAll;
public function __construct()
{
$this->requestAll = request()->all();
}
/**
* @notes: 请简要描述方法功能
* @param array $data
* @return array
*/
public function success(array $data): array
{
return $data;
}
/**
* @notes: 错误抛出
* @param string $code
* @param string $message
* @throws BsideGlobalException
*/
public function fail(string $code = Code::SYSTEM_ERROR, $message = "")
{
throw new BsideGlobalException($code, $message);
}
/**
* @notes: 统一格式化分页返回
* @return array
*/
function getPageData($pagninate): array
{
$p = $pagninate->toArray();
$result['list'] = $p ['data'];
$result['pager']['total'] = $p ['total'];
$result['pager']['page'] = $p ['current_page'];
$result['pager']['pagesize'] = $p ['per_page'];
return $result;
}
}