采购单优化

This commit is contained in:
liu
2026-08-12 17:30:46 +08:00
parent ef0d394f4f
commit d4bdabb866
3 changed files with 10 additions and 12 deletions
+1
View File
@@ -44,6 +44,7 @@ class StoreOrderModel extends Model
'tray_num', 'tray_num',
'status', 'status',
'remark', 'remark',
'purchase_id',
]; ];
protected $casts = [ protected $casts = [
+7 -10
View File
@@ -7,19 +7,14 @@ use App\Models\PurchaseOrderModel;
use App\Models\StoreOrderItemModel; use App\Models\StoreOrderItemModel;
use App\Models\StoreOrderModel; use App\Models\StoreOrderModel;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
use Throwable;
/** /**
* C1 订单汇总生成采购单 * 订单汇总生成采购单
*
* 流程(事务内):
* 1. 行锁「已接单」订单(可传 orderIds 只合并指定订单;状态条件天然排除已归集订单,幂等)
* 2. 创建采购单头(PO 单号;total_quantity / estimate_amount 取订货明细汇总)
* 3. 源订单批量回写 status = 采购中、purchase_id = 采购单ID
* 订货明细同步回写 purchase_id(采购明细直接溯源订货明细,无独立采购明细表)
*/ */
class PurchaseGenerateService readonly class PurchaseGenerateService
{ {
public function __construct(private readonly BillNumberService $billNumberService) public function __construct(private BillNumberService $billNumberService)
{ {
} }
@@ -27,6 +22,8 @@ class PurchaseGenerateService
* @param string $date 采购日期(Y-m-d * @param string $date 采购日期(Y-m-d
* @param int $operatorId 制单人(后台系统用户ID) * @param int $operatorId 制单人(后台系统用户ID)
* @param int[] $orderIds 指定合并的门店订单ID(空 = 全部已接单订单) * @param int[] $orderIds 指定合并的门店订单ID(空 = 全部已接单订单)
* @return PurchaseOrderModel
* @throws Throwable
*/ */
public function generate(string $date, int $operatorId, array $orderIds = []): PurchaseOrderModel public function generate(string $date, int $operatorId, array $orderIds = []): PurchaseOrderModel
{ {
@@ -62,7 +59,7 @@ class PurchaseGenerateService
'0' '0'
); );
$estimateAmount = $items->reduce( $estimateAmount = $items->reduce(
static fn (string $carry, $item): string => bcadd($carry, (string) $item->amount, 2), static fn (string $carry, $item): string => bcadd($carry, bcmul($item->quantity, (string) $item->cost_price, 2), 2),
'0' '0'
); );
+2 -2
View File
@@ -260,7 +260,7 @@ const PurchaseOrderPage: React.FC = () => {
render: (_, record) => record.purchase_date, render: (_, record) => record.purchase_date,
}, },
{ {
title: '预估金额', title: '预估成本',
dataIndex: 'estimate_amount', dataIndex: 'estimate_amount',
hideInForm: true, hideInForm: true,
hideInSearch: true, hideInSearch: true,
@@ -268,7 +268,7 @@ const PurchaseOrderPage: React.FC = () => {
render: (_, record) => `¥${record.estimate_amount}`, render: (_, record) => `¥${record.estimate_amount}`,
}, },
{ {
title: '实际金额', title: '实际成本',
dataIndex: 'actual_amount', dataIndex: 'actual_amount',
hideInForm: true, hideInForm: true,
hideInSearch: true, hideInSearch: true,