common.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. // 应用公共文件
  12. if (!function_exists('unThumb')) {
  13. function unThumb($src)
  14. {
  15. return str_replace('/s_', '/', $src);
  16. }
  17. }
  18. /**
  19. *判断拼团是否结束*/
  20. function isPinkStatus($pink)
  21. {
  22. if (!$pink) return false;
  23. return \app\wap\model\store\StorePink::isSetPinkOver($pink);
  24. }
  25. /**
  26. * 设置浏览信息
  27. * @param $uid
  28. * @param int $product_id
  29. * @param int $cate
  30. * @param string $type
  31. * @param string $content
  32. * @param int $min
  33. */
  34. function setView($uid, $product_id = 0, $cate = 0, $type = '', $product_type = 'product', $content = '', $min = 20)
  35. {
  36. $Db = think\Db::name('store_visit');
  37. $view = $Db->where(['uid' => $uid, 'product_id' => $product_id, 'product_type' => $product_type])->field('count,add_time,id')->find();
  38. if ($view && $type != 'search') {
  39. $time = time();
  40. if (($view['add_time'] + $min) < $time) {
  41. $Db->where(['id' => $view['id']])->update(['count' => $view['count'] + 1, 'add_time' => time()]);
  42. }
  43. } else {
  44. $cate = explode(',', $cate)[0];
  45. $Db->insert([
  46. 'add_time' => time(),
  47. 'count' => 1,
  48. 'product_id' => $product_id,
  49. 'cate_id' => $cate,
  50. 'type' => $type,
  51. 'uid' => $uid,
  52. 'product_type' => $product_type,
  53. 'content' => $content
  54. ]);
  55. }
  56. }
  57. function Trust($URL)
  58. {
  59. $isSrc = false;
  60. if (is_array($URL)) {
  61. $URL = isset($URL[4]) ? $URL[4] : '';
  62. $isSrc = true;
  63. $URL = strpos($URL, 'src=') !== false ? substr($URL, 4) : $URL;
  64. }
  65. if ($URL == '') return '';
  66. $URL = str_replace(['"', '\''], '', $URL);
  67. $strKs3 = 'ks3-cn-beijing.ksyun.com/buttomsup';
  68. $strKs4 = 'ks3-cn-beijing.ksyun.com/learn';
  69. if (strpos($URL, $strKs3) !== false) {
  70. $strCdn = str_replace($strKs3, 'buttomsup.dounixue.net', $URL);
  71. } else {
  72. $strCdn = str_replace($strKs4, 'cdn.dounixue.net', $URL);
  73. }
  74. $strCdn = str_replace('https', 'http', $strCdn);
  75. $slhttp = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https:' : 'http:';
  76. if ($slhttp == 'https:') {
  77. $strCdn = str_replace('http', 'https', $strCdn);
  78. } elseif ($slhttp == 'http:') {
  79. $strCdn = str_replace('https', 'http', $strCdn);
  80. }
  81. $pathinfo = pathinfo($URL);
  82. $t = substr(time(), 0, 10);
  83. $k = substr(md5('ptteng' . urldecode($pathinfo['filename']) . $t), 0, 16);
  84. if ($isSrc) {
  85. return 'scr="' . $strCdn . "?k={$k}&t={$t}\"";
  86. } else {
  87. return $strCdn . "?k={$k}&t={$t}";
  88. }
  89. }
  90. /**
  91. * 图片处理
  92. * @param $link
  93. * @param int $type 1=大图,2=宫图,3=全图,4=小图
  94. * @return string
  95. */
  96. function get_oss_process($link, $type = 0)
  97. {
  98. switch ($type) {
  99. case 1:
  100. $link .= '?x-oss-process=image/resize,m_lfit,h_254,w_690';
  101. break;
  102. case 2:
  103. $link .= '?x-oss-process=image/resize,m_lfit,h_200,w_330';
  104. break;
  105. case 3:
  106. $link .= '?x-oss-process=image/resize,m_lfit,h_130,w_219';
  107. break;
  108. case 4:
  109. $link .= '?x-oss-process=image/resize,m_lfit,h_254,w_690';
  110. break;
  111. }
  112. return $link;
  113. }