MAnnouncement.Class.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. <?php
  2. /**
  3. * 系统公告
  4. * Created by PhpStorm.
  5. * User: 小威
  6. * Date: 2020/04/16
  7. * Time: 17:22
  8. */
  9. namespace JinDouYun\Model\System;
  10. use Exception;
  11. use Mall\Framework\Core\ErrorCode;
  12. use Mall\Framework\Core\StatusCode;
  13. use Mall\Framework\Core\ResultWrapper;
  14. use Mall\Framework\Factory;
  15. use JinDouYun\Dao\System\DAnnouncement;
  16. class MAnnouncement
  17. {
  18. private $objDAnnouncement;
  19. private $enterpriseId;
  20. public function __construct($enterpriseId)
  21. {
  22. $this->enterpriseId = $enterpriseId;
  23. $this->objDAnnouncement = new DAnnouncement('default');
  24. }
  25. /**
  26. * 公告添加
  27. * @param $params
  28. * @return ResultWrapper
  29. * @throws Exception
  30. */
  31. public function addAnnouncement($params)
  32. {
  33. $params['createTime'] = time();
  34. $params['updateTime'] = time();
  35. $params['enterpriseId'] = $this->enterpriseId;
  36. $dbResult = $this->objDAnnouncement->insert($params);
  37. if($dbResult === false){
  38. return ResultWrapper::fail($this->objDAnnouncement->error(), ErrorCode::$dberror);
  39. }
  40. return ResultWrapper::success($dbResult);
  41. }
  42. /**
  43. * 公告删除
  44. * @param $params
  45. * @return ResultWrapper
  46. */
  47. public function delAnnouncement($params)
  48. {
  49. $dbResult = $this->objDAnnouncement->update(['deleteStatus' => StatusCode::$delete, 'updateTime' => time()], ['id' => $params]);
  50. if ($dbResult === false) {
  51. return ResultWrapper::fail($this->objDAnnouncement->error(), ErrorCode::$dberror);
  52. }
  53. return ResultWrapper::success($dbResult);
  54. }
  55. /**
  56. * 公告弹框
  57. * @param $where
  58. * @return ResultWrapper
  59. */
  60. public function upAnnouncement($where)
  61. {
  62. $where['enterpriseId'] = $this->enterpriseId;
  63. $dbResult = $this->objDAnnouncement->get($where);
  64. if ($dbResult === false) {
  65. return ResultWrapper::fail($this->objDAnnouncement->error(), ErrorCode::$dberror);
  66. }
  67. $update = ['updateTime' => time()];
  68. if($dbResult['upStatus'] == StatusCode::$standard){
  69. $update['upStatus'] = StatusCode::$delete;
  70. }else{
  71. $update['upStatus'] = StatusCode::$standard;
  72. $dbResult = $this->objDAnnouncement->update(['upStatus' => StatusCode::$delete], ['type' => $dbResult['type'], 'enterpriseId' => $this->enterpriseId]);
  73. if ($dbResult === false) {
  74. return ResultWrapper::fail($this->objDAnnouncement->error(), ErrorCode::$dberror);
  75. }
  76. }
  77. $dbResult = $this->objDAnnouncement->update($update, $where);
  78. if ($dbResult === false) {
  79. return ResultWrapper::fail($this->objDAnnouncement->error(), ErrorCode::$dberror);
  80. }
  81. return ResultWrapper::success($dbResult);
  82. }
  83. /**
  84. * 公告修改
  85. * @param $params
  86. * @param $id
  87. * @return ResultWrapper
  88. */
  89. public function editAnnouncement($params, $id)
  90. {
  91. $params['updateTime'] = time();
  92. if($params['status'] == StatusCode::$standard){
  93. $endDbResult = $this->objDAnnouncement->update(['status' => StatusCode::$delete, 'updateTime' => time()], ['enterpriseId' => $this->enterpriseId, 'type' => $params['type']]);
  94. if($endDbResult === false){
  95. return ResultWrapper::fail($this->objDAnnouncement->error(), ErrorCode::$dberror);
  96. }
  97. }
  98. $dbResult = $this->objDAnnouncement->update($params, ['id' => $id, 'enterpriseId' => $this->enterpriseId]);
  99. if ($dbResult === false) {
  100. return ResultWrapper::fail($this->objDAnnouncement->error(), ErrorCode::$dberror);
  101. }
  102. return ResultWrapper::success($dbResult);
  103. }
  104. /**
  105. * 公告启用/禁用
  106. * @param $id
  107. * @return ResultWrapper
  108. */
  109. public function onAnnouncement($id)
  110. {
  111. $dbResult = $this->objDAnnouncement->get(['id' => $id]);
  112. if($dbResult === false){
  113. return ResultWrapper::fail($this->objDAnnouncement->error(), ErrorCode::$dberror);
  114. }
  115. $update['status'] = StatusCode::$standard;
  116. $update['updateTime'] = time();
  117. if($dbResult['status'] == StatusCode::$standard){
  118. $update['status'] = StatusCode::$delete;
  119. }else{
  120. $endDbResult = $this->objDAnnouncement->update(['status' => StatusCode::$delete, 'updateTime' => time()], ['enterpriseId' => $this->enterpriseId, 'type' => $dbResult['type']]);
  121. if($endDbResult === false){
  122. return ResultWrapper::fail($this->objDAnnouncement->error(), ErrorCode::$dberror);
  123. }
  124. }
  125. $dbResult = $this->objDAnnouncement->update($update,['id' => $id]);
  126. if($dbResult === false){
  127. return ResultWrapper::fail($this->objDAnnouncement->error(), ErrorCode::$dberror);
  128. }
  129. return ResultWrapper::success($dbResult);
  130. }
  131. /**
  132. * 获取启用公告
  133. */
  134. public function getAnnouncement($where = [])
  135. {
  136. $where['status'] = StatusCode::$standard;
  137. $where['enterpriseId'] = $this->enterpriseId;
  138. $dbResult = $this->objDAnnouncement->get($where);
  139. if($dbResult === false){
  140. return ResultWrapper::fail($this->objDAnnouncement->error(), ErrorCode::$dberror);
  141. }
  142. return ResultWrapper::success($dbResult);
  143. }
  144. /**
  145. * 公告列表
  146. * @param $selectParams
  147. * @return ResultWrapper
  148. */
  149. public function getAllAnnouncement($selectParams)
  150. {
  151. $limit = $selectParams['limit'];
  152. unset($selectParams['limit']);
  153. $offset = $selectParams['offset'];
  154. unset($selectParams['offset']);
  155. $where = ['deleteStatus' => StatusCode::$standard, 'enterpriseId' => $this->enterpriseId];
  156. if(isset($selectParams['type'])){
  157. $where['type'] = $selectParams['type'];
  158. }
  159. $dbResult = $this->objDAnnouncement->select($where, '*', 'createTime desc', $offset, $limit);
  160. if($dbResult === false){
  161. return ResultWrapper::fail($this->objDAnnouncement->error(), ErrorCode::$dberror);
  162. }
  163. $total = $this->objDAnnouncement->count($where);
  164. $return = [
  165. 'data' => $dbResult,
  166. 'total' => ($total) ? intval($total) : 0,
  167. ];
  168. return ResultWrapper::success($return);
  169. }
  170. /**
  171. * 公告详情
  172. * @param $where
  173. * @return ResultWrapper
  174. */
  175. public function getAnnouncementInfo($where = [])
  176. {
  177. $where['enterpriseId'] = $this->enterpriseId;
  178. $where['deleteStatus'] = StatusCode::$standard;
  179. $dbResult = $this->objDAnnouncement->get($where);
  180. if($dbResult === false){
  181. return ResultWrapper::fail($this->objDAnnouncement->error(), ErrorCode::$dberror);
  182. }
  183. return ResultWrapper::success($dbResult);
  184. }
  185. }