Initial commit: queue workspace

Made-with: Cursor
This commit is contained in:
apple
2026-03-21 02:55:24 +08:00
commit 78de918c37
12388 changed files with 1840126 additions and 0 deletions

View File

@@ -0,0 +1,62 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\http\middleware\api;
use app\Request;
use app\services\community\CommunityUserServices;
use app\services\user\UserAuthServices;
use crmeb\exceptions\AuthException;
use crmeb\interfaces\MiddlewareInterface;
use think\exception\DbException;
/**
* Class AuthTokenMiddleware
* @package app\api\middleware
*/
class AuthTokenMiddleware implements MiddlewareInterface
{
public function handle(Request $request, \Closure $next, bool $force = true)
{
$authInfo = null;
$token = trim(ltrim($request->header('Authori-zation'), 'Bearer'));
if (!$token) $token = trim(ltrim($request->header('Authorization'), 'Bearer'));//正式版删除此行某些服务器无法获取到token调整为 Authori-zation
try {
/** @var UserAuthServices $service */
$service = app()->make(UserAuthServices::class);
$authInfo = $service->parseToken($token);
} catch (AuthException $e) {
if ($force)
return app('json')->make($e->getCode(), $e->getMessage());
}
if (!is_null($authInfo)) {
$request->user = function (string $key = null) use (&$authInfo) {
if ($key) {
return $authInfo['user'][$key] ?? '';
}
return $authInfo['user'];
};
$request->tokenData = $authInfo['tokenData'];
}
$request->isLogin = !is_null($authInfo);
$request->uid = is_null($authInfo) ? 0 : (int)$authInfo['user']->uid;
if ($request->uid) {
/** @var CommunityUserServices $communityUserServices */
$communityUserServices = app()->make(CommunityUserServices::class);
$communityUserServices->hasUser($request->uid);
}
return $next($request);
}
}

View File

@@ -0,0 +1,66 @@
<?php
/**
* +----------------------------------------------------------------------
* | CRMEB [ CRMEB赋能开发者助力企业发展 ]
* +----------------------------------------------------------------------
* | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
* +----------------------------------------------------------------------
* | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
* +----------------------------------------------------------------------
* | Author: CRMEB Team <admin@crmeb.com>
* +----------------------------------------------------------------------
*/
namespace app\http\middleware\api;
use app\Request;
use crmeb\exceptions\ApiException;
use crmeb\interfaces\MiddlewareInterface;
use crmeb\services\CacheService;
/**
* reids锁
* Class BlockerMiddleware
* @author 等风来
* @email 136327134@qq.com
* @date 2022/11/21
* @package app\http\middleware\api
*/
class BlockerMiddleware implements MiddlewareInterface
{
/**
* @param Request $request
* @param \Closure $next
* @author 等风来
* @email 136327134@qq.com
* @date 2022/11/21
*/
public function handle(Request $request, \Closure $next)
{
$uid = $request->uid();
$key = md5($request->rule()->getRule() . $uid. json_encode($request->param()));
if (!CacheService::setMutex($key)) {
throw new ApiException('请求太过频繁,请稍后再试');
}
$response = $next($request);
$this->after($response, $key);
return $response;
}
/**
* @param $response
* @param $key
* @author 等风来
* @email 136327134@qq.com
* @date 2022/11/22
*/
public function after($response, $key)
{
CacheService::delMutex($key);
}
}

View File

@@ -0,0 +1,56 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\http\middleware\api;
use app\Request;
use app\services\user\UserAuthServices;
use crmeb\interfaces\MiddlewareInterface;
/**
* 客户身份验证中间件
* Class ClientMiddleware
* @package app\http\middleware\api
*/
class ClientMiddleware implements MiddlewareInterface
{
public function handle(Request $request, \Closure $next)
{
$userId = trim(ltrim($request->param('userid')));
if (!$userId) {
return app('json')->fail('缺少Userid');
}
try {
/** @var UserAuthServices $service */
$service = app()->make(UserAuthServices::class);
$authInfo = $service->parseClient($userId);
} catch (\Throwable $e) {
return app('json')->fail($e->getMessage());
}
$request->clientInfo = function (string $key = null) use ($authInfo) {
if ($key) {
return $authInfo[$key] ?? null;
} else {
return $authInfo;
}
};
$request->userid = $userId;
return $next($request);
}
}

View File

@@ -0,0 +1,36 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\http\middleware\api;
use app\Request;
use app\services\community\CommunityUserServices;
use crmeb\interfaces\MiddlewareInterface;
/**
* 社区是否开启
* Class StationOpenMiddleware
* @package app\api\middleware
*/
class CommunityOpenMiddleware implements MiddlewareInterface
{
public function handle(Request $request, \Closure $next)
{
if (!sys_config('community_status', 1)) {
return app('json')->make('410010', '社区暂未开放');
}
//社区用户写入
$uid = $request->hasMacro('uid') ? $request->uid() : 0;
return $next($request);
}
}

View File

@@ -0,0 +1,38 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\http\middleware\api;
use app\services\message\service\StoreServiceServices;
use app\services\store\DeliveryServiceServices;
use app\services\store\SystemStoreStaffServices;
use crmeb\interfaces\MiddlewareInterface;
use app\Request;
class CustomerMiddleware implements MiddlewareInterface
{
public function handle(Request $request, \Closure $next)
{
$uid = (int)$request->uid();
/** @var StoreServiceServices $services */
$services = app()->make(StoreServiceServices::class);
/** @var SystemStoreStaffServices $storeServices */
$storeServices = app()->make(SystemStoreStaffServices::class);
$rule = trim(strtolower($request->rule()->getRule()));
/** @var DeliveryServiceServices $deliveryService */
$deliveryService = app()->make(DeliveryServiceServices::class);
$isDelivery = $deliveryService->checkoutIsService($uid);
$withRule = ['/api/order/order_verific', "/api/admin/order/detail/<orderId>"];
if (((!$services->checkoutIsService(['uid' => $uid, 'account_status' => 1, 'customer' => 1]) && !$storeServices->verifyStatus($uid)) && !$isDelivery) && !(in_array($rule, $withRule)))
return app('json')->fail('权限不足');
return $next($request);
}
}

View File

@@ -0,0 +1,41 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\http\middleware\api;
use app\Request;
use app\services\user\LoginServices;
use crmeb\interfaces\MiddlewareInterface;
/**
* 全局修改绑定分销关系
* Class ClientMiddleware
* @package app\http\middleware\api
*/
class UserSpreadMiddleware implements MiddlewareInterface
{
public function handle(Request $request, \Closure $next)
{
$spread_uid = trim(ltrim($request->param('spread_sid')));
//登录存在用户信息
$user = $request->hasMacro('user') ? $request->user() : [];
//更新绑定关系
if ($user && $spread_uid) {
/** @var LoginServices $loginServices */
$loginServices = app()->make(LoginServices::class);
$loginServices->updateUserInfo(['spread_uid' => $spread_uid], $user);
}
return $next($request);
}
}