Compare commits

...

6 Commits

Author SHA1 Message Date
panliang 06b694f6bf merge 2024-04-16 17:02:37 +08:00
panliang f66433e658 api 升职申请 2024-04-16 17:01:54 +08:00
panliang 9dceb459fc api 出差报备 2024-04-16 13:14:11 +08:00
panliang 8a695cd2c9 api 合同管理 2024-04-16 12:51:19 +08:00
panliang 1517612709 Merge branch 'main' of https://gitea.hmily.club/pdkj/store-manage into main 2024-04-16 12:11:03 +08:00
panliang feecda3d8b api 加班申请 2024-04-16 12:10:57 +08:00
26 changed files with 844 additions and 67 deletions

View File

@ -101,12 +101,14 @@ class OvertimeController extends AdminController
$detail = amisMake()->Property()->items([
['label' => __('overtime_apply.store_id'), 'content' => '${store.title}'],
['label' => __('overtime_apply.employee_id'), 'content' => '${employee.name}'],
['label' => __('overtime_apply.date'), 'content' => '${date}'],
['label' => __('overtime_apply.start_at'), 'content' => '${start_at}'],
['label' => __('overtime_apply.end_at'), 'content' => '${end_at}'],
['label' => __('overtime_apply.hours'), 'content' => '${hours}'],
['label' => __('overtime_apply.created_at'), 'content' => '${created_at}'],
['label' => __('overtime_apply.reason'), 'content' => '${reason}', 'span' => 2],
['label' => __('overtime_apply.date'), 'content' => [
amisMake()->Tag()->label('${date}'),
amisMake()->Tag()->label('${start_at}'),
amisMake()->Tag()->label('${end_at}'),
], 'span' => 2],
['label' => __('overtime_apply.hours'), 'content' => '${hours}'],
['label' => __('overtime_apply.reason'), 'content' => '${reason}', 'span' => 3],
['label' => __('workflow_log.check_status'), 'content' => amisMake()->Mapping()->name('workflow.check_status')->map(CheckStatus::options())],
['label' => __('workflow_log.checked_at'), 'content' => '${workflow.checked_at}'],
['label' => __('workflow_log.remarks'), 'content' => '${workflow.check_remarks}'],

View File

@ -61,6 +61,7 @@ class PromotionController extends AdminController
]),
]))
->columns([
amisMake()->TableColumn()->name('id')->label(__('employee_promotion.id')),
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')),
@ -70,9 +71,11 @@ class PromotionController extends AdminController
$this->rowActions([
$this->rowShowButton()->visible(Admin::user()->can('admin.hr.promotion.view')),
$this->rowEditTypeButton('drawer', 'xl')
->visible(Admin::user()->can('admin.hr.promotion.update')),
->visible(Admin::user()->can('admin.hr.promotion.update'))
->visibleOn('${can_update}'),
$this->rowDeleteButton()
->visible(Admin::user()->can('admin.hr.promotion.delete')),
->visible(Admin::user()->can('admin.hr.promotion.delete'))
->visibleOn('${can_update}'),
$this->cancelAction()->visibleOn('${promotion_status == '.PromotionStatus::Processing->value.'}'),
]),
]);
@ -102,7 +105,8 @@ class PromotionController extends AdminController
amisMake()->SelectControl()->name('job_id')->label(__('employee_promotion.job_id'))
->source(admin_url('api/keywords/tree-list').'?parent_key=job')
->labelField('name')
->valueField('key'),
->valueField('key')
->required(),
amisMake()->TextControl()->name('remarks')->label(__('employee_promotion.remarks')),
]);
}
@ -119,6 +123,19 @@ class PromotionController extends AdminController
['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}'],
['label' => __('employee_promotion.created_at'), 'content' => '${created_at}', 'span' => 3],
]);
$data = amisMake()->Property()->items([
['label' => __('employee_promotion.age'), 'content' => '${employee_data.age}'],
['label' => __('employee_promotion.sex'), 'content' => '${employee_data.sex}'],
['label' => __('employee_promotion.education'), 'content' => '${employee_data.education}'],
['label' => __('employee_promotion.first_work_time'), 'content' => '${employee_data.first_work_time}'],
['label' => __('employee_promotion.work_years'), 'content' => '${employee_data.work_years}'],
['label' => __('employee_promotion.work_years_in_company'), 'content' => '${employee_data.work_years_in_company}'],
['label' => __('employee_promotion.comment_self'), 'content' => '${employee_data.comment_self}', 'span' => 3],
['label' => __('employee_promotion.plans'), 'content' => '${employee_data.plans}', 'span' => 3],
['label' => __('employee_promotion.reason'), 'content' => '${employee_data.reason}', 'span' => 3],
]);
return $this->baseDetail()->id($detailId)->title('')->onEvent([
@ -129,6 +146,8 @@ class PromotionController extends AdminController
],
])->body([
$detail,
amisMake()->Divider()->title('补充资料'),
$data,
amisMake()->Divider(),
$this->baseWorkflowLogService($detailId)->id($serviceId),
]);

