Przeglądaj źródła

shopify代码、APP返回图标更新、云存套餐转移日志

linhaohong 10 miesięcy temu
rodzic
commit
116da74caf

+ 53 - 19
AdminController/DeviceManagementController.py

@@ -966,28 +966,62 @@ class DeviceManagement(View):
                                                                                               'name', 'sort', 'config',
                                                                                               'iconV2',
                                                                                               'app_device_type__app_version_number_id')
-                if api_version == "V2":
-                    for app_bundle in app_bundle_qs:
+
+                # 使用lang="en"来补全缺失的数据
+                en_lang_qs = AppBundle.objects.filter(
+                    app_bundle_id=app_bundle_id,
+                    app_device_type__devicenamelanguage__lang="en",
+                    app_device_type__app_version_number_id=version_number
+                ).annotate(
+                    model=F('app_device_type__model'),
+                    type=F('app_device_type__type'),
+                    icon=F('app_device_type__icon'),
+                    name=F('app_device_type__devicenamelanguage__name'),
+                    iconV2=F('app_device_type__iconV2'),
+                    sort=F('app_device_type__devicenamelanguage__sort'),
+                    config=F('app_device_type__config'),
+                    app_version_number_id=F('app_device_type__app_version_number_id')
+                ).values('model', 'type', 'icon', 'name', 'sort', 'config', 'iconV2',
+                         'app_device_type__app_version_number_id')
+
+                # 转换查询集为字典
+                current_lang_data = {item['type']: item for item in app_bundle_qs}
+                en_lang_data = {item['type']: item for item in en_lang_qs}
+
+                # 合并数据,优先使用当前语言的数据,缺少的字段用英文补充
+                for type, en_data in en_lang_data.items():
+                    current_data = current_lang_data.get(type, {})
+                    merged_data = {
+                        'type': en_data['type'],
+                        'model': current_data.get('model', en_data['model']),
+                        'icon': current_data.get('icon', en_data['icon']),
+                        'name': current_data.get('name', en_data['name']),
+                        'sort': current_data.get('sort', en_data['sort']),
+                        'config': current_data.get('config', en_data['config']),
+                        'iconV2': current_data.get('iconV2', en_data['iconV2']),
+                        'app_device_type__app_version_number_id': current_data.get(
+                            'app_device_type__app_version_number_id',
+                            en_data['app_device_type__app_version_number_id']),
+                    }
+                    if api_version == "V2":
                         app_bundle_list.append({
-                            'model': app_bundle['model'],
-                            'type': app_bundle['type'],
-                            'icon': app_bundle['iconV2'] if app_bundle['iconV2'] != "" else app_bundle['icon'],
-                            'name': app_bundle['name'],
-                            'sort': app_bundle['sort'],
-                            'config': app_bundle['config'],
-                            'app_device_type__app_version_number_id': app_bundle[
-                                'app_device_type__app_version_number_id'],
+                            'model': merged_data['model'],
+                            'type': merged_data['type'],
+                            'icon': merged_data['iconV2'] if merged_data['iconV2'] != "" else merged_data['icon'],
+                            'name': merged_data['name'],
+                            'sort': merged_data['sort'],
+                            'config': merged_data['config'],
+                            'app_device_type__app_version_number_id': merged_data['app_device_type__app_version_number_id'],
                         })
