company.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # -*- coding: utf-8 -*-
  2. import json
  3. from odoo import http
  4. from odoo.http import request
  5. from .base import BaseController
  6. import logging
  7. _logger = logging.getLogger(__name__)
  8. class WxappMessage(http.Controller, BaseController):
  9. @http.route('/<string:sub_domain>/test', auth='public', methods=['GET'])
  10. def test(self, sub_domain, **kwargs):
  11. if not sub_domain:
  12. sub_domain = 'main'
  13. return self.res_ok("{'center':'" + sub_domain + "'}")
  14. @http.route('/apply-company', auth='public', methods=['POST'], csrf=False)
  15. def check_company(self, **kwargs):
  16. company_name, company_number = self._get_params(['company', 'number'])
  17. if not company_name:
  18. return self.res_err(600, u'缺少参数:公司 company')
  19. if not company_number:
  20. return self.res_err(600, u'缺少参数:识别码 number')
  21. company_code = self._query_company_code(company_name, company_number)
  22. if not company_code:
  23. return self.res_err(700, u'公司、识别码错误')
  24. return self.res_ok({'code': company_code})
  25. def _get_params(self, param_list):
  26. if not param_list:
  27. return None
  28. param_values = []
  29. try:
  30. encrypt_type = request.params.get('encrypt_type', 'raw')
  31. if encrypt_type == 'raw':
  32. if request.httprequest.data:
  33. dic = json.loads(request.httprequest.data)
  34. for p in param_list:
  35. param_values.append(dic.get(p, None))
  36. else:
  37. for p in param_list:
  38. v = request.httprequest.values[p] if p in request.httprequest.values else None
  39. param_values.append(v)
  40. return param_values
  41. else:
  42. _logger.info(u'>>> ===error===未处理的请求类型')
  43. return None
  44. except Exception as e:
  45. _logger.info(u'>>> ===error===获取参数出错:' + str(e))
  46. return None
  47. def _query_company_code(self, company_name, company_number):
  48. return request.env(user=1)['wxapp.company'].query_code(company_name, company_number)