def select_new_pro():
    clientSocket = connect_shop_server()
    clientSocket.send(pickle.dumps(("product_oper", "select_new_pro")))

    product = pickle.loads(clientSocket.recv(1024))  # 获取全部商品应大一点
    clientSocket.close()  #使用后一定要关闭连接

    return product
def update_user(user):
    clientSocket = connect_shop_server()
    clientSocket.send(pickle.dumps(("user_oper", "update_user", user)))

    result = pickle.loads(clientSocket.recv(1024))
    clientSocket.close()  # 使用后一定要关闭连接

    return result
def select_new_order():  # 查找到最新生成的一条订单数据
    clientSocket = connect_shop_server()
    clientSocket.send(pickle.dumps(("order_oper", "select_new_order")))
    
    order = pickle.loads(clientSocket.recv(1024))  # 查询最新数据请求
    clientSocket.close()  #使用后一定要关闭连接
        
    return  order
def add_product(product):
    clientSocket = connect_shop_server()
    clientSocket.send(pickle.dumps(("product_oper", "add_product", product)))

    result = pickle.loads(clientSocket.recv(1024))  # 获得结果(bool)
    clientSocket.close()  #使用后一定要关闭连接

    return result  # 返回添加结果
def select_new_user():  # 向服务器查询最新注册的一个用户数据

    clientSocket = connect_shop_server()
    clientSocket.send(pickle.dumps(("user_oper", "select_new_user")))

    user = pickle.loads(clientSocket.recv(1024))
    clientSocket.close()  # 使用后一定要关闭连接

    return user
def add_user(user):  # 向服务器添加用户请求
    # 链接总部服务器验证管理员
    clientSocket = connect_shop_server()
    clientSocket.send(pickle.dumps(("user_oper", "add_user", user)))

    result = pickle.loads(clientSocket.recv(1024))  # 获得结果
    clientSocket.close()  # 使用后一定要关闭连接

    return result  # 返回结果
def get_all_user():

    clientSocket = connect_shop_server()
    clientSocket.send(pickle.dumps(("user_oper", "get_all_user")))

    users = pickle.loads(clientSocket.recv(1024 * 3))  # 获取全部用户应大一点
    clientSocket.close()  # 使用后一定要关闭连接

    return users
def select_user(user_id):
    clientSocket = connect_shop_server()
    user = User(user_id, "1是假参数,不起作用", "1", "1", "1")
    clientSocket.send(pickle.dumps(("user_oper", "select_user", user)))

    result, user = pickle.loads(clientSocket.recv(1024))
    clientSocket.close()  # 使用后一定要关闭连接

    return result, user
def modify_order_stat(order_id, order_new_stat):
    order = Order(order_id, 1, 1, 1, "这是假数据", order_new_stat, None)
    clientSocket = connect_shop_server()
    clientSocket.send(pickle.dumps(("order_oper", "modify_order_stat", order)))
    
    result = pickle.loads(clientSocket.recv(1024))  # 改变订单状态请求
    clientSocket.close()  #使用后一定要关闭连接
        
    return  result
def add_order(order_new):  # 添加订单
    clientSocket = connect_shop_server()
    clientSocket.send(pickle.dumps(("order_oper", "add_order", order_new)))
    
    result = pickle.loads(clientSocket.recv(1024))  # 添加订单请求
    
    clientSocket.close()  #使用后一定要关闭连接
        
    return  result
def remove_order(order_id):  # 删除订单
    order = Order(order_id, 1, 1, 1, "这是假数据", "None", None)
    clientSocket = connect_shop_server()
    clientSocket.send(pickle.dumps(("order_oper", "remove_order", order)))
    
    result = pickle.loads(clientSocket.recv(1024))  # 删除订单请求
    clientSocket.close()  #使用后一定要关闭连接
        
    return  result
def get_all_order():  # 获得所有订单
    
    clientSocket = connect_shop_server()
    clientSocket.send(pickle.dumps(("order_oper", "get_all_order")))
    
    orders = pickle.loads(clientSocket.recv(1024 * 3))  # 获取全部订单应大一点
    
    clientSocket.close()  #使用后一定要关闭连接

        
    return  orders
def get_all_pros():
    # 1.用户验证()
    # 2.权限认证,鉴权
    # 数据稽核(证据保留),写日志
    clientSocket = connect_shop_server()
    clientSocket.send(pickle.dumps(("product_oper", "get_all_pros")))

    products = pickle.loads(clientSocket.recv(1024 * 3))  # 获取全部商品应大一点
    clientSocket.close()  #使用后一定要关闭连接

    return products
def select_product(pro_id):
    product = Product(pro_id, 1, 1, 1)

    clientSocket = connect_shop_server()
    clientSocket.send(pickle.dumps(
        ("product_oper", "select_product", product)))

    result, product = pickle.loads(
        clientSocket.recv(1024))  # 获得结果(bool,product)
    clientSocket.close()  #使用后一定要关闭连接

    return result, product  # 返回查询到的商品数据
def remove_product(pro_id):
    # 向服务器发送请求
    # 链接总部服务器验证管理员
    product = Product(pro_id, 1, 1, 1)

    clientSocket = connect_shop_server()
    clientSocket.send(pickle.dumps(
        ("product_oper", "remove_product", product)))

    result = pickle.loads(clientSocket.recv(1024))  # 获得结果
    clientSocket.close()  #使用后一定要关闭连接

    return result  # 返回删除商品结果
def net_validate_admin_user(user):
    # 链接总部服务器验证管理员
    clientSocket = connect_shop_server()
    clientSocket.send(
        pickle.dumps(("user_oper", "net_validate_admin_user", user)))

    login_stat, user = pickle.loads(clientSocket.recv(1024))
    clientSocket.close()  # 使用后一定要关闭连接

    is_admin = 'N'
    if login_stat:
        is_admin = user.is_admin

    return login_stat, is_admin