EveryDayInfo.php 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Models\User;
  4. use App\Models\Notice;
  5. use Exception;
  6. use Carbon\Carbon;
  7. use Illuminate\Support\Facades\Auth;
  8. use Illuminate\Support\Facades\DB;
  9. use Illuminate\Support\Facades\Log;
  10. use Illuminate\Console\Command;
  11. class EveryDayInfo extends Command
  12. {
  13. /**
  14. * The name and signature of the console command.
  15. *
  16. * @var string
  17. */
  18. protected $signature = 'everyDayInfo';
  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::info('每日通知'.date("Y-m-d H:i:s"));
  42. $y = Carbon::yesterday();
  43. $start=Carbon::yesterday()->startOfDay();
  44. $end=Carbon::yesterday()->endOfDay();
  45. User::where('status',0)->where('cert_status',6)->chunkById(100,function($users) use($y,$start,$end){
  46. $mes=[];
  47. foreach($users as $key=>$val){
  48. $recom_count=User::where('recom_id',$val->id)->whereBetween('created_at',[$start,$end])->count();
  49. $team_ids=User::where('agent_id',$val->id)->pluck('id');
  50. $team_agents_num=User::where('agent_id',$val->id)->whereBetween('created_at',[$start,$end])->count();
  51. $agents_num=User::whereIn('agent_id',$team_ids)->whereBetween('created_at',[$start,$end])->count();
  52. $team_count=$team_agents_num + $agents_num;
  53. $no_recom_audit=User::where('recom_id',$val->id)->where('cert_status',1)->count();
  54. $no_agent_audit=User::where('agent_id',$val->id)->where('cert_status',2)->count();
  55. $no_audit=$no_recom_audit+$no_agent_audit;
  56. $content = $y->year.'年'.$y->month.'月'.$y->day.'日'.'新增代理商数据 本人邀请:'.$recom_count.'人, 团队新增:'.$team_count.'人, 未审核:'.$no_audit.'人';
  57. // Notice::where('user_id',$val->id)->update([
  58. // 'content'=>$y->year.'年'.$y->month.'月'.$y->day.'日'.'新增代理商数据 本人邀请:'.$recom_count.'人, 团队新增:'.$team_count.'人, 未审核:'.$no_audit.'人'
  59. // ]);
  60. // Notice::create([
  61. // 'user_id'=>$val->id,
  62. // 'title'=>'【每日通知】',
  63. // 'type'=>1,
  64. // 'content'=>$y->year.'年'.$y->month.'月'.$y->day.'日'.'新增代理商数据 本人邀请:'.$recom_count.'人, 团队新增:'.$team_count.'人, 未审核:'.$no_audit.'人'
  65. // ]);
  66. Notice::updateOrInsert(
  67. ['user_id' => $val->id, 'type' => 1],
  68. ['title'=>'【每日通知】','content' => $content]
  69. );
  70. // if(!empty($val->openid)){
  71. // $mes['openid']=$val->openid;
  72. // $mes['data']=[
  73. // 'first' => $y->year.'年'.$y->month.'月'.$y->day.'日'.'新增代理商数据',
  74. // 'keyword1' => $recom_count,
  75. // 'keyword2' => $team_count,
  76. // 'keyword3' => $no_audit. '(待邀请审核:'.$no_recom_audit.'人,待邀上级审核:'.$no_agent_audit.'人)',
  77. // 'remark' => '点击链接进入系统,查看详情',
  78. // ];
  79. // event(new EveryDayInfo($mes));
  80. // }
  81. }
  82. });
  83. }
  84. }