QrcodeController.php
3.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php
namespace app\wx\controllers;
use common\helpers\CheckActiveHelper;
use common\helpers\Log;
use domain\smart\ScanRecords;
use domain\smart\SellerInputRecordRepository;
use Yii;
use stdClass;
/**
* qrcode-控制器
* Class QrcodeController
* @package app\wx\controllers
*/
class QrcodeController extends BaseController
{
/**
* @throws yii\web\BadRequestHttpException
*/
public function init()
{
parent::init(); // TODO: Change the autogenerated stub
$this->checkClientStatus();
$this->handleMallAccessCtrl();
}
/**
* @return string
* @return string HTML
*/
public function actionIndex()
{
$uuid = Yii::$app->request->get("uuid");
// 判断路径中是否存在UUID
/*if (empty($uuid)) {
$this->jumpError();
}
if (strstr($uuid, "@") === false) {
$this->jumpError();
}
$explodArrar = explode("@", $uuid);
if (empty($explodArrar)) {
$this->jumpError();
}
$uuid = $explodArrar[0];*/
// @todo 校验UUID是否有效 -2 无效 0 有效未激活 2 有效已激活
$startTime = microtime(true);
$result = CheckActiveHelper::getAppCheck($uuid, "");
$etime=microtime(true);//获取程序执行结束的时间
$total=$etime-$startTime; //计算差值
Log::DEBUG("调用检查接口结果[uuid=$uuid]:" . json_encode($result) . '执行时间:' . $total . "秒");
if (isset($result["code"])) {
if ($result["code"] == 2) {
$hasRecord = SellerInputRecordRepository::findOne(["uuid" => $uuid]);
if (empty($hasRecord)) {
Log::DEBUG("执行跳转code={2},未存记录");
$this->jumpActive($uuid);
} else {
Log::DEBUG("执行跳转code={2},已存记录");
// 记录扫码次数
$scanCount = ScanRecords::updateCount($uuid);
$scanCount = $scanCount ? $scanCount : 1;
$this->jumpScanCount($uuid, $scanCount);
}
} else if ($result["code"] == 0) {
Log::DEBUG("执行跳转code={0},跳转到激活页");
$this->jumpActive($uuid);
} else {
$this->jumpError();
}
} else {
$this->jumpError();
}
}
/**
* 跳转到错误页面
*/
private function jumpError()
{
$jumpUrl = Yii::$app->params["baseUrl"]."/check#error/0";
header("Location: $jumpUrl");exit;
}
/**
* 跳转到扫码次数页面
*/
private function jumpScanCount($uuid, $scanCount)
{
$jumpUrl = Yii::$app->params["baseUrl"] . "?jumpmodel=check&jumppath=scan-count/" . $uuid . "/" . $scanCount;
header("Location: $jumpUrl");exit;
}
/**
* 跳转到激活页面
*/
private function jumpActive($uuid)
{
$jumpUrl = Yii::$app->params["baseUrl"] . "?jumpmodel=smart&jumppath=enter/" . $uuid ;
header("Location: $jumpUrl");exit;
}
}