This commit is contained in:
yaooo 2023-12-11 16:31:40 +08:00
commit e5fc0c2ffe
4 changed files with 185 additions and 17 deletions

View File

@ -16,6 +16,9 @@ namespace app\adminapi\lists\project;
use app\adminapi\lists\BaseAdminDataLists; use app\adminapi\lists\BaseAdminDataLists;
use app\common\model\auth\Admin;
use app\common\model\custom\Custom;
use app\common\model\project\Project;
use app\common\model\project\ProjectFollowUp; use app\common\model\project\ProjectFollowUp;
use app\common\lists\ListsSearchInterface; use app\common\lists\ListsSearchInterface;
@ -38,7 +41,8 @@ class ProjectFollowUpLists extends BaseAdminDataLists implements ListsSearchInte
public function setSearch(): array public function setSearch(): array
{ {
return [ return [
'=' => ['project_id', 'executor', 'contacts', 'contact_information', 'project_role', 'position', 'follow_date', 'follow_type', 'theme', 'action_description', 'project_assurance', 'follow_status', 'follow_stage', 'notes', 'next_follow_up_date', 'ceate_time'], '=' => ['follow_type', 'project_assurance', 'follow_status', 'follow_stage'],
'%like%' => ['theme','contacts','contact_information'],
]; ];
} }
@ -54,11 +58,40 @@ class ProjectFollowUpLists extends BaseAdminDataLists implements ListsSearchInte
*/ */
public function lists(): array public function lists(): array
{ {
return ProjectFollowUp::where($this->searchWhere) $params = $this->request->param();
->field(['id', 'project_id', 'executor', 'contacts', 'contact_information', 'project_role', 'position', 'follow_date', 'follow_type', 'theme', 'action_description', 'project_assurance', 'follow_status', 'follow_stage', 'notes', 'next_follow_up_date', 'ceate_time']) $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['custom_name']) && $params['custom_name'] != ''){
$customIds = Custom::where('name','like','%'.$params['custom_name'].'%')->column('id');
$projectIds = Project::where('custom_id','in',$customIds)->column('id');
$where[] = ['project_id','in',$projectIds];
}
if(isset($params['executor']) && $params['executor'] != ''){
$adminIds = Admin::where('name','like','%'.$params['executor'].'%')->column('id');
$where[] = ['executor','in',$adminIds];
}
return ProjectFollowUp::where($this->searchWhere)->where($where)
->field(['id', 'project_id', 'executor', 'follow_date', 'follow_type', 'theme', 'project_assurance', 'follow_status', 'follow_stage', 'next_follow_up_date', 'create_time'])
->limit($this->limitOffset, $this->limitLength) ->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc']) ->order(['id' => 'desc'])
->select() ->select()->each(function($item){
$item['follow_type_text'] = $item->follow_type_text;
$item['project_assurance_text'] = $item->project_assurance_text;
$item['follow_status_text'] = $item->follow_status_text;
$item['follow_stage_text'] = $item->follow_stage_text;
$item['follow_date'] = !empty($item['follow_date']) ? date('Y-m-d',$item['follow_date']) : '';
$item['next_follow_up_date'] = !empty($item['next_follow_up_date']) ? date('Y-m-d',$item['next_follow_up_date']) : '';
$project = Project::field('id,custom_id,name')->where('id',$item['project_id'])->findOrEmpty();
$custom = Custom::field('name')->where('id',$project['custom_id'])->findOrEmpty();
$executor = Admin::field('name')->where('id',$item['executor'])->findOrEmpty();
$item['executor'] = $executor['name'];
$item['project_name'] = $project['name'];
$item['custom_name'] = $custom['name'];
return $item;
})
->toArray(); ->toArray();
} }
@ -71,7 +104,22 @@ class ProjectFollowUpLists extends BaseAdminDataLists implements ListsSearchInte
*/ */
public function count(): int public function count(): int
{ {
return ProjectFollowUp::where($this->searchWhere)->count(); $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['custom_name']) && $params['custom_name'] != ''){
$customIds = Custom::where('name','like','%'.$params['custom_name'].'%')->column('id');
$projectIds = Project::where('custom_id','in',$customIds)->column('id');
$where[] = ['project_id','in',$projectIds];
}
if(isset($params['executor']) && $params['executor'] != ''){
$adminIds = Admin::where('name','like','%'.$params['executor'].'%')->column('id');
$where[] = ['executor','in',$adminIds];
}
return ProjectFollowUp::where($this->searchWhere)->where($where)->count();
} }
} }

