merge goldali with abshode_khanegi branch

This commit is contained in:
2026-06-04 12:18:53 +03:30
parent aea3cbbc6e
commit a9815fa717
28 changed files with 1359 additions and 379 deletions
@@ -7,8 +7,11 @@ use App\Models\Cnt;
use App\Models\Customer;
use App\Models\Order;
use App\Models\Price;
use App\Models\Product;
use App\Models\TransactionsAdmin;
use App\Models\Withdraw;
use App\Services\ConfigService;
use App\Services\EtehadiePriceService;
use Carbon\Carbon;
use Hekmatinasser\Verta\Verta;
use Illuminate\Http\Request;
@@ -17,7 +20,8 @@ use Rooyesh\Wallet\models\Wallet;
class DashboardController extends Controller
{
public function dashboardMaster(){
public function dashboardMaster(Request $request)
{
$tallaPrice = Price::latest()->first();
// $talla->update_date = Verta::instance(Carbon::parse($talla->updated_at))->format('Y/n/j-H:i');
$new_customer_major = Customer::where('type',1)->whereDate('created_at','<=',now())->whereDate('created_at','>=',now()->subMonths(3))
@@ -56,6 +60,49 @@ class DashboardController extends Controller
$transactions_admins = TransactionsAdmin::with(['withdraw','order',"user",'customerTo','customer'])->get();
$startDate = $request->startDateProduct
? Carbon::parse($request->startDateProduct)->startOfDay()
: now()->subMonth()->startOfDay();
$endDate = $request->endDateProduct
? Carbon::parse($request->endDateProduct)->endOfDay()
: now()->endOfDay();
$products_report = Product::with(['limitedTransactions' => function ($query) use ($startDate, $endDate) {
$query->whereBetween('created_at', [$startDate, $endDate]);
}])
->whereHas('limitedTransactions', function ($query) use ($startDate, $endDate) {
$query->whereBetween('created_at', [$startDate, $endDate]);
})
->get();
$products_report->each(function ($product) {
$product->transaction_sum_gold_buy = $product->limitedTransactions
->where('gold', '>', 0)
->sum('gold');
$product->total_negative_gold_sell = $product->limitedTransactions
->where('gold', '<', 0)
->sum('gold');
$product->total_gold = $product->limitedTransactions->sum('gold');
});
$gramPrice = (int) ($tallaPrice->price ?? 0);
$FPrices = [];
if (app(ConfigService::class)->usesEtehadiePricing()) {
$etehadie = app(EtehadiePriceService::class)->fetchMainGramPrice();
if (($etehadie['price'] ?? 0) > 0) {
$gramPrice = (int) round($etehadie['price'] / 10);
$FPrices[] = [
'id' => 'etehadie',
'name' => 'اتحادیه',
'price' => $gramPrice,
'profit' => 0,
];
}
}
$FPrices[] = ['id' => '1', 'name' => 'افجو', 'price' => $gramPrice, 'profit' => 0];
$gatewayRow = Cnt::where('key', 'is_gateway_open')->first();
return response()->json([
'GT_all_customers'=>$GT_all_customers,
'GT_no_login_customers'=>$GT_no_login_customers,
@@ -65,7 +112,12 @@ class DashboardController extends Controller
'GT_active_customers_data'=>$GT_active_customers_data,
'GT_deActive_customers'=>$GT_all_customers-$GT_active_customers,
'GT_transactions_admins'=>$transactions_admins,
'price'=>$tallaPrice->price,
'GT_products_report' => $products_report,
'update_date' => now()->timezone('Asia/Tehran')->format('Y-m-d H:i:s'),
'pricem' => round($gramPrice * 4.331802 / 10000) * 10000,
'prices' => $FPrices,
'is_gateway_open' => $gatewayRow && (string) $gatewayRow->value === '1',
'price'=>$tallaPrice?->price ?? $gramPrice,
'new_customer_major'=>$new_customer_major,
'new_customer_single'=>$new_customer_single,
'all_customer_major'=>$all_customer_major,
@@ -80,6 +132,23 @@ class DashboardController extends Controller
]);
}
public function gateway()
{
$cnt = Cnt::where('key', 'is_gateway_open')->first();
if (!$cnt) {
$cnt = Cnt::create([
'key' => 'is_gateway_open',
'value' => '1',
]);
} else {
$cnt->value = ((string) $cnt->value === '0') ? '1' : '0';
$cnt->save();
}
return $cnt;
}
public function getBalance(Request $request)
{
$startDate = Carbon::parse($request->startDate)->startOfDay();
@@ -88,9 +157,15 @@ class DashboardController extends Controller
$response["liman"]=[];
$response["kalhor"]=[];
$excludeCustomerId = (int) app(ConfigService::class)->getInt('balance_report_exclude_customer_id', 4);
$response["pay_at_update"] = Order::whereNull('pay_at')->update(['pay_at' => DB::raw('created_at')]);
//liman
$response["liman"]["orders"] = Order::with(['transactions.product'])->where('customer_id', '!=', 4)->where('sts', 2)->whereBetween('pay_at', [$startDate, $endDate])->get();
$response["liman"]["orders"] = Order::with(['transactions.product', 'customer'])
->where('customer_id', '!=', $excludeCustomerId)
->where('sts', 2)
->whereBetween('pay_at', [$startDate, $endDate])
->get();
$response["liman"]["balance"]["gold"] = 0;
$response["liman"]["balance"]["cash"] = 0;
$response["liman"]["balance_abs"]["gold"] = 0;