Exemplo n.º 1
0
def load_upgrade_account():
    qs_cursor = account_coll.find(
        {
            '$or': [{
                "receive_address": {
                    "$nin": [None, ""]
                }
            }, {
                "receiver": {
                    "$nin": [None, ""]
                }
            }, {
                "receiver_phone": {
                    "$nin": [None, ""]
                }
            }, {
                "zip_code": {
                    "$nin": [None, ""]
                }
            }]
        }, {
            "_id": 1,
            "receive_address": 1,
            "receiver": 1,
            "receiver_phone": 1,
            "zip_code": 1,
        })
    return {info['_id']: DictWrapper(info) for info in qs_cursor}
Exemplo n.º 2
0
def get_all_word_list():
    total_kw_list = []
    cursor = account_coll.find({}, {'_id': 1})
    shop_id_list = [i['_id'] for i in cursor]
    for shop_id in shop_id_list:
        shop_kw_list = get_shop_keyword_list(shop_id)
        total_kw_list.extend(shop_kw_list)
    return total_kw_list
Exemplo n.º 3
0
def batch_refresh_shopcatid(shop_id_list, is_force = False):
    # 批量刷新店铺的类目ID
    def get_shop_cat(category_ids_list):
        cat_id = 0
        if category_ids_list:
            tmp_dict = {}
            for category_ids in category_ids_list:
                tmp_cat_list = category_ids.split()[:1]
                for tmp_cat in tmp_cat_list:
                    if not tmp_dict.has_key(tmp_cat):
                        tmp_dict[tmp_cat] = 1
                    else:
                        tmp_dict[tmp_cat] += 1
            # 将字典排序成按出现次数最多的元组排序
            sorted_list = sorted(tmp_dict.iteritems(), key = lambda x:x[1], reverse = True)
            cat_id = sorted_list[0][0] # 只取第一个
        return cat_id

    temp_shop_dict = {}
    temp_cat_dict = {}

    if not is_force:
        shop_id_list = [ int(acc['_id'])  for acc in account_coll.find({'_id':{'$in':shop_id_list}, '$or':[{'cat_id':None}, {'cat_id':0}, {'cat_id':''}]}, {'_id':1}) ]

    if not shop_id_list:
        return {}, 0

    adg_cursor = adg_coll.find({'shop_id':{'$in':shop_id_list}}, {'category_ids':1, 'shop_id':1})
    for adg in adg_cursor:
        if adg:
            key = str(adg['shop_id'])
            if temp_shop_dict.has_key(key):
                temp_shop_dict[key].append(adg['category_ids'])
            else:
                temp_shop_dict[key] = [adg['category_ids']]

    for shop_id, category_ids_list in temp_shop_dict.items():
        cat_id = get_shop_cat(category_ids_list)
        key = str(cat_id)
        if temp_cat_dict.has_key(key):
            temp_cat_dict[key].append(int(shop_id))
        else:
            temp_cat_dict[key] = [int(shop_id)]

    count = 0
    result = {}
    for cat_id, shop_id_list in temp_cat_dict.items():
        result_dict = account_coll.update({'_id':{'$in':shop_id_list}}, {'$set':{'cat_id':int(cat_id)}}, upsert = False, multi = True)
        # Customer.objects.filter(shop_id__in = shop_id_list).update(cat_id = int(cat_id))
#         log.info('have already refreshed, cat_id = %s , shop_id_list = %s, result_dict=%s' % (cat_id, shop_id_list, json.dumps(result_dict)))
        if result_dict and result_dict.has_key('n'):
            count += result_dict['n']
            result_dict['cat_id'] = cat_id
            result = result_dict
    return result, count
Exemplo n.º 4
0
def tj_shop_rpt():
    print '%s: start tj shop rpt' % datetime.datetime.now()
    result_dict = init_result_dict(mnt_type_list = ['all'])
    accs = account_coll.find({}, {'_id': 1})
    for acc in accs:
        shop_id = acc['_id']
        rpt_dict = Account.Report.get_snap_list({'shop_id': shop_id}, rpt_days = INIT_RPT_DAYS)
        rpt_list = rpt_dict.get(shop_id, [])
        add_rpt(result_dict, rpt_list, 'all')

    insert_list = get_insert_list('shop', result_dict)
    rs_coll.insert(insert_list)
    print '%s: end tj shop rpt' % datetime.datetime.now()
    return
Exemplo n.º 5
0
 def add_user_keyword(cls):
     '''
     .添加用户的关键词
     '''
     result_list = []
     shop_id_list = [
         acct['_id']
         for acct in account_coll.find({'has_push': {
             '$in': [None, False]
         }}, {'_id': 1})
     ]
     for shop_id in shop_id_list:
         result_list.append(add_user_keyword.delay(shop_id))
     total = len(result_list)
     cls.monitor_result('add user keyword now len = %s and total len = %s',
                        result_list)
     return total
Exemplo n.º 6
0
    def get_valid_shops(cls):
        '''获取未过期的、有余额、需要实时优化的店铺'''
        objs = ArticleUserSubscribe.objects.filter(
            deadline__gt=datetime.datetime.now()).only('nick')
        article_dict = {obj.nick: 1 for obj in objs}

        objs = Customer.objects.all().only('shop_id', 'nick')
        customer_dict = {obj.shop_id: obj.nick for obj in objs}

        mnt_camp_list = mnt_camp_coll.find(
            {
                'mnt_rt': 1,
                'mnt_type': {
                    '$in': [2, 4]
                }
            }, {'shop_id': 1})
        mnt_shop_dict = {mnt_camp['shop_id']: 1 for mnt_camp in mnt_camp_list}

        shop_id_list = []
        acc_cur = account_coll.find(
            {'$or': [{
                'balance': {
                    '$gt': 0
                }
            }, {
                'balance': {
                    '$gt': '0'
                }
            }]}, {
                '_id': 1,
                'balance': 1
            })
        for acc in acc_cur:
            shop_id = acc['_id']
            if float(acc['balance']) < 0:
                continue
            if customer_dict.get(
                    shop_id, '') in article_dict and shop_id in mnt_shop_dict:
                shop_id_list.append(shop_id)
        return shop_id_list