Browse Source

联通停卡完善log打印

zhangdongming 3 years ago
parent
commit
9ed8ce0b20
2 changed files with 8 additions and 53 deletions
  1. 2 2
      Controller/UnicomCombo/UnicomComboTaskController.py
  2. 6 51
      Object/UnicomObject.py

+ 2 - 2
Controller/UnicomCombo/UnicomComboTaskController.py

@@ -133,8 +133,6 @@ class UnicomComboTaskView(View):
                 flow_total = combo_qs['flow_total']
                 # 队列已使用总流量总量
                 flow_total_usage = unicom_api.get_flow_usage_total(iccid)
-                logger.info('--->iccid:{};套餐总值:{},激活时队列已用总流量:{},当前最新套餐队列已使用流量量:{}'
-                            .format(iccid, flow_total, activate_usage_flow, flow_total_usage))
                 is_expire = False
                 flow = activate_usage_flow + flow_total
                 if flow_total_usage > 0:
@@ -147,11 +145,13 @@ class UnicomComboTaskView(View):
 
                 # 检查是否有当月未使用套餐 没有则停卡
                 if is_expire:
+                    logger.info('-->当前卡{}流量已用完'.format(iccid))
                     flow_exceed = flow_total_usage - flow
                     UnicomComboOrderInfo.objects.filter(id=item['id']) \
                         .update(status=2, updated_time=now_time, flow_exceed=flow_exceed)
                     activate_status = cls.query_unused_combo_and_activate(iccid, year, month,
                                                                           flow_total_usage)
+                    logger.info('-->当前卡{}流量已用完,是否有生效套餐:{}'.format(iccid, activate_status))
                     if not activate_status:
                         # 停用
                         unicom_api.change_device_to_disable(iccid)

+ 6 - 51
Object/UnicomObject.py

@@ -7,9 +7,8 @@
 @Software: PyCharm
 """
 import base64
-import datetime
 import json
-from decimal import Decimal
+import logging
 
 import requests
 from Crypto.Cipher import AES
@@ -26,6 +25,8 @@ from Object.utils.SymmetricCryptoUtil import AESencrypt
 https://www.showdoc.com.cn/unicomJYHapi/8158648460007467
 """
 
+logger = logging.getLogger('info')
+
 
 class UnicomObjeect:
     def __init__(self):
@@ -292,60 +293,14 @@ class UnicomObjeect:
         """
         if iccid:
             re_data = {"iccid": iccid, "status": 2}
-            UnicomObjeect().update_device_state(**re_data)
+            response = UnicomObjeect().update_device_state(**re_data)
+            logger.info('停用iccid响应结果:{}'.format(response))
             # 查询是否停用成功
             re_data.pop('status')
             result = UnicomObjeect().query_device_status(**re_data)
             res_dict = UnicomObjeect().get_text_dict(result)
+            logger.info('查询iccid状态{}'.format(res_dict))
             if res_dict['data']['status'] != 3:
                 UnicomObjeect().update_device_state(**re_data)
             return True
         return None
-
-
-if __name__ == '__main__':
-
-    today = datetime.datetime.today()
-    year = today.year
-    month = today.month
-    print(year)
-    print(month)
-    print(type(year))
-    if not '':
-        print('为空')
-    price = '12.13'
-    print(float(price))
-    discount = '6'
-    dd = Decimal(price) - Decimal(discount)
-    print(dd.quantize(Decimal('0.00')))
-
-    unicom_api = UnicomObjeect()
-    data = {'foo': 1, 'bar': 2, 'baz': 3}
-    print(unicom_api.createSign(**data))
-    # result = unicom_api.generate_token()
-    # result = unicom_api.refresh_token('5d0c0f30-99bd-4f17-9614-3524495b05d4')
-    params = {'iccid': '89860621330065433774', 'status': 2}
-    # response = unicom_api.verify_device(**params)
-    # response = unicom_api.query_device_status(**params)
-    response = unicom_api.update_device_state(**params)
-    # response = unicom_api.query_device_usage_history(**params)
-    # response = unicom_api.query_current_renew_list_usage_details(**params)
-    # unicom_api.get_device_batch_detail()
-    # response = unicom_api.query_package_list(**params)
-    # response = unicom_api.query_renewal_list(**params)
-
-    if response.status_code == 200:
-        res = json.loads(response.text)
-        print(res)
-    response_json = {
-        "success": True,
-        "msg": "操作成功",
-        "code": 0,
-        "data": {
-            "iccid": "8986062018007784202",
-            "completeIccid": "89860620180077842020",
-            "status": 1
-        }
-    }
-    print(response_json['data']['iccid'])
-    print(response.status_code)