- GetSkuNames added.
This commit is contained in:
@@ -2,6 +2,7 @@ package cms
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
@@ -9,6 +10,16 @@ import (
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
)
|
||||
|
||||
type SkuNameExt struct {
|
||||
model.SkuName
|
||||
Skus string `orm:"size(2000)" json:"skus"`
|
||||
}
|
||||
|
||||
type SkuNamesInfo struct {
|
||||
TotalCount int `json:"totalCount"`
|
||||
SkuNames []*SkuNameExt `json:"skuNames"`
|
||||
}
|
||||
|
||||
var (
|
||||
ErrInputCatsDoesntMatch = errors.New("输入的类别列表不合法,需要输入一个父ID下的所有子类别")
|
||||
)
|
||||
@@ -122,3 +133,124 @@ func DeleteCategory(categoryID int, isForce bool, userName string) (num int64, e
|
||||
}
|
||||
return num, err
|
||||
}
|
||||
|
||||
func GetSkuNames(keyword string, params map[string]interface{}, offset, pageSize int) (skuNamesInfo *SkuNamesInfo, err error) {
|
||||
sql := `
|
||||
FROM sku_name t1
|
||||
JOIN sku t2 ON t1.id = t2.name_id
|
||||
WHERE`
|
||||
sqlParams := make([]interface{}, 0)
|
||||
if keyword != "" {
|
||||
keywordLike := "%" + keyword + "%"
|
||||
sql += " (t1.name LIKE ? OR t1.prefix LIKE ? OR t1.comment LIKE ?"
|
||||
sqlParams = append(sqlParams, keywordLike, keywordLike, keywordLike)
|
||||
|
||||
if keywordInt64, err2 := strconv.ParseInt(keyword, 10, 64); err2 == nil {
|
||||
sql += " OR t2.jd_id = ? OR t1.id = ? OR t1.category_id = ?"
|
||||
sqlParams = append(sqlParams, keywordInt64, keywordInt64, keywordInt64)
|
||||
}
|
||||
sql += ")"
|
||||
} else {
|
||||
sql += " 1 = 1"
|
||||
}
|
||||
|
||||
if params["id"] != nil {
|
||||
sql += " AND t1.id = ?"
|
||||
sqlParams = append(sqlParams, params["id"].(int))
|
||||
}
|
||||
if params["categoryID"] != nil {
|
||||
sql += " AND t1.category_id = ?"
|
||||
sqlParams = append(sqlParams, params["categoryID"].(int))
|
||||
}
|
||||
if params["jdID"] != nil {
|
||||
sql += " AND t1.jd_id = ?"
|
||||
sqlParams = append(sqlParams, params["jdID"].(int))
|
||||
}
|
||||
if params["name"] != nil {
|
||||
sql += " AND t1.name LIKE ?"
|
||||
sqlParams = append(sqlParams, "%"+params["name"].(string)+"%")
|
||||
}
|
||||
if params["prefix"] != nil {
|
||||
sql += " AND t1.prefix LIKE ?"
|
||||
sqlParams = append(sqlParams, "%"+params["prefix"].(string)+"%")
|
||||
}
|
||||
if params["unit"] != nil {
|
||||
sql += " AND t1.unit = ?"
|
||||
sqlParams = append(sqlParams, params["unit"].(string))
|
||||
}
|
||||
if params["placeCode"] != nil {
|
||||
sql += " AND (SELECT COUNT(*) FROM sku_name_place_bind bind WHERE bind.sku_name_id = t1.id AND bind.place_code = ?) > 0"
|
||||
sqlParams = append(sqlParams, params["placeCode"].(int))
|
||||
}
|
||||
if params["isGlobal"] != nil {
|
||||
if params["isGlobal"].(bool) {
|
||||
sql += " AND t1.is_global = 1"
|
||||
} else {
|
||||
sql += " AND t1.is_global = 0"
|
||||
}
|
||||
}
|
||||
if params["fromStatus"] != nil {
|
||||
fromStatus := params["fromStatus"].(int)
|
||||
toStatus := fromStatus
|
||||
if params["toStatus"] != nil {
|
||||
toStatus = params["toStatus"].(int)
|
||||
}
|
||||
sql += " AND t1.status >= ? AND t1.status <= ?"
|
||||
sqlParams = append(sqlParams, fromStatus, toStatus)
|
||||
}
|
||||
sql += `
|
||||
GROUP BY
|
||||
t1.id,
|
||||
t1.created_at,
|
||||
t1.updated_at,
|
||||
t1.last_operator,
|
||||
t1.prefix,
|
||||
t1.name,
|
||||
t1.comment,
|
||||
t1.brand_id,
|
||||
t1.category_id,
|
||||
t1.status,
|
||||
t1.is_global,
|
||||
t1.unit,
|
||||
t1.price,
|
||||
t1.img,
|
||||
t1.elm_img_hash_code
|
||||
`
|
||||
db := dao.GetDB()
|
||||
sqlData := `
|
||||
SELECT
|
||||
SQL_CALC_FOUND_ROWS
|
||||
t1.id,
|
||||
t1.created_at,
|
||||
t1.updated_at,
|
||||
t1.last_operator,
|
||||
t1.prefix,
|
||||
t1.name,
|
||||
t1.comment,
|
||||
t1.brand_id,
|
||||
t1.category_id,
|
||||
t1.status,
|
||||
t1.is_global,
|
||||
t1.unit,
|
||||
t1.price,
|
||||
t1.img,
|
||||
t1.elm_img_hash_code, CONCAT("[", GROUP_CONCAT(CONCAT('{"id":', t2.id, ',"specQuality":', t2.spec_quality, ',"specUnit":"', t2.spec_unit, '","weight":', t2.weight, ',"jdID":', t2.jd_id, "}")), "]") skus
|
||||
` + sql + `
|
||||
ORDER BY t1.id
|
||||
LIMIT ? OFFSET ?`
|
||||
if pageSize == 0 {
|
||||
pageSize = model.DefPageSize
|
||||
}
|
||||
if offset < 0 {
|
||||
offset = 0
|
||||
}
|
||||
sqlParams = append(sqlParams, pageSize, offset)
|
||||
skuNamesInfo = &SkuNamesInfo{}
|
||||
if err = dao.GetRows(db, &skuNamesInfo.SkuNames, sqlData, sqlParams...); err == nil {
|
||||
countInfo := &struct{ Ct int }{}
|
||||
if err = dao.GetRow(db, countInfo, "SELECT FOUND_ROWS() ct"); err == nil {
|
||||
skuNamesInfo.TotalCount = countInfo.Ct
|
||||
}
|
||||
}
|
||||
return skuNamesInfo, err
|
||||
}
|
||||
|
||||
@@ -159,30 +159,26 @@ func GetStores(keyword string, params map[string]interface{}, offset, pageSize i
|
||||
}
|
||||
sql += ")"
|
||||
}
|
||||
sqlCount := "SELECT COUNT(*) ct\n" + sql
|
||||
type tcount struct {
|
||||
Ct int
|
||||
}
|
||||
countInfo := []tcount{}
|
||||
db := dao.GetDB()
|
||||
if err = dao.GetRows(db, &countInfo, sqlCount, sqlParams...); err == nil {
|
||||
sqlData := "SELECT t1.*, city.name city_name, district.name district_name, jdm.vendor_store_id jd_id, elmm.vendor_store_id elm_id, ebaim.vendor_store_id ebai_id\n" + sql + `
|
||||
|
||||
sqlData := "SELECT SQL_CALC_FOUND_ROWS t1.*, city.name city_name, district.name district_name, jdm.vendor_store_id jd_id, elmm.vendor_store_id elm_id, ebaim.vendor_store_id ebai_id\n" + sql + `
|
||||
ORDER BY id
|
||||
LIMIT ? OFFSET ?`
|
||||
if pageSize == 0 {
|
||||
pageSize = model.DefPageSize
|
||||
}
|
||||
if offset < 0 {
|
||||
offset = 0
|
||||
}
|
||||
sqlParams = append(sqlParams, pageSize, offset)
|
||||
retVal := &StoresInfo{
|
||||
TotalCount: countInfo[0].Ct,
|
||||
}
|
||||
err = dao.GetRows(db, &retVal.Stores, sqlData, sqlParams...)
|
||||
return retVal, err
|
||||
if pageSize == 0 {
|
||||
pageSize = model.DefPageSize
|
||||
}
|
||||
return nil, err
|
||||
if offset < 0 {
|
||||
offset = 0
|
||||
}
|
||||
sqlParams = append(sqlParams, pageSize, offset)
|
||||
retVal = &StoresInfo{}
|
||||
if err = dao.GetRows(db, &retVal.Stores, sqlData, sqlParams...); err == nil {
|
||||
countInfo := &struct{ Ct int }{}
|
||||
if err = dao.GetRow(db, countInfo, "SELECT FOUND_ROWS() ct"); err == nil {
|
||||
retVal.TotalCount = countInfo.Ct
|
||||
}
|
||||
}
|
||||
return retVal, err
|
||||
}
|
||||
|
||||
func GetVendorStore(vendorStoreID string, vendorID int) (retVal *StoreExt, err error) {
|
||||
|
||||
Reference in New Issue
Block a user