service = app('OrderService'); $this->orderHeaderService = app('OracleDocOrderHeaderService'); $wmsOrderHeader = factory(OracleDOCOrderHeader::class)->make([ 'customerid'=>'TEST_OW','sostatus'=>99,'userdefine1'=>'TEST_CA','warehouseid'=>'WH_TEST' ]); $orderType = factory(OracleBasCode::class)->make(['code'=>'sysy', 'codeid'=>'SO_TYP', 'codename_c'=>'测试状态']); $wmsOrderHeader->setRelation('orderType',$orderType); $code_BasCode = factory(OracleBasCode::class)->make(['codeid'=>'OW','code'=>'99','descr_c'=>'订单完成']); $wmsOrderHeader->setRelation('oracleBASCode',$code_BasCode); $this->data['warehouse'] = factory(Warehouse::class)->create(['code'=>'WH_TEST']); $this->data['logistic'] = factory(Logistic::class)->create(['code'=>'TEST_CA','name'=>'测试承运商']); $this->data['owner'] = factory(Owner::class)->create(['code'=>'TEST_OW','name'=>'测试货主']); $this->data['shop'] = factory(Shop::class)->create(['owner_id'=>$this->data['owner']['id']]); $this->data['orderHeader'] = $wmsOrderHeader; } /** * @test */ public function getUpdateOrderModelByWMSOrderHeaders() { $orderHeaders = collect([$this->data['orderHeader']]); /** * @var OwnerService $ownerService * @var LogisticService $logisticService * @var ShopService $shopService * @var WarehouseService $warehouseService * @var OrderService $orderService */ $ownerService = app("OwnerService"); $logisticService = app("LogisticService"); $shopService = app('ShopService'); $warehouseService = app('WarehouseService'); $orderService = app('OrderService'); $owners = $ownerService->getByWmsOrders($orderHeaders); $logistics = $logisticService->getByWmsOrders($orderHeaders); $shops = $shopService->getByWmsOrders($orderHeaders); $warehouses = $warehouseService->getByWmsOrders($orderHeaders); $orderService->syncOrderByWMSOrderHeaders($orderHeaders); $orders = Order::query()->whereIn('code',data_get($orderHeaders,'*.orderno'))->get(); $orders->each(function(&$item){ $item->warehouse_id = 1; $item->owner_id = 1; $item->shop_id = 1; $item->logistic_id = 1; $item->consignee_name = Str::random(50); $item->consignee_phone = Str::random(50); $item->province = Str::random(50); $item->city = Str::random(50); $item->district = Str::random(50); $item->address = Str::random(50); $item->client_code = Str::random(52); $item->wms_edittime = Carbon::now(); $item->wms_status = Str::random(10); $item->updated_at = Carbon::now(); $item->created_at = Carbon::now(); }); $update_orders = $this->service->getUpdateOrderModelByWMSOrderHeaders($orderHeaders,$orders,$warehouses,$owners,$logistics,$shops); foreach ($orderHeaders as $orderHeader) { $order = $update_orders->where('code',$orderHeader->orderno)->first(); $this->assertNotNull($order); $warehouse = Warehouse::query()->where('code',$orderHeader->warehouseid)->first(); if($orderHeader->warehouseid ?? false) $this->assertEquals($warehouse->id ?? '',$order->warehouse_id ?? ''); $owner = Owner::query()->where('code',$orderHeader->customerid)->first(); if($orderHeader->customerid ?? false) $this->assertEquals($order->owner_id ?? '',$owner->id??''); $logistic = Logistic::query()->where('code',$orderHeader->userdefine1??'')->first(); if($orderHeader->userdefine1 ?? false) $this->assertEquals($logistic->id ?? '',$logistic->id ?? ''); $shop = Shop::query()->where('name',$orderHeader->issuepartyname)->where('owner_id',$owner->id)->first(); if($orderHeader->issuepartyname ?? false) $this->assertEquals($shop->name,$orderHeader->issuepartyname); $this->assertEquals($order->consignee_name ,$orderHeader->c_contact); $this->assertEquals($order->consignee_phone ,empty($orderHeader->c_tel2)?$orderHeader->c_tel1:$orderHeader->c_tel2); $this->assertEquals($order->province ,$orderHeader->c_province); $this->assertEquals($order->city ,$orderHeader->c_city); $this->assertEquals($order->district ,$orderHeader->c_district); $this->assertEquals($order->client_code ,$orderHeader->soreference1); $this->assertEquals($order->wms_edittime ,(string)$orderHeader->edittime); $this->assertEquals($order->wms_status ,$orderHeader->oracleBASCode_codename_c); // $this->assertEquals((string)$order->created_at ,(string)$orderHeader->addtime); } } }