Skip to content

Commit

Permalink
🔨增加设备分配用户记录操作人 #113 🔨增加观察者模式 🔨资产增加额外信息字段
Browse files Browse the repository at this point in the history
  • Loading branch information
celaraze committed Dec 14, 2023
1 parent 2714aed commit 8e38028
Show file tree
Hide file tree
Showing 88 changed files with 1,696 additions and 384 deletions.
13 changes: 7 additions & 6 deletions app/Filament/Actions/DeviceAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public static function createHasUser(?Model $out_device = null): Action
$device = $out_device;
}
$data['device_id'] = $device->getKey();
$data['operator_id'] = auth()->id();
$device_has_user_service = new DeviceHasUserService();
$device_has_user_service->create($data);
NotificationUtil::make(true, '设备已分配用户');
Expand Down Expand Up @@ -124,7 +125,7 @@ public static function createHasSoftware(?Model $out_device = null): Action
foreach ($data['software_ids'] as $software_id) {
$data['software_id'] = $software_id;
$data['device_id'] = $device->getKey();
$data['user_id'] = auth()->id();
$data['operator_id'] = auth()->id();
$data['status'] = 0;
$device_has_software_service = new DeviceHasSoftwareService();
$device_has_software_service->create($data);
Expand Down Expand Up @@ -155,7 +156,7 @@ public static function createHasPart(?Model $out_device = null): Action
foreach ($data['part_ids'] as $part_id) {
$data['part_id'] = $part_id;
$data['device_id'] = $device->getKey();
$data['user_id'] = auth()->id();
$data['operator_id'] = auth()->id();
$data['status'] = 0;
$device_has_part_service = new DeviceHasPartService();
$device_has_part_service->create($data);
Expand All @@ -181,7 +182,7 @@ public static function deleteHasPart(): Action
->action(function (DeviceHasPart $device_has_part) {
try {
$data = [
'user_id' => auth()->id(),
'operator_id' => auth()->id(),
'status' => 1,
];
$device_has_part->service()->delete($data);
Expand All @@ -206,7 +207,7 @@ public static function deleteHasSoftware(): Action
->action(function (DeviceHasSoftware $device_has_software) {
try {
$data = [
'user_id' => auth()->id(),
'operator_id' => auth()->id(),
'status' => 1,
];
$device_has_software->service()->delete($data);
Expand Down Expand Up @@ -401,7 +402,7 @@ public static function batchDeleteHasPart(): BulkAction
->icon('heroicon-s-minus-circle')
->action(function (Collection $device_has_parts) {
$data = [
'user_id' => auth()->id(),
'operator_id' => auth()->id(),
'status' => 1,
];
/* @var DeviceHasPart $device_has_part */
Expand All @@ -424,7 +425,7 @@ public static function batchDeleteHasSoftware(): BulkAction
->icon('heroicon-s-minus-circle')
->action(function (Collection $device_has_software) {
$data = [
'user_id' => auth()->id(),
'operator_id' => auth()->id(),
'status' => 1,
];
/* @var DeviceHasSoftware $item */
Expand Down
4 changes: 2 additions & 2 deletions app/Filament/Actions/PartAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static function createDeviceHasPart(?Model $out_part = null): Action
$part = $out_part;
}
$data['part_id'] = $part->getKey();
$data['user_id'] = auth()->id();
$data['operator_id'] = auth()->id();
$data['status'] = 0;
$device_has_part_service = new DeviceHasPartService();
$device_has_part_service->create($data);
Expand Down Expand Up @@ -83,7 +83,7 @@ public static function deleteDeviceHasPart(): Action
->action(function (DeviceHasPart $device_has_part) {
try {
$data = [
'user_id' => auth()->id(),
'operator_id' => auth()->id(),
'status' => 1,
];
$device_has_part->service()->delete($data);
Expand Down
6 changes: 3 additions & 3 deletions app/Filament/Actions/SoftwareAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static function createDeviceHasSoftware(?Model $out_software = null): Act
foreach ($data['device_ids'] as $device_id) {
$data['device_id'] = $device_id;
$data['software_id'] = $software->getKey();
$data['user_id'] = auth()->id();
$data['operator_id'] = auth()->id();
$data['status'] = 0;
$device_has_software_service = new DeviceHasSoftwareService();
$device_has_software_service->create($data);
Expand Down Expand Up @@ -87,7 +87,7 @@ public static function deleteDeviceHasSoftware(): Action
->action(function (DeviceHasSoftware $device_has_software) {
try {
$data = [
'user_id' => auth()->id(),
'operator_id' => auth()->id(),
'status' => 1,
];
$device_has_software->service()->delete($data);
Expand Down Expand Up @@ -219,7 +219,7 @@ public static function batchDeleteDeviceHasSoftware(): BulkAction
->color('danger')
->action(function (Collection $device_has_software) {
$data = [
'user_id' => auth()->id(),
'operator_id' => auth()->id(),
'status' => 1,
];
/* @var DeviceHasSoftware $item */
Expand Down
4 changes: 2 additions & 2 deletions app/Filament/Actions/TicketAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ public static function setAssignee(): Action
->requiresConfirmation()
->action(function (Ticket $ticket) {
try {
$user_id = auth()->id();
$ticket->service()->setAssignee($user_id);
$assignee_id = auth()->id();
$ticket->service()->setAssignee($assignee_id);
NotificationUtil::make(true, '已接单');
} catch (Exception $exception) {
LogUtil::error($exception);
Expand Down
10 changes: 4 additions & 6 deletions app/Filament/Actions/VendorAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Filament\Forms\VendorForm;
use App\Filament\Forms\VendorHasContactForm;
use App\Models\Vendor;
use App\Services\VendorHasContactService;
use App\Services\VendorService;
use App\Utils\LogUtil;
use App\Utils\NotificationUtil;
Expand All @@ -28,12 +29,9 @@ public static function createHasContact(?Model $out_vendor = null): Action
if ($out_vendor) {
$vendor = $out_vendor;
}
$data = [
'name' => $data['name'],
'phone_number' => $data['phone_number'],
'email' => $data['email'],
];
$vendor->service()->createHasContacts($data);
$data['vendor_id'] = $vendor->getKey();
$vendor_has_contact_service = new VendorHasContactService();
$vendor_has_contact_service->create($data);
NotificationUtil::make(true, '已添加联系人');
} catch (Exception $exception) {
LogUtil::error($exception);
Expand Down
2 changes: 1 addition & 1 deletion app/Filament/Forms/DeviceHasUserForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static function create(): array
->required(),

Select::make('user_id')
->label('使用者')
->label('用户')
->options(UserService::pluckOptions())
->searchable()
->required(),
Expand Down
2 changes: 2 additions & 0 deletions app/Filament/Forms/VendorHasContactForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public static function createOrEdit(): array
//region 文本 邮箱 email
TextInput::make('email')
->maxLength(255)
->required()
->rules(['email'])
->label('邮箱'),
//endregion

Expand Down
4 changes: 2 additions & 2 deletions app/Filament/Resources/DeviceResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -332,9 +332,9 @@ public static function infolist(Infolist $infolist): Infolist
->schema([
ImageEntry::make('image')
->disk('public')
->label('照片')
->height(300)
->defaultImageUrl(('/images/default.jpg')),
->defaultImageUrl(('/images/default.jpg'))
->label('照片'),
]),
])->columnSpan(['lg' => 1]),
])->columns(3);
Expand Down
2 changes: 1 addition & 1 deletion app/Filament/Resources/DeviceResource/Pages/HasPart.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function table(Table $table): Table
->searchable()
->toggleable()
->label('操作时间'),
Tables\Columns\TextColumn::make('user.name')
Tables\Columns\TextColumn::make('operator.name')
->searchable()
->toggleable()
->label('操作人'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function table(Table $table): Table
->searchable()
->toggleable()
->label('操作时间'),
Tables\Columns\TextColumn::make('user.name')
Tables\Columns\TextColumn::make('operator.name')
->searchable()
->toggleable()
->label('操作人'),
Expand Down
4 changes: 4 additions & 0 deletions app/Filament/Resources/DeviceResource/Pages/HasUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ public function table(Table $table): Table
->toggleable()
->size(TextColumnSize::ExtraSmall)
->label('解除分配时间'),
Tables\Columns\TextColumn::make('operator.name')
->searchable()
->toggleable()
->label('操作人'),
Tables\Columns\TextColumn::make('status')
->toggleable()
->badge()
Expand Down
4 changes: 2 additions & 2 deletions app/Filament/Resources/InventoryResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public static function table(Table $table): Table
return AssetUtil::mapper($state);
})
->label('资产'),
Tables\Columns\TextColumn::make('user.name')
Tables\Columns\TextColumn::make('operator.name')
->label('创建人'),
Tables\Columns\TextColumn::make('hasTracks.check')
->label('已盘点数量')
Expand Down Expand Up @@ -138,7 +138,7 @@ public static function infolist(Infolist $infolist): Infolist
Group::make()->schema([
Section::make()
->schema([
TextEntry::make('user.name')
TextEntry::make('operator.name')
->label('创建人'),
]),
])->columnSpan(['lg' => 1]),
Expand Down
4 changes: 4 additions & 0 deletions app/Filament/Resources/InventoryResource/Pages/HasTrack.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ public function table(Table $table): Table
->searchable()
->toggleable()
->label('备忘'),
Tables\Columns\TextColumn::make('operator.name')
->searchable()
->toggleable()
->label('操作人'),
])
->filters([

Expand Down
41 changes: 26 additions & 15 deletions app/Filament/Resources/PartResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Filament\Infolists\Components\Grid;
use Filament\Infolists\Components\Group;
use Filament\Infolists\Components\ImageEntry;
use Filament\Infolists\Components\RepeatableEntry;
use Filament\Infolists\Components\Section;
use Filament\Infolists\Components\Split;
use Filament\Infolists\Components\TextEntry;
Expand Down Expand Up @@ -225,9 +226,15 @@ public static function infolist(Infolist $infolist): Infolist
->schema([
Group::make([
TextEntry::make('asset_number')
->label('资产编号')
->badge()
->color('primary'),
->color('primary')
->hint(function (Part $part) {
return AssetEnum::statusText($part->getAttribute('status'));
})
->hintColor(function (Part $part) {
return AssetEnum::statusColor($part->getAttribute('status'));
})
->label('资产编号'),
TextEntry::make('category.name')
->label('分类'),
]),
Expand All @@ -246,25 +253,29 @@ public static function infolist(Infolist $infolist): Infolist
TextEntry::make('description')
->label('说明'),
]),
Section::make()->schema([
RepeatableEntry::make('additional')
->schema([
TextEntry::make('name')
->columnSpan(1)
->hiddenLabel(),
TextEntry::make('text')
->columnSpan(1)
->hiddenLabel(),
])
->grid()
->columns()
->label('额外信息'),
]),
])->columnSpan(['lg' => 2]),
Group::make()->schema([
Section::make()
->schema([
TextEntry::make('status')
->formatStateUsing(function ($state) {
return AssetEnum::statusText($state);
})
->color(function ($state) {
return AssetEnum::statusColor($state);
})
->label(''),
]),
Section::make()
->schema([
ImageEntry::make('image')
->disk('public')
->label('照片')
->defaultImageUrl(('/images/default.jpg')),
->height(300)
->defaultImageUrl(('/images/default.jpg'))
->label('照片'),
]),
])->columnSpan(['lg' => 1]),
])->columns(3);
Expand Down
39 changes: 25 additions & 14 deletions app/Filament/Resources/SoftwareResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Filament\Infolists\Components\Grid;
use Filament\Infolists\Components\Group;
use Filament\Infolists\Components\ImageEntry;
use Filament\Infolists\Components\RepeatableEntry;
use Filament\Infolists\Components\Section;
use Filament\Infolists\Components\Split;
use Filament\Infolists\Components\TextEntry;
Expand Down Expand Up @@ -239,7 +240,13 @@ public static function infolist(Infolist $infolist): Infolist
TextEntry::make('asset_number')
->label('资产编号')
->badge()
->color('primary'),
->color('primary')
->hint(function (Software $software) {
return AssetEnum::statusText($software->getAttribute('status'));
})
->hintColor(function (Software $software) {
return AssetEnum::statusColor($software->getAttribute('status'));
}),
TextEntry::make('name')
->label('名称'),
TextEntry::make('category.name')
Expand All @@ -262,25 +269,29 @@ public static function infolist(Infolist $infolist): Infolist
TextEntry::make('description')
->label('说明'),
]),
Section::make()->schema([
RepeatableEntry::make('additional')
->schema([
TextEntry::make('name')
->columnSpan(1)
->hiddenLabel(),
TextEntry::make('text')
->columnSpan(1)
->hiddenLabel(),
])
->grid()
->columns()
->label('额外信息'),
]),
])->columnSpan(['lg' => 2]),
Group::make()->schema([
Section::make()
->schema([
TextEntry::make('status')
->formatStateUsing(function ($state) {
return AssetEnum::statusText($state);
})
->color(function ($state) {
return AssetEnum::statusColor($state);
})
->label(''),
]),
Section::make()
->schema([
ImageEntry::make('image')
->disk('public')
->label('照片')
->defaultImageUrl(('/images/default.jpg')),
->height(300)
->defaultImageUrl(('/images/default.jpg'))
->label('照片'),
]),
])->columnSpan(['lg' => 1]),
])->columns(3);
Expand Down
9 changes: 9 additions & 0 deletions app/Models/Brand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Models;

use App\Services\BrandService;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
Expand All @@ -11,4 +12,12 @@ class Brand extends Model
use HasFactory, SoftDeletes;

protected $table = 'brands';

/**
* 模型到服务.
*/
public function service(): BrandService
{
return new BrandService($this);
}
}
2 changes: 1 addition & 1 deletion app/Models/DeviceHasPart.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class DeviceHasPart extends Model
*/
public function user(): BelongsTo
{
return $this->belongsTo(User::class, 'user_id', 'id');
return $this->belongsTo(User::class, 'operator_id', 'id');
}

/**
Expand Down
Loading

0 comments on commit 8e38028

Please sign in to comment.