海南旅游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.

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