feat: 补齐客户端/管理端服务模块与数据库 schema,完善登录短信、法大大签署及公共函数
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
'use strict';
|
||||
module.exports = {
|
||||
/**
|
||||
* XXXnameXXX
|
||||
* @url admin/article/category/sys/list 前端调用的url参数地址
|
||||
* data 请求参数
|
||||
* @param {String} params1 参数1
|
||||
*/
|
||||
main: async (event) => {
|
||||
let {data = {}, userInfo, util, filterResponse, originalParam} = event;
|
||||
let {customUtil, uniID, config, pubFun, vk, db, _} = util;
|
||||
let {uid, adKey} = data;
|
||||
let res = {code: 0, msg: "", data: null};
|
||||
// 业务逻辑开始-----------------------------------------------------------
|
||||
const ad = await vk.baseDao.findByWhereJson({
|
||||
dbName: 'jjx-ad',
|
||||
whereJson: {adKey},
|
||||
});
|
||||
if (ad) {
|
||||
res.data = ad
|
||||
}
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
// return res;
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
'use strict';
|
||||
module.exports = {
|
||||
/**
|
||||
* XXXnameXXX
|
||||
* @url admin/article/category/sys/list 前端调用的url参数地址
|
||||
* data 请求参数
|
||||
* @param {String} params1 参数1
|
||||
*/
|
||||
main: async (event) => {
|
||||
let {data = {}, userInfo, util, filterResponse, originalParam} = event;
|
||||
let {customUtil, uniID, config, pubFun, vk, db, _} = util;
|
||||
let {
|
||||
uid,
|
||||
adKey,
|
||||
region,
|
||||
spotGoodsId,
|
||||
categoryId,
|
||||
categoryIds,
|
||||
categoryName,
|
||||
categoryNames,
|
||||
} = data;
|
||||
let res = {code: 0, msg: "", data: null};
|
||||
// 业务逻辑开始-----------------------------------------------------------
|
||||
const baseWhereJson = {adKey};
|
||||
const categoryFilterAdKeys = [9, 10, 11, 12, 13, 14, 112, 122];
|
||||
let whereJson = {adKey};
|
||||
const emptyToNull = value => (value === '' || value === undefined || value === null) ? null : value
|
||||
const appendRegionWhere = (target, provinceCode, cityCode, areaCode) => {
|
||||
if (areaCode) {
|
||||
target['region.area.code'] = areaCode;
|
||||
} else if (cityCode) {
|
||||
target['region.city.code'] = cityCode;
|
||||
} else if (provinceCode) {
|
||||
target['region.province.code'] = provinceCode;
|
||||
}
|
||||
return target
|
||||
}
|
||||
|
||||
if (!vk.pubfn.isNull(spotGoodsId)) {
|
||||
whereJson = {
|
||||
...baseWhereJson,
|
||||
spotGoodsId
|
||||
};
|
||||
} else {
|
||||
let provinceCode = null
|
||||
let cityCode = null
|
||||
let areaCode = null
|
||||
const categoryIdList = Array.isArray(categoryIds) ? categoryIds.filter(Boolean) : (vk.pubfn.isNotNull(categoryId) ? [categoryId] : [])
|
||||
const categoryNameList = Array.isArray(categoryNames) ? categoryNames.filter(Boolean) : (vk.pubfn.isNotNull(categoryName) ? [categoryName] : [])
|
||||
const categoryWhereList = []
|
||||
|
||||
if (!vk.pubfn.isNull(region)) {
|
||||
if (typeof region === 'string' || typeof region === 'number') {
|
||||
provinceCode = region
|
||||
} else if (Array.isArray(region)) {
|
||||
provinceCode = emptyToNull(region[0])
|
||||
cityCode = emptyToNull(region[1])
|
||||
areaCode = emptyToNull(region[2])
|
||||
} else if (typeof region === 'object') {
|
||||
provinceCode = emptyToNull(region.provinceCode || (region.province && region.province.code) || region.province)
|
||||
cityCode = emptyToNull(region.cityCode || (region.city && region.city.code) || region.city)
|
||||
areaCode = emptyToNull(region.areaCode || (region.area && region.area.code) || region.area)
|
||||
}
|
||||
}
|
||||
|
||||
const hasRegion = !!(provinceCode || cityCode || areaCode)
|
||||
const hasCategoryFilter = categoryIdList.length > 0 || categoryNameList.length > 0
|
||||
|
||||
if (hasRegion && categoryIdList.length > 0) {
|
||||
categoryWhereList.push(appendRegionWhere({
|
||||
...baseWhereJson,
|
||||
filterMode: 'category',
|
||||
categoryId: _.in(categoryIdList)
|
||||
}, provinceCode, cityCode, areaCode))
|
||||
categoryWhereList.push(appendRegionWhere({
|
||||
...baseWhereJson,
|
||||
filterMode: 'category',
|
||||
categoryIds: _.in(categoryIdList)
|
||||
}, provinceCode, cityCode, areaCode))
|
||||
}
|
||||
|
||||
if (hasRegion && categoryNameList.length > 0) {
|
||||
categoryWhereList.push(appendRegionWhere({
|
||||
...baseWhereJson,
|
||||
filterMode: 'category',
|
||||
categoryName: _.in(categoryNameList)
|
||||
}, provinceCode, cityCode, areaCode))
|
||||
categoryWhereList.push(appendRegionWhere({
|
||||
...baseWhereJson,
|
||||
filterMode: 'category',
|
||||
categoryNames: _.in(categoryNameList)
|
||||
}, provinceCode, cityCode, areaCode))
|
||||
}
|
||||
|
||||
if (categoryFilterAdKeys.includes(parseInt(adKey)) && (hasRegion || categoryWhereList.length > 0)) {
|
||||
const whereJsonList = []
|
||||
if (hasRegion) {
|
||||
const regionWhereJson = {
|
||||
...baseWhereJson,
|
||||
filterMode: _.or(_.eq('region'), _.exists(false))
|
||||
}
|
||||
|
||||
appendRegionWhere(regionWhereJson, provinceCode, cityCode, areaCode)
|
||||
whereJsonList.push(regionWhereJson)
|
||||
}
|
||||
whereJsonList.push(...categoryWhereList)
|
||||
whereJson = whereJsonList.length === 1 ? whereJsonList[0] : _.or(whereJsonList)
|
||||
} else if (hasRegion) {
|
||||
whereJson = {...baseWhereJson}
|
||||
appendRegionWhere(whereJson, provinceCode, cityCode, areaCode)
|
||||
} else if (categoryFilterAdKeys.includes(parseInt(adKey)) && hasCategoryFilter) {
|
||||
whereJson = {
|
||||
...baseWhereJson,
|
||||
filterMode: _.or(_.eq('region'), _.exists(false))
|
||||
}
|
||||
} else {
|
||||
whereJson = baseWhereJson
|
||||
}
|
||||
}
|
||||
console.log('whereJson', whereJson)
|
||||
const ad = await vk.baseDao.select({
|
||||
dbName: 'jjx-ad',
|
||||
whereJson,
|
||||
});
|
||||
res.data = ad.rows
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user