Prechádzať zdrojové kódy

同步商品调整,修改测试等

haozi 5 rokov pred
rodič
commit
2b37ac8144

+ 1 - 17
app/Http/Controllers/TestController.php

@@ -53,6 +53,7 @@ use App\Services\StoreService;
 use App\Services\WarehouseService;
 use App\Store;
 use App\StoreCheckingReceiveItem;
+use App\StoreItems;
 use App\User;
 use App\Warehouse;
 use App\Waybill;
@@ -1275,23 +1276,6 @@ where (commodities.owner_id,commodity_barcodes.code) in (select commodities.owne
         dd($requests);
     }
 
-    public function testGetCommodity()
-    {
-        /**
-         * @var CommodityService $commodityService
-         */
-        $ownerIds=['13'];
-        $barcodes = 'BH08B4029E027110';
-        $skus = ['BH08B4029E027110'];
-        $commodityService = app(CommodityService::class);
-        //$commodities=$commodityService->get_($ownerIds,$skus,[],true);
-//        dd($commodities->first());
-        $ownerId=13;
-        $sku='BH08B4029E027110';
-        $commodity=$commodityService->syncBarcodes($barcodes,$ownerId,$sku);
-        dd($commodity);
-    }
-
     public function syncOrderTracking()
     {
         /** @var OrderTrackingService $orderTrackingService */

+ 2 - 2
app/Services/CommodityBarcodeService.php

@@ -274,8 +274,8 @@ Class CommodityBarcodeService
             });
             return $map;
         })();
-        return CommodityBarcode::query()->with('commodity')->whereHas('commodity', function ($query) use ($owner_id,$sku) {
-            $query->whereIn('owner_id', array_unique($owner_id))->whereIn('sku',array_unique($sku));
+        return CommodityBarcode::query()->with('commodity')->whereIn('commodity_id', function ($query) use ($owner_id,$sku) {
+            $query->from('commodities')->select('id')->whereIn('owner_id', array_unique($owner_id))->whereIn('sku',array_unique($sku));
         })->get();
     }
     public function deleteCommodityBarcode(array $delete_params)

+ 9 - 4
app/Services/CommodityService.php

@@ -101,6 +101,11 @@ Class CommodityService
             if (is_array($barcode)) $builder->whereIn('code', $barcode);
             else $builder->where('code', $barcode);
         });
+        // haozi  2020-12-14
+//        $query->whereIn('id', function ($builder) use ($barcode) {
+//            if (is_array($barcode)) $builder->from('commodity_barcodes')->select('commodity_id')->whereIn('code', $barcode);
+//            else $builder->from('commodity_barcodes')->select('commodity_id')->where('code', $barcode);
+//        });
         return $query;
     }
 
