def bid_reject(event_id, bid_id):
    """
    拒件
    更新bid表、event表
    插入bid_workflow记录
    :return:
    """
    update = {'status': 6}  # 拒件
    update_event = {'is_expired': 1}
    bid = convert.query(models.Bid, id=bid_id).first()
    bid_workflow = models.BidWorkflow()
    bid_workflow.id = my_snow().get_next_id()
    bid_workflow.company_id = bid.company_id
    bid_workflow.bid_id = bid.id
    bid_workflow.user_id = bid.user_id
    bid_workflow.last_status = 0
    bid_workflow.current_status = 6
    bid_workflow.operator_id = 0
    bid_workflow.operating_time = datetime.now()
    bid_workflow.action = "调用规则进件"
    bid_workflow.suggestion = None
    bid_workflow.channel_id = bid.channel_id
    # 更新event表
    convert.update_table(models.Event, update_event, event_id=event_id)
    # 更新bid表
    convert.update_table(models.Bid, update, id=bid_id)
    return convert.add_one(bid_workflow)
Example #2
0
def update_cert_item(mobile, company_id, cert_item_list):
    """
    更新user_detail的认证项
    user_detail表造数据
    :return:
    """
    update = {'cert_item': ",".join(cert_item_list)}

    return convert.update_table(models.UserDetail,
                                update,
                                mobile=mobile,
                                company_id=company_id)
Example #3
0
def update_cert_item_of_user_apply_info(mobile, company_id, cert_item_list):
    """
    更新user_apply_info的认证项
    user_apply_info表造数据
    :return:
    """
    update = {'cert_item': ",".join(cert_item_list)}

    return convert.update_table(models.UserApplyInfo,
                                update,
                                mobile=mobile,
                                company_id=company_id)
def bid_pass(bid_id):
    """
    审核通过
    更新bid表、插入bid_workflow记录
    :return:
    """
    update = {'status': 2}  # 2 发放贷款(待放款),下一个阶段会通过放款成功进入还款(待还款)阶段
    bid = convert.query(models.Bid, id=bid_id).first()
    bid_workflow = models.BidWorkflow()
    bid_workflow.id = my_snow().get_next_id()
    bid_workflow.company_id = bid.company_id
    bid_workflow.bid_id = bid.id
    bid_workflow.user_id = bid.user_id
    bid_workflow.last_status = 1
    bid_workflow.current_status = 2
    bid_workflow.operator_id = 0
    bid_workflow.operating_time = datetime.now()
    bid_workflow.action = "调用规则进件"
    bid_workflow.suggestion = None
    bid_workflow.channel_id = bid.channel_id
    # 更新bid表
    convert.update_table(models.Bid, update, id=bid_id)
    return convert.add_one(bid_workflow)
def operate(event_id, bid_id):
    """
    正常还款 线上
    更新bid表、插入bid_workflow记录
    :return:
    """
    update = {
        'status': 7,
        'repayment_time_type': 1,
        'repayment_approach_type': 1,
        'repayment_credit_type': 1
    }
    bid = convert.query(models.Bid, id=bid_id).first()
    contract_no = get_contract_no()
    # 插入bid_workflow记录
    bid_workflow = models.BidWorkflow()
    bid_workflow.id = my_snow().get_next_id()
    bid_workflow.company_id = bid.company_id
    bid_workflow.bid_id = bid.id
    bid_workflow.user_id = bid.user_id
    bid_workflow.last_status = 3
    bid_workflow.current_status = 7
    bid_workflow.operator_id = 0
    bid_workflow.operating_time = datetime.now()
    bid_workflow.action = "还款"
    bid_workflow.suggestion = None
    bid_workflow.channel_id = bid.channel_id
    # 插入current_transaction记录
    current_transaction = models.CurrentTransaction()
    current_transaction.id = my_snow().get_next_id()
    current_transaction.company_id = bid.company_id
    current_transaction.contract_no = contract_no
    current_transaction.type = 2
    current_transaction.scene = 2
    current_transaction.status = 1
    current_transaction.amount = bid.amount
    current_transaction.customer_name = datetime.now()
    current_transaction.mobile = bid.mobile
    current_transaction.bid_id = bid.id
    current_transaction.bid_contract_no = bid.contract_no
    current_transaction.payment_channel = "富友"
    current_transaction.payment_channel_id = 2
    current_transaction.event_id = event_id
    current_transaction.channel_id = bid.channel_id
    current_transaction.transaction_time = datetime.now()
    current_transaction.comment = None
    transaction_list = list()
    # 插入transaction记录初始化
    transaction_zero = get_transaction(contract_no, bid, event_id, 0)
    transaction_list.append(transaction_zero)
    # 插入transaction记录成功
    transaction = get_transaction(contract_no, bid, event_id, 1)
    transaction_list.append(transaction)
    convert.add_all(transaction_list)
    # 插入current_transaction记录
    convert.add_one(current_transaction)
    # 更新bid表
    convert.update_table(models.Bid, update, id=bid_id)
    # 更新bill表
    update_bill = {'status': 7}
    convert.update_table(models.Bill, update_bill, id=bid_id)
    return convert.add_one(bid_workflow)
