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

优化即时账单,优化订单页面

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

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

@@ -184,7 +184,7 @@ class TestController extends Controller
         $waybills = Waybill::query()->whereNotNull("wms_bill_number")->whereNull("order_id")->get();
         foreach ($waybills as $waybill){
             $order = Order::query()->where("code",$waybill->wms_bill_number)->first();
-            $waybill->update(["order_id"=>$order->id]);
+            if ($order)$waybill->update(["order_id"=>$order->id]);
         }
     }
     public function restoreBatch()

+ 16 - 11
app/Jobs/OrderCreateInstantBill.php

@@ -7,25 +7,26 @@ use App\Services\LogService;
 use App\Services\OrderService;
 use Illuminate\Bus\Queueable;
 use Illuminate\Contracts\Queue\ShouldQueue;
+use Illuminate\Database\Eloquent\Collection;
 use Illuminate\Foundation\Bus\Dispatchable;
 use Illuminate\Queue\InteractsWithQueue;
 use Illuminate\Queue\SerializesModels;
 
 class OrderCreateInstantBill implements ShouldQueue
 {
-    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
+    use Dispatchable, InteractsWithQueue, Queueable;
 
 
-    protected $order;
+    protected $orders;
     /**
      * Create a new job instance.
      *
-     * @param Order $order
+     * @param Collection $orders
      * @return void
      */
-    public function __construct(Order $order)
+    public function __construct($orders)
     {
-        $this->order = $order;
+        $this->orders = $orders;
     }
 
     /**
@@ -36,12 +37,16 @@ class OrderCreateInstantBill implements ShouldQueue
      */
     public function handle(OrderService $service)
     {
-        try{
-            if (!$service->createInstantBill($this->order))
-                LogService::log(__METHOD__,"ERROR-订单生成即时账单",$this->order->toJson());
-        }catch (\Exception $e){
-            LogService::log(__METHOD__,"ERROR-订单生成即时账单",$this->order->toJson()." | ".$e->getMessage());
-            throw new \Exception($e->getMessage());
+        if ($this->orders){
+            foreach ($this->orders as $order){
+                try{
+                    if (!$service->createInstantBill($order))
+                        LogService::log(__METHOD__,"ERROR-订单生成即时账单",$this->order->toJson());
+                }catch (\Exception $e){
+                    LogService::log(__METHOD__,"ERROR-订单生成即时账单",$this->order->toJson()." | ".$e->getMessage());
+                    throw new \Exception($e->getMessage());
+                }
+            }
         }
     }
 }

+ 3 - 3
app/Services/OrderService.php

@@ -601,9 +601,7 @@ class OrderService
 
     public function pushQueue($orderHeaders){
         $orders = Order::query()->with(["logistic","packages.commodities.commodity"])->where('wms_status','订单完成')->whereIn('code',data_get($orderHeaders,'*.orderno'))->get();
-        $orders->each(function($order){
-            dispatch(new OrderCreateInstantBill($order));
-        });
+        dispatch(new OrderCreateInstantBill($orders));
     }
 
     public function syncOrderByWMSOrderHeaders(&$orderHeaders)
@@ -1081,6 +1079,7 @@ sql
         /** @var \stdClass $order */
         //检查订单对象
         if (!$order || $order->wms_status != "订单完成")return true;
+        if (Cache::has("owner_fee_details_orders_".$order->id))return true;
         if (OwnerFeeDetail::query()->where("outer_table_name","orders")->where("outer_id",$order->id)->first())return true;
 
         $order->loadMissing(["logistic","shop","packages.commodities.commodity","batch"]);
@@ -1171,6 +1170,7 @@ sql
             foreach ($items as &$item)$item["owner_fee_detail_id"] = $detail->id;
             if (count($items)>1)OwnerFeeDetailLogistic::query()->insert($items);
             $this->setOrderQuantity($order->owner_id,$order->logistic_id);
+            Cache::put("owner_fee_details_orders_".$order->id,1,86400);
             return true;
        }
        return false;

+ 29 - 12
app/Services/OwnerPriceExpressService.php

@@ -8,6 +8,7 @@ use App\OwnerPriceExpress;
 use App\OwnerPriceExpressProvince;
 use App\Services\common\QueryService;
 use Illuminate\Database\Eloquent\Builder;
+use Illuminate\Support\Facades\Cache;
 use Illuminate\Support\Facades\DB;
 use App\Traits\ServiceAppAop;
 
@@ -111,6 +112,8 @@ class OwnerPriceExpressService
         $result = app(QueryService::class)->priceModelAuditOrRecoverQuery($isAudit,OwnerPriceExpress::query(),$ownerId,$ids);
         if ($result["delete"])$this->destroy($result["delete"]);
         if ($result["update"])OwnerPriceExpress::query()->whereIn("id",$result["update"])->update(["operation"=>null,"target_id"=>null]);