View File

@ -20,12 +20,19 @@ class AgreementService extends BaseService
if (isset($data['images']) && $data['images']) {
$images = [];
foreach ($data['images'] as $value) {
$image = data_get($value, 'value');
$url = Str::startsWith($image, ['http://', 'https://']) ? $image : Storage::url($image);
array_push($images, [
'value' => $image,
'preview' => $url,
]);
if (is_array($value)) {
$image = data_get($value, 'value');
$url = Str::startsWith($image, ['http://', 'https://']) ? $image : Storage::url($image);
array_push($images, [
'value' => $image,
'preview' => $url,
]);
} else {
array_push($images, [
'value' => $value,
'preview' => $value,
]);
}
}
$data['images'] = $images;
}
@ -47,14 +54,34 @@ class AgreementService extends BaseService
return true;
}
public function delete(string $ids): mixed
public function update($primaryKey, $data): bool
{
$id = explode(',', $ids);
$model = $this->query()->whereKey($primaryKey)->firstOrFail();
if (!$model->canUpdate()) {
return $this->setError('审核中, 无法修改');
}
$data = $this->resloveData($data, $model);
$validate = $this->validate($data, $model);
if ($validate !== true) {
$this->setError($validate);
foreach (Agreement::whereIn('id', $id)->get() as $item) {
$item->delete();
return false;
}
$model->update($data);
$this->currentModel = $model;
return true;
}
public function delete(string $ids): mixed
{
$list = $this->query()->with(['workflow'])->whereIn('id', explode(',', $ids))->get();
foreach ($list as $item) {
if (!$item->canUpdate()) {
return $this->setError('审核中, 无法删除');
}
$item->delete();
}
return true;
}
}

View File

@ -3,6 +3,7 @@
namespace App\Admin\Services;
use Slowlyo\OwlAdmin\Services\AdminService;
use Illuminate\Database\Eloquent\Model;
/**
* @method Region getModel()
@ -14,6 +15,13 @@ class BaseService extends AdminService
protected bool $modelSortAble = false;
protected Model $currentModel;
public function getCurrentModel()
{
return $this->currentModel;
}
public function sortColumn()
{
return 'id';
@ -78,7 +86,8 @@ class BaseService extends AdminService
return false;
}
$this->modelName::create($data);
$model = $this->modelName::create($data);
$this->currentModel = $model;
return true;
}
@ -93,8 +102,9 @@ class BaseService extends AdminService
return false;
}
return $model->update($data);
$model->update($data);
$this->currentModel = $model;
return true;
}
public function delete(string $ids): mixed

View File

@ -37,6 +37,9 @@ class EmployeePromotionService extends BaseService
*/
public function apply($model, $data = [])
{
if (!$model->canUpdate()) {
return $this->setError('审核中, 无法修改');
}
$validator = Validator::make($data, [
'age' => ['required'],
'sex' => ['required'],
@ -48,7 +51,7 @@ class EmployeePromotionService extends BaseService
'plans' => ['required'],
]);
if ($validator->fails()) {
return $validator->errors()->first();
return $this->setError($validator->errors()->first());
}
$model->update(['employee_data' => $data, 'promotion_status' => PromotionStatus::Invitor]);
@ -65,35 +68,25 @@ class EmployeePromotionService extends BaseService
*/
public function invitor($model, $data = [])
{
if (!$model->canUpdate()) {
return $this->setError('审核中, 无法修改');
}
$validator = Validator::make($data, [
'reason' => ['required'],
]);
if ($validator->fails()) {
return $validator->errors()->first();
return $this->setError($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());
}
$attributes = array_merge($model->employee_data, $data);
$model->update(['employee_data' => $attributes, 'promotion_status' => PromotionStatus::Processing]);
return true;
}
public function validate($data, $model = null)
{
// todo 验证申请人的职位是否重复
$createRules = [
'store_id' => ['required'],
'employee_id' => ['required'],
@ -108,4 +101,35 @@ class EmployeePromotionService extends BaseService
return true;
}
public function update($primaryKey, $data): bool
{
$model = $this->query()->whereKey($primaryKey)->firstOrFail();
if (!$model->canUpdate()) {
return $this->setError('审核中, 无法修改');
}
$data = $this->resloveData($data, $model);
$validate = $this->validate($data, $model);
if ($validate !== true) {
$this->setError($validate);
return false;
}
$model->update($data);
$this->currentModel = $model;
return true;
}
public function delete(string $ids): mixed
{
$list = $this->query()->with(['workflow'])->whereIn('id', explode(',', $ids))->get();
foreach ($list as $item) {
if (!$item->canUpdate()) {
return $this->setError($item->promotion_status->text() . ', 无法删除');
}
$item->delete();
}
return true;
}
}

View File

@ -65,16 +65,19 @@ class HolidayApplyService extends BaseService
return false;
}
return $model->update($data);
$model->update($data);
$this->currentModel = $model;
return true;
}
public function delete(string $ids): mixed
{
$list = HolidayApply::with(['workflow'])->whereIn('id', explode(',', $ids))->get();
$list = $this->query()->with(['workflow'])->whereIn('id', explode(',', $ids))->get();
foreach ($list as $item) {
if (!$item->canUpdate()) {
return $this->setError('审核中, 无法删除');
}
$item->delete();
}
return true;
}

