-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfruit.py
648 lines (586 loc) · 23.1 KB
/
fruit.py
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
#!/usr/bin/env python
#coding=utf-8
import sys
import copy
reload(sys)
sys.setdefaultencoding('utf-8')
import sqlite3
from flask import Flask, request, session, g, redirect, url_for, \
abort, render_template, flash
from contextlib import closing
from werkzeug import secure_filename
from datetime import timedelta,date
from mail import newmail,sendmail,sendmailto
import xlwt
import alipay
import time
# configuration
PATH='/home/mrfruit/fruit/'
DATABASE = PATH+'data.db'#数据库位çᄑ?
DEBUG = True
SECRET_KEY = '\xf1\x8e\x91\x17\xbb\xef\x94\xd2\xe4\x96\x8f\x13A\x03\xbc\x1d\xeb\xd9\xe8\x8e\xe3\xed\xed\xe5'
app = Flask(__name__)
app.config.from_object(__name__)
def connect_db():#连接数据åᄎ?
return sqlite3.connect(app.config['DATABASE'])
@app.before_request
def before_request():
g.db = connect_db()
@app.after_request
def after_request(response):
g.db.close()
return response
alipayTool=alipay.alipay(
partner="2088302144896577",
key="hugp0odb7elvw131cjla0s6x2aoxizqp",
sellermail="18768114571",
notifyurl="http://www.mrfruit.cn/test",
returnurl="http://www.mrfruit.cn/test2",
showurl=""
)
@app.route('/log', methods=['GET', 'POST'])
def log():
return render_template("sorry.html")
error = None
if request.method == 'POST':
phone=request.form['phone']
cur=g.db.execute('select tel,id,name,campus,building,room,score,mail from users where tel="'+phone+'"')
row=cur.fetchall()
if not row==[]:
if request.form['stuid'] != str(row[0][1]):
#if request.form['stuid'] != "000123":
error = 'wrong id'
else:
session['logged_in'] = True
session['name']=row[0][2]
session['campus']=row[0][3]
session['building']=row[0][4]
session['room']=row[0][5]
session['score']=row[0][6]
session['mail']=row[0][7]
session['phone'] = request.form['phone']
session['stuid'] = request.form['stuid']
return redirect(url_for('order'))
else:
error = 'register before login~'
return render_template("log.html",error=error)
@app.route('/edit',methods=["POST","GET"])
def edit():
if not session.get('logged_in'):
return redirect(url_for('log'))
if request.method=='POST':
building=request.form['address2']
if 'address22' in request.form and not request.form['address']=='yq':
building+=request.form['address22']
building+="舍"
try:
g.db.execute('update users set mail=?,name=?,campus=?,building=?,room=? where tel=?',[request.form['email'],request.form['name'],request.form['address'],building,request.form['address3'],session['phone']])
g.db.commit()
except :
flash('edit fail')
return render_template("edit.html")
else:
session['name']=request.form['name']
session['campus']=request.form['address']
session['building']=building
session['room']=request.form['address3']
session['mail']=request.form['email']
return redirect(url_for('order'))
return render_template("edit.html")
@app.route('/logout')
def logout():
session.pop('logged_in', None)
flash('You were logged out')
return redirect(url_for('log'))
@app.route('/changeadd',methods=['POST'])
def changeadd():
g.db.execute('update users set name=?,campus=?,building=?,room=? where tel=?',[request.form['name'],request.form['address'],
request.form['address2'],request.form['address3'],session['phone']])
g.db.commit()
#cur=g.db.execute('select * from orders where tel=?,name=?,campus=?,building=?,room=?',[session['phone'],request.form['name'],request.form['address'],
#request.form['address2'],request.form['address3']])
#row=cur.fetchall()
#if not row==[]:
session['name']=request.form['name']
session['campus']=request.form['address']
session['building']=request.form['address2']
session['room']=request.form['address3']
return redirect(url_for('order'))
@app.route('/',methods=['GET', 'POST'])
def order():
return render_template("sorry.html")
if not session.get('logged_in'):
return redirect(url_for('log'))
cur=g.db.execute('select score,news from users where tel=?',[session['phone']])
session['score'],news=cur.fetchall()[0]
cur=g.db.execute('select * from fruits order by f_id')
if news==1:
g.db.execute('update users set news=0 where tel=?',[session['phone']])
g.db.commit()
fruits=cur.fetchall()
return render_template("order.html",fruits=fruits,news=news)
@app.route('/reg',methods=['GET', 'POST'])
def reg():
if request.method=='POST':
building=request.form['address2']
if 'address22' in request.form and not request.form['address']=='yq':
building+=request.form['address22']
building+="舍"
try:
g.db.execute('insert into users values (?,?,?,?,0,?,?,?,0,0)',[request.form['phone'],request.form['stuid'],request.form['name'],
request.form['email'],request.form['address'],building,request.form['address3']])
g.db.commit()
except :
flash('phone number existed')
return render_template("reg.html")
else:
session['logged_in'] = True
session['phone'] = request.form['phone']
session['stuid'] = request.form['stuid']
session['name']=request.form['name']
session['campus']=request.form['address']
session['building']=building
session['room']=request.form['address3']
session['mail']=request.form['email']
#g.db.execute('insert into orders values(?,0,0,1,"0",?,?,?,?,0)',[request.form['phone'],request.form['name'],request.form['address']
#,request.form['address2'],request.form['address3']])
return redirect(url_for('order'))
return render_template("reg.html")
@app.route('/msg')
def msg():
if not session.get('logged_in'):
return redirect(url_for('log'))
cur=g.db.execute('select time,me,time2,fruit from msg where tel=? order by time desc',[session['phone']])
row=cur.fetchall()
return render_template("msg.html",row=row)
@app.route('/newmsg',methods=['POST'])
def newmsg():
s="tel:"+session['phone']+" name:"+session['name']+" studyid:"+session['stuid']+" email:"+session['mail']+" message:"+request.form['txt']
print s
#newmail(s)
g.db.execute('insert into msg (tel,time,me,time2,fruit) values(?,datetime("now","localtime"),?,null,null)',[session['phone'],request.form['txt']])
g.db.commit()
#flash('we have recieved message~')
return redirect(url_for('msg'))
@app.route('/history',methods=['POST','GET'])
def history():
row=[]
price=[]
if request.method=="POST":
time1,time2=request.form['time1'].replace('/','-'),request.form['time2'].replace('/','-')
time1=time1[6:]+'-'+time1[0:5]
time2=time2[6:]+'-'+time2[0:5]
cur=g.db.execute("select time from orders where re=1 and numbers>0 and tel=? and time>=? and time<=? group by time order by time desc",[session['phone'],time1,time2])
time=cur.fetchall()
if time==[]:
flash("您查询的日期内没有订单~")
for i in time:
cur=g.db.execute("select time,weekday,f_name,sum(numbers),price,id,1 from orders where re=1 and numbers>0 and tel=? and time=? group by f_name",[session['phone'],i[0]])
r=cur.fetchall()
p=0
for j in r:
p=p+j[3]*j[4]
price.append(p)
row.append(r)
else:
cur=g.db.execute("select time from orders where re=1 and numbers>0 and tel=? group by time order by time desc",[session['phone']])
time=cur.fetchall()
if time==[]:
flash("您还没有订单~")
for i in time:
cur=g.db.execute("select time,weekday,f_name,sum(numbers),price,id,1 from orders where re=1 and numbers>0 and tel=? and time=? group by f_name",[session['phone'],i[0]])
r=cur.fetchall()
p=0
for j in r:
p=p+j[3]*j[4]
price.append(p)
row.append(r)
#raise RuntimeError
return render_template("history.html",row=row,price=price)
@app.route('/history1',methods=['GET','POST'])
def history1():
row=[]
price=[]
if request.method=="POST":
time1,time2=request.form['time1'].replace('/','-'),request.form['time2'].replace('/','-')
time1=time1[6:]+'-'+time1[0:5]
time2=time2[6:]+'-'+time2[0:5]
cur=g.db.execute("select id from orders where re=1 and numbers>0 and tel=? and buytime>=? and buytime<=? group by id order by buytime desc",[session['phone'],time1,time2])
id=cur.fetchall()
if id==[]:
flash("您查询的日期内没有订单~")
for i in id:
cur=g.db.execute("select buytime,weekday,f_name,numbers,price,id,pay from orders where re=1 and numbers>0 and tel=? and id=?",[session['phone'],i[0]])
r=cur.fetchall()
p=0
for j in r:
p=p+j[3]*j[4]
price.append(p)
row.append(r)
else:
cur=g.db.execute("select id from orders where re=1 and numbers>0 and tel=? group by id order by buytime desc",[session['phone']])
id=cur.fetchall()
if id==[]:
flash("您还没有订单~")
for i in id:
cur=g.db.execute("select buytime,weekday,f_name,numbers,price,id,pay from orders where re=1 and numbers>0 and tel=? and id=?",[session['phone'],i[0]])
r=cur.fetchall()
p=0
for j in r:
p=p+j[3]*j[4]
price.append(p)
row.append(r)
return render_template("history.html",row=row,price=price)
@app.route('/receive/<id>')
def receive(id):
g.db.execute("insert into receive values(?)",[id])
g.db.commit()
flash("已收到!我们会尽快联系你~")
return redirect(url_for("history"))
@app.route('/questions')
def questions():
return render_template("questions.html")
@app.route('/re',methods=['GET','POST'])
def re():
#g.db.execute('update orders set re=1 where tel=? and name=? and campus=? and building=? and room=? and time>?',
#[session['phone'],session['name'],session['campus'],session['building'],session['room'],str(date.today())])
#g.db.commit()
f=request.form
no=session['phone']+time.strftime('%Y%m%d%H%M%S',time.localtime(time.time()))
if request.method=="POST":
g.db.execute('delete from orders where re=0 and tel=?',[session['phone']])
g.db.commit()
w=date.isoweekday(date.today())
for key in f:
weekday=int(key[0])
f_id=int(key[2:])
numbers=int(f[key])
f_name,price=g.db.execute('select f_name,price from fruits where f_id=?',[f_id]).fetchall()[0]
if weekday>w:
setime=date.today()+timedelta(days=(weekday-w))
else:
setime=date.today()+timedelta(days=(7-w+weekday))
g.db.execute('insert into orders values(?,?,?,?,?,?,?,?,?,?,?)',[no,session['phone'],f_id,numbers,weekday,setime,0,f_name,price,0,date.today()])
g.db.commit()
money=g.db.execute('select sum(price*numbers) from orders where pay=0 and re=1 and tel=?',[session['phone']]).fetchall()[0][0]
if money:
session['money']=float(money)
else:
session['money']=0
row=[]
price=[]
cur=g.db.execute("select time from orders where re=0 and numbers>0 and tel=? and time>? group by time order by time",[session['phone'],date.today()])
ti=cur.fetchall()
for i in ti:
cur=g.db.execute("select time,weekday,f_name,numbers,price,id from orders where re=0 and numbers>0 and tel=? and time=?",[session['phone'],i[0]])
r=cur.fetchall()
p=0
for j in r:
p=p+j[3]*j[4]
price.append(p)
row.append(r)
total_fee=0
for i in price:
total_fee+=i
params={
'out_trade_no':no,
'subject' :"NO"+no,
'body' :"水果"+no,
'logistics_type':'POST',
'logistics_fee':'0',
'logistics_payment':'BUYER_PAY',
'price':str(total_fee+session['money']),
'quantity':'1',
'total_fee' :str(total_fee+session['money']),
'receive_name':session['name'],
'receive_address':session['campus']+session['building']+session['room'],
'receive_zip':'310013',
'receive_mobile':session['phone']
}
payhtml=alipayTool.createPayForm(params)
#将payhtml写到页面,这是个包含有提交按钮的表单
#flash('Your orders have been submited~~')
return render_template("list.html",payhtml=payhtml,row=row,price=price,total_fee=total_fee)
@app.route('/nopay',methods=['POST'])
def nopay():
f=request.form
g.db.execute('update orders set re=1 where id=?',[f['out_trade_no']])
g.db.commit()
money=g.db.execute('select sum(price*numbers) from orders where pay=0 and re=1 and tel=?',[session['phone']]).fetchall()[0][0]
if money:
session['money']=float(money)
else:
session['money']=0
g.db.execute('update users set money=? where tel=?',[float(money),session['phone']])
g.db.commit()
return render_template("later.html")
@app.route('/test',methods=['POST'])
def test():
f=request.form
rlt=alipayTool.notifiyCall(f,verify=True)
if rlt=='success':
total=0
ids=g.db.execute('select id from orders where tel=? and pay=0 group by id',[f['receive_mobile']]).fetchall()
for id in ids:
fee=g.db.execute('select sum(numbers*price) from orders where id=?',[id[0]]).fetchall()[0][0]
if fee>=10:
total+=fee
g.db.execute('update users set score=score+? where tel=?',[int(total/10),f['receive_mobile']])
g.db.execute('update orders set re=1,pay=1 where tel=?',[f['receive_mobile']])
g.db.commit()
return rlt
@app.route('/test2',methods=['GET'])
def test2():
f=request.args
rlt=alipayTool.notifiyCall(f,verify=True)
#raise RuntimeError
if rlt=='success':
return redirect(url_for('order'))
else:
return redirect(url_for('msg'))
@app.route('/weekly/<tel>')
def weekly(tel):
setime=date.today()+timedelta(days=-7)
cur=g.db.execute('select f_name,sum(numbers),price from orders inner join fruits on orders.f_id=fruits.f_id where orders.tel=? and re=1 and numbers>0 and time>? and time<? group by orders.f_id',[tel,str(setime),str(date.today())])
row=cur.fetchall()
price=0
for i in row:
price=price+i[1]*i[2]
return render_template('weekly.html',row=row,price=price)
@app.route('/daily/<tel>')
def daily(tel):
setime=date.today()+timedelta(days=1)
cur=g.db.execute('select f_name,sum(numbers),price from orders inner join fruits on orders.f_id=fruits.f_id where orders.tel=? and numbers>0 and re=1 and time=? group by orders.f_id',[tel,str(setime)])
row=cur.fetchall()
price=0
for i in row:
price=price+i[1]*i[2]
return render_template('daily.html',row=row,price=price)
@app.route('/admin')
def admin():
if not session.get('admin'):
return redirect(url_for('adminlog'))
return render_template('admin.html')
@app.route('/excel1')
def excel1():
if not session.get('admin'):
return redirect(url_for('adminlog'))
#表格1,水果种类,总数量,时间
cur=g.db.execute('select f_name,sum(numbers),time from orders where re=1 and time>=? and numbers>0 group by time,f_name',[str(date.today())])
row=cur.fetchall()
file = xlwt.Workbook(encoding="utf-8")
sheet = file.add_sheet('sheet1',cell_overwrite_ok=True)
sheet.write(0,0,"水果")
sheet.write(0,1,"数量")
sheet.write(0,2,"时间")
p=1
for i in row:
for j in (range(3)):
sheet.write(p,j,i[j])
p=p+1
file.save(PATH+'static/1_fruit_sum_time.xls')
return '<a href="/static/1_fruit_sum_time.xls">下载</a>'
@app.route('/excel2')
def excel2():
if not session.get('admin'):
return redirect(url_for('adminlog'))
#表格2
cur=g.db.execute('select users.tel,name,campus,building,room,f_name,numbers,time from users inner join orders on users.tel=orders.tel where re=1 and numbers>0 and time>=? order by time,campus,building,room,name',[str(date.today())])
row=cur.fetchall()
file = xlwt.Workbook(encoding="utf-8")
sheet = file.add_sheet('sheet1',cell_overwrite_ok=True)
sheet.write(0,0,"电话")
sheet.write(0,1,"姓名")
sheet.write(0,2,"校区")
sheet.write(0,3,"宿舍楼")
sheet.write(0,4,"寝室号")
sheet.write(0,5,"水果")
sheet.write(0,6,"数量")
sheet.write(0,7,"时间")
p=1
for i in row:
for j in (range(8)):
sheet.write(p,j,i[j])
p=p+1
file.save(PATH+'static/2_user_position_fruit.xls')
return '<a href="/static/2_user_position_fruit.xls">下载</a>'
@app.route('/exceloreal')
def exceloreal():
if not session.get('admin'):
return redirect(url_for('adminlog'))
#表格2
cur=g.db.execute('select users.tel,name,f_name,numbers from users inner join orealorders on users.tel=orealorders.tel where re=1 and numbers>0 order by name')
row=cur.fetchall()
file = xlwt.Workbook(encoding="utf-8")
sheet = file.add_sheet('sheet1',cell_overwrite_ok=True)
sheet.write(0,0,"电话")
sheet.write(0,1,"姓名")
sheet.write(0,2,"产品")
sheet.write(0,3,"数量")
p=1
for i in row:
for j in (range(4)):
sheet.write(p,j,i[j])
p=p+1
file.save(PATH+'static/oreal.xls')
return '<a href="/static/oreal.xls">下载</a>'
@app.route('/excel3')
def excel3():
if not session.get('admin'):
return redirect(url_for('adminlog'))
cur=g.db.execute('select campus,f_name,sum(numbers),time from orders inner join users on orders.tel=users.tel where re=1 and time>=? and numbers>0 group by time,f_name,campus order by time,campus',[str(date.today())])
row=cur.fetchall()
file = xlwt.Workbook(encoding='utf-8')
sheet = file.add_sheet('sheet1',cell_overwrite_ok=True)
sheet.write(0,0,"校区")
sheet.write(0,1,"水果")
sheet.write(0,2,"数量")
sheet.write(0,3,"时间")
p=1
for i in row:
for j in (range(4)):
sheet.write(p,j,i[j])
p=p+1
file.save(PATH+'static/3_campus_fruit_sum_time.xls')
return '<a href="/static/3_campus_fruit_sum_time.xls">下载</a>'
@app.route('/excel4')
def excel4():
if not session.get('admin'):
return redirect(url_for('adminlog'))
cur=g.db.execute('select f_name,sum(numbers),price,sum(numbers)*price from orders where re=1 and time=? and numbers>0 group by time,f_name',[str(date.today()+timedelta(days=-1))])
row=cur.fetchall()
file = xlwt.Workbook(encoding='utf-8')
sheet = file.add_sheet('sheet1',cell_overwrite_ok=True)
sheet.write(0,0,"水果")
sheet.write(0,1,"数量")
sheet.write(0,2,"单价")
sheet.write(0,3,"总额")
p=1
for i in row:
for j in (range(4)):
sheet.write(p,j,i[j])
p=p+1
file.save(PATH+'static/4_fruit_summoney.xls')
return '<a href="/static/4_fruit_summoney.xls">下载</a>'
@app.route('/excel5')
def excel5():
if not session.get('admin'):
return redirect(url_for('adminlog'))
#表格2
cur=g.db.execute('select users.tel,name,sum(numbers*price) from users inner join orders on users.tel=orders.tel where re=1 and numbers>0 and time=? group by users.tel',[str(date.today()+timedelta(days=-1))])
row=cur.fetchall()
file = xlwt.Workbook(encoding="utf-8")
sheet = file.add_sheet('sheet1',cell_overwrite_ok=True)
sheet.write(0,0,"电话")
sheet.write(0,1,"姓名")
sheet.write(0,2,"总金额")
p=1
for i in row:
for j in (range(3)):
sheet.write(p,j,i[j])
p=p+1
file.save(PATH+'static/5_user_money.xls')
return '<a href="/static/5_user_money.xls">下载</a>'
@app.route('/excel6')
def excel6():
if not session.get('admin'):
return redirect(url_for('adminlog'))
#表格2
cur=g.db.execute('''select orders.tel,name from orders inner join users on orders.tel=users.tel where time<=? and time>=?
except select orders.tel,name from orders inner join users on orders.tel=users.tel where time>=?''',[str(date.today()+timedelta(days=-14)),str(date.today()+timedelta(days=-28)),str(date.today()+timedelta(days=-14))])
row=cur.fetchall()
file = xlwt.Workbook(encoding="utf-8")
sheet = file.add_sheet('sheet1',cell_overwrite_ok=True)
sheet.write(0,0,"电话")
sheet.write(0,1,"姓名")
p=1
for i in row:
for j in (range(2)):
sheet.write(p,j,i[j])
p=p+1
file.save(PATH+'static/6_user.xls')
return '<a href="/static/6_user.xls">近两周没订_再上两周订过</a>'
@app.route('/excel7')
def excel7():
if not session.get('admin'):
return redirect(url_for('adminlog'))
#表格2
cur=g.db.execute('''select orders.tel,name from orders inner join users on orders.tel=users.tel where time>=?
except select orders.tel,name from orders inner join users on orders.tel=users.tel where time>=? and time<=?''',[str(date.today()+timedelta(days=-14)),str(date.today()+timedelta(days=-28)),str(date.today()+timedelta(days=-14))])
row=cur.fetchall()
file = xlwt.Workbook(encoding="utf-8")
sheet = file.add_sheet('sheet1',cell_overwrite_ok=True)
sheet.write(0,0,"电话")
sheet.write(0,1,"姓名")
p=1
for i in row:
for j in (range(2)):
sheet.write(p,j,i[j])
p=p+1
file.save(PATH+'static/7_user.xls')
return '<a href="/static/7_user.xls">最近两周新订</a>'
@app.route('/adminlog',methods=['GET','POST'])
def adminlog():
if request.method=='POST':
if request.form['name']=="admin" and request.form['password']=="mrfruit123":
session['admin']=True
return redirect(url_for('admin'))
else:
return redirect(url_for('adminlog'))
else:
return render_template('adminlog.html')
@app.route('/admindomsg',methods=['GET','POST'])
def admindomsg():
if not session.get('admin'):
return redirect(url_for('adminlog'))
if request.method=='POST':
g.db.execute('update msg set time2=datetime("now","localtime"),fruit=? where id=?',[request.form['re'],request.form['id']])
g.db.commit()
return redirect(url_for('admindomsg'))
else:
row=g.db.execute('select id,tel,time,me from msg where fruit is null order by time desc').fetchall()
return render_template("admindomsg.html",row=row)
@app.route('/showmsg')
def showmsg():
if not session.get('admin'):
return redirect(url_for('adminlog'))
row=g.db.execute('select * from msg where time2 is not null order by time desc').fetchall()
s="<a href='/admindomsg'>显示未处理留言</a>"
for i in row:
s+='<p>id:'+str(i[0])+"</p>"+'<p>tel:'+i[1]+'</p>'+'<p>time:'+i[2]+'</p>'+'<p>'+i[3]+'</p>'+'<p> retime:'+i[4]+'</p>'+'<p> re'+i[5]+'</p><hr>'
return s
@app.route('/showreceive')
def showreceive():
if not session.get('admin'):
return redirect(url_for('adminlog'))
row=g.db.execute('select orders.id,tel,time from receive inner join orders on receive.id=orders.id group by orders.id').fetchall()
s=""
for i in row:
s+='<p>订单编号:'+i[0]+' 联系电话:'+i[1]+' 时间:'+i[2]+'</p><a href="/doreceive/'+i[0]+'">已处理</a><hr>'
return s
@app.route('/doreceive/<id>')
def doreceive(id):
if not session.get('admin'):
return redirect(url_for('adminlog'))
g.db.execute("delete from receive where id=?",[id])
g.db.commit()
return redirect(url_for("showreceive"))
@app.route('/rootadd',methods=['GET','POST'])
def rootadd():
f_list=g.db.execute("select f_id,f_name,price from fruits").fetchall()
if request.method=='POST':
f_name,price=f_list[int(request.form['f_id'])-1][1:]
setime=request.form['time']
weekday=date.isoweekday(date(int(setime[0:4]),int(setime[5:7]),int(setime[8:10])))
no=request.form['tel']+time.strftime('%Y%m%d%H%M%S',time.localtime(time.time()))
g.db.execute("insert into orders (id,tel,f_id,numbers,time,re,f_name,price,pay,weekday) values (?,?,?,?,?,?,?,?,?,?)",[no,request.form['tel'],request.form['f_id'],request.form['numbers'],request.form['time'],1,f_name,price,1,weekday])
g.db.commit()
flash("添加成功")
return render_template("rootadd.html",f_list=f_list)
@app.route('/adminlogout')
def adminlogout():
session.pop('admin', None)
return redirect(url_for('adminlog'))
if __name__ == '__main__':
app.debug=True
app.run(host='0.0.0.0')