177 lines
5.9 KiB
PHP
177 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\model\jxgl\OaExamineDetail;
|
||
use app\common\model\jxgl\OaExamineTemp;
|
||
use app\common\model\jxgl\OaExamineTempItem;
|
||
use app\common\model\jxgl\OaSelfExamine;
|
||
use app\common\logic\BaseLogic;
|
||
use app\common\model\jxgl\OaSelfExamineDetail;
|
||
use think\facade\Db;
|
||
|
||
|
||
/**
|
||
* 自评记录逻辑
|
||
* Class OaSelfExamineLogic
|
||
* @package app\adminapi\logic\jxgl
|
||
*/
|
||
class OaSelfExamineLogic extends BaseLogic
|
||
{
|
||
|
||
|
||
/**
|
||
* @notes 添加自评记录
|
||
* @param array $params
|
||
* @return bool
|
||
* @author likeadmin
|
||
* @date 2024/06/03 15:36
|
||
*/
|
||
public static function add(array $params,$admin_id): bool
|
||
{
|
||
Db::startTrans();
|
||
try {
|
||
$res = OaSelfExamine::create([
|
||
'user_id' => $admin_id,
|
||
'examine_temp_id' => $params['examine_temp_id'],
|
||
'examine_type' => $params['examine_type'],
|
||
'examine_month' => !empty($params['examine_month']) ? strtotime($params['examine_month']) : 0
|
||
]);
|
||
foreach($params['detail'] as &$v){
|
||
$v['self_examine_id'] = $res['id'];
|
||
$v['create_time'] = time();
|
||
}
|
||
(new OaSelfExamineDetail)->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 15:36
|
||
*/
|
||
public static function edit(array $params,$admin_id): bool
|
||
{
|
||
$data = OaSelfExamine::where('id',$params['id'])->findOrEmpty();
|
||
if($data['user_id'] != $admin_id){
|
||
self::setError('你不是此数据的添加者,无权修改');
|
||
return false;
|
||
}
|
||
Db::startTrans();
|
||
try {
|
||
OaSelfExamine::where('id', $params['id'])->update([
|
||
'examine_temp_id' => $params['examine_temp_id'],
|
||
'examine_type' => $params['examine_type'],
|
||
'examine_month' => !empty($params['examine_month']) ? strtotime($params['examine_month']) : 0,
|
||
'update_time' => time()
|
||
]);
|
||
foreach($params['detail'] as $v){
|
||
if(!empty($v['id'])){
|
||
OaSelfExamineDetail::where('id',$v['id'])->update([
|
||
'self_examine_id' => $params['id'],
|
||
'examine_item' => $v['examine_item'],
|
||
'score' => $v['score'],
|
||
'examine_desc' => $v['examine_desc'],
|
||
'self_score' => $v['self_score'],
|
||
'update_time' => time(),
|
||
]);
|
||
}else{
|
||
OaSelfExamineDetail::create([
|
||
'self_examine_id' => $params['id'],
|
||
'examine_item' => $v['examine_item'],
|
||
'score' => $v['score'],
|
||
'examine_desc' => $v['examine_desc'],
|
||
'self_score' => $v['self_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/03 15:36
|
||
*/
|
||
public static function delete(array $params): bool
|
||
{
|
||
Db::startTrans();
|
||
try {
|
||
//删除自评记录
|
||
OaSelfExamine::destroy($params['id']);
|
||
//伤处自评记录考核项
|
||
OaSelfExamineDetail::destroy(function($query)use($params){
|
||
$query->where('self_examine_id','=',$params['id']);
|
||
});
|
||
//删除关联的考核记录
|
||
OaExamine::destroy(function($query)use($params){
|
||
$query->where('self_examine_id','=',$params['id']);
|
||
});
|
||
//删除关联的考核记录考核项
|
||
OaExamineDetail::destroy(function($query)use($params){
|
||
$examine_ids = OaExamine::where('self_examine_id','=',$params['id'])->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 15:36
|
||
*/
|
||
public static function detail($params): array
|
||
{
|
||
$data = OaSelfExamine::withoutField('update_time,delete_time')->findOrEmpty($params['id']);
|
||
$data['user_name'] = Admin::where('id',$data['user_id'])->value('name');
|
||
$data['temp_name'] = OaExamineTemp::where('id',$data['examine_temp_id'])->value('temp_name');
|
||
$data['examine_type_text'] = $data->examine_type_text;
|
||
$data['total_score'] = OaSelfExamineDetail::where('self_examine_id',$data['id'])->sum('score');
|
||
$data['total_self_score'] = OaSelfExamineDetail::where('self_examine_id',$data['id'])->sum('self_score');
|
||
$data['detail'] = OaSelfExamineDetail::field('id,self_score,examine_item,score,examine_desc')->where('self_examine_id',$data['id'])->select()->toArray();
|
||
return $data->toArray();
|
||
}
|
||
} |