ConfigLogic.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeshop100%开源免费商用商城系统
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | 商业版本务必购买商业授权,以免引起法律纠纷
  8. // | 禁止对系统程序代码以任何目的,任何形式的再发布
  9. // | gitee下载:https://gitee.com/likeshop_gitee
  10. // | github下载:https://github.com/likeshop-github
  11. // | 访问官网:https://www.likeshop.cn
  12. // | 访问社区:https://home.likeshop.cn
  13. // | 访问手册:http://doc.likeshop.cn
  14. // | 微信公众号:likeshop技术社区
  15. // | likeshop团队 版权所有 拥有最终解释权
  16. // +----------------------------------------------------------------------
  17. // | author: likeshopTeam
  18. // +----------------------------------------------------------------------
  19. // +----------------------------------------------------------------------
  20. // | likeshop100%开源免费商用商城系统
  21. // +----------------------------------------------------------------------
  22. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  23. // | 开源版本可自由商用,可去除界面版权logo
  24. // | 商业版本务必购买商业授权,以免引起法律纠纷
  25. // | 禁止对系统程序代码以任何目的,任何形式的再发布
  26. // | gitee下载:https://gitee.com/likeshop_gitee
  27. // | github下载:https://github.com/likeshop-github
  28. // | 访问官网:https://www.likeshop.cn
  29. // | 访问社区:https://home.likeshop.cn
  30. // | 访问手册:http://doc.likeshop.cn
  31. // | 微信公众号:likeshop技术社区
  32. // | likeshop团队 版权所有 拥有最终解释权
  33. // +----------------------------------------------------------------------
  34. // | author: likeshopTeam
  35. // +----------------------------------------------------------------------
  36. namespace app\shopapi\logic;
  37. use app\common\cache\HandleConcurrencyCache;
  38. use app\common\enum\DistributionConfigEnum;
  39. use app\common\model\DevShare;
  40. use app\common\model\DistributionConfig;
  41. use app\common\service\{
  42. FileService,
  43. ConfigService,
  44. };
  45. /**
  46. * 配置逻辑层
  47. * Class CollectLogic
  48. * @package app\common\logic
  49. */
  50. class ConfigLogic
  51. {
  52. /**
  53. * @notes 获取商城配置
  54. * @return array
  55. * @author cjhao
  56. * @date 2021/8/28 17:23
  57. */
  58. public function getConfig():array
  59. {
  60. $share_image = ConfigService::get('shop', 'share_image');
  61. $favicon = ConfigService::get('shop', 'favicon');
  62. $config = [
  63. //注册方式
  64. 'register_way' => ConfigService::get('config', 'register_way', config('project.login.register_way')),
  65. //登录方式
  66. 'login_way' => ConfigService::get('config', 'login_way',config('project.login.login_way')),
  67. //手机号码注册需验证码
  68. 'is_mobile_register_code' => ConfigService::get('config', 'is_mobile_register_code', config('project.login.is_mobile_register_code')),
  69. //注册强制绑定手机
  70. 'coerce_mobile' => ConfigService::get('config', 'coerce_mobile', config('project.login.coerce_mobile')),
  71. //公众号微信授权登录
  72. 'h5_wechat_auth' => ConfigService::get('config', 'h5_wechat_auth', config('project.login.h5_wechat_auth')),
  73. //公众号自动微信授权登录
  74. 'h5_auto_wechat_auth' => ConfigService::get('config', 'h5_auto_wechat_auth', config('project.login.h5_auto_wechat_auth')),
  75. //小程序微信授权登录
  76. 'mnp_wechat_auth' => ConfigService::get('config', 'mnp_wechat_auth', config('project.login.mnp_wechat_auth')),
  77. //小程序自动微信授权登录
  78. 'mnp_auto_wechat_auth' => ConfigService::get('config', 'mnp_auto_wechat_auth', config('project.login.mnp_auto_wechat_auth')),
  79. //字节小程序授权登录
  80. 'toutiao_auth' => ConfigService::get('config', 'toutiao_auth', config('project.login.toutiao_auth')),
  81. //字节小程序自动授权登录
  82. 'toutiao_auto_auth' => ConfigService::get('config', 'toutiao_auto_auth', config('project.login.toutiao_auto_auth')),
  83. //APP微信授权登录
  84. 'app_wechat_auth' => ConfigService::get('config', 'app_wechat_auth', config('project.login.app_wechat_auth')),
  85. //oss域名
  86. 'oss_domain' => FileService::getFileUrl(),
  87. //店铺logo
  88. 'logo' => FileService::getFileUrl(ConfigService::get('shop', 'mobile_logo')),
  89. //分享页面
  90. 'share_page' => ConfigService::get('shop', 'share_page'),
  91. //分享标题
  92. 'share_title' => ConfigService::get('shop', 'share_title', ''),
  93. //分享简介
  94. 'share_intro' => ConfigService::get('shop', 'share_intro', ''),
  95. //分享图片
  96. 'share_image' => $share_image ? FileService::getFileUrl($share_image) : '',
  97. // 小程序商城关闭状态
  98. 'mnp_status' => ConfigService::get('shop', 'status', 1),
  99. // H5商城关闭状态
  100. 'h5_status' => ConfigService::get('h5', 'status', 1),
  101. // PC商城关闭状态
  102. 'pc_status' => ConfigService::get('pc', 'status', 1),
  103. // 版权信息
  104. 'copyright' => ConfigService::get('shop', 'copyright', ''),
  105. // 备案号
  106. 'record_number' => ConfigService::get('shop', 'record_number', ''),
  107. // 备案链接
  108. 'record_system_link' => ConfigService::get('shop', 'record_system_link', ''),
  109. // 客服请求域名
  110. 'ws_domain' => env('project.ws_domain', 'ws:127.0.0.1'),
  111. //app协议弹出
  112. 'app_pop_agreement' => ConfigService::get('app','pop_agreement',1),
  113. // app微信登录
  114. // 'wechat_login' => ConfigService::get('app','wechat_login',1),
  115. 'area_js' => '/resource/js/area.js',
  116. 'shop_name' => ConfigService::get('shop', 'name'),
  117. 'domain' => request()->domain(true),
  118. 'favicon' => $favicon ? FileService::getFileUrl($favicon) : '',
  119. // 发货配置
  120. 'mini_express_send_sync' => ConfigService::get('mini_program', 'express_send_sync', 1),
  121. // 站点统计
  122. 'site_statistic' => [
  123. 'clarity_app_id' => ConfigService::get('site_statistic', 'clarity_app_id', '')
  124. ],
  125. ];
  126. return $config;
  127. }
  128. public function getLoginContentConfig(){
  129. $login_content = ConfigService::get('shop', 'login_content');
  130. return $config['login_content'] = $login_content;
  131. }
  132. /**
  133. * @notes 获取政策协议
  134. * @return array|string
  135. * @author Tab
  136. * @date 2021/7/28 16:08
  137. */
  138. public function getPolicyAgreement()
  139. {
  140. $params = request()->get();
  141. // 服务协议
  142. if (isset($params['type']) && $params['type'] == 1) {
  143. return [
  144. 'content' => ConfigService::get('shop', 'service_agreement_content', ''),
  145. 'name' => ConfigService::get('shop', 'service_agreement_name', ''),
  146. ];
  147. }
  148. // 隐私政策
  149. if (isset($params['type']) && $params['type'] == 2) {
  150. return [
  151. 'content' => ConfigService::get('shop', 'privacy_policy_content', ''),
  152. 'name' => ConfigService::get('shop', 'privacy_policy_name', ''),
  153. ];
  154. }
  155. // 分销协议
  156. if (isset($params['type']) && $params['type'] == 3) {
  157. $dbConfig = DistributionConfig::column('value', 'key');
  158. return [
  159. 'content' => $dbConfig['protocol_content'] ?? DistributionConfigEnum::DEFAULT_PROTOCOL_CONTENT,
  160. 'name' => $dbConfig['protocol_name'] ?? '分销协议',
  161. ];
  162. }
  163. //注销协议
  164. if (isset($params['type']) && $params['type'] == 4) {
  165. return [
  166. 'content' => ConfigService::get('shop', 'user_delete_content', ''),
  167. 'name' => ConfigService::get('shop', 'user_delete_name', ''),
  168. ];
  169. }
  170. return [ 'content' => '', 'name' => '' ];
  171. }
  172. /**
  173. * @notes 版权信息
  174. * @return array|int|mixed|string|null
  175. * @author ljj
  176. * @date 2022/2/22 11:49 上午
  177. */
  178. public function copyright()
  179. {
  180. return [
  181. 'copyright' => ConfigService::get('shop', 'copyright', ''),
  182. 'copyright2' => ConfigService::get('shop', 'copyright2', ''),
  183. 'copyright_auth' => ConfigService::get('shop', 'copyright_auth', []) ? : [
  184. 'type' => "1",
  185. 'list' => [
  186. [ 'image' => '', 'name' =>'', 'link' => '' ],
  187. ]
  188. ],
  189. ];
  190. }
  191. /**
  192. * @notes 获取客服配置
  193. * @return array
  194. * @author ljj
  195. * @date 2024/8/28 下午4:06
  196. */
  197. public function getKefuConfig()
  198. {
  199. $defaultData = [
  200. 'way' => 1,
  201. 'name' => '',
  202. 'remarks' => '',
  203. 'phone' => '',
  204. 'business_time' => '',
  205. 'qr_code' => '',
  206. 'enterprise_id' => '',
  207. 'kefu_link' => ''
  208. ];
  209. $config = [
  210. 'mnp' => ConfigService::get('kefu_config', 'mnp', $defaultData),
  211. 'oa' => ConfigService::get('kefu_config', 'oa', $defaultData),
  212. 'h5' => ConfigService::get('kefu_config', 'h5', $defaultData),
  213. 'pc' => ConfigService::get('kefu_config', 'pc', $defaultData),
  214. 'app' => ConfigService::get('kefu_config', 'app', $defaultData),
  215. ];
  216. if (!empty($config['mnp']['qr_code'])) $config['mnp']['qr_code'] = FileService::getFileUrl($config['mnp']['qr_code']);
  217. if (!empty($config['oa']['qr_code'])) $config['oa']['qr_code'] = FileService::getFileUrl($config['oa']['qr_code']);
  218. if (!empty($config['h5']['qr_code'])) $config['h5']['qr_code'] = FileService::getFileUrl($config['h5']['qr_code']);
  219. if (!empty($config['pc']['qr_code'])) $config['pc']['qr_code'] = FileService::getFileUrl($config['pc']['qr_code']);
  220. if (!empty($config['app']['qr_code'])) $config['app']['qr_code'] = FileService::getFileUrl($config['app']['qr_code']);
  221. return $config;
  222. }
  223. /**
  224. * @notes 获取分享配置
  225. * @return array
  226. * @throws \think\db\exception\DataNotFoundException
  227. * @throws \think\db\exception\DbException
  228. * @throws \think\db\exception\ModelNotFoundException
  229. * @author ljj
  230. * @date 2024/9/11 下午3:20
  231. */
  232. public function getShareConfig()
  233. {
  234. //读取缓存
  235. $HandleConcurrencyCache = new HandleConcurrencyCache();
  236. $lists = $HandleConcurrencyCache->getCache($HandleConcurrencyCache->getShareConfigKey());
  237. if ($lists !== false) {
  238. return $lists;
  239. }
  240. $lists = DevShare::field('*')
  241. ->append(['type_desc','page_desc'])
  242. ->select()
  243. ->toArray();
  244. //设置缓存
  245. $HandleConcurrencyCache->setCache($HandleConcurrencyCache->getShareConfigKey(),$lists);
  246. return $lists;
  247. }
  248. }