fixed auto add customer into tahesab
This commit is contained in:
@@ -7,6 +7,7 @@ use App\Http\Controllers\Site\ReportController;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use App\Models\Tahesab;
|
||||
use App\Models\Customer;
|
||||
use App\Services\TahesabSyncService;
|
||||
@@ -554,36 +555,58 @@ class TahesabController extends Controller
|
||||
$response = null;
|
||||
|
||||
if ($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($this->tahesabApiUrl(), [
|
||||
"DoNewMoshtari" => [
|
||||
(string)$customer->name,
|
||||
$this->Config('name_fa'),
|
||||
(string)$customer->mobile,
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
-1,
|
||||
0
|
||||
]
|
||||
])->json();
|
||||
$lock = Cache::lock('tahesab:register-customer:'.$customer->id, 30);
|
||||
|
||||
if ($this->sync()->responseOk($response)) {
|
||||
$customer->moshtari_code = $response['OK'];
|
||||
$customer->save();
|
||||
return $response['OK'];
|
||||
if (! $lock->get()) {
|
||||
$customer->refresh();
|
||||
|
||||
if ($customer->moshtari_code != null) {
|
||||
return $customer->moshtari_code;
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return $e->getMessage();
|
||||
|
||||
return 'ثبت مشتری در تهحساب در حال انجام است';
|
||||
}
|
||||
|
||||
return 'tahesab api error!!!';
|
||||
try {
|
||||
$customer->refresh();
|
||||
|
||||
if ($customer->moshtari_code != null) {
|
||||
return $customer->moshtari_code;
|
||||
}
|
||||
|
||||
try {
|
||||
$response = Http::withoutVerifying()->timeout(10)->withHeaders([
|
||||
'DBName' => $this->Config('tahesab_db'),
|
||||
'Content-Type' => 'application/json',
|
||||
'Authorization' => "Bearer " . $this->Config('tahesab_token'),
|
||||
])->post($this->tahesabApiUrl(), [
|
||||
"DoNewMoshtari" => [
|
||||
(string)$customer->name,
|
||||
$this->Config('name_fa'),
|
||||
(string)$customer->mobile,
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
-1,
|
||||
0
|
||||
]
|
||||
])->json();
|
||||
|
||||
if ($this->sync()->responseOk($response)) {
|
||||
$customer->moshtari_code = $response['OK'];
|
||||
$customer->save();
|
||||
return $response['OK'];
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return $e->getMessage();
|
||||
}
|
||||
|
||||
return 'tahesab api error!!!';
|
||||
} finally {
|
||||
$lock->release();
|
||||
}
|
||||
}
|
||||
|
||||
$birth_date = '';
|
||||
|
||||
Reference in New Issue
Block a user