123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208 |
- <?php
- /**
- * 系统公告
- * Created by PhpStorm.
- * User: 小威
- * Date: 2020/04/16
- * Time: 17:23
- */
- namespace JinDouYun\Controller\System;
- use Mall\Framework\Core\ErrorCode;
- use Mall\Framework\Core\StatusCode;
- use JinDouYun\Controller\BaseController;
- use JinDouYun\Model\System\MAnnouncement;
- class Announcement extends BaseController
- {
- private $objMAnnouncement;
- public function __construct($isCheckAcl = true, $isMustLogin = true)
- {
- parent::__construct($isCheckAcl, $isMustLogin);
- $this->objMAnnouncement = new MAnnouncement($this->onlineEnterpriseId);
- }
- /**
- * 公告添加
- * @throws \Exception
- */
- public function addAnnouncement()
- {
- $params = $this->request->getRawJson();
- if(empty($params)){
- parent::sendOutput('参数为空', ErrorCode::$paramError);
- }
- $data = [
- 'title' => isset($params['title']) ? $params['title'] : '',
- 'content' => isset($params['content']) ? $params['content'] : '',
- 'status' => isset($params['status']) ? $params['status'] : '',
- 'type' => isset($params['type']) ? $params['type'] : '',
- 'upStatus' => isset($params['upStatus']) ? $params['upStatus'] : '',
- ];
- foreach($data as $key => $value){
- if(empty($value)){
- parent::sendOutput($key.'参数错误', ErrorCode::$paramError);
- }
- }
- $result = $this->objMAnnouncement ->addAnnouncement($data);
- if($result->isSuccess()){
- parent::sendOutput($result->getData());
- }else{
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- }
- /**
- * 公告删除
- */
- public function delAnnouncement()
- {
- $params = $this->request->param('request_id');
- if(!$params) {
- $this->sendOutput('参数错误', ErrorCode::$paramError);
- }
- $result = $this->objMAnnouncement->delAnnouncement($params);
- if($result->isSuccess()){
- $this->sendOutput($result->getData());
- }else{
- $this->sendOutput($result->getData(), $result->getErrorCode());
- }
- }
- /**
- * 公告弹框
- */
- public function upAnnouncement()
- {
- $params = $this->request->param('request_id');
- if(!$params) {
- $this->sendOutput('参数错误', ErrorCode::$paramError);
- }
- $where['id'] = $params;
- $result = $this->objMAnnouncement->upAnnouncement($where);
- if($result->isSuccess()){
- $this->sendOutput($result->getData());
- }else{
- $this->sendOutput($result->getData(), $result->getErrorCode());
- }
- }
- /**
- * 公告编辑
- */
- public function editAnnouncement()
- {
- $id = $this->request->param('request_id');
- if(empty($id)){
- $this->sendOutput('id参数错误', ErrorCode::$paramError);
- }
- $params = $this->request->getRawJson();
- $data = [
- 'title' => isset($params['title']) ? $params['title'] : '',
- 'content' => isset($params['content']) ? $params['content'] : '',
- 'status' => isset($params['status']) ? $params['status'] : '',
- 'type' => isset($params['type']) ? $params['type'] : '',
- 'upStatus' => isset($params['upStatus']) ? $params['upStatus'] : '',
- ];
- foreach($data as $key => $value){
- if(empty($value)){
- parent::sendOutput($key.'参数错误', ErrorCode::$paramError);
- }
- }
- $result = $this->objMAnnouncement->editAnnouncement($data, $id);
- if($result->isSuccess()){
- parent::sendOutput($result->getData());
- }else{
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- }
- /**
- * 公告启用/禁用
- */
- public function onAnnouncement()
- {
- $id = $this->request->param('request_id');
- if(!$id){
- $this->sendOutput('参数错误', ErrorCode::$paramError);
- }
- $result = $this->objMAnnouncement->onAnnouncement($id);
- if($result->isSuccess()){
- parent::sendOutput($result->getData());
- }else{
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- }
- /**
- * 公告列表
- */
- public function getAllAnnouncement()
- {
- $params = $this->request->getRawJson();
- if( empty($params) ){
- $this->sendOutput('参数为空', ErrorCode::$paramError );
- }
- $pageParams = pageToOffset($params['page']?:1, $params['pageSize']?:10);
- $selectParams['limit'] = $pageParams['limit'];
- $selectParams['offset'] = $pageParams['offset'];
- if(isset($params['type']) && !empty($params['type'])){
- $selectParams['type'] = $params['type'];
- }
-
- $result = $this->objMAnnouncement->getAllAnnouncement($selectParams);
- if(!$result->isSuccess()){
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- $returnData = $result->getData();
- $pageData = [
- 'pageIndex' => $params['page'],
- 'pageSize' => $params['pageSize'],
- 'pageTotal' => $returnData['total'],
- ];
- parent::sendOutput($returnData['data'], 0, $pageData);
- }
- /**
- * 公告详情
- */
- public function getAnnouncementInfo()
- {
- $id = $this->request->param('request_id');
- if(empty($id)){
- $this->sendOutput('参数为空', ErrorCode::$paramError );
- }
- $where['id'] = $id;
- $result = $this->objMAnnouncement->getAnnouncementInfo($where);
- if($result->isSuccess()){
- parent::sendOutput($result->getData());
- }else{
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- }
- /**
- * 弹窗公告详情
- */
- public function getupStatusAnnouncementInfo()
- {
- $where['type'] = StatusCode::$delete;
- $where['upStatus'] = StatusCode::$standard;
- $result = $this->objMAnnouncement->getAnnouncementInfo($where);
- if($result->isSuccess()){
- parent::sendOutput($result->getData());
- }else{
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- }
- }
|