|
@@ -132,7 +132,7 @@ module.exports = class ProductsController extends ManagerController {
|
|
|
.notEmpty()
|
|
|
.number()
|
|
|
.extend(async (field, value, row) => {
|
|
|
- if (row.carousel_id) {
|
|
|
+ if (row.carousel_id && row.carousel_id > 0) {
|
|
|
const tmpContent = await that.ctx.postParse('content', '', val => val);
|
|
|
const result = await that.useCarouseModel.update({
|
|
|
content: tmpContent,
|
|
@@ -142,8 +142,16 @@ module.exports = class ProductsController extends ManagerController {
|
|
|
where: { carousel_id: row.carousel_id },
|
|
|
});
|
|
|
if (!result) return '商品相册更新失败,请重试';
|
|
|
+ } else {
|
|
|
+ const tmpContent = await that.ctx.postParse('content', '', val => val);
|
|
|
+ const result = await that.useCarouseModel.create({
|
|
|
+ content: tmpContent,
|
|
|
+ admin_id: that.service.manager.ActionAdminUserId(),
|
|
|
+ create_time: that.app.szjcomo.date('Y-m-d H:i:s'),
|
|
|
+ });
|
|
|
+ if (result) row.carousel_id = result.carousel_id;
|
|
|
}
|
|
|
- if (row.content_id) {
|
|
|
+ if (row.content_id && row.content_id > 0) {
|
|
|
const tmpDesction = await that.ctx.postParse('desction', '', val => val);
|
|
|
const result = await that.useContentModel.update({
|
|
|
desction: tmpDesction,
|
|
@@ -153,6 +161,15 @@ module.exports = class ProductsController extends ManagerController {
|
|
|
where: { content_id: row.content_id },
|
|
|
});
|
|
|
if (!result) return '商品详情更新失败,请重试';
|
|
|
+ } else {
|
|
|
+ // fix 上传详情失败时 重新补充详情内容
|
|
|
+ const tmpDesction = await that.ctx.postParse('desction', '', val => val);
|
|
|
+ const result = await that.useContentModel.create({
|
|
|
+ desction: tmpDesction,
|
|
|
+ admin_id: that.service.manager.ActionAdminUserId(),
|
|
|
+ create_time: that.app.szjcomo.date('Y-m-d H:i:s'),
|
|
|
+ });
|
|
|
+ if (result) row.content_id = result.content_id;
|
|
|
}
|
|
|
}),
|
|
|
admin_id: that.ctx.rules.default(that.service.manager.ActionAdminUserId())
|
|
@@ -235,6 +252,12 @@ module.exports = class ProductsController extends ManagerController {
|
|
|
const createBean = await that.app.comoBean.instance(data, {
|
|
|
transaction,
|
|
|
});
|
|
|
+ if (data.carousel_id < 1) {
|
|
|
+ throw new Error('图册提交失败,请重试');
|
|
|
+ }
|
|
|
+ if (data.content_id < 1) {
|
|
|
+ throw new Error('详情内容提交失败,请重试');
|
|
|
+ }
|
|
|
const result = await that.service.manager.create(createBean, that.useModel, '商品添加失败,请稍候重试');
|
|
|
await that.productActionAfter(result.product_id, transaction);
|
|
|
await transaction.commit();
|
|
@@ -281,6 +304,12 @@ module.exports = class ProductsController extends ManagerController {
|
|
|
const updateBean = await that.app.comoBean.instance(data, {
|
|
|
where: { product_id: data.product_id }, transaction,
|
|
|
});
|
|
|
+ if (data.carousel_id < 1) {
|
|
|
+ throw new Error('图册提交失败,请重试');
|
|
|
+ }
|
|
|
+ if (data.content_id < 1) {
|
|
|
+ throw new Error('详情内容提交失败,请重试');
|
|
|
+ }
|
|
|
const result = await that.service.manager.update(updateBean, that.useModel, '商品更新失败,请稍候重试');
|
|
|
await that.productActionAfter(data.product_id, transaction);
|
|
|
await transaction.commit();
|