示例#1
0
class CheckPaymentHandler(PermissionHandler, Handler):

    order_list = ['-id', 'confirm_status']

    search_list = [
        'consultant__nickname__contains',
        'class_list__course__title__contains', 'customer__name__contains'
    ]

    search_group = [SearchOption('pay_type'), SearchOption('confirm_status')]

    def get_urls(self):
        patterns = [
            path('list/',
                 self.wrapper(self.list_view),
                 name=self.get_list_url_name),
        ]

        patterns.extend(self.extra_urls())

        return patterns

    def action_multi_check(self, request, *args, **kwargs):

        pk_list = request.POST.getlist('pk')

        for pk in pk_list:
            payment_obj = self.model_class.objects.filter(
                id=pk, confirm_status=1).first()

            if not payment_obj:
                continue
            payment_obj.confirm_status = 2
            payment_obj.save()

            payment_obj.customer.status_choices = 1
            payment_obj.customer.save()

            payment_obj.customer.student.student_status = 2
            payment_obj.customer.student.save()

    action_multi_check.text = '批量确认'

    def action_multi_cancel(self, request, *args, **kwargs):

        pk_list = request.POST.getlist('pk')
        self.model_class.objects.filter(
            id__in=pk_list, confirm_status=1).update(confirm_status=3)

    action_multi_cancel.text = '批量驳回'

    action_list = [action_multi_check, action_multi_cancel]

    list_display = [
        Handler.display_checkbox, 'customer',
        get_choice_text('费用类型', 'pay_type'), 'paid_fee', 'class_list',
        get_datetime_text('缴费日期', 'apply_date'),
        get_choice_text('状态', 'confirm_status'), 'consultant'
    ]
示例#2
0
class PrivateCustomerHandler(PermissionHandler, Handler):

    has_add_btn = True
    model_form_class = PrivateCustomerModel

    def display_record(self, obj=None, is_header=None, *args, **kwargs):

        if is_header:
            return '跟进'

        record_url = reverse('stark:proe_consultrecord_list',
                             kwargs={'customer_id': obj.pk})
        return mark_safe("<a target='_blank' href='%s'>跟进</a>" % record_url)

    def display_payment_record(self,
                               obj=None,
                               is_header=None,
                               *args,
                               **kwargs):

        if is_header:
            return '缴费'

        record_url = reverse('stark:proe_paymentrecord_list',
                             kwargs={'customer_id': obj.pk})

        return mark_safe("<a target='_blank' href='%s'>跟进</a>" % record_url)

    def get_queryset(self, request, *args, **kwargs):

        current_user_id = request.session['user_info']['id']

        return self.model_class.objects.filter(consultant_id=current_user_id)

    def save(self, request, form, is_update, *args, **kwargs):

        current_user_id = request.session['user_info']['id']
        form.instance.consultant_id = current_user_id
        form.save()

    def action_multi_remove(self, request, *args, **kwargs):

        current_user_id = request.session['user_info']['id']
        pk_list = request.POST.getlist('pk')
        self.model_class.objects.filter(
            id__in=pk_list,
            consultant_id=current_user_id).update(consultant_id=None)

    action_multi_remove.text = '批量移除到公户'
    action_list = [
        action_multi_remove,
    ]
    list_display = [
        Handler.display_checkbox, 'name', 'contact',
        get_choice_text('状态', 'status'), display_record,
        display_payment_record, Handler.display_edit, Handler.display_del
    ]
示例#3
0
class HandelUserInfo(Handler):
    has_add_btn = True

    per_page_count = 3

    model_form_class = UserInfoModelForm

    search_list = ['name__contains', 'email__contains']  # 定义模糊查询的查询条件

    action_list = [
        Handler.multi_delete,
    ]

    search_group = [
        SearchOption(
            'gender',
            text_func=lambda field_obj: field_obj[1] + '333'),  # 定制筛选按钮显示文字
        SearchOption('depart', {'id__gt': 0}, is_multi=True)
    ]

    def display_depart(self, obj=None, is_header=None):
        '''
        定义页面显示信息,当需要进行连表查询时用,如果表的类设置了__str__方法可以直接显示,没有定义此方法可以用这个
        :param obj:
        :param is_header:
        :return:
        '''
        if is_header:
            return '部门'
        return obj.depart.title

    # def save(self, form, is_update=False):
    #     form.instance.depart_id = 1
    #     form.save()

    # 定制页面显示列
    list_display = [
        Handler.display_checkbox, 'name',
        get_choice_text('性别', 'gender'), 'email', display_depart,
        Handler.display_edit, Handler.display_del
    ]
