MClassSetting.Class.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. /**
  3. * 分类设置
  4. * Created by PhpStorm.
  5. * User: 小威
  6. * Date: 2020/
  7. * Time: 15:26
  8. */
  9. namespace JinDouYun\Model\System;
  10. use Mall\Framework\Core\ErrorCode;
  11. use Mall\Framework\Core\ResultWrapper;
  12. use JinDouYun\Dao\SystemSettings\DSystem;
  13. use Mall\Framework\Core\StatusCode;
  14. class MClassSetting
  15. {
  16. private $objDSystem;
  17. private $onlineUserId;
  18. private $onlineEnterpriseId;
  19. public function __construct($onlineUserId, $enterpriseId)
  20. {
  21. $this->onlineUserId = $onlineUserId;
  22. $this->onlineEnterpriseId = $enterpriseId;
  23. $this->objDSystem = new DSystem('default');
  24. }
  25. /**
  26. * 编辑,新增分类设置
  27. * @param $selectParams
  28. * @return ResultWrapper
  29. */
  30. public function setClassSetting($selectParams)
  31. {
  32. $dbResult = $this->objDSystem->get(['enterpriseId' => $selectParams['enterpriseId'], 'type' => StatusCode::$settingType['class']]);
  33. if ($dbResult === false) {
  34. return ResultWrapper::fail($this->objDSystem->error(), ErrorCode::$dberror);
  35. }
  36. if ($dbResult) {
  37. //修改
  38. $dbResult = $this->objDSystem->update(['content' => json_encode($selectParams['content']), 'updateTime' => time()], ['enterpriseId' => $selectParams['enterpriseId'], 'type' => StatusCode::$settingType['class']]);
  39. if ($dbResult === false) {
  40. return ResultWrapper::fail($this->objDSystem->error(), ErrorCode::$dberror);
  41. }
  42. } else {
  43. //新增
  44. $insertData = [
  45. 'enterpriseId' => $selectParams['enterpriseId'],
  46. 'type' => StatusCode::$settingType['class'],
  47. 'content' => json_encode($selectParams['content']),
  48. 'createTime' => time(),
  49. 'updateTime' => time(),
  50. ];
  51. $dbResult = $this->objDSystem->insert($insertData);
  52. if ($dbResult === false) {
  53. return ResultWrapper::fail($this->objDSystem->error(), ErrorCode::$dberror);
  54. }
  55. }
  56. return ResultWrapper::success($dbResult);
  57. }
  58. /**
  59. * 获取分类设置
  60. * @param $selectParams
  61. * @return bool|mixed
  62. */
  63. public function getClassSettingInfo($selectParams)
  64. {
  65. $dbResult = $this->objDSystem->get(['enterpriseId' => $selectParams['enterpriseId'], 'type' => StatusCode::$settingType['class']]);
  66. if ($dbResult === false) {
  67. return ResultWrapper::fail($this->objDSystem->error(), ErrorCode::$dberror);
  68. }
  69. $dbResult && $dbResult['content'] = json_decode($dbResult['content'], true);
  70. if (isset($dbResult['content'])) {
  71. return ResultWrapper::success($dbResult['content']);
  72. }
  73. return ResultWrapper::success([]);
  74. }
  75. }