|
@@ -1,5 +1,5 @@
|
|
|
from datetime import datetime
|
|
|
-
|
|
|
+import concurrent.futures
|
|
|
import pytz
|
|
|
import requests
|
|
|
from django.db.models import Q
|
|
@@ -7,9 +7,9 @@ from django.views import View
|
|
|
from Crypto.Cipher import AES
|
|
|
from Crypto.Util.Padding import pad
|
|
|
from django.contrib.auth.hashers import check_password, make_password
|
|
|
-
|
|
|
+import concurrent.futures
|
|
|
from Controller.CheckUserData import DataValid
|
|
|
-from Model.models import Device_User
|
|
|
+from Model.models import Device_User, CountryModel
|
|
|
from Object.RedisObject import RedisObject
|
|
|
from Object.ResponseObject import ResponseObject
|
|
|
import base64
|
|
@@ -90,6 +90,10 @@ class ShopifyView(View):
|
|
|
return self.shopify_login(request_dict, response)
|
|
|
elif operation == 'shopifyRegister': # APP注册定制客户信息
|
|
|
return self.shopify_register(request_dict, response)
|
|
|
+ elif operation == 'searchCustomer':
|
|
|
+ return self.search_customer(request_dict, response)
|
|
|
+ elif operation == 'searchAccount':
|
|
|
+ return self.search_account(request_dict, response)
|
|
|
else:
|
|
|
return response.json(414)
|
|
|
|
|
@@ -178,4 +182,84 @@ class ShopifyView(View):
|
|
|
|
|
|
return response.json(0)
|
|
|
|
|
|
+ def search_account(self, request_dict, response):
|
|
|
+ email = request_dict.get("email")
|
|
|
+ if not email:
|
|
|
+ return None
|
|
|
+
|
|
|
+ store_configs = [
|
|
|
+ ("us", SHOPIFY_CONFIG["us_store_name"], SHOPIFY_CONFIG["us_token"]),
|
|
|
+ ("eu", SHOPIFY_CONFIG["eu_store_name"], SHOPIFY_CONFIG["eu_token"]),
|
|
|
+ ("de", SHOPIFY_CONFIG["de_store_name"], SHOPIFY_CONFIG["de_token"]),
|
|
|
+ ("uk", SHOPIFY_CONFIG["uk_store_name"], SHOPIFY_CONFIG["uk_token"]),
|
|
|
+ ("jp", SHOPIFY_CONFIG["jp_store_name"], SHOPIFY_CONFIG["jp_token"]),
|
|
|
+ ]
|
|
|
+
|
|
|
+ def search_customer(store_name, token):
|
|
|
+ return ShopifyMultipass.search_customer_by_email(store_name, token, email)
|
|
|
+
|
|
|
+ shopify_results = {}
|
|
|
+
|
|
|
+ with concurrent.futures.ThreadPoolExecutor() as executor:
|
|
|
+ future_to_country = {executor.submit(search_customer, store_name, token): country for
|
|
|
+ country, store_name, token in store_configs}
|
|
|
+ for future in concurrent.futures.as_completed(future_to_country):
|
|
|
+ country = future_to_country[future]
|
|
|
+ shopify_results[country] = future.result()
|
|
|
+
|
|
|
+ shopify_country = next((country for country, result in shopify_results.items() if result["customers"]), "")
|
|
|
+
|
|
|
+ account_country = self.call_search_customer(email)
|
|
|
+ servers_country = "us" if account_country["us"] else "eu" if account_country["eu"] else ""
|
|
|
+
|
|
|
+ if servers_country and shopify_country:
|
|
|
+ status = 4
|
|
|
+ elif servers_country:
|
|
|
+ status = 3
|
|
|
+ elif shopify_country:
|
|
|
+ status = 2
|
|
|
+ else:
|
|
|
+ status = 1
|
|
|
+
|
|
|
+ account_status = {"status": status, "shopifyCountry": shopify_country, "ServersCountry": servers_country}
|
|
|
+ return response.json(0, account_status)
|
|
|
+
|
|
|
+ @staticmethod
|
|
|
+ def call_search_customer(email):
|
|
|
+ urls = {
|
|
|
+ "us": "https://www.dvema.com/shopify/searchCustomer",
|
|
|
+ "eu": "https://api.zositeche.com/shopify/searchCustomer"
|
|
|
+ }
|
|
|
+ params = {"email": email} # Use the provided email parameter
|
|
|
+
|
|
|
+ customer_region = {}
|
|
|
+
|
|
|
+ def fetch_customer(region, url):
|
|
|
+ try:
|
|
|
+ response = requests.get(url=url, params=params)
|
|
|
+ response.raise_for_status() # Raise an error for bad responses
|
|
|
+ customer_country = response.json().get("result", None)
|
|
|
+ return region, customer_country if not all(customer_country) else None
|
|
|
+ except requests.RequestException:
|
|
|
+ return region, None
|
|
|
+
|
|
|
+ with concurrent.futures.ThreadPoolExecutor() as executor:
|
|
|
+ future_to_region = {executor.submit(fetch_customer, region, url): region for region, url in urls.items()}
|
|
|
+ for future in concurrent.futures.as_completed(future_to_region):
|
|
|
+ region, customer_country = future.result()
|
|
|
+ customer_region[region] = customer_country
|
|
|
+
|
|
|
+ return customer_region
|
|
|
+
|
|
|
+ @staticmethod
|
|
|
+ def search_customer(request_dict, response):
|
|
|
+ email = request_dict.get("email")
|
|
|
+ user_qs = Device_User.objects.filter(Q(username=email) | Q(userEmail=email))
|
|
|
+
|
|
|
+ if not user_qs.exists():
|
|
|
+ return response.json(104)
|
|
|
+
|
|
|
+ user_region_id = user_qs.values_list('region_country', flat=True).first()
|
|
|
+ country_code = CountryModel.objects.filter(id=user_region_id).values_list("country_code", flat=True).first()
|
|
|
|
|
|
+ return response.json(0, country_code)
|