app02.py 4.8 KB

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