generated from liutk/owl-admin-base
54 lines
1.4 KiB
PHP
54 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Admin\Services\Finance;
|
|
|
|
use App\Admin\Filters\LedgerFilter;
|
|
use App\Admin\Services\BaseService;
|
|
use App\Enums\CheckStatus;
|
|
use App\Models\Ledger;
|
|
use Illuminate\Support\Facades\Validator;
|
|
|
|
class LedgerService extends BaseService
|
|
{
|
|
protected string $modelName = Ledger::class;
|
|
|
|
protected string $modelFilterName = LedgerFilter::class;
|
|
|
|
protected array $withRelationships = ['store', 'workflow'];
|
|
|
|
public function update($primaryKey, $data): bool
|
|
{
|
|
Validator::validate(
|
|
data: $data,
|
|
rules: [
|
|
'actual_commission' => ['filled', 'numeric'],
|
|
'actual_income' => ['filled', 'numeric'],
|
|
],
|
|
attributes: [
|
|
'actual_commission' => __('finance.ledger.actual_commission'),
|
|
'actual_income' => __('finance.ledger.actual_income'),
|
|
],
|
|
);
|
|
|
|
$model = $this->query()->whereKey($primaryKey)->firstOrFail();
|
|
|
|
switch ($model->workflow->check_status) {
|
|
case CheckStatus::Processing:
|
|
admin_abort('不能修改审核中的上报数据');
|
|
break;
|
|
case CheckStatus::Success:
|
|
admin_abort('不能修改审核通过的报数据');
|
|
break;
|
|
}
|
|
|
|
$model->update($data);
|
|
|
|
return true;
|
|
}
|
|
|
|
public function sortColumn()
|
|
{
|
|
return 'id';
|
|
}
|
|
}
|