This commit is contained in:
weiz 2024-03-25 16:16:12 +08:00
parent 364c491a98
commit 09df951406
6 changed files with 281 additions and 291 deletions

View File

@ -12,81 +12,81 @@
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\lists\project;
namespace app\adminapi\lists\project;
use app\adminapi\lists\BaseAdminDataLists;
use app\common\model\project\Project;
use app\common\model\project\ProjectAttendanceDetail;
use app\common\model\project\ProjectAttendanceRecord;
use app\common\lists\ListsSearchInterface;
use app\adminapi\lists\BaseAdminDataLists;
use app\common\lists\ListsSearchInterface;
use app\common\model\project\Project;
use app\common\model\project\ProjectAttendanceDetail;
use app\common\model\project\ProjectAttendanceRecord;
/**
* 考勤记录列表
* Class ProjectAttendanceRecordLists
* @package app\adminapi\listsproject
*/
class ProjectAttendanceRecordLists extends BaseAdminDataLists implements ListsSearchInterface
{
/**
* 考勤记录列表
* Class ProjectAttendanceRecordLists
* @package app\adminapi\listsproject
*/
class ProjectAttendanceRecordLists extends BaseAdminDataLists implements ListsSearchInterface
{
/**
* @notes 设置搜索条件
* @return \string[][]
* @author likeadmin
* @date 2023/12/26 09:44
*/
public function setSearch(): array
{
return [
'=' => ['attendance_date','project_id'],
];
}
/**
* @notes 设置搜索条件
* @return \string[][]
* @author likeadmin
* @date 2023/12/26 09:44
*/
public function setSearch(): array
{
return [
'=' => ['attendance_date', 'project_id'],
];
}
/**
* @notes 获取考勤记录列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author likeadmin
* @date 2023/12/26 09:44
*/
public function lists(): array
{
return ProjectAttendanceRecord::where($this->searchWhere)
->field(['id','attendance_code','project_id', 'attendance_date','remark', 'file'])
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()->each(function($item){
//'work_record_num', 'daily_salary', 'daily_living', 'daily_subsidy', 'daily_other', 'daily_income',
$project = Project::field('name,project_code')->where('id',$item['project_id'])->findOrEmpty();
$item['project_name'] = $project['name'];
$item['project_code'] = $project['project_code'];
$item['work_record_num_total'] = ProjectAttendanceDetail::where('attendance_id',$item['id'])->sum('work_record_num');
$item['daily_salary_total'] = ProjectAttendanceDetail::where('attendance_id',$item['id'])->sum('daily_salary');
$item['daily_living_total'] = ProjectAttendanceDetail::where('attendance_id',$item['id'])->sum('daily_living');
$item['daily_subsidy_total'] = ProjectAttendanceDetail::where('attendance_id',$item['id'])->sum('daily_subsidy');
$item['daily_other_total'] = ProjectAttendanceDetail::where('attendance_id',$item['id'])->sum('daily_other');
$item['daily_income_total'] = ProjectAttendanceDetail::where('attendance_id',$item['id'])->sum('daily_income');
$item['cqrs'] = ProjectAttendanceDetail::where('attendance_id',$item['id'])->count();
return $item;
})
->toArray();
}
/**
* @notes 获取考勤记录列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author likeadmin
* @date 2023/12/26 09:44
*/
public function lists(): array
{
return ProjectAttendanceRecord::where($this->searchWhere)
->field(['id', 'attendance_code', 'project_id', 'attendance_date', 'remark'])
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()->each(function ($item) {
//'work_record_num', 'daily_salary', 'daily_living', 'daily_subsidy', 'daily_other', 'daily_income',
$project = Project::field('name,project_code')->where('id', $item['project_id'])->findOrEmpty();
$item['project_name'] = $project['name'];
$item['project_code'] = $project['project_code'];
$item['work_record_num_total'] = ProjectAttendanceDetail::where('attendance_id', $item['id'])->sum('work_record_num');
$item['daily_salary_total'] = ProjectAttendanceDetail::where('attendance_id', $item['id'])->sum('daily_salary');
$item['daily_living_total'] = ProjectAttendanceDetail::where('attendance_id', $item['id'])->sum('daily_living');
$item['daily_subsidy_total'] = ProjectAttendanceDetail::where('attendance_id', $item['id'])->sum('daily_subsidy');
$item['daily_other_total'] = ProjectAttendanceDetail::where('attendance_id', $item['id'])->sum('daily_other');
$item['daily_income_total'] = ProjectAttendanceDetail::where('attendance_id', $item['id'])->sum('daily_income');
$item['cqrs'] = ProjectAttendanceDetail::where('attendance_id', $item['id'])->count();
return $item;
})
->toArray();
}
/**
* @notes 获取考勤记录数量
* @return int
* @author likeadmin
* @date 2023/12/26 09:44
*/
public function count(): int
{
return ProjectAttendanceRecord::where($this->searchWhere)->count();
}
/**
* @notes 获取考勤记录数量
* @return int
* @author likeadmin
* @date 2023/12/26 09:44
*/
public function count(): int
{
return ProjectAttendanceRecord::where($this->searchWhere)->count();
}
}
}

