139 lines
4.0 KiB
PHP
139 lines
4.0 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\works\rcbg;
|
||
|
||
|
||
use app\common\model\works\rcbg\OaSchedule;
|
||
use app\common\logic\BaseLogic;
|
||
use think\facade\Db;
|
||
|
||
|
||
/**
|
||
* 工作记录逻辑
|
||
* Class OaScheduleLogic
|
||
* @package app\adminapi\logic\works\rcbg
|
||
*/
|
||
class OaScheduleLogic extends BaseLogic
|
||
{
|
||
|
||
|
||
/**
|
||
* @notes 添加工作记录
|
||
* @param array $params
|
||
* @return bool
|
||
* @author likeadmin
|
||
* @date 2024/05/23 14:27
|
||
*/
|
||
public static function add(array $params,$admin_id): bool
|
||
{
|
||
Db::startTrans();
|
||
try {
|
||
OaSchedule::create([
|
||
'title' => $params['title'],
|
||
'start_time' => strtotime($params['start_time']),
|
||
'end_time' => strtotime($params['end_time']),
|
||
'labor_time' => (strtotime($params['end_time']) - strtotime($params['start_time'])) / 3600,
|
||
'labor_type' => $params['labor_type'],
|
||
'cid' => $params['cid'],
|
||
'remark' => $params['remark'] ?? '',
|
||
'admin_id' => $admin_id
|
||
]);
|
||
|
||
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/05/23 14:27
|
||
*/
|
||
public static function edit(array $params): bool
|
||
{
|
||
Db::startTrans();
|
||
try {
|
||
OaSchedule::where('id', $params['id'])->update([
|
||
'title' => $params['title'],
|
||
'start_time' => strtotime($params['start_time']),
|
||
'end_time' => strtotime($params['end_time']),
|
||
'labor_time' => (strtotime($params['end_time']) - strtotime($params['start_time'])) / 3600,
|
||
'labor_type' => $params['labor_type'],
|
||
'cid' => $params['cid'],
|
||
'remark' => $params['remark'] ?? ''
|
||
]);
|
||
|
||
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/05/23 14:27
|
||
*/
|
||
public static function delete(array $params): bool
|
||
{
|
||
return OaSchedule::destroy($params['id']);
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 获取工作记录详情
|
||
* @param $params
|
||
* @return array
|
||
* @author likeadmin
|
||
* @date 2024/05/23 14:27
|
||
*/
|
||
public static function detail($params): array
|
||
{
|
||
$data = OaSchedule::findOrEmpty($params['id']);
|
||
$data['cid_text'] = $data->cid_text;
|
||
$data['labor_type_text'] = $data->labor_type_text;
|
||
return $data->toArray();
|
||
}
|
||
|
||
/**
|
||
* @notes 获取工作记录日历
|
||
* @param $params
|
||
* @return array
|
||
* @author likeadmin
|
||
* @date 2024/05/23 11:53
|
||
*/
|
||
public static function calendar($params){
|
||
$where[] = [
|
||
['admin_id','=',$params['admin_id']],
|
||
['start_time','>=',strtotime($params['start_time'])],
|
||
['end_time','<=',strtotime($params['end_time'])]
|
||
];
|
||
$data = OaSchedule::where($where)->select()->toArray();
|
||
return $data;
|
||
}
|
||
} |