aichart.service.ts 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455
  1. import { Injectable } from '@angular/core';
  2. import * as Parse from 'parse';
  3. import { Router } from '@angular/router';
  4. import { HttpService } from './http.service';
  5. @Injectable({
  6. providedIn: 'root',
  7. })
  8. export class AiChatService {
  9. isLoggedIn = false;
  10. company: string = 'Qje9D4bqol';
  11. emojis: Array<any> = [];
  12. userLevelColor:any = {
  13. '1':{
  14. color:'#fff'
  15. },
  16. '2':{
  17. color:'#0ec52e'
  18. },
  19. '3':{
  20. color:'#377cf7'
  21. },
  22. '4':{
  23. color:'#cbb013'
  24. },
  25. '5':{
  26. color:'#ec760c'
  27. },
  28. '6':{
  29. color:'#ec0cce'
  30. },
  31. '7':{
  32. color:'#8d0cec'
  33. },
  34. '8':{
  35. color:'#dd0a0a'
  36. },
  37. }
  38. authorLevelColor:any = {
  39. '1':{
  40. color:'#10b590'
  41. },
  42. '2':{
  43. color:'#dd70ff'
  44. },
  45. '3':{
  46. color:'#ed9647'
  47. },
  48. '4':{
  49. color:'#fb73ca'
  50. },
  51. '5':{
  52. color:'#efeb38'
  53. },
  54. '6':{
  55. color:'#c11010'
  56. }
  57. }
  58. get identity(): boolean {
  59. let profile = JSON.parse(localStorage.getItem('profile') || '{}');
  60. return profile?.identyType === 'anchor';
  61. }
  62. constructor(private http: HttpService) {
  63. this.initEmoji();
  64. }
  65. initEmoji() {
  66. let emojiChar =
  67. '☺-😋-😌-😍-😏-😜-😝-😞-😔-😪-😁-😂-😃-😅-😆-👿-😒-😓-😔-😏-😖-😘-😚-😒-😡-😢-😣-😤-😢-😨-😳-😵-😷-😸-😻-😼-😽-😾-😿-🙊-🙋-🙏-✈-🚇-🚃-🚌-🍄-🍅-🍆-🍇-🍈-🍉-🍑-🍒-🍓-🐔-🐶-🐷-👦-👧-👱-👩-👰-👨-👲-👳-💃-💄-💅-💆-💇-🌹-💑-💓-💘-🚲';
  68. let emojiKey = [
  69. '60a',
  70. '60b',
  71. '60c',
  72. '60d',
  73. '60f',
  74. '61b',
  75. '61d',
  76. '61e',
  77. '61f',
  78. '62a',
  79. '62c',
  80. '602',
  81. '603',
  82. '605',
  83. '606',
  84. '608',
  85. '612',
  86. '613',
  87. '614',
  88. '615',
  89. '616',
  90. '618',
  91. '619',
  92. '620',
  93. '621',
  94. '623',
  95. '624',
  96. '625',
  97. '627',
  98. '629',
  99. '633',
  100. '635',
  101. '637',
  102. '63a',
  103. '63b',
  104. '63c',
  105. '63d',
  106. '63e',
  107. '63f',
  108. '64a',
  109. '64b',
  110. '64f',
  111. '681',
  112. '68a',
  113. '68b',
  114. '68c',
  115. '344',
  116. '345',
  117. '346',
  118. '347',
  119. '348',
  120. '349',
  121. '351',
  122. '352',
  123. '353',
  124. '414',
  125. '415',
  126. '416',
  127. '466',
  128. '467',
  129. '468',
  130. '469',
  131. '470',
  132. '471',
  133. '472',
  134. '473',
  135. '483',
  136. '484',
  137. '485',
  138. '486',
  139. '487',
  140. '490',
  141. '491',
  142. '493',
  143. '498',
  144. '6b4',
  145. ];
  146. let emojis = [];
  147. let emojiCharArr = emojiChar.split('-');
  148. for (let i in emojiKey) {
  149. let em = {
  150. char: emojiCharArr[i],
  151. emoji: '0x1f' + emojiKey[i],
  152. };
  153. emojis.push(em);
  154. }
  155. this.emojis = emojis;
  156. }
  157. async getAccountLog(): Promise<any> {
  158. const uid = Parse.User.current()?.id;
  159. let query = new Parse.Query('Account');
  160. query.equalTo('user', uid);
  161. query.notEqualTo('isDeleted', true);
  162. query.select('objectId');
  163. let account = await query.first();
  164. if (!account?.id) {
  165. return;
  166. }
  167. let sql = `SELECT alog."assetCount",TO_CHAR(alog."createdAt", 'YYYY-MM-DD HH24:MI:SS') AS time,
  168. (CASE WHEN alog."targetAccount" = '${account.id}' THEN 'recharge' ELSE 'used' END) cate,
  169. "assetType","orderNumber","desc"
  170. FROM "AccountLog" AS alog
  171. WHERE (alog."targetAccount" = '${account.id}' OR alog."fromAccount" = '${account.id}')
  172. AND alog."isVerified" IS TRUE
  173. AND alog."isDeleted" IS NOT TRUE
  174. ORDER BY alog."createdAt" DESC`;
  175. let data: any = await this.http.customSQL(sql);
  176. return data?.data;
  177. }
  178. async getWallet(uid: string): Promise<any> {
  179. const data = await this.http.httpRequst(
  180. 'https://server.fmode.cn/api/ailiao/wallet',
  181. { uid: uid },
  182. 'POST'
  183. );
  184. return data['data'];
  185. }
  186. /* 获取主播余额 */
  187. async getAuthorWallet(uid: string): Promise<any> {
  188. const data = await this.http.httpRequst(
  189. 'https://server.fmode.cn/api/ailiao/wallet/anthor',
  190. { uid: uid },
  191. 'POST'
  192. );
  193. return data['data'];
  194. }
  195. getFansAndFollow(uid: string): Promise<any> {
  196. let sql = `SELECT
  197. (SELECT COUNT(*) FROM "ProfileRadar" WHERE "fromUser" = '${uid}' AND "name" = '关注' AND "isDeleted" IS NOT TRUE) AS follow,
  198. (SELECT COUNT(*) FROM "ProfileRadar" WHERE "toUser" = '${uid}' AND "name" = '关注' AND "isDeleted" IS NOT TRUE) AS fans;`;
  199. return this.http.customSQL(sql);
  200. }
  201. async getGift(type?: string,id?:string): Promise<any> {
  202. let where = type ? `AND "type" = '${type}'` : ``;
  203. let whereId = id ? `AND "objectId" = '${id}'` : ``;
  204. let sql = `SELECT "objectId" AS "id","name","price","order","imgUrl","video","type","rightsMap","config"
  205. FROM "GiftModule"
  206. WHERE "company" = '${this.company}'
  207. AND "isDeleted" IS NOT TRUE
  208. ${where}
  209. ${whereId}
  210. ORDER BY "price"`;
  211. const data: any = await this.http.customSQL(sql);
  212. return data?.data;
  213. }
  214. getGiftLogCount(uid: string): Promise<any> {
  215. let sql = `SELECT SUM("index")
  216. FROM "LoveRender"
  217. WHERE "fromUser" ='${uid}'`;
  218. return this.http.customSQL(sql);
  219. }
  220. async getGiftList(uid: string, limit?: number, skip?: number): Promise<any> {
  221. let where = '';
  222. if (limit) {
  223. where = `OFFSET ${skip ?? 0} LIMIT ${limit}`;
  224. }
  225. let sql = `SELECT lr.name,lr.image
  226. FROM (
  227. SELECT *,ROW_NUMBER() OVER (PARTITION BY "gift" ORDER BY "createdAt" DESC) as rn
  228. FROM "LoveRender"
  229. WHERE "toUser" = '${uid}'
  230. AND "isDeleted" IS NOT TRUE
  231. ) lr
  232. WHERE lr.rn = 1
  233. ORDER BY lr."createdAt" DESC
  234. ${where}
  235. `;
  236. const data: any = await this.http.customSQL(sql);
  237. return data.data;
  238. }
  239. /* 获取好友列表 */
  240. async getFriends(uid: string): Promise<any> {
  241. let rejectsSql = `SELECT invited FROM "EventLog" WHERE "isDeleted" IS NOT TRUE AND "user" = '${uid}' AND "isAward" = TRUE `;
  242. let data: any = await this.http.customSQL(rejectsSql);
  243. let list = data.data;
  244. let notInclude = list?.map((item: any) => {
  245. return `'${item.invited}'`;
  246. });
  247. let sql = `SELECT u.avatar,u.nickname,u."objectId" AS uid,f."channel",
  248. f.deadline
  249. FROM
  250. (SELECT (CASE WHEN "friend" = '${uid}' THEN "user" ELSE "friend" END) fid,"channel",
  251. "Friends".config->'l0gF95BPLB' AS deadline --被删除的聊天记录时间
  252. FROM "Friends"
  253. WHERE "isDeleted" IS NOT TRUE
  254. AND "isPass" = TRUE
  255. AND ("friend" = '${uid}'
  256. OR "user" = '${uid}')
  257. GROUP BY fid,"channel",deadline) AS f
  258. LEFT JOIN "_User" AS u
  259. ON u."objectId" = f.fid
  260. ${notInclude.length > 0 ? `WHERE u."objectId" NOT IN (${notInclude})` : ''}
  261. `;
  262. return this.http.customSQL(sql);
  263. }
  264. async getRetFriends(uid: string): Promise<Parse.Object | undefined> {
  265. let query = new Parse.Query('EventLog');
  266. query.equalTo('user', Parse.User.current()?.id);
  267. query.equalTo('invited', uid);
  268. query.notEqualTo('isDeleted', false);
  269. // query.equalTo('isAward', true);
  270. query.select('isAward');
  271. return await query.first();
  272. }
  273. /* 获取系统通知 */
  274. getSysNotice(uid: string, limit?: number, skip?: number): Promise<any> {
  275. let sql = `SELECT
  276. "Friends"."objectId" fid,"friend","Friends"."user",
  277. (CASE WHEN "user" = '${uid}' THEN '请求添加' || u.name ||'为好友'
  278. ELSE '收到'||us.name||'的好友申请' END) title,
  279. (CASE WHEN "user" = '${uid}' THEN us.avatar
  280. ELSE u.avatar END) avatar,
  281. (CASE WHEN "user" = '${uid}' THEN us."objectId"
  282. ELSE u."objectId" END) tuid,
  283. (CASE WHEN "isPass" = TRUE THEN '200'
  284. WHEN "isPass" = FALSE THEN '101'
  285. ELSE '100' END) status,
  286. "Friends"."createdAt"
  287. FROM "Friends"
  288. LEFT JOIN "_User" AS u
  289. ON u."objectId" = "Friends"."user"
  290. LEFT JOIN "_User" AS us
  291. ON us."objectId" = "Friends"."friend"
  292. WHERE "Friends"."company" = '${this.company}'
  293. AND (friend = '${uid}' OR "user" = '${uid}')
  294. ORDER BY "Friends"."createdAt" DESC
  295. OFFSET ${skip || 0} LIMIT ${limit || 20}`;
  296. return this.http.customSQL(sql);
  297. }
  298. async getLinkUsers(params: {
  299. company?:string,
  300. value?:string,
  301. limit?:number,
  302. skip?:number,
  303. sex?:string,
  304. city?:string
  305. }): Promise<any> {
  306. params['company'] = this.company;
  307. let baseurl = 'https://server.fmode.cn/api/ailiao/users';
  308. const data = await this.http.httpRequst(baseurl, params, 'POST');
  309. return data?.data;
  310. }
  311. /* 赠送礼物 */
  312. async putGift(toUid: string, gid: string, giftCount?: number): Promise<any> {
  313. let baseurl = 'https://server.fmode.cn/api/ailiao/save_gift';
  314. let reqBody = {
  315. fromUid: Parse.User.current()?.id,
  316. toUid: toUid,
  317. gid: gid,
  318. index: giftCount ?? 1,
  319. };
  320. return await this.http.httpRequst(baseurl, reqBody, 'POST');
  321. }
  322. /** 获取房间列表
  323. * @star 星级
  324. * @sex 主播性别
  325. * */
  326. async getRooms(params?: any): Promise<any> {
  327. params['company'] = this.company;
  328. let baseurl = 'https://server.fmode.cn/api/ailiao/roomlist';
  329. const data = await this.http.httpRequst(baseurl, params, 'POST');
  330. return data?.data;
  331. }
  332. async getOrderAnchor(limit?: number) {
  333. let sql = `SELECT us."objectId",us."nickname",us."avatar",
  334. COALESCE(SUM(llog.gold ),0) AS "credit"
  335. FROM "LoveRender" AS llog
  336. LEFT JOIN "_User" us
  337. ON us."objectId" = llog."toUser"
  338. WHERE llog.company = '${this.company}'
  339. AND llog."isDeleted" IS NOT TRUE
  340. GROUP BY us."objectId",us."username"
  341. ORDER BY "credit" DESC LIMIT ${limit ?? 10}`;
  342. let res: any = await this.http.customSQL(sql);
  343. return res.data;
  344. }
  345. /* 获取直播时长 */
  346. async getLiveActiveLog(logid: string) {
  347. let sql = `SELECT SUM("duration") FROM "LiveActiveLog" WHERE "liveLog" = '${logid}'`;
  348. let res: any = await this.http.customSQL(sql);
  349. return res.data[0]?.sum;
  350. }
  351. async get_duration(rid: string, uid: string) {
  352. let url = 'https://server.fmode.cn/api/ailiao/remain_second';
  353. let params = {
  354. rid: rid,
  355. uid: uid,
  356. };
  357. let data = await this.http.httpRequst(url, params, 'POST');
  358. console.log(data);
  359. return data.data ?? 0;
  360. }
  361. //星座
  362. getConstellation(idCard: string): string {
  363. // 提取出生日期部分
  364. const birthDateStr = idCard.substring(6, 14);
  365. const year = parseInt(birthDateStr.substring(0, 4), 10);
  366. const month = parseInt(birthDateStr.substring(4, 6), 10);
  367. const day = parseInt(birthDateStr.substring(6, 8), 10);
  368. // 定义星座边界
  369. const constellationBoundaries = [
  370. { name: '摩羯座', start: new Date(year, 0, 20) },
  371. { name: '水瓶座', start: new Date(year, 1, 19) },
  372. { name: '双鱼座', start: new Date(year, 2, 20) },
  373. { name: '白羊座', start: new Date(year, 3, 20) },
  374. { name: '金牛座', start: new Date(year, 4, 21) },
  375. { name: '双子座', start: new Date(year, 5, 21) },
  376. { name: '巨蟹座', start: new Date(year, 6, 22) },
  377. { name: '狮子座', start: new Date(year, 7, 23) },
  378. { name: '处女座', start: new Date(year, 8, 23) },
  379. { name: '天秤座', start: new Date(year, 9, 23) },
  380. { name: '天蝎座', start: new Date(year, 10, 23) },
  381. { name: '射手座', start: new Date(year, 11, 22) },
  382. { name: '摩羯座', start: new Date(year + 1, 0, 19) }, // 用于处理12月23日及之后的情况
  383. ];
  384. // 创建输入日期对象
  385. const inputDate = new Date(year, month - 1, day);
  386. // 查找对应的星座
  387. for (let i = 0; i < constellationBoundaries.length - 1; i++) {
  388. if (
  389. inputDate >= constellationBoundaries[i].start &&
  390. inputDate < constellationBoundaries[i + 1].start
  391. ) {
  392. return constellationBoundaries[i].name;
  393. }
  394. }
  395. // 默认返回摩羯座(理论上不会执行到这里)
  396. return '摩羯座';
  397. }
  398. async getPost(limit?: number, skip?: number, uid?: string): Promise<any> {
  399. let sql = `SELECT "DramaPost"."objectId", "DramaPost".content,"DramaPost".images,"DramaPost"."isVerify",
  400. us."objectId" uid, us.avatar,us.nickname,"Profile"."identyType",TO_CHAR("DramaPost"."createdAt", 'YYYY-MM-DD HH24:MI') AS formatted_date,
  401. (SELECT "isVerify" FROM "DramaPostLog"
  402. WHERE "DramaPostLog"."dramaPost" = "DramaPost"."objectId"
  403. AND "DramaPostLog"."user" = '${Parse.User.current()?.id}'
  404. AND "DramaPostLog"."isDeleted" IS NOT TRUE
  405. LIMIT 1
  406. ) AS "isPostLog",
  407. (SELECT COUNT(*) FROM "DramaPostLog"
  408. WHERE "DramaPostLog"."dramaPost" = "DramaPost"."objectId"
  409. AND "DramaPostLog"."isDeleted" IS NOT TRUE
  410. ) AS "postCount",
  411. (SELECT "objectId" FROM "UserVip"
  412. WHERE "UserVip"."user" = "DramaPost"."user"
  413. AND "UserVip"."isDeleted" IS NOT TRUE
  414. AND DATE("UserVip"."expiredAt") >= now()
  415. ) AS "isVip"
  416. --(CASE WHEN DATE("DramaPost"."createdAt") >= now() THEN true ELSE false END)
  417. FROM "DramaPost"
  418. LEFT JOIN "_User" as us
  419. ON us."objectId" = "DramaPost"."user"
  420. LEFT JOIN "Profile"
  421. ON "Profile"."user" = "DramaPost"."user"
  422. WHERE "DramaPost"."company" = '${this.company}'
  423. AND "DramaPost"."isDeleted" IS NOT TRUE
  424. ${uid ? `AND "DramaPost"."user" = '${uid}'` : ''}
  425. ${uid ? `` : `AND "DramaPost"."isVerify" IS TRUE`}
  426. ORDER BY "DramaPost"."createdAt" DESC
  427. OFFSET ${skip ?? 0} LIMIT ${limit ?? 10}`;
  428. let res: any = await this.http.customSQL(sql);
  429. return res.data;
  430. }
  431. async getCommentScore(room:string){
  432. let sql = `SELECT (SUM("credit")/COUNT("objectId")) AS ave
  433. FROM "DramaPostLog"
  434. WHERE room = '${room}'
  435. `
  436. let res: any = await this.http.customSQL(sql);
  437. return res.data['ave'];
  438. }
  439. }