def post(self): alipay = Alipay(**self.settings) params = {} ks = list(self.request.arguments.keys()) for k in ks: params[k] = self.get_argument(k) if alipay.notify_verify(params): tn = self.get_argument("out_trade_no", None) trade_no = self.get_argument("trade_no", None) trade_status = self.get_argument("trade_status", None) logging.info("notify:%s - %s - %s" % (tn, trade_no, trade_status)) oid = int(tn.split('-')[1].replace('S', '')) try: order = Order.get(id = oid) if order.status == 0: order.status = 1 order.save() user = User.get(id = order.uid) user.credit = user.credit + int(order.price) user.save() log = CreditLog() log.uid = order.uid log.mobile = user.mobile log.ctype = 0 log.affect = int(order.price) log.log = '成功下单 - %s' % tn log.save() except Exception as ex: logging.error(ex) if trade_status == 'WAIT_SELLER_SEND_GOODS': alipay.send_goods_confirm_by_platform(trade_no) self.write("success") else: self.write("fail")
def get(self): alipay = Alipay(**self.settings) params = {} ks = list(self.request.arguments.keys()) for k in ks: params[k] = self.get_argument(k) if alipay.notify_verify(params): tn = self.get_argument("out_trade_no", None) trade_no = self.get_argument("trade_no", None) trade_status = self.get_argument("trade_status", None) logging.info("return:%s - %s - %s" % (tn, trade_no, trade_status)) oid = int(tn.split('-')[1].replace('S', '')) try: order = Order.get(id = oid) order.status = 1 order.save() user = User.get(id = order.uid) user.credit = user.credit + int(order.price) user.save() log = CreditLog() log.uid = order.uid log.mobile = user.mobile log.ctype = 0 log.affect = int(order.price) log.log = '成功下单 - %s' % tn log.save() self.session['user'] = user self.session.save() alipay.send_goods_confirm_by_platform(trade_no) self.flash("支付成功") except Exception as ex: logging.error(ex) else: self.flash("支付失败") self.redirect("/pay")
def post(self): alipay = Alipay(**self.settings) params = {} ks = self.request.arguments.keys() for k in ks: params[k] = self.get_argument(k) if alipay.notify_verify(params): tn = self.get_argument("out_trade_no", None) trade_no = self.get_argument("trade_no", None) trade_status = self.get_argument("trade_status", None) logging.info("notify:%s - %s - %s" % (tn, trade_no, trade_status)) oid = int(tn.split('-')[1].replace('S', '')) try: order = Order.get(id = oid) if order.status == 0: order.status = 1 order.save() user = User.get(id = order.uid) user.credit = user.credit + int(order.price) user.save() log = CreditLog() log.uid = order.uid log.mobile = user.mobile log.ctype = 0 log.affect = int(order.price) log.log = u'成功下单 - %s' % tn log.save() except Exception, ex: logging.error(ex) if trade_status == 'WAIT_SELLER_SEND_GOODS': alipay.send_goods_confirm_by_platform(trade_no) self.write("success")
def get(self): alipay = Alipay(**self.settings) params = {} ks = self.request.arguments.keys() for k in ks: params[k] = self.get_argument(k) if alipay.notify_verify(params): tn = self.get_argument("out_trade_no", None) trade_no = self.get_argument("trade_no", None) trade_status = self.get_argument("trade_status", None) logging.info("return:%s - %s - %s" % (tn, trade_no, trade_status)) oid = int(tn.split('-')[1].replace('S', '')) try: order = Order.get(id = oid) order.status = 1 order.save() user = User.get(id = order.uid) user.credit = user.credit + int(order.price) user.save() log = CreditLog() log.uid = order.uid log.mobile = user.mobile log.ctype = 0 log.affect = int(order.price) log.log = u'成功下单 - %s' % tn log.save() self.session['user'] = user self.session.save() alipay.send_goods_confirm_by_platform(trade_no) self.flash("支付成功") except Exception, ex: logging.error(ex) else: self.flash("支付失败")
def post(self): order = None user = self.get_current_user() try: order = Order.get(uid = user.id, status = 0) mobile = self.get_argument("mobile", user.mobile) uaid = self.get_argument("uaid", None) distrid = self.get_argument("distrid", None) day = self.get_argument("day", datetime.date.today() + datetime.timedelta(days=1)) hour = int(self.get_argument("hour", 10)) payment = self.get_argument("payment", 0) message = self.get_argument("message", "") isinvoice = self.get_argument("isinvoice", 0) invoicesub = self.get_argument("invoicesub", 0) invoicename = self.get_argument("invoicename", "") invoicecontent = self.get_argument("payment", 1) shippingprice = self.get_argument("shippingprice", 0.0) if uaid and distrid: try: distrib = Distribution.get(id = distrid) shippingprice = distrib.price except: pass order.mobile = mobile order.uaid = uaid order.distrid = distrid order.distribbed = "%s %d:00:00" % (str(day), hour) order.payment = payment order.message = message order.isinvoice = isinvoice if isinvoice: order.invoicesub = invoicesub order.invoicename = invoicename order.invoicecontent = invoicecontent order.shippingprice = shippingprice order.save() body = "" for orderitem in OrderItem.select().where(OrderItem.oid == order.id).dicts(): try: shop = Shop.get(id = orderitem['sid']) sname = "" if orderitem['said'] > 0: shopattr = ShopAttr.get(id = orderitem['said']) if shop.cid == 1: credits = shopattr.price * orderitem['num'] if credits > user.credit: OrderItem.delete().where(OrderItem.id == orderitem['id']).execute() else: user = User.get(id = user.id) user.credit = user.credit - credits user.save() clog = CreditLog() clog.uid = user.id clog.mobile = user.mobile clog.ctype = 1 clog.affect = int(credits) clog.log = u"购买" + shop.name clog.save() self.session['user'] = user self.session.save() sname = shopattr.name #body = body + shop.name + " " + sname + " " + str(orderitem['num']) + "个\n" body = body + shop.name + " " + sname + " " + str(orderitem['num']) except Exception, ex: logging.error(ex) tn = "U%d-S%d" % (user.id, order.id) if int(payment) == 1: self.redirect("/alipay/topay?tn=%s&body=%s&price=%f" % (tn, body, order.price)) else: self.flash(u"请选择地址和收货方式") self.redirect("/user/orders") else:
def post(self): order = None user = self.get_current_user() try: order = Order.get(uid=user.id, status=0) mobile = self.get_argument("mobile", user.mobile) uaid = self.get_argument("uaid", None) distrid = self.get_argument("distrid", None) day = self.get_argument( "day", datetime.date.today() + datetime.timedelta(days=1)) hour = int(self.get_argument("hour", 10)) payment = self.get_argument("payment", 0) message = self.get_argument("message", "") isinvoice = self.get_argument("isinvoice", 0) invoicesub = self.get_argument("invoicesub", 0) invoicename = self.get_argument("invoicename", "") invoicecontent = self.get_argument("payment", 1) shippingprice = self.get_argument("shippingprice", 0.0) if uaid and distrid: try: distrib = Distribution.get(id=distrid) shippingprice = distrib.price except: pass order.mobile = mobile order.uaid = uaid order.distrid = distrid order.distribbed = "%s %d:00:00" % (str(day), hour) order.payment = payment order.message = message order.isinvoice = isinvoice if isinvoice: order.invoicesub = invoicesub order.invoicename = invoicename order.invoicecontent = invoicecontent order.shippingprice = shippingprice order.save() body = "" for orderitem in OrderItem.select().where( OrderItem.oid == order.id).dicts(): try: shop = Shop.get(id=orderitem['sid']) sname = "" if orderitem['said'] > 0: shopattr = ShopAttr.get(id=orderitem['said']) if shop.cid == 1: credits = shopattr.price * orderitem['num'] if credits > user.credit: OrderItem.delete().where( OrderItem.id == orderitem['id']).execute() else: user = User.get(id=user.id) user.credit = user.credit - credits user.save() clog = CreditLog() clog.uid = user.id clog.mobile = user.mobile clog.ctype = 1 clog.affect = int(credits) clog.log = u"购买" + shop.name clog.save() self.session['user'] = user self.session.save() sname = shopattr.name body = body + shop.name + " " + sname + " " + str( orderitem['num']) + "个\n" except Exception, ex: logging.error(ex) tn = "U%d-S%d" % (user.id, order.id) if int(payment) == 1: self.redirect("/alipay/topay?tn=%s&body=%s&price=%f" % (tn, body, order.price)) else: self.flash(u"请选择地址和收货方式") self.redirect("/user/orders") else: