147 lines
3.9 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'use strict';
const MainService = require('../../main');
/**
* 系统方法层:stock.transaction(商品出入库流水查询包装层)。
*/
class StockTransactionMethodService extends MainService {
constructor(ctx) {
super(ctx);
const _noNeedLogin = '';
const _noNeedRight = 'list,storeList';
const _noNeedLog = 'list,storeList';
const _noNeedAuth = 'list,storeList';
this.systemInit(_noNeedLogin, _noNeedRight, _noNeedLog, _noNeedAuth);
}
/**
* 仓库侧商品出入库流水列表查询。
* 按当前用户仓库(ctx.user.store_id)限定数据范围。
* @param {Object} data 请求体
* @param {Object} [data.pagination] 分页参数
* @param {Object} [data.where] 查询条件
* @param {Object} [data.sort] 排序参数
* @return {Promise<Object>} 统一 success 包装
*/
async list(data = {}) {
const { service } = this;
const warehouseId = Number(this.ctx.user && this.ctx.user.store_id);
const { pagination } = data;
const { whereValue = {} } = this.prepareWhereContext(data);
const {
start_time: startTime,
end_time: endTime,
store_ids: storeIds,
stock_ids: stockIds,
transaction_type: transactionType,
order_type: orderType,
order_no: orderNo,
batch_no: batchNo,
entry_order_id: entryOrderId,
receiving_id: receivingId,
order_id: orderId,
} = whereValue;
const { sort = {} } = data;
const {
sort_field: sortFieldSnake,
sortField: sortFieldCamel,
sort_order: sortOrderSnake,
sortOrder: sortOrderCamel,
} = sort || {};
const sortOption = {
sortField: sortFieldCamel || sortFieldSnake,
sortOrder: sortOrderCamel || sortOrderSnake,
};
const result = await service.systems.stockTransaction.queryList({
warehouseId,
startTime,
endTime,
storeIds,
stockIds,
transactionType,
orderType,
orderNo,
batchNo,
entryOrderId,
receivingId,
orderId,
sort: sortOption,
pagination,
});
return this.success('ok', result);
}
/**
* 货主侧商品出入库流水列表查询。
* 按货主 store_id 限定数据范围。
* @param {Object} data 请求体
* @param {number} data.store_id 货主ID(必传)
* @param {Object} [data.pagination] 分页参数
* @param {Object} [data.where] 查询条件
* @param {Object} [data.sort] 排序参数
* @return {Promise<Object>} 统一 success 包装
*/
async storeList(data = {}) {
const { service } = this;
const storeId = Number(data.store_id);
if (!Number.isInteger(storeId) || storeId <= 0) {
return this.failure('store_id 不能为空');
}
const { pagination } = data;
const { whereValue = {} } = this.prepareWhereContext(data);
const {
start_time: startTime,
end_time: endTime,
warehouse_ids: warehouseIds,
stock_ids: stockIds,
transaction_type: transactionType,
order_type: orderType,
order_no: orderNo,
batch_no: batchNo,
entry_order_id: entryOrderId,
receiving_id: receivingId,
order_id: orderId,
} = whereValue;
const { sort = {} } = data;
const {
sort_field: sortFieldSnake,
sortField: sortFieldCamel,
sort_order: sortOrderSnake,
sortOrder: sortOrderCamel,
} = sort || {};
const sortOption = {
sortField: sortFieldCamel || sortFieldSnake,
sortOrder: sortOrderCamel || sortOrderSnake,
};
const result = await service.systems.stockTransaction.queryList({
storeId,
startTime,
endTime,
warehouseIds,
stockIds,
transactionType,
orderType,
orderNo,
batchNo,
entryOrderId,
receivingId,
orderId,
sort: sortOption,
pagination,
});
return this.success('ok', result);
}
}
module.exports = StockTransactionMethodService;