175 lines
5.9 KiB
PHP
175 lines
5.9 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\adminapi\logic\jxgl;
|
||
|
||
|
||
use app\common\model\auth\Admin;
|
||
use app\common\model\jxgl\OaExamine;
|
||
use app\common\logic\BaseLogic;
|
||
use app\common\model\jxgl\OaExamineDetail;
|
||
use app\common\model\jxgl\OaSelfExamine;
|
||
use think\facade\Db;
|
||
|
||
|
||
/**
|
||
* 考核下属记录逻辑
|
||
* Class OaExamineLogic
|
||
* @package app\adminapi\logic\jxgl
|
||
*/
|
||
class OaExamineLogic extends BaseLogic
|
||
{
|
||
|
||
|
||
/**
|
||
* @notes 添加考核下属记录
|
||
* @param array $params
|
||
* @return bool
|
||
* @author likeadmin
|
||
* @date 2024/06/04 13:37
|
||
*/
|
||
public static function add(array $params,$admin_id): bool
|
||
{
|
||
if($admin_id == $params['bkh_user_id']){
|
||
self::setError('考核人与被考核人不能相同');
|
||
return false;
|
||
}
|
||
Db::startTrans();
|
||
try {
|
||
$res = OaExamine::create([
|
||
'kh_user_id' => $admin_id,
|
||
'bkh_user_id' => $params['bkh_user_id'],
|
||
'examine_type' => $params['examine_type'],
|
||
'self_examine_id' => $params['self_examine_id'],
|
||
'content' => $params['content'] ?? ''
|
||
]);
|
||
foreach($params['detail'] as &$v){
|
||
$v['examine_id'] = $res['id'];
|
||
$v['create_time'] = time();
|
||
}
|
||
(new OaExamineDetail)->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/04 13:37
|
||
*/
|
||
public static function edit(array $params,$admin_id): bool
|
||
{
|
||
$data = OaExamine::where('id',$params['id'])->findOrEmpty();
|
||
if($data['kh_user_id'] != $admin_id){
|
||
self::setError('你不是此数据的考核者,无权修改');
|
||
return false;
|
||
}
|
||
Db::startTrans();
|
||
try {
|
||
OaExamine::where('id', $params['id'])->update([
|
||
'kh_user_id' => $admin_id,
|
||
'bkh_user_id' => $params['bkh_user_id'],
|
||
'examine_type' => $params['examine_type'],
|
||
'self_examine_id' => $params['self_examine_id'],
|
||
'content' => $params['content'] ?? ''
|
||
]);
|
||
foreach($params['detail'] as $v){
|
||
if(!empty($v['id'])){
|
||
OaExamineDetail::where('id',$v['id'])->update([
|
||
'examine_id' => $params['id'],
|
||
'examine_item' => $v['examine_item'],
|
||
'score' => $v['score'],
|
||
'examine_desc' => $v['examine_desc'],
|
||
'self_score' => $v['self_score'],
|
||
'superior_score' => $v['superior_score'],
|
||
'update_time' => time(),
|
||
]);
|
||
}else{
|
||
OaExamineDetail::create([
|
||
'examine_id' => $params['id'],
|
||
'examine_item' => $v['examine_item'],
|
||
'score' => $v['score'],
|
||
'examine_desc' => $v['examine_desc'],
|
||
'self_score' => $v['self_score'],
|
||
'superior_score' => $v['superior_score'],
|
||
'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/04 13:37
|
||
*/
|
||
public static function delete(array $params): bool
|
||
{
|
||
Db::startTrans();
|
||
try {
|
||
OaExamine::destroy($params['id']);
|
||
OaExamineDetail::destroy(function($query)use($params){
|
||
$query->where('examine_id','=',$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 2024/06/04 13:37
|
||
*/
|
||
public static function detail($params): array
|
||
{
|
||
$data = OaExamine::withoutField('update_time,delete_time')->findOrEmpty($params['id']);
|
||
$self_examine = OaSelfExamine::where('id',$data['self_examine_id'])->findOrEmpty();
|
||
$data['kh_user_name'] = Admin::where('id',$data['kh_user_id'])->value('name');
|
||
$data['bkh_user_name'] = Admin::where('id',$data['bkh_user_id'])->value('name');
|
||
$data['examine_type_text'] = $data->examine_type_text;
|
||
$data['examine_month'] = $self_examine['examine_month'];
|
||
$data['total_score'] = OaExamineDetail::where('examine_id',$data['id'])->sum('score');
|
||
$data['total_self_score'] = OaExamineDetail::where('examine_id',$data['id'])->sum('self_score');
|
||
$data['total_superior_score'] = OaExamineDetail::where('examine_id',$data['id'])->sum('superior_score');
|
||
$data['final_score'] = bcadd($data['total_self_score'],$data['total_superior_score'],2) / 2;
|
||
$data['detail'] = OaExamineDetail::field('id,examine_item,score,examine_desc,self_score,superior_score')->where('examine_id',$data['id'])->select()->toArray();
|
||
return $data->toArray();
|
||
}
|
||
} |