Commit 8908a842 by 杨树贤

地址补充接口完善

parent 4e77187f
......@@ -3,8 +3,9 @@
<component name="ChangeListManager">
<list default="true" id="fb90add0-1393-48c2-9f26-72365d42cd03" name="变更" comment="">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/app/Http/Controllers/Api/AuthApiController.php" beforeDir="false" afterPath="$PROJECT_DIR$/app/Http/Controllers/Api/AuthApiController.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/app/Models/UserModel.php" beforeDir="false" afterPath="$PROJECT_DIR$/app/Models/UserModel.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/app/Http/Controllers/Api/UserAddressApiController.php" beforeDir="false" afterPath="$PROJECT_DIR$/app/Http/Controllers/Api/UserAddressApiController.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/app/Http/Requests/UserAddressSave.php" beforeDir="false" afterPath="$PROJECT_DIR$/app/Http/Requests/UserAddressSave.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/app/Http/Services/UserAddressService.php" beforeDir="false" afterPath="$PROJECT_DIR$/app/Http/Services/UserAddressService.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/bootstrap/app.php" beforeDir="false" afterPath="$PROJECT_DIR$/bootstrap/app.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/bootstrap/cache/.gitignore" beforeDir="false" afterPath="$PROJECT_DIR$/bootstrap/cache/.gitignore" afterDir="false" />
<change beforePath="$PROJECT_DIR$/storage/app/.gitignore" beforeDir="false" afterPath="$PROJECT_DIR$/storage/app/.gitignore" afterDir="false" />
......@@ -188,7 +189,7 @@
<workItem from="1666835076791" duration="693000" />
<workItem from="1667266026118" duration="40321000" />
<workItem from="1667959054458" duration="183000" />
<workItem from="1667986756173" duration="3812000" />
<workItem from="1667986756173" duration="5340000" />
</task>
<servers />
</component>
......
......@@ -40,7 +40,8 @@ class UserAddressApiController extends Controller
'detail_address',
'city',
'province',
'post_code'
'post_code',
'is_default'
]);
$user = $request->user;
$result = UserAddressService::addUserAddress($address, $user);
......@@ -65,7 +66,8 @@ class UserAddressApiController extends Controller
'detail_address',
'city',
'province',
'post_code'
'post_code',
'is_default',
]);
$user = $request->user;
$result = UserAddressService::updateUserAddress($address, $user);
......
......@@ -24,8 +24,6 @@ class UserAddressSave extends BaseRequest
public function rules()
{
$rules = [
'email' => 'required|email',
'phone' => 'required|max:20',
'country' => 'required|max:64',
'province' => 'required|max:64',
'city' => 'required|max:64',
......@@ -35,6 +33,12 @@ class UserAddressSave extends BaseRequest
'detail_address' => 'required|max:255',
'post_code' => 'required|max:10',
];
$isRegister = request()->input('is_register');
if (!$isRegister) {
$rules['email'] = 'required|email';
$rules['phone'] = 'required|max:20';
}
if (request()->routeIs('user_address.update')) {
$rules['address_id'] = 'required';
}
......
......@@ -10,6 +10,11 @@ class UserAddressService
public static function addUserAddress($address, $user)
{
return DB::transaction(function () use ($address, $user) {
//如果没有邮箱和电话,就代表是注册的时候去新建的地址
if (empty($address['email']) && empty($address['phone'])) {
$address['email'] = $user->email;
$address['phone'] = $user->phone;
}
$address['user_id'] = $user->id;
$address['create_time'] = time();
return UserAddressModel::insert($address);
......@@ -19,9 +24,12 @@ class UserAddressService
public static function updateUserAddress($address, $user)
{
return DB::transaction(function () use ($address, $user) {
if ($address['is_default']) {
UserAddressModel::where('user_id', $user->id)->update(['is_default' => 0]);
}
$address['user_id'] = $user->id;
$address['create_time'] = time();
return UserAddressModel::where('address_id',$address['address_id'])->update($address);
return UserAddressModel::where('address_id', $address['address_id'])->update($address);
});
}
......
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