海南旅游SAAS
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
2.3 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. <?php
  2. namespace App\Http\Controllers\Api;
  3. use App\Models\Order;
  4. use Illuminate\Support\Facades\Cache;
  5. use Illuminate\Support\Facades\DB;
  6. use Illuminate\Support\Facades\Redis;
  7. /**
  8. * 仅用于测试
  9. * Class TController
  10. * @package App\Http\Controllers\Api
  11. */
  12. class TestController
  13. {
  14. public function index()
  15. {
  16. $redis_key = 'mini_program_set_host:' . substr(md5(env('APP_URL')), 0, 10);
  17. Redis::del($redis_key);
  18. }
  19. /**
  20. * 模拟登录
  21. * @param $user_id
  22. * @return string
  23. */
  24. private function login($user_id)
  25. {
  26. $token_key = md5($user_id . env('APP_KEY'));
  27. Cache::put($token_key, $user_id);
  28. return $token_key;
  29. }
  30. public function index2()
  31. {
  32. $handle = fopen(base_path('area.txt'), 'r');
  33. if ($handle) {
  34. DB::statement('TRUNCATE `areas`;');
  35. while (($line = fgets($handle, 4096)) !== false) {
  36. $line = trim($line);
  37. $last2 = substr($line, 4, 2); //区划码后2位
  38. $front2 = substr($line, 0, 2); //区划码前2位
  39. $front4 = substr($line, 0, 4); //区划码前4位
  40. //判断是否是直辖市,是直辖市则再插入一次上条记录作为二级联动
  41. if (isset($last4, $arr, $parent_arr[$front2]) && $last4 == '0000' && $last2 != '00') {
  42. $insert_id = DB::table('areas')->insertGetId(['code' => $arr[0], 'pid' => $parent_arr[$front2], 'name' => $arr[1]]);
  43. $parent_arr[$front4] = $insert_id;
  44. //对直辖市不做省直辖县处理,如:重庆市
  45. $parent_arr[$front2] = $insert_id;
  46. }
  47. $last4 = substr($line, 2, 4); //区划码后4位
  48. $arr = preg_split('/\s+/', $line);
  49. if (count($arr) !== 2) continue;
  50. if ($last4 == '0000') {
  51. $insert_id = DB::table('areas')->insertGetId(['code' => $arr[0], 'pid' => 0, 'name' => $arr[1]]);
  52. $parent_arr[$front2] = $insert_id;
  53. } else if ($last2 == '00') {
  54. $insert_id = DB::table('areas')->insertGetId(['code' => $arr[0], 'pid' => $parent_arr[$front2], 'name' => $arr[1]]);
  55. $parent_arr[$front4] = $insert_id;
  56. } else {
  57. //考虑到省直辖县级市情况,如:海南琼海市、湖北仙桃市等,但重庆市的省辖县除外(已在上面判断直辖市逻辑中做处理)
  58. $parent_id = $parent_arr[$front4] ?? $parent_arr[$front2];
  59. DB::table('areas')->insertGetId(['code' => $arr[0], 'pid' => $parent_id, 'name' => $arr[1]]);
  60. }
  61. }
  62. } else {
  63. return 'open file fail!';
  64. }
  65. return 'success';
  66. }}