def delete(): if request.method == 'GET': return "走错了" if request.method == 'POST': data = request.get_data() data = str(data,'utf-8') id = int(data.split('=')[-1]) print(id) if Commodity.delete_commodity_by_id(id) == 1: return make_json(200,'delete success') else: return make_json(500,'delete fail')
def add_comment(): if request.method == 'POST': data = request.get_json() comment = Comment() comment.comment_content = data['content'] comment.commodity_id = int(data['id']) commodity = Commodity.get_commodity_by_id(int(data['id'])) student = Student.get_student_id(current_user.id) # 设置权限,自己不能对自己的商品评论 if commodity.owner_student_id == student._school_number: abort(401) comment.user_id = current_user.id comment.username = current_user.username comment.status = 0 if comment.add_comment() == 1: return make_json(200,'success') else: return make_json(500,'fail')
def show_comment(): if request.method == 'POST': data = request.get_data() data = str(data,'utf-8') id = int(data.split('=')[-1]) results = [] l = Comment.get_comment_by_commodity_id(id) for i in l: user = User.get_user_by_id(i.user_id) j = {'username':user.username,'comment_content':i.comment_content} results.append(j) print(len(results)) return make_json(200,'success',results)
def wanna_buy(): if request.method == 'POST': # 判断卖家是否是自己 data = request.get_data() data = str(data,'utf-8') id = int(data.split('=')[-1]) commodity = Commodity.get_commodity_by_id(id) student = Student.get_student_id(current_user.id) if student._school_number == commodity.owner_student_id: return make_json(500,'这是您自己的商品') else: # 生成订单 now = time.strftime( '%Y-%m-%d %H:%M:%S', time.localtime(time.time())) r = {"commodity_id":id,"commodity_name":commodity.commodity_name,"buyer_id":student._school_number,"school_number":commodity.owner_student_id,"status":0,"create_time":now} print(r) if Order.add_order(**r): commodity.status = 1 if commodity.update_commodity() == 1: return make_json(200, '预约成功') else: return make_json(500, '预约失败')
def modify(): if request.method == 'POST': id = request.form['commodity_id'] c = Commodity.get_commodity_by_id(int(id)) file1 = request.files['photo1'] r = solve_photo(file1) if r == 2: return make_json(500, 'wrong type') else: c.commodity_photo_url1 = r file2 = request.files['photo2'] r = solve_photo(file2) if r == 2: return make_json(500, 'wrong type') else: c.commodity_photo_url2 = r file3 = request.files['photo3'] r = solve_photo(file3) if r == 2: return make_json(500, 'wrong type') else: c.commodity_photo_url3 = r file4 = request.files['photo4'] r = solve_photo(file4) if r == 2: return make_json(500, 'wrong type') else: c.commodity_photo_url4 = r file5 = request.files['photo5'] r = solve_photo(file5) if r: return make_json(500, 'wrong type') else: c.commodity_photo_url5 = r new_commodity_name = request.form['new_commodity_name'] c.commodity_name = remove_html(new_commodity_name) new_commodity_type = request.form['new_commodity_type'] c.commodity_type = remove_html(new_commodity_type) new_commodity_price = request.form['new_commodity_price'] c.price = float(new_commodity_price) new_commodity_introduction = request.form['new_commodity_introduction'] c.commodity_introduction = remove_html(new_commodity_introduction) # return make_json(200, str(type(c.status))) if c.update_commodity() == 1: return redirect("/commodity/my_commodity") else: return make_json(500,'db wrong')
def upload(): if request.method == 'POST': if current_user.is_forbid: return redirect("/auth/send_activation") c = Commodity() if 'photo1' not in request.files: flash('No file part') return make_json(500,'no photo') file1 = request.files['photo1'] r = solve_photo(file1) if r == 2: return make_json(500,'wrong type') else: c.commodity_photo_url1 = r file2 = request.files['photo2'] r = solve_photo(file2) if r == 2: return make_json(500,'wrong type') else: c.commodity_photo_url2 = r file3 = request.files['photo3'] r = solve_photo(file3) if r == 2: return make_json(500,'wrong type') else: c.commodity_photo_url3 = r file4 = request.files['photo4'] r = solve_photo(file4) if r == 2: return make_json(500,'wrong type') else: c.commodity_photo_url4 = r file5 = request.files['photo5'] r = solve_photo(file5) if r: return make_json(500,'wrong type') else: c.commodity_photo_url5 = r new_commodity_name = request.form['new_commodity_name'] c.commodity_name = remove_html(new_commodity_name) new_commodity_type = request.form['new_commodity_type'] c.commodity_type = remove_html(new_commodity_type) new_commodity_price = request.form['new_commodity_price'] c.price = float(new_commodity_price) new_commodity_introduction = request.form['new_commodity_introduction'] c.commodity_introduction = remove_html(new_commodity_introduction) # 整合时再取 student = Student.get_student_id(current_user.id) c.owner_student_id = student._school_number if c.add_commodity() == 1: return redirect('/commodity/index')