Commit b9a9aaa0 by 杨树贤

优化地址存储国家的字段

parent 8908a842
...@@ -3,9 +3,8 @@ ...@@ -3,9 +3,8 @@
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="fb90add0-1393-48c2-9f26-72365d42cd03" name="变更" comment=""> <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$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" 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$/app/Http/Services/UserAddressService.php" beforeDir="false" afterPath="$PROJECT_DIR$/app/Http/Services/UserAddressService.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/app/Models/UserAddressModel.php" beforeDir="false" afterPath="$PROJECT_DIR$/app/Models/UserAddressModel.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/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$/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" /> <change beforePath="$PROJECT_DIR$/storage/app/.gitignore" beforeDir="false" afterPath="$PROJECT_DIR$/storage/app/.gitignore" afterDir="false" />
...@@ -189,7 +188,7 @@ ...@@ -189,7 +188,7 @@
<workItem from="1666835076791" duration="693000" /> <workItem from="1666835076791" duration="693000" />
<workItem from="1667266026118" duration="40321000" /> <workItem from="1667266026118" duration="40321000" />
<workItem from="1667959054458" duration="183000" /> <workItem from="1667959054458" duration="183000" />
<workItem from="1667986756173" duration="5340000" /> <workItem from="1667986756173" duration="5874000" />
</task> </task>
<servers /> <servers />
</component> </component>
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace App\Http\Services; namespace App\Http\Services;
use App\Models\CountryModel;
use App\Models\UserAddressModel; use App\Models\UserAddressModel;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
...@@ -37,15 +38,24 @@ class UserAddressService ...@@ -37,15 +38,24 @@ class UserAddressService
{ {
$address = UserAddressModel::select(['*'])->where('address_id', $addressId) $address = UserAddressModel::select(['*'])->where('address_id', $addressId)
->first()->toArray(); ->first()->toArray();
$address['country'] = CountryModel::where('id', $address['country'])->value('name');
return $address; return $address;
} }
public static function getUserAddressList($userId) public static function getUserAddressList($userId)
{ {
$query = UserAddressModel::where('user_id', $userId)->orderBy('address_id', 'desc'); $query = UserAddressModel::with([
'country' => function ($q) {
$q->select([
'id',
'name',
]);
}
])->where('user_id', $userId)->orderBy('address_id', 'desc');
$result = $query->paginate(10)->toArray(); $result = $query->paginate(10)->toArray();
foreach ($result['data'] as &$item) { foreach ($result['data'] as &$item) {
$item['create_time'] = date('Y-m-d H:i:s', $item['create_time']); $item['create_time'] = date('Y-m-d H:i:s', $item['create_time']);
$item['country'] = \Arr::get($item['country'], 'name');
} }
unset($item); unset($item);
return $result; return $result;
......
...@@ -19,4 +19,9 @@ class UserAddressModel extends Model ...@@ -19,4 +19,9 @@ class UserAddressModel extends Model
return $this->belongsTo(UserModel::class); return $this->belongsTo(UserModel::class);
} }
public function country()
{
return $this->hasOne(CountryModel::class, 'id', 'country');
}
} }
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