Пример #1
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new OrderLog();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['OrderLog'])) {
         $model->attributes = $_POST['OrderLog'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->log_id));
         }
     }
     $this->render('create', array('model' => $model));
 }
Пример #2
0
 /**
  * 添加订单日志
  * @param $data
  */
 public function addOrderLog($data)
 {
     if (empty($data)) {
         throw new exception('数据不能为空!');
     } elseif (!$data['order_id']) {
         throw new exception('订单号不能为空!');
     } elseif (!$data['type']) {
         throw new exception('日志类型不能为空!');
     }
     $m = new OrderLog();
     $m->order_id = $data['order_id'];
     $m->admin_id = isset($data['admin_id']) ? $data['admin_id'] : 0;
     $m->admin_name = isset($data['admin_name']) ? $data['admin_name'] : '管理员';
     $m->phone = isset($data['phone']) ? $data['phone'] : '';
     $m->type = $data['type'];
     $m->msg = isset($data['msg']) ? $data['msg'] : '';
     $m->is_show = isset($data['is_show']) ? $data['is_show'] : 1;
     $m->add_time = time();
     $flag = $m->save();
     if (empty($flag)) {
         throw new exception('添加订单日志失败!', 500);
     }
     return true;
 }
Пример #3
0
 protected function afterDelete()
 {
     $orderLog = new OrderLog();
     $orderLog->op_name = 'delete';
     $orderLog->log_text = serialize($this);
     $orderLog->order_id = $this->order_id;
     $orderLog->result = 'success';
     $orderLog->save();
 }
Пример #4
0
 public static function createLog($userID, $orderID, $action, $notes = null, $amount = null)
 {
     $userID = (int) $userID;
     $orderID = (int) $orderID;
     if (!isset(self::$_actions[$action])) {
         return false;
     }
     $orderLogModel = new OrderLog();
     $orderLogModel->user_id = $userID;
     $orderLogModel->order_id = $orderID;
     $orderLogModel->action = $action;
     $orderLogModel->notes = $notes ? $notes : '';
     if ($amount) {
         $orderLogModel->amount = $amount;
     }
     $orderLogModel->save();
 }
Пример #5
0
 /**
  * 取消订单接口
  */
 public function cancelOrder($userId, $order_sn)
 {
     if (empty($userId)) {
         throw new exception('用户未登陆!', 2);
     }
     if (empty($order_sn)) {
         throw new exception('参数错误!');
     }
     $oInfo = Order::model()->findByAttributes(array('order_sn' => $order_sn));
     if (empty($oInfo)) {
         throw new exception('订单不存在!');
     } elseif ($oInfo['user_id'] != $userId) {
         throw new exception('订单错误!');
     } elseif (!in_array($oInfo['order_status'], array(0, 1))) {
         throw new exception('订单状态错误!');
     }
     //更新订单状态
     $oInfo->order_status = 9;
     $oInfo->update_time = time();
     $flag = $oInfo->save();
     if (empty($flag)) {
         throw new exception('订单保存错误!', 500);
     }
     //库存恢复
     $this->dealWithCancelOrderProductStock($oInfo['id']);
     //添加订单日志
     $m = new OrderLog();
     $m->order_id = $oInfo->id;
     $m->admin_id = '管理员';
     $m->admin_name = '管理员';
     $m->phone = '';
     $m->type = 'UserCanced';
     $m->msg = '您的订单已取消!';
     $m->is_show = 1;
     $m->add_time = time();
     $flag = $m->save();
     if (empty($flag)) {
         throw new exception('订单取消失败!', 500);
     }
     return false;
 }
