class ShopScoreHandler(AccessHandler): def initialize(self): self.shopDao = ShopDao() def post(self, *args, **kwargs): shopId = self.get_args("shop_id") scores = self.shopDao.get_comments_vary_by_shop_id(shopId) xDate=[] ##描述 shop_desc = [] ##服务 shop_service = [] ##物流 shop_logis = [] slist = list(scores) length = slist.__len__() if length > 0 and length <= 1: slist.append(slist[0]) xDate.append(slist[0][0]) xDate.append(slist[0][0]) shop_desc.append(slist[0][1]) shop_desc.append(slist[0][1]) shop_service.append(slist[0][2]) shop_service.append(slist[0][2]) shop_logis.append(slist[0][3]) shop_logis.append(slist[0][3]) elif length > 6: xDate.append(slist[length - 1][0]) shop_desc.append(slist[length - 1][1]) shop_service.append(slist[length - 1][2]) shop_logis.append(slist[length - 1][3]) data_list = slist data_list = data_list.pop(length - 1) data_list = data_list.pop(0) data_list = random.sample(data_list, 4) data_list.sort() for index in range(len(data_list)): xDate.append(slist[index][0]) shop_desc.append(slist[index][1]) shop_service.append(slist[index][2]) shop_logis.append(slist[index][3]) xDate.append(slist[0][0]) shop_desc.append(slist[0][1]) shop_service.append(slist[0][2]) shop_logis.append(slist[0][3]) else: for index in range(len(slist)): xDate.append(slist[index][0]) shop_desc.append(slist[index][1]) shop_service.append(slist[index][2]) shop_logis.append(slist[index][3]) result = {} result["status"] = 0 result["message"] = "获取数据成功" result["xDate"] = xDate result["shop_desc"] = shop_desc result["shop_service"] = shop_service result["shop_logis"] = shop_logis self.finish(result)
class TaskRankHandler(AccessHandler): def initialize(self): self.taskDao = TaskDao() self.shopDao = ShopDao() self.productDao = ProductDao() def post(self, *args, **kwargs): taskId = self.get_args("task_id") salesRank = self.shopDao.get_sales_ranking_by_task_id(taskId) salesRank = list_to_json(salesRank) commentsRank = self.shopDao.get_comments_by_task_id(taskId) commentsRank = list_to_json(commentsRank) levelRank = self.shopDao.get_shop_level_by_task_id(taskId) levelRank = list_to_json(levelRank) result = {} result["status"] = 0 result["message"] = "更新成功" result["sales"] = salesRank result["comment"] = commentsRank result["level"] = levelRank self.finish(result)
class ShopDetailsHandler(AccessHandler): def initialize(self): self.shopDao = ShopDao() def post(self, *args, **kwargs): shopId = self.get_args("shop_id") shop = self.shopDao.select_shop_last_data_by_id(shopId) shop = model_object_to_json(shop) result = {} result["status"] = 0 result["message"] = "获取数据成功" result["shop"] = shop self.finish(result)
class ShopListHandler(AccessHandler): def initialize(self): self.shopDao = ShopDao() def post(self, *args, **kwargs): shopName = self.get_args("shopName") shopArea = self.get_args("shopArea") shopType = self.get_args("shopType") shopMark = self.get_args("shopMark") minLevel = self.get_args("minLevel") maxLevel = self.get_args("maxLevel") page = self.get_args("page") pageSize = self.get_args("pageSize") taskId = self.get_args("taskId") if page is not None: page = int(page) else: page = 1 if pageSize is not None: pageSize = int(pageSize) else: pageSize = 20 shopList = self.shopDao.select_shop_list(page, pageSize, shopName, shopArea, shopType, shopMark, minLevel, maxLevel, taskId) shopCount = self.shopDao.select_shop_list_count(shopName, shopArea, shopType, shopMark, minLevel, maxLevel, taskId) shopList = shop_list_with_data_to_dict(shopList) pagination = {} pagination["current_page"] = page pagination["size"] = shopCount[0] lastPage = (shopCount[0] + pageSize - 1) / pageSize; pagination["last_page"] = lastPage pagination["pageSize"] = pageSize result = {} result["status"] = 0 result["message"] = "获取数据成功" result["shops"] = shopList result["pagination"] = pagination self.finish(result)
class IndexDataHandler(AccessHandler): def initialize(self): self.productDao = ProductDao() self.shopDao = ShopDao() self.taskDao = TaskDao() def post(self): productData = self.productDao.get_all_product() shopData = self.shopDao.select_all_shop_count() taskData = self.taskDao.get_all_task_count() result = {} result["status"] = 0 result["message"] = "获取数据成功" result["productData"] = productData result["shopData"] = shopData result["taskData"] = taskData self.finish(result)
class TaskDataHandler(AccessHandler): def initialize(self): self.taskDao = TaskDao() self.shopDao = ShopDao() self.productDao = ProductDao() def post(self, *args, **kwargs): taskId = self.get_args("task_id") shopCount = self.shopDao.select_all_shop_by_task_id(taskId) productCount = self.productDao.get_all_products_by_taskid(taskId) productSales = self.productDao.get_sales_count_by_taskid(taskId) productMidPrice = self.productDao.get_mid_price_by_taskid(taskId) result = {} result["status"] = 0 result["message"] = "更新成功" result["shopCount"] = shopCount result["productCount"] = productCount result["sales"] = productSales result["midPrice"] = productMidPrice self.finish(result)
def initialize(self): self.shopDao = ShopDao()
class ShopServiceHandler(AccessHandler): def initialize(self): self.shopDao = ShopDao() def post(self, *args, **kwargs): shopId = self.get_args("shop_id") service = self.shopDao.get_service_vary_by_shop_id(shopId) ##时间 xDate = [] ##退款 tuikuan = [] ##自主结算 auto_end = [] ##纠纷率 dispute = [] ##处罚率 punish = [] slist = list(service) length = slist.__len__() if length > 0 and length <= 1: slist.append(slist[0]) xDate.append(slist[0][0]) xDate.append(slist[0][0]) tuikuan.append(slist[0][1]) tuikuan.append(slist[0][1]) auto_end.append(slist[0][2]) auto_end.append(slist[0][2]) dispute.append(slist[0][3]) dispute.append(slist[0][3]) punish.append(slist[0][4]) punish.append(slist[0][4]) elif length > 6: xDate.append(slist[length - 1][0]) tuikuan.append(slist[length - 1][1]) auto_end.append(slist[length - 1][2]) dispute.append(slist[length - 1][3]) punish.append(slist[length - 1][4]) data_list = slist data_list = data_list.pop(length - 1) data_list = data_list.pop(0) data_list = random.sample(data_list, 4) data_list.sort() for index in range(len(data_list)): xDate.append(slist[index][0]) tuikuan.append(slist[index][1]) auto_end.append(slist[index][2]) dispute.append(slist[index][3]) punish.append(slist[index][4]) xDate.append(slist[0][0]) tuikuan.append(slist[0][1]) auto_end.append(slist[0][2]) dispute.append(slist[0][3]) punish.append(slist[0][4]) else: for index in range(len(slist)): xDate.append(slist[index][0]) tuikuan.append(slist[index][1]) auto_end.append(slist[index][2]) dispute.append(slist[index][3]) punish.append(slist[index][4]) result = {} result["status"] = 0 result["message"] = "获取数据成功" result["xDate"] = xDate result["tuikuan"] = tuikuan result["auto_end"] = auto_end result["dispute"] = dispute result["punish"] = punish self.finish(result)
def initialize(self): self.taskDao = TaskDao() self.shopDao = ShopDao() self.productDao = ProductDao()
class ShopExportHandler(BaseHandler): def initialize(self): self.shopDao = ShopDao() def get(self, *args, **kwargs): shopName = self.get_args("shopName") shopArea = self.get_args("shopArea") shopType = self.get_args("shopType") shopMark = self.get_args("shopMark") minLevel = self.get_args("minLevel") maxLevel = self.get_args("maxLevel") page = self.get_args("page") pageSize = self.get_args("pageSize") taskId = self.get_args("taskId") if page is not None: page = int(page) else: page = 1 if pageSize is not None: pageSize = int(pageSize) else: pageSize = 20 pageSize = page * pageSize page = 1 shopList = self.shopDao.select_shop_list_all(shopName, shopArea, shopType, shopMark, minLevel, maxLevel, taskId) workbook = xlwt.Workbook(encoding='utf-8') font = xlwt.Font() font.name = 'SimSu' sheet = workbook.add_sheet('导出数据') sheet.write(0, 0, '店铺名') sheet.write(0, 1, '店铺url') sheet.write(0, 2, '淘宝号') sheet.write(0, 3, '所在地') sheet.write(0, 4, '淘宝分数') # sheet.write(0, 5, '好评') # sheet.write(0, 6, '中差评') # sheet.write(0, 6, '销量') row = 1 for shop_data in shopList: midc = 0 bc = 0 sheet.write(row, 0, shop_data.shop_name) sheet.write(row, 1, shop_data.shop_url) sheet.write(row, 2, shop_data.shop_boss_tb) sheet.write(row, 3, shop_data.shop_area) sheet.write(row, 4, shop_data.shop_level) # sheet.write(row, 5, shop_data.good_comments) # sheet.write(row, 6, mb) # sheet.write(row, 6, shop_data.product_sales_count) row += 1 self.set_header('Content-Type', 'application/x-xls') filename = datetime.datetime.now().strftime("%Y-%m-%d") + ".xls" self.set_header('Content-Disposition', 'attachment; filename=' + filename + '') sio = StringIO.StringIO() workbook.save(sio) self.write(sio.getvalue()) self.finish()