AgentCustomerController.py 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. # -*- encoding: utf-8 -*-
  2. """
  3. @File : AgentCustomerController.py
  4. @Time : 2024/3/7 16:56
  5. @Author : stephen
  6. @Email : zhangdongming@asj6.wecom.work
  7. @Software: PyCharm
  8. """
  9. from django.http import QueryDict
  10. from django.views import View
  11. from datetime import datetime
  12. from AgentModel.models import AgentCustomerInfo, AgentCustomerCard, AgentCustomerPackage, AgentCloudServicePackage
  13. from Model.models import UnicomCombo, Store_Meal
  14. from Object.ResponseObject import ResponseObject
  15. from Object.TokenObject import TokenObject
  16. class AgentCustomerView(View):
  17. def get(self, request, *args, **kwargs):
  18. request.encoding = 'utf-8'
  19. operation = kwargs.get('operation')
  20. return self.validation(request.GET, request, operation)
  21. def post(self, request, *args, **kwargs):
  22. request.encoding = 'utf-8'
  23. operation = kwargs.get('operation')
  24. return self.validation(request.POST, request, operation)
  25. def delete(self, request, *args, **kwargs):
  26. request.encoding = 'utf-8'
  27. operation = kwargs.get('operation')
  28. delete = QueryDict(request.body)
  29. if not delete:
  30. delete = request.GET
  31. return self.validation(delete, request, operation)
  32. def put(self, request, *args, **kwargs):
  33. request.encoding = 'utf-8'
  34. operation = kwargs.get('operation')
  35. put = QueryDict(request.body)
  36. return self.validation(put, request, operation)
  37. def validation(self, request_dict, request, operation):
  38. AgentCustomerInfo.objects.filter()
  39. language = request_dict.get('language', 'en')
  40. response = ResponseObject(language, 'pc')
  41. if operation == 'getUnicomAndIcloud':
  42. return self.get_unicom_and_icloud(response)
  43. else:
  44. return response.json(444, 'operation')
  45. def get_unicom_and_icloud(self, response):
  46. try:
  47. # 云存储套餐查询,只包括is_show=1的记录
  48. store_meal_qs = Store_Meal.objects.filter(is_show=1).values(
  49. 'id',
  50. 'bucket__bucket',
  51. 'day',
  52. 'expire',
  53. 'commodity_type',
  54. 'commodity_code',
  55. 'is_discounts',
  56. 'discount_price',
  57. 'virtual_price',
  58. 'price',
  59. 'currency',
  60. 'symbol',
  61. 'is_show',
  62. 'is_ai',
  63. 'pixel_level',
  64. 'add_time',
  65. 'update_time'
  66. )
  67. store_meal_list = [{
  68. 'storeMealID': store_meal['id'],
  69. 'bucket': store_meal['bucket__bucket'],
  70. 'day': store_meal['day'],
  71. 'expire': store_meal['expire'],
  72. 'commodity_type': store_meal['commodity_type'],
  73. 'pay_type': [pay_type['id'] for pay_type in
  74. Store_Meal.objects.get(id=store_meal['id']).pay_type.values('id')],
  75. 'commodity_code': store_meal['commodity_code'],
  76. 'is_discounts': store_meal['is_discounts'],
  77. 'discount_price': store_meal['discount_price'],
  78. 'virtual_price': store_meal['virtual_price'],
  79. 'price': store_meal['price'],
  80. 'currency': store_meal['currency'],
  81. 'symbol': store_meal['symbol'],
  82. 'is_show': store_meal['is_show'],
  83. 'is_ai': store_meal['is_ai'],
  84. 'pixel_level': store_meal['pixel_level'],
  85. 'addTime': store_meal['add_time'].strftime("%Y-%m-%d %H:%M:%S"),
  86. 'updTime': store_meal['update_time'].strftime("%Y-%m-%d %H:%M:%S"),
  87. } for store_meal in store_meal_qs]
  88. # 联通套餐查询,只包括is_show=1的记录
  89. combo_qs = UnicomCombo.objects.filter(is_show=1, is_del=False).values(
  90. 'id', 'status', 'combo_name',
  91. 'flow_total', 'combo_type',
  92. 'expiration_days',
  93. 'expiration_type', 'price', 'is_unlimited',
  94. 'updated_time', 'created_time',
  95. 'remark', 'is_show', 'sort', 'virtual_price'
  96. )
  97. combo_list = [{
  98. 'id': item['id'],
  99. 'status': item['status'],
  100. 'comboType': item['combo_type'],
  101. 'comboName': item['combo_name'],
  102. 'flowTotal': item['flow_total'],
  103. 'expirationDays': item['expiration_days'],
  104. 'expirationType': item['expiration_type'],
  105. 'price': item['price'],
  106. 'sort': item['sort'],
  107. 'isUnlimited': item['is_unlimited'],
  108. 'updatedTime': datetime.utcfromtimestamp(item['updated_time']).strftime("%Y-%m-%d %H:%M:%S"),
  109. 'createdTime': datetime.utcfromtimestamp(item['created_time']).strftime("%Y-%m-%d %H:%M:%S"),
  110. 'remark': item['remark'],
  111. 'isShow': item['is_show'],
  112. 'payTypes': [pay_type['id'] for pay_type in
  113. UnicomCombo.objects.get(id=item['id']).pay_type.values('id')],
  114. 'virtualPrice': item['virtual_price']
  115. } for item in combo_qs]
  116. # 合并结果并返回
  117. return response.json(0, {
  118. 'storeMealList': store_meal_list,
  119. 'comboList': combo_list,
  120. })
  121. except Exception as e:
  122. print(e)
  123. return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))