orderstats.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. class orderstatsControl extends SystemControl
  3. {
  4. public function __construct()
  5. {
  6. parent::__construct();
  7. }
  8. public function indexOp()
  9. {
  10. $type = $_GET['type'] ? $_GET['type'] : 'system';
  11. $page = "{$type}.order.stats";
  12. $model_refill_order = Model('refill_order');
  13. $condition['type'] = $type;
  14. if (!empty($_GET['cid'])) {
  15. $condition['cid'] = $_GET['cid'];
  16. }
  17. if (!empty($_GET['order_time_type'])) {
  18. $condition['order_time_type'] = $_GET['order_time_type'];
  19. }
  20. $start_unixtime = intval(strtotime($_GET['query_start_time']));
  21. $end_unixtime = intval(strtotime($_GET['query_end_time']));
  22. if ($start_unixtime > 0 && $end_unixtime > $start_unixtime) {
  23. $condition['time_stamp'] = [['egt', $start_unixtime], ['lt', $end_unixtime], 'and'];
  24. } elseif ($start_unixtime > 0) {
  25. $condition['time_stamp'] = ['egt', $start_unixtime];
  26. } elseif ($end_unixtime > 0) {
  27. $condition['time_stamp'] = ['lt', $end_unixtime];
  28. }
  29. $stats_list = $model_refill_order->getOrderStatsList($condition);
  30. if ($type == 'provider') {
  31. $provider_list = Model('')->table('refill_provider,store')->field('refill_provider.store_id,store.store_name')->join('inner')
  32. ->on('store.store_id=refill_provider.store_id')->limit(1000)->select();
  33. Tpl::output('provider_list', $provider_list);
  34. } elseif ($type == 'merchant') {
  35. $merchant_list = Model('')->table('merchant')->limit(1000)->select();
  36. Tpl::output('merchant_list', $merchant_list);
  37. }
  38. $total_stats = $this->stats($stats_list);
  39. $order_time_type_text = ['notify_time' => '回调时间', 'order_time' => '下单时间'];
  40. Tpl::output('total_stats', $total_stats);
  41. Tpl::output('stats_list', $stats_list);
  42. Tpl::output('order_time_type_text', $order_time_type_text);
  43. Tpl::output('show_page', $model_refill_order->showpage());
  44. Tpl::showpage($page);
  45. }
  46. public function ExportDataOp()
  47. {
  48. $type = $_GET['type'] ? $_GET['type'] : 'system';
  49. $model_refill_order = Model('refill_order');
  50. $condition['type'] = $type;
  51. if (!empty($_GET['cid'])) {
  52. $condition['cid'] = $_GET['cid'];
  53. }
  54. if (!empty($_GET['order_time_type'])) {
  55. $condition['order_time_type'] = $_GET['order_time_type'];
  56. }
  57. $start_unixtime = intval($_GET['query_start_time']);
  58. $end_unixtime = intval($_GET['query_end_time']);
  59. if ($start_unixtime > 0 && $end_unixtime > $start_unixtime) {
  60. $condition['time_stamp'] = [['egt', $start_unixtime], ['lt', $end_unixtime], 'and'];
  61. } elseif ($start_unixtime > 0) {
  62. $condition['time_stamp'] = ['egt', $start_unixtime];
  63. } elseif ($end_unixtime > 0) {
  64. $condition['time_stamp'] = ['lt', $end_unixtime];
  65. }
  66. $stats_list = $model_refill_order->getOrderStatsList($condition,'','*','time_stamp asc');
  67. $total_stats = $this->stats($stats_list);
  68. $stats = $total_stats[$_GET['order_time_type']];
  69. if(empty($stats)) {
  70. $stats = $total_stats['notify_time'];
  71. }
  72. $result['data'] = $stats_list;
  73. $result['total_stats'] = $stats;
  74. echo(json_encode($result));
  75. exit;
  76. }
  77. private function stats($stats_list): array
  78. {
  79. $order_time_type = ['notify_time','order_time'];
  80. foreach ($order_time_type as $type){
  81. $success_count_total = $success_refill_amounts_total = $success_mch_amounts_total = $success_channel_amounts_total = $profit_amounts_total = 0;
  82. foreach ($stats_list as $stats) {
  83. if($stats['order_time_type'] != $type) continue;
  84. $success_count_total += $stats['success_count'];
  85. $success_refill_amounts_total += $stats['success_refill_amounts'];
  86. $success_mch_amounts_total += $stats['success_mch_amounts'];
  87. $success_channel_amounts_total += $stats['success_channel_amounts'];
  88. $profit_amounts_total += $stats['profit_amounts'];
  89. }
  90. $total_stats[$type] = [
  91. 'success_count_total' => $success_count_total,
  92. 'success_refill_amounts_total' => $success_refill_amounts_total,
  93. 'success_mch_amounts_toatl' => $success_mch_amounts_total,
  94. 'success_channel_amounts_total' => $success_channel_amounts_total,
  95. 'profit_amounts_total' => $profit_amounts_total
  96. ];
  97. }
  98. return $total_stats;
  99. }
  100. }