|
@@ -42,48 +42,66 @@ class card_keylistcontrol extends BaseSellerControl
|
|
|
public function statsOp()
|
|
|
{
|
|
|
$condition = ['card_id' => ['gt', 0]];
|
|
|
- if (in_array($_GET['card_state'], ['0', '1', '2', '3'])) {
|
|
|
- $condition['card_state'] = $_GET['card_state'];
|
|
|
- }
|
|
|
|
|
|
$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 => '中国电信'];
|
|
|
- $data = $stats = [];
|
|
|
+ $stats = [];
|
|
|
foreach ($items as $item) {
|
|
|
$card_count += $item['card_count'];
|
|
|
- $item['card_type_text'] = $card_type_texts[$item['card_type']];
|
|
|
+ $card_type = $item['card_type'];
|
|
|
$item['amount'] = intval($item['amount']);
|
|
|
- $key = "{$item['card_type_text']}-{$item['amount']}元";
|
|
|
+ $item['card_amounts'] = intval($item['card_amounts']);
|
|
|
+ $key = "{$card_type_texts[$card_type]}-{$item['amount']}元";
|
|
|
$stats[$key][] = $item;
|
|
|
}
|
|
|
-
|
|
|
- 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;
|
|
|
- }
|
|
|
- if(empty($data[$key]['ReserveCardCount'])) {
|
|
|
- $data[$key]['ReserveCardCount'] = $stat['card_state'] == mtopcard\ReserveCard ? $stat['card_count'] : 0;
|
|
|
- }
|
|
|
- if(empty($data[$key]['AssignedCardCount'])) {
|
|
|
- $data[$key]['AssignedCardCount'] = $stat['card_state'] == mtopcard\AssignedCard ? $stat['card_count'] : 0;
|
|
|
+ $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;
|
|
|
+ }
|
|
|
}
|
|
|
- if(empty($data[$key]['FreezedCardCount'])) {
|
|
|
- $data[$key]['FreezedCardCount'] = $stat['card_state'] == mtopcard\FreezedCard ? $stat['card_count'] : 0;
|
|
|
- }
|
|
|
- $data[$key]['amount'] = $stat['amount'];
|
|
|
}
|
|
|
+ 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);
|
|
|
Tpl::output('card_count', $card_count);
|
|
|
Tpl::output('stats', $data);
|
|
|
+ Tpl::output('totals', $total);
|
|
|
Tpl::showpage('card_key.stats');
|
|
|
}
|
|
|
|