Phone: 158 4018 8888 Email: 407593529@qq.com

服务类

2026-02-25 17:26:47 2

Service层

services层属于Model层之下(niucloud-admin框架没有DAO层),是最接近控制器层的。所有的业务逻辑都可以写在services层中。

sservice层包括model实例的变量,request请求两个字段

protected $model;  
protected $request;

service内置方法

获取当前分页页码和展示条数,会根据系统配置返回不大于配置的展示条数

public function getPageParam()

获取分页列表

public function getPageList(Model $model, array $where, string $field = '*', string $order = '', array $append = [], $with = null, $each = null){

分页数据查询,传入model(查询后结果)

public function pageQuery($model, $each = null)

分页视图列表查询

public function getPageViewList(Model $model, array $where, string $field = '*', string $order = '', array $append = [], $with = null, $each = null)

BaseService类按照端口,有以下子类

BaseCoreService、 BaseAdminService、 BaseApiService

这几个类的文件都定义在 niucloud\core\base 文件夹中。
BaseCoreService是所有内核服务类的基类,对于可能在多个端口都会调用的service类,一般继承自他。

BaseAdminService是Admin管理端的Service的基类,该类实现了站点端(商家端、租户端)的site_id 的变量的赋值和取值,当前登录的用户名和uid字段。

class BaseAdminService extends BaseService
{

    protected $site_id;
    protected $username;
    protected $uid;

    protected $app_type;
    public function __construct()
    {
        parent::__construct();
        $this->app_type = $this->request->appType();
        $this->site_id = $this->request->siteId();
        $this->username = $this->request->username();
        $this->uid = $this->request->uid();
    }
}

BaseApiService是前端API(web、uni-app)的Service的基类,该类实现了site_id 的变量的取值,当前登录的会员ID(member_id)和登录方式的字段取值。

class BaseApiService extends BaseService
{

    protected $site_id;
    protected $member_id;
    protected $channel;

    public function __construct()
    {
        parent::__construct();
        $this->site_id = $this->request->siteId();
        $this->member_id = $this->request->memberId();
        $this->channel = $this->request->getChannel();
    }
}

选择样式

选择布局
选择颜色
选择背景
选择背景