argument('type')); try{ $startId = 0; while(true) { $this->info(date('H:i:s').' 开始处理从'.$startId.'开始的数据'); $customerList = CustomerDetails::suffix($type)->where('id', '>', $startId)->select(['id', 'tag_list'])->limit(1000)->get(); if($customerList->isEmpty()) { $this->info('处理完成'); break; } $startId = $customerList->max('id'); $this->deal($customerList, $type); } } catch (\Exception $exception) { $this->error($exception->getFile().'('.$exception->getLine().'):'.$exception->getMessage()); } } public function deal($customerList, $type) { foreach($customerList as $customerInfo) { if(!empty($customerInfo->tag_list)) { $tagList = explode(',', $customerInfo->tag_list); if(in_array('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', $tagList)) { continue; } $tagList[] = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'; $newTagList = implode(',', array_values(array_unique($tagList))); } else { $newTagList = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'; } CustomerDetails::suffix($type)->where('id', $customerInfo->id)->update(['tag_list' => $newTagList]); } } }