MProcessSetting.Class.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. <?php
  2. namespace JinDouYun\Model\System;
  3. use JinDouYun\Dao\System\DAdminSetting;
  4. use JinDouYun\Dao\System\DProcessSetting;
  5. use Mall\Framework\Core\ErrorCode;
  6. use Mall\Framework\Core\ResultWrapper;
  7. use Mall\Framework\Core\StatusCode;
  8. /**
  9. * @copyright Copyright (c) https://www.qianniaovip.com All rights reserved
  10. * Description:
  11. * Class MProcessSetting
  12. * @package JinDouYun\Model\System
  13. */
  14. class MProcessSetting
  15. {
  16. /**
  17. * @var DProcessSetting
  18. */
  19. private $objDProcessSetting;
  20. /**
  21. * @var int
  22. */
  23. private $enterpriseId;
  24. /**
  25. * @var DAdminSetting
  26. */
  27. private $objDAdminSetting;
  28. /**
  29. * MProcessSetting constructor.
  30. * @param $enterpriseId
  31. */
  32. public function __construct($enterpriseId)
  33. {
  34. $this->enterpriseId = $enterpriseId;
  35. $this->objDProcessSetting = new DProcessSetting();
  36. $this->objDAdminSetting = new DAdminSetting();
  37. self::init();
  38. }
  39. /**
  40. * Doc: (des="初始化")
  41. * User: XMing
  42. * Date: 2020/11/6
  43. * Time: 2:19 下午\
  44. * @return ResultWrapper
  45. */
  46. private function init(): ResultWrapper
  47. {
  48. $adminLists = $this->objDAdminSetting->select(['type' => StatusCode::$adminSettingType['process']]);
  49. if ($adminLists === false) {
  50. return ResultWrapper::fail($this->objDAdminSetting->error(), ErrorCode::$dberror);
  51. }
  52. if (empty($adminLists)) {
  53. return ResultWrapper::success(true);
  54. }
  55. $lists = $this->objDProcessSetting->select(['enterpriseId' => $this->enterpriseId]);
  56. if ($lists === false) {
  57. return ResultWrapper::fail($this->objDProcessSetting->error(), ErrorCode::$dberror);
  58. }
  59. $processTypeIds = [];
  60. foreach ($lists as $val) {
  61. $processTypeIds[] = $val['processType'];
  62. }
  63. $inserts = [];
  64. foreach ($adminLists as $val) {
  65. if (in_array($val['signId'],$processTypeIds)){
  66. continue;
  67. }
  68. $inserts[] = [
  69. 'processType' => $val['signId'],
  70. 'enterpriseId' => $this->enterpriseId,
  71. 'content' => $val['content'],
  72. 'createTime' => time(),
  73. ];
  74. }
  75. if (!empty($inserts)){
  76. $result = $this->objDProcessSetting->insert($inserts,true);
  77. if ($result === false){
  78. return ResultWrapper::fail($this->objDProcessSetting->error(),ErrorCode::$dberror);
  79. }
  80. }
  81. return ResultWrapper::success(true);
  82. }
  83. /**
  84. * Doc: (des="设置")
  85. * User: XMing
  86. * Date: 2020/11/6
  87. * Time: 11:58 上午
  88. * @param array $params
  89. * @return ResultWrapper
  90. */
  91. public function set(array $params): ResultWrapper
  92. {
  93. $result = $this->objDProcessSetting->replace($params,true);
  94. if ($result === false) {
  95. return ResultWrapper::fail($this->objDProcessSetting->error(), ErrorCode::$paramError);
  96. }
  97. return ResultWrapper::success(true);
  98. }
  99. /**
  100. * Doc: (des="获取配置")
  101. * User: XMing
  102. * Date: 2020/11/6
  103. * Time: 12:11 下午
  104. */
  105. public function getAll(): ResultWrapper
  106. {
  107. $lists = $this->objDProcessSetting->select(['enterpriseId' => $this->enterpriseId]);
  108. if ($lists === false) {
  109. return ResultWrapper::fail($this->objDProcessSetting->error(), ErrorCode::$dberror);
  110. }
  111. foreach ($lists as &$list) {
  112. $list['content'] = empty($list['content']) ? [] : json_decode($list['content'], true);
  113. }
  114. return ResultWrapper::success($lists);
  115. }
  116. /**
  117. * Doc: (des="获取流程配置")
  118. * User: XMing
  119. * Date: 2020/11/6
  120. * Time: 4:10 下午
  121. * @param int $type
  122. * @param string $field
  123. * @return ResultWrapper
  124. */
  125. public function getProcessSettingByType(int $type,string $field = ''): ResultWrapper
  126. {
  127. $result = $this->objDProcessSetting->get(['enterpriseId'=>$this->enterpriseId,'processType'=>$type],'content');
  128. if ($result === false){
  129. return ResultWrapper::fail($this->objDProcessSetting->error(),ErrorCode::$dberror);
  130. }
  131. $set = isset($result['content']) ? json_decode($result['content'],true) : [];
  132. if (!empty($field) && !empty($set)){
  133. isset($set[$field]) && $set = $set[$field];
  134. }
  135. return ResultWrapper::success($set);
  136. }
  137. /**
  138. * Doc: (des="构建设置数据")
  139. * User: XMing
  140. * Date: 2020/11/6
  141. * Time: 12:06 下午
  142. * @param array $params
  143. * @return array
  144. */
  145. private static function buildProcessSetting(array $params): array
  146. {
  147. return [
  148. "processType" => isset($params['processType']) ? $params['processType'] : 0,
  149. //int(10) NOT NULL DEFAULT '0' COMMENT '流程类型',
  150. "content" => isset($params['content']) ? json_encode($params['content']) : null,
  151. //json DEFAULT NULL COMMENT '流程配置',
  152. "enterpriseId" => isset($params['enterpriseId']) ? $params['enterpriseId'] : 0,
  153. //int(11) NOT NULL COMMENT '企业id',
  154. "createTime" => time(),
  155. //int(10) NOT NULL DEFAULT '0' COMMENT '创建时间',
  156. "updateTime" => time(),
  157. //int(10) NOT NULL DEFAULT '0' COMMENT '更新时间'
  158. ];
  159. }
  160. }