Пример #1
0
def join_fools(request):
    user = request.session["user"]
    if request.POST:
        rem = request.POST["rem"]
        if int(rem) == 1:
            FoolsDay.objects.join_act(user_id=user.user_id)
            return JsonResponse({"statu": 200, "user_id": user.user_id})
        else:
            pass
    else:
        return page_not_found(request)
Пример #2
0
def create_active(request):
    user = request.session["user"]
    if request.POST:
        # 传过来的状态码,1代表余额,0代表提现
        status = int(request.POST["req"])
        # 每有一个人激活,就给激活的那个人赠送0.41
        user = UserInfo.objects.get(user_id=user.user_id)
        user.balance += decimal.Decimal(0.41)
        user.save()
        #先判断用户是否已经创建了愚人节活动
        if FoolsDay.objects.join_in_fools(user_id=user.user_id):
            print("用户已经创建了愚人节活动")
            return JsonResponse({"status": 403})
        else:
            print("给用户创建愚人节活动表")
            # 给用户创建愚人节活动表
            if status == 1:
                FoolsDay.objects.create(user_id=user.user_id,
                                        add_point=5,
                                        reduce_point=0,
                                        point_all=5,
                                        status=status,
                                        is_no_join=0)
            else:
                FoolsDay.objects.create(user_id=user.user_id,
                                        add_point=0,
                                        reduce_point=3,
                                        point_all=3,
                                        status=status,
                                        is_no_join=0)
        # 查询当前点击用户的上级邀请用户的userID
        inviter = UserInvite.objects.filter(invite=user.wechat_id, fools_day=1)
        if inviter:
            # 上级用户的邀请id是
            uper = inviter[0].user_id
            print("上级用户的userid是{}".format(uper))
            # 若用户点击的是余额,则是增加积分
            if len(FoolsDay.objects.filter(user_id=uper)) > 0:
                if status == 0:
                    print("用户点击的是提现开始给用户增加积分")
                    FoolsDay.objects.add_points(user_id=uper)
                # 若用户点击的是提现,则减少积分
                else:
                    print("用户点击的是余额,开始给用户减少积分")
                    FoolsDay.objects.reduce_points(user_id=uper)
                FoolsDay.objects.update_point(user_id=uper)
                return JsonResponse({"status": 200})
            else:
                return JsonResponse({"status": 403})
        else:
            return JsonResponse({"status": 200})
    else:
        return page_not_found(request)
Пример #3
0
def show_sleeping_goal(request, pk):
    goal_id = pk
    goal = SleepingGoal.objects.filter(goal_id=goal_id).filter(
        activity_type=SleepingGoal.get_activity()).first()
    if goal:
        if goal.status != "ACTIVE":
            return render(request, 'goal/finish.html', {
                'goal': goal,
                'goal_type': SleepingGoal.get_activity()
            })
        else:
            # 延迟券
            delay_ticket = UserTicket.objects.get_delay_tickets(
                goal_id=goal_id)
            # 免签券
            nosign_ticket = UserTicket.objects.get_nosigned_tickets(
                goal_id=goal_id)
            # 天数
            dates_inform = get_days(goal)
            # 查询 Activity 相关的活动信息, 找到第一个符合类型要求且在进行中的活动
            app = Activity.objects.get_active_activity(
                activity_type=SleepingGoal.get_activity())
            # TODO:FAKE
            app = fake_data([app])[0]
            # 查询头像
            person_goals = SleepingGoal.objects.filter(status="ACTIVE")[:5]
            persons = set()
            for person_goal in person_goals:
                persons.add(UserInfo.objects.get(user_id=person_goal.user_id))

            return render(
                request, "goal/sleeping.html", {
                    "app": app,
                    "goal": goal,
                    'delay': delay_ticket,
                    'nosign': nosign_ticket,
                    "datesinform": dates_inform,
                    "getuptime": goal.getup_time.strftime("%H:%M"),
                    "persons": persons
                })
    else:
        return page_not_found(request)
