def popular_recommendation(): data = json.loads(request.get_data("").decode("utf-8")) past_time = '' language = '' category1 = '' category2 = '' C = Condition() st = set_time() today_time = st.today() if "time" in data and data["time"]: past_time = st.time_frame(C.where_time(data["time"])) if "language" in data and data["language"]: language = C.language(data["language"]) if "category1" in data: category1 = data["category1"] if "category2" in data: category2 = data["category2"] result = db_user_activity.sql_popular_recommendation( today_time, past_time, language, category1, category2) if not result[0]: return jsonify({"status": -1, "message": "fail"}) for i in range(0, len(result[1])): result[1][i][ "book_img_path"] = "http://47.96.139.19:6868/library/img/" + result[ 1][i]["book_img_path"] return jsonify({"status": 0, "message": "success", "data": result[1]})
def sql_borrow_book(user_id, book_id): time = set_time() sql = "insert into borrow_info (user_id,book_id,borrow_time,return_time,state) values ({},{},'{}','{}','{}')".format( user_id, book_id, time.today(), time.next_month(), 1) sql2 = "UPDATE book_info set book_state = '1' where book_id = {}".format(book_id) result = mysql_modules(sql, sql2) return result
def sql_return_book(book_id, user_id): time = set_time() sql = "UPDATE borrow_info set state = '0',actual_return_time = '{}' where book_id = {} and user_id = {} ".format( time.today(), book_id, user_id) sql2 = "UPDATE book_info set book_state = '0' where book_id = '{}'".format(book_id) result = mysql_modules(sql, sql2) return result
def sql_feedbacks(user_id, readers, phone, feedbacks): st = set_time() sql = "insert into feedback(user_id,readers,phone,feedbacks,state,time) value ('{}','{}','{}','{}','1','{}')".format( user_id, readers, phone, feedbacks, st.today()) result = mysql_module(sql) if not result[0]: return False return True
def sql_borrowing_condition(): st = set_time() time_dict = st.first_half_year() key = list(time_dict.keys()) times = list(time_dict.values()) result_list = {} number = [] month = [] sql = 'SELECT * from (select count(borrow_id) number from borrow_info where instr(borrow_time,"{}") UNION ALL select count(borrow_id) number from borrow_info where instr(borrow_time,"{}") UNION ALL select count(borrow_id) number from borrow_info where instr(borrow_time,"{}") UNION ALL select count(borrow_id) number from borrow_info where instr(borrow_time,"{}") UNION ALL select count(borrow_id) number from borrow_info where instr(borrow_time,"{}") UNION ALL select count(borrow_id) number from borrow_info where instr(borrow_time,"{}")) as total'.format( times[0], times[1], times[2], times[3], times[4], times[5]) result = mysql_module(sql) for i in range(6): number.append(result[1][i]['number']) month.append(str(key[i]) + "月") result_list["number"] = number result_list["month"] = month return result_list
def data_access_to_database(self): st = set_time() result = db_book.insertnewbook( book_code=self.book_code, book_name=self.book_name, book_auther=self.book_auther, book_category=self.book_category, book_publisher=self.book_publisher, book_room=self.book_room, book_bookshelf=self.book_bookshelf, book_synopsis=self.book_synopsis, book_publication_date=self.book_publication_date, books_add_time=st.today(), book_language=self.book_language, book_img_path=self.src) if not result[0]: return result return [True]
def into_register_info(user_account, user_phone, username, password, email): st = set_time() select_user = "******".format( username) result = mysql_module(select_user) if result[1]: return [False, "该昵称已存在"] select_user = "******".format( username) result = mysql_module(select_user) if result[1]: return [False, "该昵称已存在"] into_user = '******' \ 'user_phone,user_registration_time) VALUES("{}","{}","{}","{}","{}","{}")'.format( user_account, password, username, email, user_phone, st.today()) result = mysql_module(into_user) if not result[0]: return [False, "注册失败"] return [True, "注册成功"]
def sql_get_feedback(user_id): st = set_time() sql = 'select feedbacks,cast(time as char) time,state from feedback where user_id = "{}" and time >="{}"'.format( user_id, st.time_frame(["past", 30])) result = mysql_module(sql) return result