OracleBasCustomerService.php 1.8 KB

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