model() public static méthode

public static model ( null | string $className = __CLASS__ )
$className null | string
 public function processCheckout(Payment $payment, CHttpRequest $request)
 {
     $payler = new Payler($payment);
     $order = Order::model()->findByUrl($payler->getOrderIdFromHash($request));
     if ($order === null) {
         Yii::log(Yii::t('PaylerModule.payler', 'The order doesn\'t exist.'), CLogger::LEVEL_ERROR);
         return false;
     }
     if ($order->isPaid()) {
         Yii::log(Yii::t('PaylerModule.payler', 'The order #{n} is already payed.', $order->getPrimaryKey()), CLogger::LEVEL_ERROR);
         return false;
     }
     if ($payler->getPaymentStatus($request) === 'Charged' && $order->pay($payment)) {
         Yii::log(Yii::t('PaylerModule.payler', 'The order #{n} has been payed successfully.', $order->getPrimaryKey()), CLogger::LEVEL_INFO);
         //Yii::app()->controller->redirect(['/order/order/view', 'url' => $order->url]);
         // return true;
         return $order;
     } else {
         Yii::log(Yii::t('PaylerModule.payler', 'An error occurred when you pay the order #{n}.', $order->getPrimaryKey()), CLogger::LEVEL_ERROR);
         //Customer was made 5 (6?) mistakes, we tell him about it...
         Yii::app()->getUser()->setFlash(yupe\widgets\YFlashMessages::ERROR_MESSAGE, Yii::t('PaylerModule.payler', 'Payment Fail'));
         //...and give another chance to pay
         //Yii::app()->controller->redirect(['/order/order/view', 'url' => $order->url]);
         //return false;
         return $order;
     }
 }
Exemple #2
0
 public function actionTest()
 {
     $start = time();
     Yii::app()->cache->flush();
     Yii::app()->db->createCommand()->truncateTable(Buy::model()->tableName());
     Yii::app()->db->createCommand()->truncateTable(Sell::model()->tableName());
     Yii::app()->db->createCommand()->truncateTable(Order::model()->tableName());
     Yii::app()->db->createCommand()->truncateTable(Balance::model()->tableName());
     // Тест на 10 000 руб.
     Status::setParam('balance', 10000);
     Status::setParam('balance_btc', 0);
     $exs = Exchange::getAllByDt('btc_rur', '2013-12-16', '2014-01-06');
     $cnt = 0;
     foreach ($exs as $exchange) {
         $obj = new stdClass();
         $obj->dtm = $exchange['dt'];
         $obj->buy = $exchange['buy'];
         $obj->sell = $exchange['sell'];
         $cnt++;
         $bot = new Bot($obj);
         $bot->run();
     }
     $end = time();
     echo '<b>Elapsed time: ' . ($end - $start) / 60 . ' min.<br/>';
     echo '<b>Steps count: ' . $cnt . '<br/>';
 }
Exemple #3
0
 public function update($id)
 {
     $transaction = Yii::app()->db->beginTransaction();
     try {
         $order = Order::model()->findByAttributes(array('id' => $id));
         $order->status = 1;
         $ordercompanyproduct = OrderCompany::model()->findAllByAttributes(array('orderId' => $id));
         if ($ordercompanyproduct) {
             foreach ($ordercompanyproduct as &$value) {
                 $code = Code::model()->findByAttributes(array('ordercompanyproductId' => $value->id));
                 $code->status = 1;
                 $value->status = 1;
                 if (!$value->save() || !$code->save()) {
                     throw new Exception("Error Processing Request", 1);
                 }
             }
         }
         $order->save();
         $transaction->commit();
     } catch (Exception $e) {
         $transaction->rollback();
         Yii::log('update fail', CLogger::LEVEL_ERROR, 'updatedb');
         return array('code' => 500, 'mes' => 'update fail');
     }
     return array('code' => 200, 'mes' => 'success');
 }
