Ejemplo n.º 1
0
 def post(self):
     notify = Notify_pub()
     xml = self.request.body
     notify.saveData(xml)
     if not notify.checkSign:
         notify.setParameter("return_code", "FAIL")
         notify.setReturnParameter("return_msg", "签名失败")
         print "签名失败"
     else:
         result = notify.getData()
         print "result:"
         print result
         
         if result["return_code"] == "FAIL":
             notify.setReturnParameter("return_code", "FAIL")
             notify.setReturnParameter("return_msg", "通信错误")
             print "通信错误"
         elif result["result_code"] == "FAIL":
             notify.setReturnParameter("return_code", "FAIL")
             notify.setReturnParameter("return_msg", result["err_code_des"])
         else:
             notify.setReturnParameter("return_code", "SUCCESS")
             out_trade_no = result["out_trade_no"]
             time_end = result["time_end"]
             print "支付成功:" + out_trade_no
             print "交易时间:" + time_end
             print "更改订单状态"
             Order.update(status = 1).where(Order.status == 0 and Order.wxid == out_trade_no).execute() #支付成功订单状态改为1
     return self.write(notify.returnXml()) 
Ejemplo n.º 2
0
    def post(self):
        notify = Notify_pub()
        xml = self.request.body
        notify.saveData(xml)
        if not notify.checkSign:
            notify.setParameter("return_code", "FAIL")
            notify.setReturnParameter("return_msg", "签名失败")
            print "签名失败"
        else:
            result = notify.getData()
            print "result:"
            print result

            if result["return_code"] == "FAIL":
                notify.setReturnParameter("return_code", "FAIL")
                notify.setReturnParameter("return_msg", "通信错误")
                print "通信错误"
            elif result["result_code"] == "FAIL":
                notify.setReturnParameter("return_code", "FAIL")
                notify.setReturnParameter("return_msg", result["err_code_des"])
            else:
                notify.setReturnParameter("return_code", "SUCCESS")
                out_trade_no = result["out_trade_no"]
                time_end = result["time_end"]
                print "支付成功:" + out_trade_no
                print "交易时间:" + time_end
                print "更改订单状态"
                Order.update(status=1).where(
                    Order.status == 0
                    and Order.wxid == out_trade_no).execute()  #支付成功订单状态改为1
        return self.write(notify.returnXml())
def reject_order(order_event):
    status = 'REJECTED'
    try:
        order = Order(order_event['order_id'])
        order.update(actions=[
            Order.order_status.set(status)
            # Order.cause.set(order_event['error']['Error'])
        ])
        return
    except UpdateError as e:
        error_message = 'update_order Error: {}'.format(vars(e))
        logging.exception(error_message)
        raise ErrorOrderUpdate(error_message)
Ejemplo n.º 4
0
def approve_order(order_event):
    status = 'APPROVED'
    try:
        order = Order(order_event['order_id'])
        order.update(
            actions=[
                Order.order_status.set(status)
            ]
        )
        return

    except UpdateError as e:
        error_message = 'update_order Error: {}'.format(vars(e))
        logging.exception(error_message)
        raise ErrorOrderUpdate(error_message)
Ejemplo n.º 5
0
    def post(self, oid):
        status = int(self.get_argument("status", 0))

        Order.update(status=status).where(Order.id == oid).execute()
        self.flash("修改成功")
        self.redirect("/admin/orders")
Ejemplo n.º 6
0
 def get(self):
     orderitems = []
     user = self.current_user
     
     order = None
     
     distributions = self.get_distributions()
     price = 0.0
     credit = 0.0
     
     try:
         order = Order.get(uid = user.id, status = 0)
         print order.id
         '''
         try:
             mobile = '18014349809'
             sendmsg(self.settings, mobile, '新订单')
         except:
             pass
         '''    
         for orderitem in OrderItem.select().where(OrderItem.oid == order.id).dicts():
             try:
                 orderitem['shop'] = Shop.get(id = orderitem['sid'])
                 _oiprice = orderitem['shop'].price
                 
                 if orderitem['said'] > 0:
                     orderitem['shopattr'] = ShopAttr.get(id = orderitem['said'])
                     if orderitem['shop'].cid == 1:
                         _oicredit = orderitem['shopattr'].price
                         credit = credit + _oicredit * orderitem['num']
                         _oiprice = orderitem['shopattr'].price
                     else:
                         _oiprice = orderitem['shopattr'].price
                 else:
                     _oiprice = float(_oiprice)
                     
                 orderitems.append(orderitem)
                 price = price + float(_oiprice) * orderitem['num']
             except:
                 pass
         print price
         price_pay = str(int(price*100))
         print 'price_pay:' + price_pay
         openid = user.openid
         print 'wx_pay:'+ openid
         jsApi = JsApi_pub()
         unifiedOrder = UnifiedOrder_pub()
         unifiedOrder.setParameter("openid",openid) #商品描述
         unifiedOrder.setParameter("body","菜市优品购物") #商品描述
         timeStamp = time.time()
         print timeStamp
         out_trade_no = "{0}{1}".format(WxPayConf_pub.APPID, int(timeStamp*100))
         unifiedOrder.setParameter("out_trade_no", out_trade_no) #商户订单号
         print 'out_trade_no:' + out_trade_no
         Order.update(wxid = out_trade_no).where(Order.id == order.id).execute()
         unifiedOrder.setParameter("total_fee", price_pay) #总金额
         print WxPayConf_pub.NOTIFY_URL
         unifiedOrder.setParameter("notify_url", WxPayConf_pub.NOTIFY_URL) #通知地址 
         unifiedOrder.setParameter("trade_type", "JSAPI") #交易类型
         
         prepay_id = unifiedOrder.getPrepayId()
         jsApi.setPrepayId(prepay_id)
         jsApiParameters = jsApi.getParameters()
         print jsApiParameters
         appid = json.loads(jsApiParameters).get("appId")
         timestamp = json.loads(jsApiParameters).get("timeStamp")
         noncestr = json.loads(jsApiParameters).get("nonceStr")
         package = json.loads(jsApiParameters).get("package")
         signtype = json.loads(jsApiParameters).get("signType")
         paysign = json.loads(jsApiParameters).get("paySign")
         print appid + timestamp + noncestr + package + signtype +paysign
         if orderitems:
             self.render("/responsive/wxpay.html", tmday = datetime.date.today() + datetime.timedelta(days=1), order  = order, orderitems = orderitems, distributions = distributions.values(), credit = credit, appid = appid, timestamp = timestamp, noncestr = noncestr, package = package, signtype = signtype, paysign = paysign)
     except:
         pass
