def reset_crm_opareter_status(shop_id): """重置CRM操作状态""" try: account_coll.update({'_id':shop_id, 'opar_status':{'$ne':0}}, {'$set':{'opar_status':0}}, multi = True) camp_coll.update({'shop_id':shop_id, 'opar_status':{'$ne':0}}, {'$set':{'opar_status':0}}, multi = True) adg_coll.update({'shop_id':shop_id, 'opar_status':{'$ne':0}}, {'$set':{'opar_status':0}}, multi = True) except Exception, e: log.error('reset crm opareter status error, error=%s' % e) return False
def add_user_keyword(shop_id): word_list = [] word_list.extend( [kw['word'] for kw in kw_coll.find({'shop_id': shop_id}, {'word'})]) KeywordInfo.insert_new_word_list(word_list) account_coll.update({'_id': shop_id}, {'$set': { 'has_push': True }}, multi=True) return 1
def check_balance(self): try: # tobj_balance = self.tapi.simba_account_balance_get() # if tobj_balance and hasattr(tobj_balance, 'balance'): # account_coll.update({'_id': self.shop_id}, {'$set':{'balance':tobj_balance.balance}}) # if tobj_balance.balance > 10: # return True balance = self.tapi.get_account_balance() account_coll.update({'_id': self.shop_id}, {'$set': { 'balance': balance }}) if balance > 10: return True return False except Exception, e: log.error('get balace error, shop_id=%s, e=%s' % (self.shop_id, e)) return False
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
# coding=UTF-8 import init_environ from apps.subway.models_account import account_coll account_coll.update({}, {'$set':{'custom_hide_column':[]}}, multi = True)