12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- <?php
- namespace App\Console\Repair;
- use App\Models\CustomerDetails;
- use Illuminate\Console\Command;
- class CustomerTagRepair extends Command
- {
- protected $signature = 'CustomerTagRepair {type?}';
- protected $description = '客户标签添加占位符处理';
- public function __construct()
- {
- parent::__construct();
- }
- public function handle() {
- $type = intval($this->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]);
- }
- }
- }
|