Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhouYang committed Feb 24, 2020

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 2901a57 commit b96f92c
Showing 229 changed files with 14,374 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -102,3 +102,8 @@ dist

# TernJS port file
.tern-port

# settings
miniprogram/settings/settings.pro.js
# cloud dev settings
cloudfunctions/main/settings.js
30 changes: 30 additions & 0 deletions README.md
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
};`
149 changes: 149 additions & 0 deletions cloudfunctions/main/address.js
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
}
Loading

0 comments on commit b96f92c

Please sign in to comment.