|
|
@@ -19,7 +19,6 @@ class WastController extends Controller
|
|
|
if (!empty($list)) {
|
|
|
foreach ($list as $item) {
|
|
|
$orderSn = $item->orderSn ?? '';
|
|
|
- $shopId = $item->shopId ?? 0;
|
|
|
$addTime = $item->addTime ?? '';
|
|
|
|
|
|
$connection = Yii::$app->db;//事务处理
|
|
|
@@ -27,25 +26,29 @@ class WastController extends Controller
|
|
|
|
|
|
try {
|
|
|
|
|
|
- $shop = ShopClass::getLockById($shopId);
|
|
|
- if (empty($shop)) {
|
|
|
- echo '没有找到店铺 ' . $shopId . ' ' . $orderSn . "\n";
|
|
|
- continue;
|
|
|
- }
|
|
|
+ $totalNum = 0;
|
|
|
$productList = StockWastageOrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
|
|
|
if (!empty($productList)) {
|
|
|
- $wast = 0;
|
|
|
foreach ($productList as $product) {
|
|
|
- $num = $product->itemNum ?? 0;
|
|
|
- $cost = $product->itemCost ?? 0;
|
|
|
- $amount = bcmul($num, $cost, 2);
|
|
|
- $wast = bcadd($amount, $wast, 2);
|
|
|
+ $itemInfo = $product->itemInfo ?? '';
|
|
|
+ if (empty($itemInfo)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ $arr = json_decode($itemInfo, true);
|
|
|
+ if (is_array($arr) == false) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ $name = $arr['itemName'] ?? '';
|
|
|
+ $cover = $arr['itemCover'] ?? '';
|
|
|
+ $product->name = $name;
|
|
|
+ $product->cover = $cover;
|
|
|
+ $product->addTime = $addTime;
|
|
|
+ $product->save();
|
|
|
+ $totalNum = bcadd($totalNum, $product->itemNum, 2);
|
|
|
}
|
|
|
- $totalWast = bcadd($wast, $shop->totalWast, 2);
|
|
|
- $shop->totalWast = $totalWast;
|
|
|
- $shop->save();
|
|
|
- //StatWastClass::replace()
|
|
|
}
|
|
|
+ $item->num = $totalNum;
|
|
|
+ $item->save();
|
|
|
|
|
|
$transaction->commit();
|
|
|
|