示例#1
0
class ChannelRouter2Update(Resource):
    method_decorators = admin_decorators

    @ns.expect(RouterAddDoc)
    @ns.marshal_with(ResponseSuccess.gen_doc(api))
    def post(self):
        """
        编辑通道适用规则
        :return:
        """
        form, error = ChannelRouter2AddForm().request_validate()
        if error:
            return error.as_response()

        current_app.logger.info(form.get_data())

        if form.amount_min.data > form.amount_max.data:
            return DataStartMoreThanError(message="最小金额不能大于最大金额").as_response()

        try:
            model, error = ChannelRouter2.update_router(
                channel_enum=form.channel.data,
                interface=form.interface.data,
                amount_min=form.amount_min.data,
                amount_max=form.amount_max.data,
                merchants=form.merchants.data,
                uid_list=form.uid_list.data,
            )
            if error:
                return DataStartMoreThanError(message=error).as_response()
        except IntegrityError as e:
            return ChannelSqlIntegrityError(message=str(e)).as_response()

        return ResponseSuccess().as_response()
示例#2
0
class WithdrawDel(Resource):
    method_decorators = admin_decorators

    @ns.expect(WithdrawAddList)
    @ns.marshal_with(ResponseSuccess.gen_doc(api))
    def post(self):
        """
        代付通道管理: 删除代付通道
        :return:
        """
        form, error = WithdrawAddForm().request_validate()

        if error:
            return error.as_response()

        if form.start_time.data >= form.end_time.data:
            return DateStartMoreThanError().as_response()

        if form.maintain_begin.data:
            if form.maintain_begin.data >= form.maintain_end.data or form.maintain_begin.data < DateTimeKit.get_cur_datetime(
            ):
                return DateStartMoreThanError().as_response()

        if Decimal(form.limit_per_min.data) >= Decimal(
                form.limit_per_max.data):
            return DataStartMoreThanError().as_response()

        if form.limit_day_max.data and Decimal(
                form.limit_per_max.data) > Decimal(form.limit_day_max.data):
            return PerLimitMustLittleDayLimitError().as_response()

        banks = [PaymentBankEnum(int(bank)) for bank in form.banks.data]

        kwargs = dict(
            fee=form.fee.data,
            fee_type=form.fee_type.data,
            limit_per_min=form.limit_per_min.data,
            limit_per_max=form.limit_per_max.data,
            limit_day_max=form.limit_day_max.data
            if form.limit_day_max.data != "" else 0,
            trade_begin_hour=form.start_time.data.hour,
            trade_begin_minute=form.start_time.data.minute,
            trade_end_hour=form.end_time.data.hour,
            trade_end_minute=form.end_time.data.minute,
            maintain_begin=form.maintain_begin.data
            if form.maintain_begin else "",
            maintain_end=form.maintain_end.data if form.maintain_end else "",
            state=form.state.data,
            banks=banks,
            valid=ModelBase.INVALID)

        rst, error = ProxyChannelConfig.update_channel(form.channel_id.data,
                                                       **kwargs)
        if error:
            return error.as_response()

        # 同步缓存
        # ChannelLimitCacheCtl(PayTypeEnum.WITHDRAW).sync_db_channels_to_cache()

        return ResponseSuccess().as_response()
示例#3
0
class ChannelRouterUpdate(Resource):
    method_decorators = admin_decorators

    @ns.expect(RuleEditList)
    @ns.marshal_with(ResponseSuccess.gen_doc(api))
    def post(self):
        """
        编辑引导规则
        :return:
        """
        form, error = ChannelRouterUpdateForm().request_validate()
        if error:
            return error.as_response()

        if form.amount_min.data > form.amount_max.data:
            return DataStartMoreThanError(message="最小金额不能大于最大金额").as_response()

        try:
            model, error = ChannelRouter.update_rule(
                router_id=form.router_id.data,
                config_list=form.config_list.data,
                interface=form.interface.data,
                amount_min=form.amount_min.data,
                amount_max=form.amount_max.data,
                merchants=form.merchants.data,
                uid_list=form.uid_list.data,
            )
            if error:
                return DataStartMoreThanError(message=error).as_response()
        except IntegrityError as e:
            return ChannelSqlIntegrityError(message=str(e)).as_response()

        return ResponseSuccess().as_response()
示例#4
0
class ChannelAdd(Resource):
    method_decorators = admin_decorators

    @ns.expect(ChannelAddList)
    @ns.marshal_with(ResponseSuccess.gen_doc(api))
    def post(self):
        """
        通道管理: 新建通道
        :return:
        """

        form, error = ChannelAddForm().request_validate()
        if error:
            return error.as_response()

        # if form.start_time.data >= form.end_time.data:
        #     return DateStartMoreThanError().as_response()

        if form.maintain_begin.data:
            if form.maintain_begin.data >= form.maintain_end.data or form.maintain_begin.data < DateTimeKit.get_cur_datetime(
            ):
                return DateStartMoreThanError().as_response()

        if Decimal(form.limit_per_min.data) >= Decimal(
                form.limit_per_max.data):
            return DataStartMoreThanError().as_response()

        if form.limit_day_max.data and Decimal(
                form.limit_per_max.data) > Decimal(form.limit_day_max.data):
            return PerLimitMustLittleDayLimitError().as_response()

        kwargs = dict(fee=form.fee.data,
                      fee_type=form.fee_type.data,
                      limit_per_min=form.limit_per_min.data,
                      limit_per_max=form.limit_per_max.data,
                      limit_day_max=form.limit_day_max.data
                      if form.limit_day_max.data != "" else 0,
                      trade_begin_hour=form.start_time.data.hour,
                      trade_begin_minute=form.start_time.data.minute,
                      trade_end_hour=form.end_time.data.hour,
                      trade_end_minute=form.end_time.data.minute,
                      maintain_begin=form.maintain_begin.data,
                      maintain_end=form.maintain_end.data,
                      settlement_type=form.settlement_type.data,
                      state=form.state.data,
                      priority=form.priority.data)

        rst, error = ChannelConfig.update_channel(form.channel_id.data,
                                                  **kwargs)
        if error:
            return error.as_response()

        # 同步缓存
        # ChannelLimitCacheCtl(PayTypeEnum.DEPOSIT).sync_db_channels_to_cache()

        return ResponseSuccess().as_response()