|
|
@@ -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();
|