v1.0.10
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
/**
|
||||
* 需求新增接口 POST /api/need/add.php
|
||||
* 必填:company_id;可选白名单字段见 NEED_FIELDS
|
||||
*/
|
||||
require_once __DIR__ . '/../common/db.php';
|
||||
require_once __DIR__ . '/../common/response.php';
|
||||
require_once __DIR__ . '/../common/auth.php';
|
||||
require_once __DIR__ . '/../common/logger.php';
|
||||
require_once __DIR__ . '/../common/helpers.php';
|
||||
|
||||
checkAjax();
|
||||
checkPermission('need');
|
||||
|
||||
$data = extractFields(NEED_FIELDS);
|
||||
if (empty($data['company_id'])) {
|
||||
Response::error('所属公司(company_id)为必填项', 400);
|
||||
}
|
||||
|
||||
$pdo = DB::getInstance()->getPdo();
|
||||
$chk = $pdo->prepare("SELECT COUNT(*) FROM companies WHERE id = ?");
|
||||
$chk->execute([$data['company_id']]);
|
||||
if ((int)$chk->fetchColumn() === 0) {
|
||||
Response::error('所属公司不存在', 400);
|
||||
}
|
||||
|
||||
[$sql, $params] = buildInsert($data);
|
||||
$pdo->prepare("INSERT INTO company_needs $sql")->execute($params);
|
||||
$newId = (int)$pdo->lastInsertId();
|
||||
|
||||
logCurrent('add', 'need', 'company_needs', $newId, $data);
|
||||
Response::success(['id' => $newId], '新增成功');
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
/**
|
||||
* 需求删除接口(作废) POST /api/need/delete.php
|
||||
* 入参:id(或 ids 逗号分隔批量)
|
||||
*/
|
||||
require_once __DIR__ . '/../common/db.php';
|
||||
require_once __DIR__ . '/../common/response.php';
|
||||
require_once __DIR__ . '/../common/auth.php';
|
||||
require_once __DIR__ . '/../common/logger.php';
|
||||
|
||||
checkAjax();
|
||||
checkPermission('need');
|
||||
|
||||
$id = (int)($_POST['id'] ?? 0);
|
||||
$ids = trim($_POST['ids'] ?? '');
|
||||
$idList = [];
|
||||
if ($id > 0) $idList[] = $id;
|
||||
if ($ids !== '') {
|
||||
foreach (explode(',', $ids) as $v) {
|
||||
$v = (int)trim($v);
|
||||
if ($v > 0) $idList[] = $v;
|
||||
}
|
||||
}
|
||||
$idList = array_unique($idList);
|
||||
if (!$idList) {
|
||||
Response::error('参数错误', 400);
|
||||
}
|
||||
|
||||
$pdo = DB::getInstance()->getPdo();
|
||||
$in = implode(',', array_fill(0, count($idList), '?'));
|
||||
$stmt = $pdo->prepare("UPDATE company_needs SET is_valid = 0 WHERE id IN ($in)");
|
||||
$stmt->execute($idList);
|
||||
$affected = $stmt->rowCount();
|
||||
|
||||
logCurrent('delete', 'need', 'company_needs', null, ['ids' => $idList]);
|
||||
Response::success(['affected' => $affected], "已作废 $affected 条需求");
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
/**
|
||||
* 需求详情接口 GET /api/need/detail.php?id=1
|
||||
*/
|
||||
require_once __DIR__ . '/../common/db.php';
|
||||
require_once __DIR__ . '/../common/response.php';
|
||||
require_once __DIR__ . '/../common/auth.php';
|
||||
|
||||
checkPermission('need');
|
||||
|
||||
$id = (int)($_REQUEST['id'] ?? 0);
|
||||
if ($id <= 0) {
|
||||
Response::error('参数错误', 400);
|
||||
}
|
||||
|
||||
$pdo = DB::getInstance()->getPdo();
|
||||
$stmt = $pdo->prepare(
|
||||
"SELECT cn.*, c.display_name, c.industry, c.country, c.website
|
||||
FROM company_needs cn
|
||||
LEFT JOIN companies c ON c.id = cn.company_id
|
||||
WHERE cn.id = ?"
|
||||
);
|
||||
$stmt->execute([$id]);
|
||||
$need = $stmt->fetch();
|
||||
if (!$need) {
|
||||
Response::error('需求不存在');
|
||||
}
|
||||
|
||||
Response::success(['need' => $need]);
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
/**
|
||||
* 需求转盘列表接口 GET/POST /api/need/list.php
|
||||
* 参数:page / limit / keyword / start_date / end_date / company_name / industry / need_category / is_valid
|
||||
*/
|
||||
require_once __DIR__ . '/../common/db.php';
|
||||
require_once __DIR__ . '/../common/response.php';
|
||||
require_once __DIR__ . '/../common/auth.php';
|
||||
|
||||
checkPermission('need');
|
||||
|
||||
[$page, $limit] = pageParams();
|
||||
$keyword = trim($_REQUEST['keyword'] ?? '');
|
||||
$startDate = trim($_REQUEST['start_date'] ?? '');
|
||||
$endDate = trim($_REQUEST['end_date'] ?? '');
|
||||
$companyName = trim($_REQUEST['company_name'] ?? '');
|
||||
$industry = trim($_REQUEST['industry'] ?? '');
|
||||
$category = trim($_REQUEST['need_category'] ?? '');
|
||||
$valid = isset($_REQUEST['is_valid']) && $_REQUEST['is_valid'] !== '' ? (int)$_REQUEST['is_valid'] : null;
|
||||
|
||||
$where = ['cn.is_valid = 1'];
|
||||
$params = [];
|
||||
if ($valid !== null) {
|
||||
$where = ['cn.is_valid = ?'];
|
||||
$params = [$valid];
|
||||
}
|
||||
if ($keyword !== '') {
|
||||
$where[] = '(cn.description LIKE ? OR cn.contact_person LIKE ? OR c.display_name LIKE ?)';
|
||||
$like = "%$keyword%";
|
||||
array_push($params, $like, $like, $like);
|
||||
}
|
||||
if ($startDate !== '') { $where[] = 'DATE(cn.created_at) >= ?'; $params[] = $startDate; }
|
||||
if ($endDate !== '') { $where[] = 'DATE(cn.created_at) <= ?'; $params[] = $endDate; }
|
||||
if ($companyName !== '') { $where[] = 'c.display_name LIKE ?'; $params[] = "%$companyName%"; }
|
||||
if ($industry !== '') { $where[] = 'c.industry = ?'; $params[] = $industry; }
|
||||
if ($category !== '') { $where[] = 'cn.need_category = ?'; $params[] = $category; }
|
||||
$whereSql = implode(' AND ', $where);
|
||||
|
||||
$pdo = DB::getInstance()->getPdo();
|
||||
|
||||
$stmt = $pdo->prepare(
|
||||
"SELECT COUNT(*) FROM company_needs cn LEFT JOIN companies c ON c.id = cn.company_id WHERE $whereSql"
|
||||
);
|
||||
$stmt->execute($params);
|
||||
$total = (int)$stmt->fetchColumn();
|
||||
|
||||
$offset = ($page - 1) * $limit;
|
||||
$stmt = $pdo->prepare(
|
||||
"SELECT cn.id, cn.company_id, c.display_name, c.industry, cn.contact_person,
|
||||
cn.need_category, cn.target_product_category, cn.application_scenario,
|
||||
cn.description, cn.is_valid, cn.created_at
|
||||
FROM company_needs cn
|
||||
LEFT JOIN companies c ON c.id = cn.company_id
|
||||
WHERE $whereSql
|
||||
ORDER BY cn.id DESC
|
||||
LIMIT $limit OFFSET $offset"
|
||||
);
|
||||
$stmt->execute($params);
|
||||
$list = $stmt->fetchAll();
|
||||
|
||||
Response::success(['list' => $list, 'total' => $total, 'page' => $page, 'limit' => $limit]);
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
/**
|
||||
* 需求推送接口(占位) POST /api/need/push.php
|
||||
* 入参:id(或 ids 逗号分隔)
|
||||
* 说明:当前为占位实现,仅写日志并返回成功;
|
||||
* 后续可扩展为调用第三方API推送JSON数据 / 通过SMTP发送邮件。
|
||||
*/
|
||||
require_once __DIR__ . '/../common/db.php';
|
||||
require_once __DIR__ . '/../common/response.php';
|
||||
require_once __DIR__ . '/../common/auth.php';
|
||||
require_once __DIR__ . '/../common/logger.php';
|
||||
|
||||
checkAjax();
|
||||
checkPermission('need');
|
||||
|
||||
$id = (int)($_POST['id'] ?? 0);
|
||||
$ids = trim($_POST['ids'] ?? '');
|
||||
$idList = [];
|
||||
if ($id > 0) $idList[] = $id;
|
||||
if ($ids !== '') {
|
||||
foreach (explode(',', $ids) as $v) {
|
||||
$v = (int)trim($v);
|
||||
if ($v > 0) $idList[] = $v;
|
||||
}
|
||||
}
|
||||
$idList = array_unique($idList);
|
||||
if (!$idList) {
|
||||
Response::error('参数错误', 400);
|
||||
}
|
||||
|
||||
$pdo = DB::getInstance()->getPdo();
|
||||
$in = implode(',', array_fill(0, count($idList), '?'));
|
||||
$stmt = $pdo->prepare("SELECT id, company_id FROM company_needs WHERE id IN ($in) AND is_valid = 1");
|
||||
$stmt->execute($idList);
|
||||
$needs = $stmt->fetchAll();
|
||||
|
||||
if (!$needs) {
|
||||
Response::error('没有可推送的有效需求');
|
||||
}
|
||||
|
||||
// TODO: 在此接入第三方API推送 / SMTP邮件发送
|
||||
// 示例:
|
||||
// foreach ($needs as $n) { sendToThirdParty($n); sendEmail($n); }
|
||||
|
||||
logCurrent('push', 'need', 'company_needs', null, ['ids' => $idList, 'count' => count($needs)]);
|
||||
Response::success(['count' => count($needs)], "已推送 " . count($needs) . " 条需求(占位实现,后续接入第三方API/邮件)");
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
/**
|
||||
* 需求编辑接口 POST /api/need/update.php
|
||||
* 入参:id + 白名单字段(可含 is_valid 作废/恢复)
|
||||
*/
|
||||
require_once __DIR__ . '/../common/db.php';
|
||||
require_once __DIR__ . '/../common/response.php';
|
||||
require_once __DIR__ . '/../common/auth.php';
|
||||
require_once __DIR__ . '/../common/logger.php';
|
||||
require_once __DIR__ . '/../common/helpers.php';
|
||||
|
||||
checkAjax();
|
||||
checkPermission('need');
|
||||
|
||||
$id = (int)($_POST['id'] ?? 0);
|
||||
if ($id <= 0) {
|
||||
Response::error('参数错误', 400);
|
||||
}
|
||||
|
||||
// is_valid 允许单独传
|
||||
$data = extractFields(NEED_FIELDS);
|
||||
if (isset($_POST['is_valid']) && $_POST['is_valid'] !== '') {
|
||||
$data['is_valid'] = (int)$_POST['is_valid'] ? 1 : 0;
|
||||
}
|
||||
if (empty($data)) {
|
||||
Response::error('没有需要更新的字段', 400);
|
||||
}
|
||||
|
||||
$pdo = DB::getInstance()->getPdo();
|
||||
$check = $pdo->prepare("SELECT * FROM company_needs WHERE id = ?");
|
||||
$check->execute([$id]);
|
||||
$old = $check->fetch();
|
||||
if (!$old) {
|
||||
Response::error('需求不存在');
|
||||
}
|
||||
|
||||
[$sets, $params] = buildUpdate($data);
|
||||
$params[] = $id;
|
||||
$pdo->prepare("UPDATE company_needs SET $sets WHERE id = ?")->execute($params);
|
||||
|
||||
logCurrent('update', 'need', 'company_needs', $id, ['before' => $old, 'after' => $data]);
|
||||
Response::success(null, '更新成功');
|
||||
Reference in New Issue
Block a user