|
|
|
|
@ -3,9 +3,12 @@
|
|
|
|
|
namespace App\Http\Controllers\Api;
|
|
|
|
|
|
|
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
|
use App\Models\Reservation;
|
|
|
|
|
use App\Models\WechatUser;
|
|
|
|
|
use Illuminate\Http\JsonResponse;
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
|
|
|
|
|
|
class H5ProfileController extends Controller
|
|
|
|
|
{
|
|
|
|
|
public function show(Request $request): JsonResponse
|
|
|
|
|
@ -36,12 +39,23 @@ class H5ProfileController extends Controller
|
|
|
|
|
'avatar_url' => ['nullable', 'string', 'max:500'],
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$user->real_name = $data['real_name'];
|
|
|
|
|
$user->phone = $data['phone'];
|
|
|
|
|
if (array_key_exists('avatar_url', $data) && $data['avatar_url'] !== null && $data['avatar_url'] !== '') {
|
|
|
|
|
$user->avatar_url = $data['avatar_url'];
|
|
|
|
|
}
|
|
|
|
|
$user->save();
|
|
|
|
|
$phone = $data['phone'];
|
|
|
|
|
|
|
|
|
|
DB::transaction(function () use ($user, $data, $phone): void {
|
|
|
|
|
$user->real_name = $data['real_name'];
|
|
|
|
|
$user->phone = $phone;
|
|
|
|
|
if (array_key_exists('avatar_url', $data) && $data['avatar_url'] !== null && $data['avatar_url'] !== '') {
|
|
|
|
|
$user->avatar_url = $data['avatar_url'];
|
|
|
|
|
}
|
|
|
|
|
$user->save();
|
|
|
|
|
|
|
|
|
|
// 曾无微信态预约(wechat_user_id 为空):资料里手机号与 visitor_phone 一致时补绑到当前微信号;已有 wechat_user_id 的订单永不覆盖
|
|
|
|
|
Reservation::query()
|
|
|
|
|
->whereNull('wechat_user_id')
|
|
|
|
|
->whereNotNull('visitor_phone')
|
|
|
|
|
->where('visitor_phone', $phone)
|
|
|
|
|
->update(['wechat_user_id' => $user->id]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return response()->json([
|
|
|
|
|
'message' => '保存成功',
|
|
|
|
|
|