diff --git a/admin/src/app/views/campus_person_role/components/campus-person-role-edit.vue b/admin/src/app/views/campus_person_role/components/campus-person-role-edit.vue index 7bc11b8b..749219bc 100644 --- a/admin/src/app/views/campus_person_role/components/campus-person-role-edit.vue +++ b/admin/src/app/views/campus_person_role/components/campus-person-role-edit.vue @@ -149,6 +149,8 @@ if(pageName == '市场人员列表'){ }else if(pageName == '销售人员列表'){ initialFormData.dept_id = 2; // campusPersonRoleTable.searchParam.role_id = 2; +}else if(pageName == '教练管理'){ + initialFormData.dept_id = 3; } const formData: Record = reactive({ ...initialFormData }) diff --git a/niucloud/app/api/controller/apiController/ClassApi.php b/niucloud/app/api/controller/apiController/ClassApi.php new file mode 100644 index 00000000..83f4ec5b --- /dev/null +++ b/niucloud/app/api/controller/apiController/ClassApi.php @@ -0,0 +1,42 @@ +member_id; + dd(111); + return success((new CourseService())->list($id,$data)); + } + + //获取课程详情 + public function courseInfo(Request $request){ + $data = $this->request->params([ + ["id",0] + ]); + return success('SUCCESS',(new CourseService())->info($data['id'])); + } + +} diff --git a/niucloud/app/api/controller/apiController/Common.php b/niucloud/app/api/controller/apiController/Common.php index 27a570ee..9011ea0e 100644 --- a/niucloud/app/api/controller/apiController/Common.php +++ b/niucloud/app/api/controller/apiController/Common.php @@ -35,4 +35,30 @@ class Common extends BaseApiService } return success($res); } + + //忘记密码-通过短信验证码进行密码重置(学生/员工通用) + public function forgetPassword(Request $request) + { + $phone = $request->param('phone', '');//手机号 + $code = $request->param('code', '');//短信验证码 + $code_type = $request->param('code_type', '');//短信验证码类型(发送/验证 短信验证码的类型)|修改密码=editPassword + $password = $request->param('password', '');//新密码 + $user_type = $request->param('user_type', '');//用户类型|customer=学生|personnel=员工(销售/教师) + + if (empty($phone) || empty($code) || empty($code_type) || empty($password) || empty($user_type)) { + return fail('缺少必填参数'); + } + + //@todo 验证短信验证码是否正确(等发送短信验证码接入后在写) + //... + + + //重置密码 + $res = (new CommonService())->forgetPassword($phone, $password, $user_type); + if(!$res['code']){ + return fail($res['msg']); + } + return success([]); + + } } diff --git a/niucloud/app/api/controller/apiController/Course.php b/niucloud/app/api/controller/apiController/Course.php new file mode 100644 index 00000000..a4b7a69d --- /dev/null +++ b/niucloud/app/api/controller/apiController/Course.php @@ -0,0 +1,74 @@ +member_id; + $data = $this->request->params([ + ["schedule_date",0] + ]); + return success((new CourseService())->list($id,$data)); + } + + //获取课程详情 + public function courseInfo(Request $request){ + $data = $this->request->params([ + ["id",0] + ]); + return success('SUCCESS',(new CourseService())->info($data['id'])); + } + + //获取添加学员列表 + public function addStudentList(Request $request){ + $data = $this->request->params([ + ["id",0] + ]); + return success('SUCCESS',(new CourseService())->StudentList($data['id'])); + } + + //获取添加学员列表 + public function addStudent(Request $request){ + $data = $this->request->params([ + ["student_id",0], + ["schedule_id",0], + ["time_slot",0], + ["resources_id",1], + ["person_id",1], + ["course_date",''] + ]); + return success('SUCCESS',(new CourseService())->addStudent($data)); + } + + //请假 + public function delStudentCourse(Request $request){ + $data = $this->request->params([ + ["student_id",0], + ["course_id",0] + ]); + return success('SUCCESS',(new CourseService())->delStudentCourse($data)); + } + +} diff --git a/niucloud/app/api/controller/apiController/CustomerResources.php b/niucloud/app/api/controller/apiController/CustomerResources.php index 16fc4e53..3112f01c 100644 --- a/niucloud/app/api/controller/apiController/CustomerResources.php +++ b/niucloud/app/api/controller/apiController/CustomerResources.php @@ -23,11 +23,41 @@ use core\base\BaseApiService; class CustomerResources extends BaseApiService { + + //获取全部客户资源 + public function getAll(Request $request){ + + $name = $request->param('name', '');//客户姓名 + if(empty($name)){ + return fail("缺少客户姓名"); + } + + $where = [ + 'name'=>$name + ]; + $res = (new CustomerResourcesService())->getAll($where); + if(!$res['code']){ + return fail($res['msg']); + } + return success($res['data']); + } + //客户资源添加 public function add(Request $request){ $date = date('Y-m-d'); + $promised_visit_time = $request->param('promised_visit_time', ''); + if($promised_visit_time){ + $promised_visit_time = date('Y-m-d H:i:s',strtotime($promised_visit_time)); + } + + + $optional_class_time = $request->param('optional_class_time', ''); + if($optional_class_time){ + $optional_class_time = date('Y-m-d H:i:s',strtotime($optional_class_time)); + } + $customer_resources_data = [ "create_year_month"=>date('Y-m'), "create_date"=>date('Y-m-d'), @@ -44,15 +74,15 @@ class CustomerResources extends BaseApiService "status" => $request->param('status', ''), "purchasing_power" => $request->param('purchasing_power', ''), "cognitive_idea" => $request->param('cognitive_idea', ''), - "optional_class_time" => $request->param('optional_class_time', ''), + "optional_class_time" => $optional_class_time, "distance" => $request->param('distance', ''), ]; $six_speed_data = [ "purchase_power" => $request->param('purchasing_power', ''), "concept_awareness" => $request->param('cognitive_idea', ''), - "promised_visit_time" => $request->param('promised_visit_time', ''),//承诺到访时间 - "preferred_class_time" => $request->param('optional_class_time', ''),//可选上课时间 + "promised_visit_time" => $promised_visit_time,//承诺到访时间 + "preferred_class_time" => $optional_class_time,//可选上课时间 "distance" => $request->param('distance', ''),//距离 "communication" => $request->param('communication', ''),//沟通备注 "staff_id" => $request->param('staff_id', ''),//人员ID diff --git a/niucloud/app/api/controller/apiController/Statistics.php b/niucloud/app/api/controller/apiController/Statistics.php new file mode 100644 index 00000000..19e6c2e2 --- /dev/null +++ b/niucloud/app/api/controller/apiController/Statistics.php @@ -0,0 +1,188 @@ +param('personnel_id','');//员工表id + $role_key_arr = $request->param('role_key_arr','');//array 角色key + //字符转数组 + $role_key_arr = explode(',',$role_key_arr); + if(empty($personnel_id)|| empty($role_key_arr)){ + return fail('缺少参数'); + } + $firstDayOfMonth = date('m月01日'); // 获取本月第一天 + $lastDayOfMonth = date('m月t日'); // 获取本月最后一天 + $dateRange = "{$firstDayOfMonth}-{$lastDayOfMonth}"; // 拼接日期范围字符串 + +// $role_key_arr = ['sale'];//@todo 调试使用 + + if(in_array('market',$role_key_arr) || in_array('market_manager',$role_key_arr)){ + //市场人员统计数据(地推拉人头的) + $data = [ + 'date_range'=>$dateRange,//拼接日期范围字符串 + 'role_type'=>'market_type',//角色类型|market_type=市场,sale_type=销售 + //本月 + 'month' => [ + 'new_total' => ($newTotal = rand(100, 500)),//拉新总人数 + 'new_total_rate' => min(100, round($newTotal / 1000 * 100, 2)),//拉新总人数比例(不超过100%) + 'assigned_sales' => ($assignedSales = rand(50, 300)),//已分配给销售的人数 + 'assigned_sales_rate' => min(100, round($assignedSales / $newTotal * 100, 2)),//已分配给销售的人数比例(不超过100%) + 'yesterday_new' => ($yesterdayNew = rand(5, 50)),//昨日拉新 + 'yesterday_new_rate' => min(100, round($yesterdayNew / $newTotal * 100, 2)),//昨日拉新比例(不超过100%) + 'today_new' => ($todayNew = rand(1, 20)),//今日拉新 + 'today_new_rate' => min(100, round($todayNew / $newTotal * 100, 2)),//今日拉新比例(不超过100%) + ], + //上月 + 'last_month' => [ + 'new_total' => ($lastNewTotal = rand(80, 400)),//拉新总人数 + 'new_total_rate' => min(100, round($lastNewTotal / 800 * 100, 2)),//拉新总人数比例(不超过100%) + 'assigned_sales' => ($lastAssignedSales = rand(40, 250)),//已分配给销售的人数 + 'assigned_sales_rate' => min(100, round($lastAssignedSales / $lastNewTotal * 100, 2)),//已分配给销售的人数比例(不超过100%) + 'yesterday_new' => ($lastYesterdayNew = rand(3, 40)),//昨日拉新人数 + 'yesterday_new_rate' => min(100, round($lastYesterdayNew / $lastNewTotal * 100, 2)),//昨日拉新人数比例(不超过100%) + 'today_new' => ($lastTodayNew = rand(1, 15)),//今日拉新人数 + 'today_new_rate' => min(100, round($lastTodayNew / $lastNewTotal * 100, 2)),//今日拉新人数比例(不超过100%) + ] + ]; + }elseif(in_array('sale',$role_key_arr) || in_array('sale_manager',$role_key_arr)){ + //销售人员统计数据(买课的) + $data = [ + 'date_range'=>$dateRange,//拼接日期范围字符串 + 'role_type'=>'sale_type',//角色类型|market_type=市场,sale_type=销售 infoData.month + //本月 + 'month' => [ + 'assigned_clients' => ($assigned = rand(50, 300)),//分配给我的客户人数 + 'contacted_clients' => ($contacted = rand(20, 150)),//已沟通的客户人数 + 'contact_rate' => min(100, round($contacted / $assigned * 100, 2)),//沟通率(不超过100%) + 'unconverted_clients' => ($unconverted = rand(10, 50)),//已沟通但没成交的客户人数 + 'unconverted_rate' => min(100, round($unconverted / $contacted * 100, 2)),//未成交率(不超过100%) + 'renewal_clients' => ($renewal = rand(5, 30)),//待续费的客户人数 + 'renewal_rate' => min(100, round($renewal / $assigned * 100, 2)),//待续费率(不超过100%) + 'closed_clients' => ($closed = rand(1, 20)),//已关单的客户人数 + 'closed_rate' => min(100, round($closed / $contacted * 100, 2)),//关单率(不超过100%) + 'conversion_rate' => min(100, round($closed / $assigned * 100, 2)),//整体转化率(不超过100%) + ], + //上月 + 'last_month' => [ + 'assigned_clients' => ($lastAssigned = rand(40, 250)),//分配给我的客户人数 + 'contacted_clients' => ($lastContacted = rand(15, 120)),//已沟通的客户人数 + 'contact_rate' => min(100, round($lastContacted / $lastAssigned * 100, 2)),//沟通率(不超过100%) + 'unconverted_clients' => ($lastUnconverted = rand(8, 40)),//已沟通但没成交的客户人数 + 'unconverted_rate' => min(100, round($lastUnconverted / $lastContacted * 100, 2)),//未成交率(不超过100%) + 'renewal_clients' => ($lastRenewal = rand(3, 25)),//待续费的客户人数 + 'renewal_rate' => min(100, round($lastRenewal / $lastAssigned * 100, 2)),//待续费率(不超过100%) + 'closed_clients' => ($lastClosed = rand(1, 15)),//已关单的客户人数 + 'closed_rate' => min(100, round($lastClosed / $lastContacted * 100, 2)),//关单率(不超过100%) + 'conversion_rate' => min(100, round($lastClosed / $lastAssigned * 100, 2)),//整体转化率(不超过100%) + ] + ]; + }else{ + return fail('角色权限不正确'); + } + + + return success($data); + } + + /** + * 员工端统计(销售)-获取销售数据页统计 + */ + public function marketData(Request $request) + { + $personnel_id = $request->param('personnel_id','');//员工表id + $role_key_arr = $request->param('role_key_arr','');//array 角色key + $role_key_arr = explode(',',$role_key_arr); + if(empty($personnel_id)|| empty($role_key_arr)){ + return fail('缺少参数'); + } + +// $role_key_arr = ['sale'];//@todo 调试使用 + + if(in_array('market',$role_key_arr) || in_array('market_manager',$role_key_arr)){ + //市场人员统计数据(地推拉人头的) + $data = [ + 'role_type'=>'market_type',//角色类型|market_type=市场,sale_type=销售 + + 'num_1' => ($assigned = rand(20, 150)),//本周已分配 + 'num_2' => ($unassigned = rand(5, 50)),//本周未分配 + 'total_1' => ($newTotal = $assigned + $unassigned),//本周拉新总数 + 'total_2' => ($lastWeekNewTotal = rand(10, 100)),//上周拉新总数 + + 'num_1_rate' => min(100, round($assigned / $newTotal * 100, 2)),//已分配比例 + 'num_2_rate' => min(100, round($unassigned / $newTotal * 100, 2)),//未分配比例 + 'num_3_rate' => min(100, round($newTotal / max(1, $lastWeekNewTotal) * 100, 2)), // 本周拉新率(对比上周) + 'num_4_rate' => min(100, round($assigned / max(1, $lastWeekNewTotal) * 100, 2)), // 本周分配率(对比上周) + 'staff_list' => [ + ['name' => '张三', 'goal' => rand(50, 200), 'wx_yj' => rand(30, 180)], + ['name' => '李四', 'goal' => rand(50, 200), 'wx_yj' => rand(30, 180)], + ['name' => '王五', 'goal' => rand(50, 200), 'wx_yj' => rand(30, 180)], + ['name' => '赵六', 'goal' => rand(50, 200), 'wx_yj' => rand(30, 180)], + ['name' => '钱七', 'goal' => rand(50, 200), 'wx_yj' => rand(30, 180)], + ['name' => '孙八', 'goal' => rand(50, 200), 'wx_yj' => rand(30, 180)], + ['name' => '周九', 'goal' => rand(50, 200), 'wx_yj' => rand(30, 180)], + ['name' => '吴十', 'goal' => rand(50, 200), 'wx_yj' => rand(30, 180)], + ['name' => '郑十一', 'goal' => rand(50, 200), 'wx_yj' => rand(30, 180)], + ['name' => '王十二', 'goal' => rand(50, 200), 'wx_yj' => rand(30, 180)], + ], + ]; + }elseif(in_array('sale',$role_key_arr) || in_array('sale_manager',$role_key_arr)){ + //销售人员统计数据(买课的) + $data = [ + 'role_type'=>'sale',//角色类型|market_type=市场,sale_type=销售 + + 'num_1' => ($assigned = rand(20, 150)),//本周已分配 + 'num_2' => ($unassigned = rand(5, 50)),//本周未分配 + 'total_1' => ($newTotal = $assigned + $unassigned),//本周拉新总数 + 'total_2' => ($lastWeekNewTotal = rand(10, 100)),//上周拉新总数 + + 'num_1_rate' => min(100, round($assigned / $newTotal * 100, 2)),//已分配比例 + 'num_2_rate' => min(100, round($unassigned / $newTotal * 100, 2)),//未分配比例 + 'num_3_rate' => min(100, round($newTotal / max(1, $lastWeekNewTotal) * 100, 2)), // 本周拉新率(对比上周) + 'num_4_rate' => min(100, round($assigned / max(1, $lastWeekNewTotal) * 100, 2)), // 本周分配率(对比上周) + 'staff_list' => [ + ['name' => '张三', 'goal' => rand(50, 200), 'wx_yj' => rand(30, 180)], + ['name' => '李四', 'goal' => rand(50, 200), 'wx_yj' => rand(30, 180)], + ['name' => '王五', 'goal' => rand(50, 200), 'wx_yj' => rand(30, 180)], + ['name' => '赵六', 'goal' => rand(50, 200), 'wx_yj' => rand(30, 180)], + ['name' => '钱七', 'goal' => rand(50, 200), 'wx_yj' => rand(30, 180)], + ['name' => '孙八', 'goal' => rand(50, 200), 'wx_yj' => rand(30, 180)], + ['name' => '周九', 'goal' => rand(50, 200), 'wx_yj' => rand(30, 180)], + ['name' => '吴十', 'goal' => rand(50, 200), 'wx_yj' => rand(30, 180)], + ['name' => '郑十一', 'goal' => rand(50, 200), 'wx_yj' => rand(30, 180)], + ['name' => '王十二', 'goal' => rand(50, 200), 'wx_yj' => rand(30, 180)], + ], + ]; + }else{ + return fail('角色权限不正确'); + } + return success($data); + } + + + +} diff --git a/niucloud/app/api/controller/login/Login.php b/niucloud/app/api/controller/login/Login.php index 6bce779e..2ad930a0 100644 --- a/niucloud/app/api/controller/login/Login.php +++ b/niucloud/app/api/controller/login/Login.php @@ -12,6 +12,7 @@ namespace app\api\controller\login; use app\dict\member\MemberLoginTypeDict; +use app\model\order_table\OrderTable; use app\model\sys\SysConfig; use app\service\admin\sys\SystemService; use app\service\api\captcha\CaptchaService; @@ -138,43 +139,8 @@ class Login extends BaseController } public function test(){ - $pay_config = Db::name("campus_pay")->where(['campus_id' => 1])->find(); - - $sysConfig = new SysConfig(); - - $vx_config = $sysConfig->where(['config_key' => 'WECHAT'])->value("value"); - - $config = [ - // 必填-商户号 - 'mch_id' => $pay_config['mchid'], - // 必填-商户私钥 字符串或路径 - 'mch_secret_cert' => $pay_config['apiclient_cert'], - // 必填-商户公钥证书路径 - 'mch_public_cert_path' => $pay_config['apiclient_key'], - // 必填 - 'notify_url' => 'https://zh.hnhbty.cn/api/pay/qrcodenotify', - // 选填-公众号 的 app_id - 'mp_app_id' => $vx_config['app_id'], - // 选填-小程序 的 app_id - 'mini_app_id' => '', - 'mch_secret_key' => $pay_config['pay_sign_key'], - ]; - $params = [ - 'out_trade_no' => '123123', - 'body' => '测试', - 'money' => 100, - ]; - $pay = new PayLoader('Wechatpay', $config); - - $url = $pay->scan($params); - - $path = qrcode( - $url['code_url'], - '', - [], - 'upload/qrcode/pay/' - ); - - echo "";die; + $order = new OrderTable(); + $order_info = $order->where(['id' => 8])->find(); + event('Student', ['event_type' => 'add','order_info' => $order_info]); } } diff --git a/niucloud/app/api/route/route.php b/niucloud/app/api/route/route.php index 2a918b90..9b55b060 100644 --- a/niucloud/app/api/route/route.php +++ b/niucloud/app/api/route/route.php @@ -176,8 +176,8 @@ Route::group(function () { Route::post('personnelLogin', 'login.Login/personnelLogin'); //获取字典 Route::get('common/getDictionary', 'apiController.Common/getDictionary'); - //员工端-修改密码操作 - Route::post('personnel/edidPassword', 'apiController.Personnel/edidPassword'); + //忘记密码-通过短信验证码进行密码重置(学生/员工通用) + Route::post('common/forgetPassword', 'apiController.Common/forgetPassword'); @@ -209,16 +209,26 @@ Route::group(function () { Route::post('personnel/edit', 'apiController.Personnel/edit'); //员工端-验证旧密码是否正确 Route::post('personnel/checkOldPwd', 'apiController.Personnel/checkOldPwd'); + //员工端-修改密码操作(通过旧密码修改新密码) + Route::post('personnel/edidPassword', 'apiController.Personnel/edidPassword'); //员工端-获取全部人员列表 Route::get('personnel/getPersonnelAll', 'apiController.Personnel/getPersonnelAll'); + + //员工端统计(销售)-获取销售首页数据统计 + Route::get('statistics/marketHome', 'apiController.Statistics/marketHome'); + //员工端统计(销售)-获取销售数据页统计 + Route::get('statistics/marketData', 'apiController.Statistics/marketData'); + //客户资源-添加 Route::post('customerResources/add', 'apiController.CustomerResources/add'); //客户资源-编辑 Route::post('customerResources/edit', 'apiController.CustomerResources/edit'); //客户资源-修改记录列表 Route::get('customerResources/getEditLogList', 'apiController.CustomerResources/getEditLogList'); + //客户资源-获取全部客户资源列表 + Route::get('customerResources/getAll', 'apiController.CustomerResources/getAll'); //资源共享-列表 @@ -274,9 +284,16 @@ Route::group(function () { - - - + //获取添加学员列表 + Route::get('course/addStudentList', 'apiController.course/addStudentList'); + Route::post('course/addStudent', 'apiController.course/addStudent'); + Route::get('course/delStudentCourse', 'apiController.course/delStudentCourse'); + //班级列表 + Route::get('class/jlClassList', 'apiController.classApi/jlClassList'); + //课程列表 + Route::get('course/courseList', 'apiController.course/courseList'); + //获取课程详情 + Route::get('course/courseInfo', 'apiController.course/courseInfo'); //教研管理文章列表 Route::get('teachingResearch/list', 'apiController.teachingResearch/list'); //教研管理文章详情 diff --git a/niucloud/app/event.php b/niucloud/app/event.php index 9f6e5d68..54824f14 100644 --- a/niucloud/app/event.php +++ b/niucloud/app/event.php @@ -117,6 +117,9 @@ $system_event = [ //计算业绩 'CalculatePerformance' => [ 'app\listener\personnel\CalculatePerformance' ], + + //学员 + 'Student' => [ 'app\listener\personnel\Student' ], ], 'subscribe' => [ ], diff --git a/niucloud/app/listener/personnel/Student.php b/niucloud/app/listener/personnel/Student.php new file mode 100644 index 00000000..824a124f --- /dev/null +++ b/niucloud/app/listener/personnel/Student.php @@ -0,0 +1,124 @@ +studentAdd($params['data']); + } + + if ($params['event_type'] === 'xiaoke') { + $this->studentXiaoke($params['data']); + } + } + + public function studentXiaoke($data){ + $courseSchedule = new CourseSchedule(); + $studentCourses = new StudentCourses(); + $student_course_usage = new StudentCourseUsage(); + $schedule_info = $courseSchedule->where(['id' => $data['schedule_id']])->find(); + $studentCourses_info = $studentCourses->where(['student_id' => $data['student_id'],'course_id' => $schedule_info['course_id']])->find(); + + $student_course_usage->insert([ + 'student_course_id' => $studentCourses_info['id'], + 'used_hours' => $studentCourses_info['single_session_count'], + 'usage_date' => date("Y-m-d") + ]); + + } + + public function studentAdd($order_info){ + $student = new \app\model\student\Student(); + $order = new OrderTable(); + $cust = new CustomerResources(); + $class_resources_rel = new ClassResourcesRel(); + $course = new Course(); + $studentCourses = new StudentCourses(); + $order_count = $order->where(['resource_id' => $order_info['resource_id']])->count(); + $cust_info = $cust->where(['id' => $order_info['resource_id']])->find(); + //创建学员关系逻辑 + if($order_count <= 1){ + $sex_arr = ['male' => 1, 'female' => 2, 'other' => 0]; + //首次支付创建学员 + $student_id = $student->insertGetId([ + 'name' => $cust_info['name'], + 'gender' => $sex_arr[$cust_info['gender']], + 'age' => $cust_info['age'], + 'campus_id' => $cust_info['campus'], + 'class_id' => $order_info['class_id'], + 'status' => 1, + 'user_id' => $order_info['resource_id'] + ]); + }else{ + $student_id = $student->where(['user_id' => $order_info['resource_id'],'class_id' => $order_info['class_id']])->value('id'); + } + + //学员课程逻辑 + $course_info = $course->where(['id' => $order_info['course_id']])->find(); + $studentCourses->insert([ + 'student_id' => $student_id, + 'course_id' => $order_info['course_id'], + 'total_hours' => $course_info['session_count'], + 'gift_hours' => $course_info['gift_session_count'], + 'start_date' => date("Y-m-d"), + 'end_date' => date("Y-m-d", strtotime("+30 days")), + 'single_session_count' => $course_info['single_session_count'] + ]); + + + //班级资源关系逻辑 + $is_rel = $class_resources_rel->where( + ['resource_id' => $order_info['resource_id'],'class_id' => $order_info['class_id']] + )->find(); + if($is_rel){ + $class_resources_rel->where(['id' => $is_rel['id']])->update(['status' => 2]); + }else{ + $class_resources_rel->insert([ + 'class_id' => $order_info['class_id'], + 'resource_id' => $order_info['resource_id'], + 'campus_id' => $cust_info['campus'], + 'source_type' => 'student', + 'join_time' => time(), + 'status' => 1, + 'create_time' => date("Y-m-d H:i:s"), + 'update_time' => date("Y-m-d H:i:s") + ]); + } + + + + + + } + + +} diff --git a/niucloud/app/model/assignment/Assignment.php b/niucloud/app/model/assignment/Assignment.php new file mode 100644 index 00000000..e61c6873 --- /dev/null +++ b/niucloud/app/model/assignment/Assignment.php @@ -0,0 +1,61 @@ +hasOne(Student::class, 'id', 'student_id'); + } + +} diff --git a/niucloud/app/model/customer_resources/CustomerResources.php b/niucloud/app/model/customer_resources/CustomerResources.php index cd2e4f79..218f156d 100644 --- a/niucloud/app/model/customer_resources/CustomerResources.php +++ b/niucloud/app/model/customer_resources/CustomerResources.php @@ -24,6 +24,7 @@ use think\model\relation\HasOne; use app\model\personnel\Personnel; use app\model\campus\Campus; +use app\model\member\Member; /** * 客户资源模型 @@ -127,7 +128,9 @@ class CustomerResources extends BaseModel } - + public function member(){ + return $this->hasOne(Member::class, 'member_id', 'member_id'); + } @@ -153,6 +156,15 @@ class CustomerResources extends BaseModel return $this->hasOne(SixSpeed::class, 'resource_id', 'id'); } + //一对多关联"资源共享表" + public function resourceSharingHasMany() + { + return $this->hasMany(ResourceSharing::class, 'resource_id', 'id'); + } + + + + /** * 获取客户初步意向度类型名称 * @param $value diff --git a/niucloud/app/service/admin/auth/AuthService.php b/niucloud/app/service/admin/auth/AuthService.php index ec9c9c58..c2b014d8 100644 --- a/niucloud/app/service/admin/auth/AuthService.php +++ b/niucloud/app/service/admin/auth/AuthService.php @@ -11,6 +11,8 @@ namespace app\service\admin\auth; +use app\model\campus_person_role\CampusPersonRole; +use app\model\personnel\Personnel; use app\Request; use app\service\admin\sys\MenuService; use app\service\admin\sys\RoleService; @@ -91,7 +93,12 @@ class AuthService extends BaseAdminService if ($is_admin) {//查询全部启用的权限 return ( new MenuService() )->getAllMenuList($status, $is_tree, $is_button); } else { - $user_role_ids = $user_info[ 'role_ids' ]; + $per = new Personnel(); + $CampusPersonRole = new CampusPersonRole(); + $per_id = $per->where(['sys_user_id' => $this->uid])->column('id'); + + $user_role_ids = $CampusPersonRole->where(['person_id' => $per_id])->column('role_id'); +// $role_service = new RoleService(); $menu_keys = $role_service->getMenuKeysByRoleIds($user_role_ids ?? []); return $menu_service->getMenuListByMenuKeys($menu_keys, $is_tree, is_button:$is_button); diff --git a/niucloud/app/service/admin/campus_person_role/CampusPersonRoleService.php b/niucloud/app/service/admin/campus_person_role/CampusPersonRoleService.php index c16555c9..f6fa7706 100644 --- a/niucloud/app/service/admin/campus_person_role/CampusPersonRoleService.php +++ b/niucloud/app/service/admin/campus_person_role/CampusPersonRoleService.php @@ -93,6 +93,8 @@ class CampusPersonRoleService extends BaseAdminService public function add(array $data) { $res = $this->model->create($data); + + return $res->id; } diff --git a/niucloud/app/service/admin/person_course_schedule/PersonCourseScheduleService.php b/niucloud/app/service/admin/person_course_schedule/PersonCourseScheduleService.php index 4825af1d..0bca593b 100644 --- a/niucloud/app/service/admin/person_course_schedule/PersonCourseScheduleService.php +++ b/niucloud/app/service/admin/person_course_schedule/PersonCourseScheduleService.php @@ -219,10 +219,9 @@ class PersonCourseScheduleService extends BaseAdminService return $data; } public function xk(int $id){ - $model = $this->model->where([['id', '=', $id]])->find(); - $res = $model->delete(); - return $res; - + $data = $this->model->where([['id', '=', $id]])->find(); + event('Student', ['event_type' => 'xiaoke','data' => $data]); + return true; } public function getCustomerResourcesAll(){ diff --git a/niucloud/app/service/api/apiService/CommonService.php b/niucloud/app/service/api/apiService/CommonService.php index 26654fd4..5a41285a 100644 --- a/niucloud/app/service/api/apiService/CommonService.php +++ b/niucloud/app/service/api/apiService/CommonService.php @@ -12,6 +12,8 @@ namespace app\service\api\apiService; use app\model\dict\Dict; +use app\model\member\Member; +use app\model\sys\SysUser; use core\base\BaseApiService; /** @@ -43,6 +45,58 @@ class CommonService extends BaseApiService } + /** + * 忘记密码功能 - 根据用户类型重置密码 + * @param string $phone 用户手机号 + * @param string $new_password 用户新密码 + * @param string $user_type 用户类型|customer=学生|personnel=员工(销售/教师) + */ + public function forgetPassword($phone, $new_password, $user_type){ + if($user_type == 'personnel'){ + //重置员工(销售/教师)密码 + $update = SysUser::where('username', $phone)->update([ + 'password' => create_password($new_password),//创建密码 + 'update_time' => time(), + ]); + if (!$update) { + $res = [ + 'code' => 0, + 'msg' => '操作失败', + 'data' => [] + ]; + } else { + $res = [ + 'code' => 1, + 'msg' => '操作成功', + 'data' => [] + ]; + } + return $res; + }else{ + //重置用户(学生)密码 + $update = Member::where('username', $phone)->update([ + 'password' => create_password($new_password),//创建密码 + 'update_time' => time(), + ]); + if (!$update) { + $res = [ + 'code' => 0, + 'msg' => '操作失败', + 'data' => [] + ]; + } else { + $res = [ + 'code' => 1, + 'msg' => '操作成功', + 'data' => [] + ]; + } + return $res; + } + + + } + /** * 对比新旧数据改变 * @param array $old_data 旧数据 diff --git a/niucloud/app/service/api/apiService/CourseService.php b/niucloud/app/service/api/apiService/CourseService.php new file mode 100644 index 00000000..ddefbf3b --- /dev/null +++ b/niucloud/app/service/api/apiService/CourseService.php @@ -0,0 +1,185 @@ +model = new Course(); + } + + //课程列表 + public function list($id,$data) + { + $where = []; + if ($data['schedule_date']) { + $where[] = ['course_date','=', $data['schedule_date']]; + } + $CourseSchedule = new CourseSchedule(); + $search_model = $CourseSchedule + ->where('coach_id', $id) + ->where($where) + ->with(['course' => function($query) { + $query->select(); + },'venue' => function($query) { + $query->select(); + }]); + $list = $this->pageQuery($search_model); + $PersonCourseSchedule = new PersonCourseSchedule(); + foreach ($list['data'] as $k => $v) { + $student = Db::name('person_course_schedule') + ->alias('pcs') + ->where('pcs.schedule_id', $v['id']) // 建议加上表别名避免冲突 + ->join('school_student st', 'pcs.student_id = st.id') + ->join('school_customer_resources cr', 'st.user_id = cr.id') + ->join('school_member sm', 'cr.member_id = sm.member_id') + ->field('st.name, sm.headimg as avatar') // 👈 正确方式取字段 + ->select(); + $list['data'][$k]['student'] = $student; + } + return $list; + } + //获取课程详情 + public function info($data) + { + $CourseSchedule = new CourseSchedule(); + $search_model = $CourseSchedule + ->where('id', $data) + ->with(['course' => function($query) { + $query->select(); + },'venue' => function($query) { + $query->select(); + },'coach' => function($query) { + $query->select(); + }]); + $list = $search_model->find(); + $student = Db::name('person_course_schedule') + ->alias('pcs') + ->where('pcs.schedule_id', $list['id']) + ->join('school_student st', 'pcs.student_id = st.id') + ->join('school_customer_resources cr', 'st.user_id = cr.id') + ->join('school_member sm', 'cr.member_id = sm.member_id') + ->field('st.name, sm.headimg as avatar') + ->select(); + $list['student'] = $student; + $student_courses = Db::name('student_courses') + ->alias('sc') + ->where('sc.course_id', $list['id']) + ->join('school_student_course_usage sscu', 'sc.id = sscu.student_course_id') + ->field('sc.student_id,sc.end_date') + ->select()->toArray(); + foreach ($student_courses as &$v){ + $student = Db::name('student') + ->alias('st') + ->where('st.id', $v['student_id']) + ->join('school_customer_resources cr', 'st.user_id = cr.id') + ->join('school_member sm', 'cr.member_id = sm.member_id') + ->field('st.name, sm.headimg as avatar') + ->find(); + $v['name'] = $student['name']; + $v['avatar'] = $student['avatar']; + } + $list['student_courses'] = $student_courses; + + $Assignment = new Assignment(); + $search_model = $Assignment->where('course_id', $data) + ->with(['student' => function($query) { + $query->with(['customerResources' => function($query) { + $query->with(['member' => function($query) { + $query->select(); + }]); + }]); + }]); + $search_model_res = $search_model->select()->toArray(); + $groupedByStatus1 = []; + $groupedByStatus2 = []; + $groupedByStatus3 = []; + + foreach ($search_model_res as $item) { + if ($item['status'] == 1){ + array_push($groupedByStatus1,$item); + } else if ($item['status'] == 2){ + array_push($groupedByStatus2,$item); + } else if ($item['status'] == 3){ + array_push($groupedByStatus3,$item); + } + } + $list['groupedByStatus1'] = $groupedByStatus1; + $list['groupedByStatus2'] = $groupedByStatus2; + $list['groupedByStatus3'] = $groupedByStatus3; + return $list; + } + + + //获取添加学员列表 + public function StudentList($id) + { + $StudentCourses = new StudentCourses(); + $PersonCourseSchedule = new PersonCourseSchedule(); + $student_arr = $PersonCourseSchedule->where('schedule_id',$id)->column('student_id'); + + $query = $StudentCourses->where('course_id', $id); + if (!empty($student_arr)) { + $query->whereNotIn('student_id', $student_arr); + } + $res = $query->field('student_id as value')->select()->toArray(); + $Student = new Student(); + foreach ($res as $k => &$v) { + $StudentName = $Student->where('id',$v['value'])->value('name'); + $v['text'] = $StudentName; + } + return $res; + } + + public function addStudent($data) + { + $PersonCourseSchedule = new PersonCourseSchedule(); + $res = $PersonCourseSchedule->create($data); + return $res; + } + + + public function delStudentCourse($data) + { + $StudentCourseUsage = new StudentCourseUsage(); + $StudentCourses = new StudentCourses(); + $StudentCourses_id = $StudentCourses->where('student_id',$data['student_id'])->where('course_id',$data['course_id'])->value('id'); + $PersonCourseSchedule_id = $StudentCourseUsage->where('student_course_id',$StudentCourses_id)->value('id'); + if ($PersonCourseSchedule_id) { + $StudentCourseUsage->where('student_course_id',$StudentCourses_id)->delete(); + return true; + } else { + return false; + } + } + + +} + diff --git a/niucloud/app/service/api/apiService/CustomerResourcesService.php b/niucloud/app/service/api/apiService/CustomerResourcesService.php index bcd4a228..142dec68 100644 --- a/niucloud/app/service/api/apiService/CustomerResourcesService.php +++ b/niucloud/app/service/api/apiService/CustomerResourcesService.php @@ -36,6 +36,42 @@ class CustomerResourcesService extends BaseApiService parent::__construct(); } + //获取全部客户资源数据 + public function getAll(array $where,string $field = '*') + { + $res = [ + 'code' => 0, + 'msg' => '操作失败', + 'data' => [] + ]; + if(!$where){ + $res['msg'] = '查询条件不能为空'; + return $res; + } + $model = new CustomerResources(); + if(!empty($where['name'])){ + $model = $model->where('name', 'like', "%{$where['name']}%"); + } + $data = $model->field($field) + ->with([ + 'resourceSharingHasMany' + ]) + ->append([ + 'initial_intent_name' + ]) + ->select()->toArray(); + if (!$data) { + $res['msg'] = '暂无数据'; + return $res; + } + $res['code'] = 1; + $res['msg'] = '操作成功'; + $res['data'] = $data; + return $res; + + + } + //添加数据 public function addData(array $customer_resources_data, array $six_speed_data) { diff --git a/niucloud/app/service/api/apiService/StatisticsService.php b/niucloud/app/service/api/apiService/StatisticsService.php new file mode 100644 index 00000000..fbc027cc --- /dev/null +++ b/niucloud/app/service/api/apiService/StatisticsService.php @@ -0,0 +1,33 @@ +where('phone', $params['phone'])->find(); + if(!$member_info){ + throw new ApiException('账号不存在'); + } if ($member_info->status != 2) throw new ApiException('账号状态异常禁止登录'); $user = (new SysUser())->where('username', $params['phone'])->find(); diff --git a/niucloud/app/service/api/pay/PayService.php b/niucloud/app/service/api/pay/PayService.php index 66f54dba..52e53909 100644 --- a/niucloud/app/service/api/pay/PayService.php +++ b/niucloud/app/service/api/pay/PayService.php @@ -166,9 +166,7 @@ class PayService extends BaseApiService public function qrcodeNotify($data,$order_id) { - $student = new Student(); $order = new OrderTable(); - $cust = new CustomerResources(); $order_info = $order->where(['id' => $order_id])->find(); if($order_info['order_status'] == 'pending' and !empty($order_info['ipv3'])){ $resource = $data['resource']; @@ -182,39 +180,8 @@ class PayService extends BaseApiService $order->where(['payment_id' => $info['out_trade_no']])->update(['order_status' => 'paid','payment_time' => date("Y-m-d H:i:s")]); - $order_count = $order->where(['resource_id' => $order_info['resource_id']])->count(); - $cust_info = $cust->where(['id' => $order_info['resource_id']])->find(); - if($order_count <= 1){ - $sex_arr = ['male' => 1, 'female' => 2, 'other' => 0]; - //首次支付创建学员 - $student->insert([ - 'name' => $cust_info['name'], - 'gender' => $sex_arr[$cust_info['gender']], - 'age' => $cust_info['age'], - 'campus_id' => $cust_info['campus'], - 'class_id' => $order_info['class_id'], - 'status' => 1, - 'user_id' => $order_info['resource_id'] - ]); - } - $is_rel = Db::name("class_resources_rel")->where( - ['resource_id' => $order_info['resource_id'],'class_id' => $order_info['class_id']] - )->find(); - if($is_rel){ - Db::name("class_resources_rel")->where(['id' => $is_rel['id']])->update(['status' => 2]); - }else{ - Db::name("class_resources_rel")->insert([ - 'class_id' => $order_info['class_id'], - 'resource_id' => $order_info['resource_id'], - 'campus_id' => $cust_info['campus'], - 'source_type' => 'student', - 'join_time' => time(), - 'status' => 1, - 'create_time' => date("Y-m-d H:i:s"), - 'update_time' => date("Y-m-d H:i:s") - ]); - } + event('Student', ['event_type' => 'add','data' => $order_info]); } }