def contract_finish(body): if "contract_id" not in body: return contract = Contract.select().where(Contract.id == body["contract_id"]).first() if not contract: return ts = TeamStatistics().select().where(TeamStatistics.team == contract.team).first() if not ts: ts = TeamStatistics() ts.user = contract.team.user ts.team = contract.team ts.total_amount += contract.total_amount if contract.hourly > 0: time_count = WeekStone.select(fn.sum(WeekStone.shot_times)).where(WeekStone.contract==contract).scalar() ts.hours += time_count ts.save() us = UserStatistics.select().where(UserStatistics.user == contract.user).first() if not us: us = UserStatistics() us.user = contract.user us.total_amount += contract.total_amount if contract.hourly > 0: us.hours += time_count us.coop_success += 1 coop_two_count = Contract.select().where(Contract.user==contract.user, Contract.status=="finish").group_by(Contract.team).having(fn.count(Contract.team) >= 2).count() us.coop_two = coop_two_count us.save()
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()
def increase_proposal(body): if "user_id" not in body: return us = UserStatistics.select().where(UserStatistics.user == body["user_id"]).first() if not us: us = UserStatistics() us.user = body["user_id"] us.proposal = 1 else: us.proposal += 1 #now = utils.now() #start = utils.timedelta(now, days=-90) #count = Proposal.select().where(Proposal.user==user_id,Proposal.ptype=='D',Proposal.create_at.between(start, now)).count() #us.season_proposal = count #us.update_at = now us.save() return
def evaluate(body): ce = ContractEvaluate.select().where(ContractEvaluate.id == body['contract_evaluate_id']).first() if not ce: return if body['role'] == "f": # 开发者评价需求者 score = decimal.Decimal(ce.exchange + ce.cooper + ce.quality + ce.skill + ce.avail + ce.deliver) else: score = decimal.Decimal(ce.exchange + ce.cooper + ce.quality + ce.skill + ce.punctual) score = score.quantize(decimal.Decimal("0.1"), rounding=decimal.ROUND_DOWN) contract = ce.contract if body['role'] == "f": ts = TeamStatistics().select().where(TeamStatistics.team == contract.team).first() if not ts: ts = TeamStatistics() ts.user = contract.team.user ts.team = contract.team ts.eveluate_num = 1 ts.score = score aver_score = decimal.Decimal(ts.score / 6).quantize(decimal.Decimal("0.1"), rounding=decimal.ROUND_DOWN) ts.aver_score = aver_score ts.save() else: ts.eveluate_num += 1 ts.score += score aver_score = decimal.Decimal(ts.score / ts.eveluate_num / 6).quantize(decimal.Decimal("0.1"), rounding=decimal.ROUND_DOWN) ts.aver_score = aver_score ts.save() else: us = UserStatistics.select().where(UserStatistics.user == contract.user).first() if not us: us = UserStatistics() us.user = contract.user us.eveluate_num = 1 us.score = score aver_score = decimal.Decimal(us.score / 5).quantize(decimal.Decimal("0.1"), rounding=decimal.ROUND_DOWN) us.aver_score = aver_score us.save() else: us.eveluate_num += 1 us.score += score aver_score = decimal.Decimal(us.score / us.eveluate_num / 5).quantize(decimal.Decimal("0.1"), rounding=decimal.ROUND_DOWN) us.aver_score = aver_score us.save() return
def increase_proposal_ok(body): if "user_id" not in body: return us = UserStatistics.select().where(UserStatistics.user == body["user_id"]).first() if not us: us = UserStatistics() us.user = int(body["user_id"]) us.success = 1 else: us.success += 1 #now = utils.now() #start = utils.timedelta(now, days=-90) #count = Proposal.select().where(Proposal.user==user_id, # Proposal.status=="interview", # Proposal.update_at.between(start, now)).count() #us.update_at = now #us.season_interview = count us.save() return
def contract_start(body): if "contract_id" not in body: return contract = Contract.select().where(Contract.id == body["contract_id"]).first() if not contract: return team = contract.team ts = TeamStatistics().select().where(TeamStatistics.team == team).first() if not ts: ts = TeamStatistics() ts.user = team.user ts.team = team ts.hires += 1 ts.save() us = UserStatistics.select().where(UserStatistics.user == contract.user).first() if not us: us = UserStatistics() us.user = contract.user us.coop += 1 us.save() return