V2176.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. namespace App\Console\Commands\Upgrade;
  3. use App\Models\PartnerModel;
  4. use App\Models\User\FeedcheckLogModel;
  5. use Illuminate\Console\Command;
  6. use Illuminate\Support\Facades\DB;
  7. class V2176 extends Command
  8. {
  9. /**
  10. * The name and signature of the console command.
  11. *
  12. * @var string
  13. */
  14. protected $signature = 'upgrade:V2176 {--d}';
  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. $deamon = $this->option('d');
  38. $npassDatas = FeedcheckLogModel::where([['is_pass', 0], ['expire_at', 0]])
  39. ->groupBy('partner_id')
  40. ->orderBy('partner_id', 'asc')->select([DB::raw("`partner_id`, COUNT(*) * 5 as cnt")])->get();
  41. $passDatas = FeedcheckLogModel::where([['is_pass', 1], ['expire_at', 0]])
  42. ->groupBy('partner_id')
  43. ->orderBy('partner_id', 'asc')->select([DB::raw("`partner_id`, COUNT(*) * 5 as cnt")])->get();
  44. $bar = null;
  45. if (!$deamon) {
  46. $bar = $this->output->createProgressBar($npassDatas->count() + $passDatas->count());
  47. $bar->start();
  48. }
  49. foreach ($npassDatas as $data) {
  50. PartnerModel::where([
  51. ['id', $data->partner_id],
  52. ['feed_tag_cnt', 0]
  53. ])->update([
  54. 'feed_tag_cnt' => $data->cnt
  55. ]);
  56. if (!$deamon) {
  57. $bar->advance(1);
  58. }
  59. }
  60. foreach ($passDatas as $data) {
  61. PartnerModel::where([
  62. ['id', $data->partner_id],
  63. ['feed_tag_like', 0]
  64. ])->increment('feed_tag_cnt', $data->cnt);
  65. PartnerModel::where([
  66. ['id', $data->partner_id],
  67. ['feed_tag_like', 0]
  68. ])->increment('feed_tag_like', $data->cnt);
  69. if (!$deamon) {
  70. $bar->advance(1);
  71. }
  72. }
  73. $sql = "UPDATE `kdgx_partner_charge_partner`
  74. set `feed_tag_cnt`= 100,
  75. `feed_tag_like`= IF(1= `sex`, 30, 60)
  76. where `is_recommend`= 1";
  77. DB::statement($sql);
  78. if (!$deamon) {
  79. $bar->finish();
  80. }
  81. }
  82. }