GenaralRecordRepository.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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['content_author_id'])){
  35. $where[] = ['content_author_id', $request['content_author_id']];
  36. }
  37. if(isset($request['related_content_id'])){
  38. $where[] = ['related_content_id', $request['related_content_id']];
  39. }
  40. if(isset($request['behavior_identification'])){
  41. $virus_id = $this->behavior->select('virus_behavior_id')->where('behavior_identification',$request['behavior_identification'])->first();
  42. if ($virus_id){
  43. $where[] = ['virus_behavior_id', $virus_id->virus_behavior_id];
  44. }
  45. }
  46. return $this->generalRecord
  47. ->where($where)
  48. ->where(function($query) use ($request){
  49. if(isset($request['created_at'])){
  50. $time = explode('_', $request['created_at']);
  51. $query->whereBetween('created_at', $time);
  52. }
  53. })
  54. ->orderBy('id','desc')
  55. ->paginate($perPage);
  56. }
  57. }