VerifyCodeController.class.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <?php
  2. /**
  3. * author xtj
  4. * intro 二维码验证类
  5. */
  6. namespace Admin\Controller;
  7. class VerifyCodeController extends AdminController
  8. {
  9. /**
  10. * author xtj
  11. * intro 类初始化方法
  12. * param
  13. * return
  14. */
  15. public function _initialize()
  16. {
  17. parent::_initialize();
  18. }
  19. //TODO 废弃的方法
  20. public function index()
  21. {
  22. /*if (!empty(I('get.bach_id'))) {*/
  23. /* for ($i = 0; $i < 5; $i++) {*/
  24. $this->verifyUrl();
  25. /* }*/
  26. /* }*/
  27. }
  28. //TODO 废弃的方法
  29. public function verifyUrl()
  30. {
  31. $arr = array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z');
  32. $sum = '';
  33. foreach ($arr as $k => $v) {
  34. $sum += M('codes_' . $v)->count();
  35. /*if (getStatusCode(M('codes_' . $v)->where(array('bach_id' => $bach_id))->getField('code'))==404) {
  36. M('VerifyCodeLog')->save(array('bach_id' => $bach_id, 'table' => 'codes_' . $v,));//记录异常数据
  37. }*/
  38. }
  39. echo $sum;
  40. }
  41. public function lock()
  42. {
  43. if (file_exists('./lock')) {
  44. echo '文件被锁定';
  45. exit;
  46. } else {
  47. @touch('./lock');
  48. echo '文件已锁定';
  49. }
  50. }
  51. public function fenbiao()
  52. {
  53. $this->lock();
  54. $CodeMode = M('codes');
  55. if (empty(S('fenbiao_page'))) {
  56. $now_page = S('fenbiao_page', 0);
  57. } else {
  58. $now_page = S('fenbiao_page');
  59. }
  60. echo '当前第' . $now_page . '页<br/>';
  61. if (empty(S('fenbiao_data'))) {
  62. $data = $CodeMode->order('id asc')->limit(0, 10000)->select();
  63. S('fenbiao_data', $data);
  64. } else {
  65. $data = S('fenbiao_data');
  66. }
  67. $t1 = microtime(true);
  68. if (!empty($data)) {
  69. $Model = M(); // 实例化一个空对象
  70. $Model->startTrans(); // 开启事务
  71. $i = 0;
  72. $codes_id = '';
  73. foreach ($data as $key => $value) {
  74. $table_name = getSubTable('codes', $value['code']);
  75. $where_str = '';
  76. $field_str = '';
  77. $j = 0;
  78. foreach ($value as $kk => $vv) {
  79. if ($j == count($value) - 1) {
  80. $field_str .= "`" . $kk . "`";
  81. $where_str .= "'" . $vv . "'";
  82. } else {
  83. $field_str .= "`" . $kk . "`,";
  84. $where_str .= "'" . $vv . "',";
  85. }
  86. $j++;
  87. }
  88. $sql = "INSERT ignore INTO `$table_name` ($field_str) VALUES ($where_str)";
  89. $Model->execute($sql);
  90. $i++;
  91. $codes_id .= $value['id'] . ',';
  92. if ($i % 200 == 0) {
  93. $codes_id = rtrim($codes_id, ',');
  94. $Model->table('qr_codes')->delete($codes_id);
  95. $codes_id = '';
  96. }
  97. }
  98. if ($i == count($data)) {
  99. $Model->commit(); // 成功则提交事务
  100. unlink('./lock');//删除文件锁定
  101. S('fenbiao_page', $now_page = $now_page + 1);
  102. $t2 = microtime(true);
  103. S('fenbiao_data', NULL);
  104. echo $t2 - $t1 . 's';
  105. } else {
  106. $Model->rollback(); // 否则将事务回滚
  107. }
  108. }
  109. }
  110. public function checkUrl()
  111. {
  112. $lines = file("./url.txt");
  113. foreach ($lines as $line) {
  114. $line = rtrim($line);
  115. $code_status = getStatusCode($line);
  116. if ($code_status == 404) {
  117. echo $line . "<br/>";
  118. } else {
  119. echo $code_status . "<br/>";
  120. }
  121. }
  122. }
  123. }