+        if (!is_array($ownerId))$ownerId = [$ownerId];
+        foreach ($ownerId as $owner)Cache::tags("expressFeeOwner:".$owner)->flush();
     }
 
     public function updateDetail(array $params, array $values)
@@ -233,6 +236,31 @@ sql
         },null);
     }
 
+    /**
+     * @param integer $owner
+     * @param integer $logistic
+     * @param integer $province
+     *
+     * @return OwnerPriceExpress|\stdClass|null
+     */
+    public function getOwnerPriceExpress($owner,$logistic,$province)
+    {
+        return Cache::tags("expressFeeOwner:".$owner)->remember("expressFee:".$owner.$logistic.$province,config("cache.expirations.rarelyChange"),
+            function ()use($owner,$logistic,$province){
+                return OwnerPriceExpress::query()->with(["details"=>function($query)use($province){
+                    /** @var Builder $query */
+                    $query->where("province_id",$province);
+                }])->whereHas("owners",function ($query)use($owner){
+                    /** @var Builder $query */
+                    $query->where("id",$owner);
+                })->whereHas("logistics",function ($query)use($logistic){
+                    /** @var Builder $query */
+                    $query->where("id",$logistic);
+                })->where(function(Builder $query){
+                    $query->whereNull("operation")->orWhere("operation","");
+                })->first();
+            });
+    }
     /**
      *
      * @param double $weight
@@ -245,18 +273,7 @@ sql
     {
         if (!$weight)return array(null,null);
 
-        $model = OwnerPriceExpress::query()->with(["details"=>function($query)use($province_id){
-            /** @var Builder $query */
-            $query->where("province_id",$province_id);
-        }])->whereHas("owners",function ($query)use($owner_id){
-            /** @var Builder $query */
-            $query->where("id",$owner_id);
-        })->whereHas("logistics",function ($query)use($logistic_id){
-            /** @var Builder $query */
-            $query->where("id",$logistic_id);
-        })->where(function(Builder $query){
-            $query->whereNull("operation")->orWhere("operation","");
-        })->first();
+        $model = $this->getOwnerPriceExpress($owner_id,$logistic_id,$province_id);
         if (!$model || count($model->details)<1)return array(null,null);
 
         if ($model->amount_interval){

+ 24 - 24
app/Services/OwnerPriceOperationService.php

@@ -252,33 +252,33 @@ class OwnerPriceOperationService
     {
         $sign = false;
         //入口仅在此处存在 缓存1000s
-        $key = "pivot_".$rule->id."_".$owner;
+        $key = "owner_price_operation_owner_".$rule->id."_".$owner;
         $discountIndex = key($result);
         $targetValue = $result[$discountIndex];
-        $pivot = app(CacheService::class)->getOrExecute($key,function ()use($key,$targetValue,&$sign,$rule,$owner){
-            try{
-                DB::beginTransaction();
-                //此处暂时未使用cache的互斥锁 使用sql行锁代替下 防止缓存击穿
-                $pivot = DB::selectOne(DB::raw("SELECT * FROM owner_price_operation_owner WHERE owner_price_operation_id = ? AND owner_id = ? for update"),[$rule->id,$owner]);
-                if ($pivot && (!$pivot->discount_date || substr($pivot->discount_date,0,7)!=date("Y-m") || $pivot->target_value < $targetValue)){
-                    //未被标记过处理时间或处理时间不为本月,或上次处理值过期,处理历史即时账单
-                    $sign = true;
-                }
-                if ($sign){
-                    //先标记成功 这将在后续推进历史单处理流程,防止程序在此堵塞
-                    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]);
-                    $pivot->discount_date = date("Y-m-d");
-                    $pivot->target_value = $targetValue;
-                    Cache::put($key,$pivot,1000);
-                }
-                DB::commit();
-            }catch (\Exception $exception){
-                DB::rollBack();
-                LogService::log(__CLASS__,"即时账单满减处理失败",$exception->getMessage());
+        $pivot = null;
+        try{
+            DB::beginTransaction();
+            //此处暂时未使用cache的互斥锁 使用sql行锁代替下 防止缓存击穿
+            $pivot = app(CacheService::class)->getOrExecute($key,function ()use($key,$targetValue,&$sign,$rule,$owner){
+                return DB::selectOne(DB::raw("SELECT * FROM owner_price_operation_owner WHERE owner_price_operation_id = ? AND owner_id = ? for update"),[$rule->id,$owner]);
+            },1000);
+            if ($pivot && (!$pivot->discount_date || substr($pivot->discount_date,0,7)!=date("Y-m") || $pivot->target_value < $targetValue)){
+                //未被标记过处理时间或处理时间不为本月,或上次处理值过期,处理历史即时账单
+                $sign = true;
             }
-            return $pivot ?? null;
-        },1000);
+            if ($sign){
+                //先标记成功 这将在后续推进历史单处理流程,防止程序在此堵塞
+                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]);
+                $pivot->discount_date = date("Y-m-d");
+                $pivot->target_value = $targetValue;
+                Cache::put($key,$pivot,1000);
+            }
+            DB::commit();
+        }catch (\Exception $exception){
+            DB::rollBack();
+            LogService::log(__CLASS__,"即时账单满减处理失败",$exception->getMessage());
+        }
         //进入历史单处理
         if ($pivot && $sign)dispatch(new HandlePastBill(array($rule,$owner,$discountIndex,$pivot)));
     }

