main
This commit is contained in:
+34
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Controllers\SuperController;
|
||||
use App\Models\BankAccount;
|
||||
use App\Models\Customer;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class BankAccountController extends SuperController
|
||||
{
|
||||
public function __construct()
|
||||
|
||||
{
|
||||
$name_model = 'user';
|
||||
$search=["cart_number","customer.name"];
|
||||
parent::__construct(BankAccount::class, ['customer'], ['*',BankAccount::$SELECT_STS_STR],$name_model,null,$search);
|
||||
}
|
||||
|
||||
public function changeSts(Request $request){
|
||||
$data = $request->all();
|
||||
$accoun = BankAccount::findOrFail($data['id']);
|
||||
$accoun->sts = $data['sts'];
|
||||
$accoun->save();
|
||||
if ($accoun->sts == 2) {
|
||||
$customer = Customer::find($accoun->customer_id);
|
||||
$this->SendMessage($customer->mobile, 'کارت بانکی شما در ' . $this->Config('name_fa') . ' تایید شد');
|
||||
}
|
||||
|
||||
|
||||
return response()->json(true);
|
||||
}
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Controllers\SuperController;
|
||||
use App\Models\Cnt;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ConstController extends SuperController
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(Cnt::class, [], ['*'], null, null, ['key']);
|
||||
}
|
||||
|
||||
public function showValue($key){
|
||||
$cnt = Cnt::where('key',$key)
|
||||
->select('id','value','title_fa')->first();
|
||||
return response()->json($cnt);
|
||||
}
|
||||
}
|
||||
+257
@@ -0,0 +1,257 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\DB\Te\TableEngine;
|
||||
use App\Http\Controllers\SuperController;
|
||||
use App\Models\Customer;
|
||||
use App\Models\TransactionsAdmin;
|
||||
use App\Models\Withdraw;
|
||||
use Illuminate\Http\Request;
|
||||
use Rooyesh\Wallet\interfaces\TransactionInterface;
|
||||
use Rooyesh\Wallet\interfaces\WalletInterface;
|
||||
use Rooyesh\Wallet\models\Transaction;
|
||||
use Rooyesh\Wallet\models\Wallet;
|
||||
use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException;
|
||||
|
||||
class CustomerController extends SuperController
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->with = [];
|
||||
$this->select = ['*'];
|
||||
$search=['name','mobile'];
|
||||
$this->query = Customer::with($this->with,'wallet')->where('is_archive',false)->where('type',1);
|
||||
// $this->query = Customer::where('is_archive',false)->get();
|
||||
parent::__construct(Customer::class, $this->with, $this->select, 'customer', $this->query, $search);
|
||||
}
|
||||
/**
|
||||
* @param $id
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function listUser(){
|
||||
$user = Customer::with(['wallet'])->select('id','name','mobile','type')->get();
|
||||
return response()->json($user);
|
||||
}
|
||||
public function updateAdmin(Request $request , $id)
|
||||
{
|
||||
$data = $request->all();
|
||||
if (isset($data['mobile']) && !is_null($data['mobile'])){
|
||||
$check_mobile = Customer::where('mobile',$data['mobile'])
|
||||
->where('id','<>',$id)
|
||||
->first();
|
||||
if (!is_null($check_mobile)){
|
||||
throw new UnprocessableEntityHttpException('این شماره همراه توسط شخص دیگری در حال استفاده است');
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($data['gold'])){
|
||||
$user = Customer::find($id);
|
||||
if ($user) {
|
||||
$user->gold = $data['gold'];
|
||||
$user->save();
|
||||
$user["g"]=true;
|
||||
}
|
||||
}
|
||||
$user["u"] = Customer::findOrFail($id)->update($data);
|
||||
return response()->json($user);
|
||||
|
||||
}
|
||||
public function referrals(Request $request,$customer_id)
|
||||
{
|
||||
$customer_referral_id = Customer::where("id",$customer_id)->first()->referral_id;
|
||||
$query_table = Customer::where("referral_to_id",$customer_referral_id);
|
||||
TableEngine::create($query_table, $request)
|
||||
->initSearch($this->search)
|
||||
->select(['*',Customer::$SELECT_TYPE_STR])
|
||||
->export($query_table);
|
||||
return response()->json($query_table);
|
||||
}
|
||||
public function funds(Request $request,$customer_id)
|
||||
{
|
||||
|
||||
$query_table = Wallet::with(['fund'])->where('owner', $customer_id); // Adjust columns as per your schema
|
||||
TableEngine::create($query_table, $request)
|
||||
->initSearch($this->search)
|
||||
->select(['id', 'owner', 'cash', 'gold','fund_id','created_at', 'updated_at'])
|
||||
->export($query_table);
|
||||
return response()->json($query_table);
|
||||
}
|
||||
public function archive($id){
|
||||
$query = Customer::findOrFail($id);
|
||||
$query->update([
|
||||
'is_archive'=>!$query->is_archive
|
||||
]);
|
||||
return response()->json(true);
|
||||
}
|
||||
public function tableWallets(Request $request){
|
||||
$query_table = Customer::with(['wallet','referral'])->where("is_archive",false)/*->where('type',1)*/;
|
||||
TableEngine::create($query_table, $request)
|
||||
->initSearch($this->search)
|
||||
->select(['*',Customer::$SELECT_TYPE_STR])
|
||||
->export($query_table);
|
||||
return response()->json($query_table);
|
||||
}
|
||||
|
||||
public function archiveTable(Request $request)
|
||||
{
|
||||
$query_table = Customer::with($this->with)->where("is_archive",true)/*->where('type',1)*/;
|
||||
TableEngine::create($query_table, $request)
|
||||
->initSearch($this->search)
|
||||
->select($this->select)
|
||||
->export($query_table);
|
||||
return response()->json($query_table);
|
||||
}
|
||||
/**
|
||||
* @param $id
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function active($id){
|
||||
$query = Customer::findOrFail($id);
|
||||
$active = !$query->active;
|
||||
$query->update([
|
||||
'active'=>!$query->active
|
||||
]);
|
||||
if ($active){
|
||||
$message ='اکانت شما توسط کارشناس سیستم تایید شد '."\n".
|
||||
'با رفتن به لینک زیر وارد حساب کاربری خود شوید'."\n".
|
||||
$this->Config('app_url')."\n".
|
||||
'با تشکر'.$this->Config('name_fa');
|
||||
}
|
||||
else{
|
||||
$message ='اکانت شما توسط کارشناس سیستم غیر فعال شد '."\n".
|
||||
'با کارشناسان ما تماس بگیرید'."\n".
|
||||
'با تشکر'.$this->Config('name_fa');
|
||||
}
|
||||
$this->Send($query->mobile,$message);
|
||||
|
||||
return response()->json(true);
|
||||
}
|
||||
public function changeTradeActive($id){
|
||||
$query = Customer::findOrFail($id);
|
||||
$query->update([
|
||||
'trade_active'=>!$query->trade_active
|
||||
]);
|
||||
return response()->json(true);
|
||||
}
|
||||
// single customer-------------------
|
||||
|
||||
public function singleArchiveTable(Request $request)
|
||||
{
|
||||
$query_table = Customer::with($this->with)->where("is_archive",true)->where('type',2);
|
||||
TableEngine::create($query_table, $request)
|
||||
->initSearch($this->search)
|
||||
->select($this->select)
|
||||
->export($query_table);
|
||||
return response()->json($query_table);
|
||||
}
|
||||
|
||||
public function singleCustomerTable(Request $request)
|
||||
{
|
||||
$query_table = Customer::with($this->with)->where("is_archive",false)->where('type',2);
|
||||
TableEngine::create($query_table, $request)
|
||||
->initSearch($this->search)
|
||||
->select($this->select)
|
||||
->export($query_table);
|
||||
return response()->json($query_table);
|
||||
}
|
||||
public function MakeValidByAdmin(Request $request,$id)
|
||||
{
|
||||
$customer = Customer::with('referral')->where('id', $id)->first();
|
||||
|
||||
if ($customer->is_legal == 2 or $customer->is_legal == 3){
|
||||
return response()->json(true);
|
||||
}
|
||||
$customer->is_legal = 2;
|
||||
$customer->save();
|
||||
|
||||
if ($this->Config('has_page_earn_money') == true && Customer::where('referral_to_id', $customer->referral->referral_id)->where('is_legal', "!=",0)->count() < 4) {
|
||||
$gift_for_inviter = 0.002;
|
||||
$gift_for_invited = 0.003;
|
||||
$Withdraw = Withdraw::create([
|
||||
'user_id' => $customer->id,
|
||||
'customer_id' => $customer->referral->id,
|
||||
"cash" => 0,
|
||||
"gold" => $gift_for_invited,
|
||||
'sts' => 5,
|
||||
]);
|
||||
$wallet_interface = new WalletInterface($customer->referral->id, 2);
|
||||
new TransactionInterface($wallet_interface, $_inp = [
|
||||
"cash" => 0,
|
||||
"gold"=> $gift_for_invited,
|
||||
'expire_at'=>now(),
|
||||
'active'=>true,
|
||||
'withdraw_id' =>$Withdraw->id,
|
||||
'start_at'=>now(),
|
||||
], 8, true,false);
|
||||
|
||||
$transaction = Transaction::where('customer_id', $customer->referral->id)->latest()->first();
|
||||
TransactionsAdmin::create([
|
||||
'customer_id' => $customer->id,
|
||||
'customer_to_id' => $customer->referral->id,
|
||||
'user_id' => $customer->id,
|
||||
'wallet' => null, // یا مقدار مناسب دیگری
|
||||
'transaction_id' => $transaction->id ,
|
||||
'cash' => 0,
|
||||
'note' => 'پاداش بابت معرفی',
|
||||
'type' => 1, // یا مقدار مناسب دیگری
|
||||
'gold' => $gift_for_invited,
|
||||
'balance_cash' => 0, // یا مقدار مناسب دیگری
|
||||
'withdraw_id' => $Withdraw->id,
|
||||
]);
|
||||
$Withdraw = Withdraw::create([
|
||||
'user_id' => $customer->id,
|
||||
'customer_id' => $customer->id,
|
||||
"cash" => 0,
|
||||
"gold" => $gift_for_inviter,
|
||||
'sts' => 5,
|
||||
]);
|
||||
$wallet_interface = new WalletInterface($customer->id, 2);
|
||||
new TransactionInterface($wallet_interface, $_inp = [
|
||||
"cash" => 0,
|
||||
"gold"=> $gift_for_inviter,
|
||||
'expire_at'=>now(),
|
||||
'active'=>true,
|
||||
'withdraw_id' =>$Withdraw->id,
|
||||
'start_at'=>now(),
|
||||
], 8, true,false);
|
||||
|
||||
$transaction = Transaction::where('customer_id', $customer->id)->latest()->first();
|
||||
TransactionsAdmin::create([
|
||||
'customer_id' => $customer->id,
|
||||
'customer_to_id' => $customer->id,
|
||||
'user_id' => $customer->id,
|
||||
'wallet' => null, // یا مقدار مناسب دیگری
|
||||
'transaction_id' => $transaction->id ,
|
||||
'cash' => 0,
|
||||
'note' => 'پاداش بابت معرفی',
|
||||
'type' => 1, // یا مقدار مناسب دیگری
|
||||
'gold' => $gift_for_inviter,
|
||||
'balance_cash' => 0, // یا مقدار مناسب دیگری
|
||||
'withdraw_id' => $Withdraw->id,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
$companyName = $this->Config('name_fa');
|
||||
$companyurl = $this->Config('app_url');
|
||||
$message ='حساب کاربری شما توسط کارشناس سیستم تایید شد '."\n".
|
||||
'با رفتن به لینک زیر وارد حساب کاربری خود شوید'."\n".
|
||||
$this->Config('app_url')."\n".
|
||||
'با تشکر'.$this->Config('name_fa');
|
||||
$this->Send($customer->mobile, $message);
|
||||
|
||||
$referrer = $customer->referral;
|
||||
|
||||
// if ($referrer) {
|
||||
// if (Customer::where('referral_to_id', $referrer->referral_id)->get()->count()<=$referrer->add_user_limit) {
|
||||
// $referrerWallet = Wallet::where('owner',$customer->referral->id)->first();
|
||||
// $message = "سلام {$referrer->name} عزیز،\n\n{$gift_for_invite} گرم طلا بابت معرفی {$customer->name} به حساب شما واریز شد.\nموجودی فعلی: {$referrerWallet->gold} گرم.\n\nاطلاعات بیشتر: $companyurl\n\nبا احترام،\n$companyName";
|
||||
// $this->Send($referrer->mobile, $message);
|
||||
// }
|
||||
// }
|
||||
|
||||
return response()->json(true);
|
||||
}
|
||||
}
|
||||
+306
@@ -0,0 +1,306 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Cnt;
|
||||
use App\Models\Customer;
|
||||
use App\Models\Order;
|
||||
use App\Models\Price;
|
||||
use App\Models\TransactionsAdmin;
|
||||
use App\Models\Withdraw;
|
||||
use Carbon\Carbon;
|
||||
use Hekmatinasser\Verta\Verta;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Rooyesh\Wallet\models\Wallet;
|
||||
|
||||
class DashboardController extends Controller
|
||||
{
|
||||
public function dashboardMaster(){
|
||||
$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 response()->json([
|
||||
'GT_all_customers'=>$GT_all_customers,
|
||||
'GT_no_login_customers'=>$GT_no_login_customers,
|
||||
'GT_no_valid_customers'=>$GT_no_valid_customers,
|
||||
'GT_no_valid_customers_data'=>$GT_no_valid_customers_data,
|
||||
'GT_active_customers'=>$GT_active_customers,
|
||||
'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,
|
||||
'new_customer_major'=>$new_customer_major,
|
||||
'new_customer_single'=>$new_customer_single,
|
||||
'all_customer_major'=>$all_customer_major,
|
||||
'all_customer_single'=>$all_customer_single,
|
||||
'archive_customer_major'=>$archive_customer_major,
|
||||
'archive_customer_single'=>$archive_customer_single,
|
||||
'all_gold'=>$all_gold,
|
||||
'all_gold_single'=>$all_gold_single,
|
||||
'await_order'=>$await_list,
|
||||
'best_customer'=>$best_customer_major,
|
||||
'best_customer_single'=>$best_customer_single,
|
||||
|
||||
]);
|
||||
}
|
||||
public function getBalance(Request $request)
|
||||
{
|
||||
$startDate = Carbon::parse($request->startDate)->startOfDay();
|
||||
$endDate = Carbon::parse($request->endDate)->endOfDay();
|
||||
$response=[];
|
||||
$response["liman"]=[];
|
||||
$response["kalhor"]=[];
|
||||
|
||||
$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"]["balance"]["gold"] = 0;
|
||||
$response["liman"]["balance"]["cash"] = 0;
|
||||
$response["liman"]["balance_abs"]["gold"] = 0;
|
||||
$response["liman"]["balance_abs"]["cash"] = 0;
|
||||
foreach ($response["liman"]["orders"] as $OrderGoldBalanceRow) {
|
||||
if ($OrderGoldBalanceRow->direction == 1){
|
||||
$response["liman"]["balance"]["gold"] += $OrderGoldBalanceRow->amount;
|
||||
$response["liman"]["balance"]["cash"] -= $OrderGoldBalanceRow->total_price;
|
||||
}
|
||||
if ($OrderGoldBalanceRow->direction == 2){
|
||||
$response["liman"]["balance"]["gold"] -= $OrderGoldBalanceRow->amount;
|
||||
$response["liman"]["balance"]["cash"] += $OrderGoldBalanceRow->total_price;
|
||||
}
|
||||
$response["liman"]["balance_abs"]["gold"] += $OrderGoldBalanceRow->amount;
|
||||
$response["liman"]["balance_abs"]["cash"] += $OrderGoldBalanceRow->total_price;
|
||||
}
|
||||
$response['goldBalanceOfLiman']= -$response["liman"]["balance"]["gold"];
|
||||
$response['cashBalanceOfLiman']= -$response["liman"]["balance"]["cash"];
|
||||
//kalhor
|
||||
// $response["kalhor"]["orders"] = Cache::remember("kalhor_orders_" . md5($startDate . $endDate), 900, function () use ($startDate, $endDate) {
|
||||
// $body = [
|
||||
// 'FromDate' => Jalalian::forge($startDate)->format('Y/m/d'),
|
||||
// 'ItemId' => 0,
|
||||
// 'OrderIndex' => 0,
|
||||
// 'ToDate' => Jalalian::forge($endDate)->format('Y/m/d'),
|
||||
// ];
|
||||
//
|
||||
// return Http::withHeaders(config('kalhor.headers'))
|
||||
// ->withCookies(config('kalhor.cookies'), 'b750.ir')
|
||||
// ->post('https://b750.ir/Deal/DealsList', $body)->json();
|
||||
// });
|
||||
|
||||
$response["kalhor"]["balance"]["gold"] = 0;
|
||||
$response["kalhor"]["balance"]["cash"] = 0;
|
||||
$response["kalhor"]["balance_abs"]["gold"] = 0;
|
||||
$response["kalhor"]["balance_abs"]["cash"] = 0;
|
||||
if (!empty($response["kalhor"]["orders"]['Data'])) {
|
||||
foreach ($response["kalhor"]["orders"]['Data'] as &$data) {
|
||||
|
||||
$data['0_save_in_liman']= 0;
|
||||
if ($data['DeclineReason'] == 0 and $data['OrderStatusStr'] !="لغو شده") { //رد نشده بود
|
||||
$data['0_save_in_liman']= 1;
|
||||
if ($data['DealTypeStr'] == "خرید" or $data['DealTypeStr'] == "خرید _ دستی") {
|
||||
$response["kalhor"]["balance"]['gold'] += $data['Count'];
|
||||
$response["kalhor"]["balance"]['cash'] -= $data['TotalPrice'];
|
||||
$direction =2;
|
||||
} elseif ($data['DealTypeStr'] == "فروش" or $data['DealTypeStr'] == "فروش _ دستی") {
|
||||
$response["kalhor"]["balance"]['gold'] -= $data['Count'];
|
||||
$response["kalhor"]["balance"]['cash'] += $data['TotalPrice'];
|
||||
$direction =1;
|
||||
}
|
||||
$response["kalhor"]["balance_abs"]['gold'] += $data['Count'];
|
||||
$response["kalhor"]["balance_abs"]['cash'] += $data['TotalPrice'];
|
||||
|
||||
if (Order::where('ref_id', $data['OrderCode'])->doesntExist()){
|
||||
$request = new Request([
|
||||
'amount' => $data['Count'],
|
||||
'customer_id' => 12,
|
||||
'method' => "liman",
|
||||
'direction' => $direction,
|
||||
'product_id' => 2,
|
||||
"price"=>$data['Mazane'],
|
||||
"cash"=>$data['TotalPrice'],
|
||||
'ref_id' => $data['OrderCode'],
|
||||
'pay_at' =>Jalalian::fromFormat('Y/m/d', explode('_', $data['ModifiedDateStr'])[0])->toCarbon()->format('Y-m-d') . ' ' . explode('_', $data['ModifiedDateStr'])[1],
|
||||
'description' => "FROM KALHOR"
|
||||
]);
|
||||
// $AdminOrderController = new AdminOrderController();
|
||||
// $response["kalhor"]["newOrders"][$data['OrderCode']] = $AdminOrderController->store($request);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$response['goldBalanceOfKalhor']= $response["kalhor"]["balance"]["gold"];
|
||||
$response['cashBalanceOfKalhor']= $response["kalhor"]["balance"]["cash"];
|
||||
//main
|
||||
$response['cashBalance']= -$response["liman"]["balance"]["cash"]+$response["kalhor"]["balance"]["cash"];
|
||||
$response['goldBalance']= -$response["liman"]["balance"]["gold"]+$response["kalhor"]["balance"]["gold"];
|
||||
//mazaneh
|
||||
$changeMesghal = config('change_mesghal');
|
||||
|
||||
/* $response['mazanehBalanceOfKalhor'] = $response["kalhor"]["balance_abs"]["gold"] != 0
|
||||
? ( $response["kalhor"]["balance_abs"]["cash"] / $response["kalhor"]["balance_abs"]["gold"])
|
||||
* $changeMesghal : 0;
|
||||
$response['mazanehBalanceOfLiman'] = $response["kalhor"]["balance_abs"]["gold"] != 0
|
||||
? ( $response["liman"]["balance_abs"]["cash"] / $response["liman"]["balance_abs"]["gold"])
|
||||
* $changeMesghal : 0;
|
||||
$response['mazanehBalance'] = $response["kalhor"]["balance_abs"]["gold"] != 0
|
||||
? (($response["liman"]["balance_abs"]["cash"]+$response["kalhor"]["balance_abs"]["cash"]) /
|
||||
($response["liman"]["balance_abs"]["gold"]+$response["kalhor"]["balance_abs"]["gold"]))
|
||||
* $changeMesghal : 0;*/
|
||||
$response['mazanehBalanceOfKalhor'] = $response["kalhor"]["balance_abs"]["gold"] != 0
|
||||
? ($response["kalhor"]["balance_abs"]["cash"] / $response["kalhor"]["balance_abs"]["gold"]) * $changeMesghal
|
||||
: 0;
|
||||
|
||||
$response['mazanehBalanceOfLiman'] = $response["liman"]["balance_abs"]["gold"] != 0
|
||||
? ($response["liman"]["balance_abs"]["cash"] / $response["liman"]["balance_abs"]["gold"]) * $changeMesghal
|
||||
: 0;
|
||||
|
||||
$totalGold = $response["liman"]["balance_abs"]["gold"] + $response["kalhor"]["balance_abs"]["gold"];
|
||||
$response['mazanehBalance'] = $totalGold != 0
|
||||
? (($response["liman"]["balance_abs"]["cash"] + $response["kalhor"]["balance_abs"]["cash"]) / $totalGold) * $changeMesghal
|
||||
: 0;
|
||||
$response['income_money'] = Withdraw::whereNotNull('zify_code')->where('sts',2)->whereBetween('updated_at', [$startDate, $endDate])->sum('cash');
|
||||
return $response;
|
||||
|
||||
}
|
||||
|
||||
public function finance(Request $request)
|
||||
{
|
||||
$startDate = $request->startDate ? Carbon::parse($request->startDate)->startOfDay() : Carbon::now()->subDays(30)->startOfDay();
|
||||
$endDate = $request->endDate ? Carbon::parse($request->endDate)->endOfDay() : Carbon::now()->endOfDay();
|
||||
|
||||
|
||||
// Fetch orders and transactions within the date range
|
||||
$ords = Order::whereBetween('created_at', [$startDate, $endDate])->get();
|
||||
$TransactionsAdmin = TransactionsAdmin::whereBetween('created_at', [$startDate, $endDate])->get();
|
||||
|
||||
// Initialize response data
|
||||
$response = [
|
||||
"fullPriceM1" => 0,
|
||||
"fullPriceM2" => 0,
|
||||
"fullPriceSood" => 0,
|
||||
"fullPriceKarmozd" => 0,
|
||||
"orderCount" => $ords->count(),
|
||||
"Gifts" => 0,
|
||||
"GiftsPrise" => 0,
|
||||
"sumAll" => 0
|
||||
];
|
||||
|
||||
// Calculate total gold gifts from transactions
|
||||
foreach ($TransactionsAdmin as $TransactionAdmin) {
|
||||
$response['Gifts'] += $TransactionAdmin->gold;
|
||||
}
|
||||
$response['Gifts'] = number_format($response['Gifts'], 3);
|
||||
|
||||
// Calculate total price of gold gifts
|
||||
$response['GiftsPrise'] = floor($response['Gifts'] * Price::latest()->first()->price);
|
||||
// Calculate order-related sums
|
||||
foreach ($ords as $ord) {
|
||||
$response['fullPriceM1'] += abs($ord->total_price_original - $ord->payment_amount);
|
||||
$response['fullPriceM2'] += $ord->service_charge_price + $ord->total_fee;
|
||||
$response['fullPriceSood'] += $ord->total_fee;
|
||||
$response['fullPriceKarmozd'] += $ord->service_charge_price;
|
||||
}
|
||||
$response['sumAll'] = $response['fullPriceM1']-$response['GiftsPrise'];
|
||||
return $response;
|
||||
}
|
||||
|
||||
public function sumSellToCustomerMajor(Request $request){
|
||||
$data = $request->all();
|
||||
$order = Order::where('direction',1)
|
||||
->where('sts',2)
|
||||
->whereDate('created_at','>=',Carbon::parse($data['start_at']))
|
||||
->whereDate('created_at','<=',Carbon::parse($data['end_at']))
|
||||
->where('type',1)
|
||||
->sum('amount');
|
||||
return response()->json($order);
|
||||
}
|
||||
public function sumSellToCustomerSingle(Request $request){
|
||||
$data = $request->all();
|
||||
$order = Order::where('direction',1)
|
||||
->where('sts',2)
|
||||
->whereDate('created_at','>=',Carbon::parse($data['start_at']))
|
||||
->whereDate('created_at','<=',Carbon::parse($data['end_at']))
|
||||
->where('type',2)
|
||||
->sum('amount');
|
||||
return response()->json($order);
|
||||
}
|
||||
public function flow(Request $request){
|
||||
$data = $request->all();
|
||||
if ($data['type'] == 'week'){
|
||||
$query=Order::where('sts',2)
|
||||
->whereDate('created_at','<=',now())
|
||||
->whereDate('created_at','>=',now()->subWeek())
|
||||
->select(['direction',DB::raw('Date(created_at) as date'),DB::raw('sum(amount) as total')])
|
||||
->groupBy(['date','direction'])
|
||||
->get();
|
||||
|
||||
}
|
||||
elseif ($data['type'] == 'month'){
|
||||
$query=Order::where('sts',2)
|
||||
->whereDate('created_at','<=',now())
|
||||
->whereDate('created_at','>=',now()->subMonth())
|
||||
->select(['direction',DB::raw('Date(created_at) as date'),DB::raw('sum(amount) as total')])
|
||||
->groupBy(['date','direction'])
|
||||
->get();
|
||||
}
|
||||
if (in_array($data['type'],['week','month'])){
|
||||
$send = [];
|
||||
foreach ($query as $i){
|
||||
if(in_array($i['date'],array_keys($send))){
|
||||
$send[$i['date']][$i['direction']] = $i['total'];
|
||||
}else{
|
||||
$send[$i['date']]['date'] =$i['date'];
|
||||
$send[$i['date']][$i['direction']] = $i['total'];
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
$query=Order::where('sts',2)
|
||||
->whereDate('created_at','<=',now())
|
||||
->whereDate('created_at','>=',now()->subYear())
|
||||
->select(['direction',DB::raw('MONTH(created_at) as month'),DB::raw('sum(amount) as total')])
|
||||
->groupBy(['month','direction'])
|
||||
->get();
|
||||
for ($i=0;$i<count($query);$i++){
|
||||
$query[$i]['month_fa'] = Verta::instance( $query[$i]['month'])->format('%B');
|
||||
}
|
||||
}
|
||||
return response()->json(array_values($send));
|
||||
}
|
||||
}
|
||||
+234
@@ -0,0 +1,234 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\DB\Te\TableEngine;
|
||||
use App\Models\Customer;
|
||||
use App\Models\Message;
|
||||
use App\Models\Order;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
|
||||
|
||||
|
||||
class MassageController extends Controller
|
||||
{
|
||||
public function send_message(Request $request)
|
||||
{
|
||||
// یافتن مشتریان با شمارههای داده شده
|
||||
$customers = Customer::whereIn('mobile', $request->numbers)->get();
|
||||
|
||||
foreach ($customers as $customer) {
|
||||
// جایگزین کردن نام در پیام
|
||||
$message = str_replace('%name%', $customer->name, $request->message);
|
||||
|
||||
// ارسال پیامک
|
||||
$this->send($customer->mobile, $message);
|
||||
}
|
||||
|
||||
return response()->json(true);
|
||||
}
|
||||
public function getFunctionDescriptions()
|
||||
{
|
||||
|
||||
return response()->json([
|
||||
[
|
||||
'function' => 'getAllCustomers',
|
||||
'name' => 'همه کاربران',
|
||||
],
|
||||
[
|
||||
'function' => 'getNoLoginCustomers',
|
||||
'name' => 'کاربران وارد نشده',
|
||||
],
|
||||
[
|
||||
'function' => 'getNoValidCustomers',
|
||||
'name' => 'کاربران احراز نشده',
|
||||
],
|
||||
[
|
||||
'function' => 'getActiveCustomers',
|
||||
'name' => 'کاربران فعال',
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public function getCustomerList(Request $request)
|
||||
{
|
||||
$customers = [];
|
||||
foreach ($request->functions as $action) {
|
||||
if ($action === 'getAllCustomers') {
|
||||
$customers = array_merge($customers, $this->getAllCustomers());
|
||||
}
|
||||
if ($action === 'getNoLoginCustomers') {
|
||||
$customers = array_merge($customers, $this->getNoLoginCustomers());
|
||||
}
|
||||
if ($action === 'getNoValidCustomers') {
|
||||
$customers = array_merge($customers, $this->getNoValidCustomers());
|
||||
}
|
||||
if ($action === 'getActiveCustomers') {
|
||||
$customers = array_merge($customers, $this->getActiveCustomers());
|
||||
}
|
||||
}
|
||||
// حذف شمارههای تکراری
|
||||
$uniqueCustomers = $this->removeDuplicateNumbers($customers);
|
||||
|
||||
return response()->json(['customers' => $uniqueCustomers]);
|
||||
}
|
||||
public function getCustomerListTable(Request $request)
|
||||
{
|
||||
$customers = [];
|
||||
foreach ($request->functions as $action) {
|
||||
if ($action === 'getAllCustomers') {
|
||||
$customers = array_merge($customers, $this->getAllCustomers());
|
||||
}
|
||||
if ($action === 'getNoLoginCustomers') {
|
||||
$customers = array_merge($customers, $this->getNoLoginCustomers());
|
||||
}
|
||||
if ($action === 'getNoValidCustomers') {
|
||||
$customers = array_merge($customers, $this->getNoValidCustomers());
|
||||
}
|
||||
if ($action === 'getActiveCustomers') {
|
||||
$customers = array_merge($customers, $this->getActiveCustomers());
|
||||
}
|
||||
}
|
||||
// Remove duplicate numbers
|
||||
$uniqueCustomers = $this->removeDuplicateNumbers($customers);
|
||||
$uniqueCustomersCollection = collect($uniqueCustomers);
|
||||
|
||||
$records = Customer::whereIn('id', $uniqueCustomersCollection->pluck('id'));
|
||||
// Initialize TableEngine
|
||||
TableEngine::create($records, $request->all())
|
||||
->initSearch(['customer.name'])
|
||||
->select([
|
||||
'id','mobile', 'name'
|
||||
])
|
||||
->export($records);
|
||||
|
||||
return response()->json($records);
|
||||
|
||||
}
|
||||
|
||||
private function getAllCustomers()
|
||||
{
|
||||
return Customer::where('type', 2)
|
||||
->where('is_archive', false)
|
||||
->get(['id', 'name', 'mobile'])
|
||||
->toArray();
|
||||
}
|
||||
|
||||
private function getNoLoginCustomers()
|
||||
{
|
||||
return Customer::where('type', 2)
|
||||
->where('is_archive', false)
|
||||
->whereNull('last_seen_at')
|
||||
->get(['id', 'name', 'mobile'])
|
||||
->toArray();
|
||||
}
|
||||
|
||||
private function getNoValidCustomers()
|
||||
{
|
||||
return Customer::where('type', 2)
|
||||
->where('is_archive', false)
|
||||
->where('is_legal', 0)
|
||||
->get(['id', 'name', 'mobile'])
|
||||
->toArray();
|
||||
}
|
||||
|
||||
private function getActiveCustomers()
|
||||
{
|
||||
return Customer::where('type', 2)
|
||||
->where('is_archive', false)
|
||||
->whereIn('id', function ($query) {
|
||||
$query->select('owner')
|
||||
->from('wallets');
|
||||
})
|
||||
->get(['id', 'name', 'mobile'])
|
||||
->toArray();
|
||||
}
|
||||
|
||||
private function removeDuplicateNumbers(array $customers)
|
||||
{
|
||||
$uniqueCustomers = [];
|
||||
$seenNumbers = [];
|
||||
|
||||
foreach ($customers as $customer) {
|
||||
if (!in_array($customer['mobile'], $seenNumbers)) {
|
||||
$seenNumbers[] = $customer['mobile'];
|
||||
$uniqueCustomers[] = $customer;
|
||||
}
|
||||
}
|
||||
|
||||
return $uniqueCustomers;
|
||||
}
|
||||
|
||||
public function messagesTable(Request $request)
|
||||
{
|
||||
$records = Message::with(['person']);
|
||||
$table = TableEngine::create($records, $request->all())
|
||||
->initSearch([])
|
||||
->select([
|
||||
'id', 'sms', 'receiver','created_at',
|
||||
]);
|
||||
return response()->json($table->export());
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the messages.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$messages = Message::all();
|
||||
return response()->json($messages);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created message in storage.
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'sms' => 'required|string',
|
||||
'receiver' => 'required|string',
|
||||
]);
|
||||
|
||||
$message = Message::create($request->only(['sms', 'receiver']));
|
||||
|
||||
return response()->json($message, 201);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified message.
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
$message = Message::findOrFail($id);
|
||||
return response()->json($message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified message in storage.
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
$request->validate([
|
||||
'sms' => 'sometimes|required|string',
|
||||
'receiver' => 'sometimes|required|string',
|
||||
]);
|
||||
|
||||
$message = Message::findOrFail($id);
|
||||
$message->update($request->only(['sms', 'receiver']));
|
||||
|
||||
return response()->json($message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified message from storage.
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
$message = Message::findOrFail($id);
|
||||
$message->delete();
|
||||
|
||||
return response()->json(null, 204);
|
||||
}
|
||||
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\DB\Te\TableEngine;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Order;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class OrderController extends Controller
|
||||
{
|
||||
public function table(Request $request){
|
||||
$records = Order::with(['customer','transactions']);
|
||||
TableEngine::create($records, $request->all())
|
||||
->initSearch(['customer.name'])
|
||||
->select([
|
||||
'*',Order::$SELECT_STS_STR
|
||||
])->export($records);
|
||||
return response()->json($records);
|
||||
}
|
||||
public function singleOrderTable(Request $request){
|
||||
$records = Order::with(['customer'])->where('type',2);
|
||||
TableEngine::create($records, $request->all())
|
||||
->initSearch(['customer.name'])
|
||||
->select([
|
||||
'*',Order::$SELECT_STS_STR
|
||||
])->export($records);
|
||||
return response()->json($records);
|
||||
}
|
||||
}
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\DB\Te\TableEngine;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Price;
|
||||
use App\Models\PriceCandle;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class PriceController extends Controller
|
||||
{
|
||||
public function store(Request $request){
|
||||
Price::create([
|
||||
"price"=>$request->price ,
|
||||
"date_at"=>date("Y-m-d"),
|
||||
"time_at"=>now()->format("H:m:s"),
|
||||
"user_id"=>auth('user')->id()
|
||||
]);
|
||||
$candle = PriceCandle::whereDate('date_at',date("Y-m-d"))->first();
|
||||
if (!is_null($candle)){
|
||||
$candle->end = $request->price;
|
||||
if ($request->price < $candle->low){
|
||||
$candle->low = $request->price;
|
||||
}
|
||||
elseif ($request->price > $candle->high){
|
||||
$candle->high = $request->price;
|
||||
}
|
||||
$candle->save();
|
||||
}else{
|
||||
PriceCandle::create([
|
||||
"start"=>$request->price,
|
||||
"end"=>$request->price,
|
||||
"high"=>$request->price,
|
||||
"low"=>$request->price,
|
||||
"date_at"=>date("Y-m-d")
|
||||
]);
|
||||
}
|
||||
return response()->json(true);
|
||||
}
|
||||
public function priceData(Request $request){
|
||||
$prise = Price::with('order');
|
||||
TableEngine::create($prise, $request)
|
||||
->initSearch(['price'])
|
||||
->select(['*'])
|
||||
->export($prise);
|
||||
return response()->json($prise);
|
||||
}
|
||||
public function table(Request $request){
|
||||
$records = Price::with(['user']);
|
||||
TableEngine::create($records, $request->all())
|
||||
->initSearch([])
|
||||
->select([
|
||||
'*'
|
||||
])->export($records);
|
||||
return response()->json($records);
|
||||
}
|
||||
}
|
||||
+246
@@ -0,0 +1,246 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Controllers\SuperController;
|
||||
use App\Models\Product;
|
||||
use App\DB\Te\TableEngine;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Http\Request;
|
||||
use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use \App\Http\Controllers\Customer\FundController;
|
||||
use App\Http\Controllers\Site\ReportController ;
|
||||
|
||||
|
||||
class ProductController extends SuperController
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->with = ['file', 'price', 'default', 'sub'];
|
||||
$this->with = [];
|
||||
parent::__construct(Product::class, $this->with, ['*'], null, null, ['title']);
|
||||
}
|
||||
public function tableProduct(Request $request)
|
||||
{
|
||||
$data = $request->all();
|
||||
if (isset($data["select"]) && is_null($data["select"])){
|
||||
$data["select"] = [];
|
||||
}
|
||||
if (is_null($this->query)){
|
||||
$query_table = $this->model::with($this->with);
|
||||
//*******کداضافه شده
|
||||
// ->where('active', '<=', now()) // فیلتر محصولات فعال
|
||||
// ->get();
|
||||
//*********
|
||||
}else{
|
||||
$query_table = $this->query;
|
||||
// $query_table = $query_table->where('active', '<=', now());
|
||||
}
|
||||
TableEngine::create($query_table, $data)
|
||||
->initSearch($this->search)
|
||||
->select($this->select)
|
||||
->export($query_table);
|
||||
$query_table['auto_open_at'] = Product::selectRaw(
|
||||
'SEC_TO_TIME(AVG(TIME_TO_SEC(TIME(auto_open_at)))) as avg_time'
|
||||
)->value('avg_time'); $query_table['auto_close_at'] = Product::selectRaw(
|
||||
'SEC_TO_TIME(AVG(TIME_TO_SEC(TIME(auto_close_at)))) as avg_time'
|
||||
)->value('avg_time');
|
||||
|
||||
// $query_table['11'] = $avgDuration;
|
||||
// $query_table['11'] = Product::avg('auto_open_at');
|
||||
// $query_table['112'] = Product::avg('auto_close_at');
|
||||
return $query_table;
|
||||
|
||||
}
|
||||
|
||||
public function editProducts(Request $request)
|
||||
{
|
||||
if (isset($request->auto_open_at, $request->auto_close_at)) {
|
||||
Product::query()->update([
|
||||
'auto_open_at' => $request->auto_open_at,
|
||||
'auto_close_at' => $request->auto_close_at,
|
||||
]);
|
||||
return response()->json(['message' => 'Products updated successfully.']);
|
||||
}
|
||||
|
||||
return response()->json(['error' => 'auto_open_at and auto_close_at must be set'], 400);
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$data = $request->all();
|
||||
|
||||
$product = Product::create($data);
|
||||
return $this->resultCreate($product->id);
|
||||
}
|
||||
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
// return 1;
|
||||
|
||||
$data = $request->all();
|
||||
if (isset($data["price"])){
|
||||
$data["reading_method"] = null;
|
||||
}
|
||||
if (isset($data["auto_close_at"]) and isset($data["auto_close_at"])){
|
||||
if ($data["auto_close_at"] == $data["auto_open_at"]){
|
||||
unset($data["auto_open_at"]);
|
||||
unset($data["auto_close_at"]);
|
||||
}
|
||||
}
|
||||
|
||||
// return $data['price'];
|
||||
|
||||
|
||||
// if(!isset($data['default'])){
|
||||
// throw new UnprocessableEntityHttpException('مقادیر اعتبارات را وارد کنید');
|
||||
// }
|
||||
|
||||
// $data['auto_open_at'] = Carbon::parse($data['auto_open_at'])->format('Y-m-d H:i:s');
|
||||
// $data['auto_close_at'] = Carbon::parse($data['auto_close_at'])->format('Y-m-d H:i:s');
|
||||
// Product::find($id)->update($data);
|
||||
Product::find($id)->update($data);
|
||||
|
||||
return response()->json(true);
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
Product::findOrFail($id)->delete();
|
||||
return response()->json(true);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function listProduct()
|
||||
{
|
||||
// $this->getPrice();
|
||||
$this->auto_close_open();
|
||||
$product = Product::with([])->where('active', 1)->get();
|
||||
return response()->json($product);
|
||||
}
|
||||
|
||||
public function getPrice()
|
||||
{
|
||||
// $RPrices = Http::get('https://pricing.liman.gold/pricingApi', [])->json();
|
||||
// $RPrices = Http::get('https://pricing.liman.gold/pricingApi', [])->json();
|
||||
$RPrices =Http::timeout(40)->get('http://212.23.201.173:8381/price_list', [])->json();
|
||||
|
||||
$products = Product::with([])->whereNotNull('reading_method')->get();
|
||||
foreach ($products as $product) {
|
||||
foreach ($RPrices as $RPrice) {
|
||||
if ($product->reading_method == $RPrice['name']) {
|
||||
$p = Product::where('id', $product->id)->update([
|
||||
'price' => $RPrice['price'],
|
||||
'price_profit' => $RPrice['profit'],
|
||||
]);
|
||||
|
||||
if($product->bubble== 1){
|
||||
$ReportController = new ReportController();
|
||||
$liquidGold= $ReportController->lastPrice();
|
||||
$p = Product::find($product->id);
|
||||
$p->amount = $RPrice['price'] / $liquidGold['price'];
|
||||
$p->save();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return response()->json(true);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function auto_close_open()
|
||||
{
|
||||
$products = Product::with([])->get();
|
||||
$current_time = now()->format('H:i:s');
|
||||
foreach ($products as $product) {
|
||||
$show = ($current_time >= $product->auto_open_at && $current_time <= $product->auto_close_at);
|
||||
Product::where('id', $product->id)->update([
|
||||
'show' => $show,
|
||||
]);
|
||||
}
|
||||
return response()->json(true);
|
||||
}
|
||||
|
||||
|
||||
public function getProduct($id)
|
||||
{
|
||||
$product = Product::with($this->with)->where('id', $id)->first();
|
||||
return response()->json($product);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $id
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function hide($id)
|
||||
{
|
||||
$query = Product::findOrFail($id);
|
||||
$query->update([
|
||||
'show' => !$query->show
|
||||
]);
|
||||
return response()->json(true);
|
||||
}
|
||||
|
||||
public function openSell($id)
|
||||
{
|
||||
return $this->toggleBooleanStatus($id, 'open_sell');
|
||||
}
|
||||
|
||||
public function openBuy($id)
|
||||
{
|
||||
return $this->toggleBooleanStatus($id, 'open_buy');
|
||||
}
|
||||
|
||||
public function auto_buy($id)
|
||||
{
|
||||
return $this->toggleBooleanStatus($id, 'auto_buy');
|
||||
}
|
||||
|
||||
public function auto_sell($id)
|
||||
{
|
||||
return $this->toggleBooleanStatus($id, 'auto_sell');
|
||||
}
|
||||
|
||||
private function toggleBooleanStatus($id, $field)
|
||||
{
|
||||
$product = Product::findOrFail($id);
|
||||
$product->$field = !$product->$field;
|
||||
$product->save();
|
||||
if (!$product->open_buy and !$product->open_sell) {
|
||||
$product->show = false;
|
||||
$product->active = false;
|
||||
} else {
|
||||
$product->show = true;
|
||||
$product->active = true;
|
||||
}
|
||||
$product->save();
|
||||
return response()->json($product->$field);
|
||||
}
|
||||
|
||||
public function auto_group($action, $method)
|
||||
{
|
||||
// Define valid actions and methods
|
||||
$validActions = ['sell' => 'auto_sell', 'buy' => 'auto_buy', 'all' => ['auto_buy', 'auto_sell']];
|
||||
$validMethods = ['true' => 1, 'false' => 0];
|
||||
// Validate action and method
|
||||
if (!isset($validActions[$action]) || !array_key_exists($method, $validMethods)) {
|
||||
return response()->json(['error' => 'Invalid action or method'], 400);
|
||||
}
|
||||
// Get fields to update and value to set
|
||||
$fields = $validActions[$action];
|
||||
$value = $validMethods[$method];
|
||||
// Update products
|
||||
Product::query()->update(array_fill_keys((array)$fields, $value));
|
||||
return response()->json(true);
|
||||
}
|
||||
|
||||
public function updatePrice(Request $request){
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
+220
@@ -0,0 +1,220 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use App\Models\Tahesab;
|
||||
use App\Models\Customer;
|
||||
use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException;
|
||||
use Hekmatinasser\Verta\Verta;
|
||||
|
||||
|
||||
class TahesabController extends Controller
|
||||
{
|
||||
public function store()
|
||||
{
|
||||
$customer = auth()->user();
|
||||
if (!$customer) {
|
||||
throw new UnprocessableEntityHttpException("Auth needed");
|
||||
}
|
||||
$customer = Customer::where('id', $customer->id)->first();
|
||||
|
||||
if ($customer && ($customer->moshtari_code !== null)) {
|
||||
return "customer exists";
|
||||
}
|
||||
try {
|
||||
$response = Http::withoutVerifying()->timeout(10)->withHeaders([
|
||||
'DBName' => $this->Config('tahesab_db'),
|
||||
'Content-Type' => 'application/json',
|
||||
'Authorization' => "Bearer " . $this->Config('tahesab_token'),
|
||||
])->post('https://185.252.86.194:8081', [
|
||||
"DoNewMoshtari" => [
|
||||
$customer->name,
|
||||
$this->Config('name_fa'),
|
||||
$customer->mobile,
|
||||
"",
|
||||
$customer->n_code ?? "",
|
||||
$customer->birth_date ?? "", // !== null ? jalalian::fromCarbon(Carbon::parse($customer->birth_date))->format('Y/m/d') : null,
|
||||
"",
|
||||
"",
|
||||
-1,
|
||||
0 // tala
|
||||
]
|
||||
]);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return $e->getMessage();
|
||||
}
|
||||
if (empty($response['OK'])) {
|
||||
return "tahesab api error!!!";
|
||||
}
|
||||
|
||||
$customer->moshtari_code = $response['OK'];
|
||||
$customer->save();
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
public function storeTrade($input = null)
|
||||
{
|
||||
if ($input instanceof \Illuminate\Http\Request) {
|
||||
$data = $input->all();
|
||||
} elseif (is_array($input)) {
|
||||
$data = $input;
|
||||
} else {
|
||||
$data = request()->all();
|
||||
}
|
||||
// return ($data);
|
||||
|
||||
if (!isset($data['customer_id']) || !isset($data['product']['amount'])) {
|
||||
return request()->expectsJson()
|
||||
? response()->json(['error' => 'Data missing: customer_id or value'], 422)
|
||||
: false;
|
||||
}
|
||||
|
||||
// $customer = auth()->user();
|
||||
// if (!$customer) {
|
||||
// throw new UnprocessableEntityHttpException("Auth needed");
|
||||
// }
|
||||
$customer = Customer::where('id', $data['customer_id'])->first();
|
||||
|
||||
if ($customer && ($customer->moshtari_code === null)) {
|
||||
$this->store();
|
||||
}
|
||||
$date = Verta::instance(Carbon::parse($data['pay_at']))->format('Y-m-d');
|
||||
[$year, $month, $day] = explode('-', $date);
|
||||
|
||||
$amount = $data['amount'];
|
||||
|
||||
$tahesab = Tahesab::create([
|
||||
"customer_id" => $customer->id,
|
||||
"desc" => $data['direction'] == 1 ? "خرید آبشده" : "فروش آبشده",
|
||||
"amount" => $amount,
|
||||
"date" => $data['pay_at'],
|
||||
"type" => $data['product']['metal_id'] == 1 ? "طلا" : "نقره",
|
||||
"created_at" => Carbon::now(),
|
||||
]);
|
||||
|
||||
try {
|
||||
$response = Http::withoutVerifying()->timeout(10)->withHeaders([
|
||||
'DBName' => $this->Config('tahesab_db'),
|
||||
'Content-Type' => 'application/json',
|
||||
'Authorization' => "Bearer " . $this->Config('tahesab_token'),
|
||||
])->post('https://185.252.86.194:8081', [
|
||||
"DoNewSanadBuySaleGOLD" => [
|
||||
1,//Sabte_Kol_Or_Movaghat_1_0
|
||||
(int)$customer->moshtari_code, //Moshtari_Code
|
||||
-1, //Factor_Number
|
||||
1, //Radif_Number
|
||||
(int)$year, //Shamsi_Year
|
||||
(int)$month, //Shamsi_Month
|
||||
(int)$day, //Shamsi_Day
|
||||
(float)$amount, //Vazn
|
||||
$data['product']['metal_id'] == 1 ? 750 : "", //Ayar
|
||||
0,
|
||||
"",
|
||||
$data['direction'] == 1 ? 0 : 1, //BuyOrSale_0_1
|
||||
(int)$data['price'], //Mazaneh
|
||||
1, //MazanehIsMesghalOrGeram_0_1
|
||||
1, //IsMotefaregheOrAbshode_0_1
|
||||
(int)$data['total_price_original'], //MablaghKol
|
||||
$data['direction'] == 1 ? "خرید آبشده" : "فروش آبشده",
|
||||
"Code_Factor",
|
||||
"", //HavalehBe_Mcode
|
||||
"", //MultiRadif
|
||||
$data['product']['metal_id'] == 1 ? 0 : 2, //Jens_Felez
|
||||
(string)Verta::instance($data['pay_at']),
|
||||
]
|
||||
]);
|
||||
} catch (Exception $e) {
|
||||
return $e->getMessage();
|
||||
}
|
||||
if ($response['OK']) {
|
||||
$tahesab->sh_factor = $response['Sh_factor'];
|
||||
$tahesab->tahesab_id = $response['OK'];
|
||||
$tahesab->factor_number = $response['Factor_Number'];
|
||||
$tahesab->tah_id = $response['ID'];
|
||||
$tahesab->res = $response;
|
||||
$tahesab->data = $data;
|
||||
$tahesab->save();
|
||||
return $data;
|
||||
}
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
// directon: 0 = daryaft az moshtari
|
||||
// directon: 1 = pardakht be moshtari
|
||||
public function wallet($input = null)
|
||||
{
|
||||
|
||||
if ($input instanceof \Illuminate\Http\Request) {
|
||||
$data = $input->all();
|
||||
} elseif (is_array($input)) {
|
||||
$data = $input;
|
||||
} else {
|
||||
$data = request()->all();
|
||||
}
|
||||
|
||||
if (!isset($data['customer_id']) || !isset($data['value'])) {
|
||||
return request()->expectsJson()
|
||||
? response()->json(['error' => 'Data missing: customer_id or value'], 422)
|
||||
: false;
|
||||
}
|
||||
|
||||
// $customer = auth()->user();
|
||||
// if (!$customer) {
|
||||
// throw new UnprocessableEntityHttpException("Auth needed");
|
||||
// }
|
||||
$customer = Customer::where('id', $data['customer_id'])->first();
|
||||
|
||||
if (!$customer || ($customer->moshtari_code === null)) {
|
||||
$this->store();
|
||||
}
|
||||
$tahesab = Tahesab::create([
|
||||
"customer_id" => $customer->id,
|
||||
"desc" => $data['direction'] == 0 ? "شارژ حساب" : "برداشت از حساب",
|
||||
"amount" => $data['value'],
|
||||
"date" => Carbon::now(),
|
||||
"created_at" => Carbon::now(),
|
||||
]);
|
||||
try {
|
||||
$response = Http::withoutVerifying()->timeout(10)->withHeaders([
|
||||
'DBName' => $this->Config('tahesab_db'),
|
||||
'Content-Type' => 'application/json',
|
||||
'Authorization' => "Bearer " . $this->Config('tahesab_token'),
|
||||
])->post('https://185.252.86.194:8081', [
|
||||
"DoNewSanadVKHBank" => [
|
||||
1,//Sabte_Kol_Or_Movaghat_1_0
|
||||
$customer->moshtari_code,//Moshtari_Code
|
||||
-1,//Factor_Number
|
||||
1,//Radif_Number
|
||||
1404,//Shamsi_Year
|
||||
10,//Shamsi_Month
|
||||
18,//Shamsi_Day
|
||||
$data['direction'],//IsDayaftAzMoshtariOrPardakhtBeMoshtari_0_1
|
||||
(int)$data['value'],//Mablagh
|
||||
$data['direction'] == 0 ? "شارژ حساب" : "برداشت از حساب",//Sharh
|
||||
"test",
|
||||
"$tahesab->id",//Code_Rahgiri
|
||||
-1,//Factor_Code
|
||||
-1,
|
||||
//MultiRadif
|
||||
]
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return $e->getMessage();
|
||||
}
|
||||
if ($response['OK']) {
|
||||
$tahesab->sh_factor = $response['Sh_factor'];
|
||||
$tahesab->tahesab_id = $response['OK'];
|
||||
$tahesab->save();
|
||||
return $data;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Controllers\SuperController;
|
||||
use App\Models\Permission;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class UserController extends SuperController
|
||||
{
|
||||
public function __construct(Request $request)
|
||||
{
|
||||
$model = User::class;
|
||||
// $with=['avatar','user_type_record'];
|
||||
$with=[];
|
||||
$select = ['*'];
|
||||
$name_model = 'user';
|
||||
$search=['name','mobile'];
|
||||
$request->request->add(['active'=>1]);
|
||||
parent::__construct($model, $with, $select, $name_model,null,$search);
|
||||
}
|
||||
|
||||
|
||||
public function me(){
|
||||
$user = User::with($this->with)
|
||||
->select($this->select)
|
||||
->findOrFail(auth()->id());
|
||||
// $permission = Permission::where('user_type',$user->user_type)->select('rid')->distinct('rid')->get()->pluck('rid')->toArray();
|
||||
// $user['permission'] = $permission;
|
||||
return response()->json($user);
|
||||
|
||||
}
|
||||
public function updateMe(Request $request){
|
||||
return parent::update($request,auth()->id());
|
||||
}
|
||||
public function getByUserType($user_type){
|
||||
$user = User::where('user_type',$user_type)->select('id','name','mobile')->get();
|
||||
return response()->json($user);
|
||||
}
|
||||
public function listUser(){
|
||||
$user = User::select('id','name','mobile','user_type')->get();
|
||||
return response()->json($user);
|
||||
}
|
||||
}
|
||||
+349
@@ -0,0 +1,349 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\DB\Te\TableEngine;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Customer;
|
||||
use App\Models\Order;
|
||||
use App\Models\Price;
|
||||
use App\Models\Product;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use App\Models\Withdraw;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Rooyesh\Wallet\interfaces\TransactionInterface;
|
||||
use Rooyesh\Wallet\interfaces\WalletInterface;
|
||||
use Rooyesh\Wallet\models\Transaction;
|
||||
use Rooyesh\Wallet\models\Wallet;
|
||||
use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException;
|
||||
use App\Http\Controllers\Admin\TahesabController;
|
||||
|
||||
|
||||
class WalletController extends Controller
|
||||
{
|
||||
public function charge2(Request $request)
|
||||
{
|
||||
$data = $request->all();
|
||||
$customer = Customer::findOrFail($data['customer_id']);
|
||||
$deposit = false;
|
||||
if ($data['value'] > 0) {
|
||||
$deposit = true;
|
||||
}
|
||||
$wallet = Wallet::where('owner', $data['customer_id'])->whereNull('fund_id')->first();
|
||||
if (is_null($wallet) && !$deposit) {
|
||||
throw new UnprocessableEntityHttpException('مقدار موجودی کمتر از درخواست شماست');
|
||||
}
|
||||
if (!is_null($wallet) && $wallet->cash < abs($data['value']) && !$deposit) {
|
||||
throw new UnprocessableEntityHttpException('مقدار موجودی کمتر از درخواست شماست');
|
||||
}
|
||||
$wallet_interface = new WalletInterface($data['customer_id'], $customer->type);
|
||||
$orders = Order::where('customer_id', $data['customer_id'])->where('sts', 1)->get();
|
||||
$gold_block = 0;
|
||||
if (count($orders) > 0) {
|
||||
$value = $data['value'];
|
||||
foreach ($orders as $order) {
|
||||
if ($value < $order->payment_remind) {
|
||||
$order->payment_amount += $value;
|
||||
$order->payment_remind -= $value;
|
||||
$order->save();
|
||||
break;
|
||||
} else {
|
||||
$value -= $order->payment_remind;
|
||||
$order->payment_amount = $order->total_price;
|
||||
$order->payment_remind = 0;
|
||||
$order->sts = 2;
|
||||
$gold_block -= $order->amount;
|
||||
$order->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
$user = auth()->user();
|
||||
$customer = Customer::findOrFail($data["customer_id"]);
|
||||
$Withdraw = Withdraw::create([
|
||||
'user_id' => $user->id,
|
||||
'customer_id' => $customer->id,
|
||||
"cash" => $data['value'],
|
||||
'sts' => 4,
|
||||
]);
|
||||
new TransactionInterface($wallet_interface, $_inp = [
|
||||
'cash' => $data['value'],
|
||||
'expire_at' => now(),
|
||||
'withdraw_id' => $Withdraw->id,
|
||||
'active' => true
|
||||
], 3, false, true, $gold_block);
|
||||
|
||||
$message = 'کیف پول شما به مبلغ ' . $data['value'] . " ریال در تاریخ " . verta()->format('Y/n/j H:i:s') . " شارژ شد " . "\n"
|
||||
. $this->Config('name_fa');
|
||||
$this->Send($customer->mobile, $message);
|
||||
return response()->json(true);
|
||||
}
|
||||
|
||||
public function charge(Request $request)
|
||||
{
|
||||
|
||||
$data = $request->all();
|
||||
$customer = Customer::findOrFail($data['customer_id']);
|
||||
$deposit = false;
|
||||
if ($data['value'] > 0) {
|
||||
$deposit = true;
|
||||
}
|
||||
$wallet = Wallet::where('owner', $data['customer_id'])->whereNull('fund_id')->first();
|
||||
if (is_null($wallet) && !$deposit) {
|
||||
throw new UnprocessableEntityHttpException('مقدار موجودی کمتر از درخواست شماست');
|
||||
}
|
||||
if (!is_null($wallet) && $wallet->cash < abs($data['value']) && !$deposit) {
|
||||
throw new UnprocessableEntityHttpException('مقدار موجودی کمتر از درخواست شماست');
|
||||
}
|
||||
$wallet_interface = new WalletInterface($data['customer_id'], $customer->type);
|
||||
$orders = Order::where('customer_id', $data['customer_id'])->where('sts', 1)->get();
|
||||
$gold_block = 0;
|
||||
|
||||
$user = auth()->user();
|
||||
$customer = Customer::findOrFail($data["customer_id"]);
|
||||
$Withdraw = Withdraw::create([
|
||||
'user_id' => $user->id,
|
||||
'customer_id' => $customer->id,
|
||||
"cash" => $data['value'],
|
||||
"note" => $data['note'],
|
||||
'sts' => 4,
|
||||
]);
|
||||
new TransactionInterface($wallet_interface, $_inp = [
|
||||
'gold' => 0,
|
||||
'cash' => $data['value'],
|
||||
'expire_at' => now(),
|
||||
"note" => $data['note'],
|
||||
'withdraw_id' => $Withdraw->id,
|
||||
'active' => true
|
||||
], 7, true, $deposit, $gold_block);
|
||||
|
||||
$data['direction'] = 0;
|
||||
// $tahesab = new TahesabController();
|
||||
// $tahesab->wallet($data);
|
||||
|
||||
$message = 'کیف پول شما به اندازه ' . number_format($data['value']) . " ریال در تاریخ " . verta()->format('Y/n/j H:i:s') . " اصلاح شد بابت" . "\n"
|
||||
. $data['note']
|
||||
. " "
|
||||
. $this->Config('name_fa');
|
||||
$this->Send($customer->mobile, $message);
|
||||
return response()->json(true);
|
||||
}
|
||||
public function charge_gold(Request $request)
|
||||
{
|
||||
|
||||
$data = $request->all();
|
||||
$customer = Customer::findOrFail($data['customer_id']);
|
||||
$deposit = false;
|
||||
if ($data['value'] > 0) {
|
||||
$deposit = true;
|
||||
|
||||
}
|
||||
$wallet = Wallet::where('owner', $data['customer_id'])->whereNull('fund_id')->first();
|
||||
// if (is_null($wallet) && !$deposit) {
|
||||
// throw new UnprocessableEntityHttpException('مقدار موجودی کمتر از درخواست شماست');
|
||||
// }
|
||||
// if (!is_null($wallet) && $wallet->cash < abs($data['value']) && !$deposit) {
|
||||
// throw new UnprocessableEntityHttpException('مقدار موجودی کمتر از درخواست شماست');
|
||||
// }
|
||||
$wallet_interface = new WalletInterface($data['customer_id'], $customer->type);
|
||||
$gold_block = 0;
|
||||
$user = auth()->user();
|
||||
$customer = Customer::findOrFail($data["customer_id"]);
|
||||
$Withdraw = Withdraw::create([
|
||||
'user_id' => $user->id,
|
||||
'customer_id' => $customer->id,
|
||||
"gold" => $data['value'],
|
||||
"note" => $data['note'],
|
||||
'sts' => 4,
|
||||
]);
|
||||
new TransactionInterface($wallet_interface, $_inp = [
|
||||
'cash' => 0,
|
||||
'gold' => $data['value'],
|
||||
'expire_at' => now(),
|
||||
"note" => $data['note'],
|
||||
'withdraw_id' => $Withdraw->id,
|
||||
'active' => true
|
||||
], 7, $deposit, false, $gold_block);
|
||||
|
||||
$message = 'کیف پول شما به اندازه ' . $data['value'] . " گرم در تاریخ " . verta()->format('Y/n/j H:i:s') . " شارژ شد بابت" . "\n"
|
||||
. $data['note']
|
||||
. $this->Config('name_fa');
|
||||
$this->Send($customer->mobile, $message);
|
||||
return response()->json(true);
|
||||
}
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
$records = Transaction::with(['customer'])->whereNull('fund_id');
|
||||
TableEngine::create($records, $request->all())
|
||||
->initSearch(['order_id', 'customer.name'])
|
||||
->select([
|
||||
'*', Transaction::$SELECT_CAJ, Transaction::$SELECT_TYPE_STR, Transaction::$SELECT_SAJ, Transaction::$SELECT_EAJ
|
||||
])->export($records);
|
||||
// foreach ($records['rows'] as &$record) {
|
||||
// if (empty($record->title) or $record->title == "تعریف نشده"){
|
||||
// $record->title = $record->type_str ;
|
||||
// $record->unit = "گرم";
|
||||
// if (isset($record->wallet)) {
|
||||
// $wallet = Wallet::with('product')->where('id',$record->wallet)->first();
|
||||
// if (isset($wallet->product)) {
|
||||
// if ($record->gold > 0){
|
||||
// $record->title = " خرید " ;
|
||||
//
|
||||
// }else{
|
||||
// $record->title = " فروش " ;
|
||||
//
|
||||
// }
|
||||
// $record->title .= $wallet->product->title ;
|
||||
// $record->unit = "عدد";
|
||||
//
|
||||
// }
|
||||
// }
|
||||
// $record->save();
|
||||
// }
|
||||
//
|
||||
// }
|
||||
|
||||
return response()->json($records);
|
||||
}
|
||||
|
||||
public function updateTransaction(Request $request)
|
||||
{
|
||||
$message = 'تراکنش تغیری نکرده.';
|
||||
$transaction = Transaction::find($request->id);
|
||||
$product = Product::find($transaction->product_id);
|
||||
|
||||
if (!$transaction) return response()->json(['error' => 'تراکنش یافت نشد.'], 404);
|
||||
|
||||
$difference = $request->input('number') - $transaction->number;
|
||||
if (abs($difference) < 0.0001) {
|
||||
return response()->json(['message' => $message], 422);
|
||||
}
|
||||
|
||||
$transaction->number = $request->input('number');
|
||||
$wallet_interface = new WalletInterface($transaction->customer_id, 2);
|
||||
|
||||
if ($wallet_interface->wallet->gold < $difference ) {
|
||||
if (!(isset($request->force) && $request->force === true)){
|
||||
return response()->json(['message' => "کاربر مورد نظر موجودی ندارد. موجودی فعلی: " . $wallet_interface->wallet->gold . " مقدار مورد نیاز: " . $difference,'type'=>406],422);
|
||||
}
|
||||
}
|
||||
$isDiposit = $difference > 0 ? 0 : 1;
|
||||
new TransactionInterface($wallet_interface, [
|
||||
"title" => "اصلاح سند " . $transaction->withdraw_id,
|
||||
"note" => $product->title,
|
||||
"product_id" => $product->id,
|
||||
"number" => 0,
|
||||
"gold" => $difference,
|
||||
'expire_at' => now(),
|
||||
'active' => true,
|
||||
'withdraw_id' => $transaction->withdraw_id,
|
||||
'start_at' => now(),
|
||||
], 51, $isDiposit, false);
|
||||
$transaction->save();
|
||||
$message = 'تراکنش با موفقیت بهروزرسانی شد.';
|
||||
|
||||
|
||||
return response()->json([
|
||||
'message' => $message,
|
||||
'transaction' => $transaction,
|
||||
// 'previous_amount' => $previousAmount,
|
||||
// 'new_amount' => $newAmount,
|
||||
'difference' => $difference,
|
||||
'wallet' => $wallet_interface->wallet,
|
||||
]);
|
||||
}
|
||||
|
||||
public function indexWallet(Request $request)
|
||||
{
|
||||
// محاسبهی مجموع gold و cash به ازای هر owner
|
||||
$records = Wallet::with('customer');
|
||||
|
||||
|
||||
// ایجاد جدول با استفاده از TableEngine
|
||||
TableEngine::create($records, $request->all())
|
||||
->initSearch(['customer.name'])
|
||||
->select(['*'])
|
||||
->export($records);
|
||||
|
||||
// محاسبهی قیمت آخرین قیمت و مجموع کلی مقادیر gold و cash
|
||||
$lastPrice = Price::latest()->first()->price;
|
||||
$walletQuery = Wallet::where('owner', '!=', 4)->where('product_id', null);
|
||||
$sums = [
|
||||
"gold" => round($walletQuery->sum('gold'), 2),
|
||||
"goldToCash" => round($walletQuery->sum('gold') * $lastPrice, 2),
|
||||
"cash" => round($walletQuery->sum('cash'), 2),
|
||||
"cashToGold" => round($walletQuery->sum('cash') / $lastPrice, 2),
|
||||
];
|
||||
|
||||
// $sums = [
|
||||
// "gold" => round(Wallet::whereNot('owner', 4)->sum('gold'), 2),
|
||||
// "goldToCash" => round(Wallet::sum('gold') * $lastPrice, 2),
|
||||
// "cash" => round(Wallet::sum('cash'), 2),
|
||||
// "cashToGold" => round(Wallet::sum('cash') / $lastPrice, 2),
|
||||
// "on" => $lastPrice,
|
||||
// ];
|
||||
|
||||
// افزودن sums به records
|
||||
$records['sums'] = $sums;
|
||||
|
||||
return response()->json($records);
|
||||
}
|
||||
|
||||
public function indexWithdraw(Request $request)
|
||||
{
|
||||
$records = Withdraw::with(['customer', 'bank_account', 'Address', "Transaction"]);
|
||||
TableEngine::create($records, $request->all())
|
||||
->initSearch(['customer.name'])
|
||||
->select([
|
||||
'*', Withdraw::$SELECT_STS_STR, Withdraw::$SELECT_DAJ
|
||||
])->export($records);
|
||||
return response()->json($records);
|
||||
}
|
||||
|
||||
public function updateWithdraw(Request $request, $id)
|
||||
{
|
||||
// پیدا کردن رکورد Withdraw با استفاده از شناسه
|
||||
$withdraw = Withdraw::find($id);
|
||||
// بررسی وجود رکورد
|
||||
if (!$withdraw) {
|
||||
return response()->json(['error' => 'Withdraw not found'], 404);
|
||||
}
|
||||
$withdraw->sts = $request->sts;
|
||||
$withdraw->save();
|
||||
return response()->json(['message' => 'Withdraw updated successfully', 'withdraw' => $withdraw]);
|
||||
}
|
||||
|
||||
public function getWithdraw(Request $request, $id)
|
||||
{
|
||||
// پیدا کردن رکورد Withdraw با استفاده از شناسه
|
||||
return $withdraw = Withdraw::with(['customer', 'bank_account', 'Address', "Transaction"])->find($id);
|
||||
// بررسی وجود رکورد
|
||||
if (!$withdraw) {
|
||||
return response()->json(['error' => 'Withdraw not found'], 404);
|
||||
}
|
||||
$withdraw->sts = $request->sts;
|
||||
$withdraw->save();
|
||||
return response()->json(['message' => 'Withdraw updated successfully', 'withdraw' => $withdraw]);
|
||||
}
|
||||
|
||||
public function completeWithdraw(Request $request)
|
||||
{
|
||||
$data = $request->all();
|
||||
$data['user_id'] = auth('user')->id();
|
||||
$data['sts'] = 2;
|
||||
$data['date_at'] = now();
|
||||
Withdraw::findOrFail($data['id'])->update($data);
|
||||
$withdraw = Withdraw::findOrFail($data['id']);
|
||||
$withdraw->update($data);
|
||||
// $tahesab = new TahesabController();
|
||||
// $tahesab->wallet([
|
||||
// 'customer_id' => $withdraw->customer_id,
|
||||
// 'value' => $withdraw->cash,
|
||||
// 'direction' => 1,
|
||||
// 'note' => 'برداشت از کیف پول شماره ' . $withdraw->id,
|
||||
// ]);
|
||||
return response()->json(true);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user