Merge pull request '新增项目日志管理模块' (#29) from zhangwei into dev

Reviewed-on: #29
This commit is contained in:
weiz 2023-12-14 11:10:14 +08:00
commit 6056a262f5
5 changed files with 519 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\project;
use app\adminapi\controller\BaseAdminController;
use app\adminapi\lists\project\ProjectLogsLists;
use app\adminapi\logic\project\ProjectLogsLogic;
use app\adminapi\validate\project\ProjectLogsValidate;
/**
* 项目日志管理控制器
* Class ProjectLogsController
* @package app\adminapi\controller\project
*/
class ProjectLogsController extends BaseAdminController
{
/**
* @notes 获取项目日志管理列表
* @return \think\response\Json
* @author likeadmin
* @date 2023/12/14 09:17
*/
public function lists()
{
return $this->dataLists(new ProjectLogsLists());
}
/**
* @notes 添加项目日志管理
* @return \think\response\Json
* @author likeadmin
* @date 2023/12/14 09:17
*/
public function add()
{
$params = (new ProjectLogsValidate())->post()->goCheck('add');
$result = ProjectLogsLogic::add($params,$this->adminId);
if (true === $result) {
return $this->success('添加成功', [], 1, 1);
}
return $this->fail(ProjectLogsLogic::getError());
}
/**
* @notes 编辑项目日志管理
* @return \think\response\Json
* @author likeadmin
* @date 2023/12/14 09:17
*/
public function edit()
{
$params = (new ProjectLogsValidate())->post()->goCheck('edit');
$result = ProjectLogsLogic::edit($params);
if (true === $result) {
return $this->success('编辑成功', [], 1, 1);
}
return $this->fail(ProjectLogsLogic::getError());
}
/**
* @notes 删除项目日志管理
* @return \think\response\Json
* @author likeadmin
* @date 2023/12/14 09:17
*/
public function delete()
{
$params = (new ProjectLogsValidate())->post()->goCheck('delete');
ProjectLogsLogic::delete($params);
return $this->success('删除成功', [], 1, 1);
}
/**
* @notes 获取项目日志管理详情
* @return \think\response\Json
* @author likeadmin
* @date 2023/12/14 09:17
*/
public function detail()
{
$params = (new ProjectLogsValidate())->goCheck('detail');
$result = ProjectLogsLogic::detail($params);
return $this->data($result);
}
}

View File

@ -0,0 +1,107 @@
<?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\project;
use app\adminapi\lists\BaseAdminDataLists;
use app\common\model\auth\Admin;
use app\common\model\project\Project;
use app\common\model\project\ProjectLogs;
use app\common\lists\ListsSearchInterface;
/**
* 项目日志管理列表
* Class ProjectLogsLists
* @package app\adminapi\listsproject
*/
class ProjectLogsLists extends BaseAdminDataLists implements ListsSearchInterface
{
/**
* @notes 设置搜索条件
* @return \string[][]
* @author likeadmin
* @date 2023/12/14 09:17
*/
public function setSearch(): array
{
return [
'=' => ['follow_type'],
'%like%' => ['theme', 'contacts', 'executor'],
];
}
/**
* @notes 获取项目日志管理列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author likeadmin
* @date 2023/12/14 09:17
*/
public function lists(): array
{
$params = $this->request->param();
$where = [];
if(isset($params['project_name']) && $params['project_name'] != ''){
$projectIds = Project::where('name','like','%'.$params['project_name'].'%')->column('id');
$where[] = ['project_id','in',$projectIds];
}
if(isset($params['add_user_name']) && $params['add_user_name'] != ''){
$adminIds = Admin::where('name','like','%'.$params['add_user_name'].'%')->column('id');
$where[] = ['add_user_id','in',$adminIds];
}
return ProjectLogs::where($this->searchWhere)->where($where)
->field(['id','project_id','content','annex','add_user_id','create_time'])
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()->each(function($item){
$project = Project::field('name,project_code')->where('id',$item['project_id'])->findOrEmpty();
$admin = Admin::field('name')->where('id',$item['add_user_id'])->findOrEmpty();
$item['project_name'] = $project['name'];
$item['project_code'] = $project['project_code'];
$item['add_user_name'] = $admin['name'];
return $item;
})
->toArray();
}
/**
* @notes 获取项目日志管理数量
* @return int
* @author likeadmin
* @date 2023/12/14 09:17
*/
public function count(): int
{
$params = $this->request->param();
$where = [];
if(isset($params['project_name']) && $params['project_name'] != ''){
$projectIds = Project::where('name','like','%'.$params['project_name'].'%')->column('id');
$where[] = ['project_id','in',$projectIds];
}
if(isset($params['add_user_name']) && $params['add_user_name'] != ''){
$adminIds = Admin::where('name','like','%'.$params['add_user_name'].'%')->column('id');
$where[] = ['add_user_id','in',$adminIds];
}
return ProjectLogs::where($this->searchWhere)->where($where)->count();
}
}

View File

@ -0,0 +1,121 @@
<?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\project;
use app\common\model\project\ProjectLogs;
use app\common\logic\BaseLogic;
use think\facade\Db;
/**
* 项目日志管理逻辑
* Class ProjectLogsLogic
* @package app\adminapi\logic\project
*/
class ProjectLogsLogic extends BaseLogic
{
/**
* @notes 添加项目日志管理
* @param array $params
* @return bool
* @author likeadmin
* @date 2023/12/14 09:17
*/
public static function add(array $params, $adminId = ''): bool
{
Db::startTrans();
try {
ProjectLogs::create([
'project_id' => $params['project_id'],
'theme' => $params['theme'],
'contacts' => $params['contacts'],
'date' => strtotime($params['date']),
'follow_type' => $params['follow_type'],
'executor' => $params['executor'],
'content' => $params['content'],
'annex' => $params['annex'],
'next_follow_up_date' => strtotime($params['next_follow_up_date']),
'add_user_id' => $adminId,
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 编辑项目日志管理
* @param array $params
* @return bool
* @author likeadmin
* @date 2023/12/14 09:17
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
ProjectLogs::where('id', $params['id'])->update([
'project_id' => $params['project_id'],
'theme' => $params['theme'],
'contacts' => $params['contacts'],
'date' => strtotime($params['date']),
'follow_type' => $params['follow_type'],
'executor' => $params['executor'],
'content' => $params['content'],
'annex' => $params['annex'],
'next_follow_up_date' => strtotime($params['next_follow_up_date']),
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 删除项目日志管理
* @param array $params
* @return bool
* @author likeadmin
* @date 2023/12/14 09:17
*/
public static function delete(array $params): bool
{
return ProjectLogs::destroy($params['id']);
}
/**
* @notes 获取项目日志管理详情
* @param $params
* @return array
* @author likeadmin
* @date 2023/12/14 09:17
*/
public static function detail($params): array
{
return ProjectLogs::findOrEmpty($params['id'])->toArray();
}
}

View File

@ -0,0 +1,149 @@
<?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\project;
use app\common\model\dict\DictData;
use app\common\model\project\Project;
use app\common\model\project\ProjectLogs;
use app\common\validate\BaseValidate;
/**
* 项目日志管理验证器
* Class ProjectLogsValidate
* @package app\adminapi\validate\project
*/
class ProjectLogsValidate extends BaseValidate
{
/**
* 设置校验规则
* @var string[]
*/
protected $rule = [
'id' => 'require|checkLog',
'project_id' => 'require|checkProject',
'theme' => 'require',
'date' => 'require|date',
'follow_type' => 'checkFollowType',
'next_follow_up_date' => 'date|checkNextFollowUpDate',
];
protected $message = [
'id.require' => '缺少必要参数',
'project_id.require' => '请选择项目',
'theme.require' => '主题不能为空',
'date.require' => '日期不能为空',
'date.date' => '日期格式不正确',
'next_follow_up_date.date' => '下次跟进时间格式不正确',
];
/**
* 参数描述
* @var string[]
*/
protected $field = [
'id' => 'id',
'project_id' => '项目名称',
'theme' => '主题',
'date' => '日期',
];
/**
* @notes 添加场景
* @return ProjectLogsValidate
* @author likeadmin
* @date 2023/12/14 09:17
*/
public function sceneAdd()
{
return $this->remove('id',true);
}
/**
* @notes 编辑场景
* @return ProjectLogsValidate
* @author likeadmin
* @date 2023/12/14 09:17
*/
public function sceneEdit()
{}
/**
* @notes 删除场景
* @return ProjectLogsValidate
* @author likeadmin
* @date 2023/12/14 09:17
*/
public function sceneDelete()
{
return $this->only(['id']);
}
/**
* @notes 详情场景
* @return ProjectLogsValidate
* @author likeadmin
* @date 2023/12/14 09:17
*/
public function sceneDetail()
{
return $this->only(['id']);
}
public function checkLog($value): bool|string
{
$data = ProjectLogs::where('id',$value)->findOrEmpty();
if($data->isEmpty()){
return '数据不存在';
}
return true;
}
public function checkProject($value): bool|string
{
$project = Project::where('id',$value)->findOrEmpty();
if($project->isEmpty()){
return '项目不存在';
}
return true;
}
public function checkFollowType($value): bool|string
{
$dictDate = DictData::where('type_value','follow_type')->column('value');
if(!in_array($value,$dictDate)){
return '类型不存在';
}
return true;
}
public function checkNextFollowUpDate($value,$rule,$data): bool|string
{
$a = strtotime($value);
$b = strtotime($data['date']);
if($a < $b){
return '下次跟进时间不能小于日志日期';
}
return true;
}
}

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\project;
use app\common\model\BaseModel;
use think\model\concern\SoftDelete;
/**
* 项目日志管理模型
* Class ProjectLogs
* @package app\common\model\project
*/
class ProjectLogs extends BaseModel
{
use SoftDelete;
protected $name = 'project_logs';
protected $deleteTime = 'delete_time';
}