Пример #4
0
def show_reading_goal(request, pk):
    user = request.session['user']
    goal_id = pk
    goal = ReadingGoal.objects.filter(goal_id=goal_id).filter(
        activity_type=ReadingGoal.get_activity()).first()
    if goal:
        if goal.status != "ACTIVE":
            return render(request, 'goal/finish.html', {
                'goal': goal,
                'goal_type': ReadingGoal.get_activity()
            })
        else:
            # 天数
            dates_inform = get_days(goal)
            # 查询 Activity 相关的活动信息, 找到第一个符合类型要求且在进行中的活动
            app = Activity.objects.get_active_activity(
                activity_type=ReadingGoal.get_activity())
            person_goals = ReadingGoal.objects.filter(status="ACTIVE")[:5]
            persons = set()
            # TODO:FAKE
            app = fake_data([app])[0]
            for person_goal in person_goals:
                persons.add(UserInfo.objects.get(user_id=person_goal.user_id))

            return render(
                request, "goal/reading.html", {
                    "WechatJSConfig": get_wechat_config(request),
                    "app": app,
                    "goal": goal,
                    "datesinform": dates_inform,
                    "notice":
                    UserAddress.objects.address_is_complete(user=user),
                    "persons": persons,
                })
    else:
        return page_not_found(request)
Пример #5
0
def show_riding_goal(request, pk):
    print('进入骑行活动')
    # 开始
    user = request.session["user"]
    goal_id = pk
    print('goal_id', pk)
    goal = RidingGoal.objects.filter(goal_id=goal_id).filter(
        activity_type=RidingGoal.get_activity()).first()
    if goal:
        if goal.status != "ACTIVE":
            return render(
                request, 'goal/riding.html', {
                    'goal': goal,
                    'goal_type': RidingGoal.get_activity(),
                    "headimg": user.headimgurl
                })
        else:
            # 免签券数量查询
            nosign_ticket = UserTicket.objects.get_nosigned_tickets(
                goal_id=goal_id)
            # 天数
            dates_inform = get_days(goal)
            # 查询 Activity 相关的活动信息, 找到第一个符合类型要求且在进行中的活动
            app = Activity.objects.get_active_activity(
                activity_type=RidingGoal.get_activity())
            # TODO:FAKE
            # app = fake_data([app])[0]
            # 查询 Activity 相关的头像信息
            person_goals = RidingGoal.objects.filter(status="ACTIVE")[:10]
            persons = set()
            for person_goal in person_goals:
                persons.add(UserInfo.objects.get(user_id=person_goal.user_id))
            # 随机查询24小时内存在的打卡记录,展示在本页面中
            # lastday, today = timezone.now() - timedelta(days=1), timezone.now()
            lastday = timezone.now() - timedelta(days=1)
            today = timezone.now()
            random_records = RidingPunchRecord.objects.filter(
                record_time__range=(lastday,
                                    today)).order_by("-record_time")[:20]

            # activate_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))
            # 获取邀请了多少好友
            # num = UserInvite.objects.filter(user_id=request.session["user"].user_id).count()

            obj = RidingGoal.objects.filter(user_id=user.user_id,
                                            status="ACTIVE")[0]
            # 该活动的打卡天数
            punch_day = obj.punch_day
            # 该活动的额外收益
            extra_earn = obj.extra_earn
            a = goal.start_time.strftime("%Y-%m-%d")
            user_end_time = (goal.start_time +
                             timedelta(days=1)).strftime("%Y-%m-%d")
            # if len(RunningPunchRecord.objects.filter(goal_id=goal_id, record_time__range=(a, user_end_time))) > 0:
            #     first_day_record = 1
            # else:
            #     first_day_record = 0

            news = []
            for record in random_records:
                voucher_ref_list = record.voucher_ref.split(",")
                userinfo = UserInfo.objects.get(user_id=record.goal.user_id)
                # reply = RunReply.objects.filter(other_id=str(record.punch_id).replace("-","")).order_by('-id')
                # response = [{"content": i.r_content, "user_id": i.user_id, "nickname": i.get_user_message.nickname} for
                #             i in reply] if len(reply) > 0 else ""
                document = record.document
                # report = RunningPunchReport.objects.filter(punch_id=record.punch_id).filter(user_id=user.user_id)
                # is_no_report = 1 if report else 0
                # praise = RunningPunchPraise.objects.filter(punch_id=record.punch_id).filter(user_id=user.user_id)
                # is_no_praise=1 if praise else 0
                record_time = record.record_time
                dis_day = "今日" if record_time.day == today.day else "昨日"
                dis_date = "%s %s:%02d" % (dis_day, record_time.hour,
                                           record_time.minute)
                news.append({
                    "headimage": userinfo.headimgurl,
                    "date": dis_date,
                    "distance": record.distance,
                    # "praise": record.praise,
                    # "report": record.report,
                    'reload': record.reload,
                    # 'is_no_report': is_no_report,
                    # 'is_no_praise': is_no_praise,
                    "name": userinfo.nickname,
                    "voucher_ref": voucher_ref_list,
                    "punch_id": record.punch_id,
                    "document": document,
                    'test': timezone.now(),
                    # "reply_data":response,
                })
            if app:
                return render(
                    request,
                    "goal/riding.html",
                    {
                        "WechatJSConfig": get_wechat_config(request),
                        "app": app,
                        "goal": goal,
                        # "invite_num": num,
                        'nosign': nosign_ticket,
                        "datesinform": dates_inform,
                        "extra_earn": extra_earn,
                        "persons": persons,
                        "news": news,
                        'nickname': user.nickname,
                        "punch_day": punch_day,
                        # "first_day_record": first_day_record
                        # "punch_id":punch_record
                    })
            else:
                return page_not_found(request)
    else:
        return page_not_found(request)
