def insertInfo(): name = request.args.get('name') phone = request.args.get('phone') position = request.args.get('position') if phone is None or len(phone.strip())<1 or not phone.isdigit(): return jsonify(Response.fail(msg="信息有误")) items = Scanner.query.filter_by(phone=phone).all() if len(items)>0: return jsonify(Response.fail(msg="该手机号已录入,请更换手机号")) else: scanner = Scanner(name, phone, position) db.session.add(scanner) db.session.commit() return jsonify(Response.success(msg="插入成功", data=scanner.id))
def verify(): info = request.args.get('info') if info is None or len(info.strip())<1: return jsonify(Response.fail(msg="信息有误,验证失败")) else: infoSegs = info.strip().split('-'); if(len(infoSegs) == 2): item = Scanner.query.get(infoSegs[0]) if item is None or cmp(item.phone, infoSegs[1])!=0: return jsonify(Response.fail(msg="信息有误,验证失败")) if item.valid == 0: return jsonify(Response.fail(msg="该二维码已被验证,不可重复验证")) item.valid = 0 db.session.commit() res = {'name':item.name, 'phone':item.phone, 'position':item.position} return jsonify(Response.success(msg="验证通过", data=res)) return jsonify(Response.fail(msg="信息有误,验证失败"))
def shit(): toast_id = int(request.args.get('toastId')) uid = int(request.args.get('uid')) shit_operation = ToastOperation(uid, toast_id, SHIT_OPERATION, datetime.now()) db.session.add(shit_operation) db.session.commit() # 让记录+1 toast = Toast.query.get(toast_id) if toast is not None: toast.shit_count += 1 db.session.commit() else: return jsonify(Response.fail(msg="找不到这条toast")) return jsonify(Response.success(msg="shit成功"))
def getToast(): toast_id = int(request.args.get('toastId')) item = Toast.query.get(toast_id) if item is not None: res = { "toast_id":item.id, "body":item.body, "time":item.creation_time.strftime("%Y-%m-%d %H:%M:%S"), "trumpet_count":item.trumpet_count, "shit_count":item.shit_count } return jsonify(Response.success(msg="拉取成功", data=res)) else: return jsonify(Response.fail(msg="找不到这条toast"))