View File

@ -12,145 +12,146 @@
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\logic\project;
namespace app\adminapi\logic\project;
use app\common\model\project\Project;
use app\common\model\project\ProjectAttendanceDetail;
use app\common\model\project\ProjectAttendanceRecord;
use app\common\logic\BaseLogic;
use app\common\model\project\ProjectPersonnel;
use think\facade\Db;
use app\common\logic\BaseLogic;
use app\common\model\project\Project;
use app\common\model\project\ProjectAttendanceDetail;
use app\common\model\project\ProjectAttendanceRecord;
use app\common\model\project\ProjectPersonnel;
use think\facade\Db;
/**
* 考勤记录逻辑
* Class ProjectAttendanceRecordLogic
* @package app\adminapi\logic\project
*/
class ProjectAttendanceRecordLogic extends BaseLogic
{
/**
* 考勤记录逻辑
* Class ProjectAttendanceRecordLogic
* @package app\adminapi\logic\project
*/
class ProjectAttendanceRecordLogic extends BaseLogic
{
/**
* @notes 添加考勤记录
* @param array $params
* @return bool
* @author likeadmin
* @date 2023/12/26 09:44
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
$attendance_detail = $params['attendance_detail'];//json_decode($params['attendance_detail'],true);
$attendance_code = data_unique_code('项目考勤记录');
$ProjectAttendanceRecordRes = ProjectAttendanceRecord::create([
'project_id' => $params['project_id'],
'attendance_code' => $attendance_code,
'attendance_date' => strtotime($params['attendance_date']),
'remark' => $params['remark'],
'file' => $params['file']? json_encode($params['file']) : null,
]);
foreach($attendance_detail as $v){
ProjectAttendanceDetail::create([
'attendance_code' => $attendance_code,
'attendance_id' => $ProjectAttendanceRecordRes->id,
'project_id' => $params['project_id'],
'person_id' => $v['person_id'],
'attendance_date' => strtotime($params['attendance_date']),
'work_start_time' => strtotime($v['work_start_time']),
'work_end_time' => strtotime($v['work_end_time']),
'work_record_num' => $v['work_record_num'],
'daily_salary' => $v['daily_salary'],
'daily_living' => $v['daily_living'],
'daily_subsidy' => $v['daily_subsidy'],
'daily_other' => $v['daily_other'],
'daily_income' => $v['daily_income'],
'remark' => $v['work_num']??'',
]);
}
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 添加考勤记录
* @param array $params
* @return bool
* @author likeadmin
* @date 2023/12/26 09:44
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
$attendance_code = data_unique_code('项目考勤记录');
$ProjectAttendanceRecordRes = ProjectAttendanceRecord::create([
'project_id' => $params['project_id'],
'attendance_code' => $attendance_code,
'attendance_date' => strtotime($params['attendance_date']),
'remark' => $params['remark'],
'annex' => $params['annex'] ? json_encode($params['annex']) : null,
]);
foreach ($params['attendance_detail'] as $v) {
ProjectAttendanceDetail::create([
'attendance_code' => $attendance_code,
'attendance_id' => $ProjectAttendanceRecordRes->id,
'project_id' => $params['project_id'],
'person_id' => $v['person_id'],
'attendance_date' => strtotime($params['attendance_date']),
'work_start_time' => strtotime($v['work_start_time']),
'work_end_time' => strtotime($v['work_end_time']),
'work_record_num' => $v['work_record_num'],
'daily_salary' => $v['daily_salary'],
'daily_living' => $v['daily_living'],
'daily_subsidy' => $v['daily_subsidy'],
'daily_other' => $v['daily_other'],
'daily_income' => $v['daily_income'],
'remark' => $v['work_num'] ?? '',
]);
}
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 编辑考勤记录
* @param array $params
* @return bool
* @author likeadmin
* @date 2023/12/26 09:44
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
ProjectAttendanceRecord::where('id', $params['id'])->update([
'attendance_date' => strtotime($params['attendance_date']),
'remark' => $params['remark'],
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 编辑考勤记录
* @param array $params
* @return bool
* @author likeadmin
* @date 2023/12/26 09:44
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
ProjectAttendanceRecord::where('id', $params['id'])->update([
'project_id' => $params['project_id'],
'attendance_date' => strtotime($params['attendance_date']),
'remark' => $params['remark'],
'annex' => $params['annex'] ? json_encode($params['annex']) : null,
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 删除考勤记录
* @param array $params
* @return bool
* @author likeadmin
* @date 2023/12/26 09:44
*/
public static function delete(array $params): bool
{
Db::startTrans();
try {
$detailIds = ProjectAttendanceDetail::where('attendance_id',$params['id'])->column('id');
ProjectAttendanceDetail::destroy($detailIds);
ProjectAttendanceRecord::destroy($params['id']);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 删除考勤记录
* @param array $params
* @return bool
* @author likeadmin
* @date 2023/12/26 09:44
*/
public static function delete(array $params): bool
{
Db::startTrans();
try {
$detailIds = ProjectAttendanceDetail::where('attendance_id', $params['id'])->column('id');
ProjectAttendanceDetail::destroy($detailIds);
ProjectAttendanceRecord::destroy($params['id']);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 获取考勤记录详情
* @param $params
* @return array
* @author likeadmin
* @date 2023/12/26 09:44
*/
public static function detail($params): array
{
$data = ProjectAttendanceRecord::field(['id','attendance_code','project_id', 'attendance_date','remark', 'file'])->findOrEmpty($params['id'])->toArray();
$project = Project::field('name,project_code')->where('id',$data['project_id'])->findOrEmpty();
$data['project_name'] = $project['name'];
$data['project_code'] = $project['project_code'];
$data['attendance_num'] = ProjectAttendanceDetail::field('id')->where('attendance_id',$data['id'])->count();
$data['attendance_detail'] = ProjectAttendanceDetail::field(['id', 'person_id', 'work_start_time', 'work_end_time', 'work_record_num', 'daily_salary', 'daily_living', 'daily_subsidy', 'daily_other', 'daily_income', 'remark'])->where('attendance_id',$data['id'])
->select()->each(function($item){
$person = ProjectPersonnel::field('name,idcard,work_type')->where('id',$item['person_id'])->findOrEmpty();
$item['name'] = $person['name'];
$item['idcard'] = $person['idcard'];
$item['work_type_text'] = $person->work_type_text;
return $item;
})
->toArray();
return $data;
}
}
/**
* @notes 获取考勤记录详情
* @param $params
* @return array
* @author likeadmin
* @date 2023/12/26 09:44
*/
public static function detail($params): array
{
$data = ProjectAttendanceRecord::field(['id', 'attendance_code', 'project_id', 'attendance_date', 'remark', 'annex'])->findOrEmpty($params['id'])->toArray();
$project = Project::field('name,project_code')->where('id', $data['project_id'])->findOrEmpty();
$data['project_name'] = $project['name'];
$data['project_code'] = $project['project_code'];
$data['attendance_num'] = ProjectAttendanceDetail::field('id')->where('attendance_id', $data['id'])->count();
$data['attendance_detail'] = ProjectAttendanceDetail::field(['id', 'person_id', 'work_start_time', 'work_end_time', 'work_record_num', 'daily_salary', 'daily_living', 'daily_subsidy', 'daily_other', 'daily_income', 'remark'])->where('attendance_id', $data['id'])
->select()->each(function ($item) {
$person = ProjectPersonnel::field('name,idcard,work_type')->where('id', $item['person_id'])->findOrEmpty();
$item['name'] = $person['name'];
$item['idcard'] = $person['idcard'];
$item['work_type_text'] = $person->work_type_text;
return $item;
})
->toArray();
return $data;
}
}

View File

@ -132,6 +132,7 @@
$project = Project::field('name,project_code')->where('id', $data['project_id'])->findOrEmpty();
$data['project_name'] = $project['name'];
$data['project_code'] = $project['project_code'];
$data['payment_type_text'] = $data->payment_type_text;
//总工资付款
$data['total_amount'] = ProjectSalaryDetail::where('salary_payment_id', $data['id'])->sum('apply_amount');
return $data->toArray();

View File

@ -37,7 +37,7 @@
'project_id' => 'require|checkProject',
'attendance_date' => 'require|dateFormat:Y-m-d',
'attendance_detail' => 'require|checkAttendanceDetail',
'file' => 'checkFile',
'annex' => 'checkAnnex',
];
protected $message = [
@ -105,16 +105,6 @@
return true;
}
public function checkFile($value): bool|string
{
if (!empty($value) && $value != '') {
if (!is_array($value)) {
return '附件必须是json数组';
}
}
return true;
}
public function checkAttendanceDetail($value, $rule, $data): bool|string
{
$attendance_detail = $value;//json_decode($value,true);

View File

@ -12,30 +12,27 @@
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\common\model\project;
namespace app\common\model\project;
use app\common\model\BaseModel;
use think\model\concern\SoftDelete;
use app\common\model\BaseModel;
use think\model\concern\SoftDelete;
/**
* 考勤记录模型
* Class ProjectAttendanceRecord
* @package app\common\model\project
*/
class ProjectAttendanceRecord extends BaseModel
{
use SoftDelete;
protected $name = 'project_attendance_record';
protected $deleteTime = 'delete_time';
public function getFileAttr($value)
/**
* 考勤记录模型
* Class ProjectAttendanceRecord
* @package app\common\model\project
*/
class ProjectAttendanceRecord extends BaseModel
{
return !empty($value) ? json_decode($value,true) : '';
use SoftDelete;
protected $name = 'project_attendance_record';
protected $deleteTime = 'delete_time';
public function getAttendanceDateAttr($value): string
{
return !empty($value) ? date('Y-m-d', $value) : '';
}
}
public function getAttendanceDateAttr($value): string
{
return !empty($value) ? date('Y-m-d',$value) : '';
}
}

View File

@ -12,38 +12,39 @@
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\common\model\project;
namespace app\common\model\project;
use app\common\model\BaseModel;
use app\common\model\dict\DictData;
use think\model\concern\SoftDelete;
use app\common\model\BaseModel;
use app\common\model\dict\DictData;
use think\model\concern\SoftDelete;
/**
* 工资付款模型
* Class ProjectSalaryPayment
* @package app\common\model\project
*/
class ProjectSalaryPayment extends BaseModel
{
use SoftDelete;
protected $name = 'project_salary_payment';
protected $deleteTime = 'delete_time';
public function getAnnexAttr($value)
/**
* 工资付款模型
* Class ProjectSalaryPayment
* @package app\common\model\project
*/
class ProjectSalaryPayment extends BaseModel
{
return !empty($value) ? json_decode($value,true) : '';
}
use SoftDelete;
public function getApplyDateAttr($value): string
{
return !empty($value) ? date('Y-m-d',$value) : '';
}
protected $name = 'project_salary_payment';
protected $deleteTime = 'delete_time';
public function getPaymentTypeAttr($value,$data): string
{
$dictData = DictData::where('type_value','salary_payment_type')->column('name','value');
return !empty($data['payment_type']) ? $dictData[$data['payment_type']] : '';
public function getAnnexAttr($value)
{
return !empty($value) ? json_decode($value, true) : '';
}
public function getApplyDateAttr($value): string
{
return !empty($value) ? date('Y-m-d', $value) : '';
}
public function getPaymentTypeTextAttr($value, $data): string
{
$dictData = DictData::where('type_value', 'salary_payment_type')->column('name', 'value');
return !empty($data['payment_type']) ? $dictData[$data['payment_type']] : '';
}
}
}