enterpriseId = $enterpriseId; $this->objDNoticeSetting = new DNoticeSetting(); $this->objDAdminSetting = new DAdminSetting(); self::init(); } /** * Doc: (des="初始化") * User: XMing * Date: 2020/11/10 * Time: 6:08 下午 */ public function init(): ResultWrapper { $result = $this->objDNoticeSetting->get(['enterpriseId'=>$this->enterpriseId]); if ($result === false){ return ResultWrapper::fail($this->objDNoticeSetting->error(),ErrorCode::$dberror); } if (!empty($result)){ return ResultWrapper::success(true); } $admin = $this->objDAdminSetting->get(['type'=>StatusCode::$adminSettingType['notice']]); if ($admin === false){ return ResultWrapper::fail($this->objDAdminSetting->error(),ErrorCode::$dberror); } if (empty($admin)){ return ResultWrapper::success(true); } if (empty($result)){ $insert = [ 'enterpriseId' => $this->enterpriseId, 'content' => $admin['content'], 'createTime' => time(), ]; $insertResult = $this->objDNoticeSetting->insert($insert); if ($insertResult === false){ return ResultWrapper::fail($this->objDNoticeSetting->error(),ErrorCode::$dberror); } } return ResultWrapper::success(true); } /** * Doc: (des="设置") * User: XMing * Date: 2020/11/10 * Time: 6:01 下午 * @param array $params * @return ResultWrapper */ public function set(array $params): ResultWrapper { $params['enterpriseId'] = $this->enterpriseId; $params['content'] = json_encode($params['content']); if (isset($params['extends'])){ unset($params['extends']); } $result = $this->objDNoticeSetting->replace($params); if ($result === false){ return ResultWrapper::fail($this->objDNoticeSetting->error(),ErrorCode::$dberror); } return ResultWrapper::success(true); } /** * Doc: (des="获取") * User: XMing * Date: 2020/11/10 * Time: 6:06 下午 * @return ResultWrapper */ public function get():ResultWrapper { $result = $this->objDNoticeSetting->get(['enterpriseId'=>$this->enterpriseId]); if ($result === false){ return ResultWrapper::fail($this->objDNoticeSetting->error(),ErrorCode::$dberror); } !empty($result['content']) && $result['content'] = json_decode($result['content'],true); return ResultWrapper::success($result); } }