123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- <?php
- /**
- * 消息Model
- * Created by PhpStorm.
- * User: 小威
- * Date: 2020/03/31
- * Time: 15:44
- */
- namespace JinDouYun\Model\Message;
- use Exception;
- use Mall\Framework\Core\ErrorCode;
- use Mall\Framework\Core\StatusCode;
- use Mall\Framework\Core\ResultWrapper;
- use JinDouYun\Dao\Message\DMessage;
- class MMessage
- {
- private $objDMessage;
- private $userCenterId;
- private $enterpriseId;
- public function __construct($enterpriseId, $userCenterId)
- {
- $this->enterpriseId = $enterpriseId;
- $this->userCenterId = $userCenterId;
- $this->objDMessage = new DMessage('default');
- $this->objDMessage->setTable($this->objDMessage->get_Table().'_'.$enterpriseId);
- }
- /**
- * 消息添加
- * @param $params
- * @return ResultWrapper
- * @throws Exception
- */
- public function addMessage($params)
- {
- $insertData['sendId'] = isset($params['sendId']) ? $params['sendId'] : $this->userCenterId;//发送人默认为当前用户
- $insertData['receiveId'] = $params['receiveId'];
- $insertData['title'] = $params['title'];
- $insertData['content'] = $params['content'];
- $insertData['type'] = isset($params['type']) ? $params['type'] : StatusCode::$messageType['inventoryNull'];
- $insertData['receiveStatus'] = StatusCode::$delete;
- $insertData['deleteStatus'] = StatusCode::$standard;
- $insertData['sendTime'] = time();
- $insertData['createTime'] = time();
- $insertData['receiveTime'] = null;
- $dbResult = $this->objDMessage->insert($insertData);
- if($dbResult === false){
- return ResultWrapper::fail($this->objDMessage->error(), ErrorCode::$dberror);
- }
- return ResultWrapper::success($dbResult);
- }
- /**
- * 消息删除
- * @param $params
- * @return ResultWrapper
- */
- public function delMessage($params)
- {
- $where = ['id' => $params['id']];
- $dbResult = $this->objDMessage->update(['deleteStatus' => StatusCode::$delete], $where);
- if($dbResult === false){
- return ResultWrapper::fail($this->objDMessage->error(), ErrorCode::$dberror);
- }else{
- return ResultWrapper::success($dbResult);
- }
- }
- /**
- * 消息列表
- * @param $params
- * @param bool $type
- * @return ResultWrapper
- */
- public function getAllMessage($params)
- {
- $limit = $params['limit'];
- unset($params['limit']);
- $offset = $params['offset'];
- unset($params['offset']);
- $where = [
- 'deleteStatus' => StatusCode::$standard,
- ];
- !empty($params['receiveStatus']) && $where['receiveStatus'] = $params['receiveStatus'];
- $dbResult = $this->objDMessage->select($where, '*', 'createTime desc', $limit, $offset);
- if ($dbResult === false) {
- return ResultWrapper::fail($this->objDMessage->error(), ErrorCode::$dberror);
- }
- $total = $this->objDMessage->count($where);
- $return = [
- 'data' => $dbResult,
- 'total' => ($total) ? intval($total) : 0,
- ];
- return ResultWrapper::success($return);
- }
- /**
- * 消息详情
- * @param $params
- * @return ResultWrapper
- */
- public function getMessageInfo($params)
- {
- $where = ['id' => $params['id']];
- $dbResult = $this->objDMessage->get($where);
- if($dbResult === false){
- return ResultWrapper::fail($this->objDMessage->error(), ErrorCode::$dberror);
- }
- return ResultWrapper::success($dbResult);
- }
- /**
- * 消息已读
- * @param $params
- * @return ResultWrapper
- */
- public function receiveMessage($params)
- {
- $where = ['id' => $params['id']];
- $dbResult = $this->objDMessage->update(['receiveStatus' => StatusCode::$standard, 'receiveTime' => time()],$where);
- if($dbResult === false){
- return ResultWrapper::fail($this->objDMessage->error(), ErrorCode::$dberror);
- }
- return ResultWrapper::success($dbResult);
- }
- }
|