public function actionDelete($id)
 {
     $model = Address::findOne(['id' => $id, 'user_id' => Yii::$app->user->id]);
     if ($model) {
         if (!$model->delete()) {
             return ['status' => 'fail', 'data' => ['message' => '收货地址删除失败!']];
         }
     }
     return ['status' => 'success', 'data' => []];
 }
Esempio n. 2
0
 public static function createDuplicate($addressId)
 {
     $address = Address::findOne($addressId);
     $model = new self();
     $model->consignee = $address->consignee;
     $model->cellphone = $address->cellphone;
     $model->gender = $address->gender;
     $model->school = $address->school->name;
     $model->building = $address->building->name;
     $model->room = $address->room;
     return $model;
 }
 public function actionDefault($id)
 {
     $model = Address::findOne(['id' => $id, 'user_id' => Yii::$app->user->id]);
     if (!$model) {
         throw new NotFoundHttpException('未找到收货地址!');
     }
     $model->is_default = Address::BOOL_TRUE;
     if ($model->save(false)) {
         Yii::$app->session->setFlash('success', '设置默认地址成功。');
     } else {
         Yii::$app->session->setFlash('danger', '设置默认地址失败。');
     }
     if (Yii::$app->request->referrer) {
         return $this->redirect(Yii::$app->request->referrer);
     } else {
         return $this->redirect(['index']);
     }
 }
Esempio n. 4
0
 /**
  * Finds the Address model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Address the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Address::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 public function actionAddressLoad($id)
 {
     $model = Address::findOne(['id' => $id, 'user_id' => Yii::$app->user->id]);
     if (!$model) {
         throw new NotFoundHttpException('未找到该地址!');
     }
     $output = ['consignee' => $model->consignee, 'gender' => $model->gender, 'cellphone' => $model->cellphone, 'building_id' => $model->building_id, 'room' => $model->room];
     Yii::$app->response->format = Response::FORMAT_JSON;
     return $output;
 }
Esempio n. 6
0
 public function actionAddress($id = null)
 {
     if ($id) {
         $model = Address::findOne($id);
         if ($model === null) {
             throw new NotFoundHttpException('model does not exist.');
         }
     } else {
         $model = new Address();
     }
     if ($model->load(Yii::$app->request->post())) {
         $model->user_id = Yii::$app->user->id;
         if ($model->save()) {
             return $this->redirect(['cart/checkout']);
         }
     }
     return $this->render('address', ['model' => $model]);
 }