SyncStoreUpdateByWmsTest.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. namespace Tests\Services\OrderService\SyncOrderTest;
  3. use App\Logistic;
  4. use App\OracleDOCASNHeader;
  5. use App\Owner;
  6. use App\Services\common\DataHandlerService;
  7. use App\Services\LogisticService;
  8. use App\OracleDOCOrderHeader;
  9. use App\Services\OracleDOCOrderHeaderService;
  10. use App\Services\OrderService;
  11. use App\Services\OwnerService;
  12. use App\Services\ShopService;
  13. use App\Services\StoreService;
  14. use App\Services\WarehouseService;
  15. use App\Shop;
  16. use App\ValueStore;
  17. use App\Warehouse;
  18. use Carbon\Carbon;
  19. use Illuminate\Foundation\Testing\RefreshDatabase;
  20. use Illuminate\Foundation\Testing\WithFaker;
  21. use Illuminate\Support\Facades\DB;
  22. use Tests\TestCase;
  23. class SyncStoreUpdateByWmsTest extends TestCase
  24. {
  25. /**
  26. * @var StoreService $service
  27. */
  28. public $service;
  29. public $stores;
  30. public $asnHeaders;
  31. public $update_at;
  32. public $last_time;
  33. public function setUp(): void
  34. {
  35. parent::setUp();
  36. $this->service=app(StoreService::class);
  37. }
  38. /**
  39. * @test
  40. */
  41. public function testStoreUpdateByWms()
  42. {
  43. $this->update_at = config('sync.asn_sync.updated_at');
  44. $this->last_time = ValueStore::query()->where('name',$this->update_at)->value('value');
  45. if (!$this->last_time) $time=Carbon::now()->subSeconds(65);
  46. $this->asnHeaders=OracleDOCASNHeader::query()
  47. ->with(['asnType', 'asnStatus', 'asnDetails' => function ($query) {
  48. $query->with(['lineStatus', 'qualityStatus','basSku']);
  49. }])
  50. ->select('asnno','asnstatus','asntype','addtime','edittime','customerid','notes','warehouseid','asnreference3')
  51. ->where('EditTime', '>=', $this->last_time ?? $time)
  52. ->whereColumn('EditTime', '<>', 'addTime')
  53. ->orderByDesc('EditTime')
  54. ->get();
  55. $this->service->storeUpdateByWms();
  56. $this->stores = $this->service->getByWms($this->asnHeaders);
  57. $this->assertNotNull($this->stores);
  58. $this->assertEquals(count($this->asnHeaders),count($this->stores));
  59. }
  60. public function tearDown(): void
  61. {
  62. ValueStore::query()->updateOrCreate([
  63. 'name' => $this->update_at,
  64. ], [
  65. 'name' => $this->update_at,
  66. 'value' => $this->last_time,
  67. ]);
  68. $storeIds=[];
  69. foreach ($this->stores as $store){
  70. array_push($storeIds,$store->id);
  71. }
  72. DB::table('stores')->whereIn('asn_code',data_get($this->asnHeaders,'*.asnno'))->delete();
  73. DB::table('store_items')->whereIn('store_id',$storeIds)->delete();
  74. cache()->flush();
  75. parent::tearDown(); // TODO: Change the autogenerated stub
  76. }
  77. }