66 lines
2.4 KiB
PHP
66 lines
2.4 KiB
PHP
<?php
|
||
/**
|
||
* 硬碎片新增接口 POST /api/fragment/hard_add.php
|
||
* 入参:source_type(company|person|product|need|mixed,必填)/
|
||
* company_name / person_name / contact_phone / contact_email /
|
||
* target_product_category / description / source_channel
|
||
* 写入 preliminary_data,status=待处理,recorded_by=当前登录用户
|
||
*/
|
||
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('preliminary');
|
||
|
||
$sourceType = trim($_POST['source_type'] ?? '');
|
||
if (!in_array($sourceType, ['company', 'person', 'product', 'need', 'mixed'], true)) {
|
||
Response::error('碎片类型(source_type)为必填项', 400);
|
||
}
|
||
|
||
$companyName = trim($_POST['company_name'] ?? '');
|
||
$personName = trim($_POST['person_name'] ?? '');
|
||
$phone = trim($_POST['contact_phone'] ?? '');
|
||
$email = trim($_POST['contact_email'] ?? '');
|
||
$category = trim($_POST['target_product_category'] ?? '');
|
||
$description = trim($_POST['description'] ?? '');
|
||
$sourceChannel = trim($_POST['source_channel'] ?? '');
|
||
if ($sourceChannel === '') {
|
||
$sourceChannel = '手动录入';
|
||
}
|
||
|
||
// 至少有一项内容才能录为碎片
|
||
if ($companyName === '' && $personName === '' && $phone === '' && $email === '' && $category === '' && $description === '') {
|
||
Response::error('请至少填写一项内容', 400);
|
||
}
|
||
|
||
$pdo = DB::getInstance()->getPdo();
|
||
$pdo->prepare(
|
||
"INSERT INTO preliminary_data
|
||
(source_type, company_name, person_name, contact_phone, contact_email,
|
||
target_product_category, description, source_channel, recorded_by, status)
|
||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, '待处理')"
|
||
)->execute([
|
||
$sourceType,
|
||
$companyName !== '' ? $companyName : null,
|
||
$personName !== '' ? $personName : null,
|
||
$phone !== '' ? $phone : null,
|
||
$email !== '' ? $email : null,
|
||
$category !== '' ? $category : null,
|
||
$description !== '' ? $description : null,
|
||
$sourceChannel,
|
||
$_SESSION['username'] ?? null,
|
||
]);
|
||
$newId = (int)$pdo->lastInsertId();
|
||
|
||
logCurrent('add', 'fragment', 'preliminary_data', $newId, [
|
||
'source_type' => $sourceType,
|
||
'company_name' => $companyName,
|
||
'person_name' => $personName,
|
||
'phone' => $phone,
|
||
'email' => $email,
|
||
]);
|
||
|
||
Response::success(['id' => $newId], '新增成功');
|