| 123456789101112131415161718192021222324252627282930313233343536373839404142 |
- <?php
- namespace App\Services;
- use App\OracleBasCustomer;
- use App\Owner;
- use Carbon\Carbon;
- Class OwnerService
- {
- /*
- * array | string $column
- * 默认一些select字段,可传递string 或 array来指定select字段
- */
- public function getSelection($column = ['id','name']){
- return Owner::filterAuthorities()->select($column)->get();
- }
- /**
- *同步WMS全部货主至WAS
- */
- public function syncOwnersData(){
- $basCustomers=OracleBasCustomer::query()
- ->select('CUSTOMERID','DESCR_C')
- ->where('DESCR_C','not like','%换ERP%')
- ->where('DESCR_C','not like','%退仓%')
- ->where('CUSTOMER_TYPE','OW')
- ->get();
- $ownerCount=Owner::count();
- if(count($basCustomers)==$ownerCount)return null;
- foreach ($basCustomers as $basCustomer){
- $owner=Owner::withTrashed()->where('code',$basCustomer['customerid'])->first();
- if (!isset($owner))
- Owner::query()->create([
- 'code'=> $basCustomer['customerid'],
- 'name'=>$basCustomer['descr_c'],
- 'created_at'=>Carbon::now()->format('Y-m-d H:i:s'),
- ]);
- }
- $owners=Owner::query()->select('id','name')->get();
- return $owners;
- }
- }
|