123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- <?php
- namespace JinDouYun\Model\System;
- use JinDouYun\Dao\System\DAdminSetting;
- use JinDouYun\Dao\System\DNoticeSetting;
- use Mall\Framework\Core\ErrorCode;
- use Mall\Framework\Core\ResultWrapper;
- use Mall\Framework\Core\StatusCode;
- class MNoticeSetting
- {
- private $objDNoticeSetting;
- private $enterpriseId;
- private $objDAdminSetting;
- /**
- * MNoticeSetting constructor.
- * @param $enterpriseId
- */
- public function __construct($enterpriseId)
- {
- $this->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);
- }
- }
|