123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- <?php
- class orderstatsControl extends SystemControl
- {
- public function __construct()
- {
- parent::__construct();
- }
- public function indexOp()
- {
- $type = $_GET['type'] ?? 'system';
- $page = "{$type}.order.stats";
- $model_refill_order = Model('refill_order');
- $condition['type'] = $type;
- if (!empty($_GET['cid'])) {
- $condition['cid'] = ['in', $_GET['cid']];
- }
- if (!empty($_GET['order_time_type'])) {
- $condition['order_time_type'] = $_GET['order_time_type'];
- }
- $start_unixtime = intval(strtotime($_GET['query_start_time']));
- $end_unixtime = intval(strtotime($_GET['query_end_time']));
- if ($start_unixtime > 0 && $end_unixtime > $start_unixtime) {
- $condition['time_stamp'] = [['egt', $start_unixtime], ['lt', $end_unixtime], 'and'];
- } elseif ($start_unixtime > 0) {
- $condition['time_stamp'] = ['egt', $start_unixtime];
- } elseif ($end_unixtime > 0) {
- $condition['time_stamp'] = ['lt', $end_unixtime];
- }
- $stats_list = $model_refill_order->getOrderStatsList($condition, 50, '*', 'time_stamp desc, cname asc');
- if($type == 'merchant') {
- foreach ($stats_list as $key => $stats) {
- $time = date("Y-m-d",$stats['time_stamp']+86400);
- $mch_cache = rcache("merchant_balance_{$time}", 'refill-');
- $caches = empty($mch_cache['data']) ? [] : unserialize($mch_cache['data']);
- if(empty($caches)) continue;
- $stats_list[$key]['available'] = ncPriceFormat($caches[$stats['cid']]) ?? '';
- }
- }
-
- $total_stats = $this->stats($stats_list);
- $order_time_type_text = ['notify_time' => '回调时间', 'order_time' => '下单时间'];
- Tpl::output('total_stats', $total_stats);
- Tpl::output('stats_list', $stats_list);
- Tpl::output('order_time_type_text', $order_time_type_text);
- Tpl::output('show_page', $model_refill_order->showpage());
- Tpl::showpage($page);
- }
- public function ExportDataOp()
- {
- $type = $_GET['type'] ?? 'system';
- $model_refill_order = Model('refill_order');
- $condition['type'] = $type;
- if (!empty($_GET['cid'])) {
- $condition['cid'] = ['in', $_GET['cid']];
- }
- if (!empty($_GET['order_time_type'])) {
- $condition['order_time_type'] = $_GET['order_time_type'];
- }
- $start_unixtime = intval($_GET['query_start_time']);
- $end_unixtime = intval($_GET['query_end_time']);
- if ($start_unixtime > 0 && $end_unixtime > $start_unixtime) {
- $condition['time_stamp'] = [['egt', $start_unixtime], ['lt', $end_unixtime], 'and'];
- } elseif ($start_unixtime > 0) {
- $condition['time_stamp'] = ['egt', $start_unixtime];
- } elseif ($end_unixtime > 0) {
- $condition['time_stamp'] = ['lt', $end_unixtime];
- }
- $stats_list = $this->all_orderstats_data($condition);
- $total_stats = $this->stats($stats_list);
- $stats = $total_stats[$_GET['order_time_type']];
- if(empty($stats)) {
- $stats = $total_stats['notify_time'];
- }
- $result['data'] = $stats_list;
- $result['total_stats'] = $stats;
- echo(json_encode($result));
- exit;
- }
- private function stats($stats_list): array
- {
- $order_time_type = ['notify_time','order_time'];
- foreach ($order_time_type as $type){
- $success_count_total = $success_refill_amounts_total = $success_mch_amounts_total = $success_channel_amounts_total = $profit_amounts_total = 0;
- foreach ($stats_list as $stats) {
- if($stats['order_time_type'] != $type) continue;
- $success_count_total += $stats['success_count'];
- $success_refill_amounts_total += $stats['success_refill_amounts'];
- $success_mch_amounts_total += $stats['success_mch_amounts'];
- $success_channel_amounts_total += $stats['success_channel_amounts'];
- $profit_amounts_total += $stats['profit_amounts'];
- }
- $total_stats[$type] = [
- 'success_count_total' => ncPriceFormat($success_count_total),
- 'success_refill_amounts_total' => ncPriceFormat($success_refill_amounts_total),
- 'success_mch_amounts_toatl' => ncPriceFormat($success_mch_amounts_total),
- 'success_channel_amounts_total' => ncPriceFormat($success_channel_amounts_total),
- 'profit_amounts_total' => ncPriceFormat($profit_amounts_total)
- ];
- }
- return $total_stats;
- }
- private function all_orderstats_data($condition): array
- {
- $i = 0;
- $result = [];
- while (true) {
- $start = $i * 1000;
- $list = Model('')->table('refill_stats')->field('*')
- ->where($condition)->order('time_stamp desc')->limit("{$start},1000")->select();
- if (empty($list)) {
- break;
- }
- $i++;
- foreach ($list as $value) {
- $result[] = $value;
- }
- }
- return $result;
- }
- }
|