Exemple #4
0
 public function createReservation($data)
 {
     $result = new Reservations();
     $result->createTime = date('Y-m-d H:i:s', time());
     foreach ($data as $k => $v) {
         $result->{$k} = $v;
     }
     $type = User::model()->findByAttributes(array('id' => $data['userId']));
     if ($data['type'] == 1 && $type == 1) {
         $orderid = Order::model()->findAllByAttributes(array('status' => 1, 'userId' => Yii::app()->user->id, 'type' => 1));
         if ($orderid) {
             $now = date('Ymd', strtotime(substr($data['startTime'], 0, 10)));
             foreach ($orderid as $list) {
                 $dp = OrderProduct::model()->find('endDate>=' . $now . ' and orderId=' . $list['id'] . ' and startDate<=' . $now);
                 if ($dp) {
                     break;
                 }
             }
             $dp->usedTimes++;
             $dp->save();
             $result->orderId = $dp['orderId'];
             $result->save();
         }
     }
     if ($result->save()) {
         $data = array('code' => 200, 'message' => 'SUCCESS');
     }
     return $data;
 }
 public function process()
 {
     $model = \Order::model();
     foreach ($this->orders as $order) {
         $model->saveItem($order);
     }
 }
 /**
  * Displays a particular model.
  * @param integer $id the ID of the model to be displayed
  */
 public function actionAdditem($item_id)
 {
     $user_id = Yii::app()->user->id;
     // find the users cart
     $user = User::model()->find(array('condition' => 'id=:user_id', 'params' => array(':user_id' => $user_id)));
     // find the users cart
     $cart = Cart::model()->find(array('condition' => 'cart_owner=:cart_owner', 'params' => array(':cart_owner' => $user_id)));
     // find the item being reffered to by item_id
     $item = Item::model()->find(array('condition' => 'id=:item_id', 'params' => array(':item_id' => $item_id)));
     if (is_null($cart)) {
         // if the cart is not found. create a cart for the user.
         $cart = new Cart();
         $cart->cart_owner = $user->id;
         $cart->save();
     }
     // check if the same order was already made & increment else, create new
     $order = Order::model()->find(array('condition' => 'item_id=:item_id AND cart_id=:cart_id AND order_by=:order_by', 'params' => array(':item_id' => $item_id, ':cart_id' => $cart->id, ':order_by' => $user->id)));
     if (is_null($order)) {
         $order = new Order();
         $order->create_time = time();
         $order->quantity = 1;
         $order->item_id = $item->id;
         $order->cart_id = $cart->id;
         $order->order_by = $user->id;
     } else {
         $order->quantity = 1 + $order->quantity;
         $order->update_time = time();
     }
     $order->save();
     // find all orders by this user.
     $orders = Order::model()->findAll('cart_id=:cart_id AND order_by=:order_by', array(':cart_id' => $cart->id, ':order_by' => $user->id));
     $return = array('success' => true, 'data' => $orders);
     echo CJavaScript::jsonEncode($return);
     Yii::app()->end();
 }
Exemple #7
0
 /**
  * Check creating new orders
  */
 public function testCreateOrder()
 {
     $microTime = microtime();
     $comment = 'test comment ' . $microTime;
     // Find any active product
     $product = StoreProduct::model()->active()->findByAttributes(array('use_configurations' => 0));
     $this->assertTrue($product instanceof StoreProduct);
     // Open product page and add to cart
     $this->open(Yii::app()->createUrl('/store/frontProduct/view', array('url' => $product->url)));
     $this->click("//input[@id='buyButton']");
     $this->open('cart');
     $this->assertTrue($this->isTextPresent($product->name));
     $this->click('css=label.radio > span');
     $this->type('id=OrderCreateForm_name', 'Tester Name');
     $this->type('id=OrderCreateForm_email', '*****@*****.**');
     $this->type('id=OrderCreateForm_phone', '0990000000');
     $this->type('id=OrderCreateForm_address', 'test address');
     $this->type('id=OrderCreateForm_comment', $comment);
     $this->clickAtAndWait('name=create');
     // Check if order successfully saved
     $order = Order::model()->findByAttributes(array('user_comment' => $comment));
     $this->assertTrue($order instanceof Order);
     // Check of ordered products
     $this->assertTrue($order->getOrderedProducts() instanceof CActiveDataProvider);
     $this->assertTrue($order->getOrderedProducts()->getTotalItemCount() > 0);
 }
 /**
  * @param Payment $payment
  * @param CHttpRequest $request
  */
 public function processCheckout(Payment $payment, CHttpRequest $request)
 {
     $settings = $payment->getPaymentSystemSettings();
     $params = ['action' => $request->getParam('action'), 'orderSumAmount' => $request->getParam('orderSumAmount'), 'orderSumCurrencyPaycash' => $request->getParam('orderSumCurrencyPaycash'), 'orderSumBankPaycash' => $request->getParam('orderSumBankPaycash'), 'shopId' => $settings['shopid'], 'invoiceId' => $request->getParam('invoiceId'), 'customerNumber' => $request->getParam('customerNumber'), 'password' => $settings['password']];
     /* @var $order Order */
     $order = Order::model()->findByPk($request->getParam('orderNumber'));
     if ($order === null) {
         $message = Yii::t('YandexMoneyModule.ymoney', 'The order doesn\'t exist.');
         Yii::log($message, CLogger::LEVEL_ERROR);
         $this->showResponse($params, $message, 200);
     }
     if ($order->isPaid()) {
         $message = Yii::t('YandexMoneyModule.ymoney', 'The order #{n} is already payed.', $order->getPrimaryKey());
         Yii::log($message, CLogger::LEVEL_ERROR);
         $this->showResponse($params, $message, 200);
     }
     if ($this->getOrderCheckSum($params) !== $request->getParam('md5')) {
         $message = Yii::t('YandexMoneyModule.ymoney', 'Wrong checksum');
         Yii::log($message, CLogger::LEVEL_ERROR);
         $this->showResponse($params, $message, 200);
     }
     if ((double) $order->getTotalPriceWithDelivery() !== (double) $params['orderSumAmount']) {
         $message = Yii::t('YandexMoneyModule.ymoney', 'Wrong payment amount');
         Yii::log($message, CLogger::LEVEL_ERROR);
         $this->showResponse($params, $message, 200);
     }
     if ($params['action'] === 'checkOrder') {
         $this->showResponse($params);
     }
     if ($params['action'] === 'paymentAviso' && $order->pay($payment)) {
         Yii::log(Yii::t('YandexMoneyModule.ymoney', 'The order #{n} has been payed successfully.', $order->getPrimaryKey()), CLogger::LEVEL_INFO);
         $this->showResponse($params);
     }
 }
