LNHttpManager+GameMate.swift 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  1. //
  2. // LNHttpManager+GameMate.swift
  3. // Lanu
  4. //
  5. // Created by OneeChan on 2025/11/20.
  6. //
  7. import Foundation
  8. private let kNetPath_GameMate_Category = "/biz/categorys"
  9. private let kNetPath_GameMate_Filter = "/biz/categorys/filter/condition"
  10. private let kNetPath_GameMate_List = "/skill/list"
  11. private let kNetPath_GameMate_Skills = "/skill/user/goods"
  12. private let kNetPath_GameMate_Info = "/user/playmate/info"
  13. private let kNetPath_GameMate_Skill_Detail = "/skill/detail"
  14. private let kNetPath_GameMate_Score = "/user/playmate/charmStar"
  15. private let kNetPath_GameMate_Skill_Comment = "/skill/goods/comments"
  16. private let kNetPath_GameMate_Search = "/playmate/search"
  17. private let kNetPath_GameMate_Mixed_Search = "/search/mixed/list"
  18. private let kNetPath_GameMate_Join_Infos = "/playmate/apply/curInfo"
  19. private let kNetPath_GameMate_Join_Improve_BaseInfo = "/playmate/apply/improve/info"
  20. private let kNetPath_GameMate_Join_Skill_Field = "/playmate/apply/setp3/info/get"
  21. private let kNetPath_GameMate_Join_Apply = "/playmate/apply/submit"
  22. private let kNetPath_GameMate_Settings_Info = "/playmate/business/info"
  23. private let kNetPath_GameMate_Settings_Switch = "/playmate/business/switch"
  24. private let kNetPath_GameMate_Settings_Time = "/playmate/getAcceptSet"
  25. private let kNetPath_GameMate_Settings_Time_Set = "/playmate/acceptSet"
  26. private let kNetPath_GameMate_Settings_Skill_List = "/playmate/skill/list"
  27. private let kNetPath_GameMate_Visitors = "/user/visitors"
  28. private let kNetPath_GameMate_Skill_Switch = "/skill/switch/get"
  29. private let kNetPath_GameMate_Skill_Switch_Set = "/skill/switch/set"
  30. private let kNetPath_GameMate_Skill_Fields = "/skill/editInfo/get"
  31. private let kNetPath_GameMate_Skill_Edit = "/skill/edit"
  32. private let kNetPath_GameMate_AutoReply_Switch = "/playmate/autoWelcome/switch"
  33. private let kNetPath_GameMate_AutoReply_List = "/playmate/welcome/list"
  34. private let kNetPath_GameMate_AutoReply_Create = "/playmate/welcome/create"
  35. private let kNetPath_GameMate_AutoReply_Update = "/playmate/welcome/update"
  36. private let kNetPath_GameMate_AutoReply_Delete = "/playmate/welcome/delete"
  37. private let kNetPath_GameMate_AutoReply_Send = "/playmate/welcome/trigger"
  38. private let kNetPath_GameMate_AutoReply_Mark = "/playmate/push/chat/submit"
  39. private let kNetPath_GameMate_AutoReply_Query = "/playmate/push/chat/quota"
  40. private let kNetPath_GameMate_PotentialUsers_List = "/playmate/push/list"
  41. enum LNGameMateAgeRange: Int, CaseIterable {
  42. case all = -1
  43. case `15-25` = 0
  44. case `25-35` = 1
  45. case `>35` = 2
  46. var text: String {
  47. switch self {
  48. case .`15-25`: "15-25"
  49. case .`25-35`: "25-35"
  50. case .`>35`: "> 35"
  51. case .all: .init(key: "A00008")
  52. }
  53. }
  54. }
  55. enum LNGameMatePriceRange: Int, CaseIterable {
  56. case all = -1
  57. case `0-10` = 0
  58. case `10-15` = 1
  59. case `15-25` = 2
  60. case `25-50` = 3
  61. case `>50` = 4
  62. var text: String {
  63. switch self {
  64. case .`0-10`: "0-10"
  65. case .`10-15`: "10-15"
  66. case .`15-25`: "15-25"
  67. case .`25-50`: "25-50"
  68. case .`>50`: "> 50"
  69. case .all: .init(key: "A00008")
  70. }
  71. }
  72. }
  73. enum LNGameMateGenderRange: Int, CaseIterable {
  74. case all = -1
  75. case unknow = 0
  76. case male = 1
  77. case female = 2
  78. var text: String {
  79. switch self {
  80. case .all: .init(key: "A00008")
  81. case .unknow: .init(key: "A00016")
  82. case .male: .init(key: "A00014")
  83. case .female: .init(key: "A00015")
  84. }
  85. }
  86. }
  87. class LNGameMateFilter {
  88. var ageRange: LNGameMateAgeRange = .all
  89. var gender: LNGameMateGenderRange = .all
  90. var areCode: String = ""
  91. var sortByStar: LNSortedType = .none
  92. var sortByPrice: LNSortedType = .none
  93. var priceRange: LNGameMatePriceRange = .all
  94. var categoryFilters: [(fieldCode: String, filterValues: [String])] = []
  95. }
  96. // MARK: 获取大品类类型
  97. extension LNHttpManager {
  98. func getGameCategories(completion: @escaping(LNGameTypeListResponse?, LNHttpError?) -> Void) {
  99. post(path: kNetPath_GameMate_Category, completion: completion)
  100. }
  101. func getGameFilterConfig(completion: @escaping (LNSkillFilterConfigList?, LNHttpError?) -> Void) {
  102. post(path: kNetPath_GameMate_Filter, completion: completion)
  103. }
  104. }
  105. // MARK: 获取陪玩师列表
  106. extension LNHttpManager {
  107. func getGameMateList(
  108. topCategory: String, category: String?,
  109. filter: LNGameMateFilter, size: Int, next: String,
  110. completion: @escaping (LNGameMateListResponse?, LNHttpError?) -> Void)
  111. {
  112. var params: [String: Any] = [
  113. "firstCode": topCategory,
  114. "code": category ?? "",
  115. "ageRange": filter.ageRange.rawValue,
  116. "gender": filter.gender.rawValue,
  117. "areCode": filter.areCode,
  118. "sortByStar": filter.sortByStar.rawValue,
  119. "sortByPrice": filter.sortByPrice.rawValue,
  120. "priceRange": filter.priceRange.rawValue,
  121. "page": [
  122. "size": size,
  123. "next": next
  124. ]
  125. ]
  126. var filters: [[String: any Encodable]] = []
  127. for item in filter.categoryFilters {
  128. filters.append([
  129. "fieldCode": item.fieldCode,
  130. "filterValues": item.filterValues
  131. ])
  132. }
  133. if !filters.isEmpty {
  134. params["categoryFilters"] = filters
  135. }
  136. post(path: kNetPath_GameMate_List,
  137. params: params,
  138. completion: completion)
  139. }
  140. }
  141. // MARK: 陪玩师信息查询
  142. extension LNHttpManager {
  143. func getUserSkills(uid: String, completion: @escaping (LNGameMateSkillListResponse?, LNHttpError?) -> Void) {
  144. post(path: kNetPath_GameMate_Skills, params: ["id": uid], completion: completion)
  145. }
  146. func getGameMateInfo(uid: String, completion: @escaping (LNGameMateInfoResponse?, LNHttpError?) -> Void) {
  147. post(path: kNetPath_GameMate_Info, params: ["id": uid], completion: completion)
  148. }
  149. func getSkillDetail(skillId: String, completion: @escaping (LNGameMateSkillDetailVO?, LNHttpError?) -> Void) {
  150. post(path: kNetPath_GameMate_Skill_Detail, params: ["id": skillId], completion: completion)
  151. }
  152. func searchGameMate(keyword: String, size: Int,
  153. next: String,
  154. completion: @escaping (LNGameMateSearchResponse?, LNHttpError?) -> Void) {
  155. post(path: kNetPath_GameMate_Search, params: [
  156. "keyword": keyword,
  157. "page": [
  158. "size": size,
  159. "next": next
  160. ]
  161. ], completion: completion)
  162. }
  163. func mixSearch(keyword: String, completion: @escaping (LNMixSearchResponse?, LNHttpError?) -> Void) {
  164. post(path: kNetPath_GameMate_Mixed_Search, params: [
  165. "keyword": keyword
  166. ], completion: completion)
  167. }
  168. func scoreGameMate(uid: String, score: Int, completion: @escaping (LNHttpError?) -> Void) {
  169. post(path: kNetPath_GameMate_Score, params: [
  170. "userNo": uid,
  171. "star": score
  172. ], completion: completion)
  173. }
  174. func getSkillCommentList(id: String, size: Int, next: String,
  175. completion: @escaping (LNSkillCommentListResponse?, LNHttpError?) -> Void) {
  176. post(path: kNetPath_GameMate_Skill_Comment, params: [
  177. "skillId": id,
  178. "page": [
  179. "size": size,
  180. "next": next
  181. ]
  182. ], completion: completion)
  183. }
  184. }
  185. // MARK: 陪玩师申请
  186. class LNCreateSkillFieldInfo {
  187. var fieldCode: String = ""
  188. var value: (any Encodable)?
  189. var duration: Int?
  190. }
  191. class LNCreateSkillFieldsInfo {
  192. var bizCategoryCode = ""
  193. var fields: [LNCreateSkillFieldInfo] = []
  194. }
  195. extension LNHttpManager {
  196. func getJoinGameMateInfo(completion: @escaping (LNJoinUsInputInfosResponse?, LNHttpError?) -> Void) {
  197. post(path: kNetPath_GameMate_Join_Infos, completion: completion)
  198. }
  199. func setJoinGameMateBaseInfo(
  200. info: LNJoinUsBaseInfoVO,
  201. completion: @escaping (LNJoinUsInputInfosResponse?, LNHttpError?) -> Void)
  202. {
  203. post(path: kNetPath_GameMate_Join_Improve_BaseInfo, params: [
  204. "avatar": info.avatar,
  205. "nickname": info.nickname,
  206. "gender": info.gender.rawValue,
  207. "birthday": info.birthday,
  208. "intro": info.intro,
  209. "languageCodes": info.languageCodes
  210. ], completion: completion)
  211. }
  212. func getCreateSkillFields(id: String, completion: @escaping (LNCreateSkillInputFieldsVO?, LNHttpError?) -> Void) {
  213. post(path: kNetPath_GameMate_Join_Skill_Field, params: [
  214. "id": id
  215. ], completion: completion)
  216. }
  217. func createSkill(info: LNCreateSkillFieldsInfo, completion: @escaping (LNHttpError?) -> Void) {
  218. var fields: [[String: Any]] = []
  219. info.fields.forEach {
  220. var field: [String: Any] = [
  221. "fieldCode": $0.fieldCode,
  222. "value": $0.value as Any
  223. ]
  224. if let duration = $0.duration {
  225. field["duration"] = duration
  226. }
  227. fields.append(field)
  228. }
  229. post(path: kNetPath_GameMate_Join_Apply, params: [
  230. "bizCategoryCode": info.bizCategoryCode,
  231. "fields": fields
  232. ], completion: completion)
  233. }
  234. }
  235. // MARK: 陪玩师管理
  236. class LNEditSkillFieldsInfo {
  237. var skillId: String = ""
  238. var apply: Bool = false
  239. var fields: [LNCreateSkillFieldInfo] = []
  240. }
  241. extension LNHttpManager {
  242. func getGameMateManagerInfo(completion: @escaping (LNGameMateManagerInfo?, LNHttpError?) -> Void) {
  243. post(path: kNetPath_GameMate_Settings_Info, completion: completion)
  244. }
  245. func enableGameMate(open: Bool, completion: @escaping (LNHttpError?) -> Void) {
  246. post(path: kNetPath_GameMate_Settings_Switch, params: [
  247. "open": open
  248. ], completion: completion)
  249. }
  250. func getOrderAccetpConfig(completion: @escaping (LNOrderAcceptConfig?, LNHttpError?) -> Void) {
  251. post(path: kNetPath_GameMate_Settings_Time, completion: completion)
  252. }
  253. func setOrderAcceptConfig(config: LNOrderAcceptConfig, completion: @escaping (LNHttpError?) -> Void) {
  254. post(path: kNetPath_GameMate_Settings_Time_Set, params: [
  255. "timeRange": config.timeRange,
  256. "weekNums": config.weekNums.compactMap({ $0.rawValue })
  257. ], completion: completion)
  258. }
  259. func getMySkillList(onlyOpen: Bool = false, completion: @escaping (LNMySkillListResponse?, LNHttpError?) -> Void) {
  260. var params: [String: Any] = [:]
  261. if onlyOpen {
  262. params["open"] = true
  263. }
  264. post(path: kNetPath_GameMate_Settings_Skill_List, params: params, completion: completion)
  265. }
  266. func enableSkill(skillId: String, open: Bool, mainSkill: Bool? = nil, completion: @escaping (LNHttpError?) -> Void) {
  267. var params: [String: (any Encodable)] = [
  268. "skillId": skillId,
  269. "open": open
  270. ]
  271. if let mainSkill {
  272. params["mainSkill"] = mainSkill
  273. }
  274. post(path: kNetPath_GameMate_Skill_Switch_Set, params: params, completion: completion)
  275. }
  276. func getVisitorsList(next: String, size: Int, completion: @escaping (LNVisitorsListResponse?, LNHttpError?) -> Void) {
  277. post(path: kNetPath_GameMate_Visitors, params: [
  278. "size": size,
  279. "next": next
  280. ], completion: completion)
  281. }
  282. func getSkillEditFields(id: String, completion: @escaping (LNSkillEditFieldsResponse?, LNHttpError?) -> Void) {
  283. post(path: kNetPath_GameMate_Skill_Fields, params: [
  284. "id": id
  285. ], completion: completion)
  286. }
  287. func commitSkillEdit(info: LNEditSkillFieldsInfo, completion: @escaping (LNHttpError?) -> Void) {
  288. var fields: [[String: Any]] = []
  289. info.fields.forEach {
  290. var field: [String: Any] = [
  291. "fieldCode": $0.fieldCode,
  292. "value": $0.value as Any
  293. ]
  294. if let duration = $0.duration {
  295. field["duration"] = duration
  296. }
  297. fields.append(field)
  298. }
  299. post(path: kNetPath_GameMate_Skill_Edit, params: [
  300. "skillId": info.skillId,
  301. "apply": info.apply,
  302. "fields": fields
  303. ], completion: completion)
  304. }
  305. func getSkillSwitchInfo(id: String, completion: @escaping (LNSkillSwitchResponse?, LNHttpError?) -> Void) {
  306. post(path: kNetPath_GameMate_Skill_Switch, params: [
  307. "id": id
  308. ], completion: completion)
  309. }
  310. }
  311. // MARK: 欢迎语(自动回复)
  312. extension LNHttpManager {
  313. func enableAutoReplay(on: Bool, completion: @escaping (LNHttpError?) -> Void) {
  314. post(path: kNetPath_GameMate_AutoReply_Switch, params: [
  315. "autoWelcomeOpen": on
  316. ], completion: completion)
  317. }
  318. func getAutoReplayList(completion: @escaping (LNAutoReplyResponse?, LNHttpError?) -> Void) {
  319. post(path: kNetPath_GameMate_AutoReply_List, completion: completion)
  320. }
  321. func deleteAutoReplay(id: String, completion: @escaping (LNHttpError?) -> Void) {
  322. post(path: kNetPath_GameMate_AutoReply_Delete, params: [
  323. "id": id
  324. ], completion: completion)
  325. }
  326. func createAutoReplay(item: LNAutoReplyVO, completion: @escaping (LNHttpError?) -> Void) {
  327. post(path: kNetPath_GameMate_AutoReply_Create, params: [
  328. "type": item.type.rawValue,
  329. "textContent": item.textContent,
  330. "voiceUrl": item.voiceUrl,
  331. "voiceDuration": item.voiceDuration
  332. ], completion: completion)
  333. }
  334. func updateAutoReplay(item: LNAutoReplyVO, completion: @escaping (LNHttpError?) -> Void) {
  335. post(path: kNetPath_GameMate_AutoReply_Update, params: [
  336. "id": item.id,
  337. "type": item.type.rawValue,
  338. "textContent": item.textContent,
  339. "voiceUrl": item.voiceUrl,
  340. "voiceDuration": item.voiceDuration
  341. ], completion: completion)
  342. }
  343. func triggerAutoReplayIfNeed(uid: String, completion: @escaping (LNHttpError?) -> Void) {
  344. post(path: kNetPath_GameMate_AutoReply_Send, params: [
  345. "playmateUserNo": uid
  346. ], completion: completion)
  347. }
  348. func markUseAutoReplay(uid: String, completion: @escaping (LNHttpError?) -> Void) {
  349. post(path: kNetPath_GameMate_AutoReply_Mark, params: [
  350. "userNo": uid
  351. ], completion: completion)
  352. }
  353. func fetchAutoReplyQuota(uid: String, completion: @escaping (LNAutoReplyQuotaResponse?, LNHttpError?) -> Void) {
  354. post(path: kNetPath_GameMate_AutoReply_Query, params: [
  355. "userNo": uid
  356. ], completion: completion)
  357. }
  358. }
  359. // MARK: 潜在用户
  360. extension LNHttpManager {
  361. func getPotentialUsers(completion: @escaping (LNPotentialUsersResponse?, LNHttpError?) -> Void) {
  362. post(path: kNetPath_GameMate_PotentialUsers_List, completion: completion)
  363. }
  364. }