WxTemplate.Class.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: XiaoMing
  5. * Date: 2020/5/8
  6. * Time: 10:04
  7. */
  8. namespace JinDouYun\Controller\Manage;
  9. use JinDouYun\Controller\BaseController;
  10. use JinDouYun\Model\Manage\MWxTemplate;
  11. use Mall\Framework\Core\ErrorCode;
  12. use Mall\Framework\Core\StatusCode;
  13. /**
  14. * 微信模版
  15. * Class WxTemplate
  16. * @package JinDouYun\Controller\Manage
  17. */
  18. class WxTemplate extends BaseController
  19. {
  20. private $objMWxTemplate;
  21. /**
  22. * WxTemplate constructor.
  23. * @param bool $isCheckAcl
  24. * @param bool $isMustLogin
  25. * @param bool $checkToken
  26. * @throws \Exception
  27. */
  28. public function __construct($isCheckAcl = false, $isMustLogin = true, $checkToken = false)
  29. {
  30. parent::__construct($isCheckAcl, $isMustLogin, $checkToken);
  31. $this->objMWxTemplate = new MWxTemplate();
  32. }
  33. /**
  34. * 获取企业小程序模版
  35. */
  36. public function getAll()
  37. {
  38. $params = $this->request->getRawJson();
  39. $pageParams = pageToOffset(isset($params['page']) ? $params['page'] : 1, isset($params['pageSize']) ? $params['pageSize'] : 10);
  40. $selectParams['limit'] = $pageParams['limit'];
  41. $selectParams['offset'] = $pageParams['offset'];
  42. $selectParams['enterpriseName'] = isset($params['enterpriseName']) ? $params['enterpriseName'] : '';
  43. $selectParams['isWeChatStatus'] = isset($params['isWeChatStatus']) ? $params['isWeChatStatus'] : '';
  44. $result = $this->objMWxTemplate->getAll($selectParams);
  45. if ($result->isSuccess()) {
  46. $returnData = $result->getData();
  47. $pageData = [
  48. 'pageIndex' => isset($params['page']) ? $params['page'] : 1,
  49. 'pageSize' => isset($params['pageSize']) ? $params['pageSize'] : 10,
  50. 'pageTotal' => $returnData['total'],
  51. ];
  52. parent::sendOutput($returnData['data'], 0, $pageData);
  53. }
  54. parent::sendOutput($result->getData(), $result->getErrorCode());
  55. }
  56. /**
  57. * 提交代码&&提交审核
  58. */
  59. public function submitCodeAndAudit()
  60. {
  61. $params = $this->request->getRawJson();
  62. if (empty($params)) {
  63. parent::sendOutput('参数为空', ErrorCode::$paramError);
  64. }
  65. $mapping = [];
  66. foreach ($params as $key => $val) {
  67. $mapping[$key] = [
  68. 'enterpriseId' => isset($val['enterpriseId']) ? $val['enterpriseId'] : null,
  69. 'weixinTemplateId' => isset($val['weixinTemplateId']) ? $val['weixinTemplateId'] : null,
  70. 'auditStatus' => isset($val['auditStatus']) ? $val['auditStatus'] : null,
  71. 'templateId' => isset($val['templateId']) ? $val['templateId'] : null,
  72. 'version' => isset($val['version']) ? $val['version'] : null,
  73. 'token' => isset($val['token']) ? $val['token'] : null,
  74. ];
  75. foreach ($mapping[$key] as $k => $v) {
  76. if (empty($v) && $v === null) {
  77. parent::sendOutput($k . '参数错误', ErrorCode::$paramError);
  78. }
  79. }
  80. }
  81. $result = $this->objMWxTemplate->submitCodeAndAudit($mapping);
  82. if ($result->isSuccess()) {
  83. parent::sendOutput($result->getData(), 0);
  84. }
  85. parent::sendOutput($result->getData(), $result->getErrorCode());
  86. }
  87. /**
  88. * 发布
  89. */
  90. public function release()
  91. {
  92. $params = $this->request->getRawJson();
  93. if (empty($params)) {
  94. parent::sendOutput('参数为空', ErrorCode::$paramError);
  95. }
  96. $mapping = [];
  97. foreach ($params as $key => $val) {
  98. $mapping[$key] = [
  99. 'enterpriseId' => isset($val['enterpriseId']) ? $val['enterpriseId'] : null,
  100. 'templateId' => isset($val['templateId']) ? $val['templateId'] : null,
  101. 'auditStatus' => isset($val['auditStatus']) ? $val['auditStatus'] : null,
  102. ];
  103. foreach ($mapping[$key] as $k => $v) {
  104. if (empty($v) && $v === null) {
  105. parent::sendOutput($k . '参数错误', ErrorCode::$paramError);
  106. }
  107. if ($k == 'auditStatus' && $v != StatusCode::$wxAuditStatus['pass']) {
  108. parent::sendOutput('企业' . $val['enterpriseId'] . '小程序暂未审核成功,请等待审核成功后发布', ErrorCode::$paramError);
  109. }
  110. }
  111. }
  112. $result = $this->objMWxTemplate->release($mapping);
  113. if ($result->isSuccess()) {
  114. parent::sendOutput($result->getData(), 0);
  115. }
  116. parent::sendOutput($result->getData(), $result->getErrorCode());
  117. }
  118. /**
  119. * 撤销审核
  120. */
  121. public function revoke()
  122. {
  123. $params = $this->request->getRawJson();
  124. if (empty($params)) {
  125. parent::sendOutput('参数为空', ErrorCode::$paramError);
  126. }
  127. $mapping = [];
  128. foreach ($params as $key => $val) {
  129. $mapping[$key] = [
  130. 'enterpriseId' => isset($val['enterpriseId']) ? $val['enterpriseId'] : null,
  131. 'templateId' => isset($val['templateId']) ? $val['templateId'] : null,
  132. 'auditStatus' => isset($val['auditStatus']) ? $val['auditStatus'] : null,
  133. ];
  134. foreach ($mapping[$key] as $k => $v) {
  135. if (empty($v) && $v === null) {
  136. parent::sendOutput($k . '参数错误', ErrorCode::$paramError);
  137. }
  138. }
  139. }
  140. $result = $this->objMWxTemplate->revoke($mapping);
  141. if ($result->isSuccess()) {
  142. parent::sendOutput($result->getData(), 0);
  143. }
  144. parent::sendOutput($result->getData(), $result->getErrorCode());
  145. }
  146. }