修正了更多功能
This commit is contained in:
@@ -14,7 +14,7 @@ function pagination(query) {
|
||||
async function list(req, res) {
|
||||
try {
|
||||
const { page, pageSize, offset } = pagination(req.query)
|
||||
const { name, phone, province, city, customer_type } = req.query
|
||||
const { name, phone, province, city } = req.query
|
||||
|
||||
let where = 'WHERE 1=1'
|
||||
const params = []
|
||||
@@ -45,10 +45,6 @@ async function list(req, res) {
|
||||
where += ' AND city = ?'
|
||||
params.push(city)
|
||||
}
|
||||
if (customer_type) {
|
||||
where += ' AND customer_type = ?'
|
||||
params.push(customer_type)
|
||||
}
|
||||
|
||||
// 查总数
|
||||
const [[{ total }]] = await pool.query(
|
||||
@@ -109,7 +105,7 @@ async function detail(req, res) {
|
||||
async function create(req, res) {
|
||||
const {
|
||||
name, phone, province, city, district,
|
||||
address, customer_type, email, remark, responsible_user_id,
|
||||
address, email, remark, responsible_user_id,
|
||||
} = req.body || {}
|
||||
|
||||
if (!name) {
|
||||
@@ -121,10 +117,10 @@ async function create(req, res) {
|
||||
const ownerId = responsible_user_id || req.user.id
|
||||
|
||||
const [result] = await pool.query(
|
||||
`INSERT INTO customers (name, phone, province, city, district, address, customer_type, email, remark, responsible_user_id)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
||||
`INSERT INTO customers (name, phone, province, city, district, address, email, remark, responsible_user_id)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
||||
[name, phone || null, province || null, city || null, district || null,
|
||||
address || null, customer_type || 'Normal', email || null, remark || null, ownerId]
|
||||
address || null, email || null, remark || null, ownerId]
|
||||
)
|
||||
const [rows] = await pool.query('SELECT * FROM customers WHERE id = ?', [result.insertId])
|
||||
res.json({ code: 0, message: 'ok', data: rows[0] })
|
||||
@@ -139,7 +135,7 @@ async function update(req, res) {
|
||||
const { id } = req.params
|
||||
const fields = [
|
||||
'name', 'phone', 'province', 'city', 'district',
|
||||
'address', 'customer_type', 'email', 'remark', 'responsible_user_id',
|
||||
'address', 'email', 'remark', 'responsible_user_id',
|
||||
]
|
||||
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user