OracleActAllocationDetailService.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace App\Services;
  3. use App\OracleActAllocationDetails;
  4. use Illuminate\Support\Facades\DB;
  5. /**
  6. * connection : oracle
  7. * table : ACT_ALLOCATION_DETAILS
  8. */
  9. Class OracleActAllocationDetailService
  10. {
  11. private function query($sql, array $params){
  12. if ($params['checktime_start'] ?? false){
  13. $sql .= " AND checktime >= '".$params['checktime_start'].":00'";
  14. }
  15. if ($params['checktime_end'] ?? false){
  16. $sql .= " AND checktime <= '".$params['checktime_end'].":59'";
  17. }
  18. return $sql;
  19. }
  20. public function paginate(array $params){
  21. $sql = "SELECT ACT_ALLOCATION_DETAILS.* FROM(SELECT ACT_ALLOCATION_DETAILS.*,ROWNUM rn FROM
  22. (SELECT orderno FROM ACT_ALLOCATION_DETAILS WHERE 1=1 ";
  23. $sql = $this->query($sql, $params);
  24. $sql .= "GROUP BY orderno)ACT_ALLOCATION_DETAILS)ACT_ALLOCATION_DETAILS
  25. WHERE ACT_ALLOCATION_DETAILS.rn <= ".$params['page']*$params['paginate']." AND rn >".($params['page']-1)*$params['paginate'];
  26. return DB::connection('oracle')->select(DB::raw($sql));
  27. }
  28. public function get(array $params){
  29. $sql = "SELECT orderno FROM ACT_ALLOCATION_DETAILS WHERE 1=1 ";
  30. $sql = $this->query($sql, $params);
  31. $sql .= "GROUP BY orderno";
  32. return DB::connection('oracle')->select(DB::raw($sql));
  33. }
  34. public function getOrderno(array $params){
  35. if (($params['page'] ?? false) && ($params['paginate'] ?? false))$allocations = $this->paginate($params);
  36. else $allocations = $this->get($params);
  37. $count = count($allocations);
  38. if (!$count)return null;
  39. $str = "(";
  40. foreach ($allocations as $index => $allocation){
  41. if ($index < $count-1){
  42. $str .= "'".$allocation->orderno."',";
  43. }else{
  44. $str .= "'".$allocation->orderno."')";
  45. }
  46. }
  47. return $str;
  48. }
  49. /**
  50. * @param array $params
  51. * @return OracleActAllocationDetails
  52. */
  53. public function first(array $params){
  54. $actAllocationDetail = OracleActAllocationDetails::query();
  55. foreach ($params as $column => $value){
  56. $actAllocationDetail->where($column, $value);
  57. }
  58. /** @var OracleActAllocationDetails $actAllocationDetail */
  59. return $actAllocationDetail->first();
  60. }
  61. }