微搭低代码MBA 培训管理系统实战 19——教务管理:从订单到课时卡的自动转化
目录前情回顾一、 数据源设计1.1 学员档案表 (MBA_StudentProfiles)1.2 课时卡表 (MBA_LearningCards)二 创建管理页面2.1 搭建财务布局2.2 搭建待支付列表页面2.3 搭建确认支付弹窗2.4 自动化开课三 配置门户数据最终效果总结前情回顾上一篇中我们讲解了销售在订单成交后录入订单。此时订单的状态还是待支付的状态需要财务确认收款情况。财务人员点击了确认收款订单状态变更为已清账。此时资金流已经闭环但学员在系统里还只是一个商机客户没有上课的权限。本节我们要解决如何让系统自动识别已付钱的客户并为其发放数字资产——课时卡。本节目标:学籍自动转化将 CRM 中的客户自动转录为正式学员。课时自动充值根据订单中的产品自动生成对应的课时卡余额。一、 数据源设计在原有订单表的基础上我们再创建两张表用来记录学员的学籍和课时卡信息1.1 学员档案表 (MBA_StudentProfiles)定位学员的基本法记录自然人属性。字段名称字段标识字段类型说明学员ID_id文本主键系统自动生成学员姓名student_name文本姓名手机号mobile文本用于登录或通知关联客户rel_customer_id关联关系关联MBA_Customer表追溯来源OpenIDopenid文本学员微信OpenID用于小程序端登录和权限控制学籍状态status枚举1-在读、2-休学、3-毕业、4-退费入学时间enroll_date日期订单支付成功的日期创建时间created_at日期时间自动生成更新时间updated_at日期时间自动更新1.2 课时卡表 (MBA_LearningCards)定位系统的资产层。它是财务与教务的交接单也是待分班列表的数据源。字段名称字段标识字段类型说明卡片ID_id文本主键关联学员rel_student_id关联关系属于哪个学员关联订单rel_order_id关联关系关联MBA_Orders表追溯交易来源关联产品rel_prod_id关联关系购买的课程产品如MBA面试突击班总课时total_hours数字初始发放数剩余课时remain_hours数字实际可用数消课扣减此处分班状态assign_status枚举核心控制位1-待分班(pending)、2-已进班(assigned)关联班级rel_class_id关联关系当前这张卡绑定的班级方便直接显示过期日期expiry_date日期课时卡有效期默认一年创建时间created_at日期时间自动生成更新时间updated_at日期时间自动更新二 创建管理页面2.1 搭建财务布局目前财务需要专属的工作台来进行资金到账的确认动作我们来给财务创建一个布局。点击布局设计点击新建布局选择左侧导航布局重命名为财务布局2.2 搭建待支付列表页面点击创建页面的图标创建订单确认页面选择财务布局切换到布局设计添加菜单切回到页面设计在财务布局的内容插槽里添加布局组件修改标题为订单确认添加顶部选项卡标签改为待办、已办添加数据表格数据模型选择订单表设置数据筛选配置为订单状态等于待支付将操作列的按钮改为确认支付2.3 搭建确认支付弹窗在页面组件下添加弹窗组件添加表单容器数据模型选择订单表场景选择更新数据标识绑定为弹窗的入参将订单的字段的状态改为只读财务确认人的选中值绑定为当前登录对象的数据标识给确认支付按钮绑定点击事件打开弹窗传入所在行的数据2.4 自动化开课当财务选择了已清账需要自动给学员创建学籍开通课时卡。我们需要创建一个自定义方法来完成操作。exportdefault asyncfunctionafterUpdate({event, data}){// data.target 直接包含当前订单的完整信息包括关联字段 const orderdata.target;const orderIdorder._id;const customerorder.rel_customer_id;// 关联的客户对象 const productorder.rel_prod_id;// 关联的产品对象 const order_status$w.select10.value // 判断订单状态是否为已清账(3)是则执行开课逻辑if(order_status3){try{await$w.utils.showLoading({title:正在开课...});//1. 查询是否已存在学员档案避免重复创建 const studentResawait$w.cloud.callDataSource({dataSourceName:MBA_StudentProfiles, methodName:wedaGetRecordsV2, params:{filter:{where:{rel_customer_id:{$eq:customer._id}}}, select:{$master:true}}});letstudentId;if(studentRes.recordsstudentRes.records.length0){// 更新已有学员档案 const existingStudentstudentRes.records[0];await$w.cloud.callDataSource({dataSourceName:MBA_StudentProfiles, methodName:wedaUpdateV2, params:{data:{status:1, // 在读 enroll_date: Date.now(),}, filter:{where:{_id:{$eq:existingStudent._id}}}}});studentIdexistingStudent._id;}else{// 创建新学员档案 const newStudentResawait$w.cloud.callDataSource({dataSourceName:MBA_StudentProfiles, methodName:wedaCreateV2, params:{data:{student_name: customer.name, mobile: customer.phone, rel_customer_id:{_id: customer._id}, openid: null, // 待学员首次登录小程序时绑定 status:1, // 在读 enroll_date: Date.now(),}}});studentIdnewStudentRes.id;}//2. 创建课时卡待分班状态 const expiryDatenew Date();expiryDate.setFullYear(expiryDate.getFullYear()1);await$w.cloud.callDataSource({dataSourceName:MBA_LearningCards, methodName:wedaCreateV2, params:{data:{rel_student_id:{_id: studentId}, rel_order_id:{_id: orderId}, rel_prod_id:{_id: product._id}, total_hours: order.product_hours||product.total_hours||0, remain_hours: order.product_hours||product.total_hours||0, assign_status:1, // 待分班 expiry_date: expiryDate.getTime(),}}});console.log(学员档案和课时卡创建成功订单 ${orderId});$w.utils.showToast({title:自动化开课成功, icon:success});}catch(error){console.error(自动化开课失败:, error);$w.utils.showToast({title:开课失败 error.message, icon:error});}finally{$w.utils.hideLoading();}}}在表单提交的时候调用此方法三 配置门户数据先创建财务角色然后添加人员配置财务门户数据需要完善一下全局登录方法添加财务岗位映射关系/* * 函数里面访问通过 app.common.[name]访问这里定义的方法或值 * 函数外面访问通过 import如在页面的 handler 引用的例子import sayHi from../../common/[name] */exportdefault asyncfunctionlogin({event, data}){try{$w.utils.showLoading({title:加载工作台中...});//1. 从云开发原生 auth 对象中获取当前已登录的手机号 const phone$w.auth.currentUser?.phone||$w.input1.value;if(!phone){return$w.utils.showToast({title:获取授权信息失败请重新登录, icon:error});}//1. 先查询是否是渠道用户 const channelResawait$w.cloud.callDataSource({dataSourceName:MBA_ChannelPartners, methodName:wedaGetRecordsV2, params:{filter:{where:{phone:{$eq:phone}}}, select:{$master:true,}}});console.log(channelRes, channelRes)if(channelRes.recordschannelRes.records.length0){// 渠道用户登录成功 const channelInfochannelRes.records[0];$w.app.dataset.state.currentChannelchannelInfo;// 渠道用户固定角色用于门户跳转判断$w.app.dataset.state.userRoles[ROLE_CHANNEL];$w.utils.showToast({title:渠道登录成功, icon:success});return;}//2. 根据手机号查询业务库中的用户信息关联查询部门和岗位 const userResawait$w.cloud.callDataSource({dataSourceName:MBA_Users, methodName:wedaGetRecordsV2, params:{filter:{where:{phone:{$eq:phone}}}, select:{$master:true, department_id: true, position_id:true}}});if(!userRes.records.length){return$w.utils.showToast({title:该手机号未在系统中注册请联系管理员, icon:error});}const useruserRes.records[0];console.log(user, user)//3. 异步更新用户的最后登录时间(不阻塞后续逻辑)$w.cloud.callDataSource({dataSourceName:MBA_Users, methodName:wedaUpdateV2, params:{data:{last_login: Date.now()}, filter:{where:{_id:{$eq:user._id}}}}}).catch(econsole.error(更新登录时间失败, e));//4. 获取用户关联的角色信息 const roleResawait$w.cloud.callDataSource({dataSourceName:MBA_RoleUsers, methodName:wedaGetRecordsV2, params:{filter:{where:{user_id:{$eq:user._id}}}, select:{$master:true, role_id:true}}});console.log(roleRes, roleRes)// 提取角色编码(例如:[ROLE_ADMIN,ROLE_TEACHER])const roleCodesroleRes.records.map(itemitem.role_id?.code).filter(Boolean);console.log(roleCodes, roleCodes)//5. 构造全局 User 对象并写入页面状态 const userInfo{...user, deptInfo: user.department_id, postInfo: user.position_id,};//5. 根据岗位信息确定用户类型 const userTypegetUserTypeByPosition(user.position_id);$w.app.dataset.state.currentUseruserInfo;$w.app.dataset.state.userRolesroleCodes;$w.app.dataset.state.userTypeuserType;}catch(e){console.error(初始化门户失败, e);$w.utils.showToast({title:系统加载失败请刷新重试, icon:error});}finally{$w.utils.hideLoading();}}// 根据岗位信息确定用户类型exportfunctiongetUserTypeByPosition(position){if(!position){returnemployee;}const positionNameposition.name||;const positionCodeposition.code||;// 岗位到用户类型的映射 const positionToTypeMap{// 销售相关岗位销售:sales,销售经理:sales-manager,销售总监:sales-manager, // 教师相关岗位教师:teacher,讲师:teacher,教授:teacher, // 其他岗位客服:employee,行政:employee,财务:finance};// 优先根据岗位编码匹配if(positionCode){if(positionCode.includes(SALES))returnsales;if(positionCode.includes(TEACHER))returnteacher;if(positionCode.includes(MANAGER))returnsales-manager;if(positionCode.includes(POST-FM))returnfinance;}// 其次根据岗位名称匹配returnpositionToTypeMap[positionName]||employee;}最终效果财务人员访问首页输入手机号跳转到对应的工作台进行相关的操作总结本篇我们介绍了财务确认相关业务流程的搭建创建了相关的表结构。在财务人员点击确认后会自动开通学籍及课时卡信息下一篇我们介绍班级管理版块敬请期待。
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2449044.html
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!