コード例 #1
0
 /**
  * 用户地址接口   
  */
 public function actionInfo($id)
 {
     $util = Yii::$app->util;
     $request = Yii::$app->getRequest();
     $params = Yii::$app->request->get();
     //判断用户是否登录
     if (!UserBaseInfo::isLogin()) {
         $util->formatResData(1202, 'please_login', ['msg' => '请你登录']);
     }
     $id = intval($id);
     //判断参数的是否为空
     if (!$id) {
         $util->formatResData(1101, 'address_param_missing', ['msg' => '地址信息参数缺失']);
     }
     //判断是否是Ajax请求
     if (!$request->getIsAjax($id)) {
         $util->formatResData(1301, 'illegal_request', ['msg' => '非法请求']);
     }
     $address = new Address();
     $data = $address->getByUserId($id);
     //通过地址ID获取对应的地址信息
     $data = $address->getById($id);
     if (!$data) {
         $util->formatResData(1102, 'id_not_exists', ['msg' => 'ID信息不存在']);
     }
     //从session或cookie中获取用户id
     $userId = UserBaseInfo::getUserId();
     if ($data['user_id'] != $userId) {
         $util->formatResData(1103, 'can_not_operate_other\'s_order_message', ['msg' => '不能操作其他人的订单信息']);
     }
     if (!$data['post_code']) {
         unset($data['post_code']);
     }
     //根据子区域id获取区域信息
     $region = District::getById($data['county'], true);
     if (!$region) {
         $util->formatResData(1104, 'region_message_not_exists', ['msg' => '该子区域ID对应的区域信息不存在']);
     }
     $result = ['city' => $region['upid'], 'province' => $region['parent']['upid']];
     $result = array_merge($data, $result);
     if ($result) {
         $util->formatResData(0, 'success', $result);
     } else {
         $util->formatResData(1201, 'get_address_fail', ['msg' => '获取地区信息失败']);
     }
 }