| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- <?php
- namespace Tests\Services\OrderService\SyncOrderTest;
- use App\Logistic;
- use App\OracleDOCASNHeader;
- use App\Owner;
- use App\Services\common\DataHandlerService;
- use App\Services\LogisticService;
- use App\OracleDOCOrderHeader;
- use App\Services\OracleDOCOrderHeaderService;
- use App\Services\OrderService;
- use App\Services\OwnerService;
- use App\Services\ShopService;
- use App\Services\StoreService;
- use App\Services\WarehouseService;
- use App\Shop;
- use App\ValueStore;
- use App\Warehouse;
- use Carbon\Carbon;
- use Illuminate\Foundation\Testing\RefreshDatabase;
- use Illuminate\Foundation\Testing\WithFaker;
- use Illuminate\Support\Facades\DB;
- use Tests\TestCase;
- class SyncStoreUpdateByWmsTest extends TestCase
- {
- /**
- * @var StoreService $service
- */
- public $service;
- public $stores;
- public $asnHeaders;
- public $update_at;
- public $last_time;
- public function setUp(): void
- {
- parent::setUp();
- $this->service=app(StoreService::class);
- }
- /**
- * @test
- */
- public function testStoreUpdateByWms()
- {
- $this->update_at = config('sync.asn_sync.updated_at');
- $this->last_time = ValueStore::query()->where('name',$this->update_at)->value('value');
- if (!$this->last_time) $time=Carbon::now()->subSeconds(65);
- $this->asnHeaders=OracleDOCASNHeader::query()
- ->with(['asnType', 'asnStatus', 'asnDetails' => function ($query) {
- $query->with(['lineStatus', 'qualityStatus','basSku']);
- }])
- ->select('asnno','asnstatus','asntype','addtime','edittime','customerid','notes','warehouseid','asnreference3')
- ->where('EditTime', '>=', $this->last_time ?? $time)
- ->whereColumn('EditTime', '<>', 'addTime')
- ->orderByDesc('EditTime')
- ->get();
- $this->service->storeUpdateByWms();
- $this->stores = $this->service->getByWms($this->asnHeaders);
- $this->assertNotNull($this->stores);
- $this->assertEquals(count($this->asnHeaders),count($this->stores));
- }
- public function tearDown(): void
- {
- ValueStore::query()->updateOrCreate([
- 'name' => $this->update_at,
- ], [
- 'name' => $this->update_at,
- 'value' => $this->last_time,
- ]);
- $storeIds=[];
- foreach ($this->stores as $store){
- array_push($storeIds,$store->id);
- }
- DB::table('stores')->whereIn('asn_code',data_get($this->asnHeaders,'*.asnno'))->delete();
- DB::table('store_items')->whereIn('store_id',$storeIds)->delete();
- cache()->flush();
- parent::tearDown(); // TODO: Change the autogenerated stub
- }
- }
|