Zhouzhendong 5 лет назад
Родитель
Сommit
99517af6ff

+ 1 - 1
app/Commodity.php

@@ -9,7 +9,7 @@ use App\Traits\ModelTimeFormat;
 class Commodity extends Model
 {
     use ModelTimeFormat;
-    protected $fillable=['name','sku','owner_id','created_at','length','width','height','volumn',"type","pack"];
+    protected $fillable=['name','sku','owner_id','created_at','length','width','height','volumn',"type","pack_spec"];
     protected $appends=['barcode'];
 //    protected $appends=['barcode','owner_name','owner_code'];
 

+ 5 - 5
app/Http/Controllers/CommodityController.php

@@ -217,7 +217,7 @@ class CommodityController extends Controller
         $commodities = $commodityService->getOwnerCommodities(['owner_id' => $owner_id, 'sku'=>$skus]);
         $updateCommodities = [];
         $updateCommodities[] = [
-            'id', 'sku', 'name', 'length', 'width', 'height', 'volumn',"pack"
+            'id', 'sku', 'name', 'length', 'width', 'height', 'volumn',"pack_spec"
         ];
         $barcodeMap = [];
         $commoditiesId = [];
@@ -229,7 +229,7 @@ class CommodityController extends Controller
             if (($commodity->sku != $trimSku) || ($commodity->length != $wms->skulength)
                 || ($commodity->width != $wms->skuwidth) || ($commodity->name != $wms->descr_c)
                 || ($commodity->height != $wms->skuhigh) || ($commodity->volumn != $wms->cube)
-                || ($commodity->pack === null)){
+                || ($commodity->pack_spec === null)){
                 $updateCommodities[] = [
                     'id'=>$commodity->id,
                     'sku'=>$trimSku,
@@ -238,7 +238,7 @@ class CommodityController extends Controller
                     'width' => $wms->skuwidth,
                     'height' => $wms->skuhigh,
                     'volumn' => $wms->cube,
-                    "pack"  => $wms->packid == 'STANDARD' ? 0 : explode("/",$wms->packid)[1],
+                    "pack_spec"  => $wms->packid == 'STANDARD' ? 0 : explode("/",$wms->packid)[1],
                 ];
             }
             if ($wms->alternate_sku1){
@@ -300,7 +300,7 @@ class CommodityController extends Controller
                 'width' => $wms->skuwidth,
                 'height' => $wms->skuhigh,
                 'volumn' => $wms->cube,
-                "pack"  => $wms->packid == 'STANDARD' ? 0 : explode("/",$wms->packid)[1],
+                "pack_spec"  => $wms->packid == 'STANDARD' ? 0 : explode("/",$wms->packid)[1],
                 "created_at" => $today,
             ];
             $barcodeMap[$wms->sku] = [];
@@ -340,7 +340,7 @@ class CommodityController extends Controller
                             'width' => $goods['width'],
                             'height' => $goods['height'],
                             'volumn' => $goods['volumn'],
-                            "pack" => $goods["pack"],
+                            "pack_spec" => $goods["pack_spec"],
                         ];
                         unset($createCommodities[$barcodeIndex[$code->code]]);
                         break;

+ 12 - 6
app/Http/Controllers/TestController.php

@@ -6,6 +6,8 @@ namespace App\Http\Controllers;
 use App\Authority;
 use App\Commodity;
 use App\CommodityBarcode;
+use App\Customer;
+use App\Feature;
 use App\Log;
 use App\Logistic;
 use App\OracleActAllocationDetails;
@@ -59,12 +61,16 @@ class TestController extends Controller
     }
 
     public function test4(){
-        DB::beginTransaction();
-        Unit::query()->lockForUpdate()->where("id",14)->first();
-        for($i=0;$i<=100;$i++){
-            sleep(1);
-            var_dump($i);
-        }
+        $model1 = factory(Feature::class,2)->create([[
+            "type" => "商品名称",
+            "logic" => "包含",
+            "describe"=>"衣服",
+        ],[
+            "type" => "订单类型",
+            "logic" => "不包含",
+            "describe"=>"创建",
+        ]]);
+        dd($model1);
     }
 
     public function test2(){

+ 2 - 2
app/Services/CommodityService.php

@@ -225,7 +225,7 @@ Class CommodityService
                 "owner_id" => $owner_id,
                 "sku" => $sku
             ]);
-            if (!$commodity || $commodity->pack === null){
+            if (!$commodity || $commodity->pack_spec === null){
                 $owner = app("OwnerService")->find($owner_id);
                 $action = new CommodityController();
                 $action->syncOwnerCommodities($owner->id,$owner->code,$sku);
@@ -233,7 +233,7 @@ Class CommodityService
             return $that->first([
                 "owner_id" => $owner_id,
                 "sku" => $sku
-            ])->pack;
+            ])->pack_spec;
         });
     }
 }

