jbit better messages
This commit is contained in:
@@ -8,7 +8,6 @@ use App\Http\Controllers\Controller;
|
|||||||
use App\Models\Address;
|
use App\Models\Address;
|
||||||
use App\Models\Customer;
|
use App\Models\Customer;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\Models\Cnt;
|
|
||||||
use App\Models\TransactionsAdmin;
|
use App\Models\TransactionsAdmin;
|
||||||
use App\Models\Withdraw;
|
use App\Models\Withdraw;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
@@ -16,10 +15,9 @@ use Rooyesh\Wallet\interfaces\TransactionInterface;
|
|||||||
use Rooyesh\Wallet\interfaces\WalletInterface;
|
use Rooyesh\Wallet\interfaces\WalletInterface;
|
||||||
use Rooyesh\Wallet\models\Wallet;
|
use Rooyesh\Wallet\models\Wallet;
|
||||||
use Rooyesh\Wallet\models\Transaction;
|
use Rooyesh\Wallet\models\Transaction;
|
||||||
use Illuminate\Support\Facades\Storage;
|
|
||||||
use Illuminate\Support\Facades\Http;
|
|
||||||
use App\Models\Setting;
|
use App\Models\Setting;
|
||||||
use App\Http\Controllers\Admin\TahesabController;
|
use App\Http\Controllers\Admin\TahesabController;
|
||||||
|
use App\Services\ConfigService;
|
||||||
use Illuminate\Support\Facades\Schema;
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
|
||||||
@@ -161,45 +159,9 @@ class CustomerController extends Controller
|
|||||||
|
|
||||||
// $tah = new TahesabController();
|
// $tah = new TahesabController();
|
||||||
// $tah->store(["customer_id" => $customer->id]);
|
// $tah->store(["customer_id" => $customer->id]);
|
||||||
if (!$customer->is_legal) {
|
$cfg = app(ConfigService::class);
|
||||||
$counter = Cnt::where('key', 'jibit_counter')->first();
|
if (!$customer->is_legal && $cfg->getBool('register_jibit_verify', false)) {
|
||||||
if(empty($counter)){
|
$response = $this->jibitNcode($customer->n_code, $customer->mobile);
|
||||||
$counter = new Cnt();
|
|
||||||
$counter->key = "jibit_counter";
|
|
||||||
$counter->value = 0;
|
|
||||||
$counter->save();
|
|
||||||
}
|
|
||||||
|
|
||||||
$nationalCode = $customer->n_code;
|
|
||||||
$mobileNumber = $customer->mobile;
|
|
||||||
// Storage::put('accessTokenGibit', ['accessToken']);
|
|
||||||
// Storage::put('refreshTokenGibit', ['refreshToken']);
|
|
||||||
$response = Http::withoutVerifying()->withToken(Storage::get('accessTokenGibit'))
|
|
||||||
->get("https://napi.jibit.ir/ide/v1/services/matching?nationalCode=".$nationalCode."&mobileNumber=".$mobileNumber)->json();
|
|
||||||
if (isset($response['code']) && $response['code']== "forbidden"){
|
|
||||||
$response = Http::withoutVerifying()->withToken(Storage::get('refreshTokenGibit'))
|
|
||||||
->post("https://napi.jibit.ir/ide/v1/tokens/generate",[
|
|
||||||
'apiKey' => "J5WxrPxPOg",
|
|
||||||
'secretKey' => "7dgeE70xQXsQL7r36j3wif6X9",
|
|
||||||
])->json();
|
|
||||||
Storage::put('accessTokenGibit', $response['accessToken']);
|
|
||||||
Storage::put('refreshTokenGibit', $response['refreshToken']);
|
|
||||||
$response = Http::withoutVerifying()->withToken(Storage::get('accessTokenGibit'))
|
|
||||||
->get("https://napi.jibit.ir/ide/v1/services/matching?nationalCode=".$nationalCode."&mobileNumber=".$mobileNumber)->json();
|
|
||||||
}
|
|
||||||
|
|
||||||
//update jibit counter
|
|
||||||
$counter->value = (int)$counter->value + 1;
|
|
||||||
$counter->save();
|
|
||||||
|
|
||||||
// $response = Http::withHeaders([
|
|
||||||
// 'Authorization' => 'Bearer mob83EBzqU7GWBmnc-6gXIp6r2G57P_94',
|
|
||||||
// 'Content-Type' => 'application/json',
|
|
||||||
// ])->post('http://185.97.116.24:20205/check_user', [
|
|
||||||
// 'number' => $customer->mobile,
|
|
||||||
// 'national' => $customer->n_code,
|
|
||||||
// 'host' => $_SERVER['HTTP_HOST'],
|
|
||||||
// ]);
|
|
||||||
|
|
||||||
if (isset($response['matched']) and $response['matched'] == true) {
|
if (isset($response['matched']) and $response['matched'] == true) {
|
||||||
$customer->is_legal = 1;
|
$customer->is_legal = 1;
|
||||||
@@ -324,17 +286,22 @@ class CustomerController extends Controller
|
|||||||
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// This block will handle the case where the code doesn't match
|
if (isset($response['matched']) && $response['matched'] === false) {
|
||||||
// if (isset($response['code']) and $response['code'] === 'mobileNumber.not_valid') {
|
return response()->json([
|
||||||
// return response()->json(['message' => "کد ملی تطابق ندارد",'response' =>$response], 422);
|
'message' => 'کد ملی و شماره موبایل با یکدیگر مطابقت ندارند. لطفاً هر دو را با دقت بررسی کرده و دوباره ثبت کنید.',
|
||||||
// } else {
|
], 422);
|
||||||
// // This block will handle other errors from the $response variable
|
}
|
||||||
// return response()->json(['response' => $response], 422);
|
|
||||||
// }
|
return response()->json([
|
||||||
return response()->json(['message' => "کد ملی ثبت شد، اما در حال حاضر سیستم نتوانست آن را تأیید کند. لطفاً منتظر بررسی و تأیید مدیر بمانید.",'response' =>$response], 422);
|
'message' => 'کد ملی ثبت شد، اما در حال حاضر سیستم نتوانست آن را تأیید کند. لطفاً منتظر بررسی و تأیید مدیر بمانید.',
|
||||||
|
], 422);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} elseif (!$customer->is_legal && !$cfg->getBool('register_jibit_verify', false)) {
|
||||||
|
return response()->json([
|
||||||
|
'message' => 'اطلاعات شما با موفقیت ثبت شد. تأیید خودکار هویت در این سامانه فعال نیست؛ لطفاً برای تکمیل احراز هویت با پشتیبانی یا مدیر سامانه تماس بگیرید.',
|
||||||
|
], 422);
|
||||||
}
|
}
|
||||||
return response()->json(true);
|
return response()->json(true);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,139 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""
|
||||||
|
Generate iran_cities_seed.sql from goldAli cities API.
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
python generate_cities_sql.py
|
||||||
|
python generate_cities_sql.py --source /path/to/cities.json
|
||||||
|
"""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import json
|
||||||
|
import sys
|
||||||
|
import urllib.request
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
SQL_DIR = Path(__file__).resolve().parent
|
||||||
|
DEFAULT_SOURCE = "https://goldaliii.com/server/api/city/all"
|
||||||
|
OUTPUT = SQL_DIR / "iran_cities_seed.sql"
|
||||||
|
|
||||||
|
ARABIC_TO_PERSIAN = str.maketrans(
|
||||||
|
{"ي": "ی", "ك": "ک", "ة": "ه", "ۀ": "ه", "ؤ": "و", "إ": "ا", "أ": "ا"}
|
||||||
|
)
|
||||||
|
|
||||||
|
TITLE_FIXES = {
|
||||||
|
"چهارمحال وبختیاری": "چهارمحال و بختیاری",
|
||||||
|
"سیستان وبلوچستان": "سیستان و بلوچستان",
|
||||||
|
"کهگیلویه وبویراحمد": "کهگیلویه و بویراحمد",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def normalize_title(title: str) -> str:
|
||||||
|
title = title.translate(ARABIC_TO_PERSIAN)
|
||||||
|
return TITLE_FIXES.get(title, title)
|
||||||
|
|
||||||
|
|
||||||
|
def sql_str(value: str | None) -> str:
|
||||||
|
if value is None:
|
||||||
|
return "NULL"
|
||||||
|
return "'" + str(value).replace("\\", "\\\\").replace("'", "''") + "'"
|
||||||
|
|
||||||
|
|
||||||
|
def sql_bool(value: bool | None) -> str:
|
||||||
|
return "1" if value else "0"
|
||||||
|
|
||||||
|
|
||||||
|
def load_rows(source: str) -> list[dict]:
|
||||||
|
if source.startswith("http://") or source.startswith("https://"):
|
||||||
|
with urllib.request.urlopen(source, timeout=60) as resp:
|
||||||
|
data = json.load(resp)
|
||||||
|
else:
|
||||||
|
data = json.loads(Path(source).read_text(encoding="utf-8"))
|
||||||
|
|
||||||
|
return [
|
||||||
|
row
|
||||||
|
for row in data
|
||||||
|
if row.get("id") != 1600 and row.get("title") != "تست"
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
def generate_sql(rows: list[dict]) -> str:
|
||||||
|
provinces = sorted(
|
||||||
|
[row for row in rows if row.get("parent_id") is None], key=lambda r: r["id"]
|
||||||
|
)
|
||||||
|
others = sorted(
|
||||||
|
[row for row in rows if row.get("parent_id") is not None], key=lambda r: r["id"]
|
||||||
|
)
|
||||||
|
ordered = provinces + others
|
||||||
|
|
||||||
|
lines = [
|
||||||
|
"-- =============================================================================",
|
||||||
|
"-- استانها + شهرها + زیرمجموعهها (جدول cities)",
|
||||||
|
"--",
|
||||||
|
"-- ساختار مطابق City model:",
|
||||||
|
"-- level=1 → استان (parent_id = NULL, has_children = 1)",
|
||||||
|
"-- level=2 → شهر/شهرستان (parent_id = id استان)",
|
||||||
|
"-- level=3 → محله/بخش (parent_id = id شهر level=2)",
|
||||||
|
"--",
|
||||||
|
f"-- تعداد: {len(ordered)} رکورد (31 استان + {len(ordered) - 31} زیرمجموعه)",
|
||||||
|
"-- =============================================================================",
|
||||||
|
"",
|
||||||
|
"START TRANSACTION;",
|
||||||
|
"",
|
||||||
|
"SET NAMES utf8mb4 COLLATE utf8mb4_unicode_ci;",
|
||||||
|
"",
|
||||||
|
"CREATE TABLE IF NOT EXISTS `cities` (",
|
||||||
|
" `id` bigint unsigned NOT NULL AUTO_INCREMENT,",
|
||||||
|
" `title` varchar(255) NOT NULL,",
|
||||||
|
" `code` varchar(50) DEFAULT NULL,",
|
||||||
|
" `parent_id` bigint unsigned DEFAULT NULL,",
|
||||||
|
" `has_children` tinyint(1) NOT NULL DEFAULT 0,",
|
||||||
|
" `level` tinyint unsigned DEFAULT NULL,",
|
||||||
|
" PRIMARY KEY (`id`),",
|
||||||
|
" KEY `cities_parent_id_index` (`parent_id`)",
|
||||||
|
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;",
|
||||||
|
"",
|
||||||
|
"ALTER TABLE `cities` MODIFY COLUMN `code` varchar(50) DEFAULT NULL;",
|
||||||
|
"",
|
||||||
|
"DELETE FROM `cities`;",
|
||||||
|
"",
|
||||||
|
]
|
||||||
|
|
||||||
|
batch_size = 50
|
||||||
|
for i in range(0, len(ordered), batch_size):
|
||||||
|
batch = ordered[i : i + batch_size]
|
||||||
|
lines.append(
|
||||||
|
"INSERT INTO `cities` (`id`, `title`, `code`, `parent_id`, `has_children`, `level`) VALUES"
|
||||||
|
)
|
||||||
|
values = []
|
||||||
|
for row in batch:
|
||||||
|
parent_id = row.get("parent_id")
|
||||||
|
level = row.get("level")
|
||||||
|
values.append(
|
||||||
|
f" ({row['id']}, {sql_str(normalize_title(row['title']))}, "
|
||||||
|
f"{sql_str(row.get('code'))}, "
|
||||||
|
f"{parent_id if parent_id is not None else 'NULL'}, "
|
||||||
|
f"{sql_bool(row.get('has_children'))}, "
|
||||||
|
f"{level if level is not None else 'NULL'})"
|
||||||
|
)
|
||||||
|
lines.append(",\n".join(values) + ";")
|
||||||
|
lines.append("")
|
||||||
|
|
||||||
|
max_id = max(row["id"] for row in ordered)
|
||||||
|
lines.extend([f"ALTER TABLE `cities` AUTO_INCREMENT = {max_id + 1};", "", "COMMIT;", ""])
|
||||||
|
return "\n".join(lines)
|
||||||
|
|
||||||
|
|
||||||
|
def main() -> None:
|
||||||
|
source = DEFAULT_SOURCE
|
||||||
|
if len(sys.argv) > 1 and sys.argv[1] == "--source" and len(sys.argv) > 2:
|
||||||
|
source = sys.argv[2]
|
||||||
|
|
||||||
|
rows = load_rows(source)
|
||||||
|
OUTPUT.write_text(generate_sql(rows), encoding="utf-8")
|
||||||
|
print(f"Wrote {OUTPUT} ({len(rows)} rows)")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user