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)
예제 #2
0
def insert_bankcard(mobile, company_id):
    """
    3银行卡认证
    user_certification表造数据
    :return:
    """
    user = convert.query(models.User, mobile=mobile,
                         company_id=company_id).first()
    user_certification = models.UserCertification()
    user_certification.id = my_snow().get_next_id()
    user_certification.channel_id = user.register_channel_id
    user_certification.status = 1  # 成功
    user_certification.succeed_flag = 1  # 成功
    user_certification.type = 3  # 0:实名认证,1运营商认证,3银行卡认
    user_certification.expiration_period = -1  # 7实名认证,30运营商认证,-1银行卡认
    user_certification.mobile = mobile
    user_certification.company_id = company_id
    return convert.add_one(user_certification)
def get_transaction(contract_no, bid, event_id, status):
    transaction = models.Transaction()
    transaction.id = my_snow().get_next_id()
    transaction.company_id = bid.company_id
    transaction.contract_no = contract_no
    transaction.type = 2
    transaction.scene = 2
    transaction.status = status
    transaction.amount = bid.amount
    transaction.customer_name = datetime.now()
    transaction.mobile = bid.mobile
    transaction.bid_id = bid.id
    transaction.bid_contract_no = bid.contract_no
    transaction.payment_channel = "富友"
    transaction.payment_channel_id = 2
    transaction.event_id = event_id
    transaction.channel_id = bid.channel_id
    transaction.transaction_time = datetime.now()
    transaction.comment = None
    return transaction
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 register_insert(company_id, channel_id, gmt_create, mobile_platform):
    """
    @:param mobile_platform : 所属客户端0:ios, 1:android 2 api
    直接插库进行模拟用户注册
    """
    # 创建user
    # 查询渠道
    channel = convert.query(models.Channel, id=channel_id).one()
    user_cid = cid_generate()
    user_mobile = fakerInstance.phone_number()
    user_id = my_snow().get_next_id()
    user_name = create_name_by_cid(user_cid)
    user_password = hashlib.md5(
        str(user_mobile).encode('utf-8')).hexdigest()[3:19]
    user_detail_address = fakerInstance.address()
    user_channel_name = channel.name

    print("register_insert user_cid", user_cid)
    print("register_insert user_mobile", user_mobile)
    print("register_insert user_id", user_id)

    user = User()
    user.gmt_create = gmt_create
    user.gmt_modified = gmt_create
    user.is_deleted = 0
    user.id = user_id
    user.company_id = company_id
    user.cid = user_cid
    user.mobile = user_mobile
    user.name = user_name
    user.password = user_password
    user.register_channel = user_channel_name
    user.register_channel_id = channel_id
    user.mobile_md5 = hashlib.md5(
        str(user_mobile).encode('utf-8')).hexdigest()[3:19]
    convert.add_one(user)

    # 创建user_detail
    user_detail = UserDetail()
    user_detail.id = my_snow().get_next_id()
    user_detail.gmt_create = gmt_create
    user_detail.gmt_modified = gmt_create
    user_detail.is_deleted = 0
    user_detail.cert_item = None
    user_detail.user_id = user_id
    user_detail.company_id = company_id
    user_detail.cid = user_cid
    user_detail.mobile = user_mobile
    user_detail.name = user_name
    user_detail.password = user_password
    user_detail.channel_id = channel_id
    user_detail.channel_name = user_channel_name
    user_detail.province = split_address(user_detail_address).get("province")
    user_detail.city = split_address(user_detail_address).get("city")
    user_detail.address = user_detail_address
    user_detail.gender = check_sex(user_cid)
    user_detail.nationality = "汉"
    user_detail.birthday = create_birthday
    user_detail.marital_status = None
    user_detail.income_level = None
    user_detail.education_level = None
    user_detail.bank_account_id = None
    user_detail.category = None
    user_detail.mobile_platform = mobile_platform
    user_detail.operator_id = None
    user_detail.first_apply_time = gmt_create
    user_detail.first_deduct_time = None
    user_detail.loan_amount = None
    user_detail.raise_amount = None
    user_detail.emrg_contact_name_a = None
    user_detail.emrg_contact_name_b = None
    user_detail.emrg_contact_mobile_a = None
    user_detail.emrg_contact_mobile_b = None
    user_detail.idcard_front_img = None
    user_detail.idcard_back_img = None
    user_detail.thirdparty_data = None
    user_detail.raise_comment = None
    user_detail.update_count = None
    user_detail.name_mirror = None
    user_detail.raise_amount_sign = None
    convert.add_one(user_detail)

    # 模拟event_id
    now = time.time()
    _event_id = str(company_id) + "_" + str(channel_id) + "_" + str(
        int(now * 1000))
    print("register_insert _event_id", _event_id)

    # 模拟token 取手机号的md5加密截取部分
    _token = user_password
    print("register_insert _event_id", _token)

    return dict(mobile=user_mobile, event_id=_event_id, token=_token)
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)
예제 #8
0
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)