Commit ab5dd96d by 杨树贤

用户模型修改

parent b35f33bd
......@@ -3,9 +3,20 @@
<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/Controllers/Api/InquiryApiController.php" beforeDir="false" afterPath="$PROJECT_DIR$/app/Http/Controllers/Api/InquiryApiController.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/app/Http/Controllers/Auth/RegisterController.php" beforeDir="false" afterPath="$PROJECT_DIR$/app/Http/Controllers/Auth/RegisterController.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/Models/Inquiry.php" beforeDir="false" afterPath="$PROJECT_DIR$/app/Models/Inquiry.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/app/Models/Inquiry.php" beforeDir="false" afterPath="$PROJECT_DIR$/app/Models/InquiryModel.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/app/Models/InquiryItems.php" beforeDir="false" afterPath="$PROJECT_DIR$/app/Models/InquiryItemsModel.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/app/Models/User.php" beforeDir="false" afterPath="$PROJECT_DIR$/app/Models/UserModel.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/app/Models/UserAddress.php" beforeDir="false" afterPath="$PROJECT_DIR$/app/Models/UserAddressModel.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/config/auth.php" beforeDir="false" afterPath="$PROJECT_DIR$/config/auth.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/config/field.php" beforeDir="false" afterPath="$PROJECT_DIR$/config/field.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/database/factories/UserAddressFactory.php" beforeDir="false" afterPath="$PROJECT_DIR$/database/factories/UserAddressFactory.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/database/factories/UserFactory.php" beforeDir="false" afterPath="$PROJECT_DIR$/database/factories/UserFactory.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/database/seeds/UserAddressSeeder.php" beforeDir="false" afterPath="$PROJECT_DIR$/database/seeds/UserAddressSeeder.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" />
<change beforePath="$PROJECT_DIR$/storage/framework/.gitignore" beforeDir="false" afterPath="$PROJECT_DIR$/storage/framework/.gitignore" afterDir="false" />
......@@ -184,7 +195,7 @@
<updated>1666170258203</updated>
<workItem from="1666170260162" duration="17108000" />
<workItem from="1666835076791" duration="693000" />
<workItem from="1667266026118" duration="22846000" />
<workItem from="1667266026118" duration="25211000" />
</task>
<servers />
</component>
......
......@@ -3,7 +3,7 @@
namespace App\Http\Controllers\Api;
use App\Http\Requests\UserRegister;
use App\Models\User;
use App\Models\UserModel;
use Illuminate\Foundation\Auth\RegistersUsers;
use Illuminate\Foundation\Auth\ThrottlesLogins;
use Illuminate\Http\Request;
......@@ -21,7 +21,7 @@ class AuthApiController extends Controller
public function register(UserRegister $request)
{
$email = $request->input('email');
if (User::where('email', $email)->exists()) {
if (UserModel::where('email', $email)->exists()) {
return $this->setError('Email has been taken');
}
......@@ -31,7 +31,7 @@ class AuthApiController extends Controller
if ($cachedEmailCode != $request->input('email_code')) {
return $this->setError('Email code invalid');
}
$user = User::createUser($request->all());
$user = UserModel::createUser($request->all());
\Auth::login($user);
return $this->setSuccess('Register success');
......@@ -51,7 +51,7 @@ class AuthApiController extends Controller
return $this->setError($validator->errors()->first());
}
$userExists = User::where('email', $request->email)->exists();
$userExists = UserModel::where('email', $request->email)->exists();
if (!$userExists) {
return $this->setError('User dose not exist');
}
......@@ -90,12 +90,12 @@ class AuthApiController extends Controller
$password = $request->get('password');
$oldPassword = $request->get('old_password');
$userId = Auth::user()->id;
$hashedPassword = User::where('id', $userId)->value('password');
$hashedPassword = UserModel::where('id', $userId)->value('password');
if (!Hash::check($oldPassword, $hashedPassword)) {
return $this->setError('Wrong Password!');
}
$user = User::find($userId);
$user = UserModel::find($userId);
$user->password = Hash::make($password);
$user->update_time = time();
$result = $user->save();
......@@ -114,7 +114,7 @@ class AuthApiController extends Controller
if (!$email) {
return $this->setError('Email address required');
}
$info = User::where('email', $email)->first();
$info = UserModel::where('email', $email)->first();
if ($info && $type == 'register') {
return $this->setError('This email had been registered');
}
......
......@@ -27,12 +27,19 @@ class InquiryApiController extends Controller
return $this->setSuccess('Add inquiry success');
}
public function lists(Request $request)
public function list(Request $request)
{
$searchKeyWord = $request->input('keyword');
$status = $request->input('status');
$userId = $request->user->id;
$result = InquiryService::getInquiryList($userId,$searchKeyWord, $status);
return $this->setSuccessData($result);
return $this->setSuccessData($result['data'],$result['total']);
}
public function detail(Request $request)
{
$inquiryId = $request->input('inquiry_id');
$inquiry = InquiryService::getInquiryDetail($inquiryId);
return $this->setSuccessData($inquiry);
}
}
......@@ -3,7 +3,7 @@
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use App\Models\User;
use App\Models\UserModel;
use App\Providers\RouteServiceProvider;
use Illuminate\Foundation\Auth\RegistersUsers;
use Illuminate\Support\Facades\Hash;
......@@ -60,11 +60,11 @@ class RegisterController extends Controller
* Create a new user instance after a valid registration.
*
* @param array $data
* @return \App\Models\User
* @return \App\Models\UserModel
*/
protected function create(array $data)
{
return User::create([
return UserModel::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => Hash::make($data['password']),
......
......@@ -2,8 +2,8 @@
namespace App\Http\Services;
use App\Models\Inquiry;
use App\Models\InquiryItems;
use App\Models\InquiryModel;
use App\Models\InquiryItemsModel;
use Illuminate\Support\Facades\DB;
class InquiryService
......@@ -19,7 +19,7 @@ class InquiryService
'remark' => $remark,
'create_time' => time(),
];
$inquiryId = Inquiry::addInquiry($inquiry);
$inquiryId = InquiryModel::addInquiry($inquiry);
$inquiryItems = [];
foreach ($items as $item) {
$inquiryItems[] = [
......@@ -31,16 +31,44 @@ class InquiryService
'create_time' => $item['create_time'],
];
}
return InquiryItems::addInquiryItems($inquiryItems);
return InquiryItemsModel::addInquiryItems($inquiryItems);
});
}
public function getInquiryList($userId,$searchKeyWord,$status)
public static function getInquiryDetail($inquiryId)
{
$query = Inquiry::where('user_id',$userId)->orderBy('inquiry_id', 'desc');
$inquiry = InquiryModel::where('inquiry_id', $inquiryId)->first()->toArray();
$inquiryItems = InquiryItemsModel::where('inquiry_id', $inquiryId)->get()->toArray();
$inquiry['items'] = $inquiryItems;
return $inquiry;
}
public static function getInquiryList($userId, $searchKeyWord, $status)
{
$query = InquiryModel::with('inquiry_items')->select([
'inquiry_id',
'inquiry_sn',
'create_time',
'remark',
'status'
])->where('user_id', $userId)->orderBy('inquiry_id', 'desc');
if (!empty($searchKeyWord)) {
// $query->where('goods_name')
$query->whereHas('inquiry_items', function ($q) use ($searchKeyWord) {
$q->where('goods_name', $searchKeyWord);
});
}
if (!empty($status)) {
$query->where('status', $status);
}
$result = $query->paginate(10)->toArray();
foreach ($result['data'] as &$item) {
$item['create_time'] = date('Y-m-d H:i:s', $item['create_time']);
$item['status_name'] = \Arr::get(config('field.inquiry_status'), $item['status']);
$item['goods_name'] = \Arr::get(\Arr::get($item['inquiry_items'], 0), 'goods_name', '');
unset($item['inquiry_items']);
}
unset($item);
return $result;
}
}
......@@ -4,8 +4,11 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class InquiryItems extends Model
class InquiryItemsModel extends Model
{
protected $table = 'inquiry_items';
public $timestamps = false;
public static function addInquiryItems($inquiryItems = [])
......
......@@ -4,14 +4,16 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Inquiry extends Model
class InquiryModel extends Model
{
//
protected $table = 'inquiry';
public $timestamps = false;
public function inquiry_items()
{
return $this->hasMany(InquiryItems::class, 'inquiry_id', 'inquiry_id');
return $this->hasMany(InquiryItemsModel::class, 'inquiry_id', 'inquiry_id');
}
public static function addInquiry($inquiry)
......
......@@ -4,15 +4,17 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class UserAddress extends Model
class UserAddressModel extends Model
{
protected $table = 'user_address';
//
protected $fillable = [
];
public function user()
{
return $this->belongsTo(User::class);
return $this->belongsTo(UserModel::class);
}
}
......@@ -7,10 +7,12 @@ use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Illuminate\Support\Facades\Hash;
class User extends Authenticatable implements MustVerifyEmail
class UserModel extends Authenticatable implements MustVerifyEmail
{
use Notifiable;
protected $table = 'users';
/**
* The attributes that are mass assignable.
*
......@@ -45,7 +47,7 @@ class User extends Authenticatable implements MustVerifyEmail
public static function createUser($data)
{
return User::create([
return UserModel::create([
'first_name' => $data['first_name'],
'last_name' => $data['last_name'],
'phone' => $data['phone'],
......
......@@ -68,7 +68,7 @@ return [
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\Models\User::class,
'model' => App\Models\UserModel::class,
],
// 'users' => [
......
......@@ -2,4 +2,10 @@
return [
'public_url' => env('PUBLIC_URL'),
'inquiry_status' => [
-1 => 'Closed',
0 => 'Pending',
1 => 'Replied',
]
];
......@@ -2,10 +2,10 @@
/** @var \Illuminate\Database\Eloquent\Factory $factory */
use App\Models\UserAddress;
use App\Models\UserAddressModel;
use Faker\Generator as Faker;
$factory->define(UserAddress::class, function (Faker $faker) {
$factory->define(UserAddressModel::class, function (Faker $faker) {
return [
'user_id' => $faker->numberBetween(10000, 20000),
'country' => $faker->country,
......
......@@ -2,7 +2,7 @@
/** @var \Illuminate\Database\Eloquent\Factory $factory */
use App\Models\User;
use App\Models\UserModel;
use Faker\Generator as Faker;
use Illuminate\Support\Str;
......@@ -17,7 +17,7 @@ use Illuminate\Support\Str;
|
*/
$factory->define(User::class, function (Faker $faker) {
$factory->define(UserModel::class, function (Faker $faker) {
return [
'name' => $faker->name,
'email' => $faker->unique()->safeEmail,
......
......@@ -11,8 +11,8 @@ class UserAddressSeeder extends Seeder
*/
public function run()
{
factory(\App\Models\UserAddress::class, 50)->create(['user_id' => 1])->each(function ($userAddress) {
$userAddress->save(factory(\App\Models\UserAddress::class)->make()->toArray());
factory(\App\Models\UserAddressModel::class, 50)->create(['user_id' => 1])->each(function ($userAddress) {
$userAddress->save(factory(\App\Models\UserAddressModel::class)->make()->toArray());
});
}
}
......@@ -21,9 +21,13 @@ Route::middleware(['api'])->namespace('Api')->group(function () {
Route::middleware(['api', 'api.check'])->namespace('Api')->group(function () {
Route::GET('/auth/logout', 'AuthApiController@logout');
Route::POST('auth/reset_password', 'AuthApiController@resetPassword');
Route::POST('auth/send_email_code', 'AuthApiController@sendEmailCode');
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