UnicomComboController.py 11 KB

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