allocatr/application/admin/controller/salary/Detail.php
2025-06-04 09:29:26 +08:00

90 lines
2.2 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 calc_total($total, $type, $value){
if ($type == 1) {
return $total + $value;
}
if ($type == 2) {
return $total - $value;
}
return $total;
}
public function clean_number($num): string {
return rtrim(rtrim(number_format($num, 10, '.', ''), '0'), '.');
}
public function settle()
{
if (false === $this->request->isPost()) {
$this->error(__("Invalid parameters"));
}
$targetAdminId = $this->request->get('target_admin_id');
$month = $this->request->get('month');
$settle = Db::name('salary_settle')
->where('salary_month', $month)
->where('target_admin_id', $targetAdminId)
->field('target_admin_id,salary_month')->find();
if (!empty($settle)) {
Db::name('salary_settle')
->where('salary_month', $month)
->where('target_admin_id', $targetAdminId)
->save([
'settle_status' => 1,
]);
$this->success();
}
Db::name('salary_settle')->insert([
'target_admin_id' => $targetAdminId,
'salary_month' => $month,
'settle_status' => 1,
]);
$this->success();
}
}