Просмотр исходного кода

客户管理-计费模型
问题件导出信息字段更新

Zhouzhendong 5 лет назад
Родитель
Сommit
365fd63fdc

+ 1 - 0
app/Console/Kernel.php

@@ -36,6 +36,7 @@ class Kernel extends ConsoleKernel
         $schedule->command('WASSyncWMSOrderInformation')->everyMinute();
         $schedule->command('syncLogCacheTask')->everyMinute();
         $schedule->command('createOwnerReport')->monthlyOn(1);
+        $schedule->command('createOwnerBillReport')->monthlyOn(1);
         $schedule->command('createOwnerAreaReport')->monthlyOn(25);
     }
 

+ 50 - 1
app/Http/Controllers/PriceModelController.php

@@ -2,6 +2,9 @@
 
 namespace App\Http\Controllers;
 
+use App\OwnerPriceOperation;
+use App\Services\OwnerOutStorageRuleService;
+use Illuminate\Database\Eloquent\Builder;
 use Illuminate\Http\Request;
 use Illuminate\Support\Facades\Gate;
 use Illuminate\Support\Facades\Validator;
@@ -86,11 +89,57 @@ class PriceModelController extends Controller
 
     public function operationIndex(Request $request){
         if(!Gate::allows('计费模型-作业-查询')){ return redirect('denied');  }
-        $models = app('OwnerPriceOperationService')->paginate($request->input(),["ownerInStorageRules","ownerOutStorageRules"]);
+        $models = app('OwnerPriceOperationService')->paginate($request->input(),["ownerInStorageRule"=>function($query){$query->with("unit");}]);
         $owners = app("OwnerService")->getSelection();
         return response()->view('maintenance.priceModel.operation.index',compact("models","owners"));
     }
 
+    /* 获取出库模型规则 */
+    public function operationGetOutStorageRule(Request $request)
+    {
+        if(!Gate::allows('计费模型-作业-查询')){ return ["success"=>false,"data"=>"无权操作"];  }
+        /** @var OwnerOutStorageRuleService $service */
+        $service = app('OwnerOutStorageRuleService');
+        $ownerOutStorageRules = $service->get(["owner_price_operation_id"=>$request->input("id")],["unit"],true);
+        return ["success"=>true,"data"=>$ownerOutStorageRules];
+    }
+    /* 修改出库模型规则 */
+    public function updateOutStorageRule(Request $request)
+    {
+        /** @var OwnerOutStorageRuleService $service */
+        $service = app('OwnerOutStorageRuleService');
+        $row = $service->update(["id"=>$request->input("id")],[
+            "amount"=>$request->input("amount"),
+            "unit_id"=>$request->input("unit_id"),
+            "priority"=>$request->input("priority"),
+            "unit_price"=>$request->input("unit_price")]);
+        if ($row == 1) return ["success"=>true];
+        return ["success"=>false,"data"=>"受影响数据数为:".$row];
+    }
+
+    public function createOutStorageRule(Request $request)
+    {
+        /** @var OwnerOutStorageRuleService $service */
+        $service = app('OwnerOutStorageRuleService');
+        switch ($request->input("strategy")){
+            case "起步":
+                $c = $service->isExist(["owner_price_operation_id"=>$request->input("owner_price_operation_id"),"strategy"=>"起步"]);
+                if ($c > 0)return ["success"=>false,"data"=>"已存在起步策略"];
+                break;
+            case "默认":
+                $c = $service->isExist(["owner_price_operation_id"=>$request->input("owner_price_operation_id"),"strategy"=>"默认"]);
+                if ($c > 0)return ["success"=>false,"data"=>"已存在默认策略"];
+                break;
+        }
+        $data = $service->create($request->input());
+        $data->load("unit");
+        return ["success"=>true,"data"=>$data];
+    }
+    public function getFeatures(Request $request)
+    {
+        return ["success"=>true,"data"=>app("FeatureService")->translationFeature($request->input("feature"))];
+    }
+
     public function operationCreate(){
         if(!Gate::allows('计费模型-作业-录入')){ return redirect('denied');  }
         return response()->view('maintenance.priceModel.operation.create');

+ 3 - 3
app/Http/Controllers/TestController.php

@@ -9,6 +9,7 @@ use App\City;
 use App\Commodity;
 use App\CommodityBarcode;
 use App\Events\CancelOrder;
+use App\Feature;
 use App\InventoryAccountMission;
 use App\InventoryCompare;
 use App\InventoryDailyLog;
@@ -30,6 +31,7 @@ use App\OrderTracking;
 use App\OrderTrackingOwner;
 use App\Owner;
 use App\OwnerFeeDetail;
+use App\OwnerOutStorageRule;
 use App\OwnerPriceOperation;
 use App\Package;
 use App\Process;
@@ -91,9 +93,7 @@ class TestController extends Controller
     }
 
     public function test4(){
-        $o = new OwnerPriceOperation;
-        dd($o->getIds('2,1'));
-
+        $str = "(1&2)|(3&78)&50";
     }
 
     public function test2(){

+ 5 - 0
app/Http/Controllers/UnitsController.php

@@ -79,4 +79,9 @@ class UnitsController extends Controller
         ]);
         return $validator;
     }
+
+    public function getUnits()
+    {
+        return ["success"=>true,"data"=>app("UnitService")->getSelection()];
+    }
 }

+ 63 - 0
app/OwnerOutStorageRule.php

@@ -13,11 +13,74 @@ class OwnerOutStorageRule extends Model
         "unit_id",                          //单位ID
         "unit_price",                       //单价
         "feature",                          //特征
+        "priority",                         //优先级 值越大越高
     ];
     public $timestamps=false;
 
+    public static $features = null;
+    public static $columnMapping = null;
+
     public function unit()
     {   //单位
         return $this->hasOne(Unit::class,"id","unit_id");
     }
