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

View File

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

View File

@ -132,6 +132,7 @@
$project = Project::field('name,project_code')->where('id', $data['project_id'])->findOrEmpty(); $project = Project::field('name,project_code')->where('id', $data['project_id'])->findOrEmpty();
$data['project_name'] = $project['name']; $data['project_name'] = $project['name'];
$data['project_code'] = $project['project_code']; $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'); $data['total_amount'] = ProjectSalaryDetail::where('salary_payment_id', $data['id'])->sum('apply_amount');
return $data->toArray(); return $data->toArray();

View File

@ -37,7 +37,7 @@
'project_id' => 'require|checkProject', 'project_id' => 'require|checkProject',
'attendance_date' => 'require|dateFormat:Y-m-d', 'attendance_date' => 'require|dateFormat:Y-m-d',
'attendance_detail' => 'require|checkAttendanceDetail', 'attendance_detail' => 'require|checkAttendanceDetail',
'file' => 'checkFile', 'annex' => 'checkAnnex',
]; ];
protected $message = [ protected $message = [
@ -105,16 +105,6 @@
return true; 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 public function checkAttendanceDetail($value, $rule, $data): bool|string
{ {
$attendance_detail = $value;//json_decode($value,true); $attendance_detail = $value;//json_decode($value,true);

View File

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