Exemple #9
0
 public function run($nurser_id, $order_id)
 {
     //throw new RuntimeException($nurser_id);
     $order_model = Order::model()->findByPk($order_id);
     if (!empty($order_model->nurser_id)) {
         $id = $order_model->nurser_id;
         $nurser_model = NurseUser::model()->findByPk($id);
         $nurser_model->status = 0;
         if (!$nurser_model->update()) {
             throw new RuntimeException("数据保存失败");
         }
     }
     //确认护士,并改成护士值班状态
     $order_model->nurser_id = $nurser_id;
     $nurse_model = NurseUser::model()->findBypk($nurser_id);
     //选择后护士状态呈现已安排
     $nurse_model->status = 1;
     //throw new RuntimeException($phone);
     $order_model->order_status = 1;
     if ($order_model->update() && $nurse_model->update()) {
         $flag = 0;
         //$phone = $nurse_model->phone;
         //$message = "橙妈妈用户已下单,请您在30分钟内确认订单...";
         //SmsCode::SendMsgs($phone,$message);
     } else {
         $flag = 1;
     }
     $vars = array('nurser_id' => $nurser_id, 'order_id' => $order_id, 'flag' => $flag);
     $this->controller->success('', $vars);
 }
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate($id)
 {
     $modelOrder = Order::model()->findByPk($id);
     $model = new SparePartsOrder();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['SparePartsOrder'])) {
         $model->spare_parts_id = $_POST['SparePartsOrder']['spareParts'];
         //            $model->attributes = $_POST['SparePartsOrder'];
         var_dump($model->attributes);
         if ($model->validate()) {
             if (isset($_POST['SparePartsOrder']['spareParts'])) {
                 $arraySpareParts = $_POST['SparePartsOrder']['spareParts'];
                 foreach ($arraySpareParts as $spareParts) {
                     $model = new SparePartsOrder();
                     $model->order_id = $modelOrder->id;
                     $model->spare_parts_id = $spareParts;
                     $model->save(false);
                 }
             }
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model, 'modelOrder' => $modelOrder));
 }
 /**
  * @param Payment $payment
  * @param CHttpRequest $request
  * @return bool
  */
 public function processCheckout(Payment $payment, CHttpRequest $request)
 {
     $amount = $request->getParam('OutSum');
     $orderId = (int) $request->getParam('InvId');
     $crc = strtoupper($request->getParam('SignatureValue'));
     $order = Order::model()->findByPk($orderId);
     if (null === $order) {
         Yii::log(Yii::t('RobokassaModule.robokassa', 'Order with id = {id} not found!', ['{id}' => $orderId]), CLogger::LEVEL_ERROR, self::LOG_CATEGORY);
         return false;
     }
     if ($order->isPaid()) {
         Yii::log(Yii::t('RobokassaModule.robokassa', 'Order with id = {id} already payed!', ['{id}' => $orderId]), CLogger::LEVEL_ERROR, self::LOG_CATEGORY);
         return false;
     }
     $settings = $payment->getPaymentSystemSettings();
     $myCrc = strtoupper(md5("{$amount}:{$orderId}:" . $settings['password2']));
     if ($myCrc !== $crc) {
         Yii::log(Yii::t('RobokassaModule.robokassa', 'Error pay order with id = {id}! Bad crc!', ['{id}' => $orderId]), CLogger::LEVEL_ERROR, self::LOG_CATEGORY);
         return false;
     }
     if ($amount != Yii::app()->money->convert($order->total_price, $payment->currency_id)) {
         Yii::log(Yii::t('RobokassaModule.robokassa', 'Error pay order with id = {id}! Incorrect price!', ['{id}' => $orderId]), CLogger::LEVEL_ERROR, self::LOG_CATEGORY);
         return false;
     }
     if ($order->pay($payment)) {
         Yii::log(Yii::t('RobokassaModule.robokassa', 'Success pay order with id = {id}!', ['{id}' => $orderId]), CLogger::LEVEL_INFO, self::LOG_CATEGORY);
         return true;
     } else {
         Yii::log(Yii::t('RobokassaModule.robokassa', 'Error pay order with id = {id}! Error change status!', ['{id}' => $orderId]), CLogger::LEVEL_ERROR, self::LOG_CATEGORY);
         return false;
     }
 }
 /**
  * This method will be triggered after redirection from payment system site.
  * If payment accepted method must return Order model to make redirection to order view.
  * @param StorePaymentMethod $method
  * @return boolean|Order
  */
 public function processPaymentRequest(StorePaymentMethod $method)
 {
     $settings = $this->getSettings($method->id);
     $cr = new CDbCriteria();
     $cr->order = 'created DESC';
     $orders = Order::model()->findAllByAttributes(array('paid' => 0));
     $orders = $this->prepareOrders($orders);
     $xmlResponse = $this->requestStatuses($orders, $settings);
     foreach ($xmlResponse->{'bills-list'}->{'bill'} as $bill) {
         if ((int) $bill->attributes()->{'status'} === 60) {
             $orderId = (string) $bill->attributes()->{'status'};
             if (isset($orders[$orderId])) {
                 $order = Order::model()->findByPk($orderId);
                 if ($order) {
                     $order->paid = true;
                     $order->save(false);
                 }
             }
         }
     }
     if (Yii::app()->request->getQuery('redirect')) {
         Yii::app()->request->redirect(Yii::app()->request->getQuery('redirect'));
     }
     Yii::app()->request->redirect('/');
 }
 /**
  * This method will be triggered after redirection from payment system site.
  * If payment accepted method must return Order model to make redirection to order view.
  * @param StorePaymentMethod $method
  * @return boolean|Order
  */
 public function processPaymentRequest(StorePaymentMethod $method)
 {
     $request = Yii::app()->request;
     $settings = $this->getSettings($method->id);
     $order = Order::model()->findByAttributes(array('secret_key' => $request->getParam('Shp_orderKey')));
     if ($order->paid) {
         return false;
     }
     $mrh_pass2 = $settings['password2'];
     $shp_order_key = $order->secret_key;
     $shp_payment_id = $method->id;
     $out_sum = $request->getParam("OutSum");
     $inv_id = $request->getParam("InvId");
     $crc = strtoupper($request->getParam("SignatureValue"));
     $my_crc = strtoupper(md5("{$out_sum}:{$inv_id}:{$mrh_pass2}:Shp_orderKey={$shp_order_key}:Shp_pmId={$shp_payment_id}"));
     // Check sum
     if ($out_sum != Yii::app()->currency->convert($order->full_price, $method->currency_id)) {
         return ERROR_SUM;
     }
     // Check sign
     if ($my_crc != $crc) {
         return "bad sign {$out_sum}:{$inv_id}:Shp_orderKey={$shp_order_key}:Shp_pmId={$shp_payment_id}";
     }
     // Set order paid
     $order->paid = 1;
     $order->save();
     // Show answer for Robokassa API service
     if (isset($_REQUEST['getResult']) && $_REQUEST['getResult'] == 'true') {
         exit("OK" . $order->id);
     }
     return $order;
 }
