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 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 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
def user_profile(user, params, lang): origin_user = user uuid = params.get("uuid", "") if uuid: user = User.select().where(User.uuid == uuid).first() if not user: return {"error_code": 20002, "msg": "user not exist"} profile = user.profile.first() languages = [] ul = UserLanguage.select().where(UserLanguage.user == user) for u in ul: languages.append(dict( language_id=u.id, name=u.name, level=u.level, )) out = dict() # user self can get private information if not uuid: out["reg_step"] = user.reg_step out["id_number"] = "%s********%s" % (profile.id_number[:6], profile.id_number[14:]) if profile.id_number else "" out["alipay"] = profile.alipay out["email"] = user.email out["phone"] = user.phone out["name"] = profile.name out["username"] = user.username out["avatar"] = widget.avatar(profile.avatar) out["completeness"] = profile.completeness out["visibility"] = profile.visibility out["level"] = profile.level out["title"] = profile.title out["overview"] = profile.overview out["hourly"] = profile.hourly out["english"] = profile.english out["skills"] = utils.loads(profile.skills) if profile.skills else [] out["available"] = profile.available out["workload"] = profile.workload location = {} if profile.location_id: city = widget.get_location(profile.location_id) province = widget.get_location(city.parent_id) location["location_id"] = profile.location_id location["name"] = utils.lang_map_name(city.name, city.ename, lang) location["parent_id"] = province.id location["parent_name"] = utils.lang_map_name(province.name, province.ename, lang) out["location"] = location out["address"] = profile.address out["postcode"] = profile.postcode out['id'] = user.uuid out["languages"] = languages out["imid"] = user.id if uuid: favorites = Favorite.select().where(Favorite.user==origin_user, Favorite.target_id==profile.user_id, Favorite.ftype == 'REQ').first() if favorites: out["favorite"] = True else: out["favorite"] = False # 开发者的评价数量和平均得分 score = UserStatistics.select(UserStatistics.eveluate_num, UserStatistics.aver_score).where(UserStatistics.user == user).first() out["eveluate_num"] = score.eveluate_num if score else 0 out["aver_score"] = score.aver_score if score else 0 return {"error_code": 0, "msg": "ok", "profile": out}
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 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 user_profile(user, params, lang): origin_user = user uuid = params.get("uuid", "") if uuid: user = User.select().where(User.uuid == uuid).first() if not user: return {"error_code": 20002, "msg": "user not exist"} profile = user.profile.first() languages = [] ul = UserLanguage.select().where(UserLanguage.user == user) for u in ul: languages.append(dict( language_id=u.id, name=u.name, level=u.level, )) out = dict() # user self can get private information if not uuid: out["reg_step"] = user.reg_step out["id_number"] = "%s********%s" % ( profile.id_number[:6], profile.id_number[14:]) if profile.id_number else "" out["alipay"] = profile.alipay out["email"] = user.email out["phone"] = user.phone out["name"] = profile.name out["username"] = user.username out["avatar"] = widget.avatar(profile.avatar) out["completeness"] = profile.completeness out["visibility"] = profile.visibility out["level"] = profile.level out["title"] = profile.title out["overview"] = profile.overview out["hourly"] = profile.hourly out["english"] = profile.english out["skills"] = utils.loads(profile.skills) if profile.skills else [] out["available"] = profile.available out["workload"] = profile.workload location = {} if profile.location_id: city = widget.get_location(profile.location_id) province = widget.get_location(city.parent_id) location["location_id"] = profile.location_id location["name"] = utils.lang_map_name(city.name, city.ename, lang) location["parent_id"] = province.id location["parent_name"] = utils.lang_map_name(province.name, province.ename, lang) out["location"] = location out["address"] = profile.address out["postcode"] = profile.postcode out['id'] = user.uuid out["languages"] = languages out["imid"] = user.id if uuid: favorites = Favorite.select().where( Favorite.user == origin_user, Favorite.target_id == profile.user_id, Favorite.ftype == 'REQ').first() if favorites: out["favorite"] = True else: out["favorite"] = False # 开发者的评价数量和平均得分 score = UserStatistics.select( UserStatistics.eveluate_num, UserStatistics.aver_score).where(UserStatistics.user == user).first() out["eveluate_num"] = score.eveluate_num if score else 0 out["aver_score"] = score.aver_score if score else 0 return {"error_code": 0, "msg": "ok", "profile": out}