web.go 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555
  1. package http
  2. import (
  3. "time"
  4. "go-common/app/job/main/growup/conf"
  5. "go-common/library/log"
  6. bm "go-common/library/net/http/blademaster"
  7. )
  8. func execAvRatio(c *bm.Context) {
  9. log.Info("begin update av charge ratio")
  10. v := new(struct {
  11. Date string `form:"date" validate:"required"`
  12. })
  13. if err := c.Bind(v); err != nil {
  14. return
  15. }
  16. t, err := time.Parse("2006-01-02", v.Date)
  17. if err != nil {
  18. log.Error("execAvRatio date error!date:%s", v.Date)
  19. return
  20. }
  21. log.Info("ratio,hour:%d, num:%d, sleep:%d", conf.Conf.Ratio.Hour, conf.Conf.Ratio.Num, conf.Conf.Ratio.Sleep)
  22. for {
  23. rows, _ := svr.DeleteAvRatio(c, conf.Conf.Ratio.Num)
  24. time.Sleep(time.Duration(conf.Conf.Ratio.Sleep) * time.Millisecond)
  25. if rows == 0 {
  26. break
  27. }
  28. }
  29. err = svr.ExecRatioForHTTP(c, t.Year(), int(t.Month()), t.Day())
  30. if err != nil {
  31. log.Error("Exec avRatio from http error!(%v)", err)
  32. } else {
  33. log.Info("Exec avRatio from http succeed!")
  34. }
  35. c.JSON(nil, err)
  36. }
  37. func execIncome(c *bm.Context) {
  38. log.Info("begin update up income")
  39. v := new(struct {
  40. Date string `form:"date" validate:"required" `
  41. })
  42. if err := c.Bind(v); err != nil {
  43. return
  44. }
  45. t, err := time.Parse("2006-01-02", v.Date)
  46. if err != nil {
  47. log.Error("execIncome date error!date:%s", v.Date)
  48. return
  49. }
  50. log.Info("income,hour:%d, num:%d, sleep:%d", conf.Conf.Income.Hour, conf.Conf.Income.Num, conf.Conf.Income.Sleep)
  51. err = svr.ExecIncomeForHTTP(c, t.Year(), int(t.Month()), t.Day())
  52. if err != nil {
  53. log.Error("ExecIncomeForHTTP error!(%v)", err)
  54. } else {
  55. log.Info("Exec Income from http succeed!")
  56. }
  57. c.JSON(nil, err)
  58. }
  59. func getUpIncomeStatis(c *bm.Context) {
  60. log.Info("begin calculate up income statis")
  61. v := new(struct {
  62. Date string `form:"date" validate:"required"`
  63. HasWithdraw int `form:"has_withdraw"`
  64. })
  65. if err := c.Bind(v); err != nil {
  66. return
  67. }
  68. err := svr.GetUpIncomeStatis(c, v.Date, v.HasWithdraw)
  69. if err != nil {
  70. log.Error("(job growup svr.GetUpIncomeStatis error(%v)", err)
  71. }
  72. c.JSON(nil, err)
  73. }
  74. func getAvIncomeStatis(c *bm.Context) {
  75. v := new(struct {
  76. Date string `form:"date" validate:"required"`
  77. })
  78. if err := c.Bind(v); err != nil {
  79. return
  80. }
  81. err := svr.GetAvIncomeStatis(c, v.Date)
  82. if err != nil {
  83. log.Error("(job growup svr.GetAvIncomeStatis error(%v)", err)
  84. }
  85. c.JSON(nil, err)
  86. }
  87. func updateTagIncome(c *bm.Context) {
  88. log.Info("begin fix tag income")
  89. v := new(struct {
  90. Date string `form:"date" validate:"required"`
  91. })
  92. if err := c.Bind(v); err != nil {
  93. return
  94. }
  95. err := svr.UpdateTagIncome(c, v.Date)
  96. if err != nil {
  97. log.Error("(job growup svr.UpdateTagIncome error(%v)", err)
  98. }
  99. c.JSON(nil, err)
  100. }
  101. func fixUpIncome(c *bm.Context) {
  102. log.Info("begin fix up income from tag")
  103. v := new(struct {
  104. Date string `form:"date" validate:"required"`
  105. TagID int64 `form:"tag_id" validate:"required"`
  106. AddCount int `form:"add_count" validate:"required"`
  107. TotalIncome int `form:"total_income" validate:"required"`
  108. })
  109. if err := c.Bind(v); err != nil {
  110. return
  111. }
  112. err := svr.FixUpIncome(c, v.Date, v.TagID, v.AddCount, v.TotalIncome)
  113. if err != nil {
  114. log.Error("(job growup svr.FixUpIncome error(%v)", err)
  115. }
  116. c.JSON(nil, err)
  117. }
  118. func fixIncome(c *bm.Context) {
  119. log.Info("begin fix income")
  120. err := svr.FixIncome(c)
  121. if err != nil {
  122. log.Error("(job growup svr.FixIncome error(%v)", err)
  123. }
  124. c.JSON(nil, err)
  125. }
  126. func fixUpAvStatis(c *bm.Context) {
  127. log.Info("begin fix up av statis")
  128. v := new(struct {
  129. Count int `form:"count" validate:"required"`
  130. })
  131. if err := c.Bind(v); err != nil {
  132. return
  133. }
  134. err := svr.FixUpAvStatis(c, v.Count)
  135. if err != nil {
  136. log.Error("(job growup svr.FixUpAvStatis error(%v)", err)
  137. }
  138. c.JSON(nil, err)
  139. }
  140. func updateWithdraw(c *bm.Context) {
  141. v := new(struct {
  142. OldDate string `form:"old_date" validate:"required"`
  143. NewDate string `form:"new_date" validate:"required"`
  144. Count int64 `form:"count" validate:"required"`
  145. })
  146. if err := c.Bind(v); err != nil {
  147. return
  148. }
  149. err := svr.UpdateWithdraw(c, v.OldDate, v.NewDate, v.Count)
  150. if err != nil {
  151. log.Error("(svr.UpdateWithdraw error(%v)", err)
  152. }
  153. c.JSON(nil, err)
  154. }
  155. func creativeIncome(c *bm.Context) {
  156. v := new(struct {
  157. Date string `form:"date" validate:"required"`
  158. })
  159. if err := c.Bind(v); err != nil {
  160. return
  161. }
  162. date, err := time.ParseInLocation("2006-01-02", v.Date, time.Local)
  163. if err != nil {
  164. log.Error("time.Parse date(%s) error", v.Date)
  165. c.JSON(nil, err)
  166. return
  167. }
  168. log.Info("start run %s income", v.Date)
  169. err = incomeSrv.RunAndSendMail(c, date)
  170. if err != nil {
  171. log.Error("incomeSrv.Run error(%v)", err)
  172. } else {
  173. log.Info("run %s income success", v.Date)
  174. }
  175. c.JSON(nil, err)
  176. }
  177. func creativeCharge(c *bm.Context) {
  178. v := new(struct {
  179. Date string `form:"date" validate:"required"`
  180. })
  181. if err := c.Bind(v); err != nil {
  182. return
  183. }
  184. date, err := time.ParseInLocation("2006-01-02", v.Date, time.Local)
  185. if err != nil {
  186. log.Error("time.Parse date(%s) error", v.Date)
  187. c.JSON(nil, err)
  188. return
  189. }
  190. log.Info("start run %s charge", v.Date)
  191. err = chargeSrv.RunAndSendMail(c, date)
  192. if err != nil {
  193. log.Error("chargeSrv.RunAndSendMail error(%v)", err)
  194. } else {
  195. log.Info("run %s charge success", v.Date)
  196. }
  197. c.JSON(nil, err)
  198. }
  199. func creativeStatis(c *bm.Context) {
  200. v := new(struct {
  201. Date string `form:"date" validate:"required"`
  202. })
  203. if err := c.Bind(v); err != nil {
  204. return
  205. }
  206. date, err := time.ParseInLocation("2006-01-02", v.Date, time.Local)
  207. if err != nil {
  208. log.Error("time.Parse date(%s) error", v.Date)
  209. c.JSON(nil, err)
  210. return
  211. }
  212. log.Info("start run %s statis", v.Date)
  213. err = incomeSrv.RunStatis(c, date)
  214. if err != nil {
  215. log.Error("incomeSrv.RunStatis error(%v)", err)
  216. } else {
  217. log.Info("run %s statis success", v.Date)
  218. }
  219. c.JSON(nil, err)
  220. }
  221. func creativeBill(c *bm.Context) {
  222. v := new(struct {
  223. StartDate string `form:"start_date" validate:"required"`
  224. EndDate string `form:"end_date" validate:"required"`
  225. })
  226. if err := c.Bind(v); err != nil {
  227. return
  228. }
  229. start, err := time.ParseInLocation("2006-01-02", v.StartDate, time.Local)
  230. if err != nil {
  231. log.Error("time.Parse date(%s) error", v.StartDate)
  232. c.JSON(nil, err)
  233. return
  234. }
  235. end, err := time.ParseInLocation("2006-01-02", v.EndDate, time.Local)
  236. if err != nil {
  237. log.Error("time.Parse date(%s) error", v.EndDate)
  238. c.JSON(nil, err)
  239. return
  240. }
  241. if err = svr.CreativeUpBill(c, start, end); err != nil {
  242. log.Error("svr.CreativeUpBill error(%v)", err)
  243. }
  244. c.JSON(nil, err)
  245. }
  246. func creativeBudget(c *bm.Context) {
  247. v := new(struct {
  248. Date string `form:"date" validate:"required"`
  249. })
  250. if err := c.Bind(v); err != nil {
  251. return
  252. }
  253. date, err := time.ParseInLocation("2006-01-02", v.Date, time.Local)
  254. if err != nil {
  255. log.Error("time.Parse date(%s) error", v.Date)
  256. c.JSON(nil, err)
  257. return
  258. }
  259. err = svr.CreativeBudget(c, date)
  260. if err != nil {
  261. log.Error("svr.CreativeBudget error(%v)", err)
  262. }
  263. c.JSON(nil, err)
  264. }
  265. func creativeActivity(c *bm.Context) {
  266. v := new(struct {
  267. Date string `form:"date" validate:"required"`
  268. })
  269. if err := c.Bind(v); err != nil {
  270. return
  271. }
  272. date, err := time.ParseInLocation("2006-01-02", v.Date, time.Local)
  273. if err != nil {
  274. log.Error("time.Parse date(%s) error", v.Date)
  275. c.JSON(nil, err)
  276. return
  277. }
  278. err = svr.CreativeActivity(c, date)
  279. if err != nil {
  280. log.Error("svr.CreativeActivity error(%v)", err)
  281. }
  282. c.JSON(nil, err)
  283. }
  284. func updateUpInfoVideo(c *bm.Context) {
  285. err := svr.UpdateUpInfo(c)
  286. if err != nil {
  287. log.Error("svr.UpdateUpInfo error(%v)", err)
  288. } else {
  289. log.Info("run %s UpdateUpInfo success", time.Now().Format("2006-01-02"))
  290. }
  291. c.JSON(nil, err)
  292. }
  293. func fixTagAdjust(c *bm.Context) {
  294. v := new(struct {
  295. ID int64 `form:"id" validate:"required"`
  296. })
  297. if err := c.Bind(v); err != nil {
  298. return
  299. }
  300. err := svr.UpdateTagAdjust(c, v.ID)
  301. if err != nil {
  302. log.Error("svr.UpdateTagAdjust error(%v)", err)
  303. }
  304. c.JSON(nil, err)
  305. }
  306. func fixAccountType(c *bm.Context) {
  307. v := new(struct {
  308. MID int64 `form:"mid" validate:"required"`
  309. AccountType int `form:"account_type" validate:"required"`
  310. })
  311. if err := c.Bind(v); err != nil {
  312. return
  313. }
  314. err := svr.UpdateAccountType(c, v.MID, v.AccountType)
  315. if err != nil {
  316. log.Error("svr.UpdateAccountType error!(%v)", err)
  317. }
  318. c.JSON(nil, err)
  319. }
  320. func syncBGM(c *bm.Context) {
  321. err := incomeSrv.SyncBgmInfo(c)
  322. if err != nil {
  323. log.Error("svr.SyncBgmInfo error!(%v)", err)
  324. }
  325. c.JSON(nil, err)
  326. }
  327. func fixUpAccount(c *bm.Context) {
  328. v := new(struct {
  329. MID int64 `form:"mid"`
  330. TotalIncome int64 `form:"total_income"`
  331. UnwithdrawIncome int64 `form:"unwithdraw_income"`
  332. })
  333. if err := c.Bind(v); err != nil {
  334. return
  335. }
  336. err := svr.UpdateUpAccountMoney(c, v.MID, v.TotalIncome, v.UnwithdrawIncome)
  337. if err != nil {
  338. log.Error("svr.UpdateUpAccountMoney error!(%v)", err)
  339. }
  340. c.JSON(nil, err)
  341. }
  342. func fixBaseIncome(c *bm.Context) {
  343. v := new(struct {
  344. MID int64 `form:"mid" validate:"required"`
  345. Base int64 `form:"base" validate:"required"`
  346. Date string `form:"date" validate:"required"`
  347. })
  348. if err := c.Bind(v); err != nil {
  349. return
  350. }
  351. err := svr.FixBaseIncome(c, v.Base, v.MID, v.Date)
  352. if err != nil {
  353. log.Error("svr.FixBaseIncome error!(%v)", err)
  354. }
  355. c.JSON(nil, err)
  356. }
  357. func fixAvBreach(c *bm.Context) {
  358. v := new(struct {
  359. MID int64 `form:"mid" validate:"required"`
  360. Date string `form:"date" validate:"required"`
  361. Count int `form:"count" validate:"required"`
  362. })
  363. if err := c.Bind(v); err != nil {
  364. return
  365. }
  366. err := svr.FixAvBreach(c, v.MID, v.Date, v.Count)
  367. if err != nil {
  368. log.Error("svr.FixAvBreach error!(%v)", err)
  369. }
  370. c.JSON(nil, err)
  371. }
  372. func fixUpTotalIncome(c *bm.Context) {
  373. v := new(struct {
  374. Table string `form:"table" validate:"required"`
  375. Date string `form:"date" validate:"required"`
  376. Count int `form:"count" validate:"required"`
  377. })
  378. if err := c.Bind(v); err != nil {
  379. return
  380. }
  381. err := svr.FixUpTotalIncome(c, v.Table, v.Date, v.Count)
  382. if err != nil {
  383. log.Error("svr.FixUpTotalIncome error!(%v)", err)
  384. }
  385. c.JSON(nil, err)
  386. }
  387. func syncUpPGC(c *bm.Context) {
  388. err := svr.SyncUpPGC(c)
  389. if err != nil {
  390. log.Error("svr.SyncUpPGC error!(%v)", err)
  391. }
  392. c.JSON(nil, err)
  393. }
  394. func syncAvBaseIncome(c *bm.Context) {
  395. v := new(struct {
  396. Table string `form:"table" validate:"required"`
  397. })
  398. if err := c.Bind(v); err != nil {
  399. return
  400. }
  401. err := svr.SyncAvBaseIncome(c, v.Table)
  402. if err != nil {
  403. log.Error("svr.SyncAvBaseIncome error!(%v)", err)
  404. }
  405. c.JSON(nil, err)
  406. }
  407. func updateColumnTag(c *bm.Context) {
  408. v := new(struct {
  409. Table string `form:"table" validate:"required"`
  410. New int `form:"new" validate:"required"`
  411. Old string `form:"old" validate:"required"`
  412. Count int64 `form:"count" validate:"required"`
  413. })
  414. if err := c.Bind(v); err != nil {
  415. return
  416. }
  417. err := svr.UpdateColumnTag(c, v.Table, v.Old, v.New, v.Count)
  418. if err != nil {
  419. log.Error("svr.UpdateColumnTag error!(%v)", err)
  420. }
  421. c.JSON(nil, err)
  422. }
  423. func syncCreditScore(c *bm.Context) {
  424. err := svr.SyncCreditScore(c)
  425. if err != nil {
  426. log.Error("svr.SyncCreditScore error!(%v)", err)
  427. }
  428. c.JSON(nil, err)
  429. }
  430. func calBgmStatis(c *bm.Context) {
  431. err := svr.FixBgmIncomeStatis(c)
  432. if err != nil {
  433. log.Error("svr.FixBgmIncomeStatis error!(%v)", err)
  434. }
  435. c.JSON(nil, err)
  436. }
  437. func calBgmBaseIncome(c *bm.Context) {
  438. v := new(struct {
  439. MID int64 `form:"mid" validate:"required"`
  440. Date string `form:"date" validate:"required"`
  441. })
  442. if err := c.Bind(v); err != nil {
  443. return
  444. }
  445. err := svr.FixBgmBaseIncome(c, v.MID, v.Date)
  446. if err != nil {
  447. log.Error("svr.FixBgmIncomeStatis error!(%v)", err)
  448. }
  449. c.JSON(nil, err)
  450. }
  451. func updateBusinessIncome(c *bm.Context) {
  452. v := new(struct {
  453. Date string `form:"date" validate:"required"`
  454. })
  455. if err := c.Bind(v); err != nil {
  456. return
  457. }
  458. err := incomeSrv.UpdateBusinessIncome(c, v.Date)
  459. if err != nil {
  460. log.Error("svr.FixBusinessIncome error!(%v)", err)
  461. }
  462. c.JSON(nil, err)
  463. }
  464. func delDataLimit(c *bm.Context) {
  465. v := new(struct {
  466. Table string `form:"table" validate:"required"`
  467. Count int64 `form:"count" validate:"required"`
  468. })
  469. if err := c.Bind(v); err != nil {
  470. return
  471. }
  472. err := svr.DelDataLimit(c, v.Table, v.Count)
  473. if err != nil {
  474. log.Error("svr.DelDataLimit error(%v)", err)
  475. }
  476. c.JSON(nil, err)
  477. }
  478. func autoBreach(c *bm.Context) {
  479. v := new(struct {
  480. Date string `form:"date" validate:"required"`
  481. })
  482. if err := c.Bind(v); err != nil {
  483. return
  484. }
  485. _, err := svr.AutoBreach(c, v.Date)
  486. if err != nil {
  487. log.Error("svr.AutoBreach error(%v)", err)
  488. }
  489. c.JSON(nil, err)
  490. }
  491. func autoPunish(c *bm.Context) {
  492. _, err := svr.AutoPunish(c)
  493. if err != nil {
  494. log.Error("svr.AutoPunish error(%v)", err)
  495. }
  496. c.JSON(nil, err)
  497. }
  498. func autoExamination(c *bm.Context) {
  499. _, err := svr.AutoExamination(c)
  500. if err != nil {
  501. log.Error("svr.AutoExamination error(%v)", err)
  502. }
  503. c.JSON(nil, err)
  504. }
  505. func syncUpAccount(c *bm.Context) {
  506. err := svr.SyncUpAccount(c)
  507. if err != nil {
  508. log.Error("svr.SyncUpAccount error(%v)", err)
  509. }
  510. c.JSON(nil, err)
  511. }