SyncStoreUpdateByWmsTest.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 SyncStoreUpdateByWmsTest extends TestCase
  25. {
  26. /**
  27. * @var StoreService $service
  28. */
  29. public $service;
  30. public $stores;
  31. public $asnHeaders;
  32. public $update_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 testStoreUpdateByWms()
  43. {
  44. $this->update_at = config('sync.asn_sync.updated_at');
  45. $this->last_time = ValueStore::query()->where('name',$this->update_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('EditTime', '>=', $this->last_time ?? $time)
  51. ->whereColumn('EditTime', '<>', 'addTime')
  52. ->orderByDesc('EditTime')
  53. ->get();
  54. $this->service->storeUpdateByWms();
  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->update_at,
  63. ], [
  64. 'name' => $this->update_at,
  65. 'value' => $this->last_time,
  66. ]);
  67. $storeIds=[];
  68. foreach ($this->stores as $store){
  69. array_push($storeIds,$store->id);
  70. }
  71. $storeItems=StoreItems::query()->whereIn('store_id',$storeIds)->get();
  72. $commodity_ids=[];
  73. foreach ($storeItems as $storeItem){
  74. array_push($commodity_ids,$storeItem->commodity_id);
  75. }
  76. DB::table('stores')->whereIn('asn_code',data_get($this->asnHeaders,'*.asnno'))->delete();
  77. DB::table('store_items')->whereIn('store_id',$storeIds)->delete();
  78. DB::table('commodities')->whereIn('id',$commodity_ids)->delete();
  79. cache()->flush();
  80. parent::tearDown(); // TODO: Change the autogenerated stub
  81. }
  82. }