商品rpc数据格式及调用方法
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

246 lines
4.0 KiB

  1. package productrpc
  2. import (
  3. "encoding/json"
  4. "log"
  5. "sort"
  6. "strconv"
  7. // "strconv"
  8. // "time"
  9. "git.tetele.net/tgo/helper"
  10. )
  11. /**
  12. * 获取商品进行中活动
  13. * 2021/10/06
  14. * GZ
  15. */
  16. func GetProductActivity(site_id, dbname, id string, url ...string) ([]map[string]string, error) {
  17. conn, err := rpc_server_conn(url...)
  18. if err != nil {
  19. return nil, err
  20. }
  21. defer conn.Close()
  22. arg := GetActivityParam{site_id, dbname, id, "0"}
  23. req, err := SetReqData(arg)
  24. if err != nil {
  25. return nil, err
  26. }
  27. res := &Response{}
  28. err = conn.GetProductActivity(req, res)
  29. if err != nil {
  30. return nil, err
  31. }
  32. res_data_de, err := GetResData(res)
  33. if err != nil {
  34. return nil, err
  35. }
  36. if res_data_de == "" {
  37. return nil, nil
  38. }
  39. var res_arr []map[string]string
  40. err = json.Unmarshal([]byte(res_data_de), &res_arr)
  41. if err != nil {
  42. return nil, err
  43. }
  44. var activitys Activitys
  45. if len(res_arr) > 0 {
  46. var start int
  47. for _, item := range res_arr {
  48. start, err = strconv.Atoi(item["Starttime"])
  49. if err != nil {
  50. log.Println(err)
  51. }
  52. activitys = append(activitys, Activity{
  53. Id: item["Id"],
  54. Start: start,
  55. })
  56. }
  57. }
  58. sort.Sort(activitys)
  59. var list []map[string]string = make([]map[string]string, 0)
  60. if len(activitys) > 0 {
  61. for _, v := range activitys {
  62. for _, old := range res_arr {
  63. if v.Id == old["Id"] {
  64. list = append(list, old)
  65. break
  66. }
  67. }
  68. }
  69. }
  70. return list, nil
  71. }
  72. /**
  73. * 获取商品预热中活动
  74. * 2021/10/06
  75. * GZ
  76. */
  77. func GetProductWarmingActivity(site_id, dbname, id string, url ...string) ([]map[string]string, error) {
  78. conn, err := rpc_server_conn(url...)
  79. if err != nil {
  80. return nil, err
  81. }
  82. defer conn.Close()
  83. arg := GetActivityParam{site_id, dbname, id, "0"}
  84. req, err := SetReqData(arg)
  85. if err != nil {
  86. return nil, err
  87. }
  88. res := &Response{}
  89. err = conn.GetProductWarmingActivity(req, res)
  90. if err != nil {
  91. return nil, err
  92. }
  93. res_data_de, err := GetResData(res)
  94. if err != nil {
  95. return nil, err
  96. }
  97. if res_data_de == "" {
  98. return nil, nil
  99. }
  100. var res_arr []map[string]string
  101. err = json.Unmarshal([]byte(res_data_de), &res_arr)
  102. if err != nil {
  103. return nil, err
  104. }
  105. var activitys Activitys
  106. if len(res_arr) > 0 {
  107. var start int
  108. for _, item := range res_arr {
  109. start, err = strconv.Atoi(item["Starttime"])
  110. if err != nil {
  111. log.Println(err)
  112. }
  113. activitys = append(activitys, Activity{
  114. Id: item["Id"],
  115. Start: start,
  116. })
  117. }
  118. }
  119. sort.Sort(activitys)
  120. var list []map[string]string = make([]map[string]string, 0)
  121. if len(activitys) > 0 {
  122. for _, v := range activitys {
  123. for _, old := range res_arr {
  124. if v.Id == old["Id"] {
  125. list = append(list, old)
  126. break
  127. }
  128. }
  129. }
  130. }
  131. return list, nil
  132. }
  133. /**
  134. * 获取商品进行中活动
  135. * 2021/10/06
  136. * GZ
  137. */
  138. func GetProductAllActivity(site_id, dbname, id string, url ...string) ([]map[string]interface{}, error) {
  139. conn, err := rpc_server_conn(url...)
  140. if err != nil {
  141. return nil, err
  142. }
  143. defer conn.Close()
  144. arg := GetActivityParam{site_id, dbname, id, "0"}
  145. req, err := SetReqData(arg)
  146. if err != nil {
  147. return nil, err
  148. }
  149. res := &Response{}
  150. err = conn.GetProductAllActivity(req, res)
  151. if err != nil {
  152. return nil, err
  153. }
  154. res_data_de, err := GetResData(res)
  155. if err != nil {
  156. return nil, err
  157. }
  158. if res_data_de == "" {
  159. return nil, nil
  160. }
  161. var res_arr []map[string]interface{}
  162. err = json.Unmarshal([]byte(res_data_de), &res_arr)
  163. if err != nil {
  164. log.Println(err)
  165. return nil, err
  166. }
  167. var activitys Activitys
  168. if len(res_arr) > 0 {
  169. var start int
  170. for _, item := range res_arr {
  171. start = helper.ToInt(item["starttime"])
  172. activitys = append(activitys, Activity{
  173. Id: helper.ToStr(item["id"]),
  174. Start: start,
  175. })
  176. }
  177. }
  178. sort.Sort(activitys)
  179. var list []map[string]interface{} = make([]map[string]interface{}, 0)
  180. if len(activitys) > 0 {
  181. for _, v := range activitys {
  182. for _, old := range res_arr {
  183. if v.Id == helper.ToStr(old["id"]) {
  184. list = append(list, old)
  185. break
  186. }
  187. }
  188. }
  189. }
  190. return list, nil
  191. }