Browse Source

更新实名机制

warrior 2 months ago
parent
commit
631628a63d

+ 6 - 0
projects/live-app/src/modules/live/link-page/link-page.component.ts

@@ -265,4 +265,10 @@ export class LinkPageComponent implements OnInit {
     this.liveService.client.leave();
     history.back();
   }
+
+  ngOnDestroy(): void {
+    if(this.liveService.isAnchor){
+      this.msgServe.setConnectState(this.currentUser?.id!, 'ONLINE');
+    }
+  }
 }

+ 6 - 8
projects/live-app/src/modules/user/certification/certification.component.html

@@ -4,10 +4,7 @@
     <div class="hred-left">
       {{ title }}
     </div>
-    <img
-      src="http://file-cloud.fmode.cn/real-idcard.png"
-      class="hred-img"
-    />
+    <img src="http://file-cloud.fmode.cn/real-idcard.png" class="hred-img" />
   </div>
   @if (isReal) {
   <div class="tips">
@@ -22,6 +19,9 @@
     <div style="margin-right: 10px">{{ secretName }}*</div>
     <div class="">{{ secretIdCard }}********</div>
   </div>
+  <div class="agreement pflex">
+    <span (click)="showAgreement()">《爱聊直播平台隐私协议》</span>
+  </div>
   } @else{
   <div class="h3">填写身份信息认证</div>
   <div class="li">
@@ -50,10 +50,8 @@
   <div class="footer" (click)="check()">提交</div>
   <div class="agreement">
     <ion-checkbox color="primary" [(ngModel)]="agreement"></ion-checkbox>
-    <div class="content">
-      阅读且同意<span (click)="showAgreement()"
-        >《爱聊直播平台隐私协议》</span
-      >
+    <div class="agreement-content">
+      阅读且同意<span (click)="showAgreement()">《爱聊直播平台隐私协议》</span>
     </div>
   </div>
   }

+ 6 - 0
projects/live-app/src/modules/user/certification/certification.component.scss

@@ -141,6 +141,12 @@
       --background-checked: #108ee9;
     }
   }
+  .pflex{
+    position: fixed;
+    bottom: 20px;
+    text-align: center;
+    width: 100%;
+  }
 }
 
 input:-internal-autofill-previewed,

+ 37 - 4
projects/live-app/src/modules/user/certification/certification.component.ts

