public function actionSavePayments() { // Changes in payment block in order managment // Не лишняя ли это функция? $this->_prepairJson(); $orderId = $this->_request->getParam('order_id'); $payment = ProjectPayments::model()->find('order_id = :ORDER_ID', array(':ORDER_ID' => $orderId)); if (!$payment) { $payment = new ProjectPayments(); $payment->order_id = $orderId; $payment->received = 0; $payment->to_receive = 0; $payment->to_pay = 0; } $to_receive = $this->_request->getParam('to_receive', 0); if ($this->_request->getParam('project_price')) { $payment->project_price = $this->_request->getParam('project_price'); } if ($this->_request->getParam('to_receive')) { $payment->to_receive += (int) $this->_request->getParam('to_receive'); } if (!($this->_request->getParam('work_price') === null)) { $payment->work_price = $this->_request->getParam('work_price'); } if ($this->_request->getParam('to_pay')) { $paying = (int) $this->_request->getParam('to_pay'); } if ($paying > 0 && $to_receive == 0 && $payment->work_price > 0 && $paying + $payment->to_pay > $payment->work_price + $payment->payed && (int) $payment->to_pay > 0) { echo CJson::encode(['Оплата превышает лимит']); Yii::app()->end(); } $payment->to_pay += $paying; if ($payment->save()) { //(To User) $order = Zakaz::model()->findByPk($orderId); if ($payment->project_price > 0 && $order && $order->status == 1) { $order->status = 2; $order->save(false); } //(To Author) //$order = Zakaz::model()->findByPk($orderId); if ($paying > 0) { $user = User::model()->with('profile')->findByPk($order->executor); $manag = User::model()->findByPk(Yii::app()->user->id); $buh = new Payment(); $buh->approve = 0; $buh->order_id = $orderId; $buh->receive_date = date('Y-m-d H:i:s'); $buh->theme = $order->title; $buh->user = $user->email; $buh->summ = $paying; $buh->payment_type = Payment::OUTCOMING_EXECUTOR; $buh->manager = $manag->email; /*$buh->details_ya = $user->profile->yandex; $buh->details_wm = $user->profile->wmr; $buh->details_bank = $user->profile->bank_account;*/ $buh->save(); } $this->_response->setData(array('project_price' => $payment->project_price, 'to_receive' => $payment->to_receive, 'work_price' => $payment->work_price, 'to_pay' => $payment->to_pay)); } else { $this->_response->setData(array('result' => 'false')); } $this->_response->send(); }
public function processOrderPage() { $message = false; $login_ok = false; if (!Yii::app()->user->isGuest && User::model()->isCustomer()) { $login_ok = true; } if (!$login_ok && isset($_POST['Login'])) { if (Yii::app()->user->isGuest) { $model = new UserLogin(); //$this->performAjaxValidation($model); // collect user input data $model->attributes = $_POST['Login']; // validate user input and redirect to previous page if valid if ($model->validate()) { //$this->lastViset(); $login_ok = true; } else { $message = 'Incorrect login or password'; //Yii::app()->end(); } } } if (!$login_ok && isset($_POST['User'])) { $model = new User(); $attributes = $_POST['User']; //$attributes['full_name'] = $_POST['User']['first_name'].' '.$_POST['User']['last_name']; $pos = strpos($attributes['email'], '@'); $attributes['username'] = str_replace(array('@', '.'), '_', $attributes['email']); // substr( $attributes['email'], 0, $pos); $attributes['full_name'] = $_POST['User']['first_name'] . ' ' . $_POST['User']['last_name']; unset($attributes['first_name']); unset($attributes['last_name']); $p = $_POST['Profile']; $country = $p['country']; $countryCodes = $this->getCountryCodes(); $code = $countryCodes[$country]; $attributes['phone_number'] = '+' . $code . $attributes['phone_number']; Yii::import('user.controllers.RegistrationController'); if (RegistrationController::register($model, $attributes)) { $login_ok = true; $profile = new Profile(); $profile->user_id = $model->id; $profile->country = $country; $profile->save(); } else { if ($attributes['email'] != '') { $message = 'Sorry, registration faild...<br>'; foreach ($model->errors as $err => $descr) { $message .= $descr[0] . '<br>'; } } } } $model = new Zakaz(); $model->attributes = $_POST['Zakaz']; // (unixtime) if ($login_ok) { Yii::import('project.controllers.ZakazController'); if (ZakazController::createProject($model, $_POST['Project'])) { $cost = $this->calculateCost($model); $payment = new ProjectPayments(); $payment->order_id = $model->id; $payment->project_price = $cost; $payment->received = 0; $payment->to_receive = $cost; $payment->work_price = 0; $payment->payed = 0; $payment->to_pay = 0; $payment->save(); if (Campaign::getPayment2Chekout() != 0) { $user = User::model()->with('profile')->findByPk($model->user_id); $data = array('sid' => Campaign::getPayment2Chekout(), 'mode' => '2CO', 'li_0_type' => 'product', 'li_0_name' => 'order' . $model->id, 'li_0_price' => $cost, 'li_0_product_id' => $model->id, 'x_receipt_link_url' => 'http://' . $_SERVER["HTTP_HOST"] . '/project/payment/affiliatePayment', 'card_holder_name' => $user->full_name, 'country' => $user->profile->country, 'email' => $user->email, 'phone' => $user->phone_number); $this->redirectWithPost('https://2checkout.com/checkout/purchase', $data); } echo 'Ok! Cost = ' . $cost; Yii::app()->end(); } else { //echo 'Project is not valid!!<br>'; //print_r($_POST['Project']); //Yii::app()->end(); $message = 'Please complete all required fields.'; } } if (!isset($model->unixtime) or $model->unixtime == '') { $model->unixtime = time(); } Yii::app()->theme = explode('.', $_SERVER['SERVER_NAME'])[0]; $this->render('page/order', array('logged' => $login_ok, 'message' => $message, 'project' => $model, 'countryCodes' => $this->getCountryCodes())); Yii::app()->end(); }