Пример #6
0
 public function attachedOrder($order, $campaign_id, $isPayment = false)
 {
     $this->wsType = 'a1';
     $this->intervalCheck = false;
     $this->isPayment = $isPayment;
     $this->newCustomer = false;
     $this->order = $order;
     $this->campaign = Campaign::model()->fillFromDbPk($campaign_id);
     if (!$this->campaign) {
         return false;
     }
     // creating child / parent link in the DB
     $parent_id = $this->order->order_id;
     // clear the model and update
     $this->order->getCopyModel();
     $this->order->parent_id = $parent_id;
     $this->order->status = 'new';
     $this->order->created = $this->order->updated = 'NOW():sql';
     //date("Y-m-d H:i:s");
     $this->order->campaign_id = $this->campaign->campaign_id;
     $this->order->click_id = NULL;
     // check for parent test order
     if ($this->order->isFlag('test')) {
         $this->test = true;
     }
     $this->order->removeFlags();
     if ($this->isPayment) {
         $this->order->addFlags('pay');
     } else {
         $this->order->flags = '';
     }
     // set test
     if ($this->test) {
         $this->order->addFlags('test');
     }
     $this->order->ship_with = NULL;
     // set default values.  will be updated further down the script
     $this->order->amount_product = '0';
     $this->order->amount_shipping = '0';
     $this->order->payment_total = '0';
     $this->order->amount_refunded = '0';
     $this->order->pixel_fired = '0';
     $this->order->shipping_id = 19;
     // Free Shipping
     $this->order->billing_cycle = 0;
     // check for test cc
     //if (stripos($this->order->payment->method->method_ref,'cc_') !== false && $this->order->payment->cc_number == Config::get()->payments->pacnet['testCC']) {
     if (isset($this->order->payment) && stripos($this->order->payment->method->method_ref, 'cc_') !== false && ($this->order->payment->num4 == strlen(Config::get()->payments->pacnet['testCC']) && $this->order->payment->num2 == substr(Config::get()->payments->pacnet['testCC'], 0, 6) && $this->order->payment->num3 == substr(Config::get()->payments->pacnet['testCC'], strlen(Config::get()->payments->pacnet['testCC']) - 4, 4))) {
         $this->order->addFlags('test');
         $this->test = true;
     }
     // Check to see if a gateway assigned to the attached campaign has the same PRN info as the gateway used in the main order.  if so, use it
     $gid = @ProfileGateways::getAttachedGatewayByPrn($parent_id, $campaign_id);
     // if not, Grab Current gateway.  will be checked again before payment is submitted.
     if (!$gid) {
         // ignore payment system type for this
         // RENABLE THIS FOR ATTACH ORDERS?  QUESTION.
         $gid = @ProfileGateways::getCurrentGatewayByIds($this->campaign->profile_id, $this->order->payment->method_id);
         if (!$gid) {
             $gid = 0;
         }
         // set to 0.  the batch job that bills the orders can deal with this
     }
     // if we have a new gateway, use it.  if not keep the old one from the parent order
     if ($gid) {
         $this->order->gateway_id = $gid;
     }
     unset($gid);
     // save order
     if (!$this->order->save(true, null, false)) {
         fb($this->order->getErrors());
         //$this->apiError('attached order error - ' . $this->order->geterrors2string());
         return false;
     }
     //Save order logs
     $orderLogModel = new OrderLog();
     $orderLogModel->order_id = $parent_id;
     $orderLogModel->user_id = 0;
     $orderLogModel->action = 26;
     $orderLogModel->notes = $this->order->order_id;
     $orderLogModel->save();
     // load products for the attach campaign
     $campProducts = new CampaignProducts('CampaignProduct');
     $campProducts->load($this->campaign->campaign_id);
     $pArray = array();
     foreach ($campProducts->products as $p) {
         $pArray[] = $p->product_id;
     }
     $this->post = array();
     $this->post['product_id'] = implode(',', $pArray);
     unset($campProducts);
     $this->buildProducts();
     $amount = $this->amount_product;
     // set shipping info
     // I'm assuming that since this is an attach campaign there's only one shipping option
     $campShip = new CampaignShippings('CampaignShipping');
     $campShip->load($this->campaign->campaign_id);
     $this->order->shipping_id = $campShip->shipping[0]->shipping_id;
     $this->order->amount_shipping = $campShip->selectedShipping($this->order->shipping_id)->amount_initial;
     // catch for missing shipping id
     if (!$this->order->shipping_id) {
         $this->order->shipping_id = 19;
         $this->order->amount_shipping = '0.00';
     }
     unset($campShip);
     // set total
     $this->order->amount_product = $amount ? $amount : '0.00';
     $this->order->status = 'new';
     $total = $this->order->amount_product + $this->order->amount_shipping;
     // check to make sure there is an amount > 0 for this order,
     // if not: 1. don't bill 2. Remove flags 3.  set ok status
     if (!$total) {
         $this->isPayment = false;
         $this->order->status = 'ok';
         $this->order->removeFlags('pay');
         $this->order->addFlags('paid');
         Event::setEvents($this->order->order_id, 8, false);
     } else {
         if ($total && !isset($this->order->payment->payment_id)) {
             $isPayment = false;
         }
     }
     // save
     if (!$this->order->save(true, null, false)) {
         fb($this->order->getErrors());
         //$this->apiError('attached error - ' . $this->order->geterrors2string());
         return false;
     }
     // process payment
     if ($this->isPayment) {
         $paymentAPI = new PaymentAPI();
         $paymentAPI->setModel($this->order->payment);
         // !$this->order->isFlag('test') && $this->order->payment->cc_number != Config::get()->payments->pacnet['testCC']
         if (!$this->test) {
             $paymentResponse = $paymentAPI->payOrder($this->order->order_id, $total);
             //fb($paymentAPI);
             //fb($paymentResponse);
         }
         // what happened?
         if ($this->test || $paymentResponse->getstatus() != 'error') {
             // ACCEPTED
             $this->order->status = 'ok';
             if (@stripos($this->order->payment->method->method_ref, 'cc_') !== false) {
                 // APPROVED / PAID
                 // was the payment actually processed, like a cc_debit?  set order total
                 $this->order->removeFlags('pay');
                 $this->order->addFlags('paid');
                 $this->order->payment_total = $total;
             } else {
                 //fb('NOT ACTUALLY PROCESSED');
                 // was the payment accepted by the gateway, but not actually processed?
                 //$this->order->addFlags('paid');
             }
             $this->order->updated = 'NOW():sql';
             //date("Y-m-d H:i:s");
             if (!$this->order->save(true, null, false)) {
                 //this should never happen.  just log the error, email the team and assume its all good for the customer
                 fb($this->order->getErrors());
             }
             Event::setEvents($this->order->order_id, 8, false);
             // NEED TO UPDATE THE GATEWAY LIMITS AND STATUS.  WOULD BE BENEFICIAL IS THIS WERE SOMEHOW AN ASYNCHRONOUS FUNCTION CALL
             //if(!$this->order->isFlag('test')) {
             //$pg = new ProfileGateways('ProfileGateway');
             //$o = clone $this->order;
             //$pg->processGatewayRoutingByOrder($o);
             //unset($o);
             //}
         } else {
             // DECLINED
             $this->order->status = 'error';
             $this->order->updated = 'NOW():sql';
             //date("Y-m-d H:i:s");
             if (!$this->order->save(true, null, false)) {
                 //this should never happen.  log the error, email the team and send the user back to the payment details page
                 fb($this->order->getErrors());
             }
             return false;
         }
     } elseif ($total) {
         // isPayment is false, but there is an amount that needs to be billed.  set up order for cron payment
         //$this->order->status = 'ok';
         $this->order->addFlags('pay');
         if (!$this->order->save(true, null, false)) {
             //this should never happen.  just log the error, email the team and assume its all good for the customer
             fb($this->order->getErrors());
         }
     }
     return $this->order->order_id;
 }
