Beispiel #1
0
def delete_addr(user_id, _id):
    """删除收货地址"""
    conn = ToConn().to_execute()
    cur = conn.cursor()
    db_conn = ToMongo()
    cur.execute(
        'update users set address_default=null where id=%s and address_default = %s',
        (user_id, _id))
    result = db_conn.delete(col='address', doc={
        '_id': ObjectId(_id)
    }).raw_result
    if result['ok'] == 1:
        conn.commit()
    else:
        conn.rollback()
    db_conn.close_conn()
Beispiel #2
0
def delete_addr_model(user_id, _id):
    rel = True
    if _id == get_user(user_id)['address_default']:
        # 如果是默认地址,删除默认地址
        conn = ToConn()
        to_exec = conn.to_execute()
        cur = to_exec.cursor()
        result = cur.execute(
            'update users set address_default=null where id=%s', (user_id, ))
        if result:
            to_exec.commit()
            to_exec.close()
        else:
            to_exec.rollback()
            to_exec.close()
            return False
    # 如果不是默认地址,直接删除默认地址
    db = ToMongo()
    count = db.delete('address', {'_id': ObjectId(_id)}).deleted_count
    if not count:
        rel = False
    db.close_conn()
    return rel