79 lines
2.2 KiB
PHP
79 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\Goods;
|
|
use app\models\Order;
|
|
use app\models\OrderDetail;
|
|
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 ScriptWhileOrderController extends Controller
|
|
{
|
|
public static $cx_mch_id=0;
|
|
|
|
/**
|
|
* 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_lock = "cxaibc:console:ScriptWhileOrderController_v4";
|
|
try {
|
|
$get = \Yii::$app->redis->setnx($redis_name_lock,1);
|
|
if(empty($get)){
|
|
var_dump("脚本正在执行中");
|
|
exit();
|
|
}
|
|
// 执行体
|
|
$redis_name = "cxgyc:YopointNotify:list";
|
|
$arr = [];
|
|
$yopoint_obj = new YopointApi();
|
|
while(true){
|
|
sleep(1);
|
|
$get = \Yii::$app->redis->rpop($redis_name);
|
|
if(empty($get)){
|
|
break;
|
|
}
|
|
$res = $yopoint_obj->syncOrder($get);
|
|
if(empty($res)){
|
|
continue;
|
|
}
|
|
$arr[] = $res;
|
|
}
|
|
foreach ($arr as $key=>$val){
|
|
// 重新写入
|
|
\Yii::$app->redis->lpush($redis_name,$val);
|
|
}
|
|
|
|
\Yii::$app->redis->del($redis_name_lock);
|
|
}catch (\Exception $e){
|
|
\Yii::$app->redis->del($redis_name_lock);
|
|
var_dump($e->getMessage());
|
|
}
|
|
echo "1分钟脚本";
|
|
exit();
|
|
}
|
|
}
|