def answer(rule, info): try: user = WeixinUser.objects.get(uid = info.user) except: user = WeixinUser() user.src = info.sp user.uid = info.user user.integral = 0 user.save() return BuildConfig(MessageBuilder.TYPE_ANSWER, None, user.id)
def start_exchange(rule, info): print "start db", time.time() try: user = WeixinUser.objects.filter(uid=info.user)[0] except: traceback.print_exc() user = WeixinUser() user.src = info.sp user.uid = info.user user.integral = 0 user.save() print "end db", time.time() if len(user.phone) == 0: return StateMachine.stateRoute[1].start(info) else: return BuildConfig(MessageBuilder.TYPE_GIFT_SHOP, None, user.id)