Exemplo n.º 1
0
def buy(request):
    """
    @summary: 购买简历
    """
    try:
        p = request.GET.copy()
        resume_id = p.get('resume_id', '')
        feed_id = p.get('feed_id', '')
        keywords = p.get('feed_keywords', '')
        job_id = p.get('job_id', '')
        user = request.user

        if ResumeBuyRecord.objects.filter(user=request.user, resume_id=resume_id).count():
            json_data = produce_return_json(data=2, status=False, error_dict=u'2.已购买过此简历_has bought this resume')
        else:
            pkg_points, user_points = point_utils.get_user_point(user)
            result, point = point_utils.consume_download_point(user)
            if result == 'success':
                status = 'LookUp' if ContactInfoData.objects.filter(resume_id=ObjectId(resume_id)).count() > 0 else 'Start'
                if status == 'LookUp':
                    # pinbot系统已经购买过,可以马上查阅了
                    json_data = produce_return_json(data=8)
                else:
                    # pinbot系统还没有,要等一段时间,后边邮件提醒一下
                    json_data = produce_return_json(data=9)

                resume = ResumeData.objects.get(pk=ObjectId(resume_id))
                record = ResumeBuyRecord(user=user, resume_id=resume_id, \
                                         feed_id=feed_id,
                                         keywords=keywords,
                                          op_time=datetime.now(), status=status, resume_url=resume.url)
                if status == 'LookUp':
                    record.finished_time = datetime.now()

                PartnerCoinUtils.download_resume(feed_id, resume_id)
                JobUtils.download_send_resume(job_id, user)

                # 反馈结果给算法,修改feed_result
                FeedUtils.feed_result_download(resume_id, feed_id)
                send_id = p.get('sendid',None)
                if send_id:
                    send_record = SendCompanyCard.objects.get(id=int(send_id))
                    record.send_card = send_record
                    send_record.points_used = 13
                    send_record.has_download = True
                    send_record.save()

                record.save()

                # 如果状态是start,就表示是当前库中没有该简历的联系信息,先发送一个通知给管理员
                # 然后需要通知爬虫去下载
                if record.status == 'Start':
                    notify_buy_resume(user, str(resume_id), resume.source)
                    asyn_send_download_msg.delay(record.id)
            else:
                json_data = produce_return_json(
                    data=5,
                    status=False,
                    error_dict=u'点数不足10点',
                    msg=u'聘点不足10点'
                )
    except Exception, e:
        if resume_id:
            json_data = produce_return_json(data=4, status=False, error_dict=str(e))
        else:
            json_data = produce_return_json(data=4, status=False, error_dict='4.resume_id is null')