150 lines
4.3 KiB
PHP
150 lines
4.3 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\auth\Admin;
|
||
use app\common\model\works\rcbg\OaWork;
|
||
use app\common\logic\BaseLogic;
|
||
use app\common\model\works\rcbg\OaWorkComment;
|
||
use app\common\model\works\rcbg\OaWorkRecord;
|
||
use think\facade\Db;
|
||
|
||
|
||
/**
|
||
* 工作汇报逻辑
|
||
* Class OaWorkLogic
|
||
* @package app\adminapi\logic\works\rcbg
|
||
*/
|
||
class OaWorkLogic extends BaseLogic
|
||
{
|
||
|
||
|
||
/**
|
||
* @notes 添加工作汇报
|
||
* @param array $params
|
||
* @return bool
|
||
* @author likeadmin
|
||
* @date 2024/05/23 15:56
|
||
*/
|
||
public static function add(array $params,$admin_id): bool
|
||
{
|
||
Db::startTrans();
|
||
try {
|
||
$res = OaWork::create([
|
||
'type' => $params['type'],
|
||
'type_user' => $params['type_user'],
|
||
'works' => $params['works'],
|
||
'plans' => $params['plans'] ?? '',
|
||
'remark' => $params['remark'] ?? '',
|
||
'admin_id' => $admin_id,
|
||
'annex' => $params['annex'] ? json_encode($params['annex']) : null,
|
||
]);
|
||
$data = [];
|
||
$to_users = explode(',',$params['type_user']);
|
||
foreach ($to_users as $v){
|
||
$data[] = [
|
||
'wid' => $res['id'],
|
||
'from_uid' => $admin_id,
|
||
'to_uid' => $v,
|
||
'send_time' => time(),
|
||
'read_time' => 0
|
||
];
|
||
}
|
||
(new OaWorkRecord()) -> saveAll($data);
|
||
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 15:56
|
||
*/
|
||
public static function edit(array $params): bool
|
||
{
|
||
Db::startTrans();
|
||
try {
|
||
OaWork::where('id', $params['id'])->update([
|
||
'type' => $params['type'],
|
||
'works' => $params['works'],
|
||
'plans' => $params['plans'] ?? '',
|
||
'remark' => $params['remark'] ?? '',
|
||
'annex' => $params['annex'] ? json_encode($params['annex']) : null,
|
||
]);
|
||
|
||
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 15:56
|
||
*/
|
||
public static function delete(array $params): bool
|
||
{
|
||
Db::startTrans();
|
||
try {
|
||
OaWork::destroy($params['id']);
|
||
OaWorkRecord::destroy(function($query)use($params){
|
||
$query->where('wid','=',$params['id']);
|
||
});
|
||
OaWorkComment::destroy(function($query)use($params){
|
||
$query->where('work_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/05/23 15:56
|
||
*/
|
||
public static function detail($params): array
|
||
{
|
||
$data = OaWork::findOrEmpty($params['id']);
|
||
$type_user = Admin::where('id','in',$data['type_user'])->column('name');
|
||
$data['type_user_names'] = implode(',',$type_user);
|
||
$data['type_text'] = $data->type_text;
|
||
return $data->toArray();
|
||
}
|
||
} |