- 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) {
|
||||
|
||||
@@ -12,6 +12,11 @@ const (
|
||||
SpecUnitML = 3
|
||||
)
|
||||
|
||||
const (
|
||||
SkuNameStatusNormal = 0
|
||||
SkuNameStatusDontSale = 1
|
||||
)
|
||||
|
||||
var (
|
||||
SpecUnitNames = []string{
|
||||
"g",
|
||||
@@ -93,19 +98,19 @@ func (*SkuCategory) TableUnique() [][]string {
|
||||
type SkuName struct {
|
||||
ModelIDCUL
|
||||
|
||||
Prefix string `orm:"size(255)"`
|
||||
Name string `orm:"size(255)"`
|
||||
Comment string `orm:"size(255)"`
|
||||
Prefix string `orm:"size(255)" json:"prefix"`
|
||||
Name string `orm:"size(255)" json:"name"`
|
||||
Comment string `orm:"size(255)" json:"comment"`
|
||||
|
||||
BrandID int `orm:"column(brand_id);default(0)"` // 此属性暂时没有使用
|
||||
CategoryID int `orm:"column(category_id)"` // 标准类别
|
||||
Status int
|
||||
BrandID int `orm:"column(brand_id);default(0)" json:"brandID"` // 此属性暂时没有使用
|
||||
CategoryID int `orm:"column(category_id)" json:"categoryID"` // 标准类别
|
||||
Status int `json:"status"`
|
||||
|
||||
IsGlobal int8 `orm:"default(1)"` // 是否是全部(全国)可见,如果否的话,可见性由SkuPlace决定
|
||||
Unit string `orm:"size(8)"`
|
||||
Price int // 单位为分,标准价,不为份的就为实际标准价,为份的为每市斤价,实际还要乘质量。todo 为份的确定必须有质量
|
||||
Img string `orm:"size(255)"`
|
||||
ElmImgHashCode string `orm:"size(64)"`
|
||||
IsGlobal int8 `orm:"default(1)" json:"isGlobal"` // 是否是全部(全国)可见,如果否的话,可见性由SkuPlace决定
|
||||
Unit string `orm:"size(8)" json:"unit"`
|
||||
Price int `json:"price"` // 单位为分,标准价,不为份的就为实际标准价,为份的为每市斤价,实际还要乘质量。todo 为份的确定必须有质量
|
||||
Img string `orm:"size(255)" json:"img"`
|
||||
ElmImgHashCode string `orm:"size(64)" json:"-"`
|
||||
}
|
||||
|
||||
// func (*SkuName) TableUnique() [][]string {
|
||||
|
||||
@@ -125,3 +125,29 @@ func (c *SkuController) DeleteCategory() {
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
// @Title 得到京西门店信息
|
||||
// @Description 得到京西门店信息,如下条件之间是与的关系
|
||||
// @Param token header string true "认证token"
|
||||
// @Param keyword query string false "查询关键字(可以为空,为空表示不限制)"
|
||||
// @Param id query int false "SkuName ID"
|
||||
// @Param name query string false "商品名称(不要求完全一致)"
|
||||
// @Param prefix query string false "商品前缀(不要求完全一致)"
|
||||
// @Param placeCode query int false "可售地点Code"
|
||||
// @Param isGlobal query bool false "是否全球可售"
|
||||
// @Param categoryID query int false "商品所属类别ID"
|
||||
// @Param unit query string false "商品单位"
|
||||
// @Param jdID query int false "商品京东ID"
|
||||
// @Param fromStatus query int false "查询起始状态(0:正常,1:下架)"
|
||||
// @Param toStatus query int false "查询结束状态(0:正常,1:下架)"
|
||||
// @Param offset query int false "门店列表起始序号(以0开始,缺省为0)"
|
||||
// @Param pageSize query int false "门店列表页大小(缺省为50)"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /GetSkuNames [get]
|
||||
func (c *SkuController) GetSkuNames() {
|
||||
c.callGetSkuNames(func(params *tSkuGetSkuNamesParams) (retVal interface{}, errCode string, err error) {
|
||||
retVal, err = cms.GetSkuNames(params.Keyword, params.MapData, params.Offset, params.PageSize)
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
@@ -159,6 +159,14 @@ func init() {
|
||||
MethodParams: param.Make(),
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:SkuController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:SkuController"],
|
||||
beego.ControllerComments{
|
||||
Method: "GetSkuNames",
|
||||
Router: `/GetSkuNames`,
|
||||
AllowHTTPMethods: []string{"get"},
|
||||
MethodParams: param.Make(),
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:SkuController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:SkuController"],
|
||||
beego.ControllerComments{
|
||||
Method: "GetVendorCategories",
|
||||
|
||||
Reference in New Issue
Block a user