商品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.

81 lines
2.6 KiB

  1. package productrpc
  2. import (
  3. "strconv"
  4. "time"
  5. )
  6. /*
  7. * 检查商品状态
  8. * 2020/09/16
  9. */
  10. func CheckStatus(productInfo map[string]string, arrival_time string) (int, string) {
  11. if productInfo["Status"] == "0" { //是否在售
  12. return 8405, "商品已下架"
  13. if productInfo["Status"] == "2" { //是否在售
  14. return 8405, "商品已售罄"
  15. }
  16. }
  17. if productInfo["Status"] != "1" { //是否在售
  18. return 8405, "商品未上架"
  19. }
  20. if productInfo["AutoOnSale"] == "1" {
  21. if productInfo["EndSaleTime"] != "0" && productInfo["EndSaleTime"] != "" { //销售截止日期
  22. end_sale_time, _ := strconv.ParseInt(productInfo["EndSaleTime"], 10, 64)
  23. if time.Unix(end_sale_time, 0).Before(time.Now()) { //截止日期在当前时间之前
  24. return 8407, "商品已过有效期"
  25. }
  26. }
  27. if productInfo["StartSaleTime"] != "0" && productInfo["StartSaleTime"] != "" { //销售开始日期
  28. end_sale_time, _ := strconv.ParseInt(productInfo["StartSaleTime"], 10, 64)
  29. if time.Unix(end_sale_time, 0).After(time.Now()) { //开始日期在当前时间之后
  30. return 8406, "商品未开售"
  31. }
  32. }
  33. }
  34. if productInfo["ValidityType"] == "1" { //用户选定使用日期
  35. if arrival_time == "" {
  36. return 10005, "请选择使用日期"
  37. } else {
  38. advance, _ := strconv.Atoi(productInfo["Advance"]) //提前几天
  39. arrival_time_int64, err := strconv.ParseInt(arrival_time, 10, 64)
  40. var release_time_int64, end_time_int64 int64 = 0, 0
  41. now := time.Now().Unix()
  42. if err != nil { // 转换失败
  43. return 10005, "日期错误"
  44. }
  45. if arrival_time_int64 < now { //不能在当前时间之前
  46. return 10005, "日期选择错误"
  47. }
  48. if productInfo["Releasetime"] != "" && productInfo["Releasetime"] != "0" {
  49. release_time_int64, _ = strconv.ParseInt(productInfo["Releasetime"], 10, 64)
  50. }
  51. if productInfo["Endtime"] != "" && productInfo["Endtime"] != "0" {
  52. end_time_int64, err = strconv.ParseInt(productInfo["Endtime"], 10, 64)
  53. if err == nil {
  54. if advance > 0 {
  55. end_time_int64 = end_time_int64 - int64(advance*24*3600) //提前几天截止预约
  56. if end_time_int64 < now {
  57. return 8409, "已截止购买"
  58. }
  59. }
  60. }
  61. }
  62. if release_time_int64 > 0 && arrival_time_int64 < release_time_int64 { //未到服务时间
  63. return 10006, "请选择" + time.Unix(release_time_int64, 0).Format("2006-01-02") + "之后的日期"
  64. }
  65. if end_time_int64 > 0 {
  66. if arrival_time_int64 > end_time_int64 { //已过服务时间
  67. return 10006, "请选择" + time.Unix(end_time_int64, 0).Format("2006-01-02") + "之前的日期"
  68. }
  69. }
  70. }
  71. }
  72. return 0, ""
  73. }