Quellcode durchsuchen

作业计费相关逻辑

Zhouzhendong vor 5 Jahren
Ursprung
Commit
fe05a2d97d

+ 1 - 1
app/Services/FeatureService.php

@@ -228,7 +228,7 @@ class FeatureService
 
         foreach ($result[0] as &$str) {
             if (is_numeric($str) && isset($features[$str])) {
-                $column = array_flip(Feature::type)[$features[$str]["type"]];
+                $column = Feature::type[$features[$str]["type"]];
                 $logic = $features[$str]["logic"];
                 $describe = $features[$str]["describe"];
                 if ($column == '商品名称' && $isMultiMatching){

+ 46 - 39
app/Services/OwnerPriceOperationService.php

@@ -129,56 +129,63 @@ class OwnerPriceOperationService
             if (!$rule->items)continue; //不存在子规则跳出
             $isDiscount = false;    //是否存在满减
             $discountIndex = 0;
+            $targetValue = 0;
             if ($type=='出库' && $rule->discount_count){
                 foreach (array_reverse(explode(",",$rule->discount_count),true) as $index=>$discount){
-                    if ($total >= $rule->discount_count){
+                    if ($total >= $discount){
                         $isDiscount = true; //第一个满足满减条件
                         $discountIndex = $index;
+                        $targetValue = $discount;
                         break;
                     }
                 }
             }
-            //满减存在且未被标记过处理时间或处理时间不为本月,处理历史即时账单
-            if ($isDiscount && (!$rule->discount_date || substr($rule->discount_date,0,7)!=date("Y-m"))){
-                try{
-                    DB::beginTransaction();
-                    $month = date("Y-m");
-                    $day = date("t",strtotime($month));
-                    foreach (OwnerFeeDetail::query()->with(["order.logistic","order.shop","order.packages.commodities.commodity","order.batch"])
-                                 ->where("owner_id",$owner_id)
-                                 ->whereBetween("worked_at",[$month."-01",$month."-".$day])->get() as $detail){
-                        $order = $detail->order;
+            //满减存在
+            if ($isDiscount){
+                //未被标记过处理时间或处理时间不为本月,或上次处理值过期,处理历史即时账单
+                $pivot = DB::selectOne(DB::raw("SELECT * FROM owner_price_operation_owner WHERE owner_price_operation_id = ? AND owner_id = ?"),[$rule->id,$owner_id]);
+                if ($pivot && (!$pivot->discount_date || substr($pivot->discount_date,0,7)!=date("Y-m") || $pivot->target_value < $targetValue)){
+                    try{
+                        DB::beginTransaction();
+                        $month = date("Y-m");
+                        $day = date("t",strtotime($month));
+                        foreach (OwnerFeeDetail::query()->with(["order.logistic","order.shop","order.packages.commodities.commodity","order.batch"])
+                                     ->where("owner_id",$owner_id)
+                                     ->whereBetween("worked_at",[$month."-01",$month."-".$day])->get() as $detail){
+                            $order = $detail->order;
 
-                        $logistic_fee = 0;
-                        $commodities = [];
-                        foreach ($order->packages as &$package){
-                            // 四维转二维
-                            foreach($package->commodities as &$commodity){
-                                $commodity["commodity_name"] = $commodity->commodity ? $commodity->commodity->name : '';
-                                $commodity["sku"] = $commodity->commodity ? $commodity->commodity->sku : '';
+                            $logistic_fee = 0;
+                            $commodities = [];
+                            foreach ($order->packages as &$package){
+                                // 四维转二维
+                                foreach($package->commodities as &$commodity){
+                                    $commodity["commodity_name"] = $commodity->commodity ? $commodity->commodity->name : '';
+                                    $commodity["sku"] = $commodity->commodity ? $commodity->commodity->sku : '';
+                                }
+                                $commodities = array_merge($commodities,$package->commodities->toArray());
                             }
-                            $commodities = array_merge($commodities,$package->commodities->toArray());
-                        }
-                        if ($logistic_fee!==null && $logistic_fee<0)$logistic_fee = null;
+                            if ($logistic_fee!==null && $logistic_fee<0)$logistic_fee = null;
 
-                        $object = ["commodities"=>$commodities,
-                            "logistic_name"=>($order->logistic ? $order->logistic->name : ''),
-                            "shop_name"=>($order->shop ? $order->shop->name : ''),
-                            "order_type"=>$order->order_type,
-                            "batch_type" => $order->batch ? $order->batch->wms_type : '',
-                            "owner_id"=>$order->owner_id];
-                        $mapping = ["packages"=>"commodities","商品名称"=>"commodity_name",
-                            "承运商"=>"logistic_name", "店铺类型"=>"shop_name",
-                            "订单类型"=>"order_type","波次类型"=>"batch_type"];
-                        $money = $this->matchItem($rule->items,$mapping,$object,$units,$owner_id,false,$isDiscount,$discountIndex);
-                        if ($money>0)$detail->update(["work_fee"=>$money]);
-                        else LogService::log(__CLASS__,"处理历史即时账单时发生匹配错误","账单主键:".$detail->id."; 错误代码".$money);
-                    };
-                    $rule->update(["discount_date"=>date("Y-m-d")]);
-                    DB::commit();
-                }catch (\Exception $e){
-                    DB::rollBack();
-                    LogService::log(__CLASS__,"处理历史即时账单时发生系统错误","计费模型主键:".$rule->id."; 错误信息".$e->getMessage());
+                            $object = ["commodities"=>$commodities,
+                                "logistic_name"=>($order->logistic ? $order->logistic->name : ''),
+                                "shop_name"=>($order->shop ? $order->shop->name : ''),
+                                "order_type"=>$order->order_type,
+                                "batch_type" => $order->batch ? $order->batch->wms_type : '',
+                                "owner_id"=>$order->owner_id];
+                            $mapping = ["packages"=>"commodities","商品名称"=>"commodity_name",
+                                "承运商"=>"logistic_name", "店铺类型"=>"shop_name",
+                                "订单类型"=>"order_type","波次类型"=>"batch_type"];
+                            $money = $this->matchItem($rule->items,$mapping,$object,$units,$owner_id,false,$isDiscount,$discountIndex);
+                            if ($money>0)$detail->update(["work_fee"=>$money]);
+                            else LogService::log(__CLASS__,"处理历史即时账单时发生匹配错误","账单主键:".$detail->id."; 错误代码".$money);
+                        };
+                        DB::update(DB::raw("UPDATE owner_price_operation_owner SET discount_date = ?,target_value = ? WHERE  owner_price_operation_id = ? AND owner_id = ?"),
+                            [date("Y-m-d"),$targetValue,$rule->id,$owner_id]);
+                        DB::commit();
+                    }catch (\Exception $e){
+                        DB::rollBack();
+                        LogService::log(__CLASS__,"处理历史即时账单时发生系统错误","计费模型主键:".$rule->id."; 错误信息".$e->getMessage());
+                    }
                 }
             }
             if ($rule->strategy == '特征'){//特征策略匹配

+ 40 - 0
database/migrations/2021_02_19_110139_change_owner_operation_owner_table.php

@@ -0,0 +1,40 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class ChangeOwnerOperationOwnerTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('owner_price_operation_owner', function (Blueprint $table) {
+            $table->date("discount_date")->nullable()->comment("满减标记日");
+            $table->integer("target_value")->nullable()->comment("目标值");
+        });
+        Schema::table('owner_price_operations', function (Blueprint $table) {
+            $table->dropColumn("discount_date");
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('owner_price_operation_owner', function (Blueprint $table) {
+            $table->dropColumn("discount_date");
+            $table->dropColumn("discount_date");
+        });
+        Schema::table('owner_price_operations', function (Blueprint $table) {
+            $table->date("discount_date")->nullable()->comment("满减标记日");
+        });
+    }
+}

+ 10 - 9
resources/views/maintenance/priceModel/operation/index.blade.php

@@ -22,9 +22,8 @@
                 <th>策略</th>
                 <th>项目</th>
                 <th>优先级</th>
-                <th>满减阈值</th>
                 <th>按单单价</th>
-                <th>按单减免单价</th>
+                <th>按单减免</th>
                 <th>本月满减达标日</th>
                 <th>特征</th>
                 <th>备注</th>
@@ -34,7 +33,7 @@
             <tr v-for="(model,i) in models" :id="'model-'+model.id">
                 <td>@{{ i+1 }}</td>
                 <td>
-                    <button v-if="thisId != model.id && model.totalPrice" class="btn btn-sm btn-info text-white" @click="showDetail(model.id,model.operationType)">维护详情</button>
+                    <button v-if="thisId != model.id" class="btn btn-sm btn-info text-white" @click="showDetail(model.id,model.operationType)">维护详情</button>
                     <button v-if="thisId == model.id" class="btn btn-sm btn-dark" @click="thisId = ''">关闭详情</button>
                 </td>
                 <td>@{{ model.name }}</td>
@@ -42,9 +41,11 @@
                 <td>@{{ model.strategy }}</td>
                 <td><small v-for="owner in model.owners" class="m-0 font-weight-bold">@{{ owner.name }}<br></small></td>
                 <td>@{{ model.priority }}</td>
-                <td>@{{ model.discountCount }}</td>
-                <td>@{{ model.totalPrice }}</td>
-                <td>@{{ model.totalDiscountPrice }}</td>
+                <td>@{{ model.totalPrice ? model.totalPrice : '/' }}</td>
+                <td>
+                    <span v-if="model.totalPrice"><small v-for="(price,i) in model.totalDiscountPrice">@{{ model.discountCount[i] }}单/@{{ price }}元<br></small></span>
+                    <span v-else>/</span>
+                </td>
                 <td>@{{ model.discountDate }}</td>
                 <td>@{{ model.feature }}</td>
                 <td><div class="text-overflow-warp-200">@{{ model.remark }}</div></td>
@@ -143,9 +144,9 @@
                         feature : "{{$model->featureFormat}}",
                         remark : "{{$model->remark}}",
                         priority : "{{$model->priority}}",
-                        discountCount : "{{$model->discount_count ?? '/'}}",
-                        totalPrice : "{{$model->total_price ?? '/'}}",
-                        totalDiscountPrice : "{{$model->total_discount_price ?? '/'}}",
+                        discountCount : "{{$model->discount_count}}" ? "{{$model->discount_count}}".split(",") : ["/"],
+                        totalPrice : "{{$model->total_price}}",
+                        totalDiscountPrice : "{{$model->total_discount_price}}" ? "{{$model->total_discount_price}}".split(",") : ["/"],
                         discountDate : "{{substr($model->discount_date,0,7)==date('Y-m') ? $model->discount_date : ''}}",
                         createdAt : "{{$model->created_at}}",
                         owners : {!! $model->ownerPriceOperationOwners !!},