BehaviorLogRepository.php 999 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. namespace App\Repositories\Behavior;
  3. use App\Models\BehaviorOperationLog;
  4. /**
  5. * Created by PhpStorm.
  6. * User: durong
  7. * Date: 2019/6/13
  8. * Time: 下午7:11
  9. */
  10. class BehaviorLogRepository
  11. {
  12. public function __construct(BehaviorOperationLog $behaviorOperationLog)
  13. {
  14. $this->behaviorOperationLog = $behaviorOperationLog;
  15. }
  16. public function log($request)
  17. {
  18. $perPage = isset($request['per_page']) ? $request['per_page'] : 20;
  19. $where = [];
  20. if(isset($request['type'])){
  21. $where[] = ['type', $request['type']];
  22. }
  23. return $this->behaviorOperationLog
  24. ->where($where)
  25. ->where(function($query) use ($request){
  26. if(isset($request['created_at'])){
  27. $time = explode('_', $request['created_at']);
  28. $query->whereBetween('created_at', $time);
  29. }
  30. })
  31. ->orderBy('id','desc')
  32. ->paginate($perPage);
  33. }
  34. }