def BuildWorkhourOfArea(self, user, region=None, province=None, city=None, school=None): areas_with_schools = yield BuildAreaData().BuildAreasWithSchools(user) choosed = { 'region': region, 'province': province, 'city': city, 'school': school } if not choosed['school']: choosed = self._GetFirstSchool(areas_with_schools) workhours = yield self._BuildWorkhourOfSchool(choosed) data = { 'working_hours': workhours, 'areas': { 'full': json.dumps(areas_with_schools), 'choosed': json.dumps({ 'area': choosed.get('region', ''), 'province': choosed.get('province', ''), 'city': choosed.get('city', ''), 'campus': choosed.get('school', '') }) } } raise gen.Return(data)
def BuildUserDetail(self, current_user, detail_user): roles = yield BuildRoleData().BuildRoleCandidatesList() for r in roles: if r['arg_name'] in detail_user['roles']: r['checked'] = True area_full = yield BuildAreaData().BuildAreasWithSchools(current_user) data = { 'member': { 'name': detail_user['name'], 'realname': detail_user.get('realname', ''), 'status': ConvertText().UserStatusToChinese(detail_user['status']), '_id': detail_user['_id'], 'mobile': detail_user.get('mobile', ''), 'note': detail_user.get('note', '') }, 'roles': [ { 'display_name': u'候选角色', 'sub_roles': roles } ], 'areas': { 'full': json.dumps(area_full), 'choosed': json.dumps( { 'area': detail_user.get('region', ''), 'province': detail_user.get('province', ''), 'city': detail_user.get('city', ''), 'campus': detail_user.get('school_name', '') } ) } } raise gen.Return(data)
def BuildBuildingsOfArea(self, user, region=None, province=None, city=None, school=None): areas_with_schools = yield BuildAreaData().BuildAreasWithSchools(user) choosed = { 'region': region, 'province': province, 'city': city, 'school': school } if not choosed['school']: choosed = self._GetFirstSchool(areas_with_schools) school = yield self.school_model.GetSchoolFromName(choosed['school']) buildings = yield self.building_model.GetSchoolBuildings(school['_id']) data = { 'building_dispatch': True if 'building' in school.get('dispatch_strategy',[]) else False, 'school_id': school['_id'], 'buildings': [ { 'name': b['name'], 'arg_name': b['_id'] } for b in buildings ], 'areas': { 'full': json.dumps(areas_with_schools), 'choosed': json.dumps( { 'area': choosed.get('region', ''), 'province': choosed.get('province', ''), 'city': choosed.get('city', ''), 'campus': choosed.get('school', '') } ) } } raise gen.Return(data)
def BuildTableFrame(self, **kw): area_full = yield BuildAreaData().BuildAreas(kw['user']) data = { 'area_full': json.dumps(area_full), 'extra_btns': [{ 'text': u'添加校区', 'href': '/campus_add' }], 'table_src': 'campus_list' } raise gen.Return(data)
def BuildTableFrame(self, **kw): areas_with_schools = yield BuildAreaData().BuildAreasWithSchools( kw['user']) data = { 'filters': { 'types': { 'name': u'姓名', 'id': u'提现ID' }, 'status': { 'processed': u'已处理', 'unprocessed': u'未处理', } }, 'table_src': 'withdraw_list', 'area_full': json.dumps(areas_with_schools) } raise gen.Return(data)
def BuildTableFrame(self, **kw): areas_with_schools = yield BuildAreaData().BuildAreasWithSchools(kw['user']) data = { 'filters': { 'types': { 'task_id': u'任务ID', 'courier_name': u'速递员姓名', 'courier_mobile': u'速递员手机号', 'courier_id': u'速递员ID' }, 'status':{ 'waiting': u'等待分配', 'dispatched': u'已分配', 'processing': u'正在配送', 'done': u'已完成' } }, 'table_src': 'task_list', 'area_full': json.dumps(areas_with_schools) } raise gen.Return(data)
def BuildTableFrame(self, **kw): areas_with_schools = yield BuildAreaData().BuildAreasWithSchools( kw['user']) data = { 'filters': { 'types': { 'courier_name': u'速递员姓名', 'courier_mobile': u'速递员手机号' }, 'status': { 'unsubmitted': u'未提交资料', 'verifying': u'审核中', 'failed': u'审核失败', 'verified': u'已审核', 'locked': u'锁定', } }, 'table_src': 'courier_list', 'area_full': json.dumps(areas_with_schools) } raise gen.Return(data)
def BuildTableFrame(self, **kw): areas_with_schools = yield BuildAreaData().BuildAreasWithSchools( kw['user']) data = { 'filters': { 'types': { 'name': u'姓名', 'id': u'提现ID' }, 'status': { 'processed': u'已处理', 'unprocessed': u'未处理', } }, 'extra_btns': [{ 'text': u'生成表格', 'href': '/expenses_export' }], 'table_src': 'expenses_list', 'area_full': json.dumps(areas_with_schools) } raise gen.Return(data)
def BuildTableFrame(self, **kw): areas_with_schools = yield BuildAreaData().BuildAreasWithSchools( kw['user']) data = { 'filters': { 'types': { 'type': u'类型', 'campus': u'归属校区' }, 'status': { 'open': u'营业中', 'closed': u'休息中', 'out': u'已关闭' } }, 'extra_btns': [{ 'text': u'添加店铺', 'href': '/shop_add' }], 'table_src': 'shop_list', 'area_full': json.dumps(areas_with_schools) } raise gen.Return(data)
def BuildTableFrame(self, **kw): areas_with_schools = yield BuildAreaData().BuildAreasWithSchools(kw['user']) data = { 'filters': { 'types': { 'name': u'帐号名', 'realname': u'真实姓名', 'mobile': u'手机号' }, 'status':{ 'normal': u'正常', 'locked': u'锁定', } }, 'extra_btns': [ { 'text': u'添加用户', 'href': '/member_add' } ], 'table_src': 'member_list', 'area_full': json.dumps(areas_with_schools) } raise gen.Return(data)
def BuildUserStatisticsOfRegion(self, user, region, province, city, school_name, page=1): areas_with_schools = yield BuildAreaData().BuildAreasWithSchools(user) PAGE_SIZE = 20 page = page - 1 skip = page * PAGE_SIZE limit = PAGE_SIZE if school_name != u'全部校区': school = yield self.school_model.GetSchoolFromName(school_name) condition = {'school_id': school['_id']} else: condition = { 'region': region, 'province': province, 'city': city, 'school_name': school_name } sort_condition = [('date', -1)] query = self.user_statistics.find(condition) record_count = yield query.count() records = yield query.sort(sort_condition).limit(limit).skip( skip).to_list(None) dates = [] counts = [] series_counts = [] for r in records: dates.append(r['date'][4:].encode('utf8')) series_counts.append(r['new_users']) counts.append([{ 'type': 'text', 'value': r['date'] }, { 'type': 'text', 'value': r['new_users'] }, { 'type': 'text', 'value': r['total_users'] }]) data = { 'title': '用户', 'page': page + 1, # 当前页数 'count': record_count, # 表格数据总条数 'limit': PAGE_SIZE, # 数据一页的最大条数 'thead': ['日期', '新增用户', '累计用户'], 'tdatas': counts, 'series': [{ 'name': '新增用户', 'type': 'line', 'data': list(reversed(series_counts)), 'feature': { 'max': False, # 自动计算最大值 'min': False, # 自动计算最小值 'avg': False # 自动计算平均值 } }], 'legend': ['Yong Hu'], # 图例文字 'xAxis': list(reversed(dates)), # 横坐标轴文字,显示年份20个放不下,显示月-日可以 'areas': { 'full': json.dumps(areas_with_schools), 'choosed': json.dumps({ 'area': region, 'province': province, 'city': city, 'campus': school_name }) } } raise gen.Return(data)
def BuildCourierDeatil(self, courier, current_user): week_date_start = self.GetWeekStartDate('this') week_date_end = week_date_start + datetime.timedelta(days=7) week_timestamp_start = int(time.mktime(week_date_start.timetuple())) week_timestamp_end = int(time.mktime(week_date_end.timetuple())) schedules = yield self.schedule_model.GetCourierSchedulesInInterval( courier['_id'], week_timestamp_start, week_timestamp_end) sched_result = { '6:00-12:00': [0, 0, 0, 0, 0, 0, 0], '12:00-18:00': [0, 0, 0, 0, 0, 0, 0], '18:00-24:00': [0, 0, 0, 0, 0, 0, 0] } for sched in schedules: start = sched['start'] sched_datetime = datetime.datetime.fromtimestamp(start) weekday = sched_datetime.weekday() time_index = self.HourToIntervalIndex(sched_datetime.hour) if time_index == 0: sched_result['6:00-12:00'][weekday] = 1 elif time_index == 1: sched_result['12:00-18:00'][weekday] = 1 elif time_index == 2: sched_result['18:00-24:00'][weekday] = 1 data = { 'courier': { 'name': courier.get('name', ''), 'status': courier['status'], 'status_text': ConvertText().CourierStatusToChinese(courier['status']), '_id': courier['_id'], 'school': courier.get('school', ''), 'mobile': courier.get('mobile', ''), 'birthday': courier.get('birthday', ''), 'edu_start_year': courier.get('graduate_year', ''), 'QQ': courier.get('qq', ''), 'created_time': ConvertText().TimestampToText(courier.get('created_time', 0)), 'balance': courier.get('balance', 0) / 100.0, 'position': courier.get('location', [0, 0]) }, 'working_hours': sched_result } photo_id = courier.get('certificate_image', None) if photo_id: data['courier'][ 'photo'] = 'http://cdn.statics.kuaikuaiyu.com/image/' + str( photo_id) + '.jpg' else: data['courier']['photo'] = '' area_full = yield BuildAreaData().BuildAreasWithSchools(current_user) school = yield self.school_model.GetSchoolFromId( courier['district_id']) data_areas = { 'full': json.dumps(area_full), 'choosed': json.dumps({ 'area': school.get('region', ''), 'province': school.get('province', ''), 'city': school.get('city', ''), 'campus': school.get('name', '') }) } data['areas'] = data_areas raise gen.Return(data)
def BuildOrderStatisticsOfRegion(self, user, region, province, city, school_name, page=1): areas_with_schools = yield BuildAreaData().BuildAreasWithSchools(user) PAGE_SIZE = 20 page = page - 1 skip = page * PAGE_SIZE limit = PAGE_SIZE if school_name != u'全部校区': school = yield self.school_model.GetSchoolFromName(school_name) condition = {'school_id': school['_id']} else: condition = { 'region': region, 'province': province, 'city': city, 'school_name': school_name } sort_condition = [('date', -1)] query = self.order_statistics.find(condition) record_count = yield query.count() order_records = yield query.sort(sort_condition).limit(limit).skip( skip).to_list(None) order_date = [] order_count = [] paid_order_count = [] for o in order_records: order_date.append(o['date'][4:].encode('utf8')) paid_order_count.append(CountOrderStatus(PAID_ORDER_STATUS, o)) order_count.append([{ 'type': 'text', 'value': o['date'] }, { 'type': 'text', 'value': CountOrderStatus(REQUEST_ORDER_STATUS, o) }, { 'type': 'text', 'value': CountOrderStatus(PAID_ORDER_STATUS, o) }, { 'type': 'text', 'value': CountOrderStatus(SCHEDULED_ORDER_STATUS, o) }, { 'type': 'text', 'value': CountOrderStatus(DONE_ORDER_STATUS, o) }, { 'type': 'price', 'value': o.get('item_price', 0) / 100.0 }]) data = { 'title': '订单统计', 'page': page + 1, # 当前页数 'count': record_count, # 表格数据总条数 'limit': PAGE_SIZE, # 数据一页的最大条数 'thead': ['日期', '请求订单', '支付订单', '调度订单', '完成订单', '销售额'], 'tdatas': order_count, 'series': [{ 'name': '支付单量', 'type': 'line', 'data': list(reversed(paid_order_count)), 'feature': { 'max': False, # 自动计算最大值 'min': False, # 自动计算最小值 'avg': False # 自动计算平均值 } }], 'legend': ['Ding Dan'], # 图例文字 'xAxis': list(reversed(order_date)), # 横坐标轴文字,显示年份20个放不下,显示月-日可以 'areas': { 'full': json.dumps(areas_with_schools), 'choosed': json.dumps({ 'area': region, 'province': province, 'city': city, 'campus': school_name }) } } raise gen.Return(data)