generated from liutk/owl-admin-base
admin 升职申请
parent
cf972448a3
commit
399388e158
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace App\Admin\Controllers;
|
||||
|
||||
use App\Admin\Services\KeywordService;
|
||||
use App\Admin\Services\System\KeywordService;
|
||||
use Slowlyo\OwlAdmin\Renderers\Form;
|
||||
use Slowlyo\OwlAdmin\Renderers\Page;
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,136 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Controllers\Hr;
|
||||
|
||||
use App\Admin\Controllers\AdminController;
|
||||
use App\Admin\Services\EmployeePromotionService;
|
||||
use Slowlyo\OwlAdmin\Renderers\Form;
|
||||
use Slowlyo\OwlAdmin\Renderers\Page;
|
||||
use Slowlyo\OwlAdmin\Admin;
|
||||
use App\Enums\{CheckStatus, PromotionStatus, EmployeeStatus};
|
||||
use App\Models\EmployeePromotion;
|
||||
use App\Traits\HasCheckActions;
|
||||
|
||||
/**
|
||||
* 升职申请
|
||||
*/
|
||||
class PromotionController extends AdminController
|
||||
{
|
||||
use HasCheckActions;
|
||||
|
||||
protected string $serviceName = EmployeePromotionService::class;
|
||||
|
||||
public function list(): Page
|
||||
{
|
||||
$crud = $this->baseCRUD()
|
||||
->tableLayout('fixed')
|
||||
->headerToolbar([
|
||||
$this->createTypeButton('drawer', 'xl')->visible(Admin::user()->can('admin.hr.promotion.create')),
|
||||
...$this->baseHeaderToolBar(),
|
||||
])
|
||||
->bulkActions([])
|
||||
->filter($this->baseFilter()->body([
|
||||
amis()->GroupControl()->mode('horizontal')->body([
|
||||
amisMake()->SelectControl()->name('store_id')->label(__('employee_promotion.store_id'))
|
||||
->source(admin_url('api/stores?_all=1'))
|
||||
->labelField('title')
|
||||
->valueField('id')
|
||||
->searchable()
|
||||
->columnRatio(3)
|
||||
->clearable(),
|
||||
amisMake()->TextControl()->name('employee_search')->label(__('employee_promotion.employee_id'))
|
||||
->placeholder(__('employee.name').'/'.__('employee.phone'))
|
||||
->columnRatio(3)
|
||||
->clearable(),
|
||||
amisMake()->SelectControl()->name('job_id')->label(__('employee_promotion.job_id'))
|
||||
->source(admin_url('api/keywords/tree-list').'?parent_key=job')
|
||||
->labelField('name')
|
||||
->valueField('key')
|
||||
->columnRatio(3)
|
||||
->clearable(),
|
||||
amisMake()->TextControl()->name('invitor_search')->label(__('employee_promotion.invitor_id'))
|
||||
->placeholder(__('employee.name').'/'.__('employee.phone'))
|
||||
->columnRatio(3)
|
||||
->clearable(),
|
||||
]),
|
||||
amis()->GroupControl()->mode('horizontal')->body([
|
||||
amisMake()->SelectControl()->name('promotion_status')->label(__('employee_promotion.promotion_status'))
|
||||
->options(PromotionStatus::options())
|
||||
->columnRatio(3)
|
||||
->clearable(),
|
||||
]),
|
||||
]))
|
||||
->columns([
|
||||
amisMake()->TableColumn()->name('store.title')->label(__('employee_promotion.store_id')),
|
||||
amisMake()->TableColumn()->name('employee.name')->label(__('employee_promotion.employee_id')),
|
||||
amisMake()->TableColumn()->name('job.name')->label(__('employee_promotion.job_id')),
|
||||
amisMake()->TableColumn()->name('invitor.name')->label(__('employee_promotion.invitor_id')),
|
||||
amisMake()->TableColumn()->name('promotion_status')->label(__('employee_promotion.promotion_status'))->set('type', 'mapping')->map(PromotionStatus::options()),
|
||||
amisMake()->TableColumn()->name('created_at')->label(__('employee_promotion.created_at')),
|
||||
$this->rowActions([
|
||||
$this->rowShowButton()->visible(Admin::user()->can('admin.hr.promotion.view')),
|
||||
$this->rowEditTypeButton('drawer', 'xl')
|
||||
->visible(Admin::user()->can('admin.hr.promotion.update')),
|
||||
$this->rowDeleteButton()
|
||||
->visible(Admin::user()->can('admin.hr.promotion.delete')),
|
||||
$this->cancelAction()->visibleOn('${promotion_status == '.PromotionStatus::Processing->value.'}'),
|
||||
]),
|
||||
]);
|
||||
|
||||
return $this->baseList($crud);
|
||||
}
|
||||
|
||||
public function form($edit): Form
|
||||
{
|
||||
return $this->baseForm()->title('')->body([
|
||||
amisMake()->SelectControl()->name('employee_id')->label(__('employee_promotion.employee_id'))
|
||||
->source(admin_url('api/employees?_all=1&store_id_gt=0&employee_status='.EmployeeStatus::Online->value))
|
||||
->labelField('name')
|
||||
->valueField('id')
|
||||
->searchable()
|
||||
->joinValues(false)
|
||||
->extractValue()
|
||||
->required(),
|
||||
amisMake()->SelectControl()->name('invitor_id')->label(__('employee_promotion.invitor_id'))
|
||||
->source(admin_url('api/employees?_all=1&store_id_gt=0&employee_status='.EmployeeStatus::Online->value))
|
||||
->labelField('name')
|
||||
->valueField('id')
|
||||
->searchable()
|
||||
->joinValues(false)
|
||||
->extractValue()
|
||||
->required(),
|
||||
amisMake()->SelectControl()->name('job_id')->label(__('employee_promotion.job_id'))
|
||||
->source(admin_url('api/keywords/tree-list').'?parent_key=job')
|
||||
->labelField('name')
|
||||
->valueField('key'),
|
||||
amisMake()->TextControl()->name('remarks')->label(__('employee_promotion.remarks')),
|
||||
]);
|
||||
}
|
||||
|
||||
public function detail(): Form
|
||||
{
|
||||
$detailId = 'promotion-detail';
|
||||
$serviceId = 'promotion-checklog-service';
|
||||
|
||||
$detail = amisMake()->Property()->items([
|
||||
['label' => __('employee_promotion.store_id'), 'content' => '${store.title}'],
|
||||
['label' => __('employee_promotion.employee_id'), 'content' => '${employee.name}'],
|
||||
['label' => __('employee_promotion.job_id'), 'content' => '${job.name}'],
|
||||
['label' => __('employee_promotion.invitor_id'), 'content' => '${invitor.name}'],
|
||||
['label' => __('employee_promotion.promotion_status'), 'content' => amisMake()->Mapping()->name('promotion_status')->map(PromotionStatus::options())],
|
||||
['label' => __('employee_promotion.remarks'), 'content' => '${remarks}'],
|
||||
]);
|
||||
|
||||
return $this->baseDetail()->id($detailId)->title('')->onEvent([
|
||||
'inited' => [
|
||||
'actions' => [
|
||||
['actionType' => 'reload', 'componentId' => $serviceId],
|
||||
]
|
||||
]
|
||||
])->body([
|
||||
$detail,
|
||||
amisMake()->Divider(),
|
||||
$this->baseWorkflowLogService($detailId)->id($serviceId),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Filters;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use EloquentFilter\ModelFilter;
|
||||
|
||||
class EmployeePromotionFilter extends ModelFilter
|
||||
{
|
||||
protected $drop_id = false;
|
||||
|
||||
public $relations = [
|
||||
'store' => [
|
||||
'store_title' => 'title',
|
||||
],
|
||||
'employee' => [
|
||||
'employee_name' => 'name',
|
||||
'employee_search' => 'search',
|
||||
],
|
||||
'invitor' => [
|
||||
'invitor_name' => 'name',
|
||||
'invitor_search' => 'search',
|
||||
],
|
||||
];
|
||||
|
||||
public function employeeId($key)
|
||||
{
|
||||
$this->where('employee_id', $key);
|
||||
}
|
||||
|
||||
public function invitorId($key)
|
||||
{
|
||||
$this->where('invitor_id', $key);
|
||||
}
|
||||
|
||||
public function storeId($key)
|
||||
{
|
||||
$this->where('store_id', $key);
|
||||
}
|
||||
|
||||
public function jobId($key)
|
||||
{
|
||||
$this->where('job_id', $key);
|
||||
}
|
||||
|
||||
public function dateRange($dates)
|
||||
{
|
||||
$dates = explode(',', $dates);
|
||||
$start = Carbon::createFromTimestamp(data_get($dates, 0, time()))->startOfDay();
|
||||
$end = Carbon::createFromTimestamp(data_get($dates, 1, time()))->endOfDay();
|
||||
$this->whereBetween('created_at', [$start, $end]);
|
||||
}
|
||||
}
|
||||
|
|
@ -16,6 +16,11 @@ class BaseService extends AdminService
|
|||
|
||||
protected bool $modelSortAble = false;
|
||||
|
||||
public function sortColumn()
|
||||
{
|
||||
return 'id';
|
||||
}
|
||||
|
||||
public function getTree()
|
||||
{
|
||||
$list = $this->query()->orderByDesc('sort')->get();
|
||||
|
|
|
|||
|
|
@ -0,0 +1,106 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Services;
|
||||
|
||||
use App\Admin\Filters\EmployeePromotionFilter;
|
||||
use App\Models\{EmployeePromotion, Employee};
|
||||
use Illuminate\Support\Facades\{Validator, DB};
|
||||
use App\Admin\WorkflowService;
|
||||
use App\Enums\PromotionStatus;
|
||||
|
||||
class EmployeePromotionService extends BaseService
|
||||
{
|
||||
protected array $withRelationships = ['employee', 'invitor', 'job', 'store', 'workflow'];
|
||||
|
||||
protected string $modelName = EmployeePromotion::class;
|
||||
|
||||
protected string $modelFilterName = EmployeePromotionFilter::class;
|
||||
|
||||
public function resloveData($data, $model = null)
|
||||
{
|
||||
// 获取员工所在的门店
|
||||
if (isset($data['employee_id'])) {
|
||||
$data['store_id'] = Employee::where('id', $data['employee_id'])->value('store_id');
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 申请人完事资料
|
||||
*
|
||||
* @param EmployeePromotion $model
|
||||
* @param array $data
|
||||
* @return bool
|
||||
*/
|
||||
public function apply($model, $data = [])
|
||||
{
|
||||
$validator = Validator::make($data, [
|
||||
'age' => ['required'],
|
||||
'sex' => ['required'],
|
||||
'education' => ['required'],
|
||||
'first_work_time' => ['required'],
|
||||
'work_years' => ['required'],
|
||||
'work_years_in_company' => ['required'],
|
||||
'comment_self' => ['required'],
|
||||
'plans' => ['required'],
|
||||
]);
|
||||
if ($validator->fails()) {
|
||||
return $validator->errors()->first();
|
||||
}
|
||||
|
||||
$model->update(['employee_data' => $data, 'promotion_status' => PromotionStatus::Invitor]);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 邀请人填写推荐理由
|
||||
*
|
||||
* @param EmployeePromotion $model
|
||||
* @param array $data
|
||||
* @return bool
|
||||
*/
|
||||
public function invitor($model, $data = [])
|
||||
{
|
||||
$validator = Validator::make($data, [
|
||||
'reason' => ['required'],
|
||||
]);
|
||||
if ($validator->fails()) {
|
||||
return $validator->errors()->first();
|
||||
}
|
||||
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
$attributes = array_merge($model->employee_data, $data);
|
||||
$model->update(['employee_data' => $data, 'promotion_status' => PromotionStatus::Processing]);
|
||||
|
||||
// 发起审核申请
|
||||
$service = WorkflowService::make();
|
||||
if ($service->apply($model->workflow, $model->employee) !== true) {
|
||||
return $this->setError($service->getError());
|
||||
}
|
||||
DB::commit();
|
||||
} catch (\Exception $e) {
|
||||
DB::rollBack();
|
||||
return $this->setError($e->getMessage());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function validate($data, $model = null)
|
||||
{
|
||||
$createRules = [
|
||||
'store_id' => ['required'],
|
||||
'employee_id' => ['required'],
|
||||
'invitor_id' => ['required'],
|
||||
'job_id' => ['required'],
|
||||
];
|
||||
$updateRules = [];
|
||||
$validator = Validator::make($data, $model ? $updateRules : $createRules);
|
||||
if ($validator->fails()) {
|
||||
return $validator->errors()->first();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -84,8 +84,9 @@ class AdminUserService extends BaseService
|
|||
$user->save();
|
||||
|
||||
if (isset($data['roles'])) {
|
||||
$roles = Arr::pull($data, 'roles');
|
||||
$user->roles()->detach();
|
||||
$user->roles()->attach($data['roles']);
|
||||
$user->roles()->attach(Arr::has($roles, '0.id') ? Arr::pluck($roles, 'id') : $roles);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ use App\Admin\Controllers\Finance\StoreStatisticController;
|
|||
use App\Admin\Controllers\Hr\EmployeeController;
|
||||
use App\Admin\Controllers\Hr\HolidayController;
|
||||
use App\Admin\Controllers\Hr\OfficalBusinessController;
|
||||
use App\Admin\Controllers\Hr\PromotionController;
|
||||
use App\Admin\Controllers\Hr\OvertimeController;
|
||||
use App\Admin\Controllers\Hr\RestController;
|
||||
use App\Admin\Controllers\Hr\SignController;
|
||||
|
|
@ -93,6 +94,8 @@ Route::group([
|
|||
$router->resource('overtime', OvertimeController::class);
|
||||
// 出差报备
|
||||
$router->resource('business', OfficalBusinessController::class);
|
||||
// 升职申请
|
||||
$router->resource('promotion', PromotionController::class);
|
||||
});
|
||||
|
||||
/*
|
||||
|
|
|
|||
|
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
/**
|
||||
* 升职申请状态
|
||||
*/
|
||||
enum PromotionStatus: int
|
||||
{
|
||||
/**
|
||||
* 待提交, 需要升职员工填写相关资料
|
||||
*/
|
||||
case Employee = 1;
|
||||
/**
|
||||
* 待补充, 等待推荐人填写理由
|
||||
*/
|
||||
case Invitor = 2;
|
||||
/**
|
||||
* 审核中, 等待后台审核
|
||||
*/
|
||||
case Processing = 3;
|
||||
/**
|
||||
* 审核通过
|
||||
*/
|
||||
case Success = 4;
|
||||
/**
|
||||
* 审核不通过
|
||||
*/
|
||||
case Fail = 5;
|
||||
|
||||
public static function options()
|
||||
{
|
||||
return [
|
||||
self::Employee->value => '待提交',
|
||||
self::Invitor->value => '待补充',
|
||||
self::Processing->value => '审核中',
|
||||
self::Success->value => '审核通过',
|
||||
self::Fail->value => '审核不通过',
|
||||
];
|
||||
}
|
||||
|
||||
public function text()
|
||||
{
|
||||
return data_get(self::options(), $this->value);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use App\Enums\PromotionStatus;
|
||||
use App\Traits\HasDateTimeFormatter;
|
||||
use EloquentFilter\Filterable;
|
||||
use App\Traits\HasCheckable;
|
||||
|
||||
/**
|
||||
* 员工升职申请
|
||||
*/
|
||||
class EmployeePromotion extends Model
|
||||
{
|
||||
use Filterable, HasDateTimeFormatter, HasCheckable;
|
||||
|
||||
protected $fillable = ['store_id', 'employee_id', 'invitor_id', 'job_id', 'promotion_status', 'employee_data', 'remarks'];
|
||||
|
||||
protected $casts = [
|
||||
'promotion_status' => PromotionStatus::class,
|
||||
'employee_data' => 'json',
|
||||
];
|
||||
|
||||
public function modelFilter()
|
||||
{
|
||||
return \App\Admin\Filters\EmployeePromotionFilter::class;
|
||||
}
|
||||
|
||||
public function store()
|
||||
{
|
||||
return $this->belongsTo(Store::class, 'store_id');
|
||||
}
|
||||
|
||||
public function employee()
|
||||
{
|
||||
return $this->belongsTo(Employee::class, 'employee_id');
|
||||
}
|
||||
|
||||
public function invitor()
|
||||
{
|
||||
return $this->belongsTo(Employee::class, 'invitor_id');
|
||||
}
|
||||
|
||||
public function job()
|
||||
{
|
||||
return $this->belongsTo(Keyword::class, 'job_id', 'key');
|
||||
}
|
||||
}
|
||||
|
|
@ -38,6 +38,7 @@ class AppServiceProvider extends ServiceProvider
|
|||
\App\Models\Ledger::class,
|
||||
\App\Models\Reimbursement::class,
|
||||
\App\Models\StoreMasterCommission::class,
|
||||
\App\Models\EmployeePromotion::class,
|
||||
])->mapWithKeys(fn ($model) => [(new $model)->getTable() => $model])->all()
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ return new class extends Migration
|
|||
$table->json('prize_images')->nullable()->comment('荣誉证书');
|
||||
$table->json('skill_images')->nullable()->comment('专业证书');
|
||||
$table->unsignedInteger('employee_status')->default(1)->comment('员工状态{1: 在职, 2: 离职}');
|
||||
$table->foreignId('admin_user_id')->comment('登录信息, 关联 admin_users.id');
|
||||
$table->foreignId('admin_user_id')->unique()->comment('登录信息, 关联 admin_users.id');
|
||||
$table->timestamp('join_at')->nullable()->comment('入职时间');
|
||||
$table->timestamp('leave_at')->nullable()->comment('离职时间');
|
||||
$table->string('remarks')->nullable()->comment('备注');
|
||||
|
|
|
|||
|
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('employee_promotions', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('store_id')->comment('门店, stores.id');
|
||||
$table->foreignId('employee_id')->comment('待升职员工, employees.id');
|
||||
$table->foreignId('invitor_id')->comment('推荐人, employees.id');
|
||||
$table->string('job_id')->comment('目标职位(job), keywords.key');
|
||||
// 1: 待提交, 需要升职员工填写相关资料
|
||||
// 2: 待补充, 等待推荐人填写理由
|
||||
// 3: 审核中, 等待后台审核
|
||||
// 4: 审核通过
|
||||
// 5: 审核不通过
|
||||
$table->unsignedInteger('promotion_status')->default(1)->comment('申请状态');
|
||||
$table->json('employee_data')->nullable()->comment('员工资料');
|
||||
$table->string('remarks')->nullable()->comment('备注');
|
||||
$table->timestamps();
|
||||
|
||||
$table->comment('升职申请');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('employee_promotions');
|
||||
}
|
||||
};
|
||||
|
|
@ -146,6 +146,12 @@ class AdminPermissionSeeder extends Seeder
|
|||
'uri' => '/hr/business',
|
||||
'resource' => true,
|
||||
],
|
||||
'promotion' => [
|
||||
'name' => '升职申请',
|
||||
'icon' => '',
|
||||
'uri' => '/hr/promotion',
|
||||
'resource' => true,
|
||||
],
|
||||
],
|
||||
],
|
||||
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ class WorkflowSeeder extends Seeder
|
|||
['key' => 'ledger', 'name' => '上报数据', 'config' => $config, 'created_at' => now(), 'updated_at' => now()],
|
||||
['key' => 'reimbursement', 'name' => '收支报销', 'config' => $config, 'created_at' => now(), 'updated_at' => now()],
|
||||
['key' => 'store_master_commission', 'name' => '店长提成', 'config' => $config, 'created_at' => now(), 'updated_at' => now()],
|
||||
['key' => 'employee_promotion', 'name' => '升职申请', 'config' => $config, 'created_at' => now(), 'updated_at' => now()],
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
'id' => 'ID',
|
||||
'created_at' => '创建时间',
|
||||
'updated_at' => '更新时间',
|
||||
'store_id' => '门店',
|
||||
'employee_id' => '申请人',
|
||||
'invitor_id' => '推荐人',
|
||||
'job_id' => '申请职位',
|
||||
'promotion_status' => '状态',
|
||||
'employee_data' => '资料',
|
||||
'remarks' => '备注',
|
||||
|
||||
'age' => '年龄',
|
||||
'sex' => '性别',
|
||||
'education' => '学历',
|
||||
'first_work_time' => '首次参加工作时间',
|
||||
'work_years' => '工作年限',
|
||||
'work_years_in_company' => '本公司工作年限',
|
||||
'comment_self' => '自我评价',
|
||||
'plans' => '未来计划',
|
||||
'reason' => '推荐理由',
|
||||
];
|
||||
Loading…
Reference in New Issue