MNoticeSetting.Class.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. namespace JinDouYun\Model\System;
  3. use JinDouYun\Dao\System\DAdminSetting;
  4. use JinDouYun\Dao\System\DNoticeSetting;
  5. use Mall\Framework\Core\ErrorCode;
  6. use Mall\Framework\Core\ResultWrapper;
  7. use Mall\Framework\Core\StatusCode;
  8. class MNoticeSetting
  9. {
  10. private $objDNoticeSetting;
  11. private $enterpriseId;
  12. private $objDAdminSetting;
  13. /**
  14. * MNoticeSetting constructor.
  15. * @param $enterpriseId
  16. */
  17. public function __construct($enterpriseId)
  18. {
  19. $this->enterpriseId = $enterpriseId;
  20. $this->objDNoticeSetting = new DNoticeSetting();
  21. $this->objDAdminSetting = new DAdminSetting();
  22. self::init();
  23. }
  24. /**
  25. * Doc: (des="初始化")
  26. * User: XMing
  27. * Date: 2020/11/10
  28. * Time: 6:08 下午
  29. */
  30. public function init(): ResultWrapper
  31. {
  32. $result = $this->objDNoticeSetting->get(['enterpriseId'=>$this->enterpriseId]);
  33. if ($result === false){
  34. return ResultWrapper::fail($this->objDNoticeSetting->error(),ErrorCode::$dberror);
  35. }
  36. if (!empty($result)){
  37. return ResultWrapper::success(true);
  38. }
  39. $admin = $this->objDAdminSetting->get(['type'=>StatusCode::$adminSettingType['notice']]);
  40. if ($admin === false){
  41. return ResultWrapper::fail($this->objDAdminSetting->error(),ErrorCode::$dberror);
  42. }
  43. if (empty($admin)){
  44. return ResultWrapper::success(true);
  45. }
  46. if (empty($result)){
  47. $insert = [
  48. 'enterpriseId' => $this->enterpriseId,
  49. 'content' => $admin['content'],
  50. 'createTime' => time(),
  51. ];
  52. $insertResult = $this->objDNoticeSetting->insert($insert);
  53. if ($insertResult === false){
  54. return ResultWrapper::fail($this->objDNoticeSetting->error(),ErrorCode::$dberror);
  55. }
  56. }
  57. return ResultWrapper::success(true);
  58. }
  59. /**
  60. * Doc: (des="设置")
  61. * User: XMing
  62. * Date: 2020/11/10
  63. * Time: 6:01 下午
  64. * @param array $params
  65. * @return ResultWrapper
  66. */
  67. public function set(array $params): ResultWrapper
  68. {
  69. $params['enterpriseId'] = $this->enterpriseId;
  70. $params['content'] = json_encode($params['content']);
  71. if (isset($params['extends'])){
  72. unset($params['extends']);
  73. }
  74. $result = $this->objDNoticeSetting->replace($params);
  75. if ($result === false){
  76. return ResultWrapper::fail($this->objDNoticeSetting->error(),ErrorCode::$dberror);
  77. }
  78. return ResultWrapper::success(true);
  79. }
  80. /**
  81. * Doc: (des="获取")
  82. * User: XMing
  83. * Date: 2020/11/10
  84. * Time: 6:06 下午
  85. * @return ResultWrapper
  86. */
  87. public function get():ResultWrapper
  88. {
  89. $result = $this->objDNoticeSetting->get(['enterpriseId'=>$this->enterpriseId]);
  90. if ($result === false){
  91. return ResultWrapper::fail($this->objDNoticeSetting->error(),ErrorCode::$dberror);
  92. }
  93. !empty($result['content']) && $result['content'] = json_decode($result['content'],true);
  94. return ResultWrapper::success($result);
  95. }
  96. }