+
+    public function translateFeature(array $features)
+    {
+        $result = [];
+        preg_match_all('/\d+|[\&\|\(\)]/',$this->feature,$result);
+        foreach ($result[0] as &$str){
+            if (is_numeric($str) && isset($features[$str]))$str = $features[$str]["type"].' '.$features[$str]["logic"].' '.$features[$str]["describe"];
+        }
+        $this->feature = implode("",$result[0]);
+    }
+
+    public function getFeatureAttribute($value)
+    {
+        if ($this->strategy == '默认')return "/";
+        return $value;
+    }
+
+
+    /* 格式化依据静态参数,在调用前设置  */
+    public function getFeatureFormatAttribute($value)
+    {
+        if ($this->strategy == '默认')return "/";
+        if (!self::$features)return $value;
+        $result = [];
+        preg_match_all('/\d+|[\&\|\(\)]/',$value,$result);
+        foreach ($result[0] as &$str){
+            if (is_numeric($str) && isset(self::$features[$str])){
+                $column = self::$features[$str]["type"];
+                $logic = self::$features[$str]["logic"];
+                $describe = self::$features[$str]["describe"];
+                if (self::$columnMapping){
+                    $column = self::$columnMapping[$column] ?? $column;
+                    switch ($logic){
+                        case "包含":
+                            $logic = " like ";
+                            $describe = "%".$describe."%";
+                            break;
+                        case "不包含":
+                            $logic = " not like ";
+                            $describe = "%".$describe."%";
+                            break;
+                        case "等于":
+                            $logic = " = ";
+                            break;
+                    }
+                    $str = $column.$logic.$describe;
+                }else $str = self::$features[$str]["type"].' '.self::$features[$str]["logic"].' '.self::$features[$str]["describe"];
+            }
+            if ($str == "&"){
+                if (self::$columnMapping) $str = " and ";
+                else $str = " 并且 ";
+            }
+            if ($str == "|"){
+                if (self::$columnMapping) $str = " or ";
+                else $str = " 或 ";
+            }
+        }
+        return implode("",$result[0]);
+    }
 }

+ 4 - 2
app/OwnerPriceOperation.php

@@ -13,11 +13,13 @@ class OwnerPriceOperation extends Model
         "strategy",         //策略
         "feature",          //特征
         "remark",           //备注
+        "priority",         //优先级 值越大越高
     ];
 
-    public function ownerInStorageRules()
+
+    public function ownerInStorageRule()
     {   //入库规则
-        return $this->hasMany(OwnerInStorageRule::class,"owner_price_operation_id","id");
+        return $this->hasOne(OwnerInStorageRule::class,"owner_price_operation_id","id");
     }
     public function ownerOutStorageRules()
     {   //出库规则

+ 4 - 0
app/Providers/AppServiceProvider.php

@@ -12,6 +12,7 @@ use App\Services\CommodityBarcodeService;
 use App\Services\common\DataHandlerService;
 use App\Services\CustomerService;
 use App\Services\DepositoryService;
+use App\Services\FeatureService;
 use App\Services\InventoryAccountMissionService;
 use App\Services\InventoryCompareService;
 use App\Services\OracleBasSkuService;
@@ -32,6 +33,7 @@ use App\Services\OrderTrackingService;
 use App\Services\OwnerAreaReportService;
 use App\Services\OwnerBillReportService;
 use App\Services\OwnerFeeDetailService;
+use App\Services\OwnerOutStorageRuleService;
 use App\Services\OwnerPriceOperationService;
 use App\Services\OwnerReportService;
 use App\Services\OwnerService;
@@ -173,6 +175,8 @@ class AppServiceProvider extends ServiceProvider
         app()->singleton('OwnerStoragePriceModelService',OwnerStoragePriceModelService::class);
         app()->singleton('UnitService',UnitService::class);
         app()->singleton('OwnerPriceOperationService',OwnerPriceOperationService::class);
+        app()->singleton('FeatureService',FeatureService::class);
+        app()->singleton('OwnerOutStorageRuleService',OwnerOutStorageRuleService::class);
     }
 
     private function loadingRejectedModuleService(){

+ 79 - 0
app/Services/FeatureService.php

@@ -0,0 +1,79 @@
+<?php 
+
+namespace App\Services; 
+
+use App\Feature;
+
+Class FeatureService
+{
+    public function getMapArray()
+    {
+        $features = Feature::query()->get();
+        $map = [];
+        foreach ($features as $feature){
+            $map[$feature->id] = ["type"=>$feature->type,"logic"=>$feature->logic,"describe"=>$feature->describe];
+        }
+        return $map;
+    }
+
+    public function translationFeature($str)
+    {
+        if (!$str)return null;
+        $result = [];
+        preg_match_all('/\d+|[\&\|\(\)]/',$str,$result); //初次匹配以数字&|()为分隔符生成数组
+        $sign = 0;  //为第二次切割做起点标记
+        $model = [];//第二次切割数组
+        $ids = [];//记录出现的特征ID,统一查询
+        foreach ($result[0] as $index => &$str){
+            if (is_numeric($str)){
+                $model[] = array_slice($result[0],$sign,($index-$sign)+1);
+                $sign = $index+1;
+                $ids[] = $str;
+            }
+        }//以数字为标准切割策略组
+        $features = Feature::query()->find($ids);//查询出现的特征
+        $featureMap = [];
+        foreach ($features as $index => $feature){
+            $featureMap[$feature->id] = $index;
+        }//为查询的特征重组为key-val形式数组留做引用
+        foreach ($model as $index => &$m){
+            $arr = [
+                "strategyGroupStartSign" => false,//是否为策略组起点,这将在解析时解析为 (
+                "calculation" => "",//运算规则,目前仅有 &,| 翻译后填入
+                "type"=>"",  //特征类型
+                "id"=>"",  //特征ID
+                "logic"=>"",  //特征逻辑
+                "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;
+                    }
+                    continue;
+                }
+                switch ($str){//特殊字符的翻译
+                    case "(":
+                        $arr["strategyGroupStartSign"] = true;
+                        break;
+                    case ")":
+                        $model[$index-1]["strategyGroupEndSign"] = true;
+                        break;
+                    case "&":
+                        $arr["calculation"] = "并且";
+                        break;
+                    case "|":
+                        $arr["calculation"] = "或";
+                        break;
+                }
+            }
+            $m = $arr;//变更当前指针为翻译结果
+        }
+        return $model;
+    }
+
+}

