def set(): res = {'code': 1, 'msg': '成功', 'data': {}} # 验证登陆 member = g.member if not member: res['code'] = -1 res['msg'] = '请先登陆' return jsonify(res) # 接收前端传递数据 nickname = request.form.get('nickname') mobile = request.form.get('mobile') province_id = request.form.get('province_id') province_str = request.form.get('province_str') city_id = request.form.get('city_id') city_str = request.form.get('city_str') area_id = request.form.get('area_id') area_str = request.form.get('area_str') address = request.form.get('address') if not all([ nickname, mobile, province_id, province_str, city_id, city_str, area_id, area_str, address ]): res['code'] = -1 res['msg'] = '请填写完整收货地址' return jsonify(res) # 手机号验证 # 存入数据库 memberaddress = MemberAddress() memberaddress.nickname = nickname memberaddress.mobile = mobile memberaddress.province_id = province_id memberaddress.province_str = province_str memberaddress.city_id = city_id memberaddress.city_str = city_str memberaddress.area_id = area_id memberaddress.area_str = area_str memberaddress.address = address memberaddress.member_id = member.id # 查找数据库中是否存在地址 count = MemberAddress.query.filter_by(member_id=member.id, is_default=1).count() if count == 0: memberaddress.is_default = 1 else: memberaddress.is_default = 0 db.session.add(memberaddress) db.session.commit() return jsonify(res)
def set(): ctx = {'code': 1, 'msg': "成功", 'data': {}} token = requests.headers.get('token') id_and_token = token.split('#') if len(id_and_token) != 2: ctx['code'] = -1 ctx['msg'] = 'token错误' return jsonify(ctx) nickname = requests.form.get('nickname') mobile = requests.form.get('mobile') province_id = requests.form.get('province_id') province_str = requests.form.get('province_str') city_str = requests.form.get('city_str') city_id = requests.form.get('city_id') area_id = requests.form.get('area_id') area_str = requests.form.get('area_str') address = requests.form.get('address`') member = Member.query.get(id_and_token[0]) if not member or member.status!=1: ctx['code'] = -1 ctx['msg'] = '用户错误' return jsonify(ctx) num = MemberAddress.query.filter_by(member_id=member.id) memberaddress = MemberAddress() memberaddress.member_id = member.id memberaddress.nickname = nickname memberaddress.mobile = mobile memberaddress.province_id = province_id memberaddress.province_str = province_str memberaddress.city_id = city_id memberaddress.city_str = city_str memberaddress.area_id = area_id memberaddress.area_str = area_str memberaddress.address = address if num == 0: memberaddress.is_default = 1 else: memberaddress.is_default = 0 db.session(memberaddress) db.commit() return jsonify(ctx) return jsonify(ctx)
def add(): res = {'code': 1, 'msg': '成功', 'data': {}} member = g.member if not member: res['code'] = -1 res['msg'] = '验证失败' return jsonify(res) nickame = request.form.get('nickname') mobile = request.form.get('mobile') province_id = request.form.get('province_id') province_str = request.form.get('province_str') city_id = request.form.get('city_id') city_str = request.form.get('city_str') area_id = request.form.get('area_id') area_str = request.form.get('area_str') address = request.form.get('address') if not all([nickame, mobile, province_str, city_id]): res['code'] = -1 res['msg'] = '参数不全' return jsonify(res) memberaddress = MemberAddress() memberaddress.nickname = nickame memberaddress.mobile = mobile memberaddress.province_id = province_id memberaddress.province_str = province_str memberaddress.city_id = city_id memberaddress.city_str = city_str memberaddress.area_id = area_id memberaddress.area_str = area_str memberaddress.address = address memberaddress.member_id = member.id count = MemberAddress.query.filter_by(member_id=member.id, is_default=1).count() if count == 0: memberaddress.is_default = 1 else: memberaddress.is_default = 0 db.session.add(memberaddress) db.session.commit() return jsonify(res)
def add(): res = {'code': 1, 'msg': '成功', 'data': {}} member = g.member if not member: res['code'] = -1 res['msg'] = "用户不存" return jsonify(res) nickname = request.form.get('nickname') mobile = request.form.get('mobile') province_id = request.form.get('province_id') province_str = request.form.get('province_str') city_id = request.form.get('city_id') city_str = request.form.get('city_str') area_id = request.form.get('area_id') area_str = request.form.get('area_str') address = request.form.get('address') # 验证手机号 mobile = str(mobile) zze = re.compile(r'1[35867]\d{9}') ze = zze.search(mobile) if ze == None: res["code"] = -1 res["msg"] = "错误" count = MemberAddress.query.filter_by(is_default=1).count() memberAddress = MemberAddress() memberAddress.nickname = nickname memberAddress.mobile = mobile memberAddress.province_str = province_str memberAddress.province_id = province_id memberAddress.city_id = city_id memberAddress.city_str = city_str memberAddress.area_id = area_id memberAddress.area_str = area_str memberAddress.address = address memberAddress.member_id = member.id if count == 0: memberAddress.is_default = 1 else: memberAddress.is_default = 0 db.session.add(memberAddress) db.session.commit() return jsonify(res)