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

82 lines
2.7 KiB

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