CRM权限管理报名流程1-销售报名信息录入
Posted fqh202
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CRM权限管理报名流程1-销售报名信息录入相关的知识,希望对你有一定的参考价值。
流程思路
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权限管理报名流程1-销售报名信息录入的主要内容,如果未能解决你的问题,请参考以下文章