Ejemplo n.º 1
0
    def charge_order(self, meituan_order_id):
        order_info = self.master.hgetall(
            "meituan:{0}".format(meituan_order_id))
        if not order_info:
            print("无法查询到订单({0})的详细信息,充值失败".format(meituan_order_id))
            return (False, "fail", "no_order_info")

        product_dict = self.get_product_dict()
        if order_info['product_id'] not in product_dict:
            print("无法查询到订单({0})的充值产品信息,充值失败".format(meituan_order_id))
            return (False, "fail", "no_product_fino")

        try:
            face_value = product_dict.get(
                order_info['product_id']).get('value')

            downstream = self.application.config['downstream'][self.USER_ID]
            code = json.dumps({
                'request_no': meituan_order_id,
                'contract_id': '100001',
                'order_id': meituan_order_id,
                'plat_offer_id': order_info['product_id'],
                'phone_id': order_info['mobile'],
                'facevalue': int(face_value),
            })

            iv = downstream['iv']
            passphrase = downstream['pass']
            aes = AES.new(passphrase, AES.MODE_CBC, iv)

            b = aes.encrypt(padding(code))
            encrypted = base64.b64encode(b).decode('utf8')

            body = json.dumps({'partner_no': self.USER_ID, 'code': encrypted})

            url = 'http://{shard}/data/order'.format(shard=downstream['shard'])

            http_client = AsyncHTTPClient()
            request = HTTPRequest(url=url, method='POST', body=body)
            response = yield http_client.fetch(request)

            if response.code == 200:
                resp = json.loads(response.body.decode('utf8'))

                result = resp['orderstatus']
                if result != 'processing':
                    print('订单({0})充值失败:{1}({2})'.format(
                        meituan_order_id, escape_data_result(result), result))
                    return (False, "fail", "charge_fail")
                else:
                    return (True, "checked", "checked")

        except Exception as e:
            print(meituan_order_id, " exception:", e)
            return (False, "fail", "exception")

        return (False, "fail", "unknown")
Ejemplo n.º 2
0
    def get_export(self):
        args = dict()
        user_id = self.current_user['partner_id']

        args['mail'] = self.argu_list.get('mail')
        args['type'] = self.argu_list.get('type')
        args['user_id'] = self.argu_list.get('user_id')

        if 'admin' not in self.current_user['roles']:
            args['user_id'] = user_id

        if not args.get('criteria'):
            args['criteria'] = {}
            args['criteria']['product'] = self.product
            args['criteria']['start'] = self.argu_list.get('start')
            args['criteria']['end'] = self.argu_list.get('end')
            args['criteria']['result'] = self.argu_list.get('result')
            args['criteria']['price'] = self.argu_list.get('price')
            args['criteria']['area'] = self.argu_list.get('area')
            args['criteria']['order_type'] = self.argu_list.get('order_type')

        else:
            request_log.info('UNKNOWN KEY CRITERIA')

        body = json.dumps(args)
        request_log.info('EXPORT DATA {0}'.format(body))
        http_client = AsyncHTTPClient()

        try:
            downstream = self.application.config['downstream'][user_id]

            iv = downstream['iv']
            passphrase = downstream['pass']
            aes = AES.new(passphrase, AES.MODE_CBC, iv)

            b = aes.encrypt(padding(body))
            encrypted = base64.b64encode(b).decode()

            base_url = self.application.config['connection']['glados_hall']
            url = base_url + '/export/request'
            headers = {'User': user_id}

            response = yield http_client.fetch(url,
                                               method='POST',
                                               headers=headers,
                                               body=encrypted)
            resp = response.body.decode()

            self.finish(resp)

        except:
            request_log.exception('EXPORT FAIL')
            self.finish(json.dumps({'status': 'fail', 'msg': '导出异常,请稍后尝试'}))

        finally:
            http_client.close()
Ejemplo n.º 3
0
    def post(self, product):

        args = self.json_args
        user_id = self.current_user['partner_id']
        args['user_id'] = user_id
        args['criteria']['product'] = product

        if 'admin' not in self.current_user['roles']:
            args['criteria']['user_id'] = user_id

        body = json.dumps(args)

        http_client = AsyncHTTPClient()

        try:
            downstream = self.application.config['downstream'][user_id]

            iv = downstream['iv']
            passphrase = downstream['pass']
            aes = AES.new(passphrase, AES.MODE_CBC, iv)

            b = aes.encrypt(padding(body))
            encrypted = base64.b64encode(b).decode()

            base_url = self.application.config['connection']['glados_hall']
            url = base_url + '/export/request'
            headers = {'User': user_id}

            response = yield http_client.fetch(url,
                                               method='POST',
                                               headers=headers,
                                               body=encrypted)
            resp = response.body.decode()

            self.finish(resp)

        except:
            request_log.exception('EXPORT FAIL')
            self.finish(json.dumps({'status': 'fail', 'msg': '导出异常,请稍后尝试'}))

        finally:
            http_client.close()
