SyncStoreCreateByWmsTest.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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\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 SyncStoreCreateByWmsTest extends TestCase
  24. {
  25. /**
  26. * @var StoreService $service
  27. */
  28. public $service;
  29. public $stores;
  30. public $asnHeaders;
  31. public $created_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 testStoreCreateByWms()
  42. {
  43. $this->created_at = config('sync.asn_sync.created_at');
  44. $this->last_time = ValueStore::query()->where('name',$this->created_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('addTime', '>=', $this->last_time??$time)
  52. ->orderByDesc('addtime')
  53. ->get();
  54. $this->service->storeCreateByWms();
  55. $this->stores = $this->service->getByWms($this->asnHeaders);
  56. $this->assertNotNull($this->stores);
  57. $this->assertEquals(count($this->asnHeaders),count($this->stores));
  58. }
  59. public function tearDown(): void
  60. {
  61. ValueStore::query()->updateOrCreate([
  62. 'name' => $this->created_at,
  63. ], [
  64. 'name' => $this->created_at,
  65. 'value' => $this->last_time,
  66. ]);
  67. $storeIds=[];
  68. foreach ($this->stores as $store){
  69. array_push($storeIds,$store->id);
  70. }
  71. DB::table('stores')->whereIn('asn_code',data_get($this->asnHeaders,'*.asnno'))->delete();
  72. DB::table('store_items')->whereIn('store_id',$storeIds)->delete();
  73. cache()->flush();
  74. parent::tearDown(); // TODO: Change the autogenerated stub
  75. }
  76. }