diff --git a/app/Http/Controllers/Admin/TahesabController.php b/app/Http/Controllers/Admin/TahesabController.php index 497f02b..d22682e 100644 --- a/app/Http/Controllers/Admin/TahesabController.php +++ b/app/Http/Controllers/Admin/TahesabController.php @@ -3,6 +3,7 @@ namespace App\Http\Controllers\Admin; use App\Http\Controllers\Controller; +use App\Http\Controllers\Site\ReportController; use Carbon\Carbon; use Illuminate\Http\Request; use Illuminate\Support\Facades\Http; @@ -141,6 +142,10 @@ class TahesabController extends Controller "date" => Carbon::now(), "created_at" => Carbon::now(), ]); + + $date = Verta::instance(Carbon::now())->format('Y-m-d'); + [$year, $month, $day] = explode('-', $date); + try { $response = Http::withoutVerifying()->timeout(10)->withHeaders([ 'DBName' => $this->Config('tahesab_db'), @@ -152,9 +157,9 @@ class TahesabController extends Controller $customer->moshtari_code,//Moshtari_Code -1,//Factor_Number 1,//Radif_Number - 1404,//Shamsi_Year - 10,//Shamsi_Month - 18,//Shamsi_Day + $year,//Shamsi_Year + $month,//Shamsi_Month + $day,//Shamsi_Day $data['direction'],//IsDayaftAzMoshtariOrPardakhtBeMoshtari_0_1 (int)$data['value'],//Mablagh $data['direction'] == 0 ? "شارژ حساب" : "برداشت از حساب",//Sharh @@ -177,6 +182,98 @@ class TahesabController extends Controller return false; } + public function walletGold($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'])) { + 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->create_user($customer->id); + $customer = Customer::where('id', $data['customer_id'])->first(); + } + + $date = Verta::instance(Carbon::now())->format('Y-m-d'); + [$year, $month, $day] = explode('-', $date); + + $amount = $data['value']; + + $tahesab = Tahesab::create([ + "customer_id" => $customer->id, + "desc" => $data['direction'] == 0 ? "شارژ کیف پول آبشده" : "برداشت از کیف پول آبشده", + "amount" => $amount, + "date" => Carbon::now(), + "type" => "طلا", + "created_at" => Carbon::now(), + ]); + + $price = new ReportController(); + $prices = $price->lastPrice(); + try { + $response = Http::withoutVerifying()->timeout(10)->withHeaders([ + 'DBName' => $this->Config('tahesab_db'), + 'Content-Type' => 'application/json', + 'Authorization' => "Bearer " . $this->Config('tahesab_token'), + ])->post((string)env('TAHESAB'), [ + "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 + 750, //Ayar + 0, + "", + $data['direction'], //BuyOrSale_0_1 + $data['direction'] == 0 ? (int)$prices['buy'] : (int)$prices['sell'], //Mazaneh + 1, //MazanehIsMesghalOrGeram_0_1 + 1, //IsMotefaregheOrAbshode_0_1 + $data['direction'] == 0 ? (int)$prices['buy'] * $amount : (int)$prices['sell'] * $amount, //MablaghKol + $data['direction'] == 0 ? "خرید آبشده" : "فروش آبشده",//Sharh + "Code_Factor", + "", //HavalehBe_Mcode + "", //MultiRadif + 0, //Jens_Felez + (string)$date, + ] + ]); + } 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; + + } + private function create_user($customer_id) { diff --git a/app/Http/Controllers/Admin/WalletController.php b/app/Http/Controllers/Admin/WalletController.php index 1f810a8..6a864a8 100644 --- a/app/Http/Controllers/Admin/WalletController.php +++ b/app/Http/Controllers/Admin/WalletController.php @@ -121,7 +121,7 @@ class WalletController extends Controller if($this->Config('send_to_tahesab') == "true"){ try { - $data['direction'] = 0; + $data['direction'] = $deposit ? 0 : 1; $tahesab = new TahesabController(); $tahesab->wallet($data); }catch (\Exception $e){ @@ -185,6 +185,16 @@ class WalletController extends Controller 'active' => true ], 7, $deposit, false, $gold_block); + //send to tahesan + if($this->Config('send_to_tahesab') == "true"){ + try { + $data['direction'] = $deposit ? 0 : 1; + $tahesab = new TahesabController(); + $tahesab->walletGold($data); + }catch (\Exception $e){ + return response($e->getMessage(), 500); + } + } //send sms to users and customer $status = $data['value'] > 0 ?" شارژ شد ": " کسر شد "; if($this->Config('charge_notif') == "true"){