-                else:
-                    for app_bundle in app_bundle_qs:
+                    else:
                         app_bundle_list.append({
-                            'model': app_bundle['model'],
-                            'type': app_bundle['type'],
-                            'icon': app_bundle['icon'],
-                            'name': app_bundle['name'],
-                            'sort': app_bundle['sort'],
-                            'config': app_bundle['config'],
-                            'app_device_type__app_version_number_id': app_bundle[
+                            'model': merged_data['model'],
+                            'type': merged_data['type'],
+                            'icon': merged_data['icon'],
+                            'name': merged_data['name'],
+                            'sort': merged_data['sort'],
+                            'config': merged_data['config'],
+                            'app_device_type__app_version_number_id': merged_data[
                                 'app_device_type__app_version_number_id'],
                         })
             dvr_list = [app_bundle for app_bundle in app_bundle_list if app_bundle['model'] == 1]

+ 12 - 4
AdminController/ServeManagementController.py

@@ -6,6 +6,7 @@ import hashlib
 import time
 import uuid
 import json
+import logging
 
 import paypalrestsdk
 import requests
@@ -30,6 +31,7 @@ from Object.TokenObject import TokenObject
 from Object.UnicomObject import UnicomObjeect
 from Service.CommonService import CommonService
 
+LOGGER = logging.getLogger('info')
 
 class serveManagement(View):
     def get(self, request, *args, **kwargs):
@@ -1506,12 +1508,16 @@ class serveManagement(View):
             if old_using_uid_bucket.exists():
                 if old_using_uid_bucket.first().endTime < nowTime:
                     return response.json(10013)
-            else:
-                if not old_unusing_uid_bucket.exists():
-                    return response.json(10017)
+            if not old_using_uid_bucket.exists() and not old_unusing_uid_bucket.exists():
+                return response.json(10017)
+
+            if old_using_uid_bucket.exists() and old_unusing_uid_bucket():
+                LOGGER.info(f'云存转移, orderID:{orderID}, 该订单同时出现在已使用和未使用数据库')
+                return response.json(10018)
 
             # 订单套餐未使用
-            if old_unusing_uid_bucket.exists():
+            elif old_unusing_uid_bucket.exists():
+                LOGGER.info(f'云存转移, orderID:{orderID}, 该订单套餐在原设备未使用')
                 with transaction.atomic():
                     # 旧设备不包含 ai
                     if old_unusing_uid_bucket.filter(is_ai=1).exists():
@@ -1536,6 +1542,7 @@ class serveManagement(View):
                         # 激活转移的套餐
                         unused = new_unused_uid_bucket[0]
                         endTime = CommonService.calcMonthLater(unused['expire'])
+                        LOGGER.info(f'云存转移, orderID:{orderID}, 激活转移之后的套餐, endTime: {endTime}')
                         # 判断是否有已过期套餐
                         if UID_Bucket.objects.filter(uid=new_uid).exists():
                             UID_Bucket.objects.filter(uid=new_uid).update(status=1, orderId=orderID, updateTime=nowTime,
@@ -1581,6 +1588,7 @@ class serveManagement(View):
 
             # 订单套餐已使用
             else:
+                LOGGER.info(f'云存转移, orderID:{orderID}, 该订单套餐在原设备已使用')
                 old_using_uid_bucket = old_using_uid_bucket.values('id', 'bucket_id', 'has_unused',
                                                                    'bucket__content').order_by('addTime')
                 old_ai_service = AiService.objects.filter(uid=old_uid, endTime__gte=nowTime, use_status=1).values('id',

+ 19 - 1
Ansjer/config.py

@@ -607,6 +607,24 @@ IN_APP_CONFIG = {
 }
 
 SHOPIFY_CONFIG = {
+    # eu店铺
+    "eu_store_name": "0ef557-2",
     "eu_token": "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",
-    "eu_multipass_secret": "f4863c9979d7ddd16e23817c0dfe7863"
+    "eu_multipass_secret": "f4863c9979d7ddd16e23817c0dfe7863",
+    # us店铺
+    "us_store_name": "zositech",
+    "us_token": "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",
+    "us_multipass_secret": "fbecba0fa968d871dcbec4aa791b9d61",
+    # de店铺
+    "de_store_name": "zositech-de",
+    "de_token": "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",
+    "de_multipass_secret": "7700aaab089cfc37d0f87f28bf1ea935",
+    # uk店铺
+    "uk_store_name": "6658bf",
+    "uk_token": "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",
+    "uk_multipass_secret": "32342c20ab0b44f8cef34e6b6f7884cc",
+    # jp店铺
+    "jp_store_name": "3b9ec5-0d",
+    "jp_token": "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",
+    "jp_multipass_secret": "3ff559255f5e9fcf783860d274406c82",
 }

+ 103 - 60
Controller/ShopifyController.py

@@ -86,13 +86,13 @@ class ShopifyView(View):
     def validation(self, request, request_dict, operation):
         language = request_dict.get('language', 'cn')
         response = ResponseObject(language)
-        if operation == 'shopifyLogin':  # APP查詢定制客户信息
+        if operation == 'shopifyLogin':
             return self.shopify_login(request_dict, response)
-        elif operation == 'shopifyRegister':  # APP注册定制客户信息
+        elif operation == 'shopifyRegister':
             return self.shopify_register(request_dict, response)
-        elif operation == 'searchCustomer':
+        elif operation == 'searchCustomer': # 查询APP注册账号情况
             return self.search_customer(request_dict, response)
-        elif operation == 'searchAccount':
+        elif operation == 'searchAccount': # 官网检测账号接口
             return self.search_account(request_dict, response)
         else:
             return response.json(414)
@@ -101,6 +101,9 @@ class ShopifyView(View):
     def shopify_login(request_dict, response):
         email = request_dict.get("email", None)
         password = request_dict.get("password", None)
+        account_region = request_dict.get("accountRegion", "")
+        account_iso2 = request_dict.get("accountIso2", "")
+        shopify_country = request_dict.get("shopifyCountry", "")
 
         if not all([email, password]):
             return response.json(444)
@@ -108,30 +111,51 @@ class ShopifyView(View):
         user_qs = Device_User.objects.filter(Q(username=email) | Q(userEmail=email))
         if not user_qs.exists():
             return response.json(104)
-        users = user_qs.values('role__rid', 'role__roleName', 'userID', 'NickName', 'username', 'userEmail',
-                               'phone', 'password', 'userIconPath')[0]
 
-        check_flag = check_password(password, users['password'])
-        if not check_flag:
-            return response.json(111)
+        users = user_qs.values(
+            'role__rid', 'role__roleName', 'userID', 'NickName',
+            'username', 'userEmail', 'phone', 'password', 'userIconPath'
+        )[0]
 
-        # 获取当前时间
-        now = datetime.now(pytz.timezone('America/New_York'))  # 你可以根据需要更改时区
+        if not check_password(password, users['password']):
+            return response.json(111)
 
-        # 格式化时间戳
+        # 获取当前时间并格式化时间戳
+        now = datetime.now(pytz.timezone('America/New_York'))
         timestamp = now.strftime('%Y-%m-%dT%H:%M:%S%z')
-        # 添加冒号到时区部分
         timestamp = timestamp[:-2] + ':' + timestamp[-2:]
 
         customer_data = {
             "email": email,
             "created_at": timestamp,
         }
-        multipass_secret = SHOPIFY_CONFIG["eu_multipass_secret"]  # multipass密钥
-        token = ShopifyMultipass.generate_multipass_token(multipass_secret, customer_data)
 
-        # 构造重定向URL
-        redirect_url = f"https://eu.zositech.com/account/login/multipass/{token}"
+        # 定义默认配置键
+        secret_key = "eu_multipass_secret"
+        store_name_key = "eu_store_name"
+
+        # 根据条件选择配置键
+        if shopify_country:
+            secret_key = f"{shopify_country}_multipass_secret"
+            store_name_key = f"{shopify_country}_store_name"
+        elif account_region == "us" and account_iso2 == "jp":
+            secret_key = "jp_multipass_secret"
+            store_name_key = "jp_store_name"
+        elif account_region == "us":
+            secret_key = "us_multipass_secret"
+            store_name_key = "us_store_name"
+        elif account_region == "eu" and account_iso2 == "de":
+            secret_key = "de_multipass_secret"
+            store_name_key = "de_store_name"
+        elif account_region == "eu" and account_iso2 == "uk":
+            secret_key = "uk_multipass_secret"
+            store_name_key = "uk_store_name"
+
+        # 获取配置并生成重定向URL
+        multipass_secret = SHOPIFY_CONFIG[secret_key]
+        store_name = SHOPIFY_CONFIG[store_name_key]
+        token = ShopifyMultipass.generate_multipass_token(multipass_secret, customer_data)
+        redirect_url = f"https://{store_name}.zositech.com/account/login/multipass/{token}"
 
         return response.json(0, redirect_url)
 
@@ -141,26 +165,17 @@ class ShopifyView(View):
         password = request_dict.get("password", None)
         authcode = request_dict.get("authCode", None)
 
-        if not all([email, password]):
+        if not all([email, password, authcode]):
             return response.json(444)
 
-        if authcode is None:
-            # 查询是否在shopify有账号
-            access_token = SHOPIFY_CONFIG["eu_token"]
-            customer_data = ShopifyMultipass.search_customer_by_email("0ef557-2", access_token, email)
-            if not customer_data['customers']:
-                return response.json(10077)
-
-        # 邮箱验证
-        else:
-            reds = RedisObject()
-            identifyingCode = reds.get_data(key=email + '_identifyingCode')
-            # 判断验证码是否过期
-            if identifyingCode is False:
-                return response.json(120)
-            # 验证码是否正确
-            if authcode != identifyingCode:
-                return response.json(121)
+        reds = RedisObject()
+        identifyingCode = reds.get_data(key=email + '_identifyingCode')
+        # 判断验证码是否过期
+        if identifyingCode is False:
+            return response.json(120)
+        # 验证码是否正确
+        if authcode != identifyingCode:
+            return response.json(121)
 
         # 注册
         if Device_User.objects.filter(Q(username=email) | Q(userEmail=email)).exists():
@@ -185,7 +200,7 @@ class ShopifyView(View):
     def search_account(self, request_dict, response):
         email = request_dict.get("email")
         if not email:
-            return None
+            return response.json(444)
 
         store_configs = [
             ("us", SHOPIFY_CONFIG["us_store_name"], SHOPIFY_CONFIG["us_token"]),
@@ -198,31 +213,59 @@ class ShopifyView(View):
         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
+        try:
+            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_continent = "us" if account_country["us"] else "eu" if account_country["eu"] else ""
+
+            if servers_continent:
+                account_region_list = []
+                if account_country.get("us"):
+                    account_region_list.append({
+                        "region": "us",
+                        "url": "https://www.dvema.com/shopify/shopifyLogin",
+                        "accountCountry": account_country["us"],
+                        "shopifyCountry": shopify_country
+                    })
+                if account_country.get("eu"):
+                    account_region_list.append({
+                        "region": "eu",
+                        "url": "https://api.zositeche.com/shopify/shopifyLogin",
+                        "accountCountry": account_country["eu"],
+                        "shopifyCountry": shopify_country
+                    })
+
+                return response.json(0, {"accountStatus": 3, "accountRegionList": account_region_list})
+            elif shopify_country:
+                if shopify_country == "eu":
+                    url = "https://eu.zositech.com/account/login"
+                elif shopify_country == "jp":
+                    url = "https://www.zosi.jp/account/login"
+                elif shopify_country == "de":
+                    url = "https://www.zositech.de/account/login"
+                elif shopify_country == "uk":
+                    url = "https://www.zositech.co.uk/account/login"
+                else:
+                    url = "https://www.zositech.com/account/login"
+                return response.json(0, {"accountStatus": 2, "url": url})
+            else:
+                url = "注册链接"
+                return response.json(0, {"accountStatus": 1, "url": url})
+
+        except Exception as e:
+            print(e)
+            return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
 
-        account_status = {"status": status, "shopifyCountry": shopify_country, "ServersCountry": servers_country}
-        return response.json(0, account_status)
 
     @staticmethod
     def call_search_customer(email):