MasterMeter.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Http\Models\Site;
  4. use Illuminate\Console\Command;
  5. use Illuminate\Support\Facades\DB;
  6. use Illuminate\Support\Facades\Log;
  7. class MasterMeter extends Command
  8. {
  9. /**
  10. * The name and signature of the console command.
  11. *
  12. * @var string
  13. */
  14. protected $signature = 'master:meter';
  15. /**
  16. * The console command description.
  17. *
  18. * @var string
  19. */
  20. protected $description = 'Command 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. $siteList = Site::query()->where('is_bq', 1)->get();
  38. $rankConnection = DB::connection('rank');
  39. foreach ($siteList as $key => $value) {
  40. if (!empty($value->old_id)) {
  41. $listReportList = $rankConnection->table('project_listreport')->where('project_id', $value->old_id)->get();
  42. foreach ($listReportList as $kk => $vv) {
  43. $ym = $vv->ym . '01';
  44. $date = date('Y-m-d H:i:s', strtotime('last day of this month', strtotime($ym)));
  45. if ($vv->traffic >= 2000 && !$value->reach_2000_at) {
  46. $value->update(['reach_2000_at' => $date]);
  47. }
  48. if ($vv->traffic >= 1500 && !$value->reach_1500_at) {
  49. $value->update(['reach_1500_at' => $date]);
  50. }
  51. if ($vv->traffic >= 1000 && !$value->reach_1000_at) {
  52. $value->update(['reach_1000_at' => $date]);
  53. }
  54. if ($vv->traffic >= 500 && !$value->reach_500_at) {
  55. $value->update(['reach_500_at' => $date]);
  56. }
  57. if ($vv->traffic >= 300 && !$value->reach_300_at) {
  58. $value->update(['reach_300_at' => $date]);
  59. }
  60. \App\Http\Models\MasterMeter::query()->create([
  61. 'site_id' => $value->id,
  62. 'old_id' => $value->old_id,
  63. 'cn_title' => $value->cn_title,
  64. 'domain' => $value->domain,
  65. 'traffic' => $vv->traffic,
  66. 'inquire' => $vv->inquire,
  67. 'ym' => date('Ym')
  68. ]);
  69. }
  70. }
  71. }
  72. $this->info('success');
  73. return;
  74. }
  75. }