2024-09-19 11:32:39 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace service\modules\v1\controllers;
|
|
|
|
|
|
|
|
|
|
use Carbon\Carbon;
|
|
|
|
|
use common\core\BaseServiceController;
|
|
|
|
|
use common\jobs\ArticleMassSendJob;
|
2024-12-19 19:20:27 +08:00
|
|
|
use common\models\oldDb\DoctorArticle;
|
2024-09-19 11:32:39 +08:00
|
|
|
use yii\base\Exception;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @doc-module 医生文章中心
|
|
|
|
|
*/
|
|
|
|
|
class DoctorArticleController extends BaseServiceController
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* @doc-name 文章列表
|
|
|
|
|
* @doc-param string keyword 标题
|
|
|
|
|
* @doc-return mixed @List{id-int-文章id,cover-string-封面,title-string-标题,created_at-int-发布时间} 文章信息
|
|
|
|
|
* @doc-return mixed @Pagination{total-int-总数据,totalPage-int-总页数,pageSize-int-每页数据} 分页信息
|
|
|
|
|
*/
|
|
|
|
|
public function actionList()
|
|
|
|
|
{
|
|
|
|
|
$post = \Yii::$app->request->post();
|
|
|
|
|
$keyword = \Yii::$app->request->post('keyword');
|
|
|
|
|
$query = DoctorArticle::find()->where([
|
|
|
|
|
'su_id' => \Yii::$app->user->identity->getId(),
|
|
|
|
|
'is_draft' => 0,
|
|
|
|
|
'is_delete' => 0,
|
|
|
|
|
])->orderBy(['id'=>SORT_DESC]);
|
|
|
|
|
if ($keyword) {
|
|
|
|
|
$query->andFilterWhere(['like', 'title', $keyword]);
|
|
|
|
|
}
|
|
|
|
|
$this->field = [
|
|
|
|
|
DoctorArticle::class => [
|
|
|
|
|
'id', 'title', 'created_at', 'video_url', 'cover',
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
$data = $this->create($query, $post)->getModels();
|
|
|
|
|
foreach ($data as $value) {
|
|
|
|
|
$value['created_at'] = Carbon::createFromTimestamp($value['created_at'])->toDateTimeString();
|
|
|
|
|
}
|
|
|
|
|
return $data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @doc-name 文章详情
|
|
|
|
|
* @doc-return mixed @DoctorArticle{*} 文章详情
|
|
|
|
|
*/
|
|
|
|
|
public function actionInfo()
|
|
|
|
|
{
|
|
|
|
|
$id = \Yii::$app->request->post('id');
|
|
|
|
|
$info = DoctorArticle::find()->where([
|
|
|
|
|
'id' => $id,
|
|
|
|
|
'su_id' => \Yii::$app->user->identity->getId(),
|
|
|
|
|
'is_delete' => 0,
|
|
|
|
|
])->one();
|
|
|
|
|
if (!$info) {
|
|
|
|
|
throw new Exception('文章不存在');
|
|
|
|
|
}
|
|
|
|
|
$info['created_at'] = Carbon::createFromTimestamp($info['created_at'])->toDateTimeString();
|
|
|
|
|
return $info;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @doc-name 草稿列表
|
|
|
|
|
* @doc-param string title 标题
|
|
|
|
|
* @doc-return mixed @List{id-int-文章id,cover-string-封面,title-string-标题,created_at-int-发布时间} 文章信息
|
|
|
|
|
* @doc-return mixed @Pagination{total-int-总数据,totalPage-int-总页数,pageSize-int-每页数据} 分页信息
|
|
|
|
|
*/
|
|
|
|
|
public function actionMyDraft()
|
|
|
|
|
{
|
|
|
|
|
$post = \Yii::$app->request->post();
|
|
|
|
|
$keyword = \Yii::$app->request->post('keyword');
|
|
|
|
|
$query = DoctorArticle::find()->where([
|
|
|
|
|
'su_id' => \Yii::$app->user->identity->getId(),
|
|
|
|
|
'is_draft' => 1,
|
|
|
|
|
'is_delete' => 0,
|
|
|
|
|
])->orderBy(['id'=>SORT_DESC]);
|
|
|
|
|
if ($keyword) {
|
|
|
|
|
$query->andFilterWhere(['like', 'title', $keyword]);
|
|
|
|
|
}
|
|
|
|
|
$this->field = [
|
|
|
|
|
DoctorArticle::class => [
|
|
|
|
|
'id', 'title', 'created_at', 'video_url', 'cover',
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
$data = $this->create($query, $post)->getModels();
|
|
|
|
|
foreach ($data as $value) {
|
|
|
|
|
$value['created_at'] = Carbon::createFromTimestamp($value['created_at'])->toDateTimeString();
|
|
|
|
|
}
|
|
|
|
|
return $data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @doc-name 文章新增编辑
|
|
|
|
|
* @doc-param int id id可选无为新增
|
|
|
|
|
* @doc-param string title 标题
|
|
|
|
|
* @doc-param string cover 封面图(可空)
|
|
|
|
|
* @doc-param string content 内容
|
|
|
|
|
* @doc-param string video_url 视频链接(可空)
|
|
|
|
|
* @doc-param int is_draft 是否是草稿0否1是
|
|
|
|
|
*/
|
|
|
|
|
public function actionSave()
|
|
|
|
|
{
|
|
|
|
|
$post = \Yii::$app->request->post();
|
|
|
|
|
|
|
|
|
|
$this->requestValidate($this->post(), [
|
|
|
|
|
['title', 'required'],
|
|
|
|
|
['content', 'required'],
|
|
|
|
|
['is_draft', 'required'],
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$id = \Yii::$app->request->post('id');
|
|
|
|
|
if ($id) {
|
2024-12-19 19:20:27 +08:00
|
|
|
/* @var \common\models\oldDb\DoctorArticle $info */
|
2024-09-19 11:32:39 +08:00
|
|
|
$info = DoctorArticle::find()->where([
|
|
|
|
|
'id' => $id,
|
|
|
|
|
'su_id' => \Yii::$app->user->identity->getId(),
|
|
|
|
|
'is_delete' => 0,
|
|
|
|
|
])->one();
|
|
|
|
|
if (!$info) {
|
|
|
|
|
throw new Exception('文章不存在');
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$info = new DoctorArticle();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$info->su_id = \Yii::$app->user->identity->getId();
|
|
|
|
|
$info->title = $post['title'] ?? null;
|
|
|
|
|
$info->cover = $post['cover'] ?? null;
|
|
|
|
|
$info->content = $post['content'] ?? null;
|
|
|
|
|
$info->video_url = $post['video_url'] ?? null;
|
|
|
|
|
$info->is_draft = $post['is_draft'];
|
|
|
|
|
$info->is_delete = 0;
|
|
|
|
|
$info->saveOrFail();
|
|
|
|
|
|
|
|
|
|
return [$id ? '编辑成功' : '新增成功'];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @doc-name 文章删除
|
|
|
|
|
* @doc-param int id 文章id
|
|
|
|
|
*/
|
|
|
|
|
public function actionDel()
|
|
|
|
|
{
|
|
|
|
|
$id = \Yii::$app->user->identity->id;
|
|
|
|
|
$article_id = \Yii::$app->request->get('id');
|
|
|
|
|
if (!$article_id) {
|
|
|
|
|
throw new Exception('请选择删除的文章');
|
|
|
|
|
}
|
|
|
|
|
$article = DoctorArticle::find()->where(['su_id' => $id, 'id' => $article_id])->one();
|
|
|
|
|
if (!$article) throw new Exception('文章不存在');
|
|
|
|
|
|
|
|
|
|
$article->is_delete = 1;
|
|
|
|
|
$article->save();
|
|
|
|
|
return ['删除成功'];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @doc-name 群发文章
|
|
|
|
|
* @doc-param string content 发送内容
|
|
|
|
|
* @doc-param string send_at 发送时间-年月日时分秒
|
|
|
|
|
* @doc-param array up_ids 患者ID数组
|
|
|
|
|
*/
|
|
|
|
|
public function actionMassSend()
|
|
|
|
|
{
|
|
|
|
|
$content = \Yii::$app->request->post('content');
|
|
|
|
|
$up_ids = explode(',', \Yii::$app->request->post('up_ids'));
|
|
|
|
|
$send_at = \Yii::$app->request->post('send_at');
|
|
|
|
|
if (count($up_ids) == 0) {
|
|
|
|
|
throw new Exception('请选择要群发的患者');
|
|
|
|
|
}
|
|
|
|
|
$su_id = \Yii::$app->user->identity->id;
|
|
|
|
|
|
|
|
|
|
\Yii::$app->queue->delay(Carbon::now()->diffInSeconds($send_at))->push(new ArticleMassSendJob(([
|
|
|
|
|
'content' => $content,
|
|
|
|
|
'su_id' => $su_id,
|
|
|
|
|
'up_ids' => $up_ids,
|
|
|
|
|
])));
|
|
|
|
|
|
|
|
|
|
return ['已添加定时发送'];
|
|
|
|
|
}
|
|
|
|
|
}
|