码迷,mamicode.com
首页 > 其他好文 > 详细

CRM权限管理(2)、报名流程1-销售报名信息录入

时间:2018-08-12 21:30:12      阅读:180      评论:0      收藏:0      [点我收藏+]

标签:cti   create   file   hub   ESS   NPU   img   label   一个   

流程思路

技术分享图片


models.py

model设计思路:
技术分享图片

具体参考:https://github.com/Fangqihan/CRM-Kingadmin/blob/master/crm/models.py

1、报名信息录入

技术分享图片

urls.py

from django.conf.urls import url,include
from crm import views

urlpatterns = [
    url(r'^enroll/$', views.add_student, name='add_student'),  # 第一步:报名信息录入
]

views.py

@login_required
def add_student(request):
    """销售人员 添加 报名学生"""
    # 1、获取所有咨询用户信息
    customers = models.CustomerInfo.objects.all()
    # 2、获取所有校区
    branches = models.Branch.objects.all()
    # 3、获取所有销售人员
    consultants = models.UserProfile.objects.filter(role__title='销售').exclude(id=1)

    if request.method == 'POST':
        # 4、获取提交的信息,包括 学生、选择的班级、咨询顾问姓名的id
        customerid = request.POST.get('customer')
        class_gradeid = request.POST.get('class_grade')
        consultantid = request.POST.get('consultant')
        
        from crm.models import StudentEnrollment
        if consultantid and class_gradeid and consultantid:
            # 5、数据合法则创建 StudentEnrollment 对象
            student_enroll = StudentEnrollment.objects.create(
                customer_id=customerid,
                class_grade_id=class_gradeid,
                consultant_id=consultantid
            )
            print('学生创建成功')
            
            # 6、生成学生完善信息 链接
            enroll_links = 'http://127.0.0.1:8008/crm/enroll/%s/' % student_enroll.id
            print(enroll_links)

    return render(request, 'crm/student_enroll.html', locals())

创建StudentEnrollment对象的约束:

class StudentEnrollment(models.Model):
    """学员报名"""
    ...

    class Meta:
        # 在一个班级内,customer必须是唯一的,否则会报错
        unique_together = ['customer', 'class_grade']
        db_table = '学生报名'

student_enroll.html

<form class="form-horizontal" method="post">
    {% csrf_token %}
    <div class="form-group">
        <label for="inputEmail3" class="col-sm-2 control-label">学生</label>
        <div class="col-sm-10">
            
            <!--所有可选择的咨询客户-->
            <select name="customer" class="form-control">
                <option>----------</option>
                {% for c in customers %}
                    <option value="{{ c.id }}">{{ c.name }}</option>
                {% endfor %}
            </select>
        </div>
    </div>

    <div class="form-group">
        <label for="inputEmail3" class="col-sm-2 control-label">校区</label>
        <div class="col-sm-10">
            <!-- 所有校区 -->
             <select name="branch" class="form-control" id="branch_select">
                <option>----------</option>
                 {% for b in branches %}
                     <option value="{{ b.id }}">{{ b.name }}</option>
                 {% endfor %}
            </select>
        </div>
    </div>

    <div class="form-group">
        <label for="inputEmail3" class="col-sm-2 control-label">班级</label>
        <div class="col-sm-10">
            <!-- 动态显示所有班级 -->
             <select name="class_grade" class="form-control" id="class_lst">
                   <option>----------</option>
            </select>
        </div>
    </div>

    <div class="form-group">
        <label for="inputEmail3" class="col-sm-2 control-label">学习顾问</label>
        <div class="col-sm-10">
            <!-- 显示所有顾问 -->
            <select name="consultant" class="form-control">
                <option>----------</option>
                {% for con in consultants %}
                    <option value="{{ con.id }}">{{ con.username }}</option>
                {% endfor %}
            </select>
        </div>
    </div>

    <div class="form-group">
        <input type="submit" class="btn btn-success" value="提交" style="float: right;margin-right: 5%">
    </div>
</form>

<hr>


<!--  -->
{% if enroll_links %}
    <label class="control-label" style="color: green">创建成功,请将链接发送给学员</label>
    <div class="">
        <input value="{{ enroll_links }}" class="form-control">
    </div>
{% endif %}



<script>
    String.prototype.format= function(){
       var args = arguments;
       return this.replace(/\{(\d+)\}/g,function(s,i){
         return args[i];
       });
    };


    // 监听 校区input框的 change 事件
    $('#branch_select').change(function () {
        // 1、取出选择的校区的id
        var id = $(this).val();
        
        // 2、清空班级列表
        $('#class_lst [value]').remove();
        $.ajax({
            // 3、发送ajax请求获取对应校区id的班级列表
            url:"/crm/get_classes/"+id+"/",
            type:'GET',
            success:function (data) {
                var ele = "";
                // 4、循环遍历返回的班级列表信息,拼接班级option标签
                $.each(data,function (k,v) {
                    console.log(k,v,v.id);
                    html_str='<option value="{0}">{1}</option>';
                    html_str=html_str.format(
                        v.id,
                        v.course__name+'('+v.semester+')期'
                    );
                    ele += html_str
                });
                // 5、动态添加标签
                $('#class_lst').append(ele)
            }
        })
    })
</script>

动态获取对应校区的班级列表

1、urls.py

url(r'^get_classes/(\d+)/$', views.get_classes, name='get_classes'),

2、views.py

from crm.models import Branch, ClassList
import json


def get_classes(request, id):
    # 1、确定校区
    branch = Branch.objects.filter(id=int(id)).first()
    
    # 2、获取校区内所有班级values信息
    classes = list(ClassList.objects.filter(branch=branch).values(
        'id', 'branch__name', 'course__name', 'semester'))
    # [{'id': 1, 'branch__name': '上海', 'course__name': 'go语言', 'semester': 1},]

    # 3、返回班级列表的json数据
    return HttpResponse(json.dumps(classes), content_type="application/json")

生成完善信息链接

技术分享图片

1、前端:

{% if enroll_links %}
    <label class="control-label" style="color: green">创建成功,请将链接发送给学员</label>
    <div class="">
        <input value="{{ enroll_links }}" class="form-control">
    </div>
{% endif %}

2、views.py:

from crm.models import StudentEnrollment
if consultantid and class_gradeid and consultantid:
    student_enroll = StudentEnrollment.objects.create(
        customer_id=customerid,
        class_grade_id=class_gradeid,
        consultant_id=consultantid
    )
    print('学生创建成功')
    enroll_links = 'http://127.0.0.1:8008/crm/enroll/%s/' % student_enroll.id
    print(enroll_links)

CRM权限管理(2)、报名流程1-销售报名信息录入

标签:cti   create   file   hub   ESS   NPU   img   label   一个   

原文地址:https://www.cnblogs.com/fqh202/p/9464286.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!