80 lines
2.7 KiB
PHP
80 lines
2.7 KiB
PHP
<?php
|
|
|
|
|
|
namespace app\common\command;
|
|
|
|
|
|
use think\console\Command;
|
|
use think\console\Input;
|
|
use think\console\Output;
|
|
use app\admin\model\ReloadDb;
|
|
use think\Db;
|
|
class AdminMsg extends Command
|
|
{
|
|
protected function configure()
|
|
{
|
|
$this->setName('admin-msg')
|
|
->setDescription('后台发布消息队列'); //
|
|
}
|
|
|
|
/**
|
|
* 清理过期装扮
|
|
* @param Input $input
|
|
* @param Output $output
|
|
* @return int|void|null
|
|
* @throws \think\Exception
|
|
* @throws \think\exception\PDOException
|
|
*/
|
|
protected function execute(Input $input, Output $output)
|
|
{
|
|
// set_time_limit(0);
|
|
ini_set ('memory_limit', '128M');
|
|
//循环监控队列数据
|
|
while (true) {
|
|
//超时重新链接
|
|
ReloadDb::init();
|
|
//取出队列数据
|
|
$redis = connectionRedis();
|
|
$data = $redis->lPop('admin_add_message111');
|
|
//查询到队列数据
|
|
if (!empty($data)) {
|
|
$data = explode('-61116-', $data);
|
|
if (count($data) == 3) {
|
|
$smid = (int)$data[0];
|
|
$title = $data[1];
|
|
$content = $data[2];
|
|
//获取所有会员id
|
|
$now_time = time();
|
|
for ($i=1;$i>0;$i++){
|
|
//分页查询
|
|
$uid_list = db::name('user')->order('uid','asc')->page($i,100)->column('uid');
|
|
if(empty($uid_list)){
|
|
//查询不到数据 跳出循环
|
|
break;
|
|
}
|
|
//录入成员数据
|
|
$insert_data = [];
|
|
foreach ($uid_list as $k => $v) {
|
|
$data = [];
|
|
$data['type'] = 1;
|
|
$data['id'] = $smid;
|
|
$data['uid'] = $v;
|
|
$data['title'] = $title;
|
|
$data['content'] = $content;
|
|
$data['is_read'] = 1;
|
|
$data['read_time'] = 0;
|
|
$data['add_time'] = $now_time;
|
|
$data['update_time'] = $now_time;
|
|
$insert_data[] = $data;
|
|
}
|
|
if (!empty($insert_data)) {
|
|
db::name('user_message')->insertAll($insert_data);
|
|
}
|
|
}
|
|
echo '后台系统消息发布成功'.date('Y-m-d H:i:s').PHP_EOL;;
|
|
}
|
|
}
|
|
sleep(3);
|
|
}
|
|
}
|
|
} |