BigGiftUserImgDCommand.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 BigGiftUserImgDCommand extends Command
  12. {
  13. /**
  14. * The name and signature of the console command.
  15. *
  16. * @var string
  17. */
  18. protected $signature = 'BigGiftUserImgDCommand';
  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('开始大礼吧B');
  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','大礼包C')->first();
  48. $data=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){
  58. $re=GiftUserImg::where('activity_id',$activity->id)->where('user_id',$v->user_id)->whereNotNull('user_img')->first();
  59. if (!$re){
  60. $res=GiftUserImg::where('user_id',$v->user_id)->whereNotNull('user_img')->orderByDesc('id')->first();
  61. if ($res){
  62. $gift=new GiftUserImg();
  63. $gift->user_id=$v->user_id;
  64. $gift->activity_id=$activity->id;
  65. $gift->type=3;
  66. $gift->img_type=1;
  67. $gift->user_img=$res->user_img;
  68. $gift->url=$this->CreateUserImg($activity->id,$v->user_id,$res->user_img);
  69. $gift->save();
  70. }
  71. }else{
  72. // if (!$re->url){
  73. $re->user_id=$v->user_id;
  74. $re->type=3;
  75. $re->img_type=1;
  76. $re->url=$this->CreateUserImg($activity->id,$v->user_id,$re->user_img);
  77. $re->save();
  78. // }
  79. }
  80. }
  81. }
  82. }
  83. // }
  84. Log::error('大礼包B结束');
  85. }
  86. public function CreateUserImg($activity_id,$user_id,$user_img){
  87. $res=GiftUserImg::where('activity_id',$activity_id)->where('type',3)->where('is_main',1)->where('img_type',0)->first();
  88. $img=GiftUserImg::where('activity_id',$activity_id)->where('type',3)->where('is_main',0)->where('img_type',0)->first();
  89. try{
  90. $imgs=new ActivityImgController();
  91. $data=$imgs->CreateImgB($user_id,$res->url,$user_img,$img->url);
  92. return $data;
  93. }catch (\Exception $exception){
  94. return null;
  95. }
  96. }
  97. }