api_bbs_w_comment.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. package route
  2. import (
  3. "opennamu/route/tool"
  4. )
  5. func Api_bbs_w_comment_all(config tool.Config, sub_code string, already_auth_check bool, do_type string) []map[string]string {
  6. end_data := []map[string]string{}
  7. return_data := Api_bbs_w_comment_one(config, already_auth_check, do_type, sub_code)
  8. return_data_in := return_data["data"].([]map[string]string)
  9. for for_a := 0; for_a < len(return_data_in); for_a++ {
  10. end_data = append(end_data, return_data_in[for_a])
  11. temp := Api_bbs_w_comment_all(config, sub_code + "-" + return_data_in[for_a]["code"], already_auth_check, do_type)
  12. if len(temp) > 0 {
  13. for for_b := 0; for_b < len(temp); for_b++ {
  14. end_data = append(end_data, temp[for_b])
  15. }
  16. }
  17. }
  18. return end_data
  19. }
  20. func Api_bbs_w_comment(config tool.Config, do_type string, sub_code string) map[string]any {
  21. db := tool.DB_connect()
  22. defer tool.DB_close(db)
  23. if do_type == "length" {
  24. bbs_and_post_num := sub_code
  25. comment_length := "0"
  26. tool.QueryRow_DB(
  27. db,
  28. "select count(*) from bbs_data where set_name = 'comment_date' and set_id = ? order by set_code + 0 desc",
  29. []any{ &comment_length },
  30. bbs_and_post_num,
  31. )
  32. reply_length := "0"
  33. tool.QueryRow_DB(
  34. db,
  35. "select count(*) from bbs_data where set_name = 'comment_date' and set_id = ? order by set_code + 0 desc",
  36. []any{ &reply_length },
  37. bbs_and_post_num + "-%",
  38. )
  39. comment_length_int := tool.Str_to_int(comment_length)
  40. reply_length_int := tool.Str_to_int(reply_length)
  41. length_int := comment_length_int + reply_length_int
  42. data_list := map[string]any{
  43. "response" : "ok",
  44. "comment" : comment_length,
  45. "reply" : reply_length,
  46. "data" : length_int,
  47. }
  48. return data_list
  49. } else {
  50. return_data := make(map[string]any)
  51. temp := []map[string]string{}
  52. if !tool.Check_acl(db, "", "", "bbs_comment", config.IP) {
  53. return_data["response"] = "require auth"
  54. } else {
  55. temp = Api_bbs_w_comment_all(config, sub_code, true, do_type)
  56. }
  57. return_data["response"] = "ok"
  58. return_data["data"] = temp
  59. return return_data
  60. }
  61. }