Commit 1dcd0214 by 赵增煜

Merge branch 'develop' of http://git.imohe.com/zhaozengyu/tzt-admin into develop

parents 5c577a59 a7704c1f
......@@ -24,6 +24,9 @@ public function test()
public function PharmacyList(Request $request)
{
$search_input = $request->input('search_input');
$lat = $request->input('lat');
$lng = $request->input('lng');
$distance = $request->input('distance_sort', 0); // 经纬度排序规则[0=从近到远,1=从远到近]
$query = PharmacyModel::query();
if ($search_input) {
$query->where('name', 'like', "%{$search_input}%");
......@@ -35,6 +38,15 @@ public function PharmacyList(Request $request)
->where('business_start', '<=', Carbon::now()->format('H:i'))
->where('business_end', '>=', Carbon::now()->format('H:i'));
if ($lat && $lng && is_numeric($lat) && is_numeric($lng)) {
$distancesql = " * , ACOS(SIN(( $lat * 3.1415) / 180 ) *SIN((lat * 3.1415) / 180 ) +COS(( $lat* 3.1415) / 180 ) * COS((lat * 3.1415) / 180 ) *COS(( $lng* 3.1415) / 180 - (lng * 3.1415) / 180 ) ) * 6380";
if ($distance_sort == 1) {
$query = $query->addSelect(DB::raw($distancesql.' as distance'))->orderBy('distance', 'DESC');
} else {
$query = $query->addSelect(DB::raw($distancesql.' as distance'))->orderBy('distance', 'ASC');
}
}
$data = $query->paginate(10);
return $this->success($data);
......
......@@ -3,6 +3,7 @@
namespace App\Api\Controllers;
use App\Http\Controllers\BaseApiController;
use App\Models\AdminUsers;
use App\Models\DoctorModel;
use App\Models\PharmacyModel;
use App\Models\User;
......@@ -138,14 +139,23 @@ public function bindRole(Request $request)
$mobile = $request->input('mobile');
$login_type = $request->input('login_type');
$code = $request->input('code');
if (! $mobile || ! $login_type || ! $code) {
return $this->failed('参数错误');
$password = $request->input('password'); // 只有药店登录会传passowrd
if (! $mobile) {
return $this->failed('请填写手机号');
}
if (! $login_type) {
return $this->failed('登录类型错误');
}
if (($login_type != User::LOGIN_TYPE_PHARMACY) && ! $code) {
return $this->failed('请填写短信验证码');
}
$verificationCode = cache()->get("sms_verification_code_{$mobile}");
if ($verificationCode != $code) {
return $this->failed('验证码错误,请重新获取!');
// 有密码说明是药店密码登录
if (! $password && ($verificationCode != $code)) {
return $this->failed('验证码错误,请重新发送!');
}
// 验证通过清除验证码
cache()->forget("sms_verification_code_{$mobile}");
......@@ -155,6 +165,15 @@ public function bindRole(Request $request)
if (! $pharmacy) {
return $this->failed('手机号不存在');
}
// 密码验证
if ($password) {
$adminUserInfo = AdminUsers::where('pharmacy_id', $pharmacy->id)->first();
$databasePassword = $adminUserInfo->password;
$flag = app('hash')->driver('bcrypt')->check($password, $databasePassword);
if (! $flag) {
return $this->failed('手机号或者密码错误!');
}
}
// 先把普通用户状态清除
if ($pharmacy->user_id > 0) {
$user = User::query()->find($pharmacy->user_id);
......
......@@ -15,7 +15,7 @@ class CheckRoleChangeMiddleware
public function handle($request, Closure $next)
{
$lastLoginType = auth('api')->user()->last_login_type;
$requestLastLoginType = $request->headers->get('last_login_type') ?: 0;
$requestLastLoginType = $request->headers->get('last-login-type') ?: 0;
if ($lastLoginType != $requestLastLoginType) {
return response()->json(['status' => false, 'code' => 600, 'message' => '您的角色切换错误~', 'data' => []]);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment