diff --git a/internal/application/order/service.go b/internal/application/order/service.go index 97d9d4f..b074133 100644 --- a/internal/application/order/service.go +++ b/internal/application/order/service.go @@ -47,6 +47,7 @@ func NewOrderService(repo order.AggregateRepository, articleRepo article.Article priceRepo: priceRepo, columnRepo: columnRepo, payService: payService, + runLog: runLog, orderRepo: orderRepo, userRepo: userRepo, couponRepo: couponRepo, diff --git a/ui/src/app/app.component.ts b/ui/src/app/app.component.ts index 9ee1354..434ee64 100644 --- a/ui/src/app/app.component.ts +++ b/ui/src/app/app.component.ts @@ -50,9 +50,9 @@ export class AppComponent implements OnInit { } else { // 如果都没有token,重定向到获取token的页面 console.log("需要获取token,重定向到授权页面"); - // window.location.href = "http://famyun.com/callback_test"; + window.location.href = "http://famyun.com/callback_test"; // 生产环境使用微信授权 - window.location.href = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx13bd75fbedf283e5&redirect_uri=http%3A%2F%2Ffamyun.com%2Fcallback&response_type=code&scope=snsapi_base&state=123#wechat_redirect"; + // window.location.href = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx13bd75fbedf283e5&redirect_uri=http%3A%2F%2Ffamyun.com%2Fcallback&response_type=code&scope=snsapi_base&state=123#wechat_redirect"; } } }); diff --git a/ui/src/app/home/component/article-content/article-content.component.ts b/ui/src/app/home/component/article-content/article-content.component.ts index 4e0996f..bcb2bd1 100644 --- a/ui/src/app/home/component/article-content/article-content.component.ts +++ b/ui/src/app/home/component/article-content/article-content.component.ts @@ -34,12 +34,13 @@ export class ArticleContentComponent implements OnInit,OnDestroy { private cdr:ChangeDetectorRef) { } ngOnInit() { - this.getData(); this.getUsername(); this.routerSub = this.router.events.subscribe(event => { if (event instanceof NavigationEnd) { if(event.url == "/home/special-column" || event.url == "/home") { this.checkOrderOcc() + this.getUsername(); + } } }); @@ -127,10 +128,18 @@ export class ArticleContentComponent implements OnInit,OnDestroy { } getUsername(){ - getUser().subscribe((res)=>{ - this.username = res.username - this.cdr.detectChanges(); - }) + const token = localStorage.getItem("token") + if(token) { + getUser().subscribe((res)=>{ + this.username = res.username + this.loadData() + this.cdr.detectChanges(); + }) + } else { + this.username = "" + this.loadData() + } + } getNewData() { diff --git a/ui/src/app/home/component/article-item/article-item.component.ts b/ui/src/app/home/component/article-item/article-item.component.ts index edc865c..721073e 100644 --- a/ui/src/app/home/component/article-item/article-item.component.ts +++ b/ui/src/app/home/component/article-item/article-item.component.ts @@ -34,37 +34,34 @@ export class ArticleItemComponent implements OnInit,AfterViewInit { } onUnlock() { - getUser().subscribe((res)=>{ - if(res.username == "") { - // 未登录,显示提示框 - this.alertCtrl.create({ - header: '提示', - message: '请先登录后再进行操作', - buttons: [ - { - text: '取消', - role: 'cancel' - }, - { - text: '去登录', - handler: () => { - // 保存当前路径并跳转到登录页 - this.navCtrl.navigateForward('/mine/login', { - state: { returnUrl: this.router.url } - }); - } + if(this.username == "") { + // 未登录,显示提示框 + this.alertCtrl.create({ + header: '提示', + message: '请先登录后再进行操作', + buttons: [ + { + text: '取消', + role: 'cancel' + }, + { + text: '去登录', + handler: () => { + // 保存当前路径并跳转到登录页 + this.navCtrl.navigateForward('/mine/login', { + state: { returnUrl: this.router.url } + }); } - ] - }).then(alert => alert.present()); - } else { - this.homeService.getArticlePrice(this.article.eventId).subscribe((res) => { - this.navCtrl.navigateForward('/home/article-buy', { - state: {article: this.article, price: res} - }); - }) - } - this.username = res.username - }) + } + ] + }).then(alert => alert.present()); + } else { + this.homeService.getArticlePrice(this.article.eventId).subscribe((res) => { + this.navCtrl.navigateForward('/home/article-buy', { + state: {article: this.article, price: res} + }); + }) + } } getFreeReadCount():number{ @@ -78,58 +75,55 @@ export class ArticleItemComponent implements OnInit,AfterViewInit { unlockArticle(event: any) { event.stopPropagation() - getUser().subscribe((res)=>{ - if(res.username == "") { - // 未登录,显示提示框 - this.alertCtrl.create({ - header: '提示', - message: '请先登录后再进行操作', - buttons: ['确定'] - }).then(alert => alert.present()); - } else { - this.alertCtrl.create({ - header: '提示', - message: `您剩余${this.freeReadCount}次,确定使用1次解锁该文章吗?解锁后剩余赠送次数为${this.freeReadCount - 1}次`, - buttons: [ - { - text: '确认', - role: 'cancel', - handler: () => { - this.homeService.unlockArticle({eventId: this.article.eventId} as Article).subscribe((res) => { - this.toastCtrl.create({ - message: '解锁成功!', - duration: 2000, - color: 'success', - position: 'top', - cssClass: 'ion-text-center' - }).then(toast => toast.present()); - this.article.unlock = true; - this.article.content = res.content; - this.article.stocks = res.stocks; - this.freeReadCount-- ; - this.cdr.detectChanges() - useGiftCount() - }, error => { - this.toastCtrl.create({ - message: '解锁失败,请稍后重试', - duration: 2000, - color: 'danger', - position: 'top', - cssClass: 'ion-text-center' - }).then(toast => toast.present()); - }) - - - } - }, - {text: '取消',} - ] - }).then((v1) => { - v1.present() - }); - } - this.username = res.username - }) + if(this.username == "") { + // 未登录,显示提示框 + this.alertCtrl.create({ + header: '提示', + message: '请先登录后再进行操作', + buttons: ['确定'] + }).then(alert => alert.present()); + } else { + this.alertCtrl.create({ + header: '提示', + message: `您剩余${this.freeReadCount}次,确定使用1次解锁该文章吗?解锁后剩余赠送次数为${this.freeReadCount - 1}次`, + buttons: [ + { + text: '确认', + role: 'cancel', + handler: () => { + this.homeService.unlockArticle({eventId: this.article.eventId} as Article).subscribe((res) => { + this.toastCtrl.create({ + message: '解锁成功!', + duration: 2000, + color: 'success', + position: 'top', + cssClass: 'ion-text-center' + }).then(toast => toast.present()); + this.article.unlock = true; + this.article.content = res.content; + this.article.stocks = res.stocks; + this.freeReadCount-- ; + this.cdr.detectChanges() + useGiftCount() + }, error => { + this.toastCtrl.create({ + message: '解锁失败,请稍后重试', + duration: 2000, + color: 'danger', + position: 'top', + cssClass: 'ion-text-center' + }).then(toast => toast.present()); + }) + + + } + }, + {text: '取消',} + ] + }).then((v1) => { + v1.present() + }); + } } diff --git a/ui/src/app/mine/login/login.page.ts b/ui/src/app/mine/login/login.page.ts index 276d152..e75ec72 100644 --- a/ui/src/app/mine/login/login.page.ts +++ b/ui/src/app/mine/login/login.page.ts @@ -9,14 +9,15 @@ import { Input } from '@angular/core'; import { FormBuilder, FormGroup, Validators } from '@angular/forms'; -import { Router } from '@angular/router'; +import {NavigationEnd, Router} from '@angular/router'; import {ModalController, NavController, ToastController} from '@ionic/angular'; -import { MineService } from '../mine.service'; +import {getUser, MineService} from '../mine.service'; import { SlidePoint, SlideRef } from "go-captcha-angular"; import {CaptchaModalComponent} from "../component/captcha-modal/captcha-modal.component"; +import {Subscription} from "rxjs"; @Component({ selector: 'app-login', @@ -34,6 +35,7 @@ export class LoginPage implements OnInit, OnDestroy,AfterViewInit { private timer: any; private verifyToken: string | null = null; private returnUrl: string | null = null; + private routerSub!: Subscription; constructor( private fb: FormBuilder, @@ -58,16 +60,31 @@ export class LoginPage implements OnInit, OnDestroy,AfterViewInit { } ngOnInit() { + this.createForm(); + this.routerSub = this.router.events.subscribe(event => { + if (event instanceof NavigationEnd) { + if(event.url == "/mine/login") { + this.checkLoginStatus() + } + } + }); + } + checkLoginStatus() { + const t = localStorage.getItem("token") + if(t!=""){ + this.navCtrl.navigateBack("/mine/login") + } } ngAfterViewInit() { } - ngOnDestroy() { this.stopCountdown() ; + if (this.routerSub) { + this.routerSub.unsubscribe(); + } } - private createForm() { // 根据登录类型动态设置验证器 this.loginForm.get('password')?.setValidators(