CityService.php 912 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. namespace App\Http\Services\V1;
  3. use App\Generated\V1\Messages\City\SearchMessage;
  4. use App\Generated\V1\Messages\City\GetListMessage;
  5. use App\Models\Common\CityModel;
  6. class CityService
  7. {
  8. /**
  9. * 城市列表
  10. * @param GetListMessage $message
  11. */
  12. public function getList(GetListMessage $message)
  13. {
  14. $provinces = CityModel::groupBy("province")->pluck('province');
  15. $data = array();
  16. foreach ($provinces as $province) {
  17. $data[$province] = CityModel::where("province", $province)->pluck('city');
  18. }
  19. $message->setResponse($data);
  20. }
  21. /**
  22. * 城市搜索
  23. * @param SearchMessage $message
  24. */
  25. public function search(SearchMessage $message)
  26. {
  27. $keyword = $message->getKeyword();
  28. $citys = CityModel::where("city", "like", "%{$keyword}%")->get();
  29. $message->setResponse($citys);
  30. }
  31. }