CompanyNameFix.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. namespace App\Console\Commands\Temp;
  3. use App\Modules\MediaPush\Models\MediaPushBookConfigs;
  4. use App\Modules\MediaPush\Models\MediaPushRelationBooks;
  5. use Illuminate\Console\Command;
  6. use DB;
  7. class CompanyNameFix extends Command
  8. {
  9. /**
  10. * The name and signature of the console command.
  11. *
  12. * @var string
  13. */
  14. protected $signature = 'company_name_fix';
  15. /**
  16. * The console command description.
  17. *
  18. * @var string
  19. */
  20. protected $description = '公司名修复';
  21. /**
  22. * Create a new command instance.
  23. *
  24. * @return void
  25. */
  26. public function __construct()
  27. {
  28. parent::__construct();
  29. }
  30. /**
  31. * Execute the console command.
  32. *
  33. * @return mixed
  34. */
  35. public function handle()
  36. {
  37. $this->updateChannelUserInfo();
  38. $this->updateChannelInfo();
  39. }
  40. /**
  41. * 修复公司名字
  42. */
  43. public function updateChannelUserInfo()
  44. {
  45. //修复company_name,distribution_manages_id,person_in_charge_name字段
  46. $users = DB::table('channel_users')->get();
  47. foreach ($users as $user){
  48. $company = DB::table('companies')->find($user->company_id);
  49. if($company){
  50. $distribution_manager = DB::table('distribution_manages')->find($company->distribution_manages_id);
  51. $params = [
  52. "company_name"=>$company->name,
  53. "distribution_manages_id"=>$company->distribution_manages_id,
  54. ];
  55. if($distribution_manager)$params["person_in_charge_name"]=$distribution_manager->nickname;
  56. $effect = DB::table('channel_users')->where('id',$user->id)->update($params);
  57. if($effect)dump($user->id.'user改动');
  58. }
  59. }
  60. }
  61. /**
  62. * 修复名字
  63. */
  64. public function updateChannelInfo()
  65. {
  66. //nickname,person_in_charge_name,distribution_manages_id字段
  67. $distribution_channels = DB::table('distribution_channels')->get();
  68. foreach ($distribution_channels as $channel){
  69. $user = DB::table('channel_users')->find($channel->channel_user_id);
  70. if($user){
  71. $effect = DB::table('distribution_channels')->where('id',$channel->id)->update(
  72. [
  73. "nickname"=>$user->company_name,
  74. "distribution_manages_id"=>$user->distribution_manages_id,
  75. "person_in_charge_name"=>$user->person_in_charge_name,
  76. ]
  77. );
  78. }
  79. if($effect)dump($channel->id.'channel改动');
  80. }
  81. }
  82. }