Ejemplo n.º 1
0
def calc_user_discover(body):
    now = utils.now()
    start = utils.timedelta(now, days=-90)
    year_start = utils.timedelta(now, days=-365)
    id_start = 0
    while 1:
        users = User.select(User.id).where(User.id>id_start).limit(200)
        if not users:
            break

        for u in users:
            user_id = u.id
            id_start = u.id

            us = UserStatistics.select().where(UserStatistics.user == u.id).first()
            if not us:
                us = UserStatistics()
                us.user = u.id
            count = UserDiscover.select(fn.SUM(UserDiscover.view_num)).where(UserDiscover.user==user_id, UserDiscover.update_at.between(start, now)).scalar()
            us.season_view = count if count else 0

            # 90天内投标
            count = Proposal.select().where(Proposal.user==user_id,Proposal.ptype=='D',Proposal.create_at.between(start, now)).count()
            us.season_proposal = count

            # 90内沟通中
            count = Proposal.select().where(Proposal.user==user_id,
                                    Proposal.status=="interview",
                                    Proposal.update_at.between(start, now)).count()
            us.season_interview = count

            # 90天内被邀请
            count = Proposal.select().where(Proposal.user==user_id,Proposal.ptype=='I',Proposal.create_at.between(start, now)).count()
            us.season_invite = count

            # 90天内被邀请回复
            count = Proposal.select().where(Proposal.user==user_id,
                                    Proposal.ptype=='I',Proposal.status=="interview",
                                    Proposal.update_at.between(start, now)).count()
            us.season_reply = count
            # 90天内被邀请当天回复
            count1 = Proposal.select().where(Proposal.user==user_id,
                                    Proposal.ptype=='I',Proposal.day_reply==True,
                                    Proposal.update_at.between(start, now)).count()
            us.season_day_reply = count1

            # 90天内雇佣
            count = Proposal.select().where(Proposal.user==user_id,
                                    Proposal.status=="hire",
                                    Proposal.update_at.between(start, now)).count()
            us.season_hire = count

            # 一年内收总金额
            year_amount = MarginRecord.select(fn.SUM(MarginRecord.amount)).where(MarginRecord.user==user_id, 
                                        MarginRecord.record_type=="income", MarginRecord.create_at.between(year_start, now)).scalar()
            us.year_amount = year_amount if year_amount else 0
            us.update_at = now
            us.save()
Ejemplo n.º 2
0
def client_login(params):
    code = params.get("code")
    if not code or len(code) != 36:
        return {"error_code":1, "msg":"params invalid"}
    key = "jump-%s" % code
    obj = misc.misc_get(key)
    if not obj:
        return {"error_code":1, "msg":"code not exists"}
    dic = utils.loads(obj.value)

    obj.delete_instance()
    if dic['expire_at'] < utils.stamp():
        return {"error_code":1, "msg":"code expire"}

    user = User.select().where(User.id==dic['user_id']).first()
    res = {"error_code":0, "msg":"ok"}
    res['session_token'] = generate_token()
    sess = Session()
    sess.user = user
    sess.session_key = res['session_token']
    sess.expire_at = utils.timedelta(utils.now(), days=1)
    res['expire_at'] = 0
    sess.save()
    res['identify'] = user.identify
    return res
Ejemplo n.º 3
0
def count_weekstone(body):
    now = utils.now()
    start = utils.timedelta(now, days=-7)
    day_start = utils.datetime_day_min(start)
    day_end = utils.datetime_day_max(start)

    weekstones = WeekStone.select().where(WeekStone.start_at.between(day_start, day_end))
    for ws in weekstones:
        # 合同状态和时薪周状态都是进行中的才自动提审
        if ws.contract.status != "carry":
            continue
        if ws.status != "carry":
            continue

        with database.atomic() as txn:
            try:
                record = WeekStoneRecord()
                record.weekstone = ws
                record.save()

                ws.status = "carry_pay"
                ws.contract.stone_status = "carry_pay"
                ws.contract.save()
                ws.save()
                queue.to_queue({"type": "weekstone_freelancer_audit", "weekstone_id": ws.id})
            except:
                txn.rollback()
Ejemplo n.º 4
0
def weekstone_day_report(body):
    now = utils.local_datetime(utils.now())
    yestorday = utils.timedelta(now, days=-1)
    start = utils.datetime_day_min(yestorday, utc=False)
    end = utils.datetime_day_max(yestorday, utc=False)

    records = ShotRecord.select().where(ShotRecord.shot_at>=start, ShotRecord.shot_at<end)
    period = end.strftime('%Y%m%d')
    dic = {}
    for rd in records:
        weekstone_id = rd.weekstone_id
        if weekstone_id not in dic:
            dic[weekstone_id] = 1
        else:
            dic[weekstone_id] += 1

    for x in dic:
        ws = WeekStone.select().where(WeekStone.id == x).first()
        contract = ws.contract

        report = WeekStoneReport()
        report.contract = contract
        report.user = contract.user
        report.team = contract.team
        report.weekstone = ws
        report.period = period
        report.times = dic[x]
        report.hourly = contract.hourly
        if ws.status == "finish":
            report.status = ws.status
        else:
            report.status = "carry"
        report.save()
