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.
115 lines
3.2 KiB
115 lines
3.2 KiB
<?php
|
|
// +----------------------------------------------------------------------
|
|
// | Niucloud-admin 企业快速开发的多应用管理平台
|
|
// +----------------------------------------------------------------------
|
|
// | 官方网址:https://www.niucloud.com
|
|
// +----------------------------------------------------------------------
|
|
// | niucloud团队 版权所有 开源版本可自由商用
|
|
// +----------------------------------------------------------------------
|
|
// | Author: Niucloud Team
|
|
// +----------------------------------------------------------------------
|
|
|
|
namespace app\service\admin\student_course_usage;
|
|
|
|
use app\model\student_course_usage\StudentCourseUsage;
|
|
|
|
use core\base\BaseAdminService;
|
|
|
|
|
|
/**
|
|
* 学员课时消费记录服务层
|
|
* Class StudentCourseUsageService
|
|
* @package app\service\admin\student_course_usage
|
|
*/
|
|
class StudentCourseUsageService extends BaseAdminService
|
|
{
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->model = new StudentCourseUsage();
|
|
}
|
|
|
|
/**
|
|
* 获取学员课时消费记录列表
|
|
* @return array
|
|
*/
|
|
public function getPage(array $data = [])
|
|
{
|
|
$where = [];
|
|
if($data['emergency_contact']){
|
|
$where[] = ['c.emergency_contact','like','%'.$data['emergency_contact'].'%'];
|
|
}
|
|
|
|
if($data['student_name']){
|
|
$where[] = ['c.name','like','%'.$data['student_name'].'%'];
|
|
}
|
|
|
|
if($data['contact_phone']){
|
|
$where[] = ['c.contact_phone','=',$data['contact_phone']];
|
|
}
|
|
|
|
$search_model = $this->model
|
|
->alias("a")
|
|
->join(['school_student_courses' => 'b'],'a.student_course_id = b.id','left')
|
|
->join(['school_student' => 'c'],'b.student_id = c.id','left')
|
|
->join(['school_course' => 'd'],'b.course_id = d.id','left')
|
|
->where($where)
|
|
->field("a.*,c.name as student_name,c.emergency_contact,d.course_name,b.total_hours,ROUND(b.total_hours - b.use_total_hours) as sy_time,ROUND(b.gift_hours - b.use_gift_hours) as gift_hours")
|
|
->order("a.id desc");
|
|
$list = $this->pageQuery($search_model);
|
|
return $list;
|
|
}
|
|
|
|
/**
|
|
* 获取学员课时消费记录信息
|
|
* @param int $id
|
|
* @return array
|
|
*/
|
|
public function getInfo(int $id)
|
|
{
|
|
$field = 'id,student_course_id,used_hours,usage_date,created_at,updated_at';
|
|
|
|
$info = $this->model->field($field)->where([['id', "=", $id]])->findOrEmpty()->toArray();
|
|
return $info;
|
|
}
|
|
|
|
/**
|
|
* 添加学员课时消费记录
|
|
* @param array $data
|
|
* @return mixed
|
|
*/
|
|
public function add(array $data)
|
|
{
|
|
$res = $this->model->create($data);
|
|
return $res->id;
|
|
|
|
}
|
|
|
|
/**
|
|
* 学员课时消费记录编辑
|
|
* @param int $id
|
|
* @param array $data
|
|
* @return bool
|
|
*/
|
|
public function edit(int $id, array $data)
|
|
{
|
|
|
|
$this->model->where([['id', '=', $id]])->update($data);
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* 删除学员课时消费记录
|
|
* @param int $id
|
|
* @return bool
|
|
*/
|
|
public function del(int $id)
|
|
{
|
|
$model = $this->model->where([['id', '=', $id]])->find();
|
|
$res = $model->delete();
|
|
return $res;
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|