| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- const d_product = require('../database/d_product');
- const {searchHandle} = require('../tools/searchSql');
- const {handle} = require('../tools/handle');
- const codeMap = require("../map/rcodeMap");
- const log = require("../logger").logger("c_product","info")
- /**
- * 加载产品
- * @param key 产品类别
- * @param p 页码
- * @param l 每页数量
- * @returns {Promise<*[]>} [err,res]
- */
- async function loadProduct(key,p,l)
- {
- p = p || 1;
- l = l || 10;
- let [err,res] = await handle(d_product.loadProducts(key, p, l));
- if(err){
- return [err,null];
- }
- return [null,res];
- }
- /**
- * 获取产品信息
- * @param id 产品id
- * @returns {Promise<*[]>}
- */
- async function getProductInfo(id)
- {
- let [err,res] = await handle(d_product.getProductInfo(id));
- if(err){
- return [err,null];
- }
- let data = {};
- if(res.length){
- data = res[0];
- }else{
- return [
- {
- eCode:codeMap.NotFound,
- eMsg:`无法找到对应产品`
- },null]
- }
- return [null,data];
- }
- async function searchProduct(type, key, p, l)
- {
- p = p || 1;
- l = l || 10;
- let _params = {
- }
- if(type !== 'all'){
- _params.type = type;
- }
- if(key){
- _params.key = key
- }
- return await searchHandle(
- '搜索产品失败',
- d_product.searchProducts,
- _params,
- p,
- l);
- }
- module.exports = {
- loadProduct,
- getProductInfo,
- searchProduct
- };
|