- 🏠 简介
- 📥 源码下载
- 🚀 安装指南
- 🔧 niucloud (服务端)
- 🖥️ admin (后台管理端)
- 📱 uni-app(手机端前端)
- 🌐 web端(PC前端)
- ⚙️ 代码生成器
- ⚙️ 配置手册
- 📚 使用手册
- 🔄 版本更新
-
❓ 常见问题
- 配置问题
- 服务器问题
- 安装升级问题
- 使用问题
- 版本问题
- 二开问题
- 问题修复
-
其他问题
- 站点site端(租户端、商家端)和saas管理端(平台端)究竟啥意思,有啥区别
- 框架中是有订单表order,假如开发一个商城插件,请问商城的订单数据是不是重新搞一个订单表shop_order
- 有些支付平台是绑定回调唯一网址或目录,如果有几个开发者开发插件都有支付那这块怎么解决?
- 站点过期,可以登录,这样对吗?
- 计划任务怎么启动啊
- Git多分支开发,切换分支
- 未获取到授权信息问题处理方案
- 下载应用时提示找不到zip解决方案
- 获取数据失败问题处理方案
- 底部导航失效问题
- 开放平台小程序审核通过发布失败问题
- 插件与框架的版本兼容问题处理方案
- 框架1.0.2之前升级最新版错误Undefined array key "content"
Service层
服务层概述
services层属于Model层之下(niucloud-admin框架没有DAO层),是最接近控制器层的。所有的业务逻辑都可以写在services层中。
目录结构
niucloud/
├── app/
│ ├── service/
│ │ ├── admin/ # 管理端服务层
│ │ │ ├── member/ # 会员相关服务
│ │ │ ├── sys/ # 系统相关服务
│ │ │ └── ... # 其他管理端服务模块
│ │ ├── api/ # API服务层(前端接口)
│ │ │ ├── member/ # 会员相关服务
│ │ │ ├── sys/ # 系统相关服务
│ │ │ └── ... # 其他API服务模块
│ │ └── core/ # 核心服务层(跨站点公共服务)
│ │ ├── member/ # 会员核心服务
│ │ ├── sys/ # 系统核心服务
│ │ └── ... # 其他核心服务模块
service层包括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();
}
}