allocatr/application/admin/controller/salary/Detail.php
2025-05-28 17:30:03 +08:00

85 lines
2.1 KiB
PHP

<?php
namespace app\admin\controller\salary;
use app\common\controller\Backend;
use think\Db;
use think\exception\PDOException;
use think\exception\ValidateException;
/**
* 工资详情
*
* @icon fa fa-circle-o
*/
class Detail extends Backend
{
/**
* Detail模型对象
* @var \app\admin\model\salary\Detail
*/
protected $model = null;
public function _initialize()
{
parent::_initialize();
$this->model = new \app\admin\model\salary\Detail;
}
/**
* 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
*/
public function custom_add()
{
if (false === $this->request->isPost()) {
$items = Db::name('salary_item')->field('id,name')->select();
$this->view->assign('items', $items);
return $this->view->fetch();
}
$params = $this->request->post('row/a');
if (empty($params)) {
$this->error(__('Parameter %s can not be empty', ''));
}
$month = $params['salary_month'] . '-01';
$targetAdminId = $params['target_admin_id'];
$salaryDetails = [];
foreach ($params as $k => $v) {
if (!str_contains($k, 'item')) {
continue;
}
$salaryDetails[] = [
'target_admin_id' => $targetAdminId,
'salary_month' => $month,
'item_id' => explode('_', $k)[1],
'item_value' => $v,
];
}
Db::name('salary_detail')
->where('salary_month', $month)
->where('target_admin_id', $targetAdminId)
->delete();
Db::name('salary_detail')
->insertAll($salaryDetails);
$this->success();
}
}