View File

@ -15,6 +15,9 @@
namespace app\adminapi\logic\project; namespace app\adminapi\logic\project;
use app\common\model\auth\Admin;
use app\common\model\custom\Custom;
use app\common\model\project\Project;
use app\common\model\project\ProjectFollowUp; use app\common\model\project\ProjectFollowUp;
use app\common\logic\BaseLogic; use app\common\logic\BaseLogic;
use think\facade\Db; use think\facade\Db;
@ -28,7 +31,6 @@ use think\facade\Db;
class ProjectFollowUpLogic extends BaseLogic class ProjectFollowUpLogic extends BaseLogic
{ {
/** /**
* @notes 添加 * @notes 添加
* @param array $params * @param array $params
@ -56,9 +58,8 @@ class ProjectFollowUpLogic extends BaseLogic
'follow_stage' => $params['follow_stage'], 'follow_stage' => $params['follow_stage'],
'notes' => $params['notes'], 'notes' => $params['notes'],
'next_follow_up_date' => strtotime($params['next_follow_up_date']), 'next_follow_up_date' => strtotime($params['next_follow_up_date']),
'ceate_time' => $params['ceate_time'] 'file' => $params['file']
]); ]);
Db::commit(); Db::commit();
return true; return true;
} catch (\Exception $e) { } catch (\Exception $e) {
@ -96,9 +97,8 @@ class ProjectFollowUpLogic extends BaseLogic
'follow_stage' => $params['follow_stage'], 'follow_stage' => $params['follow_stage'],
'notes' => $params['notes'], 'notes' => $params['notes'],
'next_follow_up_date' => strtotime($params['next_follow_up_date']), 'next_follow_up_date' => strtotime($params['next_follow_up_date']),
'ceate_time' => $params['ceate_time'] 'file' => $params['file']
]); ]);
Db::commit(); Db::commit();
return true; return true;
} catch (\Exception $e) { } catch (\Exception $e) {
@ -131,6 +131,21 @@ class ProjectFollowUpLogic extends BaseLogic
*/ */
public static function detail($params): array public static function detail($params): array
{ {
return ProjectFollowUp::findOrEmpty($params['id'])->toArray(); $data = ProjectFollowUp::findOrEmpty($params['id']);
$data['follow_type_text'] = $data->follow_type_text;
$data['project_assurance_text'] = $data->project_assurance_text;
$data['follow_status_text'] = $data->follow_status_text;
$data['follow_stage_text'] = $data->follow_stage_text;
$data['follow_date'] = !empty($data['follow_date']) ? date('Y-m-d',$data['follow_date']) : '';
$data['next_follow_up_date'] = !empty($data['next_follow_up_date']) ? date('Y-m-d',$data['next_follow_up_date']) : '';
$project = Project::field('id,custom_id,name,project_code')->where('id',$data['project_id'])->findOrEmpty();
$custom = Custom::field('name')->where('id',$project['custom_id'])->findOrEmpty();
$executor = Admin::field('name')->where('id',$data['executor'])->findOrEmpty();
$data['executor'] = $executor['name'];
$data['project_name'] = $project['name'];
$data['project_code'] = $project['project_code'];
$data['custom_name'] = $custom['name'];
unset($data['delete_time']);
return $data->toArray();
} }
} }

View File

