/** * 获取商品 * @param {object} params - 条件 * @return {object|null} - 查找结果 */ async get(params) { const { app, ctx } = this; const goodsData = await app.model.Goods.get(params) || {}; const { categoryUuid: uuid, orgUuid } = goodsData; const goodsCategory = await app.model.GoodsCategory.get({ uuid, orgUuid, attributes: ['name'], }) || {}; if (!app._.isEmpty(goodsData)) { goodsData.dataValues.categoryName = goodsCategory.name; } else { ctx.throw(200, '查询不到指定的商品'); } return goodsData; }
/** * 登录 * @return {function|null} 登录结果 */ async login() { const { ctx, app } = this; const { userName, password, loginType } = ctx.request.body; let user; if (loginType === 'admin') { // 根据userName获取管理员 user = await ctx.service.user.admin.getAdminByLogin(userName, password); } else { // 根据userName获取商家 user = await ctx.service.user.merchant.getMerchantByLogin(userName, password); } if (app._.isEmpty(user)) { return this.fail(ctx.ERROR_CODE, '账号或密码错误'); } const { uuid: userUuid, userType, name, orgUuid } = user; const result = { name, userUuid, userName, userType, orgUuid }; ctx.setToken(result); this.success(result); }
/** * 获取商品分页列表 * @param {object} params - 条件 * @return {object|null} - 查找结果 */ async query(params = {}) { const { app } = this; const goodsData = await app.model.Goods.query({ ...params, attributes: ['uuid', 'version', 'name', 'status', 'unitName', 'spec', 'goodsInfo', 'salePrice', 'thumbnail', 'categoryUuid'], }); if (goodsData.count > 0) { for (const row of goodsData.rows) { const { categoryUuid: uuid } = row || {}; const { orgUuid } = params; const goodsCategory = await app.model.GoodsCategory.get({ uuid, orgUuid, attributes: ['name'], }); if (!app._.isEmpty(goodsCategory)) { row.dataValues.categoryName = goodsCategory.name; } } } return goodsData; }
if (app._.isEmpty(merchant)) { return this.fail(ctx.ERROR_CODE, '该应用未绑定商家');
}); if (app._.isEmpty(orderData)) { ctx.throw(200, '查询不到指定的订单');