123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204 |
- <?php
- /**
- * 系统公告
- * Created by PhpStorm.
- * User: 小威
- * Date: 2020/04/16
- * Time: 17:22
- */
- namespace JinDouYun\Model\System;
- use Exception;
- use Mall\Framework\Core\ErrorCode;
- use Mall\Framework\Core\StatusCode;
- use Mall\Framework\Core\ResultWrapper;
- use Mall\Framework\Factory;
- use JinDouYun\Dao\System\DAnnouncement;
- class MAnnouncement
- {
- private $objDAnnouncement;
- private $enterpriseId;
- public function __construct($enterpriseId)
- {
- $this->enterpriseId = $enterpriseId;
- $this->objDAnnouncement = new DAnnouncement('default');
- }
- /**
- * 公告添加
- * @param $params
- * @return ResultWrapper
- * @throws Exception
- */
- public function addAnnouncement($params)
- {
- $params['createTime'] = time();
- $params['updateTime'] = time();
- $params['enterpriseId'] = $this->enterpriseId;
- $dbResult = $this->objDAnnouncement->insert($params);
- if($dbResult === false){
- return ResultWrapper::fail($this->objDAnnouncement->error(), ErrorCode::$dberror);
- }
- return ResultWrapper::success($dbResult);
- }
- /**
- * 公告删除
- * @param $params
- * @return ResultWrapper
- */
- public function delAnnouncement($params)
- {
- $dbResult = $this->objDAnnouncement->update(['deleteStatus' => StatusCode::$delete, 'updateTime' => time()], ['id' => $params]);
- if ($dbResult === false) {
- return ResultWrapper::fail($this->objDAnnouncement->error(), ErrorCode::$dberror);
- }
- return ResultWrapper::success($dbResult);
- }
- /**
- * 公告弹框
- * @param $where
- * @return ResultWrapper
- */
- public function upAnnouncement($where)
- {
- $where['enterpriseId'] = $this->enterpriseId;
- $dbResult = $this->objDAnnouncement->get($where);
- if ($dbResult === false) {
- return ResultWrapper::fail($this->objDAnnouncement->error(), ErrorCode::$dberror);
- }
- $update = ['updateTime' => time()];
- if($dbResult['upStatus'] == StatusCode::$standard){
- $update['upStatus'] = StatusCode::$delete;
- }else{
- $update['upStatus'] = StatusCode::$standard;
- $dbResult = $this->objDAnnouncement->update(['upStatus' => StatusCode::$delete], ['type' => $dbResult['type'], 'enterpriseId' => $this->enterpriseId]);
- if ($dbResult === false) {
- return ResultWrapper::fail($this->objDAnnouncement->error(), ErrorCode::$dberror);
- }
- }
- $dbResult = $this->objDAnnouncement->update($update, $where);
- if ($dbResult === false) {
- return ResultWrapper::fail($this->objDAnnouncement->error(), ErrorCode::$dberror);
- }
- return ResultWrapper::success($dbResult);
- }
- /**
- * 公告修改
- * @param $params
- * @param $id
- * @return ResultWrapper
- */
- public function editAnnouncement($params, $id)
- {
- $params['updateTime'] = time();
- if($params['status'] == StatusCode::$standard){
- $endDbResult = $this->objDAnnouncement->update(['status' => StatusCode::$delete, 'updateTime' => time()], ['enterpriseId' => $this->enterpriseId, 'type' => $params['type']]);
- if($endDbResult === false){
- return ResultWrapper::fail($this->objDAnnouncement->error(), ErrorCode::$dberror);
- }
- }
- $dbResult = $this->objDAnnouncement->update($params, ['id' => $id, 'enterpriseId' => $this->enterpriseId]);
- if ($dbResult === false) {
- return ResultWrapper::fail($this->objDAnnouncement->error(), ErrorCode::$dberror);
- }
- return ResultWrapper::success($dbResult);
- }
- /**
- * 公告启用/禁用
- * @param $id
- * @return ResultWrapper
- */
- public function onAnnouncement($id)
- {
- $dbResult = $this->objDAnnouncement->get(['id' => $id]);
- if($dbResult === false){
- return ResultWrapper::fail($this->objDAnnouncement->error(), ErrorCode::$dberror);
- }
- $update['status'] = StatusCode::$standard;
- $update['updateTime'] = time();
- if($dbResult['status'] == StatusCode::$standard){
- $update['status'] = StatusCode::$delete;
- }else{
- $endDbResult = $this->objDAnnouncement->update(['status' => StatusCode::$delete, 'updateTime' => time()], ['enterpriseId' => $this->enterpriseId, 'type' => $dbResult['type']]);
- if($endDbResult === false){
- return ResultWrapper::fail($this->objDAnnouncement->error(), ErrorCode::$dberror);
- }
- }
- $dbResult = $this->objDAnnouncement->update($update,['id' => $id]);
- if($dbResult === false){
- return ResultWrapper::fail($this->objDAnnouncement->error(), ErrorCode::$dberror);
- }
- return ResultWrapper::success($dbResult);
- }
- /**
- * 获取启用公告
- */
- public function getAnnouncement($where = [])
- {
- $where['status'] = StatusCode::$standard;
- $where['enterpriseId'] = $this->enterpriseId;
- $dbResult = $this->objDAnnouncement->get($where);
- if($dbResult === false){
- return ResultWrapper::fail($this->objDAnnouncement->error(), ErrorCode::$dberror);
- }
- return ResultWrapper::success($dbResult);
- }
- /**
- * 公告列表
- * @param $selectParams
- * @return ResultWrapper
- */
- public function getAllAnnouncement($selectParams)
- {
- $limit = $selectParams['limit'];
- unset($selectParams['limit']);
- $offset = $selectParams['offset'];
- unset($selectParams['offset']);
- $where = ['deleteStatus' => StatusCode::$standard, 'enterpriseId' => $this->enterpriseId];
- if(isset($selectParams['type'])){
- $where['type'] = $selectParams['type'];
- }
- $dbResult = $this->objDAnnouncement->select($where, '*', 'createTime desc', $offset, $limit);
- if($dbResult === false){
- return ResultWrapper::fail($this->objDAnnouncement->error(), ErrorCode::$dberror);
- }
- $total = $this->objDAnnouncement->count($where);
- $return = [
- 'data' => $dbResult,
- 'total' => ($total) ? intval($total) : 0,
- ];
- return ResultWrapper::success($return);
- }
- /**
- * 公告详情
- * @param $where
- * @return ResultWrapper
- */
- public function getAnnouncementInfo($where = [])
- {
- $where['enterpriseId'] = $this->enterpriseId;
- $where['deleteStatus'] = StatusCode::$standard;
- $dbResult = $this->objDAnnouncement->get($where);
- if($dbResult === false){
- return ResultWrapper::fail($this->objDAnnouncement->error(), ErrorCode::$dberror);
- }
- return ResultWrapper::success($dbResult);
- }
- }
|