GenaralRecordRepository.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace App\Repositories\Behavior;
  3. use App\Models\Behavior;
  4. use App\Models\GeneralRecord;
  5. /**
  6. * Created by PhpStorm.
  7. * User: durong
  8. * Date: 2019/6/14
  9. * Time: 下午8:45
  10. */
  11. class GenaralRecordRepository
  12. {
  13. public function __construct(GeneralRecord $generalRecord,Behavior $behavior)
  14. {
  15. $this->generalRecord = $generalRecord;
  16. $this->behavior = $behavior;
  17. }
  18. public function lists($request)
  19. {
  20. $perPage = isset($request['per_page']) ? $request['per_page'] : 20;
  21. $where = [];
  22. if(isset($request['id'])){
  23. $where[] = ['id', $request['id']];
  24. }
  25. if(isset($request['uid'])){
  26. $where[] = ['uid', $request['uid']];
  27. }
  28. if(isset($request['trigger_type'])){
  29. $where[] = ['trigger_type', $request['trigger_type']];
  30. }
  31. if(isset($request['virus_behavior_id'])){
  32. $where[] = ['virus_behavior_id', $request['virus_behavior_id']];
  33. }
  34. if(isset($request['behavior_identification'])){
  35. $virus_id = $this->behavior->select('virus_behavior_id')->where('behavior_identification',$request['behavior_identification'])->first();
  36. if ($virus_id){
  37. $where[] = ['virus_behavior_id', $virus_id->virus_behavior_id];
  38. }
  39. }
  40. return $this->generalRecord
  41. ->where($where)
  42. ->where(function($query) use ($request){
  43. if(isset($request['created_at'])){
  44. $time = explode('_', $request['created_at']);
  45. $query->whereBetween('created_at', $time);
  46. }
  47. })
  48. ->orderBy('id','desc')
  49. ->paginate($perPage);
  50. }
  51. }