Пример #6
0
def show_sleeping_goal(request, pk):
    from on.activities.sleeping.models import Coefficient
    # goal_id = pk
    goal = SleepingGoal.objects.filter(goal_id=pk).filter(activity_type=SleepingGoal.get_activity()).first()
    user = request.session['user']
    user_id = user.user_id
    print_test()
    if goal:
        if goal.status != "ACTIVE":
            return render(request, 'goal/finish.html',
                          {
                              'goal': goal,
                              'goal_type': SleepingGoal.get_activity(),
                              "headimg":user.headimgurl
                          })
        else:
            # 天数
            sleep_type = goal.sleep_type
            dates_inform = get_days(goal,sleep_type)
            # 查询 Activity 相关的活动信息, 找到第一个符合类型要求且在进行中的活动
            app = Activity.objects.get_active_activity(activity_type=SleepingGoal.get_activity())
            new_coeff = 0
            default = 0
            extra_coeff=0
            try:
                coeff = Coefficient.objects.get(user_id=user_id)
                default = coeff.default_coeff
                new_coeff = coeff.new_coeff
                if new_coeff:
                    extra_coeff = (new_coeff-default)/default*decimal.Decimal(100)
                    if extra_coeff >0:
                        extra_coeff  = "+%2d"%extra_coeff+"%"
                    elif extra_coeff <0:
                        extra_coeff = "%2d"%extra_coeff+"%"
                    else:
                        pass
                else:
                    extra_coeff =""
            except Coefficient.DoesNotExist as e:
                print(e)
            # 查询头像
            person_goals = SleepingGoal.objects.filter(status="ACTIVE")[:5]
            persons = set()
            for person_goal in person_goals:
                persons.add(UserInfo.objects.get(user_id=person_goal.user_id))
            # datas = comment_all(user=user)
            return render(request, "goal/sleeping.html",
                          {
                              "app": app,
                              "WechatJSConfig": get_wechat_config(request),
                              "goal": goal,
                              "nickname": user.nickname,
                              "datesinform": dates_inform,
                              "new_coeff":new_coeff,
                              # "getuptime": goal.getup_time.strftime("%H:%M"),
                              "persons": persons,
                              "datas": comment_all(user=user),
                              "default":default,
                              "extra_coeff":extra_coeff
                          })
    else:
        return page_not_found(request)