Warenwirtschaft: SalesController::store() gehärtet (Validierung, Transaktion, Lock)
Vorbereitung AP-13: Versand-Statuswechsel validiert Eingaben (Status aus shippedTypes, Action-Whitelist), läuft in DB::transaction mit lockForUpdate gegen Doppelklick/parallele Tabs. Verhalten sonst unverändert. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
parent
46da71ff18
commit
6b8fcadcbf
2 changed files with 160 additions and 13 deletions
|
|
@ -10,6 +10,8 @@ use App\Services\CustomerPriority;
|
|||
use App\Services\Invoice;
|
||||
use App\Services\Payment;
|
||||
use App\Services\PaymentService;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Request;
|
||||
|
||||
class SalesController extends Controller
|
||||
|
|
@ -417,10 +419,19 @@ class SalesController extends Controller
|
|||
if (! isset($data['id'])) {
|
||||
abort(404);
|
||||
}
|
||||
if (isset($data['action'])) {
|
||||
if ($data['action'] === 'store_shipped' && isset($data['shipped'])) {
|
||||
$shopping_order = ShoppingOrder::findOrFail($data['id']);
|
||||
$shopping_order->shipped = $data['shipped'];
|
||||
Request::validate([
|
||||
'id' => ['required', 'integer', 'exists:shopping_orders,id'],
|
||||
'action' => ['required', Rule::in(['store_shipped', 'store_txaction'])],
|
||||
'shipped' => ['required_if:action,store_shipped', 'integer', Rule::in(array_keys(ShoppingOrder::$shippedTypes))],
|
||||
'txaction' => ['required_if:action,store_txaction', 'string', 'max:20'],
|
||||
'payment_id' => ['required_if:action,store_txaction', 'integer'],
|
||||
]);
|
||||
|
||||
if ($data['action'] === 'store_shipped') {
|
||||
// Statuswechsel + Margin-/Provisionsfolgen atomar; Lock gegen Doppelklick/zweiten Tab
|
||||
DB::transaction(function () use ($data) {
|
||||
$shopping_order = ShoppingOrder::query()->lockForUpdate()->findOrFail($data['id']);
|
||||
$shopping_order->shipped = (int) $data['shipped'];
|
||||
$shopping_order->save();
|
||||
// handel Promotion Product and credit by storno
|
||||
Payment::handelUserPromotionOrder($shopping_order);
|
||||
|
|
@ -474,16 +485,15 @@ class SalesController extends Controller
|
|||
$shopping_order->shopping_order_margin->save();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* txaction ändern
|
||||
änderung der txaction von der Bestellung, Status Zahlung, offen, bezahlt, keine zahlung */
|
||||
if ($data['action'] === 'store_txaction' && isset($data['txaction']) && isset($data['payment_id'])) {
|
||||
PaymentService::updateTransactionStatus($data['id'], $data['txaction'], $data['payment_id']);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
/* txaction ändern
|
||||
änderung der txaction von der Bestellung, Status Zahlung, offen, bezahlt, keine zahlung */
|
||||
if ($data['action'] === 'store_txaction') {
|
||||
PaymentService::updateTransactionStatus($data['id'], $data['txaction'], $data['payment_id']);
|
||||
}
|
||||
|
||||
if (isset($data['back'])) {
|
||||
return redirect($data['back']);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue