企微短剧业务系统

CustomerTagRepair.php 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace App\Console\Repair;
  3. use App\Models\CustomerDetails;
  4. use Illuminate\Console\Command;
  5. class CustomerTagRepair extends Command
  6. {
  7. protected $signature = 'CustomerTagRepair {type?}';
  8. protected $description = '客户标签添加占位符处理';
  9. public function __construct()
  10. {
  11. parent::__construct();
  12. }
  13. public function handle() {
  14. $type = intval($this->argument('type'));
  15. try{
  16. $startId = 0;
  17. while(true) {
  18. $this->info(date('H:i:s').' 开始处理从'.$startId.'开始的数据');
  19. $customerList = CustomerDetails::suffix($type)->where('id', '>', $startId)->select(['id', 'tag_list'])->limit(1000)->get();
  20. if($customerList->isEmpty()) {
  21. $this->info('处理完成');
  22. break;
  23. }
  24. $startId = $customerList->max('id');
  25. $this->deal($customerList, $type);
  26. }
  27. } catch (\Exception $exception) {
  28. $this->error($exception->getFile().'('.$exception->getLine().'):'.$exception->getMessage());
  29. }
  30. }
  31. public function deal($customerList, $type) {
  32. foreach($customerList as $customerInfo) {
  33. if(!empty($customerInfo->tag_list)) {
  34. $tagList = explode(',', $customerInfo->tag_list);
  35. if(in_array('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', $tagList)) {
  36. continue;
  37. }
  38. $tagList[] = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa';
  39. $newTagList = implode(',', array_values(array_unique($tagList)));
  40. } else {
  41. $newTagList = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa';
  42. }
  43. CustomerDetails::suffix($type)->where('id', $customerInfo->id)->update(['tag_list' => $newTagList]);
  44. }
  45. }
  46. }