aichart.service.ts 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540
  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 name,image,"gift",COUNT("gift")
  226. FROM "LoveRender"
  227. WHERE "toUser" = '${uid}'
  228. AND "isDeleted" IS NOT TRUE
  229. GROUP BY name,image,"gift"
  230. ${where}
  231. `;
  232. const data: any = await this.http.customSQL(sql);
  233. return data.data;
  234. }
  235. /* 获取好友列表 */
  236. async getFriends(uid: string,val?:string): Promise<any> {
  237. let where = val ? `WHERE u.nickname LIKE '%${val}%'` : ''
  238. let rejectsSql = `SELECT invited FROM "EventLog" WHERE "isDeleted" IS NOT TRUE AND "user" = '${uid}' AND "isAward" = TRUE `;
  239. let data: any = await this.http.customSQL(rejectsSql);
  240. let list = data.data;
  241. let notInclude = list?.map((item: any) => {
  242. return `'${item.invited}'`;
  243. });
  244. let sql = `SELECT u.avatar,u.nickname,u."objectId" AS uid,f."channel",
  245. f.deadline
  246. FROM
  247. (SELECT (CASE WHEN "friend" = '${uid}' THEN "user" ELSE "friend" END) fid,"channel",
  248. "Friends".config->'l0gF95BPLB' AS deadline --被删除的聊天记录时间
  249. FROM "Friends"
  250. WHERE "isDeleted" IS NOT TRUE
  251. AND "isPass" = TRUE
  252. AND ("friend" = '${uid}'
  253. OR "user" = '${uid}')
  254. GROUP BY fid,"channel",deadline) AS f
  255. LEFT JOIN "_User" AS u
  256. ON u."objectId" = f.fid
  257. ${notInclude.length > 0 ? `WHERE u."objectId" NOT IN (${notInclude}) AND u.nickname LIKE '%${val}%'` : where}
  258. `;
  259. return this.http.customSQL(sql);
  260. }
  261. async getRetFriends(uid: string): Promise<Parse.Object | undefined> {
  262. let query = new Parse.Query('EventLog');
  263. query.equalTo('user', Parse.User.current()?.id);
  264. query.equalTo('invited', uid);
  265. query.notEqualTo('isDeleted', false);
  266. // query.equalTo('isAward', true);
  267. query.select('isAward');
  268. return await query.first();
  269. }
  270. /* 获取系统通知 */
  271. getSysNotice(uid: string, limit?: number, skip?: number): Promise<any> {
  272. let sql = `SELECT
  273. "Friends"."objectId" fid,"friend","Friends"."user",
  274. (CASE WHEN "user" = '${uid}' THEN '请求添加' || us.name ||'为好友'
  275. ELSE '收到'||u.name||'的好友申请' END) title,
  276. (CASE WHEN "user" = '${uid}' THEN us.avatar
  277. ELSE u.avatar END) avatar,
  278. (CASE WHEN "user" = '${uid}' THEN us."objectId"
  279. ELSE u."objectId" END) tuid,
  280. (CASE WHEN "isPass" = TRUE THEN '200'
  281. WHEN "isPass" = FALSE THEN '101'
  282. ELSE '100' END) status,
  283. "Friends"."createdAt"
  284. FROM "Friends"
  285. LEFT JOIN "_User" AS u
  286. ON u."objectId" = "Friends"."user"
  287. LEFT JOIN "_User" AS us
  288. ON us."objectId" = "Friends"."friend"
  289. WHERE "Friends"."company" = '${this.company}'
  290. AND "Friends"."isDeleted" IS NOT TRUE
  291. AND (friend = '${uid}' OR "user" = '${uid}')
  292. ORDER BY "Friends"."createdAt" DESC
  293. OFFSET ${skip || 0} LIMIT ${limit || 20}`;
  294. return this.http.customSQL(sql);
  295. }
  296. async getLinkUsers(params: {
  297. company?: string;
  298. value?: string;
  299. limit?: number;
  300. skip?: number;
  301. sex?: string;
  302. city?: string;
  303. }): Promise<any> {
  304. params['company'] = this.company;
  305. let baseurl = 'https://server.fmode.cn/api/ailiao/users';
  306. const data = await this.http.httpRequst(baseurl, params, 'POST');
  307. return data?.data;
  308. }
  309. /* 赠送礼物 */
  310. async putGift(toUid: string, gid: string, giftCount?: number): Promise<any> {
  311. let baseurl = 'https://server.fmode.cn/api/ailiao/save_gift';
  312. let reqBody = {
  313. fromUid: Parse.User.current()?.id,
  314. toUid: toUid,
  315. gid: gid,
  316. index: giftCount ?? 1,
  317. };
  318. return await this.http.httpRequst(baseurl, reqBody, 'POST');
  319. }
  320. /** 获取房间列表
  321. * @star 星级
  322. * @sex 主播性别
  323. * */
  324. async getRooms(params?: any): Promise<any> {
  325. params['company'] = this.company;
  326. let baseurl = 'https://server.fmode.cn/api/ailiao/roomlist';
  327. const data = await this.http.httpRequst(baseurl, params, 'POST');
  328. return data?.data;
  329. }
  330. async getOrderAnchor(type?: string, limit?: number) {
  331. let sql = `SELECT us."objectId",us."nickname",us."avatar",ROUND(SUM("credit")::numeric, 2) AS credit
  332. FROM (
  333. SELECT COALESCE(SUM(llog.gold ),0) AS "credit",llog."toUser" AS uid
  334. FROM "LoveRender" AS llog
  335. WHERE llog.company = '${this.company}'
  336. AND llog."isDeleted" IS NOT TRUE
  337. GROUP BY llog."toUser"
  338. UNION
  339. SELECT SUM(lalog.duration / 60 * lalog.unit) "credit","Room"."user" AS uid
  340. FROM "LiveActiveLog" AS lalog
  341. LEFT JOIN "Room"
  342. ON lalog."room" = "Room"."objectId"
  343. WHERE lalog.company = '${this.company}'
  344. AND lalog."isDeleted" IS NOT TRUE
  345. GROUP BY "Room"."user"
  346. ) AS tbl
  347. LEFT JOIN "_User" us
  348. ON us."objectId" = tbl.uid
  349. GROUP BY us."objectId",us."username"
  350. ORDER BY SUM(tbl."credit") DESC LIMIT ${limit ?? 50}`;
  351. if (type == 'user') {
  352. sql = `SELECT us."objectId",us."nickname",us."avatar",ROUND(SUM("credit")::numeric, 2) AS credit
  353. FROM (
  354. SELECT COALESCE(SUM(llog.gold ),0) AS "credit",llog."fromUser" AS uid
  355. FROM "LoveRender" AS llog
  356. WHERE llog.company = '${this.company}'
  357. AND llog."isDeleted" IS NOT TRUE
  358. GROUP BY llog."fromUser"
  359. UNION
  360. SELECT SUM(lalog.duration / 60 * lalog.unit) "credit",lalog."user" AS uid
  361. FROM "LiveActiveLog" AS lalog
  362. WHERE lalog.company = '${this.company}'
  363. AND lalog."isDeleted" IS NOT TRUE
  364. GROUP BY lalog."user"
  365. ) AS tbl
  366. LEFT JOIN "_User" us
  367. ON us."objectId" = tbl.uid
  368. GROUP BY us."objectId",us."username"
  369. ORDER BY SUM(tbl."credit") DESC LIMIT ${limit ?? 50}`;
  370. }
  371. let res: any = await this.http.customSQL(sql);
  372. return res.data;
  373. }
  374. /* 获取直播时长 */
  375. async getLiveActiveLog(logid: string) {
  376. let sql = `SELECT SUM("duration") FROM "LiveActiveLog" WHERE "liveLog" = '${logid}'`;
  377. let res: any = await this.http.customSQL(sql);
  378. return res.data[0]?.sum;
  379. }
  380. async get_duration(rid: string, uid: string) {
  381. let url = 'https://server.fmode.cn/api/ailiao/remain_second';
  382. let params = {
  383. rid: rid,
  384. uid: uid,
  385. };
  386. let data = await this.http.httpRequst(url, params, 'POST');
  387. console.log(data);
  388. return data.data ?? 0;
  389. }
  390. //星座
  391. getConstellation(idCard: string): string {
  392. // 提取出生日期部分
  393. const birthDateStr = idCard.substring(6, 14);
  394. const year = parseInt(birthDateStr.substring(0, 4), 10);
  395. const month = parseInt(birthDateStr.substring(4, 6), 10);
  396. const day = parseInt(birthDateStr.substring(6, 8), 10);
  397. // 定义星座边界
  398. const constellationBoundaries = [
  399. { name: '摩羯座', start: new Date(year, 0, 20) },
  400. { name: '水瓶座', start: new Date(year, 1, 19) },
  401. { name: '双鱼座', start: new Date(year, 2, 20) },
  402. { name: '白羊座', start: new Date(year, 3, 20) },
  403. { name: '金牛座', start: new Date(year, 4, 21) },
  404. { name: '双子座', start: new Date(year, 5, 21) },
  405. { name: '巨蟹座', start: new Date(year, 6, 22) },
  406. { name: '狮子座', start: new Date(year, 7, 23) },
  407. { name: '处女座', start: new Date(year, 8, 23) },
  408. { name: '天秤座', start: new Date(year, 9, 23) },
  409. { name: '天蝎座', start: new Date(year, 10, 23) },
  410. { name: '射手座', start: new Date(year, 11, 22) },
  411. { name: '摩羯座', start: new Date(year + 1, 0, 19) }, // 用于处理12月23日及之后的情况
  412. ];
  413. // 创建输入日期对象
  414. const inputDate = new Date(year, month - 1, day);
  415. // 查找对应的星座
  416. for (let i = 0; i < constellationBoundaries.length - 1; i++) {
  417. if (
  418. inputDate >= constellationBoundaries[i].start &&
  419. inputDate < constellationBoundaries[i + 1].start
  420. ) {
  421. return constellationBoundaries[i].name;
  422. }
  423. }
  424. // 默认返回摩羯座(理论上不会执行到这里)
  425. return '摩羯座';
  426. }
  427. async getPost(limit?: number, skip?: number, uid?: string): Promise<any> {
  428. let sql = `SELECT "DramaPost"."objectId", "DramaPost".content,"DramaPost".images,"DramaPost"."isVerify",
  429. us."objectId" uid, us.avatar,us.nickname,"Profile"."identyType",TO_CHAR("DramaPost"."createdAt", 'YYYY-MM-DD HH24:MI') AS formatted_date,
  430. (SELECT "isVerify" FROM "DramaPostLog"
  431. WHERE "DramaPostLog"."dramaPost" = "DramaPost"."objectId"
  432. AND "DramaPostLog"."user" = '${Parse.User.current()?.id}'
  433. AND "DramaPostLog"."isDeleted" IS NOT TRUE
  434. LIMIT 1
  435. ) AS "isPostLog",
  436. (SELECT COUNT(*) FROM "DramaPostLog"
  437. WHERE "DramaPostLog"."dramaPost" = "DramaPost"."objectId"
  438. AND "DramaPostLog"."isDeleted" IS NOT TRUE
  439. LIMIT 1
  440. ) AS "postCount",
  441. (SELECT "objectId" FROM "UserVip"
  442. WHERE "UserVip"."user" = "DramaPost"."user"
  443. AND "UserVip"."isDeleted" IS NOT TRUE
  444. AND DATE("UserVip"."expiredAt") >= now()
  445. LIMIT 1
  446. ) AS "isVip"
  447. --(CASE WHEN DATE("DramaPost"."createdAt") >= now() THEN true ELSE false END)
  448. FROM "DramaPost"
  449. LEFT JOIN "_User" as us
  450. ON us."objectId" = "DramaPost"."user"
  451. LEFT JOIN "Profile"
  452. ON "Profile"."user" = "DramaPost"."user"
  453. WHERE "DramaPost"."company" = '${this.company}'
  454. AND "DramaPost"."isDeleted" IS NOT TRUE
  455. ${uid ? `AND "DramaPost"."user" = '${uid}'` : ''}
  456. ${uid ? `` : `AND "DramaPost"."isVerify" IS TRUE`}
  457. ORDER BY "DramaPost"."createdAt" DESC
  458. OFFSET ${skip ?? 0} LIMIT ${limit ?? 10}`;
  459. let res: any = await this.http.customSQL(sql);
  460. return res.data;
  461. }
  462. async getCommentScore(room: string) {
  463. let sql = `SELECT (SUM("credit")/COUNT("objectId")) AS ave
  464. FROM "DramaPostLog"
  465. WHERE room = '${room}'
  466. `;
  467. let res: any = await this.http.customSQL(sql);
  468. return res.data[0]['ave'];
  469. }
  470. async getRelation(limit?: number, skip?: number) {
  471. let uid = Parse.User.current()?.id;
  472. let sql = `SELECT us."objectId",us."nickname",us."avatar",ROUND(SUM("credit")::numeric, 2) AS credit
  473. FROM (
  474. SELECT COALESCE(SUM(llog.gold ),0) AS "credit",llog."toUser" AS uid
  475. FROM "LoveRender" AS llog
  476. WHERE llog.company = '${this.company}'
  477. AND llog."isDeleted" IS NOT TRUE
  478. AND llog."fromUser" = '${uid}'
  479. GROUP BY llog."toUser"
  480. UNION
  481. SELECT SUM(lalog.duration / 60 * lalog.unit) "credit","Room"."user" AS uid
  482. FROM "LiveActiveLog" AS lalog
  483. LEFT JOIN "Room"
  484. ON lalog."room" = "Room"."objectId"
  485. WHERE lalog.company = '${this.company}'
  486. AND lalog."isDeleted" IS NOT TRUE
  487. AND lalog."user" = '${uid}'
  488. GROUP BY "Room"."user"
  489. ) AS tbl
  490. LEFT JOIN "_User" us
  491. ON us."objectId" = tbl.uid
  492. GROUP BY us."objectId",us."username"
  493. ORDER BY SUM(tbl."credit") DESC
  494. OFFSET ${skip || 0} LIMIT ${limit ?? 50}`;
  495. if (this.identity) {
  496. sql = `SELECT us."objectId",us."nickname",us."avatar",ROUND(SUM("credit")::numeric, 2) AS credit
  497. FROM (
  498. SELECT COALESCE(SUM(llog.gold ),0) AS "credit",llog."fromUser" AS uid
  499. FROM "LoveRender" AS llog
  500. WHERE llog.company = '${this.company}'
  501. AND llog."isDeleted" IS NOT TRUE
  502. AND llog."toUser" = '${uid}'
  503. GROUP BY llog."fromUser"
  504. UNION
  505. SELECT SUM(lalog.duration / 60 * lalog.unit) "credit",lalog."user" AS uid
  506. FROM "LiveActiveLog" AS lalog
  507. LEFT JOIN "Room"
  508. ON lalog."room" = "Room"."objectId"
  509. WHERE lalog.company = '${this.company}'
  510. AND lalog."isDeleted" IS NOT TRUE
  511. AND "Room"."user" = '${uid}'
  512. GROUP BY lalog."user"
  513. ) AS tbl
  514. LEFT JOIN "_User" us
  515. ON us."objectId" = tbl.uid
  516. GROUP BY us."objectId",us."username"
  517. ORDER BY SUM(tbl."credit") DESC
  518. OFFSET ${skip || 0} LIMIT ${limit ?? 50}`;
  519. }
  520. let res: any = await this.http.customSQL(sql);
  521. return res.data;
  522. }
  523. }