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.
1073 lines
38 KiB
1073 lines
38 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\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\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 app\dict\sys\AppTypeDict;
|
|
use app\model\member\Member;
|
|
use app\model\member\StaffMessage;
|
|
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()
|
|
{
|
|
$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();
|
|
|
|
|
|
$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['campuses_id'] = $staff['campuses_id'];
|
|
$info['role_id'] = $role_id;
|
|
|
|
if($role_id == 1){
|
|
//学员信息
|
|
$data = (new Students())->where(['user_id' => $staff['id']])->find();
|
|
|
|
|
|
$info['height'] = $data['height'];
|
|
$info['weight'] = $data['weight'];
|
|
$info['score'] = $data['score'];
|
|
$info['students_id'] = $data['id'];
|
|
$info['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)", [$info['students_id']])
|
|
->group("d.id")
|
|
->column("d.name");
|
|
$info['classes_list'] = implode(",", $classes_list);
|
|
|
|
$info['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)", [$info['students_id']])
|
|
->group("d.id")
|
|
->sum("d.duration");
|
|
|
|
$sign_count = Db::name("zhjw_students_sign")->where(['students_id' => $info['students_id']])->sum("hour");
|
|
|
|
$info['sign_count'] = $sign_count;
|
|
|
|
$info['stay_sign_count'] = $duration_count - $sign_count;
|
|
}
|
|
|
|
if(!$info['headimg']){
|
|
$info['headimg'] = "upload/attachment/image/202503/06/1741237826ea1dfb759edf0147ec8ad6fe8fb36c24_local.png";
|
|
}
|
|
|
|
return $info;
|
|
}
|
|
|
|
/**
|
|
* 检测会员信息是否存在
|
|
* @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.start_date', '<=', $data['schedule_date'])
|
|
->where('a.end_date', '>=', $data['schedule_date'])
|
|
->where('a.status','<',3)
|
|
// ->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,
|
|
LENGTH(a.max_students) - LENGTH(REPLACE(a.max_students, ',', '')) + 1 as students_count,d.id as courses_id
|
|
")
|
|
->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 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 = $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'] == 1){
|
|
$schedules = $schedules->whereRaw("FIND_IN_SET(?, b.max_students)", [$member_info['students_id']]);
|
|
}
|
|
$where['a.date_time'] = $data['schedule_date'];
|
|
$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)
|
|
->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){
|
|
// $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)
|
|
->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();
|
|
$item['has_sign_count'] = $has_sign;
|
|
$time = explode(",",$item['time_slot']);
|
|
$item['date'] = $item['date_time'].' '.$time[0].' - '.$time[1];
|
|
});
|
|
|
|
|
|
$info = $venues->where('id','=',$venue_id)->find()->toArray();
|
|
return ['list' => $list,'venues_info' => $info];
|
|
}
|
|
|
|
|
|
public function course_info($data){
|
|
$schedules = new Schedules();
|
|
$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,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($where)
|
|
->order('a.create_time desc')
|
|
->field("a.*,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 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();
|
|
|
|
$data = [];
|
|
$member_info = $this->getInfo();
|
|
$data['info'] = $member_info;
|
|
|
|
|
|
$classes_info = $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)
|
|
->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,
|
|
LENGTH(a.max_students) - LENGTH(REPLACE(a.max_students, ',', '')) + 1 as students_count,d.id as courses_id
|
|
")
|
|
->order("a.end_date desc")
|
|
->group("a.venue_id")
|
|
->find();
|
|
|
|
|
|
|
|
$classes_info['sign_count'] = Db::name("zhjw_students_sign")
|
|
->alias("a")
|
|
->join(['school_member' => 'b'],'a.students_id = b.member_id','left')
|
|
->where(['a.courses_id' => $classes_info['courses_id']])
|
|
->count();
|
|
|
|
$classes_info['my_sign_count'] = Db::name("zhjw_students_sign")
|
|
->alias("a")
|
|
->join(['school_member' => 'b'],'a.students_id = b.member_id','left')
|
|
->where(['a.courses_id' => $classes_info['courses_id'],'a.students_id' => $member_info['students_id']])
|
|
->count();
|
|
|
|
$data['classes_info'] = $classes_info;
|
|
|
|
$assignments = (new Assignments())->where(['student_id' => $member_info['students_id'],'status' => 2])->order('create_time asc')->find();
|
|
$data['assignments'] = $assignments;
|
|
|
|
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')
|
|
->where($where)
|
|
->field("a.*,b.name as coach_name,b.header as coach_pic")
|
|
->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.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;
|
|
}
|
|
|
|
|
|
public function assignments_submit($data){
|
|
$assignments = new Assignments();
|
|
$member_info = $this->getInfo();
|
|
(new 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())
|
|
]);
|
|
|
|
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 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' => implode(",",$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'],
|
|
'follow_up_content' => $data['follow_up_content'],
|
|
'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){
|
|
$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();
|
|
$follow = $follow_up_logs->where(['sales_id' => $item['id']])->order("id desc")->find();
|
|
$item['follow'] = $follow;
|
|
});
|
|
return ['count' => $count,'gh' => $gh, 'list' => $list];
|
|
}
|
|
|
|
|
|
public function client_info(array $data){
|
|
$sales = new Sales();
|
|
$follow_up_logs = new FollowUpLogs();
|
|
$info = $sales->where(['id' => $data['id']])->find();
|
|
if($info){
|
|
$info['follow'] = $follow_up_logs->where(['sales_id' => $info['id']])->order("id desc")->find();
|
|
}
|
|
return $info->toArray();
|
|
}
|
|
|
|
public function follow_list(array $data){
|
|
$follow_up_logs = new FollowUpLogs();
|
|
$list = $follow_up_logs->where(['sales_id' => $data['sales_id']])->order("id desc")->select();
|
|
return $list->toArray();
|
|
}
|
|
|
|
public function staff_list(array $data){
|
|
$where = [];
|
|
if($data['type']){
|
|
$where[] = ['type','=',$data['type']];
|
|
}
|
|
$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();
|
|
$list = Db::name("staff_message")
|
|
->where(['closed_staff_id' => $member_info['staff_id']])
|
|
->order("type asc,id desc")
|
|
->group("hair_staff_id")
|
|
->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 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;
|
|
}
|
|
|
|
|
|
}
|
|
|