index.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. include('core/function.php');
  3. $input = input('ma');
  4. if($input)
  5. {
  6. # 到数据库中查询有没有这个防伪码吧
  7. $db = db();
  8. $result = $db->field('id,company,pass,code,num')
  9. ->order('id desc')
  10. ->where('pass = ' . $input)
  11. ->limit(1,1)
  12. ->select('data');
  13. if($result && isset($result[0]) && isset($result[0]['id']))
  14. {
  15. # 搜索到了
  16. # 查询次数+1
  17. $sql = 'update data set num = num+1 where id = ' . $result[0]['id'];
  18. $db->doSql($sql);
  19. $pass = sp($result[0]['pass'], 1);
  20. $code = sp($result[0]['code'], 1);
  21. $i = 0;
  22. foreach($pass as $k => $v)
  23. {
  24. $result[0]['txt'][$i] = color($v, $code[$k], $i);
  25. $i++;
  26. }
  27. $result[0]['txt'] = implode('', $result[0]['txt']);
  28. }
  29. $company = $db->field('*')
  30. ->order('id desc')
  31. ->where('id = 1')
  32. ->limit(1,1)
  33. ->select('company');
  34. if($company)
  35. {
  36. $result[0]['ts1'] = $company[0]['ts1'];
  37. $result[0]['ts2'] = $company[0]['ts2'];
  38. }
  39. else
  40. {
  41. $result[0]['ts1'] = '该防伪码存在!';
  42. $result[0]['ts2'] = '该防伪码不存在!';
  43. }
  44. $result[0]['next'] = '';
  45. $time = time()+3600*24*365;
  46. $key = 'numv1_' . $input;
  47. $key_time = $key . '_time';
  48. if(isset($_COOKIE[$key]) && $_COOKIE[$key] > 1)
  49. {
  50. $first = $_COOKIE[$key_time];
  51. if($first > 0)
  52. {
  53. $first = date('Y/m/d H:i:s', $first);
  54. $result[0]['ts1'] = '该防伪码已于' . $first . '第一次被查询,本次为第' . $_COOKIE[$key] . '次查询,谨防假冒!The first time to query ' . $first;
  55. }
  56. else
  57. {
  58. $result[0]['ts1'] = '本次是您第'.$_COOKIE[$key].'次查询。';
  59. }
  60. }
  61. elseif(!isset($_COOKIE[$key]))
  62. {
  63. $_COOKIE[$key] = 1;
  64. setcookie($key_time, time(), $time);
  65. }
  66. setcookie($key, $_COOKIE[$key]+1, $time);
  67. $result[0]['search'] = $input;
  68. template('search', $result[0]);
  69. die;
  70. }
  71. template('index');