OracleBasCustomerService.php 1.9 KB

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