123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- <?php
- class orderstatsControl extends SystemControl
- {
- public function __construct()
- {
- parent::__construct();
- }
- public function indexOp()
- {
- $type = $_GET['type'] ? $_GET['type'] : 'system';
- $page = "{$type}.order.stats";
- $model_refill_order = Model('refill_order');
- $condition['type'] = $type;
- if (!empty($_GET['cid'])) {
- $condition['cid'] = $_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);
- if ($type == 'provider') {
- $provider_list = Model('')->table('refill_provider,store')->field('refill_provider.store_id,store.store_name')->join('inner')
- ->on('store.store_id=refill_provider.store_id')->limit(1000)->select();
- Tpl::output('provider_list', $provider_list);
- } elseif ($type == 'merchant') {
- $merchant_list = Model('')->table('merchant')->limit(1000)->select();
- Tpl::output('merchant_list', $merchant_list);
- }
- $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'] ? $_GET['type'] : 'system';
- $model_refill_order = Model('refill_order');
- $condition['type'] = $type;
- if (!empty($_GET['cid'])) {
- $condition['cid'] = $_GET['cid'];
- }
- $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 = $model_refill_order->getOrderStatsList($condition,'','*','time_stamp asc');
- $success_count_total = $success_refill_amounts_total = $success_mch_amounts_total = $success_channel_amounts_total = $profit_amounts_total = 0;
- foreach ($stats_list as $stats) {
- $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 = [
- '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)
- ];
- $result['data'] = $stats_list;
- $result['total_stats'] = $total_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' => $success_count_total,
- 'success_refill_amounts_total' => $success_refill_amounts_total,
- 'success_mch_amounts_toatl' => $success_mch_amounts_total,
- 'success_channel_amounts_total' => $success_channel_amounts_total,
- 'profit_amounts_total' => $profit_amounts_total
- ];
- }
- return $total_stats;
- }
- }
|