Example #1
0
def send_update_user(limit_time):
    """获取需要同步到百会的卖家信息"""

    file_name = CURRENT_DIR + 'data/update_user.csv'
    file_obj = file(file_name, 'w')
    update_list = ShopDBService.get_update_shop_list(limit_time)
    file_obj.write('卖家,电话,姓名,专属客服\n')
    for shop in update_list:
        shop['seller_name'] = shop.get('seller_name', '')
        shop['seller_mobile'] = shop.get('seller_mobile', '')
        shop['worker_name'] = WORKER_DICT[shop['worker_id']]
        if shop['update_time'] <= limit_time:
            continue
        if not shop['seller_name']:
            continue
        print '%(nick)s, %(seller_mobile)s, %(seller_name)s, %(worker_name)s' % (
            shop)
        file_obj.write(
            '%(nick)s, %(seller_mobile)s, %(seller_name)s, %(worker_name)s\n' %
            (shop))
    file_obj.close()
    content = '更新部分卖家信息'
    subject = '更新部分卖家信息'
    send_email_with_file('*****@*****.**', content, subject,
                         [file_name])
    def collect_online_info(self):
        """获取用户数据中心信息"""

        #获取所有用户
        all_shop = ShopDBService.get_all_shop_list()
        self.nick_shop = {}
        for shop in all_shop:
            self.nick_shop[shop['nick']] = shop

        #获取所有退款
        all_refund = RefundDBService.get_all_refunds_list()
        refund_list = [refund['order_id'] for refund in all_refund]

        #获取所有订单
        all_order = OrderDBService.get_all_orders_list()
        self.user_order = {}

        order_flag = False
        order_time = datetime.datetime.combine(
            datetime.date.today() - datetime.timedelta(days=1),
            datetime.time())

        for order in all_order:
            if not order_flag and order['occur_time'] >= order_time:
                order_flag = True
            if not order['article_code'] in self.article_code_list:
                continue
            if order['order_id'] in refund_list:
                continue
            key = order['nick'] + order['article_code']
            old_order = self.user_order.get(
                key,
                {'order_cycle_start': datetime.datetime(2011, 1, 1, 0, 0)})
            if order['order_cycle_start'] > old_order['order_cycle_start']:
                self.user_order[key] = order
        if not order_flag:
            send_sms('13738141586', str(order_time) + '的订单没有抓取成功')

        #获取所有服务支持
        all_support = SupportDBService.get_all_supports_list()
        self.user_supports = {}

        for support in all_support:
            if not support['article_code'] in self.article_code_list:
                continue
            key = support['nick'] + support['article_code']
            if not self.user_supports.has_key(key):
                self.user_supports[key] = []
            self.user_supports[key].append(support)

        #nick_worker存放 需要修改的客户客服关系 后期 取消
        self.nick_worker = {}

        for line in file(CURRENT_DIR + 'data/worker_nick.csv'):
            line_data = line.split(',')
            worker_id = int(line_data[0])
            nick = (line_data[1].split('\n'))[0].decode('utf-8')
            self.nick_worker[nick] = worker_id
    def analysis_worker_arrange(self):
        """专属客服分配情况"""
        
        return_str = '每个专属客服配置的最大服务客户数为%d.\n' % (FULL_NUM)
        for worker_id in WORKER_DICT.keys():
            number = ShopDBService.count_normal_allocated_shop(worker_id)
            return_str += '麦苗科技 %s : %d\n' % (WORKER_DICT[worker_id], number)

        return return_str
