fix some bugs from accounting 9
This commit is contained in:
@@ -19,6 +19,30 @@ class AppNotificationController extends Controller
|
||||
{
|
||||
$query = AppNotification::query()->withCount('reads');
|
||||
|
||||
$source = trim((string) $request->input('source', 'all'));
|
||||
$hasIsSystem = \Illuminate\Support\Facades\Schema::hasColumn('app_notifications', 'is_system');
|
||||
|
||||
if ($source === 'system') {
|
||||
if ($hasIsSystem) {
|
||||
$query->system();
|
||||
} else {
|
||||
$query->where(function ($q) {
|
||||
$q->whereNull('created_by')
|
||||
->orWhere('audience_label', 'like', 'سیستمی%');
|
||||
});
|
||||
}
|
||||
} elseif ($source === 'admin') {
|
||||
if ($hasIsSystem) {
|
||||
$query->adminCreated();
|
||||
} else {
|
||||
$query->whereNotNull('created_by')
|
||||
->where(function ($q) {
|
||||
$q->whereNull('audience_label')
|
||||
->orWhere('audience_label', 'not like', 'سیستمی%');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
TableEngine::create($query, $request->all())
|
||||
->initSearch(['title', 'body', 'severity', 'audience_label', 'audience_type'])
|
||||
->select(['*'])
|
||||
@@ -104,7 +128,7 @@ class AppNotificationController extends Controller
|
||||
$row = DB::transaction(function () use ($data, $audience, $audienceType, $segmentKeys, $recipients, $recipientsCount) {
|
||||
$user = auth()->user();
|
||||
|
||||
$row = AppNotification::create([
|
||||
$payload = [
|
||||
'title' => $data['title'],
|
||||
'body' => $data['body'],
|
||||
'severity' => $data['severity'],
|
||||
@@ -114,7 +138,12 @@ class AppNotificationController extends Controller
|
||||
'segment_keys' => $audienceType === AppNotificationAudienceService::TYPE_SEGMENT ? $segmentKeys : null,
|
||||
'audience_label' => $audience->buildAudienceLabel($audienceType, $segmentKeys, $recipientsCount),
|
||||
'recipients_count' => $recipientsCount,
|
||||
]);
|
||||
];
|
||||
if (\Illuminate\Support\Facades\Schema::hasColumn('app_notifications', 'is_system')) {
|
||||
$payload['is_system'] = false;
|
||||
}
|
||||
|
||||
$row = AppNotification::create($payload);
|
||||
|
||||
if ($audienceType !== AppNotificationAudienceService::TYPE_ALL) {
|
||||
$now = now();
|
||||
@@ -141,6 +170,12 @@ class AppNotificationController extends Controller
|
||||
public function update(Request $request, int $id)
|
||||
{
|
||||
$row = AppNotification::findOrFail($id);
|
||||
$isSystem = \Illuminate\Support\Facades\Schema::hasColumn('app_notifications', 'is_system')
|
||||
? (bool) $row->is_system
|
||||
: ($row->created_by === null && str_starts_with((string) $row->audience_label, 'سیستمی'));
|
||||
if ($isSystem) {
|
||||
return response()->json(['message' => 'اعلان سیستمی قابل ویرایش نیست.'], 422);
|
||||
}
|
||||
// مخاطب بعد از ارسال ثابت میماند — فقط محتوا/وضعیت
|
||||
$data = $request->validate([
|
||||
'title' => 'sometimes|required|string|max:191',
|
||||
|
||||
Reference in New Issue
Block a user