View File

@ -35,8 +35,7 @@ class OfficalBusinessService extends BaseService
public function validate($data, $model = null)
{
// 验证申请时间是否重叠
// todo
// todo 验证申请时间是否重复
$createRules = [
'employee_id' => ['required'],
'start_at' => ['required'],
@ -51,4 +50,35 @@ class OfficalBusinessService extends BaseService
return true;
}
public function update($primaryKey, $data): bool
{
$model = $this->query()->whereKey($primaryKey)->firstOrFail();
if (!$model->canUpdate()) {
return $this->setError('审核中, 无法修改');
}
$data = $this->resloveData($data, $model);
$validate = $this->validate($data, $model);
if ($validate !== true) {
$this->setError($validate);
return false;
}
$model->update($data);
$this->currentModel = $model;
return true;
}
public function delete(string $ids): mixed
{
$list = $this->query()->with(['workflow'])->whereIn('id', explode(',', $ids))->get();
foreach ($list as $item) {
if (!$item->canUpdate()) {
return $this->setError('审核中, 无法删除');
}
$item->delete();
}
return true;
}
}

View File

@ -29,6 +29,10 @@ class OvertimeApplyService extends BaseService
$data['start_at'] = $start;
$data['end_at'] = $end;
$data['date'] = $start->format('Y-m-d');
}
if (isset($data['start_at']) && isset($data['end_at'])) {
$start = $data['start_at'] instanceof \DateTime ? $data['start_at'] : Carbon::parse($data['start_at']);
$end = $data['end_at'] instanceof \DateTime ? $data['end_at'] : Carbon::parse($data['end_at']);
$data['hours'] = $start->diffInHours($end);
}
@ -37,10 +41,10 @@ class OvertimeApplyService extends BaseService
public function validate($data, $model = null)
{
// 验证申请时间是否重叠
// todo
// todo 验证申请时间是否重复
$createRules = [
'employee_id' => ['required'],
'date' => ['required'],
'start_at' => ['required'],
'end_at' => ['required'],
];
@ -52,4 +56,33 @@ class OvertimeApplyService extends BaseService
return true;
}
public function update($primaryKey, $data): bool
{
$model = $this->query()->whereKey($primaryKey)->firstOrFail();
if (!$model->canUpdate()) {
return $this->setError('审核中, 无法修改');
}
$data = $this->resloveData($data, $model);
$validate = $this->validate($data, $model);
if ($validate !== true) {
$this->setError($validate);
return false;
}
return $model->update($data);
}
public function delete(string $ids): mixed
{
$list = $this->query()->with(['workflow'])->whereIn('id', explode(',', $ids))->get();
foreach ($list as $item) {
if (!$item->canUpdate()) {
return $this->setError('审核中, 无法删除');
}
$item->delete();
}
return true;
}
}