+ 32 - 0
database/migrations/2021_04_22_112515_change_owner_fee_details_change_id_data_type.php

@@ -0,0 +1,32 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class ChangeOwnerFeeDetailsChangeIdDataType extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table("owner_fee_details",function (Blueprint $table){
+            $table->unique(["outer_id","outer_table_name"]);
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table("owner_fee_details",function (Blueprint $table){
+            $table->dropUnique(["outer_id","outer_table_name"]);
+        });
+    }
+}

+ 4 - 4
resources/views/order/index/delivering.blade.php

@@ -98,8 +98,8 @@
                                 <div v-for="oracleDOCOrderDetail in commodities[order.orderno]" class="row">
                                     <div class="col-2 border border-1">@{{ oracleDOCOrderDetail.sku }}</div>
                                     <div class="col-2 border border-1">@{{ oracleDOCOrderDetail.alternate_sku1 }}</div>
-                                    <div class="col-2 border border-1" @dblclick.stop="replaceText($event)">
-                                        <div class="w-100 text-overflow-replace-100 text-primary">@{{ oracleDOCOrderDetail.descr_c  }}</div>
+                                    <div class="col-2 border border-1" @dblclick.stop="replaceText(i)">
+                                        <div class="w-100" :class="order.replaceText ? 'text-overflow-warp-100' : 'text-overflow-replace-100 cursor-pointer'">@{{ oracleDOCOrderDetail.descr_c  }}</div>
                                     </div>
                                     <div class="col-1 border border-1">@{{ oracleDOCOrderDetail.qtyordered }}</div>
                                     <div class="col-2 border border-1">@{{ oracleDOCOrderDetail.lotnum }}</div>
@@ -751,8 +751,8 @@
                         tempTip.show('网络异常:'+error)
                     })
                 },
-                replaceText(e){
-                    e.target.firstChild.className = "w-100 text-overflow-warp-100";
+                replaceText(index){
+                    this.$set(this.orders[index],"replaceText",true);
                 },
                 getTagOrder(orderNos){
                     this.tagOrders = [];

+ 18 - 2
resources/views/test.blade.php

@@ -375,6 +375,13 @@
                 },
                 directLogistic:{
                     "C":[{name:"笕尚直发",base_km:"10"}],
+                    "D":[{name:"笕尚直发",base_km:"10",tax_rate_id:"3%"}],
+                    "U":[{name:"笕尚直发",base_km:"10",tax_rate_id:"3%",target_id:"10",details:[
+                            {car_type_id:"碰碰车",base_fee:"30",additional_fee:"50"}
+                        ]}],
+                    "H":{10:{name:"笕尚直发",base_km:"10",tax_rate_id:"3%",details:[
+                            {car_type_id:"碰碰车",base_fee:"30",additional_fee:"50"}
+                        ]}},
                 },
                 system:{
                     "C":[{usage_fee:"500"}],
@@ -450,6 +457,16 @@
                             rate:"费率",
                         },
                     },
+                    "directLogistic":{
+                        name:"名称",
+                        base_km:"起步公里数",
+                        tax_rate_id:"税率",
+                        child:{
+                            car_type_id:"车型",
+                            base_fee:"起步费",
+                            additional_fee:"续费(元/KM)"
+                        }
+                    }
                 },
             },
             selectedAudit:"logistic",
@@ -611,7 +628,6 @@
                 let itemTem = this.logisticDataFormat(tar);
                 let dataTem = this.logisticDataFormat(data);
                 let items = [];
-                console.log(itemTem,dataTem)
                 for (let key in itemTem){
                     if (dataTem[key]){
                         for (let key2 in itemTem[key]){
@@ -647,9 +663,9 @@
                 dataTem.push.apply(dataTem,this.logisticDataRestore(itemTem,"D"));
                 dataTem.push.apply(dataTem,items);
                 data.details = dataTem;
-                console.log(data.details)
             });
             this.auditList.mapping.logistic = temp;
+            temp={name:"名称",child:{car_type_id:"车型"}};
         },
         methods:{
             transformData(data,key,font=false){