+ 5 - 3
app/Services/OrderIssueService.php

@@ -227,15 +227,17 @@ class OrderIssueService
                 ->selectRaw('order_issues.id order_issue_id')
             ->sql();
         $secondOrderPackageSql = Order::query()->from('order_packages','s_o_p')->selectRaw('s_o_p.logistic_number')
+            ->leftJoin("orders as o_d","s_o_p.order_id","o_d.id")
             ->leftJoin('order_package_commodities as s_o_p_c','s_o_p_c.order_package_id','s_o_p.id')
                 ->selectRaw('s_o_p_c.amount s_o_p_c_amount')
             ->leftJoin('commodities as s_c','s_o_p_c.commodity_id','s_c.id')
                 ->selectRaw('s_c.sku s_c_sku,s_c.name s_c_name')
-            ->leftJoin('order_issues','s_o_p.order_id','order_issues.second_order_id')
+            ->leftJoin('order_issues','o_d.client_code','order_issues.second_client_no')
                 ->selectRaw('order_issues.id order_issue_id')
             ->sql();
         $rejectedBillItemSql = RejectedBillItem::query()->selectRaw('rejected_bill_items.remark,rejected_bill_items.amount rejected_bill_amount,rejected_bill_items.name_goods,rejected_bill_items.barcode_goods')
-            ->leftJoin('order_issues','rejected_bill_items.id_rejected_bill','order_issues.rejected_bill_id')
+            ->leftJoin('rejected_bills',"rejected_bill_items.id_rejected_bill","rejected_bills.id")
+            ->leftJoin('order_issues','rejected_bills.logistic_number_return','order_issues.logistic_number_return')
                 ->selectRaw('order_issues.id order_issue_id')
             ->sql();
         $logSql = OrderIssueProcessLog::query()->selectRaw('order_issue_process_logs.content log_content,order_issue_process_logs.type log_type')
@@ -257,7 +259,7 @@ class OrderIssueService
                 ->selectRaw('owners.name owner_name')
             ->leftJoin('shops','orders.shop_id','shops.id')
                 ->selectRaw('shops.name shop_name')
-            ->leftJoin('orders as s_o','s_o.id','order_issues.second_order_id')
+            ->leftJoin('orders as s_o','s_o.client_code','order_issues.second_client_no')
                 ->selectRaw('s_o.id s_o_id,s_o.client_code s_o_client_code')
             ->leftJoin('logistics as s_logistics','s_o.logistic_id','s_logistics.id')
                 ->selectRaw('s_logistics.name s_logistics_name')

+ 47 - 0
app/Services/OwnerOutStorageRuleService.php

@@ -0,0 +1,47 @@
+<?php 
+
+namespace App\Services; 
+
+use App\OwnerOutStorageRule;
+
+Class OwnerOutStorageRuleService
+{ 
+    public function get(array $params, array $withs = [], $isTranslateFeature = false, array $translateColumn = [])
+    {
+        if ($isTranslateFeature){
+            $features = app("FeatureService")->getMapArray();
+            OwnerOutStorageRule::$features = $features;
+            OwnerOutStorageRule::$columnMapping = $translateColumn;
+        }
+        $rule = OwnerOutStorageRule::query();
+        if ($withs)$rule->with($withs);
+        foreach ($params as $column=>$param){
+            $rule->where($column,$param);
+        }
+        return $rule->get()->append("featureFormat");
+    }
+
+    public function update(array $params, array $values)
+    {
+        $query = OwnerOutStorageRule::query();
+        foreach ($params as $column=>$param){
+            $query->where($column,$param);
+        }
+        return $query->update($values);
+    }
+
+    public function create(array $params)
+    {
+        return OwnerOutStorageRule::query()->create($params);
+    }
+
+
+    public function isExist(array $params)
+    {
+        $query = OwnerOutStorageRule::query();
+        foreach ($params as $column=>$param){
+            $query->where($column,$param);
+        }
+        return $query->count();
+    }
+}

+ 1 - 0
database/migrations/2020_10_27_175452_create_owner_price_operations_table.php

@@ -18,6 +18,7 @@ class CreateOwnerPriceOperationsTable extends Migration
             $table->enum("operation_type",["入库","出库"])->default("入库")->comment("操作类型");
             $table->string("name")->nullable()->comment("名称");
             $table->enum("strategy",["默认","特征"])->default("默认")->comment("策略");
+            $table->integer("priority")->default(0)->index()->comment("匹配优先级(越大越优先)");
             $table->string("feature")->nullable()->comment("特征");
             $table->string("remark")->nullable()->comment("备注");
             $table->timestamps();

+ 3 - 1
database/migrations/2020_10_28_105613_create_owner_out_storage_rules_table.php

@@ -14,12 +14,14 @@ class CreateOwnerOutStorageRulesTable extends Migration
     public function up()
     {
         Schema::create('owner_out_storage_rules', function (Blueprint $table) {
-            $table->bigInteger("owner_price_operation_id")->comment("外键作业计费模型");
+            $table->id();
+            $table->bigInteger("owner_price_operation_id")->index()->comment("外键作业计费模型");
             $table->enum("strategy",["起步","默认","特征"])->comment("出库策略");
             $table->integer("amount")->nullable()->comment("起步数");
             $table->bigInteger("unit_id")->index()->comment("外键单位");
             $table->decimal("unit_price",8,4)->comment("单价");
             $table->string("feature")->nullable()->comment("特征");
+            $table->integer("priority")->default(0)->index()->comment("匹配优先级(越大越优先)");
         });
     }
 

