def addItem(name, email): u = User(name=name, email=email) try: db_session.add(u) db_session.commit() except Exception, e: return 'wrong(key repeat)'
def register(name, pwd, uuid=None, device=None): # user_id = ticks%10000*100000*1000+1*1000 today = datetime.datetime.now() # 00000 000 000 first = int(time.time()) / 1000000 % 1000 second = int(time.time()) / 1000 % 1000 third = int(time.time()) % 1000 times = first * 10000000 + second * 10000 + third * 10 - 3950000000 + int( random.uniform(0, 9)) print "second", time.time( ), id, times, 'first:', first, 'second', second, 'third', third # user_id为十位 u = User(name=name, pwd=pwd, user_id=str(times)) u.uuid = uuid u.device = device # print 'uuid',uuid u.last_time = today try: db_session.add(u) db_session.commit() return u except Exception, e: print "用户名 重复", e return None
def userinfo(name, uuid, device): today = datetime.datetime.now() info = Userbehaviour(today, name, uuid, device) try: db_session.add(info) db_session.commit() return status_code.trueCode except Exception, e: print "userinfo", e
def feedback(user_id, content): today = datetime.datetime.now() feed = FeedBack(today, content, user_id) try: db_session.add(feed) db_session.commit() return status_code.trueCode except Exception, e: print "feedback", e return status_code.query_feedback_failure
def addOrder(deal_Prce, goods_name): user_id = 1 order = Order(user_id=user_id, deal_time=datetime.datetime.now(), deal_Prce=deal_Prce, goods_name=goods_name) try: db_session.add(order) db_session.commit() except Exception, e: return 0
def add(name, pwd): # encryption = encryptionWithString('hello') # print 'random:',random_generator # print decryptionWithString(encryption,random_generator) # signature = signatureWithString('text') # print 'verification:',verificationSignature('text1',signature) u = sqlmodel.User(name=name, pwd=pwd) try: db_session.add(u) db_session.commit() except Exception, e: return 'wrong(key repeat)'
def transformpoint(sponsor, received, point): spo = User.query.filter(User.user_id == sponsor).first() if spo: rec = User.query.filter(User.name == received).first() if rec and spo.points > float(point): spo.points = spo.points - float(point) rec.points = rec.points + float(point) try: db_session.add(spo) db_session.add(rec) db_session.commit() return status_code.trueCode except Exception, e: print status_code.query_points_transform_failuret else: return status_code.query_points_transform_received_failuret
# 登录接口 # def login(name, pwd, uuid=None, device=None): try: u = User.query.filter(User.name == name).first() except Exception, e: return 'there isnot %s' % name if u: if u.pwd == pwd: # points = User.query.filter(User.i==name).first() u.last_time = datetime.datetime.now() u.uuid = uuid u.device = device db_session.add(u) db_session.commit() return u else: return False ########################### 更新积分接口 ############################################# # # 如果paras = 0 表示查询当前积分 # 如果paras != 0 表示更改当前积分 def update_points(userid, positive_points, negative_points): if int(positive_points) == 0 and int(negative_points) == 0: try: u = User.query.filter(User.user_id == userid).first()