package cms // //import ( // "encoding/json" // "errors" // "fmt" // "git.rosy.net.cn/baseapi/utils" // "git.rosy.net.cn/jx-callback/business/jxutils/jxcontext" // "git.rosy.net.cn/jx-callback/business/jxutils/tasksch" // "git.rosy.net.cn/jx-callback/business/model" // "git.rosy.net.cn/jx-callback/business/model/dao" // "git.rosy.net.cn/jx-callback/business/partner/purchase/jx/localjx" // "github.com/360EntSecGroup-Skylar/excelize" // "io" // "mime/multipart" // "strings" //) // //// 根据excel新增待拣货订单 //func CreateOrderByExcel(ctx *jxcontext.Context, files []*multipart.FileHeader) (hint string, err error) { // if len(files) == 0 { // return "", errors.New("没有文件上传!") // } // fileHeader := files[0] // file, err := fileHeader.Open() // hint, err = RefreshJxPriceByExcelBin(ctx, file, true, true) // file.Close() // return hint, err //} // //type CreateOrderByExcelStore struct { // BuyerComment int // 备注 // StoreID int // 门店id // Skus int // 商品列表 // ExpectedDeliveredTimestamp int // 预期送达时间 // TotalPrice int // 总价格 // FreightPrice int // 运费 // OrderPrice int // 订单价格 // ActualPayPrice int // 顾客实际支付 // OrderID int // 订单id // StoreName int // 门店名称 // Weight int // 重量 // FromStoreID int // 物料ID // EarningType int // 结算方式(1为报价,2为扣点),0无 // OrderType int // 订单类型 // IsBuyNowPrice int // 守价的值只有0和1 // IsPriceDefend int // OrderID2 int // UserID int // 用户id // AddressID int // 收货地址id // CreateType int // "创建类型, 0:预创建, 1:创建" // IsDeliverySelf int // 自提 //} // //// 赋值excel表字段排序 //func SortExcelTable() *CreateOrderByExcelStore { // return &CreateOrderByExcelStore{ // StoreID: 1, // StoreName: 2, // UserID: 3, // AddressID: 4, // Skus: 5, // Weight: 6, // TotalPrice: 7, // FreightPrice: 8, // OrderPrice: 9, // ActualPayPrice: 10, // ExpectedDeliveredTimestamp: 11, // OrderType: 12, // FromStoreID: 13, // EarningType: 14, // BuyerComment: 15, // // CreateType: 16, // IsDeliverySelf: 17, // IsPriceDefend: 18, // IsBuyNowPrice: 19, // OrderID: 20, // OrderID2: 21, // } //} // //// 订单结构体 //type ExcelOrderStruct struct { // BuyerComment string `json:"buyerComment"` // 备注 // StoreID int `json:"storeID"` // Skus []*JxSkuInfo `json:"skus"` // ExpectedDeliveredTimestamp int64 `json:"expectedDeliveredTimestamp"` // 预期送达时间 // TotalPrice int64 `json:"totalPrice"` // 单位为分 订单总价 // FreightPrice int64 `json:"freightPrice"` // 单位为分 订单配送费 // OrderPrice int64 `json:"orderPrice"` // 单位为分 订单商品价格 // ActualPayPrice int64 `json:"actualPayPrice"` // 单位为分 顾客实际支付 // OrderID int64 `json:"orderID"` // StoreName string `json:"storeName"` // Weight int `json:"weight"` // FromStoreID int `json:"fromStoreID"` // // EarningType int `json:"earningType"` // OrderType int `json:"orderType"` // IsBuyNowPrice int `json:"isBuyNowPrice"` // IsPriceDefend int `json:"isPriceDefend"` // OrderID2 string `json:"-"` // 订单id2 // UserID string `json:"userID"` // 用户id // AddressId int64 `json:"address_id"` // 地址id //} // //// 商品列表 //type JxSkuInfo struct { // SkuID int `json:"skuID"` // Count int `json:"count"` // Price int64 `json:"price,omitempty"` // 原价 // SalePrice int64 `json:"salePrice,omitempty"` // 售卖价 // Name string `json:"name"` // Weight int `json:"weight"` // GroupSign bool `json:"groupSign"` // DefendPrice int64 `json:"defendPrice"` //守价 //} // //// 解析excel到订单结构体当中 //func GetCellIntoOrder(rowNum int, row []string, sheetParam *CreateOrderByExcelStore, order *ExcelOrderStruct, nameMap map[string]string) (errMsg string) { // address := make(map[string]int64, 0) // for k, cell := range row { // switch k { // case sheetParam.StoreID: // order.StoreID = utils.Str2Int(cell) // case sheetParam.StoreName: // order.StoreName = cell // case sheetParam.UserID: // order.UserID = cell // case sheetParam.AddressID: // order.AddressId = utils.Str2Int64(cell) // case sheetParam.Skus: // shop := make([]*JxSkuInfo, 0, 0) // if err := json.Unmarshal([]byte(cell), shop); err != nil { // return fmt.Sprintf("解析excel文档用户商品列表错,检查数据格式是否正确") // } // order.Skus = shop // case sheetParam.Weight: // order.Weight = utils.Str2Int(cell) // case sheetParam.TotalPrice: // order.TotalPrice = utils.Str2Int64(cell) // case sheetParam.FreightPrice: // order.FreightPrice = utils.Str2Int64(cell) // case sheetParam.OrderPrice: // order.OrderPrice = utils.Str2Int64(cell) // case sheetParam.ActualPayPrice: // order.ActualPayPrice = utils.Str2Int64(cell) // case : // // // // } // // if k == sheetParam.SkuNameIDCol { // cellReplace := strings.ReplaceAll(cell, ",", ",") // if cellReplace != "" { // if cellReplace[len(cellReplace)-1:len(cellReplace)] == "," { // cellReplace = cellReplace[0 : len(cellReplace)-1] // } // nameIDs := strings.Split(cellReplace, ",") // for _, v := range nameIDs { // if nameMap[v] != "" { // return fmt.Sprintf(" Excel中含有重复的nameID![%v]列,[%v]行,nameID [%v]\n", k+1, rowNum+1, v) // } else { // nameMap[v] = v // } // } // } // storeSkuNamePrice.NameIDGroup = cellReplace // } // if k == sheetParam.SkuPriceCol { // if IsChineseChar(cell) { // return fmt.Sprintf("Excel格式排版发生了变化!在[%v]列,[%v]行附近可能增加或减少了一列", k+1, rowNum+1) // } // storeSkuNamePrice.Price = int(utils.Float64TwoInt64(utils.Str2Float64(cell) * 100)) // } // if k == sheetParam.SkuUnitCol { // storeSkuNamePrice.Unit = cell // } // } // return errMsg //} // //func AnalysisExcelOrder(ctx *jxcontext.Context, reader io.Reader, isAsync, isContinueWhenError bool) { // excelSort := SortExcelTable() // taskSeqFunc := func(task *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) { // switch step { // case 0: // xlsx, err := excelize.OpenReader(reader) // if err != nil { // return "", err // } // rows, _ := xlsx.GetRows(xlsx.GetSheetName(1)) // for rowNum, row := range rows { // if rowNum < model.YES { // 第一行跳过 // continue // } // storeSkuNamePrice := &localjx.JxOrderInfo{} // errMsg += GetCellIntoStruct(rowNum, row, excelSort, storeSkuNamePrice, nameMap) // storeSkuNamePriceList = append(storeSkuNamePriceList, storeSkuNamePrice) // } // if errMsg != "" { // return "", errors.New(errMsg) // } else { // isErr = true // } // case 1: // db := dao.GetDB() // storeSkuNamePriceListOrg, _ := dao.GetStoreSkuNamePrice(db) // CreateOrUpdateStoreSkuNamePriceByExcel(db, ctx, storeSkuNamePriceList, storeSkuNamePriceListOrg) // storeSkuNamePriceListNew, _ := dao.GetStoreSkuNamePrice(db) // storeSkuNamePriceMapNew := StoreSkuNamePriceList2Map(ctx, storeSkuNamePriceListNew) // for _, v := range storeSkuNamePriceList { // if storeSkuNamePriceMapNew[v.OutSkuID] != nil { // storeSkuNamePriceListUpdate = append(storeSkuNamePriceListUpdate, storeSkuNamePriceMapNew[v.OutSkuID]) // } // } // taskFunc := func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) { // storeSkuNamePrice := batchItemList[0].(*model.StoreSkuNamePrice) // var skuBindInfos []*StoreSkuBindInfo // nameIDGroup := strings.Split(storeSkuNamePrice.NameIDGroup, ",") // for _, v := range nameIDGroup { // if v != "" { // nameID := int(utils.Str2Int64(v)) // for _, vv := range storeIDs { // skuList, err2 := dao.GetStoreSkusByNameIDs(db, []int{vv}, nameID) // err = err2 // if len(skuList) > 0 { // unitPrice := 0 // if skuList[0].Unit == model.UnitNames[0] { // if storeSkuNamePrice.Unit == "KG" { // unitPrice = storeSkuNamePrice.Price / 2 // } else { // unitPrice = storeSkuNamePrice.Price // } // } else { // unitPrice = storeSkuNamePrice.Price // } // storeSkuBindInfo := &StoreSkuBindInfo{ // NameID: nameID, // UnitPrice: unitPrice, // } // skuBindInfos = append(skuBindInfos, storeSkuBindInfo) // outSuccess := DataSuccess{ // NameID: nameID, // Name: skuList[0].Name, // Unit: storeSkuNamePrice.Unit, // OrgPrice: utils.Str2Float64(utils.Int64ToStr(skuList[0].UnitPrice)) / 100, // NowPrice: utils.Str2Float64(utils.Int64ToStr(int64(unitPrice))) / 100, // MixPrice: utils.Str2Float64(utils.Int64ToStr(int64(unitPrice)-skuList[0].UnitPrice)) / 100, // } // dataLock.AppendDataSuccess(outSuccess) // } else { // //京西xx门店没有关注该商品 // outFailed := DataFailed{ // NameID: nameID, // Name: storeSkuNamePrice.Name, // Comment: fmt.Sprintf("京西[%v]门店没有关注该商品,商品nameID[%v],Excel上商品名[%v]", vv, nameID, storeSkuNamePrice.Name), // } // dataLock.AppendDataFailed(outFailed) // } // } // } else { // //nameID为空,还未填写nameID // outFailed := DataFailed{ // NameID: 0, // Name: storeSkuNamePrice.Name, // Comment: fmt.Sprintf("商品nameID为空!,还未填写商品nameID,Excel上商品名[%v]", storeSkuNamePrice.Name), // } // dataLock.AppendDataFailed(outFailed) // } // } // retVal = skuBindInfos // return retVal, err // } // taskParallel := tasksch.NewParallelTask("刷新京西价", tasksch.NewParallelConfig().SetIsContinueWhenError(isContinueWhenError), ctx, taskFunc, storeSkuNamePriceListUpdate) // tasksch.HandleTask(taskParallel, task, true).Run() // skuBindInfosInter, err = taskParallel.GetResult(0) // case 2: // //更新京西价 // for _, v := range skuBindInfosInter { // skuBindInfoList = append(skuBindInfoList, v.(*StoreSkuBindInfo)) // } // if isErr { // UpdateStoresSkus(ctx, 0, storeIDs, skuBindInfoList, false, false, isAsync, isContinueWhenError) // } // case 3: // //写Excel // WriteToExcelJx(task, dataLock.dataSuccessList, dataLock.dataFailedList) // } // return result, err // } //}