OracleBasCustomerService.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace App\Services;
  3. use App\OracleBasCustomer;
  4. Class OracleBasCustomerService
  5. {
  6. /** @var CacheService $cacheService */
  7. private $cacheService;
  8. function __construct(){
  9. $this->cacheService=app('CacheService');
  10. }
  11. public function get(array $params){
  12. $query = $this->query($params);
  13. return $query->get();
  14. }
  15. public function first(array $params){
  16. return $this->query($params)->first();
  17. }
  18. public function count(array $params){
  19. $query = $this->query($params);
  20. return $query->count();
  21. }
  22. private function query(array $params){
  23. $query = OracleBasCustomer::query();
  24. foreach ($params as $column => $value){
  25. if (is_array($value))$query->whereIn($column,$value);
  26. else $query->where($column,$value);
  27. }
  28. return $query;
  29. }
  30. public function getWareHouse($customerIDs = null)
  31. {
  32. if(!$customerIDs){
  33. return OracleBasCustomer::query()->selectRaw('Customer_Type,CustomerId,Descr_C')->where('Customer_Type','WH')->get();
  34. }
  35. return OracleBasCustomer::query()
  36. ->selectRaw('Customer_Type,CustomerId,Descr_C')
  37. ->where('Customer_Type','WH')
  38. ->whereIn('CustomerId',$customerIDs)
  39. ->get();
  40. }
  41. public function getCustomers($codes)
  42. {
  43. return $this->cacheService->getOrExecute('OracleBasCustomersAll'.md5(json_encode($codes)),function()use($codes){
  44. return OracleBasCustomer::query()->select('customerid','descr_c')
  45. ->where('customer_type','OW')
  46. ->where('active_flag','Y')
  47. ->whereIn('customerid',$codes)
  48. ->get();
  49. },config('cache.expirations.owners'));
  50. }
  51. }