修复一些错误

This commit is contained in:
liu
2026-08-14 21:28:55 +08:00
parent 398bb98356
commit 228212f8e3
20 changed files with 489 additions and 100 deletions
+26 -14
View File
@@ -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([], '收款已登记');
});
}
}