feat(server): evaluate price alerts per product and fix gold discharge rounding
Alerts now bind to a product_id and share one evaluator; displayed gold within a rounding step discharges the full wallet. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -4,21 +4,17 @@ namespace App\Http\Controllers\Site;
|
||||
|
||||
use App\Http\Controllers\Admin\PriceController;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Mail\YourMailableClass;
|
||||
use App\Models\Cnt;
|
||||
use App\Models\Setting;
|
||||
use App\Models\ConfigStatic;
|
||||
use App\Models\Customer;
|
||||
use App\Services\MontzarService;
|
||||
use App\Services\ZaarboxPriceService;
|
||||
use App\Models\Price;
|
||||
use App\Models\PriceCandle;
|
||||
use App\Models\PriceTrigger;
|
||||
use App\Models\Product;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Morilog\Jalali\Jalalian;
|
||||
use App\Services\ConfigService;
|
||||
use App\Services\LivePriceCacheService;
|
||||
@@ -51,41 +47,7 @@ class ReportController extends Controller
|
||||
|
||||
public function updatePrise()
|
||||
{
|
||||
$config = app(ConfigService::class);
|
||||
$lastPrice = Price::latest()->first();
|
||||
|
||||
if (!$lastPrice) {
|
||||
return response()->json();
|
||||
}
|
||||
|
||||
$PriceTriggers = PriceTrigger::where("is_active", true)->get();
|
||||
foreach ($PriceTriggers as $PriceTrigger) {
|
||||
$diff = $PriceTrigger->dirction == 1
|
||||
? $config->displaySellPriceDiffRial()
|
||||
: ($PriceTrigger->dirction == 2 ? $config->displayBuyPriceDiffRial() : 0.0);
|
||||
$priseGold = $PriceTrigger->dirction == 1
|
||||
? $lastPrice->price - $diff
|
||||
: ($PriceTrigger->dirction == 2 ? $lastPrice->price + $diff : $lastPrice->price);
|
||||
|
||||
if (eval('return $priseGold ' . $PriceTrigger->price_condition . ' $PriceTrigger->target_price;')) {
|
||||
$customer = Customer::find($PriceTrigger->customer_id);
|
||||
if (!$customer) {
|
||||
continue;
|
||||
}
|
||||
$message = "قیمت طلا به " . number_format($priseGold, -1) . " در هر گرم رسید\n" .$this->Config('name_fa');
|
||||
if ($PriceTrigger->action == 'email') {
|
||||
Mail::to("$customer->email")->send(new YourMailableClass($message, '', '', '', ''));
|
||||
} elseif ($PriceTrigger->action == 'sms') {
|
||||
if (self::isSmsNotifEnabled('sms_notif_price_trigger')) {
|
||||
$this->send($customer->mobile, $message);
|
||||
}
|
||||
}
|
||||
$PriceTrigger->is_active = false;
|
||||
$PriceTrigger->triggered_at = Carbon::now();
|
||||
$PriceTrigger->save();
|
||||
}
|
||||
|
||||
}
|
||||
app(\App\Services\PriceTriggerService::class)->evaluateActive();
|
||||
|
||||
return response()->json();
|
||||
}
|
||||
@@ -164,9 +126,11 @@ class ReportController extends Controller
|
||||
$pricePayload = $payload;
|
||||
if (app()->runningInConsole()) {
|
||||
app(\App\Services\ConditionalOrderService::class)->evaluateFromLastPrice($pricePayload);
|
||||
app(\App\Services\PriceTriggerService::class)->evaluateActive($pricePayload);
|
||||
} else {
|
||||
dispatch(function () use ($pricePayload) {
|
||||
app(\App\Services\ConditionalOrderService::class)->evaluateFromLastPrice($pricePayload);
|
||||
app(\App\Services\PriceTriggerService::class)->evaluateActive($pricePayload);
|
||||
})->afterResponse();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user