176 lines
5.8 KiB
PHP
176 lines
5.8 KiB
PHP
<?php
|
||
// +----------------------------------------------------------------------
|
||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||
// +----------------------------------------------------------------------
|
||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||
// | 开源版本可自由商用,可去除界面版权logo
|
||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||
// | 访问官网:https://www.likeadmin.cn
|
||
// | likeadmin团队 版权所有 拥有最终解释权
|
||
// +----------------------------------------------------------------------
|
||
// | author: likeadminTeam
|
||
// +----------------------------------------------------------------------
|
||
|
||
namespace app\oa\logic\jxgl;
|
||
|
||
|
||
use app\common\model\jxgl\OaExamine;
|
||
use app\common\model\jxgl\OaExamineDetail;
|
||
use app\common\model\jxgl\OaExamineTemp;
|
||
use app\common\logic\BaseLogic;
|
||
use app\common\model\jxgl\OaExamineTempItem;
|
||
use app\common\model\jxgl\OaSelfExamine;
|
||
use app\common\model\jxgl\OaSelfExamineDetail;
|
||
use think\facade\Db;
|
||
|
||
|
||
/**
|
||
* 考核模板逻辑
|
||
* Class OaExamineTempLogic
|
||
* @package app\adminapi\logic\jxgl
|
||
*/
|
||
class OaExamineTempLogic extends BaseLogic
|
||
{
|
||
|
||
|
||
/**
|
||
* @notes 添加考核模板
|
||
* @param array $params
|
||
* @return bool
|
||
* @author likeadmin
|
||
* @date 2024/06/03 13:35
|
||
*/
|
||
public static function add(array $params): bool
|
||
{
|
||
Db::startTrans();
|
||
try {
|
||
$res = OaExamineTemp::create([
|
||
'examine_type' => $params['examine_type'],
|
||
'temp_name' => $params['temp_name'],
|
||
'create_user' => $params['create_user'],
|
||
'create_time' => !empty($params['create_time']) ? strtotime($params['create_time']) : time()
|
||
]);
|
||
foreach($params['detail'] as &$v){
|
||
$v['examine_temp_id'] = $res['id'];
|
||
$v['create_time'] = time();
|
||
}
|
||
(new OaExamineTempItem)->saveAll($params['detail']);
|
||
Db::commit();
|
||
return true;
|
||
} catch (\Exception $e) {
|
||
Db::rollback();
|
||
self::setError($e->getMessage());
|
||
return false;
|
||
}
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 编辑考核模板
|
||
* @param array $params
|
||
* @return bool
|
||
* @author likeadmin
|
||
* @date 2024/06/03 13:35
|
||
*/
|
||
public static function edit(array $params): bool
|
||
{
|
||
Db::startTrans();
|
||
try {
|
||
OaExamineTemp::where('id', $params['id'])->update([
|
||
'examine_type' => $params['examine_type'],
|
||
'temp_name' => $params['temp_name'],
|
||
'update_time' => time()
|
||
]);
|
||
foreach($params['detail'] as $v){
|
||
if(!empty($v['id'])){
|
||
OaExamineTempItem::where('id',$v['id'])->update([
|
||
'examine_temp_id' => $params['id'],
|
||
'examine_item' => $v['examine_item'],
|
||
'score' => $v['score'],
|
||
'examine_desc' => $v['examine_desc'],
|
||
'update_time' => time(),
|
||
]);
|
||
}else{
|
||
OaExamineTempItem::create([
|
||
'examine_temp_id' => $params['id'],
|
||
'examine_item' => $v['examine_item'],
|
||
'score' => $v['score'],
|
||
'examine_desc' => $v['examine_desc'],
|
||
'create_time' => time()
|
||
]);
|
||
}
|
||
}
|
||
Db::commit();
|
||
return true;
|
||
} catch (\Exception $e) {
|
||
Db::rollback();
|
||
self::setError($e->getMessage());
|
||
return false;
|
||
}
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 删除考核模板
|
||
* @param array $params
|
||
* @return bool
|
||
* @author likeadmin
|
||
* @date 2024/06/03 13:35
|
||
*/
|
||
public static function delete(array $params): bool
|
||
{
|
||
Db::startTrans();
|
||
try {
|
||
//删除考核模板
|
||
OaExamineTemp::destroy($params['id']);
|
||
//删除考核模板考核项
|
||
OaExamineTempItem::destroy(function($query)use($params){
|
||
$query->where('examine_temp_id','=',$params['id']);
|
||
});
|
||
//删除关联的自评记录
|
||
OaSelfExamine::destroy(function($query)use($params){
|
||
$query->where('examine_temp_id','=',$params['id']);
|
||
});
|
||
//删除关联的自评记录的考核项
|
||
OaSelfExamineDetail::destroy(function($query)use($params){
|
||
$self_examine_ids = OaSelfExamine::where('examine_temp_id','=',$params['id'])->column('id');
|
||
$query->where('self_examine_id','in',$self_examine_ids);
|
||
});
|
||
//删除关联的考核记录
|
||
OaExamine::destroy(function($query)use($params){
|
||
$self_examine_ids = OaSelfExamine::where('examine_temp_id','=',$params['id'])->column('id');
|
||
$query->where('self_examine_id','in',$self_examine_ids);
|
||
});
|
||
//删除关联的考核记录的考核项
|
||
OaExamineDetail::destroy(function($query)use($params){
|
||
$self_examine_ids = OaSelfExamine::where('examine_temp_id','=',$params['id'])->column('id');
|
||
$examine_ids = OaExamine::where('self_examine_id','in',$self_examine_ids)->column('id');
|
||
$query->where('examine_id','in',$examine_ids);
|
||
});
|
||
Db::commit();
|
||
return true;
|
||
} catch (\Exception $e) {
|
||
Db::rollback();
|
||
self::setError($e->getMessage());
|
||
return false;
|
||
}
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 获取考核模板详情
|
||
* @param $params
|
||
* @return array
|
||
* @author likeadmin
|
||
* @date 2024/06/03 13:35
|
||
*/
|
||
public static function detail($params): array
|
||
{
|
||
$data = OaExamineTemp::withoutField('update_time,delete_time')->findOrEmpty($params['id']);
|
||
$data['examine_type_text'] = $data->examine_type_text;
|
||
$data['total_score'] = OaExamineTempItem::where('examine_temp_id',$params['id'])->sum('score');
|
||
$data['detail'] = OaExamineTempItem::field('id,examine_item,score,examine_desc')->where('examine_temp_id',$params['id'])->select()->toArray();
|
||
return $data->toArray();
|
||
}
|
||
} |