示例#4
0
class StudentHandler(PermissionHandler, Handler):

    model_form_class = StudentModelForm
    search_list = [
        'qq__contains', 'mobile__contains', 'customer__name__contains'
    ]
    search_group = [
        SearchOption('class_list',
                     text_func=lambda x: '%s-%s' % (x.school.title, str(x)))
    ]

    def display_score(self, obj=None, is_header=None, *args, **kwargs):

        if is_header:
            return '积分管理'
        record_url = reverse('stark:proe_scorerecord_list',
                             kwargs={'student_id': obj.pk})

        return mark_safe("<a target='_blank' href='%s'>%s</a>" %
                         (record_url, obj.score))

    def get_urls(self):

        patterns = [
            path('list/',
                 self.wrapper(self.list_view),
                 name=self.get_list_url_name),
            re_path(r'^edit/(?P<pk>\d+)/$',
                    self.wrapper(self.edit_view),
                    name=self.get_edit_url_name)
        ]
        patterns.extend(self.extra_urls())

        return patterns

    list_display = [
        'customer', 'qq', 'mobile', 'emergency_contract',
        get_m2m_text('已报班级', 'class_list'), display_score,
        get_choice_text('状态', 'student_status'), Handler.display_del
    ]
示例#5
0
class PayRecordHandler(PermissionHandler, Handler):

    has_add_btn = True

    def get_list_display(self, request, *args, **kwargs):

        value = []
        if self.list_display:
            value.extend(self.list_display)
        return value

    def get_urls(self):

        patterns = [
            re_path(r'^list/(?P<customer_id>\d+)/$',
                    self.wrapper(self.list_view),
                    name=self.get_list_url_name),
            re_path(r'^add/(?P<customer_id>\d+)/$',
                    self.wrapper(self.add_view),
                    name=self.get_add_url_name)
        ]

        patterns.extend(self.extra_urls())

        return patterns

    def get_queryset(self, request, *args, **kwargs):

        current_user_id = request.session['user_info']['id']
        customer_id = kwargs.get('customer_id')
        obj = self.model_class.objects.filter(
            customer__consultant_id=current_user_id, customer_id=customer_id)

        return obj

    def get_model_form_class(self, is_add, request, pk, *args, **kwargs):

        customer_id = kwargs.get('customer_id')
        student_exists = models.Student.objects.filter(
            customer_id=customer_id).exists()

        if not student_exists:
            return StudentPaymentRecordModel
        return PaymentModel

    def save(self, request, form, is_update, *args, **kwargs):

        current_user_id = request.session['user_info']['id']
        customer_id = kwargs.get('customer_id')

        obj_exists = models.Customer.objects.filter(
            id=customer_id, consultant_id=current_user_id).exists()

        if not obj_exists:
            return HttpResponse('非法操作')

        form.instance.customer_id = customer_id
        form.instance.consulant_id = current_user_id
        form.save()

        class_list = form.cleaned_data['class_list']
        fetch_student = models.Student.objects.filter(
            customer_id=customer_id).first()

        if not fetch_student:

            qq = form.cleaned_data['qq']
            mobile = form.cleaned_data['mobile']
            emergency_contract = form.cleaned_data[' emergency_contract']
            student_object = models.Student.objects.create(
                qq=qq,
                mobile=mobile,
                emergency_contract=emergency_contract,
                customer_id=customer_id)
            student_object.class_list.add(class_list.id)
        else:
            fetch_student.class_list.add(class_list.id)

    list_display = [
        get_choice_text('费用类型', 'pay_type'), 'paid_fee', 'class_list',
        get_datetime_text('申请日期', 'apply_date'), 'consultant',
        get_choice_text('状态', 'confirm_status')
    ]