+ 2 - 1
database/migrations/2020_10_28_105639_create_owner_in_storage_rules_table.php

@@ -14,7 +14,8 @@ class CreateOwnerInStorageRulesTable extends Migration
     public function up()
     {
         Schema::create('owner_in_storage_rules', function (Blueprint $table) {
-            $table->bigInteger("owner_price_operation_id")->primary()->comment("外键作业计费模型");
+            $table->id();
+            $table->bigInteger("owner_price_operation_id")->index()->comment("外键作业计费模型");
             $table->integer("amount")->default(1)->comment("计量");
             $table->bigInteger("unit_id")->index()->comment("外键单位");
             $table->decimal("unit_price",8,4)->comment("单价");

+ 52 - 0
resources/views/maintenance/priceModel/operation/_addFeature.blade.php

@@ -0,0 +1,52 @@
+<div class="modal fade" tabindex="-1" role="dialog" id="addFeatureModal">
+    <div class="modal-dialog modal-xl modal-dialog-centered modal-dialog-scrollable">
+        <div class="modal-content">
+            <div class="modal-body">
+                <div class="container-fluid">
+                    <div class="row text-primary">
+                        <label class="col-2">特征组起始标记</label>
+                        <label class="col-1">运算规则</label>
+                        <label class="col-2">特征类型</label>
+                        <label class="col-1">特征逻辑</label>
+                        <label class="col-4">特征内容</label>
+                        <label class="col-2">特征组结束标记</label>
+                    </div>
+                    <div class="row" v-for="feature in features">
+                        <div class="form-check col-2">
+                            <label class="form-check-label">
+                                <input type="checkbox" class="form-check-input" :checked="feature.strategyGroupStartSign">
+                            </label>
+                        </div>
+                        <label class="col-1">
+                            <select class="form-control form-control-sm" v-model="feature.calculation">
+                                <option value="并且">并且</option>
+                                <option value="或">或</option>
+                            </select>
+                        </label>
+                        <label class="col-2">
+                            <select class="form-control form-control-sm" v-model="feature.type">
+                                <option v-for="t in type" :value="t">@{{ t }}</option>
+                            </select>
+                        </label>
+                        <label class="col-1">
+                            <select class="form-control form-control-sm" v-model="feature.logic">
+                                <option v-for="l in logic" :value="l">@{{ l }}</option>
+                            </select>
+                        </label>
+                        <label class="col-4">
+                            <input class="form-control form-control-sm" v-model="feature.describe">
+                        </label>
+                        <div class="form-check col-2">
+                            <label class="form-check-label">
+                                <input type="checkbox" class="form-check-input" :checked="feature.strategyGroupEndSign">
+                            </label>
+                        </div>
+                    </div>
+                </div>
+            </div>
+            <div class="modal-footer">
+                <button type="button" class="btn btn-success" @click="submitRule()">提交</button>
+            </div>
+        </div>
+    </div>
+</div>

+ 35 - 0
resources/views/maintenance/priceModel/operation/_addOutStorageRuleModal.blade.php

@@ -0,0 +1,35 @@
+<div class="modal fade" tabindex="-1" role="dialog" id="addOutStorageRule">
+    <div class="modal-dialog modal-dialog-centered">
+        <div class="modal-content">
+            <div class="modal-body">
+                <div class="mt-3 row">
+                    <label for="strategy" class="col-4">计费策略</label>
+                    <select id="strategy" class="form-control form-control-sm col-6" v-model="rule.strategy">
+                        <option v-for="s in strategy" :value="s">@{{ s }}</option>
+                    </select>
+                </div>
+                <div class="mt-3 row">
+                    <label for="amount" class="col-4">起步数</label>
+                    <input type="number" min="0" id="amount" class="form-control form-control-sm col-8"  v-model="rule.amount">
+                </div>
+                <div class="mt-3 row">
+                    <label for="unit_id" class="col-4">单位</label>
+                    <select id="unit_id" class="form-control form-control-sm col-6" v-model="rule.unit_id">
+                        <option v-for="unit in units" :value="unit.id">@{{ unit.name }}</option>
+                    </select>
+                </div>
+                <div class="mt-3 row">
+                    <label for="unit_price" class="col-4">单价</label>
+                    <input type="number" min="0" step="0.001" id="unit_price" class="form-control form-control-sm col-8" v-model="rule.unit_price">
+                </div>
+                <div class="mt-3 row">
+                    <label for="priority" class="col-4">优先级</label>
+                    <input type="number" min="0" id="priority" class="form-control form-control-sm col-8" v-model="rule.priority">
+                </div>
+            </div>
+            <div class="modal-footer">
+                <button type="button" class="btn btn-success" @click="submitRule()">提交</button>
+            </div>
+        </div>
+    </div>
+</div>

+ 228 - 7
resources/views/maintenance/priceModel/operation/index.blade.php

@@ -7,6 +7,8 @@
         @component('maintenance.priceModel.operation.menu')@endcomponent
     </div>
     <div class="container-fluid mt-2" id="container">
+        @include("maintenance.priceModel.operation._addOutStorageRuleModal")
+        @include("maintenance.priceModel.operation._addFeature")
         <div id="form_div"></div>
         <table class="table table-hover table-striped text-nowrap">
             <tr>
@@ -16,30 +18,108 @@
                 <th>类型</th>
                 <th>策略</th>
                 <th>项目</th>
+                <th>计量</th>
+                <th>单位</th>
+                <th>单价</th>
+                <th>优先级</th>
                 <th>特征</th>
                 <th>备注</th>
                 <th>录入时间</th>
                 <th>操作</th>
             </tr>
-            <tr v-for="(model,i) in models">
+            <tr v-for="(model,i) in models" :id="'model-'+model.id">
                 <td>@{{ i+1 }}</td>
                 <td>
-                    <button class="btn btn-sm btn-info">维护详情</button>
-                    <table class="table table-sm table-bordered table-striped">
-                        <tr>
-
-                        </tr>
-                    </table>
+                    <button v-if="model.operationType == '出库' && thisId != model.id" class="btn btn-sm btn-info" @click="showDetail(model.id)">维护详情</button>
+                    <button v-if="model.operationType == '出库' && thisId == model.id" class="btn btn-sm btn-dark" @click="thisId = ''">关闭详情</button>
                 </td>
                 <td>@{{ model.name }}</td>
                 <td>@{{ model.operationType }}</td>
                 <td>@{{ model.strategy }}</td>
                 <td>货主们</td>
+                <td>
+                    <label v-if="model.operationType == '出库'">/</label>
+                    <label v-else>@{{ model.ownerInStorageRuleAmount }}</label>
+                </td>
+                <td>
+                    <label v-if="model.operationType == '出库'">/</label>
+                    <label v-else>@{{ model.ownerInStorageRuleUnitName }}</label>
+                </td>
+                <td>
+                    <label v-if="model.operationType == '出库'">/</label>
+                    <label v-else>@{{ model.ownerInStorageRuleUnitPrice }}</label>
+                </td>
+                <td>@{{ model.priority }}</td>
                 <td>@{{ model.feature }}</td>
                 <td>@{{ model.remark }}</td>
                 <td>@{{ model.createdAt }}</td>
                 <td></td>
             </tr>
+            <tr id="detail" v-show="thisId">
+                <td></td>
+                <td colspan="9">
+                    <table class="table table-sm table-bordered">
+                        <tr class="text-success">
+                            <th>操作</th>
+                            <th>计费策略</th>
+                            <th>起步数</th>
+                            <th>单位</th>
+                            <th>单价</th>
+                            <th>优先级</th>
+                            <th class="text-center">特征</th>
+                            <th></th>
+                        </tr>
+                        <tr v-for="(item,i) in ownerOutStorageRules[thisId]">
+                            <td>
+                                <span v-if="updateDetailId != item.id">
+                                    <button class="btn btn-sm btn-outline-info" @click="showAddRuleModal()" v-if="i==0">新增</button>
+                                    <button class="btn btn-sm btn-outline-info" @click="showUpdateDetail(item.id)">修改</button>
+                                </span>
+                                <span v-else>
+                                    <button class="btn btn-sm btn-success" @click="submitUpdateDetail(item)">确定</button>
+                                    <button class="btn btn-sm btn-danger" @click="updateDetailId = ''">取消</button>
+                                </span>
+                            </td>
+                            <td>@{{ item.strategy }}</td>
+                            <td>
+                                <label v-if="updateDetailId == item.id">
+                                    <input type="number" min="0" id="detailAmount"  class="form-control form-control-sm"
+                                           :value="item.amount">
+                                </label>
+                                <label v-else>@{{ item.amount }}</label>
+                            </td>
+                            <td>
+                                <label v-if="updateDetailId == item.id">
+                                    <select class="form-control form-control-sm" id="detailUnit">
+                                        <option v-for="unit in units" :value="unit.id" v-if="unit.id==item.unit_id" selected>@{{ unit.name }}</option>
+                                        <option v-for="unit in units" :value="unit.id" v-if="unit.id!=item.unit_id">@{{ unit.name }}</option>
+                                    </select>
+                                </label>
+                                <label v-else>@{{ item.unit ? item.unit.name : '' }}</label>
+                            </td>
+                            <td>
+                                <label v-if="updateDetailId == item.id">
+                                    <input type="number" min="0" step="0.001" id="detailUnitPrice" class="form-control form-control-sm"
+                                           :value="item.unit_price">
+                                </label>
+                                <label v-else>@{{ item.unit_price }}</label>
+                            </td>
+                            <td>
+                                <label v-if="updateDetailId == item.id">
+                                    <input type="number" min="0" id="detailPriority" class="form-control form-control-sm"
+                                           :value="item.priority">
+                                </label>
+                                <label v-else>@{{ item.priority }}</label>
+                            </td>
+                            <td>@{{ item.featureFormat }}</td>
+                            <td>@{{ item.feature }}</td>
+                            <td>
+                                <button class="btn btn-sm btn-success" v-if="item.strategy == '特征'" @click="showAddFeatureModal(i,item.feature)">维护特征</button>
+                            </td>
+                        </tr>
+                    </table>
+                </td>
+            </tr>
         </table>
     </div>
 @stop
@@ -59,7 +139,11 @@
                         strategy : "{{$model->strategy}}",
                         feature : "{{$model->feature}}",
                         remark : "{{$model->remark}}",
+                        priority : "{{$model->priority}}",
                         createdAt : "{{$model->created_at}}",
+                        ownerInStorageRuleAmount : "{{$model->ownerInStorageRule ? $model->ownerInStorageRule->amount : ''}}",
+                        ownerInStorageRuleUnitName : "{{$model->ownerInStorageRule ? ($model->ownerInStorageRule->unit ? $model->ownerInStorageRule->unit->name : '') : ''}}",
+                        ownerInStorageRuleUnitPrice : "{{$model->ownerInStorageRule ? $model->ownerInStorageRule->unit_price : ''}}",
                     },
                     @endforeach
                 ],
@@ -68,6 +152,22 @@
                     {name:"{{$owner->id}}",value:"{{$owner->name}}"},
                     @endforeach
                 ],
