def post(self): print("[Alipay refund] notify_url!!!!!!!!") session = models.DBSession() _alipay = WapAlipay(pid=ALIPAY_PID, key=ALIPAY_KEY, seller_email=ALIPAY_SELLER_ACCOUNT) sign = self.args.pop('sign') signmethod = _alipay.getSignMethod(**self.args) if signmethod(self.args) != sign: print('sign error') return self.write('sign error') notify_data = xmltodict.parse(self.args['notify_data'])['notify'] result_details = notify_data['result_details'] transaction_id = result_details.split('^')[0] balance_history = session.query(models.BalanceHistory).filter_by( transaction_id=transaction_id).first() if not balance_history: return self.write('old_balance_history not found') order = session.query( models.Order).filter_by(transaction_id=transaction_id).first() if not order: print('order not found') return self.write('order not found') ########################################################################## order.del_reason = 'refund' order.get_num(session, order.id) #取消订单,库存增加,在售减少 shop_id = balance_history.shop_id balance_value = balance_history.balance_value shop = order.shop #该店铺余额减去订单总额 shop.shop_balance -= balance_value balance_history.is_cancel = 1 #将这条余额记录作废 balance_history.balance_type = -1 customer_id = balance_history.customer_id name = balance_history.name shop_province = balance_history.shop_province shop_name = balance_history.shop_name balance_record = balance_history.balance_record + '--退款' create_time = datetime.datetime.now() shop_totalPrice = shop.shop_balance customer_totalPrice = balance_history.customer_totalPrice transaction_id = balance_history.transaction_id available_balance = balance_history.available_balance #同时生成一条退款记录 refund_history = models.BalanceHistory( customer_id=customer_id, shop_id=shop_id, shop_province=shop_province, shop_name=shop_name, name=name, balance_record=balance_record, create_time=create_time, shop_totalPrice=shop_totalPrice, customer_totalPrice=customer_totalPrice, transaction_id=transaction_id, balance_type=9, balance_value=balance_value) session.add(refund_history) # self.session.flush() # # 9.15 woody # # 生成一条支付宝退款记录 # apply_refund = models.ApplyRefund(customer_id=customer_id,order_id=order_id,refund_type=1,refund_fee=totalPrice, # transaction_id=transaction_id,order_num=num) # self.session.add(apply_refund) session.commit() return self.write('success')
dict( unionid="oxkR_jsr9QiWscrxTSRhYSDTssLU", openid="o5SQ5tyC5Ab_g6PP2uaJV1xe2AZQ", country="中国", province="湖北", city="武汉", headimgurl= "http://wx.qlogo.cn/mmopen/XiaNUE39hM3WeU66LCia2QVBmiaLucl4hYKTaSbq5wepalu7gdgpEIG3cThwcia3B8tb0UZXoicLiaWVjZ3PgSibRoccRYsicvx0pUwB/0", nickname="喵七七", sex=2), dict( unionid="oxkR_jgG6YuVSOUlolJ1OpCPxkAk", openid="o5SQ5tzZi_MCZLOTq1av4163bIrM", country="中国", province="江西", city="南昌", headimgurl= "http://wx.qlogo.cn/mmopen/XiaNUE39hM3U4wTdKibz3icnYURFa7ia3W5h9j0yiaXWUyx3jxmjib3w2ibiaMTem7mRCia9G6uOvKmY6LWKvujMW9vWHxVItVM94xD2N/0", nickname="沿路看风景~", sex=2), ] if __name__ == "__main__": choice = input("""创建超级管理员, 输入yes继续:""") if choice == "yes": s = models.DBSession() for u in super_users: models.SuperAdmin.register_with_wx(s, u) s.close() print("create success")
def session(self): if hasattr(self, "_session"): return self._session self._session = models.DBSession() return self._session