示例#6
0
class UserHandler(PermissionHandler, Handler):

    has_add_btn = True
    search_list = [
        'name__contains', 'nickname__contains', 'depart__title__contains'
    ]
    search_group = [
        SearchOption('gender'),
        SearchOption('depart', is_multi=True)
    ]

    def get_model_form_class(self, is_add, request, pk, *args, **kwargs):

        if is_add:
            return UserAddModel
        return UserChangeModel

    def display_reset_password(self,
                               obj=None,
                               is_header=None,
                               *args,
                               **kwargs):

        if is_header:
            return '重置密码'
        return mark_safe("<a href='%s'>重置密码</a>" %
                         self.reverse_reset_password_url(pk=obj.pk))

    @property
    def get_reset_password_url_name(self):

        return self.get_url_name('reset_password')

    def reverse_reset_password_url(self, *args, **kwargs):

        return self.reverse_common_url(self.get_reset_password_url_name, *args,
                                       **kwargs)

    def extra_urls(self):

        patterns = [
            re_path(r'^reset/password/(?P<pk>\d+)/$',
                    self.wrapper(self.reset_password_view),
                    name=self.get_reset_password_url_name)
        ]

        return patterns

    def reset_password_view(self, request, pk, *args, **kwargs):

        user_obj = models.UserInfo.objects.filter(pk=pk).first()

        if not user_obj:
            return HttpResponse('用户不存在!')

        if request.method == 'GET':

            form = UserPasswordModel()
            return render(request, 'stark/change.html', {'form': form})

        form = UserPasswordModel(data=request.POST)
        if form.is_valid():
            user_obj.password = get_md5(form.cleaned_data['password'])
            user_obj.save()

            return redirect(self.reverse_list_url())
        return render(request, 'stark/change.html', {'form': form})

    list_display = [
        'name', 'nickname',
        get_choice_text('性别', 'gender'), 'phone', 'email', 'depart',
        display_reset_password, Handler.display_edit, Handler.display_del
    ]
示例#7
0
class PublicCustomerHandler(PermissionHandler, Handler):
    has_add_btn = True

    model_form_class = PublicCustomerModelForm

    def get_queryset(self, request, *args, **kwargs):
        return self.model_class.objects.filter(consultant__isnull=True)

    def display_record(self, obj=None, is_header=None, *args, **kwargs):

        if is_header:
            return '跟进记录'
        record_url = self.reverse_common_url(self.get_url_name('record_view'), pk=obj.pk)
        return mark_safe("<a href='%s'>查看跟进记录</a>" % record_url)

    def record_view(self, request, pk, *args, **kwargs):
        '''
        查看跟进记录
        :return:
        '''

        record_list = models.ConsultRecord.objects.filter(customer_id=pk)

        return render(request, 'record.html', {'record_list': record_list})

    def extra_urls(self):
        patterns = [re_path(r'^record/(?P<pk>\d+)/$', self.wrapper(self.record_view),
                            name=self.get_url_name('record_view'))]
        return patterns

    def action_multi_apply(self, request, *args, **kwargs):
        '''
        批量申请到私户
        :param request:
        :param args:
        :param kwargs:
        :return:
        '''

        current_user = request.session['user_info']['id']

        pk_list = request.POST.getlist('pk')

        # 用户私户中未转化的客户数量
        private_customer_count = models.Customer.objects.filter(consultant_id=current_user, status=2).count()

        # 对私户中未转化的客户数量限制
        if private_customer_count + len(pk_list) > 150:
            return HttpResponse('客户数量超标,私户中已经有了%s个客户,最多再能添加%s个客户' % (
                private_customer_count, 150 - private_customer_count
            ))

        # 数据库中加事务锁,防止两个人同时申请同一个客户造成混乱
        flag = False
        with transaction.atomic():
            # 在数据库中加锁
            origin_queryset = models.Customer.objects.filter(id__in=pk_list, status=2,
                                                             consultant__isnull=True).select_for_update()

            if len(origin_queryset) == len(pk_list):
                models.Customer.objects.filter(id__in=pk_list, status=2, consultant__isnull=True).update(
                    consultant_id=current_user)
                flag = True

        if not flag:
            return HttpResponse('手速太慢')

    action_multi_apply.text = '批量申请到私户'

    action_list = [action_multi_apply, ]

    list_display = [Handler.display_checkbox, 'name', 'contact', get_choice_text('状态', 'status'),
                    get_m2m_text('咨询课程', 'course'),
                    display_record, Handler.display_edit, Handler.display_del]