修复一些错误
This commit is contained in:
@@ -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 {
|
||||
// 拒绝:释放账单,门店可重新发起付款
|
||||
|
||||
Reference in New Issue
Block a user