新增部分接口路由,新增上报用户地址接口
This commit is contained in:
@@ -9,10 +9,12 @@ use App\Model\User;
|
||||
use App\Model\User as UserModel;
|
||||
use App\Model\UserDoctor;
|
||||
use App\Model\UserDoctorInfo;
|
||||
use App\Model\UserLocation;
|
||||
use App\Model\UserPatient;
|
||||
use App\Model\UserShipAddress;
|
||||
use App\Utils\Mask;
|
||||
use App\Utils\PcreMatch;
|
||||
use Extend\Tencent\map\Location;
|
||||
use Extend\TencentIm\Profile;
|
||||
use Extend\Wechat\Wechat;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
@@ -553,6 +555,71 @@ class UserService extends BaseService
|
||||
return success($popup->toArray());
|
||||
}
|
||||
|
||||
/**
|
||||
* 上报用户地址
|
||||
* @return array
|
||||
*/
|
||||
public function postLocation(): array
|
||||
{
|
||||
$user_info = $this->request->getAttribute("userInfo") ?? [];
|
||||
$request_params = $this->request->all();
|
||||
|
||||
if (empty($request_params['lon']) || empty($request_params['lat'])){
|
||||
return success();
|
||||
}
|
||||
|
||||
// 处理地址逆解析
|
||||
try {
|
||||
$location = new Location();
|
||||
$result = $location->getLocation($request_params['lon'],$request_params['lat']);
|
||||
if (empty($result)){
|
||||
return success();
|
||||
}
|
||||
|
||||
if (empty($result['address_component'])){
|
||||
return success();
|
||||
}
|
||||
|
||||
if (empty($result['address_component']['province']) || empty($result['address_component']['city'])){
|
||||
return success();
|
||||
}
|
||||
|
||||
// 处理需修改/新增数据
|
||||
$data = array();
|
||||
$data['lon'] = $request_params['lon'];
|
||||
$data['lat'] = $request_params['lat'];
|
||||
$data['province'] = $result['address_component']['province'];
|
||||
$data['city'] = $result['address_component']['city'];
|
||||
$data['county'] = $result['address_component']['district'] ?: "";
|
||||
$data['address'] = $result['address_component']['street_number'] ?: "";
|
||||
|
||||
// 获取用户地理位置
|
||||
$params = array();
|
||||
$params['user_id'] = $user_info['user_id'];
|
||||
$user_location = UserLocation::getOne($params);
|
||||
if (empty($user_location)){
|
||||
// 新增
|
||||
$data['user_id'] = $user_info['user_id'];
|
||||
$user_location = UserLocation::addUserLocation($data);
|
||||
if (empty($user_location)){
|
||||
return success();
|
||||
}
|
||||
}else{
|
||||
// 修改
|
||||
$params = array();
|
||||
$params['user_id'] = $user_info['user_id'];
|
||||
$res = UserLocation::editUserLocation($params,$data);
|
||||
if (!$res){
|
||||
return success();
|
||||
}
|
||||
}
|
||||
}catch (\Exception $e){
|
||||
return success();
|
||||
}
|
||||
|
||||
return success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过user_id获取用户openid
|
||||
* @param string|int $user_id
|
||||
|
||||
Reference in New Issue
Block a user