* @since 2.0 */ class Script5minController 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:script5min_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("5分钟脚本正在执行中"); exit(); } \Yii::$app->redis->expire($redis_name,60*10); // 执行体 $this->syncDeviceList(); $this->YopointPayCall(); // 结束执行 \Yii::$app->redis->del($redis_name); }catch (\Exception $e){ \Yii::$app->redis->del($redis_name); var_dump($e->getMessage()); } echo "5分钟脚本"; exit(); } // 同步 public function syncDeviceList(){ $obj = new YopointApi(); $res = $obj->syncDeviceList(); var_dump($res); $res = $obj->syncStockList(); var_dump($res); } // 友朋支付回调 public function YopointPayCall(){ var_dump("友朋支付回调"); $select = Order::find()->andWhere([ 'is_pay' => 1, 'plugin_sign' => 'goods', 'yopoint_status' => 1, ])->asArray()->all(); $obj = new YopointApi(); foreach ($select as $key=>$val){ // 查找友朋回调接口 $find_yopoint = YopointNotify::findOne([ 'id' => $val['yopoint_notify_id'], ]); if(!empty($find_yopoint->return_data)){ $json_de = json_decode($find_yopoint->return_data,true); $obj->openDevCall($json_de['data']['NotifyUrl'],$json_de['data']['ReceiptNo'],$val['order_no'],1); } } } }