orderstats.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. $start_unixtime = intval($_GET['query_start_time']);
  55. $end_unixtime = intval($_GET['query_end_time']);
  56. if ($start_unixtime > 0 && $end_unixtime > $start_unixtime) {
  57. $condition['time_stamp'] = [['egt', $start_unixtime], ['lt', $end_unixtime], 'and'];
  58. } elseif ($start_unixtime > 0) {
  59. $condition['time_stamp'] = ['egt', $start_unixtime];
  60. } elseif ($end_unixtime > 0) {
  61. $condition['time_stamp'] = ['lt', $end_unixtime];
  62. }
  63. $stats_list = $model_refill_order->getOrderStatsList($condition,'','*','time_stamp asc');
  64. $success_count_total = $success_refill_amounts_total = $success_mch_amounts_total = $success_channel_amounts_total = $profit_amounts_total = 0;
  65. foreach ($stats_list as $stats) {
  66. $success_count_total += $stats['success_count'];
  67. $success_refill_amounts_total += $stats['success_refill_amounts'];
  68. $success_mch_amounts_total += $stats['success_mch_amounts'];
  69. $success_channel_amounts_total += $stats['success_channel_amounts'];
  70. $profit_amounts_total += $stats['profit_amounts'];
  71. }
  72. $total_stats = [
  73. 'success_count_total' => ncPriceFormat($success_count_total),
  74. 'success_refill_amounts_total' => ncPriceFormat($success_refill_amounts_total),
  75. 'success_mch_amounts_toatl' => ncPriceFormat($success_mch_amounts_total),
  76. 'success_channel_amounts_total' => ncPriceFormat($success_channel_amounts_total),
  77. 'profit_amounts_total' => ncPriceFormat($profit_amounts_total)
  78. ];
  79. $result['data'] = $stats_list;
  80. $result['total_stats'] = $total_stats;
  81. echo(json_encode($result));
  82. exit;
  83. }
  84. private function stats($stats_list): array
  85. {
  86. $order_time_type = ['notify_time','order_time'];
  87. foreach ($order_time_type as $type){
  88. $success_count_total = $success_refill_amounts_total = $success_mch_amounts_total = $success_channel_amounts_total = $profit_amounts_total = 0;
  89. foreach ($stats_list as $stats) {
  90. if($stats['order_time_type'] != $type) continue;
  91. $success_count_total += $stats['success_count'];
  92. $success_refill_amounts_total += $stats['success_refill_amounts'];
  93. $success_mch_amounts_total += $stats['success_mch_amounts'];
  94. $success_channel_amounts_total += $stats['success_channel_amounts'];
  95. $profit_amounts_total += $stats['profit_amounts'];
  96. }
  97. $total_stats[$type] = [
  98. 'success_count_total' => $success_count_total,
  99. 'success_refill_amounts_total' => $success_refill_amounts_total,
  100. 'success_mch_amounts_toatl' => $success_mch_amounts_total,
  101. 'success_channel_amounts_total' => $success_channel_amounts_total,
  102. 'profit_amounts_total' => $profit_amounts_total
  103. ];
  104. }
  105. return $total_stats;
  106. }
  107. }