智慧教务系统 PHP-NiuCloud框架开发
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

1766 lines
63 KiB

<?php
// +----------------------------------------------------------------------
// | Niucloud-admin 企业快速开发的多应用管理平台
// +----------------------------------------------------------------------
// | 官方网址:https://www.niucloud.com
// +----------------------------------------------------------------------
// | niucloud团队 版权所有 开源版本可自由商用
// +----------------------------------------------------------------------
// | Author: Niucloud Team
// +----------------------------------------------------------------------
namespace app\service\api\member;
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\contracts\Contracts;
use addon\zhjw\app\model\courses\Courses;
use addon\zhjw\app\model\enterprise_information\EnterpriseInformation;
use addon\zhjw\app\model\follow_up_logs\FollowUpLogs;
use addon\zhjw\app\model\follow_up_reminders\FollowUpReminders;
use addon\zhjw\app\model\orders\Orders;
use addon\zhjw\app\model\sales\Sales;
use addon\zhjw\app\model\schedules\Schedules;
use addon\zhjw\app\model\staff\Staff;
use addon\zhjw\app\model\students\Students;
use addon\zhjw\app\model\timetables\Timetables;
use addon\zhjw\app\model\venues\Venues;
use addon\zhjw\app\model\zhjw_students_survey\ZhjwStudentsSurvey;
use app\dict\sys\AppTypeDict;
use app\model\member\Contact;
use app\model\member\Member;
use app\model\member\Sktj;
use app\model\member\StaffClocking;
use app\model\member\StaffMessage;
use app\model\member\Task;
use app\service\core\member\CoreMemberService;
use core\base\BaseApiService;
use core\exception\ApiException;
use core\util\Barcode;
use core\util\TokenAuth;
use DateTime;
use think\facade\Db;
use think\Model;
/**
* 会员服务层
* Class MemberService
* @package app\service\api\member
*/
class MemberService extends BaseApiService
{
public function __construct()
{
parent::__construct();
$this->model = new Member();
}
/**
* 新增会员
*/
public function add(array $data){
return $this->model->create($data)?->member_id ?? 0;
}
/**
* 更新会员
* @param array $data
* @return true
*/
public function edit(array $data)
{
$member = $this->findMemberInfo(['member_id' => $this->member_id]);
if($member->isEmpty()) throw new ApiException('MEMBER_NOT_EXIST');
$member->allowField(['nickname', 'headimg', 'birthday', 'sex', 'last_visit_time'])->save($data);
return true;
}
/**
* 获取会员信息
* @return array
*/
public function getInfo()
{
$information = [];
$schedules = new Schedules();
$campuses = new Campuses();
$sales = new Sales();
$field = 'member_id, username, member_no, mobile, register_channel, nickname, headimg, member_level, member_label, login_ip, login_type, login_time, create_time, last_visit_time, last_consum_time, sex, status, birthday, point, balance, growth, is_member, member_time, is_del, province_id, city_id, district_id, address, location, money, money_get, wx_openid, weapp_openid, commission, commission_get, commission_cash_outing';
$info = $this->model->where([['member_id', '=', $this->member_id]])
->with(['member_level_name_bind'])
->field($field)
->append(['sex_name'])
->findOrEmpty()->toArray();
$role_id = get_user_type($this->member_id);
$staff = (new Staff())->where(['member_id' => $this->member_id])->find();
$information['member_id'] = $this->member_id;
$information['staff_id'] = $staff['id'];
$information['headimg'] = $staff['header'];
$information['name'] = $staff['name'] ?? '';
$information['gender'] = $staff['gender'];
$information['phone'] = $staff['phone'];
$information['email'] = $staff['email'];
$information['birthday'] = $info['birthday'];
$information['campuses_id'] = $staff['campuses_id'];
$information['campuses_name'] = $campuses->where(['id' => $information['campuses_id']])->value('name');
$information['role_id'] = $role_id;
$information['grade'] = $staff['grade'];
if($role_id == 1){
//教练信息
$information['zsks'] = $schedules->where(['staff_id' => $staff['id']])->count();
$information['zsbj'] = $schedules->where(['staff_id' => $staff['id']])->group("class_id")->count();
$students_ids = $schedules->where(['staff_id' => $staff['id']])->column("students_ids");
$all_ids_string = implode(',', $students_ids);
$all_ids_array = explode(',', $all_ids_string);
$unique_ids = array_unique(array_filter($all_ids_array));
$information['zfzxy'] = count($unique_ids);
$startOfMonth = date('Y-m-01'); // 本月第一天,例如:2025-04-01
$endOfMonth = date('Y-m-t'); // 本月最后一天,例如:2025-04-30
$information['dyzsks'] = $schedules->where(['staff_id' => $staff['id']])->whereBetween('date_time', [$startOfMonth, $endOfMonth])->count();
$students_ids = $schedules->where(['staff_id' => $staff['id']])->whereBetween('date_time', [$startOfMonth, $endOfMonth])->column("students_ids");
$all_ids_string = implode(',', $students_ids);
$all_ids_array = explode(',', $all_ids_string);
$unique_ids = array_unique(array_filter($all_ids_array));
$information['dyzfzxy'] = count($unique_ids);
}
if($role_id == 2){
//销售信息
$information['yjds'] = $sales->where(['add_staff_id' => $staff['id']])->count();
$information['yqds'] = $sales->where(['add_staff_id' => $staff['id'],'is_status' => 2])->count();
$information['goal'] = get_goal_price($staff['id']);
}
if($role_id == 3){
//学员信息
$data = (new Students())->where(['user_id' => $staff['id']])->find();
$information['height'] = $data['height'];
$information['weight'] = $data['weight'];
$information['score'] = $data['score'];
$information['students_id'] = $data['id'];
$information['evaluation_time'] = $data['evaluation_time'];
// $info['name'] = $data['name'] ?? '';
//课程
$classes = new Classes();
$classes_list = $classes
->alias("a")
->join(['school_venues' => 'b'],'a.venue_id = b.id','left')
->join(['school_timetables' => 'c'],'a.id = c.class_id','left')
->join(['school_courses' => 'd'],'c.courses_id = d.id','left')
->whereRaw("FIND_IN_SET(?, a.max_students)", [$information['students_id']])
->group("d.id")
->column("d.name");
$information['classes_list'] = implode(",", $classes_list);
$information['classes_count'] = count($classes_list);
//总课时数
$duration_count = $classes
->alias("a")
->join(['school_venues' => 'b'],'a.venue_id = b.id','left')
->join(['school_timetables' => 'c'],'a.id = c.class_id','left')
->join(['school_courses' => 'd'],'c.courses_id = d.id','left')
->whereRaw("FIND_IN_SET(?, a.max_students)", [$information['students_id']])
->group("d.id")
->sum("d.duration");
$sign_count = Db::name("zhjw_students_sign")->where(['students_id' => $information['students_id']])->sum("hour");
$information['sign_count'] = $sign_count;
$information['stay_sign_count'] = $duration_count - $sign_count;
}
if(isset($information['headimg'])){
$information['headimg'] = "upload/attachment/image/202503/06/1741237826ea1dfb759edf0147ec8ad6fe8fb36c24_local.png";
}
return $information;
}
/**
* 检测会员信息是否存在
* @return int
*/
public function getCount($condition)
{
return $this->model->where($condition)->count();
}
/**
* 会员中心信息
*/
public function center()
{
$field = 'member_id, username, member_no, mobile, register_channel, nickname, headimg, member_level, member_label, login_ip, login_type, login_time, create_time, last_visit_time, last_consum_time, sex, status, birthday, point, balance, growth, is_member, member_time, is_del, province_id, city_id, district_id, address, location, money, money_get, commission, commission_get, commission_cash_outing';
return $this->model->where([['member_id', '=', $this->member_id]])->field($field)->append(['sex_name'])->findOrEmpty()->toArray();
}
/**
* 获取会员的模型对象(todo 慎用!!! 现主要用于登录)
* @param array $data
* @return Member|array|mixed|Model !!! 仔细看,返回值是模型对象 如果想要判断是否为空 请用 $member->isEmpty()
*/
public function findMemberInfo(array $data){
//会员账号
if(!empty($data['username']))
$where[] = ['username', '=', $data['username']];
//会员手机号
if(!empty($data['mobile']))
$where[] = ['mobile', '=', $data['mobile']];
//会员id
if(!empty($data['member_id']))
$where[] = ['member_id', '=', $data['member_id']];
//微信公众号openid
if(!empty($data['wx_openid']))
$where[] = ['wx_openid', '=', $data['wx_openid']];
//微信小程序openid
if(!empty($data['weapp_openid']))
$where[] = ['weapp_openid', '=', $data['weapp_openid']];
// 微信unionid
if(!empty($data['wx_unionid']))
$where[] = ['wx_unionid', '=', $data['wx_unionid']];
if(!empty($data['username|mobile']))
$where[] = ['username|mobile', '=', $data['username|mobile']];
if(empty($where)){
$where[] = ['member_id', '=', -1];
}
return $this->model->where($where)->findOrEmpty();
}
/**
* 通过对象修改会员信息
* @param $member
* @param $data
* @return void
*/
public function editByFind($member, $data){
return $member->save($data);
}
/**
* 修改字段
* @param string $field
* @param $data
* @return null
*/
public function modify(string $field, $data)
{
return (new CoreMemberService())->modify($this->member_id, $field, $data);
}
public function getQrcode(){
// 生成会员二维码
$qrcode_dir = 'upload/member/temp';
if (!is_dir($qrcode_dir)) mkdir($qrcode_dir, intval('0755', 8), true);
$id = "member-".$this->member_id;
$qrcode_path = "{$qrcode_dir}/order_qrcode_{$this->member_id}.png";
\core\util\QRcode::png($id, $qrcode_path, 'L', 16, 1);
// 生成会员条形码
$barcode_path = (new Barcode(14, $id))->generateBarcode($qrcode_dir, 2);
$detail = [];
$detail['verify_code_qrcode'] = image_to_base64($qrcode_path, true);
$detail['verify_code_barcode'] = image_to_base64($barcode_path);
return $detail;
}
/**
* 初始化会员数据
*/
public function initMemberData(){
if ($this->member_id) {
event("MemberLoginAfter", ['member_id' => $this->member_id]);
}
}
public function is_pass($data){
$password = $this->model->where([['member_id', '=', $this->member_id]])->value("password");
if (!check_password($data['password'], $password)){
return fail("密码不正确");
}
return success("密码正确");
}
public function set_pass($data){
if($data['old_password'] != $data['password']){
return fail("两次密码输入不一致");
}
$password_hash = create_password($data['password']);
$data = array(
'password' => $password_hash,
);
$member_info = $this->findMemberInfo([ 'member_id' => $this->member_id ]);
$this->editByFind($member_info, $data);
TokenAuth::clearToken($this->member_id, AppTypeDict::API, $this->request->apiToken());
return success("修改密码成功");
}
public function get_venues_ids($data){
$member_info = $this->getInfo();
$classes = new Classes();
$venue_ids = $classes
->alias("a")
->join(['school_venues' => 'b'],'a.venue_id = b.id','left')
->join(['school_timetables' => 'c'],'a.id = c.class_id','left')
->join(['school_courses' => 'd'],'c.courses_id = d.id','left')
->where('a.status','<',3)
->group("a.venue_id")
->column("a.venue_id");
return $venue_ids;
}
public function venues_list($data){
$member_info = $this->getInfo();
$venues = new Venues();
$ids = $this->get_venues_ids($data);
$list = $venues->where('id','in',$ids)->select()->toArray();
return $list;
}
public function jl_index(){
$member_info = $this->getInfo();
$schedules = new Schedules();
$task = new Task();
$assignments = new Assignments();
$course_list = $schedules
->alias("a")
->join(['school_classes' => 'b'],'a.class_id = b.id','left')
->join(['school_venues' => 'c'],'b.venue_id = c.id','left')
->join(['school_courses' => 'd'],'a.courses_id = d.id','left')
->where([
['a.staff_id','=',$member_info['staff_id']],
['a.status','<',3]
])
->field("a.id,a.status,d.name as courses_name,a.date_time,a.time_slot,c.address,a.students_ids")
->limit(2)
->select();
if($course_list){
$course_list = $course_list->toArray();
foreach ($course_list as $k=>$v){
$course_list[$k]['students_count'] = count(explode(",",$v['students_ids']));
$course_list[$k]['sign_count'] = Db::name("zhjw_students_sign")->where(['schedules_id' => $v['id']])->count();
}
}
//作业列表
$task_list = $task
->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.id,a.student_count,a.wc_count,c.name as courses_name,b.name as class_name,a.send_time")
->limit(3)
->order("a.send_time desc")
->select();
if($task_list){
$task_list = $task_list->toArray();
foreach ($task_list as $k=>$v){
$task_list[$k]['rate'] = ($v['wc_count'] / $v['student_count']) * 100;
$task_list[$k]['dpg_count'] = $assignments->where(['task_id' => $v['id'],'status' => 2])->count();
}
}
return ['course_list' => $course_list,'task_list' => $task_list];
}
public function get_assignments_list(){
$assignments = new Assignments();
$task = new Task();
$member_info = $this->getInfo();
$search_model = $task
->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.id,a.student_count,a.wc_count,c.name as courses_name,b.name as class_name,a.send_time")
->order("a.send_time desc");
$list = $this->pageQuery($search_model, function ($item) use($assignments){
$item['rate'] = ($item['wc_count'] / $item['student_count']) * 100;
$item['dpg_count'] = $assignments->where(['task_id' => $item['id'],'status' => 2])->count();
});
return $list;
}
//课程列表
public function course_list($data){
$member_info = $this->getInfo();
$venues = new Venues();
$classes = new Classes();
$schedules = new Schedules();
$where = [];
if($data['venue_id']){
$venue_id = $data['venue_id'];
$where['c.id'] = $venue_id;
}
else{
$venue_id = '';
// $venue_id = $this->get_venues_ids($data)[0];
// $where['c.id'] = $venue_id;
}
if($data['courses_id']){
$where['d.id'] = $data['courses_id'];
}
if($member_info['role_id'] == 3){
$schedules = $schedules->whereRaw("FIND_IN_SET(?, a.students_ids)", [$member_info['students_id']]);
}
if($member_info['role_id'] == 1){
//教练
$schedules = $schedules->where(['a.staff_id' => $member_info['staff_id']]);
}
if($data['schedule_date']){
$where['a.date_time'] = $data['schedule_date'];
}
if($data['class_id']){
$where['a.class_id'] = $data['class_id'];
}
$search_model = $schedules
->alias("a")
->join(['school_classes' => 'b'],'a.class_id = b.id','left')
->join(['school_venues' => 'c'],'b.venue_id = c.id','left')
->join(['school_courses' => 'd'],'a.courses_id = d.id','left')
->where($where)
->where([
['a.status','<',3]
])
->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")
->order("a.time_slot asc");
$list = $this->pageQuery($search_model, function ($item) use($member_info){
// $where['a.students_id'] = $member_info['students_id'];
$where['a.courses_id'] = $item['courses_id'];
$where['a.schedules_id'] = $item['id'];
$item['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)
->where(['a.status' => 1])
->order('a.create_time desc')
->field("a.*,c.header")
->limit(7)
->select();
$has_sign = Db::name("zhjw_students_sign")->where(['courses_id' => $item['courses_id']])->count();
$dkv = ($has_sign / $item['max_students']) * 100;
$item['dkv'] = $dkv;
$item['has_sign_count'] = $has_sign;
$item['leave_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)
->where(['a.status' => 2])
->order('a.create_time desc')
->field("a.*,c.header")
->limit(7)
->select();
$time = explode(",",$item['time_slot']);
$item['date'] = $item['date_time'].' '.$time[0].' - '.$time[1];
});
if($venue_id){
$info = $venues->where('id','=',$venue_id)->find()->toArray();
}else{
$info = [];
}
return ['list' => $list,'venues_info' => $info];
}
public function course_info($data){
$schedules = new Schedules();
$assignments = new Assignments();
$where = [];
$where['a.id'] = $data['id'];
$info = $schedules
->alias("a")
->join(['school_classes' => 'b'],'a.class_id = b.id','left')
->join(['school_venues' => 'c'],'b.venue_id = c.id','left')
->join(['school_courses' => 'd'],'a.courses_id = d.id','left')
->join(['school_staff' => 'e'],'a.staff_id = e.id','left')
->where($where)
->field("
a.id,b.name as classes_name,a.date_time,a.time_slot,c.name as address,
d.name as courses_name,
d.id as courses_id,a.class_id,LENGTH(b.max_students) - LENGTH(REPLACE(b.max_students, ',', '')) + 1 as students_count,
b.max_students,e.name as staff_name,e.phone as staff_phone
")
->find()->toArray();
$time = explode(",",$info['time_slot']);
$startTime = strtotime($time[0]);
$endTime = strtotime($time[1]);
$diffInSeconds = $endTime - $startTime;
$diffInHours = $diffInSeconds / 3600;
$info['hour'] = $diffInHours;
$dyTime = strtotime(date("H:i"));
if($dyTime > $startTime){
$info['status'] = 2;
}else{
$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(['a.schedules_id' => $data['id']])
->order('a.create_time desc')
->field("a.*,c.name,c.header")
->select();
//作业情况
$info['assignments'] = [];
$ass_where = [];
$ass_where[] = ['a.courses_id','=',$info['courses_id']];
$ass_where[] = ['a.class_id','=',$info['class_id']];
$startTime = strtotime($info['date_time'].' 00:00:00');
$endTime = strtotime($info['date_time'].' 23:59:59');
$ass_where[] = ['a.create_time','>=',$startTime];
$ass_where[] = ['a.create_time','<=',$endTime];
$status_map = [
2 => 'dpg_list', // 待批改
1 => 'wtj_list', // 未提交
3 => 'ypg_list' // 已批改
];
foreach ($status_map as $status => $key) {
$info['assignments'][$key] = $assignments
->alias("a")
->join(['school_zhjw_students' => 'b'],'a.student_id = b.id','left')
->join(['school_staff' => 'c'],'b.user_id = c.id','left')
->where($ass_where)
->where(['a.status' => $status])
->field("a.id,a.tj_time,c.name,c.header")
->select();
}
return $info;
}
public function getDate()
{
$dates = [];
for ($i = -2; $i <= 4; $i++) {
$date = new DateTime();
$date->modify("$i days");
$dates[] = [
'date' => $date->format('Y-m-d'),
'week' => getChineseWeekday($date),
'status' => 1
];
}
return $dates;
}
public function getMonthDate(array $data)
{
$year = date("Y");
$month = $data['month'];
$daysInMonth = getDaysInMonth($month, $year);
$dates = [];
for ($day = 1; $day <= $daysInMonth; $day++) {
$date = DateTime::createFromFormat('Y-n-j', "$year-$month-$day");
$dates[] = [
'date' => $date->format('Y-m-d'),
'status' => 1
];
}
return $dates;
}
public function students_sign_list(){
$member_info = $this->getInfo();
$where['a.students_id'] = $member_info['students_id'];
$where['a.status'] = 1;
$search_model = Db::name("zhjw_students_sign")
->alias("a")
->join(['school_courses' =>'b'],'a.courses_id = b.id','left')
->where($where)
->field("a.*,b.name")
->order('a.create_time desc');
return $this->pageQuery($search_model);
}
public function set_feedback($data){
$member_info = $this->getInfo();
Db::name("feedback")->insert([
'staff_id' => $member_info['staff_id'],
'content' => $data['content'],
'images' => $data['images'],
'mailbox' => $data['mailbox'],
'create_time' => date("Y-m-d H:i:s", time()),
]);
return true;
}
public function index(){
$venues = new Venues();
$classes = new Classes();
$survey = new ZhjwStudentsSurvey();
$schedules = new Schedules();
$data = [];
$member_info = $this->getInfo();
$data['name'] = $member_info['name'];
$data['headimg'] = $member_info['headimg'];
$data['students_id'] = $member_info['students_id'];
$data['tx'] = $survey->where(['students_id' => $member_info['students_id']])->field('height,weight,score,create_time')->findOrEmpty();
$data['kcyg'] = $schedules
->alias("a")
->join(['school_classes' => 'b'],'a.class_id = b.id','left')
->join(['school_venues' => 'c'],'b.venue_id = c.id','left')
->join(['school_courses' => 'd'],'a.courses_id = d.id','left')
->join(['school_staff' => 'e'],'a.staff_id = e.id','left')
->whereRaw("FIND_IN_SET(?, a.students_ids)", [$member_info['students_id']])
->where(['date_time' => date("Y-m-d")])
->field("
a.id,
a.date_time,
a.time_slot,
c.name as address,
d.name as courses_name
")
->find()->toArray();
if (!empty($data['kcyg']['date_time'])) {
$dt = new DateTime($data['kcyg']['date_time']);
// 格式化成 月/日
$data['kcyg']['date_md'] = $dt->format('m/d');
// 获取周几(中文)
$weekDays = ['周日','周一','周二','周三','周四','周五','周六'];
$data['kcyg']['weekday'] = $weekDays[$dt->format('w')];
}
return $data;
}
public function assignments_list($data){
$member_info = $this->getInfo();
$where = [];
$where['a.student_id'] = $member_info['students_id'];
if($data['status']){
$where['a.status'] = $data['status'];
}
$search_model = (new Assignments())
->alias("a")
->join(['school_staff' => 'b'],'a.staff_id = b.id','left')
->join(['school_zhjw_students' => 'c'],'a.student_id = c.id','left')
->join(['school_staff' => 'd'],'c.user_id = d.id','left')
->where($where)
->field("a.*,b.name as coach_name,b.header as coach_pic,d.name as xy_name,d.header")
->order('a.create_time asc');
return $this->pageQuery($search_model);
}
public function assignments_info($data){
$member_info = $this->getInfo();
$info = (new Assignments())
->alias("a")
->join(['school_staff' => 'b'],'a.staff_id = b.id','left')
->where(['a.id' => $data['id']])
->field("a.*,b.name as coach_name,b.header as coach_pic")
->find();
return $info ? $info->toArray() : [];
}
public function assignments_submit($data){
$assignments = new Assignments();
$task = new Task();
$member_info = $this->getInfo();
$assignments
->where(['student_id' => $member_info['students_id'],'id' => $data['id']])
->update([
'status' => 2,
'student_file' => $data['student_file'],
'student_file_type' => $data['student_file_type'],
'student_content' => $data['student_content'],
'tj_time' => date("Y-m-d H:i:s", time())
]);
$task_id = $assignments->where(['student_id' => $member_info['students_id'],'id' => $data['id']])->value('task_id');
$task->where(['id' => $task_id])->inc('wc_count',1)->update();
return true;
}
public function member_edit($data){
$staff = new Staff();
$member = new Member();
$member_info = $this->getInfo();
$staff_data = [
'header' => $data['header'],
'name' => $data['name'],
'gender' => $data['gender'],
'phone' => $data['phone'],
'email' => $data['email']
];
$staff->where(['id' => $member_info['staff_id']])->update($staff_data);
$member_data = [
// 'username' => $data['username'],
'address' => $data['address'],
'birthday' => $data['birthday']
];
$member->where(['member_id' => $member_info['member_id']])->update($member_data);
return "修改成功";
}
public function ask_for_leave(array $data){
$member_info = $this->getInfo();
$where['students_id'] = $member_info['students_id'];
$where['schedules_id'] = $data['schedules_id'];
$where['courses_id'] = $data['courses_id'];
$info = Db::name("zhjw_students_sign")->where($where)->find();
if($info){
Db::name("zhjw_students_sign")->where($where)->update([
'reason' => $data['reason'],
'file_url' => $data['file_url'],
'status' => 2,
'hour' => 0,
'create_time' => date("Y-m-d H:i:s", time())
]);
}else{
Db::name("zhjw_students_sign")->insert([
'students_id' => $member_info['students_id'],
'schedules_id' => $data['schedules_id'],
'courses_id' => $data['courses_id'],
'reason' => $data['reason'],
'file_url' => $data['file_url'],
'status' => 2,
'hour' => 0,
'create_time' => date("Y-m-d H:i:s", time())
]);
}
return "操作成功";
}
public function del_ask_for_leave(array $data){
$member_info = $this->getInfo();
$where['students_id'] = $member_info['students_id'];
$where['schedules_id'] = $data['schedules_id'];
$where['courses_id'] = $data['courses_id'];
Db::name("zhjw_students_sign")->where($where)->delete();
return "操作成功";
}
public function publish_job(array $data){
$classes = new Classes();
$task = new Task();
$member_info = $this->getInfo();
$students_ids = [];
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']);
}
$task_id = $task->insert([
'staff_id' => $member_info['staff_id'],
'class_id' => $data['classes_id'],
'courses_id' => $data['courses_id'],
'student_count' => count($students_ids),
'send_time' => date("Y-m-d H:i:s", time())
]);
$insert['task_id'] = $task_id;
$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(!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 student_list(){
$student = new Students();
$student_list = $student->select();
return $student_list ? $student_list->toArray() : [];
}
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 set_sales(array $data){
$member_info = $this->getInfo();
$sales = new Sales();
$follow_up_logs = new FollowUpLogs();
$follow_up_reminders = new FollowUpReminders();
if(!$data['staff_id']){
$data['is_gh'] = 1;
}
$sales_id = $sales->insertGetId([
'title' => $data['title'],
'courses_id' => $data['courses_id'],
'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' => $member_info['staff_id'],
'get_staff_id' => $data['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'],
'is_gh' => $data['is_gh'],
// 'customer_tags' => implode(",",$data['customer_tags']),
'create_time' => time(),
'update_time' => time(),
]);
if($data['is_follow'] == 1){
$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()
]);
$follow_up_reminders->insertGetId([
'follow_up_logs_id' => $logs_id,
'reminder_time' => $data['follow_up_time'],
'reminder_method' => 3,
'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'],
'entry_type' => $data['entry_type'],
'staff_id' => $data['staff_id'],
'follow_up_time' =>$data['follow_up_time'],
'requirement' => $data['requirement'],
'purchasing_power' => $data['purchasing_power'],
'cognitive_concept' => $data['cognitive_concept'],
'schooltime' => $data['schooltime'],
'distance' => $data['distance'],
'decision_maker' => $data['decision_maker'],
'emotional_intensity' => $data['emotional_intensity'],
'initial_customer_intent' => $data['initial_customer_intent'],
'initial_relationship_intent' => $data['initial_relationship_intent'],
'follow_up_content' => $data['follow_up_content'],
'role_id' => get_role_id($data['staff_id']),
'create_time' => time()
]);
if($data['is_warn'] == 1){
$follow_up_reminders->insertGetId([
'follow_up_logs_id' => $logs_id,
'follow_staff_id' => $data['follow_staff_id'],
'follow_content' => $data['follow_content'],
'reminder_time' => $data['reminder_time'],
'reminder_method' => '3',
'task_status' => 1,
'create_time' => time()
]);
}
return "添加成功";
}
public function sales_list(){
$sales = new Sales();
return $sales->order("id desc")->select()->toArray();
// 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()
// ]);
$follow_up_reminders->insertGetId([
'follow_staff_id' => $data['follow_staff_id'],
'follow_content' => $data['follow_content'],
'reminder_time' => $data['reminder_time'],
'reminder_method' => '3',
'task_status' => 1,
'create_time' => time()
]);
return "添加成功";
}
public function my_client(array $data){
$member_info = $this->getInfo();
$sales = new Sales();
$where = [];
$count = [];
$where[] = ['is_gh','=',$data['is_gh']];
$seven_days_ago = date('Y-m-d H:i:s', strtotime('-7 days'));
$seven_days_ago_30 = date('Y-m-d H:i:s', strtotime('-30 days'));
$seven_days_ago_21 = date('Y-m-d H:i:s', strtotime('-21 days'));
$seven_days_ago_60 = date('Y-m-d H:i:s', strtotime('-60 days'));
$count[0] = $sales->where($where)->count();
$count[1] = $sales->where($where)->where([
['is_status','=',1]
])->count();
$count[2] = $sales->where($where)->where([
['follow_up_time','<',$seven_days_ago]
])->count();
$count[3] = $sales->where($where)->where([
['follow_up_time','<',$seven_days_ago_30],
['is_status','=',1]
])->count();
$count[4] = $sales->where($where)->where([
['follow_up_time','<',$seven_days_ago_21]
])->count();
$count[5] = $sales->where($where)->where([
['follow_up_time','<',$seven_days_ago_60]
])->count();
if($data['type'] == 1){
$where[] = ['is_status','=',1];
}
if($data['type'] == 2){
$where[] = ['follow_up_time','<',$seven_days_ago];
}
if($data['type'] == 3){
$where[] = ['follow_up_time','<',$seven_days_ago_30];
$where[] = ['is_status','=',1];
}
if($data['type'] == 4){
$where[] = ['follow_up_time','<',$seven_days_ago_21];
}
if($data['type'] == 5){
$where[] = ['follow_up_time','<',$seven_days_ago_60];
}
//今日代领
$gh['max_count'] = Db::name("zhjw_setting")->where(['field'=>'max_get_num'])->value("value");
$gh['lq_count'] = Db::name("zhjw_sales_get")->where([
['staff_id','=',$member_info['staff_id']]
])->whereDay('create_time')->count();
$search_model = $sales->where($where)->order("id desc");
$list = $this->pageQuery($search_model, function ($item, $key) {
$follow_up_logs = new FollowUpLogs();
$member = new Member();
$staff = new Staff();
$follow = $follow_up_logs->where(['sales_id' => $item['id']])->order("id desc")->find();
$item['follow'] = $follow;
$item['hair_staff_id'] = $staff->where(['member_id' => $item['user_id']])->value("id");
});
return ['count' => $count,'gh' => $gh, 'list' => $list];
}
public function client_list(array $data){
$member_info = $this->getInfo();
$sales = new Sales();
$where = [];
if($data['student_name']){
$where[] = ['a.student_name','=',$data['student_name']];
}
$search_model = $sales
->alias("a")
->join(['school_member' => 'b'],'a.user_id = b.member_id','left')
->join(['school_staff' => 'c'],'c.member_id = b.member_id','left')
->where($where)
->field("a.*,c.id as hair_staff_id")
->order("a.id desc")->select();
return $search_model ? $search_model->toArray() : [];
}
public function client_info(array $data){
$sales = new Sales();
$follow_up_logs = new FollowUpLogs();
$staff = new Staff();
$info = $sales
->where(['id' => $data['id']])
->field([
'id',
'student_name',
'student_phone',
'is_zdgz',
'source_channel',
'customer_source',
'age',
'sex'
])
->find();
// dump($info);die;
if($info){
$sex_arr = [0=>'保密',1=>'男',2 => '女'];
$info['source_channel'] = get_gict_value('source_channel',$info['source_channel']);
$info['customer_source'] = get_gict_value('customer_source',$info['customer_source']);
$info['sex'] = $sex_arr[$info['sex']];
$info['follow'] = $follow_up_logs
->where(['sales_id' => $info['id']])
->field([
'follow_up_time',
'initial_customer_intent',
])
->order("id desc")
->find();
if(!$info['follow']){
$info['follow'] = [
'follow_up_time' => '',
'initial_customer_intent' => ''
];
}
$info['gw'] = $staff->where(['id' => $info['get_staff_id']])->value("name");
$info['cj_count'] = $sales->where(['user_id' => $info['user_id'],'is_status' => 2])->count();
$info['ty_count'] = $sales->where(['user_id' => $info['user_id'],'is_status' => 1])->count();
}
return $info->toArray();
}
public function follow_list(array $data){
$follow_up_logs = new FollowUpLogs();
$list = $follow_up_logs
->alias("a")
->join(['school_zhjw_sales' => 'b'],'b.id = a.sales_id','left')
->where(['a.sales_id' => $data['sales_id']])
->field("a.*,b.student_name,b.student_phone")
->order("a.id desc")
->select();
return $list->toArray();
}
public function staff_list(array $data){
$where = [];
if($data['type']){
$where[] = ['type','=',$data['type']];
}
if($data['role_id']){
$where[] = ['role_id','=',$data['role_id']];
}
$staff = new Staff();
$list = $staff
->where($where)
->order("id desc")->select();
return $list->toArray();
}
public function set_call_up(array $data){
$member_info = $this->getInfo();
Db::name("zhjw_sales_phone")->insert([
'staff_id' => $member_info['staff_id'],
'sales_id' => $data['sales_id'],
'create_time' => date("Y-m-d H:i:s")
]);
return true;
}
public function list_call_up(array $data){
$list = Db::name("zhjw_sales_phone")
->alias("a")
->join(['school_zhjw_sales' => 'b'],'a.sales_id = b.id','left')
->join(['school_staff' => 'c'],'a.staff_id = c.id','left')
->where(['a.sales_id' => $data['sales_id']])
->field("a.id,b.student_name,b.student_phone,c.name,a.create_time")
->order("a.id desc")->select();
return $list->toArray();
}
public function with_sales_list(array $data){
$sales = new Sales();
$where = [];
$where[] = ['is_status','=',2];
if($data['sales_id']){
$info = $sales->where(['id' => $data['sales_id']])->find();
if($data['type'] == 1){
$where[] = ['campuses_id','=',$info['campuses_id']];
}
if($data['type'] == 2){
$where[] = ['class_id','=',$info['class_id']];
}
if($data['type'] == 3){
$where[] = ['community_name','=',$info['community_name']];
}
}
$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;
});
}
public function get_sales(array $data){
$sales = new Sales();
$member_info = $this->getInfo();
Db::name("zhjw_sales_get")->insert([
'staff_id' => $member_info['staff_id'],
'sales_id' => $data['sales_id'],
'create_time' => date("Y-m-d H:i:s")
]);
$sales->where(['id' => $data['sales_id']])->update([
'is_gh' => 2,
'get_staff_id' => $member_info['staff_id']
]);
return true;
}
public function get_enterprise_information(){
$enterprise_information = new EnterpriseInformation();
$member_info = $this->getInfo();
$info = $enterprise_information->where(['campuses_id' => $member_info['campuses_id']])->find();
return $info ? $info->toArray() : [];
}
public function contact_list(){
$member_info = $this->getInfo();
$staff = new Staff();
$contact = new Contact();
$list = $contact
->where(['closed_staff_id' => $member_info['staff_id']])
->order("type asc,id desc")
->select();
if(!empty($list)){
$list = $list->toArray();
foreach ($list as $k=>$v){
$count = Db::name("staff_message")->where(['hair_staff_id' => $v['hair_staff_id'],'closed_staff_id' => $member_info['staff_id'],'status' => 2])->count();
if($v['type'] == 1){
$list[$k]['name'] = "系统消息";
$list[$k]['header'] = "";
}else{
$list[$k]['name'] = $staff->where(['id' => $v['hair_staff_id']])->value('name');
$list[$k]['header'] = $staff->where(['id' => $v['hair_staff_id']])->value('header');
}
$list[$k]['count'] = $count;
}
}
return $list;
}
public function send_message(array $data){
$member_info = $this->getInfo();
$staffMessage = new StaffMessage();
$contact = new Contact();
$is_friends = $contact->where(['hair_staff_id' => $member_info['staff_id'],'closed_staff_id' => $data['hair_staff_id']])->find();
if(!$is_friends){
$contact->insert([
'hair_staff_id' => $member_info['staff_id'],
'closed_staff_id' => $data['hair_staff_id'],
'create_time' => date('Y-m-d H:i:s')
]);
$contact->insert([
'hair_staff_id' => $data['hair_staff_id'],
'closed_staff_id' => $member_info['staff_id'],
'create_time' => date('Y-m-d H:i:s')
]);
}
$staffMessage->insert([
'hair_staff_id' => $data['hair_staff_id'],
'closed_staff_id' => $member_info['staff_id'],
'content' => $data['content'],
'create_time' => date("Y-m-d H:i:s")
]);
return true;
}
public function contact_message(array $data){
$member_info = $this->getInfo();
$staffMessage = new StaffMessage();
$staffMessage
->where(['hair_staff_id' => $data['hair_staff_id'],'closed_staff_id' => $member_info['staff_id'],'status' => 2])
->update(['status' => 1]);
$search_model = $staffMessage
->where(function ($query) use ($member_info, $data) {
$query->where([
['closed_staff_id', '=', $member_info['staff_id']],
['hair_staff_id', '=', $data['hair_staff_id']]
])->whereOr(function ($query) use ($member_info, $data) {
$query->where([
['closed_staff_id', '=', $data['hair_staff_id']],
['hair_staff_id', '=', $member_info['staff_id']]
]);
});
})
->order("id asc");
$search_model = $this->pageQuery($search_model, function ($item, $key) use ($member_info, &$last_time, &$last_sender) {
// 方向判断
if ($member_info['staff_id'] == $item['closed_staff_id']) {
$item['direction'] = "right";
} else {
$item['direction'] = "left";
}
// 处理时间显示(5 分钟内不重复)
$current_time = strtotime($item['create_time']); // 假设 created_at 字段是消息时间
if (!isset($last_time) || ($current_time - $last_time >= 300)) {
$item['show_time'] = date("Y-m-d H:i", $current_time); // 显示时间
} else {
$item['show_time'] = ""; // 5分钟内隐藏时间
}
// 更新上一次的时间和发送者
$last_time = $current_time;
});
return $search_model;
}
public function sign_client(){
$member_info = $this->getInfo();
$sales = new Sales();
$zhjw_contracts = new Contracts();
$where = [];
$where[] = ['a.is_status','=',2];
$where[] = ['a.add_staff_id','=',$member_info['staff_id']];
$search_model = $sales
->alias('a')
->join(['school_member' => 'b'],'a.user_id = b.member_id','left')
->join(['school_staff' => 'c'],'b.member_id = c.member_id','left')
->join(['school_zhjw_students' => 'd'],'d.user_id = c.id','left')
->where($where)
->group("a.id")
->field("c.id,c.name,c.header,d.have_study_time,d.end_study_time,d.id as students_id,a.id as sales_id")
->order("a.id desc");
return $this->pageQuery($search_model, function ($item, $key) use ($zhjw_contracts) {
$end_time = $zhjw_contracts->where(['student_id' => $item['students_id']])->order("end_date desc")->value('end_date');
$item['end_time'] = $end_time;
});
}
public function survey_list(array $data){
$survey = new ZhjwStudentsSurvey();
$search_model = $survey
->alias('a')
->where(['a.students_id' => $data['students_id']])
->order("a.id desc");
$list = $this->pageQuery($search_model, function ($item, $key){
});
return ['standard' => standard(),'list' => $list];
}
public function survey_info(array $data){
$survey = new ZhjwStudentsSurvey();
$info = $survey
->alias('a')
->where(['a.id' => $data['survey_id']])
->find();
$info['standard'] = standard();
return $info->toArray();
}
public function set_comment(array $data){
$assignments = new Assignments();
$assignments->where(['id' => $data['assignments_id']])->update([
'comment' => $data['comment'],
'comment_time' => date("Y-m-d H:i:s"),
'status' => 3
]);
return true;
}
public function class_list(array $data){
$member_info = $this->getInfo();
$schedules = new Schedules();
$students = new Students();
$where = [];
if($data['name']){
$where[] = ['b.name','=',$data['name']];
}
$search_model = $schedules
->alias('a')
->join(['school_classes' => 'b'],'a.class_id = b.id','left')
->where(['a.staff_id' => $member_info['staff_id']])
->where($where)
->field("a.class_id,b.name,b.max_students")
->group("a.class_id");
return $this->pageQuery($search_model, function ($item, $key) use ($students){
$students_list = $students
->alias("a")
->join(['school_staff' => 'b'],'b.id = a.user_id','left')
->where('a.id','in',$item['max_students'])
->field("a.id,b.name,b.header,a.have_study_time,a.end_study_time")
->select();
$count = 0;
foreach ($students_list as $student){
if(($student['have_study_time'] - $student['end_study_time']) <= 2){
$count++;
}
}
$item['students_list'] = $students_list;
$item['students_count'] = count($students_list);
$item['end_count'] = $count;
});
}
public function class_info(array $data){
$member_info = $this->getInfo();
$classes = new Classes();
$students = new Students();
$info = $classes->alias("a")
->join(['school_venues' => 'b'],'a.venue_id = b.id','left')
->where(['a.id' => $data['class_id']])
->field("a.id,a.name,b.address,a.start_date,a.end_date,a.max_students")
->find();
$info['students_count'] = count(explode(",",$info['max_students']));
$students_list = $students
->alias("a")
->join(['school_staff' => 'b'],'b.id = a.user_id','left')
->where('a.id','in',$info['max_students'])
->field("a.id,b.name,b.header,a.have_study_time,a.end_study_time,a.expire_time")
->select();
foreach ($students_list as $key => $student){
$students_list[$key]['expire'] = false;
if(($student['have_study_time'] - $student['end_study_time']) <= 2){
$students_list[$key]['expire'] = true;
}
}
$info['students_list'] = $students_list;
return $info->toArray();
}
public function students_info(array $data){
$students = new Students();
$assignments = new Assignments();
$info = $students
->alias("a")
->join(['school_staff' => 'b'],'b.id = a.user_id','left')
->where('a.id','=',$data['students_id'])
->field("a.id,b.name,b.header,b.phone,a.age,a.have_study_time,a.end_study_time,a.expire_time")
->find();
if($info){
$info['assignments_list'] = $assignments
->alias("a")
->join(['school_courses' => 'b'],'a.courses_id = b.id','left')
->where(['a.student_id' => $data['students_id']])
->field("a.id,a.submit_time,b.name as courses_name,a.status")
->order("a.submit_time desc")
->select();
}
return $info ? $info->toArray() : [];
}
public function students_list(){
$students = new Students();
$now = date('Y-m-d H:i:s');
$twoDaysLater = date('Y-m-d H:i:s', strtotime('+2 days'));
$search_model = $students
->alias("a")
->join(['school_staff' => 'b'], 'b.id = a.user_id', 'left')
->where([
['a.expire_time','<>',''],
['a.expire_time','>=',$now],
['a.expire_time','<=',$twoDaysLater],
])
->field("a.id, b.name, b.header, a.have_study_time, a.end_study_time, a.expire_time");
return $this->pageQuery($search_model, function ($item, $key){
});
}
public function sktj(){
$sktj = new Sktj();
$member_info = $this->getInfo();
$list = $sktj->where(['staff_id' => $member_info['staff_id']])->order("month_date asc")->select();
return $list ? $list->toArray() : [];
}
//销售业绩统计
public function performance(){
$order = new Orders();
$sales = new Sales();
$staff = new Staff();
$member_info = $this->getInfo();
$data['goal'] = $member_info['goal'];
$data['wx_performance'] = $order->where(['staff_id' => $member_info['staff_id']])->Sum("amount");
$data['new_performance'] = $order->where(['staff_id' => $member_info['staff_id'],'type' => 1])->Sum("amount");
$data['renew_performance'] = $order->where(['staff_id' => $member_info['staff_id'],'type' => 2])->Sum("amount");
$sales_count = $sales->where(['get_staff_id' => $member_info['staff_id']])->count();
$renew_count = $sales->where(['get_staff_id' => $member_info['staff_id'],'is_status' => 2])->count();
$st_count = $sales->where(['get_staff_id' => $member_info['staff_id'],'is_status' => 1])->count();
$data['cj_count'] = $renew_count;
$data['cj_lv'] = ($renew_count / $sales_count) * 100;
$data['st_count'] = $st_count;
$data['st_lv'] = ($st_count / $sales_count) * 100;
$gj_count = $sales->where(['get_staff_id' => $member_info['staff_id']])->where('follow_up_time','<>',null)->count();
$data['gj_count'] = $gj_count;
$data['gj_lv'] = ($gj_count / $sales_count) * 100;
$data['staff_list'] = [];
$staff_list = $staff->where(['type' => 2])->select()->toArray();
foreach ($staff_list as $key => $val){
$data['staff_list'][$key]['name'] = $val['name'];
$data['staff_list'][$key]['goal'] = $val['goal'];
$data['staff_list'][$key]['wx_yj'] = $order->where(['staff_id' => $member_info['staff_id']])->Sum("amount");
}
return $data;
}
//销售首页
public function xs_index(){
$order = new Orders();
$sales = new Sales();
$staff = new Staff();
$follow_up_logs = new FollowUpLogs();
$staffMessage = new StaffMessage();
$member_info = $this->getInfo();
$startOfMonth = strtotime(date('Y-m-01 00:00:00')); // 本月第一天 0点
$endOfMonth = strtotime(date('Y-m-t 23:59:59')); // 本月最后一天 23:59:59
$data['goal'] = get_goal_price($member_info['staff_id']);
$data['goal_percent'] = 100;
$data['yc_yj'] = $sales
->alias("a")
->join(['school_zhjw_follow_up_logs' => 'b'],'a.id = b.sales_id','left')
->join(['school_courses' => 'c'],'a.courses_id = c.id','left')
->where(['a.get_staff_id' => $member_info['staff_id']])
->where('a.create_time', '>=', $startOfMonth)
->where('a.create_time', '<=', $endOfMonth)
->where('b.initial_customer_intent','in','A+,A,A-')
->group("a.id")
->Sum("c.price");
$data['yc_yj_percent'] = ($data['yc_yj'] / $data['goal']) * 100;
$data['cj_yj'] = $order
->where(['staff_id' => $member_info['staff_id']])
->where('create_time', '>=', $startOfMonth)
->where('create_time', '<=', $endOfMonth)
->Sum("amount");
$data['cj_yj_percent'] = ($data['cj_yj'] / $data['goal']) * 100;
$sales_list = $sales
->alias("a")
->where(['a.get_staff_id' => $member_info['staff_id']])
->select();
$data['dlx'] = 0;
foreach ($sales_list as $key=>$val){
$is_log = $follow_up_logs->where(['sales_id' => $val['id']])->find();
if(!$is_log){
$data['dlx']++;
}
}
$data['dlq'] = $sales->where(['is_gh' => 2])->count();
$data['dsf'] = $follow_up_logs->where(['staff_id' => $member_info['staff_id']])->where('follow_up_time','<',date("Y-m-d H:i:s"))->count();
$data['dxz'] = $follow_up_logs
->alias("a")
->join(['school_zhjw_sales' => 'b'],'a.sales_id = b.id','left')
->where(['staff_id' => $member_info['staff_id']])
->where('get_staff_id','<>',$member_info['staff_id'])
->group("b.id")
->count();
$data['xx'] = $staffMessage->where(['hair_staff_id' => $member_info['staff_id'],'status' => 2])->count();
$data['date'] = date('m月').'01日 - '.date('m月t日');
return $data;
}
public function clocking_list(array $data){
$staffClocking = new StaffClocking();
$member_info = $this->getInfo();
$where = [];
if($data['status']){
$where[] = ['status','=',$data['status']];
}
$search_model = $staffClocking
->where([
['staff_id','=',$member_info['staff_id']],
])
->where($where)
->order("id desc");
return $this->pageQuery($search_model, function ($item, $key){
$courses = new Courses();
$item['courses'] = $courses->where(['id' => $item['courses_id']])->field("name,thumbnail")->find();
});
}
public function clocking_rest(array $data){
$staffClocking = new StaffClocking();
$schedules = new Schedules();
$member_info = $this->getInfo();
// $add_time = $data['date'].' 00:00:00';
// $end_time = $data['date'].' 23:59:59';
$is_clocking = $staffClocking->where([
'staff_id' => $member_info['staff_id'],
'create_time' => $data['date']
])->find();
if($is_clocking){
return "日期考勤已生成,不可请假";
}
if($member_info['role_id'] == 1){
$schedules_list = $schedules->where(['date_time' => $data['date'],'staff_id' => $member_info['staff_id']])->select();
foreach ($schedules_list as $k1=>$v1){
$time_slot = explode(",",$v1['time_slot']);
Db::name("staff_clocking")->insert([
'staff_id' => $member_info['staff_id'],
'status' => 2,
'create_time' => date("Y-m-d"),
'add_time' => $data['date'].' '.$time_slot[0].':00',
'end_time' => $data['date'].' '.$time_slot[1].':00',
'courses_id' => $v1['courses_id'],
'type' => 2
]);
}
}else{
Db::name("staff_clocking")->insert([
'staff_id' => $member_info['staff_id'],
'status' => 2,
'create_time' => date("Y-m-d"),
'add_time' => $data['date'].' 00:00:00',
'end_time' => $data['date'].' 23:59:59',
'type' => 1
]);
}
return "请假成功";
}
public function select_course_list(){
$course = new Courses();
$list = $course->select();
return $list->toArray();
}
public function contracts_list(){
$contracts = new Contracts();
$member_info = $this->getInfo();
$search_model = $contracts
->where([
['student_id','=',$member_info['students_id']],
])
->field("id,title,file_data,signatory_a,signatory_b")
->order("id desc");
return $this->pageQuery($search_model, function ($item, $key){
});
}
}