Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions app/controller/catering/seller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
const Response = require('../../util/response')
const ServiceSeller = require('../../services/catering/seller')

module.exports = {
/**
* @api {get} /api/catering/v1/sellers/:sellerId/stores 商家的店铺列表
* @apiGroup seller
* @apiPermission user
* @apiVersion 1.0.0
* @apiParam {String} param 参数
* @apiSuccess {String} data 返回数据
* @apiSuccessExample {json} Visual Preview:
* {
"success": true,
"code": 200,
"data": [
{
"seller_id": 1,
"name": "吕松东🇧🇷🇫🇷",
"thumb": "https://wx.qlogo.cn/mmopen/vi_32/DYAIOgq83eo13vc2RhqKyJI8f5qaGCcj2ZeRfic696O0a2PDZvJ2JrGL8ia8EJHA6KjR37ia2neD11IBcNJ4HianZg/132",
"store_type_id": 0,
"theme": "",
"tel": "",
"wechat": "",
"license": "",
"address": "",
"approve_status": 0,
"status": 1,
"audit_id": 0,
"id": 1
}
],
"message": "请求成功"
}
*/
stores: async function (ctx) {
let data = await ServiceSeller.storeList(ctx.uid)

return Response.output(ctx, data)
},


}
89 changes: 89 additions & 0 deletions app/controller/catering/viewer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
const Response = require('../../util/response')
const ServiceViewer = require('../../services/catering/viewer')
const ServiceCategories = require('../../services/catering/category')
const ServiceProducts = require('../../services/catering/product')
const Validate = require('request-validate')

