BigGiftUserImgCommand.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Http\Controllers\ActivityImgController;
  4. use App\Models\Activity;
  5. use App\Models\ActivityLimit;
  6. use App\Models\GiftUserImg;
  7. use App\Models\Order;
  8. use Carbon\Carbon;
  9. use Illuminate\Console\Command;
  10. use Illuminate\Support\Facades\Log;
  11. class BigGiftUserImgCommand extends Command
  12. {
  13. /**
  14. * The name and signature of the console command.
  15. *
  16. * @var string
  17. */
  18. protected $signature = 'BigGiftUserImgCommand';
  19. /**
  20. * The console command description.
  21. *
  22. * @var string
  23. */
  24. protected $description = 'Command description';
  25. /**
  26. * Create a new command instance.
  27. *
  28. * @return void
  29. */
  30. public function __construct()
  31. {
  32. parent::__construct();
  33. }
  34. /**
  35. * Execute the console command.
  36. *
  37. * @return mixed
  38. */
  39. public function handle()
  40. {
  41. Log::error('kaish');
  42. // $activity=Activity::where('id',14)->first();
  43. $activity=Activity::where('is_ing',1)->first();
  44. $time=Carbon::now();
  45. // if ($time>=$activity->start_time&&$time<=$activity->end_time){
  46. // $data=ActivityLimit::where('activity_id',$activity->id)->where('title','大礼包')->first();
  47. $data=ActivityLimit::where('activity_id',$activity->id)->where('title','大礼包B-a')->first();
  48. // $data1=ActivityLimit::where('activity_id',$activity->id)->where('title','大礼包B-b')->first();
  49. if ($data){
  50. $money=$data->account;
  51. // $money1=$data1->account;
  52. $arr=Order::whereBetween('created_at',[$activity->start_time,$activity->end_time])->where('is_deleted',0)
  53. ->groupBy('user_id')->get();
  54. foreach ($arr as $k=>$v){
  55. $moneys=Order::whereBetween('created_at',[$activity->start_time,$activity->end_time])
  56. ->where('is_deleted',0)->where('user_id',$v->user_id)->sum('money');
  57. // if ($moneys>=$money && $moneys< $money1){
  58. if ($moneys>=$money){
  59. // if ($moneys>=$money && $moneys<200000){
  60. $re=GiftUserImg::where('activity_id',$activity->id)->where('user_id',$v->user_id)->whereNotNull('user_img')->first();
  61. if (!$re){
  62. $res=GiftUserImg::where('user_id',$v->user_id)->whereNotNull('user_img')->orderByDesc('id')->first();
  63. if ($res){
  64. $gift=new GiftUserImg();
  65. $gift->user_id=$v->user_id;
  66. $gift->activity_id=$activity->id;
  67. $gift->type=1;
  68. $gift->img_type=1;
  69. $gift->user_img=$res->user_img;
  70. $gift->url=$this->CreateUserImg($activity->id,$v->user_id,$res->user_img);
  71. $gift->save();
  72. }
  73. }else{
  74. // if (!$re->url){
  75. $re->user_id=$v->user_id;
  76. $re->type=1;
  77. $re->img_type=1;
  78. $re->url=$this->CreateUserImg($activity->id,$v->user_id,$re->user_img);
  79. $re->save();
  80. // }
  81. }
  82. }
  83. }
  84. }
  85. // }
  86. Log::error('大礼包A结束');
  87. }
  88. public function CreateUserImg($activity_id,$user_id,$user_img){
  89. $res=GiftUserImg::where('activity_id',$activity_id)->where('type',1)->where('is_main',1)->where('img_type',0)->first();
  90. $img=GiftUserImg::where('activity_id',$activity_id)->where('type',1)->where('is_main',0)->where('img_type',0)->first();
  91. try{
  92. $imgs=new ActivityImgController();
  93. $data=$imgs->CreateImgB($user_id,$res->url,$user_img,$img->url);
  94. return $data;
  95. }catch (\Exception $exception){
  96. Log::error($exception->getMessage());
  97. return null;
  98. }
  99. }
  100. }