!33 代码优化

Merge pull request !33 from develop
This commit is contained in:
赵世界 2022-08-19 02:55:53 +00:00 committed by Gitee
commit 2f4b148d4c
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F

View File

@ -34,12 +34,16 @@ class BusinessOrdersUpdate
private function updateStock() private function updateStock()
{ {
[$goodsCode, $skuCode] = explode('_', $this->businessOrderItem['external_sku_id']); try {
$this->goodsSku = GoodsSku::query()->where('sku_code', $skuCode) [$goodsCode, $skuCode] = explode('_', $this->businessOrderItem['external_sku_id']);
->whereHas('goods', function ($query) use ($goodsCode) { $this->goodsSku = GoodsSku::query()->where('sku_code', $skuCode)
$query->where('goods_code', $goodsCode); ->whereHas('goods', function ($query) use ($goodsCode) {
}) $query->where('goods_code', $goodsCode);
->first(); })
->first();
} catch (\Exception $e) {
return false;
}
if ($this->goodsSku) { if ($this->goodsSku) {
$this->goodsSku->stock += $this->num; $this->goodsSku->stock += $this->num;
$this->goodsSku->save(); $this->goodsSku->save();