回筐、账单完成

This commit is contained in:
liu
2026-08-14 01:19:47 +08:00
parent e35c951a59
commit bf8ac68391
39 changed files with 1392 additions and 963 deletions
+23 -1
View File
@@ -4,8 +4,10 @@ namespace App\Services;
use App\Exceptions\RepositoryException;
use App\Models\BillModel;
use App\Models\ContainerReturnModel;
use App\Models\PurchaseOrderModel;
use App\Models\StoreModel;
use App\Models\StoreOrderItemModel;
use App\Models\StoreOrderModel;
use Illuminate\Support\Facades\DB;
use Throwable;
@@ -109,10 +111,30 @@ readonly class BillGenerateService
'operator_id' => $operatorId,
]);
// 关联该门店在采购单中的全部订单到账单
// 关联该门店在采购单中的全部订单与订单明细到账单
StoreOrderModel::query()
->whereIn('id', $storeOrders->pluck('id'))
->update(['bill_id' => $bill->id]);
StoreOrderItemModel::query()
->whereIn('order_id', $storeOrders->pluck('id'))
->update(['bill_id' => $bill->id]);
// 压筐:累加门店待回筐/托盘(行锁防并发),并写入压筐记录
$store = StoreModel::query()->lockForUpdate()->find((int) $storeId);
if ($store !== null) {
$store->pending_box_num = (int) $store->pending_box_num + (int) $row['box_num'];
$store->pending_tray_num = (int) $store->pending_tray_num + (int) $row['tray_num'];
$store->save();
}
ContainerReturnModel::create([
'store_id' => (int) $storeId,
'bill_id' => $bill->id,
'type' => ContainerReturnModel::TYPE_PRESS,
'box_num' => (int) $row['box_num'],
'tray_num' => (int) $row['tray_num'],
'return_date' => $billDate,
'operator_id' => $operatorId,
]);
$bills[] = $bill;
}