| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- <?php
- namespace App\Services;
- use App\OracleBasCustomer;
- use App\Traits\ServiceAppAop;
- class OracleBasCustomerService
- {
- use ServiceAppAop;
- protected $modelClass=OracleBasCustomer::class;
- /** @var CacheService $cacheService */
- private $cacheService;
- function __construct(){
- $this->instant($this->cacheService,'CacheService');
- }
- public function get(array $params){
- $query = $this->query($params);
- return $query->get();
- }
- public function first(array $params){
- return $this->query($params)->first();
- }
- public function count(array $params){
- $query = $this->query($params);
- return $query->count();
- }
- private function query(array $params){
- $query = OracleBasCustomer::query();
- foreach ($params as $column => $value){
- if (is_array($value))$query->whereIn($column,$value);
- else $query->where($column,$value);
- }
- return $query;
- }
- public function getWareHouse($customerIDs = null)
- {
- if(!$customerIDs){
- return OracleBasCustomer::query()->selectRaw('Customer_Type,CustomerId,Descr_C')->where('Customer_Type','WH')->get();
- }
- return OracleBasCustomer::query()
- ->selectRaw('Customer_Type,CustomerId,Descr_C')
- ->where('Customer_Type','WH')
- ->whereIn('CustomerId',$customerIDs)
- ->get();
- }
- public function getCustomers($codes = null)
- {
- return $this->cacheService->getOrExecute('OracleBasCustomersAll'.md5(json_encode($codes)),function()use($codes){
- $query = OracleBasCustomer::query()->select('customerid','descr_c')
- ->where('customer_type','OW')
- ->where('active_flag','Y');
- if ($codes!==null)$query->whereIn('customerid',$codes);
- return $query->get();
- },config('cache.expirations.owners'));
- }
- }
|