| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- <?php
- namespace App\Services;
- use App\Logistic;
- use App\OracleBasCustomer;
- use Illuminate\Support\Facades\Auth;
- Class LogisticService
- {
- public function getSelection($column = ['id','name']){
- return Logistic::query()->select($column)->get();
- }
- public function getWASLogisticsByWMSOrderHeaders($WMSOrderHeaders){
- $carrierIds = [];
- foreach ($WMSOrderHeaders as $WMSOrderHeader) {
- array_push($carrierIds,$WMSOrderHeader['carrierid']);
- }
- $carrierIds = array_unique($carrierIds);
- $carrierIds = array_diff($carrierIds,['*','',null]);
- $logistics = Logistic::query()->whereIn('code',$carrierIds)->get();
- $fillables = [];
- if(count($carrierIds) > count($logistics)){
- $logistics_fillter= data_get($logistics,'*.code');
- $logisticDiff = array_diff($carrierIds, $logistics_fillter);
- $basCustomers = OracleBasCustomer::query()->where('Customer_Type','CA')->whereIn('CustomerID',$logisticDiff)->get();
- foreach ($basCustomers as $basCustomer){
- $fillable = ['name' => $basCustomer['descr_c'], 'code' => $basCustomer['customerid']];
- array_push($fillables,$fillable);
- }
- }
- try {
- if(count($fillables) > 0){
- Logistic::query()->insert($fillables);
- LogService::log(__METHOD__,__FUNCTION__,'批量创建'.json_encode($fillables));
- }
- } catch (\Exception $e) {
- LogService::log(__METHOD__,__FUNCTION__,'创建失败「' .json_encode($fillables). $e->getMessage().$e->getTraceAsString());
- } finally {
- return $logistics = Logistic::query()->whereIn('code',$carrierIds)->get();
- }
- }
- public function firstOrCreate(array $params, array $values = null){
- $logistic = Logistic::query();
- if ($values)return $logistic->firstOrCreate($params, $values);
- return $logistic->firstOrCreate($params);
- }
- }
|