module.exports = {
/**
* @api {get} /api/catering/v1/viewers viewer列表
* @apiGroup viewer
* @apiPermission todo
* @apiVersion 1.0.0
* @apiParam {String} param 参数
* @apiSuccess {String} data 返回数据
* @apiSuccessExample {json} Visual Preview:
* {
"success": true,
"code": 200,
"message": "请求成功",
"data": [
{
"id": 1,
},
....
]
}
*/
index: async function (ctx) {
let data = await ServiceViewer.list()

return Response.output(ctx, data)
},

/**
* @api {get} /api/catering/v1/viewers/:viewerId/categories 访问店铺的分类
* @apiGroup viewer
* @apiPermission guest
* @apiVersion 1.0.0
* @apiParam {String} param 参数
* @apiSuccess {String} data 返回数据
* @apiSuccessExample {json} Visual Preview:
* {
"success": true,
"code": 200,
"message": "请求成功",
"data": [
{
"id": 1,
},
....
]
}
*/
categories: async function (ctx) {
let data = await ServiceCategories.list(ctx.params.viewerId, { status: 1 })

return Response.output(ctx, data)
},

/**
* @api {get} /api/catering/v1/viewers/:viewerId/products 访问店铺的商品
* @apiGroup viewer
* @apiPermission guest
* @apiVersion 1.0.0
* @apiParam {String} param 参数
* @apiSuccess {String} data 返回数据
* @apiSuccessExample {json} Visual Preview:
* {
"success": true,
"code": 200,
"message": "请求成功",
"data": [
{
"id": 1,
},
....
]
}
*/
products: async function (ctx) {
Validate(ctx.input, {
'category_id': 'required|nunumericm'
})
let data = await ServiceProducts.list(ctx.params.viewerId, { status: 1, categroy_id: ctx.input.category_id })

return Response.output(ctx, data)
},

}
1 change: 1 addition & 0 deletions app/libraries/constant.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ var constant = {
"CATERING_SESSION": "NS:API:CATERING_SESSION:",

"AUDIT_INFO": "NS:API:AUDIT_INFO:",
"USER_INFO": "NS:API:USER_INFO:",
"STORE_INFO": "NS:API:STORE_INFO:",

"EXPIRE_REFRESH": 86400,
Expand Down
6 changes: 3 additions & 3 deletions app/model/catering/audit.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@ module.exports = {

first: async function (id) {

let result = DB.readMysql.first(
let result = await DB.readMysql.first(
'*'
)
.from(table)
.where('audit_id', id)
.where('status', 1)

return await result
return result

},

edit: async function (data, where, notWhere = {}) {
let result = await ModelBase.execUpdate(table, data, where, notWhere)

return await result
return result
}

}
13 changes: 8 additions & 5 deletions app/model/catering/category.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const DB = require('../../libraries/db')
const ModelBase = require('../../model/base')
const _ = require('underscore')

const table = 'mist_category'

Expand All @@ -9,35 +10,37 @@ module.exports = {
return res;
},

list: async function (storeId) {
list: async function (storeId, filter = {}) {

let result = DB.readMysql.select(
'*'
)
.from(table)
.where('store_id', storeId)
.where('status', '!=', -1)
.whereNot('status', -1)

if (_.has(filter, 'status')) result.where('status', filter.status)

return await result

},

first: async function (id) {

let result = DB.readMysql.first(
let result = await DB.readMysql.first(
'*'
)
.from(table)
.where('id', id)

return await result
return result

},

edit: async function (data, where, notWhere = {}) {
let result = await ModelBase.execUpdate(table, data, where, notWhere)

return await result
return result
},

getMaxSort: async function (storeId) {
Expand Down
10 changes: 5 additions & 5 deletions app/model/catering/customer.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,32 @@ module.exports = {

getCustomerByOpenId: async function (openid) {

let user = DB.readMysql.first(
let user = await DB.readMysql.first(
'*'
)
.from(table)
.where('openid', openid)

return await user
return user

},

first: async function (customerId) {

let user = DB.readMysql.first(
let user = await DB.readMysql.first(
'*'
)
.from(table)
.where('id', customerId)

return await user
return user

},

edit: async function (data, where, notWhere = {}) {
let result = await ModelBase.execUpdate(table, data, where, notWhere)

return await result
return result
}

}
10 changes: 5 additions & 5 deletions app/model/catering/desk.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,33 @@ module.exports = {

list: async function (storeId) {

let result = DB.readMysql.select(
let result = await DB.readMysql.select(
'*'
)
.from(table)
.where('store_id', storeId)
.where('status', '!=', -1)

return await result
return result

},

first: async function (id) {

let result = DB.readMysql.first(
let result = await DB.readMysql.first(
'*'
)
.from(table)
.where('id', id)

return await result
return result

},

edit: async function (data, where, notWhere = {}) {
let result = await ModelBase.execUpdate(table, data, where, notWhere)

return await result
return result
}

}
11 changes: 9 additions & 2 deletions app/model/catering/product.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const DB = require('../../libraries/db')
const ModelBase = require('../../model/base')
const _ = require('underscore')

const table = 'mist_product'

Expand All @@ -16,7 +17,13 @@ module.exports = {
)
.from(table)
.where('store_id', storeId)
.where('status', '!=', -1)
.whereNot('status', -1)

if (_.has(filter, 'status')) result.where('status', filter.status)

if (_.has(filter, 'category_id')) {
// todo
}

return await result

Expand All @@ -35,7 +42,7 @@ module.exports = {
},

edit: async function (data, where, notWhere = {}) {
let result = await ModelBase.execUpdate(table, data, where, notWhere)
let result = ModelBase.execUpdate(table, data, where, notWhere)

return await result
}
Expand Down
23 changes: 18 additions & 5 deletions app/model/catering/seller.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,39 @@ const table = 'mist_seller'

module.exports = {
add: async function (data) {
let res = await ModelBase.execInsert(table, data)
return res;
let res = ModelBase.execInsert(table, data)
return await res;
},

list: async function (kid) {

let result = DB.readMysql.select(
'*'
)
.from(table)
.where('kid', kid)
.where('status', '!=', -1)

return await result

},

first: async function (id) {

let result = DB.readMysql.first(
'*'
)
.from(table)
.where('seller_id', id)
.where('id', id)

return await result

},

edit: async function (data, where, notWhere = {}) {
let result = await ModelBase.execUpdate(table, data, where, notWhere)
let result = ModelBase.execUpdate(table, data, where, notWhere)

return await result
}

}
}
14 changes: 13 additions & 1 deletion app/model/catering/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,20 @@ module.exports = {

},

getSellerStores: async function (sellerId) {

let result = DB.readMysql.select(
'*'
)
.from(table)
.where('seller_id', sellerId)

return await result

},

edit: async function (data, where, notWhere = {}) {
let result = await ModelBase.execUpdate(table, data, where, notWhere)
let result = ModelBase.execUpdate(table, data, where, notWhere)

return await result
}
Expand Down
Loading