智慧教务系统
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

151 lines
4.7 KiB

<?php
// +----------------------------------------------------------------------
// | Niucloud-admin 企业快速开发的多应用管理平台
// +----------------------------------------------------------------------
// | 官方网址:https://www.niucloud.com
// +----------------------------------------------------------------------
// | niucloud团队 版权所有 开源版本可自由商用
// +----------------------------------------------------------------------
// | Author: Niucloud Team
// +----------------------------------------------------------------------
namespace app\adminapi\controller\contract;
use core\base\BaseAdminController;
use app\service\admin\contract\ContractDistributionService;
use think\Response;
/**
* 合同分发控制器
* Class ContractDistribution
* @package app\adminapi\controller\contract
*/
class ContractDistribution extends BaseAdminController
{
/**
* 获取分发记录列表
* @return Response
*/
public function lists(): Response
{
$data = $this->request->params([
['contract_id', 0],
['personnel_id', 0],
['type', 0],
['status', ''],
['source_type', ''],
['page', 1],
['limit', 20]
]);
return success((new ContractDistributionService())->getDistributionList($data));
}
/**
* 手动分发合同
* @return Response
*/
public function manualDistribute(): Response
{
$data = $this->request->params([
['contract_id', 0],
['personnel_ids', []],
['type', 1]
]);
$this->validate($data, 'app\validate\contract\ContractDistribution.manualDistribute');
(new ContractDistributionService())->manualDistribute(
$data['contract_id'],
$data['personnel_ids'],
$data['type']
);
return success('DISTRIBUTE_SUCCESS');
}
/**
* 批量分发合同
* @return Response
*/
public function batchDistribute(): Response
{
$data = $this->request->params([
['distributions', []]
]);
$this->validate($data, 'app\validate\contract\ContractDistribution.batchDistribute');
(new ContractDistributionService())->batchDistribute($data['distributions']);
return success('BATCH_DISTRIBUTE_SUCCESS');
}
/**
* 取消分发
* @param int $id
* @return Response
*/
public function cancelDistribution(int $id): Response
{
(new ContractDistributionService())->cancelDistribution($id);
return success('CANCEL_SUCCESS');
}
/**
* 获取可分发人员列表
* @return Response
*/
public function getAvailablePersonnel(): Response
{
$type = $this->request->param('type', 1);
if ($type == 1) {
// 内部员工 - 从school_personnel表查询
$personnel = \think\facade\Db::table('school_personnel')
->where('status', 1)
->where('deleted_at', 0)
->field('id, name, phone, email, account_type as role')
->select()
->toArray();
// 处理数据格式,添加部门信息
foreach ($personnel as &$person) {
$person['department'] = $person['role'] === 'teacher' ? '教务部' : '销售部';
$person['role'] = $person['role'] === 'teacher' ? '教师' : '销售';
}
} else {
// 外部会员
$personnel = \think\facade\Db::table('member')
->where('status', 1)
->field('member_id as id, nickname as name, mobile as phone, email')
->select()
->toArray();
}
return success($personnel);
}
/**
* 获取分发统计信息
* @return Response
*/
public function getDistributionStats(): Response
{
$contractId = $this->request->param('contract_id', 0);
$where = [];
if ($contractId) {
$where[] = ['contract_id', '=', $contractId];
}
$stats = [
'total' => \app\model\contract_sign\ContractSign::where($where)->count(),
'pending' => \app\model\contract_sign\ContractSign::where($where)->where('status', 'pending')->count(),
'signed' => \app\model\contract_sign\ContractSign::where($where)->where('status', 'signed')->count(),
'rejected' => \app\model\contract_sign\ContractSign::where($where)->where('status', 'rejected')->count(),
];
return success($stats);
}
}