This commit is contained in:
weiz 2024-06-03 18:02:47 +08:00
parent 5835e45161
commit 4858f1def7
6 changed files with 613 additions and 0 deletions

View File

@ -0,0 +1,111 @@
<?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\controller\jxgl;
use app\adminapi\controller\BaseAdminController;
use app\adminapi\lists\jxgl\OaSelfExamineLists;
use app\adminapi\logic\jxgl\OaSelfExamineLogic;
use app\adminapi\validate\jxgl\OaSelfExamineValidate;
/**
* 自评记录控制器
* Class OaSelfExamineController
* @package app\adminapi\controller\jxgl
*/
class OaSelfExamineController extends BaseAdminController
{
/**
* @notes 获取自评记录列表
* @return \think\response\Json
* @author likeadmin
* @date 2024/06/03 15:36
*/
public function lists()
{
return $this->dataLists(new OaSelfExamineLists());
}
/**
* @notes 添加自评记录
* @return \think\response\Json
* @author likeadmin
* @date 2024/06/03 15:36
*/
public function add()
{
$params = (new OaSelfExamineValidate())->post()->goCheck('add');
$result = OaSelfExamineLogic::add($params,$this->adminId);
if (true === $result) {
return $this->success('添加成功', [], 1, 1);
}
return $this->fail(OaSelfExamineLogic::getError());
}
/**
* @notes 编辑自评记录
* @return \think\response\Json
* @author likeadmin
* @date 2024/06/03 15:36
*/
public function edit()
{
$params = (new OaSelfExamineValidate())->post()->goCheck('edit');
$result = OaSelfExamineLogic::edit($params,$this->adminId);
if (true === $result) {
return $this->success('编辑成功', [], 1, 1);
}
return $this->fail(OaSelfExamineLogic::getError());
}
/**
* @notes 删除自评记录
* @return \think\response\Json
* @author likeadmin
* @date 2024/06/03 15:36
*/
public function delete()
{
$params = (new OaSelfExamineValidate())->post()->goCheck('delete');
$result = OaSelfExamineLogic::delete($params);
if (true === $result) {
return $this->success('删除成功', [], 1, 1);
}
return $this->fail(OaSelfExamineLogic::getError());
}
/**
* @notes 获取自评记录详情
* @return \think\response\Json
* @author likeadmin
* @date 2024/06/03 15:36
*/
public function detail()
{
$params = (new OaSelfExamineValidate())->goCheck('detail');
$result = OaSelfExamineLogic::detail($params);
return $this->data($result);
}
}

View File

@ -0,0 +1,92 @@
<?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\lists\jxgl;
use app\adminapi\lists\BaseAdminDataLists;
use app\common\model\auth\Admin;
use app\common\model\jxgl\OaExamineTemp;
use app\common\model\jxgl\OaExamineTempItem;
use app\common\model\jxgl\OaSelfExamine;
use app\common\lists\ListsSearchInterface;
use app\common\model\jxgl\OaSelfExamineDetail;
/**
* 自评记录列表
* Class OaSelfExamineLists
* @package app\adminapi\listsjxgl
*/
class OaSelfExamineLists extends BaseAdminDataLists implements ListsSearchInterface
{
private $where = [];
/**
* @notes 设置搜索条件
* @return \string[][]
* @author likeadmin
* @date 2024/06/03 15:36
*/
public function setSearch(): array
{
return [
'=' => ['examine_type'],
];
}
/**
* @notes 获取自评记录列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author likeadmin
* @date 2024/06/03 15:36
*/
public function lists(): array
{
$params = $this->request->get();
if(!empty($params['examine_month'])){
$this->where[] = ['examine_month','=',strtotime($params['examine_month'])];
}
return OaSelfExamine::withoutField('update_time,delete_time')->where($this->searchWhere)->where($this->where)
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()->each(function($data){
$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'] = OaExamineTempItem::where('examine_temp_id',$data['examine_temp_id'])->sum('score');
$data['total_self_score'] = OaSelfExamineDetail::where('self_examine_id',$data['id'])->sum('self_score');
//todo
})
->toArray();
}
/**
* @notes 获取自评记录数量
* @return int
* @author likeadmin
* @date 2024/06/03 15:36
*/
public function count(): int
{
return OaSelfExamine::where($this->searchWhere)->where($this->where)->count();
}
}

View File

@ -0,0 +1,164 @@
<?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\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']);
});
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('self_examine_id,self_score,examine_item,score,examine_desc')->where('self_examine_id',$data['id'])->select()->toArray();
return $data->toArray();
}
}

View File

