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.
560 lines
20 KiB
560 lines
20 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\classes\Classes;
|
|
use addon\zhjw\app\model\courses\Courses;
|
|
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\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);
|
|
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();
|
|
$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;
|
|
}
|
|
|
|
|
|
$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)
|
|
->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");
|
|
|
|
|
|
$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){
|
|
$member_info = $this->getInfo();
|
|
$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;
|
|
}
|
|
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([
|
|
'students_id' => $member_info['students_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['student_id'] = $member_info['students_id'];
|
|
if($data['status']){
|
|
$where['status'] = $data['status'];
|
|
}
|
|
$search_model = (new Assignments())->where($where)->order('create_time asc');
|
|
return $this->pageQuery($search_model);
|
|
}
|
|
|
|
|
|
public function assignments_info($data){
|
|
$member_info = $this->getInfo();
|
|
$info = (new Assignments())->where(['student_id' => $member_info['students_id'],'id' => $data['id']])->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 "操作成功";
|
|
}
|
|
|
|
|
|
}
|
|
|