findAll( // 'company_master_id=:mid AND flag_tagline_awards=1 AND flag_pay=0', // [':mid' => Yii::app()->user->masterId] // ); $mastter_id = Yii::app()->user->masterId; $works_id = Yii::app()->db->createCommand(" SELECT DISTINCT(tw.id) FROM tag_m_work tw INNER JOIN tag_m_work_nomination_relation tnom ON tnom.work_id = tw.id WHERE tw.flag_tagline_awards = 1 AND tnom.flag_pay = 0 AND tw.company_master_id = {$mastter_id} ")->queryColumn(); $criteria = new CDbCriteria(); $criteria->addInCondition("id", $works_id); $works = MWork::model()->findAll($criteria); // $works = MWork::myCalculateSum(); $calculated = MWork::calculateSum($works); $this->render('pay', compact('works', 'calculated')); } public function actionCashlessSuccess() { $user_master_id = Yii::app()->user->masterId; $calculated = MWork::myCalculateSum(); if ($calculated['itogo'] < 19000) { $this->redirect('/pay'); } $uid = Yii::app()->request->getQuery('uid'); $session = new CHttpSession; $session->open(); $udata = $_SESSION['udata'][$uid]; if (!isset($udata) || empty($udata)) { die("Страницы не существует или время ее жизни истекло"); } $order_id = $udata['order_id']; $req_options = $udata['options']; $options = [ 'common_user' => true, ]; if (!empty($req_options)) { $options = array_merge($options, $req_options); } $HelperInvoice = new HelperInvoice(); $HelperInvoice->generate($order_id, $options); $output = $this->renderPartial('cashlessPDFTemplate', $HelperInvoice->final_data, true); /* $order_id = Yii::app()->request->getQuery('order_id'); $user_master_id = Yii::app()->user->masterId; $Order = MerchantOrder::model()->findByPk($order_id); $LegalEntity = LegalEntity::model()->findByAttributes([ 'id' => $Order->legal_entity_id ]); if ($LegalEntity === null) { $LegalEntity = LegalEntity::model()->findByAttributes([ 'master_id' => (int)$Order->master_id ]); } $customer = $LegalEntity->legal_entity . ', ИНН ' . $LegalEntity->inn . ', КПП ' . $LegalEntity->kpp . ', ' . $LegalEntity->address; if ($LegalEntity->phone) { $customer .= ', тел.: ' . $LegalEntity->phone; } $Merchant_order_pdf = new MerchantOrderPDF($calculated['itogo'], $legal_entity, $inn, $kpp, $address, $Order->nomenclature, $order_id, $user_master_id, $Order->created); $output = $this->renderPartial('cashlessPDFTemplate', [ 'total' => $calculated['itogo'], 'total_string' => HelperText::mb_ucfirst(HelperText::num2str(number_format((float)$calculated['itogo'], 2, '.', ''))), 'customer' => $customer, 'nomenclature' => $Order->nomenclature, 'works_count' => $calculated['works_count'], 'nominations_count' => $calculated['nominations_count'], 'current_year' => TaglineAwards::getCurrentYear() ], true);*/ $Merchant_order_pdf = new MerchantOrderPDF($calculated['itogo'], $legal_entity, $inn, $kpp, $address, $Order->nomenclature, $order_id, $user_master_id, $Order->created); $Merchant_order_pdf->generate($output); $Merchant_order_pdf->renderPDF(); } public function actionCashless() { $user_master_id = Yii::app()->user->masterId; if (Yii::app()->user->company) { $company_name = Yii::app()->user->company->getNameFrontend(); } else { $User_awards = UserAwards::model()->findByMasterId($user_master_id); $company_name = $User_awards->company_name ?? ''; } $calculated = MWork::myCalculateSum(); if ($calculated['itogo'] < 9000 or Yii::app()->user->isGuest) { $this->redirect('/pay'); } $model = new LegalEntity; if (isset($_POST['LegalEntity'])) { $model->attributes = $_POST['LegalEntity']; $model->master_id = $user_master_id; if ($model->validate()) { if ($model->save()) { $Order = new MerchantOrder(); $Order->direction = TaglineAwards::getCurAwards()->name_merchant_direction; $Order->type = MerchantOrder::TYPE_BEZNAL; $Order->status = MerchantOrder::STATUS_NEW; $Order->master_id = $user_master_id; $Order->description = $calculated['order_details_admin']; $Order->ordered_item_id = $calculated['ordered_item_ids']; $Order->items_external = CJSON::encode($calculated['order_data_json']); $Order->sum = $calculated['itogo']; $Order->legal_entity_id = $model->id; $Order->save(); $Order->createNomenclature(); $Order->save(); $legal_entity = $model->legal_entity; MailAdmin::sendCachelessOrder($Order, Yii::app()->user->company->lastname, $company_name, $legal_entity); $uid = md5(md5(rand(0, 100000) . $Order->id . 'flowers are yellow')); $udata['order_id'] = $Order->id; if (isset($_POST['LegalEntity']['flag_awards_description_with_classnames'])) { $value = $_POST['LegalEntity']['flag_awards_description_with_classnames']; $udata['options'] = [ 'flag_awards_description_with_classnames' => $value ]; } $session = new CHttpSession; $session->open(); $_SESSION['udata'][$uid] = $udata; $this->redirect("/pay/cashless/success?uid=$uid"); } } } $this->render('cashless', array('model' => $model)); } public function actionOrder($order_id = null) { $user_master_id = Yii::app()->user->masterId; $post_sum = $_POST['sum']; if (!$order_id) { $calculated = MWork::myCalculateSum(); if ($post_sum != $calculated['itogo']) { $this->render('order', ['bad'=>'bad-sum']); Yii::app()->end(); } if ($calculated['itogo'] <= 0) { $this->render('order', ['bad'=>'empty-sum']); Yii::app()->end(); } $Order = new MerchantOrder(); $Order->direction = TaglineAwards::getCurAwards()->name_merchant_direction; $Order->type = MerchantOrder::TYPE_YANDEX; $Order->status = MerchantOrder::STATUS_NEW; $Order->master_id = $user_master_id; $Order->description = $calculated['order_details_admin']; $Order->ordered_item_id = $calculated['ordered_item_ids']; $Order->items_external = CJSON::encode($calculated['order_data_json']); $Order->sum = $calculated['itogo']; $Order->save(); $Order->createNomenclature(); $Order->save(); $this->redirect('/pay/order/' . $Order->id); } $Order = MerchantOrder::model()->findByPk($order_id); if ($Order->master_id != $user_master_id) { throw new CHttpException(301, 'Доступ закрыт'); } $company_name = Yii::app()->user->company->name; if (Yii::app()->user->company->catalog_card->name_frontend) { $company_name = Yii::app()->user->company->catalog_card->name_frontend; } // todo: удалить после тестирования if (Yii::app()->user->masterId == 6646) { $Order->sum = 1; $Order->save(); } $this->render('order', compact('company_name', 'Order')); } public function actionYandexKassaCheckOrder() { $merchant = new Merchant(Merchant::ACTION_CHECK_ORDER); $merchant->processRequest($_REQUEST); } public function actionYandexKassaAviso() { $merchant = new Merchant(Merchant::ACTION_AVISO); $merchant->processRequest($_REQUEST); } public function actionSuccess() { $this->render('success'); } public function actionFail() { $this->render('fail'); } }