Example #1
0
 /**
  * 我的银行
  */
 public function actionShippingaddress()
 {
     $model = new UserProductAddressForm();
     $user_id = Yii::$app->user->getId();
     $thisuserpa = UserProductAddress::find()->where("user_id=" . $user_id)->one();
     if (!$thisuserpa) {
         $thisuserpa = new UserProductAddress();
     }
     if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) {
         Yii::$app->response->format = Response::FORMAT_JSON;
         return ActiveForm::validate($model);
     }
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         $thisuserpa->setAttributes($model->attributes);
         $thisuserpa->setAttribute('province', $_POST['province']);
         $thisuserpa->setAttribute('city', $_POST['city']);
         $thisuserpa->setAttribute('area', $_POST['area']);
         $address = Yii::$app->cache->get('sys_address');
         $sysaddress = $address['province'][$_POST['province']] . $address['city'][$_POST['city']] . $address['area'][$_POST['area']];
         $thisuserpa->setAttribute('sysaddress', $sysaddress);
         $resultR = $thisuserpa->save();
         $this->refresh();
         if ($resultR) {
             Yii::$app->session->setFlash('success', '更新成功');
             $this->redirect('/public/notices.html');
             Yii::$app->end();
         }
     } else {
         $model->setAttributes($thisuserpa->attributes);
         return $this->render('shippingaddress', ['model' => $model]);
     }
 }