Example #1
0
 public function saveOrder()
 {
     if ($this->user) {
         $billing_id = $_GET['billing_id'];
         $recipient_id = $_GET['recipient_id'];
         $comments = $_GET['comments'];
         $the_date = date("Y-m-d H:i:s");
         if (!verify::vIsNNUll($billing_id)) {
             alert("账单ID不能为空");
         }
         if (!verify::vIsNumber($billing_id)) {
             alert("账单ID格式错误");
         }
         if (!verify::vIsNNUll($recipient_id)) {
             alert("收件人ID不能为空");
         }
         if (!verify::vIsNumber($recipient_id)) {
             alert("收件人ID格式错误");
         }
         //保存订单
         $this->CT_Api->api = "en.order.save";
         $this->CT_Api->setParams(array('user_id' => $this->user['id'], 'the_date' => $the_date, 'pay_date' => "0000-00-00 00:00:00", 'billing_id' => $billing_id, 'recipient_id' => $recipient_id, 'status' => "录入", 'comments' => $comments, 'ship_fee' => 0.0, 'logistic' => "Fedex", 'payerid' => "", 'token' => "", 'goods_qty' => $this->shopcart->getQtyScr()));
         $orderResponse = $this->CT_Api->post();
         $order = $orderResponse['response'];
         if (strtolower(substr($order['msg'], 0, 7)) != "success") {
             alert("订单提交失败:" . $order['msg']);
         } else {
             $this->shopcart->flush();
         }
         // save to paylog table (with discount already)
         $order_code = $order['order_code'];
         $the_amount = $order['the_amount'];
         $payment = payment::getInstance();
         $result = $payment->GetToken($the_amount, $order_code, $this->shopcart->getList());
         //记录操作日志
         $user_id = $this->user['id'];
         $this->CT_Api->api = 'en.ucenter.getByUID';
         $this->CT_Api->id = $user_id;
         $dataPromo = $this->CT_Api->get();
         $this->assign('dataPromo', $dataPromo['response']);
         if ($dataPromo['response']['promo'] != '') {
             $percentage = 10;
         } else {
             $percentage = 0;
         }
         $percentage10 = $percentage / 100;
         $amount_before = $the_amount;
         $ammount_percentage = $percentage10 * $amount_before;
         $new_sum = $amount_before - $ammount_percentage;
         $new_sum = round($new_sum, 2);
         $this->CT_Api->api = "en.paylog.save";
         $this->CT_Api->setParams(array('api_name' => 'SetExpressCheckout', 'order_code' => $order_code, 'the_time' => time(), 'response' => http_build_query($result), 'amount' => $new_sum, 'token' => $result['TOKEN'], 'ack' => $result['ACK'], 'ip' => getIP()));
         $this->CT_Api->post();
         if ($result['ACK'] != "Success") {
             alert("An error occurred while pay PayPal");
         }
         $url = $payment->buildPayPaiUrl($result['TOKEN']);
         //print_r($url); die();
         redirect($url);
     } else {
         redirect("/index.php?m=user&c=index&a=login&ReturnUrl=" . getRequest());
     }
 }