def theCatAllGoods(): catId = int(request.args.get('catId')) allGoods = searchGoodsId(catId) if len(allGoods) == 0: return jsonify(StatusCode=400) else: return jsonify(StatusCode=200, allGoods=allGoods)
def expenditureOfTimeAndCat(): info = request.get_json() startTime = info.get('startTime') endTime = info.get('endTime') catId = info.get('catId') allGoodsId = searchGoodsId(catId) cost = expenditureInPeriod(startTime, endTime, allGoodsId) return jsonify(expenditure=cost)
def goodsPurchaseAmountInPeriod(): info = request.get_json() catId = info.get('catId') start_time = info.get('start_time') end_time = info.get('end_time') goodsId = searchGoodsId(catId) purchaseAmountList = [] for goodId in goodsId: purchaseAmountInPeriod.append(dict(name=goodIdToName(goodId), value=goodPurchaseAmountInPeriod(goodId, start_time, end_time))) return jsonify(purchaseAmountList=purchaseAmountList)
def revenueOfDivideTime(): # 解析请求中的数据 info = request.get_json() startTime = datetime.datetime.strptime(info.get('startTime'), '%Y-%m-%d %H:%M:%S') endTime = datetime.datetime.strptime(info.get('endTime'), '%Y-%m-%d %H:%M:%S') unit = info.get('unit') timeLength = info.get('timeLength') catId = info.get('catId') # 初始化时间划分的长度单位 delta = [] if unit == "year": delta = relativedelta(years=+timeLength) elif unit == "month": delta = relativedelta(months=+timeLength) elif unit == "day": delta = datetime.timedelta(days=timeLength) elif unit == "hour": delta = datetime.timedelta(hours=timeLength) allGoodsId = searchGoodsId(catId) #获得分类下的商品列表 # 初始化循环所叙述句 current_start = startTime current_end = startTime + delta results = [] while current_start < endTime: # 判断边界时间 if current_end > endTime: current_end = endTime # 定义保存一段时间数据的字典 aPeriod = dict() aPeriod['startTime'] = current_start.strftime('%Y-%m-%d %H:%M:%S') aPeriod['endTime'] = current_end.strftime('%Y-%m-%d %H:%M:%S') # 获取该时间段的支出 aPeriod['revenue'] = revenueInPeriod(current_start, current_end, allGoodsId) results.append(aPeriod) #改变循环条件 current_start += delta current_end = current_start + delta return jsonify(results=results)
def topCatsSaleCount(): Cats = topCats() data = [] now_time = datetime.datetime.now() delta = relativedelta(months=+1) for topCat in Cats: tmpDict = dict(catId=topCat['id'], name=topCat['name'], data=[]) goods = searchGoodsId(topCat['id']) date_time = now_time for i in range(6): tmpMonth = dict( start_time=date_time.strftime('%Y-%m-%d %H:%M:%S'), end_time=(date_time - delta).strftime('%Y-%m-%d %H:%M:%S'), count=goodsCountInPeriod(goods, date_time - delta, date_time)) tmpDict['data'].append(tmpMonth) date_time -= delta data.append(tmpDict) return jsonify(data=data)
def catPurchaseOrders(): catId = request.args.get('catId') goodsId = searchGoodsId(catId) orders = selectlimitOrders(goodsId) return jsonify(orders=orders)
def amountOFTheCat(): catId = request.args.get('catId') goodsId = searchGoodsId(catId) amount = amountOfGoods(goodsId) return jsonify(amount=amount)