+                thisId : "",
+                ownerOutStorageRules : [],
+                updateDetailId : '',
+                units : null,
+                strategy : ['起步','默认','特征'],
+                type : ['商品名称','订单类型','承运商','店铺类型'],
+                logic : ['包含','不包含','等于'],
+                rule : {
+                    "strategy" : '特征',
+                    "amount" : "",
+                    "unit_id" : "",
+                    "unit_price" : "",
+                    "priority" : 0,
+                },
+                thisRuleIndex : "",
+                features : [],
             },
             mounted(){
                 let data=[
@@ -83,6 +183,127 @@
                 });
                 this.form.init();
             },
+            methods:{
+                showDetail(id){
+                    if (this.ownerOutStorageRules[id]){
+                        this.thisId = id;
+                        $("#model-"+id).after($("#detail"));
+                        return;
+                    }
+                    window.axios.post("{{url('maintenance/priceModel/operation/getOutStorageRule')}}",{id:id})
+                        .then(res=>{
+                            if (res.data.success){
+                                this.ownerOutStorageRules[id] = res.data.data;
+                                this.thisId = id;
+                                $("#model-"+id).after($("#detail"));
+                                return;
+                            }
+                            window.tempTip.setDuration(3000);
+                            window.tempTip.show(res.data.data);
+                        }).catch(err=>{
+                        window.tempTip.setDuration(3000);
+                        window.tempTip.show("网络错误:"+err);
+                    });
+                },
+                showUpdateDetail(id){
+                    if (!this.units)this._getUnits();
+                    this.updateDetailId = id;
+                },
+                _getUnits(){
+                    window.axios.post("{{url('maintenance/unit/getUnits')}}")
+                        .then(res=>{
+                            if (res.data.success){
+                                this.units = res.data.data;
+                                return;
+                            }
+                            window.tempTip.setDuration(3000);
+                            window.tempTip.show(res.data.data);
+                        }).catch(err=>{
+                        window.tempTip.setDuration(3000);
+                        window.tempTip.show("网络错误:"+err);
+                    });
+                },
+                submitUpdateDetail(item){
+                    let amount = $("#detailAmount").val();
+                    let unit_id = $("#detailUnit").val();
+                    let unit_price = $("#detailUnitPrice").val();
+                    let priority = $("#detailPriority").val();
+                    window.axios.post("{{url('maintenance/priceModel/operation/updateOutStorageRule')}}",
+                        {id:item.id,amount:amount,unit_id:unit_id,unit_price:unit_price,priority:priority})
+                        .then(res=>{
+                            if (res.data.success){
+                                item.amount = amount;
+                                if (item.unit_id != unit_id){
+                                    this.units.some((unit)=>{
+                                        if (unit_id == unit.id){
+                                            item.unit = unit;
+                                            return true;
+                                        }
+                                    });
+                                    item.unit_id = unit_id;
+                                }
+                                item.unit_price = unit_price;
+                                item.priority = priority;
+                                this.updateDetailId = '';
+                                window.tempTip.setDuration(2000);
+                                window.tempTip.showSuccess("修改成功");
+                                return;
+                            }
+                            window.tempTip.setDuration(3000);
+                            window.tempTip.show(res.data.data);
+                        }).catch(err=>{
+                        window.tempTip.setDuration(3000);
+                        window.tempTip.show("网络错误:"+err);
+                    });
+                },
+                showAddRuleModal(){
+                    if (!this.units)this._getUnits();
+                    $("#addOutStorageRule").modal("show");
+                },
+                submitRule(){
+                    if (!this.thisId || !this.rule.strategy || !this.rule.unit_id || !this.rule.unit_price){
+                        window.tempTip.setDuration(3000);
+                        window.tempTip.show("计费策略,单位,单价为必填项");
+                        return;
+                    }
+                    window.axios.post("{{url('maintenance/priceModel/operation/createOutStorageRule')}}",
+                        {owner_price_operation_id:this.thisId,strategy:this.rule.strategy,amount:this.rule.amount,unit_id:this.rule.unit_id,unit_price:this.rule.unit_price,priority:Number(this.rule.priority)})
+                        .then(res=>{
+                            if (res.data.success){
+                                this.ownerOutStorageRules[this.thisId].unshift(res.data.data);
+                                this.$forceUpdate();
+                                window.tempTip.setDuration(2000);
+                                window.tempTip.setIndex(1099);
+                                window.tempTip.showSuccess("新增出库策略成功");
+                                $("#addOutStorageRule").modal("hide");
+                                return;
+                            }
+                            window.tempTip.setDuration(3000);
+                            window.tempTip.setIndex(1099);
+                            window.tempTip.show(res.data.data);
+                        }).catch(err=>{
+                        window.tempTip.setDuration(3000);
+                        window.tempTip.show("网络错误:"+err);
+                    });
+                },
+                showAddFeatureModal(index,feature){
+                    window.axios.post("{{url('maintenance/priceModel/operation/getFeatures')}}", {feature:feature})
+                        .then(res=>{
+                            if (res.data.success){
+                                this.features = res.data.data;
+                                this.thisIndex = index;
+                                console.log(this.features);
+                                $("#addFeatureModal").modal("show");
+                                return;
+                            }
+                            window.tempTip.setDuration(3000);
+                            window.tempTip.show(res.data.data);
+                        }).catch(err=>{
+                        window.tempTip.setDuration(3000);
+                        window.tempTip.show("网络错误:"+err);
+                    });
+                }
+            },
         });
     </script>
 @stop

