123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- <?php
- require_once(BASE_HELPER_PATH . '/mtopcard/mtopcard.php');
- class card_keyControl extends SystemControl
- {
- public function __construct()
- {
- parent::__construct();
- }
- public function statsOp()
- {
- $condition = ['card_id' => ['gt', 0]];
- $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['assigned_time'] = [ ['egt', $start_unixtime] , ['lt', $end_unixtime] , 'and'];
- }
- elseif ($start_unixtime > 0) {
- $condition['assigned_time'] = ['egt', $start_unixtime];
- }
- elseif ($end_unixtime > 0) {
- $condition['assigned_time'] = ['lt', $end_unixtime];
- }
- if(!empty($_GET['store_id'])) {
- $condition['store_id'] = $_GET['store_id'];
- }
- $items = Model('')->table('card_key')
- ->field('card_type, amount, card_state, count(*) as card_count, sum(amount) as card_amounts')
- ->where($condition)
- ->group('card_type,amount,card_state')
- ->order('card_type asc, amount asc, card_state asc')
- ->select();
- $card_count = 0;
- $card_type_texts = [1 => '中石油', 2 => '中石化', 4 => '中国移动', 5 => '中国联通', 6 => '中国电信'];
- $stats = [];
- foreach ($items as $item) {
- $card_count += $item['card_count'];
- $card_type = $item['card_type'];
- $item['amount'] = intval($item['amount']);
- $item['card_amounts'] = intval($item['card_amounts']);
- $key = "{$card_type_texts[$card_type]}-{$item['amount']}元";
- $stats[$key][] = $item;
- }
- $card_state_stats = function($stats) {
- $data = [];
- foreach ($stats as $key => $value) {
- foreach ($value as $stat) {
- if (empty($data[$key]['UnusedCardCount'])) {
- $data[$key]['UnusedCardCount'] = $stat['card_state'] == mtopcard\UnusedCard ? $stat['card_count'] : 0;
- $data[$key]['UnusedCardAmounts'] = $stat['card_state'] == mtopcard\UnusedCard ? $stat['card_amounts'] : 0;
- }
- if (empty($data[$key]['ReserveCardCount'])) {
- $data[$key]['ReserveCardCount'] = $stat['card_state'] == mtopcard\ReserveCard ? $stat['card_count'] : 0;
- $data[$key]['ReserveCardAmounts'] = $stat['card_state'] == mtopcard\ReserveCard ? $stat['card_amounts'] : 0;
- }
- if (empty($data[$key]['AssignedCardCount'])) {
- $data[$key]['AssignedCardCount'] = $stat['card_state'] == mtopcard\AssignedCard ? $stat['card_count'] : 0;
- $data[$key]['AssignedCardAmounts'] = $stat['card_state'] == mtopcard\AssignedCard ? $stat['card_amounts'] : 0;
- }
- if (empty($data[$key]['FreezedCardCount'])) {
- $data[$key]['FreezedCardCount'] = $stat['card_state'] == mtopcard\FreezedCard ? $stat['card_count'] : 0;
- $data[$key]['FreezedCardAmounts'] = $stat['card_state'] == mtopcard\FreezedCard ? $stat['card_amounts'] : 0;
- }
- }
- }
- return $data;
- };
- $data = $card_state_stats($stats);
- $totals = [];
- $items = Model('')->table('card_key')
- ->field('card_type, card_state, count(*) as card_count, sum(amount) as card_amounts')
- ->where($condition)
- ->group('card_type,card_state')
- ->order('card_type asc, card_state asc')
- ->select();
- foreach ($items as $item) {
- $card_type = $item['card_type'];
- $key = "{$card_type_texts[$card_type]}-总计:";
- $totals[$key][] = $item;
- }
- $total = $card_state_stats($totals);
- $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);
- Tpl::output('card_count', $card_count);
- Tpl::output('stats', $data);
- Tpl::output('totals', $total);
- Tpl::showpage('card_key.stats');
- }
- }
|