/**
  * 更新并返回更新结果
  *
  * @param array $data 更新收货地址数据
  *              ~
  *              [
  *                  'id' => '主键ID', 'addressee' => '', 'mobile' => '',
  *                  'county' => '', 'address' => ''
  *              ]
  *              ~
  * @param \api\group\v1\models\Address $addressModel 收货地址model对象
  * @param \common\helpers\Util $util
  *
  * @return mixed
  */
 private function update($data, $addressModel, $util)
 {
     $addr = $addressModel->getAddrById($data['id'], Address::STATUS_ENABLE, false);
     if (!$addr) {
         return $util->responseArray(6104, 'address_notexists_disable', '收货地址不存在或已被删除');
     }
     $ret = $addressModel->updateAddr($addr, $data);
     if ($ret) {
         return $util->responseArray(0, 'success', '修改成功', ['id' => $data['id'], 'addressee' => $data['addressee'], 'mobile' => $data['mobile'], 'address' => $data['address']]);
     } else {
         return $util->responseArray(-1, 'system_busy', '系统繁忙,请稍后重试');
     }
 }
Example #2
0
 /**
  * 获取用户信息
  */
 public function actionGetUser()
 {
     $params = Yii::$app->getRequest()->post();
     $util = Yii::$app->util;
     if (!isset($params['id'])) {
         return $util->responseArray(1101, 'userid_params_missing', '用户ID参数缺失');
     }
     $id = intval($params['id']);
     if ($id <= 0) {
         return $util->responseArray(2101, 'illegal_userid_params', '用户ID参数非法');
     }
     try {
         $userModel = new UserBaseInfoGroup();
         $user = $userModel->getById($id, UserBaseInfoGroup::USER_NORMAL_STATUS, true, ['id', 'avatar', 'username', 'realname', 'city', 'contact_phone', 'email', 'gender', 'personality_sig']);
         if (!$user) {
             return $util->responseArray(2100, 'user_forbidden_or_notexists', '用户不存在或者被禁用');
         }
         $addressModel = new Address();
         $address = $addressModel->getAddrByUserId($id, Address::STATUS_ENABLE, true, ['id', 'mobile', 'address']);
         $county = District::getById($user['city'], false);
         if ($county && $county['level'] == District::AREA_LEVEL_COUNTY) {
             $parentCounty = District::getById($county['upid'], true);
             $user['district'] = $parentCounty['parent']['name'] . ' ' . $parentCounty['name'] . ' ' . $county['name'];
         } else {
             $user['district'] = '';
         }
         $user['address'] = $address;
         unset($user['city']);
         return $util->responseArray(0, 'success', '成功', $user);
     } catch (Exception $ex) {
         return $util->responseArray(5101, 'database_exception', '数据库异常');
     }
 }