added some feature for accounting and price 6
This commit is contained in:
@@ -197,14 +197,14 @@ class TahesabController extends Controller
|
|||||||
// directon: 1 = pardakht be moshtari
|
// directon: 1 = pardakht be moshtari
|
||||||
public function wallet($data, ?Tahesab $existing = null)
|
public function wallet($data, ?Tahesab $existing = null)
|
||||||
{
|
{
|
||||||
|
if (empty($data['customer_id']) && $existing) {
|
||||||
// if ($input instanceof \Illuminate\Http\Request) {
|
$data = array_merge($data, [
|
||||||
// $data = $input->all();
|
'customer_id' => $existing->customer_id,
|
||||||
// } elseif (is_array($input)) {
|
'value' => $existing->amount,
|
||||||
// $data = $input;
|
'direction' => str_contains((string) $existing->desc, 'برداشت') ? 1 : 0,
|
||||||
// } else {
|
'withdraw_id' => $existing->withdraw_id,
|
||||||
// $data = request()->all();
|
]);
|
||||||
// }
|
}
|
||||||
|
|
||||||
if (!isset($data['customer_id']) || !isset($data['value'])) {
|
if (!isset($data['customer_id']) || !isset($data['value'])) {
|
||||||
return request()->expectsJson()
|
return request()->expectsJson()
|
||||||
@@ -234,7 +234,12 @@ class TahesabController extends Controller
|
|||||||
"data" => json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT),
|
"data" => json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$date = Verta::instance(Carbon::now())->format('Y-m-d');
|
if ($existing && empty($existing->data)) {
|
||||||
|
$existing->update(['data' => json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT)]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$dateSource = ($existing !== null && !empty($existing->date)) ? Carbon::parse($existing->date) : Carbon::now();
|
||||||
|
$date = Verta::instance($dateSource)->format('Y-m-d');
|
||||||
[$year, $month, $day] = explode('-', $date);
|
[$year, $month, $day] = explode('-', $date);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -384,6 +389,14 @@ class TahesabController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function goldReward($data, ?Tahesab $existing = null)
|
public function goldReward($data, ?Tahesab $existing = null)
|
||||||
{
|
{
|
||||||
|
if (empty($data['customer_id']) && $existing) {
|
||||||
|
$data = array_merge($data, [
|
||||||
|
'customer_id' => $existing->customer_id,
|
||||||
|
'value' => $existing->amount,
|
||||||
|
'desc' => $existing->desc,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
if (!isset($data['customer_id'], $data['value'])) {
|
if (!isset($data['customer_id'], $data['value'])) {
|
||||||
return request()->expectsJson()
|
return request()->expectsJson()
|
||||||
? response()->json(['error' => 'Data missing: customer_id or value'], 422)
|
? response()->json(['error' => 'Data missing: customer_id or value'], 422)
|
||||||
@@ -403,9 +416,6 @@ class TahesabController extends Controller
|
|||||||
$amount = abs((float) $data['value']);
|
$amount = abs((float) $data['value']);
|
||||||
$desc = !empty($data['desc']) ? (string) $data['desc'] : 'پاداش';
|
$desc = !empty($data['desc']) ? (string) $data['desc'] : 'پاداش';
|
||||||
|
|
||||||
$date = Verta::instance(Carbon::now())->format('Y-m-d');
|
|
||||||
[$year, $month, $day] = explode('-', $date);
|
|
||||||
|
|
||||||
$data['handler'] = 'goldReward';
|
$data['handler'] = 'goldReward';
|
||||||
$tahesab = $existing ?? Tahesab::create([
|
$tahesab = $existing ?? Tahesab::create([
|
||||||
'customer_id' => $customer->id,
|
'customer_id' => $customer->id,
|
||||||
@@ -417,6 +427,14 @@ class TahesabController extends Controller
|
|||||||
'data' => json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT),
|
'data' => json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
if ($existing && empty($existing->data)) {
|
||||||
|
$existing->update(['data' => json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT)]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$dateSource = ($existing !== null && !empty($existing->date)) ? Carbon::parse($existing->date) : Carbon::now();
|
||||||
|
$date = Verta::instance($dateSource)->format('Y-m-d');
|
||||||
|
[$year, $month, $day] = explode('-', $date);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$response = Http::withoutVerifying()->timeout(10)->withHeaders([
|
$response = Http::withoutVerifying()->timeout(10)->withHeaders([
|
||||||
'DBName' => $this->Config('tahesab_db'),
|
'DBName' => $this->Config('tahesab_db'),
|
||||||
@@ -460,25 +478,21 @@ class TahesabController extends Controller
|
|||||||
// direction: 1 = واریز طلا (خرید)، 0 = برداشت طلا (فروش)
|
// direction: 1 = واریز طلا (خرید)، 0 = برداشت طلا (فروش)
|
||||||
public function walletGold($data, ?Tahesab $existing = null)
|
public function walletGold($data, ?Tahesab $existing = null)
|
||||||
{
|
{
|
||||||
// if ($input instanceof \Illuminate\Http\Request) {
|
if (empty($data['customer_id']) && $existing) {
|
||||||
// $data = $input->all();
|
$data = array_merge($data, [
|
||||||
// } elseif (is_array($input)) {
|
'customer_id' => $existing->customer_id,
|
||||||
// $data = $input;
|
'value' => $existing->amount,
|
||||||
// } else {
|
'direction' => str_contains((string) $existing->desc, 'برداشت') ? 0 : 1,
|
||||||
// $data = request()->all();
|
'withdraw_id' => $existing->withdraw_id,
|
||||||
// }
|
]);
|
||||||
// return ($data);
|
}
|
||||||
|
|
||||||
if (!isset($data['customer_id'])) {
|
if (!isset($data['customer_id'], $data['value'])) {
|
||||||
return request()->expectsJson()
|
return request()->expectsJson()
|
||||||
? response()->json(['error' => 'Data missing: customer_id or value'], 422)
|
? response()->json(['error' => 'Data missing: customer_id or value'], 422)
|
||||||
: false;
|
: false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// $customer = auth()->user();
|
|
||||||
// if (!$customer) {
|
|
||||||
// throw new UnprocessableEntityHttpException("Auth needed");
|
|
||||||
// }
|
|
||||||
$customer = Customer::where('id', $data['customer_id'])->first();
|
$customer = Customer::where('id', $data['customer_id'])->first();
|
||||||
|
|
||||||
if ($customer && ($customer->moshtari_code === null)) {
|
if ($customer && ($customer->moshtari_code === null)) {
|
||||||
@@ -486,9 +500,6 @@ class TahesabController extends Controller
|
|||||||
$customer = Customer::where('id', $data['customer_id'])->first();
|
$customer = Customer::where('id', $data['customer_id'])->first();
|
||||||
}
|
}
|
||||||
|
|
||||||
$date = Verta::instance(Carbon::now())->format('Y-m-d');
|
|
||||||
[$year, $month, $day] = explode('-', $date);
|
|
||||||
|
|
||||||
$amount = abs($data['value']);
|
$amount = abs($data['value']);
|
||||||
$buyOrSale = (int) ($data['direction'] ?? 1) === 1 ? 1 : 0;
|
$buyOrSale = (int) ($data['direction'] ?? 1) === 1 ? 1 : 0;
|
||||||
$isDeposit = $buyOrSale === 1;
|
$isDeposit = $buyOrSale === 1;
|
||||||
@@ -505,6 +516,14 @@ class TahesabController extends Controller
|
|||||||
"data" => json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT),
|
"data" => json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
if ($existing && empty($existing->data)) {
|
||||||
|
$existing->update(['data' => json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT)]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$dateSource = ($existing !== null && !empty($existing->date)) ? Carbon::parse($existing->date) : Carbon::now();
|
||||||
|
$date = Verta::instance($dateSource)->format('Y-m-d');
|
||||||
|
[$year, $month, $day] = explode('-', $date);
|
||||||
|
|
||||||
$prices = $this->lastPriceData();
|
$prices = $this->lastPriceData();
|
||||||
|
|
||||||
$mazaneh = $isDeposit ? (int) ($prices['buy'] ?? 0) : (int) ($prices['sell'] ?? 0);
|
$mazaneh = $isDeposit ? (int) ($prices['buy'] ?? 0) : (int) ($prices['sell'] ?? 0);
|
||||||
|
|||||||
Reference in New Issue
Block a user