Ejemplo n.º 1
0
def confirmreceipt():

    # 确认收货
    # 用户冻结金额清零
    # 商户余额增加加入记录

    resp = {'code': 200, 'msg': '确认收货成功'}

    Oid = request.values['Oid'] if 'Oid' in request.values else -1
    Shopid = request.values['Shopid'] if 'Shopid' in request.values else -1

    Pay_info = PayOrder.query.filter_by(id=Oid).first()
    Pay_info.status = -5
    loginfo = Balancelog.query.filter_by(
        receipt_qrcode=Pay_info.order_sn).first()
    Shop_info = Shop.query.filter_by(Shopid=Shopid).first()
    Apply_info = Apply.query.filter_by(Aid=Shop_info.Aid).first()
    # 商户Cid
    Customer_info = Customer.query.filter_by(Cid=Apply_info.Cid).first()

    # 用户冻结金额清零
    freeze_balance = loginfo.freeze_balance
    loginfo.freeze_balance = float(0)

    mybalance = float(Customer_info.MyBalance)
    result = float(freeze_balance)
    mybalance = mybalance + result
    Customer_info.MyBalance = mybalance

    # 销量增加
    pay_order_item_info = PayOrderItem.query.filter_by(
        pay_order_id=Pay_info.id).all()
    for item in pay_order_item_info:
        product_info = Product.query.filter_by(Pid=item.Pid).first()
        sold = int(product_info.ProductSold)
        sold_result = sold + item.quantity
        product_info.ProductSold = sold_result

    # 打款给商家记录
    Balance_log = Balancelog()

    Balance_log.BankCardNumber = -1000
    Balance_log.Cid = Customer_info.Cid
    Balance_log.Openingbank = -1000
    Balance_log.balance = freeze_balance
    Balance_log.operating = 4
    Balance_log.status = 6
    Balance_log.total_balance = freeze_balance
    target_pay = PayService()
    Balance_log.receipt_qrcode = target_pay.geneOrderSn()
    Balancelog.freeze_balance = float(0)
    Balance_log.Accountname = -1000
    Balance_log.createtime = getCurrentDate()
    Balance_log.updatetime = getCurrentDate()
    db.session.add(Balance_log)

    db.session.commit()
    response = jsonify(resp)
    response.headers['Access-Control-Allow-Origin'] = '*'
    return response
Ejemplo n.º 2
0
def withdraw():
    resp = {'code': 200, 'msg': "提交申请成功"}
    req = request.values

    Cid = int(req['Cid']) if 'Cid' in req and req['Cid'] else 0
    BankCardNumber = req['BankCardNumber'] if 'BankCardNumber' in req and req['BankCardNumber'] else 0
    Openingbank = req['Openingbank'] if 'Openingbank' in req and req['Openingbank'] else 0
    Accountname = req['Accountname'] if 'Accountname' in req and req['Accountname'] else 0
    balance = req['balance'] if 'balance' in req and req['balance'] else 0

    info = Customer.query.filter_by(Cid=Cid).first()

    mybalance = float(info.MyBalance)
    result = float(balance)
    if mybalance < result:
        resp['code'] = -1
        resp['msg'] = '余额不足'
        return jsonify(resp)

    mybalance = mybalance - result
    info.MyBalance = mybalance
    db.session.add(info)

    Balance_log = Balancelog()

    Balance_log.BankCardNumber = BankCardNumber
    Balance_log.Cid = Cid
    Balance_log.Openingbank = Openingbank
    Balance_log.balance = balance
    Balance_log.operating = 3
    Balance_log.status = 1
    Balance_log.total_balance = -1000
    target_pay = PayService()
    Balance_log.receipt_qrcode = target_pay.geneOrderSn()
    Balancelog.freeze_balance = balance
    Balance_log.Accountname = Accountname
    Balance_log.createtime = getCurrentDate()
    Balance_log.updatetime = getCurrentDate()
    db.session.add(Balance_log)
    db.session.commit()

    return jsonify(resp)