<noframes id="bhrfl"><address id="bhrfl"></address>

    <address id="bhrfl"></address>

    <noframes id="bhrfl"><address id="bhrfl"><th id="bhrfl"></th></address>

    <form id="bhrfl"><th id="bhrfl"><progress id="bhrfl"></progress></th></form>

    <em id="bhrfl"><span id="bhrfl"></span></em>

    全部
    常見問題
    產品動態
    精選推薦

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

    管理 管理 編輯 刪除

    流程

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

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

    021ee202305261552279738.png

    Middleware

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

    前置中間件在訪問控制器之前會被執行調用,通常用來攔截參數,跨域配置,多語言加載,Session初始化,權限驗證,登陸驗證等處理;

    而后置中間件屬于返回數據后在執行的中間件,用來做一些返回數據后需要執行的任務等業務邏輯

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

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

    Controller

    每個控制器負責相關業務的請求接收,只做最基本的數據接收,并調用相關的sevices業務處理層,返回數據。
    例如:

    <?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

    所有的業務都在Repository層中處理,Repository層調用dao層,【注意:每個獨立的services層只能調用對應的dao層,不能調用其他模型dao層。

    比如:repository/user/UserRepository.php中只能調用dao/user/UserDao.php,無法調用 dao/order/StoreOrderDao.php。要想調用其他模型數據,

    只能在UserServices.php中調用services/order/StoreOrderServices.php的方法來實現其他模型數據調用】。

    例如:

    <?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層中主要用于當前模型基本的數據處理方法。dao層中調用對應的model,同樣無法跨層調用。
    例如:

    <?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主要用于實例化數據表,只做相關數據表的基礎設置,搜索器,設置器及表關聯等操作。

    <?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'
    ];
    /**
    * 自動轉類型
    * @var string[]
    */
    protected $type = [
    'birthday' => 'int'
    ];
    protected $updateTime = false;
    /**
    * 修改器
    */
    protected function setAddTimeAttr($value)
    {
    return time();
    }
    /**
    * 關聯訂單
    * @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

    快捷回復
    回復
    回復
    回復({{post_count}}) {{!is_user ? '我的回復' :'全部回復'}}
    排序 默認正序 回復倒序 點贊倒序

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

    作者 管理員 企業

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

    {{itemf.name}}

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

    {{itemc.user_info.nickname}}

    {{itemc.user_name}}

    回復 {{itemc.comment_user_info.nickname}}

    附件

    {{itemf.name}}

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

    相關推薦

    快速安全登錄

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

    微信登錄/注冊

    切換手機號登錄

    {{ bind_phone ? '綁定手機' : '手機登錄'}}

    {{codeText}}
    切換微信登錄/注冊
    暫不綁定
    亚洲欧美字幕
    CRMEB客服

    CRMEB咨詢熱線 咨詢熱線

    400-8888-794

    微信掃碼咨詢

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