Ejemplo n.º 4
0
    def post_start(self):
        batch_id = self.json_args['batch_id']
        user_id = self.current_user['partner_id']

        downstream = self.application.config['downstream'][user_id]
        iv = downstream['iv']
        passphrase = downstream['pass']

        try:
            session = self.session('purus')

            batch_info = session.query(BatchInfo).filter(
                BatchInfo.batch_id == batch_id).filter(
                    BatchInfo.user_id == user_id).first()

            if batch_info is None:
                raise RuntimeError('')

            q = session.query(BatchDetail).filter(
                BatchDetail.batch_id == batch_id).filter(
                    BatchDetail.status == 'create')

            count = q.count()

            i = 0
            for detail in q.order_by(BatchDetail.id).limit(20).all():

                mobile = detail.mobile
                if self.master.sismember('batch:' + batch_id, mobile):
                    continue

                key = 'product:{user_id}:data:{carrier}:{price}'.format(
                    user_id=user_id,
                    carrier=detail.carrier,
                    price=detail.price)

                stage = detail.stage + 1

                product = self.slave.hmget(key, ['offer', 'value'])
                if product[0] is None:
                    continue

                id = self.master.incr('uid:batch')

                order_id = '%s%08d%02d' % (batch_id, id, stage)

                code = json.dumps({
                    'request_no': order_id,
                    'contract_id': '100001',
                    'order_id': order_id,
                    'plat_offer_id': product[0],
                    'phone_id': mobile,
                    'facevalue': int(product[1]),
                })

                aes = AES.new(passphrase, AES.MODE_CBC, iv)
                b = aes.encrypt(padding(code))
                encrypted = base64.b64encode(b).decode('utf8')

                body = json.dumps({'partner_no': user_id, 'code': encrypted})

                url = 'http://{shard}/data/order'.format(
                    shard=downstream['shard'])

                http_client = AsyncHTTPClient()
                result = '99999'

                try:
                    request = HTTPRequest(url=url, method='POST', body=body)
                    response = yield http_client.fetch(request)

                    if response.code == 200:
                        resp = json.loads(response.body.decode('utf8'))
                        result = resp['result_code']
                except Exception as e:
                    pass
                finally:
                    http_client.close()

                # update
                if result == '00000':
                    detail.status = 'call'
                    self.master.sadd('batch:' + batch_id, mobile)
                else:
                    detail.status = 'fail'
                detail.stage = stage
                if stage > 1:
                    detail.order_id += ', ' + order_id
                else:
                    detail.order_id = order_id
                session.add(detail)
                session.commit()

        except Exception as e:
            print(e)
            self.finish(json.dumps({'data': []}))
Ejemplo n.º 5
0
    def post(self, path_args):
        user_id = self.current_user['partner_id']
        prod = self.json_args['prod']
        number = self.json_args['number']

        downstream = self.application.config['downstream'][user_id]

        if 'master' in downstream:
            master_id = downstream['master']
        else:
            master_id = user_id

        key = 'product:{master_id}:data:{prod}'.format(master_id=master_id, prod=prod)

        product = self.master.hmget(key, ['offer', 'value'])
        if product[0] is None:
            self.write_error(405)
            return

        order_id = self.order_id()

        code = json.dumps({
            'request_no': order_id,
            'contract_id': '100001',
            'order_id': order_id,
            'plat_offer_id': product[0],
            'phone_id': number,
            'facevalue': int(product[1]),
        })

        iv = downstream['iv']
        passphrase = downstream['pass']
        aes = AES.new(passphrase, AES.MODE_CBC, iv)

        b = aes.encrypt(padding(code))
        encrypted = base64.b64encode(b).decode('utf8')

        body = json.dumps({'partner_no': user_id, 'code': encrypted})

        url = 'http://{shard}/data/order'.format(shard=downstream['shard'])

        http_client = AsyncHTTPClient()
        try:
            request = HTTPRequest(url=url, method='POST', body=body)
            response = yield http_client.fetch(request)

            if response.code == 200:
                resp = json.loads(response.body.decode('utf8'))

                result = resp['result_code']
                request_no = resp.get('request_no')
                if result == '00000':
                    msg = {'status': 'ok', 'msg': '充值请求发送成功', 'sp_order_id': request_no}

                    self.master.hmset('latest:%s' % user_id, {'prod': prod, 'number': number})
                else:
                    msg = {'status': 'fail',
                           'msg': '充值请求发送失败,错误原因:{info}({result})'.format(
                               info=escape_data_result(result),
                               result=result),
                           'sp_order_id': request_no}

        except Exception as e:
            print(e)
            msg = {'status': 'fail'}
        finally:
            http_client.close()

        self.write(json.dumps(msg))