宅男在线永久免费观看网直播,亚洲欧洲日产国码无码久久99,野花社区在线观看视频,亚洲人交乣女bbw,一本一本久久a久久精品综合不卡

全部
常見問題
產(chǎn)品動態(tài)
精選推薦

CRMEB多商戶二開接口流程文檔

管理 管理 編輯 刪除

流程

主要講解controller目錄,每個(gè)controller有自己獨(dú)立的路由,配置,事件,容器,控制器中可用框架核心及擴(kuò)展。每個(gè)控制器其實(shí)就是一個(gè)獨(dú)立的控制類。

請求流程大致分為以下流程,依次從左到右

021ee202305261552279738.png

Middleware

中間件分為前置和后置中間件.

前置中間件在訪問控制器之前會被執(zhí)行調(diào)用,通常用來攔截參數(shù),跨域配置,多語言加載,Session初始化,權(quán)限驗(yàn)證,登陸驗(yàn)證等處理;

而后置中間件屬于返回?cái)?shù)據(jù)后在執(zhí)行的中間件,用來做一些返回?cái)?shù)據(jù)后需要執(zhí)行的任務(wù)等業(yè)務(wù)邏輯

下面以前置中間件為例:文件存放目錄 app/應(yīng)用名/middleware/AuthMiddleware.php

<?php
namespase app\應(yīng)用名\middleware;
use crmeb\interfaces\MiddlewareInterface;
class AuthMiddleware implements MiddlewareInterface
{
public function handle(Request $request, \Closure $next)
{
//這里可以設(shè)置請求header
//可以寫權(quán)限驗(yàn)證
//驗(yàn)證失敗直接可以拋出異常中止請求
if(false)
{
throw new AuthException('無權(quán)驗(yàn)證');
}
return $next($request);
}
}

Controller

每個(gè)控制器負(fù)責(zé)相關(guān)業(yè)務(wù)的請求接收,只做最基本的數(shù)據(jù)接收,并調(diào)用相關(guān)的sevices業(yè)務(wù)處理層,返回?cái)?shù)據(jù)。
例如:

<?php
namespace app\controller;
use app\Request;
use app\common\repositories\user\UserRepository;
class User
{
protected $repository;
public function __construct(App $app, repository $repository)
{
parent::__construct($app);
$this->repository = $repository;
}
public function lst($cid)
{
[$page, $limit] = $this->getPage();
$where = $this->request->params(['id']);
$data = $this->repository->search($where, $page, $limit);
return app('json')->success($data);
}
}

Repository

所有的業(yè)務(wù)都在Repository層中處理,Repository層調(diào)用dao層,【注意:每個(gè)獨(dú)立的services層只能調(diào)用對應(yīng)的dao層,不能調(diào)用其他模型dao層。

比如:repository/user/UserRepository.php中只能調(diào)用dao/user/UserDao.php,無法調(diào)用 dao/order/StoreOrderDao.php。要想調(diào)用其他模型數(shù)據(jù),

只能在UserServices.php中調(diào)用services/order/StoreOrderServices.php的方法來實(shí)現(xiàn)其他模型數(shù)據(jù)調(diào)用】。

例如:

<?php
namespace app\common\repositories\user;
use app\common\dao\user\UserDao;
class UserRepository extends BaseRepository
{
protected $dao;
public function __construct(UserDao $dao)
{
$this->dao = $dao;
}
public function search(array $where, int $page, int $limit)
{
$list = $this->dao->getList($where,'*',$page,$limit);
$count = $this->dao->count($where);
return compact('count','list');
}
}

Dao

dao層中主要用于當(dāng)前模型基本的數(shù)據(jù)處理方法。dao層中調(diào)用對應(yīng)的model,同樣無法跨層調(diào)用。
例如:

<?php
namespace app\dao\user;
use app\dao\BaseDao;
use app\model\user\User;
/**
* 用戶
* Class UserDao
* @package app\dao\user
*/
class UserDao extends BaseDao
{
protected function setModel(): string
{
return User::class;
}
public function getOne($uid)
{
return $this->where(['uid' => $uid])->field('username,phone')->find();
}
}

Model

model主要用于實(shí)例化數(shù)據(jù)表,只做相關(guān)數(shù)據(jù)表的基礎(chǔ)設(shè)置,搜索器,設(shè)置器及表關(guān)聯(lián)等操作。

