@ -12,8 +12,12 @@
namespace app\service\api\member;
namespace app\service\api\member;
use addon\zhjw\app\model\assignments\Assignments;
use addon\zhjw\app\model\assignments\Assignments;
use addon\zhjw\app\model\campuses\Campuses;
use addon\zhjw\app\model\classes\Classes;
use addon\zhjw\app\model\classes\Classes;
use addon\zhjw\app\model\courses\Courses;
use addon\zhjw\app\model\courses\Courses;
use addon\zhjw\app\model\follow_up_logs\FollowUpLogs;
use addon\zhjw\app\model\follow_up_reminders\FollowUpReminders;
use addon\zhjw\app\model\sales\Sales;
use addon\zhjw\app\model\schedules\Schedules;
use addon\zhjw\app\model\schedules\Schedules;
use addon\zhjw\app\model\staff\Staff;
use addon\zhjw\app\model\staff\Staff;
use addon\zhjw\app\model\students\Students;
use addon\zhjw\app\model\students\Students;
@ -78,15 +82,17 @@ class MemberService extends BaseApiService
->findOrEmpty()->toArray();
->findOrEmpty()->toArray();
$role_id = get_user_type($this->member_id);
$role_id = get_user_type($this->member_id);
$staff = (new Staff())->where(['member_id' => $this->member_id])->find();
$info['staff_id'] = $staff['id'];
$info['headimg'] = $staff['header'];
$info['name'] = $staff['name'] ?? '';
$info['gender'] = $staff['gender'];
$info['phone'] = $staff['phone'];
$info['email'] = $staff['email'];
$info['role_id'] = $role_id;
if($role_id == 1){
if($role_id == 1){
//学员信息
//学员信息
$staff = (new Staff())->where(['member_id' => $this->member_id])->find();
$info['staff_id'] = $staff['id'];
$info['headimg'] = $staff['header'];
$info['name'] = $staff['name'] ?? '';
$info['gender'] = $staff['gender'];
$info['phone'] = $staff['phone'];
$info['email'] = $staff['email'];
$data = (new Students())->where(['user_id' => $staff['id']])->find();
$data = (new Students())->where(['user_id' => $staff['id']])->find();
$info['height'] = $data['height'];
$info['height'] = $data['height'];
$info['weight'] = $data['weight'];
$info['weight'] = $data['weight'];
@ -264,7 +270,7 @@ class MemberService extends BaseApiService
->where('a.start_date', '< =', $data['schedule_date'])
->where('a.start_date', '< =', $data['schedule_date'])
->where('a.end_date', '>=', $data['schedule_date'])
->where('a.end_date', '>=', $data['schedule_date'])
->where('a.status','< ',3)
->where('a.status','< ',3)
->whereRaw("FIND_IN_SET(?, a.max_students)", [$member_info['students_id']])
// ->whereRaw("FIND_IN_SET(?, a.max_students)", [$member_info['students_id']])
->field("a.id,a.status,a.venue_id,a.start_date,a.end_date,a.max_students,a.name,b.name as address,d.name as courses_name,
->field("a.id,a.status,a.venue_id,a.start_date,a.end_date,a.max_students,a.name,b.name as address,d.name as courses_name,
LENGTH(a.max_students) - LENGTH(REPLACE(a.max_students, ',', '')) + 1 as students_count,d.id as courses_id
LENGTH(a.max_students) - LENGTH(REPLACE(a.max_students, ',', '')) + 1 as students_count,d.id as courses_id
")
")
@ -299,8 +305,13 @@ class MemberService extends BaseApiService
$venue_id = $this->get_venues_ids($data)[0];
$venue_id = $this->get_venues_ids($data)[0];
$where['c.id'] = $venue_id;
$where['c.id'] = $venue_id;
}
}
if($data['courses_id']){
$where['d.id'] = $data['courses_id'];
}
if($member_info['role_id'] == 1){
$schedules = $schedules->whereRaw("FIND_IN_SET(?, b.max_students)", [$member_info['students_id']]);
}
$where['a.date_time'] = $data['schedule_date'];
$where['a.date_time'] = $data['schedule_date'];
$search_model = $schedules
$search_model = $schedules
->alias("a")
->alias("a")
@ -308,12 +319,11 @@ class MemberService extends BaseApiService
->join(['school_venues' => 'c'],'b.venue_id = c.id','left')
->join(['school_venues' => 'c'],'b.venue_id = c.id','left')
->join(['school_courses' => 'd'],'a.courses_id = d.id','left')
->join(['school_courses' => 'd'],'a.courses_id = d.id','left')
->where($where)
->where($where)
->whereRaw("FIND_IN_SET(?, b.max_students)", [$member_info['students_id']])
->field("a.id,a.status,b.name as classes_name,a.date_time,a.time_slot,c.name as address,c.address as address_info,d.name as courses_name,d.id as courses_id,LENGTH(b.max_students) - LENGTH(REPLACE(b.max_students, ',', '')) + 1 as students_count,b.max_students");
->field("a.id,a.status,b.name as classes_name,a.date_time,a.time_slot,c.name as address,c.address as address_info,d.name as courses_name,d.id as courses_id,LENGTH(b.max_students) - LENGTH(REPLACE(b.max_students, ',', '')) + 1 as students_count,b.max_students");
$list = $this->pageQuery($search_model, function ($item) use($member_info){
$list = $this->pageQuery($search_model, function ($item) use($member_info){
$where['a.students_id'] = $member_info['students_id'];
// $where['a.students_id'] = $member_info['students_id'];
$where['a.courses_id'] = $item['courses_id'];
$where['a.courses_id'] = $item['courses_id'];
$where['a.schedules_id'] = $item['id'];
$where['a.schedules_id'] = $item['id'];
$item['sign_list'] = Db::name("zhjw_students_sign")
$item['sign_list'] = Db::name("zhjw_students_sign")
@ -340,7 +350,6 @@ class MemberService extends BaseApiService
public function course_info($data){
public function course_info($data){
$member_info = $this->getInfo();
$schedules = new Schedules();
$schedules = new Schedules();
$where = [];
$where = [];
$where['a.id'] = $data['id'];
$where['a.id'] = $data['id'];
@ -377,6 +386,19 @@ class MemberService extends BaseApiService
}else{
}else{
$info['status'] = 1;
$info['status'] = 1;
}
}
$info['sign_status'] = Db::name("zhjw_students_sign")
->where(['schedules_id' => $data['id']])
->value("status") ?: 0;
$info['sign_list'] = Db::name("zhjw_students_sign")
->alias("a")
->join(['school_zhjw_students' => 'b'],'a.students_id = b.id','left')
->join(['school_staff' => 'c'],'b.user_id = c.id','left')
->where($where)
->order('a.create_time desc')
->field("a.*,c.name,c.header")
->select();
return $info;
return $info;
}
}
@ -470,18 +492,29 @@ class MemberService extends BaseApiService
public function assignments_list($data){
public function assignments_list($data){
$member_info = $this->getInfo();
$member_info = $this->getInfo();
$where = [];
$where = [];
$where['student_id'] = $member_info['students_id'];
$where['a. student_id'] = $member_info['students_id'];
if($data['status']){
if($data['status']){
$where['status'] = $data['status'];
$where['a. status'] = $data['status'];
}
}
$search_model = (new Assignments())->where($where)->order('create_time asc');
$search_model = (new Assignments())
->alias("a")
->join(['school_staff' => 'b'],'a.staff_id = b.id','left')
->where($where)
->field("a.*,b.name as coach_name,b.header as coach_pic")
->order('a.create_time asc');
return $this->pageQuery($search_model);
return $this->pageQuery($search_model);
}
}
public function assignments_info($data){
public function assignments_info($data){
$member_info = $this->getInfo();
$member_info = $this->getInfo();
$info = (new Assignments())->where(['student_id' => $member_info['students_id'],'id' => $data['id']])->find()->toArray();
$info = (new Assignments())
->alias("a")
->join(['school_staff' => 'b'],'a.staff_id = b.id','left')
->where(['a.student_id' => $member_info['students_id'],'a.id' => $data['id']])
->field("a.*,b.name as coach_name,b.header as coach_pic")
->find()->toArray();
return $info;
return $info;
}
}
@ -557,4 +590,252 @@ class MemberService extends BaseApiService
}
}
public function publish_job(array $data){
$classes = new Classes();
$member_info = $this->getInfo();
$students_ids = [];
$insert['staff_id'] = $member_info['staff_id'];
$insert['courses_id'] = $data['courses_id'];
$insert['content_type'] = $data['content_type'];
$insert['content'] = $data['content'];
$insert['content_text'] = $data['content_text'];
$insert['submit_time'] = date("Y-m-d H:i:s", time());
$insert['create_time'] = time();
$insert['update_time'] = time();
$insert['class_id'] = $data['classes_id'];
if($data['type'] == 1){
//班级作业
$students_ids = $classes->where(['id' => $data['classes_id']])->value("max_students");
$students_ids = explode(",",$students_ids);
}else{
//学员作业
$students_ids = explode(",",$data['students_ids']);
}
if(!empty($students_ids)){
foreach ($students_ids as $k=>$v){
$insert['student_id'] = $v;
Db::name("zhjw_assignments")->insert($insert);
}
}
return "发布成功";
}
public function get_classes_list(){
$classes = new Classes();
$student = new Students();
$list = $classes->select()->toArray();
foreach ($list as $k=>$v){
$list[$k]['student_list'] = $student->where('id','in',$v['max_students'])->select();
}
return $list;
}
public function get_courses_list(){
$courses = new Courses();
$list = $courses->select()->toArray();
return $list;
}
public function get_campuses_list(){
$campuses = new Campuses();
$list = $campuses->select()->toArray();
return $list;
}
public function get_assignments_list(){
$assignments = new Assignments();
$member_info = $this->getInfo();
$search_model = $assignments
->alias("a")
->join(['school_classes' => 'b'],'a.class_id = b.id','left')
->join(['school_courses' => 'c'],'a.courses_id = c.id','left')
->where(['a.staff_id' => $member_info['staff_id']])
->field('a.type,a.staff_id, a.class_id, a.courses_id, COUNT(*) as count,a.submit_time,b.name as class_name,c.name as course_name')
->group('a.staff_id, a.class_id, a.courses_id')
->order("a.id desc");
$list = $this->pageQuery($search_model, function ($item) use($member_info){
$assignments = new Assignments();
$item['wc_count'] = $assignments
->where([
'class_id' => $item['class_id'],
'courses_id' => $item['courses_id'],
'status' => 3
])
->count();
$item['wcl'] = $item['wc_count'] / $item['count'] * 100;
$item['dpg'] = $assignments
->where([
'class_id' => $item['class_id'],
'courses_id' => $item['courses_id'],
'status' => 2
])
->count();
});
return $list;
}
public function set_sales(array $data){
$sales = new Sales();
$follow_up_logs = new FollowUpLogs();
$follow_up_reminders = new FollowUpReminders();
$sales_id = $sales->insertGetId([
'title' => $data['title'],
'user_id' => addMember($data),
'student_phone' => $data['student_phone'],
'student_name' => $data['student_name'],
'sex' => $data['sex'],
'age' => $data['age'],
'campuses_id' => $data['campuses_id'],
'school_name' => $data['school_name'],
'grade' => $data['grade'],
'class_id' => $data['class_id'],
'class_name' => $data['class_name'],
'source_channel' => $data['source_channel'],
'customer_source' => $data['customer_source'],
'add_staff_id' => $data['add_staff_id'],
'get_staff_id' => $data['get_staff_id'],
'contact_name' => $data['contact_name'],
'province_id' => $data['province_id'],
'city_id' => $data['city_id'],
'district_id' => $data['district_id'],
'full_address' => $data['full_address'],
'community_name' => $data['community_name'],
'customer_tags' => $data['customer_tags'],
'create_time' => time(),
'update_time' => time(),
]);
if($data['is_follow'] == 2){
$logs_id = $follow_up_logs->insertGetId([
'sales_id' => $sales_id,
'staff_id' => $data['staff_id'],
'role_id' => get_role_id($data['staff_id']),
'entry_type' => $data['entry_type'],
'follow_up_time' => $data['follow_up_time'],
'create_time' => time()
]);
if($data['is_warn'] == 1){
$follow_up_reminders->insertGetId([
'follow_up_logs_id' => $logs_id,
'reminder_time' => $data['follow_up_time'],
'reminder_method' => $data['follow_up_method'],
'task_status' => 1,
'create_time' => time()
]);
}
}
return "添加成功";
}
public function create_follow(array $data){
$follow_up_logs = new FollowUpLogs();
$follow_up_reminders = new FollowUpReminders();
$logs_id = $follow_up_logs->insertGetId([
'sales_id' => $data['sales_id'],
'staff_id' => $data['staff_id'],
'audio_upload' =>$data['audio_upload'],
'customer_status' => $data['customer_status'],
'sign_up_contact_id' => $data['sign_up_contact_id'],
'role_id' => get_role_id($data['staff_id']),
'entry_type' => $data['entry_type'],
'follow_up_time' => $data['follow_up_time'],
'create_time' => time()
]);
if($data['is_warn'] == 1){
$follow_up_reminders->insertGetId([
'follow_up_logs_id' => $logs_id,
'reminder_time' => $data['reminder_time'],
'reminder_method' => $data['follow_up_method'],
'task_status' => 1,
'create_time' => time()
]);
}
return "添加成功";
}
public function sales_list(){
$sales = new Sales();
$search_model = $sales->order("id desc");
return $this->pageQuery($search_model, function ($item, $key) {
});
}
public function create_task(array $data){
$follow_up_logs = new FollowUpLogs();
$follow_up_reminders = new FollowUpReminders();
$logs_id = $follow_up_logs->insertGetId([
'sales_id' => $data['sales_id'],
'staff_id' => $data['staff_id'],
'role_id' => get_role_id($data['staff_id']),
'entry_type' => $data['entry_type'],
'follow_up_time' => $data['follow_up_time'],
'create_time' => time()
]);
if($data['is_warn'] == 1){
$follow_up_reminders->insertGetId([
'follow_up_logs_id' => $logs_id,
'reminder_time' => $data['follow_up_time'],
'reminder_method' => $data['follow_up_method'],
'task_status' => 1,
'create_time' => time()
]);
}
return "添加成功";
}
public function my_client(array $data){
$sales = new Sales();
$where = [];
if($data['type'] == 1){
$where[] = ['is_status','=',1];
}
if($data['type'] == 2){
$seven_days_ago = date('Y-m-d H:i:s', strtotime('-7 days'));
$where[] = ['follow_up_time','< ',$seven_days_ago];
}
if($data['type'] == 3){
$seven_days_ago = date('Y-m-d H:i:s', strtotime('-30 days'));
$where[] = ['follow_up_time','< ',$seven_days_ago];
$where[] = ['is_status','=',1];
}
$search_model = $sales->where($where)->order("id desc");
return $this->pageQuery($search_model, function ($item, $key) {
$follow_up_logs = new FollowUpLogs();
$follow = $follow_up_logs->where(['sales_id' => $item['id']])->order("id desc")->find();
$item['follow'] = $follow;
});
}
}
}