明树Git Lab

Commit 7343e328 authored by zfp1's avatar zfp1

update

parent 40aaeb21
...@@ -9,25 +9,11 @@ async function createTraceCode(req, res, next) { ...@@ -9,25 +9,11 @@ async function createTraceCode(req, res, next) {
// //
const body = req.body; const body = req.body;
body.creator = req.user._id; body.creator = req.user._id;
// 生成溯源码: // 生成溯源码:/改成临时拼接,编辑时无动作
let tcode = `271Y8U00${body.type || 1}`; let tcodepre = `271Y8U`;
let batchNumber; tcodeend = utils.generateRandomCode(4);
if (!body.batchNumber) { body.tcodepre = tcodepre;
let source; body.tcodeend = tcodeend;
if (body.source && body.type == 1) {
source = await DB.ProductPlant.findOne({ _id: body.source }).lean();
} else if (body.source && body.type == 2) {
source = await DB.ProductPre.findOne({ _id: body.source }).lean();
} else if (body.source && body.type == 3) {
source = await DB.ProductDeep.findOne({ _id: body.source }).lean();
}
batchNumber = source.batchNumber;
} else {
batchNumber = body.batchNumber;
}
tcode = tcode + batchNumber;
tcode = tcode + utils.generateRandomCode(4);
body.tcode = tcode;
let ret = await DB.ProTraceCode.create(body); let ret = await DB.ProTraceCode.create(body);
res.sendData(ret); res.sendData(ret);
} catch (error) { } catch (error) {
...@@ -131,10 +117,11 @@ async function getTraceCode2(req, res, next) { ...@@ -131,10 +117,11 @@ async function getTraceCode2(req, res, next) {
if (!req.body._id) { if (!req.body._id) {
return res.sendError(errorMessage.resourceNotFound); return res.sendError(errorMessage.resourceNotFound);
} }
let traccode = await DB.ProTraceCode.findOne({ _id: req.body._id }, { type: 1, source: 1, tcode: 1, productSalUrl: 1,queryNum: 1, firstQueryTime: 1, _id: 1 }).lean(); let traccode = await DB.ProTraceCode.findOne({ _id: req.body._id }, { type: 1, source: 1,batchNumber:1, tcodepre: 1, tcodeend: 1, productSalUrl: 1,queryNum: 1, firstQueryTime: 1, _id: 1 }).lean();
if (!(traccode && traccode._id && traccode.source)) { if (!(traccode && traccode._id && traccode.source)) {
return res.sendError(errorMessage.resourceNotFound); return res.sendError(errorMessage.resourceNotFound);
} }
traccode.tcode = `${traccode.tcodepre}00${traccode.type}${traccode.batchNumber}${traccode.tcodeend}`;
let sourceId = traccode.source; let sourceId = traccode.source;
console.log(sourceId, "===") console.log(sourceId, "===")
let source = null; let source = null;
......
...@@ -10,7 +10,8 @@ const letianProTraceCodeSchema = new Schema({ ...@@ -10,7 +10,8 @@ const letianProTraceCodeSchema = new Schema({
// type: String, // type: String,
// comment: "产品名称" // comment: "产品名称"
// }, // },
tcode: String, // 溯源码 tcodepre: String, // 溯源码
tcodeend: String,
type: { type: {
type: Number, type: Number,
comment: "1 种植农产品 2 轻加工 3 深加工" comment: "1 种植农产品 2 轻加工 3 深加工"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment