MemberLowerCountJob.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2018/10/31
  6. * Time: 16:05
  7. */
  8. namespace app\Jobs;
  9. use Illuminate\Bus\Queueable;
  10. use Illuminate\Queue\InteractsWithQueue;
  11. use Illuminate\Queue\SerializesModels;
  12. use app\backend\modules\charts\modules\member\models\MemberLowerCount;
  13. use Illuminate\Support\Facades\DB;
  14. class MemberLowerCountJob
  15. {
  16. use InteractsWithQueue, Queueable, SerializesModels;
  17. public function __construct()
  18. {
  19. }
  20. public function handle()
  21. {
  22. $this->memberCount();
  23. }
  24. /**
  25. *
  26. */
  27. public function memberCount(){
  28. \Log::debug('下线人数排行定时任务开始执行,公众号id为', \YunShop::app()->uniacid);
  29. $list = DB::select('select count(*) as team_total, sum(if(level=1,1,0)) as first_total, sum(if(level = 2, 1, 0)) AS second_total, sum(if(level = 3, 1, 0)) AS third_total, member_id as uid, uniacid from '. DB::getTablePrefix() . 'yz_member_children where uniacid =' . \YunShop::app()->uniacid . ' group by member_id');
  30. if (empty($list)) {
  31. return;
  32. }
  33. $insert_data = array_chunk($list,2000);
  34. foreach ($insert_data as $k=>$v){
  35. MemberLowerCount::insert($v);
  36. }
  37. \Log::debug('下线人数排行定时任务执行结束,公众号id为', \YunShop::app()->uniacid);
  38. }
  39. }