123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- <?php
- /**
- * Created by PhpStorm.
- * User: XiaoMing
- * Date: 2020/5/8
- * Time: 10:04
- */
- namespace JinDouYun\Controller\Manage;
- use JinDouYun\Controller\BaseController;
- use JinDouYun\Model\Manage\MWxTemplate;
- use Mall\Framework\Core\ErrorCode;
- use Mall\Framework\Core\StatusCode;
- /**
- * 微信模版
- * Class WxTemplate
- * @package JinDouYun\Controller\Manage
- */
- class WxTemplate extends BaseController
- {
- private $objMWxTemplate;
- /**
- * WxTemplate constructor.
- * @param bool $isCheckAcl
- * @param bool $isMustLogin
- * @param bool $checkToken
- * @throws \Exception
- */
- public function __construct($isCheckAcl = false, $isMustLogin = true, $checkToken = false)
- {
- parent::__construct($isCheckAcl, $isMustLogin, $checkToken);
- $this->objMWxTemplate = new MWxTemplate();
- }
- /**
- * 获取企业小程序模版
- */
- public function getAll()
- {
- $params = $this->request->getRawJson();
- $pageParams = pageToOffset(isset($params['page']) ? $params['page'] : 1, isset($params['pageSize']) ? $params['pageSize'] : 10);
- $selectParams['limit'] = $pageParams['limit'];
- $selectParams['offset'] = $pageParams['offset'];
- $selectParams['enterpriseName'] = isset($params['enterpriseName']) ? $params['enterpriseName'] : '';
- $selectParams['isWeChatStatus'] = isset($params['isWeChatStatus']) ? $params['isWeChatStatus'] : '';
- $result = $this->objMWxTemplate->getAll($selectParams);
- if ($result->isSuccess()) {
- $returnData = $result->getData();
- $pageData = [
- 'pageIndex' => isset($params['page']) ? $params['page'] : 1,
- 'pageSize' => isset($params['pageSize']) ? $params['pageSize'] : 10,
- 'pageTotal' => $returnData['total'],
- ];
- parent::sendOutput($returnData['data'], 0, $pageData);
- }
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- /**
- * 提交代码&&提交审核
- */
- public function submitCodeAndAudit()
- {
- $params = $this->request->getRawJson();
- if (empty($params)) {
- parent::sendOutput('参数为空', ErrorCode::$paramError);
- }
- $mapping = [];
- foreach ($params as $key => $val) {
- $mapping[$key] = [
- 'enterpriseId' => isset($val['enterpriseId']) ? $val['enterpriseId'] : null,
- 'weixinTemplateId' => isset($val['weixinTemplateId']) ? $val['weixinTemplateId'] : null,
- 'auditStatus' => isset($val['auditStatus']) ? $val['auditStatus'] : null,
- 'templateId' => isset($val['templateId']) ? $val['templateId'] : null,
- 'version' => isset($val['version']) ? $val['version'] : null,
- 'token' => isset($val['token']) ? $val['token'] : null,
- ];
- foreach ($mapping[$key] as $k => $v) {
- if (empty($v) && $v === null) {
- parent::sendOutput($k . '参数错误', ErrorCode::$paramError);
- }
- }
- }
- $result = $this->objMWxTemplate->submitCodeAndAudit($mapping);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData(), 0);
- }
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- /**
- * 发布
- */
- public function release()
- {
- $params = $this->request->getRawJson();
- if (empty($params)) {
- parent::sendOutput('参数为空', ErrorCode::$paramError);
- }
- $mapping = [];
- foreach ($params as $key => $val) {
- $mapping[$key] = [
- 'enterpriseId' => isset($val['enterpriseId']) ? $val['enterpriseId'] : null,
- 'templateId' => isset($val['templateId']) ? $val['templateId'] : null,
- 'auditStatus' => isset($val['auditStatus']) ? $val['auditStatus'] : null,
- ];
- foreach ($mapping[$key] as $k => $v) {
- if (empty($v) && $v === null) {
- parent::sendOutput($k . '参数错误', ErrorCode::$paramError);
- }
- if ($k == 'auditStatus' && $v != StatusCode::$wxAuditStatus['pass']) {
- parent::sendOutput('企业' . $val['enterpriseId'] . '小程序暂未审核成功,请等待审核成功后发布', ErrorCode::$paramError);
- }
- }
- }
- $result = $this->objMWxTemplate->release($mapping);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData(), 0);
- }
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- /**
- * 撤销审核
- */
- public function revoke()
- {
- $params = $this->request->getRawJson();
- if (empty($params)) {
- parent::sendOutput('参数为空', ErrorCode::$paramError);
- }
- $mapping = [];
- foreach ($params as $key => $val) {
- $mapping[$key] = [
- 'enterpriseId' => isset($val['enterpriseId']) ? $val['enterpriseId'] : null,
- 'templateId' => isset($val['templateId']) ? $val['templateId'] : null,
- 'auditStatus' => isset($val['auditStatus']) ? $val['auditStatus'] : null,
- ];
- foreach ($mapping[$key] as $k => $v) {
- if (empty($v) && $v === null) {
- parent::sendOutput($k . '参数错误', ErrorCode::$paramError);
- }
- }
- }
- $result = $this->objMWxTemplate->revoke($mapping);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData(), 0);
- }
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- }
|