forked from tumobi/nideshop
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
39 changed files
with
771 additions
and
18 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// default config | ||
module.exports = { | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
const Base = require('./base.js'); | ||
|
||
module.exports = class extends Base { | ||
async loginAction() { | ||
const username = this.post('username'); | ||
const password = this.post('password'); | ||
|
||
const admin = await this.model('admin').where({ username: username }).find(); | ||
if (think.isEmpty(admin)) { | ||
return this.fail(401, '用户名或密码不正确1'); | ||
} | ||
|
||
if (think.md5(password + '' + admin.password_salt) !== admin.password) { | ||
return this.fail(400, '用户名或密码不正确2'); | ||
} | ||
|
||
// 更新登录信息 | ||
await this.model('admin').where({ id: admin.id }).update({ | ||
last_login_time: parseInt(Date.now() / 1000), | ||
last_login_ip: this.ctx.ip | ||
}); | ||
|
||
const TokenSerivce = this.service('token', 'admin'); | ||
const sessionKey = await TokenSerivce.create({ | ||
user_id: admin.id | ||
}); | ||
|
||
if (think.isEmpty(sessionKey)) { | ||
return this.fail('登录失败'); | ||
} | ||
|
||
const userInfo = { | ||
id: admin.id, | ||
username: admin.username, | ||
avatar: admin.avatar, | ||
admin_role_id: admin.admin_role_id | ||
}; | ||
|
||
return this.success({ token: sessionKey, userInfo: userInfo }); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module.exports = class extends think.Controller { | ||
async __before() { | ||
// 根据token值获取用户id | ||
think.token = this.ctx.header['x-nideshop-token'] || ''; | ||
const tokenSerivce = think.service('token', 'admin'); | ||
think.userId = await tokenSerivce.getUserId(); | ||
|
||
// 只允许登录操作 | ||
if (this.ctx.controller !== 'auth') { | ||
if (think.userId <= 0) { | ||
return this.fail(401, '请先登录'); | ||
} | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
const Base = require('./base.js'); | ||
|
||
module.exports = class extends Base { | ||
/** | ||
* index action | ||
* @return {Promise} [] | ||
*/ | ||
async indexAction() { | ||
const page = this.get('page') || 1; | ||
const size = this.get('size') || 10; | ||
const name = this.get('name') || ''; | ||
|
||
const model = this.model('brand'); | ||
const data = await model.field(['id', 'name', 'floor_price', 'app_list_pic_url', 'is_new', 'sort_order', 'is_show']).where({name: ['like', `%${name}%`]}).order(['id DESC']).page(page, size).countSelect(); | ||
|
||
return this.success(data); | ||
} | ||
|
||
async infoAction() { | ||
const id = this.get('id'); | ||
const model = this.model('brand'); | ||
const data = await model.where({id: id}).find(); | ||
|
||
return this.success(data); | ||
} | ||
|
||
async storeAction() { | ||
if (!this.isPost) { | ||
return false; | ||
} | ||
|
||
const values = this.post(); | ||
const id = this.post('id'); | ||
|
||
const model = this.model('brand'); | ||
values.is_show = values.is_show ? 1 : 0; | ||
values.is_new = values.is_new ? 1 : 0; | ||
if (id > 0) { | ||
await model.where({id: id}).update(values); | ||
} else { | ||
delete values.id; | ||
await model.add(values); | ||
} | ||
return this.success(values); | ||
} | ||
|
||
async destoryAction() { | ||
const id = this.post('id'); | ||
await this.model('brand').where({id: id}).limit(1).delete(); | ||
// TODO 删除图片 | ||
|
||
return this.success(); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
const Base = require('./base.js'); | ||
const _ = require('lodash'); | ||
|
||
module.exports = class extends Base { | ||
/** | ||
* index action | ||
* @return {Promise} [] | ||
*/ | ||
async indexAction() { | ||
const model = this.model('category'); | ||
const data = await model.where({is_show: 1}).order(['sort_order ASC']).select(); | ||
const topCategory = data.filter((item) => { | ||
return item.parent_id === 0; | ||
}); | ||
const categoryList = []; | ||
topCategory.map((item) => { | ||
item.level = 1; | ||
categoryList.push(item); | ||
data.map((child) => { | ||
if (child.parent_id === item.id) { | ||
child.level = 2; | ||
categoryList.push(child); | ||
} | ||
}); | ||
}); | ||
return this.success(categoryList); | ||
} | ||
|
||
async topCategoryAction() { | ||
const model = this.model('category'); | ||
const data = await model.where({parent_id: 0}).order(['id ASC']).select(); | ||
|
||
return this.success(data); | ||
} | ||
|
||
async infoAction() { | ||
const id = this.get('id'); | ||
const model = this.model('category'); | ||
const data = await model.where({id: id}).find(); | ||
|
||
return this.success(data); | ||
} | ||
|
||
async storeAction() { | ||
if (!this.isPost) { | ||
return false; | ||
} | ||
|
||
const values = this.post(); | ||
const id = this.post('id'); | ||
|
||
const model = this.model('category'); | ||
values.is_show = values.is_show ? 1 : 0; | ||
if (id > 0) { | ||
await model.where({id: id}).update(values); | ||
} else { | ||
delete values.id; | ||
await model.add(values); | ||
} | ||
return this.success(values); | ||
} | ||
|
||
async destoryAction() { | ||
const id = this.post('id'); | ||
await this.model('category').where({id: id}).limit(1).delete(); | ||
// TODO 删除图片 | ||
|
||
return this.success(); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
const Base = require('./base.js'); | ||
|
||
module.exports = class extends Base { | ||
/** | ||
* index action | ||
* @return {Promise} [] | ||
*/ | ||
async indexAction() { | ||
const page = this.get('page') || 1; | ||
const size = this.get('size') || 10; | ||
const name = this.get('name') || ''; | ||
|
||
const model = this.model('goods'); | ||
const data = await model.where({name: ['like', `%${name}%`]}).order(['id DESC']).page(page, size).countSelect(); | ||
|
||
return this.success(data); | ||
} | ||
|
||
async infoAction() { | ||
const id = this.get('id'); | ||
const model = this.model('goods'); | ||
const data = await model.where({id: id}).find(); | ||
|
||
return this.success(data); | ||
} | ||
|
||
async storeAction() { | ||
if (!this.isPost) { | ||
return false; | ||
} | ||
|
||
const values = this.post(); | ||
const id = this.post('id'); | ||
|
||
const model = this.model('goods'); | ||
values.is_on_sale = values.is_on_sale ? 1 : 0; | ||
values.is_new = values.is_new ? 1 : 0; | ||
values.is_hot = values.is_hot ? 1 : 0; | ||
if (id > 0) { | ||
await model.where({id: id}).update(values); | ||
} else { | ||
delete values.id; | ||
await model.add(values); | ||
} | ||
return this.success(values); | ||
} | ||
|
||
async destoryAction() { | ||
const id = this.post('id'); | ||
await this.model('goods').where({id: id}).limit(1).delete(); | ||
// TODO 删除图片 | ||
|
||
return this.success(); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const Base = require('./base.js'); | ||
|
||
module.exports = class extends Base { | ||
indexAction() { | ||
return this.display(); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
const Base = require('./base.js'); | ||
|
||
module.exports = class extends Base { | ||
/** | ||
* index action | ||
* @return {Promise} [] | ||
*/ | ||
async indexAction() { | ||
const page = this.get('page') || 1; | ||
const size = this.get('size') || 10; | ||
const orderSn = this.get('orderSn') || ''; | ||
const consignee = this.get('consignee') || ''; | ||
|
||
const model = this.model('order'); | ||
const data = await model.where({order_sn: ['like', `%${orderSn}%`], consignee: ['like', `%${consignee}%`]}).order(['id DESC']).page(page, size).countSelect(); | ||
const newList = []; | ||
for (const item of data.data) { | ||
item.order_status_text = await this.model('order').getOrderStatusText(item.id); | ||
newList.push(item); | ||
} | ||
data.data = newList; | ||
return this.success(data); | ||
} | ||
|
||
async infoAction() { | ||
const id = this.get('id'); | ||
const model = this.model('order'); | ||
const data = await model.where({id: id}).find(); | ||
|
||
return this.success(data); | ||
} | ||
|
||
async storeAction() { | ||
if (!this.isPost) { | ||
return false; | ||
} | ||
|
||
const values = this.post(); | ||
const id = this.post('id'); | ||
|
||
const model = this.model('order'); | ||
values.is_show = values.is_show ? 1 : 0; | ||
values.is_new = values.is_new ? 1 : 0; | ||
if (id > 0) { | ||
await model.where({id: id}).update(values); | ||
} else { | ||
delete values.id; | ||
await model.add(values); | ||
} | ||
return this.success(values); | ||
} | ||
|
||
async destoryAction() { | ||
const id = this.post('id'); | ||
await this.model('order').where({id: id}).limit(1).delete(); | ||
|
||
// 删除订单商品 | ||
await this.model('order_goods').where({order_id: id}).delete(); | ||
|
||
// TODO 事务,验证订单是否可删除(只有失效的订单才可以删除) | ||
|
||
return this.success(); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
const Base = require('./base.js'); | ||
|
||
module.exports = class extends Base { | ||
/** | ||
* index action | ||
* @return {Promise} [] | ||
*/ | ||
async indexAction() { | ||
const page = this.get('page') || 1; | ||
const size = this.get('size') || 10; | ||
const name = this.get('name') || ''; | ||
|
||
const model = this.model('topic'); | ||
const data = await model.where({title: ['like', `%${name}%`]}).order(['id DESC']).page(page, size).countSelect(); | ||
|
||
return this.success(data); | ||
} | ||
|
||
async infoAction() { | ||
const id = this.get('id'); | ||
const model = this.model('topic'); | ||
const data = await model.where({id: id}).find(); | ||
|
||
return this.success(data); | ||
} | ||
|
||
async storeAction() { | ||
if (!this.isPost) { | ||
return false; | ||
} | ||
|
||
const values = this.post(); | ||
const id = this.post('id'); | ||
|
||
const model = this.model('topic'); | ||
values.is_show = values.is_show ? 1 : 0; | ||
values.is_new = values.is_new ? 1 : 0; | ||
if (id > 0) { | ||
await model.where({id: id}).update(values); | ||
} else { | ||
delete values.id; | ||
await model.add(values); | ||
} | ||
return this.success(values); | ||
} | ||
|
||
async destoryAction() { | ||
const id = this.post('id'); | ||
await this.model('topic').where({id: id}).limit(1).delete(); | ||
// TODO 删除图片 | ||
|
||
return this.success(); | ||
} | ||
}; |
Oops, something went wrong.