-
Notifications
You must be signed in to change notification settings - Fork 1
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
ZhouYang
committed
Feb 24, 2020
1 parent
2901a57
commit b96f92c
Showing
229 changed files
with
14,374 additions
and
0 deletions.
There are no files selected for viewing
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,30 @@ | ||
# mini_shop | ||
|
||
### 配置文件说明 | ||
|
||
`const settings = { | ||
app_id: '', // 微信小程序appid | ||
app_secret: '' // 微信小程序appsecret, | ||
enviroment: 'pro' // 当前环境, | ||
cloudenv: 'cake-dev-rlbcr' // 云开发环境名称, | ||
HomePage: '/pages/home/home' // 首页路径, | ||
// tabs页面 | ||
TAB_URLS: [ | ||
'/pages/home/home', | ||
'/pages/me/me', | ||
'/pages/goods/goods', | ||
], | ||
// 主题颜色 | ||
Theme: { | ||
BgColor: '#d9262f', | ||
lightColor: '#F0f0f2', | ||
lightColor2: '#f4f4f2', | ||
blueColor: '#7dd3da', | ||
redColor: '#e67774', | ||
greenColor: '#8dbb6a' | ||
}, | ||
// 提示信息固定时间(短) | ||
shortTipDuration: 2000, | ||
// 提示信息固定时间(长) | ||
longTipDuration: 4000 | ||
};` |
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,149 @@ | ||
const db = require('./db') | ||
|
||
const queryAddress = async (event, wxContext, user) => { | ||
return { | ||
status: true, | ||
message: 'ok', | ||
data: { | ||
entities: user.address | ||
} | ||
} | ||
} | ||
|
||
const getAddress = async (event, wxContext, user) => { | ||
for (let item of user.address) { | ||
if (item.id == event.addressId) { | ||
return { | ||
status: true, | ||
message: 'ok', | ||
data: { | ||
entity: item | ||
} | ||
} | ||
} | ||
} | ||
return { | ||
status: false, | ||
message: 'address_not_found' | ||
} | ||
|
||
} | ||
|
||
const saveAddress = async (event, wxContext, user) => { | ||
let result = null | ||
for (let i = 0; i < user.address.length; i++) { | ||
if (user.address[i].id == event.addressId) { | ||
user.address[i] = event.address | ||
try { | ||
result = await db.collection('user').doc(user._id).update({ | ||
data: { | ||
address: user.address | ||
} | ||
}) | ||
} catch (e) { | ||
console.error(e) | ||
} | ||
if (!result) { | ||
return { | ||
status: false, | ||
message: 'update_address_error' | ||
} | ||
} else { | ||
return { | ||
status: true, | ||
message: 'ok' | ||
} | ||
} | ||
|
||
} | ||
} | ||
return { | ||
status: false, | ||
message: 'address_not_found' | ||
} | ||
} | ||
|
||
|
||
const deleteAddress = async (event, wxContext, user) => { | ||
let result = null | ||
for (let i = 0; i < user.address.length; i++) { | ||
if (user.address[i].id == event.addressId) { | ||
user.address.splice(i, 1) | ||
try { | ||
result = await db.collection('user').doc(user._id).update({ | ||
data: { | ||
address: user.address | ||
} | ||
}) | ||
} catch (e) { | ||
console.error(e) | ||
} | ||
if (!result) { | ||
return { | ||
status: false, | ||
message: 'update_address_error' | ||
} | ||
} else { | ||
return { | ||
status: true, | ||
message: 'ok' | ||
} | ||
} | ||
|
||
} | ||
} | ||
return { | ||
status: false, | ||
message: 'address_not_found' | ||
} | ||
} | ||
|
||
const setDefaultAddress = async (event, wxContext, user) => { | ||
let result = null | ||
let index = null | ||
for (let i = 0; i < user.address.length; i++) { | ||
if (user.address[i].id == event.addressId) { | ||
user.address[i].isDefault = true | ||
index = i | ||
} else { | ||
user.address[i].isDefault = false | ||
} | ||
} | ||
|
||
if (index === null) { | ||
return { | ||
status: false, | ||
message: 'address_not_found' | ||
} | ||
} | ||
|
||
try { | ||
result = await db.collection('user').doc(user._id).update({ | ||
data: { | ||
address: user.address | ||
} | ||
}) | ||
} catch (e) { | ||
console.error(e) | ||
} | ||
if (!result) { | ||
return { | ||
status: false, | ||
message: 'setdefault_address_error' | ||
} | ||
} else { | ||
return { | ||
status: true, | ||
message: 'ok' | ||
} | ||
} | ||
} | ||
|
||
|
||
module.exports = { | ||
queryAddress: queryAddress, | ||
getAddress: getAddres, | ||
saveAddress: saveAddress, | ||
deleteAddress: deleteAddress, | ||
setDefaultAddress: setDefaultAddress | ||
} |
Oops, something went wrong.