SyncStoreCreateByWmsTest.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. namespace Tests\Services\StoreService;
  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\StoreItems;
  17. use App\ValueStore;
  18. use App\Warehouse;
  19. use Carbon\Carbon;
  20. use Illuminate\Foundation\Testing\RefreshDatabase;
  21. use Illuminate\Foundation\Testing\WithFaker;
  22. use Illuminate\Support\Facades\DB;
  23. use Tests\TestCase;
  24. class SyncStoreCreateByWmsTest extends TestCase
  25. {
  26. /**
  27. * @var StoreService $service
  28. */
  29. public $service;
  30. public $stores;
  31. public $asnHeaders;
  32. public $created_at;
  33. public $last_time;
  34. public function setUp(): void
  35. {
  36. parent::setUp();
  37. $this->service=app(StoreService::class);
  38. }
  39. /**
  40. * @test
  41. */
  42. public function testStoreCreateByWms()
  43. {
  44. $this->created_at = config('sync.asn_sync.created_at');
  45. $this->last_time = ValueStore::query()->where('name',$this->created_at)->value('value');
  46. if (!$this->last_time) $time=Carbon::now()->subSeconds(30);
  47. $this->asnHeaders=OracleDOCASNHeader::query()
  48. ->with(['asnType', 'asnStatus'])
  49. ->select('asnno','asnstatus','asntype','addtime','edittime','customerid','notes','warehouseid','asnreference3')
  50. ->where('addTime', '>=', $this->last_time??$time)
  51. ->orderByDesc('addtime')
  52. ->get();
  53. $this->service->storeCreateByWms();
  54. $this->stores = $this->service->getByWms($this->asnHeaders);
  55. $this->assertNotNull($this->stores);
  56. $this->assertEquals(count($this->asnHeaders),count($this->stores));
  57. }
  58. public function tearDown(): void
  59. {
  60. ValueStore::query()->updateOrCreate([
  61. 'name' => $this->created_at,
  62. ], [
  63. 'name' => $this->created_at,
  64. 'value' => $this->last_time,
  65. ]);
  66. $storeIds=[];
  67. foreach ($this->stores as $store){
  68. array_push($storeIds,$store->id);
  69. }
  70. $storeItems=StoreItems::query()->whereIn('store_id',$storeIds)->get();
  71. $commodity_ids=[];
  72. foreach ($storeItems as $storeItem){
  73. array_push($commodity_ids,$storeItem->commodity_id);
  74. }
  75. DB::table('stores')->whereIn('asn_code',data_get($this->asnHeaders,'*.asnno'))->delete();
  76. DB::table('store_items')->whereIn('store_id',$storeIds)->delete();
  77. DB::table('commodities')->whereIn('id',$commodity_ids)->delete();
  78. cache()->flush();
  79. parent::tearDown(); // TODO: Change the autogenerated stub
  80. }
  81. }