UnicomComboController.py 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. # -*- encoding: utf-8 -*-
  2. """
  3. @File : UnicomComboController.py
  4. @Time : 2022/6/23 9:18
  5. @Author : stephen
  6. @Email : zhangdongming@asj6.wecom.work
  7. @Software: PyCharm
  8. """
  9. import json
  10. import logging
  11. import time
  12. from django.db import transaction
  13. from django.http import HttpResponse
  14. from django.views.generic.base import View
  15. class UnicomComboView(View):
  16. pass
  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. #
  22. # def post(self, request, *args, **kwargs):
  23. # request.encoding = 'utf-8'
  24. # operation = kwargs.get('operation')
  25. # return self.validation(request.POST, request, operation)
  26. #
  27. # def validation(self, request_dict, request, operation):
  28. # if operation == 'buy-notify':
  29. # return self.package_callback_notify(request_dict, request)
  30. # elif operation == 'device-queue-monitoring':
  31. # return self.device_queue_monitoring_push(request_dict, request)
  32. # elif operation == 'device-status-change':
  33. # return self.device_status_change_push(request_dict, request)
  34. # else:
  35. # token = TokenObject(request.META.get('HTTP_AUTHORIZATION'))
  36. # lang = request_dict.get('lang', token.lang)
  37. # response = ResponseObject(lang)
  38. # if token.code != 0:
  39. # return response.json(token.code)
  40. # user_id = token.userID
  41. # if operation == 'device-bind':
  42. # return self.device_add(user_id, request_dict, response)
  43. # elif operation == 'combo-save':
  44. # return self.save_unicom_combo(request_dict, response)
  45. # elif operation == 'combo-list':
  46. # return self.query_package_list(response)
  47. #
  48. # @classmethod
  49. # def device_add(cls, user_id, request_dict, response):
  50. # """
  51. # 设备绑定iccid
  52. # @param user_id:
  53. # @param request_dict:
  54. # @param response:
  55. # @return:
  56. # """
  57. # iccid = request_dict.get('iccid', None)
  58. # uid = request_dict.get('uid', None)
  59. # if not all([iccid, uid]):
  60. # return response.json(444)
  61. # n_time = int(time.time())
  62. # try:
  63. # # 待完善代码 根据uid与用户id验证系统设备
  64. # unicom_device_qs = UnicomDeviceInfo.objects.filter(iccid=iccid)
  65. # if unicom_device_qs.exists():
  66. # return response.json(174)
  67. # unicom_obj = UnicomObjeect()
  68. # result = unicom_obj.verify_device(iccid=iccid)
  69. # if result.status_code == 200 and result.text:
  70. # res_dict = json.loads(result.text)
  71. # if res_dict['success']:
  72. # if res_dict['data']['status'] == 0:
  73. # return response.json(173)
  74. # params = {'user_id': user_id, 'iccid': iccid, 'uid': uid, 'updated_time': n_time,
  75. # 'created_time': n_time}
  76. # UnicomDeviceInfo.objects.create(**params)
  77. # return response.json(0)
  78. # else:
  79. # return response.json(173)
  80. # except Exception as e:
  81. # print(e)
  82. # return response.json(177, repr(e))
  83. #
  84. # @classmethod
  85. # def save_unicom_combo(cls, request_dict, response):
  86. # """
  87. # 联通套餐保存
  88. # @param request_dict:
  89. # @param response:
  90. # @return:
  91. # """
  92. # combo_id = request_dict.get('id', None)
  93. # combo_name = request_dict.get('comboName', None)
  94. # flow_total = request_dict.get('flowTotal', None)
  95. # expiration_days = request_dict.get('expirationDays', None)
  96. # expiration_type = request_dict.get('expirationType', None)
  97. # price = request_dict.get('price', None)
  98. # remark = request_dict.get('remark', None)
  99. # pay_type = request_dict.get('payType', '').split(',')
  100. # if not all([pay_type, combo_name, flow_total, expiration_days, expiration_type, price]):
  101. # return response.json(444)
  102. # try:
  103. # flow_total = int(flow_total)
  104. # expiration_days = int(expiration_days)
  105. # expiration_type = int(expiration_type)
  106. # with transaction.atomic():
  107. # re_data = {
  108. # 'combo_name': combo_name,
  109. # 'flow_total': flow_total,
  110. # 'expiration_days': expiration_days,
  111. # 'expiration_type': expiration_type,
  112. # 'price': price,
  113. # }
  114. # if remark:
  115. # re_data['remark'] = remark
  116. # if combo_id:
  117. # UnicomCombo.objects.filter(id=combo_id).update(**re_data)
  118. # UnicomCombo.objects.get(id=combo_id).pay_type.set(pay_type)
  119. # return response.json(0)
  120. # UnicomCombo.objects.create(**re_data).pay_type.set(pay_type)
  121. # return response.json(0)
  122. # except Exception as e:
  123. # print(e)
  124. # return response.json(177, repr(e))
  125. #
  126. # @classmethod
  127. # def query_package_list(cls, response):
  128. # """
  129. # 查询套餐列表
  130. # @return:
  131. # """
  132. # try:
  133. # combo_qs = UnicomCombo.objects.filter(is_show=1, status=0, is_del=False) \
  134. # .order_by('sort').values('id', 'combo_name',
  135. # 'flow_total',
  136. # 'expiration_days',
  137. # 'expiration_type', 'price',
  138. # 'remark')
  139. # if not combo_qs.exists():
  140. # return response.json(0, [])
  141. # combo_list = []
  142. # for item in combo_qs:
  143. # # 获取支付方式列表
  144. # pay_type_qs = Pay_Type.objects.filter(unicomcombo=item['id']).values('id', 'payment')
  145. # combo_list.append({
  146. # 'id': item['id'],
  147. # 'comboName': item['combo_name'],
  148. # 'flowTotal': item['flow_total'],
  149. # 'expirationDays': item['expiration_days'],
  150. # 'expirationType': item['expiration_type'],
  151. # 'price': item['price'],
  152. # 'remark': item['remark'],
  153. # 'payTypes': list(pay_type_qs),
  154. # })
  155. # return response.json(0, combo_list)
  156. # except Exception as e:
  157. # print(e)
  158. # return response.json(177, repr(e))
  159. #
  160. # @classmethod
  161. # def buy_package(cls):
  162. # """
  163. # 购买套餐
  164. # @return:
  165. # """
  166. # pass
  167. #
  168. # @classmethod
  169. # def query_device_usage_history(cls):
  170. # """
  171. # 查询用量历史
  172. # @return:
  173. # """
  174. #
  175. # @staticmethod
  176. # def package_callback_notify(request_dict, request):
  177. # """
  178. # 异步套餐订购回调
  179. # @param request_dict:
  180. # @param request:
  181. # @return:
  182. # """
  183. # logger = logging.getLogger('info')
  184. # try:
  185. # logger.info('联通异步套餐订购回调参数{}'.format(request_dict))
  186. # body = request.body.decode("utf-8")
  187. # if body:
  188. # dict_data = json.loads(body)
  189. # sign = dict_data['sign']
  190. # logger.info('设备订购异步回调请求参数{}'.format(dict_data))
  191. # dict_data.pop('sign')
  192. # unicom_obj = UnicomObjeect()
  193. # generate_sign = unicom_obj.createSign(**dict_data)
  194. # logger.info('设备订购请求签名{}'.format(sign))
  195. # logger.info('设备订购生成签名{}'.format(generate_sign))
  196. # r_data = {'success': True, 'msg': '成功'}
  197. # return HttpResponse(json.dumps(r_data, ensure_ascii=False), content_type="application/json,charset=utf-8")
  198. # except Exception as e:
  199. # print(repr(e))
  200. # r_data = {'success': False, 'msg': '失败'}
  201. # return HttpResponse(json.dumps(r_data, ensure_ascii=False), content_type="application/json,charset=utf-8")
  202. #
  203. # @staticmethod
  204. # def device_queue_monitoring_push(request_dict, request):
  205. # """
  206. # 设备套餐队列用完或者到期推送
  207. # @param request_dict:
  208. # @param request:
  209. # @return:
  210. # """
  211. # logger = logging.getLogger('info')
  212. # try:
  213. # logger.info('设备套餐队列推送{}'.format(request_dict))
  214. # body = request.body.decode("utf-8")
  215. # if body:
  216. # dict_data = json.loads(body)
  217. # sign = dict_data['sign']
  218. # logger.info('设备套餐队列回调请求参数{}'.format(dict_data))
  219. # dict_data.pop('sign')
  220. # unicom_obj = UnicomObjeect()
  221. # generate_sign = unicom_obj.createSign(**dict_data)
  222. # logger.info('设备套餐队列请求签名{}'.format(sign))
  223. # logger.info('设备套餐队列生成签名{}'.format(generate_sign))
  224. # r_data = {'success': True, 'msg': '成功'}
  225. # return HttpResponse(json.dumps(r_data, ensure_ascii=False), content_type="application/json,charset=utf-8")
  226. # except Exception as e:
  227. # print(repr(e))
  228. # r_data = {'success': False, 'msg': '失败'}
  229. # return HttpResponse(json.dumps(r_data, ensure_ascii=False), content_type="application/json,charset=utf-8")
  230. #
  231. # @staticmethod
  232. # def device_status_change_push(request_dict, request):
  233. # """
  234. # 设备状态变更推送执行场景说明
  235. # @param request_dict:
  236. # @param request:
  237. # @return:
  238. # """
  239. # logger = logging.getLogger('info')
  240. # try:
  241. # logger.info('设备状态变更推送{}'.format(request_dict))
  242. # body = request.body.decode("utf-8")
  243. # if body:
  244. # dict_data = json.loads(body)
  245. # sign = dict_data['sign']
  246. # logger.info('设备状态变更推送请求参数{}'.format(dict_data))
  247. # dict_data.pop('sign')
  248. # unicom_obj = UnicomObjeect()
  249. # generate_sign = unicom_obj.createSign(**dict_data)
  250. # logger.info('设备状态变更推送请求签名{}'.format(sign))
  251. # logger.info('设备状态变更推送生成签名{}'.format(generate_sign))
  252. # r_data = {'success': True, 'msg': '成功'}
  253. # return HttpResponse(json.dumps(r_data, ensure_ascii=False), content_type="application/json,charset=utf-8")
  254. # except Exception as e:
  255. # print(repr(e))
  256. # r_data = {'success': False, 'msg': '失败'}
  257. # return HttpResponse(json.dumps(r_data, ensure_ascii=False), content_type="application/json,charset=utf-8")