def apply_clients_info(user_id): """ @api {get} /seller/apply_clients_info/<user_id>/ 06. 获取用户详细信息 @apiGroup S_商家_Seller @apiVersion 1.0.0 @apiPermission 访问授权 @apiParam {str} user_id 用户ID @apiSuccessExample {json} JSON.result 对象 { "_id": String # 主键,用户ID,其它地方为: user_id "name": String # 姓名/昵称 "phone": String #联系方式 "avatar": String # 头像 "sex": Int # 性别: [-1=未知/1=男/2=女] "apply_weight" : Double #申请减重[单位:kg] "estimated_times" : String #预计时间 "age": Int #年龄 "height" : Int #身高 [cm] "weight" : Int #体重 [kg] "sport" : String # 运动 "assessment" : String # 当前评估 } """ if not user_id: return "请求参数错误" data = {} code = 0 try: data = users.find_one(filter={"_id": user_id}, projection={"_id": 1, "name": 1, "phone": 1, "avatar": 1, "sex": 1, "apply_weight": 1, "estimated_times": 1, "age": 1, "height": 1, "weight": 1, "assessment": 1, "sport": 1}) except: code = -1 return apiresult(data, code)
def sell_comprehensive_daily(user_id): """ @api {GET} /seller/sell_comprehensive_daily/<user_id>/ 10. 获取用户综合日报列表信息 @apiGroup S_商家_Seller @apiVersion 1.0.0 @apiPermission 访问授权 @apiParam {str} next_start 分页起始ID 默认值: null @apiSuccessExample {json} JSON.result 对象 { "local_weight" : Double # 原始体重 [单位:kg] "arrange_weight" : Double # 变化体重 [单位:kg,备注:结果小于0瘦了,大于0胖了] "today_weight" : Double # 今日体重 [单位:kg] "comprehensive" : [{ "weight": Double # 今日体重 "arrange_weight" : Double # 变化体重 [单位:kg] "timed": Long # 创建时间 }] } """ if not user_id: return "请求参数不能为空" lists = [] code = 0 result = {} try: list = DB.comprehensive_daily.find(filter={"user_id": user_id}, projection={"weight": 1, "timed": 1, "_id": 1}).limit(item_count()).skip(next_start()).sort("timed", pymongo.DESCENDING) user = users.find_one(filter={"_id": user_id}, projection={"_id": 1, "weight": 1, "local_weight": 1}) for comprehen in list: com = {} com['_id'] = comprehen['_id'] com['weight'] = comprehen['weight'] if "weight" in comprehen and "weight" in user: com['arrange_weight'] = comprehen['weight'] - user['local_weight'] else: com['arrange_weight'] = float(0) com['timed'] = comprehen['timed'] lists.append(com) arrange_weight = float(0) if user: if ("weight" in user) and ("local_weight" in user): arrange_weight = user['weight'] - user['local_weight'] result = {"local_weight": user['local_weight'], "arrange_weight": arrange_weight, "today_weight": user['weight'], "comprehensive": lists} else: result = {"local_weight": float(0), "arrange_weight": arrange_weight, "today_weight": float(0), "comprehensive": lists} except: code = -1 return apiresult(result, code)
def recipes(user_id): """ @api {POST} /seller/recipes/<user_id>/ 04. 商家发布对应会员的食谱 @apiGroup S_商家_Seller @apiVersion 1.0.0 @apiPermission 访问授权 @apiParam {str} content 食谱内容 @apiSuccessExample {json} JSON.result 对象 { } """ if not user_id: return "请求参数错误" user = users.find_one(filter={"_id": user_id, "type": 0, "apply_status": 1}, projection={"_id": 1}) if not user: return "该用户不存在或还不是您的会员" content = request.form.get("content") tim = int(time.strftime('%Y%m%d', time.localtime(time.time()))) recipe = { "_id": bson.objectid.ObjectId().__str__(), "user_id": user_id, "content": content, "timed": timestamp(), "day": tim } code = 0 try: recipe_data = DB.recipes.find_one(filter={"day": tim, "user_id": user_id}, projection={"_id": 1}) if recipe_data: DB.recipes.update_one({"day": tim, "user_id": user_id}, {"$set": {"content": content, "timed": timestamp()}}) else: DB.recipes.insert_one(recipe) #修改用户信息的配餐时间 users.update_one({"_id": user_id}, {"$set": {"is_report": timestamp()}}) except: code = -1 return apiresult(None, code)
def user_info(): """ @api {GET} /user/user_info/ 01. 我的(会员用户)-信息 @apiGroup U_用户_USER @apiVersion 1.0.0 @apiSuccessExample {json} JSON.result 对象 { "_id": String # 主键,用户ID, "account": String # 账号登录名 "password": String # 密码(系统自加密存储,不可逆) "type": Int # 类别, [0=会员/1=商家] "name": String # 姓名/昵称 "oauth": [ { "open_id": String # 第三方开放ID "name": String # 第三方昵称 "avatar": String # 第三方头像 "sex": Int # 第三方性别 "timed": Long # 首次授权时间 }, ... ], "phone": String #联系方式 "avatar": String # 头像 "sex": Int # 性别: [-1=未知/1=男/2=女] "apply_weight" : Double #申请减重[单位:kg] "estimated_times" : String #预计时间 "age": Int #年龄 "height" : Int #身高 [cm] "weight" : Double #体重 [kg] "local_weight" : Double #原始体重 [kg] "local_waist" : Double #原始腰围 [cm] "sport" : String # 运动 "apply_status" : Int # 申请状态[0=申请/1=商家同意/-1=商家不同意/2=默认状态] "assessment" : String # 当前评估 "diet_timed" : Long #最新饮食日报发布时间,根据时间判断是否已报 "is_report" : Long #最新食谱发布时间,根据时间判断商家是否配餐 "status": Int # 状态: [0=正常/-1=停止] "online": Int # 在线状态: [0=离线/1=在线] "address": String # 地址 "times": { "timed": Long # 创建时间 "logined": Long # 最后登录时间, 0=还没有登录过 "stoped": Long # 停用起始时间, 如果status=-1时可以通过这个时间恢复正常 "stop_elapse": Long # 停用时长(秒), -1=永久 } } """ try: user_id = session["user_id"] # user_id = "5a3a2d504aee300b032c897e" find = users.find_one({"_id": user_id, "status": 0, "type": 0}) if find == None: find["new_assessment"] = "" return common.find(find=find) else: weight = find["weight"] height = find["height"] if weight == float(0) or height == float(0): find["new_assessment"] = "" return common.find(find=find) else: heights = float(height) / float(100) num = float(heights) * float(heights) Result = float(weight) / num if Result < 18.5: standard = "营养不良" elif Result > 18.5 and Result < 23.9999: standard = "正常体重" elif Result >= 24 and Result <= 26: standard = "超重" elif Result > 26 and Result < 28: standard = "超重,肥胖" elif Result > 28 and Result < 30: standard = "轻度肥胖" elif Result > 30 and Result < 35: standard = "中度肥胖" elif Result >= 35: standard = "重度肥胖" find["new_assessment"] = standard return common.find(find=find) except BaseException: return common.find(code=-1)
def index(): code = request.args.get('code') token_url = requests.get("https://api.weixin.qq.com/sns/oauth2/access_token?appid="+appID+"&secret="+appsecret+"&code="+code+"&grant_type=authorization_code"); json_lode = json.loads(token_url.content) openid = json_lode["openid"] access_token = json_lode["access_token"] if openid: user_data = users.find_one({"oauth.open_id": openid}) if user_data == None: user_info = requests.get("https://api.weixin.qq.com/sns/userinfo?access_token=" + access_token + "&openid=" + openid + "&lang=zh_CN") json_user_info = json.loads(user_info.content) object_id = bson.objectid.ObjectId().__str__() # 用户数据 data = { "_id": object_id, "account": "", "password": "", "type": int(0), "name": json_user_info["nickname"], "oauth": [{ "open_id": str(openid), "name": json_user_info["nickname"], "avatar": str(json_user_info["headimgurl"]), "sex": int(json_user_info["sex"]), }], "phone": "", "avatar": str(json_user_info["headimgurl"]), "sex": int(json_user_info["sex"]), "apply_weight": float(0), "age": int(0), "height": int(0), "weight": float(0), "sport": "", "apply_status": int(2), "assessment": "", "diet_timed": int(0), "is_report": int(0), "status": int(0), "online": int(1), "address": "", "local_weight": float(0), "local_waist": float(0), "estimated_times": "", "times": { "timed": int(time.time()), "logined": int(time.time()), "stoped": int(0), "stop_elapse": int(0), }, } set_data = users.insert_one(data) if set_data.inserted_id: session["user_id"] = set_data.inserted_id return render_template('index/index.html') else: type = user_data["type"] session["user_id"] = user_data["_id"] if int(type) == 0: return render_template("index/index.html") elif int(type) == 1: return render_template("index/index_admin.html")