Commit dfe9f4b7 by dong

fix20230404

parent 7d25946b
......@@ -1707,6 +1707,7 @@ class CustomerConsultation(db.Model):
__tablename__ = "customer_consultation"
__table_args__ = ({'comment': '小程序-客户咨询信息表'}) # 添加表注释
id = db.Column(db.Integer, primary_key=True, autoincrement=True, comment='主键id')
user_id = db.Column(db.Integer, comment='访客id,属于哪位访客')
project_name = db.Column(db.String(200), comment='项目名称')
investor = db.Column(db.String(100), comment='投资方名称')
investor_place = db.Column(db.String(100), default='', comment='投资方所在地')
......
......@@ -473,7 +473,7 @@ def company_detail():
# 投资咨询
@api_xiaocx.route('/Consultation', methods=['POST'])
# @login_required
@login_required
def consultation():
req_dict = request.get_json()
project_name = req_dict.get("project_name")
......@@ -486,8 +486,16 @@ def consultation():
linkman = req_dict.get("linkman")
link_mobile = req_dict.get("link_mobile")
consultation_time = datetime.datetime.now()
token = request.headers['token']
try:
user_obj = verify_token(token)
flag = user_obj.flag
user_id = user_obj.id
except:
return jsonify(code=RET.SESSIONERR, msg="Query error!")
try:
cons_obj = CustomerConsultation()
cons_obj.user_id = user_id
cons_obj.project_name = project_name
cons_obj.investor = investor
cons_obj.investor_place = investor_place
......@@ -509,55 +517,45 @@ def consultation():
# 投资咨询信息列表
@api_xiaocx.route('/ConsultationList', methods=['POST'])
# @login_required
@login_required
def consultation_list():
req_dict = request.get_json()
page = req_dict.get("page")
perpage = req_dict.get("perpage")
token = request.headers['token']
try:
cons_obj_list = CustomerConsultation.query.paginate(page, perpage).items
user_obj = verify_token(token)
flag = user_obj.flag
user_id = user_obj.id
except:
return jsonify(code=RET.SESSIONERR, msg="Query error!")
try:
if flag == 1: # 外部访客智能看到自己的信息
cons_obj_list = CustomerConsultation.query.filter(CustomerConsultation.user_id == user_id).order_by(CustomerConsultation.consultation_time.desc()).paginate(
page, perpage).items
else:
cons_obj_list = CustomerConsultation.query.order_by(CustomerConsultation.consultation_time.desc()).paginate(page, perpage).items
cons_count = CustomerConsultation.query.count()
data_li = []
for cons_obj in cons_obj_list:
print(cons_obj)
data = {
"id": cons_obj.id,
"project_name": cons_obj.project_name,
"investor": cons_obj.investor,
"investor_place": cons_obj.investor_place,
"project_type": cons_obj.project_type,
"investment_volume": cons_obj.investment_volume,
"basic_information": cons_obj.basic_information,
"land_area": cons_obj.land_area,
"linkman": cons_obj.linkman,
"link_mobile": cons_obj.link_mobile,
"flag": cons_obj.flag,
"reply_content": cons_obj.reply_content,
"consultation_time": cons_obj.consultation_time.strftime("%Y-%m-%d") if cons_obj.consultation_time else "",
# "reply_time": cons_obj.reply_time.strftime("%Y-%m-%d") if cons_obj.reply_time else "",
}
data_li.append(data)
# data = [{
# "id": cons_obj.id,
# "project_name": cons_obj.project_name,
# "investor": cons_obj.investor,
# "investor_place": cons_obj.investor_place,
# "project_type": cons_obj.project_type,
# "investment_volume": cons_obj.investment_volume,
# "basic_information": cons_obj.basic_information,
# "land_area": cons_obj.land_area,
# "linkman": cons_obj.linkman,
# "link_mobile": cons_obj.link_mobile,
# "flag": cons_obj.flag,
# "reply_content": cons_obj.reply_content,
# "consultation_time": cons_obj.consultation_time.strftime("%Y-%m-%d") if cons_obj.consultation_time else "",
# "reply_time": cons_obj.reply_time.strftime("%Y-%m-%d") if cons_obj.reply_time else "",
# } for cons_obj in cons_obj_list]
data = sorted(data_li, key=lambda x: x["consultation_time"], reverse=True)
data = [{
"id": cons_obj.id,
"project_name": cons_obj.project_name,
"investor": cons_obj.investor,
"investor_place": cons_obj.investor_place,
"project_type": cons_obj.project_type,
"investment_volume": cons_obj.investment_volume,
"basic_information": cons_obj.basic_information,
"land_area": cons_obj.land_area,
"linkman": cons_obj.linkman,
"link_mobile": cons_obj.link_mobile,
"flag": cons_obj.flag,
"reply_content": cons_obj.reply_content,
"consultation_time": cons_obj.consultation_time,
"reply_time": cons_obj.reply_time,
} for cons_obj in cons_obj_list]
except Exception as e:
current_app.logger.error(e)
return jsonify(code=RET.SESSIONERR, msg="Query error!")
return jsonify(code=RET.DBERR, msg="Query error!")
return jsonify(code=RET.OK, data={"data": data, "size": cons_count}, msg='Data query success!')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment