|
|
@@ -142,11 +142,31 @@ class OwnerPriceOperationService
|
|
|
}
|
|
|
//满减存在
|
|
|
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)){
|
|
|
- $this->handlePastBill($targetValue,$rule,$owner_id,$units,$discountIndex,$pivot);
|
|
|
- }
|
|
|
+ $sign = false;
|
|
|
+ $key = "pivot_".$rule->id."_".$owner_id;
|
|
|
+ $pivot = app(CacheService::class)->getOrExecute($key,function ()use($key,$targetValue,&$sign,$rule,$owner_id){
|
|
|
+ try{
|
|
|
+ DB::beginTransaction();
|
|
|
+ $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");
|
|
|
+ $pivot->target_value = $targetValue;
|
|
|
+ Cache::put($key,$pivot,1000);
|
|
|
+ }
|
|
|
+ DB::commit();
|
|
|
+ }catch (\Exception $exception){
|
|
|
+ DB::rollBack();
|
|
|
+ }
|
|
|
+ return $pivot ?? null;
|
|
|
+ },1000);
|
|
|
+ if ($pivot && $sign)$this->handlePastBill($targetValue,$rule,$owner_id,$units,$discountIndex,$pivot);
|
|
|
}
|
|
|
if ($rule->strategy == '特征'){//特征策略匹配
|
|
|
$bool = app("FeatureService")->matchFeature($rule->feature,$columnMapping,$matchObject);
|
|
|
@@ -328,10 +348,6 @@ class OwnerPriceOperationService
|
|
|
*/
|
|
|
public function handlePastBill($targetValue, $rule, $owner_id, $units, $discountIndex, $pivot)
|
|
|
{
|
|
|
- //先标记成功 进入处理
|
|
|
- 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]);
|
|
|
-
|
|
|
try{
|
|
|
DB::beginTransaction();
|
|
|
$month = date("Y-m");
|