main
This commit is contained in:
+230
@@ -0,0 +1,230 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Finance;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Customer;
|
||||
use App\Models\Order;
|
||||
use App\Models\Price;
|
||||
use App\Models\TransactionsAdmin;
|
||||
use App\Models\User;
|
||||
use App\Models\Withdraw;
|
||||
use App\DB\Te\TableEngine;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Rooyesh\Wallet\interfaces\TransactionInterface;
|
||||
use Rooyesh\Wallet\interfaces\WalletInterface;
|
||||
use Rooyesh\Wallet\models\Wallet;
|
||||
|
||||
class FinanceController extends Controller
|
||||
{
|
||||
public function fall(Request $request)
|
||||
{
|
||||
$transactions_admins = TransactionsAdmin::with(['withdraw','order',"user",'customerTo','customer']);
|
||||
TableEngine::create($transactions_admins, $request)
|
||||
->initSearch(['price'])
|
||||
->select(['*'])
|
||||
->export($transactions_admins);
|
||||
return response()->json($transactions_admins);
|
||||
}
|
||||
public function index()
|
||||
{
|
||||
$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))
|
||||
->count();
|
||||
$new_customer_single = Customer::where('type',2)->whereDate('created_at','<=',now())->whereDate('created_at','>=',now()->subMonths(3))
|
||||
->count();
|
||||
$all_customer_major = Customer::where('type',1)->count();
|
||||
$all_customer_single = Customer::where('type',2)->count();
|
||||
$archive_customer_major = Customer::where('type',1)->where('is_archive',true)->count();
|
||||
$archive_customer_single = Customer::where('type',2)->where('is_archive',true)->count();
|
||||
$all_gold = Order::where('direction',2)->where('type',1)->sum('amount');// جمع طلاهایی که از مشتری خریدیم
|
||||
$all_gold_single = Order::where('direction',2)->where('type',2)->sum('amount');// جمع طلاهایی که از مشتری خریدیم
|
||||
$await_list = Order::where('direction',1)->where('sts',1)->get();
|
||||
$best_customer_major=Order::with('customer')->where('type',1)->where('sts',2)->select('customer_id',DB::raw('sum(amount) as amount'))
|
||||
->groupBy('customer_id')->limit(10)->get();
|
||||
$best_customer_single=Wallet::with('customer')->whereNull('fund_id')->where('owner_type',2)->orderBy('gold','desc')->limit(10)->get();
|
||||
|
||||
|
||||
// GT
|
||||
$GT_all_customers = Customer::where('type',2)->where('is_archive',false)->count();
|
||||
$GT_no_login_customers = Customer::where('type',2)->where('is_archive',false)->where('last_seen_at',null)->count();
|
||||
$GT_no_valid_customers = Customer::where('type',2)->where('is_archive',false)->where('is_legal',0)->count();
|
||||
$GT_no_valid_customers_data = Customer::where('type',2)->where('is_archive',false)->where('is_legal',0)->get(['id','name','mobile']);
|
||||
$GT_active_customers = Customer::where('type', 2)
|
||||
->where('is_archive', false)
|
||||
->whereIn('id', function($query) {
|
||||
$query->select('owner')
|
||||
->from('wallets');
|
||||
})->count();
|
||||
$GT_active_customers_data = Customer::where('type', 2)
|
||||
->where('is_archive', false)
|
||||
->whereIn('id', function($query) {
|
||||
$query->select('owner')
|
||||
->from('wallets');
|
||||
})->get(['id','name','mobile']);
|
||||
|
||||
$transactions_admins = TransactionsAdmin::with(['withdraw','order',"user",'customerTo','customer'])->get();
|
||||
|
||||
return view('app', compact(
|
||||
'GT_all_customers',
|
||||
'GT_no_login_customers',
|
||||
'GT_no_valid_customers',
|
||||
'GT_no_valid_customers_data',
|
||||
'GT_active_customers',
|
||||
'GT_active_customers_data',
|
||||
'transactions_admins',
|
||||
'tallaPrice',
|
||||
'new_customer_major',
|
||||
'new_customer_single',
|
||||
'all_customer_major',
|
||||
'all_customer_single',
|
||||
'archive_customer_major',
|
||||
'archive_customer_single',
|
||||
'all_gold',
|
||||
'all_gold_single',
|
||||
'await_list',
|
||||
'best_customer_major',
|
||||
'best_customer_single'
|
||||
))->with('GT_deActive_customers', $GT_all_customers - $GT_active_customers)
|
||||
->with('price', $tallaPrice->price);
|
||||
|
||||
|
||||
}
|
||||
public function startTransation(Request $request)
|
||||
{
|
||||
|
||||
$user = auth()->user();
|
||||
// riyal to tomman
|
||||
$tomman = $request->value;
|
||||
$riyal = (int)($request->value / 10);
|
||||
$riyal .= 0;
|
||||
$request->value = (int)($request->value / 10);
|
||||
|
||||
$Withdraw = Withdraw::create([
|
||||
'customer_id' => auth('customer')->id(),
|
||||
"cash" => $riyal,
|
||||
'sts' => 1,
|
||||
]);
|
||||
|
||||
$url = 'https://zify.ir/api/order/v2/create';
|
||||
|
||||
$payload = [
|
||||
"payer" => [
|
||||
"first_name" => $user->fname,
|
||||
"last_name" => $user->lname,
|
||||
"phone" => $user->mobile,
|
||||
"email" => "",
|
||||
"state" => $user->city,
|
||||
"city" => $user->province,
|
||||
"address_1" => $user->id,
|
||||
"address_2" => $user->shop_name
|
||||
],
|
||||
"products" => [
|
||||
[
|
||||
"code" => "1",
|
||||
"sellQuantity" => 1,
|
||||
"title" => "IRR",
|
||||
"amount" => $request->value,
|
||||
"unlimited" => true,
|
||||
"quantity" => $request->value,
|
||||
"description" => "charge_account"
|
||||
]
|
||||
],
|
||||
"returnUrl" => "https://api.gholaktala.ir/customer/charge_account_verify",
|
||||
"clientRefId" => "$Withdraw->id",
|
||||
"shipping_total" => 0,
|
||||
"off_total" => 0,
|
||||
"tax_total" => 0
|
||||
];
|
||||
|
||||
$response = Http::withToken(env('ZIFI_TOKEN_GHOLAKTALLA'))
|
||||
->post($url, $payload);
|
||||
if ($response->successful()) {
|
||||
$responseData = $response->json();
|
||||
|
||||
$orderCode = $responseData['data']['order'] ?? null;
|
||||
if ($orderCode) {
|
||||
$Withdraw->tracked_number = $orderCode;
|
||||
$Withdraw->save();
|
||||
return "https://zify.ir/order/accept/{$orderCode}";
|
||||
} else {
|
||||
return response()->json([
|
||||
'message' => 'Order created successfully but order code is missing',
|
||||
'data' => $responseData
|
||||
]);
|
||||
}
|
||||
} else {
|
||||
$response = $response->json();
|
||||
return response()->json([$response][0], 422);
|
||||
}
|
||||
}
|
||||
|
||||
public function verifyTransation()
|
||||
{
|
||||
|
||||
$Withdraw = Withdraw::with('customer')->where('id', $_GET['clientrefid'])->first();
|
||||
|
||||
$User = Customer::where('id', $Withdraw->customer_id)->first();
|
||||
$url = 'https://zify.ir/api/order/v2/verify';
|
||||
$payload = [
|
||||
"order" => "$Withdraw->tracked_number",
|
||||
];
|
||||
$verifyResponse = Http::withToken(env('ZIFI_TOKEN_GHOLAKTALLA'))
|
||||
->post($url, $payload);
|
||||
$decodedResponse = json_decode($verifyResponse, true);
|
||||
$verifyMessage = $decodedResponse['message'];
|
||||
// return $decodedResponse['data'];
|
||||
|
||||
if (isset($decodedResponse['data']['refid']) || $verifyMessage == []) {
|
||||
if ($Withdraw->cash == $decodedResponse['data']['amount'] * 10) {
|
||||
$Withdraw->zify_code = $Withdraw->tracked_number;//ok
|
||||
$Withdraw->tracked_number = $decodedResponse['data']['refid'];//ok
|
||||
$Withdraw->sts = 2;//ok
|
||||
$Withdraw->save();
|
||||
|
||||
$wallet_interface_fund = new WalletInterface($User->id, $User->type);
|
||||
$transaction = new TransactionInterface($wallet_interface_fund, $_inp = [
|
||||
"cash" => $decodedResponse['data']['amount'] * 10,
|
||||
'expire_at' => now(),
|
||||
'withdraw_id' => $_GET['clientrefid'],
|
||||
'active' => true
|
||||
], 3, false, true);
|
||||
|
||||
//----------sms
|
||||
// User information
|
||||
$userMobile = $Withdraw->customer->mobile; // User's mobile number
|
||||
$userName = $Withdraw->customer->name; // User's name
|
||||
$chargedAmount = $Withdraw->cash; // Charged amount
|
||||
// Company name
|
||||
$companyName = $this->Config('name_fa'); // Company name from configuration
|
||||
|
||||
// Constructing the SMS message
|
||||
$message = "کاربر $userName با شماره موبایل $userMobile حساب خود را به مقدار " . number_format($chargedAmount) . " ریال شارژ کرد. با تشکر، $companyName";
|
||||
|
||||
// Getting admin mobile numbers and sending the SMS
|
||||
User::where('active', 1)->get()->each(function($admin) use ($message) {
|
||||
$this->Send($admin->mobile, $message);
|
||||
});
|
||||
|
||||
|
||||
|
||||
return view('showTransactionReport', compact('Withdraw'));
|
||||
return redirect('https://app.gholaktala.ir/transactions');
|
||||
|
||||
}
|
||||
return "مبلغ پرداختی دستکاری شده !";
|
||||
} else {
|
||||
|
||||
$Withdraw->tracked_number;
|
||||
$Withdraw->sts = 3;//no
|
||||
$Withdraw->save();
|
||||
return view('showTransactionReport', compact('Withdraw'));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user