def process(self): user_body = self.parameters.get('body') if self.check_registed_user_by_email(user_body.get('email')): return { "code": 4010, "message": returncode['4010'], }, 400 logging.info("AddUserView. {}".format(user_body)) UserService.add_user(user_body.get('name'), user_body.get('email'), user_body.get('password'), user_body.get('source'), user_body.get('email_verified'), time.time() * 1000) db.session.commit() if not user_body['email_verified']: logging.error("email_verified false, So we need send an verify email to {}".format(user_body['email'])) # get user service info again, active it. user = UserService.get_user_by_email(user_body.get('email')) UserService.active_thunderservice(user.id, user.thunderservice_id, user.thunderservice_starttime, user.thunderservice_endtime) db.session.commit() return { "code": 200, "message": "add user success", }
def process(self): user_body = self.parameters.get('body') if self.check_registed_user_by_email(user_body.get('email')): return { "code": 4010, "message": returncode['4010'], }, 400 logging.info("AddUserView. {}".format(user_body)) UserService.add_user(user_body.get('name'), user_body.get('email'), user_body.get('password'), user_body.get('appkey'), user_body.get('email_verified'), int(time.time())) db.session.commit() if not user_body.get('email_verified'): logging.error( "email_verified false, So we need send an verify email to {}". format(user_body['email'])) # get user service info again, active it. user = UserService.get_user_by_email(user_body.get('email')) UserService.active_thunderservice(user.id, user.thunderservice_id, user.thunderservice_starttime, user.thunderservice_endtime) db.session.commit() source = user_body.get('appkey') if user_body.get( 'appkey') else 'Unknown' KService_action = '101' KService.add_record(action=KService_action, parameter1=user.id, parameter2=source, timestamp=int(time.time())) return { "code": 200, "message": "add user success", }
def make_fulfill(order_id): from application.services.user_service import UserService order = OrderModel.query.filter(OrderModel.id == order_id).first() user = UserService.get_user(order.user_id) if user: from application.models.thunderservice_model import ThunderserviceModel if user.thunderservice_id == order.thunderservice_id: # 相同的thunderservice,只修改到期时间 thunderservice = ThunderserviceModel.query.filter( ThunderserviceModel.id == order.thunderservice_id).first() duration = thunderservice.duration * 86400 user.thunderservice_endtime = user.thunderservice_endtime + duration # 标记本order已经完成了 order.thunderserviceStatus = '1' db.session.commit() # 增加记录到K线图 KService_action = '201' KService.add_record(action=KService_action, parameter1=order.amount, parameter2='Paid', timestamp=int(time.time())) return True else: #取user当前的thunderservice是否是付费service,如果是,记录还剩多少时间。 timeLeft = 0 if str(user.thunderservice_id) in thunder_service_ID['FUFEI']: timeLeft = user.thunderservice_endtime - int(time.time()) if timeLeft < 0: timeLeft = 0 thunderservice = ThunderserviceModel.query.filter( ThunderserviceModel.id == order.thunderservice_id).first() user_updatedata = { "thunderservice_id": order.thunderservice_id, "thunderservice_client_amount": thunderservice.defaultClientAmount, "thunderservice_traffic_amount": thunderservice.defaultTrafficAmount, } thunderservice_starttime = time.time() thunderservice_endtime = time.time() if thunderservice.id != 1: thunderservice_endtime = thunderservice_endtime + thunderservice.duration * 86400 + timeLeft UserService.modify_user_by_id(order.user_id, update_data=user_updatedata) db.session.commit() UserService.active_thunderservice(order.user_id, order.thunderservice_id, thunderservice_starttime, thunderservice_endtime) db.session.commit() order.thunderserviceStatus = '1' db.session.commit() # 增加记录到K线图 KService_action = '201' KService.add_record(action=KService_action, parameter1=order.amount, parameter2='Paid', timestamp=int(time.time())) return True else: return False