Esempio n. 1
0
 def validate_state(self, value):
     try:
         if value.data == "0":
             self.state.data = "0"
         else:
             self.state.data = OrderStateEnum(int(value.data))
     except Exception as e:
         raise StopValidation("无效的订单状态")
Esempio n. 2
0
 def validate_state(self, value):
     try:
         if value.data == "0":
             self.state.data = "0"
         else:
             state = int(value.data) if int(value.data) in [10, 30, 40
                                                            ] else 0
             self.state.data = OrderStateEnum(state)
     except Exception as e:
         raise StopValidation("无效的订单状态")
Esempio n. 3
0
        ),
        'mch_tx_id':
        fields.String(
            required=True,
            description='商户订单号,最大128个字符',
        ),
        'sys_tx_id':
        fields.String(
            required=True,
            description='平台订单号,最大32个字符',
        ),
        'state':
        fields.String(
            required=True,
            description='订单状态',
            example=OrderStateEnum.description_name_desc(
                values=[OrderStateEnum.SUCCESS, OrderStateEnum.FAIL]),
        ),
        'extra':
        fields.String(
            required=False,
            description='(不参与签名)透传数据',
        ),
    })

##############################################
# API的响应的数据model
##############################################
DocResponseDeposit = api.model(
    'DocResponseDeposit', {
        'redirect_url':
        fields.String(
Esempio n. 4
0
 def state(self) -> OrderStateEnum:
     return OrderStateEnum(self._state)
Esempio n. 5
0
        fields.Integer(
            required=True,
            description='页码',
            example=1,
        ),
        'begin_time':
        fields.String(
            required=True, description='开始时间', example="2019-07-01 00:00:00"),
        'end_time':
        fields.String(
            required=True, description='结束时间', example="2019-07-25 00:00:00"),
        'state':
        fields.String(
            required=True,
            description='订单状态',
            example=OrderStateEnum.get_back_desc_list(PayTypeEnum.WITHDRAW) +
            ", 0为全部",
        ),
        'done_begin_time':
        fields.String(required=False,
                      description='开始时间(订单完成时间)',
                      example="2019-07-01 00:00:00"),
        'done_end_time':
        fields.String(required=False,
                      description='结束时间(订单完成时间)',
                      example="2019-07-25 00:00:00"),
    })

#################################################
# 用户提现订单详情
#################################################
Esempio n. 6
0
        fields.String(required=True, description="系统订单号", example="00001"),
        "mch_tx_id":
        fields.String(required=True, description="商户订单号", example="0001"),
        "merchant":
        fields.String(required=True, description="商户名称", example="TEST"),
        "source":
        fields.String(required=True, description="订单来源", example="测试用户"),
        "amount":
        fields.String(required=True, description="提现金额", example="5000"),
        "create_time":
        fields.String(
            required=True, description="创建时间", example="2019-01-23 09:21:34"),
        "state":
        fields.String(required=True,
                      description="订单状态",
                      example=OrderStateEnum.get_value_list()),
        "operator":
        fields.String(required=True, description="操作员", example="kv"),
        "deliver":
        fields.String(required=True,
                      description="通知状态",
                      example=DeliverStateEnum.get_value_list()),
        "user_flag":
        fields.String(required=True,
                      description="用户标签",
                      example=AccountFlagEnum.get_name_list()),
    })

