176 lines
7.5 KiB
Python
176 lines
7.5 KiB
Python
# -*- coding: utf-8 -*-
|
|
import json
|
|
import math
|
|
import logging
|
|
import datetime
|
|
from odoo import http, tools
|
|
from .tool import MakeResponse
|
|
|
|
_logger = logging.getLogger(__name__)
|
|
|
|
|
|
class fineService(http.Controller):
|
|
|
|
@http.route(['/fine_service'], type='http', auth="public",
|
|
website=True)
|
|
def list(self, **kw):
|
|
return http.request.render('tx_cms_upgrade.fineService')
|
|
|
|
@http.route(['/fine_service_data', '/fine_service_data/page/<int:page>'], type='http', auth="public",
|
|
website=True)
|
|
def listData(self, characteristic_id=0, technical_id=0, industry_id=0, page=1, **kw):
|
|
service_obj = http.request.env["tx.fine.service"].sudo()
|
|
_post_per_page = 9
|
|
page = int(page)
|
|
|
|
characteristicList = []
|
|
technicalList = []
|
|
industryList = []
|
|
characteristic_id = int(characteristic_id)
|
|
technical_id = int(technical_id)
|
|
industry_id = int(industry_id)
|
|
|
|
characteristic_ids = service_obj.characteristic_ids.sudo().search([("code", "=", "CP")])._get_dict_values()
|
|
for index, item in enumerate(characteristic_ids):
|
|
item["active"] = True if item["id"] == characteristic_id else False
|
|
characteristicList.append(item)
|
|
|
|
technical_ids = service_obj.technical_ids.sudo().search([("code", "=", "TF")])._get_dict_values()
|
|
for index, item in enumerate(technical_ids):
|
|
item["active"] = True if item["id"] == technical_id else False
|
|
technicalList.append(item)
|
|
|
|
industry_ids = service_obj.industry_ids.sudo().search([("code", "=", "TF")])._get_dict_values()
|
|
for index, item in enumerate(industry_ids):
|
|
item["active"] = True if item["id"] == industry_id else False
|
|
industryList.append(item)
|
|
|
|
domain = []
|
|
if industry_id:
|
|
domain.append(("industry_ids", "in", [industry_id]))
|
|
if technical_id:
|
|
domain.append(("technical_ids", "in", [technical_id]))
|
|
if characteristic_id:
|
|
domain.append(("characteristic_ids", "in", [characteristic_id]))
|
|
|
|
serviceAll = service_obj.search(domain)
|
|
|
|
pager = tools.lazy(
|
|
lambda: http.request.website.pager(url='/fine_service_data', total=serviceAll.__len__(),
|
|
page=page, step=_post_per_page, scope=_post_per_page,
|
|
url_args=kw))
|
|
|
|
serviceData = serviceAll[
|
|
(page - 1) * _post_per_page:page * _post_per_page]
|
|
|
|
records = []
|
|
for service in serviceData:
|
|
records.append({
|
|
"id": service.id,
|
|
"recommend": service.recommend,
|
|
"imgUrl": http.request.website.image_url(service, 'img'),
|
|
"name": service.name,
|
|
"companyName": service.company_name,
|
|
"createDate": f"""{service.create_date.year}年{service.create_date.month}月{service.create_date.day}日""",
|
|
"briefIntroduction": str(service.brief_introduction),
|
|
"technicalIds": [technical_id.name for technical_id in service.technical_ids]
|
|
})
|
|
|
|
return MakeResponse.success({
|
|
"characteristicList": characteristicList,
|
|
"technicalList": technicalList,
|
|
"industryList": industryList,
|
|
"records": records,
|
|
"characteristic_id": characteristic_id,
|
|
"technical_id": technical_id,
|
|
"industry_id": industry_id,
|
|
"pager": pager._value,
|
|
})
|
|
|
|
@http.route('/fine_service_details/<model("tx.fine.service"):obj>', type='http', auth="public",
|
|
website=True)
|
|
def object(self, obj, **kw):
|
|
return http.request.render('tx_cms_upgrade.fineServiceDetails', {
|
|
'object': obj
|
|
})
|
|
|
|
@http.route('/fine_service/details', methods=['get'], auth='public', website=True)
|
|
def record_details(self, recordId, **kw):
|
|
record_obj = http.request.env["tx.fine.service"].sudo()
|
|
obj = record_obj.sudo().browse([int(recordId)])
|
|
return MakeResponse.success({
|
|
"name": obj.name,
|
|
"briefIntroduction": obj.brief_introduction,
|
|
"technicalList": [technical_id.name for technical_id in obj.technical_ids],
|
|
"imgUrl": http.request.website.image_url(obj, 'img'),
|
|
"companyName": obj.company_name,
|
|
"content": obj.content,
|
|
})
|
|
|
|
# 有数了 -- 精细服务 列表
|
|
@http.route("/tx_base/api/service/list", methods=['POST'], auth='public', csrf=False, website=True, cors="*")
|
|
def scenes_list(self, **kw):
|
|
params = json.loads(http.request.httprequest.data.decode("utf-8"))
|
|
page_num = params.get("pageNum", 1)
|
|
page_size = params.get("pageSize", 10)
|
|
fine_name = params.get("fineName", "")
|
|
technical_type = params.get("technicalType", [])
|
|
industry_type = params.get("industryType", [])
|
|
product_type = params.get("productType", [])
|
|
|
|
model_obj = http.request.env["tx.fine.service"].sudo()
|
|
records = []
|
|
|
|
domain = []
|
|
if technical_type.__len__():
|
|
domain.append(("technical_ids", "in", technical_type))
|
|
|
|
if industry_type.__len__():
|
|
domain.append(("industry_ids", "in", industry_type))
|
|
|
|
if product_type.__len__():
|
|
domain.append(("characteristic_ids", "in", product_type))
|
|
|
|
if fine_name:
|
|
domain.append(("name", "like", f"%{fine_name}%"))
|
|
|
|
total = model_obj.search_count(domain)
|
|
|
|
offset = (page_num - 1) * page_size if page_num > 1 else 0
|
|
dataAll = model_obj.search(domain, offset, page_size)
|
|
|
|
for data in dataAll:
|
|
records.append({
|
|
"id": data.id,
|
|
"fineAvatar": f"""{data.get_base_url()}{http.request.website.image_url(data, 'img')}""",
|
|
"fineName": f"{data.name}",
|
|
"fineDescription": data.brief_introduction,
|
|
"company": data.company_name,
|
|
"isRecommend": "Y" if data.recommend else "N",
|
|
"createTime": data.create_date.strftime("%Y-%m-%d") if data.create_date else datetime.date.today().strftime("%Y-%m-%d"),
|
|
"technicalType": ",".join([technical_id.name for technical_id in data.technical_ids]),
|
|
})
|
|
pages = math.ceil(total / page_size)
|
|
return MakeResponse.opontekr_success(records, total, pages)
|
|
|
|
# 有数了 -- 精细服务 详情
|
|
@http.route("/tx_base/api/service/info", methods=['GET'], auth='public', csrf=False, website=True, cors="*")
|
|
def record_info(self, **kwargs):
|
|
try:
|
|
fineId = kwargs.get("fineId", False)
|
|
model_obj = http.request.env["tx.fine.service"].sudo()
|
|
record = model_obj.search([("id", "=", fineId)])
|
|
data = {
|
|
"createTime": record.create_date.strftime("%Y-%m-%d") if record.create_date else datetime.date.today().strftime("%Y-%m-%d"),
|
|
"fineName": record.name,
|
|
"fineDescription": record.brief_introduction,
|
|
"technicalType": ",".join([technical_id.name for technical_id in record.technical_ids]),
|
|
"company": record.company_name,
|
|
"fineAvatar": f"""{record.get_base_url()}{http.request.website.image_url(record, 'img')}""",
|
|
"productDtoList": [{"name": line.name, "content": line.content} for line in record.line_ids]
|
|
}
|
|
return MakeResponse.success(data)
|
|
except Exception as e:
|
|
_logger.error(e)
|
|
return MakeResponse.error("参数错误")
|