service = app('OrderService'); $this->orderHeaderService = app('OracleDocOrderHeaderService'); $this->dataHandlerService=app('DataHandlerService'); $this->ownerService=app('OwnerService'); $this->logisticService=app('LogisticService'); $this->shopService=app('ShopService'); $this->warehouseService=app('WarehouseService'); // $this->data['owner'] = factory(Owner::class)->create(['name'=>'测试货主']); DB::insert('insert ignore into owners (code,name) values(?,?)',['TEST_OW','测试货主']); $this->data['owner'] = Owner::query()->where('code','TEST_OW')->where('name','测试货主')->first(); $wmsOrderHeader = factory(OracleDOCOrderHeader::class)->make([ 'customerid'=>$this->data['owner']['code'],'sostatus'=>99,'userdefine1'=>'TEST_CA','warehouseid'=>'WH_TEST' ]); // $this->data['warehouse'] = factory(Warehouse::class)->create(['code'=>'WH_TEST']); $res = DB::insert('insert ignore into logistics (code,name) values(?, ?)',['TEST_CA', '测试承运商']); $this->data['logistic'] = Logistic::query()->where('code','TEST_CA')->where('name','测试承运商')->first(); $this->data['shop'] = factory(Shop::class)->create(['owner_id'=>$this->data['owner']['id']]); $code_BasCode = factory(OracleBasCode::class)->make(['codeid'=>'OW','code'=>'99','descr_c'=>'订单完成']); $orderType = factory(OracleBasCode::class)->make(['code'=>'sysy', 'codeid'=>'SO_TYP', 'codename_c'=>'测试状态']); $wmsOrderHeader->setRelation('orderType',$orderType); $wmsOrderHeader->setRelation('oracleBASCode',$code_BasCode); $this->data['orderHeader'] = $wmsOrderHeader; } /** * @test */ public function getCreateOrderModelByWMSOrderHeaders() { $orderHeaders = collect([$this->data['orderHeader']]); $warehouses = $this->getWareHouses($orderHeaders); $owners = $this->getOwners($orderHeaders); $logistics = $this->getLogistics($orderHeaders); $shops = $this->getShops($orderHeaders); $batches = []; $orders = $this->service->getByWmsOrders($orderHeaders); $crate_orders = $this->service->getCreateOrderModelsByWMSOrderHeaders($orderHeaders, $orders, $warehouses, $owners, $logistics, $shops, $batches); if($orders->count() == $orderHeaders->count() ){ $this->assertEquals($orders->count(),$orderHeaders->count()); } $crate_orders = collect($crate_orders); foreach ($orderHeaders as $orderHeader) { $order = $crate_orders->where('code',$orderHeader->orderno)->first(); $order = new Order($order); $exist_order = $orders->where('code',$orderHeader->orderno)->first(); if(isset($exist_order))continue; $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); } } public function getWareHouses($orderHeaders) { return $this->warehouseService->getByWmsOrders($orderHeaders); } public function getOwners($orderHeaders) { return $this->ownerService->getByWmsOrders($orderHeaders); } public function getLogistics($orderHeaders) { return $this->logisticService->getByWmsOrders($orderHeaders); } public function getShops($orderHeaders) { return $this->shopService->getByWmsOrders($orderHeaders); } public function tearDown(): void { cache()->forget("getLogisticByCode_{$this->data['logistic']}"); cache()->forget("getOwnerByCode_{$this->data['owner']}"); cache()->forget("getShopByCodeMap_{$this->data['shop']}"); // cache()->forget("WareHouse_{$this->data['warehouse']}"); Shop::query()->where('owner_id',$this->data['owner']['id'])->delete(); Logistic::query()->where('code','TEST_CA')->where('name','测试承运商')->forceDelete(); Owner::query()->where('name','测试货主')->delete(); Warehouse::query()->where('code','WH_TEST')->delete(); parent::tearDown(); // TODO: Change the autogenerated stub } }