where('change_type',1) ->where('source',0) ->select() ->toArray(); $insertLogData = []; foreach($weightValueLogList as $weightValueLogInfo){ // 获取用户持有信息 $holdInfo = WeightValue::where('uid',$weightValueLogInfo['uid']) ->where('brokerage_level',$weightValueLogInfo['brokerage_level']) ->find(); // 获取已经减少数量 $reduced = WeightValueLog::where('order_product_id',$data['order_product_id']) ->where('change_type',0) ->where('source',1) ->where('uid',$weightValueLogInfo['uid']) ->sum('change_quantity'); // 计算减少信息,总减少数量不能超过获取数量 $reduce = (float)sprintf("%.2f",$weightValueLogInfo['change_quantity'] * $data['refund_rate'] / 100); $totalReduce = (float)sprintf("%.2f",$reduced * $reduce); if($totalReduce > $weightValueLogInfo['change_quantity']) { $reduce = (float)sprintf("%.2f",$weightValueLogInfo['change_quantity'] - $reduced); } $changeFront = $holdInfo->quantity; $holdInfo->quantity = (float)sprintf("%.2f",$holdInfo->quantity - $reduce); $holdInfo->save(); // 记录变更记录 $insertLogData[] = [ 'uid' => $weightValueLogInfo['uid'], 'brokerage_level' => $weightValueLogInfo['brokerage_level'], 'product_id' => $weightValueLogInfo['product_id'], 'order_id' => $weightValueLogInfo['order_id'], 'order_product_id' => $weightValueLogInfo['order_product_id'], 'change_type' => 0, 'change_quantity' => $reduce, 'change_front' => $changeFront, 'change_after' => (float)$holdInfo->quantity, 'remark' => '商品退款,减少权重值', 'source' => 1, ]; } if(count($insertLogData) > 0) WeightValueLog::insertAll($insertLogData); } catch(\Exception $e){ $data['error_msg'] = $e->getMessage(); Log::info('订单退款成功 - 权重值相关处理 - 失败: '.var_export($data,1)); } $job->delete(); } public function failed($data){ Log::info('订单退款成功 - 权重值相关处理 - 失败(failed): '.var_export($data,1)); } }