bookCommon.js
6.09 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
import util from './util';
import App from './api';
const {regeneratorRuntime} = global
module.exports ={
//时间戳转化日期
changedate:function(timestamp){
var date = new Date(timestamp);//时间戳为10位需*1000,时间戳为13位的话不需乘1000
var Y= date.getFullYear();
var M =date.getMonth()+1;
var D =date.getDate();
var h = date.getHours();
var m = date.getMinutes();
var s = date.getSeconds();
return {year:Y,month:M,day:D,hour:h,minute:m,second:s};
},
//获取星期
getweek:function (index) {
var week=['周日','周一','周二','周三','周四','周五','周六'];
return week[index]
},
//判断是否是整数
isInteger:function (obj) {
return obj%1 === 0
},
//时间转化时间戳
gettimestamp:function(stringTime){
var date = new Date(stringTime.replace(/-/g, '/'));
var timestamp2=Date.parse(date)/1000;
return timestamp2
},
//日期转换 8月8日----08-08
get_date:function(thiadate){
var thismoth=thiadate.split('月')[0];
var thisday=thiadate.split('月')[1].slice(0,-1);
var timedate=(parseInt(thismoth)<10 ? '0'+thismoth : thismoth)+'-'+(parseInt(thisday)<10 ? '0'+thisday : thisday);
return timedate;
},
//日期转换 08-08----8月8日
getdate_num:function(thisdate){
var thismonth=thisdate.split('-')[0][0]=='0' ? thisdate.split('-')[0][1] : thisdate.split('-')[0];
var thisday=thisdate.split('-')[1][0]=='0' ? thisdate.split('-')[1][1] : thisdate.split('-')[1];
console.log()
var timedate=thismonth+'月'+thisday+'日';
return timedate;
},
//获得营业时段时间戳,用 - 链接
async getTimeSpace(mmdd='',timeIndex=0,stimestr=null,sc=null,YYYY='YYYY'){
try {
let d=new Date()/1000;
if(!mmdd){
mmdd=util.unixtoTime(d,'MM-DD');
}else{
mmdd=mmdd.replace(/[^\d-\/]/ig,'')
}
if(!sc){
let res = await App.Reserve.SellerInfo(util.cache('enter_params'));
sc = res.data;
}
if (sc.daily){
let ti=['morning','noon','night'];
let scDaily=sc.daily[ti[timeIndex]]||'00:00-23:59';
console.log('getTimeSpace',sc.daily,scDaily,timeIndex);
let ts=scDaily.split('-');
let stime
if(stimestr){
stime=util.unixtoTime(d,YYYY+'-'+mmdd+' '+stimestr);
}else{
stime=util.unixtoTime(d,YYYY+'-'+mmdd+' '+ts[0]+':00');
}
let etime=util.unixtoTime(d,YYYY+'-'+mmdd+' '+ts[1]+':00');
console.log('stime',stime,etime);
return (util.timetouUnix(stime)||0)+'-'+(util.timetouUnix(etime)||0);
}
}catch (e){
console.log(e);
}
return false;
},
//获得早中晚时间分组,
async getDayTimeSpace(sc=null){
try {
let d=new Date()/1000;
if(!sc){
let res = await App.Reserve.SellerInfo(util.cache('enter_params'));
sc = res.data;
}
if (sc.daily){
//sc.daily.morning=null;
let ti=['morning','noon','night'];
let dts=[[],[],[]];
ti.forEach((tx,ii)=>{
if(!sc.daily[tx]) return;
let ts=sc.daily[tx].split('-');
console.log('getDayTimeSpace',ts);
while (ts[0]<=ts[1]){
dts[ii].push(ts[0]);
let _dt=ts[0].split(':');
if(_dt[1]=='30'){
_dt[0]=parseInt(_dt[0])+1;
_dt[1]='00';
}else{
_dt[0]=parseInt(_dt[0])+0;
_dt[1]='30';
}
_dt[0]=_dt[0]<10?'0'+_dt[0]:_dt[0];
ts[0]=_dt.join(':');
}
})
return dts;
}
}catch (e){
console.log(e);
}
return false;
},
//获得时间戳在早中晚的索引
async getTimeSpaceIndex(d=new Date()/1000,sc=null){
try {
if(!sc){
let res = await App.Reserve.SellerInfo(util.cache('enter_params'));
sc = res.data;
}
if (sc.daily){
let ti=['morning','noon','night'];
let dti=0;
let date=util.unixtoTime(d,'HH:II')
ti.forEach((tx,ii)=>{
let ts=sc.daily[tx].split('-');
console.log('getTimeSpaceIndex',ts);
if(date>=ts[0] && ts[0]<=ts[1]){
dti=ii;
return dti;
}
})
return dti;
}
}catch (e){
console.log(e);
}
return 0;
},
//获得时间戳在早中晚的索引等
async getTimeSpaceIndexData(d=new Date()/1000,sc=null){
let day0 = new Date(new Date().setHours(0, 0, 0, 0)) / 1000 ;
let day1 = day0 + 86400;
let isDay=false;//是否今天
if(d<day1 && d>day0){
isDay=true;
}
let times=await this.getDayTimeSpace();
let nd=util.unixtoTime(d,'HH:II')
let obj={
timeIndex:0,
timeMatchIndex:0,
timeOpt:['','','']
};
for(let i=0;i<times.length;i++) {
let flag = false;
for (let j = 0; j < times[i].length; j++) {
//console.log('times', nd, times[i][j], i, j);
if (nd <= times[i][j]) {
obj.timeIndex = i;
obj.timeMatchIndex = j;
flag = true;
break;
}
}
if (flag) {
break;
}
if (isDay) {
obj.timeOpt[i] = 'disabled';
}
}
//console.log('times',obj);
return obj;
},
timeStrLabel:{'morning':'早市','noon':'午市','night':'晚市'},
}