浏览代码

新增五兴清空套餐订购历史记录

zhangdongming 2 年之前
父节点
当前提交
8a4fd30dea
共有 2 个文件被更改,包括 56 次插入13 次删除
  1. 37 9
      Controller/UnicomCombo/WXTechController.py
  2. 19 4
      Object/WXTechObject.py

+ 37 - 9
Controller/UnicomCombo/WXTechController.py

@@ -17,12 +17,11 @@ from Model.models import UnicomDeviceInfo, Order_Model, UnicomComboExperienceHis
 from Object.Enums.WXOperatorEnum import WXOperatorEnum
 from Object.Enums.WXStartTypeEnum import WXStartTypeEnum
 from Object.ResponseObject import ResponseObject
-from Object.TokenObject import TokenObject
 from Object.WXTechObject import WXTechObject
 from Service.CommonService import CommonService
 
 LOGGER = logging.getLogger('info')
-# 五兴科技 套餐编码 1G 15天流量包
+# 五兴科技电信套餐编码 1G-15天流量包
 COMBO_ID = 'DX-DX-FDX-JCB-1G-15天-4DX-ASJ-YTC-AT-2022123020221230144615'
 
 
@@ -53,11 +52,12 @@ class WXTechController(View):
             return self.validation(put, request, operation)
 
         def validation(self, request_dict, request, operation):
-            token = TokenObject(request.META.get('HTTP_AUTHORIZATION'))
-            lang = request_dict.get('lang', token.lang)
-            response = ResponseObject(lang)
-            if token.code != 0:
-                return response.json(token.code)
+            if operation == 'deleteCardPackage':
+                return self.delete_card_package(request_dict, ResponseObject('cn'))
+            token_code, user_id, response = CommonService \
+                .verify_token_get_user_id(request_dict, request)
+            if token_code != 0:
+                return response.json(token_code)
             if operation == 'getCardsInfo':
                 return self.get_cards_info(request_dict, response)
             elif operation == 'getExperiencePackage':
@@ -91,7 +91,7 @@ class WXTechController(View):
             """
             try:
                 LOGGER.info('*****WXTechController.get_experience_package:params'.format(request_dict))
-                serial_no = request_dict.get('serial_no', None)
+                serial_no = request_dict.get('serialNo', None)
                 if not serial_no:
                     return response.json(444)
                 # 查询是否注册iccid
@@ -123,7 +123,7 @@ class WXTechController(View):
             """
             try:
                 LOGGER.info('*****WXTechController.create_order_package:params:{}'.format(request_dict))
-                serial_no = request_dict.get('serial_no', None)
+                serial_no = request_dict.get('serialNo', None)
                 operator = request_dict.get('operator', None)
                 if not all([operator, serial_no]):
                     return response.json(444)
@@ -182,3 +182,31 @@ class WXTechController(View):
                           'trade_no': trade_no}
             Order_Model.objects.create(**order_dict)
             return True
+
+        @classmethod
+        def delete_card_package(cls, request_dict, response):
+            """
+            PC工具清空卡片的所有套餐订购记录
+            """
+            try:
+                LOGGER.info('*****WXTechController.delete_card_package:params:{}'.format(request_dict))
+                sign = request_dict.get('sign', None)
+                serial_no = request_dict.get('serialNo', None)
+                time_stamp = request_dict.get('timeStamp', None)
+                if not CommonService.check_time_stamp_token(sign, time_stamp):
+                    return response.json(13)
+                    # 查询是否注册iccid
+                unicom_device_qs = UnicomDeviceInfo.objects.filter(serial_no=serial_no) \
+                    .values('serial_no', 'user_id', 'iccid')
+                if not unicom_device_qs.exists():
+                    return response.json(173)
+                data = {'iccids': unicom_device_qs[0]['iccid'], 'operator': WXOperatorEnum.TELECOM.value}
+                wx_tech = WXTechObject()
+                res = wx_tech.delete_card_package(**data)
+                if res['code'] == '0':
+                    return response.json(0)
+                return response.json(177)
+            except Exception as e:
+                LOGGER.info('*****WXTechController.delete_card_package:errLine:{}, errMsg:{}'
+                            .format(e.__traceback__.tb_lineno, repr(e)))
+                return response.json(500, repr(e))

+ 19 - 4
Object/WXTechObject.py

@@ -68,10 +68,7 @@ class WXTechObject:
         @return: 卡信息
         """
         url = WX_TECH_URL + '/api/v2/card/getCardsInfo'
-        rq_body = self.get_request_params(**params)
-        response = requests.post(url, data=rq_body, headers=self.headers)
-        assert response.status_code == 200
-        return UnicomObjeect().get_text_dict(response)
+        return self.wx_service_api(url, **params)
 
     def create_order_package(self, **params):
         """
@@ -80,6 +77,24 @@ class WXTechObject:
         @return: 卡信息
         """
         url = WX_TECH_URL + '/api/v2/package/orderPackage'
+        return self.wx_service_api(url, **params)
+
+    def delete_card_package(self, **params):
+        """
+        清空卡片的所有套餐订购记录
+        @param params: operator、iccids
+        @return: 删除成功|失败
+        """
+        url = WX_TECH_URL + '/api/v2/outputApi/deleteCardPackage'
+        return self.wx_service_api(url, **params)
+
+    def wx_service_api(self, url, **params):
+        """
+        @param url 请求地址
+        @param 业务必填参数
+        五兴业务API 统一封装加签请求
+        """
+        # 系统参数合并业务参数并加签得到请求参数
         rq_body = self.get_request_params(**params)
         response = requests.post(url, data=rq_body, headers=self.headers)
         assert response.status_code == 200