def hasProduct(): getClassid = request.args.get('classid') procont = db_session.query(func.count(Product.proid)).filter( Product.pid == getClassid).scalar() if procont != 0: return jsonify({"state":'haspro'}) else: return jsonify({"state":'ok'})
def getSearchList(): proname = request.args.get('proname') page = int(request.args.get('pageNo',1)) #get到页数 if proname == None or proname == '': proname = '' # print proname lim = int(6) #get到每页显示数量 newcont = db_session.query(func.count(Product.proid)).\ filter(Product.proname.like("%"+proname+"%"), Product.display == 0).scalar() #计算数据总数 if newcont == None: newcont = 0 if page == 1: page_nb = 0 #如果第一页则从第0条数据开始调用 page_show = int(lim + page_nb) #调用数量的结尾数 else: page_nb = int((lim * (page - 1))) #否则用显示数量乘以当前页数减去1 得到开始数 page_show = int(lim + page_nb) #调用数量的结尾数 productlist = Product.query.\ filter(Product.proname.like("%"+proname+"%")).\ filter_by(display = 0).\ order_by(Product.add_time).limit(lim)[page_nb:page_show] return jsonify({'productlist': [Productls.to_list() for Productls in productlist]})
def news(): page = int(request.args.get('pageNo',1)) #get到页数 getpid = request.args.get('pid',1) #get到页数 lim = int(8) #get到每页显示数量 newcont = db_session.query(func.count(News.id)).\ filter(News.pid == getpid, News.display ==0).scalar() #计算数据总数 if newcont == None: newcont = 0 if page == 1: page_nb = 0 #如果第一页则从第0条数据开始调用 page_show = int(lim + page_nb) #调用数量的结尾数 else: page_nb = int((lim * (page - 1))) #否则用显示数量乘以当前页数减去1 得到开始数 page_show = int(lim + page_nb) #调用数量的结尾数 newslist = News.query.\ filter_by(pid = getpid, display = 0).\ order_by(News.addtime).limit(lim)[page_nb:page_show] return jsonify({'news': [New.to_newlist() for New in newslist]})
def ilikelist(): userid = g.current_user.id page = int(request.args.get('pageNo', 1)) #get到页数 lim = int(6) #get到每页显示数量 newcont = db_session.query(func.count(UserLike.user_id)).\ filter(UserLike.user_id == userid).scalar() #计算数据总数 if newcont == None: newcont = 0 if page == 1: page_nb = 0 #如果第一页则从第0条数据开始调用 page_show = int(lim + page_nb) #调用数量的结尾数 else: page_nb = int((lim * (page - 1))) #否则用显示数量乘以当前页数减去1 得到开始数 page_show = int(lim + page_nb) #调用数量的结尾数 likelist = UserLike.query.\ filter_by(user_id = userid).\ order_by(UserLike.add_time).limit(lim)[page_nb:page_show] return jsonify({'likelist': [LikeList.to_list() for LikeList in likelist]})
def getstProduct(): topid = int(request.args.get('topid')) page = int(request.args.get('pageNo',1)) #get到页数 if topid == None: abort(404) lim = int(6) #get到每页显示数量 newcont = db_session.query(func.count(Product.proid)).\ filter(Product.new_p == topid, Product.display == 0).scalar() #计算数据总数 if newcont == None: newcont = 0 if page == 1: page_nb = 0 #如果第一页则从第0条数据开始调用 page_show = int(lim + page_nb) #调用数量的结尾数 else: page_nb = int((lim * (page - 1))) #否则用显示数量乘以当前页数减去1 得到开始数 page_show = int(lim + page_nb) #调用数量的结尾数 productlist = Product.query.\ filter_by(new_p = topid).\ filter_by(display = 0).\ order_by(Product.add_time).limit(lim)[page_nb:page_show] return jsonify({'productlist': [Productls.to_list() for Productls in productlist]})
def get_cart_cont(): userid = g.current_user.id cartcont = db_session.query(func.count(UserCart.userid)).\ filter(UserCart.userid == userid).scalar() #计算数据总数 return jsonify({'cartcont': cartcont})
def chose_pro(): proname = request.args.get('proname') if proname == None or proname == '': proname = '' lim = int(10) #get到每页显示数量 page = int(request.args.get('page', 1)) #get到页数 newcont = db_session.query(func.count(Product.proid)).\ filter(Product.proname.like("%"+proname+"%"), Product.display == 0).scalar() #计算数据总数 page_cont = int(math.ceil(round(float(newcont) / lim, 2))) if page == 1: page_nb = 0 #如果第一页则从第0条数据开始调用 page_show = int(lim + page_nb) #调用数量的结尾数 else: page_nb = int((lim * (page - 1))) #否则用显示数量乘以当前页数减去1 得到开始数 page_show = int(lim + page_nb) #调用数量的结尾数 page_size = [] for i in range(page_cont): page_size.append(i + 1) previous = page - 1 if previous == 0: previous = 0 nextp = page + 1 if nextp == page_cont: nextp = page_cont if newcont >= lim: productlist = db_session.query(Product).\ filter(Product.proname.like("%"+proname+"%"), Product.display == 0).\ group_by(Product.proid).limit(lim)[page_nb:page_show] else: page_show = int(newcont + ((newcont * page) - 1)) # print newcont,page_show,page productlist = db_session.query(Product).\ filter(Product.proname.like("%"+proname+"%"), Product.display == 0).\ group_by(Product.proid).limit(lim)[0:page_show] return render_template("chose_product.html", productlist=productlist, page=page_size, previous=previous, nextp=nextp, page_cont=page_cont, proname=proname, newcont=newcont)
def count_distinct(db_enabled): # if db is enabled, then open a session with the database if db_enabled: session = Session() # if db is enabled, then query the database and w results = session.query(label ('Zipcode', Provider.zipcode), label('Count', func.count(Provider.firstname+Provider.lastname+Provider.credentials))).group_by(Provider.zipcode).order_by('"Count" desc').all() session.close() # Write the output to CSV file for result in results: write_csv(result) print 'Data saved to output.csv'
def get_order(): userid = g.current_user.id ordertype = int(request.args.get('ordertype', 0)) state = request.args.get('state', 0) if state == '0': state = [0] if state == '1': state = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14] if state == '15': state = [15] # print state page = int(request.args.get('pageNo', 1)) #get到页数 lim = int(3) #get到每页显示数量 newcont = db_session.query(func.count(Order.id)).\ filter(Order.userid == userid).\ filter(Order.order_type == ordertype).\ filter(Order.state.in_((state))).\ scalar() #计算数据总数 if newcont == None: newcont = 0 if page == 1: page_nb = 0 #如果第一页则从第0条数据开始调用 page_show = int(lim + page_nb) #调用数量的结尾数 else: page_nb = int((lim * (page - 1))) #否则用显示数量乘以当前页数减去1 得到开始数 page_show = int(lim + page_nb) #调用数量的结尾数 orderlist = Order.query.\ filter_by(userid = userid, order_type = ordertype ).\ filter(Order.state.in_((state))).\ order_by(Order.addtime).limit(lim)[page_nb:page_show] return jsonify({'orderlist': [Orders.to_list() for Orders in orderlist]})
def get_query_result_json(): """Get search query results and save them in a json file""" month = request.args.get( 'month') # month is a string after being passed via HTTP month = [int(i) for i in month.split(',') ] # Store all the months user chooses as integer in a list tavgLow = request.args.get('tavgLow') tavgHigh = request.args.get('tavgHigh') prcp = request.args.get('prcp') continent = request.args.get('continent') iso2 = request.args.get('iso2') # Connect to db to retrieve the city & continent objects meeting the criteria results = db.session.query(City,Continent).select_from(City).join(Climate).join(Continent)\ .filter(Climate.month.in_(month), Climate.tavg >= tavgLow, Climate.tavg <= tavgHigh) if prcp == "quartile1": results = results.filter(Climate.prcp <= 27) elif prcp == "quartile2": results = results.filter(Climate.prcp > 27, Climate.prcp <= 60) elif prcp == "quartile3": results = results.filter(Climate.prcp > 60, Climate.prcp <= 110) elif prcp == "quartile4": results = results.filter(Climate.prcp > 110) if continent: results = results.filter(Continent.continent_name == continent) if iso2: results = results.filter(City.iso2 == iso2) results = results.group_by(City,Continent)\ .having(func.count(Climate.month)==len(month)).limit(20).all() result_dict = create_result_dict(results) return jsonify({'results': result_dict})
def manage_product(): ''' 以下代码是获取分类json。 ''' classify = Classify.classify_check().all() towclass = [] for cls in classify: towclass.append({'classid':cls.classid, 'topid':cls.topid, 'classname':cls.classname, 'icon':cls.icon, 'ctype':cls.ctype, 'display':cls.display, 'sort':cls.sort}) classifylist = json.dumps(getChildren(0,towclass)) pid = int(request.args.get('pid')) display = request.args.get('display',0) proname = request.args.get('proname') # print title # 分页开始 lim = int(30) #get到每页显示数量 page = int(request.args.get('page',1)) #get到页数 # 权限判断 if pid == 0 or pid == None: if current_user.group.power == 0: #超级管理员 newcont = db_session.query(func.count(Product.proid)).filter( Product.display == display).scalar() #计算数据总数 if current_user.group.power == 1: #组长 newcont = db_session.query(func.count(Product.proid)).filter(Product.display == display, Product.teamid == current_user.teamid).scalar() #计算数据总数 if current_user.group.power == 2: #组员 newcont = db_session.query(func.count(Product.proid)).filter(Product.display == display, Product.teamid == current_user.teamid, Product.creatorid == current_user.id).scalar() #计算数据总数 else: if current_user.group.power == 0: #超级管理员 newcont = db_session.query(func.count(Product.proid)).filter(Product.pid == pid, Product.display == display).scalar() #计算数据总数 if current_user.group.power == 1: #组长 newcont = db_session.query(func.count(Product.proid)).filter(Product.pid == pid, Product.display == display, Product.teamid == current_user.teamid).scalar() #计算数据总数 if current_user.group.power == 2: #组员 newcont = db_session.query(func.count(Product.proid)).filter(Product.pid == pid, Product.display == display, Product.teamid == current_user.teamid, Product.creatorid == current_user.id).scalar() #计算数据总数 page_cont = int(math.ceil(round(float(newcont) / lim,2))) #总数除以显示数量得到分页总数 if page == 1: page_nb = 0 #如果第一页则从第0条数据开始调用 page_show = int(lim + page_nb) #调用数量的结尾数 else: page_nb = int((lim * (page - 1))) #否则用显示数量乘以当前页数减去1 得到开始数 page_show = int(lim + page_nb) #调用数量的结尾数 page_size = [] for i in range(page_cont): page_size.append(i + 1) # print '%s%s%s%s%s%s%s%s%s%s%s%s%s%s' %('总信息数:',newcont,' 每页显示数:',lim,' 当前页:',page,' 总页数:',page_cont,' 当前显示首数:',page_nb,' 当前显示尾数:',page_show,' 分页:',page_size) previous = page - 1 if previous == 0: previous = 0 nextp = page + 1 if nextp == page_cont: nextp = page_cont # 如果没有搜索条件,直接获取列表 if pid == 0 or pid == None: if proname == None: proname = '' if current_user.group.power == 0: productlist = Product.query.\ filter(Product.display == display).\ group_by(Product.proid).limit(lim)[page_nb:page_show] if current_user.group.power == 1: productlist = Product.query.\ filter( Product.display == display, Product.teamid == current_user.teamid).\ group_by(Product.proid).limit(lim)[page_nb:page_show] if current_user.group.power == 2: productlist = Product.query.\ filter(Product.display == display, Product.teamid == current_user.teamid, Product.creatorid == current_user.id).\ group_by(Product.proid).limit(lim)[page_nb:page_show] # 如果有搜索条件,计算分页,加入条件 else: if current_user.group.power == 0: #超级管理员 newcont = db_session.query(func.count(Product.proid)).\ filter(Product.proname.like("%"+proname+"%"), Product.display == display).scalar() #计算数据总数 if current_user.group.power == 1: #组长 newcont = db_session.query(func.count(Product.proid)).\ filter(Product.proname.like("%"+proname+"%"), Product.display == display, Product.teamid == current_user.teamid).scalar() #计算数据总数 if current_user.group.power == 2: #组员 newcont = db_session.query(func.count(Product.proid)).\ filter(Product.proname.like("%"+proname+"%"), Product.display == display, Product.teamid == current_user.teamid, Product.creatorid == current_user.id).scalar() #计算数据总数 page_cont = int(math.ceil(round(float(newcont) / lim,2))) page_size = [] for i in range(page_cont): page_size.append(i + 1) if newcont >= lim: if current_user.group.power == 0: #超级管理员 productlist = db_session.query(Product).\ filter(Product.proname.like("%"+proname+"%"), Product.display == display).\ group_by(Product.proid).limit(lim)[page_nb:page_show] if current_user.group.power == 1: #组长 productlist = db_session.query(Product).\ filter(Product.proname.like("%"+proname+"%"), Product.display == display, Product.teamid == current_user.teamid).\ group_by(Product.proid).limit(lim)[page_nb:page_show] if current_user.group.power == 2: #组员 productlist = db_session.query(Product).\ filter(Product.proname.like("%"+proname+"%"), Product.display == display, Product.teamid == current_user.teamid, Product.creatorid == current_user.id).\ group_by(Product.proid).limit(lim)[page_nb:page_show] else: page_show = int(newcont + ((newcont * page)-1)) # print newcont,page_show,page if current_user.group.power == 0: #超级管理员 productlist = db_session.query(Product).\ filter(Product.proname.like("%"+proname+"%"),Product.display == display).\ group_by(Product.proid).limit(lim)[0:page_show] if current_user.group.power == 1: #组长 productlist = db_session.query(Product).\ filter(Product.proname.like("%"+proname+"%"), Product.display == display, Product.teamid == current_user.teamid).\ group_by(Product.proid).limit(lim)[0:page_show] if current_user.group.power == 2: #组员 productlist = db_session.query(Product).\ filter(Product.proname.like("%"+proname+"%"), Product.display == display, Product.teamid == current_user.teamid, Product.creatorid == current_user.id).\ group_by(Product.proid).limit(lim)[0:page_show] else: if proname == None: proname = '' if current_user.group.power == 0: productlist = Product.query.\ filter(Product.pid == pid, Product.display == display).\ group_by(Product.proid).limit(lim)[page_nb:page_show] if current_user.group.power == 1: productlist = Product.query.\ filter(Product.pid == pid, Product.display == display, Product.teamid == current_user.teamid).\ group_by(Product.proid).limit(lim)[page_nb:page_show] if current_user.group.power == 2: productlist = Product.query.\ filter(Product.pid == pid, Product.display == display, Product.teamid == current_user.teamid, Product.creatorid == current_user.id).\ group_by(Product.proid).limit(lim)[page_nb:page_show] # 如果有搜索条件,计算分页,加入条件 else: if current_user.group.power == 0: #超级管理员 newcont = db_session.query(func.count(Product.proid)).\ filter(Product.proname.like("%"+proname+"%"), Product.pid == pid, Product.display == display).scalar() #计算数据总数 if current_user.group.power == 1: #组长 newcont = db_session.query(func.count(Product.proid)).\ filter(Product.proname.like("%"+proname+"%"), Product.pid == pid, Product.display == display, Product.teamid == current_user.teamid).scalar() #计算数据总数 if current_user.group.power == 2: #组员 newcont = db_session.query(func.count(Product.proid)).\ filter(Product.proname.like("%"+proname+"%"), Product.pid == pid, Product.display == display, Product.teamid == current_user.teamid, Product.creatorid == current_user.id).scalar() #计算数据总数 page_cont = int(math.ceil(round(float(newcont) / lim,2))) page_size = [] for i in range(page_cont): page_size.append(i + 1) if newcont >= lim: if current_user.group.power == 0: #超级管理员 productlist = db_session.query(Product).\ filter(Product.proname.like("%"+proname+"%"), Product.pid == pid, Product.display == display).\ group_by(Product.proid).limit(lim)[page_nb:page_show] if current_user.group.power == 1: #组长 productlist = db_session.query(Product).\ filter(Product.proname.like("%"+proname+"%"), Product.pid == pid, Product.display == display, Product.teamid == current_user.teamid).\ group_by(Product.proid).limit(lim)[page_nb:page_show] if current_user.group.power == 2: #组员 productlist = db_session.query(Product).\ filter(Product.proname.like("%"+proname+"%"), Product.pid == pid, Product.display == display, Product.teamid == current_user.teamid, Product.creatorid == current_user.id).\ group_by(Product.proid).limit(lim)[page_nb:page_show] else: page_show = int(newcont + ((newcont * page)-1)) # print newcont,page_show,page if current_user.group.power == 0: #超级管理员 productlist = db_session.query(Product).\ filter(Product.proname.like("%"+proname+"%"), Product.pid == pid, Product.display == display).\ group_by(Product.proid).limit(lim)[0:page_show] if current_user.group.power == 1: #组长 productlist = db_session.query(Product).\ filter(Product.proname.like("%"+proname+"%"), Product.pid == pid, Product.display == display, Product.teamid == current_user.teamid).\ group_by(Product.proid).limit(lim)[0:page_show] if current_user.group.power == 2: #组员 productlist = db_session.query(Product).\ filter(Product.proname.like("%"+proname+"%"), Product.pid == pid, Product.display == display, Product.teamid == current_user.teamid, Product.creatorid == current_user.id).\ group_by(Product.proid).limit(lim)[0:page_show] return render_template( "manage_product.html", pagename = 'product', pid = pid, productlist = productlist, page = page_size, previous = previous, nextp = nextp, page_cont = page_cont, proname = proname, newcont = newcont, classifylist = classifylist)
def manage_news(): pid = int(request.args.get('pid')) if pid == 1: tsActive = "manage_news" elif pid == 2: tsActive = "help" elif pid == 3: tsActive = "manage_company" display = request.args.get('display', 0) title = request.args.get('title') # print title # 分页开始 lim = int(25) #get到每页显示数量 page = int(request.args.get('page', 1)) #get到页数 if current_user.group.power == 0: #超级管理员 newcont = db_session.query(func.count(News.id)).filter( News.pid == pid, News.display == display).scalar() #计算数据总数 if current_user.group.power == 1: #组长 newcont = db_session.query(func.count(News.id)).filter( News.pid == pid, News.display == display, News.teamid == current_user.teamid).scalar() #计算数据总数 if current_user.group.power == 2: #组员 newcont = db_session.query(func.count(News.id)).filter( News.pid == pid, News.display == display, News.teamid == current_user.teamid, News.userid == current_user.id).scalar() #计算数据总数 if newcont == None: newcont = 0 page_cont = int(math.ceil(round(float(newcont) / lim, 2))) #总数除以显示数量得到分页总数 if page == 1: page_nb = 0 #如果第一页则从第0条数据开始调用 page_show = int(lim + page_nb) #调用数量的结尾数 else: page_nb = int((lim * (page - 1))) #否则用显示数量乘以当前页数减去1 得到开始数 page_show = int(lim + page_nb) #调用数量的结尾数 page_size = [] for i in range(page_cont): page_size.append(i + 1) # print '%s%s%s%s%s%s%s%s%s%s%s%s%s%s' %('总信息数:',newcont,' 每页显示数:',lim,' 当前页:',page,' 总页数:',page_cont,' 当前显示首数:',page_nb,' 当前显示尾数:',page_show,' 分页:',page_size) previous = page - 1 if previous == 0: previous = 0 nextp = page + 1 if nextp == page_cont: nextp = page_cont # 如果没有搜索条件,直接获取列表 if title == None: title = '' if current_user.group.power == 0: #超级管理员 newslist = db_session.query(News).\ filter(News.pid == pid, News.display == display).\ group_by(News.id).limit(lim)[page_nb:page_show] if current_user.group.power == 1: #组长 newslist = db_session.query(News).\ filter(News.pid == pid, News.display == display, News.teamid == current_user.teamid).\ group_by(News.id).limit(lim)[page_nb:page_show] if current_user.group.power == 2: #组员 newslist = db_session.query(News).\ filter(News.pid == pid, News.display == display, News.teamid == current_user.teamid, News.userid == current_user.id).\ group_by(News.id).limit(lim)[page_nb:page_show] # 如果有搜索条件,计算分页,加入条件 else: if current_user.group.power == 0: #超级管理员 newcont = db_session.query(func.count(News.id)).\ filter(News.title.like("%"+title+"%"), News.pid == pid, News.display == display).scalar() #计算数据总数 if current_user.group.power == 1: #组长 newcont = db_session.query(func.count(News.id)).\ filter(News.title.like("%"+title+"%"), News.pid == pid, News.display == display, News.teamid == current_user.teamid).scalar() #计算数据总数 if current_user.group.power == 2: #组员 newcont = db_session.query(func.count(News.id)).\ filter(News.title.like("%"+title+"%"), News.pid == pid, News.display == display, News.teamid == current_user.teamid, News.userid == current_user.id).scalar() #计算数据总数 page_cont = int(math.ceil(round(float(newcont) / lim, 2))) page_size = [] for i in range(page_cont): page_size.append(i + 1) # print '%s%s%s%s%s%s%s%s%s%s%s%s%s%s' %('总信息数:',newcont,' 每页显示数:',lim,' 当前页:',page,' 总页数:',page_cont,' 当前显示首数:',page_nb,' 当前显示尾数:',page_show,' 分页:',page_size) if newcont >= lim: if current_user.group.power == 0: #超级管理员 newslist = db_session.query(News).\ filter(News.title.like("%"+title+"%"), News.pid == pid, News.display == display).\ group_by(News.id).limit(lim)[page_nb:page_show] if current_user.group.power == 1: #组长 newslist = db_session.query(News).\ filter(News.title.like("%"+title+"%"), News.pid == pid, News.display == display, News.teamid == current_user.teamid).\ group_by(News.id).limit(lim)[page_nb:page_show] if current_user.group.power == 2: #组员 newslist = db_session.query(News).\ filter(News.title.like("%"+title+"%"), News.pid == pid, News.display == display, News.teamid == current_user.teamid, News.userid == current_user.id).\ group_by(News.id).limit(lim)[page_nb:page_show] else: page_show = int(newcont + ((newcont * page) - 1)) # print newcont,page_show,page if current_user.group.power == 0: #超级管理员 newslist = db_session.query(News).\ filter(News.title.like("%"+title+"%"), News.pid == pid, News.display == display).\ group_by(News.id).limit(lim)[0:page_show] if current_user.group.power == 1: #组长 newslist = db_session.query(News).\ filter(News.title.like("%"+title+"%"), News.pid == pid, News.display == display, News.teamid == current_user.teamid).\ group_by(News.id).limit(lim)[0:page_show] if current_user.group.power == 2: #组员 newslist = db_session.query(News).\ filter(News.title.like("%"+title+"%"), News.pid == pid, News.display == display, News.teamid == current_user.teamid, News.userid == current_user.id).\ group_by(News.id).limit(lim)[0:page_show] return render_template("manage_news.html", pagename=tsActive, pid=pid, newslist=newslist, page=page_size, previous=previous, nextp=nextp, page_cont=page_cont, title=title, newcont=newcont) db_session.close()
def manage_order(order_type, state=0): if order_type == None: order_type = 0 tsActive = 'manage_order' if order_type == 0: tsActive = 'manage_order' else: tsActive = 'manage_jdorder' ordernb = request.args.get('ordernb') # print title # 分页开始 lim = int(8) #get到每页显示数量 page = int(request.args.get('page', 1)) #get到页数 # 权限判断 if current_user.group.power == 0: #超级管理员 newcont = db_session.query(func.count(Order.id)).\ filter(Order.order_type == order_type, Order.state == state).scalar() #计算数据总数 if current_user.group.power <= 2 and current_user.group.power > 0: #组长 newcont = db_session.query(func.count(Order.id)).\ filter(Order.order_type == order_type, Order.state == state, Order.teamid == current_user.teamid).scalar() #计算数据总数 if newcont == None: newcont = 0 page_cont = int(math.ceil(round(float(newcont) / lim, 2))) #总数除以显示数量得到分页总数 if page == 1: page_nb = 0 #如果第一页则从第0条数据开始调用 page_show = int(lim + page_nb) #调用数量的结尾数 else: page_nb = int((lim * (page - 1))) #否则用显示数量乘以当前页数减去1 得到开始数 page_show = int(lim + page_nb) #调用数量的结尾数 page_size = [] for i in range(page_cont): page_size.append(i + 1) # print '%s%s%s%s%s%s%s%s%s%s%s%s%s%s' %('总信息数:',newcont,' 每页显示数:',lim,' 当前页:',page,' 总页数:',page_cont,' 当前显示首数:',page_nb,' 当前显示尾数:',page_show,' 分页:',page_size) previous = page - 1 if previous == 0: previous = 0 nextp = page + 1 if nextp == page_cont: nextp = page_cont # 如果没有搜索条件,直接获取列表 if ordernb == None: ordernb = '' if current_user.group.power == 0: orderlist = db_session.query(Order).\ filter(Order.order_type == order_type, Order.state == state).\ order_by(Order.addtime.desc()).limit(lim)[page_nb:page_show] if current_user.group.power <= 2 and current_user.group.power > 0: orderlist = db_session.query(Order).\ filter(Order.order_type == order_type, Order.state == state, Order.teamid == current_user.teamid).\ order_by(Order.addtime.desc()).limit(lim)[page_nb:page_show] # 如果有搜索条件,计算分页,加入条件 else: if current_user.group.power == 0: #超级管理员 newcont = db_session.query(func.count(Order.id)).\ filter(Order.number == ordernb, Order.state == state, Order.order_type == order_type).scalar() #计算数据总数 if current_user.group.power <= 2 and current_user.group.power > 0: #组长 newcont = db_session.query(func.count(Order.id)).\ filter(Order.number == ordernb, Order.state == state, Order.order_type == order_type, Order.teamid == current_user.teamid).scalar() #计算数据总数 page_cont = int(math.ceil(round(float(newcont) / lim, 2))) page_size = [] for i in range(page_cont): page_size.append(i + 1) if newcont >= lim: if current_user.group.power == 0: #超级管理员 orderlist = db_session.query(Order).\ filter(Order.number == ordernb, Order.state == state, Order.order_type == order_type).\ order_by(Order.addtime.desc()).limit(lim)[page_nb:page_show] if current_user.group.power <= 2 and current_user.group.power > 0: orderlist = db_session.query(Order).\ filter(Order.number == ordernb, Order.state == state, Order.order_type == order_type, Order.teamid == current_user.teamid).\ order_by(Order.addtime.desc()).limit(lim)[page_nb:page_show] else: page_show = int(newcont + ((newcont * page) - 1)) # print newcont,page_show,page if current_user.group.power == 0: #超级管理员 orderlist = db_session.query(Order).\ filter(Order.number == ordernb, Order.state == state, Order.order_type == order_type).\ order_by(Order.addtime.desc()).limit(lim)[0:page_show] if current_user.group.power <= 2 and current_user.group.power > 0: orderlist = db_session.query(Order).\ filter(Order.number == ordernb, Order.state == state, Order.order_type == order_type, Order.teamid == current_user.teamid).\ order_by(Order.addtime.desc()).limit(lim)[0:page_show] return render_template("manage_order.html", pagename=tsActive, order_type=order_type, orderlist=orderlist, page=page_size, previous=previous, nextp=nextp, page_cont=page_cont, ordernb=ordernb, newcont=newcont, state=state)
def gethors(what, startime, endtime): today = {} pro = [] diao = [] hours = [] firsttime = datetime.datetime.today() lasttime = datetime.datetime.today() if what == 'today': todays = datetime.datetime.today() NOW = datetime.datetime(todays.year, todays.month, todays.day, 23, 59, 59) for i in range(24): hours.append('%s%s' % (i, '点')) procont = db_session.query(func.count(Order.id)).\ filter(Order.addtime.between(NOW - datetime.timedelta(seconds=i*3600-1), NOW - datetime.timedelta(hours=i-1))).\ filter(Order.order_type==0).scalar() pro.append(procont) # print NOW - datetime.timedelta(seconds=i*3600 - 1),NOW - datetime.timedelta(hours=i - 1) diaocont = db_session.query(func.count(Order.id)).\ filter(Order.addtime.between(NOW - datetime.timedelta(seconds=i*3600-1), NOW - datetime.timedelta(hours=i-1))).\ filter(Order.order_type==1).scalar() diao.append(diaocont) today['pro'] = pro[::-1] today['diao'] = diao[::-1] firsttime = datetime.datetime(todays.year, todays.month, todays.day, 0, 0, 0) lasttime = datetime.datetime(todays.year, todays.month, todays.day, 23, 59, 59) if what == 'week': now = datetime.datetime.now() firsttime = now - datetime.timedelta(days=now.weekday()) firsttime = datetime.datetime(firsttime.year, firsttime.month, firsttime.day) lasttime = now + datetime.timedelta(days=6 - now.weekday()) lasttime = datetime.datetime(lasttime.year, lasttime.month, lasttime.day, 23, 59, 59) for i in range(1, 8, 1): procont = db_session.query(func.count(Order.id)).\ filter(and_( extract('year', Order.addtime) == firsttime.year, extract('month', Order.addtime) == firsttime.month, extract('day', Order.addtime) == firsttime.day + i )).\ filter(Order.order_type==0).scalar() pro.append(procont) diaocont = db_session.query(func.count(Order.id)).\ filter(and_( extract('year', Order.addtime) == firsttime.year, extract('month', Order.addtime) == firsttime.month, extract('day', Order.addtime) == firsttime.day + i )).\ filter(Order.order_type==1).scalar() diao.append(diaocont) if i == 1: i = '一' if i == 2: i = '二' if i == 3: i = '三' if i == 4: i = '四' if i == 5: i = '五' if i == 6: i = '六' if i == 7: i = '日' hours.append('%s%s' % ('星期', i)) today['pro'] = pro today['diao'] = diao if what == 'month': now = datetime.datetime.now() firsttime = datetime.datetime(now.year, now.month, 1) firsttime = datetime.datetime(firsttime.year, firsttime.month, firsttime.day) if now.month == 12: lasttime = datetime.datetime(now.year, 12, 31) else: lasttime = datetime.datetime(now.year, now.month + 1, 1) - datetime.timedelta(days=1) lasttime = datetime.datetime(lasttime.year, lasttime.month, lasttime.day, 23, 59, 59) lastday = lasttime.day for i in range(1, lastday + 1, 1): hours.append('%s%s' % (i, '号')) procont = db_session.query(func.count(Order.id)).\ filter(and_( extract('year', Order.addtime) == firsttime.year, extract('month', Order.addtime) == firsttime.month, extract('day', Order.addtime) == i )).\ filter(Order.order_type==0).scalar() pro.append(procont) # print NOW - datetime.timedelta(seconds=i*3600 - 1),NOW - datetime.timedelta(hours=i - 1) diaocont = db_session.query(func.count(Order.id)).\ filter(and_( extract('year', Order.addtime) == firsttime.year, extract('month', Order.addtime) == firsttime.month, extract('day', Order.addtime) == i )).\ filter(Order.order_type==1).scalar() diao.append(diaocont) today['pro'] = pro today['diao'] = diao if what == 'year': now = datetime.datetime.now() firsttime = datetime.datetime(now.year, 1, 1) firsttime = datetime.datetime(firsttime.year, firsttime.month, firsttime.day) lasttime = datetime.datetime(now.year, 12, 31) lasttime = datetime.datetime(lasttime.year, lasttime.month, lasttime.day, 23, 59, 59) # procont = db_session.query(extract('month', Order.order_type).label('month'), func.count(Order.id).label('count')).group_by('month') for i in range(1, 13, 1): hours.append('%s%s' % (i, '月')) procont = db_session.query(func.count(Order.id)).\ filter(and_( extract('year', Order.addtime) == firsttime.year, extract('month', Order.addtime) == i )).\ filter(Order.order_type==0).scalar() # procont = db_session.query(func.count(Order.id)).\ # filter(Order.addtime.between(datetime.datetime(now.year, i + 1, 1) + , datetime.datetime(now.year, i + 1, 1))).\ # filter(Order.order_type==0).scalar() pro.append(procont) # print NOW - datetime.timedelta(seconds=i*3600 - 1),NOW - datetime.timedelta(hours=i - 1) diaocont = db_session.query(func.count(Order.id)).\ filter(and_( extract('year', Order.addtime) == firsttime.year, extract('month', Order.addtime) == i )).\ filter(Order.order_type==1).scalar() diao.append(diaocont) today['pro'] = pro today['diao'] = diao if what == 'diy': firsttime = datetime.datetime.strptime(startime, '%Y-%m-%d') lasttime = datetime.datetime.strptime(endtime, '%Y-%m-%d') lasttime = datetime.datetime(lasttime.year, lasttime.month, lasttime.day, 23, 59, 59) for d in gen_dates(firsttime, (lasttime - firsttime).days + 1): hours.append('%s%s%s%s%s' % (d.year, '-', d.month, '-', d.day)) # c = lasttime - firsttime # for i in range(1,c.days + 1): procont = db_session.query(func.count(Order.id)).\ filter(and_( extract('year', Order.addtime) == d.year, extract('month', Order.addtime) == d.month, extract('day', Order.addtime) == d.day )).\ filter(Order.order_type==0).scalar() pro.append(procont) # print NOW - datetime.timedelta(seconds=i*3600 - 1),NOW - datetime.timedelta(hours=i - 1) diaocont = db_session.query(func.count(Order.id)).\ filter(and_( extract('year', Order.addtime) == d.year, extract('month', Order.addtime) == d.month, extract('day', Order.addtime) == d.day )).\ filter(Order.order_type==1).scalar() diao.append(diaocont) today['pro'] = pro today['diao'] = diao ''' firsttime 当日0点 lasttime 当日23点 获取当日商品订单金额情况 ''' # print firsttime,lasttime daif = db_session.query(Order).\ filter(Order.order_type == 0).\ filter(Order.state == 0).\ filter(Order.addtime.between(firsttime,lasttime)).all() firstmoney = db_session.query(OrderState).\ filter(OrderState.orderid == Order.id).\ filter(Order.order_type == 0).\ filter(OrderState.state == 1).\ filter(OrderState.uptime.between(firsttime,lasttime)).all() centermoney = db_session.query(OrderState).\ filter(OrderState.orderid == Order.id).\ filter(Order.order_type == 0).\ filter(OrderState.state == 8).\ filter(OrderState.uptime.between(firsttime,lasttime)).all() lastmoney = db_session.query(OrderState).\ filter(OrderState.orderid == Order.id).\ filter(Order.order_type == 0).\ filter(OrderState.state == 13).\ filter(OrderState.uptime.between(firsttime,lasttime)).all() # print firstmoney daiflen = 0 firstmoneylen = 0 centermoneylen = 0 lastmoneylen = 0 if daif: x = 0 for x in daif: daiflen += int(x.order_total) if firstmoney: # print firstmoney x = 0 for x in firstmoney: firstmoneylen += int(x.text) if centermoney: x = 0 for x in centermoney: centermoneylen += int(x.text) if lastmoney: x = 0 for x in lastmoney: lastmoneylen += int(x.text) ''' 获取当日借调订单金额 ''' diaomoneyed = db_session.query(Order).\ filter(Order.id == OrderState.orderid).\ filter(Order.order_type == 1).\ filter(OrderState.uptime.between(firsttime,lasttime)).all() diaomed = 0 if diaomoneyed: x = 0 for x in diaomoneyed: diaomed += int(x.order_total) diaomoney = db_session.query(Order).\ filter(Order.id != OrderState.orderid).\ filter(Order.order_type == 1).\ filter(Order.addtime.between(firsttime,lasttime)).all() diaom = 0 if diaomoney: x = 0 for x in diaomoney: diaom += int(x.order_total) today['hours'] = hours today['money'] = { 'dai': daiflen, 'dailen': len(daif), 'first': firstmoneylen, 'firstlen': len(firstmoney), 'center': centermoneylen, 'centerlen': len(centermoney), 'last': lastmoneylen, 'lastlen': len(lastmoney) } today['diao_money'] = { 'daidiao': diaom, 'diaoed': diaomed, 'daidiaolen': len(diaomoney), 'diaoedlen': len(diaomoneyed) } return today
def manage_guestbook(status): # 分页开始 lim = int(8) #get到每页显示数量 page = int(request.args.get('page', 1)) #get到页数 if current_user.group.power == 0: #超级管理员 newcont = db_session.query(func.count(Guestbook.id)).\ join(Users).\ join(MuGb).\ filter(Guestbook.id == MuGb.bookid).\ filter(MuGb.manageid == current_user.id).\ filter(MuGb.status == status).\ scalar() #计算数据总数 else: newcont = db_session.query(func.count(Guestbook.id)).\ join(Users).\ join(MuGb).\ filter(current_user.id == MuGb.manageid).\ filter(MuGb.status == status).\ filter(Guestbook.id == MuGb.bookid).\ filter(Users.teamid == current_user.teamid).\ scalar() #计算数据总数 if newcont == None: newcont = 0 page_cont = int(math.ceil(round(float(newcont) / lim, 2))) #总数除以显示数量得到分页总数 if page == 1: page_nb = 0 #如果第一页则从第0条数据开始调用 page_show = int(lim + page_nb) #调用数量的结尾数 else: page_nb = int((lim * (page - 1))) #否则用显示数量乘以当前页数减去1 得到开始数 page_show = int(lim + page_nb) #调用数量的结尾数 page_size = [] for i in range(page_cont): page_size.append(i + 1) # print '%s%s%s%s%s%s%s%s%s%s%s%s%s%s' %('总信息数:',newcont,' 每页显示数:',lim,' 当前页:',page,' 总页数:',page_cont,' 当前显示首数:',page_nb,' 当前显示尾数:',page_show,' 分页:',page_size) previous = page - 1 if previous == 0: previous = 0 nextp = page + 1 if nextp == page_cont: nextp = page_cont if current_user.group.power == 0: #超级管理员 guest = db_session.query(Guestbook).\ join(Users).\ join(MuGb).\ filter(Guestbook.id == MuGb.bookid).\ filter(MuGb.manageid == current_user.id).\ filter(MuGb.status == status).\ order_by(Guestbook.addtime.desc()).\ limit(lim)[page_nb:page_show] else: guest = db_session.query(Guestbook).\ join(Users).\ join(MuGb).\ filter(MuGb.status == status).\ filter(current_user.id == MuGb.manageid).\ filter(Guestbook.id == MuGb.bookid).\ filter(Users.teamid == current_user.teamid).\ order_by(Guestbook.addtime.desc()).\ limit(lim)[page_nb:page_show] return render_template("manage_guestbook.html", pagename='manage_guestbook', booklist=guest, stat=status, page=page_size, previous=previous, nextp=nextp, page_cont=page_cont, newcont=newcont)
def manage_booknb(userid): thisnb = db_session.query(func.count(MuGb.id)).filter(MuGb.manageid == userid,MuGb.status == 0).\ scalar() return jsonify({'cont': thisnb})
def manage_customers(page=1): search = request.args.get('search') verify = int(request.args.get('verify', 1)) status = int(request.args.get('status', 0)) if verify == 1 or verify == 2: tsActive = 'reg_customers' elif verify == 0: tsActive = 'manage_customers' # 工作组列表 teamlist = Team.query.all() # 分页开始 lim = int(30) #get到每页显示数量 page = int(request.args.get('page', 1)) #get到页数 if current_user.group.power == 0: #超级管理员 newcont = db_session.query(func.count(Users.id)).filter( Users.verify == verify, Users.lock == status).scalar() #计算数据总数 else: newcont = db_session.query(func.count(Users.id)).filter( Users.verify == verify, Users.lock == status, Users.teamid == current_user.teamid).scalar() #计算数据总数 if newcont == None: newcont = 0 page_cont = int(math.ceil(round(float(newcont) / lim, 2))) #总数除以显示数量得到分页总数 if page == 1: page_nb = 0 #如果第一页则从第0条数据开始调用 page_show = int(lim + page_nb) #调用数量的结尾数 else: page_nb = int((lim * (page - 1))) #否则用显示数量乘以当前页数减去1 得到开始数 page_show = int(lim + page_nb) #调用数量的结尾数 page_size = [] for i in range(page_cont): page_size.append(i + 1) # print '%s%s%s%s%s%s%s%s%s%s%s%s%s%s' %('总信息数:',newcont,' 每页显示数:',lim,' 当前页:',page,' 总页数:',page_cont,' 当前显示首数:',page_nb,' 当前显示尾数:',page_show,' 分页:',page_size) previous = page - 1 if previous == 0: previous = 0 nextp = page + 1 if nextp == page_cont: nextp = page_cont # 如果没有搜索条件,直接获取列表 if search == None: search = '' if current_user.group.power == 0: #超级管理员 userlist = Users.query.\ filter(Users.verify == verify, Users.lock == status).\ group_by(Users.id).limit(lim)[page_nb:page_show] else: userlist = Users.query.\ filter(Users.verify == verify, Users.lock == status, Users.teamid == current_user.teamid).\ group_by(Users.id).limit(lim)[page_nb:page_show] # 如果有搜索条件,计算分页,加入条件 else: if current_user.group.power == 0: #超级管理员 newcont = db_session.query(func.count(Users.id)).\ filter(or_(Users.phone.like("%"+search+"%"), Users.company.like("%"+search+"%"), Users.truename.like("%"+search+"%")), Users.verify == verify, Users.lock == status).scalar() #计算数据总数 else: newcont = db_session.query(func.count(Users.id)).\ filter(or_(Users.phone.like("%"+search+"%"), Users.company.like("%"+search+"%"), Users.truename.like("%"+search+"%")), Users.verify == verify, Users.lock == status, Users.teamid == current_user.teamid).scalar() #计算数据总数 page_cont = int(math.ceil(round(float(newcont) / lim, 2))) page_size = [] for i in range(page_cont): page_size.append(i + 1) if newcont >= lim: if current_user.group.power == 0: #超级管理员 userlist = Users.query.\ filter(or_(Users.phone.like("%"+search+"%"), Users.company.like("%"+search+"%"), Users.truename.like("%"+search+"%")), Users.verify == verify, Users.lock == status).\ group_by(Users.id).limit(lim)[page_nb:page_show] else: userlist = Users.query.\ filter(or_(Users.phone.like("%"+search+"%"), Users.company.like("%"+search+"%"), Users.truename.like("%"+search+"%")), Users.verify == verify, Users.lock == status, Users.teamid == current_user.teamid).\ group_by(Users.id).limit(lim)[page_nb:page_show] else: page_show = int(newcont + ((newcont * page) - 1)) # print newcont,page_show,page if current_user.group.power == 0: #超级管理员 userlist = Users.query.\ filter(or_(Users.phone.like("%"+search+"%"), Users.company.like("%"+search+"%"), Users.truename.like("%"+search+"%")), Users.verify == verify, Users.lock == status).\ group_by(Users.id).limit(lim)[0:page_show] else: userlist = Users.query.\ filter(or_(Users.phone.like("%"+search+"%"), Users.company.like("%"+search+"%"), Users.truename.like("%"+search+"%")), Users.verify == verify, Users.lock == status, Users.teamid == current_user.teamid).\ group_by(Users.id).limit(lim)[0:page_show] return render_template("manage_customers.html", pagename=tsActive, userlist=userlist, page=page_size, previous=previous, nextp=nextp, page_cont=page_cont, search=search, verify=verify, teamlist=teamlist, newcont=newcont)