123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- <?php
- namespace App\Console\Commands;
- use App\Http\Controllers\ActivityImgController;
- use App\Models\Activity;
- use App\Models\ActivityLimit;
- use App\Models\GiftUserImg;
- use App\Models\Order;
- use Carbon\Carbon;
- use Illuminate\Console\Command;
- use Illuminate\Support\Facades\Log;
- class BigGiftUserImgCommand extends Command
- {
- /**
- * The name and signature of the console command.
- *
- * @var string
- */
- protected $signature = 'BigGiftUserImgCommand';
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = 'Command description';
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
- /**
- * Execute the console command.
- *
- * @return mixed
- */
- public function handle()
- {
- Log::error('kaish');
- // $activity=Activity::where('id',14)->first();
- $activity=Activity::where('is_ing',1)->first();
- $time=Carbon::now();
- // if ($time>=$activity->start_time&&$time<=$activity->end_time){
- // $data=ActivityLimit::where('activity_id',$activity->id)->where('title','大礼包')->first();
- $data=ActivityLimit::where('activity_id',$activity->id)->where('title','大礼包B-a')->first();
- // $data1=ActivityLimit::where('activity_id',$activity->id)->where('title','大礼包B-b')->first();
- if ($data){
- $money=$data->account;
- // $money1=$data1->account;
- $arr=Order::whereBetween('created_at',[$activity->start_time,$activity->end_time])->where('is_deleted',0)
- ->groupBy('user_id')->get();
- foreach ($arr as $k=>$v){
- $moneys=Order::whereBetween('created_at',[$activity->start_time,$activity->end_time])
- ->where('is_deleted',0)->where('user_id',$v->user_id)->sum('money');
- // if ($moneys>=$money && $moneys< $money1){
- if ($moneys>=$money){
- // if ($moneys>=$money && $moneys<200000){
- $re=GiftUserImg::where('activity_id',$activity->id)->where('user_id',$v->user_id)->whereNotNull('user_img')->first();
- if (!$re){
- $res=GiftUserImg::where('user_id',$v->user_id)->whereNotNull('user_img')->orderByDesc('id')->first();
- if ($res){
- $gift=new GiftUserImg();
- $gift->user_id=$v->user_id;
- $gift->activity_id=$activity->id;
- $gift->type=1;
- $gift->img_type=1;
- $gift->user_img=$res->user_img;
- $gift->url=$this->CreateUserImg($activity->id,$v->user_id,$res->user_img);
- $gift->save();
- }
- }else{
- // if (!$re->url){
- $re->user_id=$v->user_id;
- $re->type=1;
- $re->img_type=1;
- $re->url=$this->CreateUserImg($activity->id,$v->user_id,$re->user_img);
- $re->save();
- // }
- }
- }
- }
- }
- // }
- Log::error('大礼包A结束');
- }
- public function CreateUserImg($activity_id,$user_id,$user_img){
- $res=GiftUserImg::where('activity_id',$activity_id)->where('type',1)->where('is_main',1)->where('img_type',0)->first();
- $img=GiftUserImg::where('activity_id',$activity_id)->where('type',1)->where('is_main',0)->where('img_type',0)->first();
- try{
- $imgs=new ActivityImgController();
- $data=$imgs->CreateImgB($user_id,$res->url,$user_img,$img->url);
- return $data;
- }catch (\Exception $exception){
- Log::error($exception->getMessage());
- return null;
- }
- }
- }
|