AllWithdrawList = api.model(
    'AllWithdrawList', {
        'entries': fields.List(fields.Nested(WithdrawItem)),
Esempio n. 7
0
    def do_notify(cls, order, op_account=None, comment=None):
        """
        网关回调通知
        :return:
        """
        rst = dict(msg=None)
        if not order.notify_url:
            # 不需要通知
            rst['msg'] = "没有通知URL,不需要发送通知"
            return rst

        if order.state not in OrderStateEnum.get_final_states():
            rst['msg'] = "订单不是成功/失败状态,还没有完成,不能通知商户"
            return rst

        data = dict(
            merchant_id=order.merchant.value,
            amount=str(order.amount),
            tx_amount=str(order.tx_amount),
            mch_tx_id=order.mch_tx_id,
            sys_tx_id=order.sys_tx_id,
            state=order.state.name,
        )

        data['sign'] = GatewaySign(order.merchant).generate_sign(data)
        data['extra'] = order.extra

        try:
            current_app.logger.info('do_notify: %s, data: %s',
                                    order.notify_url, data)
            rsp = requests.post(order.notify_url, json=data)
            current_app.logger.info('do_notify: %s, status code: %s, data: %s',
                                    order.notify_url, rsp.status_code,
                                    rsp.text)
        except:
            current_app.logger.fatal(traceback.format_exc())
            current_app.logger.error('do_notify, url: %s, request data: %s',
                                     order.notify_url, data)
            rst['msg'] = "通知失败,HTTP网络异常"
            return rst

        if rsp.status_code != 200:
            current_app.logger.error(
                'do_notify, url: %s, request data: %s, response data: %s',
                order.notify_url, data, rsp.text)
            rst['msg'] = "通知失败,HTTP status_code非200:%s" % rsp.status_code
            return rst

        try:
            json_data = rsp.json()
        except:
            current_app.logger.error(
                'do_notify, url: %s, request data: %s, response data: %s',
                order.notify_url, data, rsp.text)
            current_app.logger.fatal(traceback.format_exc())
            rst['msg'] = "通知失败,无法解析json数据"
            return rst

        if json_data['error_code'] != 200:
            rst['msg'] = "通知失败,error_code非200:%s" % json_data['error_code']
            current_app.logger.error(
                'do_notify, url: %s, request data: %s, response data: %s',
                order.notify_url, data, json_data)
            return rst

        # 更新订单通知完成
        if order.deliver != DeliverStateEnum.DONE:
            order, ref_id = OrderUpdateCtl.update_order_event(
                order_id=order.order_id,
                uid=order.uid,
                merchant=order.merchant,
                deliver=DeliverStateEnum.DONE,
                op_account=op_account,
                comment=comment,
            )
            if not order:
                rst['msg'] = '订单更新失败, 请研发检查错误日志, sys_tx_id: %s' % (
                    order.sys_tx_id, )
                current_app.logger.fatal(rst['msg'])
                return rst

        rst['msg'] = "通知成功"
        return rst
Esempio n. 8
0
    {
        "tx_id":
        fields.String(
            description="交易流水号",
            example="",
        ),
        "amount":
        fields.String(
            description='订单金额',
            example="560.03",
        ),
        "create_time":
        fields.String(description='订单发起时间', example="2019-07-29"),
        "status":
        fields.String(description='订单状态',
                      example=OrderStateEnum.get_desc_list()),
        "order_type":
        fields.String(description='订单类型', example=PayTypeEnum.get_desc_list()),
        "pay_method":
        fields.String(description='支付方式',
                      example=PayMethodEnum.get_desc_list()),

        # 转账字段
        "out_account":
        fields.String(
            description='出款手机手号码',
            example="",
        ),
        "in_account":
        fields.String(
            description='收款手机号码',
Esempio n. 9
0
        "amount":
        fields.String(required=True, description="发起金额", example="500"),
        "tx_amount":
        fields.String(required=True, description="实际支付金额", example="500"),
        "fee":
        fields.String(required=True, description="手续费", example="2"),
        "create_time":
        fields.String(
            required=True, description="创建时间", example="2019-09-23 09:21:34"),
        "done_time":
        fields.String(
            required=True, description="完成时间", example="2019-09-23  09:22:08"),
        "state":
        fields.String(required=True,
                      description="订单状态",
                      example=OrderStateEnum.get_desc_value_pairs()),
        "deliver":
        fields.String(required=True,
                      description="订单状态",
                      example=DeliverStateEnum.get_desc_value_pairs()),
    })

MerchantDepositOrderList = api.model(
    'MerchantDepositOrderList', {
        'entries': fields.List(fields.Nested(DepositOrderItem)),
        'total': fields.String(required=True, description="总条数", example="518")
    })


class MerchantDepositOrderResult(ResponseSuccess):
    data_model = MerchantDepositOrderList
Esempio n. 10
0
                      example="201903291338464873929024"),
        "pay_method":
        fields.String(required=True,
                      description="支付方法",
                      example=PayMethodEnum.description()),
        "amount":
        fields.String(required=True, description="发起金额", example="500"),
        "tx_amount":
        fields.String(required=True, description="实际支付金额", example="499.98"),
        "create_time":
        fields.String(
            required=True, description="创建时间", example="2019-09-27 08:03:45"),
        "state":
        fields.String(required=True,
                      description="订单状态",
                      example=OrderStateEnum.description())
    })

