Accept Merge Request #52: (yonghui -> mark)

Merge Request: 获取各平台未营业门店
Created By: @苏尹岚
Accepted By: @苏尹岚
URL: https://rosydev.coding.net/p/jx-callback/d/jx-callback/git/merge/52
This commit is contained in:
苏尹岚
2019-12-05 17:22:37 +08:00
10 changed files with 296 additions and 13 deletions

View File

@@ -129,6 +129,14 @@ type JxBadCommentsExt struct {
VendorOrderID2 string `orm:"column(vendor_order_id2);size(48);index" json:"vendorOrderID2"`
}
type VendorStoreExcel struct {
StoreID int `json:"门店ID"`
VendorStoreName string `json:"门店名"`
Status string `json:"营业状态"`
Tel1 string `json:"电话1"`
Tel2 string `json:"电话2"`
}
var (
ErrMissingInput = errors.New("没有有效的输入参数")
ErrCanNotFindVendor = errors.New("vendorID参数不合法")
@@ -160,6 +168,13 @@ var (
"15:00:00",
"20:00:00",
}
titleListStore = []string{
"门店ID",
"门店名",
"营业状态",
"电话1",
"电话2",
}
)
func getStoresSql(ctx *jxcontext.Context, keyword string, params map[string]interface{}, orderTimeFrom, orderTimeTo time.Time) (sql string, sqlParams []interface{}, sqlFrom string, sqlFromParams []interface{}, err error) {
@@ -2269,3 +2284,131 @@ func ExecuteFileName(filename string) (name string) {
name = fileRealName + utils.Int64ToStr(time.Now().Unix()) + filePrefix
return name
}
func GetVendorStoreInfo(ctx *jxcontext.Context, vendorIDList []int, isAsync, isContinueWhenError bool) (hint string, err error) {
var (
storeListJD []VendorStoreExcel
storeListMT []VendorStoreExcel
storeListEB []VendorStoreExcel
)
taskSeqFunc := func(task *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) {
switch step {
case 0:
for _, vendorID := range vendorIDList {
iStoreHandler, _ := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.IStoreHandler)
storeIDs, err := iStoreHandler.GetAllStoresVendorID(ctx)
if err != nil {
return "", err
}
taskFunc := func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
var storeDetail *dao.StoreDetail
storeID := batchItemList[0].(string)
if partner.IsMultiStore(vendorID) {
multiHandler, _ := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.IMultipleStoresHandler)
storeDetail, err = multiHandler.ReadStore(ctx, storeID)
if err != nil {
return retVal, err
}
} else {
singleHandler, _ := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.ISingleStoreHandler)
storeDetail, err = singleHandler.ReadStore(ctx, storeID)
if err != nil {
return retVal, err
}
}
if storeDetail.Status != model.StoreStatusOpened {
var storeExcel = VendorStoreExcel{
StoreID: storeDetail.ID,
VendorStoreName: storeDetail.Name,
Tel1: storeDetail.Tel1,
Tel2: storeDetail.Tel2,
Status: StoreStatus2Chinese(storeDetail.Status),
}
retVal = []VendorStoreExcel{storeExcel}
}
return retVal, err
}
taskParallel := tasksch.NewParallelTask("获取各平台未营业门店", tasksch.NewParallelConfig().SetIsContinueWhenError(isContinueWhenError), ctx, taskFunc, storeIDs)
tasksch.HandleTask(taskParallel, task, true).Run()
storeList, err := taskParallel.GetResult(0)
for _, v := range storeList {
if vendorID == model.VendorIDJD {
storeListJD = append(storeListJD, v.(VendorStoreExcel))
}
if vendorID == model.VendorIDEBAI {
storeListEB = append(storeListEB, v.(VendorStoreExcel))
}
if vendorID == model.VendorIDMTWM {
storeListMT = append(storeListMT, v.(VendorStoreExcel))
}
}
}
case 1:
WriteToExcelStore(task, storeListJD, storeListMT, storeListEB)
}
return result, err
}
taskSeq := tasksch.NewSeqTask2("导出各平台未营业门店-序列任务", ctx, isContinueWhenError, taskSeqFunc, 2)
tasksch.HandleTask(taskSeq, nil, true).Run()
if !isAsync {
_, err = taskSeq.GetResult(0)
hint = "1"
} else {
hint = taskSeq.GetID()
}
return hint, err
}
func WriteToExcelStore(task *tasksch.SeqTask, storeListJD, storeListMT, storeListEB []VendorStoreExcel) (err error) {
var sheetList []*excel.Obj2ExcelSheetConfig
var downloadURL, fileName string
if len(storeListJD) > 0 {
excelConf := &excel.Obj2ExcelSheetConfig{
Title: "京东平台",
Data: storeListJD,
CaptionList: titleListStore,
}
sheetList = append(sheetList, excelConf)
}
if len(storeListMT) > 0 {
excelConf := &excel.Obj2ExcelSheetConfig{
Title: "美团平台",
Data: storeListMT,
CaptionList: titleListStore,
}
sheetList = append(sheetList, excelConf)
}
if len(storeListEB) > 0 {
excelConf := &excel.Obj2ExcelSheetConfig{
Title: "饿百平台",
Data: storeListEB,
CaptionList: titleListStore,
}
sheetList = append(sheetList, excelConf)
}
if len(sheetList) == 0 {
return errors.New("所选平台没有未营业的门店!")
} else {
downloadURL, fileName, err = jxutils.UploadExeclAndPushMsg(sheetList, "各平台未营业门店统计")
if err != nil {
baseapi.SugarLogger.Errorf("WriteToExcel:upload %s failed error:%v", fileName, err)
} else {
noticeMsg := fmt.Sprintf("[详情点我]path=%s \n", downloadURL)
task.SetNoticeMsg(noticeMsg)
baseapi.SugarLogger.Debugf("WriteToExcel:upload %s success, downloadURL:%s", fileName, downloadURL)
}
}
return err
}
func StoreStatus2Chinese(status int) (str string) {
if status == model.StoreStatusOpened {
return "正常营业"
} else if status == model.StoreStatusDisabled {
return "暂停营业"
} else if status == model.StoreStatusClosed {
return "休息中"
} else {
return "未知的营业状态"
}
}

