app02.py 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. import os
  2. import numpy as np
  3. import pandas as pd
  4. from sqlalchemy import create_engine
  5. ########################################################################################################
  6. # 将小米的订单中,属于小米后台的数据剔除
  7. # data目录:小米后台下载的对账单
  8. # 0730-0809目录:我方ftp下载的对账单
  9. # out目录:给小米生成的新的对账单
  10. ########################################################################################################
  11. XIAOMI_PATH = '1123-1206'
  12. curr_path = os.path.dirname(os.path.abspath(__file__))
  13. # 小米后台数据
  14. data_path = os.path.join(curr_path,"data")
  15. print( data_path )
  16. r_dict = {}
  17. for root,dirs,files in os.walk( data_path ):
  18. for file in files:
  19. file_item = os.path.join(root,file)
  20. #print( file_item )
  21. df = pd.read_csv( file_item, usecols=[2] ,encoding='utf8')
  22. for value in df.values:
  23. order_id = value[0].strip()
  24. #print( order_id )
  25. r_dict[ order_id ] = 1
  26. #print( r_dict )
  27. # 蓝色火焰后台数据
  28. my_path = os.path.join(curr_path,XIAOMI_PATH)
  29. out_path = os.path.join(curr_path,"out")
  30. print( my_path )
  31. print( out_path )
  32. df1 = pd.DataFrame(columns=(['订单号', '手机号码', '规格', '商户订单号', '收单日期', '回调日期', '归属地', '价格', '充值状态', '状态描述']))
  33. for root,dirs,files in os.walk( my_path ):
  34. success_result = [['订单号', '手机号码', '规格', '商户订单号', '收单日期', '回调日期', '归属地', '价格', '充值状态', '状态描述']]
  35. fail_result = [['订单号', '手机号码', '规格', '商户订单号', '收单日期', '回调日期', '归属地', '价格', '充值状态', '状态描述']]
  36. #df1 = pd.DataFrame(columns=(['订单号', '手机号码', '规格', '商户订单号', '收单日期', '回调日期', '归属地', '价格', '充值状态', '状态描述']))
  37. for file in files:
  38. file_item = os.path.join(root,file)
  39. #print( file_item )
  40. df = pd.read_csv( file_item )
  41. df1 = df1.append(df)
  42. df1['订单号'] = df1['订单号'].astype(str) + "\t"
  43. #print(df1)
  44. #result = [['订单号','手机号码','规格','商户订单号','收单日期','回调日期','归属地','价格','充值状态','状态描述']]
  45. for value in df.values:
  46. order_id = value[3].strip()
  47. #print( order_id )
  48. if order_id in r_dict:
  49. #print( order_id )
  50. pass
  51. elif value[8] == 6:
  52. success_result.append(value)
  53. elif value[8] == 4:
  54. fail_result.append(value)
  55. '''
  56. #print( result )
  57. dt = np.dtype((str, 32))
  58. f_value = np.array( result, dtype=dt)
  59. print( f_value )
  60. frame = pd.DataFrame(f_value)
  61. f_path = os.path.basename(file_item)
  62. print( f_path )
  63. write_path = os.path.join(out_path,f_path)
  64. print( write_path )
  65. frame.to_csv(write_path, index=False, header=0 , sep=',',encoding='utf-8')
  66. #f_path = os.path.splitext(file_item)
  67. #write_path = f_path[0] + ".xlsx"
  68. #print( write_path )
  69. #frame = pd.DataFrame(f_value, index=['订单号','手机号码','规格','商户订单号','收单日期','回调日期','归属地','价格','充值状态','状态描述'])
  70. #frame = pd.DataFrame(f_value)
  71. #frame.to_excel( write_path )
  72. '''
  73. #print( result )
  74. dt = np.dtype((str, 32))
  75. f_success_value = np.array(success_result, dtype=dt)
  76. f_fail_value = np.array(fail_result, dtype=dt)
  77. #print(f_success_value)
  78. success_frame = pd.DataFrame(f_success_value)
  79. #print(success_frame)
  80. success_frame.iloc[:,0] = success_frame.iloc[:,0].astype(str) + "\t"
  81. fail_frame = pd.DataFrame(f_fail_value)
  82. fail_frame.iloc[:,0] = success_frame.iloc[:,0].astype(str) + "\t"
  83. total_fram = success_frame.append(fail_frame)
  84. total_fram.iloc[:,0] = success_frame.iloc[:,0].astype(str) + "\t"
  85. f_path = os.path.basename(file_item)
  86. #print( f_path )
  87. f_success_path = f_path.replace('.csv','成功订单.csv')
  88. f_fail_path = f_path.replace('.csv','失败订单.csv')
  89. t_path = f_path.replace('.csv','我方总订单.csv')
  90. #print("f_success:%s"%f_success_path)
  91. write_success_path = os.path.join(out_path,f_success_path)
  92. write_fail_path = os.path.join(out_path,f_fail_path)
  93. write_total_path = os.path.join(out_path,f_path)
  94. write_t_path = os.path.join(out_path,t_path)
  95. #print(write_success_path)
  96. success_frame.to_csv(write_success_path, index=False, header=0, sep=',', encoding='utf-8-sig')
  97. fail_frame.to_csv(write_fail_path, index=False, header=0, sep=',', encoding='utf-8-sig')
  98. total_fram.to_csv(write_total_path, index=False, header=0, sep=',', encoding='utf-8-sig')
  99. df1.to_csv(write_t_path, index=False, header=1, sep=',', encoding='utf-8-sig')