def get_all_order(): try: req_data = request.get_json() u_id = req_data["u_id"] except: return jsonify({ "status": 400, "msg": "请求参数错误" }) else: query = db.session.query(Orderlist).filter(Orderlist.u_id == u_id) if query.count() != 0: all_order = dumps(query.all()) for order in all_order: o_id = order["o_id"] all_od = dumps(db.session.query(Orderdetail).filter(Orderdetail.o_id == o_id).all()) o_detail = [] for od in all_od: goods_id = od["goods_id"] goods = dumps(db.session.query(Good).filter(Good.goods_id == goods_id).first()) od.update({"goods": goods}) o_detail.append(od) order.update({"order_detail": o_detail}) data = all_order return jsonify({ "status": 200, "msg": "获取用户所有订单成功", "data": data }) else: return jsonify({ "status": 300, "msg": "该用户暂无订单" })
def cheapgoods(): count = request.args.get("count") querys = db.session.query(DiscountGood) if not count: if querys.count() != 0: data = dumps(querys.all()) return jsonify({ "status": 200, "msg": "获取打折商品数据成功", "data": { "goods": data } }) else: return jsonify({"status": 300, "msg": "暂无数据"}) else: if querys.count() != 0: data = dumps(querys.limit(count).all()) return jsonify({ "status": 200, "msg": "获取指定数量打折商品数据成功", "data": { "goods": data } }) else: return jsonify({"status": 300, "msg": "暂无数据"})
def get_all(): query = db.session.query(Forum) if query.count() != 0: data = dumps(query.all()) return jsonify({"status": 200, "msg": "获取所有帖子成功", "data": data}) else: return jsonify({"status": 300, "msg": "暂无帖子数据"})
def get_notice(): query = db.session.query(Notice).filter(Notice.is_use == True) if query.count() != 0: data = dumps(query.first()) return jsonify({"status": 200, "msg": "获取公告信息成功", "data": data}) else: return jsonify({"status": 300, "msg": "暂无公告信息"})
def cart_allgoods(): try: req_data = request.get_json() u_id = req_data["u_id"] except: return jsonify({ "status": 400, "msg": "请求参数错误" }) else: query = db.session.query(Cart).filter(Cart.u_id == u_id) if query.count() != 0: data = dumps(query.all()) return jsonify({ "status": 200, "msg": "获取用户购物车成功", "data": data }) else: return jsonify({ "status": 300, "msg": "用户购物车为空" }) # 生成订单 '''
def follow_alldoctors(): try: req_data = request.get_json() u_id = req_data['u_id'] except: return jsonify({ 'status': 400, 'msg': '请求参数错误' }) else: query = db.session.query(FollowDoc).filter(FollowDoc.u_id == u_id) if query.count() != 0: data = dumps(query.all()) return jsonify({ 'status': 200, 'msg': "获取所有关注医生成功", 'data': { "followed_doctors": data } }) else: return jsonify({ 'status': 300, 'msg': "该用户暂未关注任何医生" })
def get_address(): try: req_data = request.get_json() u_id = req_data['u_id'] except: return jsonify({ 'status': 400, 'msg': '请求参数错误' }) else: query_user = db.session.query(User).filter(User.id == u_id) if query_user.count() != 0: query = db.session.query(UserAddres).filter(UserAddres.id == u_id) if query.count() != 0: all_addr = dumps(query.all()) return jsonify({ 'status': 200, 'msg': '获取用户所有收货地址成功', 'data': { 'alladdr': all_addr } }) else: return jsonify({ 'status': 300, "msg": '该用户暂无收货地址' }) else: return jsonify({ 'status': 500, "msg": '查无此用户' })
def info(): querys = db.session.query(Infomation) if querys.count() != 0: data = random.choice(dumps(querys.all())) return jsonify({ "status": 200, "msg": "获取资讯数据成功", "data": { "info": data } }) else: return jsonify({"status": 300, "msg": "暂无数据"})
def rotation(): querys = db.session.query(Rotatiton) select = db.session.query(RotationSelect).filter( RotationSelect.is_select == 1) if querys.count() != 0: data = dumps(querys.all()) return jsonify({ "status": 200, "msg": "获取轮播图数据成功", "data": { "urls": data, 'state': select.first().name } }) else: return jsonify({"status": 300, "msg": "暂无数据"})
def get_doctordetail(): try: req_data = request.get_json() r_id = req_data['d_id'] except: return jsonify({'status': 400, 'msg': "请求参数错误"}) else: query = db.session.query(Doctor).filter(Doctor.d_id == r_id) if query.count() != 0: data = dumps(query.all()) return jsonify({ 'status': 200, 'msg': "获取医生详情成功", 'data': { 'doctordetail': data } }) else: return jsonify({'status': 300, 'msg': "暂无该医生数据"})
def get_rooms(): try: req_data = request.get_json() h_id = req_data['h_id'] except: return jsonify({'status': 400, 'msg': "请求参数错误"}) else: query = db.session.query(Room).filter(Room.h_id == h_id) if query.count() != 0: data = dumps(query.all()) return jsonify({ 'status': 200, 'msg': "获取该医院科室数据成功", 'data': { 'rooms': data } }) else: return jsonify({'status': 300, 'msg': "暂无该医院科室数据"})
def get_hospitals(): try: req_data = request.get_json() c_id = req_data['cityid'] except: return jsonify({'status': 400, 'msg': "请求参数错误"}) else: query = db.session.query(Hospital).filter(Hospital.cityid == c_id) if query.count() != 0: data = dumps(query.all()) return jsonify({ 'status': 200, 'msg': "获取该地区医院数据成功", 'data': { 'hospitals': data } }) else: return jsonify({'status': 300, 'msg': "暂无该地区医院数据"})
def get_default(): hospital = db.session.query(Hospital).filter( Hospital.cityid == 110100).first() room1 = db.session.query(Room).filter(Room.h_id == hospital.h_id)[1] room0 = db.session.query(Room).filter(Room.h_id == hospital.h_id).first() query0 = db.session.query(Doctor).filter(Doctor.room_id == room0.room_id) query1 = db.session.query(Doctor).filter(Doctor.room_id == room1.room_id) if any((query0.count() != 0, query1.count() != 0)): data = dumps(query0.all() + query1.all()) for i, doctor in enumerate(data): doctor.update({"d_index": i}) return jsonify({ 'status': 200, 'msg': "获取默认医生数据成功", 'data': { 'doctors': data } }) else: return jsonify({'status': 300, 'msg': "暂无医生数据"})
def get_doctors(): try: req_data = request.get_json() r_id = req_data['room_id'] except: return jsonify({'status': 400, 'msg': "请求参数错误"}) else: query = db.session.query(Doctor).filter(Doctor.room_id == r_id) if query.count() != 0: data = dumps(query.all()) for i, doctor in enumerate(data): doctor.update({"d_index": i}) return jsonify({ 'status': 200, 'msg': "获取该科室医生数据成功", 'data': { 'doctors': data } }) else: return jsonify({'status': 300, 'msg': "暂无该科室医生数据"})
def login(): # 获取请求上传的json数据 try: req_data = request.get_json() phone, pwd = req_data['u_tel'], req_data['u_password'] if any((len(pwd.strip()), len(phone.strip()))) == 0: raise Exception() except: return jsonify({ 'status': 400, 'msg': '请求参数错误' }) else: query = db.session.query(User).filter(User.u_tel == phone) if query.count() == 0: return jsonify({ 'status': 300, 'msg': '查无此用户' }) else: login_user = query.first() if encode4md5(pwd) == login_user.u_password: token = new_token() add_token(phone, token) data = dumps(login_user) return jsonify({ 'status': 200, 'msg': '登录成功', 'token': token, 'data': { 'user': data } }) else: return jsonify({ 'status': 500, 'msg': '登录失败,用户名或密码错误' })
def get_allnotice(): try: req_data = request.get_json() u_id = req_data["u_id"] except: return jsonify({ "status": 400, "msg": "请求参数错误" }) else: query = db.session.query(UserNotice).filter(UserNotice.u_id == u_id) if query.count() == 0: now = datetime.datetime.now().strftime("%H:%S") new_notice1 = UserNotice(u_id=u_id, un_titile="尊敬的用户,您好!", un_text="现推出充值赠送活动:充值100元赠送5元,充值1000元赠送60元!多充多得,心动不如行动!", un_time=now) new_notice2 = UserNotice(u_id=u_id, un_titile="尊敬的用户,您好!", un_text="您的账户于2019-11-28日22:30在广东省深圳市登录成功。如果不是本人登录,请及时修改密码如是本人登录,请忽略。", un_time=now) new_notice3 = UserNotice(u_id=u_id, un_titile="尊敬的用户,您好!", un_text="折扣商品已更新!今日特价:六味地黄胶囊 、茶碱缓释片 、辛伐他汀胶囊、精制银翘解毒片、气管炎橡胶膏。", un_time=now) db.session.add_all([new_notice1, new_notice2, new_notice3]) db.session.commit() query_data = db.session.query(UserNotice).filter(UserNotice.u_id == u_id) if query_data.count() != 0: data = dumps(query.all()) return jsonify({ "status": 200, "msg": "获取用户所有消息成功", "data": { "messages": data } }) else: return jsonify({ "status": 300, "msg": "该用户暂无消息" })