Ejemplo n.º 5
0
def client_login(params):
    code = params.get("code")
    if not code or len(code) != 36:
        return {"error_code": 1, "msg": "params invalid"}
    key = "jump-%s" % code
    obj = misc.misc_get(key)
    if not obj:
        return {"error_code": 1, "msg": "code not exists"}
    dic = utils.loads(obj.value)

    obj.delete_instance()
    if dic['expire_at'] < utils.stamp():
        return {"error_code": 1, "msg": "code expire"}

    user = User.select().where(User.id == dic['user_id']).first()
    res = {"error_code": 0, "msg": "ok"}
    res['session_token'] = generate_token()
    sess = Session()
    sess.user = user
    sess.session_key = res['session_token']
    sess.expire_at = utils.timedelta(utils.now(), days=1)
    res['expire_at'] = 0
    sess.save()
    res['identify'] = user.identify
    return res
Ejemplo n.º 6
0
def check_offer_expire(body):
    # offer 2 天没处理就过期,钱退回到账户
    now = utils.now()
    start = utils.timedelta(now, days=-2)
    # TODO 分页
    records = Contract.select().where(Contract.create_at<=start, Contract.status=='paid')
    for contract in records:
        with database.atomic() as txn:
            try:
                contract.status = "expire"
                contract.expire_at = now
                contract.save()
                margin.refund_amount(contract.team.user, contract.team, contract.job, contract.amount)
                # send msg to user
                queue.to_queue({"type": "contract_expire", "contract_id": contract.id})
            except:
                txn.rollback()
Ejemplo n.º 7
0
def auto_pay_weekstone(body):
    now = utils.now()
    start = utils.timedelta(now, days=-2)
    start = utils.now()
    records = WeekStoneRecord.select().where(WeekStoneRecord.create_at<=start, WeekStoneRecord.audit_at.is_null(True))
    for rd in records:
        ws = rd.weekstone
        if ws.status != "carry_pay":
            continue
        contract = ws.contract
        if contract.status != "carry":
            continue

        with database.atomic() as txn:
            try:
                if ws.shot_times > contract.workload * 6:
                    pay_times = contract.workload * 6
                    amount = contract.amount
                else:
                    pay_times = ws.shot_times
                    amount = utils.decimal_two(contract.hourly * ws.shot_times / 6)
                ws.actual_amount = amount
                ws.status = "finish"
                ws.end_at = now

                order = margin.payment_freelancer(contract.team.user, contract.user, contract.team, amount, contract.job)
                ws.pay_order = order
                ws.save()

                contract.total_amount += amount
                contract.stone_status = "carry"
                contract.save()

                if amount != ws.amount:
                    margin.refund_amount(contract.team.user, contract.team, contract.job, ws.amount-amount)

                rd.audit_at = now
                rd.save()
                contract.status = "pause"
                contract.save()
            except:
                logger.error(traceback.format_exc())
                txn.rollback()
Ejemplo n.º 8
0
def login(uname, password):
    if not uname or not password:
        return {"error_code":20001, "msg":"parameters required"}

    user = User.select().where(User.username == uname or User.email == uname or User.phone == uname).first()
    if not user:
        return {"error_code":20002, "msg":"user not exists"}
    if not check_password(password, user.password, user.salt):
        return {"error_code":20003, "msg":"username or password invalid"}

    res = {"error_code":0, "msg":"ok"}
    res['session_token'] = generate_token()
    sess = Session()
    sess.user = user
    sess.session_key = res['session_token']

    sess.expire_at = utils.timedelta(utils.now(), days=1)
    res['expire_at'] = 0
    sess.save()

    return res
Ejemplo n.º 9
0
def login(uname, password):
    if not uname or not password:
        return {"error_code":20001, "msg":"parameters required"}

    user = SystemUser.select().where(SystemUser.username == uname).first()
    if not user:
        return {"error_code":20002, "msg":"user not exists"}
    if not check_password(password, user.password, user.salt):
        return {"error_code":20003, "msg":"username or password invalid"}

    res = {"error_code":0, "msg":"ok"}
    res['session_token'] = generate_token()
    sess = Session()
    sess.user = user
    sess.session_key = res['session_token']

    sess.expire_at = utils.timedelta(utils.now(), days=1)
    res['expire_at'] = 0
    sess.save()

    return res