Exemple #14
0
 /**
  * Check for orders without carrier chosen
  *
  * @return int
  */
 public function actionCheckPostponedOrders()
 {
     echo "Finding postponed orders..." . PHP_EOL;
     /** @var Order[] $orders */
     $orders = Order::model()->getPostponedOrders();
     $ordersCount = count($orders);
     Yii::log(sprintf("Found %s delayed %s" . PHP_EOL, $ordersCount, $this->pluralize('order', $ordersCount)), CLogger::LEVEL_ERROR, 'email_notification');
     foreach ($orders as $order) {
         Yii::log(sprintf("Sending notification email about postponed Order #%s to User #%s %s <%s>", $order->id, $order->creator_id, $order->creator->fullname, $order->creator->email), CLogger::LEVEL_INFO, 'email_notification');
         /** @var SwiftMailer $mailer */
         $mailer = Yii::app()->mailer;
         /** @var EmailTemplate $emailTemplateModel */
         $emailTemplateModel = EmailTemplate::model();
         $template = $emailTemplateModel->getEmailTemplateBySlug(EmailTemplate::TEMPLATE_ORDER_DELAYED);
         $replacements = [$order->creator->email => ['{{order}}' => CHtml::link('#' . $order->id, Yii::app()->createAbsoluteUrl('order/view', ['id' => $order->id]))]];
         if ($template) {
             $mailer->setSubject($template->subject)->setBody($template->body)->setTo($order->creator->email)->setDecoratorReplacements($replacements)->send();
         } else {
             Yii::log("Email template not found!", CLogger::LEVEL_ERROR, 'email_notification');
             return 1;
         }
     }
     echo "Done!" . PHP_EOL;
     return 0;
 }
