本帖最后由 liusonglin 于 2020-7-28 17:01 编辑
在文件中搜索方法名替
换特别注意:不要点下面的复制代码,不要点下面的复制代码,不要点下面的复制代码,手动选择复制代码
1、app\models\store\StoreOrder.php
方法名:RegressionStock
public static function RegressionStock($order) { if ($order['status'] == -2 || $order['is_del']) return true; $combinationId = $order['combination_id']; $seckill_id = $order['seckill_id']; $bargain_id = $order['bargain_id']; $res5 = true; $cartInfo = StoreOrderCartInfo::where('cart_id','in', $order['cart_id'])->select(); foreach ($cartInfo as $cart) { //增库存减销量 if ($combinationId) $res5 = $res5 && StoreCombination::incCombinationStock($cart['cart_info']['cart_num'], $combinationId, isset($cart['cart_info']['productInfo']['attrInfo']) ? $cart['cart_info']['productInfo']['attrInfo']['unique'] : ''); else if ($seckill_id) $res5 = $res5 && StoreSeckill::incSeckillStock($cart['cart_info']['cart_num'], $seckill_id, isset($cart['cart_info']['productInfo']['attrInfo']) ? $cart['cart_info']['productInfo']['attrInfo']['unique'] : ''); else if ($bargain_id) $res5 = $res5 && StoreBargain::incBargainStock($cart['cart_info']['cart_num'], $bargain_id, isset($cart['cart_info']['productInfo']['attrInfo']) ? $cart['cart_info']['productInfo']['attrInfo']['unique'] : ''); else $res5 = $res5 && StoreProduct::incProductStock($cart['cart_info']['cart_num'], $cart['cart_info']['productInfo']['id'], isset($cart['cart_info']['productInfo']['attrInfo']) ? $cart['cart_info']['productInfo']['attrInfo']['unique'] : ''); } return $res5; }
2、app\models\store\StoreBargain.php
方法名:IncBargainStock
public static function IncBargainStock($num, $bargainId, $unique = '') { $bargain = self::where('id', $bargainId)->field(['product_id', 'stock', 'sales', 'quota'])->find(); if (!$bargain) return true; if ($bargain->sales > 0) $bargain->sales = bcsub($bargain->sales, $num, 0); if ($bargain->sales < 0) $bargain->sales = 0; $res = true; if ($unique) { $res = false !== StoreProductAttrValueModel::incProductAttrStock($bargainId, $unique, $num, 2); $sku = StoreProductAttrValue::where('product_id',$bargainId)->where('unique',$unique)->where('type',2)->value('suk'); $res = $res && StoreProductAttrValue::where('product_id',$bargain['product_id'])->where('suk',$sku)->where('type',0)->inc('stock',$num)->dec('sales',$num)->update(); } $bargain->stock = bcadd($bargain->stock, $num, 0); $bargain->quota = bcadd($bargain->quota, $num, 0); $res = $res && $bargain->save() && StoreProduct::where('id',$bargain['product_id'])->inc('stock', $num)->dec('sales', $num)->update(); return $res; }
3、app\models\store\StoreSeckill.php
方法名:incSeckillStock
public static function incSeckillStock($num = 0, $seckillId = 0, $unique = '') { $seckill = self::where('id', $seckillId)->field(['product_id', 'stock', 'sales', 'quota'])->find(); if (!$seckill) return true; if ($seckill->sales > 0) $seckill->sales = bcsub($seckill->sales, $num, 0); if ($seckill->sales < 0) $seckill->sales = 0; $res = true; if ($unique) { $res = false !== StoreProductAttrValueModel::incProductAttrStock($seckillId, $unique, $num, 1); $sku = StoreProductAttrValue::where('product_id', $seckillId)->where('unique', $unique)->where('type', 1)->value('suk'); $res = $res && StoreProductAttrValue::where('product_id', $seckill['product_id'])->where('suk', $sku)->where('type', 0)->inc('stock', $num)->dec('sales', $num)->update(); } $seckill->stock = bcadd($seckill->stock, $num, 0); $seckill->quota = bcadd($seckill->quota, $num, 0); $res = $res && $seckill->save() && StoreProduct::where('id', $seckill['product_id'])->inc('stock', $num)->dec('sales', $num)->update(); return $res; }
4、app\models\store\StoreCombination.php
方法名:incCombinationStock
public static function incCombinationStock($num, $CombinationId, $unique = '') { $combination = self::where('id', $CombinationId)->field(['product_id', 'stock', 'sales', 'quota'])->find(); if (!$combination) return true; if ($combination->sales > 0) $combination->sales = bcsub($combination->sales, $num, 0); if ($combination->sales < 0) $combination->sales = 0; $res = true; if ($unique) { $res = false !== StoreProductAttrValue::incProductAttrStock($CombinationId, $unique, $num, 3); $sku = StoreProductAttrValue::where('product_id', $CombinationId)->where('unique', $unique)->where('type', 3)->value('suk'); $res = $res && StoreProductAttrValue::where('product_id', $combination['product_id'])->where('suk', $sku)->where('type', 0)->inc('stock', $num)->dec('sales', $num)->update(); } $combination->stock = bcadd($combination->stock, $num, 0); $combination->quota = bcadd($combination->quota, $num, 0); $res = $res && $combination->save() && StoreProduct::where('id', $combination['product_id'])->inc('stock', $num)->dec('sales', $num)->update(); return $res; }