Commit 95e814ff by 杨树贤

每天10点定时重置可兑换商品数额

parent 7f2b8d27
<?php
namespace App\Console\Commands;
use Common\Model\RedisModel;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;
class ResetExchangeSetting extends Command
{
// 供我们调用命令
protected $signature = 'ic:reset_exchange_setting';
// 命令的描述
protected $description = '定时重置商品兑换的配额';
// 最终执行的方法
public function handle()
{
// 在命令行打印一行信息
$this->info("开始查找...");
//重置商品可兑换限额
//先从redis缓存里面去取需要的数据
$redis = new RedisModel();
$settings = $redis->hgetall('ic_exchange_settings');
//获取到所有配置项之后,就要根据配置项里面的stock字段更新对应的列表
//列表形式为ic_exchange_setting_{$id},然后这个键是list类型,里面简单存1就好
foreach ($settings as $key => $setting) {
$setting = json_decode($setting, true);
$id = $setting['id'];
//先去删除原有的
$redis->del('ic_exchange_settings_' . $id);
$data = array_fill(0, $setting['stock'], 1);
$redis->lpush('ic_exchange_settings_' . $id, $data);
}
$this->info("执行成功!");
}
}
\ No newline at end of file
......@@ -2,6 +2,7 @@
namespace App\Console;
use App\Console\Commands\ResetExchangeSetting;
use Illuminate\Console\Scheduling\Schedule;
use Laravel\Lumen\Console\Kernel as ConsoleKernel;
......@@ -14,16 +15,18 @@ class Kernel extends ConsoleKernel
*/
protected $commands = [
//
ResetExchangeSetting::class,
];
/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
{
//
$schedule->command('ic:reset_exchange_setting')->dailyAt('10:00');
}
}
......@@ -32,10 +32,10 @@ return [
//],
],
'timer' => [
'enable' => false,
'jobs' => [
'enable' => true,
'jobs' => [
// Enable LaravelScheduleJob to run `php artisan schedule:run` every 1 minute, replace Linux Crontab
//\Hhxsv5\LaravelS\Illuminate\LaravelScheduleJob::class,
\Hhxsv5\LaravelS\Illuminate\LaravelScheduleJob::class,
// Two ways to configure parameters:
// [\App\Jobs\XxxCronJob::class, [1000, true]], // Pass in parameters when registering
// \App\Jobs\XxxCronJob::class, // Override the corresponding method to return the configuration
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment