示例#1
0
 public function finishAction()
 {
     $totalprice = $this->getRequest()->getParam('totalprice');
     session_start();
     $userid = $_SESSION['userid'];
     $orderdate = time();
     $this->orders_data = array('userid' => $userid, 'totalprice' => $totalprice, 'orderdate' => $orderdate);
     $order = new Orders();
     $this->orderid = $order->insert($this->orders_data);
     //取得mycart的资料
     $mycart = new Mycart();
     $where = "userid=" . $userid;
     $res = $mycart->fetchAll($where)->toArray();
     $i = 0;
     foreach ($res as $val) {
         $this->arr[$i++] = array('orderid' => $this->orderid, 'bookid' => $val['bookid'], 'nums' => $val['nums']);
     }
     $orderitem = new Orderitem();
     for ($i = 0; $i < count($this->arr); $i++) {
         $itemid = $orderitem->insert($this->arr[$i]);
     }
     if ($itemid > 0) {
         $mycart->delete($where);
         $this->view->info = "购买成功";
         $this->view->goto = "/finish/done?orderid=" . $this->orderid . "&totalprice=" . $totalprice;
         $this->_forward("ok", "globals");
     } else {
         $this->view->info = "购买失败";
         $this->view->goto = "/cart/cart";
         $this->_forward("error", "globals");
     }
 }
示例#2
0
<?php

require 'tables.php';
$products = json_decode($_POST['products']);
$order = new Orders();
$order->uid = $_POST['uid'];
$order->amount = $_POST['amount'];
$order->status = $_POST['state'];
$order->comment = $_POST['comment'];
$order->rid = $_POST['rid'];
$oid = $order->insert();
foreach ($products as $p) {
    $orderProducts = new orderProducts();
    $orderProducts->oid = $oid;
    $orderProducts->pid = $p->pid;
    $orderProducts->numofItems = $p->numofItems;
    $orderProducts->insert();
}
示例#3
0
文件: pay.php 项目: isonz/fxptpcn
     $total = $total + $qt * $current_price;
 }
 $len = count($sku_ids);
 if ($len > 1) {
     $title = "合并| {$len} 笔订单";
 }
 $newtotal = $total * $discount;
 $address = ReceiverAddress::getData($addressid);
 unset($address['id']);
 $address['module_id'] = 3;
 //---DB::Debug();
 DB::tranBegin('pay');
 //事务开始
 $address_id = ReceiverAddress::insert($address);
 $data = array('order_code' => $order_code, 'user_code' => $user_code, 'discount' => $discount, 'amount' => $newtotal, 'receiver_address_id' => $address_id, 'create_time' => time());
 $order_id = Orders::insert($data);
 foreach ($sku_ids as $sku_id => $qt) {
     $product_sku = ProductsSku::getData($sku_id, 'sku');
     $product_sku = isset($product_sku['sku']) ? $product_sku['sku'] : '';
     $stocknum = ProductsStock::getSkuStock($product_sku);
     if (!$product_sku || $stocknum < $qt) {
         DB::rollBack();
         Templates::Assign('errormsg', "订单保存失败,[{$product_sku}] 库存不足,错误代码 PY001");
         Templates::Display('error.html');
         exit;
     }
     $data = array('order_code' => $order_code, 'product_sku' => $product_sku, 'product_num' => $qt);
     OrdersProducts::insert($data);
     Cart::clearCart($userid, $sku_id);
     $locked = ProductsStockLock::add($order_code, $product_sku, $qt);
     if (!$locked) {