engineering/app/adminapi/logic/jxgl/OaExamineTempLogic.php
2024-06-03 15:07:25 +08:00

141 lines
4.3 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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\jxgl\OaExamineTemp;
use app\common\logic\BaseLogic;
use app\common\model\jxgl\OaExamineTempItem;
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']) : 0
]);
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'],
'create_user' => $params['create_user'],
'create_time' => !empty($params['create_time']) ? strtotime($params['create_time']) : 0,
'update_time' => time()
]);
//删除原数据
OaExamineTempItem::destroy(function($query)use($params){
$query->where('examine_temp_id','=',$params['id']);
});
foreach($params['detail'] as &$v){
$v['examine_temp_id'] = $params['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 delete(array $params): bool
{
Db::startTrans();
try {
OaExamineTemp::destroy($params['id']);
OaExamineTempItem::destroy(function($query)use($params){
$query->where('examine_temp_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/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['detail'] = OaExamineTempItem::field('id,examine_item,score,examine_desc')->where('examine_temp_id',$params['id'])->select()->toArray();
return $data->toArray();
}
}