IntegralCommand.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Models\InteLog;
  4. use App\Models\InteReview;
  5. use App\Models\InteUser;
  6. use Carbon\Carbon;
  7. use Illuminate\Console\Command;
  8. use Illuminate\Support\Facades\DB;
  9. use Illuminate\Support\Facades\Log;
  10. class IntegralCommand extends Command
  11. {
  12. /**
  13. * The name and signature of the console command.
  14. *
  15. * @var string
  16. */
  17. protected $signature = 'IntegralCommand';
  18. /**
  19. * The console command description.
  20. *
  21. * @var string
  22. */
  23. protected $description = 'Command description';
  24. /**
  25. * Create a new command instance.
  26. *
  27. * @return void
  28. */
  29. public function __construct()
  30. {
  31. parent::__construct();
  32. }
  33. /**
  34. * Execute the console command.
  35. *
  36. * @return mixed
  37. */
  38. public function handle()
  39. {
  40. Log::error('开始翻倍');
  41. for ($i=0;$i<1;$i++){
  42. $re=InteReview::where('time','<',Carbon::today()->addDays("-".$i)->timestamp)
  43. ->where('time','>',Carbon::yesterday()->addDays("-".$i)->timestamp)
  44. ->select(DB::raw('SUM(integral) as inte_all'),'uid')
  45. ->groupBy('uid')->get();
  46. foreach ($re as $k=>$v){
  47. $total=InteReview::where('time','<',Carbon::today()->addDays("-".$i)->timestamp)
  48. ->where('time','>',Carbon::yesterday()->addDays("-".$i)->timestamp)
  49. ->where('uid',$v->uid)->sum('type_jiu');
  50. if ($total>=6){
  51. $integral=$total*20;
  52. $inte=new InteLog();
  53. $inte->uid=$v->uid;
  54. $inte->type=2;
  55. $inte->integral=$integral;
  56. $inte->time=Carbon::yesterday()->addDays("-".$i)->addHours(2)->timestamp;
  57. $inte->season=48;
  58. $inte->save();
  59. $inteuser=InteUser::where('id',$v->uid)->first();
  60. $inteuser->integral+=$integral;
  61. $inteuser->save();
  62. }
  63. $inte_other=$v->inte_all-$total*20;
  64. if ($inte_other>=100){
  65. $inte=new InteLog();
  66. $inte->uid=$v->uid;
  67. $inte->type=2;
  68. $inte->integral=$inte_other;
  69. $inte->time=Carbon::yesterday()->addDays("-".$i)->addHours(2)->timestamp;
  70. $inte->season=48;
  71. $inte->save();
  72. $inteuser=InteUser::where('id',$v->uid)->first();
  73. $inteuser->integral+=$inte_other;
  74. $inteuser->save();
  75. }
  76. }
  77. }
  78. Log::error('翻倍结束');
  79. }
  80. }