View File

@ -33,10 +33,10 @@ class WorkFlowService extends BaseService
*/
public function apply(WorkflowCheck $check, Employee $user)
{
if ($check->check_status === CheckStatus::Success->value) {
if ($check->check_status === CheckStatus::Success) {
admin_abort('已经审核通过');
}
if ($check->check_status === CheckStatus::Processing->value) {
if ($check->check_status === CheckStatus::Processing) {
admin_abort('正在审核中');
}
@ -113,6 +113,8 @@ class WorkFlowService extends BaseService
'checked_at' => data_get($options, 'checked_at', now()),
]);
$check->subject->checkFail();
return true;
}
@ -128,6 +130,8 @@ class WorkFlowService extends BaseService
'check_status' => CheckStatus::Cancel,
]);
$check->subject->checkCancel();
return true;
}

View File

@ -12,7 +12,7 @@ enum PromotionStatus: int
*/
case Employee = 1;
/**
* 补充, 等待推荐人填写理由
* 推荐, 等待推荐人填写理由
*/
case Invitor = 2;
/**
@ -32,7 +32,7 @@ enum PromotionStatus: int
{
return [
self::Employee->value => '待提交',
self::Invitor->value => '待补充',
self::Invitor->value => '待推荐',
self::Processing->value => '审核中',
self::Success->value => '审核通过',
self::Fail->value => '审核不通过',

View File

@ -0,0 +1,102 @@
<?php
namespace App\Http\Controllers\Api;
use Illuminate\Http\Request;
use App\Models\Agreement;
use App\Http\Resources\AgreementResource;
use App\Admin\Services\{AgreementService, WorkFlowService};
use App\Exceptions\RuntimeException;
use Illuminate\Support\Facades\DB;
/**
* 合同管理
*/
class AgreementController extends Controller
{
public function index(Request $request)
{
$user = $this->guard()->user();
$list = Agreement::with(['workflow'])
->where('employee_id', $user->id)
->filter($request->all())
->orderBy('id', 'desc')
->paginate($request->input('per_page'));
return AgreementResource::collection($list);
}
public function show($id)
{
$info = Agreement::with(['employee', 'workflow'])->findOrFail($id);
return AgreementResource::make($info);
}
public function store(Request $request, AgreementService $service)
{
$user = $this->guard()->user();
$data = $request->all();
$data['employee_id'] = $user->id;
try {
DB::beginTransaction();
if (!$service->store($data)) {
throw new RuntimeException($result);
}
$model = $service->getCurrentModel();
$workflow = WorkFlowService::make();
if (!$workflow->apply($model->workflow, $user)) {
throw new RuntimeException($workflow->getError());
}
DB::commit();
return response()->noContent();
} catch (\Exception $e) {
DB::rollBack();
throw new RuntimeException($e->getMessage());
}
}
public function update($id, Request $request, AgreementService $service)
{
$user = $this->guard()->user();
$model = Agreement::where('employee_id', $user->id)->findOrFail($id);
try {
DB::beginTransaction();
if (!$service->update($id, $request->all())) {
throw new RuntimeException($service->getError());
}
$workflow = WorkFlowService::make();
if (!$workflow->apply($model->workflow, $user)) {
throw new RuntimeException($workflow->getError());
}
DB::commit();
return response()->noContent();
} catch (\Exception $e) {
DB::rollBack();
throw new RuntimeException($e->getMessage());
}
}
public function destroy($id, AgreementService $service)
{
$user = $this->guard()->user();
$model = Agreement::where('employee_id', $user->id)->findOrFail($id);
try {
DB::beginTransaction();
if (!$service->delete($id)) {
throw new RuntimeException($service->getError());
}
DB::commit();
return response()->noContent();
} catch (\Exception $e) {
DB::rollBack();
throw new RuntimeException($e->getMessage());
}
}
}

View File

@ -3,7 +3,7 @@
namespace App\Http\Controllers\Api\Hr;
use App\Http\Controllers\Api\Controller;
use Illuminate\Http\{Request, Response};
use Illuminate\Http\Request;
use App\Models\HolidayApply;
use App\Http\Resources\HolidayApplyResource;
use App\Admin\Services\{HolidayApplyService, WorkFlowService};

View File

