예제 #1
0
def getOrder(request):
    oid = request.GET.get("oid", None)
    checkPayment = request.GET.get("checkpayment", 0)
    checkPayment = int(checkPayment)
    _user = request.user
    if not oid:
        return Jsonify({"status":False, "error":"1101", "error_message":u"输入信息不足。"})
    oid = int(oid)
    _order = Order.objects.filter(oid=oid)
    if _order:
        _order = _order[0]
        if checkPayment==1 and int(_order.state)==0:
            result = checkWechatOrder(_order.toDict(), 0)

            payState = 0
            root = ET.fromstring(result)
            if root.find("return_code").text == "SUCCESS" and root.find("trade_state").text == "SUCCESS":
                payState = 1
            if payState == 1:
                _order.state =1
                _order.save()
            else:
                _order.state = 2
                _order.save()
        itemList = _order.itemList
        thingList = getThingList(itemList)
        address = Address.objects.filter(adid=_order.addr_id)
        if address:
            address = address[0]
            address = address.toDict()
        else:
            address=""
        return Jsonify({"status":True, "error":"", "error_message":"", "order":_order.toDict(), "address":address, "thinglist":thingList, "detail":u"同仓存取快递费: 6元。"})
    else:
        return Jsonify({"status":False, "error":"1302", "error_message":u"订单不存在。"})
예제 #2
0
def vipConfirm(request):
    _user = request.user
    _vip = VIP.objects.filter(vid=_user["vip"])
    if _vip:
        _vip = _vip[0]
        _vip.flush()
        vip_info = _vip.toDict()
    else:
        _vip = None
        vip_info = {}
    has_processing_order = False
    unfinishedOrder = VIPOrder.objects.filter(user_id=_user['uid']).filter(state=2)
    if unfinishedOrder:
        has_processing_order = True
    void = request.GET.get("void", None)
    if not void:
        return Jsonify({"status":False, "error":"1101", "error_message":u"输入信息不足。", "processing":has_processing_order, "vip":vip_info, "state":bool(vip_info)})
    _order = VIPOrder.objects.filter(void=void)
    if not _order:
        return Jsonify({"status":False, "error":"1502", "error_message":u"订单不存在。", "processing":has_processing_order, "vip":vip_info, "state":bool(vip_info)})
    _order = _order[0]
    if _order.state == 1:
        return Jsonify({"status":True, "error":"", "error_message":u"", "processing":0, "vip":vip_info, "state":bool(vip_info)})
    else:
        result = checkWechatOrder(model_to_dict(_order), 1)
        try:
            root = ET.fromstring(result)
            if root.find("return_code").text == "SUCCESS" and root.find("trade_state").text == "SUCCESS":
                _order.state = 1
                _order.save()
                newPackage = VIPPackage(level = _order.level, days = _order.month*31)
                if not _vip:
                    _vip = VIP()
                    _vip.save()
                    user = User.objects.filter(uid=_user["uid"])[0]
                    user.vip = _vip
                    user.save()
                _vip.addNewPackage(newPackage)
                vip_info = _vip.toDict()
                return Jsonify({"status":True, "error":"", "error_message":u"", "state":bool(vip_info), "vip":vip_info, "processing":0})
            else:
                _order.state=2
                _order.save()
                return Jsonify({"status":True, "error":"", "error_message":u"", "state":bool(vip_info), "vip":vip_info, "processing":1})
        except Exception, e:
            logger.error(e)
            return Jsonify({"status":False, "error":"1512", "error_message":u"微信查询失败。", "processing":1, "vip":vip_info, "state":bool(vip_info)})
예제 #3
0
def vipConfirm(request):
    _user = request.user
    _vip = VIP.objects.filter(vid=_user["vip"])
    if _vip:
        _vip = _vip[0]
        _vip.flush()
        vip_info = _vip.toDict()
    else:
        _vip = None
        vip_info = {}
    has_processing_order = False
    unfinishedOrder = VIPOrder.objects.filter(user_id=_user['uid']).filter(
        state=2)
    if unfinishedOrder:
        has_processing_order = True
    void = request.GET.get("void", None)
    if not void:
        return Jsonify({
            "status": False,
            "error": "1101",
            "error_message": u"输入信息不足。",
            "processing": has_processing_order,
            "vip": vip_info,
            "state": bool(vip_info)
        })
    _order = VIPOrder.objects.filter(void=void)
    if not _order:
        return Jsonify({
            "status": False,
            "error": "1502",
            "error_message": u"订单不存在。",
            "processing": has_processing_order,
            "vip": vip_info,
            "state": bool(vip_info)
        })
    _order = _order[0]
    if _order.state == 1:
        return Jsonify({
            "status": True,
            "error": "",
            "error_message": u"",
            "processing": 0,
            "vip": vip_info,
            "state": bool(vip_info)
        })
    else:
        result = checkWechatOrder(model_to_dict(_order), 1)
        try:
            root = ET.fromstring(result)
            if root.find("return_code").text == "SUCCESS" and root.find(
                    "trade_state").text == "SUCCESS":
                _order.state = 1
                _order.save()
                newPackage = VIPPackage(level=_order.level,
                                        days=_order.month * 31)
                if not _vip:
                    _vip = VIP()
                    _vip.save()
                    user = User.objects.filter(uid=_user["uid"])[0]
                    user.vip = _vip
                    user.save()
                _vip.addNewPackage(newPackage)
                vip_info = _vip.toDict()
                return Jsonify({
                    "status": True,
                    "error": "",
                    "error_message": u"",
                    "state": bool(vip_info),
                    "vip": vip_info,
                    "processing": 0
                })
            else:
                _order.state = 2
                _order.save()
                return Jsonify({
                    "status": True,
                    "error": "",
                    "error_message": u"",
                    "state": bool(vip_info),
                    "vip": vip_info,
                    "processing": 1
                })
        except Exception, e:
            logger.error(e)
            return Jsonify({
                "status": False,
                "error": "1512",
                "error_message": u"微信查询失败。",
                "processing": 1,
                "vip": vip_info,
                "state": bool(vip_info)
            })