NASER optimize tahesab controller
This commit is contained in:
@@ -15,77 +15,6 @@ use Hekmatinasser\Verta\Verta;
|
|||||||
|
|
||||||
class TahesabController extends Controller
|
class TahesabController extends Controller
|
||||||
{
|
{
|
||||||
public function create_user($customer_id)
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
$customer = Customer::findOrFail($customer_id);
|
|
||||||
|
|
||||||
if ($customer && ($customer->moshtari_code == null)) {
|
|
||||||
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'), [
|
|
||||||
"DoNewMoshtari" => [
|
|
||||||
(string)$customer->name,
|
|
||||||
$this->Config('name_fa'),
|
|
||||||
(string)$customer->mobile,
|
|
||||||
"",
|
|
||||||
"",
|
|
||||||
"",
|
|
||||||
"",
|
|
||||||
"",
|
|
||||||
-1,
|
|
||||||
0
|
|
||||||
]
|
|
||||||
//{"DoNewMoshtari":["Name", "GroupName", "Tel", "Address", "CodeMeli", "Tarikh_Tavalod", "Moaref", "Code_Moaref", Moshtari_Code, Jens_Felez]}
|
|
||||||
]);
|
|
||||||
if (!empty($response['OK'])) {
|
|
||||||
$customer->moshtari_code = $response['OK'];
|
|
||||||
$customer->save();
|
|
||||||
}
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
return $e->getMessage();
|
|
||||||
}
|
|
||||||
}else {
|
|
||||||
if($customer && $customer->birth_date !== null){
|
|
||||||
$birth_date = Verta::instance(Carbon::parse($customer->birth_date))->format('Y-m-d');
|
|
||||||
}
|
|
||||||
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'), [
|
|
||||||
"DoEditMoshtari" => [
|
|
||||||
$customer->name,
|
|
||||||
$this->Config('name_fa'),
|
|
||||||
$customer->mobile,
|
|
||||||
"",
|
|
||||||
$customer->n_code ?? "",
|
|
||||||
$birth_date ?? "",
|
|
||||||
"",
|
|
||||||
"",
|
|
||||||
(int)$customer->moshtari_code,
|
|
||||||
0 // tala
|
|
||||||
]
|
|
||||||
//{"DoEditMoshtari":["Name","GroupName", "Tel", "Address", "CodeMeli", "Tarikh_Tavalod", "Moaref", "Code_Moaref", Moshtari_Code]}
|
|
||||||
]);
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
return response($e->getMessage(), 500);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
if (empty($response['OK'])) {
|
|
||||||
return "tahesab api error!!!";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return true;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public function storeTrade($input = null)
|
public function storeTrade($input = null)
|
||||||
{
|
{
|
||||||
@@ -111,7 +40,8 @@ class TahesabController extends Controller
|
|||||||
$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)) {
|
||||||
$this->store();
|
$this->create_user($customer->id);
|
||||||
|
$customer = Customer::where('id', $data['customer_id'])->first();
|
||||||
}
|
}
|
||||||
$date = Verta::instance(Carbon::parse($data['pay_at']))->format('Y-m-d');
|
$date = Verta::instance(Carbon::parse($data['pay_at']))->format('Y-m-d');
|
||||||
[$year, $month, $day] = explode('-', $date);
|
[$year, $month, $day] = explode('-', $date);
|
||||||
@@ -200,8 +130,9 @@ class TahesabController extends Controller
|
|||||||
// }
|
// }
|
||||||
$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)) {
|
||||||
$this->store();
|
$this->create_user($customer->id);
|
||||||
|
$customer = Customer::where('id', $data['customer_id'])->first();
|
||||||
}
|
}
|
||||||
$tahesab = Tahesab::create([
|
$tahesab = Tahesab::create([
|
||||||
"customer_id" => $customer->id,
|
"customer_id" => $customer->id,
|
||||||
@@ -245,4 +176,78 @@ class TahesabController extends Controller
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function create_user($customer_id)
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
$customer = Customer::findOrFail($customer_id);
|
||||||
|
|
||||||
|
if ($customer && ($customer->moshtari_code == null)) {
|
||||||
|
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'), [
|
||||||
|
"DoNewMoshtari" => [
|
||||||
|
(string)$customer->name,
|
||||||
|
$this->Config('name_fa'),
|
||||||
|
(string)$customer->mobile,
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
-1,
|
||||||
|
0
|
||||||
|
]
|
||||||
|
//{"DoNewMoshtari":["Name", "GroupName", "Tel", "Address", "CodeMeli", "Tarikh_Tavalod", "Moaref", "Code_Moaref", Moshtari_Code, Jens_Felez]}
|
||||||
|
]);
|
||||||
|
if (!empty($response['OK'])) {
|
||||||
|
$customer->moshtari_code = $response['OK'];
|
||||||
|
$customer->save();
|
||||||
|
return $response['OK'];
|
||||||
|
}
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $e->getMessage();
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
if($customer && $customer->birth_date !== null){
|
||||||
|
$birth_date = Verta::instance(Carbon::parse($customer->birth_date))->format('Y-m-d');
|
||||||
|
}
|
||||||
|
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'), [
|
||||||
|
"DoEditMoshtari" => [
|
||||||
|
$customer->name,
|
||||||
|
$this->Config('name_fa'),
|
||||||
|
$customer->mobile,
|
||||||
|
"",
|
||||||
|
$customer->n_code ?? "",
|
||||||
|
$birth_date ?? "",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
(int)$customer->moshtari_code,
|
||||||
|
0 // tala
|
||||||
|
]
|
||||||
|
//{"DoEditMoshtari":["Name","GroupName", "Tel", "Address", "CodeMeli", "Tarikh_Tavalod", "Moaref", "Code_Moaref", Moshtari_Code]}
|
||||||
|
]);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return response($e->getMessage(), 500);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
if (empty($response['OK'])) {
|
||||||
|
return "tahesab api error!!!";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user