crm销售管理系统一

一、环境配置

1、首先配置pip,环境变量配置

pip 9.0.1 from c:\users\administrator\envs\crm\lib\site-packages (python 3.6)

2、安装虚拟环境

C:\Users\Administrator>pip install virtualenvwrapper-win

Collecting virtualenvwrapper-win

  Downloading virtualenvwrapper-win-1.2.4.tar.gz

Collecting virtualenv (from virtualenvwrapper-win)

  Downloading virtualenv-15.1.0-py2.py3-none-any.whl (1.8MB)

    100% |████████████████████████████████| 1.8MB 393kB/s

Installing collected packages: virtualenv, virtualenvwrapper-win

  Running setup.py install for virtualenvwrapper-win ... done

Successfully installed virtualenv-15.1.0 virtualenvwrapper-win-1.2.4

3、创建crm这个虚拟环境

C:\Users\Administrator>mkvirtualenv crm

 C:\Users\Administrator\Envs is not a directory, creating

Using base prefix 'c:\\users\\administrator\\appdata\\local\\programs\\python\\python36'

New python executable in C:\Users\Administrator\Envs\crm\Scripts\python.exe

Installing setuptools, pip, wheel...done.    

 

环境

(crm) C:\Users\Administrator>python --version

Python 3.6.3

(crm) C:\Users\Administrator>pip list

Django (1.11)

pip (9.0.1)

pytz (2017.3)

setuptools (38.2.3)

wheel (0.30.0)

二、创建项目

项目创建:

指定创建的环境

env->scripts->python.exe

组件:

django

boostrap

jquery

 

准备:

1)创建project

python manage.py startapp app01

2)设计表结构

目录结构:

 

 

权限:

1)每个人的信息别人不能看

2)领导能看到的信息别人不能看

表结构如下:

from django.db import models
from django.contrib.auth.models import User

class Customer(models.Model):
    """客户信息表
        blank是用于限制admin null为了限制数据库,所以这两个成对出现
    """
    name = models.CharField(max_length=32,blank=True,null=True)
    qq = models.CharField(max_length=64,unique=True)
    phone = models.CharField(max_length=64,blank=True,null=True,help_text="电话")
    source_choices = ((0,"转介绍"),
                      (1,"qq群"),
                      (2,"官网"),
                      (3,"51cto"),
                      (4,"知乎"),
                      (5,"市场推广"))

    source = models.SmallIntegerField(choices=source_choices,help_text="来源")
    referral_from = models.CharField(verbose_name="转介绍人qq",max_length=64,blank=True,null=True)
    consult_course = models.ForeignKey("Course",verbose_name="咨询课程")
    content = models.TextField(verbose_name="咨询详情")
    consultant = models.ForeignKey("UserProfile",verbose_name="那个人的销售记录")
    date = models.DateTimeField(auto_now_add=True,verbose_name="时间,这里自增")
    memo=models.CharField(blank=True,null=True,verbose_name="备注")
    tags = models.ManyToManyField("Tag",blank=Tag,null=True,verbose_name="和标签多对多")

    def __str__(self):
        return self.qq

class Tag(models.Model):
    name=models.CharField(unique=True,max_length=32,verbose_name="标签")

    def __str__(self):
        return self.name

class CustomerFollowUp(models.Model):
    """客户跟进表"""
    customer = models.ForeignKey("Customer",verbose_name="和客户多对一")
    content = models.TextField(verbose_name="跟进内容")
    consultant = models.ForeignKey("UserProfile",verbose_name="跟进人")
    date = models.DateTimeField(auto_now=True)
    intention_choice = ((0,"2周内报名"),
                        (1,"1个月内报名"),
                        (2,"近期无报名计划"),
                        (3,"已在其他机构报名"),
                        (4,"已报名"),
                        (5,"已拉黑"))
    intention = models.SmallIntegerField(choices=intention_choice,verbose_name="报名计划")
    date = models.DateTimeField(auto_now_add=True,verbose_name="时间")

    def __str__(self):
        return "<%s:%s>"%(self.customer.qq,self.intention)


class Course(models.Model):
    """课程表"""
    name = models.CharField(max_length=64,unique=True,verbose_name="课程名字")
    price = models.PositiveIntegerField(verbose_name="价格")
    period=models.PositiveIntegerField(verbose_name="课程周期")
    outline=models.TextField(verbose_name="课程大纲")

    def __str__(self):
        return self.name

