This commit is contained in:
weiz 2024-05-23 13:56:38 +08:00
parent 947e2b7e31
commit fe1ba6e739
5 changed files with 525 additions and 0 deletions

View File

@ -0,0 +1,108 @@
<?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\works\rcbg;
use app\adminapi\controller\BaseAdminController;
use app\adminapi\lists\works\rcbg\OaPlanLists;
use app\adminapi\logic\works\rcbg\OaPlanLogic;
use app\adminapi\validate\works\rcbg\OaPlanValidate;
/**
* 日程安排控制器
* Class OaPlanController
* @package app\adminapi\controller\works\rcbg
*/
class OaPlanController extends BaseAdminController
{
/**
* @notes 获取日程安排列表
* @return \think\response\Json
* @author likeadmin
* @date 2024/05/23 11:53
*/
public function lists()
{
return $this->dataLists(new OaPlanLists());
}
/**
* @notes 添加日程安排
* @return \think\response\Json
* @author likeadmin
* @date 2024/05/23 11:53
*/
public function add()
{
$params = (new OaPlanValidate())->post()->goCheck('add');
$result = OaPlanLogic::add($params,$this->adminId);
if (true === $result) {
return $this->success('添加成功', [], 1, 1);
}
return $this->fail(OaPlanLogic::getError());
}
/**
* @notes 编辑日程安排
* @return \think\response\Json
* @author likeadmin
* @date 2024/05/23 11:53
*/
public function edit()
{
$params = (new OaPlanValidate())->post()->goCheck('edit');
$result = OaPlanLogic::edit($params);
if (true === $result) {
return $this->success('编辑成功', [], 1, 1);
}
return $this->fail(OaPlanLogic::getError());
}
/**
* @notes 删除日程安排
* @return \think\response\Json
* @author likeadmin
* @date 2024/05/23 11:53
*/
public function delete()
{
$params = (new OaPlanValidate())->post()->goCheck('delete');
OaPlanLogic::delete($params);
return $this->success('删除成功', [], 1, 1);
}
/**
* @notes 获取日程安排详情
* @return \think\response\Json
* @author likeadmin
* @date 2024/05/23 11:53
*/
public function detail()
{
$params = (new OaPlanValidate())->goCheck('detail');
$result = OaPlanLogic::detail($params);
return $this->data($result);
}
}

View File

@ -0,0 +1,79 @@
<?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\works\rcbg;
use app\adminapi\lists\BaseAdminDataLists;
use app\common\model\works\rcbg\OaPlan;
use app\common\lists\ListsSearchInterface;
/**
* 日程安排列表
* Class OaPlanLists
* @package app\adminapi\listsworks\rcbg
*/
class OaPlanLists extends BaseAdminDataLists implements ListsSearchInterface
{
/**
* @notes 设置搜索条件
* @return \string[][]
* @author likeadmin
* @date 2024/05/23 11:53
*/
public function setSearch(): array
{
return [
'=' => ['title', 'type'],
];
}
/**
* @notes 获取日程安排列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author likeadmin
* @date 2024/05/23 11:53
*/
public function lists(): array
{
return OaPlan::where($this->searchWhere)->where('admin_id',$this->adminId)
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()->each(function($data){
$data['type_text'] = $data->type_text;
$data['remind_type_text'] = $data->remind_type_text;
})
->toArray();
}
/**
* @notes 获取日程安排数量
* @return int
* @author likeadmin
* @date 2024/05/23 11:53
*/
public function count(): int
{
return OaPlan::where($this->searchWhere)->count();
}
}

View File

