Esempio n. 1
0
def update(pid):
    db = MhDatabases()
    if request.method == 'GET':

        result = db.executeQuery("select * from goods where gid=%s",
                                 [pid])  # 从数据库获取商品信息并返回
        return render_template("update.html", result=result)
    else:
        gid = request.form.get("productId")  # 获取web前端发送的要删除的商品ID
        print(gid)
        if gid:
            db.executeUpdate("delete from goods where gid=%s",
                             [gid])  # 在数据库中删除商品信息
            return redirect(url_for('product'))
        else:
            # 获取web前端发送的商品要修改的信息
            product = []
            product.append(request.form.get("type"))
            product.append(int(request.form.get("number")))
            product.append(float(request.form.get("price")))
            product.append(request.form.get("location"))
            print(product)

            # 在数据库中修改商品信息
            db.executeUpdate(
                "update goods set sort=%s,number=%s,uprice=%s,location=%s where gid=%s",
                [product[0], product[1], product[2], product[3], pid])
            return redirect(url_for('product'))
Esempio n. 2
0
def idcodelogin():
    db = MhDatabases()
    # 获取微信小程序端传来的用户id
    id = str(json.loads(request.values.get("id")))
    print(id)
    result = db.executeQuery("select * from user where phone=%s",
                             [id])  # 查询id在数据库是否已存在
    if len(result) == 0:
        db.executeUpdate("insert into user values(%s,null,null,null) ", [id])
    res = "成功"
    return json.dumps(res)
Esempio n. 3
0
def cartdelete():
    db = MhDatabases()
    # 获取微信小程序端传来的商品id,删除商品数组
    id = str(json.loads(request.values.get("id")))
    scart = json.loads(request.values.get("scart"))
    for i in scart:
        db.executeUpdate(
            "update pcr set isdelete=1 where gid=%s and buyerid=%s and optype=5",
            [i['gid'], id])  # 修改订单isdelete项
    res = "删除成功"
    return json.dumps(res)
Esempio n. 4
0
def productAdd():
    # 连接数据库
    db = MhDatabases()
    if request.method == 'GET':
        return render_template("productAdd.html")
    else:
        # 获取要添加的商品信息
        product = []
        product.append(request.form.get("productId"))
        product.append(request.form.get("productName"))
        product.append(request.form.get("type"))
        product.append(int(request.form.get("number")))
        product.append(float(request.form.get("price")))
        product.append(request.form.get("dateofproduce"))
        product.append(request.form.get("dateofbad"))
        print(product)

        # 查询数据库中是否已存在该商品,如果不存在则向数据库添加商品信息
        result1 = db.executeQuery("select * from goods where gid=%s",
                                  [product[0]])
        result2 = db.executeQuery("select * from goods where name=%s",
                                  [product[1]])
        if len(result1[0]) == 0 and len(result2[0]) == 0:
            result = db.executeUpdate(
                "insert into goods values(%s,%s,null,%s,%s,%s,%s,%s,null)",
                product)
        else:
            result = 0
        return render_template("productAdd.html", data=result)
Esempio n. 5
0
def updatemine():
    db = MhDatabases()
    # 获取微信小程序端传来的用户修改信息
    name = str(json.loads(request.values.get("name")))
    sex = str(json.loads(request.values.get("sex")))
    id = str(json.loads(request.values.get("id")))
    password = str(json.loads(request.values.get("password")))
    result = db.executeUpdate(
        "update user set pwd=%s,gender=%s,name=%s where phone=%s",
        [password, sex, name, id])  # 修改用户在数据库中的个人信息记录
    if result == 0:
        res = "修改失败"
    else:
        res = "修改成功"
    return json.dumps(res)
Esempio n. 6
0
def cartchange():
    db = MhDatabases()

    id = str(json.loads(request.values.get("id")))
    gid = str(json.loads(request.values.get("gid")))
    quantity = int(json.loads(request.values.get("quantity")))

    r = db.executeUpdate(
        "update pcr set number=%s where gid=%s and buyerid=%s and optype=5",
        [quantity, gid, id])

    if r == 1:
        res = "修改失敗"
    else:
        res = "修改成功"

    return json.dumps(res)
Esempio n. 7
0
def deleteorders():
    db = MhDatabases()
    # 获取微信小程序端传来的ID和订单完成时间
    id = str(json.loads(request.values.get("id")))
    time = str(json.loads(request.values.get("times")))
    print("id", id, " time", time)

    # 根据ID和订单完成时间修改该订单在数据库中的isdelete项
    result = db.executeUpdate(
        "update pcr set isdelete=true where buyerid=%s and time=%s and optype=10 ",
        [id, time])

    # 返回删除的结果:
    if result == 0:
        res = "删除失败"
    else:
        res = "删除成功"
    return json.dumps(res)
Esempio n. 8
0
def userregister():
    db = MhDatabases()
    # 获取微信小程序端传来的注册用户的id,password,name,sex
    id = str(json.loads(request.values.get("id")))
    password = str(json.loads(request.values.get("password")))
    name = str(json.loads(request.values.get("name")))
    sex = str(json.loads(request.values.get("sex")))
    print("name", name, " sex", sex, " id", id, " password", password)

    # 判断id是否已注册,将信息存入数据库
    result1 = db.executeQuery("select * from user where phone=%s", [id])
    if len(result1) == 0:
        result = db.executeUpdate("insert into user values(%s,%s,%s,%s)",
                                  [id, password, sex, name])
        res = "注册成功"
    else:
        res = "注册失败,手机号已注册"
    return json.dumps(res)
