默认重量

This commit is contained in:
liu
2026-09-05 14:37:22 +08:00
parent 364471a086
commit 12cbed411b
10 changed files with 205 additions and 8 deletions
@@ -12,6 +12,7 @@ use App\Models\StoreOrderItemModel;
use App\Models\StoreOrderModel;
use App\Services\BillNumberService;
use App\Services\ItemImageResolver;
use App\Services\WeightEstimator;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
@@ -72,6 +73,7 @@ class OrderController extends BaseMiniController
$totalQuantity = '0';
$totalAmount = '0';
$totalWeight = '0';
$now = now();
$rows = [];
foreach ($items as $row) {
@@ -85,8 +87,11 @@ class OrderController extends BaseMiniController
$price = CustomerLevelModel::calcLevelPrice($product->cost_price, $level->percent);
$quantity = (string) $row['quantity'];
$amount = bcmul($price, $quantity, 2);
// 参考重量 = 订货量 × 规格折算(仅作参考,实际称重以采购录入为准)
$weight = WeightEstimator::estimate((string) $product->spec, (string) $product->unit, $quantity);
$totalQuantity = bcadd($totalQuantity, $quantity, 2);
$totalAmount = bcadd($totalAmount, $amount, 2);
$totalWeight = bcadd($totalWeight, $weight, 3);
$rows[] = [
'store_id' => $store->id,
@@ -102,7 +107,7 @@ class OrderController extends BaseMiniController
'content' => (string) $product->content,
'shelf_life' => (int) $product->shelf_life,
'quantity' => $quantity,
'weight' => 0,
'weight' => $weight,
'amount' => $amount,
'cost_price' => (string) $product->cost_price,
'remark' => '',
@@ -116,7 +121,7 @@ class OrderController extends BaseMiniController
'store_id' => $store->id,
'order_date' => $now->toDateString(),
'total_quantity' => $totalQuantity,
'total_weight' => 0,
'total_weight' => $totalWeight,
'total_amount' => $totalAmount,
'status' => StoreOrderModel::STATUS_PENDING,
'remark' => $remark,
@@ -51,7 +51,7 @@ class ProductController extends BaseController
$params,
ProductModel::query()->with(['category:id,name', 'supplier:id,name'])
)
->orderBy('sort', 'desc')
->orderBy('sort')
->orderBy('id', 'desc')
->paginate($pageSize);
$data->getCollection()->makeVisible('cost_price');
@@ -22,6 +22,7 @@ use App\Services\BillGenerateService;
use App\Services\ItemImageResolver;
use App\Services\PurchaseGenerateService;
use App\Services\PurchaseItemService;
use App\Services\WeightEstimator;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
@@ -481,7 +482,10 @@ class PurchaseOrderController extends BaseController
'content' => (string) $product->content,
'shelf_life' => (int) $product->shelf_life,
'quantity' => $quantity,
'weight' => bcadd((string) ($validated['weight'] ?? 0), '0', 3),
// 未传称重时按订货量 × 规格预填参考重量
'weight' => isset($validated['weight'])
? bcadd((string) $validated['weight'], '0', 3)
: WeightEstimator::estimate((string) $product->spec, (string) $product->unit, (string) $quantity),
'amount' => bcmul($price, (string) $quantity, 2),
'cost_price' => (string) $product->cost_price,
'remark' => '',