def creaet(self, credit, category): now = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) credit = Credit(category=category, credit=credit, createtime=now, updatetime=now, user_id=session.get('userid')) dbsession.add(credit) dbsession.commit() return credit
def buyArticle(self, username, articleid): user = dbsession.query(User).filter(User.username == username).first() article = dbsession.query(Article).filter( Article.id == articleid).first() if user.credit < article.cost_integral: return {"code": 10004, "msg": "not enough credit!"} else: now = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) user.credit -= article.cost_integral credits = Credit(category="购买文章", target=articleid, credit=-article.cost_integral, createtime=now, updatetime=now, user_id=user.id) dbsession.add(credits) dbsession.commit() return {"code": 10001, "msg": "ok"}
def resetCollect(self, userid, articleid): fa = dbsession.query(Favorite).filter( Favorite.user_id == userid, Favorite.article_id == articleid).first() if not fa: now = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) fa = Favorite(user_id=userid, article_id=articleid, is_collect=1, create=now) dbsession.add(fa) dbsession.commit() return fa.is_collect if fa.is_collect == 0: fa.is_collect = 1 dbsession.commit() return fa.is_collect if fa.is_collect == 1: fa.is_collect = 0 dbsession.commit() return fa.is_collect
def addComment(self, uesrid, articleid, replyid, content): if replyid: now = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) com = Comment(user_id=uesrid, article_id=articleid, reply_id=replyid, content=content, is_hidden=0, createtime=now, updatetime=now) dbsession.add(com) dbsession.commit() if not replyid: now = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) com = Comment(user_id=uesrid, article_id=articleid, content=content, is_hidden=0, createtime=now, updatetime=now) dbsession.add(com) dbsession.commit()
def registerUser(self, name, password): user = User(username=name, password=password, email=name) dbsession.add(user) dbsession.commit() return user