优化
This commit is contained in:
parent
99abeea2e2
commit
e3e9d990bb
28
webman/app/middleware/CrossDomain.php
Normal file
28
webman/app/middleware/CrossDomain.php
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
namespace app\middleware;
|
||||||
|
|
||||||
|
use Webman\Http\Request;
|
||||||
|
use Webman\Http\Response;
|
||||||
|
use Webman\MiddlewareInterface;
|
||||||
|
|
||||||
|
class CrossDomain implements MiddlewareInterface
|
||||||
|
{
|
||||||
|
public function process(Request $request, callable $next): Response
|
||||||
|
{
|
||||||
|
// 动态允许请求来源(支持携带Cookie)
|
||||||
|
$origin = $request->header('origin', '*');
|
||||||
|
$response = $next($request);
|
||||||
|
|
||||||
|
// 设置跨域响应头
|
||||||
|
$response->withHeaders([
|
||||||
|
'Access-Control-Allow-Origin' => $origin,
|
||||||
|
'Access-Control-Allow-Methods' => 'GET, POST, PUT, DELETE, OPTIONS',
|
||||||
|
'Access-Control-Allow-Headers' => 'Content-Type, Authorization, X-Requested-With',
|
||||||
|
'Access-Control-Allow-Credentials' => 'true', // 允许携带Cookie
|
||||||
|
'Access-Control-Max-Age' => 86400, // 预检请求缓存时间(秒)
|
||||||
|
'Vary' => 'Origin' // 避免缓存干扰
|
||||||
|
]);
|
||||||
|
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
}
|
@ -48,6 +48,7 @@ class Customer extends Model
|
|||||||
{
|
{
|
||||||
$customer['grade_txt'] = Constants::GRADE[$customer['grade']];
|
$customer['grade_txt'] = Constants::GRADE[$customer['grade']];
|
||||||
$customer['magnitude_txt'] = Constants::MAGNITUDE[$customer['magnitude']];
|
$customer['magnitude_txt'] = Constants::MAGNITUDE[$customer['magnitude']];
|
||||||
|
$customer['sex_txt'] = Constants::SEX[$customer['sex']];
|
||||||
|
|
||||||
if ($customer['grade']<=2) {
|
if ($customer['grade']<=2) {
|
||||||
$customer['follow'] = 0;
|
$customer['follow'] = 0;
|
||||||
@ -67,6 +68,8 @@ class Customer extends Model
|
|||||||
->where($where)
|
->where($where)
|
||||||
->min('created_at');
|
->min('created_at');
|
||||||
$customer['begin_follow'] = $begin_follow;
|
$customer['begin_follow'] = $begin_follow;
|
||||||
|
$customer['created_at'] = Util::timeTotDate($customer['created_at']);
|
||||||
|
$customer['updated_at'] = Util::timeTotDate($customer['updated_at']);
|
||||||
// $customer['last_follow'] = $last_follow;
|
// $customer['last_follow'] = $last_follow;
|
||||||
|
|
||||||
return $customer;
|
return $customer;
|
||||||
|
@ -36,7 +36,7 @@ class Util
|
|||||||
/**
|
/**
|
||||||
* 失败
|
* 失败
|
||||||
*/
|
*/
|
||||||
public static function fail($data = [],$message = '', $code = '500')
|
public static function fail($data = [],$message = '', $code = -1)
|
||||||
{
|
{
|
||||||
$result = [
|
$result = [
|
||||||
'code' => $code,
|
'code' => $code,
|
||||||
@ -49,7 +49,7 @@ class Util
|
|||||||
/**
|
/**
|
||||||
* 成功
|
* 成功
|
||||||
*/
|
*/
|
||||||
public static function success($data = [],$message = '', $code = '200')
|
public static function success($data = [],$message = '', $code = 0)
|
||||||
{
|
{
|
||||||
$result = [
|
$result = [
|
||||||
'code' => $code,
|
'code' => $code,
|
||||||
@ -62,7 +62,7 @@ class Util
|
|||||||
/**
|
/**
|
||||||
* 分页查询返回
|
* 分页查询返回
|
||||||
*/
|
*/
|
||||||
public static function page($data,$message = '', $code = '200')
|
public static function page($data,$message = '', $code = 0)
|
||||||
{
|
{
|
||||||
$result = [
|
$result = [
|
||||||
'code' => $code,
|
'code' => $code,
|
||||||
@ -79,5 +79,15 @@ class Util
|
|||||||
return json($result);
|
return json($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 成功日期
|
||||||
|
*/
|
||||||
|
public static function timeTotDate($time = 0, $format = 'Y-m-d H:i:s')
|
||||||
|
{
|
||||||
|
if (empty($time)) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
return date($format, $time);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -40,4 +40,15 @@ class Constants
|
|||||||
self::CUSTOMER_FOLLOW_VISIT => '线下拜访',
|
self::CUSTOMER_FOLLOW_VISIT => '线下拜访',
|
||||||
self::CUSTOMER_FOLLOW_UP => '线上跟进',
|
self::CUSTOMER_FOLLOW_UP => '线上跟进',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
//跟进类型
|
||||||
|
public const CUSTOMER_SEX_UNKNOWN = 0; // 未知
|
||||||
|
public const CUSTOMER_SEX_MAN = 1; // 男
|
||||||
|
public const CUSTOMER_SEX_WOMAN = 2; // 女
|
||||||
|
|
||||||
|
public const SEX = [
|
||||||
|
self::CUSTOMER_SEX_UNKNOWN => '未知',
|
||||||
|
self::CUSTOMER_SEX_MAN => '男',
|
||||||
|
self::CUSTOMER_SEX_WOMAN => '女',
|
||||||
|
];
|
||||||
}
|
}
|
@ -15,6 +15,7 @@
|
|||||||
return [
|
return [
|
||||||
// 全局中间件
|
// 全局中间件
|
||||||
'' => [
|
'' => [
|
||||||
app\middleware\AuthMiddleware::class,
|
app\middleware\CrossDomain::class, // 全局跨域中间件
|
||||||
|
app\middleware\AuthMiddleware::class, // 鉴权中间件
|
||||||
]
|
]
|
||||||
];
|
];
|
@ -14,6 +14,15 @@
|
|||||||
|
|
||||||
use Webman\Route;
|
use Webman\Route;
|
||||||
|
|
||||||
|
// 拦截所有OPTIONS请求并直接响应
|
||||||
|
//Route::options('[{path:.+}]', function () {
|
||||||
|
// return response('', 204)
|
||||||
|
// ->withHeaders(['Content-Type' => 'text/plain']);
|
||||||
|
//});
|
||||||
|
|
||||||
|
// 登录接口
|
||||||
|
Route::any('/login', [app\controller\UserController::class, 'login'])->middleware([app\middleware\CrossDomain::class]);
|
||||||
|
|
||||||
// 文件上传接口
|
// 文件上传接口
|
||||||
Route::post('/upload', [app\controller\UploadController::class, 'upload']);
|
Route::post('/upload', [app\controller\UploadController::class, 'upload']);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user