consumer exceed

This commit is contained in:
caoqianming 2020-08-24 11:01:00 +08:00
parent acff3881cc
commit 65fa087d93
7 changed files with 229 additions and 178 deletions

View File

@ -28,7 +28,7 @@
:tree-props="{children: 'children', hasChildren: 'hasChildren'}" :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
@row-dblclick="handleChose2" @row-dblclick="handleChose2"
> >
<el-table-column type="index" width="50"></el-table-column> <el-table-column type="index" width="100" :index="indexMethod"></el-table-column>
<el-table-column label="单位名称"> <el-table-column label="单位名称">
<template slot-scope="scope">{{ scope.row.name }}</template> <template slot-scope="scope">{{ scope.row.name }}</template>
</el-table-column> </el-table-column>
@ -140,6 +140,9 @@ export default {
}, },
handleChose2(row, column, event){ handleChose2(row, column, event){
this.$emit('handleChose',row); this.$emit('handleChose',row);
},
indexMethod(index) {
return (this.listQuery.page-1)*this.listQuery.limit + index + 1;
} }
} }
}; };

View File

@ -52,16 +52,16 @@
/> />
</el-select> </el-select>
<el-date-picker <el-date-picker
v-model="datevalue" v-model="datevalue"
type="daterange" type="daterange"
align="right" align="right"
unlink-panels unlink-panels
range-separator="至" range-separator="至"
start-placeholder="开始日期" start-placeholder="开始日期"
end-placeholder="结束日期" end-placeholder="结束日期"
value-format="yyyy-MM-dd" value-format="yyyy-MM-dd"
:picker-options="pickerOptions"> :picker-options="pickerOptions"
</el-date-picker> ></el-date-picker>
<!-- <el-select <!-- <el-select
v-model="listQuery.is_paid" v-model="listQuery.is_paid"
placeholder="是否缴费" placeholder="是否缴费"
@ -121,8 +121,18 @@
</div> </div>
<el-button slot="reference" icon="el-icon-upload2">Excel导入</el-button> <el-button slot="reference" icon="el-icon-upload2">Excel导入</el-button>
</el-popover> </el-popover>
<el-button type="primary" icon="el-icon-download" @click="exportConsumer" v-if="checkPermission(['consumer__export'])">导出Excel</el-button> <el-button
<el-button type="danger" icon="el-icon-delete" @click="handleDeletes" v-if="checkPermission(['consumer__deletes'])">批量删除</el-button> type="primary"
icon="el-icon-download"
@click="exportConsumer"
v-if="checkPermission(['consumer__export'])"
>导出Excel</el-button>
<el-button
type="danger"
icon="el-icon-delete"
@click="handleDeletes"
v-if="checkPermission(['consumer__deletes'])"
>批量删除</el-button>
<el-checkbox <el-checkbox
v-model="showCreate" v-model="showCreate"
class="filter-item" class="filter-item"
@ -142,30 +152,30 @@
@selection-change="handleSelectionChange" @selection-change="handleSelectionChange"
> >
<el-table-column type="selection" width="55"></el-table-column> <el-table-column type="selection" width="55"></el-table-column>
<el-table-column align="center" label="姓名"> <el-table-column label="姓名">
<template slot-scope="scope">{{ scope.row.name }}</template> <template slot-scope="scope">{{ scope.row.name }}</template>
</el-table-column> </el-table-column>
<el-table-column align="header-center" label="手机号" sortable="custom" prop="username"> <el-table-column label="手机号" sortable="custom" prop="username">
<template slot-scope="scope">{{ scope.row.username }}</template> <template slot-scope="scope">{{ scope.row.username }}</template>
</el-table-column> </el-table-column>
<el-table-column align="header-center" label="小程序OpenId"> <el-table-column label="小程序OpenId" :show-overflow-tooltip="true">
<template slot-scope="scope">{{ scope.row.openid }}</template> <template slot-scope="scope">{{ scope.row.openid }}</template>
</el-table-column> </el-table-column>
<el-table-column align="header-center" label="用户类型"> <el-table-column label="用户类型">
<template slot-scope="scope">{{ scope.row.role_name }}</template> <template slot-scope="scope">{{ scope.row.role_name }}</template>
</el-table-column> </el-table-column>
<el-table-column align="header-center" label="单位" sortable="custom" prop="company"> <el-table-column label="单位" sortable="custom" prop="company">
<template <template
slot-scope="scope" slot-scope="scope"
v-if="scope.row.company_name != null" v-if="scope.row.company_name != null"
>{{ scope.row.company_name }}</template> >{{ scope.row.company_name }}</template>
</el-table-column> </el-table-column>
<el-table-column align="center" label="缴费学科"> <el-table-column label="缴费学科">
<template slot-scope="scope"> <template slot-scope="scope">
<el-tag v-for="item in scope.row.subjects_name" :key="item">{{ item }}</el-tag> <el-tag v-for="item in scope.row.subjects_name" :key="item">{{ item }}</el-tag>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column align="center" label="工作类别" sortable="custom" prop="workscope"> <el-table-column label="工作类别" sortable="custom" prop="workscope">
<template slot-scope="scope"> <template slot-scope="scope">
<el-tag v-if="scope.row.workscope_name">{{ scope.row.workscope_name }}</el-tag> <el-tag v-if="scope.row.workscope_name">{{ scope.row.workscope_name }}</el-tag>
</template> </template>
@ -173,34 +183,36 @@
<el-table-column label="创建信息" sortable="custom" prop="create_time" v-if="showCreate"> <el-table-column label="创建信息" sortable="custom" prop="create_time" v-if="showCreate">
<template slot-scope="scope"> <template slot-scope="scope">
<span>{{ scope.row.create_admin_.username }}/</span> <span>{{ scope.row.create_admin_.username }}/</span>
<span>{{ scope.row.create_time }}</span> <span>{{ scope.row.create_time.substring(0,10) }}</span>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column align="center" label="操作" > <el-table-column align="left" label="操作" fixed="right" width="200">
<template slot-scope="scope"> <template slot-scope="scope">
<el-button <el-button-group>
type="primary" <el-button
size="small" type="primary"
@click="handleEdit(scope)" size="small"
icon="el-icon-edit" @click="handleEdit(scope)"
:disabled="!checkPermission(['consumer_update'])" icon="el-icon-edit"
v-if="!scope.row.is_superconsumer" :disabled="!checkPermission(['consumer_update'])"
></el-button> v-if="!scope.row.is_superconsumer"
<el-button ></el-button>
type="danger" <el-button
size="small" type="danger"
@click="handleDelete(scope)" size="small"
icon="el-icon-delete" @click="handleDelete(scope)"
:disabled="!checkPermission(['consumer_delete'])" icon="el-icon-delete"
v-if="!scope.row.is_superconsumer" :disabled="!checkPermission(['consumer_delete'])"
></el-button> v-if="!scope.row.is_superconsumer"
<el-button ></el-button>
type="primary" <el-button
size="small" type="primary"
@click="handleUnbind(scope)" size="small"
:disabled="!checkPermission(['consumer_unbind'])" @click="handleUnbind(scope)"
v-if="scope.row.username&&scope.row.openid" :disabled="!checkPermission(['consumer_unbind'])"
>解绑微信</el-button> v-if="scope.row.username&&scope.row.openid"
>解微</el-button>
</el-button-group>
</template> </template>
</el-table-column> </el-table-column>
</el-table> </el-table>
@ -228,14 +240,9 @@
<el-input v-model="consumer.username" placeholder="手机号" /> <el-input v-model="consumer.username" placeholder="手机号" />
</el-form-item> </el-form-item>
<el-form-item label="单位" prop="company"> <el-form-item label="单位" prop="company">
<el-input <el-input placeholder="单位" v-model="consumer.company_.name" readonly>
placeholder="单位" <el-button slot="append" icon="el-icon-search" @click="choose()"></el-button>
v-model="consumer.company_.name" </el-input>
readonly
>
<el-button slot="append" icon="el-icon-search" @click="choose()"></el-button>
</el-input>
<!-- <el-select <!-- <el-select
v-model="consumer.company" v-model="consumer.company"
placeholder="单位" placeholder="单位"
@ -254,7 +261,7 @@
:label="item.label" :label="item.label"
:value="item.value" :value="item.value"
></el-option> ></el-option>
</el-select> --> </el-select>-->
</el-form-item> </el-form-item>
<el-form-item label="缴费学科" prop="subjects"> <el-form-item label="缴费学科" prop="subjects">
<el-select v-model="consumer.subjects" placeholder="缴费学科" style="width:100%" multiple> <el-select v-model="consumer.subjects" placeholder="缴费学科" style="width:100%" multiple>
@ -286,6 +293,14 @@
></el-option> ></el-option>
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-form-item label="账号过期" prop="exceed_date">
<el-date-picker
v-model="consumer.exceed_date"
type="date"
placeholder="选择日期"
value-format="yyyy-MM-dd">
</el-date-picker>
</el-form-item>
</el-form> </el-form>
<div style="text-align:right;"> <div style="text-align:right;">
<el-button type="danger" @click="dialogVisible=false">取消</el-button> <el-button type="danger" @click="dialogVisible=false">取消</el-button>
@ -314,7 +329,7 @@ import {
exportConsumer, exportConsumer,
deleteConsumers, deleteConsumers,
unbindConsumer, unbindConsumer,
getConsumerRoleAll getConsumerRoleAll,
} from "@/api/crm"; } from "@/api/crm";
import { getSubjectAll } from "@/api/question"; import { getSubjectAll } from "@/api/question";
import { getWorkScopeAll } from "@/api/examtest"; import { getWorkScopeAll } from "@/api/examtest";
@ -322,36 +337,36 @@ import { getCompanyList } from "@/api/crm";
import { genTree, deepClone } from "@/utils"; import { genTree, deepClone } from "@/utils";
import checkPermission from "@/utils/permission"; import checkPermission from "@/utils/permission";
import { upUrl } from "@/api/file"; import { upUrl } from "@/api/file";
import { getUserList } from "@/api/user" import { getUserList } from "@/api/user";
import { getToken } from "@/utils/auth"; import { getToken } from "@/utils/auth";
import Pagination from "@/components/Pagination"; // secondary package based on el-pagination import Pagination from "@/components/Pagination"; // secondary package based on el-pagination
import Companychose from "@/views/crm/companychose" import Companychose from "@/views/crm/companychose";
const defaultConsumer = { const defaultConsumer = {
id: "", id: "",
name: "", name: "",
username: "", username: "",
company: null, company: null,
company_:{}, company_: {},
subjects: [], subjects: [],
workscope: null, workscope: null,
role:3 role: 3,
}; };
const listQuery = { const listQuery = {
page: 1, page: 1,
limit: 20, limit: 20,
search: "" search: "",
}; };
export default { export default {
components: { Pagination, Companychose }, components: { Pagination, Companychose },
watch: { watch: {
filterOrgText(val) { filterOrgText(val) {
this.$refs.tree.filter(val); this.$refs.tree.filter(val);
} },
}, },
data() { data() {
return { return {
dgVisiable:false, dgVisiable: false,
tableKey: 0, tableKey: 0,
showCreate: true, showCreate: true,
upUrl: upUrl(), upUrl: upUrl(),
@ -364,104 +379,109 @@ export default {
listQuery: { listQuery: {
page: 1, page: 1,
limit: 20, limit: 20,
search: "" search: "",
}, },
enabledOptions: [ enabledOptions: [
{ key: "true", display_name: "已缴" }, { key: "true", display_name: "已缴" },
{ key: "false", display_name: "未缴" } { key: "false", display_name: "未缴" },
], ],
dialogVisible: false, dialogVisible: false,
dialogType: "new", dialogType: "new",
rule1: { rule1: {
name: [{ required: true, message: "请输入姓名", trigger: "blur" }], name: [{ required: true, message: "请输入姓名", trigger: "blur" }],
username: [ username: [
{ required: true, message: "请输入手机号", trigger: "change", pattern: /^1[345789]\d{9}$/, } {
required: true,
message: "请输入手机号",
trigger: "change",
pattern: /^1[3456789]\d{9}$/,
},
], ],
role: [ role: [{ required: true, message: "请选择", trigger: "change" }],
{ required: true, message: "请选择", trigger: "change" } workscope: [{ required: true, message: "请选择", trigger: "change" }],
], subjects: [{ required: true, message: "请选择", trigger: "change" }],
workscope: [ exceed_date: [{ required: true, message: "请选择", trigger: "change" }],
{ required: true, message: "请选择", trigger: "change"}
],
subjects: [
{ required: true, message: "请选择", trigger: "change"}
]
}, },
filterOrgText: "", filterOrgText: "",
treeLoding: false, treeLoding: false,
companyData: [], companyData: [],
subjectData: [], subjectData: [],
workscopeData: [], workscopeData: [],
roleData:[], roleData: [],
selects: [], selects: [],
pickerOptions: { pickerOptions: {
shortcuts: [{ shortcuts: [
text: '最近一天', {
text: "最近一天",
onClick(picker) { onClick(picker) {
const end = new Date(); const end = new Date();
const start = new Date(); const start = new Date();
start.setTime(start.getTime() - 3600 * 1000 * 24); start.setTime(start.getTime() - 3600 * 1000 * 24);
picker.$emit('pick', [start, end]); picker.$emit("pick", [start, end]);
} },
}, { },
text: '最近一周', {
text: "最近一周",
onClick(picker) { onClick(picker) {
const end = new Date(); const end = new Date();
const start = new Date(); const start = new Date();
start.setTime(start.getTime() - 3600 * 1000 * 24 * 7); start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
picker.$emit('pick', [start, end]); picker.$emit("pick", [start, end]);
} },
}, { },
text: '最近一个月', {
text: "最近一个月",
onClick(picker) { onClick(picker) {
const end = new Date(); const end = new Date();
const start = new Date(); const start = new Date();
start.setTime(start.getTime() - 3600 * 1000 * 24 * 30); start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
picker.$emit('pick', [start, end]); picker.$emit("pick", [start, end]);
} },
}, { },
text: '最近三个月', {
text: "最近三个月",
onClick(picker) { onClick(picker) {
const end = new Date(); const end = new Date();
const start = new Date(); const start = new Date();
start.setTime(start.getTime() - 3600 * 1000 * 24 * 90); start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
picker.$emit('pick', [start, end]); picker.$emit("pick", [start, end]);
} },
}] },
}, ],
datevalue: '', },
adminOptions:[] datevalue: "",
adminOptions: [],
}; };
}, },
computed: {}, computed: {},
watch:{ watch: {
datevalue:'setTimeRange', datevalue: "setTimeRange",
}, },
created() { created() {
this.getList() this.getList();
this.getCompanyList() this.getCompanyList();
this.getSubjectAll() this.getSubjectAll();
this.getWorkScopeAll() this.getWorkScopeAll();
this.getConsumerRoleAll() this.getConsumerRoleAll();
this.getAdminOptions() this.getAdminOptions();
}, },
methods: { methods: {
checkPermission, checkPermission,
handleUploadSuccess(res, file) { handleUploadSuccess(res, file) {
if (res.code == 200) { if (res.code == 200) {
const loading = this.$loading({ text: "正在导入中..." }); const loading = this.$loading({ text: "正在导入中..." });
importConsumer(res.data).then(response => { importConsumer(res.data).then((response) => {
loading.close(); loading.close();
if (response.code == 200) { if (response.code == 200) {
this.$message({ this.$message({
message: "导入成功", message: "导入成功",
type: "success" type: "success",
}); });
this.getList(listQuery); this.getList(listQuery);
} else if (response.code == 206) { } else if (response.code == 206) {
this.$message({ this.$message({
message: "部分未成功" + response.data, message: "部分未成功" + response.data,
type: "success" type: "success",
}); });
this.getList(listQuery); this.getList(listQuery);
} else { } else {
@ -478,7 +498,7 @@ export default {
}, },
getList() { getList() {
this.listLoading = true; this.listLoading = true;
getConsumerList(this.listQuery).then(response => { getConsumerList(this.listQuery).then((response) => {
this.consumerList = response.data.results; this.consumerList = response.data.results;
this.total = response.data.count; this.total = response.data.count;
this.listLoading = false; this.listLoading = false;
@ -486,30 +506,30 @@ export default {
}, },
getCompanyList() { getCompanyList() {
this.treeLoding = true; this.treeLoding = true;
getCompanyList().then(response => { getCompanyList().then((response) => {
this.companyData = genTree(response.data.results); this.companyData = genTree(response.data.results);
this.treeLoding = false; this.treeLoding = false;
}); });
}, },
searchCompany(val) { searchCompany(val) {
this.treeLoding = true; this.treeLoding = true;
getCompanyList({search:val, perm:'all'}).then(response => { getCompanyList({ search: val, perm: "all" }).then((response) => {
this.companyData = genTree(response.data.results); this.companyData = genTree(response.data.results);
this.treeLoding = false; this.treeLoding = false;
}); });
}, },
getSubjectAll() { getSubjectAll() {
getSubjectAll().then(response => { getSubjectAll().then((response) => {
this.subjectData = genTree(response.data); this.subjectData = genTree(response.data);
}); });
}, },
getWorkScopeAll() { getWorkScopeAll() {
getWorkScopeAll().then(response => { getWorkScopeAll().then((response) => {
this.workscopeData = genTree(response.data); this.workscopeData = genTree(response.data);
}); });
}, },
getConsumerRoleAll() { getConsumerRoleAll() {
getConsumerRoleAll().then(response => { getConsumerRoleAll().then((response) => {
this.roleData = genTree(response.data); this.roleData = genTree(response.data);
}); });
}, },
@ -517,7 +537,7 @@ export default {
this.listQuery = { this.listQuery = {
page: 1, page: 1,
limit: 20, limit: 20,
search: "" search: "",
}; };
this.getList(); this.getList();
}, },
@ -535,8 +555,8 @@ export default {
}, },
handleEdit(scope) { handleEdit(scope) {
this.consumer = Object.assign({}, scope.row); // copy obj this.consumer = Object.assign({}, scope.row); // copy obj
if(this.consumer.company_ == null){ if (this.consumer.company_ == null) {
this.consumer.company_ = {} this.consumer.company_ = {};
} }
this.dialogType = "edit"; this.dialogType = "edit";
this.dialogVisible = true; this.dialogVisible = true;
@ -545,70 +565,82 @@ export default {
}); });
}, },
handleUnbind(scope) { handleUnbind(scope) {
unbindConsumer(scope.row.id).then(res => { this.$confirm("确认解除该账户的微信绑定吗!", "警告", {
if(res.code>=200){ type: "warning",
this.$message({ })
type: "success", .then(() => {
message: "解绑成功!" unbindConsumer(scope.row.id)
}); .then((res) => {
this.getList() this.$message({
} type: "success",
}).catch(err => { message: "解绑成功!",
console.error(err) });
this.getList();
})
.catch((err) => {
console.error(err);
});
}) })
.catch((err) => {
console.error(err);
});
}, },
handleDelete(scope) { handleDelete(scope) {
this.$confirm("确认删除该用户吗?将丢失数据!", "警告", { this.$confirm("确认删除该用户吗?将丢失数据!", "警告", {
confirmButtonText: "确认", confirmButtonText: "确认",
cancelButtonText: "取消", cancelButtonText: "取消",
type: "error" type: "error",
}) })
.then(async () => { .then(async () => {
await deleteConsumer(scope.row.id); await deleteConsumer(scope.row.id);
this.consumerList.splice(scope.row.index, 1); this.consumerList.splice(scope.row.index, 1);
this.$message({ this.$message({
type: "success", type: "success",
message: "成功删除!" message: "成功删除!",
}); });
}) })
.catch(err => { .catch((err) => {
console.error(err); console.error(err);
}); });
}, },
handleDeletes() { handleDeletes() {
if(this.selects.length){ if (this.selects.length) {
this.$confirm("确认删除这"+ this.selects.length + "位用户吗?将丢失数据!", "警告", { this.$confirm(
confirmButtonText: "确认", "确认删除这" + this.selects.length + "位用户吗?将丢失数据!",
cancelButtonText: "取消", "警告",
type: "error" {
}) confirmButtonText: "确认",
cancelButtonText: "取消",
type: "error",
}
)
.then(async () => { .then(async () => {
const { code } = await deleteConsumers({ ids: this.selects }); const { code } = await deleteConsumers({ ids: this.selects });
if (code >= 200) { if (code >= 200) {
this.getList() this.getList();
this.$message({ this.$message({
type: "success", type: "success",
message: "成功删除!" message: "成功删除!",
}); });
} }
}) })
.catch(err => { .catch((err) => {
console.error(err); console.error(err);
}); });
}else{ } else {
this.$message({ this.$message({
message: '请先选择', message: "请先选择",
type: 'warning' type: "warning",
}); });
} }
}, },
async confirmUser(form) { async confirmUser(form) {
this.$refs[form].validate(valid => { this.$refs[form].validate((valid) => {
if (valid) { if (valid) {
const isEdit = this.dialogType === "edit"; const isEdit = this.dialogType === "edit";
if (isEdit) { if (isEdit) {
let consumer = this.consumer; let consumer = this.consumer;
updateConsumer(this.consumer.id, consumer).then(res => { updateConsumer(this.consumer.id, consumer).then((res) => {
// for (let index = 0; index < this.consumerList.length; index++) { // for (let index = 0; index < this.consumerList.length; index++) {
// if (this.consumerList[index].id === this.consumer.id) { // if (this.consumerList[index].id === this.consumer.id) {
// this.consumerList.splice( // this.consumerList.splice(
@ -621,29 +653,16 @@ export default {
// } // }
this.getList(); this.getList();
this.dialogVisible = false; this.dialogVisible = false;
if (res.code >= 200) { this.$message.success('成功')
this.$notify({
title: "成功",
message: "编辑成功",
type: "success",
duration: 2000
});
}
}); });
} else { } else {
createConsumer(this.consumer).then(res => { createConsumer(this.consumer).then((res) => {
// this.consumer = res.data // this.consumer = res.data
// this.consumerList.unshift(this.consumer) // this.consumerList.unshift(this.consumer)
this.getList(); this.getList();
this.dialogVisible = false; this.dialogVisible = false;
if (res.code >= 200) { this.$message.success('成功')
this.$notify({
title: "成功",
message: "新增成功",
type: "success",
duration: 2000
});
}
}); });
} }
} else { } else {
@ -653,7 +672,7 @@ export default {
}, },
exportConsumer() { exportConsumer() {
const loading = this.$loading(); const loading = this.$loading();
exportConsumer(this.listQuery).then(response => { exportConsumer(this.listQuery).then((response) => {
loading.close(); loading.close();
window.open(response.data.path, "_blank"); window.open(response.data.path, "_blank");
}); });
@ -674,16 +693,16 @@ export default {
} }
this.selects = selects; this.selects = selects;
}, },
setTimeRange(){ setTimeRange() {
this.listQuery.min_create = this.datevalue[0], (this.listQuery.min_create = this.datevalue[0]),
this.listQuery.max_create = this.datevalue[1], (this.listQuery.max_create = this.datevalue[1]),
this.getList() this.getList();
}, },
getAdminOptions(){ getAdminOptions() {
if(checkPermission(['admin'])){ if (checkPermission(["admin"])) {
getUserList().then(res=>{ getUserList().then((res) => {
this.adminOptions = genTree(res.data.results) this.adminOptions = genTree(res.data.results);
}) });
} }
}, },
choose() { choose() {
@ -692,11 +711,10 @@ export default {
chooseComplete(val) { chooseComplete(val) {
this.dgVisiable = false; this.dgVisiable = false;
if (val) { if (val) {
this.consumer.company_ = val this.consumer.company_ = val;
this.consumer.company = val.id this.consumer.company = val.id;
} }
}, },
} },
}; };
</script> </script>

View File

@ -23,7 +23,7 @@ function request(url, method, data) {
msg = JSON.stringify(res.data.msg) msg = JSON.stringify(res.data.msg)
} }
if (msg.indexOf('该操作的权限')!=-1){ if (msg.indexOf('该操作的权限')!=-1){
msg = '权限不足,请注册登陆或联系课程顾问' msg = '权限不足或账户过期,请联系课程顾问'
} }
wx.showToast({ wx.showToast({
title: msg, title: msg,

View File

@ -0,0 +1,18 @@
# Generated by Django 3.0.4 on 2020-08-24 02:10
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('crm', '0021_company_create_admin'),
]
operations = [
migrations.AddField(
model_name='consumer',
name='exceed_date',
field=models.DateField(blank=True, null=True, verbose_name='账号过期'),
),
]

View File

@ -73,6 +73,7 @@ class Consumer(CommonModel):
realname = models.CharField('真实姓名', max_length=100, null=True, blank=True) realname = models.CharField('真实姓名', max_length=100, null=True, blank=True)
create_admin = models.ForeignKey(UserProfile, default=1, on_delete=models.DO_NOTHING) create_admin = models.ForeignKey(UserProfile, default=1, on_delete=models.DO_NOTHING)
exceed_date = models.DateField('账号过期', null=True, blank=True)
class Meta: class Meta:

View File

@ -3,7 +3,7 @@ from rbac.models import UserProfile
from crm.models import Consumer from crm.models import Consumer
from rest_framework.permissions import IsAuthenticated from rest_framework.permissions import IsAuthenticated
from django.core.cache import cache from django.core.cache import cache
from django.utils import timezone
# 学员接口列表 # 学员接口列表
ConsumerPerms = [ ConsumerPerms = [
'paper_view', 'paper_view',
@ -23,6 +23,8 @@ VistorPerms = [
] ]
def get_consumerperm_list(consumer): def get_consumerperm_list(consumer):
perms = consumer.role.perms.values_list('code', flat=True) perms = consumer.role.perms.values_list('code', flat=True)
if consumer.exceed_date < timezone.now():
perms.append('account_exceed')
cache.get_or_set('cperms_'+str(consumer.id), perms) cache.get_or_set('cperms_'+str(consumer.id), perms)
return perms return perms
@ -49,6 +51,8 @@ class MyPermission(RbacPermission):
if perms: if perms:
if not hasattr(view, 'perms_map'): if not hasattr(view, 'perms_map'):
return True return True
elif 'account_exceed' in perms: #账户过期
return False
else: else:
perms_map = view.perms_map perms_map = view.perms_map
_method = request._request.method.lower() _method = request._request.method.lower()

View File

@ -2,7 +2,7 @@ import json
import random import random
import warnings import warnings
from calendar import timegm from calendar import timegm
from datetime import datetime from datetime import date, datetime, timedelta
import requests import requests
from django.db.models import Q from django.db.models import Q
@ -372,6 +372,7 @@ class ConsumerViewSet(ModelViewSet):
obj.role = roleobj obj.role = roleobj
except: except:
pass pass
obj.exceed_date = datetime.now() + timedelta(days=90)
obj.save() obj.save()
m = m + 1 m = m + 1
return Response(status=status.HTTP_200_OK) return Response(status=status.HTTP_200_OK)
@ -413,6 +414,12 @@ class ConsumerViewSet(ModelViewSet):
print(i.id) print(i.id)
return Response(status=status.HTTP_200_OK) return Response(status=status.HTTP_200_OK)
@action(methods=['get'], detail=False,
url_path='correctexceed', url_name='correct_exceed', perms_map=[{'*':'correct_exceed'}])
def correctexceed(self, request):
Consumer.objects.exclude(exceed_date=None).update(exceed_date = datetime(2020,12,31))
return Response(status=status.HTTP_200_OK)
class ConsumerMPLoginView(APIView): class ConsumerMPLoginView(APIView):
""" """
小程序登陆颁发token 小程序登陆颁发token