Ejemplo n.º 7
0
 def post(self, oid):
     #status = int(self.get_argument("status", 0))
     
     Order.update(status = 3).where(Order.id == oid).execute()
     self.flash("修改成功")
     self.redirect("/user/orders")
Ejemplo n.º 8
0
    def get(self):
        orderitems = []
        user = self.current_user

        order = None

        distributions = self.get_distributions()
        price = 0.0
        credit = 0.0

        try:
            order = Order.get(uid=user.id, status=0)
            print order.id
            '''
            try:
                mobile = '18014349809'
                sendmsg(self.settings, mobile, '新订单')
            except:
                pass
            '''
            for orderitem in OrderItem.select().where(
                    OrderItem.oid == order.id).dicts():
                try:
                    orderitem['shop'] = Shop.get(id=orderitem['sid'])
                    _oiprice = orderitem['shop'].price

                    if orderitem['said'] > 0:
                        orderitem['shopattr'] = ShopAttr.get(
                            id=orderitem['said'])
                        if orderitem['shop'].cid == 1:
                            _oicredit = orderitem['shopattr'].price
                            credit = credit + _oicredit * orderitem['num']
                            _oiprice = orderitem['shopattr'].price
                        else:
                            _oiprice = orderitem['shopattr'].price
                    else:
                        _oiprice = float(_oiprice)

                    orderitems.append(orderitem)
                    price = price + float(_oiprice) * orderitem['num']
                except:
                    pass
            print price
            price_pay = str(int(price * 100))
            print 'price_pay:' + price_pay
            openid = user.openid
            print 'wx_pay:' + openid
            jsApi = JsApi_pub()
            unifiedOrder = UnifiedOrder_pub()
            unifiedOrder.setParameter("openid", openid)  #商品描述
            unifiedOrder.setParameter("body", "菜市优品购物")  #商品描述
            timeStamp = time.time()
            print timeStamp
            out_trade_no = "{0}{1}".format(WxPayConf_pub.APPID,
                                           int(timeStamp * 100))
            unifiedOrder.setParameter("out_trade_no", out_trade_no)  #商户订单号
            print 'out_trade_no:' + out_trade_no
            Order.update(wxid=out_trade_no).where(
                Order.id == order.id).execute()
            unifiedOrder.setParameter("total_fee", price_pay)  #总金额
            print WxPayConf_pub.NOTIFY_URL
            unifiedOrder.setParameter("notify_url",
                                      WxPayConf_pub.NOTIFY_URL)  #通知地址
            unifiedOrder.setParameter("trade_type", "JSAPI")  #交易类型

            prepay_id = unifiedOrder.getPrepayId()
            jsApi.setPrepayId(prepay_id)
            jsApiParameters = jsApi.getParameters()
            print jsApiParameters
            appid = json.loads(jsApiParameters).get("appId")
            timestamp = json.loads(jsApiParameters).get("timeStamp")
            noncestr = json.loads(jsApiParameters).get("nonceStr")
            package = json.loads(jsApiParameters).get("package")
            signtype = json.loads(jsApiParameters).get("signType")
            paysign = json.loads(jsApiParameters).get("paySign")
            print appid + timestamp + noncestr + package + signtype + paysign
            if orderitems:
                self.render("/responsive/wxpay.html",
                            tmday=datetime.date.today() +
                            datetime.timedelta(days=1),
                            order=order,
                            orderitems=orderitems,
                            distributions=distributions.values(),
                            credit=credit,
                            appid=appid,
                            timestamp=timestamp,
                            noncestr=noncestr,
                            package=package,
                            signtype=signtype,
                            paysign=paysign)
        except:
            pass