- store sku GetStoreSkus.
This commit is contained in:
@@ -9,7 +9,6 @@ import (
|
|||||||
"git.rosy.net.cn/baseapi/utils"
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
"git.rosy.net.cn/jx-callback/business/model"
|
"git.rosy.net.cn/jx-callback/business/model"
|
||||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||||
"git.rosy.net.cn/jx-callback/globals"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type SkuNameExt struct {
|
type SkuNameExt struct {
|
||||||
@@ -230,6 +229,7 @@ func GetSkuNames(keyword string, params map[string]interface{}, offset, pageSize
|
|||||||
t1.created_at,
|
t1.created_at,
|
||||||
t1.updated_at,
|
t1.updated_at,
|
||||||
t1.last_operator,
|
t1.last_operator,
|
||||||
|
t1.deleted_at,
|
||||||
t1.prefix,
|
t1.prefix,
|
||||||
t1.name,
|
t1.name,
|
||||||
t1.comment,
|
t1.comment,
|
||||||
@@ -248,6 +248,7 @@ func GetSkuNames(keyword string, params map[string]interface{}, offset, pageSize
|
|||||||
t1.created_at,
|
t1.created_at,
|
||||||
t1.updated_at,
|
t1.updated_at,
|
||||||
t1.last_operator,
|
t1.last_operator,
|
||||||
|
t1.deleted_at,
|
||||||
t1.prefix,
|
t1.prefix,
|
||||||
t1.name,
|
t1.name,
|
||||||
t1.comment,
|
t1.comment,
|
||||||
@@ -271,7 +272,7 @@ func GetSkuNames(keyword string, params map[string]interface{}, offset, pageSize
|
|||||||
}
|
}
|
||||||
sqlParams = append(sqlParams, pageSize, offset)
|
sqlParams = append(sqlParams, pageSize, offset)
|
||||||
skuNamesInfo = &SkuNamesInfo{}
|
skuNamesInfo = &SkuNamesInfo{}
|
||||||
globals.SugarLogger.Debug(sqlData)
|
// globals.SugarLogger.Debug(sqlData)
|
||||||
if err = dao.GetRows(db, &skuNamesInfo.SkuNames, sqlData, sqlParams...); err == nil {
|
if err = dao.GetRows(db, &skuNamesInfo.SkuNames, sqlData, sqlParams...); err == nil {
|
||||||
countInfo := &struct{ Ct int }{}
|
countInfo := &struct{ Ct int }{}
|
||||||
if err = dao.GetRow(db, countInfo, "SELECT FOUND_ROWS() ct"); err == nil {
|
if err = dao.GetRow(db, countInfo, "SELECT FOUND_ROWS() ct"); err == nil {
|
||||||
|
|||||||
162
business/jxstore/cms/store_sku.go
Normal file
162
business/jxstore/cms/store_sku.go
Normal file
@@ -0,0 +1,162 @@
|
|||||||
|
package cms
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
|
"git.rosy.net.cn/jx-callback/business/model"
|
||||||
|
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||||
|
)
|
||||||
|
|
||||||
|
type StoreSkuNameExt struct {
|
||||||
|
model.SkuName
|
||||||
|
Skus interface{} `orm:"-" json:"skus"`
|
||||||
|
SkusStr string `json:"-"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type StoreSkuNamesInfo struct {
|
||||||
|
TotalCount int `json:"totalCount"`
|
||||||
|
SkuNames []*StoreSkuNameExt `json:"skuNames"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetStoreSkus(storeID int, keyword string, params map[string]interface{}, offset, pageSize int) (skuNamesInfo *StoreSkuNamesInfo, err error) {
|
||||||
|
db := dao.GetDB()
|
||||||
|
sql := `
|
||||||
|
FROM sku_name t1
|
||||||
|
LEFT JOIN sku t2 ON t1.id = t2.name_id AND t2.deleted_at = '1970-01-01 00:00:00'
|
||||||
|
JOIN store_sku_bind t4 ON t4.sku_id = t2.id AND t4.deleted_at = '1970-01-01 00:00:00' AND t4.store_id = ?
|
||||||
|
WHERE t1.deleted_at = '1970-01-01 00:00:00'
|
||||||
|
`
|
||||||
|
sqlParams := []interface{}{
|
||||||
|
storeID,
|
||||||
|
}
|
||||||
|
if keyword != "" {
|
||||||
|
keywordLike := "%" + keyword + "%"
|
||||||
|
sql += " AND (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 t4.id = ?"
|
||||||
|
sqlParams = append(sqlParams, keywordInt64, keywordInt64)
|
||||||
|
}
|
||||||
|
sql += ")"
|
||||||
|
}
|
||||||
|
|
||||||
|
if params["nameID"] != nil {
|
||||||
|
sql += " AND t1.id = ?"
|
||||||
|
sqlParams = append(sqlParams, params["nameID"].(int))
|
||||||
|
}
|
||||||
|
if params["categoryID"] != nil {
|
||||||
|
cat := &model.SkuCategory{}
|
||||||
|
cat.ID = params["categoryID"].(int)
|
||||||
|
if err = dao.GetEntity(db, cat); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if cat.Level == 1 {
|
||||||
|
sql += " AND t1.category_id IN (SELECT id FROM sku_category WHERE parent_id = ?)"
|
||||||
|
} else {
|
||||||
|
sql += " AND t1.category_id = ?"
|
||||||
|
}
|
||||||
|
sqlParams = append(sqlParams, cat.ID)
|
||||||
|
}
|
||||||
|
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["skuID"] != nil {
|
||||||
|
sql += " AND t2.id = ?"
|
||||||
|
sqlParams = append(sqlParams, params["skuID"].(int))
|
||||||
|
}
|
||||||
|
if params["fromStatus"] != nil {
|
||||||
|
fromStatus := params["fromStatus"].(int)
|
||||||
|
toStatus := fromStatus
|
||||||
|
if params["toStatus"] != nil {
|
||||||
|
toStatus = params["toStatus"].(int)
|
||||||
|
}
|
||||||
|
sql += " AND t2.status >= ? AND t2.status <= ? AND t2.status >= ? AND t2.status <= ?"
|
||||||
|
sqlParams = append(sqlParams, fromStatus, toStatus, fromStatus, toStatus)
|
||||||
|
}
|
||||||
|
sql += `
|
||||||
|
GROUP BY
|
||||||
|
t1.id,
|
||||||
|
t1.created_at,
|
||||||
|
t1.updated_at,
|
||||||
|
t1.last_operator,
|
||||||
|
t1.deleted_at,
|
||||||
|
t1.prefix,
|
||||||
|
t1.name,
|
||||||
|
t1.comment,
|
||||||
|
t1.brand_id,
|
||||||
|
t1.category_id,
|
||||||
|
t1.is_global,
|
||||||
|
t1.unit,
|
||||||
|
t1.price,
|
||||||
|
t1.img,
|
||||||
|
t1.elm_img_hash_code
|
||||||
|
`
|
||||||
|
sqlData := `
|
||||||
|
SELECT
|
||||||
|
SQL_CALC_FOUND_ROWS
|
||||||
|
t1.id,
|
||||||
|
t1.created_at,
|
||||||
|
t1.updated_at,
|
||||||
|
t1.last_operator,
|
||||||
|
t1.deleted_at,
|
||||||
|
t1.prefix,
|
||||||
|
t1.name,
|
||||||
|
t1.comment,
|
||||||
|
t1.brand_id,
|
||||||
|
t1.category_id,
|
||||||
|
t1.is_global,
|
||||||
|
t1.unit,
|
||||||
|
t1.price,
|
||||||
|
t1.img,
|
||||||
|
t1.elm_img_hash_code,
|
||||||
|
CONCAT("[", GROUP_CONCAT(DISTINCT CONCAT('{"id":', t2.id, ',"status":', t2.status, ',"createdAt":"', CONCAT(REPLACE(t2.created_at," ","T"),"+08:00"), '","updatedAt":"', CONCAT(REPLACE(t2.updated_at," ","T"),"+08:00"), '","lastOperator":"', t2.last_operator, '","specQuality":', t2.spec_quality, ',"specUnit":"', t2.spec_unit, '","weight":', t2.weight, ',"jdID":', t2.jd_id, ',"categoryID":', t2.category_id, ',"nameID":', t2.name_id, ',"subStoreID":', t4.sub_store_id, ',"price":', t4.price, ',"storeSkuStatus":', t4.status, "}")), "]") skus_str
|
||||||
|
` + sql + `
|
||||||
|
ORDER BY t1.id
|
||||||
|
LIMIT ? OFFSET ?`
|
||||||
|
if pageSize == 0 {
|
||||||
|
pageSize = model.DefPageSize
|
||||||
|
}
|
||||||
|
if offset < 0 {
|
||||||
|
offset = 0
|
||||||
|
}
|
||||||
|
sqlParams = append(sqlParams, pageSize, offset)
|
||||||
|
skuNamesInfo = &StoreSkuNamesInfo{}
|
||||||
|
// globals.SugarLogger.Debug(sqlData)
|
||||||
|
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
|
||||||
|
for _, skuName := range skuNamesInfo.SkuNames {
|
||||||
|
if skuName.SkusStr != "" {
|
||||||
|
if err = utils.UnmarshalUseNumber([]byte(skuName.SkusStr), &skuName.Skus); err != nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return skuNamesInfo, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func SetStoreSkuStatus(storeID int, isSale bool, userName string) (num int64, err error) {
|
||||||
|
return num, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func SetStoreFocusSku(storeID int, skuID int, isFocus, isSale bool, userName string) (num int64, err error) {
|
||||||
|
return num, err
|
||||||
|
}
|
||||||
@@ -1,17 +1,32 @@
|
|||||||
package model
|
package model
|
||||||
|
|
||||||
|
const (
|
||||||
|
StoreSkuBindStatusDeleted = -1
|
||||||
|
StoreSkuBindStatusDontSale = 0
|
||||||
|
StoreSkuBindStatusNormal = 1
|
||||||
|
)
|
||||||
|
|
||||||
type StoreSkuCategoryMap struct {
|
type StoreSkuCategoryMap struct {
|
||||||
ModelIDCUL
|
ModelIDCULD
|
||||||
|
|
||||||
StoreID int `orm:"column(store_id)"`
|
StoreID int `orm:"column(store_id)"`
|
||||||
SkuCategoryID int `orm:"column(sku_category_id)"`
|
SkuCategoryID int `orm:"column(sku_category_id)"`
|
||||||
|
|
||||||
ElmID int64 `orm:"column(elm_id);index"`
|
ElmID int64 `orm:"column(elm_id);index"`
|
||||||
EbaiID int64 `orm:"column(ebai_id);index"`
|
EbaiID int64 `orm:"column(ebai_id);index"`
|
||||||
|
|
||||||
|
ElmSyncStatus int8
|
||||||
|
EbaiSyncStatus int8
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*StoreSkuCategoryMap) TableUnique() [][]string {
|
||||||
|
return [][]string{
|
||||||
|
[]string{"StoreID", "SkuCategoryID"},
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type StoreSkuBind struct {
|
type StoreSkuBind struct {
|
||||||
ModelIDCUL
|
ModelIDCULD
|
||||||
|
|
||||||
StoreID int `orm:"column(store_id)"`
|
StoreID int `orm:"column(store_id)"`
|
||||||
SkuID int `orm:"column(sku_id)"`
|
SkuID int `orm:"column(sku_id)"`
|
||||||
@@ -21,6 +36,10 @@ type StoreSkuBind struct {
|
|||||||
|
|
||||||
ElmID int64 `orm:"column(elm_id);index"`
|
ElmID int64 `orm:"column(elm_id);index"`
|
||||||
EbaiID int64 `orm:"column(ebai_id);index"`
|
EbaiID int64 `orm:"column(ebai_id);index"`
|
||||||
|
|
||||||
|
JdSyncStatus int8
|
||||||
|
ElmSyncStatus int8
|
||||||
|
EbaiSyncStatus int8
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*StoreSkuBind) TableUnique() [][]string {
|
func (*StoreSkuBind) TableUnique() [][]string {
|
||||||
|
|||||||
@@ -127,8 +127,8 @@ func (c *SkuController) DeleteCategory() {
|
|||||||
// @Param categoryID query int false "商品所属类别ID"
|
// @Param categoryID query int false "商品所属类别ID"
|
||||||
// @Param unit query string false "商品单位"
|
// @Param unit query string false "商品单位"
|
||||||
// @Param jdID query int false "商品京东ID"
|
// @Param jdID query int false "商品京东ID"
|
||||||
// @Param fromStatus query int false "查询起始状态(0:正常,1:下架)"
|
// @Param fromStatus query int false "查询起始状态(0:下架,1:正常)"
|
||||||
// @Param toStatus query int false "查询结束状态(0:正常,1:下架)"
|
// @Param toStatus query int false "查询起始状态(0:下架,1:正常)"
|
||||||
// @Param offset query int false "门店列表起始序号(以0开始,缺省为0)"
|
// @Param offset query int false "门店列表起始序号(以0开始,缺省为0)"
|
||||||
// @Param pageSize query int false "门店列表页大小(缺省为50)"
|
// @Param pageSize query int false "门店列表页大小(缺省为50)"
|
||||||
// @Success 200 {object} controllers.CallResult
|
// @Success 200 {object} controllers.CallResult
|
||||||
|
|||||||
36
controllers/cms_store_sku.go
Normal file
36
controllers/cms_store_sku.go
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
package controllers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"git.rosy.net.cn/jx-callback/business/jxstore/cms"
|
||||||
|
"github.com/astaxie/beego"
|
||||||
|
)
|
||||||
|
|
||||||
|
type StoreSkuController struct {
|
||||||
|
beego.Controller
|
||||||
|
}
|
||||||
|
|
||||||
|
// @Title 得到商家商品信息
|
||||||
|
// @Description 得到商家商品信息,如下条件之间是与的关系
|
||||||
|
// @Param token header string true "认证token"
|
||||||
|
// @Param storeID query int true "门店ID"
|
||||||
|
// @Param keyword query string false "查询关键字(可以为空,为空表示不限制)"
|
||||||
|
// @Param nameID query int false "SkuName ID"
|
||||||
|
// @Param skuID query int false "Sku ID"
|
||||||
|
// @Param name query string false "商品名称(不要求完全一致)"
|
||||||
|
// @Param prefix query string 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 /GetStoreSkus [get]
|
||||||
|
func (c *StoreSkuController) GetStoreSkus() {
|
||||||
|
c.callGetStoreSkus(func(params *tStoreSkuGetStoreSkusParams) (retVal interface{}, errCode string, err error) {
|
||||||
|
retVal, err = cms.GetStoreSkus(params.StoreID, params.Keyword, params.MapData, params.Offset, params.PageSize)
|
||||||
|
return retVal, "", err
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -359,6 +359,14 @@ func init() {
|
|||||||
MethodParams: param.Make(),
|
MethodParams: param.Make(),
|
||||||
Params: nil})
|
Params: nil})
|
||||||
|
|
||||||
|
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreSkuController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreSkuController"],
|
||||||
|
beego.ControllerComments{
|
||||||
|
Method: "GetStoreSkus",
|
||||||
|
Router: `/GetStoreSkus`,
|
||||||
|
AllowHTTPMethods: []string{"get"},
|
||||||
|
MethodParams: param.Make(),
|
||||||
|
Params: nil})
|
||||||
|
|
||||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:UserController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:UserController"],
|
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:UserController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:UserController"],
|
||||||
beego.ControllerComments{
|
beego.ControllerComments{
|
||||||
Method: "TmpAddMobile2Mobile",
|
Method: "TmpAddMobile2Mobile",
|
||||||
|
|||||||
@@ -46,6 +46,11 @@ func init() {
|
|||||||
&controllers.UserController{},
|
&controllers.UserController{},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
beego.NSNamespace("/store/sku",
|
||||||
|
beego.NSInclude(
|
||||||
|
&controllers.StoreSkuController{},
|
||||||
|
),
|
||||||
|
),
|
||||||
)
|
)
|
||||||
beego.AddNamespace(ns)
|
beego.AddNamespace(ns)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user