def orderSuccess(self, pay_order_id=0, params=None): try: pay_order_info = PayOrder.query.filter_by(id=pay_order_id).first() if not pay_order_info or pay_order_info.status not in [-7. - 8]: return True pay_order_info.pay_sn = params[ 'pay_sn'] if params and 'pay_sn' in params else '' pay_order_info.status = 1 pay_order_info.express_status = -7 pay_order_info.update_time = getCurrentDate() db.session.add(pay_order_info) # 插入售卖记录 进行后台统计功能 pay_order_items = PayOrderItem.query.filter_by( pay_order_id=pay_order_id).all() for order_item in pay_order_items: tmp_model_sale_log = FoodSaleChangeLog() tmp_model_sale_log.food_id = order_item.food_id tmp_model_sale_log.quantity = order_item.quantity tmp_model_sale_log.price = order_item.price tmp_model_sale_log.created_time = getCurrentDate() db.session.add(tmp_model_sale_log) db.session.commit() except Exception as e: db.session.rollback() return False # 在支付完成成功后 需要一个发送模板消息的信息, 在job里把数据发送出去 QueueService.addQueue( "pay", { "member_id": pay_order_info.member_id, "pay_order_id": pay_order_info.id })
def orderSuccess(pay_order_id=0, params=None): try: pay_order_info = PayOrder.query.filter_by(id=pay_order_id).first() if not pay_order_info or pay_order_info.status not in [-8, -7]: return True pay_order_info.pay_sn = params[ "pay_sn"] if params and "pay_sn" in params else "" pay_order_info.status = 1 pay_order_info.express_status = -7 pay_order_info.pay_time = getCurrentDate() pay_order_info.updated_time = getCurrentDate() db.session.add(pay_order_info) # 售卖历史 pay_order_items = PayOrderItem.query.filter_by( pay_order_id=pay_order_id).all() for order_item in pay_order_items: tmp_model_sale_log = FoodSaleChangeLog() tmp_model_sale_log.food_id = order_item.food_id tmp_model_sale_log.quantity = order_item.quantity tmp_model_sale_log.price = order_item.price tmp_model_sale_log.member_id = order_item.member_id tmp_model_sale_log.created_time = getCurrentDate() db.session.add(tmp_model_sale_log) db.session.commit() except Exception as e: db.session.rollback() return False QueueService.addQueue( "pay", { "member_id": pay_order_info.member_id, "pay_order_id": pay_order_info.id })
def orderSuccess(self, pay_order_id=0, params=None): try: pay_order_info = PayOrder.query.filter_by(id=pay_order_id).first() if not pay_order_info or pay_order_info.status not in [-8, -7]: return True pay_order_info.pay_sn = params[ 'pay_sn'] if params and 'pay_sn' in params else '' pay_order_info.status = 1 pay_order_info.express_status = -7 pay_order_info.updated_time = getCurrentDate() db.session.add(pay_order_info) pay_order_items = PayOrderItem.query.filter_by( pay_order_id=pay_order_id).all() for order_item in pay_order_items: food_id = order_item.food_id food = Food.query.filter_by(id=food_id).first() ratio = food.ratio temp_benefit = order_item.price * order_item.quantity * ratio benefit = Decimal(temp_benefit).quantize(Decimal('0.00')) user = User.query.filter( User.platform_id == order_item.platform_id).filter( User.community_name == order_item.community_name).first() user.benefit = user.benefit + benefit tmp_model_sale_log = FoodSaleChangeLog() tmp_model_sale_log.pay_order_item_id = order_item.id tmp_model_sale_log.food_id = order_item.food_id tmp_model_sale_log.platform_id = order_item.platform_id tmp_model_sale_log.community_id = order_item.community_id tmp_model_sale_log.community_name = order_item.community_name tmp_model_sale_log.quantity = order_item.quantity tmp_model_sale_log.price = order_item.price tmp_model_sale_log.benefit = benefit tmp_model_sale_log.member_id = order_item.member_id tmp_model_sale_log.created_time = getCurrentDate() db.session.add(tmp_model_sale_log) db.session.add(user) db.session.commit() except Exception as e: db.session.rollback() print(e) return False # 加入通知队列,做消息提醒和 QueueService.addQueue( "pay", { "member_id": pay_order_info.member_id, "pay_order_id": pay_order_info.id }) return True
def orderSuccess(self, pay_order_id=0, params=None): ''' 订单付款成功后的操作 status 变为1 支付成功 express_status 为-7 付款待发货 改变销售订单 :param pay_order_id: :param params: :return: ''' try: pay_order_info = PayOrder.query.filter(id=pay_order_id).first() if not pay_order_info or pay_order_info.status not in [-8, -7]: return False pay_order_info.pay_sn = params[ 'pay_sn'] if params and 'pay_sn' in params else '' pay_order_info.status = 1 pay_order_info.express_status = -7 pay_order_info.pay_time = getCurrentDate() pay_order_info.updated_time = getCurrentDate db.session.add(pay_order_info) # 插入售卖记录 进行统计 pay_order_items = PayOrderItem.query.filter_by( pay_order_id=pay_order_id).all() for order_item in pay_order_items: tmp_model_sale_log = FoodSaleChangeLog() tmp_model_sale_log.id = order_item.food_id tmp_model_sale_log.quantity = order_item.quantity tmp_model_sale_log.price = order_item.price tmp_model_sale_log.member_id = order_item.member_id tmp_model_sale_log.created_time = getCurrentDate() db.session.add(tmp_model_sale_log) db.session.commit() except Exception as e: db.session.rollback() return False QueueService.addQueue( "pay", { "member_id": pay_order_info.member_id, "pay_order_id": pay_order_info.id, })
def orderSuccess(self, pay_order_id=0, params=None): try: pay_order_info = PayOrder.query.filter_by(id=pay_order_id).first() if not pay_order_info or pay_order_info.status not in [-8, -7]: return True pay_order_info.pay_sn = params[ 'pay_sn'] if params and 'pay_sn' in params else '' pay_order_info.status = 1 pay_order_info.updated_time = getCurrentDate() db.session.add(pay_order_info) pay_order_items = PayOrderItem.query.filter_by( pay_order_id=pay_order_id).all() for order_item in pay_order_items: tmp_model_sale_log = ProductSaleChangeLog() tmp_model_sale_log.product_id = order_item.product_id tmp_model_sale_log.quantity = order_item.quantity tmp_model_sale_log.price = order_item.price tmp_model_sale_log.member_id = order_item.member_id tmp_model_sale_log.created_time = getCurrentDate() db.session.add(tmp_model_sale_log) db.session.commit() except Exception as e: db.session.rollback() print(e) return False # 加入通知队列,做消息提醒和 QueueService.addQueue( "pay", { "member_id": pay_order_info.member_id, "pay_order_id": pay_order_info.id }) return True