OwnerService.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. namespace App\Services;
  3. use App\OracleBasCustomer;
  4. use App\Owner;
  5. use Carbon\Carbon;
  6. Class OwnerService
  7. {
  8. /*
  9. * array | string $column
  10. * 默认一些select字段,可传递string 或 array来指定select字段
  11. */
  12. public function getSelection($column = ['id','name']){
  13. return Owner::filterAuthorities()->select($column)->get();
  14. }
  15. /**
  16. *同步WMS全部货主至WAS
  17. */
  18. public function syncOwnersData(){
  19. $basCustomers=OracleBasCustomer::query()
  20. ->select('CUSTOMERID','DESCR_C')
  21. ->where('DESCR_C','not like','%换ERP%')
  22. ->where('DESCR_C','not like','%退仓%')
  23. ->where('CUSTOMER_TYPE','OW')
  24. ->get();
  25. $ownerCount=Owner::count();
  26. if(count($basCustomers)==$ownerCount)return null;
  27. foreach ($basCustomers as $basCustomer){
  28. $owner=Owner::withTrashed()->where('code',$basCustomer['customerid'])->first();
  29. if (!isset($owner))
  30. Owner::query()->create([
  31. 'code'=> $basCustomer['customerid'],
  32. 'name'=>$basCustomer['descr_c'],
  33. 'created_at'=>Carbon::now()->format('Y-m-d H:i:s'),
  34. ]);
  35. }
  36. $owners=Owner::query()->select('id','name')->get();
  37. return $owners;
  38. }
  39. }