143 lines
4.9 KiB
PHP
143 lines
4.9 KiB
PHP
<?php
|
||
|
||
/**
|
||
* @author Any
|
||
* @description KISS
|
||
* @date 2021年6月30日
|
||
* @version 1.0.0
|
||
*
|
||
* _____LOG_____
|
||
*
|
||
*/
|
||
|
||
namespace app\modules\api\controllers;
|
||
|
||
use app\components\Oss;
|
||
use app\modules\api\behaviors\LoginBehavior;
|
||
use app\components\SiteHelper;
|
||
use app\components\SysConst;
|
||
use app\models\common\cms\CommonNoticeActionForm;
|
||
use app\models\common\cms\CommonNoticeListForm;
|
||
use app\models\cms\Notice;
|
||
use app\components\SysErrCode;
|
||
use Yii;
|
||
use yii\web\NotFoundHttpException;
|
||
|
||
class NoticeController extends Controller
|
||
{
|
||
public function behaviors()
|
||
{
|
||
return array_merge(parent::behaviors(), [
|
||
'login' => [
|
||
'class' => LoginBehavior::className(),
|
||
'ignore' => [
|
||
'api/notice/index',
|
||
'api/notice/detail',
|
||
'api/notice/test',
|
||
]
|
||
]
|
||
]);
|
||
}
|
||
|
||
|
||
public function actionTest()
|
||
{
|
||
|
||
var_dump($_FILES);
|
||
// 判断是否有文件上传
|
||
if (empty($_FILES['file']['name'])) {
|
||
echo "请选择要上传的文件";
|
||
exit;
|
||
}
|
||
|
||
// 上传文件的目录
|
||
$upload_dir = "/web/uploads/1/";
|
||
|
||
if (!is_dir($upload_dir)) {
|
||
mkdir(\Yii::$app->basePath . '/web/upload/1', 0777, true);
|
||
}
|
||
|
||
$file = md5($_FILES['file']['name']);
|
||
// 上传文件的全名
|
||
$upload_file = \Yii::$app->basePath . '/web/upload/1/' . $file . '.png';
|
||
// 将上传的文件从临时目录移动到指定目录
|
||
if (!move_uploaded_file($_FILES['file']['tmp_name'], $upload_file)) {
|
||
echo "文件上传失败";
|
||
} else {
|
||
$oss = new Oss();
|
||
|
||
$file = '/web/upload/1/' . $file . '.png';
|
||
//上传文件目录
|
||
$oss_data = $oss->upload($upload_file, $file);
|
||
|
||
}
|
||
|
||
}
|
||
|
||
|
||
/**
|
||
* showdoc
|
||
* @catalog 公告
|
||
* @title 公告列表
|
||
* @description 本接口提供公告列表
|
||
* @method get
|
||
* @url /api/notice/index
|
||
* @param keywords 非必选 string 关键词
|
||
* @param page 必选 int 页码
|
||
* @param limit 非必选 int 每页记录数
|
||
* @param is_top 非必选 int 是否置顶:1=是,0=否
|
||
* @param is_index 非必选 int 首页展示:1=是,0=否
|
||
* @return {"code":0,"msg":"ok","data":[{"author":"","title":"公告公告公告公告1","summary":"","content":"<p>公告公告公告公告公告公告公告公告公告公告公告公告公告额</p>","cover_url":"","id":"1","rich_text_id":"1","sort":"103","is_top":"0","is_index":"1","status":"1","created_at":"1625216065","published_at":"1625216065","viewed_num":"0","created_at_cn":"2021-07-02 16:54:25","published_at_cn":"2021-07-02 16:54:25","status_cn":"已发布"}],"count":"1","page_size":20,"page_count":1,"page_no":1,"end_flag":false}
|
||
* @return_param count int 记录条数
|
||
* @return_param page_size int 每页记录数
|
||
* @return_param page_count int 总页数
|
||
* @return_param page_no int 当前页码
|
||
* @return_param end_flag bool 是否加载结束
|
||
* @remark
|
||
*/
|
||
public function actionIndex()
|
||
{
|
||
$form = new CommonNoticeListForm();
|
||
$form->attributes = \Yii::$app->request->get();
|
||
$form->cx_mch_id = $this->cx_mch_id;
|
||
$form->status = Notice::STATUS_PUBLISHED;
|
||
$form->store_id = \Yii::$app->user->isGuest ? 0 : \Yii::$app->user->identity->store_id;
|
||
$data = $form->search();
|
||
return $this->responseHandler($data);
|
||
}
|
||
|
||
/**
|
||
* showdoc
|
||
* @catalog 公告
|
||
* @title 公告详情
|
||
* @description 本接口提供公告详情
|
||
* @method get
|
||
* @url /api/notice/detail
|
||
* @param notice_id 必选 int 公告ID
|
||
* @return {"code":0,"msg":"ok","data":{"author":"","title":"公告公告公告公告1","summary":"","content":"<p>公告公告公告公告公告公告公告公告公告公告公告公告公告额</p>","cover_url":"","id":"1","rich_text_id":"1","sort":"103","is_top":"0","is_index":"1","status":"1","created_at":"1625216065","published_at":"1625216065","viewed_num":"0","created_at_cn":"2021-07-02 16:54:25","published_at_cn":"2021-07-02 16:54:25","status_cn":"已发布"}}
|
||
* @return_param param param_type param_desc
|
||
* @remark
|
||
*/
|
||
public function actionDetail()
|
||
{
|
||
$form = new CommonNoticeActionForm();
|
||
$form->attributes = \Yii::$app->request->get();
|
||
$form->cx_mch_id = $this->cx_mch_id;
|
||
$data = $form->detail();
|
||
$render = \Yii::$app->request->get('render');
|
||
if (!$render) {
|
||
return $this->responseHandler($data);
|
||
}
|
||
if ($data['code'] != SysErrCode::$apiReturnSuccess) {
|
||
throw new NotFoundHttpException($data['msg']);
|
||
}
|
||
return $this->render('detail', [
|
||
'title' => $data['data']['title'],
|
||
'content' => $data['data']['content']
|
||
]);
|
||
}
|
||
}
|
||
|
||
|
||
|