def bid_application_insert(company_id, channel_id, mobile, bank_account_id,
                           product_id, raise_amount, user_cid, event_id,
                           gmt_create, user_id):
    """
    模拟申请进件
    """
    # 查询用户的绑定的卡
    bank_card = convert.query(models.Bankcard,
                              mobile=mobile,
                              company_id=company_id,
                              is_default=1).first()

    # 查询申请的产品信息
    product = convert.query(models.Product,
                            company_id=company_id,
                            product_id=product_id,
                            is_enabled=1).first()

    # 查询渠道
    channel = convert.query(models.Channel, id=channel_id).one()

    # 查询渠道
    user_detail = convert.query(models.UserDetail, id=user_id).one()

    _version = "1.1.0"
    _bid_id = my_snow().get_next_id()
    # 创建bid表

    bid = models.Bid()
    bid.id = _bid_id
    bid.gmt_create = gmt_create
    bid.gmt_modified = gmt_create
    bid.is_deleted = 0
    bid.bank_account_number = bank_card.get("bank_account_number")
    bid.bank_account_id = bank_account_id
    bid.amount = Decimal(product.get("amount")) + raise_amount
    bid.period = product.get("period_day")
    bid.product_id = product.get("id")
    bid.raise_amount = raise_amount
    bid.channel_id = channel_id
    bid.channel_label = channel.get("label")
    bid.channel_name = channel.get("name")
    bid.cid = user_cid
    bid.mobile = mobile
    bid.name = user_detail.get("name")
    bid.company_id = company_id
    bid.ip_address = fakerInstance.ipv4()
    bid.status = 0
    convert.add_one(bid)

    # 绑定eventId和bid
    event = models.Event()
    event.id = event_id
    event.gmt_create = gmt_create
    event.gmt_modified = gmt_create
    event.is_deleted = 0
    event.bid_id = _bid_id
    event.company_id = company_id
    event.channel_id = channel_id
    event.mobile = mobile
    event.is_expired = 0
    convert.add_one(event)

    # 修改user_detail数据
    user_detail.category = 1
    user_detail.gmt_modified = gmt_create
    user_detail.first_apply_time = gmt_create
    convert.update_table(models.UserDetail, user_id=user_id)

    # 创建userApplyInfo记录
    user_apply_info = models.UserApplyInfo()
    user_apply_info.id = my_snow().get_next_id()
    user_apply_info.gmt_create = user_detail.gmt_create
    user_apply_info.gmt_modified = user_detail.gmt_modified
    user_apply_info.is_deleted = user_detail.is_deleted
    user_apply_info.cert_item = user_detail.cert_item
    user_apply_info.user_id = user_detail.user_id
    user_apply_info.company_id = user_detail.company_id
    user_apply_info.cid = user_detail.cid
    user_apply_info.mobile = user_detail.mobile
    user_apply_info.name = user_detail.name
    user_apply_info.password = user_detail.password
    user_apply_info.channel_id = user_detail.channel_id
    user_apply_info.channel_name = user_detail.channel_name
    user_apply_info.province = user_detail.province
    user_apply_info.city = user_detail.city
    user_apply_info.address = user_detail.address
    user_apply_info.gender = user_detail.gender
    user_apply_info.nationality = user_detail.nationality
    user_apply_info.birthday = user_detail.birthday
    user_apply_info.marital_status = user_detail.marital_status
    user_apply_info.income_level = user_detail.income_level
    user_apply_info.education_level = user_detail.education_level
    user_apply_info.bank_account_id = user_detail.bank_account_id
    user_apply_info.category = user_detail.category
    user_apply_info.mobile_platform = user_detail.mobile_platform
    user_apply_info.operator_id = user_detail.operator_id
    user_apply_info.first_apply_time = user_detail.first_apply_time
    user_apply_info.first_deduct_time = user_detail.first_deduct_time
    user_apply_info.loan_amount = user_detail.loan_amount
    user_apply_info.raise_amount = user_detail.raise_amount
    user_apply_info.emrg_contact_name_a = user_detail.emrg_contact_name_a
    user_apply_info.emrg_contact_name_b = user_detail.emrg_contact_name_b
    user_apply_info.emrg_contact_mobile_a = user_detail.emrg_contact_mobile_a
    user_apply_info.emrg_contact_mobile_b = user_detail.emrg_contact_mobile_b
    user_apply_info.idcard_front_img = user_detail.idcard_front_img
    user_apply_info.idcard_back_img = user_detail.idcard_back_img
    user_apply_info.thirdparty_data = user_detail.thirdparty_data
    user_apply_info.raise_amount = user_detail.raise_comment
    user_apply_info.update_count = user_detail.update_count
    user_apply_info.name_mirror = user_detail.name_mirror
    user_apply_info.raise_amount_sign = user_detail.raise_amount_sign
    convert.add_one(user_apply_info)