@ -0,0 +1,103 @@
<?php
namespace App\Http\Controllers\Api\Hr;
use App\Http\Controllers\Api\Controller;
use Illuminate\Http\Request;
use App\Models\OfficalBusiness;
use App\Http\Resources\OfficalBusinessResource;
use App\Admin\Services\{OfficalBusinessService, WorkFlowService};
use App\Exceptions\RuntimeException;
use Illuminate\Support\Facades\DB;
/**
* 出差报备
*/
class OfficalBusinessController extends Controller
{
public function index(Request $request)
{
$user = $this->guard()->user();
$list = OfficalBusiness::with(['workflow'])
->where('employee_id', $user->id)
->filter($request->all())
->orderBy('id', 'desc')
->paginate($request->input('per_page'));
return OfficalBusinessResource::collection($list);
}
public function show($id)
{
$info = OfficalBusiness::with(['employee', 'store', 'workflow'])->findOrFail($id);
return OfficalBusinessResource::make($info);
}
public function store(Request $request, OfficalBusinessService $service)
{
$user = $this->guard()->user();
$data = $request->all();
$data['employee_id'] = $user->id;
try {
DB::beginTransaction();
if (!$service->store($data)) {
throw new RuntimeException($result);
}
$model = $service->getCurrentModel();
$workflow = WorkFlowService::make();
if (!$workflow->apply($model->workflow, $user)) {
throw new RuntimeException($workflow->getError());
}
DB::commit();
return response()->noContent();
} catch (\Exception $e) {
DB::rollBack();
throw new RuntimeException($e->getMessage());
}
}
public function update($id, Request $request, OfficalBusinessService $service)
{
$user = $this->guard()->user();
$model = OfficalBusiness::where('employee_id', $user->id)->findOrFail($id);
try {
DB::beginTransaction();
if (!$service->update($id, $request->all())) {
throw new RuntimeException($service->getError());
}
$workflow = WorkFlowService::make();
if (!$workflow->apply($model->workflow, $user)) {
throw new RuntimeException($workflow->getError());
}
DB::commit();
return response()->noContent();
} catch (\Exception $e) {
DB::rollBack();
throw new RuntimeException($e->getMessage());
}
}
public function destroy($id, OfficalBusinessService $service)
{
$user = $this->guard()->user();
$model = OfficalBusiness::where('employee_id', $user->id)->findOrFail($id);
try {
DB::beginTransaction();
if (!$service->delete($id)) {
throw new RuntimeException($service->getError());
}
DB::commit();
return response()->noContent();
} catch (\Exception $e) {
DB::rollBack();
throw new RuntimeException($e->getMessage());
}
}
}

View File

@ -0,0 +1,103 @@
<?php
namespace App\Http\Controllers\Api\Hr;
use App\Http\Controllers\Api\Controller;
use Illuminate\Http\Request;
use App\Models\OvertimeApply;
use App\Http\Resources\OvertimeApplyResource;
use App\Admin\Services\{OvertimeApplyService, WorkFlowService};
use App\Exceptions\RuntimeException;
use Illuminate\Support\Facades\DB;
/**
* 加班申请
*/
class OvertimeController extends Controller
{
public function index(Request $request)
{
$user = $this->guard()->user();
$list = OvertimeApply::with(['workflow'])
->where('employee_id', $user->id)
->filter($request->all())
->orderBy('id', 'desc')
->paginate($request->input('per_page'));
return OvertimeApplyResource::collection($list);
}
public function show($id)
{
$info = OvertimeApply::with(['employee', 'store', 'workflow'])->findOrFail($id);
return OvertimeApplyResource::make($info);
}
public function store(Request $request, OvertimeApplyService $service)
{
$user = $this->guard()->user();
$data = $request->all();
$data['employee_id'] = $user->id;
try {
DB::beginTransaction();
if (!$service->store($data)) {
throw new RuntimeException($result);
}
$model = $service->getCurrentModel();
$workflow = WorkFlowService::make();
if (!$workflow->apply($model->workflow, $user)) {
throw new RuntimeException($workflow->getError());
}
DB::commit();
return response()->noContent();
} catch (\Exception $e) {
DB::rollBack();
throw new RuntimeException($e->getMessage());
}
}
public function update($id, Request $request, OvertimeApplyService $service)
{
$user = $this->guard()->user();
$model = OvertimeApply::where('employee_id', $user->id)->findOrFail($id);
try {
DB::beginTransaction();
if (!$service->update($id, $request->all())) {
throw new RuntimeException($service->getError());
}
$workflow = WorkFlowService::make();
if (!$workflow->apply($model->workflow, $user)) {
throw new RuntimeException($workflow->getError());
}
DB::commit();
return response()->noContent();
} catch (\Exception $e) {
DB::rollBack();
throw new RuntimeException($e->getMessage());
}
}
public function destroy($id, OvertimeApplyService $service)
{
$user = $this->guard()->user();
$model = OvertimeApply::where('employee_id', $user->id)->findOrFail($id);
try {
DB::beginTransaction();
if (!$service->delete($id)) {
throw new RuntimeException($service->getError());
}
DB::commit();
return response()->noContent();
} catch (\Exception $e) {
DB::rollBack();
throw new RuntimeException($e->getMessage());
}
}
}

