houde_web_api/app/api/controller/Works/Works.php

69 lines
2.0 KiB
PHP

<?php
namespace app\api\controller\Works;
use app\BaseController;
use app\common\model\Works\Works as ModelWorks;
use app\common\model\Works\WorksType as ModelWorksType;
use app\Request;
use think\Validate;
use think\exception\ValidateException;
use think\facade\Filesystem;
use app\common\arw\adjfut\src\Excel;
use app\common\arw\adjfut\src\UploadFile;
use app\common\exception\Tool;
use think\facade\Db;
use think\facade\Env;
class Works extends BaseController
{
/**
* 获取作品列表接口
*
* @param Request request
* @return array
* @date 2023-04-25
* @author xjh
* @since 1.0.0
*/
public function getWorksList(Request $request): array
{
$params = $request->param();
$this->validate($params, [
'works_type_id|作品类型id' => 'require',
]);
$works_type = ModelWorksType::where('works_type_id', $params['works_type_id'])->find();
if (!$works_type) throwErrorMsg('该作品类型不存在!');
$con = [
['works_type.works_type_delete_time', 'NULL', null],
['classes.classes_delete_time', 'NULL', null],
['works.works_type_guid', '=', $works_type->works_type_guid],
];
$data = ModelWorks::field([
'works.works_id',
'works_type.works_type_id',
'works.works_img',
'works.works_name',
'works.works_author',
'works.works_intro',
'works.works_likes_count',
'works.works_order',
'works_type.works_type_name',
'classes.classes_name',
])
->where($con)
->leftJoin('works_type', 'works_type.works_type_guid = works.works_type_guid')
->leftJoin('classes', 'classes.classes_guid = works.classes_guid')
->order('works_order', 'asc')
->select();
return msg(0, "获取作品列表成功!", [
'count' => count($data),
'data' => $data,
]);
}
}