Example #4
0
    def collect_online_info(self):
        """获取用户数据中心信息"""
        
        #获取所有用户
        all_shop = ShopDBService.get_all_shop_list()
        self.nick_shop = {}        
        for shop in all_shop:
            self.nick_shop[shop['nick']] = shop
        
        #获取所有退款
        all_refund = RefundDBService.get_all_refunds_list()
        refund_list = [refund['order_id'] for refund in all_refund]
        
        #获取所有订单
        all_order = OrderDBService.get_all_orders_list()
        self.user_order = {}
        
        order_flag = False 
        order_time = datetime.datetime.combine(datetime.date.today()-datetime.timedelta(days=1), datetime.time())
        
        for order in all_order:
            if not order_flag and order['occur_time'] >= order_time:
                order_flag = True
            if not order['article_code'] in self.article_code_list:
                continue
            if order['order_id'] in refund_list:
                continue
            key = order['nick'] + order['article_code']
            old_order = self.user_order.get(key, {'order_cycle_start':datetime.datetime(2011, 1, 1, 0, 0)})
            if order['order_cycle_start'] > old_order['order_cycle_start']:
                self.user_order[key] = order
        if not order_flag:
            send_sms('13738141586',str(order_time)+'的订单没有抓取成功')

        #获取所有服务支持
        all_support = SupportDBService.get_all_supports_list()
        self.user_supports = {}
        
        for support in all_support:
            if not support['article_code'] in self.article_code_list:
                continue
            key = support['nick'] + support['article_code']
            if not self.user_supports.has_key(key):
                self.user_supports[key] = []
            self.user_supports[key].append(support)

        #nick_worker存放 需要修改的客户客服关系 后期 取消
        self.nick_worker = {}
        
        for line in file(CURRENT_DIR+'data/worker_nick.csv'):
            line_data = line.split(',')
            worker_id = int(line_data[0])
            nick = (line_data[1].split('\n'))[0].decode('utf-8')
            self.nick_worker[nick] = worker_id
 def collect_online_info(self):
     """获取用户数据中心信息"""
     
     logger.info('start collect_online_info')
     
     #获取所有用户
     all_shop = ShopDBService.get_all_shop_list()
     self.nick_shop = {}        
     for shop in all_shop:
         self.nick_shop[shop['nick']] = shop
     
     logger.info('finish collect shop info')
     
     #获取所有订单
     all_order = OrderDBService.get_all_orders_list()
     logger.info('finish collect order info')
     
     self.user_orders = {}
     for order in all_order:
         key = (order['nick'], order['article_code'])
         if not self.user_orders.has_key(key):    
             self.user_orders[key] = []
         self.user_orders[key].append(order)
     
     logger.info('finish arrange order info')
     
     #获取所有退款
     all_refund = RefundDBService.get_all_refunds_list()
     refund_list = [refund['order_id'] for refund in all_refund]
     
     logger.info('finish collect refund info')
     
     for key in self.user_orders.keys():
         real_orders = []
         orders = self.user_orders[key]
         orders.sort(key=lambda order:order['order_cycle_start'])
         for i in range(len(orders)):
             order = orders[i]
             if int(order['total_pay_fee']) > 500:
                 if i < len(orders) - 1:
                     next_order = orders[i+1]
                     if int(next_order['total_pay_fee']) <= 500 and next_order['biz_type'] == 2:
                         order['order_cycle_end'] = next_order['order_cycle_end']
                 real_orders.append(order)
         self.user_orders[key] = real_orders
     logger.info('finish collect_online_info')
Example #6
0
def sample_award(number):
    """抽奖程序"""
    
    all_order = OrderDBService.get_orders_between_time(datetime.datetime(2013,5,20), datetime.datetime(2013,5,26))
    all_nick = set([])
    for order in all_order:
        if order['article_code'] != 'ts-1796606':
            continue
        if str(order['order_cycle']) in ['1个月', '0个月']:
            continue
        all_nick.add(order['nick'])
    nick_list = list(all_nick)
    award_nick = random.sample(nick_list, number)
    for nick in award_nick:
        shop = ShopDBService.get_shop_by_nick(nick)
        if not shop or not shop.get('worker_id'):
            print nick + ',' + 'null'
        else:
            print nick + ',' + WORKER_DICT[shop['worker_id']]
def sample_award(number):
    """抽奖程序"""

    all_order = OrderDBService.get_orders_between_time(
        datetime.datetime(2013, 5, 20), datetime.datetime(2013, 5, 26))
    all_nick = set([])
    for order in all_order:
        if order['article_code'] != 'ts-1796606':
            continue
        if str(order['order_cycle']) in ['1个月', '0个月']:
            continue
        all_nick.add(order['nick'])
    nick_list = list(all_nick)
    award_nick = random.sample(nick_list, number)
    for nick in award_nick:
        shop = ShopDBService.get_shop_by_nick(nick)
        if not shop or not shop.get('worker_id'):
            print nick + ',' + 'null'
        else:
            print nick + ',' + WORKER_DICT[shop['worker_id']]
