123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- <?php
- namespace App\Console\Commands\Temp;
- use App\Modules\MediaPush\Models\MediaPushBookConfigs;
- use App\Modules\MediaPush\Models\MediaPushRelationBooks;
- use Illuminate\Console\Command;
- use DB;
- class CompanyNameFix extends Command
- {
- /**
- * The name and signature of the console command.
- *
- * @var string
- */
- protected $signature = 'company_name_fix';
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = '公司名修复';
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
- /**
- * Execute the console command.
- *
- * @return mixed
- */
- public function handle()
- {
- $this->updateChannelUserInfo();
- $this->updateChannelInfo();
- }
- /**
- * 修复公司名字
- */
- public function updateChannelUserInfo()
- {
- //修复company_name,distribution_manages_id,person_in_charge_name字段
- $users = DB::table('channel_users')->get();
- foreach ($users as $user){
- $company = DB::table('companies')->find($user->company_id);
- if($company){
- $distribution_manager = DB::table('distribution_manages')->find($company->distribution_manages_id);
- $params = [
- "company_name"=>$company->name,
- "distribution_manages_id"=>$company->distribution_manages_id,
- ];
- if($distribution_manager)$params["person_in_charge_name"]=$distribution_manager->nickname;
- $effect = DB::table('channel_users')->where('id',$user->id)->update($params);
- if($effect)dump($user->id.'user改动');
- }
- }
- }
- /**
- * 修复名字
- */
- public function updateChannelInfo()
- {
- //nickname,person_in_charge_name,distribution_manages_id字段
- $distribution_channels = DB::table('distribution_channels')->get();
- foreach ($distribution_channels as $channel){
- $user = DB::table('channel_users')->find($channel->channel_user_id);
- if($user){
- $effect = DB::table('distribution_channels')->where('id',$channel->id)->update(
- [
- "nickname"=>$user->company_name,
- "distribution_manages_id"=>$user->distribution_manages_id,
- "person_in_charge_name"=>$user->person_in_charge_name,
- ]
- );
- }
- if($effect)dump($channel->id.'channel改动');
- }
- }
- }
|