const mysql = require('./mysql'); const {searchSql,limitSql} = require("../tools/searchSql"); const log = require("../logger").logger("d_news","info"); function addReadNum(id){ let sql = `UPDATE hfy_news SET hits = hits + 1 WHERE id = ? limit 1`; let values = [id]; return mysql.pq(sql,values); } function loadTypes() { let sql = `SELECT * FROM hfy_news_type`; return mysql.pq(sql, []); } // 轻量搜索接口 function searchAllNewsMini(type='array',searchParam,page,limit){ let sql; let values = []; if(type === 'count'){ sql = `select count(*) as total `; }else{ sql = `select news.id as id , news.title as name, n_type.type_key `; } sql += ` from hfy_news as news , hfy_news_type as n_type ` sql += ` where news.type_id = n_type.type_id` if(searchParam.key){ sql += ` and news.title like '%${searchParam.key}%'` } if(searchParam.type){ sql += ` and n_type.type_key = ?` values.push(searchParam.type) } return searchSql(mysql.pq,type,sql,values,limit,page); } function getNewsById(id){ let sql = `SELECT * FROM hfy_news WHERE id = ? limit 1`; return mysql.pq(sql,[id]); } module.exports = { addReadNum, loadTypes, searchAllNewsMini, getNewsById }