Esempio n. 9
0
def score():
    # 连接数据库
    db = MhDatabases()

    # 获取微信小程序端传来的ID和password
    id = str(json.loads(request.values.get("id")))
    password = str(json.loads(request.values.get("password")))
    name = str(json.loads(request.values.get("name")))
    sex = str(json.loads(request.values.get("sex")))
    print("name", name, " sex", sex, " id", id, " password", password)

    # 根据ID在数据库中查询用户数据
    result1 = db.executeQuery("select * from goods where gid=%s", [id])
    if len(result1[0]) == 0:
        result = db.executeUpdate("insert into goods values(%s,%s,%s,%s,)",
                                  [id, password, sex, name])
    else:
        result = 0
    if result == 1:
        res = "注册成功"
    else:
        res = "注册失败,手机号已注册"
    return json.dumps(res)
Esempio n. 10
0
def cartadd():
    db = MhDatabases()
    # 获取微信小程序端传来的用户id,商品信息
    id = str(json.loads(request.values.get("id")))
    gid = str(json.loads(request.values.get("gid")))
    quantity = int(json.loads(request.values.get("quantity")))
    time = str(json.loads(request.values.get("time")))
    result = db.executeQuery(
        "select image,name,sort,uprice,number from goods where gid=%s",
        [gid])  # 获取商品在数据库中的详细信息
    print(result)

    if result[0][4] - quantity < 0:
        res = "库存不足"
    else:
        order = []
        price = result[0][3]
        order.append(result[0][0])
        order.append(gid)
        order.append(result[0][1])
        order.append(result[0][2])
        order.append(quantity)
        order.append(price)
        order.append(quantity * price)
        order.append(time)
        order.append(id)
        order.append(5)
        order.append(0)
        r = db.executeUpdate(
            "insert into pcr values(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)",
            order)  # 添加加入购物车记录
        if r == 1:
            res = "添加成功"
        else:
            res = "添加失败"
    return json.dumps(res)
Esempio n. 11
0
def add():
    db = MhDatabases()
    if request.method == 'GET':
        return render_template("add.html")
    else:
        # 获取web前端发送要添加的商品信息
        img = request.files.get("myFile")
        fname = img.filename
        filepath = "./static/img/" + fname
        img.save("C:/macrohardweb/static/img/" + fname)
        product = []
        product.append(request.form.get("productId"))
        product.append(request.form.get("productName"))
        product.append(filepath)
        product.append(request.form.get("type"))
        product.append(int(request.form.get("number")))
        product.append(float(request.form.get("price")))
        product.append(request.form.get("dateofproduce"))
        product.append(request.form.get("dateofbad"))
        product.append(request.form.get("location"))
        print(product)

        # 查询数据库中是否已存在该商品,如果不存在则向数据库添加商品信息
        result1 = db.executeQuery("select * from goods where gid=%s",
                                  [product[0]])
        result2 = db.executeQuery("select * from goods where name=%s",
                                  [product[1]])
        result3 = db.executeQuery("select * from goods where image=%s",
                                  [product[2]])
        if len(result1) == 0 and len(result2) == 0 and len(result3) == 0:
            result = db.executeUpdate(
                "insert into goods values(%s,%s,%s,%s,%s,%s,%s,%s,%s)",
                product)
        else:
            result = 0
        return render_template("add.html", data=result)
Esempio n. 12
0
def cartsettle():
    db = MhDatabases()
    # 获取微信小程序端传来的商品id,订单时间,结算商品数组
    id = str(json.loads(request.values.get("id")))
    time = str(json.loads(request.values.get("time")))
    scart = json.loads(request.values.get("scart"))
    print(id, time, scart)
    for i in scart:
        order = []
        result = db.executeQuery(
            "select name,image,sort,number from goods where gid=%s",
            [i['gid']])  # 获取商品信息
        print(result)
        if len(result) != 0:
            order.append(result[0][1])  # image
            order.append(i['gid'])  # gid
            order.append(result[0][0])  # name
            order.append(result[0][2])  # sort
            gnumber = result[0][3] - int(i['quantity'])  # gnumber
            order.append(int(i['quantity']))  # number
            order.append(float(i['price']))  # uprice
            order.append(int(i['quantity']) * float(i['price']))  # total
            order.append(time)  # time
            order.append(id)  # buyerid
            order.append(10)  # optype
            order.append(0)  # isdelete
            if gnumber < 0:
                res = "库存不足"
            else:
                db.executeUpdate("update goods set number=%s where gid=%s",
                                 [gnumber, order[1]])  # 修改商品库存
                db.executeUpdate(
                    "update pcr set isdelete=1 where gid=%s and buyerid=%s and optype=5",
                    [order[1], order[8]])  # 修改加入购物车订单isdelete项
                db.executeUpdate(
                    "insert into pcr values(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)",
                    order)  # 添加购买记录
                res = "结算成功"
        else:
            res = "结算失败"

    return json.dumps(res)
Esempio n. 13
0
def productUpdate(pid):
    # 连接数据库
    db = MhDatabases()
    if request.method == 'GET':
        # 从数据库获取商品信息并返回
        result = db.executeQuery("select * from goods where gid=%s", [pid])
        return render_template("productUpdate.html", result=result)
    else:
        # 获取商品可修改的信息
        product = []
        pid = request.form.get("productId")
        product.append(request.form.get("type"))
        product.append(int(request.form.get("number")))
        product.append(float(request.form.get("price")))
        print(product)

        # 在数据库中修改商品信息
        db.executeUpdate("update goods set sort=%s where gid=%s",
                         [product[0], pid])
        db.executeUpdate("update goods set number=%s where gid=%s",
                         [product[1], pid])
        db.executeUpdate("update goods set uprice=%s where gid=%s",
                         [product[2], pid])
        return redirect(url_for('product'))