Address.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. namespace app\model;
  3. use think\Model;
  4. class Address extends Model
  5. {
  6. protected $connection = 'mysql';
  7. protected $pk = 'id';
  8. protected $name = 'address';
  9. public static function getthefare($address_id, $technicalId)
  10. {
  11. $shipping = Address::find($address_id);
  12. $technical = Technical::getInfo($technicalId);
  13. $from['longitude'] = $technical['longitude'];
  14. $from['latitude'] = $technical['latitude'];
  15. $to['longitude'] = $shipping['longitude'];
  16. $to['latitude'] = $shipping['latitude'];
  17. if ($from['longitude'] && $from['latitude'] && $to['longitude'] && $to['latitude']) {
  18. $data["distance"] = Geocoder::get_distance($from, $to);
  19. if ($data["distance"]) {
  20. $Configthefare = Config::getconfig('thefare');
  21. if ($data["distance"] < (int)$Configthefare['startkm']) {
  22. $data["thefare"] = round($Configthefare['startat'], 2);
  23. } else {
  24. $data["thefare"] = $Configthefare['startat'];
  25. $data["thefare"] = round($data["thefare"] + (($data["distance"] - $Configthefare['startkm']) * $Configthefare['mileageprice']), 2);
  26. }
  27. }
  28. }
  29. return $data;
  30. }
  31. public static function geterrands($address_id, $take_address_id)
  32. {
  33. $addressdata = Address::find($address_id);
  34. if (!empty($addressdata)) {
  35. $addressdata = $addressdata->toArray();
  36. }
  37. $takeaddressdata = Address::find($take_address_id);
  38. if (!empty($takeaddressdata)) {
  39. $takeaddressdata = $takeaddressdata->toArray();
  40. }
  41. if ($addressdata['longitude'] && $addressdata['latitude'] && $takeaddressdata['longitude'] && $takeaddressdata['latitude']) {
  42. $from['longitude'] = $addressdata['longitude'];
  43. $from['latitude'] = $addressdata['latitude'];
  44. $to['longitude'] = $takeaddressdata['longitude'];
  45. $to['latitude'] = $takeaddressdata['latitude'];
  46. $data["distance"] = Geocoder::get_distance($from, $to);
  47. }
  48. if ($data["distance"]) {
  49. $errands = Config::getconfig('errands');
  50. if ($data["distance"] < (int) $errands['startkm']) {
  51. $data["amountTotle"] = round($errands['startat'], 2);
  52. } else {
  53. $data["amountTotle"] = $errands['startat'];
  54. $data["amountTotle"] = round($data["amountTotle"] + (($data["distance"] - $errands['startkm']) * $errands['mileageprice']), 2);
  55. }
  56. }
  57. return $data;
  58. }
  59. public static function Address2area($address)
  60. {
  61. preg_match('/(.*?(省|自治区|北京市|天津市|重庆市|上海市|香港特别行政区|澳门特别行政区))/', $address, $matches);
  62. if (count($matches) > 1) {
  63. $province = $matches[count($matches) - 2];
  64. $address = str_replace($province, '', $address);
  65. }
  66. preg_match('/(.*?(市|自治州|地区|区划))/', $address, $matches);
  67. if (count($matches) > 1) {
  68. $city = $matches[count($matches) - 2];
  69. $address = str_replace($city, '', $address);
  70. }
  71. preg_match('/(.*?(区|县))/', $address, $matches);
  72. if (count($matches) > 1) {
  73. $area = $matches[count($matches) - 2];
  74. $address = str_replace($area, '', $address);
  75. }
  76. return ['province_name' => isset($province) ? $province : '', 'city_name' => isset($city) ? $city : '', 'district_name' => isset($area) ? $area : '',];
  77. }
  78. }