ConfigLogic.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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. return [
  130. 'login_title' => ConfigService::get('shop', 'login_title', ''),
  131. 'login_content' => ConfigService::get('shop', 'login_content', '1')
  132. ];
  133. }
  134. /**
  135. * @notes 获取政策协议
  136. * @return array|string
  137. * @author Tab
  138. * @date 2021/7/28 16:08
  139. */
  140. public function getPolicyAgreement()
  141. {
  142. $params = request()->get();
  143. // 服务协议
  144. if (isset($params['type']) && $params['type'] == 1) {
  145. return [
  146. 'content' => ConfigService::get('shop', 'service_agreement_content', ''),
  147. 'name' => ConfigService::get('shop', 'service_agreement_name', ''),
  148. ];
  149. }
  150. // 隐私政策
  151. if (isset($params['type']) && $params['type'] == 2) {
  152. return [
  153. 'content' => ConfigService::get('shop', 'privacy_policy_content', ''),
  154. 'name' => ConfigService::get('shop', 'privacy_policy_name', ''),
  155. ];
  156. }
  157. // 分销协议
  158. if (isset($params['type']) && $params['type'] == 3) {
  159. $dbConfig = DistributionConfig::column('value', 'key');
  160. return [
  161. 'content' => $dbConfig['protocol_content'] ?? DistributionConfigEnum::DEFAULT_PROTOCOL_CONTENT,
  162. 'name' => $dbConfig['protocol_name'] ?? '分销协议',
  163. ];
  164. }
  165. //注销协议
  166. if (isset($params['type']) && $params['type'] == 4) {
  167. return [
  168. 'content' => ConfigService::get('shop', 'user_delete_content', ''),
  169. 'name' => ConfigService::get('shop', 'user_delete_name', ''),
  170. ];
  171. }
  172. return [ 'content' => '', 'name' => '' ];
  173. }
  174. /**
  175. * @notes 版权信息
  176. * @return array|int|mixed|string|null
  177. * @author ljj
  178. * @date 2022/2/22 11:49 上午
  179. */
  180. public function copyright()
  181. {
  182. return [
  183. 'copyright' => ConfigService::get('shop', 'copyright', ''),
  184. 'copyright2' => ConfigService::get('shop', 'copyright2', ''),
  185. 'copyright_auth' => ConfigService::get('shop', 'copyright_auth', []) ? : [
  186. 'type' => "1",
  187. 'list' => [
  188. [ 'image' => '', 'name' =>'', 'link' => '' ],
  189. ]
  190. ],
  191. ];
  192. }
  193. /**
  194. * @notes 获取客服配置
  195. * @return array
  196. * @author ljj
  197. * @date 2024/8/28 下午4:06
  198. */
  199. public function getKefuConfig()
  200. {
  201. $defaultData = [
  202. 'way' => 1,
  203. 'name' => '',
  204. 'remarks' => '',
  205. 'phone' => '',
  206. 'business_time' => '',
  207. 'qr_code' => '',
  208. 'enterprise_id' => '',
  209. 'kefu_link' => ''
  210. ];
  211. $config = [
  212. 'mnp' => ConfigService::get('kefu_config', 'mnp', $defaultData),
  213. 'oa' => ConfigService::get('kefu_config', 'oa', $defaultData),
  214. 'h5' => ConfigService::get('kefu_config', 'h5', $defaultData),
  215. 'pc' => ConfigService::get('kefu_config', 'pc', $defaultData),
  216. 'app' => ConfigService::get('kefu_config', 'app', $defaultData),
  217. ];
  218. if (!empty($config['mnp']['qr_code'])) $config['mnp']['qr_code'] = FileService::getFileUrl($config['mnp']['qr_code']);
  219. if (!empty($config['oa']['qr_code'])) $config['oa']['qr_code'] = FileService::getFileUrl($config['oa']['qr_code']);
  220. if (!empty($config['h5']['qr_code'])) $config['h5']['qr_code'] = FileService::getFileUrl($config['h5']['qr_code']);
  221. if (!empty($config['pc']['qr_code'])) $config['pc']['qr_code'] = FileService::getFileUrl($config['pc']['qr_code']);
  222. if (!empty($config['app']['qr_code'])) $config['app']['qr_code'] = FileService::getFileUrl($config['app']['qr_code']);
  223. return $config;
  224. }
  225. /**
  226. * @notes 获取分享配置
  227. * @return array
  228. * @throws \think\db\exception\DataNotFoundException
  229. * @throws \think\db\exception\DbException
  230. * @throws \think\db\exception\ModelNotFoundException
  231. * @author ljj
  232. * @date 2024/9/11 下午3:20
  233. */
  234. public function getShareConfig()
  235. {
  236. //读取缓存
  237. $HandleConcurrencyCache = new HandleConcurrencyCache();
  238. $lists = $HandleConcurrencyCache->getCache($HandleConcurrencyCache->getShareConfigKey());
  239. if ($lists !== false) {
  240. return $lists;
  241. }
  242. $lists = DevShare::field('*')
  243. ->append(['type_desc','page_desc'])
  244. ->select()
  245. ->toArray();
  246. //设置缓存
  247. $HandleConcurrencyCache->setCache($HandleConcurrencyCache->getShareConfigKey(),$lists);
  248. return $lists;
  249. }
  250. }