<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                ## 基礎控制器 ``` ~~~ namespace app\api\controller; use app\api\service\Token; use think\Controller; class BaseController extends Controller { protected function checkExclusiveScope() { Token::needExclusiveScope(); } protected function checkPrimaryScope() { Token::needPrimaryScope(); } protected function checkSuperScope() { Token::needSuperScope(); } } ~~~ ``` ## ## 其他控制器繼承這個 ``` ~~~ namespace app\api\controller\v1; use app\api\controller\BaseController; use app\api\model\User; use app\api\model\UserAddress; use app\api\service\Token; use app\api\service\Token as TokenService; use app\api\validate\AddressNew; use app\lib\exception\SuccessMessage; use app\lib\exception\UserException; use think\Controller; use think\Exception; class Address extends BaseController { protected $beforeActionList = [ 'checkPrimaryScope' => ['only' => 'createOrUpdateAddress,getUserAddress'] ]; /** * 獲取用戶地址信息 * @return UserAddress * @throws UserException */ public function getUserAddress(){ $uid = Token::getCurrentUid(); $userAddress = UserAddress::where('user_id', $uid) ->find(); if(!$userAddress){ throw new UserException([ 'msg' => '用戶地址不存在', 'errorCode' => 60001 ]); } return $userAddress; } /** * 更新或者創建用戶收獲地址 */ public function createOrUpdateAddress() { $validate = new AddressNew(); $validate->goCheck(); $uid = TokenService::getCurrentUid(); $user = User::get($uid); if(!$user){ throw new UserException([ 'code' => 404, 'msg' => '用戶收獲地址不存在', 'errorCode' => 60001 ]); } $userAddress = $user->address; // 根據規則取字段是很有必要的,防止惡意更新非客戶端字段 $data = $validate->getDataByRule(input('post.')); if (!$userAddress ) { // 關聯屬性不存在,則新建 $user->address() ->save($data); } else { // 存在則更新 // fromArrayToModel($user->address, $data); // 新增的save方法和更新的save方法并不一樣 // 新增的save來自于關聯關系 // 更新的save來自于模型 $user->address->save($data); } return new SuccessMessage(); } } ~~~ ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看