System.Class.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. /**
  3. * 系统设置控制器
  4. * Created by PhpStorm.
  5. * User: 小威
  6. * Date: 2019/11/19
  7. * Time: 16:00
  8. */
  9. namespace JinDouYun\Controller\SystemSettings;
  10. use Mall\Framework\Core\ErrorCode;
  11. use JinDouYun\Controller\BaseController;
  12. use JinDouYun\Model\SystemSettings\MSystem;
  13. /**
  14. * type
  15. * 1小程序设置
  16. * 2模板消息设置
  17. * 3分类模板设置
  18. * 4字节小程序设置
  19. * Class System
  20. * @package JinDouYun\Controller\SystemSettings
  21. */
  22. class System extends BaseController
  23. {
  24. private $objMSystem;
  25. public function __construct($isCheckAcl = false, $isMustLogin = true, $checkToken = true)
  26. {
  27. parent::__construct($isCheckAcl, $isMustLogin, $checkToken);
  28. $this->objMSystem = new MSystem($this->onlineEnterpriseId);
  29. }
  30. /**
  31. * 修改系统设置
  32. */
  33. public function updateSystemSettings()
  34. {
  35. $id = $this->request->param('request_id');
  36. $params = $this->request->getRawJson();
  37. if (empty($params)) {
  38. parent::sendOutput('参数为空', ErrorCode::$paramError);
  39. }
  40. $updateData = [
  41. 'enterpriseId' => $this->onlineEnterpriseId,
  42. 'type' => isset($params['type']) ? $params['type'] : '',
  43. 'content' => isset($params['content']) ? $params['content'] : '',
  44. ];
  45. foreach ($updateData as $key => $value) {
  46. if (empty($value)) {
  47. parent::sendOutput($key . '参数错误', ErrorCode::$paramError);
  48. }
  49. }
  50. if (!isset($updateData['content']['originalID'])) {
  51. parent::sendOutput('originalId参数错误', ErrorCode::$paramError);
  52. }
  53. $id && $updateData['id'] = $id;
  54. !$id && $updateData['createTime'] = time();
  55. $updateData['updateTime'] = time();
  56. $content = $updateData['content'];
  57. $updateData['content'] = json_encode($updateData['content']);
  58. $modelResult = $this->objMSystem->updateSystemSettings($updateData, $content['originalID']);
  59. if (!$modelResult->isSuccess()) {
  60. parent::sendOutput($modelResult->getData(), $modelResult->getErrorCode());
  61. }
  62. parent::sendOutput($modelResult->getData());
  63. }
  64. /**
  65. * 查询系统设置
  66. */
  67. public function getSystemSettingsInfo()
  68. {
  69. $type = $this->request->param('request_id');
  70. if (empty($type)) {
  71. parent::sendOutput('参数为空', ErrorCode::$paramError);
  72. }
  73. $modelResult = $this->objMSystem->getSystemSettingsInfo($type);
  74. if (!$modelResult->isSuccess()) {
  75. parent::sendOutput($modelResult->getData(), $modelResult->getErrorCode());
  76. }
  77. parent::sendOutput($modelResult->getData());
  78. }
  79. /**
  80. * 获取预授权码(pre_auth_code)
  81. * 官网文档地址: https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/Authorization_Process_Technical_Description.html
  82. */
  83. public function preAuthCode()
  84. {
  85. $modelResult = $this->objMSystem->preAuthCode();
  86. if (!$modelResult->isSuccess()) {
  87. parent::sendOutput($modelResult->getData(), $modelResult->getErrorCode());
  88. }
  89. parent::sendOutput($modelResult->getData());
  90. }
  91. /**
  92. * type 4 字节跳动设置
  93. * 保存字节跳动设置
  94. * {"type":4,"content":{"wxpay":{"micro_appid":"ttappid","micro_app_secret":"microappSecret","appid":"appid","merchant_id":"merchant_id","app_secret":"app_secret"},"alipay":{}}}
  95. *
  96. */
  97. public function saveByteDanceSetting()
  98. {
  99. $id = $this->request->param('request_id');
  100. $params = $this->request->getRawJson();
  101. if (empty($params)) {
  102. parent::sendOutput('参数为空', ErrorCode::$paramError);
  103. }
  104. $data = [
  105. 'enterpriseId' => $this->onlineEnterpriseId,
  106. 'type' => isset($params['type']) ? $params['type'] : '',//4
  107. 'content' => isset($params['content']) ? $params['content'] : '',
  108. ];
  109. foreach ($data as $key => $value) {
  110. if (empty($value)) {
  111. parent::sendOutput($key . '参数错误', ErrorCode::$paramError);
  112. }
  113. }
  114. if (!empty($id)) $data['id'] = $id;
  115. $data['content'] = json_encode($data['content']);
  116. $modelResult = $this->objMSystem->saveByteDanceSetting($data);
  117. if (!$modelResult->isSuccess()) {
  118. parent::sendOutput($modelResult->getData(), $modelResult->getErrorCode());
  119. }
  120. parent::sendOutput($modelResult->getData());
  121. }
  122. }