Merge branch 'mark' of e.coding.net:rosydev/jx-callback into mark

This commit is contained in:
gazebo
2019-11-15 16:40:42 +08:00
13 changed files with 579 additions and 113 deletions

View File

@@ -626,7 +626,7 @@ func (c *OrderManager) RefreshHistoryOrdersEarningPrice(ctx *jxcontext.Context,
if fromDate != "" && toDate != "" {
fromDateParam = utils.Str2Time(fromDate)
toDateParam = utils.Str2Time(toDate)
actList, _ := dao.QueryActs(db, actID, 0, math.MaxInt32, 0, "", -1, nil, nil, nil, 0, 0, 0, time.Time{}, time.Time{}, time.Time{}, time.Time{})
actList, _ := dao.QueryActs(db, actID, 0, math.MaxInt32, 0, "", -1, nil, nil, nil, 0, 0, 0, utils.DefaultTimeValue, utils.DefaultTimeValue, utils.DefaultTimeValue, utils.DefaultTimeValue)
if len(actList.Data) > 0 {
actBeginAt := actList.Data[0].BeginAt
actEndAt := actList.Data[0].EndAt
@@ -656,7 +656,7 @@ func (c *OrderManager) RefreshHistoryOrdersEarningPrice(ctx *jxcontext.Context,
return "", errors.New(fmt.Sprintf("未查询到相关结算活动活动ID[%d]", actID))
}
} else if fromDate == "" && toDate == "" {
actList, _ := dao.QueryActs(db, actID, 0, math.MaxInt32, 0, "", -1, nil, nil, nil, 0, 0, 0, time.Time{}, time.Time{}, time.Time{}, time.Time{})
actList, _ := dao.QueryActs(db, actID, 0, math.MaxInt32, 0, "", -1, nil, nil, nil, 0, 0, 0, utils.DefaultTimeValue, utils.DefaultTimeValue, utils.DefaultTimeValue, utils.DefaultTimeValue)
if len(actList.Data) > 0 {
orderList, _ = dao.QueryOrders(db, vendorOrderID, actID, vendorIDs, storeID, actList.Data[0].BeginAt, actList.Data[0].EndAt)
} else {

View File

@@ -777,6 +777,9 @@ func UpdateStore(ctx *jxcontext.Context, storeID int, payload map[string]interfa
dao.Commit(db)
}
notifyStoreOperatorChanged(store, valid["operatorPhone"])
if valid["openTime1"] != 0 || valid["closeTime1"] != 0 || valid["openTime2"] != 0 || valid["closeTime2"] != 0 {
err = CurVendorSync.ChangeStoreSkuSaleStatus(ctx, storeID, true, false)
}
}
} else {
globals.SugarLogger.Debugf("UpdateStore track:%s, store:%s", ctx.GetTrackInfo(), utils.Format4Output(store, true))

View File

@@ -116,13 +116,15 @@ type StoreSkuBindSkuInfo struct {
// UpdateStoreSku用API调用时
type StoreSkuBindInfo struct {
StoreID int `json:"storeID"`
NameID int `json:"nameID"`
UnitPrice int `json:"unitPrice"` // 对于是份的SKU就是单价每斤价格其它则为总价
IsFocus int `json:"isFocus"` // -1不关注0忽略1关注
IsSale int `json:"isSale"` // -1不可售0忽略1可售
SubStoreID int `json:"subStoreID,omitempty"`
Skus []*StoreSkuBindSkuInfo `json:"skus,omitempty"`
StoreID int `json:"storeID"`
NameID int `json:"nameID"`
UnitPrice int `json:"unitPrice"` // 对于是份的SKU就是单价每斤价格其它则为总价
IsFocus int `json:"isFocus"` // -1不关注0忽略1关注
IsSale int `json:"isSale"` // -1不可售0忽略1可售
SubStoreID int `json:"subStoreID,omitempty"`
StatusSaleBegin int16 `json:"statusSaleBegin"` //商品可售时间范围
StatusSaleEnd int16 `json:"statusSaleEnd"`
Skus []*StoreSkuBindSkuInfo `json:"skus,omitempty"`
}
type tStoreSkuBindAndSpec struct {
@@ -1076,6 +1078,21 @@ func updateStoresSkusWithoutSync(ctx *jxcontext.Context, db *dao.DaoDB, storeIDs
updateFieldMap["Price"] = 1
updateFieldMap["JxPrice"] = 1
}
if skuBindInfo.StatusSaleBegin != 0 && skuBindInfo.StatusSaleEnd != 0 {
if skuBindInfo.StatusSaleBegin < 0 || skuBindInfo.StatusSaleBegin > 2359 ||
skuBindInfo.StatusSaleEnd < 0 || skuBindInfo.StatusSaleEnd > 2359 {
dao.Rollback(db)
return nil, fmt.Errorf("更改商品:%s, 可售时间不合法!时间范围:[%v] 至 [%v]", allBinds[0].Name, skuBindInfo.StatusSaleBegin, skuBindInfo.StatusSaleEnd)
}
if skuBindInfo.StatusSaleBegin >= skuBindInfo.StatusSaleEnd {
dao.Rollback(db)
return nil, fmt.Errorf("更改商品:%s, 可售时间不允许交叉!时间范围:[%v] 至 [%v]", allBinds[0].Name, skuBindInfo.StatusSaleBegin, skuBindInfo.StatusSaleEnd)
}
updateFieldMap["StatusSaleBegin"] = int(skuBindInfo.StatusSaleBegin)
updateFieldMap["StatusSaleEnd"] = int(skuBindInfo.StatusSaleEnd)
skuBind.StatusSaleBegin = skuBindInfo.StatusSaleBegin
skuBind.StatusSaleEnd = skuBindInfo.StatusSaleEnd
}
// todo 这里应该是不需处理这个信息的吧?
// if inSkuBind != nil && inSkuBind.EbaiID != 0 {
// skuBind.EbaiID = inSkuBind.EbaiID

View File

@@ -653,3 +653,48 @@ func (v *VendorSync) SyncSkuNames(ctx *jxcontext.Context, nameIDs []int, isForce
}
return v.SyncSkus(ctx, db, nameIDs, nil, isAsync, isContinueWhenError, ctx.GetUserName())
}
func (v *VendorSync) ChangeStoreSkuSaleStatus(ctx *jxcontext.Context, storeID int, isAsync, isContinueWhenError bool) (err error) {
var (
storeIDs []int
skuIDs []int
)
db := dao.GetDB()
storeSkuList, err := dao.GetStoresSkusInfoBySaleTime(db, storeID)
if len(storeSkuList) < 1 || err != nil {
return errors.New(fmt.Sprintf("未查询到设置了可售时间的商品 GetStoresSkusInfoBySaleTimeerr : %v", err))
}
for _, v := range storeSkuList {
storeIDs = append(storeIDs, v.StoreID)
skuIDs = append(skuIDs, v.SkuID)
}
vendorIDs := partner.GetPurchasePlatformVendorIDs()
dao.UpdateStoreSkuBindSyncStatus(db, vendorIDs, storeID)
v.SyncStoresSkus(ctx, db, vendorIDs, storeIDs, skuIDs, false, isAsync, isContinueWhenError)
if err != nil {
return err
}
return nil
}
func GetTimeMixByInt(begin1, end1, begin2, end2 int16) (beginAt, endAt int16) {
if (begin1 > begin2 && begin1 > end2) || (begin2 > end1 && end2 > end1) {
return 0, 0
}
if begin1 > begin2 {
beginAt = begin1
if end1 > end2 {
endAt = end2
} else {
endAt = end1
}
} else {
beginAt = begin2
if end1 > end2 {
endAt = end2
} else {
endAt = end1
}
}
return beginAt, endAt
}

View File

@@ -299,6 +299,7 @@ func syncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, isFull bo
} else {
skus, err = dao.GetStoreSkus(db, vendorID, storeID, skuIDs)
}
if err != nil || len(skus) == 0 {
return err
}
@@ -328,8 +329,13 @@ func syncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, isFull bo
if reorderHandler != nil {
reorderSkuMap = make(map[string][]*dao.StoreSkuSyncInfo)
}
now := jxutils.OperationTime2HourMinuteFormat(time.Now())
for _, sku := range skus {
if isUpdateSkuSaleStatus(sku, storeDetail, now) {
sku.MergedStatus = model.SkuStatusDontSale
} else {
sku.MergedStatus = model.SkuStatusNormal
}
var bareSku *partner.StoreSkuInfo
isNeedReorder := false
if isStoreSkuSyncNeedDelete(sku) {
@@ -800,3 +806,39 @@ func GetSensitiveWord(singleStoreHandler partner.ISingleStoreStoreSkuHandler, st
return ""
}
func isUpdateSkuSaleStatus(sku *dao.StoreSkuSyncInfo, storeDetail *dao.StoreDetail, now int16) bool {
//商品可售时间的差集与门店营业时间的交集为不可售,其余为原本状态
var openTime int16
var closeTime int16
saleBeginTime := sku.StatusSaleBegin
saleEndTime := sku.StatusSaleEnd
if storeDetail.OpenTime2 != 0 && storeDetail.CloseTime2 != 0 {
if storeDetail.OpenTime1 < storeDetail.OpenTime2 {
openTime = storeDetail.OpenTime1
} else {
openTime = storeDetail.OpenTime2
}
if storeDetail.CloseTime1 > storeDetail.CloseTime2 {
closeTime = storeDetail.CloseTime1
} else {
closeTime = storeDetail.CloseTime2
}
} else {
openTime = storeDetail.OpenTime1
closeTime = storeDetail.CloseTime1
}
beginAt1, endAt1 := GetTimeMixByInt(0, saleBeginTime, openTime, closeTime)
beginAt2, endAt2 := GetTimeMixByInt(saleEndTime, 2400, openTime, closeTime)
if beginAt1 != 0 && endAt1 != 0 {
if now >= beginAt1 && now < endAt1 {
return true
}
}
if beginAt2 != 0 && endAt2 != 0 {
if now >= beginAt2 && now < endAt2 {
return true
}
}
return false
}

View File

@@ -1,6 +1,7 @@
package cms
import (
"fmt"
"testing"
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
@@ -30,3 +31,14 @@ func TestFreeBatchStoreSkuInfo(t *testing.T) {
t.Fatal(err)
}
}
func TestGetTimeMixByInt(t *testing.T) {
var (
time1 = 1100
time2 = 2300
time3 = 1200
time4 = 2400
)
a, b := GetTimeMixByInt(time1, time2, time3, time4)
fmt.Println(a, b)
}

View File

@@ -46,6 +46,22 @@ var (
"19:00:00",
"22:00:00",
}
ChangeStoreSkuSaleStatusList = []string{
"7:00:00",
"8:00:00",
"9:00:00",
"10:00:00",
"11:00:00",
"12:00:00",
"13:00:00",
"14:00:00",
"15:00:00",
"16:00:00",
"17:00:00",
"18:00:00",
"19:00:00",
"20:00:00",
}
openRemoteStoreTimeList = []string{
"23:30:00",
}
@@ -117,6 +133,9 @@ func Init() {
}, []string{
"04:05:06",
})
ScheduleTimerFunc("ChangeStoreSkuSaleStatus", func() {
cms.CurVendorSync.ChangeStoreSkuSaleStatus(jxcontext.AdminCtx, 0, true, false)
}, ChangeStoreSkuSaleStatusList)
}
}

View File

@@ -1,118 +1,321 @@
package yonghui
import (
"errors"
"fmt"
"math"
"mime/multipart"
"unicode"
"git.rosy.net.cn/baseapi"
"git.rosy.net.cn/baseapi/utils"
"github.com/360EntSecGroup-Skylar/excelize"
"git.rosy.net.cn/baseapi/platformapi/jdapi"
"git.rosy.net.cn/baseapi/platformapi/weimobapi"
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
"github.com/360EntSecGroup-Skylar/excelize"
"git.rosy.net.cn/jx-callback/business/jxutils/tasksch"
"git.rosy.net.cn/jx-callback/business/model/dao"
"git.rosy.net.cn/jx-callback/globals/api"
)
type SheetParam struct {
SkuIDCol int
SkuPriceCol int
OrgSkuIdCol int
OrgSkuPriceCol int
SkuRow int
}
var (
sheetNames = []string{"蔬菜", "水果", "肉禽", "净配", "水产", "干货", "MINI肉禽价格"}
sheetMap = map[string]*SheetParam{
"蔬菜": &SheetParam{
SkuIDCol: 0,
SkuPriceCol: 14,
OrgSkuIdCol: 5,
OrgSkuPriceCol: 8,
SkuRow: 2,
}, "水果": &SheetParam{
SkuIDCol: 0,
SkuPriceCol: 14,
OrgSkuIdCol: 5,
OrgSkuPriceCol: 8,
SkuRow: 2,
}, "肉禽": &SheetParam{
SkuIDCol: 0,
SkuPriceCol: 12,
OrgSkuIdCol: 4,
OrgSkuPriceCol: 7,
SkuRow: 1,
}, "净配": &SheetParam{
SkuIDCol: 0,
SkuPriceCol: 12,
OrgSkuIdCol: 4,
OrgSkuPriceCol: 7,
SkuRow: 1,
}, "水产": &SheetParam{
SkuIDCol: 1,
SkuPriceCol: 15,
OrgSkuIdCol: 6,
OrgSkuPriceCol: 9,
SkuRow: 1,
}, "干货": &SheetParam{
SkuIDCol: 0,
SkuPriceCol: 13,
OrgSkuIdCol: 4,
OrgSkuPriceCol: 7,
SkuRow: 2,
}, "MINI肉禽价格": &SheetParam{
SkuIDCol: 1,
SkuPriceCol: 5,
OrgSkuIdCol: -1,
OrgSkuPriceCol: -1,
SkuRow: 1,
},
}
)
//sheet1 蔬菜
var (
sheet1SkuIdCol = 0
sheet1SkuPriceCol = 14
sheet1OrgSkuIdCol = 5
sheet1OrgSkuPriceCol = 8
const (
parallelCount = 5
UpdateGoodsShelfStatusCount = 50 //微盟下架商品api限制一次50个
)
func SendFilesToStores(ctx *jxcontext.Context, files []*multipart.FileHeader) (hint string, err error) {
func LoadExcelByYongHui(ctx *jxcontext.Context, files []*multipart.FileHeader, isAsync bool) (hint string, err error) {
var (
// skuId string
// skuPrice string
skuMap = make(map[string]string)
skuMap = make(map[string]float64)
errMsg string
costPrice float64 //成本价
goodsList []*weimobapi.GoodsInfo
goodsIDListForPutAway []interface{}
)
db := dao.GetDB()
if len(files) == 0 {
return "", errors.New("没有文件上传!")
}
taskSeqFunc := func(task *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) {
switch step {
case 0:
//读取excel文件
xlsx, err := excelize.OpenFile(files[0].Filename)
if err != nil {
return "", err
}
for k, _ := range sheetMap {
sheetParam := sheetMap[k]
rows, _ := xlsx.GetRows(k)
for rowNum, row := range rows {
if rowNum < sheetParam.SkuRow {
continue
}
GetCellIntoMap(sheetParam.SkuIDCol, sheetParam.SkuPriceCol, sheetParam.OrgSkuIdCol, sheetParam.OrgSkuPriceCol, skuMap, row, k, rowNum)
if len(skuMap) < 1 {
errMsg += fmt.Sprintf("读取Excel数据失败Excel格式排版可能发生了变化sheetName: [%v]", k)
}
}
if errMsg != "" {
return "", errors.New(errMsg)
}
}
case 1:
//获取微盟所有商品
goodsList, err = GetWeiMobGoodsList()
if err != nil {
baseapi.SugarLogger.Errorf("GetWeiMobGoodsList error:%v", err)
}
taskFunc2 := func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
v := batchItemList[0].(*weimobapi.GoodsInfo)
goodsDetail, err := api.WeimobAPI.QueryGoodsDetail(v.GoodsID)
if err != nil {
baseapi.SugarLogger.Errorf("QueryGoodsDetail error:%v", err)
}
v.GoodsDetailInfo = goodsDetail
return retVal, err
}
taskParallel2 := tasksch.NewParallelTask("获取微盟商品", tasksch.NewParallelConfig().SetParallelCount(parallelCount), ctx, taskFunc2, goodsList)
tasksch.HandleTask(taskParallel2, task, true).Run()
_, err = taskParallel2.GetResult(0)
//找出excel上有微盟没有的,有就列出报错,不进行更新
goodsInfoAndDetailMap := GetGoodsInfoAndDetailMap(goodsList)
for k, _ := range skuMap {
//表示excel上有微盟上没有
if goodsInfoAndDetailMap[k] == nil {
errMsg += fmt.Sprintf("在微盟上未找到该商品excel商品ID : [%v]\n", k)
}
}
if errMsg != "" {
return "", errors.New(errMsg)
}
case 2:
//找出微盟上有excel上没有的有就更新没有就下架
taskFunc3 := func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
goods := batchItemList[0].(*weimobapi.GoodsInfo)
goodsDetail := goods.GoodsDetailInfo
spuCode := goodsDetail.OuterGoodsCode
if spuCode != "" {
//如果微盟商品里找得到excel中的商品
if skuMap[spuCode] != 0 {
//获取京西库商品
skuList, _ := dao.GetSkus(db, nil, []int{int(utils.Str2Int64(goodsDetail.SkuMap.SingleSku.OuterSkuCode))}, nil, nil)
if len(skuList) == 0 {
errMsg += fmt.Sprintf("在京西库中未找到该商品name_id : [%v] \n", goodsDetail.SkuMap.SingleSku.OuterSkuCode)
} else {
if skuList[0].Unit != "份" {
costPrice = Float64Round(0.5 / goodsDetail.SkuMap.SingleSku.B2CSku.Weight * skuMap[spuCode])
} else {
costPrice = skuMap[spuCode]
}
if errMsg == "" {
_, _, err = updateWeiMobGoods(costPrice, skuMap[spuCode], goodsDetail)
}
}
} else {
//下架微盟商品
retVal = []int64{goodsDetail.GoodsID}
}
}
return retVal, err
}
taskParallel3 := tasksch.NewParallelTask("根据获取的微盟所有商品并更新", tasksch.NewParallelConfig().SetParallelCount(parallelCount), ctx, taskFunc3, goodsList)
tasksch.HandleTask(taskParallel3, task, true).Run()
goodsIDListForPutAwayInterface, err2 := taskParallel3.GetResult(0)
if err = err2; err != nil {
return "", err
}
// 批量下架微盟商品
goodsIDListForPutAway = goodsIDListForPutAwayInterface
case 3:
if errMsg == "" {
taskFunc4 := func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
int64Slice := []int64{}
for _, v := range batchItemList {
int64Slice = append(int64Slice, v.(int64))
}
// PutAwayWeiMobSku(int64Slice)
return retVal, err
}
taskParallel4 := tasksch.NewParallelTask("下架微盟商品", tasksch.NewParallelConfig().SetParallelCount(parallelCount).SetBatchSize(UpdateGoodsShelfStatusCount), ctx, taskFunc4, goodsIDListForPutAway)
tasksch.HandleTask(taskParallel4, task, true).Run()
_, err = taskParallel4.GetResult(0)
}
}
return result, err
}
taskSeq := tasksch.NewSeqTask("读取永辉Excel文件修改微盟商品价格可售状态-序列任务", ctx, taskSeqFunc, 4)
tasksch.HandleTask(taskSeq, nil, true).Run()
if !isAsync {
_, err = taskSeq.GetResult(0)
hint = "1"
} else {
hint = taskSeq.GetID()
}
if errMsg != "" {
baseapi.SugarLogger.Debugf(errMsg)
}
return hint, err
}
func PutAwayWeiMobSku(goodsIDListForPutAway []int64) {
err := api.WeimobAPI.UpdateGoodsShelfStatus(goodsIDListForPutAway, false)
if err != nil {
baseapi.SugarLogger.Errorf("UpdateGoodsShelfStatus error:%v", err)
}
}
func GetGoodsInfoAndDetailMap(goodsList []*weimobapi.GoodsInfo) (goodsMap map[string]*weimobapi.GoodsInfo) {
goodsMap = make(map[string]*weimobapi.GoodsInfo)
for _, v := range goodsList {
goodsMap[v.GoodsDetailInfo.OuterGoodsCode] = v
}
return goodsMap
}
func updateWeiMobGoods(costPrice, salePrice float64, goodsDetail *weimobapi.GoodsDetailInfo) (goodsID int64, skuMap map[string]int64, err error) {
var (
categoryList []*weimobapi.CategoryList
skuListInfo = goodsDetail.SkuList[0]
skuListParam []*weimobapi.SkuList
categoryID int
deliveryTypeListSlice []int64
)
//查询配送方式
deliveryTypeList, err := api.WeimobAPI.FindDeliveryTypeList(goodsDetail.GoodsID)
if err != nil {
baseapi.SugarLogger.Errorf("FindDeliveryTypeList error:%v", err)
}
for _, deliveryType := range deliveryTypeList {
if deliveryType.Selected {
deliveryTypeListSlice = append(deliveryTypeListSlice, deliveryType.DeliveryID)
}
}
//查询运费模板
freightTemplateListInfo, err := api.WeimobAPI.FindFreightTemplateList(goodsDetail.GoodsID)
if err != nil {
baseapi.SugarLogger.Errorf("FindFreightTemplateList error:%v", err)
}
//寻找分类子ID
categoryList = goodsDetail.CategoryList
if len(categoryList) > 0 {
categoryID = categoryList[len(categoryList)-1].CategoryID
} else {
return 0, nil, errors.New(fmt.Sprintf("未查询到此商品的分类信息goodsID : [%v] ,", goodsDetail.GoodsID))
}
b2CSku := &weimobapi.B2CSku{
Weight: skuListInfo.B2CSku.Weight,
Volume: skuListInfo.B2CSku.Volume,
}
b2CGoods := &weimobapi.B2CGoods{
B2CGoodsType: goodsDetail.B2CGoods.B2CGoodsType,
DeliveryTypeIDList: deliveryTypeListSlice,
FreightTemplateID: freightTemplateListInfo.DefaultFreightTemplate.TemplateID,
}
skuList := &weimobapi.SkuList{
SalePrice: salePrice,
CostPrice: costPrice,
SkuID: skuListInfo.SkuID,
EditStockNum: skuListInfo.EditStockNum,
OuterSkuCode: skuListInfo.OuterSkuCode,
B2CSku: b2CSku,
}
skuListParam = append(skuListParam, skuList)
goods := &weimobapi.Goods{
B2CGoods: b2CGoods,
SkuList: skuListParam,
Title: goodsDetail.Title,
IsMultiSku: goodsDetail.IsMultiSku,
IsPutAway: goodsDetail.IsPutAway,
GoodsImageURL: goodsDetail.GoodsImageURL,
GoodsID: goodsDetail.GoodsID,
CategoryID: categoryID,
OuterGoodsCode: goodsDetail.OuterGoodsCode,
PointDeductRatio: goodsDetail.PointDeductRatio,
}
updateGoodsParam := &weimobapi.UpdateGoodsParam{
Goods: goods,
}
return api.WeimobAPI.UpdateGoods3(updateGoodsParam)
}
func GetWeiMobGoodsList() (goodsList []*weimobapi.GoodsInfo, err error) {
param := &weimobapi.QueryGoodsListParam{
PageNum: 1,
PageSize: jdapi.MaxSkuIDsCount4QueryListBySkuIds,
}
// if len(files) == 0 {
// return "", errors.New("没有文件上传!")
// }
xlsx, err := excelize.OpenFile("111.xlsx")
if err != nil {
fmt.Println(err)
return
}
for _, v := range sheetNames {
// goodsParam := &weimobapi.GoodsParameter{}
rows, _ := xlsx.GetRows(v)
switch v {
case "蔬菜":
for _, row := range rows {
for k, _ := range row {
if k == sheet1SkuIdCol {
}
// if !IsChineseChar(colCell) {
// }
}
fmt.Println()
}
for {
goodsInfoList, _, err := api.WeimobAPI.QueryGoodsList(param)
if err != nil {
return nil, err
}
if len(goodsInfoList) > 0 {
goodsList = append(goodsList, goodsInfoList...)
}
if len(goodsInfoList) < param.PageSize {
break
}
param.PageNum++
}
// xlFile, err := xlsx.OpenFile("111.xlsx")
// if err != nil {
// errors.New(err.Error())
// }
// excelize
// for _, sheet := range xlFile.Sheets {
// if sheet.Name == "蔬菜" {
// for j := 0; j < len(sheet.Rows); j++ {
// cells := sheet.Rows[j].Cells
// for i := 0; i < len(cells); i++ {
// cell := cells[i]
// if i == 0 {
// if _, err := strconv.Atoi(cell.String()); err != nil || cell.String() == "" {
// continue
// }
// skuId = cell.String()
// }
// if i == 14 {
// skuPrice = cell.String()
// }
// skuMap[skuId] = skuPrice
// }
// }
// }
// }
for k, v := range skuMap {
fmt.Println(k)
fmt.Println(v)
}
GetWeiMoGoodsList(param)
return "", err
}
func GetWeiMoGoodsList(param *weimobapi.QueryGoodsListParam) {
// for {
// skuList, _, err2 := getAPI("").QuerySkuInfos(param)
// if err = err2; err != nil {
// return nil, err
// }
// if len(skuList) > 0 {
// batchSkuNameList := make([]*partner.SkuNameInfo, len(skuList))
// for k, v := range skuList {
// batchSkuNameList[k] = vendorSku2Jx(v)
// }
// setSkuNameListPic(batchSkuNameList)
// skuNameList = append(skuNameList, batchSkuNameList...)
// }
// if len(skuList) < param.PageSize {
// break
// }
// param.PageNum++
// }
return goodsList, err
}
func IsChineseChar(str string) bool {
@@ -123,3 +326,49 @@ func IsChineseChar(str string) bool {
}
return false
}
func GetCellIntoMap(skuIDCol, skuPriceCol, orgSkuIDCol, orgSkuPriceCol int, skuMap map[string]float64, row []string, sheetName string, rowNum int) {
var (
skuID string
orgSkuID string
skuPrice float64
orgSkuPrice float64
)
for k, cell := range row {
if !IsChineseChar(cell) && cell != "" {
if k == skuIDCol && skuIDCol >= 0 {
skuID = cell
}
if k == skuPriceCol && skuPriceCol >= 0 {
skuPrice = Float64Round(utils.Str2Float64WithDefault(cell, 0))
}
if k == orgSkuIDCol && orgSkuIDCol >= 0 {
orgSkuID = "0" + cell
}
if k == orgSkuPriceCol && orgSkuPriceCol >= 0 {
orgSkuPrice = Float64Round(utils.Str2Float64WithDefault(cell, 0))
}
}
}
if skuMap[skuID] != 0 && skuMap[skuID] != skuPrice {
if skuPrice > skuMap[skuID] {
skuMap[skuID] = skuPrice
}
// fmt.Sprintf("读取excel表格出错有商品ID重复且价格不同,sheetName : [%v] ,行数 : [%v] , 商品编码 [%v] , 价格:[%v]\n", sheetName, rowNum, skuID, skuPrice)
} else {
skuMap[skuID] = skuPrice
}
if skuMap[orgSkuID] != 0 && skuMap[orgSkuID] != orgSkuPrice {
if orgSkuPrice > skuMap[orgSkuID] {
skuMap[orgSkuID] = orgSkuPrice
}
// fmt.Sprintf("读取excel表格出错有商品ID重复且价格不同,sheetName : [%v] ,行数 : [%v], 商品编码 [%v] , 价格:[%v]\n", sheetName, rowNum, orgSkuID, orgSkuPrice)
} else if orgSkuPriceCol >= 0 && orgSkuIDCol >= 0 {
skuMap[orgSkuID] = orgSkuPrice
}
delete(skuMap, "")
}
func Float64Round(f float64) (flt float64) {
return math.Round(f*100) / 100
}

View File

@@ -688,6 +688,10 @@ func OperationTimeStr4VendorStore(v *model.VendorStoreSnapshot) (str string) {
return str
}
func OperationTime2HourMinuteFormat(time time.Time) (i int16) {
return int16(time.Hour()*100 + time.Minute())
}
// 得到饿百订单的取货码
func GetEbaiOrderGetCode(order *model.GoodsOrder) (getCode string) {
if order.VendorID == model.VendorIDEBAI && len(order.VendorOrderID2) >= 4 {

View File

@@ -1,7 +1,9 @@
package dao
import (
"errors"
"fmt"
"strings"
"time"
"git.rosy.net.cn/baseapi/utils"
@@ -79,9 +81,11 @@ type StoreSkuSyncInfo struct {
StoreCatSyncStatus int8
VendorCatID string `orm:"column(vendor_cat_id)"`
VendorPrice int64
MergedStatus int
SkuName string
VendorPrice int64
MergedStatus int
SkuName string
StatusSaleBegin int16 `json:"statusSaleBegin"` //商品可售时间范围
StatusSaleEnd int16 `json:"statusSaleEnd"`
}
type MissingStoreSkuInfo struct {
@@ -216,7 +220,7 @@ func GetStoreSkus2(db *DaoDB, vendorID, storeID int, skuIDs []int, mustDirty boo
fieldPrefix := ConvertDBFieldPrefix(model.VendorNames[vendorID])
sql := `
SELECT t1.id bind_id, t1.sku_id, t1.price, t1.unit_price, t1.status store_sku_status, %s.%s_id vendor_sku_id,
t1.%s_sync_status store_sku_sync_status, t1.store_id, t1.deleted_at bind_deleted_at,
t1.%s_sync_status store_sku_sync_status, t1.store_id, t1.deleted_at bind_deleted_at,t1.status_sale_begin,t1.status_sale_end,
t2.*,
t3.id name_id, t3.prefix, t3.name, t3.unit, t3.upc,
IF(t11.%s <> '', t11.%s, t3.img) img,
@@ -584,3 +588,55 @@ func (s *StoreSkuSyncInfo) GetSeq() int {
}
return int(s.VendorPrice)
}
func GetStoresSkusInfoBySaleTime(db *DaoDB, storeID int) (storeSkuBindList []*model.StoreSkuBind, err error) {
sql := `
SELECT t1.*
FROM store_sku_bind t1
WHERE t1.status_sale_begin <> 0 AND t1.status_sale_end <> 0
AND t1.status = ?
AND t1.deleted_at = ?
`
sqlParams := []interface{}{
model.SkuStatusNormal,
utils.DefaultTimeValue,
}
if storeID > 0 {
sql += ` AND t1.store_id = ?`
sqlParams = append(sqlParams, storeID)
}
err = GetRows(db, &storeSkuBindList, sql, sqlParams...)
return storeSkuBindList, err
}
func UpdateStoreSkuBindSyncStatus(db *DaoDB, vendorIDs []int, storeID int) (num int64, err error) {
sql := `
UPDATE store_sku_bind
SET
`
fmtParams := []interface{}{}
sqlParams := []interface{}{}
if len(vendorIDs) > 0 {
for _, v := range vendorIDs {
fieldPrefix := ConvertDBFieldPrefix(model.VendorNames[v])
sql += ` %s_sync_status = ?,`
fmtParams = append(fmtParams, fieldPrefix)
sqlParams = append(sqlParams, model.SyncFlagSaleMask)
}
} else {
return 0, errors.New("取平台ID名有错误partner.GetPurchasePlatformVendorIDs()")
}
sql = sql[0:strings.LastIndex(sql, ",")]
sql = fmt.Sprintf(sql, fmtParams...)
sql += ` WHERE status = ?
AND deleted_at = ?
AND status_sale_begin <> 0
AND status_sale_end <> 0
`
sqlParams = append(sqlParams, model.StoreSkuBindStatusNormal, utils.DefaultTimeValue)
if storeID > 0 {
sql += ` AND store_id = ?`
sqlParams = append(sqlParams, storeID)
}
return ExecuteSQL(db, sql, sqlParams...)
}

View File

@@ -112,6 +112,9 @@ type StoreSkuBind struct {
// WscPrice int `json:"wscPrice"`
AutoSaleAt time.Time `orm:"type(datetime);null" json:"autoSaleAt"`
StatusSaleBegin int16 `json:"statusSaleBegin"` //商品可售时间范围
StatusSaleEnd int16 `json:"statusSaleEnd"`
}
func (*StoreSkuBind) TableUnique() [][]string {

View File

@@ -1,6 +1,8 @@
package controllers
import (
"io"
"git.rosy.net.cn/jx-callback/business/jxstore/yonghui"
"github.com/astaxie/beego"
)
@@ -12,16 +14,30 @@ type YongHuiController struct {
// @Title 读取永辉excel文件
// @Description 读取永辉excel文件
// @Param token header string true "认证token"
// @Param token header string false "认证token"
// @Param isAsync query bool false "是否异步,缺省是同步"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /LoadExcelByYongHui [post]
// @router /LoadExcelByYongHui [post,get]
func (c *YongHuiController) LoadExcelByYongHui() {
c.callLoadExcelByYongHui(func(params *tYonghuiLoadExcelByYongHuiParams) (retVal interface{}, errCode string, err error) {
r := c.Ctx.Request
files := r.MultipartForm.File["userfiles"]
retVal, err = yonghui.SendFilesToStores(params.Ctx, files)
return retVal, "", err
})
if c.Ctx.Input.IsGet() {
w := c.Ctx.ResponseWriter
// 上传页面
w.Header().Add("Content-Type", "text/html")
w.WriteHeader(200)
html := `
<form enctype="multipart/form-data" action="/v2/yonghui/LoadExcelByYongHui" method="POST">
Send this file: <input name="userfiles" multiple accept="*" type="file" />
<input type="submit" value="Send File" />
</form>
`
io.WriteString(w, html)
} else if c.Ctx.Input.IsPost() {
c.callLoadExcelByYongHui(func(params *tYonghuiLoadExcelByYongHuiParams) (retVal interface{}, errCode string, err error) {
r := c.Ctx.Request
files := r.MultipartForm.File["userfiles"]
retVal, err = yonghui.LoadExcelByYongHui(params.Ctx, files, params.IsAsync)
return retVal, "", err
})
}
}

View File

@@ -2002,7 +2002,7 @@ func init() {
beego.ControllerComments{
Method: "LoadExcelByYongHui",
Router: `/LoadExcelByYongHui`,
AllowHTTPMethods: []string{"post"},
AllowHTTPMethods: []string{"post","get"},
MethodParams: param.Make(),
Filters: nil,
Params: nil})