+ 2 - 2
app/Services/CustomerService.php

@@ -11,9 +11,9 @@ Class CustomerService
         return Customer::query()->select($column)->get();
     }
 
-    public function paginate()
+    public function paginate($paginate = 50)
     {
-        return Customer::query()->orderByDesc('id')->paginate(50);
+        return Customer::query()->orderByDesc('id')->paginate($paginate);
     }
 
     public function create(array $params)

+ 71 - 13
app/Services/FeatureService.php

@@ -16,6 +16,22 @@ Class FeatureService
         return $map;
     }
 
+    /**
+     *  将特征翻译为数组显示
+     *      $str : "1&2|(3&4)"
+     *      array:[
+     *          "strategyGroupStartSign" => false,  //是否为策略组起点,这将在解析时解析为 (
+                "calculation" => "",                //运算规则,目前仅有 &,| 翻译后填入
+                "type"=>"",                         //特征类型
+                "id"=>"",                           //特征ID
+                "logic"=>"",                        //特征逻辑
+                "describe"=>"",                     //特征信息
+                "strategyGroupEndSign" => false,    //是否为策略组终点,这将在解析时解析为 )
+     *      ]
+     *
+     * @param string $str
+     * @return array
+     */
     public function translationFeature($str)
     {
         if (!$str)return null;
@@ -24,14 +40,14 @@ Class FeatureService
         $sign = 0;  //为第二次切割做起点标记
         $model = [];//第二次切割数组
         $ids = [];//记录出现的特征ID,统一查询
-        foreach ($result[0] as $index => &$str){
-            if (is_numeric($str)){
+        foreach ($result[0] as $index => &$item){
+            if (is_numeric($item)){
                 $model[] = array_slice($result[0],$sign,($index-$sign)+1);
                 $sign = $index+1;
-                $ids[] = $str;
+                $ids[] = $item;
                 continue;
             }
-            if ($index == count($result[0])-1 && $str == ')'){
+            if ($index == count($result[0])-1 && $item == ')'){
                 $model[] = [")"];
             }
         }//以数字为标准切割策略组
@@ -50,17 +66,17 @@ Class FeatureService
                 "describe"=>"",  //特征信息
                 "strategyGroupEndSign" => false,//是否为策略组终点,这将在解析时解析为 )
             ];//最终对象组模型,策略组将几组特征组合引用
-            foreach ($m as $str){
-                if (is_numeric($str)){//填入特征信息
-                    if (isset($featureMap[$str])){
-                        $arr["type"] = $features[$featureMap[$str]]->type;
-                        $arr["id"] = $features[$featureMap[$str]]->id;
-                        $arr["logic"] = $features[$featureMap[$str]]->logic;
-                        $arr["describe"] = $features[$featureMap[$str]]->describe;
+            foreach ($m as $string){
+                if (is_numeric($string)){//填入特征信息
+                    if (isset($featureMap[$string])){
+                        $arr["type"] = $features[$featureMap[$string]]->type;
+                        $arr["id"] = $features[$featureMap[$string]]->id;
+                        $arr["logic"] = $features[$featureMap[$string]]->logic;
+                        $arr["describe"] = $features[$featureMap[$string]]->describe;
                     }
                     continue;
                 }
-                switch ($str){//特殊字符的翻译
+                switch ($string){//特殊字符的翻译
                     case "(":
                         $arr["strategyGroupStartSign"] = true;
                         break;
@@ -84,6 +100,24 @@ Class FeatureService
         return $model;
     }
 
+    /**
+     *  与translationFeature相反,将一组与translationFeature参数解析为简述
+     *      $features:[
+     *          "strategyGroupStartSign" => false,  //是否为策略组起点,这将在解析时解析为 (
+                "calculation" => "",                //运算规则,目前仅有 &,| 翻译后填入
+                "type"=>"",                         //特征类型
+                "id"=>"",                           //特征ID
+                "logic"=>"",                        //特征逻辑
+                "describe"=>"",                     //特征信息
+                "strategyGroupEndSign" => false,    //是否为策略组终点,这将在解析时解析为 )
+     *      ]
+     *      array:[
+     *          "feature"   //简述结果
+     *          "map"       //简述中出现的Map特征对象重组为key-val数组
+     *      ]
+     * @param array $features
+     * @return array
+     */
     public function analysisFeature($features)
     {
         $str = "";
@@ -98,7 +132,7 @@ Class FeatureService
             $feature["id"] = $f->id;
             $map[$feature["id"]] = $f;
             if ($feature["calculation"] == '并且')$str .= '&';
-            else $str .= '|';
+            if ($feature["calculation"] == '或') $str .= '|';
             if ($feature["strategyGroupStartSign"])$str .= "(";
             $str .= $feature["id"];
             if ($feature["strategyGroupEndSign"])$str .= ")";
@@ -106,6 +140,18 @@ Class FeatureService
         return ['feature'=>$str,"map"=>$map];
     }
 
+    /**
+     * 格式化简述特征为可阅读显示
+     *      $features : 特征对象集 重组为key-val数组数据,key为ID
+     *      $value : 简述特征 例: "1&2|(3&4)"
+     *      $columnMapping : 特征type属性字段映射 例:["商品名称"=>"commodity_name"],指定该参数会使特征格式化为SQL段
+     *      string : 例:"商品名称 包含 衣服 并且(订单类型 等于 创建订单 或者 承运商 不包含 顺丰)"
+     *
+     * @param array $features
+     * @param string $value
+     * @param array $columnMapping
+     * @return string
+     */
     public function formatFeature(array $features, $value, $columnMapping = null)
     {
         if (!$features)return $value;
@@ -145,6 +191,18 @@ Class FeatureService
         return implode("",$result[0]);
     }
 
+    /**
+     *  匹配特征
+     *      $vale : 特征简述 例: "1&2|(3|4)"
+     *      $columnMapping : 列映射 例:["商品名称"=>"commodity_name"]
+     *      $matchObject : 被匹配对象,必须存在列映射所指定字段 例:["commodity_name"=>"衣服"]
+     *      bool true匹配成功 false匹配失败
+     *
+     * @param string $value
+     * @param array $columnMapping
+     * @param array $matchObject
+     * @return bool
+     */
     public function matchFeature($value, $columnMapping, $matchObject) :bool
     {
         preg_match_all('/\d+/',$value,$ids);

+ 16 - 0
database/factories/FeatureFactory.php

@@ -0,0 +1,16 @@
+<?php
+
+/** @var \Illuminate\Database\Eloquent\Factory $factory */
+
+use App\Feature;
+use Faker\Generator as Faker;
+
+$factory->define(Feature::class, function (Faker $faker) {
+    $type = ['商品名称','订单类型','承运商','店铺类型'];
+    $logic = ['包含','不包含','等于'];
+    return [
+        "type" => $type[array_rand($type)],     //类型
+        "logic" => $logic[array_rand($logic)],    //逻辑
+        "describe" => \Illuminate\Support\Str::random(5), //特征
+    ];
+});

+ 2 - 2
database/migrations/2020_03_25_164101_create_processes_additional_bills_table.php

@@ -15,7 +15,7 @@ class CreateProcessesAdditionalBillsTable extends Migration
      */
     public function up()
     {
-        Schema::create('processes_contents', function (Blueprint $table) {
+        Schema::create('processes_additional_bills', function (Blueprint $table) {
             $table->bigIncrements('id');
             $table->bigInteger('process_id')->index()->comment('外键二次加工单');
             $table->string('wms_code')->index()->comment('单据号');
@@ -32,6 +32,6 @@ class CreateProcessesAdditionalBillsTable extends Migration
      */
     public function down()
     {
-        Schema::dropIfExists('processes_contents');
+        Schema::dropIfExists('processes_additional_bills');
     }
 }

+ 2 - 2
database/migrations/2020_11_17_170541_add_column_pack_commodities_table.php

@@ -14,7 +14,7 @@ class AddColumnPackCommoditiesTable extends Migration
     public function up()
     {
         Schema::table('commodities', function (Blueprint $table) {
-            $table->integer("pack")->nullable()->comment("包装规格");
+            $table->integer("pack_spec")->nullable()->comment("包装规格");
         });
     }
 
@@ -26,7 +26,7 @@ class AddColumnPackCommoditiesTable extends Migration
     public function down()
     {
         Schema::table('commodities', function (Blueprint $table) {
-            $table->dropColumn("pack");
+            $table->dropColumn("pack_spec");
         });
     }
 }

+ 25 - 1
resources/views/maintenance/priceModel/operation/create.blade.php

@@ -57,7 +57,10 @@
             </div>
             <div class="row mt-3">
                 <label class="col-2">特征:</label>
-                <label v-if="model.feature">@{{ model.feature }}</label>
+                <label v-if="model.feature">
+                    @{{ model.feature }}
+                    <input hidden name="feature" :value="model.feature" type="text">
+                </label>
                 <button type="button" class="btn btn-dark col-2 ml-2" @click="showAddFeatureModal(-1,model.feature)">调整特征</button>
             </div>
             <div class="row mt-3">
@@ -175,6 +178,7 @@
                 thisIndex : "",
                 errors:{!! $errors !!},
                 existStrategy:{default:false,starting:false},
+                oldFeature : '',
             },
             methods:{
                 outRuleUnique(strategy){
@@ -203,10 +207,30 @@
                     this.$delete(this.model.rules,index);
                 },
                 showAddFeatureModal(index,feature){
+                    if (!feature){
+                        this.features = [{
+                            "strategyGroupStartSign": false,
+                            "calculation" : "",
+                            "type" : "",
+                            "id" : "",  //特征ID
+                            "logic" : "",  //特征逻辑
+                            "describe" : "",  //特征信息
+                            "strategyGroupEndSign" : false,
+                        }];
+                        this.thisIndex = index;
+                        $("#addFeatureModal").modal("show");
+                        return;
+                    }
+                    if (this.oldFeature == feature) {
+                        this.thisIndex = index;
+                        $("#addFeatureModal").modal("show");
+                        return;
+                    }
                     window.axios.post("{{url('maintenance/priceModel/operation/getFeatures')}}", {feature:feature})
                         .then(res=>{
                             if (res.data.success){
                                 this.features = res.data.data;
+                                this.oldFeature = feature;
                                 if (!this.features || this.features.length === 0){
                                     this.features = [{
                                         "strategyGroupStartSign": false,

+ 5 - 0
resources/views/maintenance/priceModel/operation/index.blade.php

@@ -77,6 +77,11 @@
                             <th class="text-center">特征</th>
                             <th></th>
                         </tr>
+                        <tr v-if="ownerOutStorageRules[thisId] && ownerOutStorageRules[thisId].length == 0">
+                            <td colspan="8">
+                                @can("计费模型-作业-编辑")<button class="btn btn-sm btn-outline-info" @click="showAddRuleModal()">新增</button>@endcan
+                            </td>
+                        </tr>
                         <tr v-for="(item,i) in ownerOutStorageRules[thisId]">
                             <td>
                                 <span v-if="updateDetailId != item.id">

+ 76 - 0
tests/Services/CustomerTest.php

@@ -0,0 +1,76 @@
+<?php
+
+namespace Tests\Unit\Customer;
+
+use App\Customer;
+use App\Services\CustomerService;
+use Illuminate\Support\Str;
+use Tests\TestCase;
+
+class CustomerTest extends TestCase
+{
+    /** @var CustomerService */
+    public $service;
+    public $data;
+
+    public static function tearDownAfterClass(): void
+    {
+        parent::tearDownAfterClass();
+        Customer::query()->truncate();
+    }
+    protected function setUp(): void
+    {
+        parent::setUp();
+        $this->service = app(CustomerService::class);
+        $this->data = [
+            "model" => [
+                "code" => date('Ymd').Str::random(4),
+                "name" => date('Ymd').Str::random(5),
+                "company_name" => date('Ymd').Str::random(6),
+            ]
+        ];
+    }
+
+    public function create(){
+        $model = $this->service->create($this->data["model"]);
+        $this->assertNotNull($model);
+        $this->data["model"]["id"] = $model->id;
+        $this->assertEquals($model->code,$this->data["model"]["code"]);
+        $this->assertEquals($model->name,$this->data["model"]["name"]);
+        $this->assertEquals($model->company_name,$this->data["model"]["company_name"]);
+    }
+    public function testGetSelection(){
+        $this->create();
+        $models = $this->service->getSelection(["id","name","company_name"]);
+        $this->assertGreaterThanOrEqual(1,count($models));
+        $this->assertArrayHasKey("company_name",$models[0]);
+    }
+    public function testPaginate(){
+        $this->create();
+        $models = $this->service->paginate(5);
+        $this->assertGreaterThanOrEqual(1,count($models));
+        $this->assertLessThanOrEqual(5,count($models));
+    }
+    public function testFind(){
+        $this->create();
+        $model = $this->service->find($this->data["model"]["id"]);
+        $this->assertNotNull($model);
+    }
+    public function testUpdate()
+    {
+        $this->create();
+        $value = date('YmdH').Str::random(4);
+        $row = $this->service->update(["id"=>$this->data["model"]["id"]],[
+            "name" => $value,
+        ]);
+        $this->data["model"]["name"] = $value;
+        $this->assertEquals($row,1);
+    }
+    public function testDestroy()
+    {
+        $this->create();
+        $row = $this->service->destroy($this->data["model"]["id"]);
+        $this->assertEquals($row,1);
+        $this->assertDeleted("customers", $this->data["model"]);
+    }
+}

+ 112 - 0
tests/Services/FeatureServiceTest.php

@@ -0,0 +1,112 @@
+<?php
+
+namespace Tests\Unit\Customer;
+
+use App\Feature;
+use App\Services\FeatureService;
+use Tests\TestCase;
+
+class FeatureServiceTest extends TestCase
+{
+    /** @var FeatureService */
+    public $service;
+    public $data;
+
+    protected function setUp(): void
+    {
+        parent::setUp();
+        $this->service = app(FeatureService::class);
+        $this->data = [
+            [
+                "type" => "商品名称",
+                "logic" => "包含",
+                "describe"=>"衣服",
+            ],[
+                "type" => "订单类型",
+                "logic" => "不包含",
+                "describe"=>"创建",
+            ],[
+                "type" => "承运商",
+                "logic" => "等于",
+                "describe"=>"顺丰",
+            ],[
+                "type" => "店铺类型",
+                "logic" => "不包含",
+                "describe"=>"日用品",
+            ],[
+                "type" => "商品名称",
+                "logic" => "不包含",
+                "describe"=>"鞋子",
+            ],[
+                "type" => "订单类型",
+                "logic" => "包含",
+                "describe"=>"取消",
+            ]
+        ];
+    }
+
+    public function testGetMapArray(){
+        factory(Feature::class,3)->create();
+        $models = $this->service->getMapArray();
+        $this->assertGreaterThanOrEqual(3,count($models));
+    }
+    public function testTranslationFeature(){
+        $model1 = factory(Feature::class)->create($this->data[0]);
+        $model2 = factory(Feature::class)->create($this->data[1]);
+        $model3 = factory(Feature::class)->create($this->data[2]);
+        $str = $model1->id."&(".$model2->id."|".$model3->id.")";
+        $result = $this->service->translationFeature($str);
+        $this->assertEquals(3,count($result));
+        $this->assertEquals("订单类型",$result[1]["type"]);
+        $this->assertEquals(false,$result[0]["strategyGroupStartSign"]);
+        $this->assertEquals(true,$result[1]["strategyGroupStartSign"]);
+        $this->assertEquals("并且",$result[1]["calculation"]);
+        $this->assertEquals(true,$result[2]["strategyGroupEndSign"]);
+        $this->assertEquals("或",$result[2]["calculation"]);
+    }
+    public function testAnalysisFeature(){
+        $model1 = factory(Feature::class)->create($this->data[4]);
+        $model2 = factory(Feature::class)->create($this->data[5]);
+        $model3 = factory(Feature::class)->create($this->data[3]);
+        $params = [
+            [
+                "strategyGroupStartSign" => true,
+                "calculation" => "",
+                "type"=>"商品名称",
+                "logic"=>"不包含",
+                "describe"=>"鞋子",
+                "strategyGroupEndSign" => false,
+            ],[
+                "strategyGroupStartSign" => false,
+                "calculation" => "并且",
+                "type"=>"订单类型",
+                "logic"=>"包含",
+                "describe"=>"取消",
+                "strategyGroupEndSign" => true,
+            ],[
+                "strategyGroupStartSign" => false,
+                "calculation" => "或",
+                "type"=>"店铺类型",
+                "logic"=>"不包含",
+                "describe"=>"日用品",
+                "strategyGroupEndSign" => false,
+            ]
+        ];
+        $expected = "(".$model1->id."&".$model2->id.")|".$model3->id;
+        $result = $this->service->analysisFeature($params);
+        $this->assertIsArray($result);
+        $this->assertCount(2,$result);
+        $this->assertArrayHasKey("feature",$result);
+        $this->assertEquals($expected,$result["feature"]);
+    }
+    public function testFormatFeature(){
+
+    }
+    //$expected = "商品名称 包含 衣服 并且(订单类型 不包含 创建 或 承运商 等于 顺丰)";
+
+    public function testTruncate(){
+        Feature::query()->truncate();
+        $feature = Feature::query()->get();
+        $this->assertCount(0,$feature);
+    }
+}

+ 0 - 17
tests/Unit/Customer/CustomerTest.php

@@ -1,17 +0,0 @@
-<?php
-
-namespace Tests\Unit\Customer;
-
-use PHPUnit\Framework\TestCase;
-
-class CustomerTest extends TestCase
-{
-    /**
-     * web访问
-     *
-     * @return void
-     */
-    public function testProjectReportIndex(){
-
-    }
-}