修复一些错误
This commit is contained in:
@@ -33,16 +33,14 @@ class PurchaseOrderExport implements FromCollection, WithHeadings, WithMapping,
|
||||
|
||||
/**
|
||||
* @param PurchaseOrderModel $purchase 采购单
|
||||
* @param string $type all 全品类 / category 仅蔬果分类
|
||||
*/
|
||||
public function __construct(
|
||||
private readonly PurchaseOrderModel $purchase,
|
||||
private readonly string $type = 'all',
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出行(商品聚合行,按 分类sort → 商品sort 排序;蔬果分类时按顶级分类名过滤)
|
||||
* 导出行(商品聚合行,按 分类sort → 商品sort 排序)
|
||||
*/
|
||||
public function collection(): Collection
|
||||
{
|
||||
@@ -114,13 +112,6 @@ class PurchaseOrderExport implements FromCollection, WithHeadings, WithMapping,
|
||||
$items = collect($rows);
|
||||
$this->loadLookups($items);
|
||||
|
||||
if ($this->type === 'category') {
|
||||
$items = $items->filter(function (array $row): bool {
|
||||
$rootName = $this->categoryNames[$row['product_id']] ?? '';
|
||||
return str_contains($rootName, '蔬菜') || str_contains($rootName, '水果');
|
||||
})->values();
|
||||
}
|
||||
|
||||
$sort = 1;
|
||||
return $this->items = $items->map(static function (array $row) use (&$sort): array {
|
||||
$row['sort'] = $sort++;
|
||||
|
||||
@@ -30,7 +30,10 @@ class NoticeController extends BaseMiniController
|
||||
$readBroadcastIds = NoticeModel::query()
|
||||
->where('user_id', $user->id)
|
||||
->whereNotNull('data->broadcast_from')
|
||||
->pluck('data->broadcast_from');
|
||||
->pluck('data')
|
||||
->map(static fn (?array $data) => $data['broadcast_from'] ?? null)
|
||||
->filter()
|
||||
->values();
|
||||
|
||||
$query = NoticeModel::query()->where(function ($q) use ($user, $readBroadcastIds) {
|
||||
$q->where('user_id', $user->id)
|
||||
|
||||
@@ -101,10 +101,10 @@ class StoreOrderController extends BaseController
|
||||
public function status(int $id, Request $request): JsonResponse
|
||||
{
|
||||
$data = $request->validate([
|
||||
'status' => 'required|integer|in:1,3,4,9',
|
||||
'status' => 'required|integer|in:1,9',
|
||||
], [
|
||||
'status.required' => '目标状态不能为空',
|
||||
'status.in' => '目标状态值不正确',
|
||||
'status.in' => '目标状态仅支持接单或取消订单',
|
||||
]);
|
||||
|
||||
$order = StoreOrderModel::find($id);
|
||||
@@ -136,13 +136,13 @@ class StoreOrderController extends BaseController
|
||||
$data = $request->validate([
|
||||
'ids' => 'required|array|min:1',
|
||||
'ids.*' => 'integer|exists:store_order,id',
|
||||
'status' => 'required|integer|in:1,3,4,9',
|
||||
'status' => 'required|integer|in:1,9',
|
||||
], [
|
||||
'ids.required' => '请选择要流转的订单',
|
||||
'ids.min' => '请选择要流转的订单',
|
||||
'ids.*.exists' => '订单不存在',
|
||||
'status.required' => '目标状态不能为空',
|
||||
'status.in' => '目标状态值不正确',
|
||||
'status.in' => '目标状态仅支持接单或取消订单',
|
||||
]);
|
||||
|
||||
$target = (int) $data['status'];
|
||||
@@ -196,6 +196,9 @@ class StoreOrderController extends BaseController
|
||||
/**
|
||||
* 状态流转合法路径
|
||||
*
|
||||
* 手动流转仅保留「接单」「取消订单」;后续状态由业务链路自动推进:
|
||||
* 生成采购单 → 采购中;采购单完成 → 配送中;生成账单 → 已完成
|
||||
*
|
||||
* @return int[]
|
||||
*/
|
||||
private function allowedTransitions(int $status): array
|
||||
@@ -205,11 +208,6 @@ class StoreOrderController extends BaseController
|
||||
StoreOrderModel::STATUS_SUMMARIZED,
|
||||
StoreOrderModel::STATUS_CANCELLED,
|
||||
],
|
||||
StoreOrderModel::STATUS_DELIVERING => [
|
||||
StoreOrderModel::STATUS_DISTRIBUTION,
|
||||
StoreOrderModel::STATUS_COMPLETED,
|
||||
],
|
||||
StoreOrderModel::STATUS_DISTRIBUTION => [StoreOrderModel::STATUS_COMPLETED],
|
||||
default => [],
|
||||
};
|
||||
}
|
||||
|
||||
@@ -252,19 +252,15 @@ class PurchaseOrderController extends BaseController
|
||||
* @throws
|
||||
*/
|
||||
#[GetRoute(route: '/{id}/export', authorize: 'export', where: ['id' => '[0-9]+'])]
|
||||
public function export(int $id, Request $request): Response
|
||||
public function export(int $id): Response
|
||||
{
|
||||
$purchase = PurchaseOrderModel::find($id);
|
||||
if (empty($purchase)) {
|
||||
throw new RepositoryException('采购单不存在');
|
||||
}
|
||||
$type = (string) $request->query('type', 'all');
|
||||
if (! in_array($type, ['all', 'category'], true)) {
|
||||
throw new RepositoryException('导出类型参数不正确(all 全品类 / category 蔬果分类)');
|
||||
}
|
||||
|
||||
return Excel::download(
|
||||
new PurchaseOrderExport($purchase, $type),
|
||||
new PurchaseOrderExport($purchase),
|
||||
$purchase->purchase_no . '_采购单.xlsx',
|
||||
);
|
||||
}
|
||||
|
||||
@@ -5,9 +5,11 @@ namespace App\Http\Controllers\Recon;
|
||||
use App\Exceptions\RepositoryException;
|
||||
use App\Exports\BillExport;
|
||||
use App\Models\BillModel;
|
||||
use App\Models\StoreModel;
|
||||
use App\Services\BillDetailService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use Modules\AnnoRoute\Attribute\GetRoute;
|
||||
use Modules\AnnoRoute\Attribute\PutRoute;
|
||||
@@ -119,7 +121,8 @@ class BillController extends BaseController
|
||||
}
|
||||
|
||||
/**
|
||||
* 确认收款:线下收款后手动登记付款信息,支付状态置为已支付
|
||||
* 确认收款:线下收款后手动登记付款信息,支付状态置为已支付;
|
||||
* 累加门店总采购金额(只统计商品金额)
|
||||
*/
|
||||
#[PutRoute(route: '/{id}/pay', authorize: 'pay', where: ['id' => '[0-9]+'])]
|
||||
public function pay(int $id, Request $request): JsonResponse
|
||||
@@ -132,20 +135,29 @@ class BillController extends BaseController
|
||||
'pay_remark.max' => '付款备注超过最大长度',
|
||||
]);
|
||||
|
||||
$bill = BillModel::find($id);
|
||||
if (empty($bill)) {
|
||||
throw new RepositoryException('账单不存在');
|
||||
}
|
||||
if ($bill->status === BillModel::STATUS_PAID) {
|
||||
throw new RepositoryException('账单已支付,请勿重复收款');
|
||||
}
|
||||
return DB::transaction(function () use ($id, $data, $request) {
|
||||
$bill = BillModel::query()->lockForUpdate()->find($id);
|
||||
if (empty($bill)) {
|
||||
throw new RepositoryException('账单不存在');
|
||||
}
|
||||
if ($bill->status === BillModel::STATUS_PAID) {
|
||||
throw new RepositoryException('账单已支付,请勿重复收款');
|
||||
}
|
||||
|
||||
$bill->status = BillModel::STATUS_PAID;
|
||||
$bill->paid_at = $data['paid_at'] ?? now();
|
||||
$bill->pay_remark = (string) ($data['pay_remark'] ?? '');
|
||||
$bill->paid_operator_id = (int) $request->user()->id;
|
||||
$bill->save();
|
||||
$bill->status = BillModel::STATUS_PAID;
|
||||
$bill->paid_at = $data['paid_at'] ?? now();
|
||||
$bill->pay_remark = (string) ($data['pay_remark'] ?? '');
|
||||
$bill->paid_operator_id = (int) $request->user()->id;
|
||||
$bill->save();
|
||||
|
||||
return $this->success([], '收款已登记');
|
||||
// 累加门店总采购金额(只统计商品金额,不含配送费/附加金额)
|
||||
$store = StoreModel::query()->lockForUpdate()->find($bill->store_id);
|
||||
if ($store !== null) {
|
||||
$store->total_purchase_amount = bcadd((string) $store->total_purchase_amount, (string) $bill->product_amount, 2);
|
||||
$store->save();
|
||||
}
|
||||
|
||||
return $this->success([], '收款已登记');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace App\Http\Controllers\Recon;
|
||||
use App\Exceptions\RepositoryException;
|
||||
use App\Models\BillModel;
|
||||
use App\Models\PaymentModel;
|
||||
use App\Models\StoreModel;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
@@ -112,6 +113,19 @@ class PaymentController extends BaseController
|
||||
'paid_operator_id' => $auditorId,
|
||||
'pay_remark' => $methodName . '(支付单号 ' . $payment->payment_no . ')',
|
||||
]);
|
||||
|
||||
// 按门店累加总采购金额(只统计商品金额,不含配送费/附加金额)
|
||||
foreach ($bills->groupBy('store_id')->sortKeys() as $storeId => $storeBills) {
|
||||
$amount = '0';
|
||||
foreach ($storeBills as $storeBill) {
|
||||
$amount = bcadd($amount, (string) $storeBill->product_amount, 2);
|
||||
}
|
||||
$store = StoreModel::query()->lockForUpdate()->find((int) $storeId);
|
||||
if ($store !== null) {
|
||||
$store->total_purchase_amount = bcadd((string) $store->total_purchase_amount, $amount, 2);
|
||||
$store->save();
|
||||
}
|
||||
}
|
||||
$payment->status = PaymentModel::STATUS_APPROVED;
|
||||
} else {
|
||||
// 拒绝:释放账单,门店可重新发起付款
|
||||
|
||||
@@ -40,6 +40,7 @@ class StoreModel extends Model
|
||||
'payment_cycle_days' => 'integer',
|
||||
'pending_box_num' => 'integer',
|
||||
'pending_tray_num' => 'integer',
|
||||
'total_purchase_amount' => 'decimal:2',
|
||||
'status' => 'integer',
|
||||
];
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ use Throwable;
|
||||
* 1. 锁定采购单全部有效订单,按门店分组,校验提交门店完整覆盖
|
||||
* 2. 商品金额 = 门店订单商品金额汇总(快照,生成后不可修改)
|
||||
* 3. 附加金额 = 周转筐数量×筐单价 + 托盘数量×托盘单价(单价取站点配置快照)
|
||||
* 4. 总金额 = 商品金额 + 配送费 + 附加金额;回写门店订单 bill_id 完成关联
|
||||
* 4. 总金额 = 商品金额 + 配送费 + 附加金额;回写门店订单 bill_id 完成关联,订单状态置为已完成
|
||||
*/
|
||||
readonly class BillGenerateService
|
||||
{
|
||||
@@ -111,10 +111,13 @@ readonly class BillGenerateService
|
||||
'operator_id' => $operatorId,
|
||||
]);
|
||||
|
||||
// 关联该门店在采购单中的全部订单与订单明细到账单
|
||||
// 关联该门店在采购单中的全部订单与订单明细到账单,订单转入「已完成」
|
||||
StoreOrderModel::query()
|
||||
->whereIn('id', $storeOrders->pluck('id'))
|
||||
->update(['bill_id' => $bill->id]);
|
||||
->update([
|
||||
'bill_id' => $bill->id,
|
||||
'status' => StoreOrderModel::STATUS_COMPLETED,
|
||||
]);
|
||||
StoreOrderItemModel::query()
|
||||
->whereIn('order_id', $storeOrders->pluck('id'))
|
||||
->update(['bill_id' => $bill->id]);
|
||||
|
||||
Reference in New Issue
Block a user