BrowseRecordFacadeRepository.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. namespace App\Repositories\Eloquent;
  3. use App\Repositories\Contracts\CollectInterface;
  4. use App\Models\BrowseRecord;
  5. /**
  6. * 浏览记录
  7. * @author lilin
  8. *
  9. */
  10. class BrowseRecordFacadeRepository extends BaseRepository implements CollectInterface
  11. {
  12. public function getList(array $conditions, array $fields, string $sort, int $page, int $limit)
  13. {
  14. $result = BrowseRecord::with(['scale', 'drill', 'specialist'])
  15. ->where(function($query) use($conditions){
  16. if (isset($conditions['uid'])){
  17. $query->where('uid', $conditions['uid']);
  18. }
  19. if (isset($conditions['column'])){
  20. if ($conditions['column']==2){
  21. $query->where('column', 3);
  22. $query->whereRaw("
  23. object_id in ( select id from specialist_infos where second_id in (12,13) )
  24. ");
  25. }elseif ($conditions['column']==3){
  26. $query->where('column', 3);
  27. $query->whereRaw("
  28. object_id NOT IN ( select id from specialist_infos where second_id in (12,13) )
  29. ");
  30. }elseif ($conditions['column']==1){
  31. $query->where('column', 1);
  32. }
  33. }
  34. if (isset($conditions['object_id'])){
  35. $query->where('object_id', $conditions['object_id']);
  36. }
  37. })->groupBy("object_id")
  38. ->orderByRaw($sort)
  39. ->paginate($limit, $fields);
  40. return $this->response($result);
  41. }
  42. public function sign(string $op, string $task, string $version, array $parameter)
  43. {
  44. $appid = config('console.thirdScale.appid');
  45. $key = config('console.thirdScale.key');
  46. ksort($parameter);
  47. $pStr = '';
  48. foreach ($parameter as $v) {
  49. $pStr .= $v;
  50. }
  51. $str = $parameter['appid'] . $op . $task . $version . $pStr . $key;
  52. return md5($str);
  53. }
  54. public function findBy(array $conditions, array $fields){
  55. $result = BrowseRecord::where(function($query) use($conditions){
  56. if (isset($conditions['id'])){
  57. $query->where('id', $conditions['id']);
  58. }
  59. if (isset($conditions['uid'])){
  60. $query->where('uid', $conditions['uid']);
  61. }
  62. if (isset($conditions['column'])){
  63. $query->where('column', $conditions['column']);
  64. }
  65. if (isset($conditions['object_id'])){
  66. $query->where('object_id', $conditions['object_id']);
  67. }
  68. })->first($fields);
  69. return $result ? $this->response($result) : $this->error()->dataDoesNotExist();
  70. }
  71. public function create(array $data)
  72. {
  73. $result = BrowseRecord::create($data);
  74. return $result ? $this->response($result) : $this->error()->fail();
  75. }
  76. public function updateBy(array $conditions, array $data)
  77. {
  78. $result = BrowseRecord::where(function($query) use($conditions){
  79. if (isset($conditions['id'])){
  80. $query->where('id', $conditions['id']);
  81. }
  82. if (isset($conditions['uid'])){
  83. $query->where('uid', $conditions['uid']);
  84. }
  85. if (isset($conditions['column'])){
  86. $query->where('column', $conditions['column']);
  87. }
  88. if (isset($conditions['object_id'])){
  89. $query->where('object_id', $conditions['object_id']);
  90. }
  91. })->update($data);
  92. return $result ? $this->response($result) : $this->error()->fail();
  93. }
  94. public function deleteBy(array $conditions)
  95. {
  96. $result = BrowseRecord::where(function($query) use($conditions){
  97. if (isset($conditions['id'])){
  98. $query->where('id', $conditions['id']);
  99. }
  100. if (isset($conditions['uid'])){
  101. $query->where('uid', $conditions['uid']);
  102. }
  103. })->delete();
  104. return $result ? $this->response($result) : $this->error()->fail();
  105. }
  106. }