def earn_gold(request): """ 用户获取金币 """ param = json.loads(request.body) user = request.user if not user.is_authenticated(): return HttpResponse(CommonResponse(error_code=401, error_message="用户未登录").to_json(), content_type=CONTENT_TYPE_JSON) gold = param["gold"] group_id = param["group_id"] # 看看有没有领取过 reward_cycle_id = param["reward_cycle_id"] reward_cycle = RewardCycle.objects.get(id=reward_cycle_id) in_set = judge_in_set(user, group_id, reward_cycle) if in_set: return HttpResponse(CommonResponse( error_code=401, error_message="该广告位金币已经领取").to_json(), content_type=CONTENT_TYPE_JSON) reward_cycle = RewardCycle.objects.filter().order_by( "-first_created").first() with transaction.atomic(): # 增加获取记录 create_get_gold_record(user=user, gold=gold, group_id=group_id) # 增加金币并推送 cash_service.earn_gold(gold=gold, user=user) expire = get_current_expire() add_judge(user, group_id, expire, reward_cycle) return HttpResponse(CommonResponse(error_code=0, error_message="", data={}).to_json(), content_type=CONTENT_TYPE_JSON)
def sign_up(request): """ :type request HttpRequest """ param = json.loads(request.body) phone = param["phone"] token = param["token"] password = param["password"] device_token = param["device_token"] success = service.validate_token(phone, token, service.TYPE_SIGN_UP) session_id = "" if success: user, code, message = service.actual_sign_up(phone, password, device_token) if code == 0: user = authenticate(username=phone, password=password) login(request, user) if not request.session.session_key: request.session.save() session_id = request.session.session_key user.userprofile.device_token = device_token user.userprofile.current_session_id = session_id user.userprofile.save() return HttpResponse(CommonResponse(error_code=code, error_message=message, data={ "sessionid": session_id }).to_json(), content_type=CONTENT_TYPE_JSON) message = "验证码错误" code = 401 return HttpResponse(CommonResponse(error_code=code, error_message=message).to_json(), content_type=CONTENT_TYPE_JSON)
def sign_in(request): """ :type request HttpRequest """ param = json.loads(request.body) phone = param["phone"] password = param["password"] device_token = param["device_token"] user = authenticate(username=phone, password=password) if user is not None: login(request, user) if not request.session.session_key: request.session.save() session_id = request.session.session_key user.userprofile.device_token = device_token user.userprofile.current_session_id = session_id user.userprofile.save() data = {"sessionid": session_id} return HttpResponse(CommonResponse(error_code=0, error_message="登录成功", data=data).to_json(), content_type=CONTENT_TYPE_JSON) return HttpResponse(CommonResponse(error_code=401, error_message="用户名或密码错误").to_json(), status=401, content_type=CONTENT_TYPE_JSON)
def wrapper(request, *args, **kwargs): print request.COOKIES user = request.user if not user.is_authenticated(): return HttpResponse(CommonResponse( error_code=401, error_message="用户未登录").to_json(), content_type=CONTENT_TYPE_JSON) user_profile = user.userprofile current_session_id = request.session.session_key if user_profile.current_session_id != "" and current_session_id != user_profile.current_session_id: return HttpResponse(CommonResponse( error_code=401, error_message="用户未登录").to_json(), content_type=CONTENT_TYPE_JSON) return func(request, *args, **kwargs)
def need_update(request): param = json.loads(request.body) version = param.get("version_num") update, return_value = update_to(version) return_value["need_update"] = update return HttpResponse(CommonResponse(error_code=0, error_message="", data=return_value).to_json(), content_type=CONTENT_TYPE_JSON)
def sign_up_token(request): """ :type request HttpRequest """ param = json.loads(request.body) phone = param["phone"] user = get_user_by_username(phone) if not user: service.get_sign_up_token(phone) return HttpResponse(CommonResponse(error_code=0, error_message="", data={}).to_json(), content_type=CONTENT_TYPE_JSON) else: return HttpResponse( CommonResponse(error_code=101, error_message="账号已存在").to_json())
def change_password(request): """ :type request HttpRequest """ param = json.loads(request.body) phone = param["phone"] old_password = param["old_password"] new_password = param["new_password"] user = authenticate(username=phone, password=old_password) if user: code, message = service.actual_change_password(phone, new_password) return HttpResponse(CommonResponse(error_code=code, error_message=message).to_json(), content_type=CONTENT_TYPE_JSON) return HttpResponse(CommonResponse(error_code=401, error_message="旧密码错误").to_json(), content_type=CONTENT_TYPE_JSON)
def sign_out(request): """ :type request HttpRequest """ logout(request) return HttpResponse(CommonResponse(error_code=0, error_message="登出成功").to_json(), content_type=CONTENT_TYPE_JSON)
def reset_password(request): """ :type request HttpRequest """ param = json.loads(request.body) phone = param["phone"] token = param["token"] password = param["password"] success = service.validate_token(phone, token, service.TYPE_RESET_PASSWORD) if success: code, message = service.actual_change_password(phone, password) return HttpResponse(CommonResponse(error_code=code, error_message=message).to_json(), content_type=CONTENT_TYPE_JSON) return HttpResponse(CommonResponse(error_code=401, error_message="验证码错误").to_json(), content_type=CONTENT_TYPE_JSON)
def get_ad_config_view(request): """ /ad/get_ad_config """ data = get_ad_config() return HttpResponse(CommonResponse(error_code=0, error_message="", data=data).to_json(), content_type=CONTENT_TYPE_JSON)
def get_cash_config_view(request): cash_category_list = service.get_cash_config() return HttpResponse(CommonResponse(error_code=0, error_message="", data={ "cash_category_list": cash_category_list }).to_json(), content_type=CONTENT_TYPE_JSON)
def get_upload_token_view(request): auth = Auth(access_key=access_key, secret_key=secret_key) token = auth.upload_token("weiwenrui1234567890") return HttpResponse(CommonResponse(error_code=0, error_message="", data={ "token": token }).to_json(), content_type=CONTENT_TYPE_JSON)
def reset_password_token(request): """ :type request HttpRequest """ param = json.loads(request.body) phone = param["phone"] service.get_reset_password_token(phone) return HttpResponse(CommonResponse(error_code=0, error_message="", data={}).to_json(), content_type=CONTENT_TYPE_JSON)
def user_info(request): """ 获取用户主页信息 """ user = request.user if not user.is_authenticated(): return HttpResponse(CommonResponse(error_code=401, error_message="用户未登录").to_json(), content_type=CONTENT_TYPE_JSON) data = service.get_user_info(user.id) reward_cycle = RewardCycle.objects.filter().order_by( "-first_created").first() data["group_id_list"] = get_judge_set(user, reward_cycle) return HttpResponse(CommonResponse(error_code=0, error_message="", data=data).to_json(), content_type=CONTENT_TYPE_JSON)
def get_reward_cycle_view(request): """ /ad/get_reward_cycle """ get_reward_cycle = get_reward_cycle_json() return HttpResponse(CommonResponse(error_code=0, error_message="", data={ "get_reward_cycle": get_reward_cycle }).to_json(), content_type=CONTENT_TYPE_JSON)
def get_exchange_rate_view(request): """ /ad/get_exchange_rate """ exchange_rate = get_latest_exchange_rate_json() return HttpResponse(CommonResponse(error_code=0, error_message="", data={ "exchange_rate": exchange_rate }).to_json(), content_type=CONTENT_TYPE_JSON)
def get_ad_policy_view(request): """ /ad/get_ad_policy """ ad_policies = get_ad_policy() return HttpResponse(CommonResponse(error_code=0, error_message="", data={ "ad_policies": ad_policies }).to_json(), content_type=CONTENT_TYPE_JSON)
def tstatistics(request): param = json.loads(request.body) today = timezone.now() ad_source = param.get("ad_source") ad_position = param.get("ad_position") update_key = param.get("update_key") update_value = param.get("update_value") t_statistics_record_event(today, ad_source=ad_source, ad_position=ad_position, update_key=update_key, update_value=update_value) return HttpResponse(CommonResponse(error_code=0, error_message="").to_json(), content_type=CONTENT_TYPE_JSON)
def need_shield_view(request): """ /ad/need_shield/ """ param = json.loads(request.body) channel = param.get("channel") city = param.get("city") need = need_shield(channel, city) return HttpResponse(CommonResponse(error_code=0, error_message="", data={ "need_shield": need }).to_json(), content_type=CONTENT_TYPE_JSON)
def get_shield_config_view(request): """ /ad/get_shield_config """ global_shield_config, channel_shield_config_list = get_shield_config() return HttpResponse(CommonResponse(error_code=0, error_message="", data={ "global_shield_config": global_shield_config, "channel_shield_config_list": channel_shield_config_list, }).to_json(), content_type=CONTENT_TYPE_JSON)
def feedback(request): param = json.loads(request.body) description = param.get("description", "") pictures = param.get("pictures", []) contact = param.get("contact", "") phone = param.get("phone", "") UserFeedback.objects.create(description=description, pictures=json.dumps(pictures), contact=contact, phone=phone) return HttpResponse(CommonResponse(error_code=0, error_message="", data={}).to_json(), content_type=CONTENT_TYPE_JSON)
def get_reward_condition_view(request): """ /ad/get_reward_condition """ read_reward_condition, download_reward_condition = get_reward_condition_json( ) return HttpResponse(CommonResponse(error_code=0, error_message="", data={ "read_reward_condition": read_reward_condition, "download_reward_condition": download_reward_condition }).to_json(), content_type=CONTENT_TYPE_JSON)
def generate_cash_record(request): """ 生成提现记录 """ param = json.loads(request.body) user = request.user if not user.is_authenticated(): return HttpResponse(CommonResponse(error_code=401, error_message="用户未登录").to_json(), content_type=CONTENT_TYPE_JSON) money = param["money"] # 提现金额 phone = param["phone"] # 提现人填写的手机号 real_name = param.get("real_name", "") # 真是姓名 device_id = param.get("device_id", "") # 设备id identity = param["identity"] # 身份证号 machine_type = param.get("machine_type", "") # 机型 米6什么的 device_brand = param.get("device_brand", "") # 手机品牌 cash_type = param.get("cash_type", "") # 提现类型 channel = param.get("channel", "") # 渠道 version_num = param.get("version_num", "") # 版本号 code, message = service.generate_cash_record(user=user, money=money, phone=phone, real_name=real_name, device_id=device_id, channel=channel, identity=identity, version_num=version_num, machine_type=machine_type, cash_type=cash_type, device_brand=device_brand) return HttpResponse(CommonResponse(error_code=code, error_message=message).to_json(), content_type=CONTENT_TYPE_JSON)