Commit da4bb473 by 杨树贤

地址管理相关接口以及国家数据

parent fcc22723
......@@ -3,8 +3,12 @@
<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/Http/Services/InquiryService.php" beforeDir="false" afterPath="$PROJECT_DIR$/app/Http/Services/InquiryService.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/Controllers/Api/UserApiController.php" beforeDir="false" afterPath="$PROJECT_DIR$/app/Http/Controllers/Api/UserApiController.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/app/Http/Controllers/UserAddressesController.php" beforeDir="false" afterPath="$PROJECT_DIR$/app/Http/Controllers/UserAddressController.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/app/Http/Requests/BaseRequest.php" beforeDir="false" afterPath="$PROJECT_DIR$/app/Http/Requests/BaseRequest.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/app/Http/Requests/UserRegister.php" beforeDir="false" afterPath="$PROJECT_DIR$/app/Http/Requests/UserRegister.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$/routes/api.php" beforeDir="false" afterPath="$PROJECT_DIR$/routes/api.php" 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/public/.gitignore" beforeDir="false" afterPath="$PROJECT_DIR$/storage/app/public/.gitignore" afterDir="false" />
......@@ -150,18 +154,18 @@
<property name="RunOnceActivity.OpenProjectViewOnStart" value="true" />
<property name="RunOnceActivity.ShowReadmeOnStart" value="true" />
<property name="WebServerToolWindowFactoryState" value="false" />
<property name="last_opened_file_path" value="$PROJECT_DIR$/app/Http/Controllers/Api" />
<property name="last_opened_file_path" value="$PROJECT_DIR$/app/Http/Services" />
<property name="nodejs_interpreter_path.stuck_in_default_project" value="undefined stuck path" />
<property name="nodejs_package_manager_path" value="npm" />
<property name="vue.rearranger.settings.migration" value="true" />
</component>
<component name="RecentsManager">
<key name="CopyFile.RECENT_KEYS">
<recent name="\\wsl$\Ubuntu-20.04\data\www\semour_web\app\Http\Services" />
<recent name="\\wsl$\Ubuntu-20.04\data\www\semour_web\app\Http\Controllers\Api" />
<recent name="\\wsl$\Ubuntu-20.04\data\www\semour_web\app\Models" />
<recent name="\\wsl$\Ubuntu-20.04\data\www\semour_web\resources\views" />
<recent name="\\wsl$\Ubuntu-20.04\data\www\semour_web\resources\views\sku" />
<recent name="\\wsl$\Ubuntu-20.04\data\www\semour_web\resources\views\mall" />
<recent name="\\wsl$\Ubuntu-20.04\data\www\semour_web\app\Http\Controllers" />
</key>
<key name="MoveFile.RECENT_KEYS">
<recent name="\\wsl$\Ubuntu-20.04\data\www\semour_web\resources\views\home" />
......@@ -184,7 +188,7 @@
<updated>1666170258203</updated>
<workItem from="1666170260162" duration="17108000" />
<workItem from="1666835076791" duration="693000" />
<workItem from="1667266026118" duration="31053000" />
<workItem from="1667266026118" duration="39423000" />
</task>
<servers />
</component>
......
<?php
namespace App\Http\Controllers\Api;
use App\Http\Requests\InquirySave;
use App\Http\Services\CountryService;
use App\Http\Services\InquiryService;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
class CountryApiController extends Controller
{
public function list(Request $request)
{
$data = CountryService::getCountryList();
return $this->setSuccessData($data['data'], $data['total']);
}
}
......@@ -2,11 +2,89 @@
namespace App\Http\Controllers\Api;
use App\Http\Requests\UserAddressSave;
use App\Http\Services\UserAddressService;
use App\Models\UserAddressModel;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Http\Request;
class UserAddressApiController extends Controller
{
public function list(Request $request)
{
$userId = $request->user->id;
$data = UserAddressService::getUserAddressList($userId);
return $this->setSuccessData($data['data'], $data['total']);
}
public function detail(Request $request)
{
$addressId = $request->input('address_id');
$data = UserAddressService::getUserAddressDetail($addressId);
return $this->setSuccessData($data);
}
public function add(UserAddressSave $request)
{
$address = $request->only([
'email',
'phone',
'country',
'address_type',
'last_name',
'first_name',
'company_name',
'detail_address',
'city',
'province',
'post_code'
]);
$user = $request->user;
$result = UserAddressService::addUserAddress($address, $user);
if (!$result) {
return $this->setError('Add user address failed');
}
return $this->setSuccess('Add user address success');
}
public function update(UserAddressSave $request)
{
$address = $request->only([
'address_id',
'email',
'phone',
'country',
'address_type',
'last_name',
'first_name',
'company_name',
'detail_address',
'city',
'province',
'post_code'
]);
$user = $request->user;
$result = UserAddressService::updateUserAddress($address, $user);
if (!$result) {
return $this->setError('Update user address failed');
}
return $this->setSuccess('Update user address success');
}
public function delete(Request $request)
{
$addressId = $request->input('address_id');
$result = UserAddressModel::where('address_id',$addressId)->delete();
if (!$result) {
return $this->setError('Delete user address failed');
}
return $this->setSuccess('Delete user address success');
}
}
......@@ -2,6 +2,7 @@
namespace App\Http\Controllers\Api;
use App\Http\Requests\UserUpdate;
use App\Models\UserModel;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
......@@ -30,7 +31,7 @@ class UserApiController extends Controller
return $this->setSuccessData($user);
}
public function update(Request $request)
public function update(UserUpdate $request)
{
$data = $request->only([
'account_properties',
......@@ -38,15 +39,14 @@ class UserApiController extends Controller
'first_name',
'last_name',
]);
$id = $request->user->id;
$data['update_time'] = time();
$result = UserModel::where('id', $id)->update($data);
if (!$result) {
return $this->setError('Save user info failed');
return $this->setError('Update user info failed');
}
return $this->setSuccess('Save user info success');
return $this->setSuccess('Update user info success');
}
public function changePhone(Request $request)
......@@ -81,7 +81,8 @@ class UserApiController extends Controller
$email = $request->input('email');
$validator = Validator::make($request->all(), [
'email' => 'required|email',
'password' => 'required|max:100'
'password' => 'required|max:100',
'email_code' => 'required'
]);
if ($validator->fails()) {
......
......@@ -4,10 +4,10 @@ namespace App\Http\Controllers;
use Illuminate\Http\Request;
class UserAddressesController extends Controller
class UserAddressController extends Controller
{
public function index(Request $request)
{
return view('user_addresses.index');
return view('user_address.index');
}
}
......@@ -40,11 +40,7 @@ class BaseRequest extends FormRequest
public function __get($key)
{
if ($key == 'user') {
return request()->get('user');
}
if ($key == 'perms') {
return request()->get('perms');
return request()->user;
}
}
......
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class UserAddressSave extends BaseRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
$rules = [
'email' => 'required|email',
'phone' => 'required|max:20',
'country' => 'required|max:64',
'province' => 'required|max:64',
'city' => 'required|max:64',
'last_name' => 'required|max:50',
'first_name' => 'required|max:50',
'company_name' => 'required|max:50',
'detail_address' => 'required|max:255',
'post_code' => 'required|max:10',
];
if (request()->routeIs('user_address.update')) {
$rules['address_id'] = 'required';
}
return $rules;
}
}
......@@ -27,11 +27,11 @@ class UserRegister extends BaseRequest
[
'email' => 'required|string|email|max:100',
'password' => 'required|string|min:8|confirmed',
'first_name' => 'required|max:100',
'last_name' => 'required|max:100',
'email_code' => 'required|max:100',
'first_name' => 'required|max:50',
'last_name' => 'required|max:50',
'email_code' => 'required|max:10',
'phone' => 'required|max:100',
'company_name' => 'required|max:100',
'company_name' => 'required|max:50',
]
];
}
......
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class UserUpdate extends BaseRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'account_properties' => 'required|in:1,2',
'company_name' => 'required|max:50',
'first_name' => 'required|max:50',
'last_name' => 'required|max:50',
];
}
}
<?php
namespace App\Http\Services;
use App\Models\CountryModel;
class CountryService
{
public static function getCountryList()
{
$result = CountryModel::paginate(10)->toArray();
return $result;
}
}
<?php
namespace App\Http\Services;
use App\Models\UserAddressModel;
use Illuminate\Support\Facades\DB;
class UserAddressService
{
public static function addUserAddress($address, $user)
{
return DB::transaction(function () use ($address, $user) {
$address['user_id'] = $user->id;
$address['create_time'] = time();
return UserAddressModel::insert($address);
});
}
public static function updateUserAddress($address, $user)
{
return DB::transaction(function () use ($address, $user) {
$address['user_id'] = $user->id;
$address['create_time'] = time();
return UserAddressModel::where('address_id',$address['address_id'])->update($address);
});
}
public static function getUserAddressDetail($addressId)
{
$address = UserAddressModel::select(['*'])->where('address_id', $addressId)
->first()->toArray();
return $address;
}
public static function getUserAddressList($userId)
{
$query = UserAddressModel::where('user_id', $userId)->orderBy('address_id', 'desc');
$result = $query->paginate(10)->toArray();
foreach ($result['data'] as &$item) {
$item['create_time'] = date('Y-m-d H:i:s', $item['create_time']);
}
unset($item);
return $result;
}
}
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class CountryModel extends Model
{
protected $table = 'country';
public $timestamps = false;
}
......@@ -8,6 +8,8 @@ class UserAddressModel extends Model
{
protected $table = 'user_address';
public $timestamps = false;
//
protected $fillable = [
];
......
......@@ -27,9 +27,21 @@ Route::middleware(['api', 'api.check'])->namespace('Api')->group(function () {
Route::POST('auth/send_email_code', 'AuthApiController@sendEmailCode');
Route::get('user/info', 'UserApiController@info');
Route::POST('user/update', 'UserApiController@update');
Route::POST('user/change_phone', 'UserApiController@changePhone');
Route::POST('user/change_email', 'UserApiController@changeEmail');
Route::POST('inquiry/add', 'InquiryApiController@add');
Route::GET('inquiry/list', 'InquiryApiController@list');
Route::GET('inquiry/detail', 'InquiryApiController@detail');
Route::get('user_address/list', 'UserAddressApiController@list');
Route::get('user_address/detail', 'UserAddressApiController@detail')->name('user_address.detail');
Route::POST('user_address/add', 'UserAddressApiController@add')->name('user_address.add');
Route::POST('user_address/update', 'UserAddressApiController@update')->name('user_address.update');
Route::POST('user_address/delete', 'UserAddressApiController@delete')->name('user_address.delete');
Route::get('country/list', 'CountryApiController@list');
Route::ANY('inquiry/add', 'InquiryApiController@add');
Route::ANY('inquiry/list', 'InquiryApiController@list');
Route::ANY('inquiry/detail', 'InquiryApiController@detail');
});
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