def addSign(request): res={'code':1,'message':''} try: uid=request.GET['uid'] package=request.GET['packagename'] except: return HttpResponse(json.dumps(res)) #if True: try: moneyChanged=0 temp=downloadtask.objects.filter(packagename=package,uid=uid,percent__lt=1) if len(temp)==0: res['code']=0 res['message']=0 return HttpResponse(json.dumps(res)) item=temp[0] lasttime=item.time now=datetime.now(tz=pytz.utc) delta=now-lasttime app=App.objects.get(packagename=package) if item.percent<.8 and delta.days==1: print 'run' per=.2 moneyChanged=app.price*per item.money=item.money+moneyChanged item.percent=item.percent+per item.save() dev=Device.objects.get(uid=uid) dev.money+=moneyChanged dev.signin+=moneyChanged dev.allin+=moneyChanged dev.save() log=record() log.uid=uid log.type='sign:'+package log.amount=moneyChanged log.save() elif item.percent<.95 and delta.days==4: per=.1 moneyChanged=app.price*per item.money=item.money+moneyChanged item.percent=item.percent+per item.save() dev=Device.objects.get(uid=uid) dev.money+=moneyChanged dev.signin+=moneyChanged dev.allin+=moneyChanged dev.save() log=record() log.uid=uid log.type='sign:'+package log.amount=moneyChanged log.save() #else: except: return HttpResponse(json.dumps(res)) res['code']=0 res['message']=moneyChanged #res['message']=str(delta.days) return HttpResponse(json.dumps(res))
def addquickin(request): res = {'code': 1, 'message': ''} try: uid = request.GET['uid'] coin = float(request.GET['coin']) except: return HttpResponse(json.dumps(res)) #if True: try: device = Device.objects.get(uid=uid) money = coin / 1000.0 device.money += money device.allin += money device.quickin += money device.save() log = record() log.uid = uid log.type = 'quick:' + str(money) log.amount = money log.save() #else: except: return HttpResponse(json.dumps(res)) res['code'] = 0 res['message'] = '申请成功' return HttpResponse(json.dumps(res))
def addquickin(request): res={'code':1,'message':''} try: uid=request.GET['uid'] coin=float(request.GET['coin']) except: return HttpResponse(json.dumps(res)) #if True: try: device=Device.objects.get(uid=uid) money=coin/1000.0 device.money+=money device.allin+=money device.quickin+=money device.save() log=record() log.uid=uid log.type='quick:'+str(money) log.amount=money log.save() #else: except: return HttpResponse(json.dumps(res)) res['code']=0 res['message']='申请成功' return HttpResponse(json.dumps(res))
def addpayrequest(request): res = {'code': 1, 'message': ''} try: uid = request.GET['uid'] paytype = request.GET['paytype'] spend = float(request.GET['spend']) except: return HttpResponse(json.dumps(res)) #if True: try: device = Device.objects.get(uid=uid) if device.money < spend: res['message'] = '余额不足' return HttpResponse(json.dumps(res)) device.money -= spend device.allout += spend device.save() item = payrequest() item.uid = uid item.paytype = paytype item.spend = spend item.status = 'wait' item.save() log = record() log.uid = uid log.type = 'payrequest:' + paytype log.amount = spend log.save() #else: except: return HttpResponse(json.dumps(res)) res['code'] = 0 res['message'] = '申请成功' return HttpResponse(json.dumps(res))
def addpayrequest(request): res={'code':1,'message':''} try: uid=request.GET['uid'] paytype=request.GET['paytype'] spend=float(request.GET['spend']) except: return HttpResponse(json.dumps(res)) #if True: try: device=Device.objects.get(uid=uid) if device.money<spend: res['message']='余额不足' return HttpResponse(json.dumps(res)) device.money-=spend device.allout+=spend device.save() item=payrequest() item.uid=uid item.paytype=paytype item.spend=spend item.status='wait' item.save() log=record() log.uid=uid log.type='payrequest:'+paytype log.amount=spend log.save() #else: except: return HttpResponse(json.dumps(res)) res['code']=0 res['message']='申请成功' return HttpResponse(json.dumps(res))
def addWallpaper(request): res = {'code': 1, 'message': ''} try: uid = request.GET['uid'] wallpapername = request.GET['wallpapername'] leftorright = request.GET['lorr'] except: res['message'] = 'paramerr' return HttpResponse(json.dumps(res)) #if True: try: temp = wallpapertask.objects.filter(wallpapername=wallpapername, uid=uid) if len(temp) == 0: item = wallpapertask() item.wallpapername = wallpapername item.uid = uid item.lorr = -1 item.money = 0 item.percent = 0 item.save() temp = wallpapertask.objects.filter(wallpapername=wallpapername, uid=uid) if len(temp) > 0: item = temp[0] paper = Wallpaper.objects.get(name=wallpapername) changeMoney = 0 if leftorright == '0': changeMoney = paper.leftprice if ( item.money + paper.leftprice <= paper.maxmoney) else ( paper.maxmoney - item.money) else: changeMoney = paper.rightprice if ( item.money + paper.rightprice <= paper.maxmoney) else ( paper.maxmoney - item.money) item.money += changeMoney item.percent = item.money / paper.maxmoney dev = Device.objects.get(uid=uid) dev.money += changeMoney dev.wallpaperin += changeMoney dev.allin += changeMoney dev.save() log = record() log.uid = uid log.type = 'wallpaper:' + wallpapername + str(leftorright) log.amount = changeMoney log.save() item.save() #else: except: return HttpResponse(json.dumps(res)) res['code'] = 0 res['message'] = item.money return HttpResponse(json.dumps(res))
def addWallpaper(request): res={'code':1,'message':''} try: uid=request.GET['uid'] wallpapername=request.GET['wallpapername'] leftorright=request.GET['lorr'] except: res['message']='paramerr' return HttpResponse(json.dumps(res)) #if True: try: temp=wallpapertask.objects.filter(wallpapername=wallpapername,uid=uid) if len(temp)==0: item=wallpapertask() item.wallpapername=wallpapername item.uid=uid item.lorr=-1 item.money=0 item.percent=0 item.save() temp=wallpapertask.objects.filter(wallpapername=wallpapername,uid=uid) if len(temp)>0: item=temp[0] paper=Wallpaper.objects.get(name=wallpapername) changeMoney=0 if leftorright=='0': changeMoney=paper.leftprice if (item.money+paper.leftprice<=paper.maxmoney) else (paper.maxmoney-item.money) else: changeMoney=paper.rightprice if (item.money+paper.rightprice<=paper.maxmoney) else (paper.maxmoney-item.money) item.money+=changeMoney item.percent=item.money/paper.maxmoney dev=Device.objects.get(uid=uid) dev.money+=changeMoney dev.wallpaperin+=changeMoney dev.allin+=changeMoney dev.save() log=record() log.uid=uid log.type='wallpaper:'+wallpapername+str(leftorright) log.amount=changeMoney log.save() item.save() #else: except: return HttpResponse(json.dumps(res)) res['code']=0 res['message']=item.money return HttpResponse(json.dumps(res))
def order(request): record = models.record() trade = models.repertory() trade.uid = request.GET.get('username') trade.blank_contract = request.GET.get('blank_contract') trade.more_contract = request.GET.get('more_contract') trade.hand = request.GET.get('hand') trade.more_price = request.GET.get('more_price') trade.blank_price = request.GET.get('blank_price') trade.bond = float(request.GET.get('bond')) trade.time = request.GET.get('time') trade.add() record.more_contract = trade.more_contract record.blank_contract = trade.blank_contract record.blank_price = trade.blank_price record.more_price = trade.more_price record.time = trade.time record.hand = trade.hand record.bond = trade.bond record.state = 0 record.uid = trade.uid record.add() finance = models.finance() finance.uid = request.GET.get('username') last_finance = finance.getlast()[0] new_finance = models.finance() new_finance.uid = last_finance.uid new_finance.invest = last_finance.invest + trade.bond new_finance.total = last_finance.total new_finance.free = new_finance.total - new_finance.invest new_finance.time = trade.time new_finance.add() return HttpResponse(json.dumps({'result':1}))
def save(request): match = re.match(r'(?P<day>\d{1,2})/(?P<month>\d{1,2})/(?P<year>\d{4})', request.POST["date"]) groups = match.groupdict() edate = datetime.date(int(groups['year']), int(groups['month']), int(groups['day'])) rec = None try: for rand_url in RandomUrl(URL_LEN, URL_GEN_TRIES): rec = record(url = rand_url, name = request.POST["name"], title = request.POST["title"], text = request.POST["text"], exp_date = edate) try: rec.save(force_insert = True) break except IntegrityError: pass except LookupError: return HttpResponse("<b>Cannot search new URL</b>") return HttpResponseRedirect(reverse('paste_bin.views.viewrec', args = (rec.url,)))
def trade(request): ret = models.ret() trade = models.repertory() trade.id = request.GET.get('Repo_Id') trade.sell() record = models.record() record.more_contract = trade.blank_contract record.blank_contract = trade.more_contract try : record.blank_price = request.GET.get('blank_price') record.more_price = request.GET.get('more_price') except: return HttpResponse(json.dumps({"result":0})) record.time = request.GET.get('time') record.hand = trade.hand record.bond = trade.bond record.state = 0 record.uid = request.GET.get('username') record.add() finance = models.finance() finance.uid = record.uid last_finance = finance.getlast()[0] new_finance = models.finance() new_finance.uid = last_finance.uid new_finance.invest = last_finance.invest - trade.bond new_finance.total = last_finance.total + float(request.GET.get('profit')) new_finance.free = new_finance.total - new_finance.invest new_finance.time = trade.time new_finance.add() return HttpResponse(json.dumps({"result":1}))
def order(request): record = models.record() trade = models.repertory() trade.uid = request.GET.get('username') trade.blank_contract = request.GET.get('blank_contract') trade.more_contract = request.GET.get('more_contract') trade.hand = request.GET.get('hand') trade.more_price = request.GET.get('more_price') trade.blank_price = request.GET.get('blank_price') trade.bond = float(request.GET.get('bond')) trade.time = request.GET.get('time') trade.add() record.more_contract = trade.more_contract record.blank_contract = trade.blank_contract record.blank_price = trade.blank_price record.more_price = trade.more_price record.time = trade.time record.hand = trade.hand record.bond = trade.bond record.state = 0 record.uid = trade.uid record.add() finance = models.finance() finance.uid = request.GET.get('username') last_finance = finance.getlast()[0] new_finance = models.finance() new_finance.uid = last_finance.uid new_finance.invest = last_finance.invest + trade.bond new_finance.total = last_finance.total new_finance.free = new_finance.total - new_finance.invest new_finance.time = trade.time new_finance.add() return HttpResponse(json.dumps({'result': 1}))
def trade(request): ret = models.ret() trade = models.repertory() trade.id = request.GET.get('Repo_Id') trade.sell() record = models.record() record.more_contract = trade.blank_contract record.blank_contract = trade.more_contract try: record.blank_price = request.GET.get('blank_price') record.more_price = request.GET.get('more_price') except: return HttpResponse(json.dumps({"result": 0})) record.time = request.GET.get('time') record.hand = trade.hand record.bond = trade.bond record.state = 0 record.uid = request.GET.get('username') record.add() finance = models.finance() finance.uid = record.uid last_finance = finance.getlast()[0] new_finance = models.finance() new_finance.uid = last_finance.uid new_finance.invest = last_finance.invest - trade.bond new_finance.total = last_finance.total + float(request.GET.get('profit')) new_finance.free = new_finance.total - new_finance.invest new_finance.time = trade.time new_finance.add() return HttpResponse(json.dumps({"result": 1}))
def adddownload(request): res = {'code': 1, 'message': ''} try: uid = request.GET['uid'] package = request.GET['packagename'] except: return HttpResponse(json.dumps(res)) #if True: try: temp = downloadtask.objects.filter( packagename=package, uid=uid, ) if len(temp) > 0: res['code'] = 0 res['message'] = 0 return HttpResponse(json.dumps(res)) app = App.objects.get(packagename=package) item = downloadtask() item.uid = uid item.money = app.price * .5 item.packagename = package item.percent = .5 item.save() dev = Device.objects.get(uid=uid) dev.money += item.money dev.downin += item.money dev.allin += item.money dev.downloadcount += 1 dev.save() log = record() log.uid = uid log.type = 'download:' + package log.amount = item.money log.save() if (dev.fathername != None and len(dev.fathername) > 4): try: fatherMoney = item.money * .2 faDev = Device.objects.get(uid=dev.fathername) faDev.money += fatherMoney faDev.spreadin += fatherMoney faDev.allin += fatherMoney log2 = record() log2.uid = dev.fathername log2.type = "sondownload:" + package log2.amount = fatherMoney log2.save() if dev.downloadcount == 3: faDev.money += 1.5 faDev.spreadin += 1.5 faDev.allin += 1.5 log3 = record() log3.uid = dev.fathername log3.type = "sonachieve:" + dev.downloadcount log3.amount = 1.5 log3.save() faDev.save() except: pass #else: except: return HttpResponse(json.dumps(res)) res['code'] = 0 res['message'] = item.money return HttpResponse(json.dumps(res))
def adddownload(request): res={'code':1,'message':''} try: uid=request.GET['uid'] package=request.GET['packagename'] except: return HttpResponse(json.dumps(res)) #if True: try: temp=downloadtask.objects.filter(packagename=package,uid=uid,) if len(temp)>0: res['code']=0 res['message']=0 return HttpResponse(json.dumps(res)) app=App.objects.get(packagename=package) item=downloadtask() item.uid=uid item.money=app.price*.7 item.packagename=package item.percent=.7 item.save() dev=Device.objects.get(uid=uid) dev.money+=item.money dev.downin+=item.money dev.allin+=item.money dev.downloadcount+=1 dev.save() log=record() log.uid=uid log.type='download:'+package log.amount=item.money log.save() if(dev.fathername!=None and len(dev.fathername)>4): try: fatherMoney=item.money*.2 faDev=Device.objects.get(uid=dev.fathername) faDev.money+=fatherMoney faDev.spreadin+=fatherMoney faDev.allin+=fatherMoney log2=record() log2.uid=dev.fathername log2.type="sondownload:"+package log2.amount=fatherMoney log2.save() if dev.downloadcount==3: faDev.activenum+=1 faDev.money+=1.5 faDev.spreadin+=1.5 faDev.allin+=1.5 log3=record() log3.uid=dev.fathername log3.type="sonachieve:"+dev.downloadcount log3.amount=1.5 log3.save() faDev.save() except: pass #else: except: return HttpResponse(json.dumps(res)) res['code']=0 res['message']=item.money return HttpResponse(json.dumps(res))
def cancelOrder(request): id = int(request.GET.get('id')) record = models.record() record.id = id record.cancel() return HttpResponse(json.dumps({'result': 1}))
def history(request): username = request.GET.get('username') record = models.record() record.uid = username records = record.get() return HttpResponse(json.dumps(records))
def cancelOrder(request): id = int(request.GET.get('id')) record = models.record() record.id = id record.cancel() return HttpResponse(json.dumps({'result':1}))