warrior 4 сар өмнө
parent
commit
2ebd45944f

+ 1 - 1
projects/live-app/src/app/components/live/live.component.ts

@@ -59,7 +59,7 @@ export class LiveComponent implements OnInit {
     // queryProfile.notEqualTo('isDeleted', true);
     // this.profile = await queryProfile.first();
     if (this.room?.id) {
-      // await this.liveService.getToken(this.room);
+      await this.liveService.getToken(this.room);
     } else {
       const alert = await this.alertController.create({
         header: '提示',

+ 10 - 8
projects/live-app/src/moduls/live/link-page/link-page.component.html

@@ -16,7 +16,7 @@
         [style.color]="isFollow ? '#fe454e' : '#fff'"
       ></ion-icon>
     </div>
-    <div class="report">
+    <div class="report" (click)="onReport($event)">
       <ion-icon name="warning-outline"></ion-icon>
     </div>
     <div class="exit" (click)="endCall($event)">
@@ -30,13 +30,15 @@
     [style.visibility]="showTool ? 'visible' : 'hidden'"
   >
     <div class="row" style="justify-content: center">
-      <div class="tips">
-        剩余通话时长
-        <span
-          [style.color]="liveService.countdown > 120 ? '#ffc409' : '#ff2636'"
-          >{{ liveService.countdown | secondsToTime }}</span
-        >
-      </div>
+      @if(liveService.connection_state === 'connected'){
+        <div class="tips">
+          剩余通话时长
+          <span
+            [style.color]="liveService.countdown > 120 ? '#ffc409' : '#ff2636'"
+            >{{ liveService.countdown | secondsToTime }}</span
+          >
+        </div>
+      }
     </div>
     @if (!liveService.isAnchor) {
     <div class="row">

+ 64 - 12
projects/live-app/src/moduls/live/link-page/link-page.component.ts

@@ -55,6 +55,7 @@ export class LinkPageComponent implements OnInit {
   giftCount: number = 1;
   wallet: any = { balance: 0 };
   isShowGiftModal: boolean = false; // 是否显示礼物动效弹窗
+  times: any;
   constructor(
     public toastController: ToastController,
     private loadingCtrl: LoadingController,
@@ -79,10 +80,10 @@ export class LinkPageComponent implements OnInit {
     const loading = await this.loadingCtrl.create({
       message: '加载中',
     });
+    loading.present();
     this.getRoom();
     this.giftList = await this.aiServ.getGift();
     console.log(this.giftList);
-    loading.present();
     loading.dismiss();
   }
   async getRoom() {
@@ -90,14 +91,15 @@ export class LinkPageComponent implements OnInit {
     query.equalTo('objectId', this.rid);
     query.notEqualTo('isDeleted', true);
     query.include('user');
+    query.select('user');
     this.room = await query.first();
     this.getFollwState(this.room?.get('user').id);
   }
   /* 关注状态 */
   async getFollwState(uid: string) {
     let query = new Parse.Query('ProfileRadar');
-    query.equalTo('toUser', this.currentUser?.id);
-    query.equalTo('fromUser', uid);
+    query.equalTo('toUser', uid);
+    query.equalTo('fromUser', this.currentUser?.id);
     query.notEqualTo('isDeleted', true);
     query.equalTo('name', '关注');
     let r = await query.first();
@@ -172,18 +174,36 @@ export class LinkPageComponent implements OnInit {
         },
         {
           text: '确定',
-          handler: () => {
-            this.showGiftModal = false;
-            this.isShowGiftModal = true;
-            setTimeout(() => {
-              this.isShowGiftModal = false;
-            }, 5000);
+          handler: async () => {
+            const loading = await this.loadingCtrl.create({
+              message: '送出礼物中...',
+            });
+            loading.present();
+            let fid = this.room?.get('user').id;
+            this.aiServ
+              .putGift(fid, this.currentGift.id, this.giftCount)
+              .then((data) => {
+                console.log(data);
+                this.liveService.get_duration()
+                loading.dismiss();
+                this.showGiftModal = false;
+                this.isShowGiftModal = true;
+                setTimeout(() => {
+                  this.isShowGiftModal = false;
+                }, 5000);
+              })
+              .catch((err) => {
+                this.showGiftModal = false;
+                loading.dismiss();
+                console.error(err);
+              });
           },
         },
       ],
     });
     await alert.present();
   }
+
   onChange() {
     this.giftCount = this.giftCount < 1 ? 1 : Math.floor(this.giftCount);
     console.log(this.giftCount);
@@ -197,17 +217,49 @@ export class LinkPageComponent implements OnInit {
       message: '你确定退出登录吗?',
       buttons: [
         {
-          text: '确定',
+          text: '取消',
           role: 'cancel',
-          cssClass: 'secondary',
           handler: (blah) => {
+          },
+        },
+        {
+          text: '确定',
+          cssClass: 'secondary',
+          handler: () => {
             console.log('Confirm Cancel: blah');
             this.onExit();
           },
         },
+      ],
+    });
+    await alert.present();
+  }
+  async onReport(e: any){
+    e.cancelBubble = true;
+    const alert = await this.alertController.create({
+      cssClass: 'my-custom-class',
+      header: '举报',
+      message: '请填写您需要举报的内容',
+      inputs: [
+        {
+          name: 'report',
+          type: 'textarea',
+          placeholder: '举报内容',
+        },
+      ],
+      buttons: [
         {
           text: '取消',
-          handler: () => {},
+          role: 'cancel',
+          handler: (data) => {},
+        },
+        {
+          text: '确定',
+          cssClass: 'secondary',
+          handler: (data) => {
+            let report = data.report;
+            console.log(report);
+          },
         },
       ],
     });

+ 1 - 1
projects/live-app/src/moduls/user/profile/profile.component.html

@@ -115,7 +115,7 @@
       <div class="title-text">ta的礼物墙</div>
       <div class="gift">
         @for (item of giftList; track $index) {
-        <img [src]="item?.get('image')" alt="" />
+        <img [src]="item?.image" alt="" />
         }
       </div>
     </div>

+ 32 - 19
projects/live-app/src/moduls/user/profile/profile.component.ts

@@ -3,6 +3,7 @@ import { CommonModule, DatePipe } from '@angular/common';
 import { NavComponent } from '../../../app/components/nav/nav.component';
 import { ActivatedRoute, Router } from '@angular/router';
 import {
+  AlertController,
   IonicModule,
   LoadingController,
   ToastController,
@@ -44,9 +45,9 @@ export class ProfileComponent implements OnInit {
     gift: 0, //送出礼物
   };
   isFollow: boolean = false;
-  giftList: Array<Parse.Object> = []; //礼物
+  giftList: any[] = []; //礼物
   isOpen: boolean = false; //打开弹窗
-  room?:Parse.Object;
+  room?: Parse.Object;
 
   constructor(
     private activateRoute: ActivatedRoute,
@@ -54,7 +55,8 @@ export class ProfileComponent implements OnInit {
     public toastController: ToastController,
     public loadingCtrl: LoadingController,
     private aiChatServ: AiChatService,
-    private http: HttpService
+    private http: HttpService,
+    private alertController: AlertController
   ) {}
 
   ngOnInit() {
@@ -62,7 +64,7 @@ export class ProfileComponent implements OnInit {
       let id: any = params.get('id');
       this.uid = id;
       await this.refresh();
-      this.getRoom()
+      this.getRoom();
     });
   }
   async refresh() {
@@ -75,9 +77,9 @@ export class ProfileComponent implements OnInit {
     let res = await this.aiChatServ.getFansAndFollow(this.uid);
     this.numsObject.fans = res.data[0].fans;
     this.numsObject.follow = res.data[0].follow;
-    let res1 = await this.aiChatServ.getGiftLog(this.uid);
+    let res1 = await this.aiChatServ.getGiftLogCount(this.uid);
     this.numsObject.gift = res1.data[0].gift ?? 0;
-    await this.getLoveRender();
+    this.giftList = await this.aiChatServ.getGiftList(this.uid, 16);
     loading.dismiss();
   }
   async getRoom() {
@@ -116,14 +118,6 @@ export class ProfileComponent implements OnInit {
     let r = await query.first();
     this.isFollow = r?.id ? true : false;
   }
-  /* 打赏 */
-  async getLoveRender() {
-    let query = new Parse.Query('LoveRender');
-    query.equalTo('toUser', this.uid);
-    query.notEqualTo('isDeleted', true);
-    query.limit(12);
-    this.giftList = await query.find();
-  }
   /* 关注 */
   async onCollection() {
     let query = new Parse.Query('ProfileRadar');
@@ -151,7 +145,7 @@ export class ProfileComponent implements OnInit {
     profileRadar?.set('isDeleted', this.isFollow);
     await profileRadar?.save();
     this.isFollow = !this.isFollow;
-    this.isFollow ? this.numsObject.fans+=1 : this.numsObject.fans-=1;
+    this.isFollow ? (this.numsObject.fans += 1) : (this.numsObject.fans -= 1);
   }
   onShowImg(url: string) {
     this.currenImg = url;
@@ -202,10 +196,29 @@ export class ProfileComponent implements OnInit {
       },
     });
   }
-  toMsg(){
-    this.router.navigate(['live/chat/'+this.uid]);
+  toMsg() {
+    this.router.navigate(['live/chat/' + this.uid]);
   }
-  toLiveContact(){
-    this.router.navigate(['live/link-room/'+this.room?.id]);
+  async toLiveContact() {
+    const alert = await this.alertController.create({
+      cssClass: 'my-custom-class',
+      header: '邀请通话',
+      message: '你将与对方发起私聊通话',
+      buttons: [
+        {
+          text: '取消',
+          role: 'cancel',
+          handler: (blah) => {},
+        },
+        {
+          text: '确定',
+          cssClass: 'secondary',
+          handler: () => {
+            this.router.navigate(['live/link-room/' + this.room?.id]);
+          },
+        },
+      ],
+    });
+    await alert.present();
   }
 }

+ 38 - 3
projects/live-app/src/services/aichart.service.ts

@@ -9,13 +9,13 @@ export class AiChatService {
   isLoggedIn = false;
   company: string = 'Qje9D4bqol';
   constructor(private router: Router, private http: HttpService) {}
-  async getWallet(uid: string):Promise<any> {
+  async getWallet(uid: string): Promise<any> {
     const data = await this.http.httpRequst(
       'https://server.fmode.cn/api/ailiao/wallet',
       { uid: uid },
       'POST'
     );
-    return data['data']
+    return data['data'];
   }
   getFansAndFollow(uid: string): Promise<any> {
     let sql = `SELECT 
@@ -33,12 +33,31 @@ export class AiChatService {
     const data: any = await this.http.customSQL(sql);
     return data?.data;
   }
-  getGiftLog(uid: string): Promise<any> {
+  getGiftLogCount(uid: string): Promise<any> {
     let sql = `SELECT SUM("index")
     FROM "LoveRender"
     WHERE "fromUser" ='${uid}'`;
     return this.http.customSQL(sql);
   }
+  async getGiftList(uid: string, limit?: number, skip?:number): Promise<any> {
+    let where = '';
+    if (limit) {
+      where = `OFFSET ${skip ?? 0} LIMIT ${limit}`;
+    }
+    let sql = `SELECT lr.name,lr.image
+    FROM (
+      SELECT *,ROW_NUMBER() OVER (PARTITION BY "gift" ORDER BY "createdAt" DESC) as rn
+      FROM "LoveRender"
+      WHERE "toUser" = '${uid}'
+      AND "isDeleted" IS NOT TRUE
+    ) lr
+    WHERE lr.rn = 1
+    ORDER BY lr."createdAt" DESC
+    ${where}
+    `;
+    const data:any = await this.http.customSQL(sql);
+    return data.data
+  }
   getFriends(uid: string): Promise<any> {
     let sql = `SELECT u.avatar,u.nickname,u.name,u."objectId" AS uid FROM 
     (SELECT (CASE WHEN "friend" = '${uid}' THEN "user" ELSE "friend" END) fid
@@ -73,4 +92,20 @@ export class AiChatService {
         ORDER BY ntbl."createdAt" DESC`;
     let res = await this.http.customSQL(sql);
   }
+
+  /* 赠送礼物 */
+  async putGift(
+    fromUid: string,
+    gid: string,
+    giftCount?: number
+  ): Promise<any> {
+    let baseurl = 'https://server.fmode.cn/api/ailiao/save_gift';
+    let reqBody = {
+      fromUid: Parse.User.current()?.id,
+      toUid: fromUid,
+      gid: gid,
+      index: giftCount ?? 1,
+    };
+    return await this.http.httpRequst(baseurl, reqBody, 'POST');
+  }
 }

+ 11 - 3
projects/live-app/src/services/live.service.ts

@@ -229,7 +229,7 @@ export class LiveService {
       await this.client.publish(Object.values(this.localTracks));
     } catch (err) {
       console.log('发布本地视频失败:', err);
-      this.alertTips('发布本地视频失败:');
+      this.alertTips('发布本地视频失败','提示',()=>history.back());
     }
   }
   /* 订阅远程视频 */
@@ -350,8 +350,6 @@ export class LiveService {
           //首次进入至少计时2分钟,不足2分钟按2分钟计算扣时
           await this.publishSelf();
           await this.get_duration();
-          this.countdown = this.surplusNumber; // 初始化倒计时
-          this.startCountdown();
           this.computeDuration(60000 * 2);
         } else {
           this.timer = setTimeout(() => {
@@ -386,6 +384,7 @@ export class LiveService {
     }, 1000);
   }
   async get_duration() {
+    this.timer_countdown && clearInterval(this.timer_countdown);
     let url = 'https://server.fmode.cn/api/ailiao/remain_second';
     let params = {
       rid: this.room?.id,
@@ -394,7 +393,16 @@ export class LiveService {
     let data = await this.http.httpRequst(url, params, 'POST');
     console.log(data);
     this.surplusNumber = data.data ?? 0;
+    this.countdown = this.surplusNumber; // 初始化倒计时
+    if(this.countdown <= 120){
+      this.alertTips('剩余通话时间不足2分钟,请及时充值')
+    }
+    let arr = ['RECONNECTING', 'DISCONNECTED', 'DISCONNECTING'];
+    if (!arr.includes(this.connection_state as any)) {
+      this.startCountdown();
+    }
   }
+
   startCountdown() {
     this.timer_countdown = setInterval(() => {
       if (this.countdown > 0) {