class branch(models.Model):
    """校区"""
    name=models.CharField(max_length=128,unique=True)
    addr = models.CharField(max_length=128)

    def __str__(self):
        return self.name

class ClassList(models.Model):
    """班级表"""
    branch=models.ForeignKey("branch",verbose_name="和校区关联")
    course=models.ForeignKey("Course",verbose_name="和课程关联")
    class_type_choice=((0,"面授"),
                       (1,"周末"),
                       (2,"网络"),)
    class_type=models.SmallIntegerField(choices=class_type_choice,verbose_name="开班类型")
    semester = models.PositiveIntegerField(verbose_name="学期")
    teachers = models.ManyToManyField("UserProfile",verbose_name="老师和账号关联")
    start_date = models.DateTimeField(verbose_name="开班日期")
    end_date = models.DateTimeField(verbose_name="毕业日期",blank=True,null=True)

    def __str__(self):
        return "%s %s %s"%(self.branch,self.course,self.semester)

    class Meta:
        unique_together=("branch","course","semester")

class CourseRecord(models.Model):
    """上课记录表"""
    from_class = models.ForeignKey("ClassList", verbose_name="关联班级")
    day_num = models.PositiveIntegerField(verbose_name="第几节(天)")
    teacher = models.ForeignKey("UserProfile",verbose_name="老师")
    has_homework = models.BooleanField(default=True,verbose_name="是否有作业")
    homework_title= models.CharField(max_length=128,blank=True,null=True,verbose_name="作业头部信息")
    homework_content = models.TextField(blank=True,null=True,verbose_name="作业内容")
    online = models.TextField(verbose_name="本节课程大纲")
    date = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        return "%s %s"%(self.from_class,self.day_num)

    class Meta:
        unique_together=("from_class","day_num")
        verbose_name_plural="上课记录表"

class StudyRecord(models.Model):
    """学习记录表"""
    student = models.ForeignKey("Enrollment",verbose_name="关联报名表")
    course_record = models.ForeignKey("CourseRecord",verbose_name="和上课记录关联")
    attendance_choices = ((0,"已签到"),
                          (1,"迟到"),
                          (2,"缺勤"),
                          (3,"早退"))
    attendanc = models.SmallIntegerField(choices=attendance_choices,default=0,verbose_name="上课状态")
    score_choices=((100,"A+"),
                   (90,"A"),
                   (85,"B+"),
                   (80,"B"),
                   (75,"B-"),
                   (70,"C+"),
                   (60,"C"),
                   (40,"C-"),
                   (-50,"D"),
                   (-100,"COPY"),
                   (0,"N/A"))
    score = models.SmallIntegerField(choices=score_choices,default=0,verbose_name="分数")
    memo = models.TextField(blank=True,null=True,verbose_name="备注")
    date = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        return "%s %s %s"%(self.student,self.course_record,self.score)


class Enrollment(models.Model):
    """报名表"""
    customer = models.ForeignKey("Customer",verbose_name="那个人报名")
    enrolled_class = models.ForeignKey("ClassList",verbose_name="所报班级")
    consultant = models.ForeignKey("UserProfile",verbose_name="课程顾问")
    contract_agreed = models.BooleanField(default=False,verbose_name="学员已经同意合同条款")
    contract_approved = models.BooleanField(default=False,verbose_name="合同已经审核")
    date = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        return "%s %s"%(self.customer,self.enrolled_class)

    class Meta:
        unique_together=("customer","enrolled_class")

class Payment(models.Model):
    """缴费记录"""
    customer=models.ForeignKey("Customer")
    course = models.ForeignKey("Course",verbose_name="所报课程")
    amount = models.PositiveIntegerField(verbose_name="数额",default=500)
    consultant = models.ForeignKey("UserProfile",verbose_name="用户")
    date = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        return "%s %s"%(self.customer,self.amount)


class UserProfile(models.Model):
    """账号表"""
    user=models.OneToOneField(User)
    name = models.CharField(max_length=32)
    roles = models.ManyToManyField("Role",blank=True,null=True)

    def __str__(self):
        return self.name

class Role(models.Model):
    """角色表"""
    name = models.CharField(max_length=32,unique=True)

    def __str__(self):
        return self.name
View Code

注意这里的账号表中的user和django.contrib.auth.models中的User是一对一的关系

三、配置数据库

1、首先下载数据库 具体

2、下载navicat  

 

posted @ 2017-12-17 20:34  pi-pi-miao-miao  阅读(295)  评论(0编辑  收藏  举报