Ejemplo n.º 1
0
 public static function updateOrderProductStock($order_code)
 {
     if (!$order_code) {
         return false;
     }
     $stocklocks = ProductsStockLock::getList("order_code='{$order_code}'", '*', 'id ASC');
     if (!$stocklocks) {
         return false;
     }
     foreach ($stocklocks as $stocklock) {
         $product_sku = $stocklock['product_sku'];
         $product_num = $stocklock['product_num'];
         $exp_date = $stocklock['exp_date'];
         $orderpro = OrdersProducts::getOne(array("order_code" => $order_code, 'product_sku' => $product_sku), 'id, exp_date');
         $id = isset($orderpro['id']) ? (int) $orderpro['id'] : 0;
         $expdate = isset($orderpro['exp_date']) ? (int) $orderpro['exp_date'] : 0;
         if ($id && !$expdate) {
             OrdersProducts::update($id, array('product_num' => $product_num, 'exp_date' => $exp_date));
         } else {
             $data = array('order_code' => $order_code, 'product_sku' => $product_sku, 'product_num' => $product_num, 'exp_date' => $stocklock['exp_date']);
             OrdersProducts::insert($data);
         }
     }
 }
Ejemplo n.º 2
0
            $sql = " SELECT a.* FROM {$ordertable} AS a, {$orderproducttable} AS b WHERE RIGHT(a.order_code,2)='BH' AND a.order_code=b.order_code AND a.user_code='{$user_code}' ORDER BY a.id DESC";
            $order = Paging::bySQL($sql, $page, $page_size, 'a');
        } else {
            //DB::Debug();
            $ordertable = Orders::table();
            $orderproducttable = OrdersProducts::table();
            $sql = " SELECT a.* FROM {$ordertable} AS a, {$orderproducttable} AS b WHERE (RIGHT(a.order_code,2)='SK' OR LEFT(a.order_code,4)='FXAD') AND a.order_code=b.order_code AND a.user_code='{$user_code}' AND (a.order_code LIKE '%{$keyword}%' OR b.product_sku LIKE '%{$keyword}%')  GROUP BY a.order_code ORDER BY a.id DESC";
            $order = Paging::bySQL($sql, $page, $page_size, 'a');
        }
    }
}
$orders = $order['data'];
$paged = $order['page'];
foreach ($orders as $k => $order) {
    $order_code = $order['order_code'];
    $products = OrdersProducts::getUserProducts($order_code);
    $tmp = array();
    //获取各个PRODCUT STOCK
    $len = count($products);
    for ($i = 0; $i < $len; $i++) {
        if (!isset($products[$i])) {
            continue;
        }
        /*
        //合并相同 ITEM 的SKU 
        for ($j=$i+1; $j<$len; $j++){
        	if(!isset($products[$j])) continue;
        	if($products[$i]['item']===$products[$j]['item']){
        		$products[$i]['outstock'][] = array('product_num'=>$products[$j]['product_num'],'exp_date'=>$products[$j]['exp_date']);
        		unset($products[$j]);
        	}
Ejemplo n.º 3
0
 public static function outStockInsertOrderProduct($order_code, $sku, $qt)
 {
     //DB::Debug();
     $stocknum = ProductsStock::getSkuStock($sku);
     //检查库存是否充足
     if ($stocknum < $qt) {
         return false;
     }
     DB::tranBegin('outStockInsertOrderProduct');
     //事务开始
     $stock_ids = ProductsStock::getSkuOutStock($sku, $qt);
     //查询库存中的批号
     if (!$stock_ids) {
         return false;
     }
     foreach ($stock_ids as $sid => $stocks) {
         $exp_date = isset($stocks['exp_date']) ? (int) $stocks['exp_date'] : 0;
         $stock = isset($stocks['stock']) ? (int) $stocks['stock'] : 0;
         if ($stock < 1) {
             continue;
         }
         ProductsStock::reduce("id='{$sid}'", 'stock', $stock);
         //从库存和批号中减去
         OrdersProducts::insert(array('order_code' => $order_code, 'product_sku' => $sku, 'product_num' => $stock, 'exp_date' => $exp_date));
     }
     $commit_status = DB::tranEnd('outStockInsertOrderProduct');
     return $commit_status;
 }
Ejemplo n.º 4
0
 $sku = ProductsSku::getData($id);
 if (!$sku) {
     header("Location: /html/404.html?004");
     exit;
 }
 $item_code = $sku['item'];
 $item = ProductsItem::getOne(array('item' => $item_code, 'status' => 1));
 if (!$item) {
     header("Location: /html/404.html?005");
     exit;
 }
 $sku['iteminfo'] = $item;
 $sku_code = $sku['sku'];
 $pics = ProductsPic::getSkuPics($sku_code, 'path', 'sort DESC LIMIT 0,3');
 $sku['pics'] = $pics;
 $sku['order_num'] = OrdersProducts::getSkuAllNum($sku_code);
 $sku['stock'] = ProductsStock::getSkuStock($sku_code);
 $skus = ProductsSku::getItemSkus($item_code, "id,sku,sku_name");
 $skus = ProductsSku::getProductsPic($skus);
 $sku['skus'] = $skus;
 $userid = isset($_SESSION['userid']) ? (int) $_SESSION['userid'] : 0;
 $history = array();
 if ($userid) {
     $history = UsersHistory::getProductViewLog($userid, $id);
 }
 if (!$history) {
     $history = ProductsSku::getRand($item_code);
 }
 $history = ProductsSku::getProductsPic($history);
 $history = ProductsSku::getProductsItemTitle($history);
 ProductsSku::increase("id={$id}", 'view_num');
Ejemplo n.º 5
0
function orderNotify()
{
    $orders = Orders::publicPayOrderSignVerify();
    $order_code = isset($orders['order_code']) ? $orders['order_code'] : '';
    $order_id = isset($orders['id']) ? (int) $orders['id'] : 0;
    $order_status = isset($orders['order_status']) ? (int) $orders['order_status'] : 0;
    $pay_transaction_id = isset($orders['pay_transaction_id']) ? $orders['pay_transaction_id'] : '';
    $paid = isset($orders['paid']) ? $orders['paid'] : 0;
    $paymethod_code = $orders['paymethod_code'];
    if (1 == $order_status) {
        $pay_method = PaymentMethod::getOne(array('code' => $paymethod_code), 'id');
        $pay_method = isset($pay_method['id']) ? (int) $pay_method['id'] : 0;
        $sk_order_code = null;
        $order_type = substr($order_code, -2, 2);
        if ('YK' == $order_type) {
            $sk_order_code = str_replace('YK', 'SK', $order_code);
        }
        DB::tranBegin('notify');
        //事务开始
        Orders::update(array('order_code' => $order_code), array('paid' => $paid, 'order_status' => 2, 'pay_method' => $pay_method, 'pay_transaction_id' => $pay_transaction_id, 'pay_time' => time()));
        if ($sk_order_code) {
            Orders::update(array('order_code' => $sk_order_code), array('order_status' => 5));
        }
        ProductsStockLock::changeStatus($order_code, 1);
        OrdersProducts::updateOrderProductStock($order_code);
        $commit_status = DB::tranEnd('notify');
        if (!$commit_status) {
            ABase::toJson(1, 'FAIL', $orders);
        }
    }
    ABase::toJson(0, 'SUCCESS', $orders);
}
Ejemplo n.º 6
0
 public static function getOrderPrducts($order_code)
 {
     if (!$order_code) {
         return array();
     }
     //-- 处理重复ORDER SKU, 同一个SKU有不同批号时会出现重复
     $tmp = array();
     $products = OrdersProducts::getUserProducts($order_code);
     for ($i = 0; $i < count($products); $i++) {
         $products[$i]['outstock'][] = array('product_num' => $products[$i]['product_num'], 'exp_date' => $products[$i]['exp_date']);
         for ($j = $i + 1; $j < count($products); $j++) {
             if ($products[$i]['sku'] == $products[$j]['sku']) {
                 $products[$i]['outstock'][] = array('product_num' => $products[$j]['product_num'], 'exp_date' => $products[$j]['exp_date']);
                 $tmp[$j] = $j;
             }
         }
     }
     foreach ($tmp as $k => $v) {
         if (isset($products[$k])) {
             unset($products[$k]);
         }
     }
     //-- END 处理重复ORDER SKU
     ProductsSku::getProductsPic($products);
     //var_dump($products);
     return $products;
 }
Ejemplo n.º 7
0
 //事务开始
 $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) {
         break;
     }
 }
 if (!$locked) {
     DB::tranStop();
 }
 $commit_status = DB::tranEnd('pay');
 //--- end tran
 if (!$order_id || !$commit_status) {
     Templates::Assign('errormsg', "订单保存失败,[{$product_sku}] 库存不足,错误代码 PAY002");
     Templates::Display('error.html');
     exit;