from Utils.sql_handler import test_env_conn from TestData.inbox.channel_test_data import channelData channel_select_sql = f'select * from `resource_item` where brand_id = {channelData.brandId} and resource_id in (7,2,3,4,6)' #2:livechat 3:facebook 4:email 6:ins 7:whatsapp channel_select_result = test_env_conn.select_many_value(sql=channel_select_sql) channel_id = channel_select_result[0]['id'] channel_name_select_sql = f'select * from `shop` where id = {channel_select_result[0]["rel_id"]}' channel_name_select_result = test_env_conn.select_one_value(sql=channel_name_select_sql) channel_name = channel_name_select_result['shop_name'] channel_rel_id = channel_select_result[0]['rel_id'] channel_resource_id = channel_select_result[0]['resource_id'] setattr(channelData, 'channel_id', channel_id) setattr(channelData, 'channel_name', channel_name) setattr(channelData, 'channel_resource_id', channel_resource_id) channel_open_room_select_sql = f'select * from `im_room` where site_id = {channel_rel_id} and status = 1 and is_ignore = 0 and room_type != 2' channel_open_room_select_result = test_env_conn.select_many_value(sql=channel_open_room_select_sql) setattr(channelData, 'channel_open_room_num', len(channel_open_room_select_result)) setattr(channelData, 'channel_open_room_num_add', len(channel_open_room_select_result) + 1) customer_service_select_sql = f'select * from `rel_customerservice_brand` where brand_id = {channelData.brandId} and is_delete = 0' customer_service_select_result = test_env_conn.select_many_value(sql=customer_service_select_sql) customer_service_id_list = set([i['customer_service_id'] for i in customer_service_select_result]) customer_service_list_select_sql = f'select * from `customer_service` where id in {tuple(customer_service_id_list)} and customer_type = 0' customer_service_list_select_result = test_env_conn.select_many_value(sql=customer_service_list_select_sql) end = 0 for cs in customer_service_list_select_result: for customer in customer_service_select_result: if customer['customer_service_id'] == cs['id'] and customer['is_activation']: customer_service_id = customer['customer_service_id'] setattr(channelData, 'customer_service_name', cs['name']) setattr(channelData, 'customer_service_image', cs['profile']) setattr(channelData, 'customer_service_email', cs['email']) end = 1 break if end: break setattr(channelData, 'customer_service_num', len(customer_service_list_select_result)) setattr(channelData, 'customer_service_id', customer_service_id) customer_channel_open_room_select_sql = f'select * from `im_room` where site_id = {channel_rel_id} and status = 1 and room_type != 2 and is_ignore = 0 and allocation_uid = {customer_service_id}' customer_channel_open_room_select_result = test_env_conn.select_many_value(sql=customer_channel_open_room_select_sql) setattr(channelData, 'customer_channel_open_room_num', len(customer_channel_open_room_select_result)) customer_open_room_select_sql = f'select * from `im_room` where status = 1 and room_type != 2 and is_ignore = 0 and allocation_uid = {customer_service_id}' customer_open_room_select_result = test_env_conn.select_many_value(sql=customer_open_room_select_sql) setattr(channelData, 'customer_open_room_num', len(customer_open_room_select_result)) setattr(channelData, 'customer_open_room_num_add', len(customer_open_room_select_result) + 1) other_room_select_sql = f'select * from `im_room` where allocation_uid != {customer_service_id} and room_type != 2 and cate_id = {channelData.brandId} and status = 1 limit 10' other_room_select_result = test_env_conn.select_one_value(sql=other_room_select_sql) setattr(channelData, 'other_room_id', other_room_select_result['room_id'])