Example #1
0
 public function actionServices()
 {
     if (!\Yii::$app->user->isGuest) {
         $services = [];
         $user = User::findOne(\Yii::$app->user->id);
         $model = false;
         if (empty($user->address)) {
             $show = "address";
             $model = new PersonalAccountAddress();
             $model->user_id = $user->id;
             if ($model->load(\Yii::$app->request->post()) && $model->save()) {
                 $show = "personalAccAdd";
                 $services = Services::find()->all();
                 $model = new PersonalAccount();
             }
         } elseif (empty($user->accs)) {
             $show = "personalAccAdd";
             $services = Services::find()->all();
             $model = new PersonalAccount();
             if (!empty($_POST['acc'])) {
                 $accs = $_POST['acc'];
                 $validate = true;
                 $accounts = [];
                 foreach ($accs as $index => $acc) {
                     if ($acc) {
                         $account[$index] = new PersonalAccount();
                         $account[$index]->value = $acc;
                         $account[$index]->service_id = $index;
                         $account[$index]->user_id = $user->id;
                         $validate = $validate && $account[$index]->validate();
                     }
                 }
                 if ($validate) {
                     foreach ($account as $_account) {
                         $_account->save();
                     }
                     $show = "personalAccShow";
                     $model = PersonalAccount::find()->where('user_id = :user_id', [':user_id' => $user->id])->all();
                 }
             }
         } else {
             $show = "personalAccShow";
             $services = PersonalAccount::find()->where('user_id = :user_id', [':user_id' => $user->id])->all();
         }
         return $this->render('services', ['model' => $model, 'services' => $services, 'show' => $show]);
     } else {
         return $this->redirect('/');
     }
 }
Example #2
0
 public function actionGetHistoryForService()
 {
     $token = $this->getToken();
     if ($token) {
         $user = User::find()->where('password_reset_token = :token', [':token' => $token])->one();
         if (!empty($user)) {
             if (!empty($_POST['bill']) && !empty($_POST['service_id'])) {
                 $service = Services::find()->where('id = :id', [':id' => $_POST['service_id']])->one();
                 if ($service) {
                     $persAcc = PersonalAccount::find()->where('value = :value', [':value' => $_POST['bill']])->one();
                     if ($persAcc) {
                         $result = ['status' => ['code' => 200, 'message' => 'ОК'], 'data' => ['tariff' => $service->tariff, 'tariff_measure' => $service->tariff_measure, 'history' => []]];
                         $history = PaymentData::find()->where('personal_acc_id = :personal_acc_id', [':personal_acc_id' => $persAcc->id])->andWhere('service_id = :service_id', [':service_id' => $_POST['service_id']])->all();
                         if ($history) {
                             foreach ($history as $index => $payment) {
                                 $result['data']['history'][$index] = ['date' => "" . $payment->kvit_date, 'dept_end' => $payment->dept_end, 'dept_begin' => $payment->dept_begin, 'enrolled' => $payment->enrolled, 'paid' => $payment->paid, 'bill' => $_POST['bill']];
                             }
                         }
                     } else {
                         $result = ['status' => ['code' => 409, 'message' => 'Лицевой счет не найден']];
                     }
                 } else {
                     $result = ['status' => ['code' => 406, 'message' => 'Услуга не найдена']];
                 }
             } else {
                 $result = ['status' => ['code' => 403, 'message' => 'Не все обязательные поля заполнены']];
             }
         } else {
             $result = ['status' => ['code' => 402, 'message' => 'Пользователь не найден']];
         }
     } else {
         $result = ['status' => ['code' => 400, 'message' => 'Значение Token не задано']];
     }
     return Json::encode($result);
 }