@@ -61,6 +61,8 @@ export class CertificationComponent implements OnInit {
     this.profile = await query.first();
     if (this.profile?.id) {
       this.isReal = this.profile.get('isCross');
+      if (this.isReal)
+        localStorage.setItem('profile', JSON.stringify(this.profile.toJSON()));
       this.secretIdCard = this.profile.get('idcard')?.slice(0, 6);
       this.secretName = this.profile.get('name')?.slice(0, 1);
     }
@@ -86,10 +88,16 @@ export class CertificationComponent implements OnInit {
   }
 
   async check() {
+    if(!this.agreement){
+      this.presentToast('请先阅读且同意隐私协议',1500,'danger')
+      return
+    }
     this.loading = await this.loadCtrl.create();
     this.loading.present();
     this.time && clearTimeout(this.time);
     this.time = setTimeout(async () => {
+      this.name = this.name.trim();
+      this.idCard = this.idCard.trim();
       console.log(this.name, this.idCard);
       if (!this.idCard || this.idCard.length != 18 || !this.name) {
         this.loading.dismiss();
@@ -107,7 +115,11 @@ export class CertificationComponent implements OnInit {
         );
         return;
       }
-
+      if(this.getAgeFromIdCard(this.idCard) < 18){
+        this.loading.dismiss();
+        await this.presentToast('根据平台规定,仅限满18周岁用户使用。',1500,'danger')
+        return
+      }
       let res: any = await this.service.postAuth(
         this.company,
         this.idCard,
@@ -117,8 +129,8 @@ export class CertificationComponent implements OnInit {
         let { isok } = res.data.result;
         console.log(isok);
         if (isok) {
-          let { sex } = res.data.result.IdCardInfor;
-          this.anthProfile(sex);
+          let { sex,city } = res.data.result.IdCardInfor;
+          this.anthProfile(sex,city);
           return;
         }
         this.loading.dismiss();
@@ -134,7 +146,7 @@ export class CertificationComponent implements OnInit {
     }, 500);
   }
 
-  async anthProfile(sex: string) {
+  async anthProfile(sex: string,city:string) {
     let user = Parse.User.current();
     let query = new Parse.Query('Profile');
     query.equalTo('idcard', this.idCard);
@@ -168,6 +180,7 @@ export class CertificationComponent implements OnInit {
     this.profile?.set('idcard', this.idCard);
     this.profile?.set('name', this.name);
     this.profile?.set('sex', sex);
+    this.profile?.set('city', city);
     this.profile?.set('isCross', true);
     await this.profile?.save();
     if (this.profile?.id) {
@@ -180,4 +193,24 @@ export class CertificationComponent implements OnInit {
       }, 1500);
     }
   }
+
+  getAgeFromIdCard(idCard: string): number {
+    // 提取出生日期部分
+    const birthDateStr = idCard.substring(6, 14);
+    const year = parseInt(birthDateStr.substring(0, 4), 10);
+    const month = parseInt(birthDateStr.substring(4, 6), 10);
+    const day = parseInt(birthDateStr.substring(6, 8), 10);
+    // 创建出生日期对象
+    const birthDate = new Date(year, month - 1, day);
+    // 获取当前日期
+    const today = new Date();
+    // 计算年龄
+    let age = today.getFullYear() - birthDate.getFullYear();
+    const monthDiff = today.getMonth() - birthDate.getMonth();
+    if (monthDiff < 0 || (monthDiff === 0 && today.getDate() < birthDate.getDate())) {
+      age--;
+    }
+    return age;
+  }
+
 }

+ 4 - 4
projects/live-app/src/modules/user/profile/profile.component.html

@@ -31,23 +31,23 @@
                 src="https://file-cloud.fmode.cn/Qje9D4bqol/20241109/pctmvt110807052.png"
                 alt=""
               />
-              {{ profiel?.get("age") || "未知" }}
+              {{ profile?.get("age") || "未知" }}
             </div>
           </div>
         </div>
         <div class="user-status">
           <span class="id">爱聊ID:{{ user?.id }}</span>
-          @if (profiel?.get('isCheck')) {
+          <!-- @if (profile?.get('isCheck')) {
           <div class="state">
             <span class="spot"></span>
             <span class="tag">勿扰</span>
           </div>
-          }@else {
+          }@else { -->
           <div class="state">
             <span class="spot" [style.background]="state.color"></span>
             <span class="tag">{{ state.val }}</span>
           </div>
-          }
+          <!-- } -->
           @if (profile?.get('identyType') === 'anchor') {
             <div class="video-unit">通话:{{profile?.get('laborCosts')}}钻石/分钟</div>
           }

+ 18 - 4
projects/live-app/src/modules/user/profile/profile.component.ts

@@ -39,7 +39,6 @@ export class ProfileComponent implements OnInit {
   // @ViewChild('upload') upload!: UploadComponent;
   uid: string = '';
   currentUser?: Parse.Object = Parse.User.current(); //当前登录用户
-  profiel?: Parse.Object; // 用户信息
   user?: Parse.Object; // 查看用户
   @ViewChild('preview') preview!: ImagePreviewComponent;
   friends?: Parse.Object; // 好友
@@ -75,6 +74,10 @@ export class ProfileComponent implements OnInit {
   }
   get state() {
     let map: any = {
+      REFUSE:{
+        val: '勿扰',
+        color: '#f1ac16',
+      },
       ONLINE: {
         val: '在线',
         color: '#28bb50',
@@ -107,6 +110,9 @@ export class ProfileComponent implements OnInit {
       } else {
         this.userStatus = 'ONLINE';
       }
+      if(this.profile?.get('isCheck') && this.userStatus == 'ONLINE'){
+        this.userStatus = 'REFUSE'
+      }
     });
   }
   ngOnDestroy(): void {
@@ -160,9 +166,8 @@ export class ProfileComponent implements OnInit {
       queryUser.equalTo('objectId', this.uid);
       this.user = await queryUser.first();
     }
-    console.log(this.user, this.profile);
-    this.birthdat = getBirthdatByIdNo(this.profiel?.get('idcard') || '');
-    this.constellation = getConstellation(this.profiel?.get('idcard') || '');
+    this.birthdat = getBirthdatByIdNo(this.profile?.get('idcard') || '');
+    this.constellation = getConstellation(this.profile?.get('idcard') || '');
   }
   /* 关注状态 */
   async getFollwState() {
@@ -286,6 +291,15 @@ export class ProfileComponent implements OnInit {
     this.router.navigate(['live/chat/' + this.friends?.get('channel')]);
   }
   async toLiveContact() {
+    if(this.userStatus == 'REFUSE'){
+      const toast = await this.toastController.create({
+        message: '对方已设置免打扰状态',
+        color: 'warning',
+        duration: 1500,
+      });
+      toast.present();
+      return
+    }
     this.userStatus = await this.connectTask.getState(this.uid, this.uid);
     if (this.userStatus !== 'ONLINE') {
       const toast = await this.toastController.create({

+ 38 - 13
projects/live-app/src/services/auth.guard.ts

@@ -1,20 +1,24 @@
-import { Injectable } from "@angular/core";
+import { Injectable } from '@angular/core';
 import {
   CanActivate,
   ActivatedRouteSnapshot,
   RouterStateSnapshot,
-} from "@angular/router";
-import { Observable } from "rxjs";
-import { Router } from "@angular/router";
-import Parse from "parse";
+} from '@angular/router';
+import { Observable } from 'rxjs';
+import { Router } from '@angular/router';
+import Parse from 'parse';
+import { AlertController } from '../modules/ionic-standalone.modules';
 
 @Injectable({
-  providedIn: "root",
+  providedIn: 'root',
 })
 export class AuthGuard implements CanActivate {
-  LoginPage = "login";
+  LoginPage = 'login';
 
-  constructor(public router: Router) {}
+  constructor(
+    public router: Router,
+    private alertController: AlertController
+  ) {}
 
   canActivate(
     next: ActivatedRouteSnapshot,
@@ -27,12 +31,33 @@ export class AuthGuard implements CanActivate {
   checkLogin(url: string): boolean {
     // 如果已登录,直接跳转当前路由 跳出该函数
     let currentUser = Parse.User.current();
-    if (currentUser && currentUser.id) {
-      return true;
+    if (!currentUser?.id) {
+      // 否则重定向到login页面
+      this.router.navigate([this.LoginPage]);
+      return false;
     }
-    // 否则重定向到login页面
-    this.router.navigate([this.LoginPage]);
-    return false;
+    let p = localStorage.getItem('profile');
+    if (url !== '/user/certification' && (!p || !JSON.parse(p)?.isCross)) {
+      this.alertModal();
+    }
+    return true;
+  }
+  async alertModal() {
+    const alert = await this.alertController.create({
+      cssClass: 'my-custom-class',
+      header: '实名认证',
+      message: '根据相关法律法规要求,请先完成实名',
+      backdropDismiss: false,
+      buttons: [
+        {
+          text: '去认证',
+          handler: () => {
+            this.router.navigate(['user/certification']);
+          },
+        },
+      ],
+    });
+    await alert.present();
   }
 }
 export { CanActivate };

+ 2 - 2
projects/live-app/src/services/connectTask.service.ts

@@ -94,8 +94,8 @@ export class ConnectTaskService {
         channelType ?? 'MESSAGE'
       );
       const { states, userId, statesCount } = result; // Tony 的临时状态
-      console.log(states.Mode);
-      console.log(result);
+      console.log(`${userId}用户状态:${states.Mode}`);
+      // console.log(result);
       return states.Mode;
     } catch (status: any) {
       const { operation, reason, errorCode } = status;

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

@@ -275,9 +275,9 @@ export class LiveService {
           remoteEle.textContent = '对方离开直播间';
         }
         //主播离开,停止计时计费
-        if (!this.isAnchor) {
+        // if (!this.isAnchor) {
           this.client.leave();
-        }
+        // }
         this.alertTips('对方已离开直播间');
       }
     });
@@ -297,7 +297,7 @@ export class LiveService {
             this.msgSer.unsubscribeMessage(this.room?.get('user')?.id);
           }
         }
-        console.log('状态变更:', this.connection_state);
+        console.log('live状态变更:', this.connection_state);
       }
     );
     this.monitorDevices();

+ 4 - 2
projects/live-app/src/services/message.service.ts

@@ -80,8 +80,10 @@ export class MessageService {
       let states = [
         'USERCALLINVITATION',
         'REFUSEINVITATION_' + this.userId,
+        'REFUSEINVITATION_' + event.publisher,
         'CLOASEINVITATION',
         'RESPONSEINVITOIN_' + this.userId,
+        'RESPONSEINVITOIN_' + event.publisher,
       ];
       const message = JSON.parse(event.message);
       let is_self = event.publisher == this.userId;
@@ -118,12 +120,12 @@ export class MessageService {
       Mode: mode,
     };
     try {
-      let res = await this.rtmClient?.presence.setState(
+      await this.rtmClient?.presence.setState(
         channelName,
         channelType,
         states
       );
-      console.log('频道状态发生更改:', res);
+      console.log('频道状态发生更改:', mode);
     } catch (err: any) {
       console.log(err);
     }

+ 2 - 2
projects/live-app/src/services/utils.ts

@@ -21,10 +21,10 @@ export function getBirthdatByIdNo(iIdNo:string) {
   if (iIdNo.length == 15) {
     tmpStr = iIdNo.substring(6, 12);
     tmpStr = "19" + tmpStr;
-    tmpStr = tmpStr.substring(0, 4) + "/" + tmpStr.substring(4, 6) + "/" + tmpStr.substring(6)
+    tmpStr = tmpStr.substring(4, 6) + "月" + tmpStr.substring(6) + '日'
   } else {
     tmpStr = iIdNo.substring(6, 14);
-    tmpStr = tmpStr.substring(0, 4) + "/" + tmpStr.substring(4, 6) + "/" + tmpStr.substring(6)
+    tmpStr = tmpStr.substring(4, 6) + "月" + tmpStr.substring(6) + '日'
   }
   return tmpStr;
 }