View File

@@ -2161,14 +2161,26 @@ func ReCalculateJxPrice(ctx *jxcontext.Context, storeIDs []int) (err error) {
return err
}
func GetTopSkusByStoreIDs(ctx *jxcontext.Context, storeIDs []int) (skuAndName []*model.SkuAndName, err error) {
func GetTopSkusByStoreIDs(ctx *jxcontext.Context, storeIDs []int) (skuName []*model.SkuName, err error) {
if len(storeIDs) == 0 {
return skuAndName, err
return skuName, err
}
db := dao.GetDB()
skuAndName, err = dao.GetTopSkusByStoreIDs(db, storeIDs)
skuName, err = dao.GetTopSkusByStoreIDs(db, storeIDs)
if err != nil {
return nil, err
}
return skuAndName, err
return skuName, err
}
func GetTopCategorysByStoreIDs(ctx *jxcontext.Context, storeIDs []int) (skuCategory []*model.SkuCategory, err error) {
if len(storeIDs) == 0 {
return skuCategory, err
}
db := dao.GetDB()
skuCategory, err = dao.GetTopCategorysByStoreIDs(db, storeIDs)
if err != nil {
return nil, err
}
return skuCategory, err
}

View File

@@ -33,3 +33,8 @@ func GetStatisticsReportForAfsOrders(ctx *jxcontext.Context, storeIDs []int, fro
statisticsReportForOrdersList, err = dao.GetGetStatisticsReportForAfsOrders(db, storeIDs, fromDateParm, toDateParm)
return statisticsReportForOrdersList, err
}
func StatisticsReportForStoreSkusPrice(ctx *jxcontext.Context, cityCodes, skuIDs []int) (err error) {
db := dao.GetDB()
return dao.GetStatisticsReportForStoreSkusPrice(db, cityCodes, skuIDs)
}

View File

@@ -177,3 +177,8 @@ func GetGetStatisticsReportForAfsOrders(db *DaoDB, storeIDs []int, fromDate time
}
return nil, err
}
func GetStatisticsReportForStoreSkusPrice(db *DaoDB, cityCodes, skuIDs []int) (err error) {
return err
}