View File

@ -0,0 +1,115 @@
<?php
namespace App\Http\Controllers\Api\Hr;
use App\Http\Controllers\Api\Controller;
use Illuminate\Http\Request;
use App\Models\EmployeePromotion;
use App\Http\Resources\EmployeePromotionResource;
use App\Admin\Services\{EmployeePromotionService, WorkFlowService};
use App\Exceptions\RuntimeException;
use Illuminate\Support\Facades\DB;
use App\Enums\PromotionStatus;
/**
* 升职申请
*/
class PromotionController extends Controller
{
/**
* 申请列表
*/
public function applyList(Request $request)
{
$user = $this->guard()->user();
$list = EmployeePromotion::with(['workflow', 'invitor', 'job'])
->where('employee_id', $user->id)
->filter($request->all())
->orderBy('id', 'desc')
->paginate($request->input('per_page'));
return EmployeePromotionResource::collection($list);
}
/**
* 推荐列表
*/
public function inviteList(Request $request)
{
$user = $this->guard()->user();
$list = EmployeePromotion::with(['workflow', 'employee', 'job'])
->where('invitor_id', $user->id)
->filter($request->all())
->orderBy('id', 'desc')
->paginate($request->input('per_page'));
return EmployeePromotionResource::collection($list);
}
public function show($id)
{
$info = EmployeePromotion::with(['workflow', 'employee', 'invitor', 'job'])->findOrFail($id);
return EmployeePromotionResource::make($info);
}
/**
* 申请人完善资料
*/
public function applyUpdate($id, Request $request, EmployeePromotionService $service)
{
$user = $this->guard()->user();
$info = EmployeePromotion::where('employee_id', $user->id)->findOrFail($id);
if (!$service->apply($info, $request->all())) {
throw new RuntimeException($service->getError());
}
return response()->noContent();
}
/**
* 推荐人填写
*/
public function inviteUpdate($id, Request $request, EmployeePromotionService $service)
{
$user = $this->guard()->user();
$model = EmployeePromotion::with(['workflow', 'employee'])->where('invitor_id', $user->id)->findOrFail($id);
try {
DB::beginTransaction();
if (!$service->invitor($model, $request->all())) {
throw new RuntimeException($service->getError());
}
$workflow = WorkFlowService::make();
if (!$workflow->apply($model->workflow, $model->employee)) {
throw new RuntimeException($workflow->getError());
}
DB::commit();
return response()->noContent();
} catch (\Exception $e) {
DB::rollBack();
throw new RuntimeException($e->getMessage());
}
}
public function destroy($id, EmployeePromotionService $service)
{
$user = $this->guard()->user();
$model = EmployeePromotion::where('employee_id', $user->id)->findOrFail($id);
try {
DB::beginTransaction();
if (!$service->delete($id)) {
throw new RuntimeException($service->getError());
}
DB::commit();
return response()->noContent();
} catch (\Exception $e) {
DB::rollBack();
throw new RuntimeException($e->getMessage());
}
}
}

View File