@ -15,6 +15,9 @@
namespace app\adminapi\validate\project; namespace app\adminapi\validate\project;
use app\common\model\auth\Admin;
use app\common\model\dict\DictData;
use app\common\model\project\Project;
use app\common\validate\BaseValidate; use app\common\validate\BaseValidate;
@ -32,8 +35,31 @@ class ProjectFollowUpValidate extends BaseValidate
*/ */
protected $rule = [ protected $rule = [
'id' => 'require', 'id' => 'require',
'project_id' => 'require|checkProject',
'executor' => 'require|integer|checkExecutor',
'theme' => 'require',
'follow_date' => 'require|date',
'follow_type' => 'require|checkType',
'project_assurance' => 'require|checkAssurance',
'follow_status' => 'require|checkStatus',
'follow_stage' => 'require|checkStage',
'next_follow_up_date' => 'date|checkDate'
]; ];
protected $message = [
'id.require' => '缺少必要参数',
'project_id.require' => '请选择项目',
'executor.require' => '请选择执行人',
'executor.integer' => '执行人数据格式错误',
'theme.require' => '请填写主题',
'follow_date.require' => '请选择日期',
'follow_date.date' => '日期格式错误',
'follow_type.require' => '请选择类型',
'project_assurance.require' => '请选择项目把握度',
'follow_status.require' => '请选择状态',
'follow_stage.require' => '请选择阶段',
'next_follow_up_date.date' => '下次回访日期格式错误'
];
/** /**
* 参数描述 * 参数描述
@ -64,7 +90,7 @@ class ProjectFollowUpValidate extends BaseValidate
*/ */
public function sceneEdit() public function sceneEdit()
{ {
return $this->only(['id']);
} }
@ -91,4 +117,60 @@ class ProjectFollowUpValidate extends BaseValidate
return $this->only(['id']); return $this->only(['id']);
} }
public function checkProject($value): bool|string
{
$project = Project::where('id',$value)->findOrEmpty();
if($project->isEmpty()){
return '项目不存在';
}
return true;
}
public function checkExecutor($value): bool|string
{
$admin = Admin::where('id',$value)->findOrEmpty();
if($admin->isEmpty()){
return '执行人不存在';
}
return true;
}
public function checkType($value): bool|string
{
$dictData = DictData::where('type_value','follow_type')->column('value');
if(!in_array($value,$dictData)){
return '类型值错误';
}
return true;
}
public function checkAssurance($value): bool|string
{
$dictData = DictData::where('type_value','project_assurance')->column('value');
if(!in_array($value,$dictData)){
return '项目把握度值错误';
}
return true;
}
public function checkStatus($value): bool|string
{
$dictData = DictData::where('type_value','follow_status')->column('value');
if(!in_array($value,$dictData)){
return '状态值错误';
}
return true;
}
public function checkStage($value): bool|string
{
$dictData = DictData::where('type_value','follow_stage')->column('value');
if(!in_array($value,$dictData)){
return '阶段值错误';
}
return true;
}
public function checkDate($value,$rule,$data) {
if(strtotime($value) < strtotime($data['follow_date'])){
return '下次回访日期不能小于项目跟进日期';
}
return true;
}
} }

View File

@ -16,6 +16,7 @@ namespace app\common\model\project;
use app\common\model\BaseModel; use app\common\model\BaseModel;
use app\common\model\dict\DictData;
use think\model\concern\SoftDelete; use think\model\concern\SoftDelete;
@ -30,5 +31,27 @@ class ProjectFollowUp extends BaseModel
protected $name = 'project_follow_up'; protected $name = 'project_follow_up';
protected $deleteTime = 'delete_time'; protected $deleteTime = 'delete_time';
public function getFollowTypeTextAttr($value,$data)
{
$dictData = DictData::where('type_value','follow_type')->column('name','value');
return $dictData[$data['follow_type']];
}
public function getProjectAssuranceTextAttr($value,$data)
{
$dictData = DictData::where('type_value','project_assurance')->column('name','value');
return $dictData[$data['project_assurance']];
}
public function getFollowStatusTextAttr($value,$data)
{
$dictData = DictData::where('type_value','follow_status')->column('name','value');
return $dictData[$data['follow_status']];
}
public function getFollowStageTextAttr($value,$data)
{
$dictData = DictData::where('type_value','follow_stage')->column('name','value');
return $dictData[$data['follow_stage']];
}
} }