新增了获取科普文章列表的接口
This commit is contained in:
parent
ba91b80fb4
commit
bed64ae079
69
app/Controller/ArticleController.php
Normal file
69
app/Controller/ArticleController.php
Normal file
@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Model\ArticleScience;
|
||||
use App\Request\ArticleRequest;
|
||||
use App\Request\PatientDoctorRequest;
|
||||
use App\Services\PatientDoctorService;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
/**
|
||||
* 文章管理
|
||||
*/
|
||||
class ArticleController extends AbstractController
|
||||
{
|
||||
/**
|
||||
* 获取科普文章列表
|
||||
* @return ResponseInterface
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function getArticleScienceList(): ResponseInterface
|
||||
{
|
||||
$request = $this->container->get(ArticleRequest::class);
|
||||
$request->scene('getArticleScienceList')->validateResolved();
|
||||
|
||||
$keyword = $this->request->input('keyword',"");
|
||||
$is_top = $this->request->input('is_top');
|
||||
$source_id = $this->request->input('source_id');
|
||||
$basic_class_id = $this->request->input('basic_class_id');
|
||||
$page = $this->request->input('page',1);
|
||||
$per_page = $this->request->input('per_page',10);
|
||||
|
||||
// 组合条件
|
||||
$article_science_params = array();// 文章搜索
|
||||
$article_science_class_params = array();// 文章分类搜索
|
||||
|
||||
// 是否置顶(0:否 1:是)
|
||||
if (!empty($is_top)){
|
||||
$article_science_params['is_top'] = $is_top;
|
||||
}
|
||||
|
||||
// 来源id
|
||||
if (!empty($source_id)){
|
||||
$article_science_params['source_id'] = $source_id;
|
||||
}
|
||||
|
||||
// 分类id
|
||||
if (!empty($basic_class_id)){
|
||||
$article_science_class_params['basic_class_id'] = $basic_class_id;
|
||||
}
|
||||
|
||||
$fields = ["*"];
|
||||
$article_sciences = ArticleScience::getArticleSciencePage($keyword,$article_science_params, $article_science_class_params, $fields,$page,$per_page);
|
||||
if (!empty($article_sciences['data'])) {
|
||||
foreach ($article_sciences['data'] as &$article_science) {
|
||||
$article_science['article_image'] = addAliyunOssWebsite($article_science['article_image']);
|
||||
|
||||
if (!empty($article_science["ArticleScienceSource"])){
|
||||
$article_science["ArticleScienceSource"]["source_image"] = addAliyunOssWebsite($article_science["ArticleScienceSource"]["source_image"]);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return $this->response->json($article_sciences);
|
||||
}
|
||||
}
|
||||
123
app/Model/ArticleScience.php
Normal file
123
app/Model/ArticleScience.php
Normal file
@ -0,0 +1,123 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Model;
|
||||
|
||||
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Hyperf\Database\Model\Collection;
|
||||
use Hyperf\Database\Model\Relations\HasMany;
|
||||
use Hyperf\Database\Model\Relations\HasOne;
|
||||
use Hyperf\DbConnection\Db;
|
||||
use Hyperf\Snowflake\Concern\Snowflake;
|
||||
|
||||
/**
|
||||
* @property int $article_id 主键id
|
||||
* @property string $article_title 文章标题
|
||||
* @property int $article_status 文章状态(1:正常 2:禁用)
|
||||
* @property int $is_top 是否置顶(0:否 1:是)
|
||||
* @property string $article_image 文章图片(1张)
|
||||
* @property int $source_id 文章来源id
|
||||
* @property string $article_url 文章地址
|
||||
* @property Carbon $created_at 创建时间
|
||||
* @property Carbon $updated_at 修改时间
|
||||
*/
|
||||
class ArticleScience extends Model
|
||||
{
|
||||
use Snowflake;
|
||||
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*/
|
||||
protected ?string $table = 'article_science';
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*/
|
||||
protected array $fillable = ['article_id', 'article_title', 'article_status', 'is_top', 'article_image', 'source_id', 'article_url', 'created_at', 'updated_at'];
|
||||
|
||||
protected string $primaryKey = "article_id";
|
||||
|
||||
/**
|
||||
* 关联来源
|
||||
*/
|
||||
public function ArticleScienceSource(): HasOne
|
||||
{
|
||||
return $this->hasOne(ArticleScienceSource::class, 'source_id', 'source_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联分类
|
||||
* @return HasMany
|
||||
*/
|
||||
public function ArticleScienceClass(): HasMany
|
||||
{
|
||||
return $this->hasMany(ArticleScienceClass::class, "article_id", "article_id");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取信息-单条
|
||||
* @param array $params
|
||||
* @param array $fields
|
||||
* @return object|null
|
||||
*/
|
||||
public static function getOne(array $params, array $fields = ['*']): object|null
|
||||
{
|
||||
return self::where($params)->first($fields);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取数据-多
|
||||
* @param array $params
|
||||
* @param array $fields
|
||||
* @return Collection|array
|
||||
*/
|
||||
public static function getList(array $params = [], array $fields = ['*']): Collection|array
|
||||
{
|
||||
return self::where($params)->get($fields);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取列表
|
||||
* @param string $keyword
|
||||
* @param array $article_science_params 搜索条件
|
||||
* @param array $article_science_class_params 分类搜索条件
|
||||
* @param array $fields
|
||||
* @param int|null $page
|
||||
* @param int|null $per_page
|
||||
* @return array
|
||||
*/
|
||||
public static function getArticleSciencePage(string $keyword = "", array $article_science_params = [], array $article_science_class_params = [], array $fields = ["*"], int $page = null, ?int $per_page = 10): array
|
||||
{
|
||||
$query = self::with(['ArticleScienceSource'])
|
||||
->where($article_science_params)
|
||||
->when($keyword, function ($query, $keyword) {
|
||||
$query->where(function ($query) use ($keyword) {
|
||||
$query->orwhere("article_title", 'like', '%' . $keyword . '%');
|
||||
$query->orWhereHas('ArticleScienceSource', function ($query) use ($keyword) {
|
||||
$query->where('source_name', 'like', '%' . $keyword . '%');
|
||||
});
|
||||
$query->orWhereHas('ArticleScienceClass.BasicArticleClass', function ($query) use ($keyword) {
|
||||
$query->where('basic_class_name', 'like', '%' . $keyword . '%');
|
||||
});
|
||||
});
|
||||
})
|
||||
->whereHas('ArticleScienceClass.BasicArticleClass', function ($query) use ($article_science_class_params) {
|
||||
$query->where($article_science_class_params);
|
||||
});
|
||||
|
||||
$result = $query->paginate($per_page, $fields, "page", $page);
|
||||
|
||||
$data = array();
|
||||
$data['current_page'] = $result->currentPage();// 当前页码
|
||||
$data['total'] = $result->total();//数据总数
|
||||
$data['data'] = $result->items();//数据
|
||||
$data['per_page'] = $result->perPage();//每页个数
|
||||
$data['last_page'] = $result->lastPage();//最后一页
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
}
|
||||
67
app/Model/ArticleScienceClass.php
Normal file
67
app/Model/ArticleScienceClass.php
Normal file
@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Model;
|
||||
|
||||
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Hyperf\Database\Model\Collection;
|
||||
use Hyperf\Database\Model\Relations\HasOne;
|
||||
use Hyperf\Snowflake\Concern\Snowflake;
|
||||
|
||||
/**
|
||||
* @property int $class_id 主键id
|
||||
* @property int $article_id 文章-科普id
|
||||
* @property int $basic_class_id 基础数据-科普-分类id
|
||||
* @property Carbon $created_at 创建时间
|
||||
* @property Carbon $updated_at 修改时间
|
||||
*/
|
||||
class ArticleScienceClass extends Model
|
||||
{
|
||||
use Snowflake;
|
||||
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*/
|
||||
protected ?string $table = 'article_science_class';
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*/
|
||||
protected array $fillable = ['class_id', 'article_id', 'basic_class_id', 'created_at', 'updated_at'];
|
||||
|
||||
protected string $primaryKey = "class_id";
|
||||
|
||||
/**
|
||||
* 关联基础分类
|
||||
*/
|
||||
public function BasicArticleClass(): HasOne
|
||||
{
|
||||
return $this->hasOne(BasicArticleClass::class, 'basic_class_id', 'basic_class_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取信息-单条
|
||||
* @param array $params
|
||||
* @param array $fields
|
||||
* @return object|null
|
||||
*/
|
||||
public static function getOne(array $params, array $fields = ['*']): object|null
|
||||
{
|
||||
return self::where($params)->first($fields);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取数据-多
|
||||
* @param array $params
|
||||
* @param array $fields
|
||||
* @return Collection|array
|
||||
*/
|
||||
public static function getList(array $params = [], array $fields = ['*']): Collection|array
|
||||
{
|
||||
return self::where($params)->get($fields);
|
||||
}
|
||||
|
||||
}
|
||||
57
app/Model/ArticleScienceSource.php
Normal file
57
app/Model/ArticleScienceSource.php
Normal file
@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Model;
|
||||
|
||||
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Hyperf\Database\Model\Collection;
|
||||
use Hyperf\Snowflake\Concern\Snowflake;
|
||||
|
||||
/**
|
||||
* @property int $source_id 主键id
|
||||
* @property string $source_name 来源名称
|
||||
* @property string $source_image 来源图片
|
||||
* @property Carbon $created_at 创建时间
|
||||
* @property Carbon $updated_at 修改时间
|
||||
*/
|
||||
class ArticleScienceSource extends Model
|
||||
{
|
||||
use Snowflake;
|
||||
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*/
|
||||
protected ?string $table = 'article_science_source';
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*/
|
||||
protected array $fillable = ['source_id', 'source_name', 'source_image', 'created_at', 'updated_at'];
|
||||
|
||||
protected string $primaryKey = "source_id";
|
||||
|
||||
/**
|
||||
* 获取信息-单条
|
||||
* @param array $params
|
||||
* @param array $fields
|
||||
* @return object|null
|
||||
*/
|
||||
public static function getOne(array $params, array $fields = ['*']): object|null
|
||||
{
|
||||
return self::where($params)->first($fields);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取数据-多
|
||||
* @param array $params
|
||||
* @param array $fields
|
||||
* @return Collection|array
|
||||
*/
|
||||
public static function getList(array $params = [], array $fields = ['*']): Collection|array
|
||||
{
|
||||
return self::where($params)->get($fields);
|
||||
}
|
||||
}
|
||||
58
app/Model/BasicArticleClass.php
Normal file
58
app/Model/BasicArticleClass.php
Normal file
@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Model;
|
||||
|
||||
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Hyperf\Database\Model\Collection;
|
||||
use Hyperf\Snowflake\Concern\Snowflake;
|
||||
|
||||
/**
|
||||
* @property int $basic_class_id 主键id
|
||||
* @property string $basic_class_name 分类名称
|
||||
* @property int $basic_class_sort 排序(越大排序越靠前)
|
||||
* @property Carbon $created_at 创建时间
|
||||
* @property Carbon $updated_at 修改时间
|
||||
*/
|
||||
class BasicArticleClass extends Model
|
||||
{
|
||||
use Snowflake;
|
||||
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*/
|
||||
protected ?string $table = 'basic_article_class';
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*/
|
||||
protected array $fillable = ['basic_class_id', 'basic_class_name', 'basic_class_sort', 'created_at', 'updated_at'];
|
||||
|
||||
protected string $primaryKey = "basic_class_id";
|
||||
|
||||
/**
|
||||
* 获取信息-单条
|
||||
* @param array $params
|
||||
* @param array $fields
|
||||
* @return object|null
|
||||
*/
|
||||
public static function getOne(array $params, array $fields = ['*']): object|null
|
||||
{
|
||||
return self::where($params)->first($fields);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取数据-多
|
||||
* @param array $params
|
||||
* @param array $fields
|
||||
* @return Collection|array
|
||||
*/
|
||||
public static function getList(array $params = [], array $fields = ['*']): Collection|array
|
||||
{
|
||||
return self::where($params)->get($fields);
|
||||
}
|
||||
|
||||
}
|
||||
51
app/Request/ArticleRequest.php
Normal file
51
app/Request/ArticleRequest.php
Normal file
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Request;
|
||||
|
||||
use App\Constants\HttpEnumCode;
|
||||
use Hyperf\Validation\Request\FormRequest;
|
||||
|
||||
class ArticleRequest extends FormRequest
|
||||
{
|
||||
protected array $scenes = [
|
||||
'getArticleScienceList' => [
|
||||
'keyword',
|
||||
'is_top',
|
||||
'source_id',
|
||||
'basic_class_id',
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'is_top' => ['sometimes','numeric','min:0','max:1'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取已定义验证规则的错误消息.
|
||||
*/
|
||||
public function messages(): array
|
||||
{
|
||||
return [
|
||||
'is_top.required' => HttpEnumCode::getMessage(HttpEnumCode::CLIENT_HTTP_ERROR),
|
||||
'is_top.numeric' => HttpEnumCode::getMessage(HttpEnumCode::CLIENT_HTTP_ERROR),
|
||||
'is_top.min' => HttpEnumCode::getMessage(HttpEnumCode::CLIENT_HTTP_ERROR),
|
||||
'is_top.max' => HttpEnumCode::getMessage(HttpEnumCode::CLIENT_HTTP_ERROR),
|
||||
];
|
||||
}
|
||||
}
|
||||
@ -11,6 +11,7 @@ declare(strict_types=1);
|
||||
*/
|
||||
|
||||
use App\Controller\AreaController;
|
||||
use App\Controller\ArticleController;
|
||||
use App\Controller\BasicDataController;
|
||||
use App\Controller\CallBackController;
|
||||
use App\Controller\DetectionController;
|
||||
@ -620,6 +621,15 @@ Router::addGroup('/patient', function () {
|
||||
// 检测是否可创建服务包问诊订单
|
||||
Router::get('/check/{order_no}', [OrderServicePackageController::class, 'getServicePackageInquiryCheck']);
|
||||
});
|
||||
|
||||
// 文章
|
||||
Router::addGroup('/article', function () {
|
||||
// 科普文章
|
||||
Router::addGroup('/science', function () {
|
||||
// 获取科普文章列表
|
||||
Router::get('', [ArticleController::class, 'getArticleScienceList']);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// 药师端api
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user