|
@@ -2,9 +2,11 @@
|
|
|
|
|
|
|
|
namespace tw\command;
|
|
namespace tw\command;
|
|
|
|
|
|
|
|
|
|
+use app\admin\model\store\StoreProduct;
|
|
|
use app\admin\model\store\StoreProductAttr;
|
|
use app\admin\model\store\StoreProductAttr;
|
|
|
use app\admin\model\store\StoreProductAttrResult;
|
|
use app\admin\model\store\StoreProductAttrResult;
|
|
|
use app\admin\model\store\StoreProductAttrValue;
|
|
use app\admin\model\store\StoreProductAttrValue;
|
|
|
|
|
+use app\admin\model\system\SystemLog;
|
|
|
use app\models\store\StoreProductRule;
|
|
use app\models\store\StoreProductRule;
|
|
|
use think\console\Command;
|
|
use think\console\Command;
|
|
|
use think\console\Input;
|
|
use think\console\Input;
|
|
@@ -260,7 +262,25 @@ class Maintain extends Command
|
|
|
*/
|
|
*/
|
|
|
protected function prod()
|
|
protected function prod()
|
|
|
{
|
|
{
|
|
|
- console::log(__FUNCTION__);
|
|
|
|
|
|
|
+ $now = time();
|
|
|
|
|
+ $days = Config::get('app.off_days_before', 30);
|
|
|
|
|
+ $days_ago = $now - $days * SECONDS_OF_ONEDAY;
|
|
|
|
|
+ // 找到过期商品
|
|
|
|
|
+ $products = StoreProduct::where([
|
|
|
|
|
+ 'is_del' => 0,
|
|
|
|
|
+ 'is_show' => 1,
|
|
|
|
|
+ ])->where('add_time', '<', $days_ago)
|
|
|
|
|
+ ->select()->toArray();
|
|
|
|
|
+ // 下架
|
|
|
|
|
+ $ids = [];
|
|
|
|
|
+ foreach ($products as $p) {
|
|
|
|
|
+ array_push($ids, $p['id']);
|
|
|
|
|
+ }
|
|
|
|
|
+ $ret = Storeproduct::where('id', 'in', $ids)->update([
|
|
|
|
|
+ 'is_show' => 0,
|
|
|
|
|
+ ]);
|
|
|
|
|
+ // 记录日志
|
|
|
|
|
+ warnlog("auto off-shelves executed: $ret" . json_encode($ids));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -277,6 +297,15 @@ class Maintain extends Command
|
|
|
*/
|
|
*/
|
|
|
protected function backup()
|
|
protected function backup()
|
|
|
{
|
|
{
|
|
|
|
|
+ $db = config('database.connections.' . config('database.default'));
|
|
|
|
|
+ $user = $db['username'];
|
|
|
|
|
+ $password = $db['password'];
|
|
|
|
|
+ $host = $db['hostname'];
|
|
|
|
|
+ $database = $db['database'];
|
|
|
|
|
+ $now = time();
|
|
|
|
|
+ $dir = "backup-$now.sql";
|
|
|
|
|
+ exec("mysqldump --user={$user} --password={$password} --host={$host} {$database} --result-file={$dir} 2>&1", $output);
|
|
|
|
|
+ warnlog('backup database:' . json_encode($output));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
protected function none()
|
|
protected function none()
|