Config.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. <?php
  2. namespace app\admin\controller\shopro;
  3. use app\admin\model\shopro\Config as ShoproConfig;
  4. class Config extends Common
  5. {
  6. protected $noNeedRight = ['index', 'platformStatus', 'getPlatformUrl'];
  7. public function index()
  8. {
  9. $configList = [
  10. [
  11. 'label' => '基本信息',
  12. 'name' => 'shopro/config/basic',
  13. 'status' => $this->auth->check('shopro/config/basic')
  14. ],
  15. [
  16. 'label' => '用户配置',
  17. 'name' => 'shopro/config/user',
  18. 'status' => $this->auth->check('shopro/config/user')
  19. ],
  20. [
  21. 'label' => '平台配置',
  22. 'name' => 'shopro/config/platform',
  23. 'status' => $this->auth->check('shopro/config/platform')
  24. ],
  25. [
  26. 'label' => '订单配置',
  27. 'name' => 'shopro/config/order',
  28. 'status' => $this->auth->check('shopro/config/order')
  29. ],
  30. [
  31. 'label' => '商品配置',
  32. 'name' => 'shopro/config/goods',
  33. 'status' => $this->auth->check('shopro/config/goods')
  34. ],
  35. [
  36. 'label' => '物流配置',
  37. 'name' => 'shopro/config/dispatch',
  38. 'status' => $this->auth->check('shopro/config/dispatch')
  39. ],
  40. [
  41. 'label' => '充值提现',
  42. 'name' => 'shopro/config/rechargewithdraw',
  43. 'status' => $this->auth->check('shopro/config/rechargewithdraw')
  44. ],
  45. [
  46. 'label' => '分销配置',
  47. 'name' => 'shopro/config/commission',
  48. 'status' => $this->auth->check('shopro/config/commission')
  49. ],
  50. [
  51. 'label' => '支付配置',
  52. 'name' => 'shopro/pay_config',
  53. 'status' => $this->auth->check('shopro/pay_config')
  54. ],
  55. [
  56. 'label' => '客服配置',
  57. 'name' => 'shopro/config/chat',
  58. 'status' => $this->auth->check('shopro/config/chat')
  59. ],
  60. [
  61. 'label' => 'Redis配置',
  62. 'name' => 'shopro/config/redis',
  63. 'status' => $this->auth->check('shopro/config/redis')
  64. ]
  65. ];
  66. $this->assignconfig("configList", $configList);
  67. return $this->view->fetch();
  68. }
  69. /**
  70. * 基本配置
  71. */
  72. public function basic()
  73. {
  74. if ('GET' === $this->request->method()) {
  75. $configs = ShoproConfig::getConfigs('shop.basic', false);
  76. } elseif ('POST' === $this->request->method()) {
  77. $configs = ShoproConfig::setConfigs('shop.basic', $this->request->param());
  78. }
  79. $this->success('操作成功', null, $configs);
  80. }
  81. /**
  82. * 用户默认配置
  83. */
  84. public function user()
  85. {
  86. if ('GET' === $this->request->method()) {
  87. $configs = ShoproConfig::getConfigs('shop.user', false);
  88. } elseif ('POST' === $this->request->method()) {
  89. $configs = ShoproConfig::setConfigs('shop.user', $this->request->param());
  90. }
  91. $this->success('操作成功', null, $configs);
  92. }
  93. /**
  94. * 物流配置
  95. */
  96. public function dispatch()
  97. {
  98. if ('GET' === $this->request->method()) {
  99. $configs = ShoproConfig::getConfigs('shop.dispatch', false);
  100. $configs['callback'] = $this->request->domain() . '/addons/shopro/order.express/push';
  101. } elseif ('POST' === $this->request->method()) {
  102. $configs = ShoproConfig::setConfigs('shop.dispatch', $this->request->param());
  103. }
  104. $this->success('操作成功', null, $configs);
  105. }
  106. /**
  107. * 平台状态
  108. */
  109. public function platformStatus()
  110. {
  111. $status = [
  112. 'H5' => ShoproConfig::getConfigs('shop.platform.H5.status', false),
  113. 'App' => ShoproConfig::getConfigs('shop.platform.App.status', false),
  114. 'WechatMiniProgram' => ShoproConfig::getConfigs('shop.platform.WechatMiniProgram.status', false),
  115. 'WechatOfficialAccount' => ShoproConfig::getConfigs('shop.platform.WechatOfficialAccount.status', false),
  116. ];
  117. $this->success('操作成功', null, $status);
  118. }
  119. /**
  120. * 平台配置
  121. */
  122. public function platform($platform)
  123. {
  124. if (!$this->request->isAjax()) {
  125. return $this->view->fetch();
  126. }
  127. if (!in_array($platform, ['App', 'H5', 'WechatMiniProgram', 'WechatOfficialAccount'])) {
  128. $this->error('平台不支持');
  129. }
  130. if ('GET' === $this->request->method()) {
  131. $configs = ShoproConfig::getConfigs('shop.platform.' . $platform, false);
  132. } elseif ('POST' === $this->request->method()) {
  133. $params = $this->request->param();
  134. if (!isset($params['share']['methods'])) {
  135. $params['share']['methods'] = [];
  136. }
  137. if (!isset($params['payment']['methods'])) {
  138. $params['payment']['methods'] = [];
  139. }
  140. $configs = ShoproConfig::setConfigs('shop.platform.' . $platform, $params);
  141. }
  142. $this->success('操作成功', null, $configs);
  143. }
  144. public function commission()
  145. {
  146. if ('GET' === $this->request->method()) {
  147. $configs = ShoproConfig::getConfigs('shop.commission', false);
  148. } elseif ('POST' === $this->request->method()) {
  149. check_env('commission');
  150. $params = $this->request->param();
  151. $configs = ShoproConfig::setConfigs('shop.commission', $params);
  152. }
  153. $this->success('操作成功', null, $configs);
  154. }
  155. /**
  156. * 订单配置
  157. */
  158. public function order()
  159. {
  160. if ('GET' === $this->request->method()) {
  161. $configs = ShoproConfig::getConfigs('shop.order', false);
  162. } elseif ('POST' === $this->request->method()) {
  163. $configs = ShoproConfig::setConfigs('shop.order', $this->request->param());
  164. }
  165. $this->success('操作成功', null, $configs);
  166. }
  167. /**
  168. * 商品配置
  169. */
  170. public function goods()
  171. {
  172. if ('GET' === $this->request->method()) {
  173. $configs = ShoproConfig::getConfigs('shop.goods', false);
  174. } elseif ('POST' === $this->request->method()) {
  175. $configs = ShoproConfig::setConfigs('shop.goods', $this->request->param());
  176. }
  177. $this->success('操作成功', null, $configs);
  178. }
  179. /**
  180. * 充值提现配置
  181. */
  182. public function rechargeWithdraw()
  183. {
  184. if ('GET' === $this->request->method()) {
  185. $configs = ShoproConfig::getConfigs('shop.recharge_withdraw', false);
  186. } elseif ('POST' === $this->request->method()) {
  187. $params = $this->request->param();
  188. if (!isset($params['recharge']['methods'])) {
  189. $params['recharge']['methods'] = [];
  190. }
  191. if (!isset($params['recharge']['quick_amounts'])) {
  192. $params['recharge']['quick_amounts'] = [];
  193. }
  194. if (!isset($params['withdraw']['methods'])) {
  195. $params['withdraw']['methods'] = [];
  196. }
  197. $configs = ShoproConfig::setConfigs('shop.recharge_withdraw', $params);
  198. }
  199. $this->success('操作成功', null, $configs);
  200. }
  201. /**
  202. * 客服配置
  203. */
  204. public function chat()
  205. {
  206. if ('GET' === $this->request->method()) {
  207. $configs = ShoproConfig::getConfigs('chat', false);
  208. } elseif ('POST' === $this->request->method()) {
  209. $configs = ShoproConfig::setConfigs('chat', $this->request->param());
  210. // 存文件
  211. file_put_contents(
  212. ROOT_PATH . 'application' . DS . 'extra' . DS . 'chat.php',
  213. '<?php' . "\n\nreturn " . short_var_export($this->request->param(), true) . ";"
  214. );
  215. }
  216. $this->success('操作成功', null, $configs);
  217. }
  218. /**
  219. * redis 配置
  220. */
  221. public function redis()
  222. {
  223. exit;
  224. if ('GET' === $this->request->method()) {
  225. $default = [
  226. 'host' => '127.0.0.1', // redis 主机地址
  227. 'password' => '', // redis 密码
  228. 'port' => 6379, // redis 端口
  229. 'select' => 1, // redis 数据库
  230. 'timeout' => 0, // redis 超时时间
  231. 'persistent' => false, // redis 持续性,连接复用
  232. ];
  233. $redis = \think\Config::get('redis');
  234. $redis['empty_password'] = 0;
  235. $redis['password'] = ''; // 隐藏密码
  236. $configs = $redis ? array_merge($default, $redis) : $default;
  237. } elseif ('POST' === $this->request->method()) {
  238. operate_filter();
  239. $configs = $this->request->param();
  240. $empty_password = (int)$configs['empty_password']; // 是否设置空密码
  241. unset($configs['empty_password']);
  242. if (isset($configs['password']) && empty($configs['password'])) {
  243. $redis = \think\Config::get('redis');
  244. // 不修改密码,保持为原始值
  245. $configs['password'] = $redis['password'] ?? '';
  246. } elseif ($empty_password) {
  247. $configs['password'] = '';
  248. }
  249. $configs['persistent'] = (isset($configs['persistent']) && ($configs['persistent'] === true || $configs['persistent'] == 'true')) ? true : false;
  250. // 存文件
  251. file_put_contents(
  252. ROOT_PATH . 'application' . DS . 'extra' . DS . 'redis.php',
  253. '<?php' . "\n\nreturn " . short_var_export($configs, true) . ";"
  254. );
  255. }
  256. $this->success('操作成功', null, $configs);
  257. }
  258. public function getPlatformUrl()
  259. {
  260. $h5Url = ShoproConfig::getConfigField('shop.basic.domain');
  261. $wechatMpAppid = ShoproConfig::getConfigField('shop.platform.WechatMiniProgram.app_id');
  262. $this->success('', null, [
  263. 'url' => $h5Url,
  264. 'appid' => $wechatMpAppid
  265. ]);
  266. }
  267. }