2024-09-21 10:39:17 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace app\api\logic;
|
|
|
|
|
|
|
|
|
|
use app\common\basics\Logic;
|
|
|
|
|
use app\common\model\BusinessSchool;
|
|
|
|
|
use app\common\model\BusinessSchoolCategory;
|
2024-09-23 16:06:00 +08:00
|
|
|
use app\common\model\BusinessSchoolFile;
|
2024-09-21 10:39:17 +08:00
|
|
|
|
|
|
|
|
class BusinessSchoolLogic extends Logic
|
|
|
|
|
{
|
2024-09-21 15:43:36 +08:00
|
|
|
// 获取分类
|
2024-09-21 10:39:17 +08:00
|
|
|
public static function category()
|
|
|
|
|
{
|
|
|
|
|
try {
|
2024-09-21 10:54:10 +08:00
|
|
|
return BusinessSchoolCategory::field(['id', 'name'])
|
2024-09-21 10:39:17 +08:00
|
|
|
->where([
|
|
|
|
|
['del', '=', 0],
|
|
|
|
|
['is_show', '=', 1]
|
2024-09-21 10:54:10 +08:00
|
|
|
])->order('sort asc')->select()->toArray();
|
2024-09-21 10:39:17 +08:00
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
return ['error'=>$e->getMessage()];
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-09-21 11:36:56 +08:00
|
|
|
|
2024-09-21 15:43:36 +08:00
|
|
|
// 获取列表
|
2024-09-21 11:36:56 +08:00
|
|
|
public static function lists($get)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
$where = [
|
|
|
|
|
['a.del', '=', 0],
|
|
|
|
|
['a.is_show', '=', 1],
|
|
|
|
|
['c.del', '=', 0],
|
|
|
|
|
['c.is_show', '=', 1],
|
|
|
|
|
];
|
|
|
|
|
if(isset($get['cid']) && !empty($get['cid'])) {
|
|
|
|
|
$where[] = ['cid', '=', $get['cid']];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$order = [
|
2024-09-21 11:45:10 +08:00
|
|
|
'a.sort' => 'asc',
|
|
|
|
|
'a.id' => 'desc'
|
2024-09-21 11:36:56 +08:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$model = new BusinessSchool();
|
|
|
|
|
|
2024-09-23 16:55:05 +08:00
|
|
|
$count = $model->alias('a')->join('business_school_category c', 'c.id = a.cid')->where($where)->count();
|
2024-09-21 11:36:56 +08:00
|
|
|
|
|
|
|
|
$list = $model->alias('a')
|
2024-09-21 11:42:37 +08:00
|
|
|
->join('business_school_category c', 'c.id = a.cid')
|
2024-09-21 14:53:35 +08:00
|
|
|
->field(['a.id', 'a.title', 'a.video', 'a.intro'])
|
2024-09-21 11:36:56 +08:00
|
|
|
->where($where)
|
|
|
|
|
->order($order)
|
|
|
|
|
->page($get['page_no'], $get['page_size'])
|
|
|
|
|
->select()
|
|
|
|
|
->toArray();
|
|
|
|
|
|
|
|
|
|
$more = is_more($count, $get['page_no'], $get['page_size']);
|
|
|
|
|
|
|
|
|
|
$data = [
|
|
|
|
|
'list' => $list,
|
|
|
|
|
'page_no' => $get['page_no'],
|
|
|
|
|
'page_size' => $get['page_size'],
|
|
|
|
|
'count' => $count,
|
|
|
|
|
'more' => $more
|
|
|
|
|
];
|
|
|
|
|
return $data;
|
|
|
|
|
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
return ['error'=>$e->getMessage()];
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-09-21 15:43:36 +08:00
|
|
|
|
|
|
|
|
// 获取详情
|
|
|
|
|
public static function detail($id)
|
|
|
|
|
{
|
2024-09-21 15:57:09 +08:00
|
|
|
$article = BusinessSchool::field('id, title, video, content, intro')->where([
|
2024-09-21 15:43:36 +08:00
|
|
|
'id' => $id,
|
|
|
|
|
'del' => 0,
|
|
|
|
|
'is_show' => 1
|
|
|
|
|
])->findOrEmpty();
|
|
|
|
|
if($article->isEmpty()) {
|
|
|
|
|
$article = [];
|
|
|
|
|
}else{
|
|
|
|
|
$article = $article->toArray();
|
2024-09-23 17:26:20 +08:00
|
|
|
$file = BusinessSchoolFile::where('bsid', $id)->select()->toArray();
|
2024-09-23 17:27:16 +08:00
|
|
|
foreach ($file as $k => &$v) {
|
2024-09-23 17:12:21 +08:00
|
|
|
if ($v['type'] == 1) {
|
|
|
|
|
$article['image'][] = $v['src'];
|
|
|
|
|
} else if($v['type'] == 2) {
|
2024-09-23 17:27:16 +08:00
|
|
|
$article['file'][$k]['src'] = $v['src'];
|
|
|
|
|
$article['file'][$k]['name'] = basename($v['src']);
|
2024-09-23 17:12:21 +08:00
|
|
|
}
|
|
|
|
|
}
|
2024-09-21 15:43:36 +08:00
|
|
|
}
|
|
|
|
|
return $article;
|
|
|
|
|
}
|
2024-09-21 10:39:17 +08:00
|
|
|
}
|