Commit c63800c0 by 杨树贤

询价接口

parent 045dfe30
......@@ -3,9 +3,8 @@
<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/ApiHelper/Response.php" beforeDir="false" afterPath="$PROJECT_DIR$/app/Http/ApiHelper/Response.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/Models/User.php" beforeDir="false" afterPath="$PROJECT_DIR$/app/Models/User.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/config/database.php" beforeDir="false" afterPath="$PROJECT_DIR$/config/database.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" />
......@@ -150,18 +149,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" />
<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" />
<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\Exceptions" />
<recent name="\\wsl$\Ubuntu-20.04\data\www\semour_web\app\Http" />
<recent name="\\wsl$\Ubuntu-20.04\data\www\semour_web\resources\views\about" />
<recent name="\\wsl$\Ubuntu-20.04\data\www\semour_web\app\Http\Traits" />
<recent name="\\wsl$\Ubuntu-20.04\data\www\semour_web\app\Http\Api" />
</key>
<key name="MoveFile.RECENT_KEYS">
<recent name="\\wsl$\Ubuntu-20.04\data\www\semour_web\resources\views\home" />
......@@ -184,7 +183,7 @@
<updated>1666170258203</updated>
<workItem from="1666170260162" duration="17108000" />
<workItem from="1666835076791" duration="693000" />
<workItem from="1667266026118" duration="12368000" />
<workItem from="1667266026118" duration="18067000" />
</task>
<servers />
</component>
......
<?php
namespace App\Exceptions;
use App\Http\ApiHelper\Response;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
/*
*无效请求异常
*/
class InvalidRequestException extends \Exception
{
public $field;
public function __construct($message, $field, $code = 200)
{
$this->field = $field;
parent::__construct($message, $code);
}
public function render(Request $request)
{
$request_uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '';
$path_info = parse_url($request_uri);
$err_info = [
'domain' => isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '',
'interface' => isset($path_info) ? $path_info['path'] : '',
'user_agent' => isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '',
'ip' => request()->getClientIp(),
'time' => time(),
'other' => '',
'request_params' => $_REQUEST,
'msg' => $this->getMessage(),
"code" => $this->getCode(),
];
Log::error(json_encode($err_info, JSON_UNESCAPED_UNICODE));
if ($this->field) {
return response()->json(json_decode(Response::setError($this->message, $this->field), true));
} else {
return response()->json(json_decode(Response::setError($this->message), true));
}
}
}
......@@ -17,9 +17,15 @@ class Response
JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
}
public static function setErrorWithField($errMsg, $field, $errCode = ApiCode::API_CODE_ERROR, $data = [])
{
return json_encode(['code' => $errCode, 'msg' => $errMsg, 'field' => $field, 'data' => $data],
JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
}
public static function setSuccess($data, $code = ApiCode::API_CODE_SUCCESS, $msg = "")
{
return json_encode(['code' => $code, 'msg' => $msg, 'data' => $data],
JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
}
}
\ No newline at end of file
}
......@@ -20,7 +20,7 @@ class AuthApiController extends Controller
public function register(Request $request)
{
$validator = Validator::make($request->all(), [
'email' => 'required|string|email|max:255|unique:users',
'email' => 'required|string|email|max:100',
'password' => 'required|string|min:8|confirmed',
'first_name' => 'required|max:100',
'last_name' => 'required|max:100',
......@@ -30,12 +30,19 @@ class AuthApiController extends Controller
], [
'password.confirmed' => 'Passwords do not match!',
]);
if ($validator->fails()) {
$keyName = $validator->errors()->keys()[0];
return $this->setError($validator->errors()->first());
}
$email = $request->input('email');
if (User::where('email', $email)->exists()) {
return $this->setError('Email has been taken');
}
//判断邮箱验证码
$redisKey = 'sem_email_code_register_' . $request->input('email');
$redisKey = 'sem_email_code_register_' . $email;
$cachedEmailCode = Redis::get($redisKey);
if ($cachedEmailCode != $request->input('email_code')) {
return $this->setError('Email code invalid');
......@@ -131,6 +138,9 @@ class AuthApiController extends Controller
//发送验证码
$code = mt_rand(1000, 9999);
$redisKey = 'sem_email_code_' . $type . '_' . $email;
if (Redis::get($redisKey)) {
return $this->setError('Email code had been sent');
}
Redis::set($redisKey, $code);
Redis::expire($redisKey, 60);
$subject = config('mail.from.name');
......
<?php
namespace App\Http\Controllers\Api;
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 InquiryApiController extends Controller
{
public function add(Request $request)
{
$data = $request->all();
$validator = Validator::make($data, [
'items.*.goods_name' => 'required|string|email|max:100',
'items.*.brand_name' => 'required|string|email|max:100',
'items.*.inquiry_number' => 'required|integer',
'remark' => 'max:255',
]);
if ($validator->fails()) {
$keyName = $validator->errors()->keys()[0];
return $this->setError($validator->errors()->first());
}
$user = request()->user();
$result = InquiryService::addInquiry($data, $user);
if (!$result) {
return $this->setError('Add inquiry failed , please contact administrator');
}
return $this->setSuccess('Add inquiry success');
}
}
<?php
namespace App\Http\Services;
class AuthService
{
}
<?php
namespace App\Http\Services;
use App\Models\Inquiry;
use App\Models\InquiryItems;
class InquiryService
{
public static function addInquiry($data, $user)
{
return DB::transaction(function () use ($data, $user) {
$items = \Arr::get($data, 'item', []);
$remark = $data['remark'];
$inquiry = [
'user_id' => $user->user_id,
'user_types' => $user->account_properties,
'remark' => $remark,
'create_time' => time(),
];
$inquiryId = Inquiry::addInquiry($inquiry);
$inquiryItems = [];
foreach ($items as $item) {
$inquiryItems[] = [
'inquiry_id' => $inquiryId,
'goods_name' => $item['goods_name'],
'brand_name' => $item['brand_name'],
'inquiry_number' => $item['inquiry_number'],
'remark' => $remark,
'create_time' => $item['create_time'],
];
}
return InquiryItems::addInquiryItems($inquiryItems);
});
}
}
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Inquiry extends Model
{
//
public $timestamps = false;
public static function addInquiry($inquiry)
{
return self::insertGetId($inquiry);
}
}
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class InquiryItems extends Model
{
public $timestamps = false;
public static function addInquiryItems($inquiryItems = [])
{
return self::insert($inquiryItems);
}
}
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