@ -0,0 +1,169 @@
<?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\validate\jxgl;
use app\common\model\dict\DictData;
use app\common\model\jxgl\OaExamineTemp;
use app\common\model\jxgl\OaSelfExamine;
use app\common\model\jxgl\OaSelfExamineDetail;
use app\common\validate\BaseValidate;
/**
* 自评记录验证器
* Class OaSelfExamineValidate
* @package app\adminapi\validate\jxgl
*/
class OaSelfExamineValidate extends BaseValidate
{
/**
* 设置校验规则
* @var string[]
*/
protected $rule = [
'id' => 'require|checkData',
'examine_type' => 'require|checkExamineType',
'examine_temp_id' => 'require|checkExamineTemp',
'examine_month' => 'require|dateFormat:Y-m',
'detail' => 'require|checkDetail'
];
/**
* 参数描述
* @var string[]
*/
protected $field = [
'id' => 'id',
'examine_type' => '考核类别',
'examine_temp_id' => '考核模板',
'examine_month' => '考核月份',
'detail' => '考核项',
];
/**
* @notes 添加场景
* @return OaSelfExamineValidate
* @author likeadmin
* @date 2024/06/03 15:36
*/
public function sceneAdd()
{
return $this->only(['examine_temp_id','examine_type','examine_month','detail']);
}
/**
* @notes 编辑场景
* @return OaSelfExamineValidate
* @author likeadmin
* @date 2024/06/03 15:36
*/
public function sceneEdit()
{
return $this->only(['id','examine_temp_id','examine_type','examine_month','detail']);
}
/**
* @notes 删除场景
* @return OaSelfExamineValidate
* @author likeadmin
* @date 2024/06/03 15:36
*/
public function sceneDelete()
{
return $this->only(['id']);
}
/**
* @notes 详情场景
* @return OaSelfExamineValidate
* @author likeadmin
* @date 2024/06/03 15:36
*/
public function sceneDetail()
{
return $this->only(['id']);
}
public function checkData($value): bool|string
{
$data = OaSelfExamine::where('id',$value)->findOrEmpty();
if($data->isEmpty()){
return '数据不存在';
}
return true;
}
public function checkExamineType($value): bool|string
{
$dict = DictData::where('type_value','jxgl_check_type')->column('value');
if(!in_array($value,$dict)){
return '考核类别无效';
}
return true;
}
public function checkExamineTemp($value,$rule,$data): bool|string
{
$temp = OaExamineTemp::where('id',$value)->where('examine_type',$data['examine_type'])->findOrEmpty();
if($temp->isEmpty()){
return '考核模板信息不存在';
}
return true;
}
public function checkDetail($value): bool|string
{
if(!is_array($value) || empty($value)){
return '考核项数据格式错误';
}
foreach($value as $k => $v){
if(isset($v['id']) && !empty($v['id'])){
$data = OaSelfExamineDetail::where('id',$v['id'])->findOrEmpty();
if($data->isEmpty()){
return '第'.($k+1).'行数据不存在';
}
}
if(empty($v['examine_item'])){
return '第'.($k+1).'行考核项为空';
}
if(empty($v['score'])){
return '第'.($k+1).'行分数为空';
}else{
if(!is_numeric($v['score']) || $v['score'] < 0){
return '第'.($k+1).'行分数必须是大于0的数字';
}
}
if(empty($v['examine_desc'])){
return '第'.($k+1).'行考核说明为空';
}
if(empty($v['self_score'])){
return '第'.($k+1).'行自评评分为空';
}else{
if(!is_numeric($v['self_score']) || $v['self_score'] < 0){
return '第'.($k+1).'行自评评分必须是大于0的数字';
}
}
}
return true;
}
}

View File

@ -0,0 +1,43 @@
<?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\common\model\jxgl;
use app\common\model\BaseModel;
use app\common\model\dict\DictData;
use think\model\concern\SoftDelete;
/**
* 自评记录模型
* Class OaSelfExamine
* @package app\common\model\jxgl
*/
class OaSelfExamine extends BaseModel
{
use SoftDelete;
protected $name = 'oa_self_examine';
protected $deleteTime = 'delete_time';
public function getExamineTypeTextAttr($value,$data){
$dict = DictData::where('type_value','jxgl_check_type')->column('name','value');
return !empty($data['examine_type']) ? $dict[$data['examine_type']] : '';
}
public function getExamineMonthAttr($value): string
{
return !empty($value) ? date('Y-m',$value) : '';
}
}

View File

@ -0,0 +1,34 @@
<?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\common\model\jxgl;
use app\common\model\BaseModel;
use think\model\concern\SoftDelete;
/**
* 自评记录明细模型
* Class OaSelfExamineDetail
* @package app\common\model\jxgl
*/
class OaSelfExamineDetail extends BaseModel
{
use SoftDelete;
protected $name = 'oa_self_examine_detail';
protected $deleteTime = 'delete_time';
}