@ -35,12 +35,10 @@ class SignRepairController extends Controller
try {
DB::beginTransaction();
$data = $service->resloveData($data);
$result = $service->validate($data);
if ($result !== true) {
if (!$service->store($data)) {
throw new RuntimeException($result);
}
$model = EmployeeSignRepair::create($data);
$model = $service->getCurrentModel();
$workflow = WorkFlowService::make();
if (!$workflow->apply($model->workflow, $user)) {
throw new RuntimeException($workflow->getError());
@ -71,12 +69,9 @@ class SignRepairController extends Controller
try {
DB::beginTransaction();
$data = $service->resloveData($request->all(), $model);
$result = $service->validate($data, $model);
if ($result !== true) {
throw new RuntimeException($result);
if (!$service->update($id, $request->all())) {
throw new RuntimeException($service->getError());
}
$model->update($data);
$workflow = WorkFlowService::make();
if (!$workflow->apply($model->workflow, $user)) {
throw new RuntimeException($workflow->getError());

View File

@ -4,7 +4,7 @@ namespace App\Http\Controllers\Api;
use Illuminate\Http\{Request, Response};
use Illuminate\Database\Eloquent\Relations\Relation;
use App\Http\Resources\{ReimbursementResource, WorkflowLogResource, EmployeeSignRepairResource, HolidayApplyResource};
use App\Http\Resources\{ReimbursementResource, WorkflowLogResource, EmployeeSignRepairResource, HolidayApplyResource, OvertimeApplyResource, AgreementResource, EmployeePromotionResource};
use App\Enums\CheckStatus;
use App\Models\{WorkflowLog, WorkflowCheck};
use Illuminate\Support\Facades\DB;
@ -126,7 +126,15 @@ class WorkflowController extends Controller
'reimbursements' => ReimbursementResource::class,
'employee_sign_repairs' => EmployeeSignRepairResource::class,
'holiday_applies' => HolidayApplyResource::class,
'overtime_applies' => OvertimeApplyResource::class,
'agreements' => AgreementResource::class,
'offical_business' => OfficalBusinessResource::class,
'employee_promotions' => EmployeePromotionResource::class,
];
return data_get($map, $key);
$resource = data_get($map, $key);
if (!$resource) {
throw new RuntimeException('未知的 subject_type resource: ' . $key);
}
return $resource;
}
}

View File

@ -0,0 +1,30 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class AgreementResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'name' => $this->name,
'images' => $this->images,
'employee_id' => $this->employee_id,
'employee' => EmployeeResource::make($this->whenLoaded('employee')),
'workflow_check' => WorkflowCheckResource::make($this->whenLoaded('workflow')),
'created_at' => $this->created_at->timestamp,
];
}
}

View File

@ -0,0 +1,38 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class EmployeePromotionResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'employee_id' => $this->employee_id,
'employee' => EmployeeResource::make($this->whenLoaded('employee')),
'store_id' => $this->store_id,
'store' => StoreResource::make($this->whenLoaded('store')),
'invitor_id' => $this->invitor_id,
'invitor' => EmployeeResource::make($this->whenLoaded('invitor')),
'job_id' => $this->job_id,
'job' => KeywordResource::make($this->whenLoaded('job')),
'promotion_status' => $this->promotion_status,
'promotion_status_text' => $this->promotion_status->text(),
'employee_data' => $this->employee_data,
'created_at' => $this->created_at->timestamp,
'workflow_check' => WorkflowCheckResource::make($this->whenLoaded('workflow')),
];
}
}

View File

@ -0,0 +1,35 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class OfficalBusinessResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'employee_id' => $this->employee_id,
'employee' => EmployeeResource::make($this->whenLoaded('employee')),
'store_id' => $this->store_id,
'store' => StoreResource::make($this->whenLoaded('store')),
'workflow_check' => WorkflowCheckResource::make($this->whenLoaded('workflow')),
'start_at' => $this->start_at->timestamp,
'end_at' => $this->end_at->timestamp,
'address' => $this->address,
'reason' => $this->reason,
'created_at' => $this->created_at->timestamp,
];
}
}

View File

@ -0,0 +1,36 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class OvertimeApplyResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'employee_id' => $this->employee_id,
'employee' => EmployeeResource::make($this->whenLoaded('employee')),
'store_id' => $this->store_id,
'store' => StoreResource::make($this->whenLoaded('store')),
'workflow_check' => WorkflowCheckResource::make($this->whenLoaded('workflow')),
'date' => $this->date->timestamp,
'start_at' => $this->start_at->timestamp,
'end_at' => $this->end_at->timestamp,
'hours' => $this->hours,
'reason' => $this->reason,
'created_at' => $this->created_at->timestamp,
];
}
}

View File

