def editBook(): """编辑图书""" if request.method == 'POST': next = request.form.get('next', '') try: result = edit_book_model(request) except Exception as e: logging.exception( 'book_admin -> edit_book -> edit_book_model [Exception]:%s', e) return abort(404) + str(e) if result: # 成功重定向上一页 return redirect(next) elif result == 0: flash('没有改变!') return redirect(request.referrer) else: # 失败重定向刷新 flash('提交失败!') return redirect(request.referrer) # GET method book_id = request.args.get('book_id', '') try: book = get_book_for_id(book_id) except Exception as e: logging.exception( 'book_admin -> edit_book -> get_book_for_id [Exception]:%s', e) return abort(404) + str(e) return render_template('admin/editBook.html', book=book)
def bookDetails(): """图书详情""" book_id = request.args.get('book_id', '') try: book = get_book_for_id(book_id) except Exception as e: logging.exception( 'book_admin -> book_details -> get_book_for_id [Exception]:%s', e) return abort(404) + str(e) return render_template('admin/bookDeatils.html', book=book)
def add_book(): """添加图书""" if request.method == 'POST': try: result = add_book_model(request) except Exception as e: logging.exception( 'book_admin add_book add_book_model [Exception]:%s', e) return abort(404) + str(e) if result.inserted_id: try: book = get_book_for_id(result, inserted_id=True) except Exception as e: logging.exception( 'book_admin add_book get_book_for_id [Exception]:%s', e) return abort(404) + str(e) return render_template('admin/bookDeatils.html', book=book) else: flash('操作失败') return redirect(request.url) return render_template('admin/addBook.html', page_active="add_book")
def get_order_details_model(order_no, user_id): """获取订单详情""" update_status_to_5() # 更新订单状态 db_conn = ToMongo() cur = db_conn.get_col('order').find_one({ 'user_id': user_id, 'order_no': order_no }) create_time = cur['create_time'] effective_time = create_time + ORDER_EFFECTIVE_TIME is_processed = cur['is_processed'] amount = cur['amount'] order_id = cur['_id'] order_no = cur['order_no'] is_effective = cur['is_effective'] address = cur['address'] status = cur['orders_status'] logistics = format_logistics(cur['logistics']) book_list = [] for book in cur['books']: book_dict = {} book_dict['num'] = book['book_num'] book_id = book['book_id'] book_dict['book'] = get_book_for_id(book_id) book_list.append(book_dict) order_dict = {} order_dict['books'] = book_list order_dict['_id'] = order_id order_dict['create_time'] = format_time_second(create_time) order_dict['effective_time'] = format_time_second(effective_time) order_dict['is_processed'] = is_processed order_dict['amount'] = amount order_dict['order_no'] = order_no order_dict['is_effective'] = is_effective order_dict['address'] = address order_dict['status'] = status order_dict['logistics'] = logistics db_conn.close_conn() return order_dict
def get_orders(user_id, status): """获取用户订单信息""" query = format_query(user_id, status) db_conn = ToMongo() result = db_conn.get_col('order').find(query).sort('order_no', -1) orders = [] result = list(result) for order in result: status = order['orders_status'] amount = order['amount'] order_no = order['order_no'] create_time = order['create_time'] effective_time = order['create_time'] + ORDER_EFFECTIVE_TIME books = order['books'] book_info = [] # 15天自动确认收货 if status == 2 and create_time + AUTO_RECEIVE < get_now(): rel = update_status_user_id(order_no, user_id) if rel.modified_count: status = 3 for book in books: book_num = book['book_num'] # 图书下架后get_book查询不到信息,会抛出错误 book_info.append({ 'book_num': book_num, 'books': get_book_for_id(book['book_id']) }) orders.append({ 'status': status, 'amount': amount, 'order_no': order_no, 'create_time': format_time_second(create_time), 'book_info': book_info, 'effective_time': format_time_second(effective_time), }) db_conn.close_conn() return orders