PreBase.php
1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
/**
* 商品库存
* User: ziy
* Date: 14-7-22
* Time: 下午6:32
*/
class YHMCart_Hook_Orders_PreBase extends YHMCart_Hook_Abstract
{
/**
* @param array $package
*/
static function run(YHMCart_Hook_Orders $package)
{
self::AntiXSRFFilter();
$package = $package->getOrder();
self::blackList($package);
self::checkStorage($package);
}
/**
* 库存验证
* @param $package
* @throws Exception
*/
private static function checkStorage(array $package)
{
$goods_list = $package['goods_list'];
foreach ($goods_list as $g) {
$stock = YHMProduct_Models_Stock_Client::getStockBySku($g['product_sku']);
$goodsInfo = YHMProduct_Models_Goods_Client::getOneByProductSkc($g['product_skc']);
if (empty($stock) || $stock['stock_number'] < $g['buy_number']) {
$goodsName = '';
if (!empty($goodsInfo)) {
$goodsName = $goodsInfo['goods_name'];
}
$txt=$goodsName . '已售罄';
throw new Exception($txt,400);
}
if (!empty($goodsInfo)) {
$goodsName = $goodsInfo['goods_name'];
if ($goodsInfo['status'] == 0) {
$txt = '商品已无效,请联系卖家';
throw new Exception($txt, 400);
}
}
}
}
/**
* 黑名单
* @param array $package
* @throws Exception
*/
private static function blackList(array $package)
{
}
#TODO 不能购买自己的商品
private static function aa()
{
}
static function AntiXSRFFilter()
{
Q_Core_Session::start('auth_check_submit')->__unset('auth_submit_action');
}
}