WithdrawItem = api.model(
    "WithdrawItem", {
        "mch_tx_id":
        fields.String(required=True,
                      description="商户订单号",
                      example="PN20190328123344444404444"),
        "sys_tx_id":
        fields.String(required=True,
                      description="系统订单号",
                      example="201903291338464873929024"),
        "amount":
        fields.String(required=True, description="提现金额", example="500"),
        "fee":
Esempio n. 11
0
class DepositOrderListSelectResultForm(BaseForm):
    """
    运营在新增商户时,配置商户的基本信息表单
    """
    order_id = StringField(description="商户订单号/系统订单号", default="")
    merchant_name = StringField(validators=[], description="商户名称")
    channel = StringField(validators=[], description="通道名称")
    page_size = IntegerField(validators=[DataRequired()], description="单页数据条数")
    page_index = IntegerField(validators=[DataRequired()], description="页码")
    begin_time = StringField(validators=[DataRequired()],
                             description="开始时间",
                             default="")
    end_time = StringField(validators=[DataRequired()],
                           description="结束时间",
                           default="")
    state = StringField(validators=[DataRequired()],
                        default="0",
                        description=OrderStateEnum.description())
    done_begin_time = StringField(description="开始时间(订单完成时间)", default="")
    done_end_time = StringField(description="结束时间(订单完成时间)", default="")

    @stop_validate_if_error_occurred
    def validate_channel(self, value):
        try:
            if value.data:
                self.channel.data = ChannelConfigEnum.from_name(value.data)
            else:
                self.channel.data = None
        except Exception as e:
            raise StopValidation("无效的channel")

    @stop_validate_if_error_occurred
    def validate_done_begin_time(self, value):
        try:
            if value.data:
                self.done_begin_time.data = DateTimeKit.str_to_datetime(
                    value.data, DateTimeFormatEnum.SECONDS_FORMAT)
        except Exception as e:
            raise StopValidation("时间格式不对 精确到秒")

    @stop_validate_if_error_occurred
    def validate_done_end_time(self, value):
        try:
            if value.data:
                self.done_end_time.data = DateTimeKit.str_to_datetime(
                    value.data, DateTimeFormatEnum.SECONDS_FORMAT)
        except Exception as e:
            raise StopValidation("时间格式不对 精确到秒")

    @stop_validate_if_error_occurred
    def validate_page_size(self, value):
        try:
            if not isinstance(value.data, int):
                raise StopValidation("无效的数据类型")
            if value.data == 0:
                raise StopValidation("单页条数不能为0")
            self.page_size.data = value.data
        except Exception as e:
            raise StopValidation("无效的数据条数")

    @stop_validate_if_error_occurred
    def validate_page_index(self, value):
        try:
            if not isinstance(value.data, int):
                raise StopValidation("无效的数据类型")
            if value.data == 0:
                raise StopValidation("页码不能为 0")
            self.page_index.data = value.data
        except Exception as e:
            raise StopValidation("无效的页码")

    @stop_validate_if_error_occurred
    def validate_merchant_name(self, value):
        try:
            if value.data:
                self.merchant_name.data = MerchantEnum.from_name(value.data)
            else:
                self.merchant_name.data = None
        except Exception as e:
            raise StopValidation("无效的商户名称")

    @stop_validate_if_error_occurred
    def validate_state(self, value):
        try:
            if value.data == "0":
                self.state.data = "0"
            else:
                self.state.data = OrderStateEnum(int(value.data))
        except Exception as e:
            raise StopValidation("无效的订单状态")

    @stop_validate_if_error_occurred
    def validate_begin_time(self, value):
        try:
            self.begin_time.data = DateTimeKit.str_to_datetime(
                value.data, DateTimeFormatEnum.SECONDS_FORMAT)
        except Exception as e:
            raise StopValidation("时间格式不对 精确到秒")

    @stop_validate_if_error_occurred
    def validate_end_time(self, value):
        try:
            self.end_time.data = DateTimeKit.str_to_datetime(
                value.data, DateTimeFormatEnum.SECONDS_FORMAT)
        except Exception as e:
            raise StopValidation("时间格式不对 精确到秒")
Esempio n. 12
0
    def post(self):
        """
        充值订单详情
        :return:
        """
        # form表单验证用提款的
        form, error = WithDrawBankForm().request_validate()
        if error:
            return error.as_response()

        # 取得订单id
        order_id = form.order_id.data
        # 根据订单id获取对应的商户 用户id
        order_map = GlobalOrderId.query_global_id(order_id)
        # 获取商户id
        merchant = order_map.merchant

        # 根据商户id 订单id查询具体的订单信息
        entry = OrderDeposit.query_by_order_id(order_id=order_id,
                                               merchant=merchant)

        # 查询对应的订单详情表
        detail = OrderDetailDeposit.query_by_order_id(merchant=merchant,
                                                      order_id=order_id)

        # 拼接返回数据
        detail_head = dict(
            source=entry.source.desc,
            create_time=entry.str_create_time,
            done_time=detail.str_done_time,
            mch_tx_id=entry.mch_tx_id,
            sys_tx_id=entry.sys_tx_id,
            state=entry.state.get_back_desc(PayTypeEnum.DEPOSIT),
            settle=entry.settle.desc,
            deliver=entry.deliver.desc,
            amount=entry.amount,
        )
        order_merchant_info = dict(merchant_name=merchant.name,
                                   offer=detail.offer,
                                   fee=detail.fee,
                                   cost=detail.cost,
                                   profit=detail.profit)
        deliver_info = None
        if entry.channel_id:
            proxy_entry = ChannelConfig.query_by_channel_id(entry.channel_id)
            channel_enum = proxy_entry.channel_enum

            deliver_info = dict(channel_name=channel_enum.desc,
                                mch_id=channel_enum.conf['mch_id'],
                                channel_tx_id=entry.channel_tx_id)
        user_info = dict(
            user_id=entry.uid,
            ip=detail.ip,
            location=GeoIpKit(detail.ip).location,
            device="",
        )

        event_entries = OrderEvent.query_model(
            query_fields=dict(order_id=entry.order_id), date=entry.create_time)

        event_log_list = list()

        for event in event_entries:
            order_event = event.data_after[0]
            order_event.update(event.data_after[1])

            if 'state' in order_event:
                state = list(order_event['state'].keys())[0]
                event_log_list.append(
                    dict(
                        operate_type=OrderStateEnum.from_name(
                            state).get_back_desc(PayTypeEnum.DEPOSIT),
                        operator=order_event.get('op_account') or '',
                        result="成功",
                        operate_time=DateTimeKit.timestamp_to_datetime(
                            order_event['update_time']),
                        comment=order_event.get('comment') or '',
                    ))

            if 'deliver' in order_event:
                deliver = list(order_event['deliver'].keys())[0]
                event_log_list.append(
                    dict(
                        operate_type=DeliverStateEnum.from_name(deliver).desc,
                        operator=order_event.get('op_account') or '',
                        result="成功",
                        operate_time=DateTimeKit.timestamp_to_datetime(
                            order_event['update_time']),
                        comment=order_event.get('comment') or '',
                    ))

        return DepositOrderDetailResult(bs_data=dict(
            detail_head=detail_head,
            order_merchant_info=order_merchant_info,
            deliver_info=deliver_info,
            user_info=user_info,
            event_log_list=event_log_list), ).as_response()
Esempio n. 13
0
    def post(self):
        """
        提现订单详情
        :return:
        """
        form, error = WithDrawBankForm().request_validate()
        if error:
            return error.as_response()

        order_id = form.order_id.data
        order_map = GlobalOrderId.query_global_id(order_id)
        merchant = order_map.merchant
        entry = OrderWithdraw.query_by_order_id(order_id=order_id,
                                                merchant=merchant)
        detail = OrderDetailWithdraw.query_by_order_id(merchant=merchant,
                                                       order_id=order_id)
        detail_head = dict(source=entry.source.desc,
                           op_account=detail.op_account,
                           deliver_type=detail.deliver_type.desc
                           if detail.deliver_type else None,
                           create_time=entry.str_create_time,
                           alloc_time=detail.str_alloc_time,
                           deal_time=detail.str_deal_time,
                           done_time=detail.str_done_time,
                           mch_tx_id=entry.mch_tx_id,
                           sys_tx_id=entry.sys_tx_id,
                           state=entry.state.get_back_desc(
                               PayTypeEnum.WITHDRAW),
                           settle=entry.settle.desc,
                           deliver=entry.deliver.desc,
                           amount=entry.amount)
        order_merchant_info = dict(
            merchant_name=merchant.name,
            fee=detail.fee,
            cost=detail.cost,
            profit=detail.profit,
            withdraw_type="测试" if merchant.is_test else "用户提现")
        deliver_info = None
        if entry.channel_id:
            proxy_entry = ProxyChannelConfig.query_by_channel_id(
                entry.channel_id)
            channel_enum = proxy_entry.channel_enum

            deliver_info = dict(channel_name=channel_enum.desc,
                                mch_id=channel_enum.conf['mch_id'],
                                channel_tx_id=entry.channel_tx_id)
        user_info = dict(
            user_id=entry.uid,
            ip=detail.ip,
            location=GeoIpKit(detail.ip).location,
            device="",
        )

        event_entries = OrderEvent.query_model(
            query_fields=dict(order_id=entry.order_id), date=entry.create_time)

        event_log_list = list()

        for event in event_entries:
            order_event = event.data_after[0]
            order_event.update(event.data_after[1])

            if 'state' in order_event:
                state = list(order_event['state'].keys())[0]
                event_log_list.append(
                    dict(
                        operate_type=OrderStateEnum.from_name(
                            state).get_back_desc(PayTypeEnum.WITHDRAW),
                        operator=order_event.get('op_account') or '',
                        result="成功",
                        operate_time=DateTimeKit.timestamp_to_datetime(
                            order_event['update_time']),
                        comment=order_event.get('comment') or '',
                    ))

            if 'deliver' in order_event:
                deliver = list(order_event['deliver'].keys())[0]
                event_log_list.append(
                    dict(
                        operate_type=DeliverStateEnum.from_name(deliver).desc,
                        operator=order_event.get('op_account') or '',
                        result="成功",
                        operate_time=DateTimeKit.timestamp_to_datetime(
                            order_event['update_time']),
                        comment=order_event.get('comment') or '',
                    ))

        return WithdrawOrderDetailResult(
            bs_data=dict(detail_head=detail_head,
                         order_merchant_info=order_merchant_info,
                         deliver_info=deliver_info,
                         user_info=user_info,
                         event_log_list=event_log_list)).as_response()