def write(): """ 新增日记 :return: """ phone = request.form.get('phone') user = User.objects.filter(phone=phone).first() if user: uid = user.uid username = user.username else: return AppResponse.response(code=-1, data={"title": "用户不存在"}) title = request.form.get('title') data = request.form.get('data') text = request.form.get('text') status = request.form.get('status') if status == 'true' or status == True: status = 1 elif status == 'false' or status == False: status = 0 if phone is None or title is None or data is None or text is None or status is None: return AppResponse.response(code=-1, data={"title": "内容均不可为空;请重新输入"}) content = Content(phone=phone, uid=uid, username=username, title=title, data=data, text=text, status=status) content.save() return AppResponse.response(code=1, data={"title": "日记发布成功"})
def tourists_register_submit(request_data): """ 游客注册提交 :param request_data:公共参数 :return: """ try: if Relationship.device_uid_exists(device_id=request_data.device_id): return AppResponse.response(code=-8888, message="此设备非新设备") user = UserInfo(status="active", devices=[request_data.device_id], gold_coin_balance=0, cash_balance=0.0, box_pkg_name=request_data.box_pkg_name, create_time=time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()), last_login_time=time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()), register_method="tourists", is_tourists=True, register_type="tourists") user.generate_yid() if request_data.channel_name: user.channel_name = request_data.channel_name if request_data.version_name: user.version_name = request_data.version_name user.nick_name = f"游客{user.uid}" user.tongdun_decision = "Accept" # logger.info("code: %d, device_id number: %s, message: %s" % (1, request_data.device_id, "游客注册成功")) msg = "注册成功" relation_ship = Relationship.get_by_id(request_data.device_id, user.uid) if not relation_ship: relation_ship = Relationship.create(channel_name=request_data.channel_name, device_id=request_data.device_id, mac_addr=request_data.mac_addr, android_id=request_data.android_id, imei=request_data.imei, first_time=time.strftime("%Y-%m-%d %H:%M:%S"), version_name=request_data.version_name, user_id=user.uid, last_update_time=int(time.time()), box_pkg_name=request_data.box_pkg_name, is_tourists=True) else: relation_ship.update_attr(channel_name=request_data.channel_name, device_id=request_data.device_id, mac_addr=request_data.mac_addr, android_id=request_data.android_id, imei=request_data.imei, last_update_time=int(time.time()), version_name=request_data.version_name, user_id=user.uid) relation_ship.save() user.save() return AppResponse.response(code=1, message=msg, data={ "yid": user.yid, "user_id": user.uid, "user_name": user.nick_name }) except Exception as e: # logger.exception(e) return AppResponse.response(code=-1000)
def delete(): """ 删除日记 :return: """ cid = request.form.get('cid') if cid is None: return AppResponse.response(code=-1, data={"title": "日记ID不能为空"}) con = Content.objects.filter(_id=cid).first() if con: Content.objects.filter(_id=cid).delete() return AppResponse.response(code=1, data={"title": "删除成功"}) else: return AppResponse.response(code=1, data={"title": "该文章不存在"})
def register3(): if request.method == 'POST': name = request.args.get('name') password = request.args.get('password') email = request.args.get('email') user_obj = UserInfo.objects.filter(name=name).first() if user_obj: return AppResponse.response(code=1, data='用户已存在') user_obj = UserInfo(name=name, password=password, email=email) user_obj.save() # 调用celery的发送邮件任务,将其加入消息队列,并将用户id传入 result = send_email2.delay(name) print(check_result(result.id)) return AppResponse.response(code=1, data='注册成功,已向你发送一封激活邮件') return AppResponse.response(code=1, data='ok')
def register2(): if request.method == 'POST': name = request.args.get('name') password = request.args.get('password') email = request.args.get('email') user_obj = UserInfo.objects.filter(name=name).first() if user_obj: # 调用celery的发送邮件任务,将其加入消息队列,并将用户id传入 result = is_active.delay(name) print(check_result(result.id)) return AppResponse.response(code=1, data='用户已存在,激活成功') user_obj = UserInfo(name=name, password=password, email=email) user_obj.save() return AppResponse.response(code=1, data='注册成功,请您继续请求后即可激活') return AppResponse.response(code=1, data='ok')
def get_login(l_params): """ 游客登陆 :return: """ phone_number = request.args.get('phone_number') channel_name = l_params.channel_name try: u = UserInfo.objects(phone_number=phone_number)[0] data = dict(uid=u["uid"], phone_number=u['phone_number'], channel_name=channel_name) return AppResponse.response(code=1, data=data) except: return AppResponse.response(code=-1008)
def Production_consumption(): """生产及解锁消耗金币,只能计算小等级的升级消耗 param id: 该参数为工厂id param grade: 该参数为工厂当前等级 param mgrade: 该参数为工厂从当前等级要升级n次 param discount: 该参数为工厂当前消耗便宜系数 """ id = request.args.get('id') grade = request.args.get('grade') num = request.args.get('num') discount = request.args.get('discount', '1.0') xgrade = int(grade) all = [] for n in range(int(num)): xgc = Unit_conversion(int(basic_output[int(id) - 1][4])) pro = xgc[0] * (float(basic_output[int(id) - 1][5])** xgrade) * float(discount) xpro = Unit_conversion((pro, xgc[1])) all.append(xpro) xgrade += 1 xall = get_sum2(all) name = basic_output[int(id) - 1][1] data = dict( id=id, consumption=Unit_conversion(xall), log= f"{name} 从 {grade} 级升到 {int(grade) + int(num)} 级共需要消耗 {Unit_conversion(xall)}" ) return AppResponse.response(code=1, data=data)
def get_data(): """ 获取人天表信息 :return: """ _id = request.args.get('_id') user_id = request.args.get('user_id') device_id = request.args.get('device_id') date = request.args.get('date') game_count = request.args.get('game_count') u = UserDayStat(user_id=user_id, device_id=device_id, date=date, game_count=game_count) u.win_game_count = 500 u.save() uid = u.uid data = dict(user_id=uid, device_id=device_id, date=date, game_count=game_count) # current_app.logger.info(data) log.info(data) log.debug("Do something") log.warning("Something maybe fail.") log.info("Finish") return AppResponse.response(code=1, data=data)
def get_diary(): """ 获取日记详情 :return: """ cid = request.args.get('cid') if cid is None: return AppResponse.response(code=-1, data={"title": "该文章不存在"}) con = Content.objects.filter(_id=cid).first() cont = dict(cid=con.cid, title=con.title, data=con.data, username=con.username, text=con.text, status=con.status) return AppResponse.response(code=1, data=cont)
def auto_login(): """ 用户登陆 :return: """ phone = request.form.get('phone') token = request.form.get('token') cer = wechet_fun.certify_token(phone, token) if cer: user = User.objects.filter(phone=phone).first() data = dict(username=user.username, phone=phone, token=token, title="自动登陆成功") return AppResponse.response(code=1, data=data) else: return AppResponse.response(code=-1, data={"title": "登陆已过期请重新登录"})
def register(): username = request.form.get('username') phone = request.form.get('phone') password = request.form.get('password') re_password = request.form.get('re_password') if username is None or password is None or phone is None: return AppResponse.response(code=-1, data={"title": "用户名及密码、手机号均不可为空;请重新输入"}) if User.objects.filter(phone=phone).first(): return AppResponse.response(code=-1, data={"title": "用户已存在请直接登录"}) if password == re_password: user = User(username=username, phone=phone) user.hash_password(password) user.save() return AppResponse.response(code=1, data={"title": "注册成功"}) else: return AppResponse.response(code=-1, data={"title": "密码输入不一致请重新输入"})
def tourists_submit(l_params): """ 游客登录 :return: """ try: return tourists_register_submit(l_params) except Exception as e: return AppResponse.response(code=-1000, device_id=l_params.device_id)
def get_data(): """ 获取全部日记 :return: """ phone = request.form.get('phone') if phone is None: return AppResponse.response(code=-1, data={"title": "手机号不可为空;请重新输入"}) content = Content.objects.filter(phone=phone).all() data = [] for con in content: cont = dict(cid=con.cid, title=con.title, data=con.data, username=con.username, text=con.text, status=con.status) data.append(cont) print(data) return AppResponse.response(code=1, data=data)
def info(): """ 获取留言 :return: """ name_id = request.args.get('name_id') age = request.args.get('age') name = request.args.get('name') gender = request.args.get('gender') data = dict(name_id=name_id, age=age, name=name, gender=gender) Info(name_id=name_id, age=age, name=name, gender=gender).save() return AppResponse.response(code=1, data=data)
def login(): """ 游客注册 :return: """ phone_number = request.args.get('phone_number') channel_name = request.args.get('channel_name') u = UserInfo(phone_number=phone_number, channel_name=channel_name) u.save() uid = u.uid data = dict(uid=uid, phone_number=phone_number, channel_name=channel_name) return AppResponse.response(code=1, data=data)
def login(): """ 用户注册 :return: """ name_id = request.args.get('name_id') age = request.args.get('age') name = request.args.get('name') gender = request.args.get('gender') data = dict(name_id=name_id, age=age, name=name, gender=gender) Users(name_id=name_id, name=name, age=age, gender=gender).save() return AppResponse.response(code=1, data=data)
def get(): """ 获取留言 :return: """ boards = list(Board.objects().all()) data = dict(messager_name=boards[0]["messager_name"], content=boards[0]["content"], messager_age=boards[0]["messager_age"], receiver=boards[0]["receiver"], create_time=str(boards[0]["create_time"]), messager_sex=boards[0]["messager_sex"]) return AppResponse.response(code=1, data=data)
def Basic_output(): """计算工厂实时秒产值 param ids: 该参数为当前已解锁的全部工厂id,以列表传入 param grade: 该参数为当前已解锁的全部工厂的当前等级,需要与ids列表内元素纵向一一对应,以列表传入 param double: 该参数为当前已解锁的全部工厂的当前翻倍数,需要与ids列表内元素纵向一一对应,以列表传入 param accelerate: 该参数为当前已解锁的全部工厂的当前加速倍率,需要与ids列表内元素纵向一一对应,以列表传入 """ ids = request.args.get('ids') grade = request.args.get('grade') double = request.args.get('double') accelerate = request.args.get('accelerate') idsx = ids.split(',') gradex = grade.split(',') doublex = double.split(',') acceleratex = accelerate.split(',') if len(idsx) == len(gradex) == len(doublex) == len(acceleratex): re = output(idsx, gradex, doublex, acceleratex) else: return AppResponse.response(code=-1000, message="各个工厂对应等级翻倍长度有误,请重新输入~") data = dict(sum=re[0], output=re[1]) return AppResponse.response(code=1, data=data)
def Reward_acquisition(): """计算招商引资&网红直播&离线收益&钻石兑换 param ids: 该参数为当前已解锁的全部工厂id,以列表传入 param grade: 该参数为当前已解锁的全部工厂的当前等级,需要与ids列表内元素纵向一一对应,以列表传入 param double: 该参数为当前已解锁的全部工厂的当前翻倍数,需要与ids列表内元素纵向一一对应,以列表传入 param accelerate: 该参数为当前已解锁的全部工厂的当前加速倍率,需要与ids列表内元素纵向一一对应,以列表传入 param type: 该参数为计算类别,1-招商引资,2-网红直播,3-离线收益,4-钻石兑换;以整形传入 param time: 该参数为要计算收益的时间,以秒计算,以整形传入 """ ids = request.args.get('ids') grade = request.args.get('grade') double = request.args.get('double') accelerate = request.args.get('accelerate') type = request.args.get('type') time = request.args.get('time') idsx = ids.split(',') gradex = grade.split(',') doublex = double.split(',') acceleratex = accelerate.split(',') if len(idsx) == len(gradex) == len(doublex) == len(acceleratex): re = output(idsx, gradex, doublex, acceleratex) attract = re[0][0] * int(time) * 60 attract = Unit_conversion((attract, re[0][1])) if int(type) == 1: result = f"本次招商引资获得奖励为:{attract}" elif int(type) == 2: result = f"本次网红直播获得奖励为:{attract}" elif int(type) == 3: result = f"本次离线收益获得奖励为:{Unit_conversion((attract[0]* 0.8, attract[1]))}" elif int(type) == 4: result = f"本次钻石兑换获得奖励为:{attract}" else: return AppResponse.response(code=-1000, message="奖励类型参数错误,请重新输入~") else: return AppResponse.response(code=-1000, message="各个工厂对应等级翻倍长度有误,请重新输入~") data = dict(result=result) return AppResponse.response(code=1, data=data)
def login(): """ 用户登陆 :return: """ username = request.form.get('username') password = request.form.get('password') phone = request.form.get('phone') if username is None or password is None or phone is None: return AppResponse.response(code=-1, data={"title": "用户名及密码、手机号均不可为空;请重新输入"}) user = User.objects.filter(phone=phone).first() if user: if user.verify_password(password): token = wechet_fun.generate_token(phone) data = dict(username=username, phone=phone, token=token, title="登陆成功") return AppResponse.response(code=1, data=data) else: return AppResponse.response(code=-1, data={"title": "密码错误"}) else: return AppResponse.response(code=-1, data={"title": "没有该用户请先注册后再登录"})
def _wrapped(*args, **kwargs): try: if "l_params" in kwargs: l_params = kwargs["l_params"] else: kwargs["l_params"] = l_params = ParamsParseInit(request) start_time = time.time() f = view(*args, **kwargs) used_time = time.time() - start_time if used_time >= 0.1: # logger.sls_log(event_name="view_used_time", device_id=l_params.device_id, uid=l_params.user_id,view=view.__name__, # used_time=used_time) pass return f except Exception as e: # logger.exception(e) return AppResponse.response(code=-100, funname=view.__name__)
def fruit_reward(): """我的水果店数值测试接口 param id: 该参数为工厂id param grade: 该参数为工厂当前等级 param mgrade: 该参数为工厂当前目标要升级到的等级 """ yid = request.args.get('yid') game_count = request.args.get('game_count') is_test = request.args.get('is_test') open_verification = request.args.get('open_verification') version_name = request.args.get('version_name') channel_name = request.args.get('channel_name') game_version = request.args.get('game_version') device_id = request.args.get('device_id') file_obj = request.files.get('file') if file_obj: f = open(setting.data + '\\fruit\\test.xlsx', 'wb') data = file_obj.read() f.write(data) f.close() dir = os.listdir(setting.data) for i in dir: if f'{yid}.txt' == i: path = setting.data + f'\\{yid}.txt' try: os.remove(path) # 删除文件 # os.rmdir(path) # 删除文件夹 except: pass test = ContentTest(yid=yid, game_count=int(game_count), is_test=int(is_test), channel_name=channel_name, version_name=version_name, device_id=device_id, game_version=game_version, open_verification=int(open_verification)) test.start_test() with open(setting.data + f'\\{yid}.txt', 'r', encoding='utf-8') as f: re = f.readlines() data = dict(log=re) return AppResponse.response(code=1, data=data)
def Production_consumption2(): """生产及解锁消耗金币 param id: 该参数为工厂id param grade: 该参数为工厂当前等级 param mgrade: 该参数为工厂当前目标要升级到的等级 """ id = request.args.get('id') grade = request.args.get('grade') mgrade = request.args.get('mgrade') data = Data2.get_data(id) print(data) ldata = data[int(grade) - 1:int(mgrade) - 1] all = [] for n in ldata: d = tuple(n) all.append(d) xall = get_sum2(all) name = basic_output[int(id) - 1][1] data = dict( id=id, consumption=Unit_conversion(xall), log=f"{name} 从 {grade} 级升到 {mgrade} 级共需要消耗 {Unit_conversion(xall)}") return AppResponse.response(code=1, data=data)
def add(): """ 添加留言 :return: """ messager_name = request.args.get('messager_name') content = request.args.get('content') messager_age = request.args.get('messager_age') messager_sex = request.args.get('messager_sex') receiver = request.args.get('receiver') create_time = request.args.get('create_time') data = dict(messager_name=messager_name, content=content, messager_age=messager_age, receiver=receiver, create_time=create_time, messager_sex=messager_sex) Board(messager_name=messager_name, content=content, messager_age=messager_age, receiver=receiver, create_time=create_time, messager_sex=messager_sex).save() return AppResponse.response(code=1, data=data)
def login(request): # 此处写登录的逻辑即可 return AppResponse.response(code=1, data='ok')