Пример #7
0
 function logsAction()
 {
     if (isset($_POST['model']) && $_POST['model'] == 'orderlogs') {
         $orderID = AF::get($_POST, 'order_id');
         if (!$orderID) {
             Message::echoJsonError(__('emply_order_id'));
         }
         $notes = AF::get($_POST, 'notes');
         if (!$notes) {
             Message::echoJsonError(__('emply_notes'));
         }
         $modelOrderLog = new OrderLog();
         $modelOrderLog->order_id = $orderID;
         $modelOrderLog->user_id = $this->user->user_id;
         $modelOrderLog->action = 15;
         $modelOrderLog->notes = $notes;
         if ($modelOrderLog->save()) {
             Message::echoJsonSuccess();
         } else {
             Message::echoJsonError(__('orderlogs_not_created'));
         }
         die;
     }
     $orderID = AF::get($this->params, 'order_id');
     $clearArray = array('action');
     $this->filter($clearArray);
     $pagination = new Pagination(array('action' => $this->action, 'controller' => $this->controller, 'params' => $this->params));
     $models = AFActiveDataProvider::models('OrderLog', $this->params, $pagination);
     $dataProvider = $models->getAll();
     $FilterFields = $models->getoutFilterFields(array('action'));
     $this->addToPageTitle(__('order_logs'));
     Assets::css('jquery-ui');
     Assets::js('//code.jquery.com/ui/1.10.3/jquery-ui.js');
     Assets::js('dateRange/jquery.daterange');
     Assets::js('jquery.form');
     $this->render('logs', array('dataProvider' => $dataProvider, 'pagination' => $pagination, 'orderID' => $orderID, 'FilterFields' => $FilterFields));
 }