View File

@@ -662,18 +662,20 @@ func GetStoreSkusByNameIDs(db *DaoDB, storeIDs []int, nameID int) (skuList []*St
return skuList, err
}
func GetTopSkusByStoreIDs(db *DaoDB, storeIDs []int) (skuAndName []*model.SkuAndName, err error) {
func GetTopSkusByStoreIDs(db *DaoDB, storeIDs []int) (skuName []*model.SkuName, err error) {
sql := `
SELECT *
SELECT t3.*
FROM(
SELECT SUM(b.count) count,b.sku_id
SELECT SUM(b.count) count,d.id
FROM goods_order a
JOIN order_sku b ON a.vendor_order_id = b.vendor_order_id
JOIN sku c ON b.sku_id = c.id AND c.deleted_at = ?
JOIN sku_name d ON d.id = c.name_id AND d.deleted_at = ?
WHERE 1=1
`
sqlParams := []interface{}{
utils.DefaultTimeValue,
utils.DefaultTimeValue,
}
if len(storeIDs) > 0 {
sql += " AND a.store_id in(" + GenQuestionMarks(len(storeIDs)) + ")"
@@ -681,15 +683,47 @@ func GetTopSkusByStoreIDs(db *DaoDB, storeIDs []int) (skuAndName []*model.SkuAnd
}
sql += `
AND b.sale_price > ?
GROUP BY b.sku_id)t1
JOIN sku t2 ON t1.sku_id = t2.id
JOIN sku_name t3 ON t2.name_id = t3.id
GROUP BY d.id)t1
JOIN sku_name t3 ON t1.id = t3.id
ORDER BY t1.count DESC
LIMIT ?
`
sqlParams = append(sqlParams, 100, 30)
err = GetRows(db, &skuAndName, sql, sqlParams...)
return skuAndName, err
err = GetRows(db, &skuName, sql, sqlParams...)
return skuName, err
}
func GetTopCategorysByStoreIDs(db *DaoDB, storeIDs []int) (skuCategory []*model.SkuCategory, err error) {
sql := `
SELECT t3.*
FROM(
SELECT SUM(b.count) count,d.category_id
FROM goods_order a
JOIN order_sku b ON a.vendor_order_id = b.vendor_order_id
JOIN sku c ON b.sku_id = c.id AND c.deleted_at = ?
JOIN sku_name d ON d.id = c.name_id AND d.deleted_at = ?
WHERE 1=1
`
sqlParams := []interface{}{
utils.DefaultTimeValue,
utils.DefaultTimeValue,
}
if len(storeIDs) > 0 {
sql += " AND a.store_id in(" + GenQuestionMarks(len(storeIDs)) + ")"
sqlParams = append(sqlParams, storeIDs)
}
sql += `
AND b.sale_price > ?
GROUP BY d.category_id)t1
JOIN sku_category t3 ON t1.category_id = t3.id
AND t3.level = ?
AND t3.deleted_at = ?
ORDER BY t1.count DESC
LIMIT ?
`
sqlParams = append(sqlParams, 100, 2, utils.DefaultTimeValue, 10)
err = GetRows(db, &skuCategory, sql, sqlParams...)
return skuCategory, err
}
func SetStoreSkuBindVendorPrice(storeSkuBind *model.StoreSkuBind, vendorID int, vendorPrice int) {

View File

@@ -39,9 +39,12 @@ func New() (obj *PurchaseHandler) {
}
func EbaiBusStatus2JxStatus(ebaiStatus int) int {
if ebaiStatus == ebaiapi.ShopBusStatusHaveRest || ebaiStatus == ebaiapi.ShopBusStatusSuspended {
if ebaiStatus == ebaiapi.ShopBusStatusHaveRest {
return model.StoreStatusClosed
}
if ebaiStatus == ebaiapi.ShopBusStatusSuspended {
return model.StoreStatusDisabled
}
return model.StoreStatusOpened
}

View File

@@ -562,3 +562,22 @@ func (c *StoreController) JdStoreInfoCoordinateRecover() {
return retVal, "", err
})
}
// @Title 导出平台门店信息
// @Description 导出平台门店信息
// @Param token header string true "认证token"
// @Param vendorIDs formData string true "平台ID列表"
// @Param isAsync formData bool false "是否异步操作"
// @Param isContinueWhenError formData bool false "单个同步失败是否继续缺省false"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /GetVendorStoreInfo [post]
func (c *StoreController) GetVendorStoreInfo() {
var vendorIDList []int
c.callGetVendorStoreInfo(func(params *tStoreGetVendorStoreInfoParams) (retVal interface{}, errCode string, err error) {
if err = jxutils.Strings2Objs(params.VendorIDs, &vendorIDList); err == nil {
retVal, err = cms.GetVendorStoreInfo(params.Ctx, vendorIDList, params.IsAsync, params.IsContinueWhenError)
}
return retVal, "", err
})
}

View File

@@ -464,3 +464,20 @@ func (c *StoreSkuController) GetTopSkusByStoreIDs() {
return retVal, "", err
})
}
// @Title 根据门店信息查找推荐分类(按商品销量)
// @Description 根据门店信息查找推荐分类(按商品销量)
// @Param token header string true "认证token"
// @Param storeIDs query string true "门店列表"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /GetTopCategorysByStoreIDs [get]
func (c *StoreSkuController) GetTopCategorysByStoreIDs() {
var storeIDList []int
c.callGetTopCategorysByStoreIDs(func(params *tStoreSkuGetTopCategorysByStoreIDsParams) (retVal interface{}, errCode string, err error) {
if jxutils.Strings2Objs(params.StoreIDs, &storeIDList); err == nil {
retVal, err = cms.GetTopCategorysByStoreIDs(params.Ctx, storeIDList)
}
return retVal, "", err
})
}

