BaseLogic.php 1.2 KB
<?php

namespace App\Http\Logic\Bside;

use App\Enums\Common\Code;
use App\Exceptions\BsideGlobalException;

/**
 * @notes: 逻辑层基类 控制器调用 统一返回 统一抛出异常
 * @author:wlj
 * @date: 2022/6/7 17:37
 */
class BaseLogic
{
    /**
     * @notes: 请简要描述方法功能
     * @param array $data
     * @return array
     * @author:wlj
     * @date: 2022/7/19 12:25
     */
    public function success(array $data): array
    {
        return $data;
    }

    /**
     * @notes: 错误抛出
     * @param string $code
     * @param string $message
     * @throws BsideGlobalException
     * @author:wlj
     * @date: 2022/7/19 12:28
     */
    public function fail(string $code = Code::SYSTEM_ERROR, $message = "")
    {
        throw new BsideGlobalException($code, $message);
    }

    /**
     * @notes: 统一格式化分页返回
     * @return array
     * @author:wlj
     * @date: 2022/7/11 15:34
     */
    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;
    }

}