Exemplo n.º 1
1
def signup5(request):
    user=request.user
    a=Apply.objects.get(user=user.id)
    if a.src == GROUP_ID.Shenma:
        return HttpResponseRedirect(reverse('shenma_apply_success'))
    
    address = a.businessaddr+' '+a.contact+' '+a.mobile
    if request.method == "GET":
        query = Q(userid = request.user.id) & (
            (Q(type=BuyType.BUY_DEPOSITE)&Q(status=1)) |
            Q(type=BuyType.BUY_COD))
        if Recharge.objects.filter(query).count() > 0:
            return HttpResponseRedirect('/account')
        else:
            return render_to_response('%s/signup5.html'%SIGNUP_TEMPLATE_PATH, {'address': address}, context_instance=RequestContext(request))
    else: #用户提交的付款表单
        post = request.POST
        num=0.0
        product_name = ''
        product_desc = ''
        buy_type = post['pay_deposit']
        pay_type = 0
        desc = ''
        use_old_addr = post['old_addr']
        
        if use_old_addr == 'old':
            desc =  address
        else:
            desc += citylist[int(post['province'])]['n']+citylist[int(post['province'])]['c'][int(post['city'])]
            desc += post['address']+';'
            #desc += post['post']+';'
            desc += post['contact']+';'
            desc += post['mobile']

        if buy_type == 'deposit':
            pay_type = BuyType.BUY_DEPOSITE
            product_name = u'押金'
            num = 200
        elif buy_type == 'cod':
            pay_type = BuyType.BUY_COD
            product_name = u'货到付款'
            num = 0
        else:
            return HttpResponse(json.dumps({'ret':False,'msg':'Unsupported type of purchasing!'}))
        product_desc = u'购买钱方科技的读卡器'
        
        if buy_type == 'cod':
            charges = Recharge.objects.filter(userid = request.user.id, type=BuyType.BUY_COD)
            if charges.count()<=0:
                charge = Recharge(userid=request.user.id, type=pay_type, fee=num, desc=desc, status=0)
                charge.save()
                return HttpResponseRedirect(reverse('apply_buy_success'))
                #return render_to_response('msg/paid_cod_success.html')
            else:
                return render_to_response('msg/paid_cod_not_allowed.html')
        charge = Recharge(userid=request.user.id, type=pay_type, fee=num, desc=desc, status=0)
        charge.save()

        
        pay = alipay.Alipay()
        num = 0.01
        return_url = qfpay.QF_DOMAIN+'/charge_return'
        notify_url = qfpay.QF_DOMAIN+'/charge_notify'
        url = pay.create_order_url(
            '2088002089455812',
            'create_direct_pay_by_user',
            '*****@*****.**',
            '',
            return_url,notify_url,
            product_name,
            product_desc,
            charge.id, num)
        return HttpResponseRedirect(url)
Exemplo n.º 2
0
 def create_charge(self):
     ch = Recharge.objects.filter(userid = self.user)
     if ch.count() > 0:
         ch[0].update(type=BuyType.SHENMA,fee=0,desc=u"神码渠道用户不需要购买读卡器",status=1)
     else:
         charge = Recharge(userid = self.user,
                             type=BuyType.SHENMA,
                             fee=0,
                             desc=u"神码渠道用户不需要购买读卡器",
                             status=1)
         charge.save()
Exemplo n.º 3
0
def signup5(request):
    query = Q(userid = request.user.id) & (
            (Q(type=BuyType.BUY_DEPOSITE)&Q(status=1)) |
            Q(type=BuyType.BUY_COD))
        
    if Recharge.objects.filter(query).count() > 0:
        return HttpResponseRedirect('/account')

    user,a =request.user,Apply.objects.get(user=request.user.id)
    address = a.businessaddr+' '+a.contact+' '+a.mobile
    count = a.terminalcount
    everyterminalfee = 499
    fee = a.terminalcount * everyterminalfee
    
    if request.method == "GET":
        return render_to_response('%s/signup5.html'%SIGNUP_TEMPLATE_ROOT, 
                {'address': address,'fee':fee,'count':count}, 
                context_instance=RequestContext(request))
    else:
        post = request.POST
        num=0.0
        product_name = ''
        product_desc = ''
        buy_type = post['pay_deposit']
        pay_type = 0
        desc = ''
        use_old_addr = post['old_addr']
        
        buyername=''
        buyercontactmethod=''
        buyeraddress=''

        if use_old_addr == 'old':
            desc =  address 
            buyername=a.contact
            buyercontactmethod=a.mobile
            buyeraddress=a.businessaddr

        else:
            desc += citylist[int(post['province'])]['n']+citylist[int(post['province'])]['c'][int(post['city'])]
            desc += post['address']+';'
            desc += post['contact']+';'
            desc += post['mobile']

            buyername=post['contact']
            buyercontactmethod=post['mobile']
            buyeraddress=citylist[int(post['province'])]['n']+citylist[int(post['province'])]['c'][int(post['city'])]+post['address']

        if buy_type == 'deposit':
            pay_type = BuyType.BUY_DEPOSITE
            product_name = u'购买读卡器'
            num = a.terminalcount*everyterminalfee
        else:
            pay_type = BuyType.BUY_COD
            product_name = u'货到付款'
            num = a.terminalcount*everyterminalfee+20
        
        product_desc = u'购买钱方科技的读卡器'
       
        try:
            au = AuditLog.objects.filter(user_id = request.user.id,result=1).order_by("-id")[0]
        except:
            au = AuditLog(user_id=request.user.id,create_user=0,create_date=datetime.datetime.now())

        if buy_type == 'cod': #货到付款
            #创建购买记录和发货单              
            charge = Recharge(userid=request.user.id, type=pay_type, fee=num, desc=desc, status=0)
            charge.save()
            create_invoice(request,buyername,buyercontactmethod,buyeraddress,BuyType.BUY_COD,num,count,au)
            return HttpResponseRedirect(reverse('apply_buy_success'))
        else:
            #删除历史未付款单据 
            oldChanges = Recharge.objects.filter(userid = request.user.id,
                                                type=BuyType.BUY_DEPOSITE,
                                                status = 0)
            oldChanges.delete()

            charge = Recharge(userid=request.user.id, type=pay_type, fee=num, desc=desc, status=0)
            charge.save()
            create_invoice(request,buyername,buyercontactmethod,buyeraddress,BuyType.BUY_DEPOSITE,num,count,au)
            pay = alipay.Alipay()
            #num = 0.01
            return_url = qfpay.QF_DOMAIN+'/charge_return'
            notify_url = qfpay.QF_DOMAIN+'/charge_notify'
            url = pay.create_order_url(
                '2088002089455812', #partner
                'create_direct_pay_by_user',
                '*****@*****.**',
                '',
                return_url,#pay succeed callback url
                notify_url, #???
                product_name,
                product_desc,
                charge.id, #钱方交易号
                num #price
                )
            nmlogging.info(url)
            return HttpResponseRedirect(url)