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

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