|
@@ -1,5 +1,6 @@
|
|
|
const mysql = require('./mysql');
|
|
const mysql = require('./mysql');
|
|
|
const {searchSql,limitSql} = require("../tools/searchSql");
|
|
const {searchSql,limitSql} = require("../tools/searchSql");
|
|
|
|
|
+const time = require("../tools/time_cjs");
|
|
|
const log = require("../logger").logger("d_product","info")
|
|
const log = require("../logger").logger("d_product","info")
|
|
|
function loadProducts(key, page, limit) {
|
|
function loadProducts(key, page, limit) {
|
|
|
let sql = ``;
|
|
let sql = ``;
|
|
@@ -111,11 +112,66 @@ function getProductById(id){
|
|
|
let sql = `SELECT *,name as title FROM hfy_product WHERE proid = ? limit 1`;
|
|
let sql = `SELECT *,name as title FROM hfy_product WHERE proid = ? limit 1`;
|
|
|
return mysql.pq(sql,[id]);
|
|
return mysql.pq(sql,[id]);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+function getProductByTypeId(id){
|
|
|
|
|
+ let sql = `SELECT * FROM hfy_product WHERE type_id = ?`;
|
|
|
|
|
+ return mysql.pq(sql,[id]);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+// 获取产品类型列表
|
|
|
|
|
+function getProductTypeList() {
|
|
|
|
|
+ let sql = `SELECT * FROM hfy_product_type`;
|
|
|
|
|
+ return mysql.pq(sql, []);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+// 编辑产品类型
|
|
|
|
|
+function editProductType(id, typeChange) {
|
|
|
|
|
+ let sql = ``
|
|
|
|
|
+ let values = [];
|
|
|
|
|
+ sql += `UPDATE hfy_product_type SET date_time = ?`;
|
|
|
|
|
+ values.push(time.getUnixTimeStamp());
|
|
|
|
|
+ if(typeChange.type_name){
|
|
|
|
|
+ sql += `,type_name = ?`;
|
|
|
|
|
+ values.push(typeChange.type_name);
|
|
|
|
|
+ }
|
|
|
|
|
+ if(typeChange.type_key){
|
|
|
|
|
+ sql += `,type_key = ?`;
|
|
|
|
|
+ values.push(typeChange.type_key);
|
|
|
|
|
+ }
|
|
|
|
|
+ if(typeChange.type_sort){
|
|
|
|
|
+ sql += `,type_sort = ?`;
|
|
|
|
|
+ values.push(typeChange.type_sort);
|
|
|
|
|
+ }
|
|
|
|
|
+ if(typeChange.type_logo){
|
|
|
|
|
+ sql += `,type_logo = ?`;
|
|
|
|
|
+ values.push(typeChange.type_logo);
|
|
|
|
|
+ }
|
|
|
|
|
+ sql += ` WHERE type_id = ?`;
|
|
|
|
|
+ values.push(id);
|
|
|
|
|
+ return mysql.pq(sql, values);
|
|
|
|
|
+}
|
|
|
|
|
+// 删除产品类型
|
|
|
|
|
+function deleteProductType(id) {
|
|
|
|
|
+ let sql = `DELETE FROM hfy_product_type WHERE type_id = ?`;
|
|
|
|
|
+ return mysql.pq(sql, [id]);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+// 新增产品类型
|
|
|
|
|
+function addProductType(type) {
|
|
|
|
|
+ let sql = `INSERT INTO hfy_product_type (date_time, type_name, type_key, type_sort, type_logo) VALUES (?, ?, ?, ?, ?)`;
|
|
|
|
|
+ return mysql.pq(sql, [time.getUnixTimeStamp(), type.type_name, type.type_key, type.type_sort, type.type_logo]);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
module.exports = {
|
|
module.exports = {
|
|
|
loadProducts,
|
|
loadProducts,
|
|
|
getProductInfo,
|
|
getProductInfo,
|
|
|
searchProducts,
|
|
searchProducts,
|
|
|
searchProductsByMini,
|
|
searchProductsByMini,
|
|
|
loadTypes,
|
|
loadTypes,
|
|
|
- getProductById
|
|
|
|
|
|
|
+ getProductByTypeId,
|
|
|
|
|
+ getProductById,
|
|
|
|
|
+ getProductTypeList,
|
|
|
|
|
+ editProductType,
|
|
|
|
|
+ deleteProductType,
|
|
|
|
|
+ addProductType
|
|
|
}
|
|
}
|