Example #8
0
def send_update_user(limit_time):
    """获取需要同步到百会的卖家信息"""
    
    file_name = CURRENT_DIR+'data/update_user.csv'
    file_obj = file(file_name, 'w')
    update_list = ShopDBService.get_update_shop_list(limit_time)
    file_obj.write('卖家,电话,姓名,专属客服\n')
    for shop in update_list:
        shop['seller_name'] = shop.get('seller_name', '')
        shop['seller_mobile'] = shop.get('seller_mobile', '')
        shop['worker_name'] = WORKER_DICT[shop['worker_id']]
        if shop['update_time'] <= limit_time:
            continue
        if not shop['seller_name']:
            continue
        print '%(nick)s, %(seller_mobile)s, %(seller_name)s, %(worker_name)s' % (shop)
        file_obj.write('%(nick)s, %(seller_mobile)s, %(seller_name)s, %(worker_name)s\n' % (shop))
    file_obj.close()
    content = '更新部分卖家信息'
    subject = '更新部分卖家信息'
    send_email_with_file('*****@*****.**', content, subject, [file_name])
    def update_online(self):
        """更新用户中心"""

        for shop in self.update_shops:
            ShopDBService.upset_shop(shop)
Example #10
0
class Shop(object):

    syb_conn = syb_db['CommonInfo']
    bd_conn = bd_db['CommonInfo']

    @classmethod
    def get_shop_info_by_sid(cls, soft_code, shop_id):
        """根据shop_id获得店铺基本信息"""

        pass

    @classmethod
    def get_shop_status_by_sid(cls, soft_code, shop_id):
        """根据shop_id获得店铺设置信息"""

        pass

    @classmethod
    def get_shop_info_by_nick(cls, soft_code, nick):
        """根据nick获得店铺基本信息"""

        pass

    @classmethod
    def get_shop_status_by_nick(cls, soft_code, nick):
        """根据nick获得店铺设置信息"""

        pass

    @classmethod
    def get_all_shop_info(cls, soft_code):
        """获取所有shop_info"""

        if soft_code == 1:
            shops_info = cls.bd_conn['shop_info'].find()
        elif soft_code == 2:
            shops_info = cls.syb_conn['shop_info'].find()
        shops_info = [shop for shop in shops_info]
        return shops_info

    @classmethod
    def get_all_shop_status(cls, soft_code):
        """获取所有shop_status"""

        if soft_code == 1:
            shops_status = cls.bd_conn['shop_status'].find()
        elif soft_code == 2:
            shops_status = cls.syb_conn['shop_status'].find()
        shops_status = [shop for shop in shops_status]
        return shops_status

    @classmethod
    def get_all_normal_shop_status(cls, soft_code):
        """获取省油宝的所有正常shop_status"""

        shop_status_list = Shop.get_all_shop_status(soft_code)
        normal_shop_list = []
        for shop_status in shop_status_list:
            if shop_status.get('session_expired', False):
                continue
            if shop_status.get('insuff_level', False):
                continue
            normal_shop_list.append(shop_status)

        return normal_shop_list

    @classmethod
    def store_shop_to_center(cls, nick, sid, article_code, deadline,
                             access_token):
        """存储用户数据到数据中心"""

        shop = {'nick': str(nick), 'sid': int(sid)}
        try:
            if article_code == 'ts-1796606':
                seller = ShopServiceSYB.get_seller_info_by_nick(
                    nick, access_token)
            elif article_code == 'ts-1797607':
                seller = ShopServiceXCW.get_seller_info_by_nick(
                    nick, access_token)
        except Exception, e:
            return None
        if seller:
            shop['seller_mobile'] = seller.get('seller_mobile', '')
            shop['seller_name'] = seller.get('seller_name', '')
            shop['seller_email'] = seller.get('seller_email', '')

        shop['worker_id'] = ShopDBService.allocate_one_shop()
        shop[article_code + '_deadline'] = deadline
        shop[article_code + '_status'] = '初始化'
        shop['update_time'] = datetime.datetime.now()
        shop['flag'] = True
        ShopDBService.upsert_shop(shop)
        return shop
Example #11
0
    def update_online(self):
        """更新用户中心"""

        for shop in self.update_shops:
            ShopDBService.upset_shop(shop)