fix tahesab
This commit is contained in:
@@ -218,11 +218,10 @@ class CustomerController extends SuperController
|
|||||||
if($this->Config('send_to_tahesab') == "true"){
|
if($this->Config('send_to_tahesab') == "true"){
|
||||||
try {
|
try {
|
||||||
$tahesab = new TahesabController();
|
$tahesab = new TahesabController();
|
||||||
$tahesab->walletGold([
|
$tahesab->goldReward([
|
||||||
'customer_id'=> $customer->id,
|
'customer_id' => $customer->referral->id,
|
||||||
'value'=> $gift_for_inviter,
|
'value' => $gift_for_inviter,
|
||||||
'direction'=> 0,
|
'desc' => 'پاداش بابت معرفی',
|
||||||
'desc' => 'پاداش بابت معرفی'
|
|
||||||
]);
|
]);
|
||||||
}catch (\Exception $e){
|
}catch (\Exception $e){
|
||||||
return response($e->getMessage(), 500);
|
return response($e->getMessage(), 500);
|
||||||
@@ -268,11 +267,10 @@ class CustomerController extends SuperController
|
|||||||
if($this->Config('send_to_tahesab') == "true"){
|
if($this->Config('send_to_tahesab') == "true"){
|
||||||
try {
|
try {
|
||||||
$tahesab = new TahesabController();
|
$tahesab = new TahesabController();
|
||||||
$tahesab->walletGold([
|
$tahesab->goldReward([
|
||||||
'customer_id'=> $customer->id,
|
'customer_id' => $customer->id,
|
||||||
'value'=> $gift_for_inviter,
|
'value' => $gift_for_invited,
|
||||||
'direction'=> 0,
|
'desc' => 'پاداش بابت ثبت نام',
|
||||||
'desc' => 'پاداش بابت ثبت نام'
|
|
||||||
]);
|
]);
|
||||||
}catch (\Exception $e){
|
}catch (\Exception $e){
|
||||||
return response($e->getMessage(), 500);
|
return response($e->getMessage(), 500);
|
||||||
|
|||||||
@@ -48,6 +48,10 @@ class TahesabController extends Controller
|
|||||||
[$year, $month, $day] = explode('-', $date);
|
[$year, $month, $day] = explode('-', $date);
|
||||||
|
|
||||||
$amount = $data['amount'];
|
$amount = $data['amount'];
|
||||||
|
$isBuy = (int) ($data['direction'] ?? 0) === 1;
|
||||||
|
$mablaghKol = $isBuy
|
||||||
|
? (int) round((float) $amount * (float) $data['price'])
|
||||||
|
: (int) ($data['total_price'] ?? round((float) $amount * (float) $data['price']));
|
||||||
|
|
||||||
$tahesab = Tahesab::create([
|
$tahesab = Tahesab::create([
|
||||||
"customer_id" => $customer->id,
|
"customer_id" => $customer->id,
|
||||||
@@ -81,16 +85,16 @@ class TahesabController extends Controller
|
|||||||
(int)$data['price'], //Mazaneh
|
(int)$data['price'], //Mazaneh
|
||||||
1, //MazanehIsMesghalOrGeram_0_1
|
1, //MazanehIsMesghalOrGeram_0_1
|
||||||
1, //IsMotefaregheOrAbshode_0_1
|
1, //IsMotefaregheOrAbshode_0_1
|
||||||
(int)$data['total_price'], //MablaghKol
|
$mablaghKol, //MablaghKol — خرید: وزن خالص × قیمت (بعد از کارمزد)
|
||||||
$data['direction'] == 1 ? "خرید آبشده" : "فروش آبشده", //sharh
|
$data['direction'] == 1 ? "خرید آبشده" : "فروش آبشده", //sharh
|
||||||
"Code_Factor",
|
-1, //Factor_Code — خودکار
|
||||||
"", //HavalehBe_Mcode
|
-1, //HavalehBe_Mcode
|
||||||
"", //MultiRadif
|
-1, //MultiRadif
|
||||||
$data['product']['metal_id'] == 1 ? 0 : 2, //Jens_Felez
|
$data['product']['metal_id'] == 1 ? 0 : 2, //Jens_Felez
|
||||||
(string)Verta::instance($data['pay_at']),
|
(string)Verta::instance($data['pay_at']),
|
||||||
]
|
]
|
||||||
])->json();
|
])->json();
|
||||||
} catch (Exception $e) {
|
} catch (\Exception $e) {
|
||||||
return $e->getMessage();
|
return $e->getMessage();
|
||||||
}
|
}
|
||||||
if ($response['OK']) {
|
if ($response['OK']) {
|
||||||
@@ -98,7 +102,7 @@ class TahesabController extends Controller
|
|||||||
"sh_factor" => $response['Sh_factor'],
|
"sh_factor" => $response['Sh_factor'],
|
||||||
"tahesab_id" => $response['OK'],
|
"tahesab_id" => $response['OK'],
|
||||||
"factor_number" => $response['Factor_Number'],
|
"factor_number" => $response['Factor_Number'],
|
||||||
"tah_id" => $response['ID'],
|
"tah_id" => $response['ID'] ?? null,
|
||||||
"data" => json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT),
|
"data" => json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT),
|
||||||
"res" => json_encode($response, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT),
|
"res" => json_encode($response, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT),
|
||||||
]);
|
]);
|
||||||
@@ -281,6 +285,89 @@ class TahesabController extends Controller
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* پاداش/هدیه طلایی — سند بدهی وزنی (مثل ثبت دستی «بدهی / بابت معرفی» در تهحساب).
|
||||||
|
*/
|
||||||
|
public function goldReward($data)
|
||||||
|
{
|
||||||
|
if (!isset($data['customer_id'], $data['value'])) {
|
||||||
|
return request()->expectsJson()
|
||||||
|
? response()->json(['error' => 'Data missing: customer_id or value'], 422)
|
||||||
|
: false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$customer = Customer::where('id', $data['customer_id'])->first();
|
||||||
|
if (!$customer) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($customer->moshtari_code === null) {
|
||||||
|
$this->create_user($customer->id);
|
||||||
|
$customer = Customer::where('id', $data['customer_id'])->first();
|
||||||
|
}
|
||||||
|
|
||||||
|
$amount = abs((float) $data['value']);
|
||||||
|
$desc = !empty($data['desc']) ? (string) $data['desc'] : 'پاداش';
|
||||||
|
|
||||||
|
$date = Verta::instance(Carbon::now())->format('Y-m-d');
|
||||||
|
[$year, $month, $day] = explode('-', $date);
|
||||||
|
|
||||||
|
$tahesab = Tahesab::create([
|
||||||
|
'customer_id' => $customer->id,
|
||||||
|
'desc' => $desc,
|
||||||
|
'amount' => $amount,
|
||||||
|
'date' => Carbon::now(),
|
||||||
|
'type' => 'طلا',
|
||||||
|
'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((string) env('TAHESAB'), [
|
||||||
|
'DoNewSanadTalabBedehi' => [
|
||||||
|
1, // Sabte_Kol
|
||||||
|
(int) $customer->moshtari_code,
|
||||||
|
-1, // Factor_Number
|
||||||
|
1, // Radif_Number
|
||||||
|
(int) $year,
|
||||||
|
(int) $month,
|
||||||
|
(int) $day,
|
||||||
|
0, // IsBedehiOrTalab — بدهی (فروشگاه به مشتری طلا بدهکار است)
|
||||||
|
0, // MablaghKol — بدون مبلغ ریالی
|
||||||
|
$desc,
|
||||||
|
$desc, // Baabat
|
||||||
|
(float) $amount,
|
||||||
|
-1, // Factor_Code
|
||||||
|
-1, // HavalehBe_Mcode
|
||||||
|
-1, // MultiRadif
|
||||||
|
0, // Jens_Felez — طلا
|
||||||
|
'IRR',
|
||||||
|
],
|
||||||
|
])->json();
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $e->getMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($response['OK']) {
|
||||||
|
Tahesab::where('id', $tahesab->id)->update([
|
||||||
|
'sh_factor' => $response['Sh_factor'] ?? null,
|
||||||
|
'tahesab_id' => $response['OK'],
|
||||||
|
'factor_number' => $response['Factor_Number'] ?? null,
|
||||||
|
'tah_id' => $response['ID'] ?? null,
|
||||||
|
'data' => json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT),
|
||||||
|
'res' => json_encode($response, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT),
|
||||||
|
]);
|
||||||
|
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// direction: 1 = واریز طلا (خرید)، 0 = برداشت طلا (فروش)
|
||||||
public function walletGold($data)
|
public function walletGold($data)
|
||||||
{
|
{
|
||||||
// if ($input instanceof \Illuminate\Http\Request) {
|
// if ($input instanceof \Illuminate\Http\Request) {
|
||||||
@@ -313,10 +400,12 @@ class TahesabController extends Controller
|
|||||||
[$year, $month, $day] = explode('-', $date);
|
[$year, $month, $day] = explode('-', $date);
|
||||||
|
|
||||||
$amount = abs($data['value']);
|
$amount = abs($data['value']);
|
||||||
|
$buyOrSale = (int) ($data['direction'] ?? 1) === 1 ? 1 : 0;
|
||||||
|
$isDeposit = $buyOrSale === 1;
|
||||||
|
|
||||||
$tahesab = Tahesab::create([
|
$tahesab = Tahesab::create([
|
||||||
"customer_id" => $customer->id,
|
"customer_id" => $customer->id,
|
||||||
"desc" => $data['direction'] == 0 ? "شارژ کیف پول آبشده" : "برداشت از کیف پول آبشده",
|
"desc" => $isDeposit ? "شارژ کیف پول آبشده" : "برداشت از کیف پول آبشده",
|
||||||
"amount" => $amount,
|
"amount" => $amount,
|
||||||
"date" => Carbon::now(),
|
"date" => Carbon::now(),
|
||||||
"type" => "طلا",
|
"type" => "طلا",
|
||||||
@@ -325,6 +414,12 @@ class TahesabController extends Controller
|
|||||||
|
|
||||||
$price = new ReportController();
|
$price = new ReportController();
|
||||||
$prices = $price->lastPrice();
|
$prices = $price->lastPrice();
|
||||||
|
$mazaneh = $isDeposit ? (int) $prices['buy'] : (int) $prices['sell'];
|
||||||
|
$mablaghKol = (int) round($mazaneh * $amount);
|
||||||
|
$sharh = !empty($data['desc'])
|
||||||
|
? $data['desc']
|
||||||
|
: ($isDeposit ? 'خرید آبشده' : 'فروش آبشده');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$response = Http::withoutVerifying()->timeout(10)->withHeaders([
|
$response = Http::withoutVerifying()->timeout(10)->withHeaders([
|
||||||
'DBName' => $this->Config('tahesab_db'),
|
'DBName' => $this->Config('tahesab_db'),
|
||||||
@@ -343,22 +438,20 @@ class TahesabController extends Controller
|
|||||||
750, //Ayar
|
750, //Ayar
|
||||||
0,
|
0,
|
||||||
"",
|
"",
|
||||||
$data['direction'], //BuyOrSale_0_1
|
$buyOrSale, //BuyOrSale_0_1 — 1=خرید، 0=فروش
|
||||||
$data['direction'] == 0 ? (int)$prices['buy'] : (int)$prices['sell'], //Mazaneh
|
$mazaneh, //Mazaneh
|
||||||
1, //MazanehIsMesghalOrGeram_0_1
|
1, //MazanehIsMesghalOrGeram_0_1
|
||||||
1, //IsMotefaregheOrAbshode_0_1
|
1, //IsMotefaregheOrAbshode_0_1
|
||||||
$data['direction'] == 0 ? (int)$prices['buy'] * $amount : (int)$prices['sell'] * $amount, //MablaghKol
|
$mablaghKol, //MablaghKol
|
||||||
!empty($data['desc'])
|
$sharh,//Sharh
|
||||||
? $data['desc']
|
-1, //Factor_Code — خودکار
|
||||||
: (($data['direction'] ?? null) == 0 ? "خرید آبشده" : "فروش آبشده"),//Sharh
|
-1, //HavalehBe_Mcode
|
||||||
"Code_Factor",
|
-1, //MultiRadif
|
||||||
"", //HavalehBe_Mcode
|
|
||||||
"", //MultiRadif
|
|
||||||
0, //Jens_Felez
|
0, //Jens_Felez
|
||||||
(string)$date,
|
(string)$date,
|
||||||
]
|
]
|
||||||
])->json();
|
])->json();
|
||||||
} catch (Exception $e) {
|
} catch (\Exception $e) {
|
||||||
return $e->getMessage();
|
return $e->getMessage();
|
||||||
}
|
}
|
||||||
if ($response['OK']) {
|
if ($response['OK']) {
|
||||||
@@ -366,7 +459,7 @@ class TahesabController extends Controller
|
|||||||
"sh_factor" => $response['Sh_factor'],
|
"sh_factor" => $response['Sh_factor'],
|
||||||
"tahesab_id" => $response['OK'],
|
"tahesab_id" => $response['OK'],
|
||||||
"factor_number" => $response['Factor_Number'],
|
"factor_number" => $response['Factor_Number'],
|
||||||
"tah_id" => $response['ID'],
|
"tah_id" => $response['ID'] ?? null,
|
||||||
"data" => json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT),
|
"data" => json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT),
|
||||||
"res" => json_encode($response, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT),
|
"res" => json_encode($response, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT),
|
||||||
]);
|
]);
|
||||||
|
|||||||
@@ -189,7 +189,7 @@ class WalletController extends Controller
|
|||||||
//send to tahesan
|
//send to tahesan
|
||||||
if($this->Config('send_to_tahesab') == "true"){
|
if($this->Config('send_to_tahesab') == "true"){
|
||||||
try {
|
try {
|
||||||
$data['direction'] = $deposit ? 1 : 2;
|
$data['direction'] = $deposit ? 1 : 0;
|
||||||
$tahesab = new TahesabController();
|
$tahesab = new TahesabController();
|
||||||
$tahesab->walletGold($data);
|
$tahesab->walletGold($data);
|
||||||
}catch (\Exception $e){
|
}catch (\Exception $e){
|
||||||
|
|||||||
@@ -220,11 +220,10 @@ class CustomerController extends Controller
|
|||||||
if($this->Config('send_to_tahesab') == "true"){
|
if($this->Config('send_to_tahesab') == "true"){
|
||||||
try {
|
try {
|
||||||
$tahesab = new TahesabController();
|
$tahesab = new TahesabController();
|
||||||
$tahesab->walletGold([
|
$tahesab->goldReward([
|
||||||
'customer_id'=> $customer->id,
|
'customer_id' => $customer->referral->id,
|
||||||
'value'=> $gift_for_inviter,
|
'value' => $gift_for_inviter,
|
||||||
'direction'=> 0,
|
'desc' => 'پاداش بابت معرفی',
|
||||||
'desc' => 'پاداش بابت معرفی'
|
|
||||||
]);
|
]);
|
||||||
}catch (\Exception $e){
|
}catch (\Exception $e){
|
||||||
return response($e->getMessage(), 500);
|
return response($e->getMessage(), 500);
|
||||||
@@ -270,11 +269,10 @@ class CustomerController extends Controller
|
|||||||
if($this->Config('send_to_tahesab') == "true"){
|
if($this->Config('send_to_tahesab') == "true"){
|
||||||
try {
|
try {
|
||||||
$tahesab = new TahesabController();
|
$tahesab = new TahesabController();
|
||||||
$tahesab->walletGold([
|
$tahesab->goldReward([
|
||||||
'customer_id'=> $customer->id,
|
'customer_id' => $customer->id,
|
||||||
'value'=> $gift_for_inviter,
|
'value' => $gift_for_invited,
|
||||||
'direction'=> 0,
|
'desc' => 'پاداش بابت ثبت نام',
|
||||||
'desc' => 'پاداش بابت ثبت نام'
|
|
||||||
]);
|
]);
|
||||||
}catch (\Exception $e){
|
}catch (\Exception $e){
|
||||||
return response($e->getMessage(), 500);
|
return response($e->getMessage(), 500);
|
||||||
|
|||||||
Reference in New Issue
Block a user