123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- <?php
- namespace app\admin\command;
- use app\common\library\Rabbitmq;
- use app\common\library\Ssdb;
- use PhpAmqpLib\Message\AMQPMessage;
- use think\console\Command;
- use think\console\Input;
- use think\console\Output;
- use think\Log;
- use think\Request;
- class UpdateCustom extends Command
- {
- protected function configure()
- {
- $this->setName('UpdateCustom')
- ->setDescription('刷新Custom的MessageJson数据');
- }
- /**
- * 入口方法
- *
- * @param Input $input
- * @param Output $output
- * @return int|null|void
- */
- protected function execute(Input $input, Output $output)
- {
- //cli模式下无法获取到当前的项目模块,手动指定一下
- Request::instance()->module('admin');
- $total = 0;
- $map['id'] = ['>=',1];
- //一次最多转移100个
- while($list = model('Custom')->where($map)->limit(10)->column('id,message_json')){
- $keys = array_keys($list);
- $map['id'] = ['>',end($keys)];
- if($list){
- foreach($list as $key => $val){
- $json = is_array($val) == true ? $val : json_decode($val);
- if($json){
- if(!is_array($json)){
- $json = json_decode($json);
- }
- $data = array_shift($json);
- $data = json_encode(array($data),JSON_UNESCAPED_UNICODE);
- if(false !== model('Custom')->where('id',$key)->update(['message_json'=>'"'.addslashes($data).'"'])){
- $total++;
- $output->info('数据更新成功,ID:'.$key.' Source:'.json_encode($val).' Update:'.$data);
- }else{
- $output->info('数据更新失败,ID:'.$key.' 写入失败');
- }
- }else{
- $output->error('数据更新失败,MAP:'.var_export($map,true).' 空数据');
- }
- }
- }
- usleep(1000);
- }
- $output->info('数据更新结束,共计更新数据:'.$total.'条');
- }
- }
|