ForhelpController.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. namespace app\index\controller;
  3. use think\exception\ValidateException;
  4. use app\model\Forhelp;
  5. use app\model\Technical;
  6. use app\model\Geocoder;
  7. use app\model\UuidRelation;
  8. class ForhelpController extends Base
  9. {
  10. public function add()
  11. {
  12. $uuid = UuidRelation::getuuid(UID(), 'technical');
  13. $data = input('post.');
  14. $data['weid'] = weid();
  15. $data['uuid'] = $uuid;
  16. $data['username'] = Technical::getTitle($uuid);
  17. $data['tel'] = Technical::getTel($uuid);
  18. $data['title'] = $data['username'] . '发送了求助';
  19. $reverse = Geocoder::reverse_geocoding($data['latitude'], $data['longitude']);
  20. $data['province_name'] = $reverse['addressComponent']['province'];
  21. $data['city_name'] = $reverse['addressComponent']['city'];
  22. $data['district_name'] = $reverse['addressComponent']['district'];
  23. $data['dizhi'] = $reverse['formatted_address'];
  24. try {
  25. $res = Forhelp::create($data);
  26. } catch (\Exception $e) {
  27. throw new ValidateException($e->getMessage());
  28. }
  29. return $this->json(['msg' => '求助发送成功']);
  30. }
  31. }