generated from liutk/owl-admin-base
店长提成审核
parent
0c90525765
commit
1b993b3f76
|
|
@ -108,6 +108,14 @@ abstract class AdminController extends Controller
|
|||
|
||||
protected function prepareException(Throwable $e)
|
||||
{
|
||||
if ($e instanceof ValidationException) {
|
||||
$message = Arr::first($e->errors());
|
||||
if (is_array($message)) {
|
||||
$message = Arr::first($message);
|
||||
}
|
||||
$e = new AdminException($message ?: '参数错误');
|
||||
}
|
||||
|
||||
return $e;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ namespace App\Admin\Controllers\Finance;
|
|||
|
||||
use App\Admin\Controllers\AdminController;
|
||||
use App\Admin\Services\Finance\StoreMasterCommissionService;
|
||||
use App\Enums\CheckStatus;
|
||||
use App\Traits\HasCheckActions;
|
||||
use Slowlyo\OwlAdmin\Admin;
|
||||
use Slowlyo\OwlAdmin\Renderers\Form;
|
||||
use Slowlyo\OwlAdmin\Renderers\Page;
|
||||
|
|
@ -13,6 +15,8 @@ use Slowlyo\OwlAdmin\Renderers\Page;
|
|||
*/
|
||||
class StoreMasterCommissionController extends AdminController
|
||||
{
|
||||
use HasCheckActions;
|
||||
|
||||
protected string $serviceName = StoreMasterCommissionService::class;
|
||||
|
||||
public function list(): Page
|
||||
|
|
@ -40,20 +44,36 @@ class StoreMasterCommissionController extends AdminController
|
|||
]),
|
||||
]))
|
||||
->columns([
|
||||
amis()->TableColumn()->name('id')->label(__('finance.store_master_commission.id')),
|
||||
amis()->TableColumn()->name('month')->label(__('finance.store_master_commission.month')),
|
||||
amis()->TableColumn()->name('store.title')->label(__('finance.store_master_commission.store')),
|
||||
amis()->TableColumn()->name('master.name')->label(__('finance.store_master_commission.store_master')),
|
||||
amis()->TableColumn()->name('commission')->label(__('finance.store_master_commission.commission')),
|
||||
amis()->TableColumn()->name('daily_expenses')->label(__('finance.store_master_commission.daily_expenses')),
|
||||
amis()->TableColumn()->name('employee_expenses')->label(__('finance.store_master_commission.employee_expenses')),
|
||||
amis()->TableColumn()->name('other_expenses')->label(__('finance.store_master_commission.other_expenses')),
|
||||
amis()->TableColumn()->name('created_at')->label(__('finance.store_master_commission.created_at')),
|
||||
amis()->TableColumn('id', __('finance.store_master_commission.id')),
|
||||
amis()->TableColumn('month', __('finance.store_master_commission.month')),
|
||||
amis()->TableColumn('store.title', __('finance.store_master_commission.store')),
|
||||
amis()->TableColumn('master.name', __('finance.store_master_commission.store_master')),
|
||||
amis()->TableColumn('commission', __('finance.store_master_commission.commission')),
|
||||
amis()->TableColumn('daily_expenses', __('finance.store_master_commission.daily_expenses')),
|
||||
amis()->TableColumn('employee_expenses', __('finance.store_master_commission.employee_expenses')),
|
||||
amis()->TableColumn('other_expenses', __('finance.store_master_commission.other_expenses')),
|
||||
amis()->TableColumn('workflow.check_status', __('workflow_log.check_status'))->set('type', 'mapping')->map(CheckStatus::labelMap()),
|
||||
amis()->TableColumn('created_at', __('finance.store_master_commission.created_at')),
|
||||
$this->rowActions([
|
||||
$this->applyAction()
|
||||
->api(
|
||||
amis()->BaseApi()
|
||||
->url(admin_url('api/workflow/apply'))
|
||||
->method('post')
|
||||
->data(['id' => '${workflow.id}'])
|
||||
),
|
||||
$this->succesAction(),
|
||||
$this->failAction(),
|
||||
$this->cancelAction(),
|
||||
$this->rowEditTypeButton('drawer', 'lg')
|
||||
->visible(Admin::user()->can('admin.finance.store_master_commissions.update')),
|
||||
->visible(Admin::user()->can('admin.finance.store_master_commissions.update'))
|
||||
->visibleOn('${OR(workflow.check_status == '.CheckStatus::None->value.', workflow.check_status == '.CheckStatus::Cancel->value.', workflow.check_status == '.CheckStatus::Fail->value.')}'),
|
||||
$this->rowShowButton()
|
||||
->visible(Admin::user()->can('admin.finance.store_master_commissions.view')),
|
||||
$this->rowDeleteButton()
|
||||
->visible(Admin::user()->can('admin.finance.store_master_commissions.delete')),
|
||||
->visible(Admin::user()->can('admin.finance.store_master_commissions.delete'))
|
||||
->visibleOn('${OR(workflow.check_status == '.CheckStatus::None->value.', workflow.check_status == '.CheckStatus::Cancel->value.', workflow.check_status == '.CheckStatus::Fail->value.')}'),
|
||||
|
||||
]),
|
||||
]);
|
||||
|
||||
|
|
@ -105,4 +125,45 @@ class StoreMasterCommissionController extends AdminController
|
|||
->required(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function detail(): Form
|
||||
{
|
||||
$detail = amis()->Property()->items([
|
||||
['label' => __('finance.store_master_commission.month'), 'content' => '${month}'],
|
||||
['label' => __('finance.store_master_commission.store'), 'content' => '${store.title}'],
|
||||
['label' => __('finance.store_master_commission.store_master'), 'content' => '${master.name}'],
|
||||
['label' => __('finance.store_master_commission.commission'), 'content' => '${commission}'],
|
||||
['label' => __('finance.store_master_commission.daily_expenses'), 'content' => '${daily_expenses}'],
|
||||
['label' => __('finance.store_master_commission.employee_expenses'), 'content' => '${employee_expenses}'],
|
||||
['label' => __('finance.store_master_commission.other_expenses'), 'content' => '${other_expenses}'],
|
||||
['label' => __('finance.store_master_commission.created_at'), 'content' => '${created_at}'],
|
||||
['label' => __('workflow_log.check_status'), 'content' => amis()->Mapping()->name('workflow.check_status')->map(CheckStatus::labelMap())],
|
||||
['label' => __('workflow_log.checked_at'), 'content' => '${workflow.checked_at}'],
|
||||
['label' => __('workflow_log.remarks'), 'content' => '${workflow.check_remarks}', 'span' => 2],
|
||||
]);
|
||||
$table = amis()->Service()
|
||||
->id('offical-business-checklog-table')
|
||||
->initFetch(false)
|
||||
->api(admin_url('api/workflow/logs?id=${workflow.id}'))
|
||||
->body(
|
||||
amis()->Table()->columnsTogglable(false)->itemActions([
|
||||
$this->succesAction()->reload('offical-business-detail'),
|
||||
$this->failAction()->reload('offical-business-detail'),
|
||||
])->columns([
|
||||
amis()->TableColumn()->name('batch_id')->label(__('workflow_log.batch_id')),
|
||||
amis()->TableColumn()->name('check_name')->label(__('workflow_log.check_name')),
|
||||
amis()->TableColumn()->name('check_user.name')->label(__('workflow_log.check_user_id')),
|
||||
amis()->TableColumn()->name('check_status')->label(__('workflow_log.check_status'))->set('type', 'mapping')->map(CheckStatus::options()),
|
||||
amis()->TableColumn()->name('checked_at')->label(__('workflow_log.checked_at')),
|
||||
amis()->TableColumn()->name('remarks')->label(__('workflow_log.remarks')),
|
||||
])
|
||||
);
|
||||
return $this->baseDetail()->id('offical-business-detail')->title('')->onEvent([
|
||||
'inited' => [
|
||||
'actions' => [
|
||||
['actionType' => 'reload', 'componentId' => 'offical-business-checklog-table'],
|
||||
]
|
||||
]
|
||||
])->body([$detail, amis()->Divider(), $table]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,8 @@ use Illuminate\Database\Eloquent\Relations\Relation;
|
|||
|
||||
/**
|
||||
* 审核流程管理
|
||||
*
|
||||
* @property WorkFlowService $service
|
||||
*/
|
||||
class WorkflowController extends AdminController
|
||||
{
|
||||
|
|
@ -93,11 +95,22 @@ class WorkflowController extends AdminController
|
|||
public function apply(Request $request)
|
||||
{
|
||||
$model = WorkflowCheck::findOrFail($request->input('id'));
|
||||
$user = Employee::findOrFail($request->input('user'));
|
||||
|
||||
$employee = $request->whenFilled('user', function ($id) {
|
||||
if ($employee = Employee::find($id)) {
|
||||
return $employee;
|
||||
}
|
||||
admin_abort('员工未找到');
|
||||
}, function () {
|
||||
if ($employee = Employee::where('admin_user_id', Admin::user()->id)->first()) {
|
||||
return $employee;
|
||||
}
|
||||
admin_abort('当前登录账户未关联员工');
|
||||
});
|
||||
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
if (!$this->service->apply($model, $user)) {
|
||||
if (!$this->service->apply($model, $employee)) {
|
||||
return $this->response()->fail($this->service->getError());
|
||||
}
|
||||
DB::commit();
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ use Illuminate\Support\Facades\Validator;
|
|||
|
||||
class StoreMasterCommissionService extends BaseService
|
||||
{
|
||||
protected array $withRelationships = ['store', 'master'];
|
||||
protected array $withRelationships = ['store', 'master', 'workflow'];
|
||||
|
||||
protected string $modelName = StoreMasterCommission::class;
|
||||
|
||||
|
|
@ -18,7 +18,7 @@ class StoreMasterCommissionService extends BaseService
|
|||
|
||||
public function store($data): bool
|
||||
{
|
||||
$validator = Validator::make(
|
||||
Validator::validate(
|
||||
data: $data,
|
||||
rules: [
|
||||
'month' => ['bail', 'required', 'date_format:Y-m'],
|
||||
|
|
@ -38,13 +38,11 @@ class StoreMasterCommissionService extends BaseService
|
|||
],
|
||||
);
|
||||
|
||||
admin_abort_if($validator->fails(), $validator->errors()->first());
|
||||
$store = Store::findOrFail($data['store_id']);
|
||||
|
||||
$attributes = $validator->validated();
|
||||
|
||||
$store = Store::findOrFail($attributes['store_id']);
|
||||
|
||||
$attributes['store_master_id'] = $store->master_id;
|
||||
$attributes = array_merge($data, [
|
||||
'store_master_id' => $store->master_id,
|
||||
]);
|
||||
|
||||
$this->modelName::create($attributes);
|
||||
|
||||
|
|
@ -53,7 +51,7 @@ class StoreMasterCommissionService extends BaseService
|
|||
|
||||
public function update($primaryKey, $data): bool
|
||||
{
|
||||
$validator = Validator::make(
|
||||
Validator::validate(
|
||||
data: $data,
|
||||
rules: [
|
||||
'month' => ['filled', 'required', 'date_format:Y-m'],
|
||||
|
|
@ -73,19 +71,38 @@ class StoreMasterCommissionService extends BaseService
|
|||
],
|
||||
);
|
||||
|
||||
admin_abort_if($validator->fails(), $validator->errors()->first());
|
||||
|
||||
$attributes = $validator->validated();
|
||||
|
||||
$model = $this->query()->whereKey($primaryKey)->firstOrFail();
|
||||
|
||||
// 如果门店发生改变,则更新店长
|
||||
if ($model->store_id != $attributes['store_id']) {
|
||||
$store = Store::findOrFail($attributes['store_id']);
|
||||
$attributes['store_master_id'] = $store->master_id;
|
||||
foreach ([
|
||||
'month',
|
||||
'store_id',
|
||||
'commission',
|
||||
'daily_expenses',
|
||||
'employee_expenses',
|
||||
'other_expenses',
|
||||
] as $attribute) {
|
||||
if (! array_key_exists($attribute, $data)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
switch ($attribute) {
|
||||
case 'store_id':
|
||||
if ($model->store_id != $data['store_id']) {
|
||||
$store = Store::findOrFail($data['store_id']);
|
||||
$model->store_id = $store->id;
|
||||
$model->store_master_id = $store->master_id;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
$model->{$attribute} = $data[$attribute];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $model->update($attributes);
|
||||
$model->save();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function sortColumn()
|
||||
|
|
|
|||
|
|
@ -123,7 +123,6 @@ Route::group([
|
|||
], function (Router $router) {
|
||||
// 上报数据
|
||||
$router->resource('ledgers', LedgerController::class);
|
||||
$router->post('ledgers/{ledger}/approval', [LedgerController::class, 'approval'])->name('ledgers.approval');
|
||||
$router->post('ledgers/{ledger}/ledger-amount', [LedgerController::class, 'updateLedgerAmount'])->name('ledgers.update_ledger_amount');
|
||||
// 佣金收入
|
||||
$router->get('commission-incomes', [CommissionIncomeController::class, 'index'])->name('commission_incomes.index');
|
||||
|
|
@ -135,7 +134,6 @@ Route::group([
|
|||
$router->get('store-statistics', [StoreStatisticController::class, 'index'])->name('store_statistics.index');
|
||||
// 店长提成
|
||||
$router->resource('store-master-commissions', StoreMasterCommissionController::class);
|
||||
$router->post('store-master-commissions/{store_master_commission}/approval', [StoreMasterCommissionController::class, 'approval'])->name('store_statistics.approval');
|
||||
});
|
||||
|
||||
/*
|
||||
|
|
|
|||
|
|
@ -33,12 +33,23 @@ enum CheckStatus: int
|
|||
return [
|
||||
self::None->value => '待提审',
|
||||
self::Processing->value => '审核中',
|
||||
self::Success->value => '审核通过',
|
||||
self::Fail->value => '审核不通过',
|
||||
self::Success->value => '已通过',
|
||||
self::Fail->value => '已拒绝',
|
||||
self::Cancel->value => '已取消',
|
||||
];
|
||||
}
|
||||
|
||||
public static function labelMap(): array
|
||||
{
|
||||
return [
|
||||
self::None->value => '<span class="label label-default">'.self::None->text().'</span>',
|
||||
self::Processing->value => '<span class="label label-primary">'.self::Processing->text().'</span>',
|
||||
self::Success->value => '<span class="label label-success">'.self::Success->text().'</span>',
|
||||
self::Fail->value => '<span class="label label-danger">'.self::Fail->text().'</span>',
|
||||
self::Cancel->value => '<span class="label bg-gray-400">'.self::Cancel->text().'</span>',
|
||||
];
|
||||
}
|
||||
|
||||
public function text()
|
||||
{
|
||||
return data_get(self::options(), $this->value);
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
namespace App\Models;
|
||||
|
||||
use App\Enums\StoreMasterCommissionApprovalStatus;
|
||||
use App\Traits\HasCheckable;
|
||||
use App\Traits\HasDateTimeFormatter;
|
||||
use EloquentFilter\Filterable;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
|
|
@ -11,7 +12,7 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|||
|
||||
class StoreMasterCommission extends Model
|
||||
{
|
||||
use Filterable, HasDateTimeFormatter, HasFactory;
|
||||
use Filterable, HasDateTimeFormatter, HasFactory, HasCheckable;
|
||||
|
||||
protected $fillable = [
|
||||
'month',
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ class AppServiceProvider extends ServiceProvider
|
|||
\App\Models\OvertimeApply::class,
|
||||
\App\Models\OfficalBusiness::class,
|
||||
\App\Models\Reimbursement::class,
|
||||
\App\Models\StoreMasterCommission::class,
|
||||
])->mapWithKeys(fn ($model) => [(new $model)->getTable() => $model])->all()
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ trait HasCheckActions
|
|||
->level('link')
|
||||
->api('post:' . admin_url('api/workflow/success?id=${id}'))
|
||||
->confirmText(__('admin.confirm'))
|
||||
->visibleOn('${check_status == '.CheckStatus::Processing->value.'}');
|
||||
->visibleOn('${workflow.check_status == '.CheckStatus::Processing->value.'}');
|
||||
}
|
||||
|
||||
public function failAction()
|
||||
|
|
@ -57,6 +57,6 @@ trait HasCheckActions
|
|||
amisMake()->TextControl()->name('remarks')->label(__('workflow_log.remarks'))->required(),
|
||||
])
|
||||
))
|
||||
->visibleOn('${check_status == '.CheckStatus::Processing->value.'}');
|
||||
->visibleOn('${workflow.check_status == '.CheckStatus::Processing->value.'}');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -236,7 +236,7 @@ class AdminPermissionSeeder extends Seeder
|
|||
'name' => '店长提成',
|
||||
'icon' => 'icon-park-outline:paper-money',
|
||||
'uri' => '/finance/store-master-commissions',
|
||||
'resource' => ['list', 'create', 'update', 'delete'],
|
||||
'resource' => true,
|
||||
'children' => [],
|
||||
],
|
||||
],
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ class WorkflowSeeder extends Seeder
|
|||
['key' => 'overtime_apply', 'name' => '加班申请', 'config' => $config, 'created_at' => now(), 'updated_at' => now()],
|
||||
['key' => 'offical_business', '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()],
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue