def post(self): code = self.get_argument("code", "") cardno = self.get_argument("cardno", "") cardid = self.get_argument("cardid", "") cardtype = self.get_argument("cardtype", "") price = self.get_argument("price", "") post_data = {} # for key in self.request.arguments: # post_data[key] = self.get_arguments(key) # print post_data if not price or float(price) < 0.5: self.finish("2") return charge = chargemodel(self) # 验证电桩是否存在 device = charge.device_info(code) if device: # 设备存在 则验证卡 uinfo = charge.user_card(cardno, cardtype, cardid) if uinfo: # 订单唯一性 only = charge.only_order(uinfo["id"]) if not only: self.finish("3") return # 卡也存在 thistime = int(time.time()) order = charge.make_order(uinfo["id"], code, thistime, price) if order: self.finish("1") return self.finish("0")
def get(self): openid = self.get_secure_cookie('openid') #openid = 'oXq4LtyH8lET2u6iTuvxnWJGxr68' page = self.get_argument('page',1) showtime = self.get_argument('st','1') if showtime == '1': #一个月内 creatime = int(time.time()-2592000) elif showtime == '2': #六个月内 creatime = int(time.time()-15552000) user = usermodel(self) #绑定用户信息 info = user.userbind(openid) charge = chargemodel(self) #查询条件 where = {'o.user_id =':int(info['id']),'o.creatime >=':creatime} #查询列表 clist = charge.chargelist(where,int(page),4) #页面信息 if clist: page_info = charge.page_bar(2) if page_info['all_num'] > page_info['per_page']: more = True else: more = False else: more = False page_info = {'this_page':1,'all_page':0} self.render("wechat/recharge.html",clist=clist,st=showtime,more=more,pinfo=page_info)
def get(self): id = self.get_argument('id','') page = self.get_argument('page',1) start = self.get_argument('start','') end = self.get_argument('end','') user = usermodel(self) #绑定用户信息 # print id # return info = user.trueinfo( '', id ) charge = chargemodel(self) #查询条件 where = {'o.user_id =':int(info['id'])} if start: st = time.mktime(time.strptime(start,'%Y-%m-%d')) where['o.creatime >='] = st if end: en = time.mktime(time.strptime(end,'%Y-%m-%d')) where['o.creatime <='] = en #查询列表 clist = charge.chargelist(where,int(page),20) #页面信息 if clist: page_bar = charge.page_bar(1) pinfo = charge.page_bar(2) else: page_bar = None pinfo = {'this_page':1,'all_page':0,'per_page':20} search = {'start':start,'end':end} self.render("admin/rechargelist.html",id=id,clist=clist,page_bar=page_bar,pinfo=pinfo,search=search)
def get(self): openid = self.get_secure_cookie('openid') user = usermodel(self) info = user.userbind(openid) charge = chargemodel(self) info['balance'] = charge.getpackage(info['id']) self.render("wechat/ucenter.html", info=info )
def get(self): cardno = self.get_argument('cardno','') cardid = self.get_argument('cardid','') cardtype = self.get_argument('cardtype','') page = self.get_argument('page','1') per_page = self.get_argument('per_page',15) target = self.get_argument('target','') valid = validate() valid.Add( cardno,'识别码', ['Isdigit'] ) valid.Add( cardid,'卡号', ['NoEmpty','Isdigit'] ) valid.Add( cardtype,'卡分类', ['NoEmpty','Isdigit'] ) valid.Add( page,'当前页', ['NoEmpty','Isdigit'] ) valid.Add( per_page,'每页显示', ['NoEmpty','Isdigit'] ) if not valid._CheckMate(): self.finish( self.respone_data( 0, valid._Message() ) ) return user = usermodel(self) userid = user.carduser(cardno,cardtype,cardid) charge = chargemodel(self) if target == 'deposit': where = {'user_id =':userid['user_id']} dlist = charge.savelist(where,int(page),int(per_page)) elif target == 'recharge': where = {'o.user_id =':userid['user_id'],'o.finish >':0} dlist = charge.chargelist(where,int(page),int(per_page)) else: dlist = [] self.render("point/print.html",dlist=json.dumps(dlist),target=target,cardno=cardno,cardid=cardid,cardtype=cardtype,page=page,per_page=per_page)
def get(self): cardno = self.get_argument('cardno','') cardid = self.get_argument('cardid','') cardtype = self.get_argument('cardtype','') page = self.get_argument('page','1') per_page = self.get_argument('per_page','20') valid = validate() valid.Add( cardno,'识别码', ['NoEmpty','Isdigit'] ) valid.Add( cardid,'卡号', ['NoEmpty','Isdigit'] ) valid.Add( cardtype,'卡分类', ['NoEmpty','Isdigit'] ) valid.Add( page,'当前页', ['NoEmpty','Isdigit'] ) valid.Add( per_page,'每页显示', ['NoEmpty','Isdigit'] ) if not valid._CheckMate(): self.finish( self.respone_data( 0, valid._Message() ) ) return user = usermodel(self) userid = user.carduser(cardno,cardtype,cardid) charge = chargemodel(self) #查询条件 if userid: where = {'o.user_id =':userid['user_id'],'o.finish >':0} clist = charge.chargelist(where,int(page),int(per_page)) if clist: pinfo = charge.page_bar(2) else: clist = [] pinfo = {'this_page':1,'all_page':0,'all_num':0,'per_page':per_page} self.finish( self.respone_list( clist, pinfo ) ) else: self.finish( self.respone_data( 0, apimsg.notice(222) ) )
def get(self): openid = self.get_secure_cookie('openid') user = usermodel(self) info = user.userbind(openid) charge = chargemodel(self) balance = charge.getpackage(info['id']) self.render("wechat/money.html", balance=balance)
def get(self): id = self.get_argument('id','') charge = chargemodel(self) res = charge.del_recharge(id) if res == 1: self.prompt( 1, apimsg.notice(305), self.request.headers['Referer'] ) else: self.prompt( 0, apimsg.notice(307), 'javascript:history.go(-1)', res )
def post(self): code = self.get_argument('code','') openid = self.get_secure_cookie('openid') # openid = 'oXq4Lt-ob9EmU2AITP8Cz6Ur-bac' user = usermodel(self) info = user.userbind(openid) card = user.cardinfo(info['id']) charge = chargemodel(self) order_info = charge.search_order( code,info['id'] ) #当前电桩详情 device_info = charge.device_info( code ) if device_info and device_info['status'] == 2: #订单状态为充电中 if order_info: code = order_info['code'] kind = int(code[0:4]) + 0xC000 no = int(code[4:]) #获取访问的地址 _socket = SOCKETClient(setting['from_address'], setting['from_port'],False) packed_data = _socket.get_data(kind,no) respone = _socket.handle_send( packed_data ) ip,port = _socket.find_ip( respone ) if not ip: #地址获取失败 self.finish('5') return #发起soket去通知电桩 停止充电 datas = [ card['cardtype'], card['cardid'] ] _send = SOCKETClient(ip, port) s = struct.Struct('<HI') packed_data = s.pack(*datas) new_datas = [ord(x) for x in packed_data] set_data = _send.set_data(kind,no,0x9,0x0,new_datas) try: respone = _send.handle_send( set_data ) except: #访问超时 self.finish('4') return # print [hex(ord(x)) for x in respone] if ord(respone[9]) == 0xc4: #离线 self.finish('0') else: #正常完成 self.finish('1') else: #充电已经完成 self.finish('2') else: #电桩非工作中 self.finish('3')
def get(self): page = self.get_argument('page',1) where = {'o.finish =':0} charge = chargemodel(self) clist = charge.workinglist(where,int(page),20) if clist: page_bar = charge.page_bar(1) pinfo = charge.page_bar(2) else: page_bar = None pinfo = {'this_page':1,'all_page':0,'per_page':20} self.render("admin/recharging.html",clist=clist,page_bar=page_bar,pinfo=pinfo)
def get(self): id = self.get_argument('id','') openid = self.get_secure_cookie('openid') #openid = 'oXq4LtyH8lET2u6iTuvxnWJGxr68' user = usermodel(self) info = user.userbind(openid) charge = chargemodel(self) detail = charge.order_info(id) #验证自己的订单以及 if detail and detail['user_id'] == int(info['id']): self.render("wechat/charge_detail.html", detail=detail) else: self.tips( 0, apimsg.notice(400) )
def get(self): oid = self.get_argument('oid','') if oid: charge = chargemodel(self) info = charge.order_info(oid) if info and info['finish'] == 0: res = charge.error_end( oid ) if res: #写入日志 self.prompt( 1, apimsg.notice(305), self.request.headers['Referer'] ) else: self.prompt( 0, apimsg.notice(307), 'javascript:history.go(-1)' ) else: self.prompt( 0, apimsg.notice(223), 'javascript:history.go(-1)' ) else: self.prompt( 0, apimsg.notice(400), 'javascript:history.go(-1)' )
def get(self): session = self.get_secure_cookie('session') card = cardmodel(self) username = card.getusername( session ) user = usermodel(self) #用户信息 uinfo = user.userinfo(username) oid = self.get_argument('oid','') if id: charge = chargemodel(self) detail = charge.order_info(oid) #验证自己的订单以及 if detail and detail['user_id'] == int(uinfo['id']): self.finish( json.dumps(detail) ) return self.finish( '0' )
def get(self): openid = self.get_secure_cookie('openid') #openid = 'oXq4LtyH8lET2u6iTuvxnWJGxr68' user = usermodel(self) info = user.userbind(openid) charge = chargemodel(self) balance = charge.getpackage(info['id']) code = charge.get_pile(info['id']) combos = charge.charge_combos() price = charge.newPrice( time.time() ) if not code: self.tips( 0, apimsg.notice(400), '/recharge' ) return if not price: self.tips( 0, apimsg.notice(211) ) return self.render("wechat/combo.html", code=code, balance=balance, combos=combos, price=price )
def post(self): page = self.get_argument('page',1) session = self.get_secure_cookie('session') card = cardmodel(self) username = card.getusername( session ) user = usermodel(self) uinfo = user.userinfo(username) charge = chargemodel(self) where = {'o.user_id =':int(uinfo['id']),'o.finish >':0} clist = charge.chargelist(where,int(page),10) if clist: #页面信息 pinfo = charge.page_bar(2) reback = {'clist':clist,'pinfo':pinfo} self.finish( json.dumps(reback) ) else: self.finish('0')
def post(self): cardno = self.get_argument('cardno','') cardid = self.get_argument('cardid','') cardtype = self.get_argument('cardtype','') money = self.get_argument('money',0) valid = validate() valid.Add( cardno,'识别码', ['NoEmpty','Isdigit'] ) valid.Add( cardtype,'分类', ['NoEmpty','Isdigit'] ) valid.Add( cardid,'卡id', ['NoEmpty','Isdigit'] ) valid.Add( money,'钱数', ['NoEmpty','Isdigit'] ) if not valid._CheckMate(): self.finish( self.respone_data( 0, valid._Message() ) ) return #当前商家信息 session = self.get_secure_cookie('seller') card = cardmodel(self) sid = card.get_seller_id( session ) seller = card.sellerinfo( sid ) #用户信息 user = usermodel(self) userid = user.carduser(cardno,cardtype,cardid) if userid: uid = userid['user_id'] uinfo = user.trueinfo( '', uid ) charge = chargemodel(self) balance = charge.getpackage( uid ) #金额计算 fakemoney = int(money)*100 newmoney = ( float(balance)*100+fakemoney ) / 100 #当前时间 nowtime = int(time.time()) #订单号 oid = user.build_order() #描述组合 descript = seller['sellername']+u'用户'+uinfo['username']+'('+uinfo['nickname']+u')充值'+money log = logmodel(self) try: log.change_purse( newmoney, uid ) log.save_order( oid, uid, money, nowtime, 'point', seller['sellername'] ) log.save_payments( oid, sid, money, uid, descript, nowtime ) log.commit_submit() self.finish( self.respone_data( 1 ) ) except: self.finish( self.respone_data( 0, apimsg.notice(307) ) ) else: self.finish( self.respone_data( 0, apimsg.notice(222) ) )
def get(self): code = self.get_argument('charge-number','') openid = self.get_secure_cookie('openid') #openid = 'oXq4LtyH8lET2u6iTuvxnWJGxr68' valid = validate() valid.Add( code,'设备码', ['NoEmpty','Isdigit','IsLegalAccounts'], 12, 12 ) if not valid._CheckMate(): #跳转去相关页面 self.tips( 0, apimsg.notice(400), 'back', valid._Message() ) return user = usermodel(self) info = user.userbind(openid) charge = chargemodel(self) res = charge.bind_pile( info['id'], code ) if res == 1: self.redirect('/combo') else: self.tips( 0, res )
def get(self): left = {} dev = devicemodel(self) #电桩异常提示数量 left['error'] = dev.error_number() nowtime = int(time.time()) #电桩异常提示详情 if left['error'] > 0: dlist = dev.error_list( nowtime ) else: dlist = None charge = chargemodel(self) where = {'o.finish =':0} clist = charge.workinglist(where,1,1) pinfo = charge.page_bar(2) if pinfo: left['working'] = pinfo['all_num'] else: left['working'] = 0 self.render("admin/main.html",left=left,dlist=dlist)
def get(self): #获取访问openid openid = self.get_secure_cookie('openid') if not openid or openid == 'None': code = self.get_argument('code','') openid = self.rd.get('code:'+code) if not openid or openid == 'None': #redis依然无法获取openid self.write_error(2) user = usermodel(self) info = user.userbind(openid) if info['bind']: #已经绑定 charge = chargemodel(self) info['balance'] = charge.getpackage(info['id']) card = user.cardinfo(info['id']) else: #未绑定 info['balance'] = 0 card = {'cardtype':0,'cardid':0} self.render("wechat/index.html", info=info, card=card)
def post(self): code = self.get_argument("code", "") cardno = self.get_argument("cardno", "") cardid = self.get_argument("cardid", "") cardtype = self.get_argument("cardtype", "") pay = self.get_argument("pay", "") # 冻结(消费)金额 elec = self.get_argument("elec", "") # 电量 finish = self.get_argument("finish", "") # 订单完成状态 acttime = self.get_argument("acttime", "") # 耗时 # 检查是否有冻结资金 if float(pay) < 0: # 没冻结资金 self.finish("2") return charge = chargemodel(self) # 电桩找到绑定用户 user = charge.user_card(cardno, cardtype, cardid) # 用户等待订单只能有一个 if user: status = charge.once_order(user["id"], code) # 订单数量异常 if not status: # 状态 self.finish("3") return # 结算 param = { "code": code, "pay": float(pay), "elec": float(elec), "finish": int(finish), "acttime": int(acttime), } res = charge.account(**param) if res: self.finish("1") return self.finish("0")
def post(self): page = self.get_argument('page',1) openid = self.get_secure_cookie('openid') #openid = 'oXq4LtyH8lET2u6iTuvxnWJGxr68' showtime = self.get_argument('st','1') if showtime == '1': #一个月内 creatime = int(time.time()-2592000) elif showtime == '2': #六个月内 creatime = int(time.time()-15552000) user = usermodel(self) #绑定用户信息 info = user.userbind(openid) #查询条件 where = {'o.user_id =':int(info['id']),'o.creatime >=':creatime} charge = chargemodel(self) #查询列表 clist = charge.chargelist(where,int(page),4) #页面信息 if clist: self.write(json.dumps(clist)) else: self.write(False)
def post(self): cardno = self.get_argument('cardno','') cardnumber = self.get_argument('cardnumber','') money = self.get_argument('money',0) valid = validate() valid.Add( cardno,'识别码', ['NoEmpty','Isdigit'] ) valid.Add( cardnumber,'卡号', ['NoEmpty','Isdigit','IsAccessLen'], 12, 12 ) valid.Add( float(money),'钱数', ['NoEmpty','IsFloat'] ) if not valid._CheckMate(): self.finish( self.respone_data( 0, valid._Message() ) ) return user = usermodel(self) cardtype = int(cardnumber[0:4]) cardid = int(cardnumber[4:]) userid = user.carduser(cardno,cardtype,cardid) charge = chargemodel(self) balance = charge.getpackage( userid['user_id'] ) money = int(float(money)*100) newmoney = float(balance)*100+float(money) res = user.purse_edit( id=userid['user_id'], balance=newmoney/100 ) if res == '1': self.finish( self.respone_data( 1 ) ) else: self.finish( self.respone_data( 0, apimsg.notice(307) ) )
def get(self): cardno = self.get_argument('cardno','') cardnumber = self.get_argument('cardnumber','') start = self.get_argument('start','') end = self.get_argument('end','') page = self.get_argument('page','1') per_page = self.get_argument('per_page','10') valid = validate() valid.Add( cardno,'识别码', ['Isdigit'] ) valid.Add( cardnumber,'卡号', ['Isdigit','IsAccessLen'], 12, 12 ) valid.Add( page,'当前页', ['NoEmpty','Isdigit'] ) valid.Add( per_page,'每页显示', ['NoEmpty','Isdigit'] ) if not valid._CheckMate(): self.finish( self.respone_data( 0, valid._Message() ) ) return user = usermodel(self) cardtype = int(cardnumber[0:4]) cardid = int(cardnumber[4:]) userid = user.carduser(cardno,cardtype,cardid) charge = chargemodel(self) #查询条件 if userid: where = {'user_id =':userid['user_id']} if start and start.isdigit(): where['acttime >='] = start if end and end.isdigit(): where['acttime <='] = end dlist = charge.savelist(where,int(page),int(per_page)) if dlist: pinfo = charge.page_bar(2) else: dlist = [] pinfo = {'this_page':1,'all_page':0,'all_num':0,'per_page':per_page} self.finish( self.respone_list( dlist, pinfo ) ) else: self.finish( self.respone_data( 0, apimsg.notice(222) ) )
def post(self): openid = self.get_secure_cookie('openid') #openid = 'oXq4LtyH8lET2u6iTuvxnWJGxr68' user = usermodel(self) info = user.userbind(openid) card = user.cardinfo(info['id']) choose = self.get_argument('choose','') code = self.get_argument('code','') value = self.get_argument(choose+'_input','') valid = validate() valid.Add( code,'设备码', ['NoEmpty','Isdigit','IsLegalAccounts'], 12, 12 ) valid.Add( choose,'充值方式', ['NoEmpty'] ) if not valid._CheckMate(): #跳转去相关页面 self.tips( 0, apimsg.notice(400), 'back', valid._Message() ) return charge = chargemodel(self) #钱包余钱 balance = charge.getpackage(info['id']) #验证充值参数 param = check_value( choose, value, balance ) if not param: self.tips( 0, apimsg.notice(400) ) return if not card: self.tips( 0, apimsg.notice(304) ) return price = charge.newPrice( time.time() ) if not price or price < 0.5: self.tips( 0, apimsg.notice(211) ) return #获取电桩状态 待机的话就开工 status = charge.check_status( code ) if status > 1: self.tips( 0, apimsg.notice(status) ) return #订单唯一性 only = charge.only_order(info['id']) if not only: self.tips( 0, apimsg.notice(217) ) return thistime = int(time.time()) #写入订单表 #order = charge.make_order(info['id'],code,thistime) #if not order: # self.tips( 0, apimsg.notice(216) ) # return #电桩设备码 kind = int(code[0:4]) + 0xC000 no = int(code[4:]) #获取访问的地址 _socket = SOCKETClient(setting['from_address'], setting['from_port'],False) packed_data = _socket.get_data(kind,no) try: respone = _socket.handle_send( packed_data ) except: self.tips( 0, apimsg.notice(219) ) return ip,port = _socket.find_ip( respone ) if not ip: self.tips( 0, apimsg.notice(215) ) return #发起soket去通知电桩,带上设备码和用户id以及怎么充 datas = [ 4,param['token'],price*100,card['cardno'],card['cardtype'],card['cardid'],balance*100,param['money']*100,0,param['mini'],0,param['elec']*100,0 ] _send = SOCKETClient(ip, port) s = struct.Struct('<BBHIHIIIIHHII') packed_data = s.pack(*datas) #ns = struct.Struct('%dB' %s.size) #new_datas = ns.unpack(packed_data) new_datas = [ord(x) for x in packed_data] set_data = _send.set_data(kind,no,0x2,0x1,new_datas) try: respone = _send.handle_send( set_data ) except: self.tips( 0, apimsg.notice(219) ) return # print [hex(ord(x)) for x in respone] #异步 #asyncore.loop() if ord(respone[9]) == 0xc4: self.tips( 0, apimsg.notice(219) ) else: params = urllib.urlencode({'thistime':thistime,'choose':choose,'value':value,'code':code}) url = "/charging?%s" %(params) self.redirect( url )
def post(self): openid = self.get_secure_cookie('openid') # openid = 'oXq4LtyH8lET2u6iTuvxnWJGxr68' user = usermodel(self) info = user.userbind(openid) card = user.cardinfo(info['id']) choose = self.get_argument('choose','') code = self.get_argument('code','') value = self.get_argument('value','') valid = validate() valid.Add( code,'设备码', ['NoEmpty','Isdigit','IsLegalAccounts'], 12, 12 ) valid.Add( choose,'充值方式', ['NoEmpty'] ) if not valid._CheckMate(): #跳转去相关页面 self.finish('5') return charge = chargemodel(self) #钱包余钱 balance = charge.getpackage(info['id']) #验证充值参数 param = check_value( choose, value, balance ) if not param: self.finish('5') return #没有绑定卡 if not card: self.finish('6') return price = charge.newPrice( time.time() ) if not price or price < 0.5: self.finish('7') return #设备状态判断 status = charge.check_status( code ) if status == 226: self.finish('3') return elif status == 214: self.finish('2') return elif status == 210: self.finish('4') return #订单唯一性 only = charge.only_order(info['id']) if not only: self.finish('8') return #电桩设备码 kind = int(code[0:4]) + 0xC000 no = int(code[4:]) #获取访问的地址 _socket = SOCKETClient(setting['from_address'], setting['from_port'],False) packed_data = _socket.get_data(kind,no) try: respone = _socket.handle_send( packed_data ) except: self.finish('3') return ip,port = _socket.find_ip( respone ) if not ip: self.finish('4') return #发送用户信息通知 message = str(info['nickname']) if info['nickname'] else str(info['username']) doll = message.decode('utf-8').encode('gb2312') sendmess = [] key = len(doll) #最多发送12字符 for x in range(0,12): if x < key: sendmess.append( ord( doll[x] ) ) else: sendmess.append(0) #时间 nowtime = time.localtime() datas = [ nowtime.tm_sec,nowtime.tm_min,nowtime.tm_hour,nowtime.tm_wday,5,0,0,0,0,0] + sendmess + [0] _mess = SOCKETClient(ip, port) set_mess = _mess.set_data(kind,no,0x2,0x4,datas) try: respone = _mess.handle_send( set_mess ) except: self.finish('3') return #异步 #asyncore.loop() # print balance #发起soket去通知电桩,带上设备码和用户id以及怎么充 datas = [ 3,param['token'],price*100,card['cardno'],card['cardtype'],card['cardid'],balance*100,param['money']*100,0,param['mini'],0,param['elec']*100,0 ] _send = SOCKETClient(ip, port) #数据流格式 s = struct.Struct('<BBHIHIIIIHHII') packed_data = s.pack(*datas) #ns = struct.Struct('%dB' %s.size) #new_datas = ns.unpack(packed_data) new_datas = [ord(x) for x in packed_data] set_data = _send.set_data(kind,no,0x2,0x1,new_datas) try: respone = _send.handle_send( set_data ) except: self.finish('3') return # print [hex(ord(x)) for x in respone] #异步 #asyncore.loop() if ord(respone[9]) == 0xc4: self.finish('3') else: self.finish('1')