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: 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() print(e) return False return True
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 testFood(self,date): from common.models.food.Food import Food list = Food.query.all() if list: for item in list: model = FoodSaleChangeLog() model.food_id = item.id model.quantity = random.randint( 1,10 ) model.price = model.quantity * item.price model.member_id = 1 model.created_time = date + " " + getFormatDate( format = "%H:%M:%S") db.session.add( model ) db.session.commit()
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.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 addPayCallbackData(self, pay_order_id=0, type='pay', data=''): try: app.logger.info("enter 1") if int(pay_order_id) < 1: return False app.logger.info("enter 11") pay_order_info = PayOrder.query.filter_by( id=pay_order_id, express_status=-7).first() if not pay_order_info: return False pay_order_items = PayOrderItem.query.filter_by( pay_order_id=pay_order_id).all() if not pay_order_items: return False model_callback = PayOrderCallbackData() model_callback.pay_order_id = pay_order_id if type == "pay": app.logger.info("enter 2") # `1` # 新增 售卖数量改变sale # 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() # `2` # 每个月的月底进行统计或者更新 # 更新销售总量 notice_content = [] if pay_order_items: date_from = datetime.datetime.now().strftime( "%Y-%m-01 00:00:00") date_to = datetime.datetime.now().strftime( "%Y-%m-31 23:59:59") for item in pay_order_items: tmp_food_info = Food.query.filter_by( id=item.food_id).first() if not tmp_food_info: continue notice_content.append( "%s %s份" % (tmp_food_info.name, item.quantity)) # 当月数量 # query( 0, 1) 当中指针为0 和 1的两个对象。 tmp_stat_info = db.session.query(FoodSaleChangeLog, func.sum(FoodSaleChangeLog.quantity).label("total")) \ .filter(FoodSaleChangeLog.food_id == item.food_id)\ .filter(FoodSaleChangeLog.created_time >= date_from, FoodSaleChangeLog.created_time <= date_to).first() app.logger.info( "当月数量:tmp_stat_info:{0}".format(tmp_stat_info)) tmp_month_count = tmp_stat_info[1] if tmp_stat_info[ 1] else 0 tmp_food_info.total_count += item.quantity # 错误修改 tmp_food_info.month_count = tmp_month_count db.session.add(tmp_food_info) app.logger.info("enter 3") # `3` # 设置为取餐号 pay_order_info.express_status = -6 # -6 pay_order_info.updated_time = getCurrentDate() db.session.add(pay_order_info) model_callback.pay_data = data model_callback.refund_data = '' elif type == "cancel": # `1` 归还库存 if pay_order_items: # 需要归还库存 for item in pay_order_items: tmp_food_info = Food.query.filter_by( id=item.food_id).first() if tmp_food_info: tmp_food_info.stock = tmp_food_info.stock + item.quantity tmp_food_info.updated_time = getCurrentDate() db.session.add(tmp_food_info) db.session.commit() FoodService.setStockChangeLog( item.food_id, item.quantity, "订单取消") # `2` 变更状态 pay_order_info.status = 0 pay_order_info.express_status = 0 pay_order_info.updated_time = getCurrentDate() db.session.add(pay_order_info) db.session.commit() model_callback.refund_data = data model_callback.pay_data = '' else: db.session.rollback() return False model_callback.created_time = model_callback.updated_time = getCurrentDate( ) db.session.add(model_callback) db.session.commit() except Exception as e: db.session.rollback() print("exception is :%s" % e) app.logger.info("exception") return False # 统计end return True