<?php
namespace app\model\user;
use crmeb\basic\BaseModel;
use think\Model;
/**
* Class User
* @package app\model\user
*/
class User extends BaseModel
{
/**
* @var string
*/
protected $pk = 'uid';
protected $name = 'user';
protected $insert = ['add_time', 'add_ip', 'last_time', 'last_ip'];
protected $hidden = [
'add_ip', 'account', 'clean_time', 'last_ip', 'pwd'
];
/**
* 自動轉(zhuǎn)類型
* @var string[]
*/
protected $type = [
'birthday' => 'int'
];
protected $updateTime = false;
/**
* 修改器
*/
protected function setAddTimeAttr($value)
{
return time();
}
/**
* 關(guān)聯(lián)訂單
* @return User|\think\model\relation\HasMany
*/
public function order()
{
return $this->hasMany(StoreOrder::class, 'uid', 'uid');
}
/**
/**
* 搜索器 用戶uid
* @param Model $query
* @param $value
*/
public function searchUidAttr($query, $value)
{
if (is_array($value))
$query->whereIn('uid', $value);
else
$query->where('uid', $value);
}
}


原文鏈接: https://blog.csdn.net/jiazi1024/article/details/124284742

請登錄后查看

CRMEB-慕白寒窗雪 最后編輯于2023-05-26 15:57:26

快捷回復(fù)
回復(fù)
回復(fù)
回復(fù)({{post_count}}) {{!is_user ? '我的回復(fù)' :'全部回復(fù)'}}
排序 默認(rèn)正序 回復(fù)倒序 點(diǎn)贊倒序

{{item.user_info.nickname ? item.user_info.nickname : item.user_name}} LV.{{ item.user_info.bbs_level }}

作者 管理員 企業(yè)

{{item.floor}}# 同步到gitee 已同步到gitee {{item.is_suggest == 1? '取消推薦': '推薦'}}
{{item.is_suggest == 1? '取消推薦': '推薦'}}
沙發(fā) 板凳 地板 {{item.floor}}#
{{item.user_info.title || '暫無簡介'}}
附件

{{itemf.name}}

{{item.created_at}}  {{item.ip_address}}
打賞
已打賞¥{{item.reward_price}}
{{item.like_count}}
{{item.showReply ? '取消回復(fù)' : '回復(fù)'}}
刪除
回復(fù)
回復(fù)

{{itemc.user_info.nickname}}

{{itemc.user_name}}

回復(fù) {{itemc.comment_user_info.nickname}}

附件

{{itemf.name}}

{{itemc.created_at}}
打賞
已打賞¥{{itemc.reward_price}}
{{itemc.like_count}}
{{itemc.showReply ? '取消回復(fù)' : '回復(fù)'}}
刪除
回復(fù)
回復(fù)
查看更多
打賞
已打賞¥{{reward_price}}
4771
{{like_count}}
{{collect_count}}
添加回復(fù) ({{post_count}})

相關(guān)推薦

快速安全登錄

使用微信掃碼登錄
{{item.label}} 加精
{{item.label}} {{item.label}} 板塊推薦 常見問題 產(chǎn)品動態(tài) 精選推薦 首頁頭條 首頁動態(tài) 首頁推薦
取 消 確 定
回復(fù)
回復(fù)
問題:
問題自動獲取的帖子內(nèi)容,不準(zhǔn)確時(shí)需要手動修改. [獲取答案]
答案:
提交
bug 需求 取 消 確 定
打賞金額
當(dāng)前余額:¥{{rewardUserInfo.reward_price}}
{{item.price}}元
請輸入 0.1-{{reward_max_price}} 范圍內(nèi)的數(shù)值
打賞成功
¥{{price}}
完成 確認(rèn)打賞

微信登錄/注冊

切換手機(jī)號登錄

{{ bind_phone ? '綁定手機(jī)' : '手機(jī)登錄'}}

{{codeText}}
切換微信登錄/注冊
暫不綁定
CRMEB客服

CRMEB咨詢熱線 咨詢熱線

400-8888-794

微信掃碼咨詢

CRMEB開源商城下載 源碼下載 CRMEB幫助文檔 幫助文檔
返回頂部 返回頂部
CRMEB客服