View File

@@ -48,3 +48,21 @@ func (c *ReportController) StatisticsReportForAfsOrders() {
return retVal, "", err
})
}
// @Title 查询京西门店商品价格统计相关信息
// @Description 查询京西门店商品价格统计相关信息
// @Param token header string true "认证token"
// @Param cityCodes formData string true "城市ID列表[1,2,3]"
// @Param skuIDs formData string true "skuID列表[1,2,3]"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /StatisticsReportForStoreSkusPrice [post]
func (c *ReportController) StatisticsReportForStoreSkusPrice() {
c.callStatisticsReportForStoreSkusPrice(func(params *tReportStatisticsReportForStoreSkusPriceParams) (retVal interface{}, errCode string, err error) {
var cityCodeList, skuIDList []int
if err = jxutils.Strings2Objs(params.CityCodes, &cityCodeList, params.SkuIDs, &skuIDList); err == nil {
err = report.StatisticsReportForStoreSkusPrice(params.Ctx, cityCodeList, skuIDList)
}
return retVal, "", err
})
}

View File

@@ -1062,6 +1062,15 @@ func init() {
Filters: nil,
Params: nil})
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:ReportController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:ReportController"],
beego.ControllerComments{
Method: "StatisticsReportForStoreSkusPrice",
Router: `/StatisticsReportForStoreSkusPrice`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Filters: nil,
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: "AddCategory",
@@ -1404,6 +1413,15 @@ func init() {
Filters: nil,
Params: nil})
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreController"],
beego.ControllerComments{
Method: "GetVendorStoreInfo",
Router: `/GetVendorStoreInfo`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Filters: nil,
Params: nil})
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreController"],
beego.ControllerComments{
Method: "GetWeeklyStoreScore",
@@ -1566,6 +1584,15 @@ func init() {
Filters: 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: "GetTopCategorysByStoreIDs",
Router: `/GetTopCategorysByStoreIDs`,
AllowHTTPMethods: []string{"get"},
MethodParams: param.Make(),
Filters: 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: "GetTopSkusByStoreIDs",