12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541 |
- package jobs
- //import (
- // "encoding/json"
- // "errors"
- // "fmt"
- // "gadmin/internal/cron/jobs/types"
- // "github.com/hashicorp/go-version"
- // "github.com/sirupsen/logrus"
- // "io"
- // "io/fs"
- // "io/ioutil"
- // "leafstalk/covenant/constants"
- // "leafstalk/covenant/model"
- // "net/http"
- // "os"
- // "path"
- // "path/filepath"
- // "strconv"
- // "strings"
- // "sync"
- // "time"
- //)
- //
- //var SyncGoodsJson = new(JSyncGoodsJson)
- //
- //type JSyncGoodsJson struct {
- // sync.Mutex
- // TMap map[string]int
- // bc *model.BaseConfig
- // center []*types.GiftCenterItem
- // outPath string
- //}
- //
- //// 需要下载的json文件列表
- //var downJsonFiles = []string{
- // "base_data.json",
- // "Giftcenter.json", //礼包分类
- // "shop.json",
- // "PropsStore.json",
- // "LimitGift.json",
- //
- // "DailyGift.json",
- // "RoleGift.json",
- // "NewerGift.json",
- // "Holiday9Gift.json",
- // "LanternFestivalGift.json",
- // "Holiday3_Gift.json",
- // "BuyOnceGetThreeDays.json",
- // "TombSweepingDayGift.json",
- // "LaborDayGift.json",
- // "DragonBoatFestivalGift.json",
- // "WeekendGift.json",
- // "QixiFestivalGift.json",
- // "MoonFestivalGift.json",
- // "EquipBoxGiftPack.json",
- // "EquipBoxBase.json",
- // "EndlessPassportBase.json",
- //}
- //
- //var passJsonFiles = map[string]struct{}{
- // "base_data.json": {},
- // "Giftcenter.json": {},
- // "shop.json": {},
- // "PropsStore.json": {},
- // "LimitGift.json": {},
- //}
- //
- //func NewSyncGoodsJson() *JSyncGoodsJson {
- // return &JSyncGoodsJson{
- // TMap: make(map[string]int),
- // bc: &model.BaseConfig{},
- // center: make([]*types.GiftCenterItem, 0),
- // outPath: "",
- // }
- //}
- //
- //func (j *JSyncGoodsJson) Run(jsonVersion string) {
- // logrus.Info("同步商品json文件...")
- // //本地存放json地址
- // outPath := fmt.Sprintf("%s/%s", os.Getenv("JSON_PATH"), "shop")
- // j.outPath = outPath
- //
- // //默认下载地址
- // downloadUrl := "https://gravecs.mg.xhgame.com/json/" + jsonVersion + "/server"
- // //获取下载地址
- // if os.Getenv("GIN_MODE") == "release" && os.Getenv("ADMIN_PLATFORM") == "wechat" {
- // downloadUrl = "https://srgtw.mg.xhgame.com/grave/json/wx/" + jsonVersion + "/server"
- // } else if os.Getenv("GIN_MODE") == "release" && os.Getenv("ADMIN_PLATFORM") == "dy" {
- // downloadUrl = "https://srgtw.mg.xhgame.com/grave/json/tt/" + jsonVersion + "/server"
- // } else if os.Getenv("GIN_MODE") == "release" && os.Getenv("ADMIN_PLATFORM") == "mt" {
- // downloadUrl = "https://srgtw.mg.xhgame.com/grave/json/mt/" + jsonVersion + "/server"
- // }
- // j.Lock()
- // defer func() {
- // j.Unlock()
- // if err := recover(); err != nil {
- // logrus.Errorf("同步商品json失败:%v", err)
- // }
- // }()
- // //下载json文件到指定文件夹
- // err := j.download(downloadUrl, outPath, downJsonFiles)
- // if err != nil {
- // logrus.Errorf("download err:%v", err)
- // return
- // }
- // logrus.Info("下载完成")
- // //获取giftCenter数据
- // err = j.giftCenter(fmt.Sprintf("%s/%s", outPath, "GiftCenter.json"))
- // if err != nil {
- // logrus.Errorf("giftCenter err:%v", err)
- // return
- // }
- // logrus.Info("giftCenter加载完成")
- //
- // //获取baseConf
- // err = j.baseConf(fmt.Sprintf("%s/%s", outPath, "base_data.json"))
- // if err != nil {
- // logrus.Errorf("baseConf err:%v", err)
- // return
- // }
- // logrus.Info("baseConf加载完成")
- // //遍历json文件
- // allData := make([]*model.SalesGoods, 0)
- // for _, file := range downJsonFiles {
- // if _, ok := passJsonFiles[file]; ok {
- // continue
- // }
- // filePath := fmt.Sprintf("%s/%s", outPath, file)
- // logrus.Infof("加载%s...", filePath)
- // //清洗数据
- // data, err := j.cleanData(filePath)
- // if err != nil {
- // logrus.Errorf("cleanData err:%v", err)
- // return
- // }
- // logrus.Infof("加载%s完成...", filePath)
- // allData = append(allData, data...)
- // }
- // //组装数据
- // err = j.ShopGoods(fmt.Sprintf("%s/%s", outPath, "shop.json"), fmt.Sprintf("%s/%s", outPath, "PropsStore.json"), fmt.Sprintf("%s/%s", outPath, "LimitGift.json"), allData)
- // if err != nil {
- // logrus.Errorf("ShopGoods err:%v", err)
- // return
- // }
- // logrus.Infof("Encoder success")
- //}
- //
- ///*
- //下载json文件
- //downloadPath: 下载地址
- //outPutPath: 输出地址
- //downJsonFiles: 下载的json文件列表
- //*/
- //func (j *JSyncGoodsJson) download(downloadPath, outPutPath string, downJsonFiles []string) error {
- // //检查文件夹是否存在
- // _, err := os.Stat(outPutPath)
- // if errors.Is(err, fs.ErrNotExist) {
- // //创建目标文件夹
- // err = os.MkdirAll(outPutPath, 0755)
- // if err != nil {
- // return err
- // }
- // }
- //
- // // 下载文件
- // for _, file := range downJsonFiles {
- // filePath := fmt.Sprintf("%s/%s", outPutPath, file)
- // logrus.Infof("下载文件:%s...", file)
- // err := j.downloadFile(filePath, downloadPath+"/"+file)
- // if err != nil {
- // logrus.Errorf("无法下载文件:%v", err)
- // } else {
- // logrus.Infof("下载文件:%s...", file)
- // }
- // }
- // return nil
- //}
- //
- //func (j *JSyncGoodsJson) downloadFile(outFilePath, url string) error {
- // logrus.Infof("outFile:%s; url:%s", outFilePath, url)
- // // 发送 GET 请求
- // resp, err := http.Get(url)
- // if err != nil {
- // return err
- // }
- // defer resp.Body.Close()
- //
- // // 创建文件
- // out, err := os.Create(outFilePath)
- // if err != nil {
- // return err
- // }
- // defer out.Close()
- //
- // // 将响应体内容写入文件
- // _, err = io.Copy(out, resp.Body)
- // if err != nil {
- // return err
- // }
- //
- // return nil
- //}
- //
- //func (j *JSyncGoodsJson) giftCenter(filePath string) error {
- // talentFile, err := os.Open(filePath)
- // if err != nil {
- // logrus.Errorln("读取日志文件失败", err)
- // }
- // defer talentFile.Close()
- // var gifts []*types.GiftCenterItem
- // decoder := json.NewDecoder(talentFile)
- // err = decoder.Decode(&gifts)
- // if err != nil {
- // return err
- // }
- // for _, v := range gifts {
- // tm, _ := time.ParseInLocation("2006-01-02 15:04:05", v.St, time.Local)
- // v.StartTime = tm.Unix()
- //
- // tm, _ = time.ParseInLocation("2006-01-02 15:04:05", v.Et, time.Local)
- // v.EndTime = tm.Unix()
- // //整理礼包类型
- // j.TMap[v.Title] = v.Type
- // }
- // j.center = gifts
- // return nil
- //}
- //func (j *JSyncGoodsJson) baseConf(baseJsonPath string) error {
- //
- // _, err := j.RowsToCols2(baseJsonPath, true)
- // if err != nil {
- // return err
- // }
- //
- // bc := new(model.BaseConfig)
- // _, err = j.loadJsonFile(fmt.Sprintf("%s", baseJsonPath), &bc)
- // if err != nil {
- // return err
- // }
- // j.bc = bc
- // return nil
- //}
- //func (j *JSyncGoodsJson) cleanData(filePath string) ([]*model.SalesGoods, error) {
- // ptrFile, err := os.Open(filePath)
- // if err != nil {
- // logrus.Errorf("读取日志文件%s失败:%v", filePath, err)
- // return nil, err
- // }
- // defer ptrFile.Close()
- // fileName := filepath.Base(filePath)
- // switch fileName {
- // case "DailyGift.json":
- // data, err := j.cleanDataGiftGoods(ptrFile)
- // if err != nil {
- // return nil, err
- // }
- // return data, nil
- // case "RoleGift.json":
- // data, err := j.cleanDataGiftGoods(ptrFile)
- // if err != nil {
- // return nil, err
- // }
- // for i, v := range data {
- // data[i].TotalTimes = v.AdDayTimes
- // data[i].AdDayTimes = 0
- // }
- // return data, nil
- // case "NewerGift.json":
- // data, err := j.cleanNewerGift(ptrFile)
- // if err != nil {
- // return nil, err
- // }
- // return data, nil
- // case "Holiday9Gift.json":
- // data, err := j.cleanNewYearGift(ptrFile)
- // if err != nil {
- // return nil, err
- // }
- // return data, nil
- // case "LanternFestivalGift.json":
- // data, err := j.YearFifteenGift(ptrFile)
- // if err != nil {
- // return nil, err
- // }
- // return data, nil
- // case "Holiday3_Gift.json":
- // data, err := j.Holiday38Gift(ptrFile)
- // if err != nil {
- // return nil, err
- // }
- // return data, nil
- // case "BuyOnceGetThreeDays.json":
- // data, err := j.SpecialGift(ptrFile)
- // if err != nil {
- // return nil, err
- // }
- // return data, nil
- // case "TombSweepingDayGift.json", "LaborDayGift.json", "DragonBoatFestivalGift.json":
- // data, err := j.TombSweepGift(ptrFile)
- // if err != nil {
- // return nil, err
- // }
- // return data, nil
- // case "WeekendGift.json":
- // data, err := j.WeekendGift(ptrFile)
- // if err != nil {
- // return nil, err
- // }
- // return data, nil
- // case "QixiFestivalGift.json":
- // data, err := j.QIXIGift(ptrFile)
- // if err != nil {
- // return nil, err
- // }
- // return data, nil
- // case "MoonFestivalGift.json":
- // data, err := j.MoonFestivalGift(ptrFile)
- // if err != nil {
- // return nil, err
- // }
- // return data, nil
- // case "EquipBoxGiftPack.json":
- // data, err := j.BoxKeyGift(ptrFile)
- // if err != nil {
- // return nil, err
- // }
- // return data, nil
- // case "EquipBoxBase.json":
- // data, err := j.EquipBoxBase(ptrFile)
- // if err != nil {
- // return nil, err
- // }
- // return data, nil
- // case "EndlessPassportBase.json":
- // data, err := j.EndlessPassGift(ptrFile)
- // if err != nil {
- // return nil, err
- // }
- // return data, nil
- // }
- // return nil, errors.New("未找到对应的json文件")
- //}
- //
- //func (j *JSyncGoodsJson) cleanDataGiftGoods(ptrFile *os.File) ([]*model.SalesGoods, error) {
- // var gifts []types.MidGiftItem
- //
- // fileName := strings.TrimSuffix(filepath.Base(ptrFile.Name()), filepath.Ext(ptrFile.Name()))
- // tNum := 0
- // if typeNum, ok := j.TMap[fileName]; ok {
- // tNum = typeNum
- // }
- //
- // decoder := json.NewDecoder(ptrFile)
- // err := decoder.Decode(&gifts)
- // if err != nil {
- // return nil, err
- // }
- // var allJson []*model.SalesGoods
- // for _, v := range gifts {
- // if v.Show == 0 {
- // continue
- // }
- //
- // if v.Type == 0 {
- // v.Type = tNum
- // }
- //
- // gd := &model.SalesGoods{}
- // gd.ID = v.ID
- // gd.AdDayTimes = v.Limit
- // gd.GoodsType = v.Type
- // gd.Name = v.Name
- // dm := model.DropMaterial{
- // ID: 0,
- // Count: v.Price,
- // }
- // gd.Cost = append(gd.Cost, dm)
- //
- // for _, v2 := range v.Materials {
- // dm = model.DropMaterial{}
- // dm.ID = v2[0]
- // dm.Count = int(v2[1])
- // gd.Materials = append(gd.Materials, dm)
- // }
- //
- // //时间
- // if len(v.StartTime) > 0 {
- // tm, err := time.ParseInLocation("2006-01-02 15:04:05", v.StartTime, time.Local)
- // if err != nil {
- // return nil, err
- // }
- // gd.StartTime = tm.Unix()
- // }
- // if len(v.EndTime) > 0 {
- // tm, err := time.ParseInLocation("2006-01-02 15:04:05", v.EndTime, time.Local)
- // if err != nil {
- // return nil, err
- // }
- // gd.EndTime = tm.Unix()
- // }
- // allJson = append(allJson, gd)
- // }
- // return allJson, nil
- //}
- //func (j *JSyncGoodsJson) cleanNewerGift(ptrFile *os.File) ([]*model.SalesGoods, error) {
- // var gifts []types.MidNewerItem
- // decoder := json.NewDecoder(ptrFile)
- // err := decoder.Decode(&gifts)
- // if err != nil {
- // return nil, err
- // }
- // fileName := strings.TrimSuffix(filepath.Base(ptrFile.Name()), filepath.Ext(ptrFile.Name()))
- // tNum := 0
- // if typeNum, ok := j.TMap[fileName]; ok {
- // tNum = typeNum
- // }
- //
- // var allJson []*model.SalesGoods
- // for _, v := range gifts {
- // gd := new(model.SalesGoods)
- // gd.ID = v.ID
- // gd.TotalTimes = v.Limit
- // gd.GoodsType = tNum
- // gd.OpenLevel = v.Level
- // gd.Name = v.Name
- // dm := model.DropMaterial{
- // ID: 0,
- // Count: v.Price,
- // }
- // gd.Cost = append(gd.Cost, dm)
- //
- // for _, v2 := range v.Materials {
- //
- // tp1 := v2[0]
- // if tp1 == 0 {
- // dm := new(model.DropMaterial)
- // dm.ID = v2[1]
- // dm.Count = int(v2[2])
- // gd.Materials = append(gd.Materials, *dm)
- // } else {
- // id := v2[1]
- // count := int(v2[2])
- //
- // for i := 0; i < count; i++ {
- // gd.Equipments = append(gd.Equipments, id)
- // }
- // }
- // }
- // allJson = append(allJson, gd)
- // }
- // return allJson, nil
- //}
- //func (j *JSyncGoodsJson) cleanNewYearGift(ptrFile *os.File) ([]*model.SalesGoods, error) {
- // var gifts []types.MidNewYearGiftItem
- // decoder := json.NewDecoder(ptrFile)
- // err := decoder.Decode(&gifts)
- // if err != nil {
- // return nil, err
- // }
- //
- // var allJson []*model.SalesGoods
- // for _, v := range gifts {
- // if v.Show == 0 {
- // continue
- // }
- //
- // gd := new(model.SalesGoods)
- // gd.ID = v.ID
- // gd.GoodsType = v.Type
- // gd.AdDayTimes = v.Limit
- // gd.AdCoolDown = v.AdCoolDown
- // gd.Name = v.Name
- // costId := int64(0)
- // switch v.PriceType {
- // case 0: // 免费 或者没有该字段
- // case 2, 3: // 广告
- // costId = int64(model.ADTicket)
- // case 6: // 钻石
- // costId = int64(constants.MaterilaId_Diamond)
- // case 7: // 现金
- // costId = 0
- // case 8: //金币
- // costId = constants.MaterilaId_Coin
- // }
- //
- // dm := model.DropMaterial{
- // ID: costId,
- // Count: v.Price,
- // }
- // gd.Cost = append(gd.Cost, dm)
- //
- // for _, v2 := range v.Materials {
- // dm := new(model.DropMaterial)
- // dm.ID = v2[0]
- // dm.Count = int(v2[1])
- // gd.Materials = append(gd.Materials, *dm)
- // }
- //
- // //时间
- // if len(v.StartTime) > 0 {
- // tm, err := time.ParseInLocation("2006-01-02 15:04:05", v.StartTime, time.Local)
- // if err != nil {
- // return nil, err
- // }
- // gd.StartTime = tm.Unix()
- // }
- // if len(v.EndTime) > 0 {
- // tm, err := time.ParseInLocation("2006-01-02 15:04:05", v.EndTime, time.Local)
- // if err != nil {
- // return nil, err
- // }
- // gd.EndTime = tm.Unix()
- // }
- //
- // allJson = append(allJson, gd)
- // }
- // return allJson, nil
- //}
- //func (j *JSyncGoodsJson) YearFifteenGift(ptrFile *os.File) ([]*model.SalesGoods, error) {
- // var gifts []types.MidNewYearGiftItem
- //
- // decoder := json.NewDecoder(ptrFile)
- // err := decoder.Decode(&gifts)
- // if err != nil {
- // return nil, err
- // }
- //
- // var allJson []*model.SalesGoods
- // for _, v := range gifts {
- // if v.Show == 0 {
- // continue
- // }
- //
- // gd := new(model.SalesGoods)
- // gd.ID = v.ID
- // gd.GoodsType = v.Type
- // gd.AdDayTimes = v.Limit
- // gd.AdCoolDown = v.AdCoolDown
- // gd.Name = v.Name
- // costId := int64(0)
- // switch v.PriceType {
- // case 0: // 免费 或者没有该字段
- // case 2, 3: // 广告
- // costId = int64(model.ADTicket)
- // case 6: // 钻石
- // costId = int64(constants.MaterilaId_Diamond)
- // case 7: // 现金
- // costId = 0
- // case 8: //金币
- // costId = constants.MaterilaId_Coin
- // }
- //
- // dm := model.DropMaterial{
- // ID: costId,
- // Count: v.Price,
- // }
- // gd.Cost = append(gd.Cost, dm)
- //
- // for _, v2 := range v.Materials {
- // dm := new(model.DropMaterial)
- // dm.ID = v2[0]
- // dm.Count = int(v2[1])
- // gd.Materials = append(gd.Materials, *dm)
- // }
- //
- // //时间
- // if len(v.StartTime) > 0 {
- // tm, err := time.ParseInLocation("2006-01-02 15:04:05", v.StartTime, time.Local)
- // if err != nil {
- // return nil, err
- // }
- // gd.StartTime = tm.Unix()
- // }
- // if len(v.EndTime) > 0 {
- // tm, err := time.ParseInLocation("2006-01-02 15:04:05", v.EndTime, time.Local)
- // if err != nil {
- // return nil, err
- // }
- // gd.EndTime = tm.Unix()
- // }
- //
- // allJson = append(allJson, gd)
- // }
- // return allJson, nil
- //}
- //func (j *JSyncGoodsJson) Holiday38Gift(ptrFile *os.File) ([]*model.SalesGoods, error) {
- // var gifts []types.MidHoliday38Gift
- //
- // decoder := json.NewDecoder(ptrFile)
- // err := decoder.Decode(&gifts)
- // if err != nil {
- // return nil, err
- // }
- //
- // var allJson []*model.SalesGoods
- // for _, v := range gifts {
- // if v.Show == 0 {
- // continue
- // }
- //
- // gd := new(model.SalesGoods)
- // gd.ID = v.ID
- // gd.AdDayTimes = v.Limit
- // gd.GoodsType = v.Type
- // gd.Name = v.Name
- // dm := model.DropMaterial{
- // ID: 0,
- // Count: v.Price,
- // }
- // gd.Cost = append(gd.Cost, dm)
- //
- // for _, v2 := range v.Materials {
- // dm := new(model.DropMaterial)
- // dm.ID = v2[0]
- // dm.Count = int(v2[1])
- // gd.Materials = append(gd.Materials, *dm)
- // }
- //
- // //时间
- // if len(v.StartTime) > 0 {
- // tm, err := time.ParseInLocation("2006-01-02 15:04:05", v.StartTime, time.Local)
- // if err != nil {
- // return nil, err
- // }
- // gd.StartTime = tm.Unix()
- // }
- // if len(v.EndTime) > 0 {
- // tm, err := time.ParseInLocation("2006-01-02 15:04:05", v.EndTime, time.Local)
- // if err != nil {
- // return nil, err
- // }
- // gd.EndTime = tm.Unix()
- // }
- //
- // allJson = append(allJson, gd)
- // }
- // return allJson, nil
- //}
- //func (j *JSyncGoodsJson) SpecialGift(ptrFile *os.File) ([]*model.SalesGoods, error) {
- // var gifts []types.SpecialGift
- // decoder := json.NewDecoder(ptrFile)
- // err := decoder.Decode(&gifts)
- // if err != nil {
- // return nil, err
- // }
- //
- // fileName := strings.TrimSuffix(filepath.Base(ptrFile.Name()), filepath.Ext(ptrFile.Name()))
- // tNum := 0
- // if typeNum, ok := j.TMap[fileName]; ok {
- // tNum = typeNum
- // }
- //
- // var allJson []*model.SalesGoods
- // for _, v := range gifts {
- // gd := new(model.SalesGoods)
- // gd.ID = v.ID
- // gd.TotalTimes = 1 // 只能购买一次
- // gd.GoodsType = tNum
- // gd.MaxLevel = v.MaxLevel
- // gd.Name = v.Name
- // dm := model.DropMaterial{
- // ID: 0,
- // Count: v.Price,
- // }
- // gd.Cost = append(gd.Cost, dm)
- //
- // for _, v2 := range v.Materials {
- // tp1 := 0 // 材料
- // if 10000000 < v2[0] {
- // tp1 = 1 // 装备
- // }
- // if tp1 == 0 {
- // dm := new(model.DropMaterial)
- // dm.ID = v2[0]
- // dm.Count = int(v2[1])
- // gd.Materials = append(gd.Materials, *dm)
- // } else {
- // id := v2[0]
- // count := int(v2[1])
- //
- // for i := 0; i < count; i++ {
- // gd.Equipments = append(gd.Equipments, id)
- // }
- // }
- // }
- // allJson = append(allJson, gd)
- // }
- // return allJson, nil
- //}
- //func (j *JSyncGoodsJson) TombSweepGift(ptrFile *os.File) ([]*model.SalesGoods, error) {
- // var gifts []types.MidNewYearGiftItem
- //
- // decoder := json.NewDecoder(ptrFile)
- // err := decoder.Decode(&gifts)
- // if err != nil {
- // return nil, err
- // }
- //
- // var allJson []*model.SalesGoods
- // for _, v := range gifts {
- // if v.Show == 0 {
- // continue
- // }
- //
- // gd := new(model.SalesGoods)
- // gd.ID = v.ID
- // gd.AdDayTimes = v.Limit
- // gd.GoodsType = v.Type
- // gd.AdCoolDown = v.AdCoolDown
- // gd.Name = v.Name
- // costType := int64(0)
- // switch v.PriceType {
- // case 0: // 免费 或者没有该字段
- // case 2, 3: // 广告
- // costType = int64(model.ADTicket)
- // case 6: // 钻石
- // costType = int64(constants.MaterilaId_Diamond)
- // case 7: // 现金
- // }
- //
- // dm := model.DropMaterial{
- // ID: costType,
- // Count: v.Price,
- // }
- // gd.Cost = append(gd.Cost, dm)
- //
- // for _, v2 := range v.Materials {
- // dm := new(model.DropMaterial)
- // dm.ID = v2[0]
- // dm.Count = int(v2[1])
- // gd.Materials = append(gd.Materials, *dm)
- // }
- //
- // //时间
- // if len(v.StartTime) > 0 {
- // tm, err := time.ParseInLocation("2006-01-02 15:04:05", v.StartTime, time.Local)
- // if err != nil {
- // return nil, err
- // }
- // gd.StartTime = tm.Unix()
- // }
- // if len(v.EndTime) > 0 {
- // tm, err := time.ParseInLocation("2006-01-02 15:04:05", v.EndTime, time.Local)
- // if err != nil {
- // return nil, err
- // }
- // gd.EndTime = tm.Unix()
- // }
- //
- // allJson = append(allJson, gd)
- // }
- // return allJson, nil
- //}
- //func (j *JSyncGoodsJson) WeekendGift(ptrFile *os.File) ([]*model.SalesGoods, error) {
- // var gifts []types.WeekendGift
- // decoder := json.NewDecoder(ptrFile)
- // err := decoder.Decode(&gifts)
- // if err != nil {
- // return nil, err
- // }
- //
- // var (
- // allJson []*model.SalesGoods
- // attrs = make(map[int64]*types.WeekendGiftAttr)
- // )
- // for _, v := range gifts {
- // if v.ShowOrNot == 0 {
- // continue
- // }
- //
- // gd := new(model.SalesGoods)
- // gd.ID = v.GiftId
- // gd.AdDayTimes = v.GiftLimit
- // gd.GoodsType = v.Type
- // gd.Name = v.Name
- // id := v.PriceType
- // if v.PriceType == 2 {
- // id = 0
- // }
- //
- // dm := model.DropMaterial{
- // ID: id,
- // Count: v.GiftPrice,
- // }
- // gd.Cost = append(gd.Cost, dm)
- //
- // for _, v2 := range v.GiftAward {
- // dm := new(model.DropMaterial)
- // dm.ID = int64(v2[0])
- // dm.Count = int(v2[1])
- // gd.Materials = append(gd.Materials, *dm)
- // }
- //
- // //时间
- // if len(v.GiftStartTime) > 0 {
- // tm, err := time.ParseInLocation("2006-01-02 15:04:05", v.GiftStartTime, time.Local)
- // if err != nil {
- // return nil, err
- // }
- // gd.StartTime = tm.Unix()
- // }
- // if len(v.GiftEndTime) > 0 {
- // tm, err := time.ParseInLocation("2006-01-02 15:04:05", v.GiftEndTime, time.Local)
- // if err != nil {
- // return nil, err
- // }
- // gd.EndTime = tm.Unix()
- // }
- //
- // allJson = append(allJson, gd)
- //
- // // 属性表
- // attrs[v.GiftId] = &types.WeekendGiftAttr{
- // ID: v.GiftId,
- // Name: v.Name,
- // Week: v.Week,
- // Weight: v.Weight,
- // LimitType: v.GiftLimitType[0],
- // LimitCount: v.GiftLimitType[1],
- // Cost: v.GiftPrice,
- // }
- // }
- //
- // //写文件
- // writeFile := fmt.Sprintf("%s/%s", j.outPath, "WeekendGiftAttr.json")
- // writePtr, err := os.Create(writeFile)
- // if err != nil {
- // return nil, err
- // }
- // defer writePtr.Close()
- // encoder := json.NewEncoder(writePtr)
- // if err = encoder.Encode(&attrs); err != nil {
- // return nil, err
- // }
- // return allJson, nil
- //}
- //func (j *JSyncGoodsJson) QIXIGift(ptrFile *os.File) ([]*model.SalesGoods, error) {
- // var gifts []types.MidNewYearGiftItem
- //
- // decoder := json.NewDecoder(ptrFile)
- // err := decoder.Decode(&gifts)
- // if err != nil {
- // return nil, err
- // }
- //
- // var allJson []*model.SalesGoods
- // for _, v := range gifts {
- // if v.Show == 0 {
- // continue
- // }
- //
- // gd := new(model.SalesGoods)
- // gd.ID = v.ID
- // gd.AdDayTimes = v.Limit
- // gd.GoodsType = v.Type
- // gd.Name = v.Name
- // dm := model.DropMaterial{
- // ID: 0,
- // Count: v.Price,
- // }
- // gd.Cost = append(gd.Cost, dm)
- //
- // for _, v2 := range v.Materials {
- // dm := new(model.DropMaterial)
- // dm.ID = v2[0]
- // dm.Count = int(v2[1])
- // gd.Materials = append(gd.Materials, *dm)
- // }
- //
- // //时间
- // if len(v.StartTime) > 0 {
- // tm, err := time.ParseInLocation("2006-01-02 15:04:05", v.StartTime, time.Local)
- // if err != nil {
- // return nil, err
- // }
- // gd.StartTime = tm.Unix()
- // }
- // if len(v.EndTime) > 0 {
- // tm, err := time.ParseInLocation("2006-01-02 15:04:05", v.EndTime, time.Local)
- // if err != nil {
- // return nil, err
- // }
- // gd.EndTime = tm.Unix()
- // }
- //
- // allJson = append(allJson, gd)
- // }
- // return allJson, nil
- //}
- //func (j *JSyncGoodsJson) MoonFestivalGift(ptrFile *os.File) ([]*model.SalesGoods, error) {
- // var gifts []types.MidNewYearGiftItem
- //
- // decoder := json.NewDecoder(ptrFile)
- // err := decoder.Decode(&gifts)
- // if err != nil {
- // return nil, err
- // }
- //
- // var allJson []*model.SalesGoods
- // for _, v := range gifts {
- // if v.Show == 0 {
- // continue
- // }
- //
- // gd := new(model.SalesGoods)
- // gd.ID = v.ID
- // gd.AdDayTimes = v.Limit
- // gd.GoodsType = v.Type
- // gd.Name = v.Name
- // dm := model.DropMaterial{
- // ID: 0,
- // Count: v.Price,
- // }
- // gd.Cost = append(gd.Cost, dm)
- //
- // for _, v2 := range v.Materials {
- // dm := new(model.DropMaterial)
- // dm.ID = v2[0]
- // dm.Count = int(v2[1])
- // gd.Materials = append(gd.Materials, *dm)
- // }
- //
- // //时间
- // if len(v.StartTime) > 0 {
- // tm, err := time.ParseInLocation("2006-01-02 15:04:05", v.StartTime, time.Local)
- // if err != nil {
- // return nil, err
- // }
- // gd.StartTime = tm.Unix()
- // }
- // if len(v.EndTime) > 0 {
- // tm, err := time.ParseInLocation("2006-01-02 15:04:05", v.EndTime, time.Local)
- // if err != nil {
- // return nil, err
- // }
- // gd.EndTime = tm.Unix()
- // }
- //
- // allJson = append(allJson, gd)
- // }
- // return allJson, nil
- //}
- //func (j *JSyncGoodsJson) BoxKeyGift(ptrFile *os.File) ([]*model.SalesGoods, error) {
- // var gifts []types.MidBoxKeyGiftItem
- //
- // decoder := json.NewDecoder(ptrFile)
- // err := decoder.Decode(&gifts)
- // if err != nil {
- // return nil, err
- // }
- //
- // var allJson []*model.SalesGoods
- // for _, v := range gifts {
- //
- // gd := new(model.SalesGoods)
- // gd.ID = v.ID
- // gd.AdDayTimes = v.Limit
- // gd.GoodsType = v.Type
- // gd.PlatGroup = v.PlatGroup
- // gd.Name = v.Name
- // id := int64(0)
- // switch v.GetType {
- // case 0: // 免费
- // case 2, 3: // 广告
- // id = int64(model.ADTicket)
- // case 6: // 钻石
- // id = int64(constants.MaterilaId_Diamond)
- // case 7: // 现金
- // }
- // gd.AdCoolDown = v.AdCoolDown
- // dm := model.DropMaterial{
- // ID: id,
- // Count: v.Price,
- // }
- // gd.Cost = append(gd.Cost, dm)
- //
- // for _, v2 := range v.Materials {
- // dm := new(model.DropMaterial)
- // dm.ID = v2[0]
- // dm.Count = int(v2[1])
- // gd.Materials = append(gd.Materials, *dm)
- // }
- //
- // allJson = append(allJson, gd)
- // }
- // return allJson, nil
- //}
- //func (j *JSyncGoodsJson) EquipBoxBase(ptrFile *os.File) ([]*model.SalesGoods, error) {
- // var items []types.MidEquipBoxBase
- //
- // decoder := json.NewDecoder(ptrFile)
- // err := decoder.Decode(&items)
- // if err != nil {
- // return nil, err
- // }
- //
- // var allJson []*model.SalesGoods
- // for _, v := range items {
- // gd := new(model.SalesGoods)
- // gd.ID = v.GoodsId
- // gd.GoodsType = v.BoxType
- // dm := model.DropMaterial{
- // ID: v.Cost,
- // Count: 1,
- // }
- // gd.Cost = append(gd.Cost, dm)
- // gd.Name = v.Name
- // allJson = append(allJson, gd)
- // }
- // return allJson, nil
- //}
- //func (j *JSyncGoodsJson) EndlessPassGift(ptrFile *os.File) ([]*model.SalesGoods, error) {
- // var gifts []types.MidEndlessPassGift
- //
- // decoder := json.NewDecoder(ptrFile)
- // err := decoder.Decode(&gifts)
- // if err != nil {
- // return nil, err
- // }
- //
- // var allJson []*model.SalesGoods
- // for _, v := range gifts {
- //
- // gd := new(model.SalesGoods)
- // gd.ID = v.ID
- // gd.AdDayTimes = 1
- // gd.GoodsType = v.GoodsType
- // gd.Name = v.Name
- // id := int64(0)
- // switch v.GetType {
- // case 0: // 免费
- // case 2, 3: // 广告
- // id = int64(model.ADTicket)
- // case 6: // 钻石
- // id = int64(constants.MaterilaId_Diamond)
- // case 7: // 现金
- // }
- //
- // dm := model.DropMaterial{
- // ID: id,
- // Count: v.Price,
- // }
- // gd.Cost = append(gd.Cost, dm)
- //
- // if v.AddPassportExp != 0 {
- // dm := new(model.DropMaterial)
- // //TODO model.EndLessExp 值
- // dm.ID = model.EndLessExp
- // dm.Count = v.AddPassportExp
- // gd.Materials = append(gd.Materials, *dm)
- // }
- //
- // if v.ReturnDiamond != 0 {
- // dm := new(model.DropMaterial)
- // dm.ID = constants.MaterilaId_Diamond
- // dm.Count = v.ReturnDiamond
- // gd.Materials = append(gd.Materials, *dm)
- // }
- //
- // allJson = append(allJson, gd)
- // }
- // return allJson, nil
- //}
- //func (j *JSyncGoodsJson) ShopGoods(shopJsonPath, propsStoreJsonPath, limitGiftPath string, allJson []*model.SalesGoods) error {
- // ptfFile, err := os.Open(shopJsonPath)
- // if err != nil {
- // logrus.Errorln("读取日志文件失败", err)
- // }
- // defer ptfFile.Close()
- // fileName := filepath.Base(shopJsonPath)
- //
- // var materials []types.MidSalesSalesGoods
- //
- // decoder := json.NewDecoder(ptfFile)
- // err = decoder.Decode(&materials)
- // if err != nil {
- // logrus.Errorf("%v Decoder failed %v", fileName, err.Error())
- // return err
- // }
- //
- // allBox := make(map[int64]*model.SalesGoods)
- // logrus.Infof("初始化allBox...")
- //
- // for _, v := range materials {
- // n := new(model.SalesGoods)
- // n.ID = v.ID
- // n.AdCoolDown = v.AdCoolDown
- // n.AdDayTimes = v.AdDayTimes
- // n.AdDayType = v.AdDayType
- // n.PlatGroup = v.PlatGroup
- // n.GoodsType = v.Type
- // n.Name = v.Name
- // if len(v.GiftNum) == 2 {
- // dm := model.DropMaterial{
- // ID: v.GiftNum[0],
- // Count: int(v.GiftNum[1]),
- // }
- // n.Gift = append(n.Gift, dm)
- // }
- //
- // // 当数组大于1时,表示有多种购买方式
- // priceCount := len(v.Price)
- // switch priceCount {
- // case 0:
- // case 1:
- // dm := model.DropMaterial{}
- // price := v.Price[0]
- // if price[0] > 0 {
- // dm.ID = price[0]
- // }
- // dm.Count = int(price[1])
- // n.Cost = append(n.Cost, dm)
- // case 2, 3:
- // dm := model.DropMaterial{}
- // price := v.Price[0]
- // if price[0] > 0 {
- // dm.ID = price[0]
- // }
- // dm.Count = int(price[1])
- // n.Cost = append(n.Cost, dm)
- //
- // contents := model.ExtractMaterials(v.Content)
- // n.Materials = append(n.Materials, *contents[0])
- //
- // // 第二、三种支付方式
- //
- // for k, p1 := range v.Price {
- // if k == 0 {
- // continue
- // }
- //
- // gs := new(model.SalesGoods2)
- //
- // dm2 := model.DropMaterial{}
- // dm2.ID = p1[0]
- // dm2.Count = int(p1[1])
- // gs.Cost = append(gs.Cost, dm2)
- //
- // gs.Materials = append(gs.Materials, *contents[k])
- //
- // n.OtherGoods = append(n.OtherGoods, gs)
- // }
- //
- // default:
- // logrus.Errorf("foud shop error priceCount != 1 2\n", n)
- // }
- //
- // if v.Double == 1 {
- // n.FirstDouble = 1
- // }
- //
- // var ms []*model.DropMaterial
- // var es []int64
- //
- // if len(v.Content[0]) == 2 {
- // ms = model.ExtractMaterials(v.Content)
- // } else {
- // ms, es = model.ExtractMerialEquips(v.Content)
- // }
- //
- // if priceCount < 2 {
- // for _, v := range ms {
- // n.Materials = append(n.Materials, *v)
- // }
- // n.Equipments = es
- // }
- //
- // allBox[n.ID] = n
- //
- // //监测配置数值
- // if n.ID <= 0 || n.GoodsType <= 0 ||
- // (len(n.Cost) == 0 && n.GoodsType != 7 && n.GoodsType != 14) ||
- // (len(n.Materials) == 0 && len(n.Equipments) == 0) {
- // logrus.Errorf("foud shop error1 %v\n", n)
- // }
- // for _, v := range n.Cost {
- // if v.ID > 100000 {
- // logrus.Errorf("foud shop error2 %v\n", v)
- // }
- // }
- // for _, v := range n.Gift {
- // if v.ID > 100000 {
- // logrus.Errorf("foud shop error3 %v\n", v)
- // }
- // }
- // }
- // logrus.Infof("初始化allBox完成")
- //
- // logrus.Infof("allBox加载otherGoods...")
- // otherGoods, err := ExtractPropStore(propsStoreJsonPath)
- // if err != nil {
- // logrus.Errorf("ExtractPropStore err: %v", err.Error())
- // return err
- // }
- // for k, v := range otherGoods {
- // allBox[k] = v
- // }
- // logrus.Infof("allBox加载otherGoods完成")
- //
- // logrus.Infof("allBox加载allJson...")
- // for _, v := range allJson {
- // allBox[v.ID] = v
- // }
- // logrus.Infof("allBox加载allJson完成")
- //
- // logrus.Infof("allBox加载limitGoods...")
- // // 导入需要RMB支付的限时礼包
- // limitGoods, err := ExtractLimitGiftGoods(limitGiftPath, int(j.bc.LimitgiftPerDayMaximum))
- // if err != nil {
- // logrus.Errorf("ExtractLimitGiftGoods err: %v", err.Error())
- // return err
- // }
- // for k, v := range limitGoods {
- // allBox[k] = v
- // }
- // logrus.Infof("allBox加载limitGoods完成")
- //
- // logrus.Infof("allBox转化购买等级限制...")
- // // 商品上限购买等级不限制时转化为一个非常大的数
- // for _, v := range allBox {
- // if v.MaxLevel == 0 {
- // v.MaxLevel = 1000000
- // }
- // }
- // logrus.Infof("allBox转化购买等级限制完成")
- //
- // //保存到指定文件夹内
- // lastDir, err := j.getLatestVersion()
- // if err != nil {
- // logrus.Errorf("getLatestVersion err: %v", err)
- // }
- // logrus.Infof("最新的文件夹:%s/%s", os.Getenv("JSON_PATH"), lastDir)
- // writeFile := fmt.Sprintf("%s/%s/%s", os.Getenv("JSON_PATH"), lastDir, "product.json")
- // writePtr, err := os.Create(writeFile)
- // if err != nil {
- // logrus.Errorln("写日志文件失败", err)
- // return err
- // }
- // defer writePtr.Close()
- // encoder := json.NewEncoder(writePtr)
- // err = encoder.Encode(&allBox)
- // if err != nil {
- // logrus.Errorln("Encoder failed", err.Error())
- // return err
- // }
- // return nil
- //}
- //
- //func (j *JSyncGoodsJson) getLatestVersion() (string, error) {
- // // 读取指定目录下的所有文件夹名称
- // folders, err := ioutil.ReadDir(os.Getenv("JSON_PATH"))
- // if err != nil {
- // logrus.Errorf("Failed to read directory:%v", err)
- // return "", err
- // }
- //
- // var latestVersion *version.Version
- //
- // // 遍历文件夹列表,比较版本号
- // for _, folder := range folders {
- // if folder.IsDir() {
- // versionStr := folder.Name()
- // logrus.Infof("folderName:%s", versionStr)
- // if strings.HasPrefix(versionStr, "v") {
- // v, err := version.NewVersion(versionStr[1:]) // 移除前缀 "v" 并创建版本对象
- // if err != nil {
- // fmt.Println("Failed to parse version:", err)
- // continue
- // }
- //
- // if latestVersion == nil || v.GreaterThan(latestVersion) {
- // latestVersion = v
- // }
- // }
- // }
- // }
- //
- // if latestVersion != nil {
- // return fmt.Sprintf("v%s", latestVersion.String()), nil
- // }
- // return "", errors.New("no version folders found")
- //}
- //
- //func (j *JSyncGoodsJson) RowsToCols2(filePath string, save bool) (map[string]interface{}, error) {
- // fileName := filepath.Base(filePath)
- //
- // ext := path.Ext(fileName)
- // // 去除后缀,获取文件名
- // name := fileName[:len(fileName)-len(ext)]
- // //writeFile := filepath.Base(filePath)
- // writeFilePath := fmt.Sprintf("%s/%s2.json", j.outPath, name)
- // _, err := os.Stat(writeFilePath)
- // if !errors.Is(err, fs.ErrNotExist) {
- // logrus.Infof("%s已存在", writeFilePath)
- // return nil, nil
- // }
- // // 读数据
- // talentFile, err := os.Open(filePath)
- // if err != nil {
- // logrus.Errorln("读取日志文件失败", err)
- // return nil, err
- // }
- // defer talentFile.Close()
- //
- // var items []*types.MidCol
- //
- // decoder := json.NewDecoder(talentFile)
- // err = decoder.Decode(&items)
- // if err != nil {
- // logrus.Errorf("%v Decoder failed, %v", fileName, err.Error())
- // return nil, err
- // }
- //
- // // KV
- // allObjects := make(map[string]interface{})
- // for _, v := range items {
- //
- // switch v.Type {
- // case "STRING":
- // allObjects[v.Key] = v.Value
- // case "INT":
- // allObjects[v.Key], _ = strconv.ParseInt(v.Value, 10, 64)
- // case "FLOAT":
- // allObjects[v.Key], _ = strconv.ParseFloat(v.Value, 64)
- // case "STRINGARR":
- // var val []string
- // if err = json.Unmarshal([]byte(v.Value), &val); err != nil {
- // logrus.Errorf("%v Unmarshal STRINGARR error:%+v", fileName, v.Value)
- // return nil, err
- // }
- // allObjects[v.Key] = val
- // case "INTARR", "ARR":
- // var val []int64
- // if err = json.Unmarshal([]byte(v.Value), &val); err != nil {
- // logrus.Errorf("%v Unmarshal STRINGARR error:%+v", fileName, v.Value)
- // return nil, err
- // }
- // allObjects[v.Key] = val
- // case "FLOATARR":
- // var val []float64
- // if err = json.Unmarshal([]byte(v.Value), &val); err != nil {
- // logrus.Errorf("%v Unmarshal STRINGARR error:%+v", fileName, v.Value)
- // return nil, err
- // }
- // allObjects[v.Key] = val
- // case "STRINGARRS":
- // var val [][]string
- // if err = json.Unmarshal([]byte(v.Value), &val); err != nil {
- // logrus.Errorf("%v Unmarshal STRINGARR error:%+v", fileName, v.Value)
- // return nil, err
- // }
- // allObjects[v.Key] = val
- // case "INTARRS", "ARRS":
- // var val [][]int64
- // if err = json.Unmarshal([]byte(v.Value), &val); err != nil {
- // logrus.Errorf("%v Unmarshal STRINGARR error:%+v", fileName, v.Value)
- // return nil, err
- // }
- // allObjects[v.Key] = val
- // case "FLOATARRS":
- // var val [][]float64
- // if err = json.Unmarshal([]byte(v.Value), &val); err != nil {
- // logrus.Errorf("%v Unmarshal STRINGARR error:%+v", fileName, v.Value)
- // return nil, err
- // }
- // allObjects[v.Key] = val
- // }
- // }
- //
- // if !save {
- // return allObjects, nil
- // }
- //
- // // 保存
- // logrus.Infof("RowsToCols2 base2:%s", writeFilePath)
- // writePtr, err := os.Create(writeFilePath)
- // if err != nil {
- // logrus.Errorf("%v RowsToCols2 CreateFile failed. %v", fileName, err)
- // return nil, err
- // }
- // defer writePtr.Close()
- // encoder2 := json.NewEncoder(writePtr)
- // err = encoder2.Encode(&allObjects)
- // if err != nil {
- // logrus.Errorf("%v RowsToCols2 save failed. %v", fileName, err.Error())
- // return nil, err
- // }
- // return allObjects, nil
- //}
- //func (j *JSyncGoodsJson) loadJsonFile(filePath string, items interface{}) (interface{}, error) {
- // fileName := filepath.Base(filePath)
- // ext := path.Ext(fileName)
- // // 去除后缀,获取文件名
- // name := fileName[:len(fileName)-len(ext)]
- // writeFilePath := fmt.Sprintf("%s/%s2.json", j.outPath, name)
- // logrus.Infof("loadJsonFile base2:%s", writeFilePath)
- //
- // roleFile, err := os.Open(writeFilePath)
- // if err != nil {
- // logrus.Errorln("读取日志文件失败", err)
- // }
- // defer roleFile.Close()
- //
- // //var roles []MidRoleAttr
- // decoder := json.NewDecoder(roleFile)
- // err = decoder.Decode(&items)
- // if err != nil {
- // logrus.Errorf("%v Decoder failed. %v", fileName, err.Error())
- // return nil, err
- // }
- // return items, nil
- //}
- //func ExtractPropStore(filePath string) (map[int64]*model.SalesGoods, error) {
- // ptfFile, err := os.Open(filePath)
- // if err != nil {
- // logrus.Errorln("读取日志文件失败", err)
- // }
- // defer ptfFile.Close()
- // fileName := filepath.Base(filePath)
- //
- // var materials []types.MidPropStoreGoods
- //
- // decoder := json.NewDecoder(ptfFile)
- // err = decoder.Decode(&materials)
- // if err != nil {
- // logrus.Errorf("%v Decoder failed", fileName, err.Error())
- // return nil, err
- // }
- //
- // allBox := make(map[int64]*model.SalesGoods)
- // for _, v := range materials {
- // n := new(model.SalesGoods)
- // n.ID = v.ID
- // n.GoodsType = v.Type
- //
- // if len(v.Price) == 2 {
- // dm := model.DropMaterial{}
- // if v.Price[0] > 0 {
- // dm.ID = v.Price[0]
- // }
- // dm.Count = int(v.Price[1])
- // n.Cost = append(n.Cost, dm)
- // }
- // n.Name = v.Name
- //
- // dm := model.DropMaterial{ID: v.Content[0], Count: int(v.Content[1])}
- // n.Materials = append(n.Materials, dm)
- //
- // allBox[n.ID] = n
- //
- // //监测配置数值
- // if n.ID <= 0 || n.GoodsType <= 0 ||
- // (len(n.Cost) == 0) ||
- // (len(n.Materials) == 0 && len(n.Equipments) == 0) {
- // logrus.Errorf("foud shop error5 %v\n", n)
- // }
- // }
- //
- // return allBox, nil
- //}
- //func ExtractLimitGiftGoods(filePath string, openLevel int) (map[int64]*model.SalesGoods, error) {
- // ptfFile, err := os.Open(filePath)
- // if err != nil {
- // logrus.Errorln("读取日志文件失败", err)
- // }
- // defer ptfFile.Close()
- // fileName := filepath.Base(filePath)
- //
- // var goods []types.LimitGiftGoods
- //
- // decoder := json.NewDecoder(ptfFile)
- // err = decoder.Decode(&goods)
- // if err != nil {
- // logrus.Errorf("%v Decoder failed", fileName, err.Error())
- // return nil, err
- // }
- //
- // allBox := make(map[int64]*model.SalesGoods)
- // for _, v := range goods {
- // n := new(model.SalesGoods)
- // n.ID = v.Id
- // n.GoodsType = v.Type
- // n.OpenLevel = openLevel
- // n.Name = v.Name
- // if len(v.Price) >= 2 {
- // var id int64 = 0 // 0金币,1钻石,2RMB
- // if v.Price[0] == 0 {
- // id = 1001
- // }
- // if v.Price[0] == 1 {
- // id = 1002
- // }
- // dm := model.DropMaterial{}
- // dm.ID = id
- // dm.Count = int(v.Price[1])
- // n.Cost = append(n.Cost, dm)
- // }
- //
- // var (
- // material []model.DropMaterial
- // equipment []int64
- // )
- //
- // for _, award := range v.Award {
- // if len(award) == 0 { // 没有奖励内容
- // continue
- // }
- //
- // if 10000000 < award[0] {
- // // 装备
- // for i := 0; i < int(award[1]); i++ {
- // equipment = append(equipment, award[0])
- // }
- // } else {
- // // 材料、金币、钻石
- // material = append(material, model.DropMaterial{
- // ID: award[0],
- // Count: int(award[1]),
- // })
- // }
- // }
- //
- // if len(material) == 0 && len(equipment) == 0 {
- // continue
- // }
- //
- // n.Materials = material
- // n.Equipments = equipment
- // allBox[n.ID] = n
- //
- // //监测配置数值
- // if n.ID <= 0 || n.GoodsType <= 0 ||
- // (len(n.Cost) == 0) ||
- // (len(n.Materials) == 0 && len(n.Equipments) == 0) {
- // logrus.Errorf("foud limitGiftGoods error5 %v\n", n)
- // }
- // }
- //
- // return allBox, nil
- //}
|