瀏覽代碼

Merge branch 'zzd' of ssh://was.baoshi56.com:10022/var/git/bswas

LD 5 年之前
父節點
當前提交
a5b1a82a81
共有 2 個文件被更改,包括 17 次插入4 次删除
  1. 10 0
      app/Http/Controllers/TestController.php
  2. 7 4
      app/Services/OwnerPriceOperationService.php

+ 10 - 0
app/Http/Controllers/TestController.php

@@ -160,6 +160,16 @@ class TestController extends Controller
         dd(Region::query()->where("id", ">=", 404)->where("id", "<=", 432)->delete());
     }
     public function tt1(){
+        $owners = Owner::query()->withCount(["ownerPriceDirectLogistics","ownerPriceLogistics","ownerPriceExpresses","ownerPriceOperations","ownerStoragePriceModels"])->get();
+        foreach ($owners as $owner){
+            $arr = [];
+            if ($owner->owner_storage_price_models_count > 0)$arr[] = "0";
+            if ($owner->owner_price_operations_count > 0)$arr[] = "1";
+            if ($owner->owner_price_expresses_count > 0)$arr[] = "2";
+            if ($owner->owner_price_logistics_count > 0)$arr[] = "3";
+            if ($owner->owner_price_direct_logistics_count > 0)$arr[] = "4";
+            $owner->update(["relevance"=>json_encode($arr)]);
+        }
     }
 
     public function zzd()

+ 7 - 4
app/Services/OwnerPriceOperationService.php

@@ -143,17 +143,19 @@ class OwnerPriceOperationService
             //满减存在
             if ($isDiscount){
                 $sign = false;
+                //入口仅在此处存在 缓存1000s
                 $key = "pivot_".$rule->id."_".$owner_id;
                 $pivot = app(CacheService::class)->getOrExecute($key,function ()use($key,$targetValue,&$sign,$rule,$owner_id){
                     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_id]);
                         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_id]);
                             $pivot->discount_date = date("Y-m-d");
@@ -163,10 +165,12 @@ class OwnerPriceOperationService
                         DB::commit();
                     }catch (\Exception $exception){
                         DB::rollBack();
+                        LogService::log(__CLASS__,"即时账单满减处理失败",$exception->getMessage());
                     }
                     return $pivot ?? null;
                 },1000);
-                if ($pivot && $sign)$this->handlePastBill($targetValue,$rule,$owner_id,$units,$discountIndex,$pivot);
+                //进入历史单处理
+                if ($pivot && $sign)$this->handlePastBill($rule,$owner_id,$units,$discountIndex,$pivot);
             }
             if ($rule->strategy == '特征'){//特征策略匹配
                 $bool = app("FeatureService")->matchFeature($rule->feature,$columnMapping,$matchObject);
@@ -339,14 +343,13 @@ class OwnerPriceOperationService
     /**
      * 处理历史账单
      *
-     * @param int $targetValue
      * @param object $rule
      * @param int $owner_id
      * @param array $units
      * @param int $discountIndex
      * @param object $pivot
      */
-    public function handlePastBill($targetValue, $rule, $owner_id, $units, $discountIndex, $pivot)
+    public function handlePastBill($rule, $owner_id, $units, $discountIndex, $pivot)
     {
         try{
             DB::beginTransaction();