@ -7,6 +7,7 @@ use App\Traits\HasCheckable;
use App\Traits\HasDateTimeFormatter;
use EloquentFilter\Filterable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Casts\Attribute;
/**
* 员工升职申请
@ -22,11 +23,38 @@ class EmployeePromotion extends Model
'employee_data' => 'json',
];
protected $appends = ['can_update'];
public function modelFilter()
{
return \App\Admin\Filters\EmployeePromotionFilter::class;
}
public function checkSuccess()
{
$this->update(['promotion_status' => PromotionStatus::Success]);
}
public function checkFail()
{
$this->update(['promotion_status' => PromotionStatus::Fail]);
}
public function checkCancel()
{
$this->update(['promotion_status' => PromotionStatus::Employee]);
}
public function canUpdate(): bool
{
return in_array($this->promotion_status, [PromotionStatus::Employee, PromotionStatus::Invitor, PromotionStatus::Fail]);
}
public function getCanUpdateAttribute()
{
return $this->canUpdate();
}
public function store()
{
return $this->belongsTo(Store::class, 'store_id');

View File

@ -19,8 +19,8 @@ class OfficalBusiness extends Model
protected $fillable = ['store_id', 'employee_id', 'start_at', 'end_at', 'address', 'reason'];
protected $casts = [
'start_at' => 'date:Y-m-d',
'end_at' => 'date:Y-m-d',
'start_at' => 'date:Y-m-d H:i',
'end_at' => 'date:Y-m-d H:i',
];
public function modelFilter()

View File

@ -3,8 +3,7 @@
namespace App\Models;
use App\Enums\{CheckStatus};
use App\Traits\HasCheckable;
use App\Traits\HasDateTimeFormatter;
use App\Traits\{HasCheckable, HasDateTimeFormatter};
use EloquentFilter\Filterable;
use Illuminate\Database\Eloquent\Model;
@ -19,8 +18,8 @@ class OvertimeApply extends Model
protected $casts = [
'date' => 'date:Y-m-d',
'start_at' => 'datetime',
'end_at' => 'datetime',
'start_at' => 'datetime:H:i',
'end_at' => 'datetime:H:i',
];
public function modelFilter()

View File

@ -4,6 +4,7 @@ namespace App\Traits;
use App\Models\WorkflowCheck;
use Illuminate\Support\Str;
use App\Enums\CheckStatus;
trait HasCheckable
{
@ -38,6 +39,21 @@ trait HasCheckable
}
public function checkFail()
{
}
public function checkCancel()
{
}
public function canUpdate(): bool
{
return in_array($this->workflow?->check_status, [CheckStatus::None, CheckStatus::Fail, CheckStatus::Cancel]);
}
/**
* 关联审核流水
*/

View File

@ -69,9 +69,26 @@ Route::group([
// 请假管理
Route::apiResource('hr/holidays', \App\Http\Controllers\Api\Hr\HolidayController::class);
// 加班申请
Route::apiResource('hr/overtimes', \App\Http\Controllers\Api\Hr\OvertimeController::class);
// 出差报备
Route::apiResource('hr/offical-bussiness', \App\Http\Controllers\Api\Hr\OfficalBusinessController::class);
// 升职申请
Route::get('hr/promotion/apply', [\App\Http\Controllers\Api\Hr\PromotionController::class, 'applyList']);
Route::get('hr/promotion/invite', [\App\Http\Controllers\Api\Hr\PromotionController::class, 'inviteList']);
Route::get('hr/promotion/{id}', [\App\Http\Controllers\Api\Hr\PromotionController::class, 'show']);
Route::post('hr/promotion/{id}/apply', [\App\Http\Controllers\Api\Hr\PromotionController::class, 'applyUpdate']);
Route::post('hr/promotion/{id}/invite', [\App\Http\Controllers\Api\Hr\PromotionController::class, 'inviteUpdate']);
Route::delete('hr/promotion/{id}', [\App\Http\Controllers\Api\Hr\PromotionController::class, 'destroy']);
// 报销管理
Route::apiResource('reimbursements', \App\Http\Controllers\Api\ReimbursementController::class);
// 合同管理
Route::apiResource('agreements', \App\Http\Controllers\Api\AgreementController::class);
// 审核流程
Route::get('workflow', [\App\Http\Controllers\Api\WorkflowController::class, 'index']);
Route::get('workflow/{id}', [\App\Http\Controllers\Api\WorkflowController::class, 'show']);