diff --git a/README.md b/README.md index f28ea49..515189c 100644 --- a/README.md +++ b/README.md @@ -1,31 +1,95 @@ -# qimen +# 奇门WMS(qimen-wms) -奇门wms +基于 Egg.js 的仓储管理系统(WMS),支持多快递平台对接、订单管理、打印、权限、配置等功能,适合中小型电商、仓储企业二次开发。 -## QuickStart +--- - +## 目录结构 -see [egg docs][egg] for more detail. - -### Development - -```bash -npm i -npm run dev -open http://localhost:7001/ +``` +├── app/ # 业务主目录(controller, service, model, router等) +│ ├── controller/ # 控制器(API、模板、认证等) +│ ├── service/ # 业务服务(含快手/PolyAPI、打印、系统等) +│ ├── model/ # Sequelize模型 +│ ├── dict/ # 业务字典 +│ ├── view/ # 前端模板 +│ └── router.js # 路由定义 +├── config/ # 配置(含poloapi、redis、数据库等) +├── database/ # 数据库迁移与配置 +├── public/ # 静态资源 +├── logs/ # 日志 +├── run/ # 运行时/元数据 +├── test/ # 单元测试 +├── package.json # 依赖与脚本 +├── app.js # 应用入口 +└── README.md # 项目说明 ``` -### Deploy +## 主要依赖 +- egg.js 3.x +- egg-sequelize、egg-mysql、egg-redis +- egg-jwt、egg-cors、egg-view-ejs +- fast-xml-parser、cos-js-sdk-v5、qiniu-js、soap +## 快速开始 + +```bash +npm install +npm run dev +# 访问 http://localhost:6060/ +``` + +## 启动与部署 + +开发环境: +```bash +npm run dev +``` +生产环境: ```bash npm start npm stop ``` -### npm scripts +## 常用 npm 脚本 +- `npm run lint` 代码风格检查 +- `npm test` 单元测试 +- `npm run dev` 本地开发 +- `npm start` 启动生产服务 -- Use `npm run lint` to check code style. -- Use `npm test` to run unit test. +## 配置说明 +- 主要配置文件在 `config/` 目录下(如 poloapi.js、config.default.js、config.local.js) +- 数据库、Redis、快手/PolyAPI等均可在对应文件中调整 -[egg]: https://eggjs.org +## 主要功能模块 +- 多快递平台对接(快手/PolyAPI等,详见 config/poloapi.js) +- 订单管理、打印、仓库/门店管理 +- 权限与角色、员工管理 +- API接口(RESTful风格,详见 app/router.js) +- 日志、配置、业务字典 + +## 路由示例 +- `GET /` 首页/健康检查 +- `POST /qimen` 奇门接口 +- `POST /api/warehouse` 仓库API +- `POST /api/store` 门店API +- `POST /api/v1` 旧版API +- `POST /api/v2` 新版API +- `GET /template/xml/:id` 获取打印模板 +- `GET|POST /auth/printSetting/:code` 打印台设置 + +## 开发建议 +- 业务字典已全局挂载(见 app.js) +- 所有服务建议继承 Egg Service,便于单元测试 +- 配置、密钥等敏感信息请勿提交到仓库 + +## 常见问题 +- 启动端口默认 6060,可在 `package.json` 或 `config` 中调整 +- 数据库/Redis 连接失败请检查 config.local.js +- 打印、快递API对接请参考 `app/service/systems/polo_api.js` 和 `config/poloapi.js` + +--- + +如需二次开发或遇到问题,欢迎提 issue 或联系维护者。 + +[Egg.js 官方文档](https://eggjs.org) diff --git a/app/service/main.js b/app/service/main.js index 1dc4fab..e12c300 100644 --- a/app/service/main.js +++ b/app/service/main.js @@ -227,7 +227,7 @@ class MainService extends Service { const decoded = app.jwt.verify(token, app.config.jwt.secret); const now = Math.floor(Date.now() / 1000); const expiresIn = decoded.exp - now; - if (expiresIn < 1800 && expiresIn > 0) { + if (expiresIn < 14399 && expiresIn > 0) { // 移除过期时间(exp)和签发时间(iat),保留其他payload const { exp, iat, ...payload } = decoded; diff --git a/app/service/systemMethods/storage/receiving.js b/app/service/systemMethods/storage/receiving.js index 08ba957..b16fbe9 100644 --- a/app/service/systemMethods/storage/receiving.js +++ b/app/service/systemMethods/storage/receiving.js @@ -19,6 +19,16 @@ class configService extends MainService { const result = await service.systems.storage.receiving.getReceivingList(where, pagination); return this.success('ok', result); } + async getReceivingDetail(data) { + const { service } = this; + const result = await service.systems.storage.receiving.getReceivingDetail(data); + return this.success('ok', result); + } + async batchCancelReceiving(data){ + const { service } = this; + const result = await service.systems.storage.receiving.batchCancelReceiving(data); + return this.success('ok', result); + } async create(data) { const { service } = this; const result = await service.systems.storage.receiving.create(data); diff --git a/app/service/systems/polo_api.js b/app/service/systems/polo_api.js new file mode 100644 index 0000000..307f7b6 --- /dev/null +++ b/app/service/systems/polo_api.js @@ -0,0 +1,203 @@ +'use strict'; + +const Service = require('egg').Service; +const poloApiConfig = require('../../../config/poloapi'); + +const crypto = require('crypto'); +const querystring = require('querystring'); + +class PoloApiService extends Service { + constructor(ctx) { + super(ctx); + this.configPoloApi = poloApiConfig; + } + + // 批量组装订单JSON + getJsonDatas(expressConfig, list) { + const formatter = 'yyyy-MM-dd HH:mm:ss'; + const now = new Date(); + const tempDate = this._formatDate(now, formatter); + const cal = new Date(); + const year = cal.getFullYear(); + const month = cal.getMonth() + 1; + const day = cal.getDate() + 3; + const day1 = cal.getDate() + 4; + const sb1 = this._formatPickupDate(year, month, day); + const sb2 = this._formatPickupDate(year, month, day1); + + let orders = []; + for (const wmsOrder of list) { + let txLogisticID = wmsOrder.sourceId; + txLogisticID = txLogisticID.length < 6 ? txLogisticID.padStart(6, '0') : txLogisticID; + if (wmsOrder.postcode === 'p10') { + if (txLogisticID.length > 19) txLogisticID = txLogisticID.slice(-19); + } else { + if (txLogisticID.length > 28) txLogisticID = txLogisticID.slice(-28); + } + txLogisticID = txLogisticID.replace(/_/g, ''); + + // 快递公司代码 + const cpcode = this.configPoloApi.postCodeMap[wmsOrder.postcode] || ''; + + // 商品名 + let cnname = ''; + let ycflag = !(wmsOrder.wareHouseId === 5400 || wmsOrder.storeId === 58303); + if (ycflag) { + const items = wmsOrder.items || ''; + const splitStr = items.split('|'); + if (splitStr.length > 0) { + const s = splitStr[0]; + const sArr = s.split(','); + if (sArr.length > 2) cnname = sArr[2]; + } + } else { + cnname = 'sp'; + } + + // 收件人手机号 + let mobile = wmsOrder.tempMobile || wmsOrder.tel || ''; + + /* + order对象结构(41-77): + { + businessplat, ismultiplepieces, businesstype, cpcode, customercode, customername, + goods: [goods对象结构(49-56)], + logisticsproductname, logistictype, mainsubpaymode, needencrypt, numpackage, + orderno, ordersource, ordertype, plattradeno, ProviderID, providercode, + receiver: receiver对象结构(59-65), sender: sender对象结构(66-75), shipperno, sitecode, Inputsite, transtype + } + goods对象结构(49-56): + { + cnname, count, unit, currencytype, Unit, weight, price + } + receiver对象结构(59-65): + { + address, name, area, city, mobile, province + } + sender对象结构(66-75): + { + country, Company, address, name, area, town, city, phone, mobile, tel, province + } + */ + // 组装订单对象(下标范围:约第41-77行) + const order = { // [order对象开始 41] + businessplat: 'OTHERS', // 41 + ismultiplepieces: '0', + businesstype: 'JH_Normal', + cpcode, + customercode: '', + customername: expressConfig.storeProperty || '测试', + goods: [{ // [goods对象开始 49] + cnname, + count: String(wmsOrder.goodsCount), + unit: '属性', + currencytype: 'CNY', + Unit: '', + weight: String(wmsOrder.orderWeight), + price: '0.0', + }], // [goods对象结束 56] + logisticsproductname: 'JH_02', + logistictype: cpcode, + mainsubpaymode: '1', + needencrypt: '1', + numpackage: '1', + orderno: wmsOrder.sourceOrderCode || (wmsOrder.id && wmsOrder.id.length > 13 ? wmsOrder.id.substring(0, 14) : wmsOrder.id), + ordersource: 'KUAI_SHOU', + ordertype: 'JH_Normal', + plattradeno: wmsOrder.sourceOrderCode || txLogisticID, + ProviderID: wmsOrder.postcode === 'p03' ? 1327 : (wmsOrder.postcode === 'p04' ? 1499 : ''), + providercode: cpcode, + receiver: { // [receiver对象开始 59] + address: wmsOrder.address, + name: wmsOrder.name, + area: wmsOrder.expAreaName, + city: wmsOrder.cityName, + mobile, + province: wmsOrder.province, + }, // [receiver对象结束 65] + sender: { // [sender对象开始 66] + country: 'CN', + Company: expressConfig.storeName, + address: expressConfig.address, + name: expressConfig.senderName, + area: expressConfig.districtName && expressConfig.districtName.indexOf(';') === -1 ? expressConfig.districtName : expressConfig.districtName.split(';')[0], + town: expressConfig.districtName && expressConfig.districtName.indexOf(';') !== -1 ? expressConfig.districtName.split(';')[1] : undefined, + city: expressConfig.cityName, + phone: expressConfig.senderTel, + mobile: expressConfig.senderTel, + tel: expressConfig.senderTel, + province: expressConfig.provinceName, + }, // [sender对象结束 75] + shipperno: ['p22', 'p35', 'p10'].includes(wmsOrder.postcode) ? expressConfig.siteCode : expressConfig.clientId, + sitecode: expressConfig.siteCode || '', + Inputsite: expressConfig.siteCode || '', + transtype: '0', + // 省略部分特殊字段和extraInfo,后续可补充 + }; // [order对象结束 77] + // 特殊字段 + if (wmsOrder.postcode === 'p10') { + order.pickUpDate = sb1; + order.pickUpEndDate = sb2; + } + orders.push(order); + } + + const body = JSON.stringify({ orders, shoptype: 'JH_001' }); + + // 组装url参数 + const urlParams = { + method: 'Differ.JH.Logistics.PostOrder', + appkey: this.configPoloApi.appKey, + token: expressConfig.sessionKey, + platid: this.configPoloApi.platid, + version: this.configPoloApi.version, + bizcontent: encodeURIComponent(body), + contenttype: this.configPoloApi.contenttype, + timestamp: encodeURIComponent(this._formatDate(new Date(), 'yyyy-MM-dd HH:mm:ss')), + }; + // 签名 + const signMap = { ...urlParams, bizcontent: body, timestamp: this._formatDate(new Date(), 'yyyy-MM-dd HH:mm:ss') }; + const signText = this.getSignText(signMap, this.configPoloApi.appSecret); + urlParams.sign = this.md5Encrypt(signText.toLowerCase(), 'utf8'); + + // 返回请求体和参数 + return { body, urlParams }; + } + + // 单个订单JSON(略,结构同上,建议复用 getJsonDatas 逻辑) + getJsonData(expressConfig, wmsOrder, deliveryOrder, type) { + // 可根据 type 判断调用 getJsonDatas 或单独组装 + return this.getJsonDatas(expressConfig, [wmsOrder]); + } + + // 生成签名字符串 + getSignText(signMap, secret) { + let sb = '' + secret; + Object.keys(signMap).sort().forEach(key => { + sb += key + signMap[key]; + }); + sb += secret; + return sb; + } + + // MD5加密 + md5Encrypt(text, encoding = 'utf8') { + return crypto.createHash('md5').update(text, encoding).digest('hex'); + } + + // 工具:格式化日期 + _formatDate(date, fmt) { + // 仅支持 yyyy-MM-dd HH:mm:ss + const pad = n => n < 10 ? '0' + n : n; + return date.getFullYear() + '-' + pad(date.getMonth() + 1) + '-' + pad(date.getDate()) + ' ' + + pad(date.getHours()) + ':' + pad(date.getMinutes()) + ':' + pad(date.getSeconds()); + } + + // 工具:组装取件日期 + _formatPickupDate(year, month, day) { + const pad = n => n < 10 ? '0' + n : n; + return `${year}-${pad(month)}-${pad(day)} 18:00:00`; + } +} + +module.exports = PoloApiService; \ No newline at end of file diff --git a/app/service/systems/storage/receiving.js b/app/service/systems/storage/receiving.js index 15e5149..6e04e25 100644 --- a/app/service/systems/storage/receiving.js +++ b/app/service/systems/storage/receiving.js @@ -34,7 +34,7 @@ class ReceivingService extends Service { where: {}, order: [], attributes: { - exclude: [ 'deleted_at' ], + exclude: ['deleted_at'], }, }; const prohibitedQueryOptions = { @@ -66,23 +66,25 @@ class ReceivingService extends Service { // 检查是否是快捷查询,快捷查询字段 if (fieldKey === 'quickWhere') { - dynamicConditions.push({ [Op.or]: { - store_name: { - [Sequelize.Op.like]: `%${condition.value}%`, - }, - receiving_number: { - [Sequelize.Op.like]: `%${condition.value}%`, - }, - tracking_number: { - [Sequelize.Op.like]: `%${condition.value}%`, - }, - creator_snapshot: { - [Sequelize.Op.like]: `%${condition.value}%`, - }, - license_plate: { - [Sequelize.Op.like]: `%${condition.value}%`, - }, - } }); + dynamicConditions.push({ + [Op.or]: { + store_name: { + [Sequelize.Op.like]: `%${condition.value}%`, + }, + receiving_number: { + [Sequelize.Op.like]: `%${condition.value}%`, + }, + tracking_number: { + [Sequelize.Op.like]: `%${condition.value}%`, + }, + creator_snapshot: { + [Sequelize.Op.like]: `%${condition.value}%`, + }, + license_plate: { + [Sequelize.Op.like]: `%${condition.value}%`, + }, + } + }); continue; // 暂不添加到动态条件中 } // 其他字段的处理 @@ -106,20 +108,20 @@ class ReceivingService extends Service { const actualSortField = validSortFields.includes(sortField) ? sortField : 'create_at'; const actualSortOrder = sortOrder.toUpperCase() === 'ASC' ? 'ASC' : 'DESC'; - queryOptions.order.push([ actualSortField, actualSortOrder ]); + queryOptions.order.push([actualSortField, actualSortOrder]); // 计算分页偏移量 const offset = (page - 1) * pageSize; // 执行查询:获取总数和数据 - const [ total, data ] = await Promise.all([ + const [total, data] = await Promise.all([ // 获取总数 ctx.model.Receiving.count({ where: queryOptions.where, include: [{ model: ctx.model.StoreWarehouse, as: 'store', - attributes: [ 'store_remask' ], + attributes: ['store_remask'], where: { use_status: 1, }, @@ -127,7 +129,7 @@ class ReceivingService extends Service { }, { model: ctx.model.AccountStoreEmployee, as: 'creator', - attributes: [ 'real_name' ], + attributes: ['real_name'], required: true, }], distinct: true, @@ -139,7 +141,7 @@ class ReceivingService extends Service { include: [{ model: ctx.model.StoreWarehouse, as: 'store', - attributes: [ 'store_remask' ], + attributes: ['store_remask'], where: { use_status: 1, }, @@ -147,7 +149,7 @@ class ReceivingService extends Service { }, { model: ctx.model.AccountStoreEmployee, as: 'creator', - attributes: [ 'real_name' ], + attributes: ['real_name'], required: true, }], limit: parseInt(pageSize), @@ -176,7 +178,7 @@ class ReceivingService extends Service { include: [{ model: ctx.model.File, as: 'file', - attributes: [ 'file_url' ], + attributes: ['file_url'], required: true, }], }); @@ -273,6 +275,112 @@ class ReceivingService extends Service { }; } } + /* + * 获取收货单详情 + */ + async getReceivingDetail(data) { + const { id, pagination } = data; + const { page, pageSize } = pagination; + const { ctx, app } = this; + const { Op } = app.Sequelize; + // 获取用户仓库ID,增加错误处理 + const warehouseId = ctx.user?.store_id; + if (!warehouseId) { + return { code: 0, message: '用户未绑定仓库', data: {} }; + } + try { + // 1. 查询收货单主表 + const receiving = await app.model.Receiving.findOne({ where: { id, warehouse_id: warehouseId } }); + if (!receiving) { + return { code: 0, message: '无记录或无权访问', data: {} }; + } + // 2. 查询收货单明细,按分页 + const receivingItems = await app.model.ReceivingDetail.findAll({ + where: { receiving_id: id }, + offset: (page - 1) * pageSize, + limit: pageSize, + }); + // 获取明细总数 + const totalItems = await app.model.ReceivingDetail.count({ where: { receiving_id: id } }); + //组装分页信息 + const pagination = { + total: totalItems, + currentPage: page, + pageSize: pageSize, + totalPages: Math.ceil(totalItems / pageSize), + hasPrevious: page > 1, + hasNext: page < Math.ceil(totalItems / pageSize), + }; + + // 3. 获取明细ID数组 + const receivingItemsIds = receivingItems.map(item => item.id); + // 4. 查询明细图片(如果明细数量大于0) + const itemImagesMap = {}; // 用于存储每个明细的图片 + if (receivingItemsIds.length > 0) { + const receivingItemsImages = await ctx.model.FileReference.findAll({ + where: { + business_type: 'receivingItem', + business_id: { [Op.in]: receivingItemsIds }, + } + }); + // 将图片按明细ID分组,eggjs 不能使用forEach异步处理,所以改为同步处理 + for (const image of receivingItemsImages) { + if (!itemImagesMap[image.business_id]) { + itemImagesMap[image.business_id] = []; + } + itemImagesMap[image.business_id].push(image); + } + } + // 5. 将图片合并到对应的明细中 + const items = receivingItems.map(item => { + return { + ...item.toJSON(), + images: itemImagesMap[item.id] || [], + }; + }); + // 6. 查询主表的图片 + const receivingImages = await ctx.model.FileReference.findAll({ + where: { + business_type: 'receiving', + business_id: id, + } + }); + // 7. 组装返回数据 + receiving.dataValues.details = items; // 包含图片的明细数据 + receiving.dataValues.images = receivingImages; // 包含主表图片 + receiving.dataValues.pagination = pagination; // 包含分页信息 + return { code: 200, message: '查询成功', data: { receiving } }; + + } catch (error) { + console.error('获取收货单详情失败:', error); + return { code: 500, message: '服务器错误', data: {} }; + } + } + //批量作废 + async batchCancelReceiving(data) { + const { ids } = data; + const { ctx } = this; + const { Op } = ctx.model.Sequelize; + const warehouse_id = ctx.user.store_id; + try { + //先查询这些单据是否都存在且状态允许作废 + const receivings = await ctx.model.Receiving.findAll({where:{ id: { [Op.in]: ids }, warehouse_id }}); + if (receivings.length !== ids.length) { + return { code: 0, message: '部分单据不存在或无权访问', data: {} }; + }else{ + const invalidStatus = receivings.find(r => r.status !== 'receiving'); + if (invalidStatus) { + return { code: 0, message: '部分单据状态不允许作废', data: {} }; + } + // 批量更新状态为cancelled + await ctx.model.Receiving.update({ status: 'cancelled' }, { where: { id: { [Op.in]: ids }, warehouse_id } }); + return { code: 200, message: '批量作废成功', data: {} }; + } + } catch (error) { + console.error('批量作废收货单失败:', error); + return { code: 500, message: '服务器错误', data: {} }; + } + } isEmptyValue(value) { if (value === undefined || value === null) { return true; @@ -502,7 +610,7 @@ class ReceivingService extends Service { case 'daterange': // 处理日期范围:数组的第一个元素是开始时间,第二个元素是结束时间 if (Array.isArray(value) && value.length === 2) { - const [ startDate, endDate ] = value; + const [startDate, endDate] = value; console.log(startDate, endDate); console.log(startDate ? service.main.normalizeDate(startDate, false) : null, endDate ? service.main.normalizeDate(endDate, true) : null); return [ @@ -556,35 +664,35 @@ class ReceivingService extends Service { }; // 2. 生成收货单号 (格式: R + 时间戳的day + 3位序列号,如: RR20231215001) - const now = new Date(); - console.log('当前时间:', now); - const dateStr = Math.floor(now.getTime() / (1000 * 60 * 60 * 24)); // 时间戳到今日的天数 - const prefix = `R${dateStr}`; + const now = new Date(); + console.log('当前时间:', now); + const dateStr = Math.floor(now.getTime() / (1000 * 60 * 60 * 24)); // 时间戳到今日的天数 + const prefix = `R${dateStr}`; - // 查找当天最大的收货单号 - const maxReceiving = await app.model.Receiving.findOne({ - where: { - receiving_number: { - [app.Sequelize.Op.like]: `${prefix}%`, - }, - warehouse_id + // 查找当天最大的收货单号 + const maxReceiving = await app.model.Receiving.findOne({ + where: { + receiving_number: { + [app.Sequelize.Op.like]: `${prefix}%`, }, - order: [[ 'receiving_number', 'DESC' ]], - }); + warehouse_id + }, + order: [['receiving_number', 'DESC']], + }); - let sequence = 1; - if (maxReceiving) { - // 提取最大收货单号的序号部分 - const lastNumStr = maxReceiving.receiving_number.replace(prefix, ''); - const lastNum = parseInt(lastNumStr); - sequence = lastNum + 1; - } + let sequence = 1; + if (maxReceiving) { + // 提取最大收货单号的序号部分 + const lastNumStr = maxReceiving.receiving_number.replace(prefix, ''); + const lastNum = parseInt(lastNumStr); + sequence = lastNum + 1; + } - // 序号动态长度:<1000用3位,<10000用4位,>=10000用5位 - let seqLen = 3; - if (sequence >= 1000 && sequence < 10000) seqLen = 4; - if (sequence >= 10000) seqLen = 5; - const receiving_number = `${prefix}${sequence.toString().padStart(seqLen, '0')}`; + // 序号动态长度:<1000用3位,<10000用4位,>=10000用5位 + let seqLen = 3; + if (sequence >= 1000 && sequence < 10000) seqLen = 4; + if (sequence >= 10000) seqLen = 5; + const receiving_number = `${prefix}${sequence.toString().padStart(seqLen, '0')}`; // 3. 获取店铺名称(如果有货主) let store_name = null; if (store_id) { @@ -661,7 +769,7 @@ class ReceivingService extends Service { include: [{ model: ctx.model.StoreWarehouse, as: 'store', - attributes: [ 'store_remask' ], + attributes: ['store_remask'], where: { use_status: 1, }, @@ -669,7 +777,7 @@ class ReceivingService extends Service { }, { model: ctx.model.AccountStoreEmployee, as: 'creator', - attributes: [ 'real_name' ], + attributes: ['real_name'], required: false, }], // 不需要order,因为根据id查询已经是唯一的 @@ -688,10 +796,10 @@ class ReceivingService extends Service { { model: ctx.model.LocationSpace, as: 'receiving_space', - attributes: [ 'space_code', 'custom_barcode', 'custom_name' ], + attributes: ['space_code', 'custom_barcode', 'custom_name'], }, ], - order: [[ 'id', 'DESC' ]], // 保持倒序,最新在前 + order: [['id', 'DESC']], // 保持倒序,最新在前 }); // 3. 获取明细ID数组 @@ -710,7 +818,7 @@ class ReceivingService extends Service { include: [{ model: ctx.model.File, as: 'file', - attributes: [ 'file_url' ], + attributes: ['file_url'], required: true, }], }); @@ -744,7 +852,7 @@ class ReceivingService extends Service { include: [{ model: ctx.model.File, as: 'file', - attributes: [ 'file_url' ], + attributes: ['file_url'], required: true, }], }); @@ -818,7 +926,7 @@ class ReceivingService extends Service { // 获取更新后的明细列表 const allDetails = await ctx.model.ReceivingDetail.findAll({ where: { receiving_id }, - order: [[ 'id', 'DESC' ]], + order: [['id', 'DESC']], }); // 格式化返回数据 @@ -872,7 +980,7 @@ class ReceivingService extends Service { { model: ctx.model.Receiving, as: 'receiving', - attributes: [ 'id', 'status' ], + attributes: ['id', 'status'], }, ], }); @@ -965,7 +1073,7 @@ class ReceivingService extends Service { } // 更新明细 - const [ affectedRows ] = await ctx.model.ReceivingDetail.update(updateData, { + const [affectedRows] = await ctx.model.ReceivingDetail.update(updateData, { where: { id }, }); @@ -988,7 +1096,7 @@ class ReceivingService extends Service { { model: ctx.model.StockWarehouse, as: 'system_product', - attributes: [ 'id', 'name', 'barcode', 'spec', 'unit', 'images' ], + attributes: ['id', 'name', 'barcode', 'spec', 'unit', 'images'], }, ], }); @@ -1037,7 +1145,7 @@ class ReceivingService extends Service { { model: ctx.model.StoreWarehouse, as: 'store_stock', - attributes: [ 'store_id', 'store_remask' ], + attributes: ['store_id', 'store_remask'], }, ], }); @@ -1121,8 +1229,8 @@ class ReceivingService extends Service { const stats = await ctx.model.ReceivingDetail.findAll({ where: { receiving_id: receivingId }, attributes: [ - [ ctx.model.fn('COUNT', ctx.model.col('id')), 'total_items' ], - [ ctx.model.fn('SUM', ctx.model.col('actual_quantity')), 'total_quantity' ], + [ctx.model.fn('COUNT', ctx.model.col('id')), 'total_items'], + [ctx.model.fn('SUM', ctx.model.col('actual_quantity')), 'total_quantity'], ], raw: true, transaction, @@ -1200,7 +1308,7 @@ class ReceivingService extends Service { { model: ctx.model.Receiving, as: 'receiving', - attributes: [ 'id', 'status' ], + attributes: ['id', 'status'], where: { warehouse_id, }, @@ -1251,7 +1359,7 @@ class ReceivingService extends Service { // 获取删除后的所有明细 const remainingDetails = await ctx.model.ReceivingDetail.findAll({ where: { receiving_id }, - order: [[ 'id', 'DESC' ]], + order: [['id', 'DESC']], }); // 格式化返回数据 @@ -1343,7 +1451,7 @@ class ReceivingService extends Service { { model: app.model.Receiving, as: 'receiving', - attributes: [ 'id', 'warehouse_id', 'store_id', 'store_name' ], + attributes: ['id', 'warehouse_id', 'store_id', 'store_name'], where: { warehouse_id: warehouseId, id: receiving_id, @@ -1414,12 +1522,12 @@ class ReceivingService extends Service { { model: app.model.StoreWarehouse, as: 'store_stock', - attributes: [ 'store_id', 'store_remask' ], + attributes: ['store_id', 'store_remask'], }, { model: app.model.StockBarcode, as: 'barcodes', - attributes: [ 'barcode' ], + attributes: ['barcode'], required: false, }, ], @@ -1658,7 +1766,7 @@ class ReceivingService extends Service { model: ctx.model.ReceivingDetail, as: 'details', required: false, - attributes: [ 'id', 'system_product_id', 'product_name', 'barcode', 'actual_quantity', 'weight' ], + attributes: ['id', 'system_product_id', 'product_name', 'barcode', 'actual_quantity', 'weight'], }], }); @@ -1732,14 +1840,14 @@ class ReceivingService extends Service { // 这里的关键修复:不仅要检查数组是否存在且有长度,还要检查数组中的元素是否有实际的数据 const hasPhoto = imageArray && - imageArray.length > 0 && - imageArray.some(img => { - // 检查图片对象是否有实际的数据 - return img.dataValues || - img.file_path || - img.url || - (img._options && Object.keys(img._options).length > 0); - }); + imageArray.length > 0 && + imageArray.some(img => { + // 检查图片对象是否有实际的数据 + return img.dataValues || + img.file_path || + img.url || + (img._options && Object.keys(img._options).length > 0); + }); const hasBarcode = !!detail.barcode && detail.barcode.trim() !== ''; const hasWeight = detail.weight > 0; const hasCount = detail.actual_quantity > 0; diff --git a/config/config.default.js b/config/config.default.js index 8cfba58..b315709 100644 --- a/config/config.default.js +++ b/config/config.default.js @@ -162,6 +162,9 @@ module.exports = appInfo => { hostname: '0.0.0.0', }, }; + config.poloapi ={ + + } config.printService = { url: 'http://localhost:4050', }; diff --git a/config/poloapi.js b/config/poloapi.js new file mode 100644 index 0000000..f738b18 --- /dev/null +++ b/config/poloapi.js @@ -0,0 +1,29 @@ +// config/poloapi.js +// 快手/PolyAPI相关固定配置 + +module.exports = { + appKey: "8e770a60b9684c558f40e4796a96710f", + appSecret: "c9cb1df531b441a8872c60ffb7f900a6", + platid: "633", + version: "1.5", + contenttype: "json", + urls: "https://api.polyapi.com/openapi/do", + // 快递公司代码映射 + postCodeMap: { + p01: "YTO", + p02: "STO", + p03: "YUNDA", + p04: "ZTO", + p05: "SF", + p06: "TTKDEX", + p07: "EMS", + p10: "JD", + p22: "POSTB", + p35: "POST_DSBK", + p09: "huitongkuaidi", + p26: "debangwuliu", + p32: "JT", + p34: "FENGWANG" + } + // 如有更多固定配置,可继续补充 +}; diff --git a/day.log b/day.log new file mode 100644 index 0000000..1565249 Binary files /dev/null and b/day.log differ