2
0

api_bbs_w_tabom_post.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. package route
  2. import (
  3. "opennamu/route/tool"
  4. "strconv"
  5. "strings"
  6. )
  7. func Api_bbs_w_tabom_post(config tool.Config) string {
  8. db := tool.DB_connect()
  9. defer tool.DB_close(db)
  10. other_set := map[string]string{}
  11. json.Unmarshal([]byte(config.Other_set), &other_set)
  12. sub_code := other_set["sub_code"]
  13. sub_code_parts := strings.Split(sub_code, "-")
  14. bbs_num := ""
  15. post_num := ""
  16. if len(sub_code_parts) > 1 {
  17. bbs_num = sub_code_parts[0]
  18. post_num = sub_code_parts[1]
  19. }
  20. return_data := make(map[string]any)
  21. if !tool.Check_acl(db, "", "", "bbs_comment", config.IP) {
  22. return_data["response"] = "require auth"
  23. } else {
  24. no_data := ""
  25. exist := tool.QueryRow_DB(
  26. db,
  27. "select set_data from bbs_data where set_name = 'tabom_list' and set_data = ? and set_id = ? and set_code = ?",
  28. []any{ &no_data },
  29. config.IP, bbs_num, post_num,
  30. )
  31. if !exist {
  32. return_data["response"] = "ok"
  33. tabom_count := ""
  34. exsit := tool.QueryRow_DB(
  35. db,
  36. "select set_data from bbs_data where set_name = 'tabom_count' and set_id = ? and set_code = ?",
  37. []any{ &tabom_count },
  38. bbs_num, post_num,
  39. )
  40. if !exsit {
  41. tool.Exec_DB(
  42. db,
  43. "insert into bbs_data (set_name, set_data, set_id, set_code) values ('tabom_count', ?, ?, ?)",
  44. tabom_count, bbs_num, post_num,
  45. )
  46. }
  47. tabom_count_int := tool.Str_to_int(tabom_count)
  48. tabom_count_int += 1
  49. tabom_count_str := strconv.Itoa(tabom_count_int)
  50. tool.Exec_DB(
  51. db,
  52. "update bbs_data set set_data = ? where set_name = 'tabom_count' and set_id = ? and set_code = ?",
  53. tabom_count_str, bbs_num, post_num,
  54. )
  55. tool.Exec_DB(
  56. db,
  57. "insert into bbs_data (set_name, set_data, set_id, set_code) values ('tabom_list', ?, ?, ?)",
  58. config.IP, bbs_num, post_num,
  59. )
  60. } else {
  61. return_data["response"] = "same user exist"
  62. }
  63. }
  64. json_data, _ := json.Marshal(return_data)
  65. return string(json_data)
  66. }