isEmpty()) { Log::error('账户流水记录:用户不存在', ['sourceSn' => $sourceSn, 'userId' => $userId]); return false; } $changeObject = AccountLogEnum::getChangeObject($changeType); if(!$changeObject) { Log::error('账户流水记录:变动类型不存在', ['sourceSn' => $sourceSn, 'userId' => $userId, 'changeType' => $changeType]); return false; } switch ($changeObject) { // 用户余额 case AccountLogEnum::UM: $left_amount = $user->user_money; break; // 其他 } if($extra){ $company_id=$extra['company_id']??0; $extra=json_encode($extra, JSON_UNESCAPED_UNICODE); }else{ $extra=''; $company_id=0; } $data = [ 'sn' => generate_sn(UserAccountLog::class, 'sn', 20), 'user_id' => $userId, 'company_id'=>$company_id, 'change_object' => $changeObject, 'change_type' => $changeType, 'action' => $action, 'left_amount' => $left_amount, 'change_amount' => $changeAmount, 'source_sn' => $sourceSn, 'remark' => $remark, 'extra' => $extra, 'status'=>$status, ]; return UserAccountLog::create($data); } }