@ -0,0 +1,168 @@
<?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\works\rcbg;
use app\common\model\works\rcbg\OaPlan;
use app\common\logic\BaseLogic;
use think\facade\Db;
/**
* 日程安排逻辑
* Class OaPlanLogic
* @package app\adminapi\logic\works\rcbg
*/
class OaPlanLogic extends BaseLogic
{
/**
* @notes 添加日程安排
* @param array $params
* @return bool
* @author likeadmin
* @date 2024/05/23 11:53
*/
public static function add(array $params,$admin_id): bool
{
$start_time = strtotime($params['start_time']);
$end_time = strtotime($params['end_time']);
$remind_time = 0;
if (isset($param['remind_type'])) {
if($param['remind_type']==1){
$remind_time = $start_time-5*60;
}
if($param['remind_type']==2){
$remind_time = $start_time-15*60;
}
if($param['remind_type']==3){
$remind_time = $start_time-30*60;
}
if($param['remind_type']==4){
$remind_time = $start_time-60*60;
}
if($param['remind_type']==5){
$remind_time = $start_time-120*60;
}
if($param['remind_type']==6){
$remind_time = $start_time-1440*60;
}
}
Db::startTrans();
try {
OaPlan::create([
'title' => $params['title'],
'type' => $params['type'],
'start_time' => $start_time,
'end_time' => $end_time,
'remind_type' => $params['remind_type'],
'remind_time' => $remind_time,
'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 11:53
*/
public static function edit(array $params): bool
{
$start_time = strtotime($params['start_time']);
$end_time = strtotime($params['end_time']);
$remind_time = 0;
if (isset($param['remind_type'])) {
if($param['remind_type']==1){
$remind_time = $start_time-5*60;
}
if($param['remind_type']==2){
$remind_time = $start_time-15*60;
}
if($param['remind_type']==3){
$remind_time = $start_time-30*60;
}
if($param['remind_type']==4){
$remind_time = $start_time-60*60;
}
if($param['remind_type']==5){
$remind_time = $start_time-120*60;
}
if($param['remind_type']==6){
$remind_time = $start_time-1440*60;
}
}
Db::startTrans();
try {
OaPlan::where('id', $params['id'])->update([
'title' => $params['title'],
'type' => $params['type'],
'start_time' => $start_time,
'end_time' => $end_time,
'remind_type' => $params['remind_type'],
'remind_time' => $remind_time,
'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 11:53
*/
public static function delete(array $params): bool
{
return OaPlan::destroy($params['id']);
}
/**
* @notes 获取日程安排详情
* @param $params
* @return array
* @author likeadmin
* @date 2024/05/23 11:53
*/
public static function detail($params): array
{
$data = OaPlan::findOrEmpty($params['id']);
$data['type_text'] = $data->type_text;
$data['remind_type_text'] = $data->remind_type_text;
return $data->toArray();
}
}

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\validate\works\rcbg;
use app\common\model\works\rcbg\OaPlan;
use app\common\validate\BaseValidate;
/**
* 日程安排验证器
* Class OaPlanValidate
* @package app\adminapi\validate\works\rcbg
*/
class OaPlanValidate extends BaseValidate
{
/**
* 设置校验规则
* @var string[]
*/
protected $rule = [
'id' => 'require|checkData',
'title' => 'require',
'type' => 'require|integer|in:0,1,2,3,4',
'start_time' => 'require|dateFormat:Y-m-d H:i',
'end_time' => 'require|dateFormat:Y-m-d H:i',
'remind_type' => 'require|integer|in:0,1,2,3,4,5,6',
];
/**
* 参数描述
* @var string[]
*/
protected $field = [
'id' => 'id',
'title' => '工作安排主题',
'type' => '日程优先级',
'start_time' => '开始时间',
'end_time' => '结束时间',
'remind_type' => '提醒类型',
];
/**
* @notes 添加场景
* @return OaPlanValidate
* @author likeadmin
* @date 2024/05/23 11:53
*/
public function sceneAdd()
{
return $this->only(['title','type','start_time','end_time','remind_type']);
}
/**
* @notes 编辑场景
* @return OaPlanValidate
* @author likeadmin
* @date 2024/05/23 11:53
*/
public function sceneEdit()
{
return $this->only(['id','title','type','start_time','end_time','remind_type']);
}
/**
* @notes 删除场景
* @return OaPlanValidate
* @author likeadmin
* @date 2024/05/23 11:53
*/
public function sceneDelete()
{
return $this->only(['id']);
}
/**
* @notes 详情场景
* @return OaPlanValidate
* @author likeadmin
* @date 2024/05/23 11:53
*/
public function sceneDetail()
{
return $this->only(['id']);
}
public function checkData($value): bool|string
{
$data = OaPlan::field('id')->where('id',$value)->findOrEmpty();
return $data->isEmpty() ? '数据不存在' : true;
}
}

View File

@ -0,0 +1,59 @@
<?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\works\rcbg;
use app\common\model\BaseModel;
use think\model\concern\SoftDelete;
/**
* 日程安排模型
* Class OaPlan
* @package app\common\model\works\rcbg
*/
class OaPlan extends BaseModel
{
use SoftDelete;
protected $name = 'oa_plan';
protected $deleteTime = 'delete_time';
public function getStartTimeAttr($value): string
{
return !empty($value) ? date('Y-m-d H:i',$value) : '';
}
public function getEndTimeAttr($value): string
{
return !empty($value) ? date('Y-m-d H:i',$value) : '';
}
public function getRemindTimeAttr($value): string
{
return !empty($value) ? date('Y-m-d H:i',$value) : '';
}
public function getTypeTextAttr($value,$data): string
{
$arr = [0=>'无优先级',1=>'不重要',2=>'次要',3=>'重要',4=>'紧急'];
return $arr[$data['type']];
}
public function getRemindTypeTextAttr($value,$data): string
{
$arr = [0=>'不提醒',1=>'提前5分钟',2=>'提前15分钟',3=>'提前30分钟',4=>'提前1小时',5=>'提前2小时',6=>'提前1天'];
return $arr[$data['remind_type']];
}
}