瀏覽代碼

维护服务中活动状态的脚本

wufeng 2 年之前
父節點
當前提交
f81cf8e398
共有 1 個文件被更改,包括 52 次插入0 次删除
  1. 52 0
      app/admin/command/HandleServiceStatus.php

+ 52 - 0
app/admin/command/HandleServiceStatus.php

@@ -0,0 +1,52 @@
+<?php declare(strict_types=1);
+
+namespace app\admin\command;
+
+use app\model\CommonModel;
+use app\model\ServiceModel;
+use think\console\Command;
+use think\console\Input;
+use think\console\Output;
+use think\facade\Cache;
+
+
+//处理服务的活动状态
+class HandleServiceStatus extends Command
+{
+
+    protected function configure()
+    {
+//        parent::configure(); // TODO: Change the autogenerated stub
+        $this->setName('HandleServiceStatus')->setDescription('处理服务的活动状态');
+
+    }
+
+
+    protected function execute(Input $input, Output $output)
+    {
+
+        $key = 'handle_service_status';
+        $redis = Cache::store('redis')->get($key);
+
+        if (!$redis) {
+
+            Cache::set($key, 1, 60);
+
+            $date = date('Y-m-d H:i:s');
+
+            ServiceModel::where('is_del', CommonModel::$del_normal)
+                ->where('starttime', '<=', $date)
+                ->where('endtime', '>', $date)
+                ->save(['activity_status' => ServiceModel::$activity_status_ing, 'updaterid' => 0, 'updater' => '脚本', 'updatetime' => $date]);
+
+            ServiceModel::where('is_del', CommonModel::$del_normal)
+                ->where('endtime', '<', $date)
+                ->save(['activity_status' => ServiceModel::$activity_status_end, 'updaterid' => 0, 'updater' => '脚本', 'updatetime' => $date]);
+
+            Cache::set($key, 0);
+        }
+
+    }
+
+
+}