sync_goods_json.go 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541
  1. package jobs
  2. //import (
  3. // "encoding/json"
  4. // "errors"
  5. // "fmt"
  6. // "gadmin/internal/cron/jobs/types"
  7. // "github.com/hashicorp/go-version"
  8. // "github.com/sirupsen/logrus"
  9. // "io"
  10. // "io/fs"
  11. // "io/ioutil"
  12. // "leafstalk/covenant/constants"
  13. // "leafstalk/covenant/model"
  14. // "net/http"
  15. // "os"
  16. // "path"
  17. // "path/filepath"
  18. // "strconv"
  19. // "strings"
  20. // "sync"
  21. // "time"
  22. //)
  23. //
  24. //var SyncGoodsJson = new(JSyncGoodsJson)
  25. //
  26. //type JSyncGoodsJson struct {
  27. // sync.Mutex
  28. // TMap map[string]int
  29. // bc *model.BaseConfig
  30. // center []*types.GiftCenterItem
  31. // outPath string
  32. //}
  33. //
  34. //// 需要下载的json文件列表
  35. //var downJsonFiles = []string{
  36. // "base_data.json",
  37. // "Giftcenter.json", //礼包分类
  38. // "shop.json",
  39. // "PropsStore.json",
  40. // "LimitGift.json",
  41. //
  42. // "DailyGift.json",
  43. // "RoleGift.json",
  44. // "NewerGift.json",
  45. // "Holiday9Gift.json",
  46. // "LanternFestivalGift.json",
  47. // "Holiday3_Gift.json",
  48. // "BuyOnceGetThreeDays.json",
  49. // "TombSweepingDayGift.json",
  50. // "LaborDayGift.json",
  51. // "DragonBoatFestivalGift.json",
  52. // "WeekendGift.json",
  53. // "QixiFestivalGift.json",
  54. // "MoonFestivalGift.json",
  55. // "EquipBoxGiftPack.json",
  56. // "EquipBoxBase.json",
  57. // "EndlessPassportBase.json",
  58. //}
  59. //
  60. //var passJsonFiles = map[string]struct{}{
  61. // "base_data.json": {},
  62. // "Giftcenter.json": {},
  63. // "shop.json": {},
  64. // "PropsStore.json": {},
  65. // "LimitGift.json": {},
  66. //}
  67. //
  68. //func NewSyncGoodsJson() *JSyncGoodsJson {
  69. // return &JSyncGoodsJson{
  70. // TMap: make(map[string]int),
  71. // bc: &model.BaseConfig{},
  72. // center: make([]*types.GiftCenterItem, 0),
  73. // outPath: "",
  74. // }
  75. //}
  76. //
  77. //func (j *JSyncGoodsJson) Run(jsonVersion string) {
  78. // logrus.Info("同步商品json文件...")
  79. // //本地存放json地址
  80. // outPath := fmt.Sprintf("%s/%s", os.Getenv("JSON_PATH"), "shop")
  81. // j.outPath = outPath
  82. //
  83. // //默认下载地址
  84. // downloadUrl := "https://gravecs.mg.xhgame.com/json/" + jsonVersion + "/server"
  85. // //获取下载地址
  86. // if os.Getenv("GIN_MODE") == "release" && os.Getenv("ADMIN_PLATFORM") == "wechat" {
  87. // downloadUrl = "https://srgtw.mg.xhgame.com/grave/json/wx/" + jsonVersion + "/server"
  88. // } else if os.Getenv("GIN_MODE") == "release" && os.Getenv("ADMIN_PLATFORM") == "dy" {
  89. // downloadUrl = "https://srgtw.mg.xhgame.com/grave/json/tt/" + jsonVersion + "/server"
  90. // } else if os.Getenv("GIN_MODE") == "release" && os.Getenv("ADMIN_PLATFORM") == "mt" {
  91. // downloadUrl = "https://srgtw.mg.xhgame.com/grave/json/mt/" + jsonVersion + "/server"
  92. // }
  93. // j.Lock()
  94. // defer func() {
  95. // j.Unlock()
  96. // if err := recover(); err != nil {
  97. // logrus.Errorf("同步商品json失败:%v", err)
  98. // }
  99. // }()
  100. // //下载json文件到指定文件夹
  101. // err := j.download(downloadUrl, outPath, downJsonFiles)
  102. // if err != nil {
  103. // logrus.Errorf("download err:%v", err)
  104. // return
  105. // }
  106. // logrus.Info("下载完成")
  107. // //获取giftCenter数据
  108. // err = j.giftCenter(fmt.Sprintf("%s/%s", outPath, "GiftCenter.json"))
  109. // if err != nil {
  110. // logrus.Errorf("giftCenter err:%v", err)
  111. // return
  112. // }
  113. // logrus.Info("giftCenter加载完成")
  114. //
  115. // //获取baseConf
  116. // err = j.baseConf(fmt.Sprintf("%s/%s", outPath, "base_data.json"))
  117. // if err != nil {
  118. // logrus.Errorf("baseConf err:%v", err)
  119. // return
  120. // }
  121. // logrus.Info("baseConf加载完成")
  122. // //遍历json文件
  123. // allData := make([]*model.SalesGoods, 0)
  124. // for _, file := range downJsonFiles {
  125. // if _, ok := passJsonFiles[file]; ok {
  126. // continue
  127. // }
  128. // filePath := fmt.Sprintf("%s/%s", outPath, file)
  129. // logrus.Infof("加载%s...", filePath)
  130. // //清洗数据
  131. // data, err := j.cleanData(filePath)
  132. // if err != nil {
  133. // logrus.Errorf("cleanData err:%v", err)
  134. // return
  135. // }
  136. // logrus.Infof("加载%s完成...", filePath)
  137. // allData = append(allData, data...)
  138. // }
  139. // //组装数据
  140. // 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)
  141. // if err != nil {
  142. // logrus.Errorf("ShopGoods err:%v", err)
  143. // return
  144. // }
  145. // logrus.Infof("Encoder success")
  146. //}
  147. //
  148. ///*
  149. //下载json文件
  150. //downloadPath: 下载地址
  151. //outPutPath: 输出地址
  152. //downJsonFiles: 下载的json文件列表
  153. //*/
  154. //func (j *JSyncGoodsJson) download(downloadPath, outPutPath string, downJsonFiles []string) error {
  155. // //检查文件夹是否存在
  156. // _, err := os.Stat(outPutPath)
  157. // if errors.Is(err, fs.ErrNotExist) {
  158. // //创建目标文件夹
  159. // err = os.MkdirAll(outPutPath, 0755)
  160. // if err != nil {
  161. // return err
  162. // }
  163. // }
  164. //
  165. // // 下载文件
  166. // for _, file := range downJsonFiles {
  167. // filePath := fmt.Sprintf("%s/%s", outPutPath, file)
  168. // logrus.Infof("下载文件:%s...", file)
  169. // err := j.downloadFile(filePath, downloadPath+"/"+file)
  170. // if err != nil {
  171. // logrus.Errorf("无法下载文件:%v", err)
  172. // } else {
  173. // logrus.Infof("下载文件:%s...", file)
  174. // }
  175. // }
  176. // return nil
  177. //}
  178. //
  179. //func (j *JSyncGoodsJson) downloadFile(outFilePath, url string) error {
  180. // logrus.Infof("outFile:%s; url:%s", outFilePath, url)
  181. // // 发送 GET 请求
  182. // resp, err := http.Get(url)
  183. // if err != nil {
  184. // return err
  185. // }
  186. // defer resp.Body.Close()
  187. //
  188. // // 创建文件
  189. // out, err := os.Create(outFilePath)
  190. // if err != nil {
  191. // return err
  192. // }
  193. // defer out.Close()
  194. //
  195. // // 将响应体内容写入文件
  196. // _, err = io.Copy(out, resp.Body)
  197. // if err != nil {
  198. // return err
  199. // }
  200. //
  201. // return nil
  202. //}
  203. //
  204. //func (j *JSyncGoodsJson) giftCenter(filePath string) error {
  205. // talentFile, err := os.Open(filePath)
  206. // if err != nil {
  207. // logrus.Errorln("读取日志文件失败", err)
  208. // }
  209. // defer talentFile.Close()
  210. // var gifts []*types.GiftCenterItem
  211. // decoder := json.NewDecoder(talentFile)
  212. // err = decoder.Decode(&gifts)
  213. // if err != nil {
  214. // return err
  215. // }
  216. // for _, v := range gifts {
  217. // tm, _ := time.ParseInLocation("2006-01-02 15:04:05", v.St, time.Local)
  218. // v.StartTime = tm.Unix()
  219. //
  220. // tm, _ = time.ParseInLocation("2006-01-02 15:04:05", v.Et, time.Local)
  221. // v.EndTime = tm.Unix()
  222. // //整理礼包类型
  223. // j.TMap[v.Title] = v.Type
  224. // }
  225. // j.center = gifts
  226. // return nil
  227. //}
  228. //func (j *JSyncGoodsJson) baseConf(baseJsonPath string) error {
  229. //
  230. // _, err := j.RowsToCols2(baseJsonPath, true)
  231. // if err != nil {
  232. // return err
  233. // }
  234. //
  235. // bc := new(model.BaseConfig)
  236. // _, err = j.loadJsonFile(fmt.Sprintf("%s", baseJsonPath), &bc)
  237. // if err != nil {
  238. // return err
  239. // }
  240. // j.bc = bc
  241. // return nil
  242. //}
  243. //func (j *JSyncGoodsJson) cleanData(filePath string) ([]*model.SalesGoods, error) {
  244. // ptrFile, err := os.Open(filePath)
  245. // if err != nil {
  246. // logrus.Errorf("读取日志文件%s失败:%v", filePath, err)
  247. // return nil, err
  248. // }
  249. // defer ptrFile.Close()
  250. // fileName := filepath.Base(filePath)
  251. // switch fileName {
  252. // case "DailyGift.json":
  253. // data, err := j.cleanDataGiftGoods(ptrFile)
  254. // if err != nil {
  255. // return nil, err
  256. // }
  257. // return data, nil
  258. // case "RoleGift.json":
  259. // data, err := j.cleanDataGiftGoods(ptrFile)
  260. // if err != nil {
  261. // return nil, err
  262. // }
  263. // for i, v := range data {
  264. // data[i].TotalTimes = v.AdDayTimes
  265. // data[i].AdDayTimes = 0
  266. // }
  267. // return data, nil
  268. // case "NewerGift.json":
  269. // data, err := j.cleanNewerGift(ptrFile)
  270. // if err != nil {
  271. // return nil, err
  272. // }
  273. // return data, nil
  274. // case "Holiday9Gift.json":
  275. // data, err := j.cleanNewYearGift(ptrFile)
  276. // if err != nil {
  277. // return nil, err
  278. // }
  279. // return data, nil
  280. // case "LanternFestivalGift.json":
  281. // data, err := j.YearFifteenGift(ptrFile)
  282. // if err != nil {
  283. // return nil, err
  284. // }
  285. // return data, nil
  286. // case "Holiday3_Gift.json":
  287. // data, err := j.Holiday38Gift(ptrFile)
  288. // if err != nil {
  289. // return nil, err
  290. // }
  291. // return data, nil
  292. // case "BuyOnceGetThreeDays.json":
  293. // data, err := j.SpecialGift(ptrFile)
  294. // if err != nil {
  295. // return nil, err
  296. // }
  297. // return data, nil
  298. // case "TombSweepingDayGift.json", "LaborDayGift.json", "DragonBoatFestivalGift.json":
  299. // data, err := j.TombSweepGift(ptrFile)
  300. // if err != nil {
  301. // return nil, err
  302. // }
  303. // return data, nil
  304. // case "WeekendGift.json":
  305. // data, err := j.WeekendGift(ptrFile)
  306. // if err != nil {
  307. // return nil, err
  308. // }
  309. // return data, nil
  310. // case "QixiFestivalGift.json":
  311. // data, err := j.QIXIGift(ptrFile)
  312. // if err != nil {
  313. // return nil, err
  314. // }
  315. // return data, nil
  316. // case "MoonFestivalGift.json":
  317. // data, err := j.MoonFestivalGift(ptrFile)
  318. // if err != nil {
  319. // return nil, err
  320. // }
  321. // return data, nil
  322. // case "EquipBoxGiftPack.json":
  323. // data, err := j.BoxKeyGift(ptrFile)
  324. // if err != nil {
  325. // return nil, err
  326. // }
  327. // return data, nil
  328. // case "EquipBoxBase.json":
  329. // data, err := j.EquipBoxBase(ptrFile)
  330. // if err != nil {
  331. // return nil, err
  332. // }
  333. // return data, nil
  334. // case "EndlessPassportBase.json":
  335. // data, err := j.EndlessPassGift(ptrFile)
  336. // if err != nil {
  337. // return nil, err
  338. // }
  339. // return data, nil
  340. // }
  341. // return nil, errors.New("未找到对应的json文件")
  342. //}
  343. //
  344. //func (j *JSyncGoodsJson) cleanDataGiftGoods(ptrFile *os.File) ([]*model.SalesGoods, error) {
  345. // var gifts []types.MidGiftItem
  346. //
  347. // fileName := strings.TrimSuffix(filepath.Base(ptrFile.Name()), filepath.Ext(ptrFile.Name()))
  348. // tNum := 0
  349. // if typeNum, ok := j.TMap[fileName]; ok {
  350. // tNum = typeNum
  351. // }
  352. //
  353. // decoder := json.NewDecoder(ptrFile)
  354. // err := decoder.Decode(&gifts)
  355. // if err != nil {
  356. // return nil, err
  357. // }
  358. // var allJson []*model.SalesGoods
  359. // for _, v := range gifts {
  360. // if v.Show == 0 {
  361. // continue
  362. // }
  363. //
  364. // if v.Type == 0 {
  365. // v.Type = tNum
  366. // }
  367. //
  368. // gd := &model.SalesGoods{}
  369. // gd.ID = v.ID
  370. // gd.AdDayTimes = v.Limit
  371. // gd.GoodsType = v.Type
  372. // gd.Name = v.Name
  373. // dm := model.DropMaterial{
  374. // ID: 0,
  375. // Count: v.Price,
  376. // }
  377. // gd.Cost = append(gd.Cost, dm)
  378. //
  379. // for _, v2 := range v.Materials {
  380. // dm = model.DropMaterial{}
  381. // dm.ID = v2[0]
  382. // dm.Count = int(v2[1])
  383. // gd.Materials = append(gd.Materials, dm)
  384. // }
  385. //
  386. // //时间
  387. // if len(v.StartTime) > 0 {
  388. // tm, err := time.ParseInLocation("2006-01-02 15:04:05", v.StartTime, time.Local)
  389. // if err != nil {
  390. // return nil, err
  391. // }
  392. // gd.StartTime = tm.Unix()
  393. // }
  394. // if len(v.EndTime) > 0 {
  395. // tm, err := time.ParseInLocation("2006-01-02 15:04:05", v.EndTime, time.Local)
  396. // if err != nil {
  397. // return nil, err
  398. // }
  399. // gd.EndTime = tm.Unix()
  400. // }
  401. // allJson = append(allJson, gd)
  402. // }
  403. // return allJson, nil
  404. //}
  405. //func (j *JSyncGoodsJson) cleanNewerGift(ptrFile *os.File) ([]*model.SalesGoods, error) {
  406. // var gifts []types.MidNewerItem
  407. // decoder := json.NewDecoder(ptrFile)
  408. // err := decoder.Decode(&gifts)
  409. // if err != nil {
  410. // return nil, err
  411. // }
  412. // fileName := strings.TrimSuffix(filepath.Base(ptrFile.Name()), filepath.Ext(ptrFile.Name()))
  413. // tNum := 0
  414. // if typeNum, ok := j.TMap[fileName]; ok {
  415. // tNum = typeNum
  416. // }
  417. //
  418. // var allJson []*model.SalesGoods
  419. // for _, v := range gifts {
  420. // gd := new(model.SalesGoods)
  421. // gd.ID = v.ID
  422. // gd.TotalTimes = v.Limit
  423. // gd.GoodsType = tNum
  424. // gd.OpenLevel = v.Level
  425. // gd.Name = v.Name
  426. // dm := model.DropMaterial{
  427. // ID: 0,
  428. // Count: v.Price,
  429. // }
  430. // gd.Cost = append(gd.Cost, dm)
  431. //
  432. // for _, v2 := range v.Materials {
  433. //
  434. // tp1 := v2[0]
  435. // if tp1 == 0 {
  436. // dm := new(model.DropMaterial)
  437. // dm.ID = v2[1]
  438. // dm.Count = int(v2[2])
  439. // gd.Materials = append(gd.Materials, *dm)
  440. // } else {
  441. // id := v2[1]
  442. // count := int(v2[2])
  443. //
  444. // for i := 0; i < count; i++ {
  445. // gd.Equipments = append(gd.Equipments, id)
  446. // }
  447. // }
  448. // }
  449. // allJson = append(allJson, gd)
  450. // }
  451. // return allJson, nil
  452. //}
  453. //func (j *JSyncGoodsJson) cleanNewYearGift(ptrFile *os.File) ([]*model.SalesGoods, error) {
  454. // var gifts []types.MidNewYearGiftItem
  455. // decoder := json.NewDecoder(ptrFile)
  456. // err := decoder.Decode(&gifts)
  457. // if err != nil {
  458. // return nil, err
  459. // }
  460. //
  461. // var allJson []*model.SalesGoods
  462. // for _, v := range gifts {
  463. // if v.Show == 0 {
  464. // continue
  465. // }
  466. //
  467. // gd := new(model.SalesGoods)
  468. // gd.ID = v.ID
  469. // gd.GoodsType = v.Type
  470. // gd.AdDayTimes = v.Limit
  471. // gd.AdCoolDown = v.AdCoolDown
  472. // gd.Name = v.Name
  473. // costId := int64(0)
  474. // switch v.PriceType {
  475. // case 0: // 免费 或者没有该字段
  476. // case 2, 3: // 广告
  477. // costId = int64(model.ADTicket)
  478. // case 6: // 钻石
  479. // costId = int64(constants.MaterilaId_Diamond)
  480. // case 7: // 现金
  481. // costId = 0
  482. // case 8: //金币
  483. // costId = constants.MaterilaId_Coin
  484. // }
  485. //
  486. // dm := model.DropMaterial{
  487. // ID: costId,
  488. // Count: v.Price,
  489. // }
  490. // gd.Cost = append(gd.Cost, dm)
  491. //
  492. // for _, v2 := range v.Materials {
  493. // dm := new(model.DropMaterial)
  494. // dm.ID = v2[0]
  495. // dm.Count = int(v2[1])
  496. // gd.Materials = append(gd.Materials, *dm)
  497. // }
  498. //
  499. // //时间
  500. // if len(v.StartTime) > 0 {
  501. // tm, err := time.ParseInLocation("2006-01-02 15:04:05", v.StartTime, time.Local)
  502. // if err != nil {
  503. // return nil, err
  504. // }
  505. // gd.StartTime = tm.Unix()
  506. // }
  507. // if len(v.EndTime) > 0 {
  508. // tm, err := time.ParseInLocation("2006-01-02 15:04:05", v.EndTime, time.Local)
  509. // if err != nil {
  510. // return nil, err
  511. // }
  512. // gd.EndTime = tm.Unix()
  513. // }
  514. //
  515. // allJson = append(allJson, gd)
  516. // }
  517. // return allJson, nil
  518. //}
  519. //func (j *JSyncGoodsJson) YearFifteenGift(ptrFile *os.File) ([]*model.SalesGoods, error) {
  520. // var gifts []types.MidNewYearGiftItem
  521. //
  522. // decoder := json.NewDecoder(ptrFile)
  523. // err := decoder.Decode(&gifts)
  524. // if err != nil {
  525. // return nil, err
  526. // }
  527. //
  528. // var allJson []*model.SalesGoods
  529. // for _, v := range gifts {
  530. // if v.Show == 0 {
  531. // continue
  532. // }
  533. //
  534. // gd := new(model.SalesGoods)
  535. // gd.ID = v.ID
  536. // gd.GoodsType = v.Type
  537. // gd.AdDayTimes = v.Limit
  538. // gd.AdCoolDown = v.AdCoolDown
  539. // gd.Name = v.Name
  540. // costId := int64(0)
  541. // switch v.PriceType {
  542. // case 0: // 免费 或者没有该字段
  543. // case 2, 3: // 广告
  544. // costId = int64(model.ADTicket)
  545. // case 6: // 钻石
  546. // costId = int64(constants.MaterilaId_Diamond)
  547. // case 7: // 现金
  548. // costId = 0
  549. // case 8: //金币
  550. // costId = constants.MaterilaId_Coin
  551. // }
  552. //
  553. // dm := model.DropMaterial{
  554. // ID: costId,
  555. // Count: v.Price,
  556. // }
  557. // gd.Cost = append(gd.Cost, dm)
  558. //
  559. // for _, v2 := range v.Materials {
  560. // dm := new(model.DropMaterial)
  561. // dm.ID = v2[0]
  562. // dm.Count = int(v2[1])
  563. // gd.Materials = append(gd.Materials, *dm)
  564. // }
  565. //
  566. // //时间
  567. // if len(v.StartTime) > 0 {
  568. // tm, err := time.ParseInLocation("2006-01-02 15:04:05", v.StartTime, time.Local)
  569. // if err != nil {
  570. // return nil, err
  571. // }
  572. // gd.StartTime = tm.Unix()
  573. // }
  574. // if len(v.EndTime) > 0 {
  575. // tm, err := time.ParseInLocation("2006-01-02 15:04:05", v.EndTime, time.Local)
  576. // if err != nil {
  577. // return nil, err
  578. // }
  579. // gd.EndTime = tm.Unix()
  580. // }
  581. //
  582. // allJson = append(allJson, gd)
  583. // }
  584. // return allJson, nil
  585. //}
  586. //func (j *JSyncGoodsJson) Holiday38Gift(ptrFile *os.File) ([]*model.SalesGoods, error) {
  587. // var gifts []types.MidHoliday38Gift
  588. //
  589. // decoder := json.NewDecoder(ptrFile)
  590. // err := decoder.Decode(&gifts)
  591. // if err != nil {
  592. // return nil, err
  593. // }
  594. //
  595. // var allJson []*model.SalesGoods
  596. // for _, v := range gifts {
  597. // if v.Show == 0 {
  598. // continue
  599. // }
  600. //
  601. // gd := new(model.SalesGoods)
  602. // gd.ID = v.ID
  603. // gd.AdDayTimes = v.Limit
  604. // gd.GoodsType = v.Type
  605. // gd.Name = v.Name
  606. // dm := model.DropMaterial{
  607. // ID: 0,
  608. // Count: v.Price,
  609. // }
  610. // gd.Cost = append(gd.Cost, dm)
  611. //
  612. // for _, v2 := range v.Materials {
  613. // dm := new(model.DropMaterial)
  614. // dm.ID = v2[0]
  615. // dm.Count = int(v2[1])
  616. // gd.Materials = append(gd.Materials, *dm)
  617. // }
  618. //
  619. // //时间
  620. // if len(v.StartTime) > 0 {
  621. // tm, err := time.ParseInLocation("2006-01-02 15:04:05", v.StartTime, time.Local)
  622. // if err != nil {
  623. // return nil, err
  624. // }
  625. // gd.StartTime = tm.Unix()
  626. // }
  627. // if len(v.EndTime) > 0 {
  628. // tm, err := time.ParseInLocation("2006-01-02 15:04:05", v.EndTime, time.Local)
  629. // if err != nil {
  630. // return nil, err
  631. // }
  632. // gd.EndTime = tm.Unix()
  633. // }
  634. //
  635. // allJson = append(allJson, gd)
  636. // }
  637. // return allJson, nil
  638. //}
  639. //func (j *JSyncGoodsJson) SpecialGift(ptrFile *os.File) ([]*model.SalesGoods, error) {
  640. // var gifts []types.SpecialGift
  641. // decoder := json.NewDecoder(ptrFile)
  642. // err := decoder.Decode(&gifts)
  643. // if err != nil {
  644. // return nil, err
  645. // }
  646. //
  647. // fileName := strings.TrimSuffix(filepath.Base(ptrFile.Name()), filepath.Ext(ptrFile.Name()))
  648. // tNum := 0
  649. // if typeNum, ok := j.TMap[fileName]; ok {
  650. // tNum = typeNum
  651. // }
  652. //
  653. // var allJson []*model.SalesGoods
  654. // for _, v := range gifts {
  655. // gd := new(model.SalesGoods)
  656. // gd.ID = v.ID
  657. // gd.TotalTimes = 1 // 只能购买一次
  658. // gd.GoodsType = tNum
  659. // gd.MaxLevel = v.MaxLevel
  660. // gd.Name = v.Name
  661. // dm := model.DropMaterial{
  662. // ID: 0,
  663. // Count: v.Price,
  664. // }
  665. // gd.Cost = append(gd.Cost, dm)
  666. //
  667. // for _, v2 := range v.Materials {
  668. // tp1 := 0 // 材料
  669. // if 10000000 < v2[0] {
  670. // tp1 = 1 // 装备
  671. // }
  672. // if tp1 == 0 {
  673. // dm := new(model.DropMaterial)
  674. // dm.ID = v2[0]
  675. // dm.Count = int(v2[1])
  676. // gd.Materials = append(gd.Materials, *dm)
  677. // } else {
  678. // id := v2[0]
  679. // count := int(v2[1])
  680. //
  681. // for i := 0; i < count; i++ {
  682. // gd.Equipments = append(gd.Equipments, id)
  683. // }
  684. // }
  685. // }
  686. // allJson = append(allJson, gd)
  687. // }
  688. // return allJson, nil
  689. //}
  690. //func (j *JSyncGoodsJson) TombSweepGift(ptrFile *os.File) ([]*model.SalesGoods, error) {
  691. // var gifts []types.MidNewYearGiftItem
  692. //
  693. // decoder := json.NewDecoder(ptrFile)
  694. // err := decoder.Decode(&gifts)
  695. // if err != nil {
  696. // return nil, err
  697. // }
  698. //
  699. // var allJson []*model.SalesGoods
  700. // for _, v := range gifts {
  701. // if v.Show == 0 {
  702. // continue
  703. // }
  704. //
  705. // gd := new(model.SalesGoods)
  706. // gd.ID = v.ID
  707. // gd.AdDayTimes = v.Limit
  708. // gd.GoodsType = v.Type
  709. // gd.AdCoolDown = v.AdCoolDown
  710. // gd.Name = v.Name
  711. // costType := int64(0)
  712. // switch v.PriceType {
  713. // case 0: // 免费 或者没有该字段
  714. // case 2, 3: // 广告
  715. // costType = int64(model.ADTicket)
  716. // case 6: // 钻石
  717. // costType = int64(constants.MaterilaId_Diamond)
  718. // case 7: // 现金
  719. // }
  720. //
  721. // dm := model.DropMaterial{
  722. // ID: costType,
  723. // Count: v.Price,
  724. // }
  725. // gd.Cost = append(gd.Cost, dm)
  726. //
  727. // for _, v2 := range v.Materials {
  728. // dm := new(model.DropMaterial)
  729. // dm.ID = v2[0]
  730. // dm.Count = int(v2[1])
  731. // gd.Materials = append(gd.Materials, *dm)
  732. // }
  733. //
  734. // //时间
  735. // if len(v.StartTime) > 0 {
  736. // tm, err := time.ParseInLocation("2006-01-02 15:04:05", v.StartTime, time.Local)
  737. // if err != nil {
  738. // return nil, err
  739. // }
  740. // gd.StartTime = tm.Unix()
  741. // }
  742. // if len(v.EndTime) > 0 {
  743. // tm, err := time.ParseInLocation("2006-01-02 15:04:05", v.EndTime, time.Local)
  744. // if err != nil {
  745. // return nil, err
  746. // }
  747. // gd.EndTime = tm.Unix()
  748. // }
  749. //
  750. // allJson = append(allJson, gd)
  751. // }
  752. // return allJson, nil
  753. //}
  754. //func (j *JSyncGoodsJson) WeekendGift(ptrFile *os.File) ([]*model.SalesGoods, error) {
  755. // var gifts []types.WeekendGift
  756. // decoder := json.NewDecoder(ptrFile)
  757. // err := decoder.Decode(&gifts)
  758. // if err != nil {
  759. // return nil, err
  760. // }
  761. //
  762. // var (
  763. // allJson []*model.SalesGoods
  764. // attrs = make(map[int64]*types.WeekendGiftAttr)
  765. // )
  766. // for _, v := range gifts {
  767. // if v.ShowOrNot == 0 {
  768. // continue
  769. // }
  770. //
  771. // gd := new(model.SalesGoods)
  772. // gd.ID = v.GiftId
  773. // gd.AdDayTimes = v.GiftLimit
  774. // gd.GoodsType = v.Type
  775. // gd.Name = v.Name
  776. // id := v.PriceType
  777. // if v.PriceType == 2 {
  778. // id = 0
  779. // }
  780. //
  781. // dm := model.DropMaterial{
  782. // ID: id,
  783. // Count: v.GiftPrice,
  784. // }
  785. // gd.Cost = append(gd.Cost, dm)
  786. //
  787. // for _, v2 := range v.GiftAward {
  788. // dm := new(model.DropMaterial)
  789. // dm.ID = int64(v2[0])
  790. // dm.Count = int(v2[1])
  791. // gd.Materials = append(gd.Materials, *dm)
  792. // }
  793. //
  794. // //时间
  795. // if len(v.GiftStartTime) > 0 {
  796. // tm, err := time.ParseInLocation("2006-01-02 15:04:05", v.GiftStartTime, time.Local)
  797. // if err != nil {
  798. // return nil, err
  799. // }
  800. // gd.StartTime = tm.Unix()
  801. // }
  802. // if len(v.GiftEndTime) > 0 {
  803. // tm, err := time.ParseInLocation("2006-01-02 15:04:05", v.GiftEndTime, time.Local)
  804. // if err != nil {
  805. // return nil, err
  806. // }
  807. // gd.EndTime = tm.Unix()
  808. // }
  809. //
  810. // allJson = append(allJson, gd)
  811. //
  812. // // 属性表
  813. // attrs[v.GiftId] = &types.WeekendGiftAttr{
  814. // ID: v.GiftId,
  815. // Name: v.Name,
  816. // Week: v.Week,
  817. // Weight: v.Weight,
  818. // LimitType: v.GiftLimitType[0],
  819. // LimitCount: v.GiftLimitType[1],
  820. // Cost: v.GiftPrice,
  821. // }
  822. // }
  823. //
  824. // //写文件
  825. // writeFile := fmt.Sprintf("%s/%s", j.outPath, "WeekendGiftAttr.json")
  826. // writePtr, err := os.Create(writeFile)
  827. // if err != nil {
  828. // return nil, err
  829. // }
  830. // defer writePtr.Close()
  831. // encoder := json.NewEncoder(writePtr)
  832. // if err = encoder.Encode(&attrs); err != nil {
  833. // return nil, err
  834. // }
  835. // return allJson, nil
  836. //}
  837. //func (j *JSyncGoodsJson) QIXIGift(ptrFile *os.File) ([]*model.SalesGoods, error) {
  838. // var gifts []types.MidNewYearGiftItem
  839. //
  840. // decoder := json.NewDecoder(ptrFile)
  841. // err := decoder.Decode(&gifts)
  842. // if err != nil {
  843. // return nil, err
  844. // }
  845. //
  846. // var allJson []*model.SalesGoods
  847. // for _, v := range gifts {
  848. // if v.Show == 0 {
  849. // continue
  850. // }
  851. //
  852. // gd := new(model.SalesGoods)
  853. // gd.ID = v.ID
  854. // gd.AdDayTimes = v.Limit
  855. // gd.GoodsType = v.Type
  856. // gd.Name = v.Name
  857. // dm := model.DropMaterial{
  858. // ID: 0,
  859. // Count: v.Price,
  860. // }
  861. // gd.Cost = append(gd.Cost, dm)
  862. //
  863. // for _, v2 := range v.Materials {
  864. // dm := new(model.DropMaterial)
  865. // dm.ID = v2[0]
  866. // dm.Count = int(v2[1])
  867. // gd.Materials = append(gd.Materials, *dm)
  868. // }
  869. //
  870. // //时间
  871. // if len(v.StartTime) > 0 {
  872. // tm, err := time.ParseInLocation("2006-01-02 15:04:05", v.StartTime, time.Local)
  873. // if err != nil {
  874. // return nil, err
  875. // }
  876. // gd.StartTime = tm.Unix()
  877. // }
  878. // if len(v.EndTime) > 0 {
  879. // tm, err := time.ParseInLocation("2006-01-02 15:04:05", v.EndTime, time.Local)
  880. // if err != nil {
  881. // return nil, err
  882. // }
  883. // gd.EndTime = tm.Unix()
  884. // }
  885. //
  886. // allJson = append(allJson, gd)
  887. // }
  888. // return allJson, nil
  889. //}
  890. //func (j *JSyncGoodsJson) MoonFestivalGift(ptrFile *os.File) ([]*model.SalesGoods, error) {
  891. // var gifts []types.MidNewYearGiftItem
  892. //
  893. // decoder := json.NewDecoder(ptrFile)
  894. // err := decoder.Decode(&gifts)
  895. // if err != nil {
  896. // return nil, err
  897. // }
  898. //
  899. // var allJson []*model.SalesGoods
  900. // for _, v := range gifts {
  901. // if v.Show == 0 {
  902. // continue
  903. // }
  904. //
  905. // gd := new(model.SalesGoods)
  906. // gd.ID = v.ID
  907. // gd.AdDayTimes = v.Limit
  908. // gd.GoodsType = v.Type
  909. // gd.Name = v.Name
  910. // dm := model.DropMaterial{
  911. // ID: 0,
  912. // Count: v.Price,
  913. // }
  914. // gd.Cost = append(gd.Cost, dm)
  915. //
  916. // for _, v2 := range v.Materials {
  917. // dm := new(model.DropMaterial)
  918. // dm.ID = v2[0]
  919. // dm.Count = int(v2[1])
  920. // gd.Materials = append(gd.Materials, *dm)
  921. // }
  922. //
  923. // //时间
  924. // if len(v.StartTime) > 0 {
  925. // tm, err := time.ParseInLocation("2006-01-02 15:04:05", v.StartTime, time.Local)
  926. // if err != nil {
  927. // return nil, err
  928. // }
  929. // gd.StartTime = tm.Unix()
  930. // }
  931. // if len(v.EndTime) > 0 {
  932. // tm, err := time.ParseInLocation("2006-01-02 15:04:05", v.EndTime, time.Local)
  933. // if err != nil {
  934. // return nil, err
  935. // }
  936. // gd.EndTime = tm.Unix()
  937. // }
  938. //
  939. // allJson = append(allJson, gd)
  940. // }
  941. // return allJson, nil
  942. //}
  943. //func (j *JSyncGoodsJson) BoxKeyGift(ptrFile *os.File) ([]*model.SalesGoods, error) {
  944. // var gifts []types.MidBoxKeyGiftItem
  945. //
  946. // decoder := json.NewDecoder(ptrFile)
  947. // err := decoder.Decode(&gifts)
  948. // if err != nil {
  949. // return nil, err
  950. // }
  951. //
  952. // var allJson []*model.SalesGoods
  953. // for _, v := range gifts {
  954. //
  955. // gd := new(model.SalesGoods)
  956. // gd.ID = v.ID
  957. // gd.AdDayTimes = v.Limit
  958. // gd.GoodsType = v.Type
  959. // gd.PlatGroup = v.PlatGroup
  960. // gd.Name = v.Name
  961. // id := int64(0)
  962. // switch v.GetType {
  963. // case 0: // 免费
  964. // case 2, 3: // 广告
  965. // id = int64(model.ADTicket)
  966. // case 6: // 钻石
  967. // id = int64(constants.MaterilaId_Diamond)
  968. // case 7: // 现金
  969. // }
  970. // gd.AdCoolDown = v.AdCoolDown
  971. // dm := model.DropMaterial{
  972. // ID: id,
  973. // Count: v.Price,
  974. // }
  975. // gd.Cost = append(gd.Cost, dm)
  976. //
  977. // for _, v2 := range v.Materials {
  978. // dm := new(model.DropMaterial)
  979. // dm.ID = v2[0]
  980. // dm.Count = int(v2[1])
  981. // gd.Materials = append(gd.Materials, *dm)
  982. // }
  983. //
  984. // allJson = append(allJson, gd)
  985. // }
  986. // return allJson, nil
  987. //}
  988. //func (j *JSyncGoodsJson) EquipBoxBase(ptrFile *os.File) ([]*model.SalesGoods, error) {
  989. // var items []types.MidEquipBoxBase
  990. //
  991. // decoder := json.NewDecoder(ptrFile)
  992. // err := decoder.Decode(&items)
  993. // if err != nil {
  994. // return nil, err
  995. // }
  996. //
  997. // var allJson []*model.SalesGoods
  998. // for _, v := range items {
  999. // gd := new(model.SalesGoods)
  1000. // gd.ID = v.GoodsId
  1001. // gd.GoodsType = v.BoxType
  1002. // dm := model.DropMaterial{
  1003. // ID: v.Cost,
  1004. // Count: 1,
  1005. // }
  1006. // gd.Cost = append(gd.Cost, dm)
  1007. // gd.Name = v.Name
  1008. // allJson = append(allJson, gd)
  1009. // }
  1010. // return allJson, nil
  1011. //}
  1012. //func (j *JSyncGoodsJson) EndlessPassGift(ptrFile *os.File) ([]*model.SalesGoods, error) {
  1013. // var gifts []types.MidEndlessPassGift
  1014. //
  1015. // decoder := json.NewDecoder(ptrFile)
  1016. // err := decoder.Decode(&gifts)
  1017. // if err != nil {
  1018. // return nil, err
  1019. // }
  1020. //
  1021. // var allJson []*model.SalesGoods
  1022. // for _, v := range gifts {
  1023. //
  1024. // gd := new(model.SalesGoods)
  1025. // gd.ID = v.ID
  1026. // gd.AdDayTimes = 1
  1027. // gd.GoodsType = v.GoodsType
  1028. // gd.Name = v.Name
  1029. // id := int64(0)
  1030. // switch v.GetType {
  1031. // case 0: // 免费
  1032. // case 2, 3: // 广告
  1033. // id = int64(model.ADTicket)
  1034. // case 6: // 钻石
  1035. // id = int64(constants.MaterilaId_Diamond)
  1036. // case 7: // 现金
  1037. // }
  1038. //
  1039. // dm := model.DropMaterial{
  1040. // ID: id,
  1041. // Count: v.Price,
  1042. // }
  1043. // gd.Cost = append(gd.Cost, dm)
  1044. //
  1045. // if v.AddPassportExp != 0 {
  1046. // dm := new(model.DropMaterial)
  1047. // //TODO model.EndLessExp 值
  1048. // dm.ID = model.EndLessExp
  1049. // dm.Count = v.AddPassportExp
  1050. // gd.Materials = append(gd.Materials, *dm)
  1051. // }
  1052. //
  1053. // if v.ReturnDiamond != 0 {
  1054. // dm := new(model.DropMaterial)
  1055. // dm.ID = constants.MaterilaId_Diamond
  1056. // dm.Count = v.ReturnDiamond
  1057. // gd.Materials = append(gd.Materials, *dm)
  1058. // }
  1059. //
  1060. // allJson = append(allJson, gd)
  1061. // }
  1062. // return allJson, nil
  1063. //}
  1064. //func (j *JSyncGoodsJson) ShopGoods(shopJsonPath, propsStoreJsonPath, limitGiftPath string, allJson []*model.SalesGoods) error {
  1065. // ptfFile, err := os.Open(shopJsonPath)
  1066. // if err != nil {
  1067. // logrus.Errorln("读取日志文件失败", err)
  1068. // }
  1069. // defer ptfFile.Close()
  1070. // fileName := filepath.Base(shopJsonPath)
  1071. //
  1072. // var materials []types.MidSalesSalesGoods
  1073. //
  1074. // decoder := json.NewDecoder(ptfFile)
  1075. // err = decoder.Decode(&materials)
  1076. // if err != nil {
  1077. // logrus.Errorf("%v Decoder failed %v", fileName, err.Error())
  1078. // return err
  1079. // }
  1080. //
  1081. // allBox := make(map[int64]*model.SalesGoods)
  1082. // logrus.Infof("初始化allBox...")
  1083. //
  1084. // for _, v := range materials {
  1085. // n := new(model.SalesGoods)
  1086. // n.ID = v.ID
  1087. // n.AdCoolDown = v.AdCoolDown
  1088. // n.AdDayTimes = v.AdDayTimes
  1089. // n.AdDayType = v.AdDayType
  1090. // n.PlatGroup = v.PlatGroup
  1091. // n.GoodsType = v.Type
  1092. // n.Name = v.Name
  1093. // if len(v.GiftNum) == 2 {
  1094. // dm := model.DropMaterial{
  1095. // ID: v.GiftNum[0],
  1096. // Count: int(v.GiftNum[1]),
  1097. // }
  1098. // n.Gift = append(n.Gift, dm)
  1099. // }
  1100. //
  1101. // // 当数组大于1时,表示有多种购买方式
  1102. // priceCount := len(v.Price)
  1103. // switch priceCount {
  1104. // case 0:
  1105. // case 1:
  1106. // dm := model.DropMaterial{}
  1107. // price := v.Price[0]
  1108. // if price[0] > 0 {
  1109. // dm.ID = price[0]
  1110. // }
  1111. // dm.Count = int(price[1])
  1112. // n.Cost = append(n.Cost, dm)
  1113. // case 2, 3:
  1114. // dm := model.DropMaterial{}
  1115. // price := v.Price[0]
  1116. // if price[0] > 0 {
  1117. // dm.ID = price[0]
  1118. // }
  1119. // dm.Count = int(price[1])
  1120. // n.Cost = append(n.Cost, dm)
  1121. //
  1122. // contents := model.ExtractMaterials(v.Content)
  1123. // n.Materials = append(n.Materials, *contents[0])
  1124. //
  1125. // // 第二、三种支付方式
  1126. //
  1127. // for k, p1 := range v.Price {
  1128. // if k == 0 {
  1129. // continue
  1130. // }
  1131. //
  1132. // gs := new(model.SalesGoods2)
  1133. //
  1134. // dm2 := model.DropMaterial{}
  1135. // dm2.ID = p1[0]
  1136. // dm2.Count = int(p1[1])
  1137. // gs.Cost = append(gs.Cost, dm2)
  1138. //
  1139. // gs.Materials = append(gs.Materials, *contents[k])
  1140. //
  1141. // n.OtherGoods = append(n.OtherGoods, gs)
  1142. // }
  1143. //
  1144. // default:
  1145. // logrus.Errorf("foud shop error priceCount != 1 2\n", n)
  1146. // }
  1147. //
  1148. // if v.Double == 1 {
  1149. // n.FirstDouble = 1
  1150. // }
  1151. //
  1152. // var ms []*model.DropMaterial
  1153. // var es []int64
  1154. //
  1155. // if len(v.Content[0]) == 2 {
  1156. // ms = model.ExtractMaterials(v.Content)
  1157. // } else {
  1158. // ms, es = model.ExtractMerialEquips(v.Content)
  1159. // }
  1160. //
  1161. // if priceCount < 2 {
  1162. // for _, v := range ms {
  1163. // n.Materials = append(n.Materials, *v)
  1164. // }
  1165. // n.Equipments = es
  1166. // }
  1167. //
  1168. // allBox[n.ID] = n
  1169. //
  1170. // //监测配置数值
  1171. // if n.ID <= 0 || n.GoodsType <= 0 ||
  1172. // (len(n.Cost) == 0 && n.GoodsType != 7 && n.GoodsType != 14) ||
  1173. // (len(n.Materials) == 0 && len(n.Equipments) == 0) {
  1174. // logrus.Errorf("foud shop error1 %v\n", n)
  1175. // }
  1176. // for _, v := range n.Cost {
  1177. // if v.ID > 100000 {
  1178. // logrus.Errorf("foud shop error2 %v\n", v)
  1179. // }
  1180. // }
  1181. // for _, v := range n.Gift {
  1182. // if v.ID > 100000 {
  1183. // logrus.Errorf("foud shop error3 %v\n", v)
  1184. // }
  1185. // }
  1186. // }
  1187. // logrus.Infof("初始化allBox完成")
  1188. //
  1189. // logrus.Infof("allBox加载otherGoods...")
  1190. // otherGoods, err := ExtractPropStore(propsStoreJsonPath)
  1191. // if err != nil {
  1192. // logrus.Errorf("ExtractPropStore err: %v", err.Error())
  1193. // return err
  1194. // }
  1195. // for k, v := range otherGoods {
  1196. // allBox[k] = v
  1197. // }
  1198. // logrus.Infof("allBox加载otherGoods完成")
  1199. //
  1200. // logrus.Infof("allBox加载allJson...")
  1201. // for _, v := range allJson {
  1202. // allBox[v.ID] = v
  1203. // }
  1204. // logrus.Infof("allBox加载allJson完成")
  1205. //
  1206. // logrus.Infof("allBox加载limitGoods...")
  1207. // // 导入需要RMB支付的限时礼包
  1208. // limitGoods, err := ExtractLimitGiftGoods(limitGiftPath, int(j.bc.LimitgiftPerDayMaximum))
  1209. // if err != nil {
  1210. // logrus.Errorf("ExtractLimitGiftGoods err: %v", err.Error())
  1211. // return err
  1212. // }
  1213. // for k, v := range limitGoods {
  1214. // allBox[k] = v
  1215. // }
  1216. // logrus.Infof("allBox加载limitGoods完成")
  1217. //
  1218. // logrus.Infof("allBox转化购买等级限制...")
  1219. // // 商品上限购买等级不限制时转化为一个非常大的数
  1220. // for _, v := range allBox {
  1221. // if v.MaxLevel == 0 {
  1222. // v.MaxLevel = 1000000
  1223. // }
  1224. // }
  1225. // logrus.Infof("allBox转化购买等级限制完成")
  1226. //
  1227. // //保存到指定文件夹内
  1228. // lastDir, err := j.getLatestVersion()
  1229. // if err != nil {
  1230. // logrus.Errorf("getLatestVersion err: %v", err)
  1231. // }
  1232. // logrus.Infof("最新的文件夹:%s/%s", os.Getenv("JSON_PATH"), lastDir)
  1233. // writeFile := fmt.Sprintf("%s/%s/%s", os.Getenv("JSON_PATH"), lastDir, "product.json")
  1234. // writePtr, err := os.Create(writeFile)
  1235. // if err != nil {
  1236. // logrus.Errorln("写日志文件失败", err)
  1237. // return err
  1238. // }
  1239. // defer writePtr.Close()
  1240. // encoder := json.NewEncoder(writePtr)
  1241. // err = encoder.Encode(&allBox)
  1242. // if err != nil {
  1243. // logrus.Errorln("Encoder failed", err.Error())
  1244. // return err
  1245. // }
  1246. // return nil
  1247. //}
  1248. //
  1249. //func (j *JSyncGoodsJson) getLatestVersion() (string, error) {
  1250. // // 读取指定目录下的所有文件夹名称
  1251. // folders, err := ioutil.ReadDir(os.Getenv("JSON_PATH"))
  1252. // if err != nil {
  1253. // logrus.Errorf("Failed to read directory:%v", err)
  1254. // return "", err
  1255. // }
  1256. //
  1257. // var latestVersion *version.Version
  1258. //
  1259. // // 遍历文件夹列表,比较版本号
  1260. // for _, folder := range folders {
  1261. // if folder.IsDir() {
  1262. // versionStr := folder.Name()
  1263. // logrus.Infof("folderName:%s", versionStr)
  1264. // if strings.HasPrefix(versionStr, "v") {
  1265. // v, err := version.NewVersion(versionStr[1:]) // 移除前缀 "v" 并创建版本对象
  1266. // if err != nil {
  1267. // fmt.Println("Failed to parse version:", err)
  1268. // continue
  1269. // }
  1270. //
  1271. // if latestVersion == nil || v.GreaterThan(latestVersion) {
  1272. // latestVersion = v
  1273. // }
  1274. // }
  1275. // }
  1276. // }
  1277. //
  1278. // if latestVersion != nil {
  1279. // return fmt.Sprintf("v%s", latestVersion.String()), nil
  1280. // }
  1281. // return "", errors.New("no version folders found")
  1282. //}
  1283. //
  1284. //func (j *JSyncGoodsJson) RowsToCols2(filePath string, save bool) (map[string]interface{}, error) {
  1285. // fileName := filepath.Base(filePath)
  1286. //
  1287. // ext := path.Ext(fileName)
  1288. // // 去除后缀,获取文件名
  1289. // name := fileName[:len(fileName)-len(ext)]
  1290. // //writeFile := filepath.Base(filePath)
  1291. // writeFilePath := fmt.Sprintf("%s/%s2.json", j.outPath, name)
  1292. // _, err := os.Stat(writeFilePath)
  1293. // if !errors.Is(err, fs.ErrNotExist) {
  1294. // logrus.Infof("%s已存在", writeFilePath)
  1295. // return nil, nil
  1296. // }
  1297. // // 读数据
  1298. // talentFile, err := os.Open(filePath)
  1299. // if err != nil {
  1300. // logrus.Errorln("读取日志文件失败", err)
  1301. // return nil, err
  1302. // }
  1303. // defer talentFile.Close()
  1304. //
  1305. // var items []*types.MidCol
  1306. //
  1307. // decoder := json.NewDecoder(talentFile)
  1308. // err = decoder.Decode(&items)
  1309. // if err != nil {
  1310. // logrus.Errorf("%v Decoder failed, %v", fileName, err.Error())
  1311. // return nil, err
  1312. // }
  1313. //
  1314. // // KV
  1315. // allObjects := make(map[string]interface{})
  1316. // for _, v := range items {
  1317. //
  1318. // switch v.Type {
  1319. // case "STRING":
  1320. // allObjects[v.Key] = v.Value
  1321. // case "INT":
  1322. // allObjects[v.Key], _ = strconv.ParseInt(v.Value, 10, 64)
  1323. // case "FLOAT":
  1324. // allObjects[v.Key], _ = strconv.ParseFloat(v.Value, 64)
  1325. // case "STRINGARR":
  1326. // var val []string
  1327. // if err = json.Unmarshal([]byte(v.Value), &val); err != nil {
  1328. // logrus.Errorf("%v Unmarshal STRINGARR error:%+v", fileName, v.Value)
  1329. // return nil, err
  1330. // }
  1331. // allObjects[v.Key] = val
  1332. // case "INTARR", "ARR":
  1333. // var val []int64
  1334. // if err = json.Unmarshal([]byte(v.Value), &val); err != nil {
  1335. // logrus.Errorf("%v Unmarshal STRINGARR error:%+v", fileName, v.Value)
  1336. // return nil, err
  1337. // }
  1338. // allObjects[v.Key] = val
  1339. // case "FLOATARR":
  1340. // var val []float64
  1341. // if err = json.Unmarshal([]byte(v.Value), &val); err != nil {
  1342. // logrus.Errorf("%v Unmarshal STRINGARR error:%+v", fileName, v.Value)
  1343. // return nil, err
  1344. // }
  1345. // allObjects[v.Key] = val
  1346. // case "STRINGARRS":
  1347. // var val [][]string
  1348. // if err = json.Unmarshal([]byte(v.Value), &val); err != nil {
  1349. // logrus.Errorf("%v Unmarshal STRINGARR error:%+v", fileName, v.Value)
  1350. // return nil, err
  1351. // }
  1352. // allObjects[v.Key] = val
  1353. // case "INTARRS", "ARRS":
  1354. // var val [][]int64
  1355. // if err = json.Unmarshal([]byte(v.Value), &val); err != nil {
  1356. // logrus.Errorf("%v Unmarshal STRINGARR error:%+v", fileName, v.Value)
  1357. // return nil, err
  1358. // }
  1359. // allObjects[v.Key] = val
  1360. // case "FLOATARRS":
  1361. // var val [][]float64
  1362. // if err = json.Unmarshal([]byte(v.Value), &val); err != nil {
  1363. // logrus.Errorf("%v Unmarshal STRINGARR error:%+v", fileName, v.Value)
  1364. // return nil, err
  1365. // }
  1366. // allObjects[v.Key] = val
  1367. // }
  1368. // }
  1369. //
  1370. // if !save {
  1371. // return allObjects, nil
  1372. // }
  1373. //
  1374. // // 保存
  1375. // logrus.Infof("RowsToCols2 base2:%s", writeFilePath)
  1376. // writePtr, err := os.Create(writeFilePath)
  1377. // if err != nil {
  1378. // logrus.Errorf("%v RowsToCols2 CreateFile failed. %v", fileName, err)
  1379. // return nil, err
  1380. // }
  1381. // defer writePtr.Close()
  1382. // encoder2 := json.NewEncoder(writePtr)
  1383. // err = encoder2.Encode(&allObjects)
  1384. // if err != nil {
  1385. // logrus.Errorf("%v RowsToCols2 save failed. %v", fileName, err.Error())
  1386. // return nil, err
  1387. // }
  1388. // return allObjects, nil
  1389. //}
  1390. //func (j *JSyncGoodsJson) loadJsonFile(filePath string, items interface{}) (interface{}, error) {
  1391. // fileName := filepath.Base(filePath)
  1392. // ext := path.Ext(fileName)
  1393. // // 去除后缀,获取文件名
  1394. // name := fileName[:len(fileName)-len(ext)]
  1395. // writeFilePath := fmt.Sprintf("%s/%s2.json", j.outPath, name)
  1396. // logrus.Infof("loadJsonFile base2:%s", writeFilePath)
  1397. //
  1398. // roleFile, err := os.Open(writeFilePath)
  1399. // if err != nil {
  1400. // logrus.Errorln("读取日志文件失败", err)
  1401. // }
  1402. // defer roleFile.Close()
  1403. //
  1404. // //var roles []MidRoleAttr
  1405. // decoder := json.NewDecoder(roleFile)
  1406. // err = decoder.Decode(&items)
  1407. // if err != nil {
  1408. // logrus.Errorf("%v Decoder failed. %v", fileName, err.Error())
  1409. // return nil, err
  1410. // }
  1411. // return items, nil
  1412. //}
  1413. //func ExtractPropStore(filePath string) (map[int64]*model.SalesGoods, error) {
  1414. // ptfFile, err := os.Open(filePath)
  1415. // if err != nil {
  1416. // logrus.Errorln("读取日志文件失败", err)
  1417. // }
  1418. // defer ptfFile.Close()
  1419. // fileName := filepath.Base(filePath)
  1420. //
  1421. // var materials []types.MidPropStoreGoods
  1422. //
  1423. // decoder := json.NewDecoder(ptfFile)
  1424. // err = decoder.Decode(&materials)
  1425. // if err != nil {
  1426. // logrus.Errorf("%v Decoder failed", fileName, err.Error())
  1427. // return nil, err
  1428. // }
  1429. //
  1430. // allBox := make(map[int64]*model.SalesGoods)
  1431. // for _, v := range materials {
  1432. // n := new(model.SalesGoods)
  1433. // n.ID = v.ID
  1434. // n.GoodsType = v.Type
  1435. //
  1436. // if len(v.Price) == 2 {
  1437. // dm := model.DropMaterial{}
  1438. // if v.Price[0] > 0 {
  1439. // dm.ID = v.Price[0]
  1440. // }
  1441. // dm.Count = int(v.Price[1])
  1442. // n.Cost = append(n.Cost, dm)
  1443. // }
  1444. // n.Name = v.Name
  1445. //
  1446. // dm := model.DropMaterial{ID: v.Content[0], Count: int(v.Content[1])}
  1447. // n.Materials = append(n.Materials, dm)
  1448. //
  1449. // allBox[n.ID] = n
  1450. //
  1451. // //监测配置数值
  1452. // if n.ID <= 0 || n.GoodsType <= 0 ||
  1453. // (len(n.Cost) == 0) ||
  1454. // (len(n.Materials) == 0 && len(n.Equipments) == 0) {
  1455. // logrus.Errorf("foud shop error5 %v\n", n)
  1456. // }
  1457. // }
  1458. //
  1459. // return allBox, nil
  1460. //}
  1461. //func ExtractLimitGiftGoods(filePath string, openLevel int) (map[int64]*model.SalesGoods, error) {
  1462. // ptfFile, err := os.Open(filePath)
  1463. // if err != nil {
  1464. // logrus.Errorln("读取日志文件失败", err)
  1465. // }
  1466. // defer ptfFile.Close()
  1467. // fileName := filepath.Base(filePath)
  1468. //
  1469. // var goods []types.LimitGiftGoods
  1470. //
  1471. // decoder := json.NewDecoder(ptfFile)
  1472. // err = decoder.Decode(&goods)
  1473. // if err != nil {
  1474. // logrus.Errorf("%v Decoder failed", fileName, err.Error())
  1475. // return nil, err
  1476. // }
  1477. //
  1478. // allBox := make(map[int64]*model.SalesGoods)
  1479. // for _, v := range goods {
  1480. // n := new(model.SalesGoods)
  1481. // n.ID = v.Id
  1482. // n.GoodsType = v.Type
  1483. // n.OpenLevel = openLevel
  1484. // n.Name = v.Name
  1485. // if len(v.Price) >= 2 {
  1486. // var id int64 = 0 // 0金币,1钻石,2RMB
  1487. // if v.Price[0] == 0 {
  1488. // id = 1001
  1489. // }
  1490. // if v.Price[0] == 1 {
  1491. // id = 1002
  1492. // }
  1493. // dm := model.DropMaterial{}
  1494. // dm.ID = id
  1495. // dm.Count = int(v.Price[1])
  1496. // n.Cost = append(n.Cost, dm)
  1497. // }
  1498. //
  1499. // var (
  1500. // material []model.DropMaterial
  1501. // equipment []int64
  1502. // )
  1503. //
  1504. // for _, award := range v.Award {
  1505. // if len(award) == 0 { // 没有奖励内容
  1506. // continue
  1507. // }
  1508. //
  1509. // if 10000000 < award[0] {
  1510. // // 装备
  1511. // for i := 0; i < int(award[1]); i++ {
  1512. // equipment = append(equipment, award[0])
  1513. // }
  1514. // } else {
  1515. // // 材料、金币、钻石
  1516. // material = append(material, model.DropMaterial{
  1517. // ID: award[0],
  1518. // Count: int(award[1]),
  1519. // })
  1520. // }
  1521. // }
  1522. //
  1523. // if len(material) == 0 && len(equipment) == 0 {
  1524. // continue
  1525. // }
  1526. //
  1527. // n.Materials = material
  1528. // n.Equipments = equipment
  1529. // allBox[n.ID] = n
  1530. //
  1531. // //监测配置数值
  1532. // if n.ID <= 0 || n.GoodsType <= 0 ||
  1533. // (len(n.Cost) == 0) ||
  1534. // (len(n.Materials) == 0 && len(n.Equipments) == 0) {
  1535. // logrus.Errorf("foud limitGiftGoods error5 %v\n", n)
  1536. // }
  1537. // }
  1538. //
  1539. // return allBox, nil
  1540. //}