Exemple #1
0
def create_group(body):
    if "user_id" not in body or "team_id" not in body:
        return

    if "contract_id" not in body and "proposal_id" not in body:
        return

    # 有contract_id 表示要发offer

    create_friend(body["user_id"], body["team_id"])

    if "proposal_id" not in body:
        return

    prop = Proposal.select().where(Proposal.id == body["proposal_id"]).first()
    if not prop:
        return

    img = IMGroup.select().where(IMGroup.proposal == prop).first()
    if not img:
        uri = "%s/create_group" % imserver
        param = {
            "req_user_id": body["req_user_id"],
            "group_name": body["group_name"],
            "group_type": 3,
            "token": "abc",
            "group_avatar": "",
            "user_id_list": [body["user_id"], body["team_id"]]
        }
        headers = {'user-agent': 'yunzujia async create group by zhenjing'}
        # {"error_code":0,"error_msg":"成功","group_id":194}
        try:
            res = requests.post(uri, headers=headers, data=json.dumps(param))
            logger.error("im server: %s, %s" % (res.status_code, res.content))

            cont = json.loads(res.content)
            if cont['error_code'] == 0:
                img = IMGroup()
                img.proposal = body["proposal_id"]
                if "contract_id" in body:
                    img.contract = body["contract_id"]
                img.im_group_id = cont['group_id']
                img.save()

                if "contract_id" in body:
                    contract = prop.contract
                    send_offer(contract, body, cont["group_id"])
            return
        except:
            logger.error("im server cannot connected")
            return

    if "contract_id" in body:
        contract = Contract.select().where(
            Contract.id == body["contract_id"]).first()
        group_id = img.im_group_id
        img.contract = contract
        img.save()

        send_offer(contract, body, group_id)
Exemple #2
0
def create_group(body):
    if "user_id" not in body or "team_id" not in body:
        return

    if "contract_id" not in body and "proposal_id" not in body:
        return

    # 有contract_id 表示要发offer

    create_friend(body["user_id"], body["team_id"])

    if "proposal_id" not in body:
        return

    prop = Proposal.select().where(Proposal.id == body["proposal_id"]).first()
    if not prop:
        return

    img = IMGroup.select().where(IMGroup.proposal == prop).first()
    if not img:
        uri = "%s/create_group" % imserver
        param = {"req_user_id":body["req_user_id"], "group_name":body["group_name"],
                "group_type":3, "token":"abc", "group_avatar":"", "user_id_list":[body["user_id"], body["team_id"]]}
        headers = {'user-agent': 'yunzujia async create group by zhenjing'}
        # {"error_code":0,"error_msg":"成功","group_id":194}
        try:
            res = requests.post(uri, headers=headers, data=json.dumps(param))
            logger.error("im server: %s, %s" % (res.status_code, res.content))

            cont = json.loads(res.content)
            if cont['error_code'] == 0:
                img = IMGroup()
                img.proposal = body["proposal_id"]
                if "contract_id" in body:
                    img.contract = body["contract_id"]
                img.im_group_id = cont['group_id']
                img.save()

                if "contract_id" in body:
                    contract = prop.contract
                    send_offer(contract, body, cont["group_id"])
            return
        except:
            logger.error("im server cannot connected")
            return

    if "contract_id" in body:
        contract = Contract.select().where(Contract.id == body["contract_id"]).first()
        group_id = img.im_group_id
        img.contract = contract
        img.save()

        send_offer(contract, body, group_id)
Exemple #3
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()