forked from wangtunan/vue-mooc
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathbill.js
53 lines (51 loc) · 1 KB
/
bill.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import mongoose from 'mongoose'
import billData from '../initData/bill.js'
import { getGuid, getOrderId } from '../../src/utils/utils.js'
const Schema = mongoose.Schema
const BillSchema = new Schema({
id: {
type: String,
required: true,
unique: true,
index: true
},
userid: {
type: String,
required: true
},
orderno: {
type: String,
required: true
},
name: {
type: String,
required: true
},
time: {
type: String,
required: true
},
cost: {
type: Number,
required: true
},
way: {
text: String,
code: Number
}
})
const billModel = mongoose.model('bill', BillSchema)
// 判断有无数据,没有则初始化数据
export function initUserBills (userid) {
billModel.find((err, data) => {
if (!data || data.length === 0) {
billData.forEach(item => {
item.id = getGuid()
item.userid = userid,
item.orderno = getOrderId()
billModel.create(item)
})
}
})
}
export default billModel