+ 7 - 0
routes/web.php

@@ -92,6 +92,10 @@ Route::group(['prefix'=>'maintenance'],function(){
 
         Route::group(['prefix'=>'operation'],function(){
             Route::get('create','PriceModelController@operationCreate');
+            Route::post('getOutStorageRule','PriceModelController@operationGetOutStorageRule');
+            Route::post('updateOutStorageRule','PriceModelController@updateOutStorageRule');
+            Route::post('createOutStorageRule','PriceModelController@createOutStorageRule');
+            Route::post('getFeatures','PriceModelController@getFeatures');
         });
         Route::get('operation','PriceModelController@operationIndex');
 
@@ -110,6 +114,9 @@ Route::group(['prefix'=>'maintenance'],function(){
         });
         Route::get('directLogistic','PriceModelController@directLogisticIndex');
     });
+    Route::group(['prefix'=>'unit'],function(){
+        Route::post('getUnits','UnitsController@getUnits');
+    });
 
     Route::get('syncRedisLogs','LogController@syncRedisLogs');
     Route::resource('log', 'LogController');

+ 94 - 58
serves/excelExportGo/api/controller/orderController.go

@@ -1,9 +1,9 @@
 package controller
 
 import (
-	"bswas/utilities"
-	"strconv"
-	"strings"
+    "bswas/utilities"
+    "strconv"
+    "strings"
 )
 
 func OrderFormat(data []map[string]string) ([]interface{}, [][]interface{}, map[string]string) {
@@ -161,60 +161,96 @@ func MergerOrderIssueData(data map[string]map[string]interface{}, orderPackages
 }
 
 func mergerOrderPackage(data map[string]map[string]interface{}, orderPackages []map[string]string) map[string]map[string]interface{} {
-	for _,orderPackage := range orderPackages {
-		_,isExist := data[orderPackage["order_issue_id"]]["orderPackages"]
-		if isExist {
-			data[orderPackage["order_issue_id"]]["orderPackages"] = append(data[orderPackage["order_issue_id"]]["orderPackages"].([]map[string]string),orderPackage)
-		}else{
-			sliced := []map[string]string{
-				orderPackage,
-			}
-			data[orderPackage["order_issue_id"]]["orderPackages"] = sliced
-		}
-	}
-	return data
+    for _,orderPackage := range orderPackages {
+        if data[orderPackage["order_issue_id"]] == nil {
+            items := []map[string]string{
+                orderPackage,
+            }
+            se := map[string]interface{}{
+                "orderPackages" : items,
+            }
+            data[orderPackage["order_issue_id"]] = se
+            continue
+        }
+        if data[orderPackage["order_issue_id"]]["orderPackages"] == nil {
+            items := []map[string]string{
+                orderPackage,
+            }
+            data[orderPackage["order_issue_id"]]["orderPackages"] = items
+            continue
+        }
+        data[orderPackage["order_issue_id"]]["orderPackages"] = append(data[orderPackage["order_issue_id"]]["orderPackages"].([]map[string]string),orderPackage)
+    }
+    return data
 }
 func mergerSecondOrderPackage(data map[string]map[string]interface{}, secondOrderPackages []map[string]string) map[string]map[string]interface{} {
 	for _,secondOrderPackage := range secondOrderPackages {
-		_,isExist := data[secondOrderPackage["order_issue_id"]]["secondOrderPackages"]
-		if isExist {
-			data[secondOrderPackage["order_issue_id"]]["secondOrderPackages"] = append(data[secondOrderPackage["order_issue_id"]]["secondOrderPackages"].([]map[string]string),secondOrderPackage)
-		}else{
-			sliced := []map[string]string{
-				secondOrderPackage,
-			}
-			data[secondOrderPackage["order_issue_id"]]["secondOrderPackages"] = sliced
-		}
+        if data[secondOrderPackage["order_issue_id"]] == nil {
+            items := []map[string]string{
+                secondOrderPackage,
+            }
+            se := map[string]interface{}{
+                "secondOrderPackages" : items,
+            }
+            data[secondOrderPackage["order_issue_id"]] = se
+            continue
+        }
+        if data[secondOrderPackage["order_issue_id"]]["secondOrderPackages"] == nil {
+            items := []map[string]string{
+                secondOrderPackage,
+            }
+            data[secondOrderPackage["order_issue_id"]]["secondOrderPackages"] = items
+            continue
+        }
+        data[secondOrderPackage["order_issue_id"]]["secondOrderPackages"] = append(data[secondOrderPackage["order_issue_id"]]["secondOrderPackages"].([]map[string]string),secondOrderPackage)
 	}
 	return data
 }
 func mergerRejectedBillItem(data map[string]map[string]interface{}, rejectedBillItems []map[string]string) map[string]map[string]interface{} {
-	for _,rejectedBillItem := range rejectedBillItems {
-		_,isExist := data[rejectedBillItem["order_issue_id"]]["rejectedBillItems"]
-		if isExist {
-			data[rejectedBillItem["order_issue_id"]]["rejectedBillItems"] = append(data[rejectedBillItem["order_issue_id"]]["rejectedBillItems"].([]map[string]string),rejectedBillItem)
-		}else{
-			sliced := []map[string]string{
-				rejectedBillItem,
-			}
-			data[rejectedBillItem["order_issue_id"]]["rejectedBillItems"] = sliced
-		}
-	}
-	return data
+    for _,rejectedBillItem := range rejectedBillItems {
+        if data[rejectedBillItem["order_issue_id"]] == nil {
+            items := []map[string]string{
+                rejectedBillItem,
+            }
+            se := map[string]interface{}{
+                "rejectedBillItems" : items,
+            }
+            data[rejectedBillItem["order_issue_id"]] = se
+            continue
+        }
+        if data[rejectedBillItem["order_issue_id"]]["rejectedBillItems"] == nil {
+            items := []map[string]string{
+                rejectedBillItem,
+            }
+            data[rejectedBillItem["order_issue_id"]]["rejectedBillItems"] = items
+            continue
+        }
+        data[rejectedBillItem["order_issue_id"]]["rejectedBillItems"] = append(data[rejectedBillItem["order_issue_id"]]["rejectedBillItems"].([]map[string]string),rejectedBillItem)
+    }
+    return data
 }
 func mergerLog(data map[string]map[string]interface{}, logs []map[string]string) map[string]map[string]interface{} {
-	for _,log := range logs {
-		_,isExist := data[log["order_issue_id"]]["logs"]
-		if isExist {
-			data[log["order_issue_id"]]["logs"] = append(data[log["order_issue_id"]]["logs"].([]map[string]string),log)
-		}else{
-			sliced := []map[string]string{
-				log,
-			}
-			data[log["order_issue_id"]]["logs"] = sliced
-		}
-	}
-	return data
+    for _,log := range logs {
+        if data[log["order_issue_id"]] == nil {
+            items := []map[string]string{
+                log,
+            }
+            se := map[string]interface{}{
+                "logs" : items,
+            }
+            data[log["order_issue_id"]] = se
+            continue
+        }
+        if data[log["order_issue_id"]]["logs"] == nil {
+            items := []map[string]string{
+                log,
+            }
+            data[log["order_issue_id"]]["logs"] = items
+            continue
+        }
+        data[log["order_issue_id"]]["logs"] = append(data[log["order_issue_id"]]["logs"].([]map[string]string),log)
+    }
+    return data
 }
 func OrderIssueFormat(dataMap map[string]map[string]interface{}) ([]interface{}, [][]interface{}, map[string]string)  {
 	row := []interface{}{
@@ -366,8 +402,8 @@ func GetOrderIssuesModel(orderIssues []map[string]string)(modelData map[string]m
 	secondOrderPackageConditionValue string, rejectedBillItemConditionValue string, logConditionValue string){
 	modelData = make(map[string]map[string]interface{})
 	orderPackageConditionValue = " WHERE order_packages.order_id IN ("
-	secondOrderPackageConditionValue = " WHERE s_o_p.order_id IN ("
-	rejectedBillItemConditionValue = " WHERE rejected_bill_items.id_rejected_bill IN ("
+	secondOrderPackageConditionValue = " WHERE o_d.client_code IN ("
+	rejectedBillItemConditionValue = " WHERE rejected_bills.logistic_number_return IN ("
 	logConditionValue = " WHERE order_issue_process_logs.order_issue_id IN ("
 	for index,value := range orderIssues{
 		orderIssue := map[string]interface{}{
@@ -402,11 +438,11 @@ func GetOrderIssuesModel(orderIssues []map[string]string)(modelData map[string]m
 			if value["order_id"] != "" {
 				orderPackageConditionValue += value["order_id"]+","
 			}
-			if value["s_o_id"] != "" {
-				secondOrderPackageConditionValue += value["s_o_id"]+","
+			if value["s_o_client_code"] != "" {
+				secondOrderPackageConditionValue += "'"+value["s_o_client_code"]+"',"
 			}
-			if value["rejected_bill_id"] != "" {
-				rejectedBillItemConditionValue += value["rejected_bill_id"]+","
+			if value["logistic_number_return"] != "" {
+				rejectedBillItemConditionValue += "'"+value["logistic_number_return"]+"',"
 			}
 			if value["id"] != "" {
 				logConditionValue += value["id"]+","
@@ -415,11 +451,11 @@ func GetOrderIssuesModel(orderIssues []map[string]string)(modelData map[string]m
 			if value["order_id"] != "" {
 				orderPackageConditionValue += value["order_id"]
 			}
-			if value["s_o_id"] != "" {
-				secondOrderPackageConditionValue += value["s_o_id"]
+			if value["s_o_client_code"] != "" {
+				secondOrderPackageConditionValue += "'"+value["s_o_client_code"]+"'"
 			}
-			if value["rejected_bill_id"] != "" {
-				rejectedBillItemConditionValue += value["rejected_bill_id"]
+			if value["logistic_number_return"] != "" {
+				rejectedBillItemConditionValue += "'"+value["logistic_number_return"]+"'"
 			}
 			if value["id"] != "" {
 				logConditionValue += value["id"]

+ 7 - 0
serves/excelExportGo/logs/2020-11-09.log

@@ -0,0 +1,7 @@
+
+[ERROR]   09:50:12
+   /orm/query.go:11   SQL执行错误!(select s_o_p.logistic_number, s_o_p_c.amount s_o_p_c_amount, s_c.sku s_c_sku,s_c.name s_c_name, order_issues.id order_issue_id from `order_packages` as `s_o_p` left join `order_package_commodities` as `s_o_p_c` on `s_o_p_c`.`order_package_id` = `s_o_p`.`id` left join `commodities` as `s_c` on `s_o_p_c`.`commodity_id` = `s_c`.`id` left join `order_issues` on `s_o_p`.`order_id` = `order_issues`.`second_order_id` WHERE s_o_p.client_code IN (BSCK2020110800433-1))
+[ERROR]   09:55:24
+   /orm/query.go:11   SQL执行错误!(select s_o_p.logistic_number, s_o_p_c.amount s_o_p_c_amount, s_c.sku s_c_sku,s_c.name s_c_name, order_issues.id order_issue_id from `order_packages` as `s_o_p` left join `orders` as `o_d` on `s_o_p`.`order_id` = `o_d`.`id` left join `order_package_commodities` as `s_o_p_c` on `s_o_p_c`.`order_package_id` = `s_o_p`.`id` left join `commodities` as `s_c` on `s_o_p_c`.`commodity_id` = `s_c`.`id` left join `order_issues` on `s_o_p`.`order_id` = `order_issues`.`second_order_id` WHERE o_d.client_code IN (BSCK2020110800433-1))
+[ERROR]   13:08:51
+   /orm/query.go:11   SQL执行错误!(select rejected_bill_items.remark,rejected_bill_items.amount rejected_bill_amount,rejected_bill_items.name_goods,rejected_bill_items.barcode_goods, order_issues.id order_issue_id from `rejected_bill_items` left join `order_issues` on `rejected_bill_items`.`logistic_number_return` = `order_issues`.`logistic_number_return` WHERE rejected_bill_items.logistic_number_return IN ('75404377502519'))