|
@@ -0,0 +1,174 @@
|
|
|
+<?php
|
|
|
+defined('InShopNC') or exit('Access Invalid!');
|
|
|
+
|
|
|
+require_once(BASE_HELPER_PATH . '/mtopcard/mtopcard.php');
|
|
|
+
|
|
|
+class card_keylistcontrol extends BaseSellerControl
|
|
|
+{
|
|
|
+ public function __construct()
|
|
|
+ {
|
|
|
+ parent::__construct();
|
|
|
+ }
|
|
|
+
|
|
|
+ public function listOp()
|
|
|
+ {
|
|
|
+ $mod_card = Model('card_key');
|
|
|
+ if (!empty($_GET['card_type'])) {
|
|
|
+ $condition['card_type'] = $_GET['card_type'];
|
|
|
+ }
|
|
|
+ if (!empty($_GET['card_no'])) {
|
|
|
+ $condition['card_no'] = $_GET['card_no'];
|
|
|
+ }
|
|
|
+ if (!empty($_GET['card_state'])) {
|
|
|
+ $condition['card_state'] = $_GET['card_state'];
|
|
|
+ }
|
|
|
+ $cards = $mod_card->getCardsList($condition, 15);
|
|
|
+ $card_state_text = ['未使用', '充值中', '已使用', '冻结'];
|
|
|
+ $card_type_texts = [1 => '中石油', 2 => '中石化', 4 => '中国移动', 5 => '中国联通', 6 => '中国电信'];
|
|
|
+ foreach ($cards as $key => $card) {
|
|
|
+ $cards[$key]['card_state_text'] = $card_state_text[$card['card_state']];
|
|
|
+ $cards[$key]['card_type_text'] = $card_type_texts[$card['card_type']];
|
|
|
+ }
|
|
|
+ Tpl::output('cards', $cards);
|
|
|
+ Tpl::output('show_page', $mod_card->showpage());
|
|
|
+ Tpl::showpage('card_key.list');
|
|
|
+ }
|
|
|
+
|
|
|
+ public function statsOp()
|
|
|
+ {
|
|
|
+ $condition = [];
|
|
|
+ if (!empty($_GET['card_state'])) {
|
|
|
+ $condition['card_state'] = $_GET['card_state'];
|
|
|
+ }
|
|
|
+ $counts = Model('')->table('card_key')
|
|
|
+ ->field('count(*) as card_count, card_type, amount')
|
|
|
+ ->where($condition)
|
|
|
+ ->group('card_type,amount')
|
|
|
+ ->select();
|
|
|
+ $card_count = 0;
|
|
|
+ $card_type_texts = [1 => '中石油', 2 => '中石化', 4 => '中国移动', 5 => '中国联通', 6 => '中国电信'];
|
|
|
+ $stats = [];
|
|
|
+ foreach ($counts as $key => $count) {
|
|
|
+ $card_count += $count['card_count'];
|
|
|
+ $count['card_type_text'] = $card_type_texts[$count['card_type']];
|
|
|
+ $count['amount'] = intval($count['amount']);
|
|
|
+ $stats[$count['card_type']][] = $count;
|
|
|
+ }
|
|
|
+ Tpl::output('card_count', $card_count);
|
|
|
+ Tpl::output('stats', $stats);
|
|
|
+ Tpl::showpage('card_key.stats');
|
|
|
+ }
|
|
|
+
|
|
|
+ public function editOp()
|
|
|
+ {
|
|
|
+ $card_id = $_GET['card_id'] ?? $_POST['card_id'];
|
|
|
+ $mod_card = Model('card_key');
|
|
|
+ $card = $mod_card->getCards(['card_id' => $card_id]);
|
|
|
+ if (empty($card)) {
|
|
|
+ showDialog('卡密不存在', 'reload', 'error');
|
|
|
+ }
|
|
|
+ if ($card['card_state'] != mtopcard\FreezedCard && !empty($card_state)) {
|
|
|
+ showDialog('非冻结状态下,不可更改卡密使用状态', 'reload', 'error');
|
|
|
+ }
|
|
|
+ $card = $card[0];
|
|
|
+ $card_state_text = ['未使用', '暂时绑定', '已绑定', '冻结'];
|
|
|
+ $card_type_texts = [1 => '中石油', 2 => '中石化', 4 => '中国移动', 5 => '中国联通', 6 => '中国电信'];
|
|
|
+ $cards['card_state_text'] = $card_state_text[$card['card_state']];
|
|
|
+ $cards['card_type_text'] = $card_type_texts[$card['card_type']];
|
|
|
+ if (chksubmit()) {
|
|
|
+ $card_type = $_POST['card_type'];
|
|
|
+ $card_no = $_POST['card_no'];
|
|
|
+ $card_key = $_POST['card_key'];
|
|
|
+ $unfreeze = empty($_POST['unfreeze']) ? false : true;
|
|
|
+
|
|
|
+ [$state, $msg] = $this->checkCardKey($card_no, $card_key, $card_type);
|
|
|
+ if ($state == false) {
|
|
|
+ showDialog($msg, 'reload', 'error');
|
|
|
+ }
|
|
|
+ $check_card_no = $mod_card->getCards(['card_no' => $card_no, 'card_id' => ['neq', $card_id]]);
|
|
|
+ $check_card_key = $mod_card->getCards(['card_key' => $card_key, 'card_id' => ['neq', $card_id]]);
|
|
|
+ if (!empty($check_card_no) || !empty($check_card_key)) {
|
|
|
+ showDialog('此卡号或卡密已存在', 'reload', 'error');
|
|
|
+ }
|
|
|
+ $update['card_no'] = $card_no;
|
|
|
+ $update['card_key'] = $card_key;
|
|
|
+
|
|
|
+ try {
|
|
|
+ $trans = new trans_wapper($mod_card, __METHOD__);
|
|
|
+ $res = $mod_card->where(['card_id' => $card_id])->update($update);
|
|
|
+ $unfreeze_resp = true;
|
|
|
+ if ($unfreeze == true) {
|
|
|
+ $unfreeze_resp = mtopcard\cards_helper::unfreeze($card_id);
|
|
|
+ }
|
|
|
+ if ($res && $unfreeze_resp) {
|
|
|
+ $trans->commit();
|
|
|
+ showDialog('处理成功', 'index.php?act=card_keylist&op=list', 'succ');
|
|
|
+ } else {
|
|
|
+ $trans->rollback();
|
|
|
+ showDialog('处理失败', 'reload', 'error');
|
|
|
+ }
|
|
|
+ } catch (Exception $e) {
|
|
|
+ $trans->rollback();
|
|
|
+ showDialog('处理失败', 'reload', 'error');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Tpl::output('card', $card);
|
|
|
+ Tpl::showpage('card_key.edit');
|
|
|
+ }
|
|
|
+
|
|
|
+ public function editStateOp()
|
|
|
+ {
|
|
|
+ $card_id = $_GET['card_id'] ?? $_POST['card_id'];
|
|
|
+ $mod_card = Model('card_key');
|
|
|
+ $card = $mod_card->getCards(['card_id' => $card_id]);
|
|
|
+ if (empty($card)) {
|
|
|
+ showDialog('卡密不存在', 'reload', 'error');
|
|
|
+ }
|
|
|
+ if ($card['card_state'] != mtopcard\UnusedCard) {
|
|
|
+ showDialog('只有未使用的卡密可冻结', 'reload', 'error');
|
|
|
+ }
|
|
|
+
|
|
|
+ $res = mtopcard\cards_helper::manual_freeze($card_id, '手动冻结');
|
|
|
+ if ($res) {
|
|
|
+ showDialog('处理成功', 'index.php?act=card_keylist&op=list', 'succ');
|
|
|
+ } else {
|
|
|
+ showDialog('处理失败', 'reload', 'error');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private function checkCardKey($card_no, $card_key, $card_type)
|
|
|
+ {
|
|
|
+ switch ($card_type) {
|
|
|
+// case 1:
|
|
|
+// $card_no_check = '/^[0-9a-zA-Z]{17}$/';
|
|
|
+// $card_key_check = '/^[0-9a-zA-Z]{20}$/';
|
|
|
+// break;
|
|
|
+ case 2:
|
|
|
+ $card_no_check = '/^[0-9a-zA-Z]{16}$/';
|
|
|
+ $card_key_check = '/^[0-9a-zA-Z]{20}$/';
|
|
|
+ break;
|
|
|
+ case 4:
|
|
|
+ $card_no_check = '/^[0-9a-zA-Z]{17}$/';
|
|
|
+ $card_key_check = '/^[0-9a-zA-Z]{18}$/';
|
|
|
+ break;
|
|
|
+ case 5:
|
|
|
+ $card_no_check = '/^[0-9a-zA-Z]{15}$/';
|
|
|
+ $card_key_check = '/^[0-9a-zA-Z]{19}$/';
|
|
|
+ break;
|
|
|
+ case 6:
|
|
|
+ $card_no_check = '/^[0-9a-zA-Z]{19}$/';
|
|
|
+ $card_key_check = '/^[0-9a-zA-Z]{18}$/';
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ return [false, '卡种类型错误'];
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ if (!preg_match($card_no_check, $card_no, $matches)) {
|
|
|
+ return [false, "卡号:{$card_no}卡密:{$card_key},卡号验证错误"];
|
|
|
+ }
|
|
|
+ if (!preg_match($card_key_check, $card_key, $matches)) {
|
|
|
+ return [false, "卡号:{$card_no}卡密:{$card_key},卡密验证错误"];
|
|
|
+ }
|
|
|
+ return [true, 'success'];
|
|
|
+ }
|
|
|
+}
|