123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344 |
- <?php
- namespace App\Console\Commands;
- use App\Models\Basic;
- use App\Models\Enroll;
- use App\Models\InteDetail;
- use App\Models\InteLog;
- use App\Models\InteReview;
- use App\Models\InteUser;
- use App\Models\User;
- use App\Models\WdOrder;
- use Carbon\Carbon;
- use GuzzleHttp\Client;
- use Illuminate\Console\Command;
- use Illuminate\Support\Facades\DB;
- use Illuminate\Support\Facades\File;
- use Illuminate\Support\Facades\Log;
- use Intervention\Image\Facades\Image;
- class SearchWdOrderCommand extends Command
- {
- /**
- * The name and signature of the console command.
- *
- * @var string
- */
- protected $signature = 'SearchWdOrderCommand';
- /**
- * 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()
- {
- /*
- * 学分查询
- * */
- $number_arr=InteReview::where('season',48)->where('inte_type',1)->pluck('number')->toArray();
- if ($number_arr){
- $order_no_arr=WdOrder::whereIn('order_no',$number_arr)->where('apply_cancel',2)
- ->pluck('order_no');
- if ($order_no_arr){
- InteReview::whereIn('number',$order_no_arr)->delete();
- $rr=InteLog::whereIn('number',$order_no_arr)->get();
- foreach ($rr as $k=>$v){
- $uu=InteUser::where('id',$v->uid)->first();
- $uu->integral-=$v->integral;
- $uu->save();
- }
- InteLog::whereIn('number',$order_no_arr)->delete();
- }
- }
- $order_today_arr=WdOrder::where('apply_cancel','<>',2)
- ->whereBetween('pay_at',[Carbon::now()->addHours(-1),Carbon::now()])->pluck('order_no')->toArray();
- Log::error($order_today_arr);
- //求交集
- $array_intersect=array_intersect($number_arr,$order_today_arr);
- $array_diff=array_diff($order_today_arr,$array_intersect);
- // Log::error('微店的日志');
- // Log::error($array_diff);
- // Log::error($order_today_arr);
- if ($array_diff){
- $re=WdOrder::whereIn('order_no',$array_diff)->with(['orderDetail','store'=>function($q){
- $q->whereNull('deleted_at');
- }])->get();
- // Log::error($re);
- foreach ($re as $k=>$v){
- $type1=0;
- $i=0;
- $ii=0;
- $iii=0;
- $iiii=0;
- $iiiii=0;
- $iiiiis=0;
- $jiu=0;
- $type_size_1=[];
- $type_size_2=[];
- $type_size_3=[];
- $type_size_4=[];
- $type_size_5=[];
- $type_size_6=[];
- $type_size_jiu=[];
- $type2=0;
- $type3=0;
- $type4=0;
- $type5=0;
- $type6=0;
- $typejiu=0;
- if ($v->store){
- $user=InteUser::where('user_id',$v->store->user_id)->first();
- if ($user){
- if ($v->orderDetail){
- foreach ($v->orderDetail as $ke=>$va){
- if ($va->goods_id==1 || $va->goods_id==26){
- $type1+=$va->num;
- $s=mb_substr($va->type,0,1);
- if ($s=='男'){
- $sex=1;
- }else{
- $sex=0;
- }
- $type_size_1[$i]=[
- 'size'=>$va->size,
- 'sex'=>$sex,
- 'num'=>$va->num
- ];
- $i++;
- }elseif ($va->goods_id==2){
- $type2+=$va->num;
- $s=mb_substr($va->type,0,1);
- if ($s=='男'){
- $sex=1;
- }else{
- $sex=0;
- }
- $type_size_2[$ii]=[
- 'size'=>$va->size,
- 'sex'=>$sex,
- 'num'=>$va->num
- ];
- $ii++;
- }elseif ($va->goods_id==3){
- $type3+=$va->num;
- $s=mb_substr($va->type,0,1);
- if ($s=='男'){
- $sex=1;
- }else{
- $sex=0;
- }
- $type_size_2[$iii]=[
- 'size'=>$va->size,
- 'sex'=>$sex,
- 'num'=>$va->num
- ];
- $iii++;
- }elseif ($va->goods_id==4){
- $type4+=$va->num;
- $s=mb_substr($va->type,0,1);
- if ($s=='男'){
- $sex=1;
- }else{
- $sex=0;
- }
- $type_size_2[$iiii]=[
- 'size'=>$va->size,
- 'sex'=>$sex,
- 'num'=>$va->num
- ];
- $iiii++;
- }elseif ($va->goods_id==25){
- $type5+=$va->num;
- $s=mb_substr($va->type,0,1);
- if ($s=='男'){
- $sex=1;
- }else{
- $sex=0;
- }
- $type_size_5[$iiiii]=[
- 'size'=>$va->size,
- 'sex'=>$sex,
- 'num'=>$va->num
- ];
- $iiiii++;
- }
- elseif ($va->goods_id==27){
- $type6+=$va->num;
- $sex=1;
- $type_size_6[$iiiii]=[
- 'size'=>$va->size,
- 'sex'=>$sex,
- 'num'=>$va->num
- ];
- $iiiiis++;
- }elseif ($va->goods_id==28 || $va->goods_id==29){
- $typejiu+=$va->num;
- $sex=1;
- $type_size_jiu[$jiu]=[
- 'size'=>$va->size,
- 'sex'=>$sex,
- 'num'=>$va->num
- ];
- $jiu++;
- }
- }
- $int=new InteReview();
- $int->uid=$user->id;
- $int->season=48;
- $int->integral=($type1+$type2+$type3+$type4+$type5+$type6)*20+$typejiu*20;
- $int->type_one=$type1;
- $int->type_two=$type2;
- $int->type_three=$type3;
- $int->type_four=$type4;
- $int->type_five=$type5;
- $int->type_six=$type6;
- $int->type_jiu=$typejiu;
- $int->time=strtotime($v->pay_at);
- $int->figure=$v->account;
- $int->number=$v->order_no;
- $int->imgurl=$v->order_no;
- $int->inte_type=1;
- $int->type=0;
- $int->status=0;
- $int->save();
- $user->integral+=$int->integral;
- $user->save();
- if ($type_size_1){
- foreach ($type_size_1 as $kes=>$val){
- $r=new InteDetail();
- $r->inte_review_id=$int->id;
- $r->size=$val['size'];
- $r->num=$val['num'];
- $r->sex=$val['sex'];
- $r->status=0;
- $r->type=1;
- $r->save();
- }
- }
- if ($type_size_2){
- foreach ($type_size_2 as $kes=>$val){
- $r=new InteDetail();
- $r->inte_review_id=$int->id;
- $r->size=$val['size'];
- $r->num=$val['num'];
- $r->sex=$val['sex'];
- $r->status=0;
- $r->type=2;
- $r->save();
- }
- }
- if ($type_size_3){
- foreach ($type_size_3 as $kes=>$val){
- $r=new InteDetail();
- $r->inte_review_id=$int->id;
- $r->size=$val['size'];
- $r->num=$val['num'];
- $r->sex=$val['sex'];
- $r->status=0;
- $r->type=3;
- $r->save();
- }
- }
- if ($type_size_4){
- foreach ($type_size_4 as $kes=>$val){
- $r=new InteDetail();
- $r->inte_review_id=$int->id;
- $r->size=$val['size'];
- $r->num=$val['num'];
- $r->sex=$val['sex'];
- $r->status=0;
- $r->type=4;
- $r->save();
- }
- }
- if ($type_size_5){
- foreach ($type_size_5 as $kes=>$val){
- $r=new InteDetail();
- $r->inte_review_id=$int->id;
- $r->size=$val['size'];
- $r->num=$val['num'];
- $r->sex=$val['sex'];
- $r->status=0;
- $r->type=5;
- $r->save();
- }
- }
- if ($type_size_6){
- foreach ($type_size_6 as $kes=>$val){
- $r=new InteDetail();
- $r->inte_review_id=$int->id;
- $r->size=$val['size'];
- $r->num=$val['num'];
- $r->sex=$val['sex'];
- $r->status=0;
- $r->type=6;
- $r->save();
- }
- }
- if ($type_size_jiu){
- foreach ($type_size_jiu as $kes=>$val){
- $r=new InteDetail();
- $r->inte_review_id=$int->id;
- $r->size=$val['size'];
- $r->num=$val['num'];
- $r->sex=$val['sex'];
- $r->status=0;
- $r->type=6;
- $r->save();
- }
- }
- $in_log=new InteLog();
- $in_log->season=48;
- $in_log->integral=$int->integral;
- $in_log->time=$int->time;
- $in_log->type=1;
- $in_log->number=$int->number;
- $in_log->uid=$user->id;
- $in_log->save();
- }
- }else{
- Log::error('根据手机号找不到对应的代理,手机号为:'.$v->store->phone);
- }
- }
- }
- }
- Log::error('拉取微店支付结束');
- }
- }
|