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

99 lines
3.1 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\AdminSetting;
  4. use App\Models\AgentProduct;
  5. use App\Models\MiniProgramUploadLog;
  6. use EasyWeChat\Factory;
  7. use Illuminate\Support\Facades\Cache;
  8. use Illuminate\Support\Facades\DB;
  9. /**
  10. * 仅用于测试
  11. * Class TController
  12. * @package App\Http\Controllers\Api
  13. */
  14. class TestController
  15. {
  16. public function index()
  17. {
  18. $appid = 'wx5bd5789ad8f89524';
  19. $message = json_decode('{"ToUserName":"gh_f4ab40774bed","FromUserName":"o4seR5d-TVCImgh2aE6UtrQn6LIM","CreateTime":"1631670431","MsgType":"event","Event":"weapp_audit_success","SuccTime":"1631670431"}', true);
  20. DB::table('mini_program_events')
  21. ->insert([
  22. 'type' => 1,
  23. 'response' => json_encode($message),
  24. 'event' => $message['MsgType'] ?? '',
  25. 'created_at' => now()
  26. ]);
  27. //审核结果通知
  28. if (isset($message['MsgType'], $message['Event']) && $message['MsgType'] == 'event') {
  29. $auditArr = [
  30. 'weapp_audit_success' => 0, //成功
  31. 'weapp_audit_fail' => 1, //拒绝
  32. 'weapp_audit_delay' => 4, //审核延后
  33. ];
  34. $log = MiniProgramUploadLog::query()
  35. ->where('appid', $appid)
  36. ->orderBy('id', 'desc')
  37. ->first();
  38. $log->is_success = $auditArr[$message['Event']] ?? -1;
  39. $log->save();
  40. }
  41. }
  42. /**
  43. * 模拟登录
  44. * @param $user_id
  45. * @return string
  46. */
  47. private function login($user_id)
  48. {
  49. $token_key = md5($user_id . env('APP_KEY'));
  50. Cache::put($token_key, $user_id);
  51. return $token_key;
  52. }
  53. public function index2()
  54. {
  55. $handle = fopen(base_path('area.txt'), 'r');
  56. if ($handle) {
  57. DB::statement('TRUNCATE `areas`;');
  58. while (($line = fgets($handle, 4096)) !== false) {
  59. $line = trim($line);
  60. $last2 = substr($line, 4, 2); //区划码后2位
  61. $front2 = substr($line, 0, 2); //区划码前2位
  62. $front4 = substr($line, 0, 4); //区划码前4位
  63. //判断是否是直辖市,是直辖市则再插入一次上条记录作为二级联动
  64. if (isset($last4, $arr, $parent_arr[$front2]) && $last4 == '0000' && $last2 != '00') {
  65. $insert_id = DB::table('areas')->insertGetId(['code' => $arr[0], 'pid' => $parent_arr[$front2], 'name' => $arr[1]]);
  66. $parent_arr[$front4] = $insert_id;
  67. //对直辖市不做省直辖县处理,如:重庆市
  68. $parent_arr[$front2] = $insert_id;
  69. }
  70. $last4 = substr($line, 2, 4); //区划码后4位
  71. $arr = preg_split('/\s+/', $line);
  72. if (count($arr) !== 2) continue;
  73. if ($last4 == '0000') {
  74. $insert_id = DB::table('areas')->insertGetId(['code' => $arr[0], 'pid' => 0, 'name' => $arr[1]]);
  75. $parent_arr[$front2] = $insert_id;
  76. } else if ($last2 == '00') {
  77. $insert_id = DB::table('areas')->insertGetId(['code' => $arr[0], 'pid' => $parent_arr[$front2], 'name' => $arr[1]]);
  78. $parent_arr[$front4] = $insert_id;
  79. } else {
  80. //考虑到省直辖县级市情况,如:海南琼海市、湖北仙桃市等,但重庆市的省辖县除外(已在上面判断直辖市逻辑中做处理)
  81. $parent_id = $parent_arr[$front4] ?? $parent_arr[$front2];
  82. DB::table('areas')->insertGetId(['code' => $arr[0], 'pid' => $parent_id, 'name' => $arr[1]]);
  83. }
  84. }
  85. } else {
  86. return 'open file fail!';
  87. }
  88. return 'success';
  89. }}