EnterpriseBindTemplate.Class.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <?php
  2. /**
  3. * 企业使用模版
  4. * Created by PhpStorm.
  5. * User: XiaoMing
  6. * Date: 2019/11/29
  7. * Time: 16:36
  8. */
  9. namespace JinDouYun\Controller\System;
  10. use Mall\Framework\Core\ErrorCode;
  11. use JinDouYun\Cache\EnterpriseCache;
  12. use JinDouYun\Controller\BaseController;
  13. use JinDouYun\Model\System\MEnterpriseBindTemplate;
  14. use Mall\Framework\Core\StatusCode;
  15. class EnterpriseBindTemplate extends BaseController
  16. {
  17. private $objMEnterpriseBindTemplate;
  18. /**
  19. * SystemTemplate constructor.
  20. * @param bool $isCheckAcl
  21. * @param bool $isMustLogin
  22. */
  23. public function __construct($isCheckAcl = true, $isMustLogin = true)
  24. {
  25. parent::__construct($isCheckAcl, $isMustLogin);
  26. $this->objMEnterpriseBindTemplate = new MEnterpriseBindTemplate($this->onlineUserId, $this->onlineEnterpriseId);
  27. }
  28. /**
  29. * 企业模版 (启用/停用)
  30. */
  31. public function bindTemplate()
  32. {
  33. $params = $this->request->getRawJson();
  34. $data = [
  35. 'templateId' => $this->request->param('request_id'),
  36. 'enableStatus' => isset($params['enableStatus']) ? $params['enableStatus'] : '',
  37. 'weixinTemplateId' => isset($params['weixinTemplateId']) ? $params['weixinTemplateId'] : '',
  38. 'enterpriseId' => $this->onlineEnterpriseId,
  39. 'version' => isset($params['version']) ? $params['version'] : '',
  40. ];
  41. foreach ($data as $key => $value) {
  42. if (empty($value) && $value != 0) {
  43. $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
  44. }
  45. }
  46. $result = $this->objMEnterpriseBindTemplate->bindTemplate($data, $this->token);
  47. if ($result->isSuccess()) {
  48. $objEnterpriseCache = new EnterpriseCache();
  49. $objEnterpriseCache->EnterpriseDataCache($this->onlineEnterpriseId, 'weixinTemplateId', $data['weixinTemplateId']);
  50. $objEnterpriseCache->EnterpriseDataCache($this->onlineEnterpriseId, 'templateId', $data['templateId']);
  51. parent::sendOutput($result->getData());
  52. }
  53. parent::sendOutput($result->getData(), $result->getErrorCode());
  54. }
  55. /**
  56. * 获取企业正在使用的模版
  57. */
  58. public function getAllTemplate()
  59. {
  60. $dbResult = $this->objMEnterpriseBindTemplate->getAllTemplate();
  61. if ($dbResult->isSuccess()) {
  62. $returnData = $dbResult->getData();
  63. parent::sendOutput($returnData['data'], 0);
  64. }
  65. parent::sendOutput($dbResult->getData(), ErrorCode::$dberror);
  66. }
  67. /**
  68. * 2-1,查询审核状态
  69. */
  70. public function getAuditStatus()
  71. {
  72. $params = $this->request->getRawJson();
  73. $paramsData = [
  74. 'templateId' => isset($params['templateId']) ? $params['templateId'] : '',
  75. 'enterpriseId' => $this->onlineEnterpriseId,
  76. 'auditId' => isset($params['auditId']) ? $params['auditId'] : '',
  77. ];
  78. foreach ($paramsData as $key => $value) {
  79. if (empty($value)) {
  80. parent::sendOutput($key . '参数为空!', ErrorCode::$paramError);
  81. }
  82. }
  83. $dbResult = $this->objMEnterpriseBindTemplate->getAuditStatus($paramsData);
  84. if (!$dbResult->isSuccess()) {
  85. parent::sendOutput($dbResult->getData(), ErrorCode::$dberror);
  86. }
  87. parent::sendOutput($dbResult->getData());
  88. }
  89. /**
  90. * 小程序提交代码
  91. */
  92. public function submitCode()
  93. {
  94. $params = $this->request->getRawJson();
  95. $data = [
  96. 'templateId' => $this->request->param('request_id'),
  97. 'enableStatus' => StatusCode::$standard,
  98. 'weixinTemplateId' => isset($params['weixinTemplateId']) ? $params['weixinTemplateId'] : '',
  99. 'enterpriseId' => $this->onlineEnterpriseId,
  100. 'version' => isset($params['version']) ? $params['version'] : '',
  101. ];
  102. // var_dump( $data);
  103. // die;
  104. foreach ($data as $key => $value) {
  105. if (empty($value) && $value != 0) {
  106. parent::sendOutput($key . '参数错误', ErrorCode::$paramError);
  107. }
  108. }
  109. $result = $this->objMEnterpriseBindTemplate->submitCode($data, $this->token);
  110. if ($result->isSuccess()) {
  111. $objEnterpriseCache = new EnterpriseCache();
  112. $objEnterpriseCache->EnterpriseDataCache($this->onlineEnterpriseId, 'weixinTemplateId', $data['weixinTemplateId']);
  113. $objEnterpriseCache->EnterpriseDataCache($this->onlineEnterpriseId, 'templateId', $data['templateId']);
  114. parent::sendOutput($result->getData());
  115. }
  116. parent::sendOutput($result->getData(), $result->getErrorCode());
  117. }
  118. /**
  119. * 2.提交审核
  120. */
  121. public function submitAudit()
  122. {
  123. $params = $this->request->getRawJson();
  124. $paramsData = [
  125. 'templateId' => isset($params['templateId']) ? $params['templateId'] : '',
  126. 'enterpriseId' => $this->onlineEnterpriseId,
  127. ];
  128. foreach ($paramsData as $key => $value) {
  129. if (empty($value)) {
  130. parent::sendOutput($key . '参数为空!', ErrorCode::$paramError);
  131. }
  132. }
  133. $dbResult = $this->objMEnterpriseBindTemplate->submitAudit($paramsData);
  134. if (!$dbResult->isSuccess()) {
  135. parent::sendOutput($dbResult->getData(), ErrorCode::$dberror);
  136. }
  137. parent::sendOutput($dbResult->getData());
  138. }
  139. /**
  140. * 3.发布
  141. */
  142. public function release()
  143. {
  144. $params = $this->request->getRawJson();
  145. $paramsData = [
  146. 'templateId' => isset($params['templateId']) ? $params['templateId'] : '',
  147. 'enterpriseId' => $this->onlineEnterpriseId,
  148. ];
  149. foreach ($paramsData as $key => $value) {
  150. if (empty($value)) {
  151. parent::sendOutput($key . '参数为空!', ErrorCode::$paramError);
  152. }
  153. }
  154. $dbResult = $this->objMEnterpriseBindTemplate->release($paramsData);
  155. if (!$dbResult->isSuccess()) {
  156. parent::sendOutput($dbResult->getData(), ErrorCode::$dberror);
  157. }
  158. parent::sendOutput($dbResult->getData());
  159. }
  160. /**
  161. * 获取当前提交代码之后,小程序的状态
  162. */
  163. public function getWxStatus()
  164. {
  165. $dbResult = $this->objMEnterpriseBindTemplate->getWxStatus();
  166. if (!$dbResult->isSuccess()) {
  167. parent::sendOutput($dbResult->getData(), ErrorCode::$dberror);
  168. }
  169. parent::sendOutput($dbResult->getData());
  170. }
  171. }