1
This commit is contained in:
@@ -170,7 +170,7 @@ module.exports = {
|
||||
* /api/user/delivery-config/get:
|
||||
* post:
|
||||
* summary: 获取投递配置
|
||||
* description: 根据设备SN码获取用户的投递配置,返回 account_config 表中的 auto_deliver_config 对象
|
||||
* description: 根据设备SN码获取用户的投递配置,返回 pla_account 表中的 deliver_config 对象
|
||||
* tags: [前端-用户管理]
|
||||
* requestBody:
|
||||
* required: true
|
||||
@@ -201,7 +201,7 @@ module.exports = {
|
||||
* data:
|
||||
* type: object
|
||||
* properties:
|
||||
* auto_deliver_config:
|
||||
* deliver_config:
|
||||
* type: object
|
||||
* description: 自动投递配置对象,如果不存在则返回 null
|
||||
* nullable: true
|
||||
@@ -217,7 +217,7 @@ module.exports = {
|
||||
return ctx.fail('请提供设备SN码');
|
||||
}
|
||||
|
||||
const { pla_account, account_config } = await Framework.getModels();
|
||||
const { pla_account } = await Framework.getModels();
|
||||
|
||||
// 根据 sn_code 查找账号
|
||||
const user = await pla_account.findOne({
|
||||
@@ -228,15 +228,10 @@ module.exports = {
|
||||
return ctx.fail('用户不存在');
|
||||
}
|
||||
|
||||
// 从 account_config 表获取配置
|
||||
const accountConfig = await account_config.findOne({
|
||||
where: { account_id: user.id }
|
||||
});
|
||||
// 从 pla_account 表的 deliver_config 字段获取配置
|
||||
const deliver_config = user.deliver_config || null;
|
||||
|
||||
// 直接返回 auto_deliver_config 对象
|
||||
const auto_deliver_config = accountConfig?.auto_deliver_config || null;
|
||||
|
||||
return ctx.success({ auto_deliver_config });
|
||||
return ctx.success({ deliver_config });
|
||||
} catch (error) {
|
||||
console.error('获取投递配置失败:', error);
|
||||
return ctx.fail('获取投递配置失败: ' + error.message);
|
||||
@@ -248,7 +243,7 @@ module.exports = {
|
||||
* /api/user/delivery-config/save:
|
||||
* post:
|
||||
* summary: 保存投递配置
|
||||
* description: 根据设备SN码保存用户的投递配置到 account_config 表的 auto_deliver_config 字段
|
||||
* description: 根据设备SN码保存用户的投递配置到 pla_account 表的 deliver_config 字段
|
||||
* tags: [前端-用户管理]
|
||||
* requestBody:
|
||||
* required: true
|
||||
@@ -258,12 +253,12 @@ module.exports = {
|
||||
* type: object
|
||||
* required:
|
||||
* - sn_code
|
||||
* - auto_deliver_config
|
||||
* - deliver_config
|
||||
* properties:
|
||||
* sn_code:
|
||||
* type: string
|
||||
* description: 设备SN码
|
||||
* auto_deliver_config:
|
||||
* deliver_config:
|
||||
* type: object
|
||||
* description: 自动投递配置对象
|
||||
* properties:
|
||||
@@ -308,18 +303,18 @@ module.exports = {
|
||||
try {
|
||||
console.log('[User Controller] 收到保存投递配置请求');
|
||||
const body = ctx.getBody();
|
||||
const { sn_code, auto_deliver_config } = body;
|
||||
console.log('[User Controller] sn_code:', sn_code, 'auto_deliver_config:', JSON.stringify(auto_deliver_config));
|
||||
const { sn_code, deliver_config } = body;
|
||||
console.log('[User Controller] sn_code:', sn_code, 'deliver_config:', JSON.stringify(deliver_config));
|
||||
|
||||
if (!sn_code) {
|
||||
return ctx.fail('请提供设备SN码');
|
||||
}
|
||||
|
||||
if (!auto_deliver_config) {
|
||||
return ctx.fail('请提供 auto_deliver_config 配置对象');
|
||||
if (!deliver_config) {
|
||||
return ctx.fail('请提供 deliver_config 配置对象');
|
||||
}
|
||||
|
||||
const { pla_account, account_config } = await Framework.getModels();
|
||||
const { pla_account } = await Framework.getModels();
|
||||
|
||||
// 根据 sn_code 查找账号
|
||||
const user = await pla_account.findOne({
|
||||
@@ -330,34 +325,15 @@ module.exports = {
|
||||
return ctx.fail('用户不存在');
|
||||
}
|
||||
|
||||
// 查找或创建 account_config 记录
|
||||
const accountConfig = await account_config.findOne({
|
||||
where: { account_id: user.id }
|
||||
});
|
||||
|
||||
if (accountConfig) {
|
||||
// 更新现有配置
|
||||
await account_config.update(
|
||||
{ auto_deliver_config: auto_deliver_config },
|
||||
{ where: { account_id: user.id } }
|
||||
);
|
||||
} else {
|
||||
// 创建新配置
|
||||
await account_config.create({
|
||||
account_id: user.id,
|
||||
platform_type: user.platform_type || 'boss',
|
||||
auto_deliver_config: auto_deliver_config
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// 更新 pla_account 表的 auto_deliver 字段
|
||||
// 更新 pla_account 表的 deliver_config 和 auto_deliver 字段
|
||||
await pla_account.update(
|
||||
{ auto_deliver: auto_deliver_config.autoDelivery ? 1 : 0 },
|
||||
{
|
||||
deliver_config: deliver_config,
|
||||
auto_deliver: deliver_config.auto_delivery ? 1 : 0
|
||||
},
|
||||
{ where: { id: user.id } }
|
||||
);
|
||||
|
||||
|
||||
return ctx.success({ message: '配置保存成功' });
|
||||
} catch (error) {
|
||||
console.error('保存投递配置失败:', error);
|
||||
|
||||
Reference in New Issue
Block a user