def myCommentAdd(): resp = {'code': 200, 'msg': '操作成功', 'data': {}} req = request.values instructor_comment_id = int( req['instructor_comment_id']) if 'instructor_comment_id' in req else 0 score = int(req['score']) if 'score' in req else 0 content = req['content'] if 'content' in req else '' member_info = session.member_info if not member_info: resp['code'] = -1 resp['msg'] = '获取信息失败,未登录' return jsonify(resp) model_comment = MemberComments() model_comment.member_id = member_info.id model_comment.instructor_comment_id = instructor_comment_id model_comment.score = score model_comment.content = content model_comment.created_time = getCurrentDate() db.session.add(model_comment) db.session.commit() return jsonify(resp)
def myCommentAdd(): resp = {'code': 200, 'msg': '操作成功~', 'data': {}} member_info = g.member_info req = request.values order_sn = req['order_sn'] if 'order_sn' in req else '' score = req['score'] if 'score' in req else 10 content = req['content'] if 'content' in req else '' pay_order_info = PayOrder.query.filter_by(member_id=member_info.id, order_sn=order_sn).first() if not pay_order_info: resp['code'] = -1 resp['msg'] = "系统繁忙,请稍后再试~~" return jsonify(resp) if pay_order_info.comment_status: resp['code'] = -1 resp['msg'] = "已经评价过了~~" return jsonify(resp) pay_order_items = PayOrderItem.query.filter_by( pay_order_id=pay_order_info.id).all() food_ids = selectFilterObj(pay_order_items, "food_id") tmp_food_ids_str = '_'.join(str(s) for s in food_ids if s not in [None]) model_comment = MemberComments() model_comment.food_ids = "_%s_" % tmp_food_ids_str model_comment.member_id = member_info.id model_comment.pay_order_id = pay_order_info.id model_comment.score = score model_comment.content = content db.session.add(model_comment) pay_order_info.comment_status = 1 pay_order_info.updated_time = getCurrentDate() db.session.add(pay_order_info) db.session.commit() #更新对应商品评论数量 for tmp_food_id in food_ids: tmp_food_info = Food.query.filter_by(id=tmp_food_id).first() if not tmp_food_info: continue tmp_food_info.comment_count += 1 db.session.add(tmp_food_info) db.session.commit() return jsonify(resp)
def myCommentAdd(): resp = {'code': 200, 'msg': '操作成功', 'data': {}} member_info = g.member_info req = request.values order_sn = req['order_sn'] if 'order_sn' in req else '' score = req['score'] if 'score' in req else 10 content = req['content'] if 'content' in req else 10 pay_order_info = PayOrder.query.filter_by(member_id=member_info.id, order_sn=order_sn).first() if not pay_order_info: resp['code'] = -1 resp['msg'] = '系统繁忙,请稍后再试' return jsonify(resp) if pay_order_info.comment_status: resp['code'] = -1 resp['msg'] = '已经评级过了' return jsonify(resp) pay_order_items = PayOrderItem.query.filter_by( pay_order_id=pay_order_info.id) food_ids = selectFilterObj(pay_order_items, 'food_id') tmp_food_ids_str = '_'.join(str(s) for s in food_ids if s not in [None]) model_comment = MemberComments() model_comment.food_ids = '_%s_' % tmp_food_ids_str model_comment.member_id = member_info.id model_comment.pay_order_id = pay_order_info.id model_comment.score = score model_comment.content = content model_comment.created_time = getCurrentDate() db.session.add(model_comment) pay_order_info.comment_status = 1 pay_order_info.updated_time = getCurrentDate() db.session.add(pay_order_info) db.session.commit() return jsonify(resp)
def myCommentAdd(): resp = {'code': 200, 'msg': '操作成功~', 'data': {}} member_info = g.member_info req = request.values id = req['id'] if 'id' in req else '' score = req['score'] if 'score' in req else 10 content = req['content'] if 'content' in req else '' if not content: resp['code'] = -1 resp['msg'] = "总结不可以为空" return jsonify(resp) pay_order_item_info = PayOrderItem.query.filter_by( member_id=member_info.id ,id = id).first() if not pay_order_item_info: resp['code'] = -1 resp['msg'] = "系统繁忙,请稍后再试~~" return jsonify(resp) if pay_order_item_info.comment_status: resp['code'] = -1 resp['msg'] = "已经评价过了~~" return jsonify(resp) # pay_order_items = PayOrderItem.query.filter_by( pay_order_id = pay_order_info.id ).all() # food_ids = selectFilterObj( pay_order_items,"food_id" ) # tmp_food_ids_str = '_'.join(str(s) for s in food_ids if s not in [None]) model_comment = MemberComments() model_comment.food_ids = pay_order_item_info.food_id model_comment.member_id = member_info.id model_comment.pay_order_id = pay_order_item_info.id model_comment.score = score model_comment.content = content db.session.add( model_comment ) pay_order_item_info.comment_status = 1 pay_order_item_info.updated_time = getCurrentDate() db.session.add( pay_order_item_info ) db.session.commit() return jsonify(resp)
def addComments(self, params): try: order_sn = params['order_sn'] if 'order_sn' in params else '' score = params['score'] if 'score' in params else 10 content = params['content'] if 'content' in params else '' member_id = params['member_id'] if 'member_id' in params else 0 print("member_id is:{0}".format(member_id)) pay_order_info = PayOrder.query.filter_by( member_id=member_id, order_sn=order_sn).first() if not pay_order_info: return False if pay_order_info.comment_status: return True pay_order_items = PayOrderItem.query.filter_by( pay_order_id=pay_order_info.id).all() food_ids = selectFilterObj(pay_order_items, "food_id") tmp_food_ids_str = '_'.join( str(s) for s in food_ids if s not in [None]) model_comment = MemberComments() model_comment.food_ids = "_%s_" % tmp_food_ids_str model_comment.member_id = pay_order_info.member_id model_comment.pay_order_id = pay_order_info.id model_comment.score = score model_comment.content = content db.session.add(model_comment) pay_order_info.comment_status = 1 pay_order_info.updated_time = getCurrentDate() db.session.add(pay_order_info) db.session.commit() except Exception as e: db.session.rollback() print("exception is :%s" % e) app.logger.info("exception") return False return True