Updata:更新检索sql
This commit is contained in:
parent
40bd33d19c
commit
24423900d3
@ -123,16 +123,14 @@ func GetInvoiceList(req *bundle.GetInvoiceListReq) (data []*model.InvoiceInfo, t
|
|||||||
query = query.Where("COALESCE(invoice.apply_time, pia.apply_time) <= ?", req.ApplyTimeEnd)
|
query = query.Where("COALESCE(invoice.apply_time, pia.apply_time) <= ?", req.ApplyTimeEnd)
|
||||||
}
|
}
|
||||||
if req.Name != "" {
|
if req.Name != "" {
|
||||||
// 使用 COALESCE 后的 name 进行模糊筛选
|
// 使用 COALESCE 后的 name 进行模糊筛选,统一 collation 避免 Illegal mix of collations
|
||||||
query = query.Where("COALESCE(pia.name, rn.name) LIKE ?", "%"+req.Name+"%")
|
query = query.Where("COALESCE(pia.name, rn.name) COLLATE utf8mb4_general_ci LIKE ?", "%"+req.Name+"%")
|
||||||
}
|
}
|
||||||
if req.Phone != "" {
|
if req.Phone != "" {
|
||||||
// 使用 COALESCE 后的 phone 进行模糊筛选
|
query = query.Where("COALESCE(pia.phone, user.tel_num) COLLATE utf8mb4_general_ci LIKE ?", "%"+req.Phone+"%")
|
||||||
query = query.Where("COALESCE(pia.phone, user.tel_num) LIKE ?", "%"+req.Phone+"%")
|
|
||||||
}
|
}
|
||||||
if req.Country != "" {
|
if req.Country != "" {
|
||||||
// 使用 COALESCE 后的 country 进行模糊筛选(与 SELECT 一致使用 rn.nationality)
|
query = query.Where("COALESCE(pia.country, rn.nationality) COLLATE utf8mb4_general_ci LIKE ?", "%"+req.Country+"%")
|
||||||
query = query.Where("COALESCE(pia.country, rn.nationality) LIKE ?", "%"+req.Country+"%")
|
|
||||||
}
|
}
|
||||||
if req.UserName != "" {
|
if req.UserName != "" {
|
||||||
query = query.Where("invoice.user_name LIKE ?", "%"+req.UserName+"%")
|
query = query.Where("invoice.user_name LIKE ?", "%"+req.UserName+"%")
|
||||||
@ -193,6 +191,7 @@ func GetOrderInfoByOrderNo(req *bundle.GetOrderInfoByOrderNoReq) (orderRecord *m
|
|||||||
Joins("left join `micro-account`.`user` as user on user.id = bundle_order_records.customer_id and user.deleted_at = 0").
|
Joins("left join `micro-account`.`user` as user on user.id = bundle_order_records.customer_id and user.deleted_at = 0").
|
||||||
Joins("left join `micro-account`.`real_name` as rn on rn.id = user.real_name_id and rn.deleted_at = 0").
|
Joins("left join `micro-account`.`real_name` as rn on rn.id = user.real_name_id and rn.deleted_at = 0").
|
||||||
Where("order_no = ?", req.OrderNo).
|
Where("order_no = ?", req.OrderNo).
|
||||||
|
Where("bundle_order_records.deleted_at is null").
|
||||||
Order("bundle_order_records.created_at DESC").
|
Order("bundle_order_records.created_at DESC").
|
||||||
First(&orderRecord).Error
|
First(&orderRecord).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user