/**
  * Creates a new Transferorder model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Transferorder();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Beispiel #2
0
 public function actionForm()
 {
     $model = new Transferorder();
     //  $rentmodel = new Rentorder();
     if (!empty(Yii::$app->request->get('Transferorder')['from']) and !empty(Yii::$app->request->get('Transferorder')['to']) and !empty(Yii::$app->request->get('Transferorder')['car'])) {
         if ($model->load(Yii::$app->request->post())) {
             $jsondata = BaseJson::decode(Yii::$app->request->get('Transferorder')['car'], true);
             $model->car = $jsondata['car'];
             $amount = Yii::$app->db->createCommand('SELECT priceT , cent FROM auto  where id = :json')->bindValue(':json', $model->car)->queryOne();
             $converter = new CurrencyConverter();
             $rate = $converter->convert('USD', 'AZN');
             $kmsums = $model->fplaceid;
             // echo $kmsums;
             $z = 0;
             if ($kmsums > 35) {
                 $qiymet = $amount['cent'] * $rate * ($kmsums - 35) + $amount['priceT'] * $rate;
                 //   $giymet = $qiymet-($qiymet*10/100);
                 $model->amount = $qiymet;
                 // echo $kmsums.' $'.$model->amount;
                 if ($model->return == 1) {
                     $model->amount = $model->amount * 2;
                 }
                 if ($model->seat > 0) {
                     $model->amount = $model->amount + $model->seat * 4 * $rate;
                 }
                 $model->amount = intval($model->amount) . $z . $z;
             } else {
                 $model->amount = $amount['priceT'] * $rate;
                 if ($model->return == 1) {
                     $model->amount = $model->amount * 2;
                 }
                 if ($model->seat > 0) {
                     $model->amount = $model->amount + $model->seat * 4 * $rate;
                 }
                 $model->amount = intval($model->amount) . $z . $z;
             }
             echo $model->amount . '<br>';
             date_default_timezone_set('Asia/Baku');
             $model->pickuptime = strtotime(str_replace('/', '-', $model->date) . '' . $model->time);
             if ($model->return == 1) {
                 $model->rpickuptime = strtotime(str_replace('/', '-', $model->rdate) . '' . $model->rtime);
             }
             $reference = $model->id . time();
             $reference = sha1($reference);
             $model->reference = $reference;
             if ($model->validate()) {
                 if (empty($model->status)) {
                     if ($model->save()) {
                         // require Yii::app()->basePath . '/frontend/views/site/mail.php';
                         //                                    require(__DIR__ . '/../views/site/mail.php');
                         //
                         //
                         //                                 $email = \Yii::$app->mailer->compose()
                         //                                    ->setFrom('*****@*****.**')
                         //                                    ->setTo(['*****@*****.**','*****@*****.**'])
                         //                                    ->setSubject('Yeni Sifariş')
                         //                                    ->setHtmlBody($html)
                         //                                    ->send();
                         //                                $mid = 'transfer365';
                         //                                $amount = $model->amount;
                         //                                $currency = 944;
                         //                                $description = 'test';
                         //                                $referance = $model->reference;
                         //                                $language = 'az';
                         //                                $key = '123456qwerty';
                         //                                $signature = md5(strlen($mid).$mid.strlen($amount).$amount.strlen($currency).$currency.(!empty($description)?strlen($description).$description :"0").strlen($reference).$reference.strlen($language).$language.$key);
                         //                                $signature = strtoupper($signature);
                         // return $this->redirect('https://test.millikart.az:7444/gateway/payment/register?' . http_build_query(['mid' => $mid,'amount' => $amount, 'currency' => $currency, 'description' => $description, 'reference'=>$model->reference,'language'=>$language,'signature'=>$signature,'redirect'=>1]));
                         return $this->redirect(['site/confirmation', 'id' => $model->id, 'mode' => 'transfer', 'placeStart' => $model->placeStart, 'placeEnd' => $model->placeEnd, 'distance' => $model->distance, 'duration' => $model->duration]);
                     }
                 }
             } else {
                 // validation failed: $errors is an array containing error messages
                 foreach ($model->errors as $errors) {
                     var_dump($errors) . '<br>';
                 }
             }
         }
         return $this->render('form', ['model' => $model]);
     }
     return $this->redirect('site/error');
 }