MEnterpriseTemplateModule.Class.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. /**
  3. * 企业模版模块数据
  4. * Created by PhpStorm.
  5. * User: XiaoMing
  6. * Date: 2019/11/29
  7. * Time: 15:30
  8. */
  9. namespace JinDouYun\Model\System;
  10. use Mall\Framework\Core\ErrorCode;
  11. use Mall\Framework\Core\ResultWrapper;
  12. use JinDouYun\Dao\System\DEnterpriseTemplateModule;
  13. class MEnterpriseTemplateModule
  14. {
  15. private $objDEnterpriseTemplateModule;
  16. private $onlineUserId;
  17. private $onlineEnterpriseId;
  18. private $objMTemplateModule;
  19. /**
  20. * MEnterpriseTemplateModule constructor.
  21. * @param $onlineUserId
  22. * @param $enterpriseId
  23. * @throws \Exception
  24. */
  25. public function __construct($onlineUserId, $enterpriseId)
  26. {
  27. $this->onlineUserId = $onlineUserId;
  28. $this->onlineEnterpriseId = $enterpriseId;
  29. $this->objMTemplateModule = new MTemplateModule($this->onlineUserId, $this->onlineEnterpriseId);
  30. $this->objDEnterpriseTemplateModule = new DEnterpriseTemplateModule('default');
  31. $this->objDEnterpriseTemplateModule->setTable($this->objDEnterpriseTemplateModule->get_Table() . '_' . $this->onlineEnterpriseId);
  32. }
  33. /**
  34. * @param $params
  35. * @return ResultWrapper
  36. */
  37. public function add($params)
  38. {
  39. $moduleId = $this->objMTemplateModule->getModuleIdByAlias(['alias' => $params['moduleAlias'], 'templateId' => $params['templateId']]);
  40. if (empty($moduleId)) {
  41. return ResultWrapper::fail('未找到模板', ErrorCode::$dberror);
  42. }
  43. $params['moduleId'] = $moduleId;
  44. $dbResult = $this->objDEnterpriseTemplateModule->replace($params);
  45. if ($dbResult === false) {
  46. return ResultWrapper::fail($this->objDEnterpriseTemplateModule->error(), ErrorCode::$dberror);
  47. }
  48. return ResultWrapper::success($dbResult);
  49. }
  50. /**
  51. * 根据模版id+模块id,获取当前企业下改模块的数据
  52. * @param $selectParams
  53. * @return ResultWrapper
  54. */
  55. public function getModuleInfo($selectParams)
  56. {
  57. $moduleId = $this->objMTemplateModule->getModuleIdByAlias(['alias' => $selectParams['moduleAlias'], 'templateId' => $selectParams['templateId']]);
  58. if (empty($moduleId)) {
  59. return ResultWrapper::fail('未找到模板', ErrorCode::$dberror);
  60. }
  61. $selectParams['moduleId'] = $moduleId;
  62. $dbResult = $this->objDEnterpriseTemplateModule->get($selectParams);
  63. if ($dbResult === false) {
  64. return ResultWrapper::fail($this->objDEnterpriseTemplateModule->error(), ErrorCode::$dberror);
  65. }
  66. if (isset($dbResult['moduleData'])) {
  67. $dbResult['moduleData'] = empty($dbResult['moduleData']) ? [] : json_decode($dbResult['moduleData'], true);
  68. }
  69. return ResultWrapper::success($dbResult);
  70. }
  71. /**
  72. * 编辑企业模版模块数据
  73. * @param $params
  74. * @return ResultWrapper
  75. */
  76. public function edit($params)
  77. {
  78. $moduleId = $this->objMTemplateModule->getModuleIdByAlias(['alias' => $params['moduleAlias'], 'templateId' => $params['templateId']]);
  79. if (empty($moduleId)) {
  80. return ResultWrapper::fail('未找到模板', ErrorCode::$dberror);
  81. }
  82. $params['moduleId'] = $moduleId;
  83. $dbResult = $this->objDEnterpriseTemplateModule->replace($params);
  84. if ($dbResult === false) {
  85. return ResultWrapper::fail($this->objDEnterpriseTemplateModule->error(), ErrorCode::$dberror);
  86. }
  87. return ResultWrapper::success($dbResult);
  88. }
  89. /**
  90. * 获取企业模版模块数据数据
  91. * @param $selectParams
  92. * @return array|bool
  93. */
  94. public function getModuleByIds($selectParams)
  95. {
  96. $dbResult = $this->objDEnterpriseTemplateModule->select($selectParams);
  97. if ($dbResult === false) {
  98. return [];
  99. }
  100. $return = [];
  101. foreach ($dbResult as $key => $val) {
  102. $return[$val['moduleAlias']] = $val;
  103. }
  104. return $return;
  105. }
  106. }