2021SC@SDUSC
本周开始我们来分析controller下的center文件夹,它包含了cmswing的用户注册、支付、资金管理等多项重要功能。
首先我们来看account.js,该文件包含了用户消费支付时要使用的方法:
1.
async __before() {
await super.__before();
// await this.weblogin();
if (!this.is_login) {
if (this.isMobile) {
return this.redirect('/center/public/login');
} else {
return this.redirect('/cmswing/error/login');
}
}
}
与我们之前分析的几个文件相同,进行支付等相关操作前需要对用户的状态进行验证,判断用户是否是登录状态(this.is_login)。若未登录,再用内部if语句根据情况跳转到登陆页面:this.isMobile返回true,则代表是手机端,直接跳转到登录页面,否则返回error下的登陆。
2.
async indexAction() {
this.tactive = 'user';
const type = this.get('type') || null;
let data;
if (think.isEmpty(type)) {
data = await this.model('balance_log').where({user_id: this.user.uid}).page(this.get('page')).order('time DESC').countSelect();
} else if (type == 1) {
data = aw