Commit 2c0ee0e9 by 肖康

Merge branch 'dev/ver/1.0.0' of http://git.ichunt.net/semour/semour_web into dev/ver/1.0.0

parents 693a0bd6 fcc22723
......@@ -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/SkuController.php" beforeDir="false" afterPath="$PROJECT_DIR$/app/Http/Controllers/SkuController.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/routes/web.php" beforeDir="false" afterPath="$PROJECT_DIR$/routes/web.php" 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$/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" />
......@@ -149,18 +150,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" />
<property name="last_opened_file_path" value="$PROJECT_DIR$/app/Http/Controllers/Api" />
<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\Controllers" />
<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\Requests" />
<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\Exceptions" />
<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" />
......@@ -183,7 +184,7 @@
<updated>1666170258203</updated>
<workItem from="1666170260162" duration="17108000" />
<workItem from="1666835076791" duration="693000" />
<workItem from="1667266026118" duration="20780000" />
<workItem from="1667266026118" duration="31053000" />
</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();
......@@ -111,10 +111,14 @@ class AuthApiController extends Controller
{
$email = $request->input('email');
$type = $request->input('type', 'register');
if (!$email) {
return $this->setError('Email address required');
$validator = Validator::make($request->all(), [
'email' => 'required|email',
]);
if ($validator->fails()) {
return $this->setError($validator->errors()->first());
}
$info = User::where('email', $email)->first();
$info = UserModel::where('email', $email)->first();
if ($info && $type == 'register') {
return $this->setError('This email had been registered');
}
......
......@@ -26,4 +26,20 @@ class InquiryApiController extends Controller
return $this->setSuccess('Add inquiry success');
}
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['data'],$result['total']);
}
public function detail(Request $request)
{
$inquiryId = $request->input('inquiry_id');
$inquiry = InquiryService::getInquiryDetail($inquiryId);
return $this->setSuccessData($inquiry);
}
}
<?php
namespace App\Http\Controllers\Api;
use App\Models\UserModel;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Redis;
use Illuminate\Support\Facades\Validator;
class UserApiController extends Controller
{
public function info(Request $request)
{
$user = $request->user();
$user = \Arr::only($user->toArray(), [
'id',
'name',
'email',
'phone',
'account_properties',
'company_name',
'first_name',
'last_name',
]);
return $this->setSuccessData($user);
}
public function update(Request $request)
{
$data = $request->only([
'account_properties',
'company_name',
'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->setSuccess('Save user info success');
}
public function changePhone(Request $request)
{
$password = $request->input('password');
$phone = $request->input('phone');
$validator = Validator::make($request->all(), [
'phone' => 'required',
'password' => 'required|max:100'
]);
if ($validator->fails()) {
return $this->setError($validator->errors()->first());
}
$userId = Auth::user()->id;
$hashedPassword = UserModel::where('id', $userId)->value('password');
if (!Hash::check($password, $hashedPassword)) {
return $this->setError('Wrong Password!');
}
$result = UserModel::where('id', $userId)->update(['phone' => $phone]);
if (!$result) {
return $this->setError('Change phone failed');
}
return $this->setSuccess('Change phone success');
}
public function changeEmail(Request $request)
{
$password = $request->input('password');
$email = $request->input('email');
$validator = Validator::make($request->all(), [
'email' => 'required|email',
'password' => 'required|max:100'
]);
if ($validator->fails()) {
return $this->setError($validator->errors()->first());
}
$userId = Auth::user()->id;
$hashedPassword = UserModel::where('id', $userId)->value('password');
if (!Hash::check($password, $hashedPassword)) {
return $this->setError('Wrong Password!');
}
//发送邮箱验证码
$redisKey = 'sem_email_code_change_email' . '_' . $email;
$cachedEmailCode = Redis::get($redisKey);
if ($cachedEmailCode != $request->input('email_code')) {
return $this->setError('Email code invalid');
}
$result = UserModel::where('id', $userId)->update(['email' => $email]);
if (!$result) {
return $this->setError('Change email failed');
}
return $this->setSuccess('Change email success');
}
}
......@@ -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,8 +31,53 @@ class InquiryService
'create_time' => $item['create_time'],
];
}
return InquiryItems::addInquiryItems($inquiryItems);
return InquiryItemsModel::addInquiryItems($inquiryItems);
});
}
public static function getInquiryDetail($inquiryId)
{
$inquiry = InquiryModel::select([
'inquiry_id',
'inquiry_sn',
'status',
'remark',
])->where('inquiry_id', $inquiryId)->first()->toArray();
$inquiryItems = InquiryItemsModel::select([
'goods_name',
'brand_name',
'inquiry_number',
])->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->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,11 +4,18 @@ 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(InquiryItemsModel::class, 'inquiry_id', 'inquiry_id');
}
public static function addInquiry($inquiry)
{
return self::insertGetId($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,15 @@ 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::get('user/info', 'UserApiController@info');
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