Announcement.Class.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. <?php
  2. /**
  3. * 系统公告
  4. * Created by PhpStorm.
  5. * User: 小威
  6. * Date: 2020/04/16
  7. * Time: 17:23
  8. */
  9. namespace JinDouYun\Controller\System;
  10. use Mall\Framework\Core\ErrorCode;
  11. use Mall\Framework\Core\StatusCode;
  12. use JinDouYun\Controller\BaseController;
  13. use JinDouYun\Model\System\MAnnouncement;
  14. class Announcement extends BaseController
  15. {
  16. private $objMAnnouncement;
  17. public function __construct($isCheckAcl = true, $isMustLogin = true)
  18. {
  19. parent::__construct($isCheckAcl, $isMustLogin);
  20. $this->objMAnnouncement = new MAnnouncement($this->onlineEnterpriseId);
  21. }
  22. /**
  23. * 公告添加
  24. * @throws \Exception
  25. */
  26. public function addAnnouncement()
  27. {
  28. $params = $this->request->getRawJson();
  29. if(empty($params)){
  30. parent::sendOutput('参数为空', ErrorCode::$paramError);
  31. }
  32. $data = [
  33. 'title' => isset($params['title']) ? $params['title'] : '',
  34. 'content' => isset($params['content']) ? $params['content'] : '',
  35. 'status' => isset($params['status']) ? $params['status'] : '',
  36. 'type' => isset($params['type']) ? $params['type'] : '',
  37. 'upStatus' => isset($params['upStatus']) ? $params['upStatus'] : '',
  38. ];
  39. foreach($data as $key => $value){
  40. if(empty($value)){
  41. parent::sendOutput($key.'参数错误', ErrorCode::$paramError);
  42. }
  43. }
  44. $result = $this->objMAnnouncement ->addAnnouncement($data);
  45. if($result->isSuccess()){
  46. parent::sendOutput($result->getData());
  47. }else{
  48. parent::sendOutput($result->getData(), $result->getErrorCode());
  49. }
  50. }
  51. /**
  52. * 公告删除
  53. */
  54. public function delAnnouncement()
  55. {
  56. $params = $this->request->param('request_id');
  57. if(!$params) {
  58. $this->sendOutput('参数错误', ErrorCode::$paramError);
  59. }
  60. $result = $this->objMAnnouncement->delAnnouncement($params);
  61. if($result->isSuccess()){
  62. $this->sendOutput($result->getData());
  63. }else{
  64. $this->sendOutput($result->getData(), $result->getErrorCode());
  65. }
  66. }
  67. /**
  68. * 公告弹框
  69. */
  70. public function upAnnouncement()
  71. {
  72. $params = $this->request->param('request_id');
  73. if(!$params) {
  74. $this->sendOutput('参数错误', ErrorCode::$paramError);
  75. }
  76. $where['id'] = $params;
  77. $result = $this->objMAnnouncement->upAnnouncement($where);
  78. if($result->isSuccess()){
  79. $this->sendOutput($result->getData());
  80. }else{
  81. $this->sendOutput($result->getData(), $result->getErrorCode());
  82. }
  83. }
  84. /**
  85. * 公告编辑
  86. */
  87. public function editAnnouncement()
  88. {
  89. $id = $this->request->param('request_id');
  90. if(empty($id)){
  91. $this->sendOutput('id参数错误', ErrorCode::$paramError);
  92. }
  93. $params = $this->request->getRawJson();
  94. $data = [
  95. 'title' => isset($params['title']) ? $params['title'] : '',
  96. 'content' => isset($params['content']) ? $params['content'] : '',
  97. 'status' => isset($params['status']) ? $params['status'] : '',
  98. 'type' => isset($params['type']) ? $params['type'] : '',
  99. 'upStatus' => isset($params['upStatus']) ? $params['upStatus'] : '',
  100. ];
  101. foreach($data as $key => $value){
  102. if(empty($value)){
  103. parent::sendOutput($key.'参数错误', ErrorCode::$paramError);
  104. }
  105. }
  106. $result = $this->objMAnnouncement->editAnnouncement($data, $id);
  107. if($result->isSuccess()){
  108. parent::sendOutput($result->getData());
  109. }else{
  110. parent::sendOutput($result->getData(), $result->getErrorCode());
  111. }
  112. }
  113. /**
  114. * 公告启用/禁用
  115. */
  116. public function onAnnouncement()
  117. {
  118. $id = $this->request->param('request_id');
  119. if(!$id){
  120. $this->sendOutput('参数错误', ErrorCode::$paramError);
  121. }
  122. $result = $this->objMAnnouncement->onAnnouncement($id);
  123. if($result->isSuccess()){
  124. parent::sendOutput($result->getData());
  125. }else{
  126. parent::sendOutput($result->getData(), $result->getErrorCode());
  127. }
  128. }
  129. /**
  130. * 公告列表
  131. */
  132. public function getAllAnnouncement()
  133. {
  134. $params = $this->request->getRawJson();
  135. if( empty($params) ){
  136. $this->sendOutput('参数为空', ErrorCode::$paramError );
  137. }
  138. $pageParams = pageToOffset($params['page']?:1, $params['pageSize']?:10);
  139. $selectParams['limit'] = $pageParams['limit'];
  140. $selectParams['offset'] = $pageParams['offset'];
  141. if(isset($params['type']) && !empty($params['type'])){
  142. $selectParams['type'] = $params['type'];
  143. }
  144. $result = $this->objMAnnouncement->getAllAnnouncement($selectParams);
  145. if(!$result->isSuccess()){
  146. parent::sendOutput($result->getData(), $result->getErrorCode());
  147. }
  148. $returnData = $result->getData();
  149. $pageData = [
  150. 'pageIndex' => $params['page'],
  151. 'pageSize' => $params['pageSize'],
  152. 'pageTotal' => $returnData['total'],
  153. ];
  154. parent::sendOutput($returnData['data'], 0, $pageData);
  155. }
  156. /**
  157. * 公告详情
  158. */
  159. public function getAnnouncementInfo()
  160. {
  161. $id = $this->request->param('request_id');
  162. if(empty($id)){
  163. $this->sendOutput('参数为空', ErrorCode::$paramError );
  164. }
  165. $where['id'] = $id;
  166. $result = $this->objMAnnouncement->getAnnouncementInfo($where);
  167. if($result->isSuccess()){
  168. parent::sendOutput($result->getData());
  169. }else{
  170. parent::sendOutput($result->getData(), $result->getErrorCode());
  171. }
  172. }
  173. /**
  174. * 弹窗公告详情
  175. */
  176. public function getupStatusAnnouncementInfo()
  177. {
  178. $where['type'] = StatusCode::$delete;
  179. $where['upStatus'] = StatusCode::$standard;
  180. $result = $this->objMAnnouncement->getAnnouncementInfo($where);
  181. if($result->isSuccess()){
  182. parent::sendOutput($result->getData());
  183. }else{
  184. parent::sendOutput($result->getData(), $result->getErrorCode());
  185. }
  186. }
  187. }