KefuConfigLogic.php 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. namespace app\adminapi\logic\kefu;
  20. use app\common\logic\BaseLogic;
  21. use app\common\service\ConfigService;
  22. use app\common\service\FileService;
  23. use think\facade\Db;
  24. class KefuConfigLogic extends BaseLogic
  25. {
  26. /**
  27. * @notes 获取
  28. * @return array
  29. * @author ljj
  30. * @date 2024/8/27 下午5:17
  31. */
  32. public static function getConfig()
  33. {
  34. $defaultData = [
  35. 'way' => '1',
  36. 'name' => '',
  37. 'remarks' => '',
  38. 'phone' => '',
  39. 'business_time' => '',
  40. 'qr_code' => '',
  41. 'enterprise_id' => '',
  42. 'kefu_link' => ''
  43. ];
  44. $config = [
  45. 'mnp' => ConfigService::get('kefu_config', 'mnp', $defaultData),
  46. 'oa' => ConfigService::get('kefu_config', 'oa', $defaultData),
  47. 'h5' => ConfigService::get('kefu_config', 'h5', $defaultData),
  48. 'pc' => ConfigService::get('kefu_config', 'pc', $defaultData),
  49. 'app' => ConfigService::get('kefu_config', 'app', $defaultData),
  50. ];
  51. if (!empty($config['mnp']['qr_code'])) $config['mnp']['qr_code'] = FileService::getFileUrl($config['mnp']['qr_code']);
  52. if (!empty($config['oa']['qr_code'])) $config['oa']['qr_code'] = FileService::getFileUrl($config['oa']['qr_code']);
  53. if (!empty($config['h5']['qr_code'])) $config['h5']['qr_code'] = FileService::getFileUrl($config['h5']['qr_code']);
  54. if (!empty($config['pc']['qr_code'])) $config['pc']['qr_code'] = FileService::getFileUrl($config['pc']['qr_code']);
  55. if (!empty($config['app']['qr_code'])) $config['app']['qr_code'] = FileService::getFileUrl($config['app']['qr_code']);
  56. return $config;
  57. }
  58. /**
  59. * @notes 设置
  60. * @param $params
  61. * @return string|true
  62. * @author ljj
  63. * @date 2024/8/27 下午5:17
  64. */
  65. public static function setConfig($params)
  66. {
  67. Db::startTrans();
  68. try {
  69. foreach($params as $key => $value) {
  70. if(!in_array($key, ['mnp','oa','h5','pc','app'])) {
  71. throw new \think\Exception('数据异常');
  72. }
  73. ConfigService::set('kefu_config', $key, $value);
  74. }
  75. // 提交事务
  76. Db::commit();
  77. return true;
  78. } catch (\Exception $e) {
  79. // 回滚事务
  80. Db::rollback();
  81. return $e->getMessage();
  82. }
  83. }
  84. }