common.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. // 应用公共文件
  12. /**
  13. * 敏感词过滤
  14. *
  15. * @param string
  16. * @return string
  17. */
  18. function sensitive_words_filter($str)
  19. {
  20. header('content-type:text/html;charset=utf-8');
  21. if (!$str) return '';
  22. $file = ROOT_PATH . 'public/static/plug/censorwords/CensorWords';
  23. $words = file($file);
  24. foreach ($words as $word) {
  25. $word = str_replace(array("\r\n", "\r", "\n", " "), '', $word);
  26. if (!$word) continue;
  27. $ret = @preg_match("/$word/", $str, $match);
  28. if ($ret) {
  29. return $match[0];
  30. }
  31. }
  32. return '';
  33. }
  34. function getController()
  35. {
  36. return strtolower(preg_replace('/((?<=[a-z])(?=[A-Z]))/', '_', think\Request::instance()->controller()));
  37. }
  38. function getModule()
  39. {
  40. return strtolower(preg_replace('/((?<=[a-z])(?=[A-Z]))/', '_', think\Request::instance()->module()));
  41. }
  42. function processingData($browse_count)
  43. {
  44. if ($browse_count > 9999) {
  45. $browse_count = bcdiv($browse_count, 10000, 1) . 'W';
  46. }
  47. return $browse_count;
  48. }
  49. /**
  50. * 获取图片库链接地址
  51. * @param $key
  52. * @return string
  53. */
  54. function get_image_Url($key)
  55. {
  56. return think\Url::build('admin/widget.images/index', ['fodder' => $key]);
  57. }
  58. /**
  59. * 获取链接对应的key
  60. * @param $value
  61. * @param bool $returnType
  62. * @param string $rep
  63. * @return array|string
  64. * @throws \think\db\exception\DataNotFoundException
  65. * @throws \think\db\exception\ModelNotFoundException
  66. * @throws \think\exception\DbException
  67. */
  68. function get_key_attr($value, $returnType = true, $rep = '')
  69. {
  70. if (!$value) return '';
  71. $inif = \app\admin\model\system\SystemAttachment::where('att_dir', $value)->find();
  72. if ($inif) {
  73. return [
  74. 'key' => $inif->name,
  75. 'pic' => $value,
  76. ];
  77. } else {
  78. if ($returnType) {
  79. return [
  80. 'key' => '',
  81. 'pic' => $value,
  82. ];
  83. } else {
  84. return [
  85. 'key' => '',
  86. 'pic' => '',
  87. ];
  88. }
  89. }
  90. }
  91. /**
  92. * 获取系统配置内容
  93. * @param $name
  94. * @param string $default
  95. * @return string
  96. */
  97. function get_config_content($name, $default = '')
  98. {
  99. try {
  100. return \app\admin\model\system\SystemConfigContent::getValue($name);
  101. } catch (\Throwable $e) {
  102. return $default;
  103. }
  104. }
  105. /**
  106. * 打印日志
  107. * @param $name
  108. * @param $data
  109. * @param int $type
  110. */
  111. function live_log($name, $data, $type = 8)
  112. {
  113. file_put_contents($name . '.txt', '[' . date('Y-m-d H:i:s', time()) . ']' . print_r($data, true) . "\r\n", $type);
  114. }
  115. /**获取当前登录用户的角色信息
  116. * @return mixed
  117. */
  118. function get_login_role()
  119. {
  120. $role['role_id'] = \think\Session::get("adminInfo")['roles'];
  121. $role['role_sign'] = \think\Session::get("adminInfo")['role_sign'];
  122. return $role;
  123. }
  124. /**获取登录用户账户信息
  125. * @return mixed
  126. */
  127. function get_login_id()
  128. {
  129. $admin['admin_id'] = \think\Session::get("adminId");
  130. return $admin;
  131. }
  132. function money_rate_num($money, $type)
  133. {
  134. if (!$money) $money = 0;
  135. if (!$type) return \service\JsonService::fail('非法参数2');
  136. switch ($type) {
  137. case "gold":
  138. $goldRate = \service\SystemConfigService::get("gold_rate");
  139. $num = bcmul($money, $goldRate, 0);
  140. return $num;
  141. default:
  142. return \service\JsonService::fail('汇率类型缺失');
  143. }
  144. }
  145. function getUrlToDomain()
  146. {
  147. $site_url = \service\SystemConfigService::get('site_url');
  148. if ($site_url == '') $site_url = $_SERVER['PHP_SELF'];
  149. $arr = parse_url($site_url);
  150. if (!isset($arr['host'])) $arr['host'] = $arr['path'];
  151. $array = explode('.', $arr['host']);
  152. return implode('_', $array);
  153. }
  154. if (!function_exists('filter_emoji')) {
  155. // 过滤掉emoji表情
  156. function filter_emoji($str)
  157. {
  158. preg_match_all('/[\x{4e00}-\x{9fff}\d\w\s[:punct:]]+/u', $str, $result);
  159. return join('', $result[0]);
  160. }
  161. }
  162. function lightTypeNmae($light_type)
  163. {
  164. switch ($light_type) {
  165. case 1:
  166. $type = '图文';
  167. break;
  168. case 2:
  169. $type = '音频';
  170. break;
  171. case 3:
  172. $type = '视频';
  173. break;
  174. }
  175. return $type;
  176. }
  177. //读取版本号
  178. function getversion()
  179. {
  180. $version_arr = [];
  181. $curent_version = @file(dirname(__DIR__) . '/.version');
  182. foreach ($curent_version as $val) {
  183. list($k, $v) = explode('=', $val);
  184. $version_arr[$k] = trim($v);
  185. }
  186. return $version_arr;
  187. }