def insert(mobile, company_id):
    """
    插入银行卡数据
    bankcard表造数据
    :return:
    """
    user = convert.query(models.User, mobile=mobile,
                         company_id=company_id).first()
    # 一定要保证user表有数据
    if user is None:
        return
    print(user)
    user_detail = convert.query(models.UserDetail,
                                mobile=mobile,
                                company_id=company_id).first()
    bankcard_data = convert.query(models.Bankcard,
                                  mobile=mobile,
                                  company_id=company_id,
                                  is_default=1).first()
    payment_channel = convert.query(models.PaymentChannel,
                                    company_id=company_id,
                                    is_default=1).first()
    card_no = generate()
    dict_bank_info = get_bank(card_no)
    while dict_bank_info is None:
        card_no = generate()
        dict_bank_info = get_bank(card_no)
    bankcard = models.Bankcard()
    # 检查是否有默认卡
    if bankcard_data is None:
        id = my_snow().get_next_id()
        bankcard.id = id
        bankcard.user_id = user.id
        bankcard.company_id = company_id
        bankcard.bank_code = dict_bank_info['bank_code']
        bankcard.bank_account_number = card_no
        bankcard.bank_account_name = user.name
        bankcard.bank_name = dict_bank_info['bank_name']
        bankcard.mobile = mobile
        bankcard.is_default = 1
        bankcard.payment_channel = payment_channel.payment_channel_name if payment_channel is not None else "富有"  # '支付渠道 富有, 易宝'
        bankcard.is_binding = 1  # '1 已绑定  0 已经解绑',
        bankcard.mchntcd = payment_channel.mchntcd
        if user_detail.bank_account_id is None:
            update = {'bank_account_id': id}
            convert.update_table(models.UserDetail,
                                 update,
                                 mobile=mobile,
                                 company_id=company_id)
    else:
        bankcard.id = my_snow().get_next_id()
        bankcard.user_id = user.id
        bankcard.company_id = company_id
        bankcard.bank_code = dict_bank_info['bank_code']
        bankcard.bank_account_number = card_no
        bankcard.bank_account_name = user.name
        bankcard.bank_name = dict_bank_info['bank_name']
        bankcard.mobile = mobile
        bankcard.is_default = 0
        bankcard.payment_channel = payment_channel.payment_channel_name if payment_channel is not None else "富有"  # '支付渠道 富有, 易宝'
        bankcard.is_binding = 1  # '1 已绑定  0 已经解绑',
        bankcard.mchntcd = payment_channel.mchntcd
    return convert.add_one(bankcard)