StockSale.php
1.8 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
<?php
namespace addons\groupon\library\traits;
use addons\groupon\exception\Exception;
use addons\groupon\model\ActivityGoodsSkuPrice;
use addons\groupon\model\Goods;
use addons\groupon\model\GoodsSkuPrice;
use addons\groupon\model\OrderItem;
use addons\groupon\model\ScoreGoodsSkuPrice;
/**
* 库存销量
*/
trait StockSale
{
use StockWarning;
// 真实正向 减库存加销量
public function realForwardStockSale($order) {
$items = OrderItem::where('order_id', $order['id'])->select();
foreach ($items as $key => $orderItem) {
// 增加商品销量
Goods::where('id', $orderItem->goods_id)->setInc('sales', $orderItem->goods_num);
$goodsSkuPrice = GoodsSkuPrice::where('id', $orderItem->goods_sku_price_id)->find();
if ($goodsSkuPrice) {
$goodsSkuPrice->setDec('stock', $orderItem->goods_num); // 减少库存
$goodsSkuPrice->setInc('sales', $orderItem->goods_num); // 增加销量
// 库存预警检测
$this->checkStockWarning($goodsSkuPrice);
}
}
}
// 真实反向 加库存减销量(支付过的现在没有返库存,暂时没用)
public function realBackStockSale($order)
{
$items = OrderItem::where('order_id', $order['id'])->select();
foreach ($items as $key => $orderItem) {
// 返还商品销量
Goods::where('id', $orderItem->goods_id)->setDec('sales', $orderItem->goods_num);
// 返还规格库存
$goodsSkuPrice = GoodsSkuPrice::where('id', $orderItem->goods_sku_price_id)->find();
if ($goodsSkuPrice) {
$goodsSkuPrice->setInc('stock', $orderItem->goods_num);
$goodsSkuPrice->setDec('sales', $orderItem->goods_num);
}
}
}
}