@@ -784,8 +789,8 @@ Class CommodityService
                     return Cache::remember('commodity_' . $md5, $time, function () use ($skus, $barcodes) {
                         return Commodity::query()
                             ->with(['barcodes', 'owner'])
-                            ->whereHas('barcodes', function ($query) use ($barcodes) {
-                                $query->whereIn('code', $barcodes);
+                            ->whereIn('id', function ($query) use ($barcodes) {
+                                $query->from('commodity_barcodes')->select('commodity_id')->whereIn('code', $barcodes);
                             })
                             ->whereIn('sku', $skus)->get();
                     });
@@ -796,8 +801,8 @@ Class CommodityService
                 sort($barcodes);
                 $commodities = Commodity::query()
                     ->with(['barcodes', 'owner'])
-                    ->whereHas('barcodes', function ($query) use ($barcodes) {
-                        $query->whereIn('code', $barcodes);
+                    ->whereIn('id', function ($query) use ($barcodes) {
+                        $query->from('commodity_barcodes')->select('commodity_id')->whereIn('code', $barcodes);
                     })->get();
                 if ($ownerIds) {
                     sort($ownerIds);

+ 2 - 2
app/Services/StoreItemService.php

@@ -167,8 +167,8 @@ Class StoreItemService
         if (!$asnDetails) {
             return null;
         }
-        return StoreItems::query()->with('store')->whereHas('store', function ($query) use ($asnDetails) {
-            $query->whereIn('asn_code', array_unique(data_get($asnDetails, '*.asnno')));
+        return StoreItems::query()->with('store')->whereIn('store_id', function ($query) use ($asnDetails) {
+            $query->from('stores')->select('id')->whereIn('asn_code', array_unique(data_get($asnDetails, '*.asnno')));
         })->get();
     }
 

+ 3 - 0
database/factories/OracleBasSKUFactory.php

@@ -10,6 +10,9 @@ $factory->define(OracleBasSKU::class, function (Faker $faker) {
         'customerid'=>$faker->name,
         'sku' =>$faker->name,
         'descr_c' =>$faker->title(20),
+        'alternate_sku1' =>$faker->name,
+        'alternate_sku2' =>$faker->name,
+        'alternate_sku3' =>$faker->name,
         'packid'=>$faker->name,
         'skulength' =>$faker->numberBetween(1,100),
         'skuwidth'=>$faker->numberBetween(1,100),

+ 1 - 1
phpunit.xml

@@ -34,7 +34,7 @@
         <server name="APP_ENV" value="testing"/>
         <server name="BCRYPT_ROUNDS" value="4"/>
         <server name="CACHE_DRIVER" value="redis"/>
-        <!--<server name="DB_CONNECTION" value="sqlite"/>
+      <!--  <server name="DB_CONNECTION" value="sqlite"/>
         <server name="DB_DATABASE" value=":memory:"/>-->
         <server name="MAIL_DRIVER" value="array"/>
         <server name="QUEUE_CONNECTION" value="sync"/>

+ 3 - 3
resources/views/inventory/stockInventory/inventoryMission.blade.php

@@ -222,7 +222,7 @@
 
                     <span class="form-group ml-4" v-if="dataExtraStatus.addingNew&&addInventoryMission" id="countBlock">
                         <label for="count" class="text-secondary font-weight-bold">请输盘点数</label>
-                        <input type="text" id="amountInput"  @keypress="amountPress($event)"
+                        <input type="number" id="amountInput"  @keypress="amountPress($event)"
                                name="count" class="form-control input" value="@if(old('count')){{old('count')}}@endif"  autocomplete="off">
                     </span>
                     <span type="button" class="btn btn-sm btn-outline-danger col-md-2 form-group ml-4" v-if="location" style="max-width: 160px" @click="stockInventoryByLocation()">盘点该库位下所有记录</span>
@@ -251,7 +251,7 @@
                         </tr>
                         <tr  class="selectingRow" id="blueTrPc">
                             <td>
-                                <input type="text"  onkeypress="listVue.selectingRow(event)" name="amount" class="form-control-sm blueAmountPc"   autocomplete="off"  oninput="inputs.amount=event.target.value">
+                                <input type="number"  onkeypress="listVue.selectingRow(event)" name="amount" class="form-control-sm blueAmountPc"   autocomplete="off"  oninput="inputs.amount=event.target.value">
                             </td>
                             <td>
                                 <span class="btn btn-sm btn-outline-primary stockButtonPc"  onclick="listVue.盘点选中任务(event)">选定盘点</span>
@@ -281,7 +281,7 @@
                                 <div>
                                     <span  class="mr-3 text-nowrap"><span class="font-weight-bold">输入盘点数:</span>
                                         <span>
-                                                <input type="text"  onkeypress="listVue.selectingRow(event)" name="amount" class="form-control-sm blueAmount"  autocomplete="off"  oninput="inputs.amount=event.target.value">
+                                                <input type="number"  onkeypress="listVue.selectingRow(event)" name="amount" class="form-control-sm blueAmount"  autocomplete="off"  oninput="inputs.amount=event.target.value">
                                         </span>
                                     </span>
                                     <span class="mr-3 text-nowrap"><span class="font-weight-bold">操作:</span><span class="btn btn-sm btn-outline-primary stockButton" onclick="listVue.盘点选中任务(event)">选定盘点</span></span>

+ 0 - 2
tests/Services/CommodityService/GetCommodityByOwnerCodeAndSKUTest.php

@@ -12,8 +12,6 @@ use Tests\TestCase;
 
 class GetCommodityByOwnerCodeAndSKUTest extends TestCase
 {
-    use RefreshDatabase;
-
     /**
      * @var CommodityService $service
      */

+ 0 - 1
tests/Services/CommodityService/GetParamsByBasSKUTest.php

@@ -12,7 +12,6 @@ use Tests\TestCase;
 
 class GetParamsByBasSKUTest extends TestCase
 {
-    use RefreshDatabase;
     /** @var CommodityService $service */
     private $service;
     private $data = [];

+ 61 - 0
tests/Services/CommodityService/Get_Test.php

@@ -0,0 +1,61 @@
+<?php
+
+
+namespace Tests\Services\CommodityService;
+
+
+use App\Commodity;
+use App\CommodityBarcode;
+use App\OracleBasSKU;
+use App\Owner;
+use App\Services\CommodityService;
+use Tests\TestCase;
+
+class Get_Test extends TestCase
+{
+    /** @var CommodityService $service */
+    private $service;
+    private $data = [];
+    private $owner_id;
+    public function setUp(): void
+    {
+        parent::setUp(); // TODO: Change the autogenerated stub
+        cache()->flush();
+        $this->service = app('CommodityService');
+        $owner =  factory(Owner::class)->create();
+        $commodity=factory(Commodity::class)->create(['owner_id'=>$owner->id]);
+        $this->data['owner'] = $owner;
+        $this->data['commodity'] = $commodity;
+        $this->data['basSku']=OracleBasSKU::query()->orderByDesc('edittime')->first();
+    }
+
+    public function testGet_OnlyOwnerIds()
+    {
+        $commodities=$this->service->get_([$this->data['commodity']['owner_id']]);
+        $this->assertNotNull($commodities);
+        $this->assertEquals($this->data['commodity']['sku'],$commodities->first()['sku']);
+    }
+    public function testGet_HasOwnerIdsAndSkus()
+    {
+        $commodities=$this->service->get_([$this->data['commodity']['owner_id']],[$this->data['commodity']['sku']]);
+        $this->assertEquals(1,count($commodities));
+    }
+    public function testGet_SyncAndSelect()
+    {
+        if ($this->data['basSku']) $this->assertNotNull($this->data['basSku']);
+        $this->owner_id=Owner::query()->where('code',$this->data['basSku']['customerid'])->value('id');
+        $commodities=$this->service->get_([ $this->owner_id],[$this->data['basSku']['sku']],[],true);
+        $this->assertEquals($this->data['basSku']['sku'],$commodities->first()['sku']);
+    }
+
+    public function tearDown(): void
+    {
+        $this->data['owner']->delete();
+        $this->data['commodity']->delete();
+        $commodity_id=Commodity::query()->where('owner_id',$this->owner_id)->value('id');
+        Commodity::query()->where('id',$commodity_id)->delete();
+        CommodityBarcode::query()->where('commodity_id',$commodity_id)->delete();
+        cache()->flush();
+        parent::tearDown(); // TODO: Change the autogenerated stub
+    }
+}