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.
113 lines
3.2 KiB
113 lines
3.2 KiB
<?php
|
|
// +----------------------------------------------------------------------
|
|
// | Niucloud-admin 企业快速开发的多应用管理平台
|
|
// +----------------------------------------------------------------------
|
|
// | 官方网址:https://www.niucloud.com
|
|
// +----------------------------------------------------------------------
|
|
// | niucloud团队 版权所有 开源版本可自由商用
|
|
// +----------------------------------------------------------------------
|
|
// | Author: Niucloud Team
|
|
// +----------------------------------------------------------------------
|
|
|
|
namespace app\service\admin\course;
|
|
|
|
use app\model\contract\Contract;
|
|
use app\model\course\Course;
|
|
|
|
use core\base\BaseAdminService;
|
|
|
|
|
|
/**
|
|
* 课程服务层
|
|
* Class CourseService
|
|
* @package app\service\admin\course
|
|
*/
|
|
class CourseService extends BaseAdminService
|
|
{
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->model = new Course();
|
|
}
|
|
|
|
/**
|
|
* 获取课程列表
|
|
* @param array $where
|
|
* @return array
|
|
*/
|
|
public function getPage(array $where = [])
|
|
{
|
|
$field = 'id,course_name,course_type,duration,session_count,contract_id,single_session_count,price,internal_reminder,customer_reminder,remarks,created_at,updated_at,deleted_at';
|
|
$order = 'id desc';
|
|
|
|
$search_model = $this->model->withSearch(["id","course_name","course_type","duration","session_count","single_session_count","price","internal_reminder","customer_reminder","remarks"], $where)->field($field)->order($order);
|
|
$list = $this->pageQuery($search_model);
|
|
return $list;
|
|
}
|
|
|
|
public function contract_all(){
|
|
$contract = new Contract();
|
|
$list = $contract->where(['contract_type' => '外部','contract_status' => '可用'])->select()->toArray();
|
|
return $list;
|
|
}
|
|
|
|
/**
|
|
* 获取课程信息
|
|
* @param int $id
|
|
* @return array
|
|
*/
|
|
public function getInfo(int $id)
|
|
{
|
|
$field = 'id,course_name,course_type,duration,session_count,contract_id,single_session_count,price,internal_reminder,customer_reminder,remarks,created_at,updated_at,deleted_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;
|
|
}
|
|
|
|
/**
|
|
* 获取课程列表
|
|
*/
|
|
public function getAllCourseList($where)
|
|
{
|
|
$field = 'id,course_name';
|
|
$where = array_filter($where);
|
|
return $this->model->where($where)->field($field)->select()->toArray();
|
|
}
|
|
|
|
}
|
|
|