fix(orders): cover with colleague only for main_wallet_products
Silver and other non-main products settle locally instead of posting to Montzar. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -975,9 +975,27 @@ class SingleOrderController extends Controller
|
||||
\App\Services\Automation\AutomationEvents::fire($event, (int) $customer->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* پوشش همکار فقط برای محصولات کیف اصلی (main_wallet_products).
|
||||
* نقره/شمش/سکه و بقیه فقط محلی ثبت میشوند.
|
||||
*/
|
||||
private function shouldCoverOrderWithColleague(array $data): bool
|
||||
{
|
||||
if (! app(ConfigService::class)->usesMontzarPricing()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$productId = (int) ($data['product_id'] ?? $data['abshode_id'] ?? 0);
|
||||
if ($productId <= 0) {
|
||||
$productId = (int) (app(ConfigService::class)->mainProductId() ?? 0);
|
||||
}
|
||||
|
||||
return $productId > 0 && app(ConfigService::class)->isMainWalletProduct($productId);
|
||||
}
|
||||
|
||||
private function assertProviderOrderAccepted(array &$data): void
|
||||
{
|
||||
if (!app(ConfigService::class)->usesMontzarPricing()) {
|
||||
if (! $this->shouldCoverOrderWithColleague($data)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -991,12 +1009,13 @@ class SingleOrderController extends Controller
|
||||
/**
|
||||
* اول رکورد محلی (در انتظار همکار)، بعد ارسال به لیمان، بعد کیف.
|
||||
* اگر همکار رد کند یا کیف بترکد، همان رکورد با وضعیت ناموفق و شرح خطا میماند.
|
||||
* فقط main_wallet_products به همکار میروند.
|
||||
*/
|
||||
private function openOrderThenCoverWithProvider(array &$data): Order
|
||||
{
|
||||
$this->syncOrderProfitFields($data);
|
||||
$montzar = app(ConfigService::class)->usesMontzarPricing();
|
||||
if ($montzar) {
|
||||
$cover = $this->shouldCoverOrderWithColleague($data);
|
||||
if ($cover) {
|
||||
$this->assertNoRecentDuplicateLocalOrder($data);
|
||||
$data['sts'] = 4;
|
||||
$data['payment_sts'] = 1;
|
||||
@@ -1006,7 +1025,7 @@ class SingleOrderController extends Controller
|
||||
$order = Order::create($data);
|
||||
$data['order'] = $order;
|
||||
|
||||
if ($montzar) {
|
||||
if ($cover) {
|
||||
try {
|
||||
$this->assertProviderOrderAccepted($data);
|
||||
$this->finalizeProviderOrder($data);
|
||||
@@ -1071,7 +1090,7 @@ class SingleOrderController extends Controller
|
||||
|
||||
private function finalizeProviderOrder(array &$data): void
|
||||
{
|
||||
if (!app(ConfigService::class)->usesMontzarPricing()) {
|
||||
if (! $this->shouldCoverOrderWithColleague($data)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user