Exemple #15
0
 public function actionIndex()
 {
     // total semua pemasukan
     $criteria = new CDbCriteria();
     $criteria->addBetweenCondition('TANGGAL_ORDER', date('Y-m-01', strtotime('this month')), date('Y-m-t', strtotime('this month')));
     $kredit = Order::model()->findAll($criteria);
     $total = 0;
     foreach ($kredit as $k) {
         $total += $k->TOTAL;
     }
     // menghitung total order
     $order_c = Order::model()->count();
     // menghitung total pasien
     $pelanggan_c = Pasien::model()->count();
     // get data order hari ini
     $criteria2 = new CDbCriteria();
     $criteria2->condition = 'date(TANGGAL_ORDER) = date(NOW())';
     $hariini = Order::model()->count($criteria2);
     // get barang yang tanggal expired
     $expired = Item::getExpired();
     // data obat habis
     $criteria = new CDbCriteria();
     $criteria->order = 'TANGGAL_ORDER DESC';
     $criteria->limit = '5';
     $dataProvider = new CActiveDataProvider('Pasien', array('pagination' => false, 'criteria' => $criteria));
     $this->render('index', array('total' => $total, 'order' => $order_c, 'pelanggan' => $pelanggan_c, 'hariini' => $hariini, 'expired' => $expired));
 }
Exemple #16
0
 public function run($id)
 {
     $order_info = Order::model()->findByPk($id);
     if ($order_info->delete()) {
         $this->controller->success('');
     }
 }
 /**
  * @param $id
  * @return Order
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = Order::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, Yii::t('OrderModule.order', 'Page not found!'));
     }
     return $model;
 }
 /**
  * Lazy loading of order.
  * Order ID should be passed from a parameter.
  *
  * @return type 
  */
 public function getOrder()
 {
     if ($this->_order === null) {
         $orderId = Yii::App()->request->getParam('order_id');
         $this->_order = Order::model()->findByPk($orderId);
     }
     return $this->_order;
 }
 /**
  * Get orders created today
  *
  * @return CActiveDataProvider
  */
 public function getTodayOrders()
 {
     $cr = new CDbCriteria();
     $cr->addCondition('created >= "' . date('Y-m-d 00:00:00') . '"');
     $dataProvider = Order::model()->search();
     $dataProvider->setCriteria($cr);
     return $dataProvider;
 }
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer the ID of the model to be loaded
  */
 public function loadModel($id)
 {
     $model = Order::model()->findByPk((int) $id);
     if ($model === null) {
         throw new CHttpException(404, 'Запрашиваемая страница не существует.');
     }
     return $model;
 }
Exemple #21
0
 public function loadModel($id)
 {
     $model = Order::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
 public static function callInterswitch($ref, &$json)
 {
     //$ref = $_POST['txnref'];
     $order = Order::model()->findByAttributes(array('payment_code' => $ref));
     $pay = PaymentTransaction::model()->findByAttributes(array('reference_number' => $ref));
     $url = UtilityHelper::yiiparam('interswitchGet') . '?productid=' . UtilityHelper::yiiparam('interswitchProductID') . '&transactionreference=' . $ref . '&amount=' . $order->total * 100;
     //self::sendToLog($url);
     try {
         $cURL = curl_init();
         curl_setopt($cURL, CURLOPT_URL, $url);
         curl_setopt($cURL, CURLOPT_HTTPGET, true);
         curl_setopt($cURL, CURLOPT_RETURNTRANSFER, 1);
         curl_setopt($cURL, CURLOPT_SSL_VERIFYPEER, 0);
         curl_setopt($cURL, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Accept: application/json', 'Hash: ' . hash('sha512', UtilityHelper::yiiparam('interswitchProductID') . $ref . UtilityHelper::yiiparam('MAC_key'))));
         $result = curl_exec($cURL);
         if (FALSE === $result) {
             throw new Exception(curl_error($cURL), curl_errno($cURL));
         }
         //self::sendToLog($result,"Json things!!!");
         curl_close($cURL);
     } catch (Exception $e) {
         self::sendToLog(sprintf('Curl failed with error #%d: %s', $e->getCode(), $e->getMessage()), "CURL Interswitch Error");
         return false;
     }
     $json = json_decode($result, true);
     //$pay->transaction_date = $json['TransactionDate'];
     //$pay->reference_number = $ref;
     $pay->payment_reference = $json['PaymentReference'];
     $pay->response_description = $json['ResponseDescription'];
     $pay->response_code = $json['ResponseCode'];
     $pay->approved_amount = $json['Amount'] / 100;
     //$pay->customer_name = ;
     $pay->save();
     $json['CustomerName'] = $pay->customer_name;
     $total = UtilityHelper::formatPrice($order->total);
     $siteurl = UtilityHelper::yiiparam('siteUrl');
     if (empty($order->check)) {
         $messg = "Dear {$order->firstname} {$order->lastname},<br/><br/>You have just attempted making payment for order #{$order->id} on {$order->store_url}. Find the details below.<br/><br/>Amount: {$total}<br/><br/>Response Description: {$json['ResponseDescription']}<br/><br/>Response Code: {$json['ResponseCode']}<br/><br/>Transaction Ref No: {$ref}<br/><br/>Payment Reference: {$json['PaymentReference']}<br/><br/>Transaction Date: {$json['TransactionDate']}<br/>";
         if ($json['ResponseCode'] == '09') {
         } else {
             if ($json['ResponseCode'] == '00') {
                 UtilityHelper::sendMail(UtilityHelper::yiiparam('salesEmail'), $order->email, 'Successful Payment Notification', $messg);
                 //UtilityHelper::changeOrderStatus($order->id);
                 $order->order_status_id = 2;
                 $order->check = 1;
                 $order->save();
                 UtilityHelper::subtractOrder($order->id);
             } else {
                 UtilityHelper::sendMail(UtilityHelper::yiiparam('salesEmail'), $order->email, 'Failed Payment Notification', $messg);
                 //UtilityHelper::changeOrderStatus($order->id,10);
                 $order->order_status_id = 10;
                 $order->check = 1;
                 $order->save();
             }
         }
     }
     //return $order;
 }
 public function run()
 {
     $this->controller->pageTitle = 'Book a Workspace';
     $now = date('Y-m-d', time());
     $date = Yii::app()->request->getParam('date');
     $date = $date == '' ? $now : $date;
     $proxy = new CHub();
     $result = $proxy->getHubList();
     if (Yii::app()->request->isAjaxRequest) {
         $id = Yii::app()->request->getParam('id');
         $hub = Yii::app()->request->getParam('hub');
         $date = Yii::app()->request->getParam('date');
         if ($id) {
             $date = date('Ymd', strtotime($date));
             $record = Reservations::model()->findAll('startTime =' . date('Ymd', strtotime($date)) . '100000' . ' and userId=' . Yii::app()->user->id . ' and type=1 and status=1');
             $orderid = Order::model()->findAllByAttributes(array('status' => 1, 'userId' => Yii::app()->user->id, 'type' => 1));
             if ($orderid) {
                 foreach ($orderid as $list) {
                     $order = OrderProduct::model()->find('endDate>=' . $date . ' and orderId=' . $list['id'] . ' and startDate<=' . $date);
                     if ($order) {
                         break;
                     }
                 }
                 if ($order) {
                     echo CJSON::encode(array('code' => 200, 'data' => array('num' => $order['totalTimes'] - $order['usedTimes'], 'count' => count($record))));
                 } else {
                     echo CJSON::encode(array('code' => 200, 'data' => array('num' => 0)));
                 }
             } else {
                 $code = CodeUsed::model()->findAll('userId=' . Yii::app()->user->id);
                 if ($code) {
                     foreach ($code as $list) {
                         $value = Code::model()->find('endDate>=' . $date . ' and id=' . $list['codeId'] . ' and startDate<=' . $date);
                         if ($value) {
                             break;
                         }
                     }
                     if ($value) {
                         echo CJSON::encode(array('code' => 200, 'data' => array('num' => 1, 'count' => count($record))));
                     } else {
                         echo CJSON::encode(array('code' => 200, 'data' => array('num' => 0)));
                     }
                 } else {
                     echo CJSON::encode(array('code' => 200, 'data' => array('num' => 0)));
                 }
             }
         } else {
             $proxy = new CReservation();
             $result = $proxy->getNumber($date);
             if ($result['code'] == 200) {
                 $data = array('code' => 200, 'data' => $result);
                 echo CJSON::encode($data);
             }
         }
     } else {
         $this->controller->render('workspacelist', array('data' => $result['data'], 'date' => $date));
     }
 }
 /**
  * Get orders date_create today
  *
  * @return ActiveDataProvider
  */
 public function getTodayOrders()
 {
     Yii::import('mod.cart.models.Order');
     $cr = new CDbCriteria();
     $cr->addCondition('date_create >= "' . date('Y-m-d 00:00:00') . '"');
     $dataProvider = Order::model()->search();
     $dataProvider->setCriteria($cr);
     return $dataProvider;
 }
Exemple #25
0
 /**
  * Find order by secret_key and display.
  * @throws CHttpException
  */
 public function actionView()
 {
     $secret_key = Yii::app()->request->getParam('secret_key');
     $model = Order::model()->find('secret_key=:secret_key', array(':secret_key' => $secret_key));
     if (!$model) {
         throw new CHttpException(404, Yii::t('OrdersModule.core', 'Ошибка. Заказ не найден.'));
     }
     $this->render('view', array('model' => $model));
 }
 public function run()
 {
     $criteria = new CDbCriteria();
     $dataProvider = new CActiveDataProvider('Order', ['criteria' => $criteria, 'sort' => ['defaultOrder' => 'id DESC'], 'pagination' => ['pageSize' => (int) $this->limit]]);
     $cacheTime = Yii::app()->controller->yupe->coreCacheTime;
     $model = Order::model();
     $dependency = new CDbCacheDependency('select max(modified) from ' . $model->tableName());
     $this->render('panel-stat', ['ordersCount' => $model->cache($cacheTime, $dependency)->count(), 'newOrdersCount' => $model->cache($cacheTime, $dependency)->new()->count(), 'dataProvider' => $dataProvider]);
 }
Exemple #27
0
 public static function firePixelPb($model)
 {
     $db = SafeMySQL::getInstance();
     if (!$model instanceof Order) {
         $model = Order::model()->findByPk($model);
     }
     if (!$model->order_id) {
         return false;
     }
     // NOTE: temp. If a payment bank in array - we don't need to fire pixel
     if ($model->payment && is_object($model->payment) && $model->payment->num2 && in_array($model->payment->num2, self::$_bannedBins) && in_array($model->campaign_id, self::$_bannedCampaigns)) {
         return false;
     }
     $fire = false;
     if ($model->aff_id) {
         $sql = 'SELECT * FROM `pixel_rates` WHERE `campaign_id` = ?i AND `method_id` = ?i AND `aff_id` = ?i';
         $result = $db->query($sql, $model->campaign_id, $model->payment->method_id, $model->aff_id);
         $count_rows = $result->num_rows;
     } else {
         $count_rows = 0;
     }
     if (!$model->aff_id || !$count_rows) {
         $sql = 'SELECT * FROM `pixel_rates` WHERE `campaign_id` = ?i AND `method_id` = ?i AND `aff_id` IS NULL';
         $result = $db->query($sql, $model->campaign_id, $model->payment->method_id);
         if (!$result->num_rows) {
             $fire = true;
         } else {
             $fire_result = $db->fetch($result);
             if ($fire_result['rate']) {
                 $fire = true;
             }
             if ($model->aff_id) {
                 $r = $fire_result['rate'] == 0 ? 0 : 1;
                 $sql = 'INSERT IGNORE INTO `pixel_rates` (`campaign_id`, `method_id`, `aff_id`, `rate`, `total_fired`, `total_orders`)
                                 SELECT `campaign_id`, `method_id`, ?i, `rate`, ' . $r . ', 1
                                 FROM `pixel_rates` WHERE `campaign_id` = ?i AND `method_id` = ?i AND `aff_id` IS NULL';
                 $db->query($sql, $model->aff_id, $model->campaign_id, $model->payment->method_id);
             }
         }
     } else {
         $fire_result = $db->fetch($result);
         if ($fire_result['rate'] != 0 && ($fire_result['total_orders'] == 0 || 100 * $fire_result['total_fired'] / ($fire_result['total_orders'] + 1) < $fire_result['rate'])) {
             $sql = 'UPDATE `pixel_rates` SET `total_fired` = `total_fired` + 1, `total_orders` = `total_orders` + 1 WHERE `campaign_id` = ?i AND `method_id` = ?s AND `aff_id` = ?i';
             $db->query($sql, $model->campaign_id, $model->payment->method_id, $model->aff_id);
             $fire = true;
         } else {
             $sql = 'UPDATE `pixel_rates` SET `total_orders` = `total_orders` + 1 WHERE `campaign_id` = ?i AND `method_id` = ?s AND `aff_id` = ?i';
             $db->query($sql, $model->campaign_id, $model->payment->method_id, $model->aff_id);
         }
     }
     if ($fire) {
         $sql = 'UPDATE `orders` SET `pixel_fired` = 1 WHERE `order_id` = ?i';
         $db->query($sql, $model->order_id);
         exec('/usr/bin/php-cli /home/pinnacle/public_html/lj3/nws/pixels_pb.php ' . $model->order_id . ' > /dev/null 2>&1 &');
     }
 }
 public function actionIndex()
 {
     if (Yii::app()->user->isGuest) {
         $this->redirect(array('/admin/login'));
     } else {
         // latest 10 orders
         $orders = Order::model()->findAll(new CDbCriteria(array('limit' => 10)));
         $this->render('index', array('orders' => $orders));
     }
 }
 /**
  * @param $year
  * @param $month
  * @return array
  */
 public function loadOrders($year, $month)
 {
     $month = (int) $month;
     if ($month < 10) {
         $month = '0' . $month;
     }
     $date_match = (int) $year . '-' . $month;
     $query = new CDbCriteria(array('condition' => "date_create LIKE '{$date_match}%'"));
     return Order::model()->findAll($query);
 }
 public function NotifyProcess($data, &$msg)
 {
     // Array( <- $data
     //     [appid] => wx043b7e57e5b34701
     //     [attach] => tst
     //     [bank_type] => CFT
     //     [cash_fee] => 1
     //     [fee_type] => CNY
     //     [is_subscribe] => Y
     //     [mch_id] => 1255284001
     //     [nonce_str] => m5kw5jw21ymyy97an9zzu4tn9pzr8ut2
     //     [openid] => oRqCWt8RWZA9-JoDs2TbhvKBl-kA
     //     [out_trade_no] => 125528400120150727185109
     //     [result_code] => SUCCESS
     //     [return_code] => SUCCESS
     //     [sign] => AB42A3E63459944637BF05771D86669E
     //     [time_end] => 20150727185147
     //     [total_fee] => 1
     //     [trade_type] => JSAPI
     //     [transaction_id] => 1005280712201507270489874922
     // )
     // Yii::log(print_r($data, true), CLogger::LEVEL_ERROR, 'payment.notify');
     $notfiyOutput = array();
     if (!array_key_exists("transaction_id", $data)) {
         $msg = "输入参数不正确";
         return false;
     }
     //查询订单,判断订单真实性
     if (!$this->Queryorder($data["transaction_id"], $data['trade_type'])) {
         $msg = "订单查询失败";
         return false;
     }
     //更新订单状态
     $order = new COrder();
     $result = $order->update($data['out_trade_no']);
     if ($result['code'] !== 200) {
         Yii::log('update fail', CLogger::LEVEL_ERROR, 'payment.notify');
     } else {
         $orderitem = Order::model()->findByAttributes(array('id' => $data['out_trade_no']));
         $userId = $orderitem->userId;
         $user = User::model()->findByAttributes(array('id' => $userId));
         Yii::log($data['attach'], CLogger::LEVEL_ERROR, 'payment.notify');
         if ($user->status == 0) {
             $user->status = 1;
         }
         if ($data['attach']) {
             $user->deadDate = $data['attach'];
         }
         if ($user->save()) {
             return true;
         } else {
             throw new Exception("dead Date fail", 1);
         }
     }
 }