139 lines
4.1 KiB
PHP
139 lines
4.1 KiB
PHP
<?php
|
|
|
|
namespace app\admin\controller;
|
|
|
|
use app\common\controller\Backend;
|
|
use app\common\library\DatabaseRoute;
|
|
use ba\Random;
|
|
use think\facade\Db;
|
|
|
|
class Course extends Backend
|
|
{
|
|
protected array $noNeedLogin = ['*'];
|
|
protected array $noNeedPermission = ['statisticsIncomeMoney'];
|
|
|
|
|
|
public function selectCourse()
|
|
{
|
|
$params = $this->request->param();
|
|
$res = \app\api\model\Course::selectCourse($params);
|
|
$this->successWithData($res['data']);
|
|
}
|
|
|
|
public function insertCourse()
|
|
{
|
|
$params = $this->request->post();
|
|
$params = convertKeysCamelToSnakeRecursive($params);
|
|
$params['is_delete'] = 0;
|
|
$params['create_time'] = getNormalDate();
|
|
$params['course_id'] = Random::generateRandomPrefixedId();
|
|
$params['banner_id'] = empty($params['banner_id']) ? null : $params['banner_id'];
|
|
if ($params['course_type'] == 2 || $params['course_type'] == 3) {
|
|
$copy = unserialize(serialize($params));
|
|
unset($copy['remark']);
|
|
$id = Db::name('course')->insert($copy);
|
|
DatabaseRoute::getDb('course_details', $id, true)->insert([
|
|
'course_id' => $id,
|
|
'video_url' => $params['remark'] ?? '',
|
|
'view_count' => 0,
|
|
'play_complete_count' => 0,
|
|
]);
|
|
}else {
|
|
unset($params['remark']);
|
|
$id = Db::name('course')->insert($params);
|
|
}
|
|
|
|
$this->success();
|
|
}
|
|
|
|
public function updateCourse()
|
|
{
|
|
$params = $this->request->post();
|
|
$params = convertKeysCamelToSnakeRecursive($params);
|
|
unset($params['banner_id']);
|
|
Db::name('course')->where([
|
|
'course_id' => $params['course_id']
|
|
])->update($params);
|
|
$this->success();
|
|
}
|
|
|
|
public function selectCourseById()
|
|
{
|
|
$params = $this->request->param();
|
|
$where = [
|
|
'course_id' => $params['id']
|
|
];
|
|
if (!empty($params['good'])) {
|
|
if ($params['good'] == 1) {
|
|
$where['good'] = $params['good'];
|
|
}else{
|
|
$where['good'] = $params['good'];
|
|
}
|
|
}
|
|
$this->successWithData(DatabaseRoute::paginateDb('course_details', function ($query) use($where) {
|
|
$query->where($where);
|
|
return $query->order('sort', false);
|
|
}, $params['page'], $params['limit'], [
|
|
'course_id' => $params['id']
|
|
]));
|
|
|
|
}
|
|
|
|
public function updateDelete()
|
|
{
|
|
$params = $this->request->param();
|
|
Db::name('course')->where([
|
|
'course_id' => $params['id']
|
|
])->delete();
|
|
$this->success();
|
|
}
|
|
|
|
public function updateCourseStatus()
|
|
{
|
|
$params = $this->request->param();
|
|
$params['ids'] = explode(',', $params['ids']);
|
|
foreach ($params['ids'] as $id) {
|
|
Db::name('course')->where([
|
|
'course_id' => $id
|
|
])->update([
|
|
'status' => $params['status']
|
|
]);
|
|
}
|
|
|
|
$this->success();
|
|
}
|
|
|
|
public function updateCourseDetails()
|
|
{
|
|
$param = $this->request->param();
|
|
$param['ids'] = explode(',', $param['ids']);
|
|
foreach ($param['ids'] as $id) {
|
|
DatabaseRoute::getAllDbData('course_details', function ($query) use ($id, $param) {
|
|
return $query->where([
|
|
'course_details_id' => $id
|
|
]);
|
|
})->update([
|
|
'is_price' => bccomp($param['price'],0, 4) == 0 ? 2 : 1,
|
|
'content' => $param['content'],
|
|
'title_img' => $param['titleImg'],
|
|
]);
|
|
}
|
|
|
|
$this->success();
|
|
}
|
|
|
|
public function deleteCourseDetailsByIds()
|
|
{
|
|
$params = $this->request->param();
|
|
$params['ids'] = explode(',', $params['ids']);
|
|
foreach ($params['ids'] as $id) {
|
|
DatabaseRoute::getAllDbData('course_details', function ($query) use ($id) {
|
|
return $query->where([
|
|
'course_details_id' => $id
|
|
]);
|
|
})->delete();
|
|
}
|
|
|
|
$this->success();
|
|
}
|
|
} |