main.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. package main
  2. import (
  3. qu "app.yhyue.com/moapp/jybase/common"
  4. "app.yhyue.com/moapp/jybase/mysql"
  5. "encoding/json"
  6. "log"
  7. )
  8. type sysConfig struct {
  9. Mysql map[string]interface{} `json:"mysql"`
  10. }
  11. var SysConfig sysConfig
  12. var Mysql *mysql.Mysql
  13. func init() {
  14. qu.ReadConfig("./config.json", &SysConfig)
  15. Mysql = &mysql.Mysql{
  16. Address: SysConfig.Mysql["address"].(string),
  17. UserName: SysConfig.Mysql["userName"].(string),
  18. PassWord: SysConfig.Mysql["passWord"].(string),
  19. DBName: SysConfig.Mysql["dbName"].(string),
  20. MaxOpenConns: qu.IntAll(SysConfig.Mysql["maxOpenConns"]),
  21. MaxIdleConns: qu.IntAll(SysConfig.Mysql["maxIdleConns"]),
  22. }
  23. Mysql.Init()
  24. }
  25. func main() {
  26. log.Println("回款信息同步。。。开始")
  27. query := `select order_code,filter from dataexport_order where (locate('"isAll":1', filter) > 0 or locate('"isAll":2', filter) > 0 or locate('"isAll":3', filter) > 0)`
  28. log.Println("query :", query)
  29. data := Mysql.SelectBySql(query)
  30. if data != nil && *data != nil && len(*data) > 0 {
  31. for _, v := range *data {
  32. order_code := qu.ObjToString(v["order_code"])
  33. filterMap := map[string]interface{}{}
  34. filterData := qu.ObjToString(v["filter"])
  35. if err := json.Unmarshal([]byte(filterData), &filterMap); err == nil {
  36. transferV := qu.ObjToString(filterMap["transferV"])
  37. transferVTime := qu.ObjToString(filterMap["transferVTime"])
  38. isAll := qu.IntAll(filterMap["isAll"])
  39. return_status := 0
  40. if transferV != "" {
  41. refund_id := Mysql.Insert("return_money_record", map[string]interface{}{
  42. "order_code": order_code,
  43. "return_time": transferVTime,
  44. "return_voucher_url": transferV,
  45. "operate_time": qu.NowFormat(qu.Date_Full_Layout),
  46. "state": 1,
  47. })
  48. if refund_id > 0 {
  49. log.Println("回款表插入成功 ", order_code)
  50. } else {
  51. log.Println("回款表插入失败 ", order_code)
  52. }
  53. }
  54. if filterMap["collects"] != nil {
  55. collects := qu.ObjArrToMapArr(filterMap["collects"].([]interface{}))
  56. for _, vv := range collects {
  57. tV := qu.ObjToString(vv["transferV"])
  58. tVTime := qu.ObjToString(vv["transferVTime"])
  59. price := qu.IntAll(vv["price"]) * 100
  60. refund_id := Mysql.Insert("return_money_record", map[string]interface{}{
  61. "order_code": order_code,
  62. "return_time": tVTime,
  63. "return_voucher_url": tV,
  64. "operate_time": qu.NowFormat(qu.Date_Full_Layout),
  65. "return_money": price,
  66. "state": 1,
  67. })
  68. if refund_id > 0 {
  69. log.Println("回款表collects插入成功 ", order_code)
  70. } else {
  71. log.Println("回款表collects插入失败 ", order_code)
  72. }
  73. }
  74. }
  75. if isAll > 0 {
  76. if isAll == 1 {
  77. return_status = 1
  78. } else if isAll == 2 {
  79. return_status = 0
  80. } else if isAll == 3 {
  81. return_status = 2
  82. }
  83. ok := Mysql.Update("dataexport_order", map[string]interface{}{"order_code": order_code}, map[string]interface{}{"return_status": return_status})
  84. if ok {
  85. log.Println("回款状态修改成功 ", order_code)
  86. }
  87. }
  88. }
  89. }
  90. } else {
  91. log.Println("未查询到回款数据")
  92. }
  93. log.Println("回款信息同步。。。结束")
  94. }