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

71 lines
2.6 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
  1. <?php
  2. namespace App\Http\Controllers\Api;
  3. use App\Models\Order;
  4. use App\Models\OrderProductItem;
  5. use App\Models\Product;
  6. /**
  7. * 仅用于测试
  8. * Class TController
  9. * @package App\Http\Controllers\Api
  10. */
  11. class TestController
  12. {
  13. public function index()
  14. {
  15. //test
  16. $ids = Order::orderBy('id')->get(['id AS order_id', 'product_ids', 'agent_id', 'agent_product_id']);
  17. foreach ($ids as $v) {
  18. $item = Product::query()->whereIn('id', explode(',', $v['product_ids']))
  19. ->orderBy('id')->get(['id AS product_id', 'supplier_id'])->toArray();
  20. foreach ($item as $v2) {
  21. if (!OrderProductItem::query()->where(['order_id' => $v['order_id'], 'product_id' => $v2['product_id']])->exists()) {
  22. $v2['order_id'] = $v['order_id'];
  23. $v2['agent_id'] = $v['agent_id'];
  24. $v2['agent_product_id'] = $v['agent_product_id'];
  25. OrderProductItem::query()->create($v2);
  26. }
  27. }
  28. }
  29. return '';
  30. }
  31. public function area()
  32. {
  33. $handle = fopen(Env::get('root_path').'2020-11行政区划(民政部).txt', 'r');
  34. if ($handle) {
  35. Db::execute('TRUNCATE `aqs_area`;');
  36. while (($line = fgets($handle, 4096)) !== false) {
  37. $line = trim($line);
  38. $last2 = substr($line, 4, 2); //区划码后2位
  39. $front2 = substr($line, 0, 2); //区划码前2位
  40. $front4 = substr($line, 0, 4); //区划码前4位
  41. //判断是否是直辖市,是直辖市则再插入一次上条记录作为二级联动
  42. if( isset($last4, $arr, $parent_arr[$front2]) && $last4=='0000' && $last2!='00' ) {
  43. $insert_id = Db::name('area')->insertGetId(['area_code'=>$arr[0], 'parent_id'=>$parent_arr[$front2], 'name'=>$arr[1]]);
  44. $parent_arr[$front4] = $insert_id;
  45. //对直辖市不做省直辖县处理,如:重庆市
  46. $parent_arr[$front2] = $insert_id;
  47. }
  48. $last4 = substr($line, 2, 4); //区划码后4位
  49. $arr = preg_split('/\s+/', $line);
  50. if( $last4 == '0000' ) {
  51. $insert_id = Db::name('area')->insertGetId(['area_code'=>$arr[0], 'parent_id'=>0, 'name'=>$arr[1]]);
  52. $parent_arr[$front2] = $insert_id;
  53. } else if( $last2 == '00' ) {
  54. $insert_id = Db::name('area')->insertGetId(['area_code'=>$arr[0], 'parent_id'=>$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::name('area')->insertGetId(['area_code'=>$arr[0], 'parent_id'=>$parent_id, 'name'=>$arr[1]]);
  60. }
  61. }
  62. }
  63. }}