channelCpcCode.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Modules\Channel\Services\ChannelService;
  4. use App\Modules\Channel\Services\CompanyService;
  5. use Illuminate\Console\Command;
  6. use Redis;
  7. class channelCpcCode extends Command
  8. {
  9. /**
  10. * The name and signature of the console command.
  11. *
  12. * @var string
  13. */
  14. protected $signature = 'channel:cpccode';
  15. /**
  16. * The console command description.
  17. *
  18. * @var string
  19. */
  20. protected $description = 'reset cpc code';
  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->start();
  38. }
  39. private function start()
  40. {
  41. $result = CompanyService::getAllCompanyCpcCode();
  42. foreach ($result as $item){
  43. $channels = ChannelService::getByChannelUserId($item->id);
  44. $code = empty($item->channel)?'zw001':$item->channel;
  45. if($channels->isNotEmpty()){
  46. foreach ($channels as $channel) {
  47. Redis::hset('channel:setting:'.$channel->id,'cpc_channel',$code);
  48. }
  49. }
  50. }
  51. }
  52. }