1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- <?php
- namespace App\Console\Commands;
- use App\Models\User;
- use App\Models\Notice;
- use Exception;
- use Carbon\Carbon;
- use Illuminate\Support\Facades\Auth;
- use Illuminate\Support\Facades\DB;
- use Illuminate\Support\Facades\Log;
- use Illuminate\Console\Command;
- class EveryDayInfo extends Command
- {
- /**
- * The name and signature of the console command.
- *
- * @var string
- */
- protected $signature = 'everyDayInfo';
- /**
- * 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::info('每日通知'.date("Y-m-d H:i:s"));
- $y = Carbon::yesterday();
- $start=Carbon::yesterday()->startOfDay();
- $end=Carbon::yesterday()->endOfDay();
- User::where('status',0)->where('cert_status',6)->chunkById(100,function($users) use($y,$start,$end){
- $mes=[];
- foreach($users as $key=>$val){
- $recom_count=User::where('recom_id',$val->id)->whereBetween('created_at',[$start,$end])->count();
- $team_ids=User::where('agent_id',$val->id)->pluck('id');
- $team_agents_num=User::where('agent_id',$val->id)->whereBetween('created_at',[$start,$end])->count();
- $agents_num=User::whereIn('agent_id',$team_ids)->whereBetween('created_at',[$start,$end])->count();
- $team_count=$team_agents_num + $agents_num;
- $no_recom_audit=User::where('recom_id',$val->id)->where('cert_status',1)->count();
- $no_agent_audit=User::where('agent_id',$val->id)->where('cert_status',2)->count();
- $no_audit=$no_recom_audit+$no_agent_audit;
- $content = $y->year.'年'.$y->month.'月'.$y->day.'日'.'新增代理商数据 本人邀请:'.$recom_count.'人, 团队新增:'.$team_count.'人, 未审核:'.$no_audit.'人';
- // Notice::where('user_id',$val->id)->update([
- // 'content'=>$y->year.'年'.$y->month.'月'.$y->day.'日'.'新增代理商数据 本人邀请:'.$recom_count.'人, 团队新增:'.$team_count.'人, 未审核:'.$no_audit.'人'
- // ]);
- // Notice::create([
- // 'user_id'=>$val->id,
- // 'title'=>'【每日通知】',
- // 'type'=>1,
- // 'content'=>$y->year.'年'.$y->month.'月'.$y->day.'日'.'新增代理商数据 本人邀请:'.$recom_count.'人, 团队新增:'.$team_count.'人, 未审核:'.$no_audit.'人'
- // ]);
- Notice::updateOrInsert(
- ['user_id' => $val->id, 'type' => 1],
- ['title'=>'【每日通知】','content' => $content]
- );
- // if(!empty($val->openid)){
- // $mes['openid']=$val->openid;
- // $mes['data']=[
- // 'first' => $y->year.'年'.$y->month.'月'.$y->day.'日'.'新增代理商数据',
- // 'keyword1' => $recom_count,
- // 'keyword2' => $team_count,
- // 'keyword3' => $no_audit. '(待邀请审核:'.$no_recom_audit.'人,待邀上级审核:'.$no_agent_audit.'人)',
- // 'remark' => '点击链接进入系统,查看详情',
- // ];
- // event(new EveryDayInfo($mes));
- // }
- }
- });
- }
- }
|