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); } }