where(['user_id' => $user_id]) ->where('is_default', 1) ->order('is_default desc') ->find(); if (!$result) { return []; } return $result; } /** * @notes 根据ID获取地址 * @param $user_id * @param $id * @return array * @throws @\think\db\exception\DataNotFoundException * @throws @\think\db\exception\DbException * @throws @\think\db\exception\ModelNotFoundException * @author 张无忌 * @date 2021/8/3 16:47 */ public static function getAddressById($user_id, $id) { $model = new self; $result = $model->where(['user_id'=>$user_id]) ->where('id', '=', intval($id)) ->find(); if (!$result) { return []; } return $result; } /** * @notes 获取一条收货地址 * @param $user_id * @param $id * @return array * @author 张无忌 * @date 2021/8/3 16:42 */ public static function getOneAddress($user_id, $id=0) { if ($id > 0) { return self::getAddressById($user_id, $id); } return self::getDefaultAddress($user_id); } }