SystemPushMessage.Class.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. <?php
  2. /**
  3. * 系统推送消息
  4. * Created by PhpStorm.
  5. * User: phperstar
  6. * Date: 2021/05/07
  7. * Time: 15:38
  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\MSystemPushMessage;
  14. class SystemPushMessage extends BaseController
  15. {
  16. private $objMSystemPushMessage;
  17. /**
  18. * SystemTemplate constructor.
  19. * @param bool $isCheckAcl
  20. * @param bool $isMustLogin
  21. */
  22. public function __construct($isCheckAcl = true, $isMustLogin = true)
  23. {
  24. parent::__construct($isCheckAcl, $isMustLogin);
  25. $this->objMSystemPushMessage = new MSystemPushMessage($this->onlineUserId, $this->onlineEnterpriseId);
  26. }
  27. /**
  28. * 添加,编辑系统模版
  29. * @return array
  30. */
  31. public function commonFieldFilter()
  32. {
  33. $params = $this->request->getRawJson();
  34. if (empty($params)) {
  35. $this->sendOutput('参数为空', ErrorCode::$paramError);
  36. }
  37. $data = [
  38. 'title' => isset($params['title']) ? $params['title'] : '',
  39. ];
  40. foreach ($data as $key => $value) {
  41. if (empty($value) && $value !== 0) {
  42. $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
  43. }
  44. }
  45. $data['enableStatus'] = isset($params['enableStatus']) ? $params['enableStatus'] : StatusCode::$delete;
  46. return $data;
  47. }
  48. /**
  49. * 添加系统模版
  50. * @throws \Exception
  51. */
  52. public function add()
  53. {
  54. $data = $this->commonFieldFilter();
  55. $result = $this->objMSystemPushMessage->add($data);
  56. if ($result->isSuccess()) {
  57. parent::sendOutput($result->getData());
  58. }
  59. parent::sendOutput($result->getData(), $result->getErrorCode());
  60. }
  61. /**
  62. * 推送渠道启用/停用
  63. */
  64. public function updatePushEnableStatus()
  65. {
  66. $params = $this->request->getRawJson();
  67. if (empty($params)) {
  68. $this->sendOutput('参数为空', ErrorCode::$paramError);
  69. }
  70. $updateData = [
  71. 'id' => getArrayItem($params, 'id', 0),
  72. 'weixinEnabledStatus' => getArrayItem($params, 'weixinEnabledStatus', 0),
  73. 'smsEnabledStatus' => getArrayItem($params, 'smsEnabledStatus', 0),
  74. ];
  75. foreach ($updateData as $key => $value) {
  76. if (empty($value)) {
  77. $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
  78. }
  79. }
  80. $result = $this->objMSystemPushMessage->updatePushEnableStatus($updateData);
  81. if ($result->isSuccess()) {
  82. parent::sendOutput($result->getData());
  83. }
  84. parent::sendOutput($result->getData(), $result->getErrorCode());
  85. }
  86. /**
  87. * 推送消息启用/停用
  88. */
  89. public function updateEnableStatus()
  90. {
  91. $params = $this->request->getRawJson();
  92. if (empty($params)) {
  93. $this->sendOutput('参数为空', ErrorCode::$paramError);
  94. }
  95. $updateData = [
  96. 'id' => getArrayItem($params, 'id', 0),
  97. 'enabledStatus' => getArrayItem($params, 'enabledStatus', 0),
  98. ];
  99. foreach ($updateData as $key => $value) {
  100. if (empty($value)) {
  101. $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
  102. }
  103. }
  104. $result = $this->objMSystemPushMessage->updateEnableStatus($updateData);
  105. if ($result->isSuccess()) {
  106. parent::sendOutput($result->getData());
  107. }
  108. parent::sendOutput($result->getData(), $result->getErrorCode());
  109. }
  110. /**
  111. * 获取系统内置推送消息模板列表
  112. */
  113. public function getAll()
  114. {
  115. $params = $this->request->getRawJson();
  116. $pageParams = pageToOffset(isset($params['page']) ? $params['page'] : 1, isset($params['pageSize']) ? $params['pageSize'] : 10);
  117. $selectParams = [
  118. 'limit' => $pageParams['limit'],
  119. 'offset' => $pageParams['offset'],
  120. 'type' => getArrayItem($params, 'type', 0),
  121. 'enabledStatus' => getArrayItem($params, 'enabledStatus', 0),
  122. 'keyword' => getArrayItem($params, 'keyword', ''),
  123. ];
  124. $dbResult = $this->objMSystemPushMessage->getAll($selectParams);
  125. if ($dbResult->isSuccess()) {
  126. $returnData = $dbResult->getData();
  127. $pageData = [
  128. 'pageIndex' => $params['page'],
  129. 'pageSize' => $params['pageSize'],
  130. 'pageTotal' => $returnData['total'],
  131. ];
  132. parent::sendOutput($returnData['data'], 0, $pageData);
  133. }
  134. parent::sendOutput($dbResult->getData(), ErrorCode::$dberror);
  135. }
  136. /**
  137. * 配置详情
  138. */
  139. public function settingDetail()
  140. {
  141. $id = $this->request->param('request_id');
  142. if (empty($id)) {
  143. $this->sendOutput('参数错误', ErrorCode::$paramError);
  144. }
  145. $result = $this->objMSystemPushMessage->settingDetail($id);
  146. if($result->isSuccess()){
  147. $this->sendOutput($result->getData());
  148. }else{
  149. $this->sendOutput($result->getData(), $result->getErrorCode());
  150. }
  151. }
  152. /**
  153. * 编辑系统模版
  154. */
  155. public function edit()
  156. {
  157. $params = $this->request->getRawJson();
  158. if (empty($params)) {
  159. $this->sendOutput('参数为空', ErrorCode::$paramError);
  160. }
  161. $updateData = [
  162. 'id' => getArrayItem($params, 'id', 0),
  163. 'weixinEnabledStatus' => getArrayItem($params, 'weixinEnabledStatus', 0),
  164. 'smsEnabledStatus' => getArrayItem($params, 'smsEnabledStatus', 0),
  165. 'weixinTemplateId' => getArrayItem($params, 'weixinTemplateId', 0),
  166. ];
  167. foreach ($updateData as $key => $value) {
  168. if (empty($value)) {
  169. $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
  170. }
  171. }
  172. $result = $this->objMSystemPushMessage->edit($updateData);
  173. if ($result->isSuccess()) {
  174. parent::sendOutput($result->getData());
  175. }
  176. parent::sendOutput($result->getData(), $result->getErrorCode());
  177. }
  178. /**
  179. * 删除系统模版
  180. */
  181. public function del()
  182. {
  183. $id = $this->request->param('request_id');
  184. if (!$id) {
  185. $this->sendOutput('参数错误', ErrorCode::$paramError);
  186. }
  187. if (!is_array($id)) {
  188. $id = [$id];
  189. }
  190. $result = $this->objMSystemPushMessage->del($id);
  191. if ($result->isSuccess()) {
  192. parent::sendOutput($result->getData());
  193. }
  194. parent::sendOutput($result->getData(), $result->getErrorCode());
  195. }
  196. /**
  197. * 自动创建微信模板消息
  198. */
  199. public function autoCreateWeiXinTemplateId()
  200. {
  201. $id = $this->request->param('request_id');
  202. if (!$id) {
  203. $this->sendOutput('参数错误', ErrorCode::$paramError);
  204. }
  205. $result = $this->objMSystemPushMessage->autoCreateWeiXinTemplateId($id);
  206. if ($result->isSuccess()) {
  207. parent::sendOutput($result->getData());
  208. }
  209. parent::sendOutput($result->getData(), $result->getErrorCode());
  210. }
  211. }