def subapply(): if 'loginbean' in session: loginbean = session['loginbean'] if request.method == 'POST': shop = Shops() shop['uid'] = loginbean['id'] shop['shopname'] = request.form.get('shopname') shop['address'] = request.form.get('address') shop['lng'] = float(request.form.get('lng')) shop['lat'] = float(request.form.get('lat')) shop['tel'] = request.form.get('tel') print(shop['lng']) print(shop['lat']) fArr = ('idcard', 'ownercard', 'blicense', 'hlicense') for item in fArr: f = request.files[item] if f and allowed_file(f.filename): # 判断是否是允许上传的文件类型 filename = photos.save(request.files[item]) shop[item] = '/static/photos/idcards/' + filename updtime = time.time() shop.updtime = updtime shop.createtime = updtime shop.flag = 0 shop.save() #----修改users表中role=2(审核中)--------- u = Users.objects(_id=shop.uid).update(set__role=2) loginbean['role'] = 2 session['loginbean'] = loginbean # return redirect('/home') return ('<script>alert("提交成功");location.href="/home";</script>') else: return ('<script>alert("账号信息过期,请重新登录");location.href="/";</script>')
def subapply(): if 'loginbean' in session: loginbean = session['loginbean'] if request.method == 'POST': shopid = request.form.get('shopid') #接参,接收id前端传来请求 if shopid == None: # 如果数据库里没有执行下面 shop = Shops() #--------修改users表中role=2(审核中 )---------- # u = Users.objects(_id=shop.uid).updata(inc__role=1) #增加 # u = Users.objects(_id=shop.uid).update(set__role=2) #修改 # msg.save() else: shop = Shops.objects(_id=shopid, uid=loginbean['id']).first() # print(shop['uid']) shop['uid'] = loginbean['id'] shop['shopname'] = request.form.get('shopname') shop['address'] = request.form.get('address') shop['lng'] = float(request.form.get('lng')) shop['lat'] = float(request.form.get('lat')) shop['tel'] = request.form.get('tel') #以上是入库操作 # shopname = request.form.get('shopname') app.config['UPLOADED_PHOTOS_DEST'] = os.getcwd( ) + '/static/photos' # 文件储存地址 configure_uploads(app, photos) #使用configure_uploads()方法注册并完成相应的配置 fArr = ('idcard', 'ownercard', 'blicense', 'hlicense') for item in fArr: if item in request.files: f = request.files[item] if f and allowed_file(f.filename): # 判断是否是允许上传的文件类型 filename = photos.save(request.files[item]) # print(filename) shop[item] = '/static/photos/' + filename # --------构建shops商家,入库插入数据 updtime = time.strftime('%Y-%m-%d %H:%M:%S') #将时间转换成整体显示 # updtime = time.time() shop.updtime = updtime shop.flag = 0 if shopid == None: # 如果数据库里没有执行下面 shop.createtime = updtime shop.save() u = Users.objects(_id=shop.uid).update(set__role=2) loginbean['role'] = 2 session['loginbean'] = loginbean return redirect('/home') else: return '<script>alert("session过期,请重新登录");location.href="/";</script>'