def do_bind(self, customer_list): Customer.bind_user_info(customer_list) if self.export_type == '1': # 导出最新一笔订单 Customer.bind_last_subscribe(customer_list, self.subscribe_category) elif self.export_type == '2': # 导出7天报表数据 Customer.bind_7days_data(customer_list) elif self.export_type == '3': Customer.bind_last_subscribe(customer_list, self.subscribe_category) Customer.bind_7days_data(customer_list) for c in customer_list: if self.myself.position != 'SMANAGER': c.qq = c.phone = ''
def init_customer_consult(): shop_id_list = list(Subscribe.objects.filter(create_time__gte=datetime.datetime(2017, 2, 9)).values_list('shop_id', flat=True)) Customer.get_or_create_servers(shop_id_list)
def export_data_from_tpm_main(): print u'1st, 获取新旧ID映射列表' id_dict = get_newid_byoldid() invalid_nick_list = [] customer_dict = {} print u'2nd, 获取TPM客户' tpcustomer_list = get_tpcustomers() nick2shop_dict = get_nick2shop_dict() for tc in tpcustomer_list: is_new = False nick = tc[1].strip() shop_id = int(nick2shop_dict.get(nick, 0)) if not shop_id: is_new = True shop_id = Customer.get_shop_by_nick(nick) if not shop_id: invalid_nick_list.append(nick) continue customer_dict.update({ tc[0]: { 'shop_id': shop_id, 'nick': tc[1], 'seller': tc[2], 'phone': tc[3], 'qq': tc[4], 'ww': tc[5], 'ztc_name': tc[6], 'ztc_psw': tc[7], 'lz_name': tc[8], 'lz_psw': tc[9], 'acct_status': tc[10] == 'dead' and 1 or 0, 'note': tc[11], 'update_time': tc[12], 'create_time': tc[13], 'is_new': is_new } }) print u'3rd, 总客户数:%s, 需导入客户数:%s, 无效客户数:%s' % ( len(tpcustomer_list), len(customer_dict), len(invalid_nick_list)) invalid_order_list = [] order_list = [] tporder_list = get_tporders() for to in tporder_list: customer_obj = customer_dict.get(to[0], None) if not customer_obj: invalid_order_list.append(to) else: order_list.append({ 'shop_id': customer_obj['shop_id'], 'psuser_id': id_dict[to[1]], 'pay': int(to[2]) * 100, 'start_date': to[3], 'end_date': to[4], 'note': to[5], 'create_time': to[6], 'cycle': '', 'biz_type': 1, 'operater_id': id_dict[to[7]], 'article_code': 'tp-001', 'article_name': '直通车托管' }) print u'4th, 总订单数:%s, 需导入数:%s, 无效订单数:%s' % ( len(tporder_list), len(order_list), len(invalid_order_list)) old_count, new_count, cust_failed_list = insert_customer(customer_dict) insert_count, order_failed_list = insert_order(order_list) print u'5th, 导入完成,customer新增%s个,更新%s个,失败%s个; subscribe新增%s个,失败%s个' % ( new_count, old_count, len(cust_failed_list), insert_count, len(order_failed_list))
def do_bind(self, customer_list): customer_list = super(WorkBenchConsult, self).do_bind(customer_list) Customer.bind_user_info(customer_list) Customer.bulk_bind_events(customer_list)
def bind_client_group_ids(self, customer_list, all_client_group): """绑定客户群ids""" Customer.bind_client_group_ids(customer_list=customer_list, all_client_group=all_client_group)
def do_bind(self, customer_list): """绑定额外的数据""" customer_list = Customer.binder_order_info(customer_list, self.subscribe_category) return customer_list
# coding=UTF-8 '''刷新客户的服务人员分配''' import init_environ, datetime from apps.ncrm.models import Customer if __name__ == "__main__": print 'refresh_customer_consult begin' today = datetime.date.today() days_30ago = today - datetime.timedelta(days = 30) # 暂定到期时间大于30天前的客户为我们需要的数据 shop_id_list = list(Customer.objects.filter(latest_end__gte = days_30ago).values_list('shop_id', flat=True)) i, j, k = 0, 100, len(shop_id_list) while shop_id_list[i:i+j]: print '%s / %s' % (i+j, k) Customer.get_or_create_servers(shop_id_list[i:i+j]) i += j print 'end at %s' % datetime.datetime.now()