86 lines
2.2 KiB
PHP
86 lines
2.2 KiB
PHP
<?php
|
|
/**
|
|
* @link http://www.yiiframework.com/
|
|
* @copyright Copyright (c) 2008 Yii Software LLC
|
|
* @license http://www.yiiframework.com/license/
|
|
*/
|
|
|
|
namespace app\commands;
|
|
|
|
use app\components\YopointApi;
|
|
use app\models\BallCart;
|
|
use app\models\BallMark;
|
|
use app\models\Order;
|
|
use app\models\Signing;
|
|
use app\models\YopointNotify;
|
|
use app\modules\api\components\Mqtt;
|
|
use yii\console\Controller;
|
|
use yii\console\ExitCode;
|
|
use \PhpMqtt\Client\MQTTClient;
|
|
use \PhpMqtt\Client\ConnectionSettings;
|
|
use app\models\Store;
|
|
|
|
/**
|
|
* This command echoes the first argument that you have entered.
|
|
*
|
|
* This command is provided as an example for you to learn how to create console commands.
|
|
*
|
|
* @author Qiang Xue <qiang.xue@gmail.com>
|
|
* @since 2.0
|
|
*/
|
|
class Script1minController extends Controller
|
|
{
|
|
/**
|
|
* This command echoes what you have entered as the message.
|
|
* @param string $message the message to be echoed.
|
|
* @return int Exit code
|
|
*/
|
|
public function actionIndex()
|
|
{
|
|
$redis_name = "cxaibc:console:script1min_lock";
|
|
try {
|
|
$get = \Yii::$app->redis->setnx($redis_name, 1);
|
|
if (empty($get)) {
|
|
$ttl = \Yii::$app->redis->ttl($redis_name);
|
|
if ($ttl === -1) {
|
|
\Yii::$app->redis->expire($redis_name, 60);
|
|
}
|
|
var_dump("1分钟脚本正在执行中");
|
|
exit();
|
|
}
|
|
\Yii::$app->redis->expire($redis_name, 60 * 10);
|
|
// 执行体
|
|
$this->signingCancel();
|
|
// 结束执行
|
|
\Yii::$app->redis->del($redis_name);
|
|
} catch (\Exception $e) {
|
|
\Yii::$app->redis->del($redis_name);
|
|
var_dump($e->getMessage());
|
|
}
|
|
echo "1分钟脚本";
|
|
exit();
|
|
}
|
|
|
|
|
|
public function signingCancel()
|
|
{
|
|
$signings = Signing::find()->where(['status' => '0'])->all();
|
|
|
|
foreach ($signings as $item) {
|
|
|
|
$time = time() - $item->create_time;
|
|
|
|
if ($time > 600) {
|
|
$signing = Signing::findOne($item->id);
|
|
$signing->status = 4;
|
|
$signing->reason = '超时未支付';
|
|
$signing->save();
|
|
}
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
}
|