FixPushUserChannel.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Modules\Book\Models\BookConfig;
  4. use App\Modules\Book\Services\BookConfigService;
  5. use App\Modules\Push\Models\QappPushUser;
  6. use GuzzleHttp\Cookie\SetCookie;
  7. use Illuminate\Console\Command;
  8. use GuzzleHttp\Client;
  9. use App\Modules\Book\Models\Book;
  10. use App\Modules\Book\Models\Chapter;
  11. use DB;
  12. class FixPushUserChannel extends Command
  13. {
  14. /**
  15. * The name and signature of the console command.
  16. *
  17. * @var string
  18. */
  19. protected $signature = 'FixPushUserChannel {--channel_id=} {--distribution_channel_id=}';
  20. /**
  21. * The console command description.
  22. *
  23. * @var string
  24. */
  25. protected $description = 'Command description';
  26. /**
  27. * Create a new command instance.
  28. *
  29. * @return void
  30. */
  31. public function __construct()
  32. {
  33. parent::__construct();
  34. }
  35. /**
  36. * Execute the console command.
  37. *
  38. * @return mixed
  39. */
  40. public function handle()
  41. {
  42. $channel_id = $this->option('channel_id');
  43. $distribution_channel_id = $this->option('distribution_channel_id');
  44. //
  45. $qapp_push_users = QappPushUser::leftjoin('users','users.id','qapp_push_user.uid')
  46. ->leftjoin('qapp_push_app',function($join){
  47. $join->on('users.distribution_channel_id','=','qapp_push_app.uid')
  48. ->on('qapp_push_user.provider','=','qapp_push_app.provider');
  49. })
  50. ->where('qapp_push_user.channel_id',$channel_id)
  51. ->where('users.distribution_channel_id',$distribution_channel_id)
  52. ->select('qapp_push_user.*','users.send_order_id','users.distribution_channel_id','qapp_push_app.app_id as appId')
  53. ->get();
  54. if(!$qapp_push_users->isEmpty()){
  55. try {
  56. foreach($qapp_push_users as $item){
  57. if($item->distribution_channel_id != $item->channel_id && $item->app_id != $item->appId){
  58. DB::table('qapp_push_user')->where('id',$item->id)->update(['app_id' => $item->appId, 'channel_id' => $item->distribution_channel_id]);
  59. }
  60. }
  61. } catch (\Exception $e) {
  62. \Log::info('FixPushUserChannel_error:channel_id'.$channel_id.' distribution_channel_id:'.$distribution_channel_id);
  63. \Log::info('FixPushUserChannel_error:'.$e->getMessage());
  64. }
  65. }
  66. }
  67. }