def register(self, doc_name="test_document", doc_type=0, doc_version="1.0.0"): document_data = db.query_one( "SELECT * FROM `document_register` WHERE `name`=:name AND `type` = :type AND `version`=:version", { "name": doc_name, "type": doc_type, "version": doc_version }) if not document_data: raise (NotDocumentError("没有文档信息: %s" % doc_name)) _document_type = {0: self.response_code, 1: self.request_model} try: data = json.loads(document_data["data"]) return _document_type[doc_type](code=document_data["code"], name=document_data["name"], data=data) except Exception as err: import ipdb ipdb.set_trace()
def get(self): "获取用户信息" tokens = request.args.get("token") if not tokens: return {"status": 404, "msg": '参数错误'} result = db.query_one( """ SELECT * FROM tokens WHERE token=:token AND is_deleted=0 AND expiration_time >= :time """, { "token": tokens, "time": int(time.time()) }) if not result: return {"status": 401, "msg": 'token已过期'} result = db.query_one( """ SELECT * FROM user_profiles WHERE user_id = :user_id """, {"user_id": result["user_id"]}) result["nickName"] = result["nickname"] result["avatarUrl"] = result["avatar_url"] return {"status": 200, "msg": "成功", "data": result}
def get(self): """ 随机查看一条留言 """ try: data = db.query_one( "SELECT content, FROM_UNIXTIME(create_time, '%Y-%m-%d %h') as create_time FROM `work_msg` ORDER BY RAND() DESC LIMIT 0, 1" ) return {'status': 200, 'msg': data} except Exception as err: return {'status': 400, 'msg': '失败'}
def get(): "获取用户OPEN_ID" tokens = request.args.get("token") if not tokens: return {"status": 404, "msg": '参数错误'} result = db.query_one( """ SELECT * FROM tokens WHERE token=:token AND is_deleted=0 AND expiration_time >= :time """, { "token": tokens, "time": int(time.time()) }) if not result: return {"status": 401, "msg": 'token已过期'} return {"status": 200, "msg": "成功", "data": result["user_id"]}
def post(self): "通过WX登录后调用" try: kw = request.json user = {} user["user_id"] = kw["user_id"] # 检查用户是否已经存在数据 result = db.query_one( "SELECT * FROM user_profiles WHERE user_id=:user_id", user) if not result: # 添加用户 user["nickname"] = kw["nickName"] user["gender"] = kw["gender"] user["province"] = kw["province"] user["city"] = kw["city"] user["login_time"] = int(time.time()) user["status"] = 0 user["avatar_url"] = kw["avatarUrl"] result = db.insert( """insert into user_profiles (`user_id`, `nickname`, `gender`, `province`, `city`, `login_time`, `status`, `avatar_url`) values (:user_id, :nickname, :gender, :province, :city, :login_time, :status, :avatar_url) """, user) print({"statuc": 200, "msg": "成功"}) return {"statuc": 200, "msg": "成功"} else: # 检查状态是否允许登录 if result["status"] == 1: return {"statuc": 401, "msg": "不要再尝试挑战规则了。"} data = {} data["login_time"] = int(time.time()) data["user_id"] = result["user_id"] result = db.update( "UPDATE user_profiles SET login_time=:login_time WHERE user_id=:user_id", data) print({"statuc": 200, "msg": "成功"}) return {"statuc": 200, "msg": "成功"} except Exception as err: print(err) return {"statuc": 400, "msg": err}
def get(self): "获取用户列表" where = request.args try: index = int(where.get("index", 0)) count = 11 except Exception as err: return {"status": 400, "msg": "错误"}, 400 # 查询用户信息 infoSql = "select * from `user_profiles` WHERE `status` !=1" result = db.query(infoSql) if not result: return {"status": 404, "msg": '没有数据'} # filters 状态 0=空闲 1=接单 2=停止接单 3=休息 keys = {0: "空闲", 1: "接单", 2: "停止接单", 3: "休息"} # 时间类型 1=小时 2=工作日 3=休息日 4=工作月份 5=休息月份 5=季度 princeType = { 1: "小时", 2: "工作日", 3: "休息日", 4: "工作月份", 5: "休息月份", 5: "季度" } for k, v in enumerate(result): # 每个用户只要查出一部视频信息 videoSql = "SELECT video_url FROM `user_video` WHERE is_hide=0 AND is_deleted=0 AND is_auth=1 AND user_id=:user_id ORDER BY create_time DESC limit 0, 1" video = db.query_one(videoSql, {"user_id": v["user_id"]}) if not video: video = {"video_url": ""} v["video"] = video # 查询当前用户的类型 categorySql = "SELECT `name` FROM `category_directions_items` WHERE id=%s" % v[ "dictionary_type"] category = db.query_one(categorySql) if not category: category = "平面模特" else: category = category["name"] v["category_name"] = category # 查询当前用户的价格 priceSql = "SELECT price, time_length, time_type FROM `user_price` WHERE user_id=:user_id" price = db.query_one(priceSql, {"user_id": v["user_id"]}) if not price: price = {"price": "面谈", "time_length": "", "time_type": ""} else: price = { "price": "%0.2f" % price["price"], "time_length": price["time_length"], "time_type": princeType[price["time_type"]] } v["price"] = price # 判断当前用户的状态 status = v["operation_state"] v["status"] = keys[status] result[k] = v return {"status": 200, "msg": "成功", "data": result}