| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- <?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::query()->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;
- }
- public function first(array $params){
- $owner = Owner::query();
- foreach ($params as $column => $value){
- $owner->where($column, $value);
- }
- return $owner->first();
- }
- public function create(array $params){
- $owner = Owner::query()->create($params);
- return $owner;
- }
- }
|